]>
Commit | Line | Data |
---|---|---|
79e53945 JB |
1 | /* |
2 | * Copyright © 2006-2007 Intel Corporation | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * Eric Anholt <eric@anholt.net> | |
25 | */ | |
26 | ||
618563e3 | 27 | #include <linux/dmi.h> |
c1c7af60 JB |
28 | #include <linux/module.h> |
29 | #include <linux/input.h> | |
79e53945 | 30 | #include <linux/i2c.h> |
7662c8bd | 31 | #include <linux/kernel.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
9cce37f4 | 33 | #include <linux/vgaarb.h> |
e0dac65e | 34 | #include <drm/drm_edid.h> |
760285e7 | 35 | #include <drm/drmP.h> |
79e53945 | 36 | #include "intel_drv.h" |
760285e7 | 37 | #include <drm/i915_drm.h> |
79e53945 | 38 | #include "i915_drv.h" |
e5510fac | 39 | #include "i915_trace.h" |
319c1d42 | 40 | #include <drm/drm_atomic.h> |
c196e1d6 | 41 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
42 | #include <drm/drm_dp_helper.h> |
43 | #include <drm/drm_crtc_helper.h> | |
465c120c MR |
44 | #include <drm/drm_plane_helper.h> |
45 | #include <drm/drm_rect.h> | |
c0f372b3 | 46 | #include <linux/dma_remapping.h> |
79e53945 | 47 | |
465c120c | 48 | /* Primary plane formats for gen <= 3 */ |
568db4f2 | 49 | static const uint32_t i8xx_primary_formats[] = { |
67fe7dc5 DL |
50 | DRM_FORMAT_C8, |
51 | DRM_FORMAT_RGB565, | |
465c120c | 52 | DRM_FORMAT_XRGB1555, |
67fe7dc5 | 53 | DRM_FORMAT_XRGB8888, |
465c120c MR |
54 | }; |
55 | ||
56 | /* Primary plane formats for gen >= 4 */ | |
568db4f2 | 57 | static const uint32_t i965_primary_formats[] = { |
6c0fd451 DL |
58 | DRM_FORMAT_C8, |
59 | DRM_FORMAT_RGB565, | |
60 | DRM_FORMAT_XRGB8888, | |
61 | DRM_FORMAT_XBGR8888, | |
62 | DRM_FORMAT_XRGB2101010, | |
63 | DRM_FORMAT_XBGR2101010, | |
64 | }; | |
65 | ||
66 | static const uint32_t skl_primary_formats[] = { | |
67fe7dc5 DL |
67 | DRM_FORMAT_C8, |
68 | DRM_FORMAT_RGB565, | |
69 | DRM_FORMAT_XRGB8888, | |
465c120c | 70 | DRM_FORMAT_XBGR8888, |
67fe7dc5 | 71 | DRM_FORMAT_ARGB8888, |
465c120c MR |
72 | DRM_FORMAT_ABGR8888, |
73 | DRM_FORMAT_XRGB2101010, | |
465c120c | 74 | DRM_FORMAT_XBGR2101010, |
ea916ea0 KM |
75 | DRM_FORMAT_YUYV, |
76 | DRM_FORMAT_YVYU, | |
77 | DRM_FORMAT_UYVY, | |
78 | DRM_FORMAT_VYUY, | |
465c120c MR |
79 | }; |
80 | ||
3d7d6510 MR |
81 | /* Cursor formats */ |
82 | static const uint32_t intel_cursor_formats[] = { | |
83 | DRM_FORMAT_ARGB8888, | |
84 | }; | |
85 | ||
6b383a7f | 86 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
79e53945 | 87 | |
f1f644dc | 88 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 89 | struct intel_crtc_state *pipe_config); |
18442d08 | 90 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 91 | struct intel_crtc_state *pipe_config); |
f1f644dc | 92 | |
eb1bfe80 JB |
93 | static int intel_framebuffer_init(struct drm_device *dev, |
94 | struct intel_framebuffer *ifb, | |
95 | struct drm_mode_fb_cmd2 *mode_cmd, | |
96 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
97 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
98 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
29407aab | 99 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
100 | struct intel_link_m_n *m_n, |
101 | struct intel_link_m_n *m2_n2); | |
29407aab | 102 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 DV |
103 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
104 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
d288f65f | 105 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 106 | const struct intel_crtc_state *pipe_config); |
d288f65f | 107 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 108 | const struct intel_crtc_state *pipe_config); |
613d2b27 ML |
109 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
110 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); | |
549e2bfb CK |
111 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
112 | struct intel_crtc_state *crtc_state); | |
5ab7b0b7 ID |
113 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
114 | int num_connectors); | |
bfd16b2a ML |
115 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
116 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); | |
117 | static void ironlake_pfit_enable(struct intel_crtc *crtc); | |
043e9bda | 118 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
e7457a9a | 119 | |
79e53945 | 120 | typedef struct { |
0206e353 | 121 | int min, max; |
79e53945 JB |
122 | } intel_range_t; |
123 | ||
124 | typedef struct { | |
0206e353 AJ |
125 | int dot_limit; |
126 | int p2_slow, p2_fast; | |
79e53945 JB |
127 | } intel_p2_t; |
128 | ||
d4906093 ML |
129 | typedef struct intel_limit intel_limit_t; |
130 | struct intel_limit { | |
0206e353 AJ |
131 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
132 | intel_p2_t p2; | |
d4906093 | 133 | }; |
79e53945 | 134 | |
bfa7df01 VS |
135 | /* returns HPLL frequency in kHz */ |
136 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) | |
137 | { | |
138 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; | |
139 | ||
140 | /* Obtain SKU information */ | |
141 | mutex_lock(&dev_priv->sb_lock); | |
142 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
143 | CCK_FUSE_HPLL_FREQ_MASK; | |
144 | mutex_unlock(&dev_priv->sb_lock); | |
145 | ||
146 | return vco_freq[hpll_freq] * 1000; | |
147 | } | |
148 | ||
149 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, | |
150 | const char *name, u32 reg) | |
151 | { | |
152 | u32 val; | |
153 | int divider; | |
154 | ||
155 | if (dev_priv->hpll_freq == 0) | |
156 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
157 | ||
158 | mutex_lock(&dev_priv->sb_lock); | |
159 | val = vlv_cck_read(dev_priv, reg); | |
160 | mutex_unlock(&dev_priv->sb_lock); | |
161 | ||
162 | divider = val & CCK_FREQUENCY_VALUES; | |
163 | ||
164 | WARN((val & CCK_FREQUENCY_STATUS) != | |
165 | (divider << CCK_FREQUENCY_STATUS_SHIFT), | |
166 | "%s change in progress\n", name); | |
167 | ||
168 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); | |
169 | } | |
170 | ||
d2acd215 DV |
171 | int |
172 | intel_pch_rawclk(struct drm_device *dev) | |
173 | { | |
174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
175 | ||
176 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
177 | ||
178 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
179 | } | |
180 | ||
79e50a4f JN |
181 | /* hrawclock is 1/4 the FSB frequency */ |
182 | int intel_hrawclk(struct drm_device *dev) | |
183 | { | |
184 | struct drm_i915_private *dev_priv = dev->dev_private; | |
185 | uint32_t clkcfg; | |
186 | ||
187 | /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */ | |
188 | if (IS_VALLEYVIEW(dev)) | |
189 | return 200; | |
190 | ||
191 | clkcfg = I915_READ(CLKCFG); | |
192 | switch (clkcfg & CLKCFG_FSB_MASK) { | |
193 | case CLKCFG_FSB_400: | |
194 | return 100; | |
195 | case CLKCFG_FSB_533: | |
196 | return 133; | |
197 | case CLKCFG_FSB_667: | |
198 | return 166; | |
199 | case CLKCFG_FSB_800: | |
200 | return 200; | |
201 | case CLKCFG_FSB_1067: | |
202 | return 266; | |
203 | case CLKCFG_FSB_1333: | |
204 | return 333; | |
205 | /* these two are just a guess; one of them might be right */ | |
206 | case CLKCFG_FSB_1600: | |
207 | case CLKCFG_FSB_1600_ALT: | |
208 | return 400; | |
209 | default: | |
210 | return 133; | |
211 | } | |
212 | } | |
213 | ||
bfa7df01 VS |
214 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
215 | { | |
216 | if (!IS_VALLEYVIEW(dev_priv)) | |
217 | return; | |
218 | ||
219 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", | |
220 | CCK_CZ_CLOCK_CONTROL); | |
221 | ||
222 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); | |
223 | } | |
224 | ||
021357ac CW |
225 | static inline u32 /* units of 100MHz */ |
226 | intel_fdi_link_freq(struct drm_device *dev) | |
227 | { | |
8b99e68c CW |
228 | if (IS_GEN5(dev)) { |
229 | struct drm_i915_private *dev_priv = dev->dev_private; | |
230 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
231 | } else | |
232 | return 27; | |
021357ac CW |
233 | } |
234 | ||
5d536e28 | 235 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 236 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 237 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 238 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
239 | .m = { .min = 96, .max = 140 }, |
240 | .m1 = { .min = 18, .max = 26 }, | |
241 | .m2 = { .min = 6, .max = 16 }, | |
242 | .p = { .min = 4, .max = 128 }, | |
243 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
244 | .p2 = { .dot_limit = 165000, |
245 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
246 | }; |
247 | ||
5d536e28 DV |
248 | static const intel_limit_t intel_limits_i8xx_dvo = { |
249 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 250 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 251 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
252 | .m = { .min = 96, .max = 140 }, |
253 | .m1 = { .min = 18, .max = 26 }, | |
254 | .m2 = { .min = 6, .max = 16 }, | |
255 | .p = { .min = 4, .max = 128 }, | |
256 | .p1 = { .min = 2, .max = 33 }, | |
257 | .p2 = { .dot_limit = 165000, | |
258 | .p2_slow = 4, .p2_fast = 4 }, | |
259 | }; | |
260 | ||
e4b36699 | 261 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 262 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 263 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 264 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
265 | .m = { .min = 96, .max = 140 }, |
266 | .m1 = { .min = 18, .max = 26 }, | |
267 | .m2 = { .min = 6, .max = 16 }, | |
268 | .p = { .min = 4, .max = 128 }, | |
269 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
270 | .p2 = { .dot_limit = 165000, |
271 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 272 | }; |
273e27ca | 273 | |
e4b36699 | 274 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
275 | .dot = { .min = 20000, .max = 400000 }, |
276 | .vco = { .min = 1400000, .max = 2800000 }, | |
277 | .n = { .min = 1, .max = 6 }, | |
278 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
279 | .m1 = { .min = 8, .max = 18 }, |
280 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
281 | .p = { .min = 5, .max = 80 }, |
282 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
283 | .p2 = { .dot_limit = 200000, |
284 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
285 | }; |
286 | ||
287 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
288 | .dot = { .min = 20000, .max = 400000 }, |
289 | .vco = { .min = 1400000, .max = 2800000 }, | |
290 | .n = { .min = 1, .max = 6 }, | |
291 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
292 | .m1 = { .min = 8, .max = 18 }, |
293 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
294 | .p = { .min = 7, .max = 98 }, |
295 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
296 | .p2 = { .dot_limit = 112000, |
297 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
298 | }; |
299 | ||
273e27ca | 300 | |
e4b36699 | 301 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
302 | .dot = { .min = 25000, .max = 270000 }, |
303 | .vco = { .min = 1750000, .max = 3500000}, | |
304 | .n = { .min = 1, .max = 4 }, | |
305 | .m = { .min = 104, .max = 138 }, | |
306 | .m1 = { .min = 17, .max = 23 }, | |
307 | .m2 = { .min = 5, .max = 11 }, | |
308 | .p = { .min = 10, .max = 30 }, | |
309 | .p1 = { .min = 1, .max = 3}, | |
310 | .p2 = { .dot_limit = 270000, | |
311 | .p2_slow = 10, | |
312 | .p2_fast = 10 | |
044c7c41 | 313 | }, |
e4b36699 KP |
314 | }; |
315 | ||
316 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
317 | .dot = { .min = 22000, .max = 400000 }, |
318 | .vco = { .min = 1750000, .max = 3500000}, | |
319 | .n = { .min = 1, .max = 4 }, | |
320 | .m = { .min = 104, .max = 138 }, | |
321 | .m1 = { .min = 16, .max = 23 }, | |
322 | .m2 = { .min = 5, .max = 11 }, | |
323 | .p = { .min = 5, .max = 80 }, | |
324 | .p1 = { .min = 1, .max = 8}, | |
325 | .p2 = { .dot_limit = 165000, | |
326 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
327 | }; |
328 | ||
329 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
330 | .dot = { .min = 20000, .max = 115000 }, |
331 | .vco = { .min = 1750000, .max = 3500000 }, | |
332 | .n = { .min = 1, .max = 3 }, | |
333 | .m = { .min = 104, .max = 138 }, | |
334 | .m1 = { .min = 17, .max = 23 }, | |
335 | .m2 = { .min = 5, .max = 11 }, | |
336 | .p = { .min = 28, .max = 112 }, | |
337 | .p1 = { .min = 2, .max = 8 }, | |
338 | .p2 = { .dot_limit = 0, | |
339 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 340 | }, |
e4b36699 KP |
341 | }; |
342 | ||
343 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
344 | .dot = { .min = 80000, .max = 224000 }, |
345 | .vco = { .min = 1750000, .max = 3500000 }, | |
346 | .n = { .min = 1, .max = 3 }, | |
347 | .m = { .min = 104, .max = 138 }, | |
348 | .m1 = { .min = 17, .max = 23 }, | |
349 | .m2 = { .min = 5, .max = 11 }, | |
350 | .p = { .min = 14, .max = 42 }, | |
351 | .p1 = { .min = 2, .max = 6 }, | |
352 | .p2 = { .dot_limit = 0, | |
353 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 354 | }, |
e4b36699 KP |
355 | }; |
356 | ||
f2b115e6 | 357 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
358 | .dot = { .min = 20000, .max = 400000}, |
359 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 360 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
361 | .n = { .min = 3, .max = 6 }, |
362 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 363 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
364 | .m1 = { .min = 0, .max = 0 }, |
365 | .m2 = { .min = 0, .max = 254 }, | |
366 | .p = { .min = 5, .max = 80 }, | |
367 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
368 | .p2 = { .dot_limit = 200000, |
369 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
370 | }; |
371 | ||
f2b115e6 | 372 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
373 | .dot = { .min = 20000, .max = 400000 }, |
374 | .vco = { .min = 1700000, .max = 3500000 }, | |
375 | .n = { .min = 3, .max = 6 }, | |
376 | .m = { .min = 2, .max = 256 }, | |
377 | .m1 = { .min = 0, .max = 0 }, | |
378 | .m2 = { .min = 0, .max = 254 }, | |
379 | .p = { .min = 7, .max = 112 }, | |
380 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
381 | .p2 = { .dot_limit = 112000, |
382 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
383 | }; |
384 | ||
273e27ca EA |
385 | /* Ironlake / Sandybridge |
386 | * | |
387 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
388 | * the range value for them is (actual_value - 2). | |
389 | */ | |
b91ad0ec | 390 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
391 | .dot = { .min = 25000, .max = 350000 }, |
392 | .vco = { .min = 1760000, .max = 3510000 }, | |
393 | .n = { .min = 1, .max = 5 }, | |
394 | .m = { .min = 79, .max = 127 }, | |
395 | .m1 = { .min = 12, .max = 22 }, | |
396 | .m2 = { .min = 5, .max = 9 }, | |
397 | .p = { .min = 5, .max = 80 }, | |
398 | .p1 = { .min = 1, .max = 8 }, | |
399 | .p2 = { .dot_limit = 225000, | |
400 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
401 | }; |
402 | ||
b91ad0ec | 403 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
404 | .dot = { .min = 25000, .max = 350000 }, |
405 | .vco = { .min = 1760000, .max = 3510000 }, | |
406 | .n = { .min = 1, .max = 3 }, | |
407 | .m = { .min = 79, .max = 118 }, | |
408 | .m1 = { .min = 12, .max = 22 }, | |
409 | .m2 = { .min = 5, .max = 9 }, | |
410 | .p = { .min = 28, .max = 112 }, | |
411 | .p1 = { .min = 2, .max = 8 }, | |
412 | .p2 = { .dot_limit = 225000, | |
413 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
414 | }; |
415 | ||
416 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
417 | .dot = { .min = 25000, .max = 350000 }, |
418 | .vco = { .min = 1760000, .max = 3510000 }, | |
419 | .n = { .min = 1, .max = 3 }, | |
420 | .m = { .min = 79, .max = 127 }, | |
421 | .m1 = { .min = 12, .max = 22 }, | |
422 | .m2 = { .min = 5, .max = 9 }, | |
423 | .p = { .min = 14, .max = 56 }, | |
424 | .p1 = { .min = 2, .max = 8 }, | |
425 | .p2 = { .dot_limit = 225000, | |
426 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
427 | }; |
428 | ||
273e27ca | 429 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 430 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
431 | .dot = { .min = 25000, .max = 350000 }, |
432 | .vco = { .min = 1760000, .max = 3510000 }, | |
433 | .n = { .min = 1, .max = 2 }, | |
434 | .m = { .min = 79, .max = 126 }, | |
435 | .m1 = { .min = 12, .max = 22 }, | |
436 | .m2 = { .min = 5, .max = 9 }, | |
437 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 438 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
439 | .p2 = { .dot_limit = 225000, |
440 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
441 | }; |
442 | ||
443 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
444 | .dot = { .min = 25000, .max = 350000 }, |
445 | .vco = { .min = 1760000, .max = 3510000 }, | |
446 | .n = { .min = 1, .max = 3 }, | |
447 | .m = { .min = 79, .max = 126 }, | |
448 | .m1 = { .min = 12, .max = 22 }, | |
449 | .m2 = { .min = 5, .max = 9 }, | |
450 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 451 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
452 | .p2 = { .dot_limit = 225000, |
453 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
454 | }; |
455 | ||
dc730512 | 456 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
457 | /* |
458 | * These are the data rate limits (measured in fast clocks) | |
459 | * since those are the strictest limits we have. The fast | |
460 | * clock and actual rate limits are more relaxed, so checking | |
461 | * them would make no difference. | |
462 | */ | |
463 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 464 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 465 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
466 | .m1 = { .min = 2, .max = 3 }, |
467 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 468 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 469 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
470 | }; |
471 | ||
ef9348c8 CML |
472 | static const intel_limit_t intel_limits_chv = { |
473 | /* | |
474 | * These are the data rate limits (measured in fast clocks) | |
475 | * since those are the strictest limits we have. The fast | |
476 | * clock and actual rate limits are more relaxed, so checking | |
477 | * them would make no difference. | |
478 | */ | |
479 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 480 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
481 | .n = { .min = 1, .max = 1 }, |
482 | .m1 = { .min = 2, .max = 2 }, | |
483 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
484 | .p1 = { .min = 2, .max = 4 }, | |
485 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
486 | }; | |
487 | ||
5ab7b0b7 ID |
488 | static const intel_limit_t intel_limits_bxt = { |
489 | /* FIXME: find real dot limits */ | |
490 | .dot = { .min = 0, .max = INT_MAX }, | |
e6292556 | 491 | .vco = { .min = 4800000, .max = 6700000 }, |
5ab7b0b7 ID |
492 | .n = { .min = 1, .max = 1 }, |
493 | .m1 = { .min = 2, .max = 2 }, | |
494 | /* FIXME: find real m2 limits */ | |
495 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
496 | .p1 = { .min = 2, .max = 4 }, | |
497 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
498 | }; | |
499 | ||
cdba954e ACO |
500 | static bool |
501 | needs_modeset(struct drm_crtc_state *state) | |
502 | { | |
fc596660 | 503 | return drm_atomic_crtc_needs_modeset(state); |
cdba954e ACO |
504 | } |
505 | ||
e0638cdf PZ |
506 | /** |
507 | * Returns whether any output on the specified pipe is of the specified type | |
508 | */ | |
4093561b | 509 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 510 | { |
409ee761 | 511 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
512 | struct intel_encoder *encoder; |
513 | ||
409ee761 | 514 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
515 | if (encoder->type == type) |
516 | return true; | |
517 | ||
518 | return false; | |
519 | } | |
520 | ||
d0737e1d ACO |
521 | /** |
522 | * Returns whether any output on the specified pipe will have the specified | |
523 | * type after a staged modeset is complete, i.e., the same as | |
524 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
525 | * encoder->crtc. | |
526 | */ | |
a93e255f ACO |
527 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
528 | int type) | |
d0737e1d | 529 | { |
a93e255f | 530 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 531 | struct drm_connector *connector; |
a93e255f | 532 | struct drm_connector_state *connector_state; |
d0737e1d | 533 | struct intel_encoder *encoder; |
a93e255f ACO |
534 | int i, num_connectors = 0; |
535 | ||
da3ced29 | 536 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
537 | if (connector_state->crtc != crtc_state->base.crtc) |
538 | continue; | |
539 | ||
540 | num_connectors++; | |
d0737e1d | 541 | |
a93e255f ACO |
542 | encoder = to_intel_encoder(connector_state->best_encoder); |
543 | if (encoder->type == type) | |
d0737e1d | 544 | return true; |
a93e255f ACO |
545 | } |
546 | ||
547 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
548 | |
549 | return false; | |
550 | } | |
551 | ||
a93e255f ACO |
552 | static const intel_limit_t * |
553 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 554 | { |
a93e255f | 555 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 556 | const intel_limit_t *limit; |
b91ad0ec | 557 | |
a93e255f | 558 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 559 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 560 | if (refclk == 100000) |
b91ad0ec ZW |
561 | limit = &intel_limits_ironlake_dual_lvds_100m; |
562 | else | |
563 | limit = &intel_limits_ironlake_dual_lvds; | |
564 | } else { | |
1b894b59 | 565 | if (refclk == 100000) |
b91ad0ec ZW |
566 | limit = &intel_limits_ironlake_single_lvds_100m; |
567 | else | |
568 | limit = &intel_limits_ironlake_single_lvds; | |
569 | } | |
c6bb3538 | 570 | } else |
b91ad0ec | 571 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
572 | |
573 | return limit; | |
574 | } | |
575 | ||
a93e255f ACO |
576 | static const intel_limit_t * |
577 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 578 | { |
a93e255f | 579 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
580 | const intel_limit_t *limit; |
581 | ||
a93e255f | 582 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 583 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 584 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 585 | else |
e4b36699 | 586 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
587 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
588 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 589 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 590 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 591 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 592 | } else /* The option is for other outputs */ |
e4b36699 | 593 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
594 | |
595 | return limit; | |
596 | } | |
597 | ||
a93e255f ACO |
598 | static const intel_limit_t * |
599 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 600 | { |
a93e255f | 601 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
602 | const intel_limit_t *limit; |
603 | ||
5ab7b0b7 ID |
604 | if (IS_BROXTON(dev)) |
605 | limit = &intel_limits_bxt; | |
606 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 607 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 608 | else if (IS_G4X(dev)) { |
a93e255f | 609 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 610 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 611 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 612 | limit = &intel_limits_pineview_lvds; |
2177832f | 613 | else |
f2b115e6 | 614 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
615 | } else if (IS_CHERRYVIEW(dev)) { |
616 | limit = &intel_limits_chv; | |
a0c4da24 | 617 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 618 | limit = &intel_limits_vlv; |
a6c45cf0 | 619 | } else if (!IS_GEN2(dev)) { |
a93e255f | 620 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
621 | limit = &intel_limits_i9xx_lvds; |
622 | else | |
623 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 624 | } else { |
a93e255f | 625 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 626 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 627 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 628 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
629 | else |
630 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
631 | } |
632 | return limit; | |
633 | } | |
634 | ||
dccbea3b ID |
635 | /* |
636 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
637 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
638 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
639 | * The helpers' return value is the rate of the clock that is fed to the | |
640 | * display engine's pipe which can be the above fast dot clock rate or a | |
641 | * divided-down version of it. | |
642 | */ | |
f2b115e6 | 643 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
dccbea3b | 644 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
79e53945 | 645 | { |
2177832f SL |
646 | clock->m = clock->m2 + 2; |
647 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e | 648 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
dccbea3b | 649 | return 0; |
fb03ac01 VS |
650 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
651 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
652 | |
653 | return clock->dot; | |
2177832f SL |
654 | } |
655 | ||
7429e9d4 DV |
656 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
657 | { | |
658 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
659 | } | |
660 | ||
dccbea3b | 661 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
2177832f | 662 | { |
7429e9d4 | 663 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 664 | clock->p = clock->p1 * clock->p2; |
ed5ca77e | 665 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
dccbea3b | 666 | return 0; |
fb03ac01 VS |
667 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
668 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
669 | |
670 | return clock->dot; | |
79e53945 JB |
671 | } |
672 | ||
dccbea3b | 673 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
589eca67 ID |
674 | { |
675 | clock->m = clock->m1 * clock->m2; | |
676 | clock->p = clock->p1 * clock->p2; | |
677 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 678 | return 0; |
589eca67 ID |
679 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
680 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
681 | |
682 | return clock->dot / 5; | |
589eca67 ID |
683 | } |
684 | ||
dccbea3b | 685 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
ef9348c8 CML |
686 | { |
687 | clock->m = clock->m1 * clock->m2; | |
688 | clock->p = clock->p1 * clock->p2; | |
689 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 690 | return 0; |
ef9348c8 CML |
691 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
692 | clock->n << 22); | |
693 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
694 | |
695 | return clock->dot / 5; | |
ef9348c8 CML |
696 | } |
697 | ||
7c04d1d9 | 698 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
699 | /** |
700 | * Returns whether the given set of divisors are valid for a given refclk with | |
701 | * the given connectors. | |
702 | */ | |
703 | ||
1b894b59 CW |
704 | static bool intel_PLL_is_valid(struct drm_device *dev, |
705 | const intel_limit_t *limit, | |
706 | const intel_clock_t *clock) | |
79e53945 | 707 | { |
f01b7962 VS |
708 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
709 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 710 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 711 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 712 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 713 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 714 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 715 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 716 | |
5ab7b0b7 | 717 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
f01b7962 VS |
718 | if (clock->m1 <= clock->m2) |
719 | INTELPllInvalid("m1 <= m2\n"); | |
720 | ||
5ab7b0b7 | 721 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
722 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
723 | INTELPllInvalid("p out of range\n"); | |
724 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
725 | INTELPllInvalid("m out of range\n"); | |
726 | } | |
727 | ||
79e53945 | 728 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 729 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
730 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
731 | * connector, etc., rather than just a single range. | |
732 | */ | |
733 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 734 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
735 | |
736 | return true; | |
737 | } | |
738 | ||
3b1429d9 VS |
739 | static int |
740 | i9xx_select_p2_div(const intel_limit_t *limit, | |
741 | const struct intel_crtc_state *crtc_state, | |
742 | int target) | |
79e53945 | 743 | { |
3b1429d9 | 744 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 745 | |
a93e255f | 746 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 747 | /* |
a210b028 DV |
748 | * For LVDS just rely on its current settings for dual-channel. |
749 | * We haven't figured out how to reliably set up different | |
750 | * single/dual channel state, if we even can. | |
79e53945 | 751 | */ |
1974cad0 | 752 | if (intel_is_dual_link_lvds(dev)) |
3b1429d9 | 753 | return limit->p2.p2_fast; |
79e53945 | 754 | else |
3b1429d9 | 755 | return limit->p2.p2_slow; |
79e53945 JB |
756 | } else { |
757 | if (target < limit->p2.dot_limit) | |
3b1429d9 | 758 | return limit->p2.p2_slow; |
79e53945 | 759 | else |
3b1429d9 | 760 | return limit->p2.p2_fast; |
79e53945 | 761 | } |
3b1429d9 VS |
762 | } |
763 | ||
764 | static bool | |
765 | i9xx_find_best_dpll(const intel_limit_t *limit, | |
766 | struct intel_crtc_state *crtc_state, | |
767 | int target, int refclk, intel_clock_t *match_clock, | |
768 | intel_clock_t *best_clock) | |
769 | { | |
770 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
771 | intel_clock_t clock; | |
772 | int err = target; | |
79e53945 | 773 | |
0206e353 | 774 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 775 | |
3b1429d9 VS |
776 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
777 | ||
42158660 ZY |
778 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
779 | clock.m1++) { | |
780 | for (clock.m2 = limit->m2.min; | |
781 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 782 | if (clock.m2 >= clock.m1) |
42158660 ZY |
783 | break; |
784 | for (clock.n = limit->n.min; | |
785 | clock.n <= limit->n.max; clock.n++) { | |
786 | for (clock.p1 = limit->p1.min; | |
787 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
788 | int this_err; |
789 | ||
dccbea3b | 790 | i9xx_calc_dpll_params(refclk, &clock); |
ac58c3f0 DV |
791 | if (!intel_PLL_is_valid(dev, limit, |
792 | &clock)) | |
793 | continue; | |
794 | if (match_clock && | |
795 | clock.p != match_clock->p) | |
796 | continue; | |
797 | ||
798 | this_err = abs(clock.dot - target); | |
799 | if (this_err < err) { | |
800 | *best_clock = clock; | |
801 | err = this_err; | |
802 | } | |
803 | } | |
804 | } | |
805 | } | |
806 | } | |
807 | ||
808 | return (err != target); | |
809 | } | |
810 | ||
811 | static bool | |
a93e255f ACO |
812 | pnv_find_best_dpll(const intel_limit_t *limit, |
813 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
814 | int target, int refclk, intel_clock_t *match_clock, |
815 | intel_clock_t *best_clock) | |
79e53945 | 816 | { |
3b1429d9 | 817 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 818 | intel_clock_t clock; |
79e53945 JB |
819 | int err = target; |
820 | ||
0206e353 | 821 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 822 | |
3b1429d9 VS |
823 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
824 | ||
42158660 ZY |
825 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
826 | clock.m1++) { | |
827 | for (clock.m2 = limit->m2.min; | |
828 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
829 | for (clock.n = limit->n.min; |
830 | clock.n <= limit->n.max; clock.n++) { | |
831 | for (clock.p1 = limit->p1.min; | |
832 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
833 | int this_err; |
834 | ||
dccbea3b | 835 | pnv_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
836 | if (!intel_PLL_is_valid(dev, limit, |
837 | &clock)) | |
79e53945 | 838 | continue; |
cec2f356 SP |
839 | if (match_clock && |
840 | clock.p != match_clock->p) | |
841 | continue; | |
79e53945 JB |
842 | |
843 | this_err = abs(clock.dot - target); | |
844 | if (this_err < err) { | |
845 | *best_clock = clock; | |
846 | err = this_err; | |
847 | } | |
848 | } | |
849 | } | |
850 | } | |
851 | } | |
852 | ||
853 | return (err != target); | |
854 | } | |
855 | ||
d4906093 | 856 | static bool |
a93e255f ACO |
857 | g4x_find_best_dpll(const intel_limit_t *limit, |
858 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
859 | int target, int refclk, intel_clock_t *match_clock, |
860 | intel_clock_t *best_clock) | |
d4906093 | 861 | { |
3b1429d9 | 862 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d4906093 ML |
863 | intel_clock_t clock; |
864 | int max_n; | |
3b1429d9 | 865 | bool found = false; |
6ba770dc AJ |
866 | /* approximately equals target * 0.00585 */ |
867 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
868 | |
869 | memset(best_clock, 0, sizeof(*best_clock)); | |
3b1429d9 VS |
870 | |
871 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
872 | ||
d4906093 | 873 | max_n = limit->n.max; |
f77f13e2 | 874 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 875 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 876 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
877 | for (clock.m1 = limit->m1.max; |
878 | clock.m1 >= limit->m1.min; clock.m1--) { | |
879 | for (clock.m2 = limit->m2.max; | |
880 | clock.m2 >= limit->m2.min; clock.m2--) { | |
881 | for (clock.p1 = limit->p1.max; | |
882 | clock.p1 >= limit->p1.min; clock.p1--) { | |
883 | int this_err; | |
884 | ||
dccbea3b | 885 | i9xx_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
886 | if (!intel_PLL_is_valid(dev, limit, |
887 | &clock)) | |
d4906093 | 888 | continue; |
1b894b59 CW |
889 | |
890 | this_err = abs(clock.dot - target); | |
d4906093 ML |
891 | if (this_err < err_most) { |
892 | *best_clock = clock; | |
893 | err_most = this_err; | |
894 | max_n = clock.n; | |
895 | found = true; | |
896 | } | |
897 | } | |
898 | } | |
899 | } | |
900 | } | |
2c07245f ZW |
901 | return found; |
902 | } | |
903 | ||
d5dd62bd ID |
904 | /* |
905 | * Check if the calculated PLL configuration is more optimal compared to the | |
906 | * best configuration and error found so far. Return the calculated error. | |
907 | */ | |
908 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
909 | const intel_clock_t *calculated_clock, | |
910 | const intel_clock_t *best_clock, | |
911 | unsigned int best_error_ppm, | |
912 | unsigned int *error_ppm) | |
913 | { | |
9ca3ba01 ID |
914 | /* |
915 | * For CHV ignore the error and consider only the P value. | |
916 | * Prefer a bigger P value based on HW requirements. | |
917 | */ | |
918 | if (IS_CHERRYVIEW(dev)) { | |
919 | *error_ppm = 0; | |
920 | ||
921 | return calculated_clock->p > best_clock->p; | |
922 | } | |
923 | ||
24be4e46 ID |
924 | if (WARN_ON_ONCE(!target_freq)) |
925 | return false; | |
926 | ||
d5dd62bd ID |
927 | *error_ppm = div_u64(1000000ULL * |
928 | abs(target_freq - calculated_clock->dot), | |
929 | target_freq); | |
930 | /* | |
931 | * Prefer a better P value over a better (smaller) error if the error | |
932 | * is small. Ensure this preference for future configurations too by | |
933 | * setting the error to 0. | |
934 | */ | |
935 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
936 | *error_ppm = 0; | |
937 | ||
938 | return true; | |
939 | } | |
940 | ||
941 | return *error_ppm + 10 < best_error_ppm; | |
942 | } | |
943 | ||
a0c4da24 | 944 | static bool |
a93e255f ACO |
945 | vlv_find_best_dpll(const intel_limit_t *limit, |
946 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
947 | int target, int refclk, intel_clock_t *match_clock, |
948 | intel_clock_t *best_clock) | |
a0c4da24 | 949 | { |
a93e255f | 950 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 951 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 952 | intel_clock_t clock; |
69e4f900 | 953 | unsigned int bestppm = 1000000; |
27e639bf VS |
954 | /* min update 19.2 MHz */ |
955 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 956 | bool found = false; |
a0c4da24 | 957 | |
6b4bf1c4 VS |
958 | target *= 5; /* fast clock */ |
959 | ||
960 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
961 | |
962 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 963 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 964 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 965 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 966 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 967 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 968 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 969 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 970 | unsigned int ppm; |
69e4f900 | 971 | |
6b4bf1c4 VS |
972 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
973 | refclk * clock.m1); | |
974 | ||
dccbea3b | 975 | vlv_calc_dpll_params(refclk, &clock); |
43b0ac53 | 976 | |
f01b7962 VS |
977 | if (!intel_PLL_is_valid(dev, limit, |
978 | &clock)) | |
43b0ac53 VS |
979 | continue; |
980 | ||
d5dd62bd ID |
981 | if (!vlv_PLL_is_optimal(dev, target, |
982 | &clock, | |
983 | best_clock, | |
984 | bestppm, &ppm)) | |
985 | continue; | |
6b4bf1c4 | 986 | |
d5dd62bd ID |
987 | *best_clock = clock; |
988 | bestppm = ppm; | |
989 | found = true; | |
a0c4da24 JB |
990 | } |
991 | } | |
992 | } | |
993 | } | |
a0c4da24 | 994 | |
49e497ef | 995 | return found; |
a0c4da24 | 996 | } |
a4fc5ed6 | 997 | |
ef9348c8 | 998 | static bool |
a93e255f ACO |
999 | chv_find_best_dpll(const intel_limit_t *limit, |
1000 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
1001 | int target, int refclk, intel_clock_t *match_clock, |
1002 | intel_clock_t *best_clock) | |
1003 | { | |
a93e255f | 1004 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 1005 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 1006 | unsigned int best_error_ppm; |
ef9348c8 CML |
1007 | intel_clock_t clock; |
1008 | uint64_t m2; | |
1009 | int found = false; | |
1010 | ||
1011 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 1012 | best_error_ppm = 1000000; |
ef9348c8 CML |
1013 | |
1014 | /* | |
1015 | * Based on hardware doc, the n always set to 1, and m1 always | |
1016 | * set to 2. If requires to support 200Mhz refclk, we need to | |
1017 | * revisit this because n may not 1 anymore. | |
1018 | */ | |
1019 | clock.n = 1, clock.m1 = 2; | |
1020 | target *= 5; /* fast clock */ | |
1021 | ||
1022 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
1023 | for (clock.p2 = limit->p2.p2_fast; | |
1024 | clock.p2 >= limit->p2.p2_slow; | |
1025 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 1026 | unsigned int error_ppm; |
ef9348c8 CML |
1027 | |
1028 | clock.p = clock.p1 * clock.p2; | |
1029 | ||
1030 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
1031 | clock.n) << 22, refclk * clock.m1); | |
1032 | ||
1033 | if (m2 > INT_MAX/clock.m1) | |
1034 | continue; | |
1035 | ||
1036 | clock.m2 = m2; | |
1037 | ||
dccbea3b | 1038 | chv_calc_dpll_params(refclk, &clock); |
ef9348c8 CML |
1039 | |
1040 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
1041 | continue; | |
1042 | ||
9ca3ba01 ID |
1043 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
1044 | best_error_ppm, &error_ppm)) | |
1045 | continue; | |
1046 | ||
1047 | *best_clock = clock; | |
1048 | best_error_ppm = error_ppm; | |
1049 | found = true; | |
ef9348c8 CML |
1050 | } |
1051 | } | |
1052 | ||
1053 | return found; | |
1054 | } | |
1055 | ||
5ab7b0b7 ID |
1056 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
1057 | intel_clock_t *best_clock) | |
1058 | { | |
1059 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
1060 | ||
1061 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
1062 | target_clock, refclk, NULL, best_clock); | |
1063 | } | |
1064 | ||
20ddf665 VS |
1065 | bool intel_crtc_active(struct drm_crtc *crtc) |
1066 | { | |
1067 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1068 | ||
1069 | /* Be paranoid as we can arrive here with only partial | |
1070 | * state retrieved from the hardware during setup. | |
1071 | * | |
241bfc38 | 1072 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
1073 | * as Haswell has gained clock readout/fastboot support. |
1074 | * | |
66e514c1 | 1075 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 1076 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1077 | * |
1078 | * FIXME: The intel_crtc->active here should be switched to | |
1079 | * crtc->state->active once we have proper CRTC states wired up | |
1080 | * for atomic. | |
20ddf665 | 1081 | */ |
c3d1f436 | 1082 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1083 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1084 | } |
1085 | ||
a5c961d1 PZ |
1086 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1087 | enum pipe pipe) | |
1088 | { | |
1089 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1090 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1091 | ||
6e3c9717 | 1092 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1093 | } |
1094 | ||
fbf49ea2 VS |
1095 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1096 | { | |
1097 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1098 | u32 reg = PIPEDSL(pipe); | |
1099 | u32 line1, line2; | |
1100 | u32 line_mask; | |
1101 | ||
1102 | if (IS_GEN2(dev)) | |
1103 | line_mask = DSL_LINEMASK_GEN2; | |
1104 | else | |
1105 | line_mask = DSL_LINEMASK_GEN3; | |
1106 | ||
1107 | line1 = I915_READ(reg) & line_mask; | |
6adfb1ef | 1108 | msleep(5); |
fbf49ea2 VS |
1109 | line2 = I915_READ(reg) & line_mask; |
1110 | ||
1111 | return line1 == line2; | |
1112 | } | |
1113 | ||
ab7ad7f6 KP |
1114 | /* |
1115 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1116 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1117 | * |
1118 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1119 | * spinning on the vblank interrupt status bit, since we won't actually | |
1120 | * see an interrupt when the pipe is disabled. | |
1121 | * | |
ab7ad7f6 KP |
1122 | * On Gen4 and above: |
1123 | * wait for the pipe register state bit to turn off | |
1124 | * | |
1125 | * Otherwise: | |
1126 | * wait for the display line value to settle (it usually | |
1127 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1128 | * |
9d0498a2 | 1129 | */ |
575f7ab7 | 1130 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1131 | { |
575f7ab7 | 1132 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1133 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1134 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1135 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1136 | |
1137 | if (INTEL_INFO(dev)->gen >= 4) { | |
702e7a56 | 1138 | int reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1139 | |
1140 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1141 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1142 | 100)) | |
284637d9 | 1143 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1144 | } else { |
ab7ad7f6 | 1145 | /* Wait for the display line to settle */ |
fbf49ea2 | 1146 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1147 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1148 | } |
79e53945 JB |
1149 | } |
1150 | ||
b24e7179 JB |
1151 | static const char *state_string(bool enabled) |
1152 | { | |
1153 | return enabled ? "on" : "off"; | |
1154 | } | |
1155 | ||
1156 | /* Only for pre-ILK configs */ | |
55607e8a DV |
1157 | void assert_pll(struct drm_i915_private *dev_priv, |
1158 | enum pipe pipe, bool state) | |
b24e7179 | 1159 | { |
b24e7179 JB |
1160 | u32 val; |
1161 | bool cur_state; | |
1162 | ||
649636ef | 1163 | val = I915_READ(DPLL(pipe)); |
b24e7179 | 1164 | cur_state = !!(val & DPLL_VCO_ENABLE); |
e2c719b7 | 1165 | I915_STATE_WARN(cur_state != state, |
b24e7179 JB |
1166 | "PLL state assertion failure (expected %s, current %s)\n", |
1167 | state_string(state), state_string(cur_state)); | |
1168 | } | |
b24e7179 | 1169 | |
23538ef1 JN |
1170 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1171 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1172 | { | |
1173 | u32 val; | |
1174 | bool cur_state; | |
1175 | ||
a580516d | 1176 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1177 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1178 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1179 | |
1180 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1181 | I915_STATE_WARN(cur_state != state, |
23538ef1 JN |
1182 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
1183 | state_string(state), state_string(cur_state)); | |
1184 | } | |
1185 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1186 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1187 | ||
55607e8a | 1188 | struct intel_shared_dpll * |
e2b78267 DV |
1189 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1190 | { | |
1191 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1192 | ||
6e3c9717 | 1193 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1194 | return NULL; |
1195 | ||
6e3c9717 | 1196 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1197 | } |
1198 | ||
040484af | 1199 | /* For ILK+ */ |
55607e8a DV |
1200 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1201 | struct intel_shared_dpll *pll, | |
1202 | bool state) | |
040484af | 1203 | { |
040484af | 1204 | bool cur_state; |
5358901f | 1205 | struct intel_dpll_hw_state hw_state; |
040484af | 1206 | |
92b27b08 | 1207 | if (WARN (!pll, |
46edb027 | 1208 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
ee7b9f93 | 1209 | return; |
ee7b9f93 | 1210 | |
5358901f | 1211 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1212 | I915_STATE_WARN(cur_state != state, |
5358901f DV |
1213 | "%s assertion failure (expected %s, current %s)\n", |
1214 | pll->name, state_string(state), state_string(cur_state)); | |
040484af | 1215 | } |
040484af JB |
1216 | |
1217 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1218 | enum pipe pipe, bool state) | |
1219 | { | |
040484af | 1220 | bool cur_state; |
ad80a810 PZ |
1221 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1222 | pipe); | |
040484af | 1223 | |
affa9354 PZ |
1224 | if (HAS_DDI(dev_priv->dev)) { |
1225 | /* DDI does not have a specific FDI_TX register */ | |
649636ef | 1226 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
ad80a810 | 1227 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 | 1228 | } else { |
649636ef | 1229 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
bf507ef7 ED |
1230 | cur_state = !!(val & FDI_TX_ENABLE); |
1231 | } | |
e2c719b7 | 1232 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1233 | "FDI TX state assertion failure (expected %s, current %s)\n", |
1234 | state_string(state), state_string(cur_state)); | |
1235 | } | |
1236 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1237 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1238 | ||
1239 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1240 | enum pipe pipe, bool state) | |
1241 | { | |
040484af JB |
1242 | u32 val; |
1243 | bool cur_state; | |
1244 | ||
649636ef | 1245 | val = I915_READ(FDI_RX_CTL(pipe)); |
d63fa0dc | 1246 | cur_state = !!(val & FDI_RX_ENABLE); |
e2c719b7 | 1247 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1248 | "FDI RX state assertion failure (expected %s, current %s)\n", |
1249 | state_string(state), state_string(cur_state)); | |
1250 | } | |
1251 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1252 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1253 | ||
1254 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1255 | enum pipe pipe) | |
1256 | { | |
040484af JB |
1257 | u32 val; |
1258 | ||
1259 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1260 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1261 | return; |
1262 | ||
bf507ef7 | 1263 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1264 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1265 | return; |
1266 | ||
649636ef | 1267 | val = I915_READ(FDI_TX_CTL(pipe)); |
e2c719b7 | 1268 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1269 | } |
1270 | ||
55607e8a DV |
1271 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1272 | enum pipe pipe, bool state) | |
040484af | 1273 | { |
040484af | 1274 | u32 val; |
55607e8a | 1275 | bool cur_state; |
040484af | 1276 | |
649636ef | 1277 | val = I915_READ(FDI_RX_CTL(pipe)); |
55607e8a | 1278 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1279 | I915_STATE_WARN(cur_state != state, |
55607e8a DV |
1280 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
1281 | state_string(state), state_string(cur_state)); | |
040484af JB |
1282 | } |
1283 | ||
b680c37a DV |
1284 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1285 | enum pipe pipe) | |
ea0760cf | 1286 | { |
bedd4dba JN |
1287 | struct drm_device *dev = dev_priv->dev; |
1288 | int pp_reg; | |
ea0760cf JB |
1289 | u32 val; |
1290 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1291 | bool locked = true; |
ea0760cf | 1292 | |
bedd4dba JN |
1293 | if (WARN_ON(HAS_DDI(dev))) |
1294 | return; | |
1295 | ||
1296 | if (HAS_PCH_SPLIT(dev)) { | |
1297 | u32 port_sel; | |
1298 | ||
ea0760cf | 1299 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1300 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1301 | ||
1302 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1303 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1304 | panel_pipe = PIPE_B; | |
1305 | /* XXX: else fix for eDP */ | |
1306 | } else if (IS_VALLEYVIEW(dev)) { | |
1307 | /* presumably write lock depends on pipe, not port select */ | |
1308 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1309 | panel_pipe = pipe; | |
ea0760cf JB |
1310 | } else { |
1311 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1312 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1313 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1314 | } |
1315 | ||
1316 | val = I915_READ(pp_reg); | |
1317 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1318 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1319 | locked = false; |
1320 | ||
e2c719b7 | 1321 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1322 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1323 | pipe_name(pipe)); |
ea0760cf JB |
1324 | } |
1325 | ||
93ce0ba6 JN |
1326 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1327 | enum pipe pipe, bool state) | |
1328 | { | |
1329 | struct drm_device *dev = dev_priv->dev; | |
1330 | bool cur_state; | |
1331 | ||
d9d82081 | 1332 | if (IS_845G(dev) || IS_I865G(dev)) |
0b87c24e | 1333 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
d9d82081 | 1334 | else |
5efb3e28 | 1335 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1336 | |
e2c719b7 | 1337 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 JN |
1338 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
1339 | pipe_name(pipe), state_string(state), state_string(cur_state)); | |
1340 | } | |
1341 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1342 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1343 | ||
b840d907 JB |
1344 | void assert_pipe(struct drm_i915_private *dev_priv, |
1345 | enum pipe pipe, bool state) | |
b24e7179 | 1346 | { |
63d7bbe9 | 1347 | bool cur_state; |
702e7a56 PZ |
1348 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1349 | pipe); | |
b24e7179 | 1350 | |
b6b5d049 VS |
1351 | /* if we need the pipe quirk it must be always on */ |
1352 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1353 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1354 | state = true; |
1355 | ||
f458ebbc | 1356 | if (!intel_display_power_is_enabled(dev_priv, |
b97186f0 | 1357 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
69310161 PZ |
1358 | cur_state = false; |
1359 | } else { | |
649636ef | 1360 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
69310161 PZ |
1361 | cur_state = !!(val & PIPECONF_ENABLE); |
1362 | } | |
1363 | ||
e2c719b7 | 1364 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1365 | "pipe %c assertion failure (expected %s, current %s)\n", |
9db4a9c7 | 1366 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
b24e7179 JB |
1367 | } |
1368 | ||
931872fc CW |
1369 | static void assert_plane(struct drm_i915_private *dev_priv, |
1370 | enum plane plane, bool state) | |
b24e7179 | 1371 | { |
b24e7179 | 1372 | u32 val; |
931872fc | 1373 | bool cur_state; |
b24e7179 | 1374 | |
649636ef | 1375 | val = I915_READ(DSPCNTR(plane)); |
931872fc | 1376 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1377 | I915_STATE_WARN(cur_state != state, |
931872fc CW |
1378 | "plane %c assertion failure (expected %s, current %s)\n", |
1379 | plane_name(plane), state_string(state), state_string(cur_state)); | |
b24e7179 JB |
1380 | } |
1381 | ||
931872fc CW |
1382 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1383 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1384 | ||
b24e7179 JB |
1385 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1386 | enum pipe pipe) | |
1387 | { | |
653e1026 | 1388 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1389 | int i; |
b24e7179 | 1390 | |
653e1026 VS |
1391 | /* Primary planes are fixed to pipes on gen4+ */ |
1392 | if (INTEL_INFO(dev)->gen >= 4) { | |
649636ef | 1393 | u32 val = I915_READ(DSPCNTR(pipe)); |
e2c719b7 | 1394 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1395 | "plane %c assertion failure, should be disabled but not\n", |
1396 | plane_name(pipe)); | |
19ec1358 | 1397 | return; |
28c05794 | 1398 | } |
19ec1358 | 1399 | |
b24e7179 | 1400 | /* Need to check both planes against the pipe */ |
055e393f | 1401 | for_each_pipe(dev_priv, i) { |
649636ef VS |
1402 | u32 val = I915_READ(DSPCNTR(i)); |
1403 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
b24e7179 | 1404 | DISPPLANE_SEL_PIPE_SHIFT; |
e2c719b7 | 1405 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1406 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1407 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1408 | } |
1409 | } | |
1410 | ||
19332d7a JB |
1411 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1412 | enum pipe pipe) | |
1413 | { | |
20674eef | 1414 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1415 | int sprite; |
19332d7a | 1416 | |
7feb8b88 | 1417 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1418 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1419 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1420 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1421 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1422 | sprite, pipe_name(pipe)); | |
1423 | } | |
1424 | } else if (IS_VALLEYVIEW(dev)) { | |
3bdcfc0c | 1425 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1426 | u32 val = I915_READ(SPCNTR(pipe, sprite)); |
e2c719b7 | 1427 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1428 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1429 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1430 | } |
1431 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
649636ef | 1432 | u32 val = I915_READ(SPRCTL(pipe)); |
e2c719b7 | 1433 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1434 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1435 | plane_name(pipe), pipe_name(pipe)); |
1436 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
649636ef | 1437 | u32 val = I915_READ(DVSCNTR(pipe)); |
e2c719b7 | 1438 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1439 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1440 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1441 | } |
1442 | } | |
1443 | ||
08c71e5e VS |
1444 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1445 | { | |
e2c719b7 | 1446 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1447 | drm_crtc_vblank_put(crtc); |
1448 | } | |
1449 | ||
89eff4be | 1450 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1451 | { |
1452 | u32 val; | |
1453 | bool enabled; | |
1454 | ||
e2c719b7 | 1455 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1456 | |
92f2584a JB |
1457 | val = I915_READ(PCH_DREF_CONTROL); |
1458 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1459 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1460 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1461 | } |
1462 | ||
ab9412ba DV |
1463 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1464 | enum pipe pipe) | |
92f2584a | 1465 | { |
92f2584a JB |
1466 | u32 val; |
1467 | bool enabled; | |
1468 | ||
649636ef | 1469 | val = I915_READ(PCH_TRANSCONF(pipe)); |
92f2584a | 1470 | enabled = !!(val & TRANS_ENABLE); |
e2c719b7 | 1471 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1472 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1473 | pipe_name(pipe)); | |
92f2584a JB |
1474 | } |
1475 | ||
4e634389 KP |
1476 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1477 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1478 | { |
1479 | if ((val & DP_PORT_EN) == 0) | |
1480 | return false; | |
1481 | ||
1482 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1483 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); | |
1484 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); | |
1485 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1486 | return false; | |
44f37d1f CML |
1487 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1488 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1489 | return false; | |
f0575e92 KP |
1490 | } else { |
1491 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1492 | return false; | |
1493 | } | |
1494 | return true; | |
1495 | } | |
1496 | ||
1519b995 KP |
1497 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1498 | enum pipe pipe, u32 val) | |
1499 | { | |
dc0fa718 | 1500 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1501 | return false; |
1502 | ||
1503 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1504 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1505 | return false; |
44f37d1f CML |
1506 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1507 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1508 | return false; | |
1519b995 | 1509 | } else { |
dc0fa718 | 1510 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1511 | return false; |
1512 | } | |
1513 | return true; | |
1514 | } | |
1515 | ||
1516 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1517 | enum pipe pipe, u32 val) | |
1518 | { | |
1519 | if ((val & LVDS_PORT_EN) == 0) | |
1520 | return false; | |
1521 | ||
1522 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1523 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1524 | return false; | |
1525 | } else { | |
1526 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1527 | return false; | |
1528 | } | |
1529 | return true; | |
1530 | } | |
1531 | ||
1532 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1533 | enum pipe pipe, u32 val) | |
1534 | { | |
1535 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1536 | return false; | |
1537 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1538 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1539 | return false; | |
1540 | } else { | |
1541 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1542 | return false; | |
1543 | } | |
1544 | return true; | |
1545 | } | |
1546 | ||
291906f1 | 1547 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0575e92 | 1548 | enum pipe pipe, int reg, u32 port_sel) |
291906f1 | 1549 | { |
47a05eca | 1550 | u32 val = I915_READ(reg); |
e2c719b7 | 1551 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1552 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1553 | reg, pipe_name(pipe)); |
de9a35ab | 1554 | |
e2c719b7 | 1555 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1556 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1557 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1558 | } |
1559 | ||
1560 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1561 | enum pipe pipe, int reg) | |
1562 | { | |
47a05eca | 1563 | u32 val = I915_READ(reg); |
e2c719b7 | 1564 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1565 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1566 | reg, pipe_name(pipe)); |
de9a35ab | 1567 | |
e2c719b7 | 1568 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1569 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1570 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1571 | } |
1572 | ||
1573 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1574 | enum pipe pipe) | |
1575 | { | |
291906f1 | 1576 | u32 val; |
291906f1 | 1577 | |
f0575e92 KP |
1578 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1579 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1580 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 | 1581 | |
649636ef | 1582 | val = I915_READ(PCH_ADPA); |
e2c719b7 | 1583 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1584 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1585 | pipe_name(pipe)); |
291906f1 | 1586 | |
649636ef | 1587 | val = I915_READ(PCH_LVDS); |
e2c719b7 | 1588 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1589 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1590 | pipe_name(pipe)); |
291906f1 | 1591 | |
e2debe91 PZ |
1592 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1593 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1594 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1595 | } |
1596 | ||
d288f65f | 1597 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1598 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1599 | { |
426115cf DV |
1600 | struct drm_device *dev = crtc->base.dev; |
1601 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1602 | int reg = DPLL(crtc->pipe); | |
d288f65f | 1603 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1604 | |
426115cf | 1605 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 DV |
1606 | |
1607 | /* No really, not for ILK+ */ | |
1608 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); | |
1609 | ||
1610 | /* PLL is protected by panel, make sure we can write it */ | |
6a9e7363 | 1611 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1612 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1613 | |
426115cf DV |
1614 | I915_WRITE(reg, dpll); |
1615 | POSTING_READ(reg); | |
1616 | udelay(150); | |
1617 | ||
1618 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1619 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1620 | ||
d288f65f | 1621 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1622 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1623 | |
1624 | /* We do this three times for luck */ | |
426115cf | 1625 | I915_WRITE(reg, dpll); |
87442f73 DV |
1626 | POSTING_READ(reg); |
1627 | udelay(150); /* wait for warmup */ | |
426115cf | 1628 | I915_WRITE(reg, dpll); |
87442f73 DV |
1629 | POSTING_READ(reg); |
1630 | udelay(150); /* wait for warmup */ | |
426115cf | 1631 | I915_WRITE(reg, dpll); |
87442f73 DV |
1632 | POSTING_READ(reg); |
1633 | udelay(150); /* wait for warmup */ | |
1634 | } | |
1635 | ||
d288f65f | 1636 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1637 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1638 | { |
1639 | struct drm_device *dev = crtc->base.dev; | |
1640 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1641 | int pipe = crtc->pipe; | |
1642 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1643 | u32 tmp; |
1644 | ||
1645 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1646 | ||
1647 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); | |
1648 | ||
a580516d | 1649 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1650 | |
1651 | /* Enable back the 10bit clock to display controller */ | |
1652 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1653 | tmp |= DPIO_DCLKP_EN; | |
1654 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1655 | ||
54433e91 VS |
1656 | mutex_unlock(&dev_priv->sb_lock); |
1657 | ||
9d556c99 CML |
1658 | /* |
1659 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1660 | */ | |
1661 | udelay(1); | |
1662 | ||
1663 | /* Enable PLL */ | |
d288f65f | 1664 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1665 | |
1666 | /* Check PLL is locked */ | |
a11b0703 | 1667 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1668 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1669 | ||
a11b0703 | 1670 | /* not sure when this should be written */ |
d288f65f | 1671 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 | 1672 | POSTING_READ(DPLL_MD(pipe)); |
9d556c99 CML |
1673 | } |
1674 | ||
1c4e0274 VS |
1675 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1676 | { | |
1677 | struct intel_crtc *crtc; | |
1678 | int count = 0; | |
1679 | ||
1680 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1681 | count += crtc->base.state->active && |
409ee761 | 1682 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1683 | |
1684 | return count; | |
1685 | } | |
1686 | ||
66e3d5c0 | 1687 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1688 | { |
66e3d5c0 DV |
1689 | struct drm_device *dev = crtc->base.dev; |
1690 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1691 | int reg = DPLL(crtc->pipe); | |
6e3c9717 | 1692 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1693 | |
66e3d5c0 | 1694 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1695 | |
63d7bbe9 | 1696 | /* No really, not for ILK+ */ |
3d13ef2e | 1697 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1698 | |
1699 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1700 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1701 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1702 | |
1c4e0274 VS |
1703 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1704 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1705 | /* | |
1706 | * It appears to be important that we don't enable this | |
1707 | * for the current pipe before otherwise configuring the | |
1708 | * PLL. No idea how this should be handled if multiple | |
1709 | * DVO outputs are enabled simultaneosly. | |
1710 | */ | |
1711 | dpll |= DPLL_DVO_2X_MODE; | |
1712 | I915_WRITE(DPLL(!crtc->pipe), | |
1713 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1714 | } | |
66e3d5c0 DV |
1715 | |
1716 | /* Wait for the clocks to stabilize. */ | |
1717 | POSTING_READ(reg); | |
1718 | udelay(150); | |
1719 | ||
1720 | if (INTEL_INFO(dev)->gen >= 4) { | |
1721 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1722 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1723 | } else { |
1724 | /* The pixel multiplier can only be updated once the | |
1725 | * DPLL is enabled and the clocks are stable. | |
1726 | * | |
1727 | * So write it again. | |
1728 | */ | |
1729 | I915_WRITE(reg, dpll); | |
1730 | } | |
63d7bbe9 JB |
1731 | |
1732 | /* We do this three times for luck */ | |
66e3d5c0 | 1733 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1734 | POSTING_READ(reg); |
1735 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1736 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1737 | POSTING_READ(reg); |
1738 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1739 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1740 | POSTING_READ(reg); |
1741 | udelay(150); /* wait for warmup */ | |
1742 | } | |
1743 | ||
1744 | /** | |
50b44a44 | 1745 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1746 | * @dev_priv: i915 private structure |
1747 | * @pipe: pipe PLL to disable | |
1748 | * | |
1749 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1750 | * | |
1751 | * Note! This is for pre-ILK only. | |
1752 | */ | |
1c4e0274 | 1753 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1754 | { |
1c4e0274 VS |
1755 | struct drm_device *dev = crtc->base.dev; |
1756 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1757 | enum pipe pipe = crtc->pipe; | |
1758 | ||
1759 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1760 | if (IS_I830(dev) && | |
409ee761 | 1761 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1762 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1763 | I915_WRITE(DPLL(PIPE_B), |
1764 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1765 | I915_WRITE(DPLL(PIPE_A), | |
1766 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1767 | } | |
1768 | ||
b6b5d049 VS |
1769 | /* Don't disable pipe or pipe PLLs if needed */ |
1770 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1771 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1772 | return; |
1773 | ||
1774 | /* Make sure the pipe isn't still relying on us */ | |
1775 | assert_pipe_disabled(dev_priv, pipe); | |
1776 | ||
b8afb911 | 1777 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1778 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1779 | } |
1780 | ||
f6071166 JB |
1781 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1782 | { | |
b8afb911 | 1783 | u32 val; |
f6071166 JB |
1784 | |
1785 | /* Make sure the pipe isn't still relying on us */ | |
1786 | assert_pipe_disabled(dev_priv, pipe); | |
1787 | ||
e5cbfbfb ID |
1788 | /* |
1789 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1790 | * The latter is needed for VGA hotplug / manual detection. | |
1791 | */ | |
b8afb911 | 1792 | val = DPLL_VGA_MODE_DIS; |
f6071166 | 1793 | if (pipe == PIPE_B) |
60bfe44f | 1794 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
f6071166 JB |
1795 | I915_WRITE(DPLL(pipe), val); |
1796 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1797 | |
1798 | } | |
1799 | ||
1800 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1801 | { | |
d752048d | 1802 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1803 | u32 val; |
1804 | ||
a11b0703 VS |
1805 | /* Make sure the pipe isn't still relying on us */ |
1806 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1807 | |
a11b0703 | 1808 | /* Set PLL en = 0 */ |
60bfe44f VS |
1809 | val = DPLL_SSC_REF_CLK_CHV | |
1810 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1811 | if (pipe != PIPE_A) |
1812 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1813 | I915_WRITE(DPLL(pipe), val); | |
1814 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1815 | |
a580516d | 1816 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1817 | |
1818 | /* Disable 10bit clock to display controller */ | |
1819 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1820 | val &= ~DPIO_DCLKP_EN; | |
1821 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1822 | ||
a580516d | 1823 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1824 | } |
1825 | ||
e4607fcf | 1826 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1827 | struct intel_digital_port *dport, |
1828 | unsigned int expected_mask) | |
89b667f8 JB |
1829 | { |
1830 | u32 port_mask; | |
00fc31b7 | 1831 | int dpll_reg; |
89b667f8 | 1832 | |
e4607fcf CML |
1833 | switch (dport->port) { |
1834 | case PORT_B: | |
89b667f8 | 1835 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1836 | dpll_reg = DPLL(0); |
e4607fcf CML |
1837 | break; |
1838 | case PORT_C: | |
89b667f8 | 1839 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1840 | dpll_reg = DPLL(0); |
9b6de0a1 | 1841 | expected_mask <<= 4; |
00fc31b7 CML |
1842 | break; |
1843 | case PORT_D: | |
1844 | port_mask = DPLL_PORTD_READY_MASK; | |
1845 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1846 | break; |
1847 | default: | |
1848 | BUG(); | |
1849 | } | |
89b667f8 | 1850 | |
9b6de0a1 VS |
1851 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1852 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1853 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1854 | } |
1855 | ||
b14b1055 DV |
1856 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1857 | { | |
1858 | struct drm_device *dev = crtc->base.dev; | |
1859 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1860 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1861 | ||
be19f0ff CW |
1862 | if (WARN_ON(pll == NULL)) |
1863 | return; | |
1864 | ||
3e369b76 | 1865 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1866 | if (pll->active == 0) { |
1867 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1868 | WARN_ON(pll->on); | |
1869 | assert_shared_dpll_disabled(dev_priv, pll); | |
1870 | ||
1871 | pll->mode_set(dev_priv, pll); | |
1872 | } | |
1873 | } | |
1874 | ||
92f2584a | 1875 | /** |
85b3894f | 1876 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1877 | * @dev_priv: i915 private structure |
1878 | * @pipe: pipe PLL to enable | |
1879 | * | |
1880 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1881 | * drives the transcoder clock. | |
1882 | */ | |
85b3894f | 1883 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1884 | { |
3d13ef2e DL |
1885 | struct drm_device *dev = crtc->base.dev; |
1886 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1887 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1888 | |
87a875bb | 1889 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1890 | return; |
1891 | ||
3e369b76 | 1892 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1893 | return; |
ee7b9f93 | 1894 | |
74dd6928 | 1895 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1896 | pll->name, pll->active, pll->on, |
e2b78267 | 1897 | crtc->base.base.id); |
92f2584a | 1898 | |
cdbd2316 DV |
1899 | if (pll->active++) { |
1900 | WARN_ON(!pll->on); | |
e9d6944e | 1901 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1902 | return; |
1903 | } | |
f4a091c7 | 1904 | WARN_ON(pll->on); |
ee7b9f93 | 1905 | |
bd2bb1b9 PZ |
1906 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1907 | ||
46edb027 | 1908 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1909 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1910 | pll->on = true; |
92f2584a JB |
1911 | } |
1912 | ||
f6daaec2 | 1913 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1914 | { |
3d13ef2e DL |
1915 | struct drm_device *dev = crtc->base.dev; |
1916 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1917 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1918 | |
92f2584a | 1919 | /* PCH only available on ILK+ */ |
80aa9312 JB |
1920 | if (INTEL_INFO(dev)->gen < 5) |
1921 | return; | |
1922 | ||
eddfcbcd ML |
1923 | if (pll == NULL) |
1924 | return; | |
92f2584a | 1925 | |
eddfcbcd | 1926 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) |
48da64a8 | 1927 | return; |
7a419866 | 1928 | |
46edb027 DV |
1929 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1930 | pll->name, pll->active, pll->on, | |
e2b78267 | 1931 | crtc->base.base.id); |
7a419866 | 1932 | |
48da64a8 | 1933 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1934 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1935 | return; |
1936 | } | |
1937 | ||
e9d6944e | 1938 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1939 | WARN_ON(!pll->on); |
cdbd2316 | 1940 | if (--pll->active) |
7a419866 | 1941 | return; |
ee7b9f93 | 1942 | |
46edb027 | 1943 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1944 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1945 | pll->on = false; |
bd2bb1b9 PZ |
1946 | |
1947 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1948 | } |
1949 | ||
b8a4f404 PZ |
1950 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1951 | enum pipe pipe) | |
040484af | 1952 | { |
23670b32 | 1953 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1954 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1955 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
23670b32 | 1956 | uint32_t reg, val, pipeconf_val; |
040484af JB |
1957 | |
1958 | /* PCH only available on ILK+ */ | |
55522f37 | 1959 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1960 | |
1961 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1962 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1963 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1964 | |
1965 | /* FDI must be feeding us bits for PCH ports */ | |
1966 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1967 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1968 | ||
23670b32 DV |
1969 | if (HAS_PCH_CPT(dev)) { |
1970 | /* Workaround: Set the timing override bit before enabling the | |
1971 | * pch transcoder. */ | |
1972 | reg = TRANS_CHICKEN2(pipe); | |
1973 | val = I915_READ(reg); | |
1974 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1975 | I915_WRITE(reg, val); | |
59c859d6 | 1976 | } |
23670b32 | 1977 | |
ab9412ba | 1978 | reg = PCH_TRANSCONF(pipe); |
040484af | 1979 | val = I915_READ(reg); |
5f7f726d | 1980 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
1981 | |
1982 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
1983 | /* | |
c5de7c6f VS |
1984 | * Make the BPC in transcoder be consistent with |
1985 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1986 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1987 | */ |
dfd07d72 | 1988 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
1989 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
1990 | val |= PIPECONF_8BPC; | |
1991 | else | |
1992 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 1993 | } |
5f7f726d PZ |
1994 | |
1995 | val &= ~TRANS_INTERLACE_MASK; | |
1996 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 1997 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 1998 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
1999 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2000 | else | |
2001 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2002 | else |
2003 | val |= TRANS_PROGRESSIVE; | |
2004 | ||
040484af JB |
2005 | I915_WRITE(reg, val | TRANS_ENABLE); |
2006 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2007 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2008 | } |
2009 | ||
8fb033d7 | 2010 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2011 | enum transcoder cpu_transcoder) |
040484af | 2012 | { |
8fb033d7 | 2013 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2014 | |
2015 | /* PCH only available on ILK+ */ | |
55522f37 | 2016 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2017 | |
8fb033d7 | 2018 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2019 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2020 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2021 | |
223a6fdf | 2022 | /* Workaround: set timing override bit. */ |
36c0d0cf | 2023 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2024 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2025 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
223a6fdf | 2026 | |
25f3ef11 | 2027 | val = TRANS_ENABLE; |
937bb610 | 2028 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2029 | |
9a76b1c6 PZ |
2030 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2031 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2032 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2033 | else |
2034 | val |= TRANS_PROGRESSIVE; | |
2035 | ||
ab9412ba DV |
2036 | I915_WRITE(LPT_TRANSCONF, val); |
2037 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2038 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2039 | } |
2040 | ||
b8a4f404 PZ |
2041 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2042 | enum pipe pipe) | |
040484af | 2043 | { |
23670b32 DV |
2044 | struct drm_device *dev = dev_priv->dev; |
2045 | uint32_t reg, val; | |
040484af JB |
2046 | |
2047 | /* FDI relies on the transcoder */ | |
2048 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2049 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2050 | ||
291906f1 JB |
2051 | /* Ports must be off as well */ |
2052 | assert_pch_ports_disabled(dev_priv, pipe); | |
2053 | ||
ab9412ba | 2054 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2055 | val = I915_READ(reg); |
2056 | val &= ~TRANS_ENABLE; | |
2057 | I915_WRITE(reg, val); | |
2058 | /* wait for PCH transcoder off, transcoder state */ | |
2059 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2060 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 DV |
2061 | |
2062 | if (!HAS_PCH_IBX(dev)) { | |
2063 | /* Workaround: Clear the timing override chicken bit again. */ | |
2064 | reg = TRANS_CHICKEN2(pipe); | |
2065 | val = I915_READ(reg); | |
2066 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2067 | I915_WRITE(reg, val); | |
2068 | } | |
040484af JB |
2069 | } |
2070 | ||
ab4d966c | 2071 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2072 | { |
8fb033d7 PZ |
2073 | u32 val; |
2074 | ||
ab9412ba | 2075 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2076 | val &= ~TRANS_ENABLE; |
ab9412ba | 2077 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2078 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2079 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2080 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2081 | |
2082 | /* Workaround: clear timing override bit. */ | |
36c0d0cf | 2083 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2084 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2085 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
040484af JB |
2086 | } |
2087 | ||
b24e7179 | 2088 | /** |
309cfea8 | 2089 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2090 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2091 | * |
0372264a | 2092 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2093 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2094 | */ |
e1fdc473 | 2095 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2096 | { |
0372264a PZ |
2097 | struct drm_device *dev = crtc->base.dev; |
2098 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2099 | enum pipe pipe = crtc->pipe; | |
1a70a728 | 2100 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
1a240d4d | 2101 | enum pipe pch_transcoder; |
b24e7179 JB |
2102 | int reg; |
2103 | u32 val; | |
2104 | ||
9e2ee2dd VS |
2105 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
2106 | ||
58c6eaa2 | 2107 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2108 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2109 | assert_sprites_disabled(dev_priv, pipe); |
2110 | ||
681e5811 | 2111 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2112 | pch_transcoder = TRANSCODER_A; |
2113 | else | |
2114 | pch_transcoder = pipe; | |
2115 | ||
b24e7179 JB |
2116 | /* |
2117 | * A pipe without a PLL won't actually be able to drive bits from | |
2118 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2119 | * need the check. | |
2120 | */ | |
50360403 | 2121 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
409ee761 | 2122 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
2123 | assert_dsi_pll_enabled(dev_priv); |
2124 | else | |
2125 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2126 | else { |
6e3c9717 | 2127 | if (crtc->config->has_pch_encoder) { |
040484af | 2128 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2129 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2130 | assert_fdi_tx_pll_enabled(dev_priv, |
2131 | (enum pipe) cpu_transcoder); | |
040484af JB |
2132 | } |
2133 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2134 | } | |
b24e7179 | 2135 | |
702e7a56 | 2136 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2137 | val = I915_READ(reg); |
7ad25d48 | 2138 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2139 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2140 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2141 | return; |
7ad25d48 | 2142 | } |
00d70b15 CW |
2143 | |
2144 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2145 | POSTING_READ(reg); |
b24e7179 JB |
2146 | } |
2147 | ||
2148 | /** | |
309cfea8 | 2149 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2150 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2151 | * |
575f7ab7 VS |
2152 | * Disable the pipe of @crtc, making sure that various hardware |
2153 | * specific requirements are met, if applicable, e.g. plane | |
2154 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2155 | * |
2156 | * Will wait until the pipe has shut down before returning. | |
2157 | */ | |
575f7ab7 | 2158 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2159 | { |
575f7ab7 | 2160 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2161 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2162 | enum pipe pipe = crtc->pipe; |
b24e7179 JB |
2163 | int reg; |
2164 | u32 val; | |
2165 | ||
9e2ee2dd VS |
2166 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
2167 | ||
b24e7179 JB |
2168 | /* |
2169 | * Make sure planes won't keep trying to pump pixels to us, | |
2170 | * or we might hang the display. | |
2171 | */ | |
2172 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2173 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2174 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2175 | |
702e7a56 | 2176 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2177 | val = I915_READ(reg); |
00d70b15 CW |
2178 | if ((val & PIPECONF_ENABLE) == 0) |
2179 | return; | |
2180 | ||
67adc644 VS |
2181 | /* |
2182 | * Double wide has implications for planes | |
2183 | * so best keep it disabled when not needed. | |
2184 | */ | |
6e3c9717 | 2185 | if (crtc->config->double_wide) |
67adc644 VS |
2186 | val &= ~PIPECONF_DOUBLE_WIDE; |
2187 | ||
2188 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2189 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2190 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2191 | val &= ~PIPECONF_ENABLE; |
2192 | ||
2193 | I915_WRITE(reg, val); | |
2194 | if ((val & PIPECONF_ENABLE) == 0) | |
2195 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2196 | } |
2197 | ||
693db184 CW |
2198 | static bool need_vtd_wa(struct drm_device *dev) |
2199 | { | |
2200 | #ifdef CONFIG_INTEL_IOMMU | |
2201 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2202 | return true; | |
2203 | #endif | |
2204 | return false; | |
2205 | } | |
2206 | ||
50470bb0 | 2207 | unsigned int |
6761dd31 | 2208 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
fe47ea0c | 2209 | uint64_t fb_format_modifier, unsigned int plane) |
a57ce0b2 | 2210 | { |
6761dd31 TU |
2211 | unsigned int tile_height; |
2212 | uint32_t pixel_bytes; | |
a57ce0b2 | 2213 | |
b5d0e9bf DL |
2214 | switch (fb_format_modifier) { |
2215 | case DRM_FORMAT_MOD_NONE: | |
2216 | tile_height = 1; | |
2217 | break; | |
2218 | case I915_FORMAT_MOD_X_TILED: | |
2219 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2220 | break; | |
2221 | case I915_FORMAT_MOD_Y_TILED: | |
2222 | tile_height = 32; | |
2223 | break; | |
2224 | case I915_FORMAT_MOD_Yf_TILED: | |
fe47ea0c | 2225 | pixel_bytes = drm_format_plane_cpp(pixel_format, plane); |
6761dd31 | 2226 | switch (pixel_bytes) { |
b5d0e9bf | 2227 | default: |
6761dd31 | 2228 | case 1: |
b5d0e9bf DL |
2229 | tile_height = 64; |
2230 | break; | |
6761dd31 TU |
2231 | case 2: |
2232 | case 4: | |
b5d0e9bf DL |
2233 | tile_height = 32; |
2234 | break; | |
6761dd31 | 2235 | case 8: |
b5d0e9bf DL |
2236 | tile_height = 16; |
2237 | break; | |
6761dd31 | 2238 | case 16: |
b5d0e9bf DL |
2239 | WARN_ONCE(1, |
2240 | "128-bit pixels are not supported for display!"); | |
2241 | tile_height = 16; | |
2242 | break; | |
2243 | } | |
2244 | break; | |
2245 | default: | |
2246 | MISSING_CASE(fb_format_modifier); | |
2247 | tile_height = 1; | |
2248 | break; | |
2249 | } | |
091df6cb | 2250 | |
6761dd31 TU |
2251 | return tile_height; |
2252 | } | |
2253 | ||
2254 | unsigned int | |
2255 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2256 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2257 | { | |
2258 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
fe47ea0c | 2259 | fb_format_modifier, 0)); |
a57ce0b2 JB |
2260 | } |
2261 | ||
f64b98cd TU |
2262 | static int |
2263 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, | |
2264 | const struct drm_plane_state *plane_state) | |
2265 | { | |
50470bb0 | 2266 | struct intel_rotation_info *info = &view->rotation_info; |
84fe03f7 | 2267 | unsigned int tile_height, tile_pitch; |
50470bb0 | 2268 | |
f64b98cd TU |
2269 | *view = i915_ggtt_view_normal; |
2270 | ||
50470bb0 TU |
2271 | if (!plane_state) |
2272 | return 0; | |
2273 | ||
121920fa | 2274 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
50470bb0 TU |
2275 | return 0; |
2276 | ||
9abc4648 | 2277 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2278 | |
2279 | info->height = fb->height; | |
2280 | info->pixel_format = fb->pixel_format; | |
2281 | info->pitch = fb->pitches[0]; | |
89e3e142 | 2282 | info->uv_offset = fb->offsets[1]; |
50470bb0 TU |
2283 | info->fb_modifier = fb->modifier[0]; |
2284 | ||
84fe03f7 | 2285 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, |
fe47ea0c | 2286 | fb->modifier[0], 0); |
84fe03f7 TU |
2287 | tile_pitch = PAGE_SIZE / tile_height; |
2288 | info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2289 | info->height_pages = DIV_ROUND_UP(fb->height, tile_height); | |
2290 | info->size = info->width_pages * info->height_pages * PAGE_SIZE; | |
2291 | ||
89e3e142 TU |
2292 | if (info->pixel_format == DRM_FORMAT_NV12) { |
2293 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, | |
2294 | fb->modifier[0], 1); | |
2295 | tile_pitch = PAGE_SIZE / tile_height; | |
2296 | info->width_pages_uv = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2297 | info->height_pages_uv = DIV_ROUND_UP(fb->height / 2, | |
2298 | tile_height); | |
2299 | info->size_uv = info->width_pages_uv * info->height_pages_uv * | |
2300 | PAGE_SIZE; | |
2301 | } | |
2302 | ||
f64b98cd TU |
2303 | return 0; |
2304 | } | |
2305 | ||
4e9a86b6 VS |
2306 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
2307 | { | |
2308 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2309 | return 256 * 1024; | |
985b8bb4 VS |
2310 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
2311 | IS_VALLEYVIEW(dev_priv)) | |
4e9a86b6 VS |
2312 | return 128 * 1024; |
2313 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2314 | return 4 * 1024; | |
2315 | else | |
44c5905e | 2316 | return 0; |
4e9a86b6 VS |
2317 | } |
2318 | ||
127bd2ac | 2319 | int |
850c4cdc TU |
2320 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2321 | struct drm_framebuffer *fb, | |
7580d774 | 2322 | const struct drm_plane_state *plane_state) |
6b95a207 | 2323 | { |
850c4cdc | 2324 | struct drm_device *dev = fb->dev; |
ce453d81 | 2325 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2326 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2327 | struct i915_ggtt_view view; |
6b95a207 KH |
2328 | u32 alignment; |
2329 | int ret; | |
2330 | ||
ebcdd39e MR |
2331 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2332 | ||
7b911adc TU |
2333 | switch (fb->modifier[0]) { |
2334 | case DRM_FORMAT_MOD_NONE: | |
4e9a86b6 | 2335 | alignment = intel_linear_alignment(dev_priv); |
6b95a207 | 2336 | break; |
7b911adc | 2337 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2338 | if (INTEL_INFO(dev)->gen >= 9) |
2339 | alignment = 256 * 1024; | |
2340 | else { | |
2341 | /* pin() will align the object as required by fence */ | |
2342 | alignment = 0; | |
2343 | } | |
6b95a207 | 2344 | break; |
7b911adc | 2345 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2346 | case I915_FORMAT_MOD_Yf_TILED: |
2347 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2348 | "Y tiling bo slipped through, driver bug!\n")) | |
2349 | return -EINVAL; | |
2350 | alignment = 1 * 1024 * 1024; | |
2351 | break; | |
6b95a207 | 2352 | default: |
7b911adc TU |
2353 | MISSING_CASE(fb->modifier[0]); |
2354 | return -EINVAL; | |
6b95a207 KH |
2355 | } |
2356 | ||
f64b98cd TU |
2357 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2358 | if (ret) | |
2359 | return ret; | |
2360 | ||
693db184 CW |
2361 | /* Note that the w/a also requires 64 PTE of padding following the |
2362 | * bo. We currently fill all unused PTE with the shadow page and so | |
2363 | * we should always have valid PTE following the scanout preventing | |
2364 | * the VT-d warning. | |
2365 | */ | |
2366 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2367 | alignment = 256 * 1024; | |
2368 | ||
d6dd6843 PZ |
2369 | /* |
2370 | * Global gtt pte registers are special registers which actually forward | |
2371 | * writes to a chunk of system memory. Which means that there is no risk | |
2372 | * that the register values disappear as soon as we call | |
2373 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2374 | * pin/unpin/fence and not more. | |
2375 | */ | |
2376 | intel_runtime_pm_get(dev_priv); | |
2377 | ||
7580d774 ML |
2378 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
2379 | &view); | |
48b956c5 | 2380 | if (ret) |
b26a6b35 | 2381 | goto err_pm; |
6b95a207 KH |
2382 | |
2383 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2384 | * fence, whereas 965+ only requires a fence if using | |
2385 | * framebuffer compression. For simplicity, we always install | |
2386 | * a fence as the cost is not that onerous. | |
2387 | */ | |
06d98131 | 2388 | ret = i915_gem_object_get_fence(obj); |
842315ee ML |
2389 | if (ret == -EDEADLK) { |
2390 | /* | |
2391 | * -EDEADLK means there are no free fences | |
2392 | * no pending flips. | |
2393 | * | |
2394 | * This is propagated to atomic, but it uses | |
2395 | * -EDEADLK to force a locking recovery, so | |
2396 | * change the returned error to -EBUSY. | |
2397 | */ | |
2398 | ret = -EBUSY; | |
2399 | goto err_unpin; | |
2400 | } else if (ret) | |
9a5a53b3 | 2401 | goto err_unpin; |
1690e1eb | 2402 | |
9a5a53b3 | 2403 | i915_gem_object_pin_fence(obj); |
6b95a207 | 2404 | |
d6dd6843 | 2405 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2406 | return 0; |
48b956c5 CW |
2407 | |
2408 | err_unpin: | |
f64b98cd | 2409 | i915_gem_object_unpin_from_display_plane(obj, &view); |
b26a6b35 | 2410 | err_pm: |
d6dd6843 | 2411 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2412 | return ret; |
6b95a207 KH |
2413 | } |
2414 | ||
82bc3b2d TU |
2415 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2416 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2417 | { |
82bc3b2d | 2418 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd TU |
2419 | struct i915_ggtt_view view; |
2420 | int ret; | |
82bc3b2d | 2421 | |
ebcdd39e MR |
2422 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2423 | ||
f64b98cd TU |
2424 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2425 | WARN_ONCE(ret, "Couldn't get view from plane state!"); | |
2426 | ||
1690e1eb | 2427 | i915_gem_object_unpin_fence(obj); |
f64b98cd | 2428 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2429 | } |
2430 | ||
c2c75131 DV |
2431 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2432 | * is assumed to be a power-of-two. */ | |
4e9a86b6 VS |
2433 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
2434 | int *x, int *y, | |
bc752862 CW |
2435 | unsigned int tiling_mode, |
2436 | unsigned int cpp, | |
2437 | unsigned int pitch) | |
c2c75131 | 2438 | { |
bc752862 CW |
2439 | if (tiling_mode != I915_TILING_NONE) { |
2440 | unsigned int tile_rows, tiles; | |
c2c75131 | 2441 | |
bc752862 CW |
2442 | tile_rows = *y / 8; |
2443 | *y %= 8; | |
c2c75131 | 2444 | |
bc752862 CW |
2445 | tiles = *x / (512/cpp); |
2446 | *x %= 512/cpp; | |
2447 | ||
2448 | return tile_rows * pitch * 8 + tiles * 4096; | |
2449 | } else { | |
4e9a86b6 | 2450 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
bc752862 CW |
2451 | unsigned int offset; |
2452 | ||
2453 | offset = *y * pitch + *x * cpp; | |
4e9a86b6 VS |
2454 | *y = (offset & alignment) / pitch; |
2455 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2456 | return offset & ~alignment; | |
bc752862 | 2457 | } |
c2c75131 DV |
2458 | } |
2459 | ||
b35d63fa | 2460 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2461 | { |
2462 | switch (format) { | |
2463 | case DISPPLANE_8BPP: | |
2464 | return DRM_FORMAT_C8; | |
2465 | case DISPPLANE_BGRX555: | |
2466 | return DRM_FORMAT_XRGB1555; | |
2467 | case DISPPLANE_BGRX565: | |
2468 | return DRM_FORMAT_RGB565; | |
2469 | default: | |
2470 | case DISPPLANE_BGRX888: | |
2471 | return DRM_FORMAT_XRGB8888; | |
2472 | case DISPPLANE_RGBX888: | |
2473 | return DRM_FORMAT_XBGR8888; | |
2474 | case DISPPLANE_BGRX101010: | |
2475 | return DRM_FORMAT_XRGB2101010; | |
2476 | case DISPPLANE_RGBX101010: | |
2477 | return DRM_FORMAT_XBGR2101010; | |
2478 | } | |
2479 | } | |
2480 | ||
bc8d7dff DL |
2481 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2482 | { | |
2483 | switch (format) { | |
2484 | case PLANE_CTL_FORMAT_RGB_565: | |
2485 | return DRM_FORMAT_RGB565; | |
2486 | default: | |
2487 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2488 | if (rgb_order) { | |
2489 | if (alpha) | |
2490 | return DRM_FORMAT_ABGR8888; | |
2491 | else | |
2492 | return DRM_FORMAT_XBGR8888; | |
2493 | } else { | |
2494 | if (alpha) | |
2495 | return DRM_FORMAT_ARGB8888; | |
2496 | else | |
2497 | return DRM_FORMAT_XRGB8888; | |
2498 | } | |
2499 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2500 | if (rgb_order) | |
2501 | return DRM_FORMAT_XBGR2101010; | |
2502 | else | |
2503 | return DRM_FORMAT_XRGB2101010; | |
2504 | } | |
2505 | } | |
2506 | ||
5724dbd1 | 2507 | static bool |
f6936e29 DV |
2508 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2509 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2510 | { |
2511 | struct drm_device *dev = crtc->base.dev; | |
3badb49f | 2512 | struct drm_i915_private *dev_priv = to_i915(dev); |
46f297fb JB |
2513 | struct drm_i915_gem_object *obj = NULL; |
2514 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2515 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2516 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2517 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2518 | PAGE_SIZE); | |
2519 | ||
2520 | size_aligned -= base_aligned; | |
46f297fb | 2521 | |
ff2652ea CW |
2522 | if (plane_config->size == 0) |
2523 | return false; | |
2524 | ||
3badb49f PZ |
2525 | /* If the FB is too big, just don't use it since fbdev is not very |
2526 | * important and we should probably use that space with FBC or other | |
2527 | * features. */ | |
2528 | if (size_aligned * 2 > dev_priv->gtt.stolen_usable_size) | |
2529 | return false; | |
2530 | ||
f37b5c2b DV |
2531 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2532 | base_aligned, | |
2533 | base_aligned, | |
2534 | size_aligned); | |
46f297fb | 2535 | if (!obj) |
484b41dd | 2536 | return false; |
46f297fb | 2537 | |
49af449b DL |
2538 | obj->tiling_mode = plane_config->tiling; |
2539 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2540 | obj->stride = fb->pitches[0]; |
46f297fb | 2541 | |
6bf129df DL |
2542 | mode_cmd.pixel_format = fb->pixel_format; |
2543 | mode_cmd.width = fb->width; | |
2544 | mode_cmd.height = fb->height; | |
2545 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2546 | mode_cmd.modifier[0] = fb->modifier[0]; |
2547 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2548 | |
2549 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2550 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2551 | &mode_cmd, obj)) { |
46f297fb JB |
2552 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2553 | goto out_unref_obj; | |
2554 | } | |
46f297fb | 2555 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2556 | |
f6936e29 | 2557 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2558 | return true; |
46f297fb JB |
2559 | |
2560 | out_unref_obj: | |
2561 | drm_gem_object_unreference(&obj->base); | |
2562 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2563 | return false; |
2564 | } | |
2565 | ||
afd65eb4 MR |
2566 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2567 | static void | |
2568 | update_state_fb(struct drm_plane *plane) | |
2569 | { | |
2570 | if (plane->fb == plane->state->fb) | |
2571 | return; | |
2572 | ||
2573 | if (plane->state->fb) | |
2574 | drm_framebuffer_unreference(plane->state->fb); | |
2575 | plane->state->fb = plane->fb; | |
2576 | if (plane->state->fb) | |
2577 | drm_framebuffer_reference(plane->state->fb); | |
2578 | } | |
2579 | ||
5724dbd1 | 2580 | static void |
f6936e29 DV |
2581 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2582 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2583 | { |
2584 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2585 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2586 | struct drm_crtc *c; |
2587 | struct intel_crtc *i; | |
2ff8fde1 | 2588 | struct drm_i915_gem_object *obj; |
88595ac9 | 2589 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2590 | struct drm_plane_state *plane_state = primary->state; |
88595ac9 | 2591 | struct drm_framebuffer *fb; |
484b41dd | 2592 | |
2d14030b | 2593 | if (!plane_config->fb) |
484b41dd JB |
2594 | return; |
2595 | ||
f6936e29 | 2596 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2597 | fb = &plane_config->fb->base; |
2598 | goto valid_fb; | |
f55548b5 | 2599 | } |
484b41dd | 2600 | |
2d14030b | 2601 | kfree(plane_config->fb); |
484b41dd JB |
2602 | |
2603 | /* | |
2604 | * Failed to alloc the obj, check to see if we should share | |
2605 | * an fb with another CRTC instead | |
2606 | */ | |
70e1e0ec | 2607 | for_each_crtc(dev, c) { |
484b41dd JB |
2608 | i = to_intel_crtc(c); |
2609 | ||
2610 | if (c == &intel_crtc->base) | |
2611 | continue; | |
2612 | ||
2ff8fde1 MR |
2613 | if (!i->active) |
2614 | continue; | |
2615 | ||
88595ac9 DV |
2616 | fb = c->primary->fb; |
2617 | if (!fb) | |
484b41dd JB |
2618 | continue; |
2619 | ||
88595ac9 | 2620 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2621 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2622 | drm_framebuffer_reference(fb); |
2623 | goto valid_fb; | |
484b41dd JB |
2624 | } |
2625 | } | |
88595ac9 DV |
2626 | |
2627 | return; | |
2628 | ||
2629 | valid_fb: | |
be5651f2 ML |
2630 | plane_state->src_x = plane_state->src_y = 0; |
2631 | plane_state->src_w = fb->width << 16; | |
2632 | plane_state->src_h = fb->height << 16; | |
2633 | ||
2634 | plane_state->crtc_x = plane_state->src_y = 0; | |
2635 | plane_state->crtc_w = fb->width; | |
2636 | plane_state->crtc_h = fb->height; | |
2637 | ||
88595ac9 DV |
2638 | obj = intel_fb_obj(fb); |
2639 | if (obj->tiling_mode != I915_TILING_NONE) | |
2640 | dev_priv->preserve_bios_swizzle = true; | |
2641 | ||
be5651f2 ML |
2642 | drm_framebuffer_reference(fb); |
2643 | primary->fb = primary->state->fb = fb; | |
36750f28 | 2644 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
36750f28 | 2645 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
a9ff8714 | 2646 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
46f297fb JB |
2647 | } |
2648 | ||
29b9bde6 DV |
2649 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2650 | struct drm_framebuffer *fb, | |
2651 | int x, int y) | |
81255565 JB |
2652 | { |
2653 | struct drm_device *dev = crtc->dev; | |
2654 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2655 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2656 | struct drm_plane *primary = crtc->primary; |
2657 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2658 | struct drm_i915_gem_object *obj; |
81255565 | 2659 | int plane = intel_crtc->plane; |
e506a0c6 | 2660 | unsigned long linear_offset; |
81255565 | 2661 | u32 dspcntr; |
f45651ba | 2662 | u32 reg = DSPCNTR(plane); |
48404c1e | 2663 | int pixel_size; |
f45651ba | 2664 | |
b70709a6 | 2665 | if (!visible || !fb) { |
fdd508a6 VS |
2666 | I915_WRITE(reg, 0); |
2667 | if (INTEL_INFO(dev)->gen >= 4) | |
2668 | I915_WRITE(DSPSURF(plane), 0); | |
2669 | else | |
2670 | I915_WRITE(DSPADDR(plane), 0); | |
2671 | POSTING_READ(reg); | |
2672 | return; | |
2673 | } | |
2674 | ||
c9ba6fad VS |
2675 | obj = intel_fb_obj(fb); |
2676 | if (WARN_ON(obj == NULL)) | |
2677 | return; | |
2678 | ||
2679 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2680 | ||
f45651ba VS |
2681 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2682 | ||
fdd508a6 | 2683 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2684 | |
2685 | if (INTEL_INFO(dev)->gen < 4) { | |
2686 | if (intel_crtc->pipe == PIPE_B) | |
2687 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2688 | ||
2689 | /* pipesrc and dspsize control the size that is scaled from, | |
2690 | * which should always be the user's requested size. | |
2691 | */ | |
2692 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2693 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2694 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2695 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2696 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2697 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2698 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2699 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2700 | I915_WRITE(PRIMPOS(plane), 0); |
2701 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2702 | } |
81255565 | 2703 | |
57779d06 VS |
2704 | switch (fb->pixel_format) { |
2705 | case DRM_FORMAT_C8: | |
81255565 JB |
2706 | dspcntr |= DISPPLANE_8BPP; |
2707 | break; | |
57779d06 | 2708 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2709 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2710 | break; |
57779d06 VS |
2711 | case DRM_FORMAT_RGB565: |
2712 | dspcntr |= DISPPLANE_BGRX565; | |
2713 | break; | |
2714 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2715 | dspcntr |= DISPPLANE_BGRX888; |
2716 | break; | |
2717 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2718 | dspcntr |= DISPPLANE_RGBX888; |
2719 | break; | |
2720 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2721 | dspcntr |= DISPPLANE_BGRX101010; |
2722 | break; | |
2723 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2724 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2725 | break; |
2726 | default: | |
baba133a | 2727 | BUG(); |
81255565 | 2728 | } |
57779d06 | 2729 | |
f45651ba VS |
2730 | if (INTEL_INFO(dev)->gen >= 4 && |
2731 | obj->tiling_mode != I915_TILING_NONE) | |
2732 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2733 | |
de1aa629 VS |
2734 | if (IS_G4X(dev)) |
2735 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2736 | ||
b9897127 | 2737 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2738 | |
c2c75131 DV |
2739 | if (INTEL_INFO(dev)->gen >= 4) { |
2740 | intel_crtc->dspaddr_offset = | |
4e9a86b6 VS |
2741 | intel_gen4_compute_page_offset(dev_priv, |
2742 | &x, &y, obj->tiling_mode, | |
b9897127 | 2743 | pixel_size, |
bc752862 | 2744 | fb->pitches[0]); |
c2c75131 DV |
2745 | linear_offset -= intel_crtc->dspaddr_offset; |
2746 | } else { | |
e506a0c6 | 2747 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2748 | } |
e506a0c6 | 2749 | |
8e7d688b | 2750 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2751 | dspcntr |= DISPPLANE_ROTATE_180; |
2752 | ||
6e3c9717 ACO |
2753 | x += (intel_crtc->config->pipe_src_w - 1); |
2754 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2755 | |
2756 | /* Finding the last pixel of the last line of the display | |
2757 | data and adding to linear_offset*/ | |
2758 | linear_offset += | |
6e3c9717 ACO |
2759 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2760 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2761 | } |
2762 | ||
2db3366b PZ |
2763 | intel_crtc->adjusted_x = x; |
2764 | intel_crtc->adjusted_y = y; | |
2765 | ||
48404c1e SJ |
2766 | I915_WRITE(reg, dspcntr); |
2767 | ||
01f2c773 | 2768 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2769 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2770 | I915_WRITE(DSPSURF(plane), |
2771 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2772 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2773 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2774 | } else |
f343c5f6 | 2775 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2776 | POSTING_READ(reg); |
17638cd6 JB |
2777 | } |
2778 | ||
29b9bde6 DV |
2779 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2780 | struct drm_framebuffer *fb, | |
2781 | int x, int y) | |
17638cd6 JB |
2782 | { |
2783 | struct drm_device *dev = crtc->dev; | |
2784 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2785 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2786 | struct drm_plane *primary = crtc->primary; |
2787 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2788 | struct drm_i915_gem_object *obj; |
17638cd6 | 2789 | int plane = intel_crtc->plane; |
e506a0c6 | 2790 | unsigned long linear_offset; |
17638cd6 | 2791 | u32 dspcntr; |
f45651ba | 2792 | u32 reg = DSPCNTR(plane); |
48404c1e | 2793 | int pixel_size; |
f45651ba | 2794 | |
b70709a6 | 2795 | if (!visible || !fb) { |
fdd508a6 VS |
2796 | I915_WRITE(reg, 0); |
2797 | I915_WRITE(DSPSURF(plane), 0); | |
2798 | POSTING_READ(reg); | |
2799 | return; | |
2800 | } | |
2801 | ||
c9ba6fad VS |
2802 | obj = intel_fb_obj(fb); |
2803 | if (WARN_ON(obj == NULL)) | |
2804 | return; | |
2805 | ||
2806 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2807 | ||
f45651ba VS |
2808 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2809 | ||
fdd508a6 | 2810 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2811 | |
2812 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2813 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2814 | |
57779d06 VS |
2815 | switch (fb->pixel_format) { |
2816 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2817 | dspcntr |= DISPPLANE_8BPP; |
2818 | break; | |
57779d06 VS |
2819 | case DRM_FORMAT_RGB565: |
2820 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2821 | break; |
57779d06 | 2822 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2823 | dspcntr |= DISPPLANE_BGRX888; |
2824 | break; | |
2825 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2826 | dspcntr |= DISPPLANE_RGBX888; |
2827 | break; | |
2828 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2829 | dspcntr |= DISPPLANE_BGRX101010; |
2830 | break; | |
2831 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2832 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2833 | break; |
2834 | default: | |
baba133a | 2835 | BUG(); |
17638cd6 JB |
2836 | } |
2837 | ||
2838 | if (obj->tiling_mode != I915_TILING_NONE) | |
2839 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2840 | |
f45651ba | 2841 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2842 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2843 | |
b9897127 | 2844 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2845 | intel_crtc->dspaddr_offset = |
4e9a86b6 VS |
2846 | intel_gen4_compute_page_offset(dev_priv, |
2847 | &x, &y, obj->tiling_mode, | |
b9897127 | 2848 | pixel_size, |
bc752862 | 2849 | fb->pitches[0]); |
c2c75131 | 2850 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2851 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2852 | dspcntr |= DISPPLANE_ROTATE_180; |
2853 | ||
2854 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2855 | x += (intel_crtc->config->pipe_src_w - 1); |
2856 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2857 | |
2858 | /* Finding the last pixel of the last line of the display | |
2859 | data and adding to linear_offset*/ | |
2860 | linear_offset += | |
6e3c9717 ACO |
2861 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2862 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2863 | } |
2864 | } | |
2865 | ||
2db3366b PZ |
2866 | intel_crtc->adjusted_x = x; |
2867 | intel_crtc->adjusted_y = y; | |
2868 | ||
48404c1e | 2869 | I915_WRITE(reg, dspcntr); |
17638cd6 | 2870 | |
01f2c773 | 2871 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2872 | I915_WRITE(DSPSURF(plane), |
2873 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2874 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2875 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2876 | } else { | |
2877 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2878 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2879 | } | |
17638cd6 | 2880 | POSTING_READ(reg); |
17638cd6 JB |
2881 | } |
2882 | ||
b321803d DL |
2883 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2884 | uint32_t pixel_format) | |
2885 | { | |
2886 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2887 | ||
2888 | /* | |
2889 | * The stride is either expressed as a multiple of 64 bytes | |
2890 | * chunks for linear buffers or in number of tiles for tiled | |
2891 | * buffers. | |
2892 | */ | |
2893 | switch (fb_modifier) { | |
2894 | case DRM_FORMAT_MOD_NONE: | |
2895 | return 64; | |
2896 | case I915_FORMAT_MOD_X_TILED: | |
2897 | if (INTEL_INFO(dev)->gen == 2) | |
2898 | return 128; | |
2899 | return 512; | |
2900 | case I915_FORMAT_MOD_Y_TILED: | |
2901 | /* No need to check for old gens and Y tiling since this is | |
2902 | * about the display engine and those will be blocked before | |
2903 | * we get here. | |
2904 | */ | |
2905 | return 128; | |
2906 | case I915_FORMAT_MOD_Yf_TILED: | |
2907 | if (bits_per_pixel == 8) | |
2908 | return 64; | |
2909 | else | |
2910 | return 128; | |
2911 | default: | |
2912 | MISSING_CASE(fb_modifier); | |
2913 | return 64; | |
2914 | } | |
2915 | } | |
2916 | ||
44eb0cb9 MK |
2917 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
2918 | struct drm_i915_gem_object *obj, | |
2919 | unsigned int plane) | |
121920fa | 2920 | { |
9abc4648 | 2921 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
dedf278c | 2922 | struct i915_vma *vma; |
44eb0cb9 | 2923 | u64 offset; |
121920fa TU |
2924 | |
2925 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) | |
9abc4648 | 2926 | view = &i915_ggtt_view_rotated; |
121920fa | 2927 | |
dedf278c TU |
2928 | vma = i915_gem_obj_to_ggtt_view(obj, view); |
2929 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", | |
2930 | view->type)) | |
2931 | return -1; | |
2932 | ||
44eb0cb9 | 2933 | offset = vma->node.start; |
dedf278c TU |
2934 | |
2935 | if (plane == 1) { | |
2936 | offset += vma->ggtt_view.rotation_info.uv_start_page * | |
2937 | PAGE_SIZE; | |
2938 | } | |
2939 | ||
44eb0cb9 MK |
2940 | WARN_ON(upper_32_bits(offset)); |
2941 | ||
2942 | return lower_32_bits(offset); | |
121920fa TU |
2943 | } |
2944 | ||
e435d6e5 ML |
2945 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
2946 | { | |
2947 | struct drm_device *dev = intel_crtc->base.dev; | |
2948 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2949 | ||
2950 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
2951 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
2952 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
2953 | } |
2954 | ||
a1b2278e CK |
2955 | /* |
2956 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2957 | */ | |
0583236e | 2958 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 2959 | { |
a1b2278e CK |
2960 | struct intel_crtc_scaler_state *scaler_state; |
2961 | int i; | |
2962 | ||
a1b2278e CK |
2963 | scaler_state = &intel_crtc->config->scaler_state; |
2964 | ||
2965 | /* loop through and disable scalers that aren't in use */ | |
2966 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
2967 | if (!scaler_state->scalers[i].in_use) |
2968 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
2969 | } |
2970 | } | |
2971 | ||
6156a456 | 2972 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2973 | { |
6156a456 | 2974 | switch (pixel_format) { |
d161cf7a | 2975 | case DRM_FORMAT_C8: |
c34ce3d1 | 2976 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2977 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2978 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2979 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2980 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2981 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2982 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2983 | /* |
2984 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2985 | * to be already pre-multiplied. We need to add a knob (or a different | |
2986 | * DRM_FORMAT) for user-space to configure that. | |
2987 | */ | |
f75fb42a | 2988 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 2989 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 2990 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 2991 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 2992 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 2993 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 2994 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 2995 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 2996 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 2997 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 2998 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 2999 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 3000 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 3001 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 3002 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 3003 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 3004 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 3005 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 3006 | default: |
4249eeef | 3007 | MISSING_CASE(pixel_format); |
70d21f0e | 3008 | } |
8cfcba41 | 3009 | |
c34ce3d1 | 3010 | return 0; |
6156a456 | 3011 | } |
70d21f0e | 3012 | |
6156a456 CK |
3013 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
3014 | { | |
6156a456 | 3015 | switch (fb_modifier) { |
30af77c4 | 3016 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 3017 | break; |
30af77c4 | 3018 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 3019 | return PLANE_CTL_TILED_X; |
b321803d | 3020 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 3021 | return PLANE_CTL_TILED_Y; |
b321803d | 3022 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3023 | return PLANE_CTL_TILED_YF; |
70d21f0e | 3024 | default: |
6156a456 | 3025 | MISSING_CASE(fb_modifier); |
70d21f0e | 3026 | } |
8cfcba41 | 3027 | |
c34ce3d1 | 3028 | return 0; |
6156a456 | 3029 | } |
70d21f0e | 3030 | |
6156a456 CK |
3031 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
3032 | { | |
3b7a5119 | 3033 | switch (rotation) { |
6156a456 CK |
3034 | case BIT(DRM_ROTATE_0): |
3035 | break; | |
1e8df167 SJ |
3036 | /* |
3037 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3038 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3039 | */ | |
3b7a5119 | 3040 | case BIT(DRM_ROTATE_90): |
1e8df167 | 3041 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 3042 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3043 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3044 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3045 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3046 | default: |
3047 | MISSING_CASE(rotation); | |
3048 | } | |
3049 | ||
c34ce3d1 | 3050 | return 0; |
6156a456 CK |
3051 | } |
3052 | ||
3053 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
3054 | struct drm_framebuffer *fb, | |
3055 | int x, int y) | |
3056 | { | |
3057 | struct drm_device *dev = crtc->dev; | |
3058 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3059 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3060 | struct drm_plane *plane = crtc->primary; |
3061 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3062 | struct drm_i915_gem_object *obj; |
3063 | int pipe = intel_crtc->pipe; | |
3064 | u32 plane_ctl, stride_div, stride; | |
3065 | u32 tile_height, plane_offset, plane_size; | |
3066 | unsigned int rotation; | |
3067 | int x_offset, y_offset; | |
44eb0cb9 | 3068 | u32 surf_addr; |
6156a456 CK |
3069 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3070 | struct intel_plane_state *plane_state; | |
3071 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3072 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3073 | int scaler_id = -1; | |
3074 | ||
6156a456 CK |
3075 | plane_state = to_intel_plane_state(plane->state); |
3076 | ||
b70709a6 | 3077 | if (!visible || !fb) { |
6156a456 CK |
3078 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3079 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3080 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3081 | return; | |
3b7a5119 | 3082 | } |
70d21f0e | 3083 | |
6156a456 CK |
3084 | plane_ctl = PLANE_CTL_ENABLE | |
3085 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3086 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3087 | ||
3088 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3089 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3090 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3091 | ||
3092 | rotation = plane->state->rotation; | |
3093 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3094 | ||
b321803d DL |
3095 | obj = intel_fb_obj(fb); |
3096 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3097 | fb->pixel_format); | |
dedf278c | 3098 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
3b7a5119 | 3099 | |
a42e5a23 PZ |
3100 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
3101 | ||
3102 | scaler_id = plane_state->scaler_id; | |
3103 | src_x = plane_state->src.x1 >> 16; | |
3104 | src_y = plane_state->src.y1 >> 16; | |
3105 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3106 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3107 | dst_x = plane_state->dst.x1; | |
3108 | dst_y = plane_state->dst.y1; | |
3109 | dst_w = drm_rect_width(&plane_state->dst); | |
3110 | dst_h = drm_rect_height(&plane_state->dst); | |
3111 | ||
3112 | WARN_ON(x != src_x || y != src_y); | |
6156a456 | 3113 | |
3b7a5119 SJ |
3114 | if (intel_rotation_90_or_270(rotation)) { |
3115 | /* stride = Surface height in tiles */ | |
2614f17d | 3116 | tile_height = intel_tile_height(dev, fb->pixel_format, |
fe47ea0c | 3117 | fb->modifier[0], 0); |
3b7a5119 | 3118 | stride = DIV_ROUND_UP(fb->height, tile_height); |
6156a456 | 3119 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3120 | y_offset = x; |
6156a456 | 3121 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3122 | } else { |
3123 | stride = fb->pitches[0] / stride_div; | |
3124 | x_offset = x; | |
3125 | y_offset = y; | |
6156a456 | 3126 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3127 | } |
3128 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3129 | |
2db3366b PZ |
3130 | intel_crtc->adjusted_x = x_offset; |
3131 | intel_crtc->adjusted_y = y_offset; | |
3132 | ||
70d21f0e | 3133 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3134 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3135 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3136 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3137 | |
3138 | if (scaler_id >= 0) { | |
3139 | uint32_t ps_ctrl = 0; | |
3140 | ||
3141 | WARN_ON(!dst_w || !dst_h); | |
3142 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3143 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3144 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3145 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3146 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3147 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3148 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3149 | } else { | |
3150 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3151 | } | |
3152 | ||
121920fa | 3153 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3154 | |
3155 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3156 | } | |
3157 | ||
17638cd6 JB |
3158 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3159 | static int | |
3160 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3161 | int x, int y, enum mode_set_atomic state) | |
3162 | { | |
3163 | struct drm_device *dev = crtc->dev; | |
3164 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3165 | |
ff2a3117 | 3166 | if (dev_priv->fbc.disable_fbc) |
7733b49b | 3167 | dev_priv->fbc.disable_fbc(dev_priv); |
81255565 | 3168 | |
29b9bde6 DV |
3169 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3170 | ||
3171 | return 0; | |
81255565 JB |
3172 | } |
3173 | ||
7514747d | 3174 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3175 | { |
96a02917 VS |
3176 | struct drm_crtc *crtc; |
3177 | ||
70e1e0ec | 3178 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3180 | enum plane plane = intel_crtc->plane; | |
3181 | ||
3182 | intel_prepare_page_flip(dev, plane); | |
3183 | intel_finish_page_flip_plane(dev, plane); | |
3184 | } | |
7514747d VS |
3185 | } |
3186 | ||
3187 | static void intel_update_primary_planes(struct drm_device *dev) | |
3188 | { | |
7514747d | 3189 | struct drm_crtc *crtc; |
96a02917 | 3190 | |
70e1e0ec | 3191 | for_each_crtc(dev, crtc) { |
11c22da6 ML |
3192 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
3193 | struct intel_plane_state *plane_state; | |
96a02917 | 3194 | |
11c22da6 | 3195 | drm_modeset_lock_crtc(crtc, &plane->base); |
11c22da6 ML |
3196 | plane_state = to_intel_plane_state(plane->base.state); |
3197 | ||
f029ee82 | 3198 | if (crtc->state->active && plane_state->base.fb) |
11c22da6 ML |
3199 | plane->commit_plane(&plane->base, plane_state); |
3200 | ||
3201 | drm_modeset_unlock_crtc(crtc); | |
96a02917 VS |
3202 | } |
3203 | } | |
3204 | ||
7514747d VS |
3205 | void intel_prepare_reset(struct drm_device *dev) |
3206 | { | |
3207 | /* no reset support for gen2 */ | |
3208 | if (IS_GEN2(dev)) | |
3209 | return; | |
3210 | ||
3211 | /* reset doesn't touch the display */ | |
3212 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3213 | return; | |
3214 | ||
3215 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3216 | /* |
3217 | * Disabling the crtcs gracefully seems nicer. Also the | |
3218 | * g33 docs say we should at least disable all the planes. | |
3219 | */ | |
6b72d486 | 3220 | intel_display_suspend(dev); |
7514747d VS |
3221 | } |
3222 | ||
3223 | void intel_finish_reset(struct drm_device *dev) | |
3224 | { | |
3225 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3226 | ||
3227 | /* | |
3228 | * Flips in the rings will be nuked by the reset, | |
3229 | * so complete all pending flips so that user space | |
3230 | * will get its events and not get stuck. | |
3231 | */ | |
3232 | intel_complete_page_flips(dev); | |
3233 | ||
3234 | /* no reset support for gen2 */ | |
3235 | if (IS_GEN2(dev)) | |
3236 | return; | |
3237 | ||
3238 | /* reset doesn't touch the display */ | |
3239 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3240 | /* | |
3241 | * Flips in the rings have been nuked by the reset, | |
3242 | * so update the base address of all primary | |
3243 | * planes to the the last fb to make sure we're | |
3244 | * showing the correct fb after a reset. | |
11c22da6 ML |
3245 | * |
3246 | * FIXME: Atomic will make this obsolete since we won't schedule | |
3247 | * CS-based flips (which might get lost in gpu resets) any more. | |
7514747d VS |
3248 | */ |
3249 | intel_update_primary_planes(dev); | |
3250 | return; | |
3251 | } | |
3252 | ||
3253 | /* | |
3254 | * The display has been reset as well, | |
3255 | * so need a full re-initialization. | |
3256 | */ | |
3257 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3258 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3259 | ||
3260 | intel_modeset_init_hw(dev); | |
3261 | ||
3262 | spin_lock_irq(&dev_priv->irq_lock); | |
3263 | if (dev_priv->display.hpd_irq_setup) | |
3264 | dev_priv->display.hpd_irq_setup(dev); | |
3265 | spin_unlock_irq(&dev_priv->irq_lock); | |
3266 | ||
043e9bda | 3267 | intel_display_resume(dev); |
7514747d VS |
3268 | |
3269 | intel_hpd_init(dev_priv); | |
3270 | ||
3271 | drm_modeset_unlock_all(dev); | |
3272 | } | |
3273 | ||
7d5e3799 CW |
3274 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3275 | { | |
3276 | struct drm_device *dev = crtc->dev; | |
3277 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3278 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3279 | bool pending; |
3280 | ||
3281 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3282 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3283 | return false; | |
3284 | ||
5e2d7afc | 3285 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3286 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3287 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3288 | |
3289 | return pending; | |
3290 | } | |
3291 | ||
bfd16b2a ML |
3292 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
3293 | struct intel_crtc_state *old_crtc_state) | |
e30e8f75 GP |
3294 | { |
3295 | struct drm_device *dev = crtc->base.dev; | |
3296 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bfd16b2a ML |
3297 | struct intel_crtc_state *pipe_config = |
3298 | to_intel_crtc_state(crtc->base.state); | |
e30e8f75 | 3299 | |
bfd16b2a ML |
3300 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
3301 | crtc->base.mode = crtc->base.state->mode; | |
3302 | ||
3303 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", | |
3304 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, | |
3305 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
e30e8f75 | 3306 | |
44522d85 ML |
3307 | if (HAS_DDI(dev)) |
3308 | intel_set_pipe_csc(&crtc->base); | |
3309 | ||
e30e8f75 GP |
3310 | /* |
3311 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3312 | * that in compute_mode_changes we check the native mode (not the pfit | |
3313 | * mode) to see if we can flip rather than do a full mode set. In the | |
3314 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3315 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3316 | * sized surface. | |
e30e8f75 GP |
3317 | */ |
3318 | ||
e30e8f75 | 3319 | I915_WRITE(PIPESRC(crtc->pipe), |
bfd16b2a ML |
3320 | ((pipe_config->pipe_src_w - 1) << 16) | |
3321 | (pipe_config->pipe_src_h - 1)); | |
3322 | ||
3323 | /* on skylake this is done by detaching scalers */ | |
3324 | if (INTEL_INFO(dev)->gen >= 9) { | |
3325 | skl_detach_scalers(crtc); | |
3326 | ||
3327 | if (pipe_config->pch_pfit.enabled) | |
3328 | skylake_pfit_enable(crtc); | |
3329 | } else if (HAS_PCH_SPLIT(dev)) { | |
3330 | if (pipe_config->pch_pfit.enabled) | |
3331 | ironlake_pfit_enable(crtc); | |
3332 | else if (old_crtc_state->pch_pfit.enabled) | |
3333 | ironlake_pfit_disable(crtc, true); | |
e30e8f75 | 3334 | } |
e30e8f75 GP |
3335 | } |
3336 | ||
5e84e1a4 ZW |
3337 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3338 | { | |
3339 | struct drm_device *dev = crtc->dev; | |
3340 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3341 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3342 | int pipe = intel_crtc->pipe; | |
3343 | u32 reg, temp; | |
3344 | ||
3345 | /* enable normal train */ | |
3346 | reg = FDI_TX_CTL(pipe); | |
3347 | temp = I915_READ(reg); | |
61e499bf | 3348 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3349 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3350 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3351 | } else { |
3352 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3353 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3354 | } |
5e84e1a4 ZW |
3355 | I915_WRITE(reg, temp); |
3356 | ||
3357 | reg = FDI_RX_CTL(pipe); | |
3358 | temp = I915_READ(reg); | |
3359 | if (HAS_PCH_CPT(dev)) { | |
3360 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3361 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3362 | } else { | |
3363 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3364 | temp |= FDI_LINK_TRAIN_NONE; | |
3365 | } | |
3366 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3367 | ||
3368 | /* wait one idle pattern time */ | |
3369 | POSTING_READ(reg); | |
3370 | udelay(1000); | |
357555c0 JB |
3371 | |
3372 | /* IVB wants error correction enabled */ | |
3373 | if (IS_IVYBRIDGE(dev)) | |
3374 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3375 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3376 | } |
3377 | ||
8db9d77b ZW |
3378 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3379 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3380 | { | |
3381 | struct drm_device *dev = crtc->dev; | |
3382 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3383 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3384 | int pipe = intel_crtc->pipe; | |
5eddb70b | 3385 | u32 reg, temp, tries; |
8db9d77b | 3386 | |
1c8562f6 | 3387 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3388 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3389 | |
e1a44743 AJ |
3390 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3391 | for train result */ | |
5eddb70b CW |
3392 | reg = FDI_RX_IMR(pipe); |
3393 | temp = I915_READ(reg); | |
e1a44743 AJ |
3394 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3395 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3396 | I915_WRITE(reg, temp); |
3397 | I915_READ(reg); | |
e1a44743 AJ |
3398 | udelay(150); |
3399 | ||
8db9d77b | 3400 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3401 | reg = FDI_TX_CTL(pipe); |
3402 | temp = I915_READ(reg); | |
627eb5a3 | 3403 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3404 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3405 | temp &= ~FDI_LINK_TRAIN_NONE; |
3406 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3407 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3408 | |
5eddb70b CW |
3409 | reg = FDI_RX_CTL(pipe); |
3410 | temp = I915_READ(reg); | |
8db9d77b ZW |
3411 | temp &= ~FDI_LINK_TRAIN_NONE; |
3412 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3413 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3414 | ||
3415 | POSTING_READ(reg); | |
8db9d77b ZW |
3416 | udelay(150); |
3417 | ||
5b2adf89 | 3418 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3419 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3420 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3421 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3422 | |
5eddb70b | 3423 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3424 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3425 | temp = I915_READ(reg); |
8db9d77b ZW |
3426 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3427 | ||
3428 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3429 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3430 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3431 | break; |
3432 | } | |
8db9d77b | 3433 | } |
e1a44743 | 3434 | if (tries == 5) |
5eddb70b | 3435 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3436 | |
3437 | /* Train 2 */ | |
5eddb70b CW |
3438 | reg = FDI_TX_CTL(pipe); |
3439 | temp = I915_READ(reg); | |
8db9d77b ZW |
3440 | temp &= ~FDI_LINK_TRAIN_NONE; |
3441 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3442 | I915_WRITE(reg, temp); |
8db9d77b | 3443 | |
5eddb70b CW |
3444 | reg = FDI_RX_CTL(pipe); |
3445 | temp = I915_READ(reg); | |
8db9d77b ZW |
3446 | temp &= ~FDI_LINK_TRAIN_NONE; |
3447 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3448 | I915_WRITE(reg, temp); |
8db9d77b | 3449 | |
5eddb70b CW |
3450 | POSTING_READ(reg); |
3451 | udelay(150); | |
8db9d77b | 3452 | |
5eddb70b | 3453 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3454 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3455 | temp = I915_READ(reg); |
8db9d77b ZW |
3456 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3457 | ||
3458 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3459 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3460 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3461 | break; | |
3462 | } | |
8db9d77b | 3463 | } |
e1a44743 | 3464 | if (tries == 5) |
5eddb70b | 3465 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3466 | |
3467 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3468 | |
8db9d77b ZW |
3469 | } |
3470 | ||
0206e353 | 3471 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3472 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3473 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3474 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3475 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3476 | }; | |
3477 | ||
3478 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3479 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3480 | { | |
3481 | struct drm_device *dev = crtc->dev; | |
3482 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3483 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3484 | int pipe = intel_crtc->pipe; | |
fa37d39e | 3485 | u32 reg, temp, i, retry; |
8db9d77b | 3486 | |
e1a44743 AJ |
3487 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3488 | for train result */ | |
5eddb70b CW |
3489 | reg = FDI_RX_IMR(pipe); |
3490 | temp = I915_READ(reg); | |
e1a44743 AJ |
3491 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3492 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3493 | I915_WRITE(reg, temp); |
3494 | ||
3495 | POSTING_READ(reg); | |
e1a44743 AJ |
3496 | udelay(150); |
3497 | ||
8db9d77b | 3498 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3499 | reg = FDI_TX_CTL(pipe); |
3500 | temp = I915_READ(reg); | |
627eb5a3 | 3501 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3502 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3503 | temp &= ~FDI_LINK_TRAIN_NONE; |
3504 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3505 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3506 | /* SNB-B */ | |
3507 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3508 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3509 | |
d74cf324 DV |
3510 | I915_WRITE(FDI_RX_MISC(pipe), |
3511 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3512 | ||
5eddb70b CW |
3513 | reg = FDI_RX_CTL(pipe); |
3514 | temp = I915_READ(reg); | |
8db9d77b ZW |
3515 | if (HAS_PCH_CPT(dev)) { |
3516 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3517 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3518 | } else { | |
3519 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3520 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3521 | } | |
5eddb70b CW |
3522 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3523 | ||
3524 | POSTING_READ(reg); | |
8db9d77b ZW |
3525 | udelay(150); |
3526 | ||
0206e353 | 3527 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3528 | reg = FDI_TX_CTL(pipe); |
3529 | temp = I915_READ(reg); | |
8db9d77b ZW |
3530 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3531 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3532 | I915_WRITE(reg, temp); |
3533 | ||
3534 | POSTING_READ(reg); | |
8db9d77b ZW |
3535 | udelay(500); |
3536 | ||
fa37d39e SP |
3537 | for (retry = 0; retry < 5; retry++) { |
3538 | reg = FDI_RX_IIR(pipe); | |
3539 | temp = I915_READ(reg); | |
3540 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3541 | if (temp & FDI_RX_BIT_LOCK) { | |
3542 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3543 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3544 | break; | |
3545 | } | |
3546 | udelay(50); | |
8db9d77b | 3547 | } |
fa37d39e SP |
3548 | if (retry < 5) |
3549 | break; | |
8db9d77b ZW |
3550 | } |
3551 | if (i == 4) | |
5eddb70b | 3552 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3553 | |
3554 | /* Train 2 */ | |
5eddb70b CW |
3555 | reg = FDI_TX_CTL(pipe); |
3556 | temp = I915_READ(reg); | |
8db9d77b ZW |
3557 | temp &= ~FDI_LINK_TRAIN_NONE; |
3558 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3559 | if (IS_GEN6(dev)) { | |
3560 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3561 | /* SNB-B */ | |
3562 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3563 | } | |
5eddb70b | 3564 | I915_WRITE(reg, temp); |
8db9d77b | 3565 | |
5eddb70b CW |
3566 | reg = FDI_RX_CTL(pipe); |
3567 | temp = I915_READ(reg); | |
8db9d77b ZW |
3568 | if (HAS_PCH_CPT(dev)) { |
3569 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3570 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3571 | } else { | |
3572 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3573 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3574 | } | |
5eddb70b CW |
3575 | I915_WRITE(reg, temp); |
3576 | ||
3577 | POSTING_READ(reg); | |
8db9d77b ZW |
3578 | udelay(150); |
3579 | ||
0206e353 | 3580 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3581 | reg = FDI_TX_CTL(pipe); |
3582 | temp = I915_READ(reg); | |
8db9d77b ZW |
3583 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3584 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3585 | I915_WRITE(reg, temp); |
3586 | ||
3587 | POSTING_READ(reg); | |
8db9d77b ZW |
3588 | udelay(500); |
3589 | ||
fa37d39e SP |
3590 | for (retry = 0; retry < 5; retry++) { |
3591 | reg = FDI_RX_IIR(pipe); | |
3592 | temp = I915_READ(reg); | |
3593 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3594 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3595 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3596 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3597 | break; | |
3598 | } | |
3599 | udelay(50); | |
8db9d77b | 3600 | } |
fa37d39e SP |
3601 | if (retry < 5) |
3602 | break; | |
8db9d77b ZW |
3603 | } |
3604 | if (i == 4) | |
5eddb70b | 3605 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3606 | |
3607 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3608 | } | |
3609 | ||
357555c0 JB |
3610 | /* Manual link training for Ivy Bridge A0 parts */ |
3611 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3612 | { | |
3613 | struct drm_device *dev = crtc->dev; | |
3614 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3615 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3616 | int pipe = intel_crtc->pipe; | |
139ccd3f | 3617 | u32 reg, temp, i, j; |
357555c0 JB |
3618 | |
3619 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3620 | for train result */ | |
3621 | reg = FDI_RX_IMR(pipe); | |
3622 | temp = I915_READ(reg); | |
3623 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3624 | temp &= ~FDI_RX_BIT_LOCK; | |
3625 | I915_WRITE(reg, temp); | |
3626 | ||
3627 | POSTING_READ(reg); | |
3628 | udelay(150); | |
3629 | ||
01a415fd DV |
3630 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3631 | I915_READ(FDI_RX_IIR(pipe))); | |
3632 | ||
139ccd3f JB |
3633 | /* Try each vswing and preemphasis setting twice before moving on */ |
3634 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3635 | /* disable first in case we need to retry */ | |
3636 | reg = FDI_TX_CTL(pipe); | |
3637 | temp = I915_READ(reg); | |
3638 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3639 | temp &= ~FDI_TX_ENABLE; | |
3640 | I915_WRITE(reg, temp); | |
357555c0 | 3641 | |
139ccd3f JB |
3642 | reg = FDI_RX_CTL(pipe); |
3643 | temp = I915_READ(reg); | |
3644 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3645 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3646 | temp &= ~FDI_RX_ENABLE; | |
3647 | I915_WRITE(reg, temp); | |
357555c0 | 3648 | |
139ccd3f | 3649 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3650 | reg = FDI_TX_CTL(pipe); |
3651 | temp = I915_READ(reg); | |
139ccd3f | 3652 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3653 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3654 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3655 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3656 | temp |= snb_b_fdi_train_param[j/2]; |
3657 | temp |= FDI_COMPOSITE_SYNC; | |
3658 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3659 | |
139ccd3f JB |
3660 | I915_WRITE(FDI_RX_MISC(pipe), |
3661 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3662 | |
139ccd3f | 3663 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3664 | temp = I915_READ(reg); |
139ccd3f JB |
3665 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3666 | temp |= FDI_COMPOSITE_SYNC; | |
3667 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3668 | |
139ccd3f JB |
3669 | POSTING_READ(reg); |
3670 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3671 | |
139ccd3f JB |
3672 | for (i = 0; i < 4; i++) { |
3673 | reg = FDI_RX_IIR(pipe); | |
3674 | temp = I915_READ(reg); | |
3675 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3676 | |
139ccd3f JB |
3677 | if (temp & FDI_RX_BIT_LOCK || |
3678 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3679 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3680 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3681 | i); | |
3682 | break; | |
3683 | } | |
3684 | udelay(1); /* should be 0.5us */ | |
3685 | } | |
3686 | if (i == 4) { | |
3687 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3688 | continue; | |
3689 | } | |
357555c0 | 3690 | |
139ccd3f | 3691 | /* Train 2 */ |
357555c0 JB |
3692 | reg = FDI_TX_CTL(pipe); |
3693 | temp = I915_READ(reg); | |
139ccd3f JB |
3694 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3695 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3696 | I915_WRITE(reg, temp); | |
3697 | ||
3698 | reg = FDI_RX_CTL(pipe); | |
3699 | temp = I915_READ(reg); | |
3700 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3701 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3702 | I915_WRITE(reg, temp); |
3703 | ||
3704 | POSTING_READ(reg); | |
139ccd3f | 3705 | udelay(2); /* should be 1.5us */ |
357555c0 | 3706 | |
139ccd3f JB |
3707 | for (i = 0; i < 4; i++) { |
3708 | reg = FDI_RX_IIR(pipe); | |
3709 | temp = I915_READ(reg); | |
3710 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3711 | |
139ccd3f JB |
3712 | if (temp & FDI_RX_SYMBOL_LOCK || |
3713 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3714 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3715 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3716 | i); | |
3717 | goto train_done; | |
3718 | } | |
3719 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3720 | } |
139ccd3f JB |
3721 | if (i == 4) |
3722 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3723 | } |
357555c0 | 3724 | |
139ccd3f | 3725 | train_done: |
357555c0 JB |
3726 | DRM_DEBUG_KMS("FDI train done.\n"); |
3727 | } | |
3728 | ||
88cefb6c | 3729 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3730 | { |
88cefb6c | 3731 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3732 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3733 | int pipe = intel_crtc->pipe; |
5eddb70b | 3734 | u32 reg, temp; |
79e53945 | 3735 | |
c64e311e | 3736 | |
c98e9dcf | 3737 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3738 | reg = FDI_RX_CTL(pipe); |
3739 | temp = I915_READ(reg); | |
627eb5a3 | 3740 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3741 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3742 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3743 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3744 | ||
3745 | POSTING_READ(reg); | |
c98e9dcf JB |
3746 | udelay(200); |
3747 | ||
3748 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3749 | temp = I915_READ(reg); |
3750 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3751 | ||
3752 | POSTING_READ(reg); | |
c98e9dcf JB |
3753 | udelay(200); |
3754 | ||
20749730 PZ |
3755 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3756 | reg = FDI_TX_CTL(pipe); | |
3757 | temp = I915_READ(reg); | |
3758 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3759 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3760 | |
20749730 PZ |
3761 | POSTING_READ(reg); |
3762 | udelay(100); | |
6be4a607 | 3763 | } |
0e23b99d JB |
3764 | } |
3765 | ||
88cefb6c DV |
3766 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3767 | { | |
3768 | struct drm_device *dev = intel_crtc->base.dev; | |
3769 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3770 | int pipe = intel_crtc->pipe; | |
3771 | u32 reg, temp; | |
3772 | ||
3773 | /* Switch from PCDclk to Rawclk */ | |
3774 | reg = FDI_RX_CTL(pipe); | |
3775 | temp = I915_READ(reg); | |
3776 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3777 | ||
3778 | /* Disable CPU FDI TX PLL */ | |
3779 | reg = FDI_TX_CTL(pipe); | |
3780 | temp = I915_READ(reg); | |
3781 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3782 | ||
3783 | POSTING_READ(reg); | |
3784 | udelay(100); | |
3785 | ||
3786 | reg = FDI_RX_CTL(pipe); | |
3787 | temp = I915_READ(reg); | |
3788 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3789 | ||
3790 | /* Wait for the clocks to turn off. */ | |
3791 | POSTING_READ(reg); | |
3792 | udelay(100); | |
3793 | } | |
3794 | ||
0fc932b8 JB |
3795 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3796 | { | |
3797 | struct drm_device *dev = crtc->dev; | |
3798 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3799 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3800 | int pipe = intel_crtc->pipe; | |
3801 | u32 reg, temp; | |
3802 | ||
3803 | /* disable CPU FDI tx and PCH FDI rx */ | |
3804 | reg = FDI_TX_CTL(pipe); | |
3805 | temp = I915_READ(reg); | |
3806 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3807 | POSTING_READ(reg); | |
3808 | ||
3809 | reg = FDI_RX_CTL(pipe); | |
3810 | temp = I915_READ(reg); | |
3811 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3812 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3813 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3814 | ||
3815 | POSTING_READ(reg); | |
3816 | udelay(100); | |
3817 | ||
3818 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3819 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3820 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3821 | |
3822 | /* still set train pattern 1 */ | |
3823 | reg = FDI_TX_CTL(pipe); | |
3824 | temp = I915_READ(reg); | |
3825 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3826 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3827 | I915_WRITE(reg, temp); | |
3828 | ||
3829 | reg = FDI_RX_CTL(pipe); | |
3830 | temp = I915_READ(reg); | |
3831 | if (HAS_PCH_CPT(dev)) { | |
3832 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3833 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3834 | } else { | |
3835 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3836 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3837 | } | |
3838 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3839 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3840 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3841 | I915_WRITE(reg, temp); |
3842 | ||
3843 | POSTING_READ(reg); | |
3844 | udelay(100); | |
3845 | } | |
3846 | ||
5dce5b93 CW |
3847 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3848 | { | |
3849 | struct intel_crtc *crtc; | |
3850 | ||
3851 | /* Note that we don't need to be called with mode_config.lock here | |
3852 | * as our list of CRTC objects is static for the lifetime of the | |
3853 | * device and so cannot disappear as we iterate. Similarly, we can | |
3854 | * happily treat the predicates as racy, atomic checks as userspace | |
3855 | * cannot claim and pin a new fb without at least acquring the | |
3856 | * struct_mutex and so serialising with us. | |
3857 | */ | |
d3fcc808 | 3858 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3859 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3860 | continue; | |
3861 | ||
3862 | if (crtc->unpin_work) | |
3863 | intel_wait_for_vblank(dev, crtc->pipe); | |
3864 | ||
3865 | return true; | |
3866 | } | |
3867 | ||
3868 | return false; | |
3869 | } | |
3870 | ||
d6bbafa1 CW |
3871 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3872 | { | |
3873 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3874 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3875 | ||
3876 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3877 | smp_rmb(); | |
3878 | intel_crtc->unpin_work = NULL; | |
3879 | ||
3880 | if (work->event) | |
3881 | drm_send_vblank_event(intel_crtc->base.dev, | |
3882 | intel_crtc->pipe, | |
3883 | work->event); | |
3884 | ||
3885 | drm_crtc_vblank_put(&intel_crtc->base); | |
3886 | ||
3887 | wake_up_all(&dev_priv->pending_flip_queue); | |
3888 | queue_work(dev_priv->wq, &work->work); | |
3889 | ||
3890 | trace_i915_flip_complete(intel_crtc->plane, | |
3891 | work->pending_flip_obj); | |
3892 | } | |
3893 | ||
5008e874 | 3894 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3895 | { |
0f91128d | 3896 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3897 | struct drm_i915_private *dev_priv = dev->dev_private; |
5008e874 | 3898 | long ret; |
e6c3a2a6 | 3899 | |
2c10d571 | 3900 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
5008e874 ML |
3901 | |
3902 | ret = wait_event_interruptible_timeout( | |
3903 | dev_priv->pending_flip_queue, | |
3904 | !intel_crtc_has_pending_flip(crtc), | |
3905 | 60*HZ); | |
3906 | ||
3907 | if (ret < 0) | |
3908 | return ret; | |
3909 | ||
3910 | if (ret == 0) { | |
9c787942 | 3911 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
2c10d571 | 3912 | |
5e2d7afc | 3913 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3914 | if (intel_crtc->unpin_work) { |
3915 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3916 | page_flip_completed(intel_crtc); | |
3917 | } | |
5e2d7afc | 3918 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3919 | } |
5bb61643 | 3920 | |
5008e874 | 3921 | return 0; |
e6c3a2a6 CW |
3922 | } |
3923 | ||
e615efe4 ED |
3924 | /* Program iCLKIP clock to the desired frequency */ |
3925 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3926 | { | |
3927 | struct drm_device *dev = crtc->dev; | |
3928 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3929 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3930 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3931 | u32 temp; | |
3932 | ||
a580516d | 3933 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 3934 | |
e615efe4 ED |
3935 | /* It is necessary to ungate the pixclk gate prior to programming |
3936 | * the divisors, and gate it back when it is done. | |
3937 | */ | |
3938 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3939 | ||
3940 | /* Disable SSCCTL */ | |
3941 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3942 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3943 | SBI_SSCCTL_DISABLE, | |
3944 | SBI_ICLK); | |
e615efe4 ED |
3945 | |
3946 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3947 | if (clock == 20000) { |
e615efe4 ED |
3948 | auxdiv = 1; |
3949 | divsel = 0x41; | |
3950 | phaseinc = 0x20; | |
3951 | } else { | |
3952 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3953 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3954 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3955 | * convert the virtual clock precision to KHz here for higher |
3956 | * precision. | |
3957 | */ | |
3958 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3959 | u32 iclk_pi_range = 64; | |
3960 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3961 | ||
12d7ceed | 3962 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3963 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3964 | pi_value = desired_divisor % iclk_pi_range; | |
3965 | ||
3966 | auxdiv = 0; | |
3967 | divsel = msb_divisor_value - 2; | |
3968 | phaseinc = pi_value; | |
3969 | } | |
3970 | ||
3971 | /* This should not happen with any sane values */ | |
3972 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3973 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3974 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3975 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3976 | ||
3977 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3978 | clock, |
e615efe4 ED |
3979 | auxdiv, |
3980 | divsel, | |
3981 | phasedir, | |
3982 | phaseinc); | |
3983 | ||
3984 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 3985 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
3986 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
3987 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
3988 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
3989 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
3990 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
3991 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 3992 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
3993 | |
3994 | /* Program SSCAUXDIV */ | |
988d6ee8 | 3995 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
3996 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
3997 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 3998 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
3999 | |
4000 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4001 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4002 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4003 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
4004 | |
4005 | /* Wait for initialization time */ | |
4006 | udelay(24); | |
4007 | ||
4008 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 | 4009 | |
a580516d | 4010 | mutex_unlock(&dev_priv->sb_lock); |
e615efe4 ED |
4011 | } |
4012 | ||
275f01b2 DV |
4013 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4014 | enum pipe pch_transcoder) | |
4015 | { | |
4016 | struct drm_device *dev = crtc->base.dev; | |
4017 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4018 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4019 | |
4020 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4021 | I915_READ(HTOTAL(cpu_transcoder))); | |
4022 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4023 | I915_READ(HBLANK(cpu_transcoder))); | |
4024 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4025 | I915_READ(HSYNC(cpu_transcoder))); | |
4026 | ||
4027 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4028 | I915_READ(VTOTAL(cpu_transcoder))); | |
4029 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4030 | I915_READ(VBLANK(cpu_transcoder))); | |
4031 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4032 | I915_READ(VSYNC(cpu_transcoder))); | |
4033 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4034 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4035 | } | |
4036 | ||
003632d9 | 4037 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4038 | { |
4039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4040 | uint32_t temp; | |
4041 | ||
4042 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4043 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4044 | return; |
4045 | ||
4046 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4047 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4048 | ||
003632d9 ACO |
4049 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4050 | if (enable) | |
4051 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4052 | ||
4053 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4054 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4055 | POSTING_READ(SOUTH_CHICKEN1); | |
4056 | } | |
4057 | ||
4058 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4059 | { | |
4060 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4061 | |
4062 | switch (intel_crtc->pipe) { | |
4063 | case PIPE_A: | |
4064 | break; | |
4065 | case PIPE_B: | |
6e3c9717 | 4066 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4067 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4068 | else |
003632d9 | 4069 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4070 | |
4071 | break; | |
4072 | case PIPE_C: | |
003632d9 | 4073 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4074 | |
4075 | break; | |
4076 | default: | |
4077 | BUG(); | |
4078 | } | |
4079 | } | |
4080 | ||
f67a559d JB |
4081 | /* |
4082 | * Enable PCH resources required for PCH ports: | |
4083 | * - PCH PLLs | |
4084 | * - FDI training & RX/TX | |
4085 | * - update transcoder timings | |
4086 | * - DP transcoding bits | |
4087 | * - transcoder | |
4088 | */ | |
4089 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4090 | { |
4091 | struct drm_device *dev = crtc->dev; | |
4092 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4093 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4094 | int pipe = intel_crtc->pipe; | |
ee7b9f93 | 4095 | u32 reg, temp; |
2c07245f | 4096 | |
ab9412ba | 4097 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4098 | |
1fbc0d78 DV |
4099 | if (IS_IVYBRIDGE(dev)) |
4100 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4101 | ||
cd986abb DV |
4102 | /* Write the TU size bits before fdi link training, so that error |
4103 | * detection works. */ | |
4104 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4105 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4106 | ||
c98e9dcf | 4107 | /* For PCH output, training FDI link */ |
674cf967 | 4108 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4109 | |
3ad8a208 DV |
4110 | /* We need to program the right clock selection before writing the pixel |
4111 | * mutliplier into the DPLL. */ | |
303b81e0 | 4112 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4113 | u32 sel; |
4b645f14 | 4114 | |
c98e9dcf | 4115 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4116 | temp |= TRANS_DPLL_ENABLE(pipe); |
4117 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4118 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4119 | temp |= sel; |
4120 | else | |
4121 | temp &= ~sel; | |
c98e9dcf | 4122 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4123 | } |
5eddb70b | 4124 | |
3ad8a208 DV |
4125 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4126 | * transcoder, and we actually should do this to not upset any PCH | |
4127 | * transcoder that already use the clock when we share it. | |
4128 | * | |
4129 | * Note that enable_shared_dpll tries to do the right thing, but | |
4130 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4131 | * the right LVDS enable sequence. */ | |
85b3894f | 4132 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4133 | |
d9b6cb56 JB |
4134 | /* set transcoder timing, panel must allow it */ |
4135 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4136 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4137 | |
303b81e0 | 4138 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4139 | |
c98e9dcf | 4140 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4141 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
dfd07d72 | 4142 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
5eddb70b CW |
4143 | reg = TRANS_DP_CTL(pipe); |
4144 | temp = I915_READ(reg); | |
4145 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4146 | TRANS_DP_SYNC_MASK | |
4147 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4148 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4149 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf JB |
4150 | |
4151 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) | |
5eddb70b | 4152 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
c98e9dcf | 4153 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4154 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4155 | |
4156 | switch (intel_trans_dp_port_sel(crtc)) { | |
4157 | case PCH_DP_B: | |
5eddb70b | 4158 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf JB |
4159 | break; |
4160 | case PCH_DP_C: | |
5eddb70b | 4161 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf JB |
4162 | break; |
4163 | case PCH_DP_D: | |
5eddb70b | 4164 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4165 | break; |
4166 | default: | |
e95d41e1 | 4167 | BUG(); |
32f9d658 | 4168 | } |
2c07245f | 4169 | |
5eddb70b | 4170 | I915_WRITE(reg, temp); |
6be4a607 | 4171 | } |
b52eb4dc | 4172 | |
b8a4f404 | 4173 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4174 | } |
4175 | ||
1507e5bd PZ |
4176 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4177 | { | |
4178 | struct drm_device *dev = crtc->dev; | |
4179 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4181 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4182 | |
ab9412ba | 4183 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4184 | |
8c52b5e8 | 4185 | lpt_program_iclkip(crtc); |
1507e5bd | 4186 | |
0540e488 | 4187 | /* Set transcoder timing. */ |
275f01b2 | 4188 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4189 | |
937bb610 | 4190 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4191 | } |
4192 | ||
190f68c5 ACO |
4193 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4194 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4195 | { |
e2b78267 | 4196 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4197 | struct intel_shared_dpll *pll; |
de419ab6 | 4198 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4199 | enum intel_dpll_id i; |
ee7b9f93 | 4200 | |
de419ab6 ML |
4201 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4202 | ||
98b6bd99 DV |
4203 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4204 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4205 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4206 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4207 | |
46edb027 DV |
4208 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4209 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4210 | |
de419ab6 | 4211 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4212 | |
98b6bd99 DV |
4213 | goto found; |
4214 | } | |
4215 | ||
bcddf610 S |
4216 | if (IS_BROXTON(dev_priv->dev)) { |
4217 | /* PLL is attached to port in bxt */ | |
4218 | struct intel_encoder *encoder; | |
4219 | struct intel_digital_port *intel_dig_port; | |
4220 | ||
4221 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4222 | if (WARN_ON(!encoder)) | |
4223 | return NULL; | |
4224 | ||
4225 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4226 | /* 1:1 mapping between ports and PLLs */ | |
4227 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4228 | pll = &dev_priv->shared_dplls[i]; | |
4229 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4230 | crtc->base.base.id, pll->name); | |
de419ab6 | 4231 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4232 | |
4233 | goto found; | |
4234 | } | |
4235 | ||
e72f9fbf DV |
4236 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4237 | pll = &dev_priv->shared_dplls[i]; | |
ee7b9f93 JB |
4238 | |
4239 | /* Only want to check enabled timings first */ | |
de419ab6 | 4240 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4241 | continue; |
4242 | ||
190f68c5 | 4243 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4244 | &shared_dpll[i].hw_state, |
4245 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4246 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4247 | crtc->base.base.id, pll->name, |
de419ab6 | 4248 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4249 | pll->active); |
ee7b9f93 JB |
4250 | goto found; |
4251 | } | |
4252 | } | |
4253 | ||
4254 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4255 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4256 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4257 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4258 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4259 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4260 | goto found; |
4261 | } | |
4262 | } | |
4263 | ||
4264 | return NULL; | |
4265 | ||
4266 | found: | |
de419ab6 ML |
4267 | if (shared_dpll[i].crtc_mask == 0) |
4268 | shared_dpll[i].hw_state = | |
4269 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4270 | |
190f68c5 | 4271 | crtc_state->shared_dpll = i; |
46edb027 DV |
4272 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4273 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4274 | |
de419ab6 | 4275 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4276 | |
ee7b9f93 JB |
4277 | return pll; |
4278 | } | |
4279 | ||
de419ab6 | 4280 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4281 | { |
de419ab6 ML |
4282 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4283 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4284 | struct intel_shared_dpll *pll; |
4285 | enum intel_dpll_id i; | |
4286 | ||
de419ab6 ML |
4287 | if (!to_intel_atomic_state(state)->dpll_set) |
4288 | return; | |
8bd31e67 | 4289 | |
de419ab6 | 4290 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4291 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4292 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4293 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4294 | } |
4295 | } | |
4296 | ||
a1520318 | 4297 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4298 | { |
4299 | struct drm_i915_private *dev_priv = dev->dev_private; | |
23670b32 | 4300 | int dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4301 | u32 temp; |
4302 | ||
4303 | temp = I915_READ(dslreg); | |
4304 | udelay(500); | |
4305 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4306 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4307 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4308 | } |
4309 | } | |
4310 | ||
86adf9d7 ML |
4311 | static int |
4312 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4313 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4314 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4315 | { |
86adf9d7 ML |
4316 | struct intel_crtc_scaler_state *scaler_state = |
4317 | &crtc_state->scaler_state; | |
4318 | struct intel_crtc *intel_crtc = | |
4319 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4320 | int need_scaling; |
6156a456 CK |
4321 | |
4322 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4323 | (src_h != dst_w || src_w != dst_h): | |
4324 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4325 | |
4326 | /* | |
4327 | * if plane is being disabled or scaler is no more required or force detach | |
4328 | * - free scaler binded to this plane/crtc | |
4329 | * - in order to do this, update crtc->scaler_usage | |
4330 | * | |
4331 | * Here scaler state in crtc_state is set free so that | |
4332 | * scaler can be assigned to other user. Actual register | |
4333 | * update to free the scaler is done in plane/panel-fit programming. | |
4334 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4335 | */ | |
86adf9d7 | 4336 | if (force_detach || !need_scaling) { |
a1b2278e | 4337 | if (*scaler_id >= 0) { |
86adf9d7 | 4338 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4339 | scaler_state->scalers[*scaler_id].in_use = 0; |
4340 | ||
86adf9d7 ML |
4341 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4342 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4343 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4344 | scaler_state->scaler_users); |
4345 | *scaler_id = -1; | |
4346 | } | |
4347 | return 0; | |
4348 | } | |
4349 | ||
4350 | /* range checks */ | |
4351 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4352 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4353 | ||
4354 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4355 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4356 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4357 | "size is out of scaler range\n", |
86adf9d7 | 4358 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4359 | return -EINVAL; |
4360 | } | |
4361 | ||
86adf9d7 ML |
4362 | /* mark this plane as a scaler user in crtc_state */ |
4363 | scaler_state->scaler_users |= (1 << scaler_user); | |
4364 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4365 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4366 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4367 | scaler_state->scaler_users); | |
4368 | ||
4369 | return 0; | |
4370 | } | |
4371 | ||
4372 | /** | |
4373 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4374 | * | |
4375 | * @state: crtc's scaler state | |
86adf9d7 ML |
4376 | * |
4377 | * Return | |
4378 | * 0 - scaler_usage updated successfully | |
4379 | * error - requested scaling cannot be supported or other error condition | |
4380 | */ | |
e435d6e5 | 4381 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 ML |
4382 | { |
4383 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
7c5f93b0 | 4384 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
86adf9d7 ML |
4385 | |
4386 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4387 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4388 | ||
e435d6e5 | 4389 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
86adf9d7 ML |
4390 | &state->scaler_state.scaler_id, DRM_ROTATE_0, |
4391 | state->pipe_src_w, state->pipe_src_h, | |
aad941d5 | 4392 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
86adf9d7 ML |
4393 | } |
4394 | ||
4395 | /** | |
4396 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4397 | * | |
4398 | * @state: crtc's scaler state | |
86adf9d7 ML |
4399 | * @plane_state: atomic plane state to update |
4400 | * | |
4401 | * Return | |
4402 | * 0 - scaler_usage updated successfully | |
4403 | * error - requested scaling cannot be supported or other error condition | |
4404 | */ | |
da20eabd ML |
4405 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4406 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4407 | { |
4408 | ||
4409 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4410 | struct intel_plane *intel_plane = |
4411 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4412 | struct drm_framebuffer *fb = plane_state->base.fb; |
4413 | int ret; | |
4414 | ||
4415 | bool force_detach = !fb || !plane_state->visible; | |
4416 | ||
4417 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4418 | intel_plane->base.base.id, intel_crtc->pipe, | |
4419 | drm_plane_index(&intel_plane->base)); | |
4420 | ||
4421 | ret = skl_update_scaler(crtc_state, force_detach, | |
4422 | drm_plane_index(&intel_plane->base), | |
4423 | &plane_state->scaler_id, | |
4424 | plane_state->base.rotation, | |
4425 | drm_rect_width(&plane_state->src) >> 16, | |
4426 | drm_rect_height(&plane_state->src) >> 16, | |
4427 | drm_rect_width(&plane_state->dst), | |
4428 | drm_rect_height(&plane_state->dst)); | |
4429 | ||
4430 | if (ret || plane_state->scaler_id < 0) | |
4431 | return ret; | |
4432 | ||
a1b2278e | 4433 | /* check colorkey */ |
818ed961 | 4434 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
86adf9d7 | 4435 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
818ed961 | 4436 | intel_plane->base.base.id); |
a1b2278e CK |
4437 | return -EINVAL; |
4438 | } | |
4439 | ||
4440 | /* Check src format */ | |
86adf9d7 ML |
4441 | switch (fb->pixel_format) { |
4442 | case DRM_FORMAT_RGB565: | |
4443 | case DRM_FORMAT_XBGR8888: | |
4444 | case DRM_FORMAT_XRGB8888: | |
4445 | case DRM_FORMAT_ABGR8888: | |
4446 | case DRM_FORMAT_ARGB8888: | |
4447 | case DRM_FORMAT_XRGB2101010: | |
4448 | case DRM_FORMAT_XBGR2101010: | |
4449 | case DRM_FORMAT_YUYV: | |
4450 | case DRM_FORMAT_YVYU: | |
4451 | case DRM_FORMAT_UYVY: | |
4452 | case DRM_FORMAT_VYUY: | |
4453 | break; | |
4454 | default: | |
4455 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4456 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4457 | return -EINVAL; | |
a1b2278e CK |
4458 | } |
4459 | ||
a1b2278e CK |
4460 | return 0; |
4461 | } | |
4462 | ||
e435d6e5 ML |
4463 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4464 | { | |
4465 | int i; | |
4466 | ||
4467 | for (i = 0; i < crtc->num_scalers; i++) | |
4468 | skl_detach_scaler(crtc, i); | |
4469 | } | |
4470 | ||
4471 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4472 | { |
4473 | struct drm_device *dev = crtc->base.dev; | |
4474 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4475 | int pipe = crtc->pipe; | |
a1b2278e CK |
4476 | struct intel_crtc_scaler_state *scaler_state = |
4477 | &crtc->config->scaler_state; | |
4478 | ||
4479 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4480 | ||
6e3c9717 | 4481 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4482 | int id; |
4483 | ||
4484 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4485 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4486 | return; | |
4487 | } | |
4488 | ||
4489 | id = scaler_state->scaler_id; | |
4490 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4491 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4492 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4493 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4494 | ||
4495 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4496 | } |
4497 | } | |
4498 | ||
b074cec8 JB |
4499 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4500 | { | |
4501 | struct drm_device *dev = crtc->base.dev; | |
4502 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4503 | int pipe = crtc->pipe; | |
4504 | ||
6e3c9717 | 4505 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4506 | /* Force use of hard-coded filter coefficients |
4507 | * as some pre-programmed values are broken, | |
4508 | * e.g. x201. | |
4509 | */ | |
4510 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4511 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4512 | PF_PIPE_SEL_IVB(pipe)); | |
4513 | else | |
4514 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4515 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4516 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4517 | } |
4518 | } | |
4519 | ||
20bc8673 | 4520 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4521 | { |
cea165c3 VS |
4522 | struct drm_device *dev = crtc->base.dev; |
4523 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4524 | |
6e3c9717 | 4525 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4526 | return; |
4527 | ||
cea165c3 VS |
4528 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4529 | intel_wait_for_vblank(dev, crtc->pipe); | |
4530 | ||
d77e4531 | 4531 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4532 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4533 | mutex_lock(&dev_priv->rps.hw_lock); |
4534 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4535 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4536 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4537 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4538 | * mailbox." Moreover, the mailbox may return a bogus state, |
4539 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4540 | */ |
4541 | } else { | |
4542 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4543 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4544 | * is essentially intel_wait_for_vblank. If we don't have this | |
4545 | * and don't wait for vblanks until the end of crtc_enable, then | |
4546 | * the HW state readout code will complain that the expected | |
4547 | * IPS_CTL value is not the one we read. */ | |
4548 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4549 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4550 | } | |
d77e4531 PZ |
4551 | } |
4552 | ||
20bc8673 | 4553 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4554 | { |
4555 | struct drm_device *dev = crtc->base.dev; | |
4556 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4557 | ||
6e3c9717 | 4558 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4559 | return; |
4560 | ||
4561 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4562 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4563 | mutex_lock(&dev_priv->rps.hw_lock); |
4564 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4565 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4566 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4567 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4568 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4569 | } else { |
2a114cc1 | 4570 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4571 | POSTING_READ(IPS_CTL); |
4572 | } | |
d77e4531 PZ |
4573 | |
4574 | /* We need to wait for a vblank before we can disable the plane. */ | |
4575 | intel_wait_for_vblank(dev, crtc->pipe); | |
4576 | } | |
4577 | ||
4578 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4579 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4580 | { | |
4581 | struct drm_device *dev = crtc->dev; | |
4582 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4583 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4584 | enum pipe pipe = intel_crtc->pipe; | |
d77e4531 PZ |
4585 | int i; |
4586 | bool reenable_ips = false; | |
4587 | ||
4588 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4589 | if (!crtc->state->active) |
d77e4531 PZ |
4590 | return; |
4591 | ||
50360403 | 4592 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
409ee761 | 4593 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
d77e4531 PZ |
4594 | assert_dsi_pll_enabled(dev_priv); |
4595 | else | |
4596 | assert_pll_enabled(dev_priv, pipe); | |
4597 | } | |
4598 | ||
d77e4531 PZ |
4599 | /* Workaround : Do not read or write the pipe palette/gamma data while |
4600 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4601 | */ | |
6e3c9717 | 4602 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4603 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4604 | GAMMA_MODE_MODE_SPLIT)) { | |
4605 | hsw_disable_ips(intel_crtc); | |
4606 | reenable_ips = true; | |
4607 | } | |
4608 | ||
4609 | for (i = 0; i < 256; i++) { | |
f65a9c5b VS |
4610 | u32 palreg; |
4611 | ||
4612 | if (HAS_GMCH_DISPLAY(dev)) | |
4613 | palreg = PALETTE(pipe, i); | |
4614 | else | |
4615 | palreg = LGC_PALETTE(pipe, i); | |
4616 | ||
4617 | I915_WRITE(palreg, | |
d77e4531 PZ |
4618 | (intel_crtc->lut_r[i] << 16) | |
4619 | (intel_crtc->lut_g[i] << 8) | | |
4620 | intel_crtc->lut_b[i]); | |
4621 | } | |
4622 | ||
4623 | if (reenable_ips) | |
4624 | hsw_enable_ips(intel_crtc); | |
4625 | } | |
4626 | ||
7cac945f | 4627 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4628 | { |
7cac945f | 4629 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4630 | struct drm_device *dev = intel_crtc->base.dev; |
4631 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4632 | ||
4633 | mutex_lock(&dev->struct_mutex); | |
4634 | dev_priv->mm.interruptible = false; | |
4635 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4636 | dev_priv->mm.interruptible = true; | |
4637 | mutex_unlock(&dev->struct_mutex); | |
4638 | } | |
4639 | ||
4640 | /* Let userspace switch the overlay on again. In most cases userspace | |
4641 | * has to recompute where to put it anyway. | |
4642 | */ | |
4643 | } | |
4644 | ||
87d4300a ML |
4645 | /** |
4646 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4647 | * @crtc: the CRTC whose primary plane was just enabled | |
4648 | * | |
4649 | * Performs potentially sleeping operations that must be done after the primary | |
4650 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4651 | * called due to an explicit primary plane update, or due to an implicit | |
4652 | * re-enable that is caused when a sprite plane is updated to no longer | |
4653 | * completely hide the primary plane. | |
4654 | */ | |
4655 | static void | |
4656 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4657 | { |
4658 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4659 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4660 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4661 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4662 | |
87d4300a ML |
4663 | /* |
4664 | * BDW signals flip done immediately if the plane | |
4665 | * is disabled, even if the plane enable is already | |
4666 | * armed to occur at the next vblank :( | |
4667 | */ | |
4668 | if (IS_BROADWELL(dev)) | |
4669 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4670 | |
87d4300a ML |
4671 | /* |
4672 | * FIXME IPS should be fine as long as one plane is | |
4673 | * enabled, but in practice it seems to have problems | |
4674 | * when going from primary only to sprite only and vice | |
4675 | * versa. | |
4676 | */ | |
a5c4d7bc VS |
4677 | hsw_enable_ips(intel_crtc); |
4678 | ||
f99d7069 | 4679 | /* |
87d4300a ML |
4680 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4681 | * So don't enable underrun reporting before at least some planes | |
4682 | * are enabled. | |
4683 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4684 | * but leave the pipe running. | |
f99d7069 | 4685 | */ |
87d4300a ML |
4686 | if (IS_GEN2(dev)) |
4687 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4688 | ||
4689 | /* Underruns don't raise interrupts, so check manually. */ | |
4690 | if (HAS_GMCH_DISPLAY(dev)) | |
4691 | i9xx_check_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4692 | } |
4693 | ||
87d4300a ML |
4694 | /** |
4695 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4696 | * @crtc: the CRTC whose primary plane is to be disabled | |
4697 | * | |
4698 | * Performs potentially sleeping operations that must be done before the | |
4699 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4700 | * be called due to an explicit primary plane update, or due to an implicit | |
4701 | * disable that is caused when a sprite plane completely hides the primary | |
4702 | * plane. | |
4703 | */ | |
4704 | static void | |
4705 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4706 | { |
4707 | struct drm_device *dev = crtc->dev; | |
4708 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4709 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4710 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4711 | |
87d4300a ML |
4712 | /* |
4713 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4714 | * So diasble underrun reporting before all the planes get disabled. | |
4715 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4716 | * but leave the pipe running. | |
4717 | */ | |
4718 | if (IS_GEN2(dev)) | |
4719 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4720 | |
87d4300a ML |
4721 | /* |
4722 | * Vblank time updates from the shadow to live plane control register | |
4723 | * are blocked if the memory self-refresh mode is active at that | |
4724 | * moment. So to make sure the plane gets truly disabled, disable | |
4725 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4726 | * will be checked/applied by the HW only at the next frame start | |
4727 | * event which is after the vblank start event, so we need to have a | |
4728 | * wait-for-vblank between disabling the plane and the pipe. | |
4729 | */ | |
262cd2e1 | 4730 | if (HAS_GMCH_DISPLAY(dev)) { |
87d4300a | 4731 | intel_set_memory_cxsr(dev_priv, false); |
262cd2e1 VS |
4732 | dev_priv->wm.vlv.cxsr = false; |
4733 | intel_wait_for_vblank(dev, pipe); | |
4734 | } | |
87d4300a | 4735 | |
87d4300a ML |
4736 | /* |
4737 | * FIXME IPS should be fine as long as one plane is | |
4738 | * enabled, but in practice it seems to have problems | |
4739 | * when going from primary only to sprite only and vice | |
4740 | * versa. | |
4741 | */ | |
a5c4d7bc | 4742 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4743 | } |
4744 | ||
ac21b225 ML |
4745 | static void intel_post_plane_update(struct intel_crtc *crtc) |
4746 | { | |
4747 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4748 | struct drm_device *dev = crtc->base.dev; | |
7733b49b | 4749 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 ML |
4750 | |
4751 | if (atomic->wait_vblank) | |
4752 | intel_wait_for_vblank(dev, crtc->pipe); | |
4753 | ||
4754 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4755 | ||
852eb00d VS |
4756 | if (atomic->disable_cxsr) |
4757 | crtc->wm.cxsr_allowed = true; | |
4758 | ||
f015c551 VS |
4759 | if (crtc->atomic.update_wm_post) |
4760 | intel_update_watermarks(&crtc->base); | |
4761 | ||
c80ac854 | 4762 | if (atomic->update_fbc) |
7733b49b | 4763 | intel_fbc_update(dev_priv); |
ac21b225 ML |
4764 | |
4765 | if (atomic->post_enable_primary) | |
4766 | intel_post_enable_primary(&crtc->base); | |
4767 | ||
ac21b225 ML |
4768 | memset(atomic, 0, sizeof(*atomic)); |
4769 | } | |
4770 | ||
4771 | static void intel_pre_plane_update(struct intel_crtc *crtc) | |
4772 | { | |
4773 | struct drm_device *dev = crtc->base.dev; | |
eddfcbcd | 4774 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 | 4775 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
ac21b225 | 4776 | |
c80ac854 | 4777 | if (atomic->disable_fbc) |
25ad93fd | 4778 | intel_fbc_disable_crtc(crtc); |
ac21b225 | 4779 | |
066cf55b RV |
4780 | if (crtc->atomic.disable_ips) |
4781 | hsw_disable_ips(crtc); | |
4782 | ||
ac21b225 ML |
4783 | if (atomic->pre_disable_primary) |
4784 | intel_pre_disable_primary(&crtc->base); | |
852eb00d VS |
4785 | |
4786 | if (atomic->disable_cxsr) { | |
4787 | crtc->wm.cxsr_allowed = false; | |
4788 | intel_set_memory_cxsr(dev_priv, false); | |
4789 | } | |
ac21b225 ML |
4790 | } |
4791 | ||
d032ffa0 | 4792 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4793 | { |
4794 | struct drm_device *dev = crtc->dev; | |
4795 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4796 | struct drm_plane *p; |
87d4300a ML |
4797 | int pipe = intel_crtc->pipe; |
4798 | ||
7cac945f | 4799 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4800 | |
d032ffa0 ML |
4801 | drm_for_each_plane_mask(p, dev, plane_mask) |
4802 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4803 | |
f99d7069 DV |
4804 | /* |
4805 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4806 | * to compute the mask of flip planes precisely. For the time being | |
4807 | * consider this a flip to a NULL plane. | |
4808 | */ | |
4809 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4810 | } |
4811 | ||
f67a559d JB |
4812 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4813 | { | |
4814 | struct drm_device *dev = crtc->dev; | |
4815 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4816 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4817 | struct intel_encoder *encoder; |
f67a559d | 4818 | int pipe = intel_crtc->pipe; |
f67a559d | 4819 | |
53d9f4e9 | 4820 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4821 | return; |
4822 | ||
6e3c9717 | 4823 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4824 | intel_prepare_shared_dpll(intel_crtc); |
4825 | ||
6e3c9717 | 4826 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4827 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4828 | |
4829 | intel_set_pipe_timings(intel_crtc); | |
4830 | ||
6e3c9717 | 4831 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4832 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4833 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4834 | } |
4835 | ||
4836 | ironlake_set_pipeconf(crtc); | |
4837 | ||
f67a559d | 4838 | intel_crtc->active = true; |
8664281b | 4839 | |
a72e4c9f DV |
4840 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4841 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
8664281b | 4842 | |
f6736a1a | 4843 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4844 | if (encoder->pre_enable) |
4845 | encoder->pre_enable(encoder); | |
f67a559d | 4846 | |
6e3c9717 | 4847 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4848 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4849 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4850 | * enabling. */ | |
88cefb6c | 4851 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4852 | } else { |
4853 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4854 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4855 | } | |
f67a559d | 4856 | |
b074cec8 | 4857 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4858 | |
9c54c0dd JB |
4859 | /* |
4860 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4861 | * clocks enabled | |
4862 | */ | |
4863 | intel_crtc_load_lut(crtc); | |
4864 | ||
f37fcc2a | 4865 | intel_update_watermarks(crtc); |
e1fdc473 | 4866 | intel_enable_pipe(intel_crtc); |
f67a559d | 4867 | |
6e3c9717 | 4868 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4869 | ironlake_pch_enable(crtc); |
c98e9dcf | 4870 | |
f9b61ff6 DV |
4871 | assert_vblank_disabled(crtc); |
4872 | drm_crtc_vblank_on(crtc); | |
4873 | ||
fa5c73b1 DV |
4874 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4875 | encoder->enable(encoder); | |
61b77ddd DV |
4876 | |
4877 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4878 | cpt_verify_modeset(dev, intel_crtc->pipe); |
6be4a607 JB |
4879 | } |
4880 | ||
42db64ef PZ |
4881 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4882 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4883 | { | |
f5adf94e | 4884 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4885 | } |
4886 | ||
4f771f10 PZ |
4887 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4888 | { | |
4889 | struct drm_device *dev = crtc->dev; | |
4890 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4891 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4892 | struct intel_encoder *encoder; | |
99d736a2 ML |
4893 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4894 | struct intel_crtc_state *pipe_config = | |
4895 | to_intel_crtc_state(crtc->state); | |
7d4aefd0 | 4896 | bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
4f771f10 | 4897 | |
53d9f4e9 | 4898 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4899 | return; |
4900 | ||
df8ad70c DV |
4901 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4902 | intel_enable_shared_dpll(intel_crtc); | |
4903 | ||
6e3c9717 | 4904 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4905 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
4906 | |
4907 | intel_set_pipe_timings(intel_crtc); | |
4908 | ||
6e3c9717 ACO |
4909 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
4910 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
4911 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
4912 | } |
4913 | ||
6e3c9717 | 4914 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4915 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4916 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4917 | } |
4918 | ||
4919 | haswell_set_pipeconf(crtc); | |
4920 | ||
4921 | intel_set_pipe_csc(crtc); | |
4922 | ||
4f771f10 | 4923 | intel_crtc->active = true; |
8664281b | 4924 | |
a72e4c9f | 4925 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
7d4aefd0 SS |
4926 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4927 | if (encoder->pre_pll_enable) | |
4928 | encoder->pre_pll_enable(encoder); | |
4f771f10 PZ |
4929 | if (encoder->pre_enable) |
4930 | encoder->pre_enable(encoder); | |
7d4aefd0 | 4931 | } |
4f771f10 | 4932 | |
6e3c9717 | 4933 | if (intel_crtc->config->has_pch_encoder) { |
a72e4c9f DV |
4934 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
4935 | true); | |
4fe9467d ID |
4936 | dev_priv->display.fdi_link_train(crtc); |
4937 | } | |
4938 | ||
7d4aefd0 SS |
4939 | if (!is_dsi) |
4940 | intel_ddi_enable_pipe_clock(intel_crtc); | |
4f771f10 | 4941 | |
1c132b44 | 4942 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 4943 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 4944 | else |
1c132b44 | 4945 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
4946 | |
4947 | /* | |
4948 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4949 | * clocks enabled | |
4950 | */ | |
4951 | intel_crtc_load_lut(crtc); | |
4952 | ||
1f544388 | 4953 | intel_ddi_set_pipe_settings(crtc); |
7d4aefd0 SS |
4954 | if (!is_dsi) |
4955 | intel_ddi_enable_transcoder_func(crtc); | |
4f771f10 | 4956 | |
f37fcc2a | 4957 | intel_update_watermarks(crtc); |
e1fdc473 | 4958 | intel_enable_pipe(intel_crtc); |
42db64ef | 4959 | |
6e3c9717 | 4960 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 4961 | lpt_pch_enable(crtc); |
4f771f10 | 4962 | |
7d4aefd0 | 4963 | if (intel_crtc->config->dp_encoder_is_mst && !is_dsi) |
0e32b39c DA |
4964 | intel_ddi_set_vc_payload_alloc(crtc, true); |
4965 | ||
f9b61ff6 DV |
4966 | assert_vblank_disabled(crtc); |
4967 | drm_crtc_vblank_on(crtc); | |
4968 | ||
8807e55b | 4969 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 4970 | encoder->enable(encoder); |
8807e55b JN |
4971 | intel_opregion_notify_encoder(encoder, true); |
4972 | } | |
4f771f10 | 4973 | |
e4916946 PZ |
4974 | /* If we change the relative order between pipe/planes enabling, we need |
4975 | * to change the workaround. */ | |
99d736a2 ML |
4976 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
4977 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
4978 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4979 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4980 | } | |
4f771f10 PZ |
4981 | } |
4982 | ||
bfd16b2a | 4983 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
4984 | { |
4985 | struct drm_device *dev = crtc->base.dev; | |
4986 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4987 | int pipe = crtc->pipe; | |
4988 | ||
4989 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
4990 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 4991 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
4992 | I915_WRITE(PF_CTL(pipe), 0); |
4993 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
4994 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
4995 | } | |
4996 | } | |
4997 | ||
6be4a607 JB |
4998 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
4999 | { | |
5000 | struct drm_device *dev = crtc->dev; | |
5001 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5002 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5003 | struct intel_encoder *encoder; |
6be4a607 | 5004 | int pipe = intel_crtc->pipe; |
5eddb70b | 5005 | u32 reg, temp; |
b52eb4dc | 5006 | |
ea9d758d DV |
5007 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5008 | encoder->disable(encoder); | |
5009 | ||
f9b61ff6 DV |
5010 | drm_crtc_vblank_off(crtc); |
5011 | assert_vblank_disabled(crtc); | |
5012 | ||
6e3c9717 | 5013 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f | 5014 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
d925c59a | 5015 | |
575f7ab7 | 5016 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5017 | |
bfd16b2a | 5018 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 5019 | |
5a74f70a VS |
5020 | if (intel_crtc->config->has_pch_encoder) |
5021 | ironlake_fdi_disable(crtc); | |
5022 | ||
bf49ec8c DV |
5023 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5024 | if (encoder->post_disable) | |
5025 | encoder->post_disable(encoder); | |
2c07245f | 5026 | |
6e3c9717 | 5027 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5028 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5029 | |
d925c59a DV |
5030 | if (HAS_PCH_CPT(dev)) { |
5031 | /* disable TRANS_DP_CTL */ | |
5032 | reg = TRANS_DP_CTL(pipe); | |
5033 | temp = I915_READ(reg); | |
5034 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5035 | TRANS_DP_PORT_SEL_MASK); | |
5036 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5037 | I915_WRITE(reg, temp); | |
5038 | ||
5039 | /* disable DPLL_SEL */ | |
5040 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5041 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5042 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5043 | } |
e3421a18 | 5044 | |
d925c59a DV |
5045 | ironlake_fdi_pll_disable(intel_crtc); |
5046 | } | |
6be4a607 | 5047 | } |
1b3c7a47 | 5048 | |
4f771f10 | 5049 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5050 | { |
4f771f10 PZ |
5051 | struct drm_device *dev = crtc->dev; |
5052 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5053 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5054 | struct intel_encoder *encoder; |
6e3c9717 | 5055 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7d4aefd0 | 5056 | bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
ee7b9f93 | 5057 | |
8807e55b JN |
5058 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5059 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5060 | encoder->disable(encoder); |
8807e55b | 5061 | } |
4f771f10 | 5062 | |
f9b61ff6 DV |
5063 | drm_crtc_vblank_off(crtc); |
5064 | assert_vblank_disabled(crtc); | |
5065 | ||
6e3c9717 | 5066 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f DV |
5067 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5068 | false); | |
575f7ab7 | 5069 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5070 | |
6e3c9717 | 5071 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5072 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5073 | ||
7d4aefd0 SS |
5074 | if (!is_dsi) |
5075 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); | |
4f771f10 | 5076 | |
1c132b44 | 5077 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5078 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5079 | else |
bfd16b2a | 5080 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5081 | |
7d4aefd0 SS |
5082 | if (!is_dsi) |
5083 | intel_ddi_disable_pipe_clock(intel_crtc); | |
4f771f10 | 5084 | |
6e3c9717 | 5085 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5086 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5087 | intel_ddi_fdi_disable(crtc); |
83616634 | 5088 | } |
4f771f10 | 5089 | |
97b040aa ID |
5090 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5091 | if (encoder->post_disable) | |
5092 | encoder->post_disable(encoder); | |
4f771f10 PZ |
5093 | } |
5094 | ||
2dd24552 JB |
5095 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5096 | { | |
5097 | struct drm_device *dev = crtc->base.dev; | |
5098 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5099 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5100 | |
681a8504 | 5101 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5102 | return; |
5103 | ||
2dd24552 | 5104 | /* |
c0b03411 DV |
5105 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5106 | * according to register description and PRM. | |
2dd24552 | 5107 | */ |
c0b03411 DV |
5108 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5109 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5110 | |
b074cec8 JB |
5111 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5112 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5113 | |
5114 | /* Border color in case we don't scale up to the full screen. Black by | |
5115 | * default, change to something else for debugging. */ | |
5116 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5117 | } |
5118 | ||
d05410f9 DA |
5119 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5120 | { | |
5121 | switch (port) { | |
5122 | case PORT_A: | |
5123 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; | |
5124 | case PORT_B: | |
5125 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; | |
5126 | case PORT_C: | |
5127 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; | |
5128 | case PORT_D: | |
5129 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; | |
d8e19f99 XZ |
5130 | case PORT_E: |
5131 | return POWER_DOMAIN_PORT_DDI_E_2_LANES; | |
d05410f9 DA |
5132 | default: |
5133 | WARN_ON_ONCE(1); | |
5134 | return POWER_DOMAIN_PORT_OTHER; | |
5135 | } | |
5136 | } | |
5137 | ||
77d22dca ID |
5138 | #define for_each_power_domain(domain, mask) \ |
5139 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5140 | if ((1 << (domain)) & (mask)) | |
5141 | ||
319be8ae ID |
5142 | enum intel_display_power_domain |
5143 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5144 | { | |
5145 | struct drm_device *dev = intel_encoder->base.dev; | |
5146 | struct intel_digital_port *intel_dig_port; | |
5147 | ||
5148 | switch (intel_encoder->type) { | |
5149 | case INTEL_OUTPUT_UNKNOWN: | |
5150 | /* Only DDI platforms should ever use this output type */ | |
5151 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5152 | case INTEL_OUTPUT_DISPLAYPORT: | |
5153 | case INTEL_OUTPUT_HDMI: | |
5154 | case INTEL_OUTPUT_EDP: | |
5155 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5156 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5157 | case INTEL_OUTPUT_DP_MST: |
5158 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5159 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5160 | case INTEL_OUTPUT_ANALOG: |
5161 | return POWER_DOMAIN_PORT_CRT; | |
5162 | case INTEL_OUTPUT_DSI: | |
5163 | return POWER_DOMAIN_PORT_DSI; | |
5164 | default: | |
5165 | return POWER_DOMAIN_PORT_OTHER; | |
5166 | } | |
5167 | } | |
5168 | ||
5169 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) | |
77d22dca | 5170 | { |
319be8ae ID |
5171 | struct drm_device *dev = crtc->dev; |
5172 | struct intel_encoder *intel_encoder; | |
5173 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5174 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca | 5175 | unsigned long mask; |
1a70a728 | 5176 | enum transcoder transcoder = intel_crtc->config->cpu_transcoder; |
77d22dca | 5177 | |
292b990e ML |
5178 | if (!crtc->state->active) |
5179 | return 0; | |
5180 | ||
77d22dca ID |
5181 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5182 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5183 | if (intel_crtc->config->pch_pfit.enabled || |
5184 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5185 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5186 | ||
319be8ae ID |
5187 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5188 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5189 | ||
77d22dca ID |
5190 | return mask; |
5191 | } | |
5192 | ||
292b990e | 5193 | static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5194 | { |
292b990e ML |
5195 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5196 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5197 | enum intel_display_power_domain domain; | |
5198 | unsigned long domains, new_domains, old_domains; | |
77d22dca | 5199 | |
292b990e ML |
5200 | old_domains = intel_crtc->enabled_power_domains; |
5201 | intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc); | |
77d22dca | 5202 | |
292b990e ML |
5203 | domains = new_domains & ~old_domains; |
5204 | ||
5205 | for_each_power_domain(domain, domains) | |
5206 | intel_display_power_get(dev_priv, domain); | |
5207 | ||
5208 | return old_domains & ~new_domains; | |
5209 | } | |
5210 | ||
5211 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5212 | unsigned long domains) | |
5213 | { | |
5214 | enum intel_display_power_domain domain; | |
5215 | ||
5216 | for_each_power_domain(domain, domains) | |
5217 | intel_display_power_put(dev_priv, domain); | |
5218 | } | |
77d22dca | 5219 | |
292b990e ML |
5220 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
5221 | { | |
5222 | struct drm_device *dev = state->dev; | |
5223 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5224 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
5225 | struct drm_crtc_state *crtc_state; | |
5226 | struct drm_crtc *crtc; | |
5227 | int i; | |
77d22dca | 5228 | |
292b990e ML |
5229 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5230 | if (needs_modeset(crtc->state)) | |
5231 | put_domains[to_intel_crtc(crtc)->pipe] = | |
5232 | modeset_get_crtc_power_domains(crtc); | |
77d22dca ID |
5233 | } |
5234 | ||
27c329ed ML |
5235 | if (dev_priv->display.modeset_commit_cdclk) { |
5236 | unsigned int cdclk = to_intel_atomic_state(state)->cdclk; | |
5237 | ||
5238 | if (cdclk != dev_priv->cdclk_freq && | |
5239 | !WARN_ON(!state->allow_modeset)) | |
5240 | dev_priv->display.modeset_commit_cdclk(state); | |
5241 | } | |
50f6e502 | 5242 | |
292b990e ML |
5243 | for (i = 0; i < I915_MAX_PIPES; i++) |
5244 | if (put_domains[i]) | |
5245 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
77d22dca ID |
5246 | } |
5247 | ||
adafdc6f MK |
5248 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5249 | { | |
5250 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5251 | ||
5252 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5253 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5254 | return max_cdclk_freq; | |
5255 | else if (IS_CHERRYVIEW(dev_priv)) | |
5256 | return max_cdclk_freq*95/100; | |
5257 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5258 | return 2*max_cdclk_freq*90/100; | |
5259 | else | |
5260 | return max_cdclk_freq*90/100; | |
5261 | } | |
5262 | ||
560a7ae4 DL |
5263 | static void intel_update_max_cdclk(struct drm_device *dev) |
5264 | { | |
5265 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5266 | ||
ef11bdb3 | 5267 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
560a7ae4 DL |
5268 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
5269 | ||
5270 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5271 | dev_priv->max_cdclk_freq = 675000; | |
5272 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5273 | dev_priv->max_cdclk_freq = 540000; | |
5274 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5275 | dev_priv->max_cdclk_freq = 450000; | |
5276 | else | |
5277 | dev_priv->max_cdclk_freq = 337500; | |
5278 | } else if (IS_BROADWELL(dev)) { | |
5279 | /* | |
5280 | * FIXME with extra cooling we can allow | |
5281 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5282 | * How can we know if extra cooling is | |
5283 | * available? PCI ID, VTB, something else? | |
5284 | */ | |
5285 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5286 | dev_priv->max_cdclk_freq = 450000; | |
5287 | else if (IS_BDW_ULX(dev)) | |
5288 | dev_priv->max_cdclk_freq = 450000; | |
5289 | else if (IS_BDW_ULT(dev)) | |
5290 | dev_priv->max_cdclk_freq = 540000; | |
5291 | else | |
5292 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5293 | } else if (IS_CHERRYVIEW(dev)) { |
5294 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5295 | } else if (IS_VALLEYVIEW(dev)) { |
5296 | dev_priv->max_cdclk_freq = 400000; | |
5297 | } else { | |
5298 | /* otherwise assume cdclk is fixed */ | |
5299 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5300 | } | |
5301 | ||
adafdc6f MK |
5302 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5303 | ||
560a7ae4 DL |
5304 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5305 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5306 | |
5307 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5308 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5309 | } |
5310 | ||
5311 | static void intel_update_cdclk(struct drm_device *dev) | |
5312 | { | |
5313 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5314 | ||
5315 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5316 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5317 | dev_priv->cdclk_freq); | |
5318 | ||
5319 | /* | |
5320 | * Program the gmbus_freq based on the cdclk frequency. | |
5321 | * BSpec erroneously claims we should aim for 4MHz, but | |
5322 | * in fact 1MHz is the correct frequency. | |
5323 | */ | |
5324 | if (IS_VALLEYVIEW(dev)) { | |
5325 | /* | |
5326 | * Program the gmbus_freq based on the cdclk frequency. | |
5327 | * BSpec erroneously claims we should aim for 4MHz, but | |
5328 | * in fact 1MHz is the correct frequency. | |
5329 | */ | |
5330 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5331 | } | |
5332 | ||
5333 | if (dev_priv->max_cdclk_freq == 0) | |
5334 | intel_update_max_cdclk(dev); | |
5335 | } | |
5336 | ||
70d0c574 | 5337 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5338 | { |
5339 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5340 | uint32_t divider; | |
5341 | uint32_t ratio; | |
5342 | uint32_t current_freq; | |
5343 | int ret; | |
5344 | ||
5345 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5346 | switch (frequency) { | |
5347 | case 144000: | |
5348 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5349 | ratio = BXT_DE_PLL_RATIO(60); | |
5350 | break; | |
5351 | case 288000: | |
5352 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5353 | ratio = BXT_DE_PLL_RATIO(60); | |
5354 | break; | |
5355 | case 384000: | |
5356 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5357 | ratio = BXT_DE_PLL_RATIO(60); | |
5358 | break; | |
5359 | case 576000: | |
5360 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5361 | ratio = BXT_DE_PLL_RATIO(60); | |
5362 | break; | |
5363 | case 624000: | |
5364 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5365 | ratio = BXT_DE_PLL_RATIO(65); | |
5366 | break; | |
5367 | case 19200: | |
5368 | /* | |
5369 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5370 | * to suppress GCC warning. | |
5371 | */ | |
5372 | ratio = 0; | |
5373 | divider = 0; | |
5374 | break; | |
5375 | default: | |
5376 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5377 | ||
5378 | return; | |
5379 | } | |
5380 | ||
5381 | mutex_lock(&dev_priv->rps.hw_lock); | |
5382 | /* Inform power controller of upcoming frequency change */ | |
5383 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5384 | 0x80000000); | |
5385 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5386 | ||
5387 | if (ret) { | |
5388 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5389 | ret, frequency); | |
5390 | return; | |
5391 | } | |
5392 | ||
5393 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5394 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5395 | current_freq = current_freq * 500 + 1000; | |
5396 | ||
5397 | /* | |
5398 | * DE PLL has to be disabled when | |
5399 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5400 | * - before setting to 624MHz (PLL needs toggling) | |
5401 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5402 | */ | |
5403 | if (frequency == 19200 || frequency == 624000 || | |
5404 | current_freq == 624000) { | |
5405 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5406 | /* Timeout 200us */ | |
5407 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5408 | 1)) | |
5409 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5410 | } | |
5411 | ||
5412 | if (frequency != 19200) { | |
5413 | uint32_t val; | |
5414 | ||
5415 | val = I915_READ(BXT_DE_PLL_CTL); | |
5416 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5417 | val |= ratio; | |
5418 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5419 | ||
5420 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5421 | /* Timeout 200us */ | |
5422 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5423 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5424 | ||
5425 | val = I915_READ(CDCLK_CTL); | |
5426 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5427 | val |= divider; | |
5428 | /* | |
5429 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5430 | * enable otherwise. | |
5431 | */ | |
5432 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5433 | if (frequency >= 500000) | |
5434 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5435 | ||
5436 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5437 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5438 | val |= (frequency - 1000) / 500; | |
5439 | I915_WRITE(CDCLK_CTL, val); | |
5440 | } | |
5441 | ||
5442 | mutex_lock(&dev_priv->rps.hw_lock); | |
5443 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5444 | DIV_ROUND_UP(frequency, 25000)); | |
5445 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5446 | ||
5447 | if (ret) { | |
5448 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5449 | ret, frequency); | |
5450 | return; | |
5451 | } | |
5452 | ||
a47871bd | 5453 | intel_update_cdclk(dev); |
f8437dd1 VK |
5454 | } |
5455 | ||
5456 | void broxton_init_cdclk(struct drm_device *dev) | |
5457 | { | |
5458 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5459 | uint32_t val; | |
5460 | ||
5461 | /* | |
5462 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5463 | * or else the reset will hang because there is no PCH to respond. | |
5464 | * Move the handshake programming to initialization sequence. | |
5465 | * Previously was left up to BIOS. | |
5466 | */ | |
5467 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5468 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5469 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5470 | ||
5471 | /* Enable PG1 for cdclk */ | |
5472 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5473 | ||
5474 | /* check if cd clock is enabled */ | |
5475 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5476 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5477 | return; | |
5478 | } | |
5479 | ||
5480 | /* | |
5481 | * FIXME: | |
5482 | * - The initial CDCLK needs to be read from VBT. | |
5483 | * Need to make this change after VBT has changes for BXT. | |
5484 | * - check if setting the max (or any) cdclk freq is really necessary | |
5485 | * here, it belongs to modeset time | |
5486 | */ | |
5487 | broxton_set_cdclk(dev, 624000); | |
5488 | ||
5489 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5490 | POSTING_READ(DBUF_CTL); |
5491 | ||
f8437dd1 VK |
5492 | udelay(10); |
5493 | ||
5494 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5495 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5496 | } | |
5497 | ||
5498 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5499 | { | |
5500 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5501 | ||
5502 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5503 | POSTING_READ(DBUF_CTL); |
5504 | ||
f8437dd1 VK |
5505 | udelay(10); |
5506 | ||
5507 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5508 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5509 | ||
5510 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5511 | broxton_set_cdclk(dev, 19200); | |
5512 | ||
5513 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5514 | } | |
5515 | ||
5d96d8af DL |
5516 | static const struct skl_cdclk_entry { |
5517 | unsigned int freq; | |
5518 | unsigned int vco; | |
5519 | } skl_cdclk_frequencies[] = { | |
5520 | { .freq = 308570, .vco = 8640 }, | |
5521 | { .freq = 337500, .vco = 8100 }, | |
5522 | { .freq = 432000, .vco = 8640 }, | |
5523 | { .freq = 450000, .vco = 8100 }, | |
5524 | { .freq = 540000, .vco = 8100 }, | |
5525 | { .freq = 617140, .vco = 8640 }, | |
5526 | { .freq = 675000, .vco = 8100 }, | |
5527 | }; | |
5528 | ||
5529 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5530 | { | |
5531 | return (freq - 1000) / 500; | |
5532 | } | |
5533 | ||
5534 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5535 | { | |
5536 | unsigned int i; | |
5537 | ||
5538 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5539 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5540 | ||
5541 | if (e->freq == freq) | |
5542 | return e->vco; | |
5543 | } | |
5544 | ||
5545 | return 8100; | |
5546 | } | |
5547 | ||
5548 | static void | |
5549 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5550 | { | |
5551 | unsigned int min_freq; | |
5552 | u32 val; | |
5553 | ||
5554 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5555 | val = I915_READ(CDCLK_CTL); | |
5556 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5557 | val |= CDCLK_FREQ_337_308; | |
5558 | ||
5559 | if (required_vco == 8640) | |
5560 | min_freq = 308570; | |
5561 | else | |
5562 | min_freq = 337500; | |
5563 | ||
5564 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5565 | ||
5566 | I915_WRITE(CDCLK_CTL, val); | |
5567 | POSTING_READ(CDCLK_CTL); | |
5568 | ||
5569 | /* | |
5570 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5571 | * taking into account the VCO required to operate the eDP panel at the | |
5572 | * desired frequency. The usual DP link rates operate with a VCO of | |
5573 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5574 | * The modeset code is responsible for the selection of the exact link | |
5575 | * rate later on, with the constraint of choosing a frequency that | |
5576 | * works with required_vco. | |
5577 | */ | |
5578 | val = I915_READ(DPLL_CTRL1); | |
5579 | ||
5580 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5581 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5582 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5583 | if (required_vco == 8640) | |
5584 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5585 | SKL_DPLL0); | |
5586 | else | |
5587 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5588 | SKL_DPLL0); | |
5589 | ||
5590 | I915_WRITE(DPLL_CTRL1, val); | |
5591 | POSTING_READ(DPLL_CTRL1); | |
5592 | ||
5593 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5594 | ||
5595 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5596 | DRM_ERROR("DPLL0 not locked\n"); | |
5597 | } | |
5598 | ||
5599 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5600 | { | |
5601 | int ret; | |
5602 | u32 val; | |
5603 | ||
5604 | /* inform PCU we want to change CDCLK */ | |
5605 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5606 | mutex_lock(&dev_priv->rps.hw_lock); | |
5607 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5608 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5609 | ||
5610 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5611 | } | |
5612 | ||
5613 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5614 | { | |
5615 | unsigned int i; | |
5616 | ||
5617 | for (i = 0; i < 15; i++) { | |
5618 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5619 | return true; | |
5620 | udelay(10); | |
5621 | } | |
5622 | ||
5623 | return false; | |
5624 | } | |
5625 | ||
5626 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5627 | { | |
560a7ae4 | 5628 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5629 | u32 freq_select, pcu_ack; |
5630 | ||
5631 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5632 | ||
5633 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5634 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5635 | return; | |
5636 | } | |
5637 | ||
5638 | /* set CDCLK_CTL */ | |
5639 | switch(freq) { | |
5640 | case 450000: | |
5641 | case 432000: | |
5642 | freq_select = CDCLK_FREQ_450_432; | |
5643 | pcu_ack = 1; | |
5644 | break; | |
5645 | case 540000: | |
5646 | freq_select = CDCLK_FREQ_540; | |
5647 | pcu_ack = 2; | |
5648 | break; | |
5649 | case 308570: | |
5650 | case 337500: | |
5651 | default: | |
5652 | freq_select = CDCLK_FREQ_337_308; | |
5653 | pcu_ack = 0; | |
5654 | break; | |
5655 | case 617140: | |
5656 | case 675000: | |
5657 | freq_select = CDCLK_FREQ_675_617; | |
5658 | pcu_ack = 3; | |
5659 | break; | |
5660 | } | |
5661 | ||
5662 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5663 | POSTING_READ(CDCLK_CTL); | |
5664 | ||
5665 | /* inform PCU of the change */ | |
5666 | mutex_lock(&dev_priv->rps.hw_lock); | |
5667 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5668 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5669 | |
5670 | intel_update_cdclk(dev); | |
5d96d8af DL |
5671 | } |
5672 | ||
5673 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5674 | { | |
5675 | /* disable DBUF power */ | |
5676 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5677 | POSTING_READ(DBUF_CTL); | |
5678 | ||
5679 | udelay(10); | |
5680 | ||
5681 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5682 | DRM_ERROR("DBuf power disable timeout\n"); | |
5683 | ||
4e961e42 AM |
5684 | /* |
5685 | * DMC assumes ownership of LCPLL and will get confused if we touch it. | |
5686 | */ | |
5687 | if (dev_priv->csr.dmc_payload) { | |
5688 | /* disable DPLL0 */ | |
5689 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & | |
5690 | ~LCPLL_PLL_ENABLE); | |
5691 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5692 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5693 | } | |
5d96d8af DL |
5694 | |
5695 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5696 | } | |
5697 | ||
5698 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5699 | { | |
5700 | u32 val; | |
5701 | unsigned int required_vco; | |
5702 | ||
5703 | /* enable PCH reset handshake */ | |
5704 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5705 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE); | |
5706 | ||
5707 | /* enable PG1 and Misc I/O */ | |
5708 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5709 | ||
39d9b85a GW |
5710 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5711 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5712 | /* enable DPLL0 */ | |
5713 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5714 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5715 | } |
5716 | ||
5d96d8af DL |
5717 | /* set CDCLK to the frequency the BIOS chose */ |
5718 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5719 | ||
5720 | /* enable DBUF power */ | |
5721 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5722 | POSTING_READ(DBUF_CTL); | |
5723 | ||
5724 | udelay(10); | |
5725 | ||
5726 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5727 | DRM_ERROR("DBuf power enable timeout\n"); | |
5728 | } | |
5729 | ||
c73666f3 SK |
5730 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
5731 | { | |
5732 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5733 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5734 | int freq = dev_priv->skl_boot_cdclk; | |
5735 | ||
f1b391a5 SK |
5736 | /* |
5737 | * check if the pre-os intialized the display | |
5738 | * There is SWF18 scratchpad register defined which is set by the | |
5739 | * pre-os which can be used by the OS drivers to check the status | |
5740 | */ | |
5741 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5742 | goto sanitize; | |
5743 | ||
c73666f3 SK |
5744 | /* Is PLL enabled and locked ? */ |
5745 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5746 | goto sanitize; | |
5747 | ||
5748 | /* DPLL okay; verify the cdclock | |
5749 | * | |
5750 | * Noticed in some instances that the freq selection is correct but | |
5751 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5752 | * enable display. Verify the same as well. | |
5753 | */ | |
5754 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5755 | /* All well; nothing to sanitize */ | |
5756 | return false; | |
5757 | sanitize: | |
5758 | /* | |
5759 | * As of now initialize with max cdclk till | |
5760 | * we get dynamic cdclk support | |
5761 | * */ | |
5762 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5763 | skl_init_cdclk(dev_priv); | |
5764 | ||
5765 | /* we did have to sanitize */ | |
5766 | return true; | |
5767 | } | |
5768 | ||
30a970c6 JB |
5769 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5770 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5771 | { | |
5772 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5773 | u32 val, cmd; | |
5774 | ||
164dfd28 VK |
5775 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5776 | != dev_priv->cdclk_freq); | |
d60c4473 | 5777 | |
dfcab17e | 5778 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5779 | cmd = 2; |
dfcab17e | 5780 | else if (cdclk == 266667) |
30a970c6 JB |
5781 | cmd = 1; |
5782 | else | |
5783 | cmd = 0; | |
5784 | ||
5785 | mutex_lock(&dev_priv->rps.hw_lock); | |
5786 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5787 | val &= ~DSPFREQGUAR_MASK; | |
5788 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5789 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5790 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5791 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5792 | 50)) { | |
5793 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5794 | } | |
5795 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5796 | ||
54433e91 VS |
5797 | mutex_lock(&dev_priv->sb_lock); |
5798 | ||
dfcab17e | 5799 | if (cdclk == 400000) { |
6bcda4f0 | 5800 | u32 divider; |
30a970c6 | 5801 | |
6bcda4f0 | 5802 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5803 | |
30a970c6 JB |
5804 | /* adjust cdclk divider */ |
5805 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 5806 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
5807 | val |= divider; |
5808 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5809 | |
5810 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 5811 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
5812 | 50)) |
5813 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5814 | } |
5815 | ||
30a970c6 JB |
5816 | /* adjust self-refresh exit latency value */ |
5817 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5818 | val &= ~0x7f; | |
5819 | ||
5820 | /* | |
5821 | * For high bandwidth configs, we set a higher latency in the bunit | |
5822 | * so that the core display fetch happens in time to avoid underruns. | |
5823 | */ | |
dfcab17e | 5824 | if (cdclk == 400000) |
30a970c6 JB |
5825 | val |= 4500 / 250; /* 4.5 usec */ |
5826 | else | |
5827 | val |= 3000 / 250; /* 3.0 usec */ | |
5828 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5829 | |
a580516d | 5830 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5831 | |
b6283055 | 5832 | intel_update_cdclk(dev); |
30a970c6 JB |
5833 | } |
5834 | ||
383c5a6a VS |
5835 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5836 | { | |
5837 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5838 | u32 val, cmd; | |
5839 | ||
164dfd28 VK |
5840 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5841 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5842 | |
5843 | switch (cdclk) { | |
383c5a6a VS |
5844 | case 333333: |
5845 | case 320000: | |
383c5a6a | 5846 | case 266667: |
383c5a6a | 5847 | case 200000: |
383c5a6a VS |
5848 | break; |
5849 | default: | |
5f77eeb0 | 5850 | MISSING_CASE(cdclk); |
383c5a6a VS |
5851 | return; |
5852 | } | |
5853 | ||
9d0d3fda VS |
5854 | /* |
5855 | * Specs are full of misinformation, but testing on actual | |
5856 | * hardware has shown that we just need to write the desired | |
5857 | * CCK divider into the Punit register. | |
5858 | */ | |
5859 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5860 | ||
383c5a6a VS |
5861 | mutex_lock(&dev_priv->rps.hw_lock); |
5862 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5863 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5864 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5865 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5866 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5867 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5868 | 50)) { | |
5869 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5870 | } | |
5871 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5872 | ||
b6283055 | 5873 | intel_update_cdclk(dev); |
383c5a6a VS |
5874 | } |
5875 | ||
30a970c6 JB |
5876 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5877 | int max_pixclk) | |
5878 | { | |
6bcda4f0 | 5879 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5880 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5881 | |
30a970c6 JB |
5882 | /* |
5883 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5884 | * 200MHz | |
5885 | * 267MHz | |
29dc7ef3 | 5886 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5887 | * 400MHz (VLV only) |
5888 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5889 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5890 | * |
5891 | * We seem to get an unstable or solid color picture at 200MHz. | |
5892 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5893 | * are off. | |
30a970c6 | 5894 | */ |
6cca3195 VS |
5895 | if (!IS_CHERRYVIEW(dev_priv) && |
5896 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5897 | return 400000; |
6cca3195 | 5898 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5899 | return freq_320; |
e37c67a1 | 5900 | else if (max_pixclk > 0) |
dfcab17e | 5901 | return 266667; |
e37c67a1 VS |
5902 | else |
5903 | return 200000; | |
30a970c6 JB |
5904 | } |
5905 | ||
f8437dd1 VK |
5906 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5907 | int max_pixclk) | |
5908 | { | |
5909 | /* | |
5910 | * FIXME: | |
5911 | * - remove the guardband, it's not needed on BXT | |
5912 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5913 | */ | |
5914 | if (max_pixclk > 576000*9/10) | |
5915 | return 624000; | |
5916 | else if (max_pixclk > 384000*9/10) | |
5917 | return 576000; | |
5918 | else if (max_pixclk > 288000*9/10) | |
5919 | return 384000; | |
5920 | else if (max_pixclk > 144000*9/10) | |
5921 | return 288000; | |
5922 | else | |
5923 | return 144000; | |
5924 | } | |
5925 | ||
a821fc46 ACO |
5926 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5927 | * that's non-NULL, look at current state otherwise. */ | |
5928 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5929 | struct drm_atomic_state *state) | |
30a970c6 | 5930 | { |
30a970c6 | 5931 | struct intel_crtc *intel_crtc; |
304603f4 | 5932 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5933 | int max_pixclk = 0; |
5934 | ||
d3fcc808 | 5935 | for_each_intel_crtc(dev, intel_crtc) { |
27c329ed | 5936 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
304603f4 ACO |
5937 | if (IS_ERR(crtc_state)) |
5938 | return PTR_ERR(crtc_state); | |
5939 | ||
5940 | if (!crtc_state->base.enable) | |
5941 | continue; | |
5942 | ||
5943 | max_pixclk = max(max_pixclk, | |
5944 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5945 | } |
5946 | ||
5947 | return max_pixclk; | |
5948 | } | |
5949 | ||
27c329ed | 5950 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 5951 | { |
27c329ed ML |
5952 | struct drm_device *dev = state->dev; |
5953 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5954 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
30a970c6 | 5955 | |
304603f4 ACO |
5956 | if (max_pixclk < 0) |
5957 | return max_pixclk; | |
30a970c6 | 5958 | |
27c329ed ML |
5959 | to_intel_atomic_state(state)->cdclk = |
5960 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
0a9ab303 | 5961 | |
27c329ed ML |
5962 | return 0; |
5963 | } | |
304603f4 | 5964 | |
27c329ed ML |
5965 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
5966 | { | |
5967 | struct drm_device *dev = state->dev; | |
5968 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5969 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
85a96e7a | 5970 | |
27c329ed ML |
5971 | if (max_pixclk < 0) |
5972 | return max_pixclk; | |
85a96e7a | 5973 | |
27c329ed ML |
5974 | to_intel_atomic_state(state)->cdclk = |
5975 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
85a96e7a | 5976 | |
27c329ed | 5977 | return 0; |
30a970c6 JB |
5978 | } |
5979 | ||
1e69cd74 VS |
5980 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
5981 | { | |
5982 | unsigned int credits, default_credits; | |
5983 | ||
5984 | if (IS_CHERRYVIEW(dev_priv)) | |
5985 | default_credits = PFI_CREDIT(12); | |
5986 | else | |
5987 | default_credits = PFI_CREDIT(8); | |
5988 | ||
bfa7df01 | 5989 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
5990 | /* CHV suggested value is 31 or 63 */ |
5991 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 5992 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
5993 | else |
5994 | credits = PFI_CREDIT(15); | |
5995 | } else { | |
5996 | credits = default_credits; | |
5997 | } | |
5998 | ||
5999 | /* | |
6000 | * WA - write default credits before re-programming | |
6001 | * FIXME: should we also set the resend bit here? | |
6002 | */ | |
6003 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6004 | default_credits); | |
6005 | ||
6006 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6007 | credits | PFI_CREDIT_RESEND); | |
6008 | ||
6009 | /* | |
6010 | * FIXME is this guaranteed to clear | |
6011 | * immediately or should we poll for it? | |
6012 | */ | |
6013 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6014 | } | |
6015 | ||
27c329ed | 6016 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6017 | { |
a821fc46 | 6018 | struct drm_device *dev = old_state->dev; |
27c329ed | 6019 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
30a970c6 | 6020 | struct drm_i915_private *dev_priv = dev->dev_private; |
30a970c6 | 6021 | |
27c329ed ML |
6022 | /* |
6023 | * FIXME: We can end up here with all power domains off, yet | |
6024 | * with a CDCLK frequency other than the minimum. To account | |
6025 | * for this take the PIPE-A power domain, which covers the HW | |
6026 | * blocks needed for the following programming. This can be | |
6027 | * removed once it's guaranteed that we get here either with | |
6028 | * the minimum CDCLK set, or the required power domains | |
6029 | * enabled. | |
6030 | */ | |
6031 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6032 | |
27c329ed ML |
6033 | if (IS_CHERRYVIEW(dev)) |
6034 | cherryview_set_cdclk(dev, req_cdclk); | |
6035 | else | |
6036 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6037 | |
27c329ed | 6038 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6039 | |
27c329ed | 6040 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6041 | } |
6042 | ||
89b667f8 JB |
6043 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6044 | { | |
6045 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6046 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6047 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6048 | struct intel_encoder *encoder; | |
6049 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6050 | bool is_dsi; |
89b667f8 | 6051 | |
53d9f4e9 | 6052 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6053 | return; |
6054 | ||
409ee761 | 6055 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6056 | |
6e3c9717 | 6057 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6058 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6059 | |
6060 | intel_set_pipe_timings(intel_crtc); | |
6061 | ||
c14b0485 VS |
6062 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6063 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6064 | ||
6065 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6066 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6067 | } | |
6068 | ||
5b18e57c DV |
6069 | i9xx_set_pipeconf(intel_crtc); |
6070 | ||
89b667f8 | 6071 | intel_crtc->active = true; |
89b667f8 | 6072 | |
a72e4c9f | 6073 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6074 | |
89b667f8 JB |
6075 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6076 | if (encoder->pre_pll_enable) | |
6077 | encoder->pre_pll_enable(encoder); | |
6078 | ||
9d556c99 | 6079 | if (!is_dsi) { |
c0b4c660 VS |
6080 | if (IS_CHERRYVIEW(dev)) { |
6081 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6082 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6083 | } else { |
6084 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6085 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6086 | } |
9d556c99 | 6087 | } |
89b667f8 JB |
6088 | |
6089 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6090 | if (encoder->pre_enable) | |
6091 | encoder->pre_enable(encoder); | |
6092 | ||
2dd24552 JB |
6093 | i9xx_pfit_enable(intel_crtc); |
6094 | ||
63cbb074 VS |
6095 | intel_crtc_load_lut(crtc); |
6096 | ||
e1fdc473 | 6097 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6098 | |
4b3a9526 VS |
6099 | assert_vblank_disabled(crtc); |
6100 | drm_crtc_vblank_on(crtc); | |
6101 | ||
f9b61ff6 DV |
6102 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6103 | encoder->enable(encoder); | |
89b667f8 JB |
6104 | } |
6105 | ||
f13c2ef3 DV |
6106 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6107 | { | |
6108 | struct drm_device *dev = crtc->base.dev; | |
6109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6110 | ||
6e3c9717 ACO |
6111 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6112 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6113 | } |
6114 | ||
0b8765c6 | 6115 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6116 | { |
6117 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6118 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6119 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6120 | struct intel_encoder *encoder; |
79e53945 | 6121 | int pipe = intel_crtc->pipe; |
79e53945 | 6122 | |
53d9f4e9 | 6123 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6124 | return; |
6125 | ||
f13c2ef3 DV |
6126 | i9xx_set_pll_dividers(intel_crtc); |
6127 | ||
6e3c9717 | 6128 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6129 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6130 | |
6131 | intel_set_pipe_timings(intel_crtc); | |
6132 | ||
5b18e57c DV |
6133 | i9xx_set_pipeconf(intel_crtc); |
6134 | ||
f7abfe8b | 6135 | intel_crtc->active = true; |
6b383a7f | 6136 | |
4a3436e8 | 6137 | if (!IS_GEN2(dev)) |
a72e4c9f | 6138 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6139 | |
9d6d9f19 MK |
6140 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6141 | if (encoder->pre_enable) | |
6142 | encoder->pre_enable(encoder); | |
6143 | ||
f6736a1a DV |
6144 | i9xx_enable_pll(intel_crtc); |
6145 | ||
2dd24552 JB |
6146 | i9xx_pfit_enable(intel_crtc); |
6147 | ||
63cbb074 VS |
6148 | intel_crtc_load_lut(crtc); |
6149 | ||
f37fcc2a | 6150 | intel_update_watermarks(crtc); |
e1fdc473 | 6151 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6152 | |
4b3a9526 VS |
6153 | assert_vblank_disabled(crtc); |
6154 | drm_crtc_vblank_on(crtc); | |
6155 | ||
f9b61ff6 DV |
6156 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6157 | encoder->enable(encoder); | |
0b8765c6 | 6158 | } |
79e53945 | 6159 | |
87476d63 DV |
6160 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6161 | { | |
6162 | struct drm_device *dev = crtc->base.dev; | |
6163 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6164 | |
6e3c9717 | 6165 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6166 | return; |
87476d63 | 6167 | |
328d8e82 | 6168 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6169 | |
328d8e82 DV |
6170 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6171 | I915_READ(PFIT_CONTROL)); | |
6172 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6173 | } |
6174 | ||
0b8765c6 JB |
6175 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6176 | { | |
6177 | struct drm_device *dev = crtc->dev; | |
6178 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6180 | struct intel_encoder *encoder; |
0b8765c6 | 6181 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6182 | |
6304cd91 VS |
6183 | /* |
6184 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6185 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6186 | * We also need to wait on all gmch platforms because of the |
6187 | * self-refresh mode constraint explained above. | |
6304cd91 | 6188 | */ |
564ed191 | 6189 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6190 | |
4b3a9526 VS |
6191 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6192 | encoder->disable(encoder); | |
6193 | ||
f9b61ff6 DV |
6194 | drm_crtc_vblank_off(crtc); |
6195 | assert_vblank_disabled(crtc); | |
6196 | ||
575f7ab7 | 6197 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6198 | |
87476d63 | 6199 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6200 | |
89b667f8 JB |
6201 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6202 | if (encoder->post_disable) | |
6203 | encoder->post_disable(encoder); | |
6204 | ||
409ee761 | 6205 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6206 | if (IS_CHERRYVIEW(dev)) |
6207 | chv_disable_pll(dev_priv, pipe); | |
6208 | else if (IS_VALLEYVIEW(dev)) | |
6209 | vlv_disable_pll(dev_priv, pipe); | |
6210 | else | |
1c4e0274 | 6211 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6212 | } |
0b8765c6 | 6213 | |
d6db995f VS |
6214 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6215 | if (encoder->post_pll_disable) | |
6216 | encoder->post_pll_disable(encoder); | |
6217 | ||
4a3436e8 | 6218 | if (!IS_GEN2(dev)) |
a72e4c9f | 6219 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
0b8765c6 JB |
6220 | } |
6221 | ||
b17d48e2 ML |
6222 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6223 | { | |
6224 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6225 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6226 | enum intel_display_power_domain domain; | |
6227 | unsigned long domains; | |
6228 | ||
6229 | if (!intel_crtc->active) | |
6230 | return; | |
6231 | ||
a539205a | 6232 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
fc32b1fd ML |
6233 | WARN_ON(intel_crtc->unpin_work); |
6234 | ||
a539205a ML |
6235 | intel_pre_disable_primary(crtc); |
6236 | } | |
6237 | ||
d032ffa0 | 6238 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 | 6239 | dev_priv->display.crtc_disable(crtc); |
37d9078b MR |
6240 | intel_crtc->active = false; |
6241 | intel_update_watermarks(crtc); | |
1f7457b1 | 6242 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6243 | |
6244 | domains = intel_crtc->enabled_power_domains; | |
6245 | for_each_power_domain(domain, domains) | |
6246 | intel_display_power_put(dev_priv, domain); | |
6247 | intel_crtc->enabled_power_domains = 0; | |
6248 | } | |
6249 | ||
6b72d486 ML |
6250 | /* |
6251 | * turn all crtc's off, but do not adjust state | |
6252 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6253 | */ | |
70e0bd74 | 6254 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6255 | { |
70e0bd74 ML |
6256 | struct drm_mode_config *config = &dev->mode_config; |
6257 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
6258 | struct drm_atomic_state *state; | |
6b72d486 | 6259 | struct drm_crtc *crtc; |
70e0bd74 ML |
6260 | unsigned crtc_mask = 0; |
6261 | int ret = 0; | |
6262 | ||
6263 | if (WARN_ON(!ctx)) | |
6264 | return 0; | |
6265 | ||
6266 | lockdep_assert_held(&ctx->ww_ctx); | |
6267 | state = drm_atomic_state_alloc(dev); | |
6268 | if (WARN_ON(!state)) | |
6269 | return -ENOMEM; | |
6270 | ||
6271 | state->acquire_ctx = ctx; | |
6272 | state->allow_modeset = true; | |
6273 | ||
6274 | for_each_crtc(dev, crtc) { | |
6275 | struct drm_crtc_state *crtc_state = | |
6276 | drm_atomic_get_crtc_state(state, crtc); | |
6b72d486 | 6277 | |
70e0bd74 ML |
6278 | ret = PTR_ERR_OR_ZERO(crtc_state); |
6279 | if (ret) | |
6280 | goto free; | |
6281 | ||
6282 | if (!crtc_state->active) | |
6283 | continue; | |
6284 | ||
6285 | crtc_state->active = false; | |
6286 | crtc_mask |= 1 << drm_crtc_index(crtc); | |
6287 | } | |
6288 | ||
6289 | if (crtc_mask) { | |
74c090b1 | 6290 | ret = drm_atomic_commit(state); |
70e0bd74 ML |
6291 | |
6292 | if (!ret) { | |
6293 | for_each_crtc(dev, crtc) | |
6294 | if (crtc_mask & (1 << drm_crtc_index(crtc))) | |
6295 | crtc->state->active = true; | |
6296 | ||
6297 | return ret; | |
6298 | } | |
6299 | } | |
6300 | ||
6301 | free: | |
6302 | if (ret) | |
6303 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6304 | drm_atomic_state_free(state); | |
6305 | return ret; | |
ee7b9f93 JB |
6306 | } |
6307 | ||
ea5b213a | 6308 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6309 | { |
4ef69c7a | 6310 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6311 | |
ea5b213a CW |
6312 | drm_encoder_cleanup(encoder); |
6313 | kfree(intel_encoder); | |
7e7d76c3 JB |
6314 | } |
6315 | ||
0a91ca29 DV |
6316 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6317 | * internal consistency). */ | |
b980514c | 6318 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6319 | { |
35dd3c64 ML |
6320 | struct drm_crtc *crtc = connector->base.state->crtc; |
6321 | ||
6322 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6323 | connector->base.base.id, | |
6324 | connector->base.name); | |
6325 | ||
0a91ca29 | 6326 | if (connector->get_hw_state(connector)) { |
e85376cb | 6327 | struct intel_encoder *encoder = connector->encoder; |
35dd3c64 | 6328 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6329 | |
35dd3c64 ML |
6330 | I915_STATE_WARN(!crtc, |
6331 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6332 | |
35dd3c64 ML |
6333 | if (!crtc) |
6334 | return; | |
6335 | ||
6336 | I915_STATE_WARN(!crtc->state->active, | |
6337 | "connector is active, but attached crtc isn't\n"); | |
6338 | ||
e85376cb | 6339 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6340 | return; |
6341 | ||
e85376cb | 6342 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6343 | "atomic encoder doesn't match attached encoder\n"); |
6344 | ||
e85376cb | 6345 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6346 | "attached encoder crtc differs from connector crtc\n"); |
6347 | } else { | |
4d688a2a ML |
6348 | I915_STATE_WARN(crtc && crtc->state->active, |
6349 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6350 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6351 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6352 | } |
79e53945 JB |
6353 | } |
6354 | ||
08d9bc92 ACO |
6355 | int intel_connector_init(struct intel_connector *connector) |
6356 | { | |
6357 | struct drm_connector_state *connector_state; | |
6358 | ||
6359 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6360 | if (!connector_state) | |
6361 | return -ENOMEM; | |
6362 | ||
6363 | connector->base.state = connector_state; | |
6364 | return 0; | |
6365 | } | |
6366 | ||
6367 | struct intel_connector *intel_connector_alloc(void) | |
6368 | { | |
6369 | struct intel_connector *connector; | |
6370 | ||
6371 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6372 | if (!connector) | |
6373 | return NULL; | |
6374 | ||
6375 | if (intel_connector_init(connector) < 0) { | |
6376 | kfree(connector); | |
6377 | return NULL; | |
6378 | } | |
6379 | ||
6380 | return connector; | |
6381 | } | |
6382 | ||
f0947c37 DV |
6383 | /* Simple connector->get_hw_state implementation for encoders that support only |
6384 | * one connector and no cloning and hence the encoder state determines the state | |
6385 | * of the connector. */ | |
6386 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6387 | { |
24929352 | 6388 | enum pipe pipe = 0; |
f0947c37 | 6389 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6390 | |
f0947c37 | 6391 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6392 | } |
6393 | ||
6d293983 | 6394 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6395 | { |
6d293983 ACO |
6396 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6397 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6398 | |
6399 | return 0; | |
6400 | } | |
6401 | ||
6d293983 | 6402 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6403 | struct intel_crtc_state *pipe_config) |
1857e1da | 6404 | { |
6d293983 ACO |
6405 | struct drm_atomic_state *state = pipe_config->base.state; |
6406 | struct intel_crtc *other_crtc; | |
6407 | struct intel_crtc_state *other_crtc_state; | |
6408 | ||
1857e1da DV |
6409 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6410 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6411 | if (pipe_config->fdi_lanes > 4) { | |
6412 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6413 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6414 | return -EINVAL; |
1857e1da DV |
6415 | } |
6416 | ||
bafb6553 | 6417 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6418 | if (pipe_config->fdi_lanes > 2) { |
6419 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6420 | pipe_config->fdi_lanes); | |
6d293983 | 6421 | return -EINVAL; |
1857e1da | 6422 | } else { |
6d293983 | 6423 | return 0; |
1857e1da DV |
6424 | } |
6425 | } | |
6426 | ||
6427 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6428 | return 0; |
1857e1da DV |
6429 | |
6430 | /* Ivybridge 3 pipe is really complicated */ | |
6431 | switch (pipe) { | |
6432 | case PIPE_A: | |
6d293983 | 6433 | return 0; |
1857e1da | 6434 | case PIPE_B: |
6d293983 ACO |
6435 | if (pipe_config->fdi_lanes <= 2) |
6436 | return 0; | |
6437 | ||
6438 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6439 | other_crtc_state = | |
6440 | intel_atomic_get_crtc_state(state, other_crtc); | |
6441 | if (IS_ERR(other_crtc_state)) | |
6442 | return PTR_ERR(other_crtc_state); | |
6443 | ||
6444 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6445 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6446 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6447 | return -EINVAL; |
1857e1da | 6448 | } |
6d293983 | 6449 | return 0; |
1857e1da | 6450 | case PIPE_C: |
251cc67c VS |
6451 | if (pipe_config->fdi_lanes > 2) { |
6452 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6453 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6454 | return -EINVAL; |
251cc67c | 6455 | } |
6d293983 ACO |
6456 | |
6457 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6458 | other_crtc_state = | |
6459 | intel_atomic_get_crtc_state(state, other_crtc); | |
6460 | if (IS_ERR(other_crtc_state)) | |
6461 | return PTR_ERR(other_crtc_state); | |
6462 | ||
6463 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6464 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6465 | return -EINVAL; |
1857e1da | 6466 | } |
6d293983 | 6467 | return 0; |
1857e1da DV |
6468 | default: |
6469 | BUG(); | |
6470 | } | |
6471 | } | |
6472 | ||
e29c22c0 DV |
6473 | #define RETRY 1 |
6474 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6475 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6476 | { |
1857e1da | 6477 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6478 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6479 | int lane, link_bw, fdi_dotclock, ret; |
6480 | bool needs_recompute = false; | |
877d48d5 | 6481 | |
e29c22c0 | 6482 | retry: |
877d48d5 DV |
6483 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6484 | * each output octet as 10 bits. The actual frequency | |
6485 | * is stored as a divider into a 100MHz clock, and the | |
6486 | * mode pixel clock is stored in units of 1KHz. | |
6487 | * Hence the bw of each lane in terms of the mode signal | |
6488 | * is: | |
6489 | */ | |
6490 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6491 | ||
241bfc38 | 6492 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6493 | |
2bd89a07 | 6494 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6495 | pipe_config->pipe_bpp); |
6496 | ||
6497 | pipe_config->fdi_lanes = lane; | |
6498 | ||
2bd89a07 | 6499 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6500 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6501 | |
6d293983 ACO |
6502 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6503 | intel_crtc->pipe, pipe_config); | |
6504 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6505 | pipe_config->pipe_bpp -= 2*3; |
6506 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6507 | pipe_config->pipe_bpp); | |
6508 | needs_recompute = true; | |
6509 | pipe_config->bw_constrained = true; | |
6510 | ||
6511 | goto retry; | |
6512 | } | |
6513 | ||
6514 | if (needs_recompute) | |
6515 | return RETRY; | |
6516 | ||
6d293983 | 6517 | return ret; |
877d48d5 DV |
6518 | } |
6519 | ||
8cfb3407 VS |
6520 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6521 | struct intel_crtc_state *pipe_config) | |
6522 | { | |
6523 | if (pipe_config->pipe_bpp > 24) | |
6524 | return false; | |
6525 | ||
6526 | /* HSW can handle pixel rate up to cdclk? */ | |
6527 | if (IS_HASWELL(dev_priv->dev)) | |
6528 | return true; | |
6529 | ||
6530 | /* | |
b432e5cf VS |
6531 | * We compare against max which means we must take |
6532 | * the increased cdclk requirement into account when | |
6533 | * calculating the new cdclk. | |
6534 | * | |
6535 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6536 | */ |
6537 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6538 | dev_priv->max_cdclk_freq * 95 / 100; | |
6539 | } | |
6540 | ||
42db64ef | 6541 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6542 | struct intel_crtc_state *pipe_config) |
42db64ef | 6543 | { |
8cfb3407 VS |
6544 | struct drm_device *dev = crtc->base.dev; |
6545 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6546 | ||
d330a953 | 6547 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6548 | hsw_crtc_supports_ips(crtc) && |
6549 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6550 | } |
6551 | ||
39acb4aa VS |
6552 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6553 | { | |
6554 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6555 | ||
6556 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6557 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6558 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6559 | } | |
6560 | ||
a43f6e0f | 6561 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6562 | struct intel_crtc_state *pipe_config) |
79e53945 | 6563 | { |
a43f6e0f | 6564 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6565 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6566 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6567 | |
ad3a4479 | 6568 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6569 | if (INTEL_INFO(dev)->gen < 4) { |
39acb4aa | 6570 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6571 | |
6572 | /* | |
39acb4aa | 6573 | * Enable double wide mode when the dot clock |
cf532bb2 | 6574 | * is > 90% of the (display) core speed. |
cf532bb2 | 6575 | */ |
39acb4aa VS |
6576 | if (intel_crtc_supports_double_wide(crtc) && |
6577 | adjusted_mode->crtc_clock > clock_limit) { | |
ad3a4479 | 6578 | clock_limit *= 2; |
cf532bb2 | 6579 | pipe_config->double_wide = true; |
ad3a4479 VS |
6580 | } |
6581 | ||
39acb4aa VS |
6582 | if (adjusted_mode->crtc_clock > clock_limit) { |
6583 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6584 | adjusted_mode->crtc_clock, clock_limit, | |
6585 | yesno(pipe_config->double_wide)); | |
e29c22c0 | 6586 | return -EINVAL; |
39acb4aa | 6587 | } |
2c07245f | 6588 | } |
89749350 | 6589 | |
1d1d0e27 VS |
6590 | /* |
6591 | * Pipe horizontal size must be even in: | |
6592 | * - DVO ganged mode | |
6593 | * - LVDS dual channel mode | |
6594 | * - Double wide pipe | |
6595 | */ | |
a93e255f | 6596 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6597 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6598 | pipe_config->pipe_src_w &= ~1; | |
6599 | ||
8693a824 DL |
6600 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6601 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6602 | */ |
6603 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6604 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6605 | return -EINVAL; |
44f46b42 | 6606 | |
f5adf94e | 6607 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6608 | hsw_compute_ips_config(crtc, pipe_config); |
6609 | ||
877d48d5 | 6610 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6611 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6612 | |
cf5a15be | 6613 | return 0; |
79e53945 JB |
6614 | } |
6615 | ||
1652d19e VS |
6616 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6617 | { | |
6618 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6619 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6620 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6621 | uint32_t linkrate; | |
6622 | ||
414355a7 | 6623 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6624 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6625 | |
6626 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6627 | return 540000; | |
6628 | ||
6629 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6630 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6631 | |
71cd8423 DL |
6632 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6633 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6634 | /* vco 8640 */ |
6635 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6636 | case CDCLK_FREQ_450_432: | |
6637 | return 432000; | |
6638 | case CDCLK_FREQ_337_308: | |
6639 | return 308570; | |
6640 | case CDCLK_FREQ_675_617: | |
6641 | return 617140; | |
6642 | default: | |
6643 | WARN(1, "Unknown cd freq selection\n"); | |
6644 | } | |
6645 | } else { | |
6646 | /* vco 8100 */ | |
6647 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6648 | case CDCLK_FREQ_450_432: | |
6649 | return 450000; | |
6650 | case CDCLK_FREQ_337_308: | |
6651 | return 337500; | |
6652 | case CDCLK_FREQ_675_617: | |
6653 | return 675000; | |
6654 | default: | |
6655 | WARN(1, "Unknown cd freq selection\n"); | |
6656 | } | |
6657 | } | |
6658 | ||
6659 | /* error case, do as if DPLL0 isn't enabled */ | |
6660 | return 24000; | |
6661 | } | |
6662 | ||
acd3f3d3 BP |
6663 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6664 | { | |
6665 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6666 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6667 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6668 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6669 | int cdclk; | |
6670 | ||
6671 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6672 | return 19200; | |
6673 | ||
6674 | cdclk = 19200 * pll_ratio / 2; | |
6675 | ||
6676 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6677 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6678 | return cdclk; /* 576MHz or 624MHz */ | |
6679 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6680 | return cdclk * 2 / 3; /* 384MHz */ | |
6681 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6682 | return cdclk / 2; /* 288MHz */ | |
6683 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6684 | return cdclk / 4; /* 144MHz */ | |
6685 | } | |
6686 | ||
6687 | /* error case, do as if DE PLL isn't enabled */ | |
6688 | return 19200; | |
6689 | } | |
6690 | ||
1652d19e VS |
6691 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6692 | { | |
6693 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6694 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6695 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6696 | ||
6697 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6698 | return 800000; | |
6699 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6700 | return 450000; | |
6701 | else if (freq == LCPLL_CLK_FREQ_450) | |
6702 | return 450000; | |
6703 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6704 | return 540000; | |
6705 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6706 | return 337500; | |
6707 | else | |
6708 | return 675000; | |
6709 | } | |
6710 | ||
6711 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6712 | { | |
6713 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6714 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6715 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6716 | ||
6717 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6718 | return 800000; | |
6719 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6720 | return 450000; | |
6721 | else if (freq == LCPLL_CLK_FREQ_450) | |
6722 | return 450000; | |
6723 | else if (IS_HSW_ULT(dev)) | |
6724 | return 337500; | |
6725 | else | |
6726 | return 540000; | |
79e53945 JB |
6727 | } |
6728 | ||
25eb05fc JB |
6729 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6730 | { | |
bfa7df01 VS |
6731 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6732 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6733 | } |
6734 | ||
b37a6434 VS |
6735 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6736 | { | |
6737 | return 450000; | |
6738 | } | |
6739 | ||
e70236a8 JB |
6740 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6741 | { | |
6742 | return 400000; | |
6743 | } | |
79e53945 | 6744 | |
e70236a8 | 6745 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6746 | { |
e907f170 | 6747 | return 333333; |
e70236a8 | 6748 | } |
79e53945 | 6749 | |
e70236a8 JB |
6750 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6751 | { | |
6752 | return 200000; | |
6753 | } | |
79e53945 | 6754 | |
257a7ffc DV |
6755 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6756 | { | |
6757 | u16 gcfgc = 0; | |
6758 | ||
6759 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6760 | ||
6761 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6762 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6763 | return 266667; |
257a7ffc | 6764 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6765 | return 333333; |
257a7ffc | 6766 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6767 | return 444444; |
257a7ffc DV |
6768 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6769 | return 200000; | |
6770 | default: | |
6771 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6772 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6773 | return 133333; |
257a7ffc | 6774 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6775 | return 166667; |
257a7ffc DV |
6776 | } |
6777 | } | |
6778 | ||
e70236a8 JB |
6779 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6780 | { | |
6781 | u16 gcfgc = 0; | |
79e53945 | 6782 | |
e70236a8 JB |
6783 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6784 | ||
6785 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6786 | return 133333; |
e70236a8 JB |
6787 | else { |
6788 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6789 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6790 | return 333333; |
e70236a8 JB |
6791 | default: |
6792 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6793 | return 190000; | |
79e53945 | 6794 | } |
e70236a8 JB |
6795 | } |
6796 | } | |
6797 | ||
6798 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6799 | { | |
e907f170 | 6800 | return 266667; |
e70236a8 JB |
6801 | } |
6802 | ||
1b1d2716 | 6803 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6804 | { |
6805 | u16 hpllcc = 0; | |
1b1d2716 | 6806 | |
65cd2b3f VS |
6807 | /* |
6808 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6809 | * encoding is different :( | |
6810 | * FIXME is this the right way to detect 852GM/852GMV? | |
6811 | */ | |
6812 | if (dev->pdev->revision == 0x1) | |
6813 | return 133333; | |
6814 | ||
1b1d2716 VS |
6815 | pci_bus_read_config_word(dev->pdev->bus, |
6816 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6817 | ||
e70236a8 JB |
6818 | /* Assume that the hardware is in the high speed state. This |
6819 | * should be the default. | |
6820 | */ | |
6821 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6822 | case GC_CLOCK_133_200: | |
1b1d2716 | 6823 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6824 | case GC_CLOCK_100_200: |
6825 | return 200000; | |
6826 | case GC_CLOCK_166_250: | |
6827 | return 250000; | |
6828 | case GC_CLOCK_100_133: | |
e907f170 | 6829 | return 133333; |
1b1d2716 VS |
6830 | case GC_CLOCK_133_266: |
6831 | case GC_CLOCK_133_266_2: | |
6832 | case GC_CLOCK_166_266: | |
6833 | return 266667; | |
e70236a8 | 6834 | } |
79e53945 | 6835 | |
e70236a8 JB |
6836 | /* Shouldn't happen */ |
6837 | return 0; | |
6838 | } | |
79e53945 | 6839 | |
e70236a8 JB |
6840 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6841 | { | |
e907f170 | 6842 | return 133333; |
79e53945 JB |
6843 | } |
6844 | ||
34edce2f VS |
6845 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6846 | { | |
6847 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6848 | static const unsigned int blb_vco[8] = { | |
6849 | [0] = 3200000, | |
6850 | [1] = 4000000, | |
6851 | [2] = 5333333, | |
6852 | [3] = 4800000, | |
6853 | [4] = 6400000, | |
6854 | }; | |
6855 | static const unsigned int pnv_vco[8] = { | |
6856 | [0] = 3200000, | |
6857 | [1] = 4000000, | |
6858 | [2] = 5333333, | |
6859 | [3] = 4800000, | |
6860 | [4] = 2666667, | |
6861 | }; | |
6862 | static const unsigned int cl_vco[8] = { | |
6863 | [0] = 3200000, | |
6864 | [1] = 4000000, | |
6865 | [2] = 5333333, | |
6866 | [3] = 6400000, | |
6867 | [4] = 3333333, | |
6868 | [5] = 3566667, | |
6869 | [6] = 4266667, | |
6870 | }; | |
6871 | static const unsigned int elk_vco[8] = { | |
6872 | [0] = 3200000, | |
6873 | [1] = 4000000, | |
6874 | [2] = 5333333, | |
6875 | [3] = 4800000, | |
6876 | }; | |
6877 | static const unsigned int ctg_vco[8] = { | |
6878 | [0] = 3200000, | |
6879 | [1] = 4000000, | |
6880 | [2] = 5333333, | |
6881 | [3] = 6400000, | |
6882 | [4] = 2666667, | |
6883 | [5] = 4266667, | |
6884 | }; | |
6885 | const unsigned int *vco_table; | |
6886 | unsigned int vco; | |
6887 | uint8_t tmp = 0; | |
6888 | ||
6889 | /* FIXME other chipsets? */ | |
6890 | if (IS_GM45(dev)) | |
6891 | vco_table = ctg_vco; | |
6892 | else if (IS_G4X(dev)) | |
6893 | vco_table = elk_vco; | |
6894 | else if (IS_CRESTLINE(dev)) | |
6895 | vco_table = cl_vco; | |
6896 | else if (IS_PINEVIEW(dev)) | |
6897 | vco_table = pnv_vco; | |
6898 | else if (IS_G33(dev)) | |
6899 | vco_table = blb_vco; | |
6900 | else | |
6901 | return 0; | |
6902 | ||
6903 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6904 | ||
6905 | vco = vco_table[tmp & 0x7]; | |
6906 | if (vco == 0) | |
6907 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6908 | else | |
6909 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6910 | ||
6911 | return vco; | |
6912 | } | |
6913 | ||
6914 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
6915 | { | |
6916 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6917 | uint16_t tmp = 0; | |
6918 | ||
6919 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6920 | ||
6921 | cdclk_sel = (tmp >> 12) & 0x1; | |
6922 | ||
6923 | switch (vco) { | |
6924 | case 2666667: | |
6925 | case 4000000: | |
6926 | case 5333333: | |
6927 | return cdclk_sel ? 333333 : 222222; | |
6928 | case 3200000: | |
6929 | return cdclk_sel ? 320000 : 228571; | |
6930 | default: | |
6931 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
6932 | return 222222; | |
6933 | } | |
6934 | } | |
6935 | ||
6936 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
6937 | { | |
6938 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
6939 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
6940 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
6941 | const uint8_t *div_table; | |
6942 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6943 | uint16_t tmp = 0; | |
6944 | ||
6945 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6946 | ||
6947 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
6948 | ||
6949 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6950 | goto fail; | |
6951 | ||
6952 | switch (vco) { | |
6953 | case 3200000: | |
6954 | div_table = div_3200; | |
6955 | break; | |
6956 | case 4000000: | |
6957 | div_table = div_4000; | |
6958 | break; | |
6959 | case 5333333: | |
6960 | div_table = div_5333; | |
6961 | break; | |
6962 | default: | |
6963 | goto fail; | |
6964 | } | |
6965 | ||
6966 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
6967 | ||
caf4e252 | 6968 | fail: |
34edce2f VS |
6969 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
6970 | return 200000; | |
6971 | } | |
6972 | ||
6973 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
6974 | { | |
6975 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
6976 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
6977 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
6978 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
6979 | const uint8_t *div_table; | |
6980 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6981 | uint16_t tmp = 0; | |
6982 | ||
6983 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6984 | ||
6985 | cdclk_sel = (tmp >> 4) & 0x7; | |
6986 | ||
6987 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6988 | goto fail; | |
6989 | ||
6990 | switch (vco) { | |
6991 | case 3200000: | |
6992 | div_table = div_3200; | |
6993 | break; | |
6994 | case 4000000: | |
6995 | div_table = div_4000; | |
6996 | break; | |
6997 | case 4800000: | |
6998 | div_table = div_4800; | |
6999 | break; | |
7000 | case 5333333: | |
7001 | div_table = div_5333; | |
7002 | break; | |
7003 | default: | |
7004 | goto fail; | |
7005 | } | |
7006 | ||
7007 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7008 | ||
caf4e252 | 7009 | fail: |
34edce2f VS |
7010 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7011 | return 190476; | |
7012 | } | |
7013 | ||
2c07245f | 7014 | static void |
a65851af | 7015 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7016 | { |
a65851af VS |
7017 | while (*num > DATA_LINK_M_N_MASK || |
7018 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7019 | *num >>= 1; |
7020 | *den >>= 1; | |
7021 | } | |
7022 | } | |
7023 | ||
a65851af VS |
7024 | static void compute_m_n(unsigned int m, unsigned int n, |
7025 | uint32_t *ret_m, uint32_t *ret_n) | |
7026 | { | |
7027 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7028 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7029 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7030 | } | |
7031 | ||
e69d0bc1 DV |
7032 | void |
7033 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7034 | int pixel_clock, int link_clock, | |
7035 | struct intel_link_m_n *m_n) | |
2c07245f | 7036 | { |
e69d0bc1 | 7037 | m_n->tu = 64; |
a65851af VS |
7038 | |
7039 | compute_m_n(bits_per_pixel * pixel_clock, | |
7040 | link_clock * nlanes * 8, | |
7041 | &m_n->gmch_m, &m_n->gmch_n); | |
7042 | ||
7043 | compute_m_n(pixel_clock, link_clock, | |
7044 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7045 | } |
7046 | ||
a7615030 CW |
7047 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7048 | { | |
d330a953 JN |
7049 | if (i915.panel_use_ssc >= 0) |
7050 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7051 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7052 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7053 | } |
7054 | ||
a93e255f ACO |
7055 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7056 | int num_connectors) | |
c65d77d8 | 7057 | { |
a93e255f | 7058 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7059 | struct drm_i915_private *dev_priv = dev->dev_private; |
7060 | int refclk; | |
7061 | ||
a93e255f ACO |
7062 | WARN_ON(!crtc_state->base.state); |
7063 | ||
5ab7b0b7 | 7064 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7065 | refclk = 100000; |
a93e255f | 7066 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7067 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7068 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7069 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7070 | } else if (!IS_GEN2(dev)) { |
7071 | refclk = 96000; | |
7072 | } else { | |
7073 | refclk = 48000; | |
7074 | } | |
7075 | ||
7076 | return refclk; | |
7077 | } | |
7078 | ||
7429e9d4 | 7079 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7080 | { |
7df00d7a | 7081 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7082 | } |
f47709a9 | 7083 | |
7429e9d4 DV |
7084 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7085 | { | |
7086 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7087 | } |
7088 | ||
f47709a9 | 7089 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7090 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7091 | intel_clock_t *reduced_clock) |
7092 | { | |
f47709a9 | 7093 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7094 | u32 fp, fp2 = 0; |
7095 | ||
7096 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7097 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7098 | if (reduced_clock) |
7429e9d4 | 7099 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7100 | } else { |
190f68c5 | 7101 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7102 | if (reduced_clock) |
7429e9d4 | 7103 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7104 | } |
7105 | ||
190f68c5 | 7106 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7107 | |
f47709a9 | 7108 | crtc->lowfreq_avail = false; |
a93e255f | 7109 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7110 | reduced_clock) { |
190f68c5 | 7111 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7112 | crtc->lowfreq_avail = true; |
a7516a05 | 7113 | } else { |
190f68c5 | 7114 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7115 | } |
7116 | } | |
7117 | ||
5e69f97f CML |
7118 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7119 | pipe) | |
89b667f8 JB |
7120 | { |
7121 | u32 reg_val; | |
7122 | ||
7123 | /* | |
7124 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7125 | * and set it to a reasonable value instead. | |
7126 | */ | |
ab3c759a | 7127 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7128 | reg_val &= 0xffffff00; |
7129 | reg_val |= 0x00000030; | |
ab3c759a | 7130 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7131 | |
ab3c759a | 7132 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7133 | reg_val &= 0x8cffffff; |
7134 | reg_val = 0x8c000000; | |
ab3c759a | 7135 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7136 | |
ab3c759a | 7137 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7138 | reg_val &= 0xffffff00; |
ab3c759a | 7139 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7140 | |
ab3c759a | 7141 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7142 | reg_val &= 0x00ffffff; |
7143 | reg_val |= 0xb0000000; | |
ab3c759a | 7144 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7145 | } |
7146 | ||
b551842d DV |
7147 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7148 | struct intel_link_m_n *m_n) | |
7149 | { | |
7150 | struct drm_device *dev = crtc->base.dev; | |
7151 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7152 | int pipe = crtc->pipe; | |
7153 | ||
e3b95f1e DV |
7154 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7155 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7156 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7157 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7158 | } |
7159 | ||
7160 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7161 | struct intel_link_m_n *m_n, |
7162 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7163 | { |
7164 | struct drm_device *dev = crtc->base.dev; | |
7165 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7166 | int pipe = crtc->pipe; | |
6e3c9717 | 7167 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7168 | |
7169 | if (INTEL_INFO(dev)->gen >= 5) { | |
7170 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7171 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7172 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7173 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7174 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7175 | * for gen < 8) and if DRRS is supported (to make sure the | |
7176 | * registers are not unnecessarily accessed). | |
7177 | */ | |
44395bfe | 7178 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7179 | crtc->config->has_drrs) { |
f769cd24 VK |
7180 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7181 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7182 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7183 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7184 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7185 | } | |
b551842d | 7186 | } else { |
e3b95f1e DV |
7187 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7188 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7189 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7190 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7191 | } |
7192 | } | |
7193 | ||
fe3cd48d | 7194 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7195 | { |
fe3cd48d R |
7196 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7197 | ||
7198 | if (m_n == M1_N1) { | |
7199 | dp_m_n = &crtc->config->dp_m_n; | |
7200 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7201 | } else if (m_n == M2_N2) { | |
7202 | ||
7203 | /* | |
7204 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7205 | * needs to be programmed into M1_N1. | |
7206 | */ | |
7207 | dp_m_n = &crtc->config->dp_m2_n2; | |
7208 | } else { | |
7209 | DRM_ERROR("Unsupported divider value\n"); | |
7210 | return; | |
7211 | } | |
7212 | ||
6e3c9717 ACO |
7213 | if (crtc->config->has_pch_encoder) |
7214 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7215 | else |
fe3cd48d | 7216 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7217 | } |
7218 | ||
251ac862 DV |
7219 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7220 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7221 | { |
7222 | u32 dpll, dpll_md; | |
7223 | ||
7224 | /* | |
7225 | * Enable DPIO clock input. We should never disable the reference | |
7226 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7227 | * on it. | |
7228 | */ | |
60bfe44f VS |
7229 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7230 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7231 | /* We should never disable this, set it here for state tracking */ |
7232 | if (crtc->pipe == PIPE_B) | |
7233 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7234 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7235 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7236 | |
d288f65f | 7237 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7238 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7239 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7240 | } |
7241 | ||
d288f65f | 7242 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7243 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7244 | { |
f47709a9 | 7245 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7246 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7247 | int pipe = crtc->pipe; |
bdd4b6a6 | 7248 | u32 mdiv; |
a0c4da24 | 7249 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7250 | u32 coreclk, reg_val; |
a0c4da24 | 7251 | |
a580516d | 7252 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7253 | |
d288f65f VS |
7254 | bestn = pipe_config->dpll.n; |
7255 | bestm1 = pipe_config->dpll.m1; | |
7256 | bestm2 = pipe_config->dpll.m2; | |
7257 | bestp1 = pipe_config->dpll.p1; | |
7258 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7259 | |
89b667f8 JB |
7260 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7261 | ||
7262 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7263 | if (pipe == PIPE_B) |
5e69f97f | 7264 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7265 | |
7266 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7267 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7268 | |
7269 | /* Disable target IRef on PLL */ | |
ab3c759a | 7270 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7271 | reg_val &= 0x00ffffff; |
ab3c759a | 7272 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7273 | |
7274 | /* Disable fast lock */ | |
ab3c759a | 7275 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7276 | |
7277 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7278 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7279 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7280 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7281 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7282 | |
7283 | /* | |
7284 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7285 | * but we don't support that). | |
7286 | * Note: don't use the DAC post divider as it seems unstable. | |
7287 | */ | |
7288 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7289 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7290 | |
a0c4da24 | 7291 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7292 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7293 | |
89b667f8 | 7294 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7295 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7296 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7297 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7298 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7299 | 0x009f0003); |
89b667f8 | 7300 | else |
ab3c759a | 7301 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7302 | 0x00d0000f); |
7303 | ||
681a8504 | 7304 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7305 | /* Use SSC source */ |
bdd4b6a6 | 7306 | if (pipe == PIPE_A) |
ab3c759a | 7307 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7308 | 0x0df40000); |
7309 | else | |
ab3c759a | 7310 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7311 | 0x0df70000); |
7312 | } else { /* HDMI or VGA */ | |
7313 | /* Use bend source */ | |
bdd4b6a6 | 7314 | if (pipe == PIPE_A) |
ab3c759a | 7315 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7316 | 0x0df70000); |
7317 | else | |
ab3c759a | 7318 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7319 | 0x0df40000); |
7320 | } | |
a0c4da24 | 7321 | |
ab3c759a | 7322 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7323 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7324 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7325 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7326 | coreclk |= 0x01000000; |
ab3c759a | 7327 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7328 | |
ab3c759a | 7329 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7330 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7331 | } |
7332 | ||
251ac862 DV |
7333 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7334 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7335 | { |
60bfe44f VS |
7336 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7337 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7338 | DPLL_VCO_ENABLE; |
7339 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7340 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7341 | |
d288f65f VS |
7342 | pipe_config->dpll_hw_state.dpll_md = |
7343 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7344 | } |
7345 | ||
d288f65f | 7346 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7347 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7348 | { |
7349 | struct drm_device *dev = crtc->base.dev; | |
7350 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7351 | int pipe = crtc->pipe; | |
7352 | int dpll_reg = DPLL(crtc->pipe); | |
7353 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 7354 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7355 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7356 | u32 dpio_val; |
9cbe40c1 | 7357 | int vco; |
9d556c99 | 7358 | |
d288f65f VS |
7359 | bestn = pipe_config->dpll.n; |
7360 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7361 | bestm1 = pipe_config->dpll.m1; | |
7362 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7363 | bestp1 = pipe_config->dpll.p1; | |
7364 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7365 | vco = pipe_config->dpll.vco; |
a945ce7e | 7366 | dpio_val = 0; |
9cbe40c1 | 7367 | loopfilter = 0; |
9d556c99 CML |
7368 | |
7369 | /* | |
7370 | * Enable Refclk and SSC | |
7371 | */ | |
a11b0703 | 7372 | I915_WRITE(dpll_reg, |
d288f65f | 7373 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7374 | |
a580516d | 7375 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7376 | |
9d556c99 CML |
7377 | /* p1 and p2 divider */ |
7378 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7379 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7380 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7381 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7382 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7383 | ||
7384 | /* Feedback post-divider - m2 */ | |
7385 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7386 | ||
7387 | /* Feedback refclk divider - n and m1 */ | |
7388 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7389 | DPIO_CHV_M1_DIV_BY_2 | | |
7390 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7391 | ||
7392 | /* M2 fraction division */ | |
25a25dfc | 7393 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7394 | |
7395 | /* M2 fraction division enable */ | |
a945ce7e VP |
7396 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7397 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7398 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7399 | if (bestm2_frac) | |
7400 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7401 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7402 | |
de3a0fde VP |
7403 | /* Program digital lock detect threshold */ |
7404 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7405 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7406 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7407 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7408 | if (!bestm2_frac) | |
7409 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7410 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7411 | ||
9d556c99 | 7412 | /* Loop filter */ |
9cbe40c1 VP |
7413 | if (vco == 5400000) { |
7414 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7415 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7416 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7417 | tribuf_calcntr = 0x9; | |
7418 | } else if (vco <= 6200000) { | |
7419 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7420 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7421 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7422 | tribuf_calcntr = 0x9; | |
7423 | } else if (vco <= 6480000) { | |
7424 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7425 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7426 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7427 | tribuf_calcntr = 0x8; | |
7428 | } else { | |
7429 | /* Not supported. Apply the same limits as in the max case */ | |
7430 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7431 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7432 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7433 | tribuf_calcntr = 0; | |
7434 | } | |
9d556c99 CML |
7435 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7436 | ||
968040b2 | 7437 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7438 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7439 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7440 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7441 | ||
9d556c99 CML |
7442 | /* AFC Recal */ |
7443 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7444 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7445 | DPIO_AFC_RECAL); | |
7446 | ||
a580516d | 7447 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7448 | } |
7449 | ||
d288f65f VS |
7450 | /** |
7451 | * vlv_force_pll_on - forcibly enable just the PLL | |
7452 | * @dev_priv: i915 private structure | |
7453 | * @pipe: pipe PLL to enable | |
7454 | * @dpll: PLL configuration | |
7455 | * | |
7456 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7457 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7458 | * be enabled. | |
7459 | */ | |
7460 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7461 | const struct dpll *dpll) | |
7462 | { | |
7463 | struct intel_crtc *crtc = | |
7464 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7465 | struct intel_crtc_state pipe_config = { |
a93e255f | 7466 | .base.crtc = &crtc->base, |
d288f65f VS |
7467 | .pixel_multiplier = 1, |
7468 | .dpll = *dpll, | |
7469 | }; | |
7470 | ||
7471 | if (IS_CHERRYVIEW(dev)) { | |
251ac862 | 7472 | chv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7473 | chv_prepare_pll(crtc, &pipe_config); |
7474 | chv_enable_pll(crtc, &pipe_config); | |
7475 | } else { | |
251ac862 | 7476 | vlv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7477 | vlv_prepare_pll(crtc, &pipe_config); |
7478 | vlv_enable_pll(crtc, &pipe_config); | |
7479 | } | |
7480 | } | |
7481 | ||
7482 | /** | |
7483 | * vlv_force_pll_off - forcibly disable just the PLL | |
7484 | * @dev_priv: i915 private structure | |
7485 | * @pipe: pipe PLL to disable | |
7486 | * | |
7487 | * Disable the PLL for @pipe. To be used in cases where we need | |
7488 | * the PLL enabled even when @pipe is not going to be enabled. | |
7489 | */ | |
7490 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7491 | { | |
7492 | if (IS_CHERRYVIEW(dev)) | |
7493 | chv_disable_pll(to_i915(dev), pipe); | |
7494 | else | |
7495 | vlv_disable_pll(to_i915(dev), pipe); | |
7496 | } | |
7497 | ||
251ac862 DV |
7498 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7499 | struct intel_crtc_state *crtc_state, | |
7500 | intel_clock_t *reduced_clock, | |
7501 | int num_connectors) | |
eb1cbe48 | 7502 | { |
f47709a9 | 7503 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7504 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7505 | u32 dpll; |
7506 | bool is_sdvo; | |
190f68c5 | 7507 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7508 | |
190f68c5 | 7509 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7510 | |
a93e255f ACO |
7511 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7512 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7513 | |
7514 | dpll = DPLL_VGA_MODE_DIS; | |
7515 | ||
a93e255f | 7516 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7517 | dpll |= DPLLB_MODE_LVDS; |
7518 | else | |
7519 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7520 | |
ef1b460d | 7521 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7522 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7523 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7524 | } |
198a037f DV |
7525 | |
7526 | if (is_sdvo) | |
4a33e48d | 7527 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7528 | |
190f68c5 | 7529 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7530 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7531 | |
7532 | /* compute bitmask from p1 value */ | |
7533 | if (IS_PINEVIEW(dev)) | |
7534 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7535 | else { | |
7536 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7537 | if (IS_G4X(dev) && reduced_clock) | |
7538 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7539 | } | |
7540 | switch (clock->p2) { | |
7541 | case 5: | |
7542 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7543 | break; | |
7544 | case 7: | |
7545 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7546 | break; | |
7547 | case 10: | |
7548 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7549 | break; | |
7550 | case 14: | |
7551 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7552 | break; | |
7553 | } | |
7554 | if (INTEL_INFO(dev)->gen >= 4) | |
7555 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7556 | ||
190f68c5 | 7557 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7558 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7559 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7560 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7561 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7562 | else | |
7563 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7564 | ||
7565 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7566 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7567 | |
eb1cbe48 | 7568 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7569 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7570 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7571 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7572 | } |
7573 | } | |
7574 | ||
251ac862 DV |
7575 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7576 | struct intel_crtc_state *crtc_state, | |
7577 | intel_clock_t *reduced_clock, | |
7578 | int num_connectors) | |
eb1cbe48 | 7579 | { |
f47709a9 | 7580 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7581 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7582 | u32 dpll; |
190f68c5 | 7583 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7584 | |
190f68c5 | 7585 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7586 | |
eb1cbe48 DV |
7587 | dpll = DPLL_VGA_MODE_DIS; |
7588 | ||
a93e255f | 7589 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7590 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7591 | } else { | |
7592 | if (clock->p1 == 2) | |
7593 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7594 | else | |
7595 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7596 | if (clock->p2 == 4) | |
7597 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7598 | } | |
7599 | ||
a93e255f | 7600 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7601 | dpll |= DPLL_DVO_2X_MODE; |
7602 | ||
a93e255f | 7603 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7604 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7605 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7606 | else | |
7607 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7608 | ||
7609 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7610 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7611 | } |
7612 | ||
8a654f3b | 7613 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7614 | { |
7615 | struct drm_device *dev = intel_crtc->base.dev; | |
7616 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7617 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7618 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7619 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7620 | uint32_t crtc_vtotal, crtc_vblank_end; |
7621 | int vsyncshift = 0; | |
4d8a62ea DV |
7622 | |
7623 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7624 | * the hw state checker will get angry at the mismatch. */ | |
7625 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7626 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7627 | |
609aeaca | 7628 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7629 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7630 | crtc_vtotal -= 1; |
7631 | crtc_vblank_end -= 1; | |
609aeaca | 7632 | |
409ee761 | 7633 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7634 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7635 | else | |
7636 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7637 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7638 | if (vsyncshift < 0) |
7639 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7640 | } |
7641 | ||
7642 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7643 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7644 | |
fe2b8f9d | 7645 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7646 | (adjusted_mode->crtc_hdisplay - 1) | |
7647 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7648 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7649 | (adjusted_mode->crtc_hblank_start - 1) | |
7650 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7651 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7652 | (adjusted_mode->crtc_hsync_start - 1) | |
7653 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7654 | ||
fe2b8f9d | 7655 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7656 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7657 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7658 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7659 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7660 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7661 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7662 | (adjusted_mode->crtc_vsync_start - 1) | |
7663 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7664 | ||
b5e508d4 PZ |
7665 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7666 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7667 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7668 | * bits. */ | |
7669 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7670 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7671 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7672 | ||
b0e77b9c PZ |
7673 | /* pipesrc controls the size that is scaled from, which should |
7674 | * always be the user's requested size. | |
7675 | */ | |
7676 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7677 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7678 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7679 | } |
7680 | ||
1bd1bd80 | 7681 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7682 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7683 | { |
7684 | struct drm_device *dev = crtc->base.dev; | |
7685 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7686 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7687 | uint32_t tmp; | |
7688 | ||
7689 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7690 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7691 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7692 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7693 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7694 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7695 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7696 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7697 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7698 | |
7699 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7700 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7701 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7702 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7703 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7704 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7705 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7706 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7707 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7708 | |
7709 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7710 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7711 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7712 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7713 | } |
7714 | ||
7715 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7716 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7717 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7718 | ||
2d112de7 ACO |
7719 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7720 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7721 | } |
7722 | ||
f6a83288 | 7723 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7724 | struct intel_crtc_state *pipe_config) |
babea61d | 7725 | { |
2d112de7 ACO |
7726 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7727 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7728 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7729 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7730 | |
2d112de7 ACO |
7731 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7732 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7733 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7734 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7735 | |
2d112de7 | 7736 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7737 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7738 | |
2d112de7 ACO |
7739 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7740 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7741 | |
7742 | mode->hsync = drm_mode_hsync(mode); | |
7743 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7744 | drm_mode_set_name(mode); | |
babea61d JB |
7745 | } |
7746 | ||
84b046f3 DV |
7747 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7748 | { | |
7749 | struct drm_device *dev = intel_crtc->base.dev; | |
7750 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7751 | uint32_t pipeconf; | |
7752 | ||
9f11a9e4 | 7753 | pipeconf = 0; |
84b046f3 | 7754 | |
b6b5d049 VS |
7755 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7756 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7757 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7758 | |
6e3c9717 | 7759 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7760 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7761 | |
ff9ce46e DV |
7762 | /* only g4x and later have fancy bpc/dither controls */ |
7763 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7764 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7765 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7766 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7767 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7768 | |
6e3c9717 | 7769 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7770 | case 18: |
7771 | pipeconf |= PIPECONF_6BPC; | |
7772 | break; | |
7773 | case 24: | |
7774 | pipeconf |= PIPECONF_8BPC; | |
7775 | break; | |
7776 | case 30: | |
7777 | pipeconf |= PIPECONF_10BPC; | |
7778 | break; | |
7779 | default: | |
7780 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7781 | BUG(); | |
84b046f3 DV |
7782 | } |
7783 | } | |
7784 | ||
7785 | if (HAS_PIPE_CXSR(dev)) { | |
7786 | if (intel_crtc->lowfreq_avail) { | |
7787 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7788 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7789 | } else { | |
7790 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7791 | } |
7792 | } | |
7793 | ||
6e3c9717 | 7794 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7795 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7796 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7797 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7798 | else | |
7799 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7800 | } else | |
84b046f3 DV |
7801 | pipeconf |= PIPECONF_PROGRESSIVE; |
7802 | ||
6e3c9717 | 7803 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7804 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7805 | |
84b046f3 DV |
7806 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7807 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7808 | } | |
7809 | ||
190f68c5 ACO |
7810 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7811 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7812 | { |
c7653199 | 7813 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7814 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7815 | int refclk, num_connectors = 0; |
c329a4ec DV |
7816 | intel_clock_t clock; |
7817 | bool ok; | |
7818 | bool is_dsi = false; | |
5eddb70b | 7819 | struct intel_encoder *encoder; |
d4906093 | 7820 | const intel_limit_t *limit; |
55bb9992 | 7821 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7822 | struct drm_connector *connector; |
55bb9992 ACO |
7823 | struct drm_connector_state *connector_state; |
7824 | int i; | |
79e53945 | 7825 | |
dd3cd74a ACO |
7826 | memset(&crtc_state->dpll_hw_state, 0, |
7827 | sizeof(crtc_state->dpll_hw_state)); | |
7828 | ||
da3ced29 | 7829 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7830 | if (connector_state->crtc != &crtc->base) |
7831 | continue; | |
7832 | ||
7833 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7834 | ||
5eddb70b | 7835 | switch (encoder->type) { |
e9fd1c02 JN |
7836 | case INTEL_OUTPUT_DSI: |
7837 | is_dsi = true; | |
7838 | break; | |
6847d71b PZ |
7839 | default: |
7840 | break; | |
79e53945 | 7841 | } |
43565a06 | 7842 | |
c751ce4f | 7843 | num_connectors++; |
79e53945 JB |
7844 | } |
7845 | ||
f2335330 | 7846 | if (is_dsi) |
5b18e57c | 7847 | return 0; |
f2335330 | 7848 | |
190f68c5 | 7849 | if (!crtc_state->clock_set) { |
a93e255f | 7850 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7851 | |
e9fd1c02 JN |
7852 | /* |
7853 | * Returns a set of divisors for the desired target clock with | |
7854 | * the given refclk, or FALSE. The returned values represent | |
7855 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7856 | * 2) / p1 / p2. | |
7857 | */ | |
a93e255f ACO |
7858 | limit = intel_limit(crtc_state, refclk); |
7859 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7860 | crtc_state->port_clock, |
e9fd1c02 | 7861 | refclk, NULL, &clock); |
f2335330 | 7862 | if (!ok) { |
e9fd1c02 JN |
7863 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7864 | return -EINVAL; | |
7865 | } | |
79e53945 | 7866 | |
f2335330 | 7867 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
7868 | crtc_state->dpll.n = clock.n; |
7869 | crtc_state->dpll.m1 = clock.m1; | |
7870 | crtc_state->dpll.m2 = clock.m2; | |
7871 | crtc_state->dpll.p1 = clock.p1; | |
7872 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7873 | } |
7026d4ac | 7874 | |
e9fd1c02 | 7875 | if (IS_GEN2(dev)) { |
c329a4ec | 7876 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7877 | num_connectors); |
9d556c99 | 7878 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 7879 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7880 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 7881 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7882 | } else { |
c329a4ec | 7883 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7884 | num_connectors); |
e9fd1c02 | 7885 | } |
79e53945 | 7886 | |
c8f7a0db | 7887 | return 0; |
f564048e EA |
7888 | } |
7889 | ||
2fa2fe9a | 7890 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7891 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7892 | { |
7893 | struct drm_device *dev = crtc->base.dev; | |
7894 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7895 | uint32_t tmp; | |
7896 | ||
dc9e7dec VS |
7897 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7898 | return; | |
7899 | ||
2fa2fe9a | 7900 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7901 | if (!(tmp & PFIT_ENABLE)) |
7902 | return; | |
2fa2fe9a | 7903 | |
06922821 | 7904 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7905 | if (INTEL_INFO(dev)->gen < 4) { |
7906 | if (crtc->pipe != PIPE_B) | |
7907 | return; | |
2fa2fe9a DV |
7908 | } else { |
7909 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7910 | return; | |
7911 | } | |
7912 | ||
06922821 | 7913 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
7914 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
7915 | if (INTEL_INFO(dev)->gen < 5) | |
7916 | pipe_config->gmch_pfit.lvds_border_bits = | |
7917 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
7918 | } | |
7919 | ||
acbec814 | 7920 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7921 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7922 | { |
7923 | struct drm_device *dev = crtc->base.dev; | |
7924 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7925 | int pipe = pipe_config->cpu_transcoder; | |
7926 | intel_clock_t clock; | |
7927 | u32 mdiv; | |
662c6ecb | 7928 | int refclk = 100000; |
acbec814 | 7929 | |
f573de5a SK |
7930 | /* In case of MIPI DPLL will not even be used */ |
7931 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
7932 | return; | |
7933 | ||
a580516d | 7934 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 7935 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 7936 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
7937 | |
7938 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7939 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7940 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7941 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7942 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7943 | ||
dccbea3b | 7944 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
7945 | } |
7946 | ||
5724dbd1 DL |
7947 | static void |
7948 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7949 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7950 | { |
7951 | struct drm_device *dev = crtc->base.dev; | |
7952 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7953 | u32 val, base, offset; | |
7954 | int pipe = crtc->pipe, plane = crtc->plane; | |
7955 | int fourcc, pixel_format; | |
6761dd31 | 7956 | unsigned int aligned_height; |
b113d5ee | 7957 | struct drm_framebuffer *fb; |
1b842c89 | 7958 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7959 | |
42a7b088 DL |
7960 | val = I915_READ(DSPCNTR(plane)); |
7961 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7962 | return; | |
7963 | ||
d9806c9f | 7964 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7965 | if (!intel_fb) { |
1ad292b5 JB |
7966 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7967 | return; | |
7968 | } | |
7969 | ||
1b842c89 DL |
7970 | fb = &intel_fb->base; |
7971 | ||
18c5247e DV |
7972 | if (INTEL_INFO(dev)->gen >= 4) { |
7973 | if (val & DISPPLANE_TILED) { | |
49af449b | 7974 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
7975 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
7976 | } | |
7977 | } | |
1ad292b5 JB |
7978 | |
7979 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 7980 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
7981 | fb->pixel_format = fourcc; |
7982 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
7983 | |
7984 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 7985 | if (plane_config->tiling) |
1ad292b5 JB |
7986 | offset = I915_READ(DSPTILEOFF(plane)); |
7987 | else | |
7988 | offset = I915_READ(DSPLINOFF(plane)); | |
7989 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
7990 | } else { | |
7991 | base = I915_READ(DSPADDR(plane)); | |
7992 | } | |
7993 | plane_config->base = base; | |
7994 | ||
7995 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
7996 | fb->width = ((val >> 16) & 0xfff) + 1; |
7997 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
7998 | |
7999 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8000 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8001 | |
b113d5ee | 8002 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8003 | fb->pixel_format, |
8004 | fb->modifier[0]); | |
1ad292b5 | 8005 | |
f37b5c2b | 8006 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8007 | |
2844a921 DL |
8008 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8009 | pipe_name(pipe), plane, fb->width, fb->height, | |
8010 | fb->bits_per_pixel, base, fb->pitches[0], | |
8011 | plane_config->size); | |
1ad292b5 | 8012 | |
2d14030b | 8013 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8014 | } |
8015 | ||
70b23a98 | 8016 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8017 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8018 | { |
8019 | struct drm_device *dev = crtc->base.dev; | |
8020 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8021 | int pipe = pipe_config->cpu_transcoder; | |
8022 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8023 | intel_clock_t clock; | |
0d7b6b11 | 8024 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8025 | int refclk = 100000; |
8026 | ||
a580516d | 8027 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8028 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8029 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8030 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8031 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8032 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8033 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8034 | |
8035 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8036 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8037 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8038 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8039 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8040 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8041 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8042 | ||
dccbea3b | 8043 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8044 | } |
8045 | ||
0e8ffe1b | 8046 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8047 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8048 | { |
8049 | struct drm_device *dev = crtc->base.dev; | |
8050 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8051 | uint32_t tmp; | |
8052 | ||
f458ebbc DV |
8053 | if (!intel_display_power_is_enabled(dev_priv, |
8054 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8055 | return false; |
8056 | ||
e143a21c | 8057 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8058 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8059 | |
0e8ffe1b DV |
8060 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8061 | if (!(tmp & PIPECONF_ENABLE)) | |
8062 | return false; | |
8063 | ||
42571aef VS |
8064 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8065 | switch (tmp & PIPECONF_BPC_MASK) { | |
8066 | case PIPECONF_6BPC: | |
8067 | pipe_config->pipe_bpp = 18; | |
8068 | break; | |
8069 | case PIPECONF_8BPC: | |
8070 | pipe_config->pipe_bpp = 24; | |
8071 | break; | |
8072 | case PIPECONF_10BPC: | |
8073 | pipe_config->pipe_bpp = 30; | |
8074 | break; | |
8075 | default: | |
8076 | break; | |
8077 | } | |
8078 | } | |
8079 | ||
b5a9fa09 DV |
8080 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8081 | pipe_config->limited_color_range = true; | |
8082 | ||
282740f7 VS |
8083 | if (INTEL_INFO(dev)->gen < 4) |
8084 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8085 | ||
1bd1bd80 DV |
8086 | intel_get_pipe_timings(crtc, pipe_config); |
8087 | ||
2fa2fe9a DV |
8088 | i9xx_get_pfit_config(crtc, pipe_config); |
8089 | ||
6c49f241 DV |
8090 | if (INTEL_INFO(dev)->gen >= 4) { |
8091 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8092 | pipe_config->pixel_multiplier = | |
8093 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8094 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8095 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8096 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8097 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8098 | pipe_config->pixel_multiplier = | |
8099 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8100 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8101 | } else { | |
8102 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8103 | * port and will be fixed up in the encoder->get_config | |
8104 | * function. */ | |
8105 | pipe_config->pixel_multiplier = 1; | |
8106 | } | |
8bcc2795 DV |
8107 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8108 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8109 | /* |
8110 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8111 | * on 830. Filter it out here so that we don't | |
8112 | * report errors due to that. | |
8113 | */ | |
8114 | if (IS_I830(dev)) | |
8115 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8116 | ||
8bcc2795 DV |
8117 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8118 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8119 | } else { |
8120 | /* Mask out read-only status bits. */ | |
8121 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8122 | DPLL_PORTC_READY_MASK | | |
8123 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8124 | } |
6c49f241 | 8125 | |
70b23a98 VS |
8126 | if (IS_CHERRYVIEW(dev)) |
8127 | chv_crtc_clock_get(crtc, pipe_config); | |
8128 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8129 | vlv_crtc_clock_get(crtc, pipe_config); |
8130 | else | |
8131 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8132 | |
0f64614d VS |
8133 | /* |
8134 | * Normally the dotclock is filled in by the encoder .get_config() | |
8135 | * but in case the pipe is enabled w/o any ports we need a sane | |
8136 | * default. | |
8137 | */ | |
8138 | pipe_config->base.adjusted_mode.crtc_clock = | |
8139 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8140 | ||
0e8ffe1b DV |
8141 | return true; |
8142 | } | |
8143 | ||
dde86e2d | 8144 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8145 | { |
8146 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8147 | struct intel_encoder *encoder; |
74cfd7ac | 8148 | u32 val, final; |
13d83a67 | 8149 | bool has_lvds = false; |
199e5d79 | 8150 | bool has_cpu_edp = false; |
199e5d79 | 8151 | bool has_panel = false; |
99eb6a01 KP |
8152 | bool has_ck505 = false; |
8153 | bool can_ssc = false; | |
13d83a67 JB |
8154 | |
8155 | /* We need to take the global config into account */ | |
b2784e15 | 8156 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8157 | switch (encoder->type) { |
8158 | case INTEL_OUTPUT_LVDS: | |
8159 | has_panel = true; | |
8160 | has_lvds = true; | |
8161 | break; | |
8162 | case INTEL_OUTPUT_EDP: | |
8163 | has_panel = true; | |
2de6905f | 8164 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8165 | has_cpu_edp = true; |
8166 | break; | |
6847d71b PZ |
8167 | default: |
8168 | break; | |
13d83a67 JB |
8169 | } |
8170 | } | |
8171 | ||
99eb6a01 | 8172 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8173 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8174 | can_ssc = has_ck505; |
8175 | } else { | |
8176 | has_ck505 = false; | |
8177 | can_ssc = true; | |
8178 | } | |
8179 | ||
2de6905f ID |
8180 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8181 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8182 | |
8183 | /* Ironlake: try to setup display ref clock before DPLL | |
8184 | * enabling. This is only under driver's control after | |
8185 | * PCH B stepping, previous chipset stepping should be | |
8186 | * ignoring this setting. | |
8187 | */ | |
74cfd7ac CW |
8188 | val = I915_READ(PCH_DREF_CONTROL); |
8189 | ||
8190 | /* As we must carefully and slowly disable/enable each source in turn, | |
8191 | * compute the final state we want first and check if we need to | |
8192 | * make any changes at all. | |
8193 | */ | |
8194 | final = val; | |
8195 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8196 | if (has_ck505) | |
8197 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8198 | else | |
8199 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8200 | ||
8201 | final &= ~DREF_SSC_SOURCE_MASK; | |
8202 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8203 | final &= ~DREF_SSC1_ENABLE; | |
8204 | ||
8205 | if (has_panel) { | |
8206 | final |= DREF_SSC_SOURCE_ENABLE; | |
8207 | ||
8208 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8209 | final |= DREF_SSC1_ENABLE; | |
8210 | ||
8211 | if (has_cpu_edp) { | |
8212 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8213 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8214 | else | |
8215 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8216 | } else | |
8217 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8218 | } else { | |
8219 | final |= DREF_SSC_SOURCE_DISABLE; | |
8220 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8221 | } | |
8222 | ||
8223 | if (final == val) | |
8224 | return; | |
8225 | ||
13d83a67 | 8226 | /* Always enable nonspread source */ |
74cfd7ac | 8227 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8228 | |
99eb6a01 | 8229 | if (has_ck505) |
74cfd7ac | 8230 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8231 | else |
74cfd7ac | 8232 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8233 | |
199e5d79 | 8234 | if (has_panel) { |
74cfd7ac CW |
8235 | val &= ~DREF_SSC_SOURCE_MASK; |
8236 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8237 | |
199e5d79 | 8238 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8239 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8240 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8241 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8242 | } else |
74cfd7ac | 8243 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8244 | |
8245 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8246 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8247 | POSTING_READ(PCH_DREF_CONTROL); |
8248 | udelay(200); | |
8249 | ||
74cfd7ac | 8250 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8251 | |
8252 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8253 | if (has_cpu_edp) { |
99eb6a01 | 8254 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8255 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8256 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8257 | } else |
74cfd7ac | 8258 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8259 | } else |
74cfd7ac | 8260 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8261 | |
74cfd7ac | 8262 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8263 | POSTING_READ(PCH_DREF_CONTROL); |
8264 | udelay(200); | |
8265 | } else { | |
8266 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8267 | ||
74cfd7ac | 8268 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8269 | |
8270 | /* Turn off CPU output */ | |
74cfd7ac | 8271 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8272 | |
74cfd7ac | 8273 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8274 | POSTING_READ(PCH_DREF_CONTROL); |
8275 | udelay(200); | |
8276 | ||
8277 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8278 | val &= ~DREF_SSC_SOURCE_MASK; |
8279 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8280 | |
8281 | /* Turn off SSC1 */ | |
74cfd7ac | 8282 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8283 | |
74cfd7ac | 8284 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8285 | POSTING_READ(PCH_DREF_CONTROL); |
8286 | udelay(200); | |
8287 | } | |
74cfd7ac CW |
8288 | |
8289 | BUG_ON(val != final); | |
13d83a67 JB |
8290 | } |
8291 | ||
f31f2d55 | 8292 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8293 | { |
f31f2d55 | 8294 | uint32_t tmp; |
dde86e2d | 8295 | |
0ff066a9 PZ |
8296 | tmp = I915_READ(SOUTH_CHICKEN2); |
8297 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8298 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8299 | |
0ff066a9 PZ |
8300 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8301 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8302 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8303 | |
0ff066a9 PZ |
8304 | tmp = I915_READ(SOUTH_CHICKEN2); |
8305 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8306 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8307 | |
0ff066a9 PZ |
8308 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8309 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8310 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8311 | } |
8312 | ||
8313 | /* WaMPhyProgramming:hsw */ | |
8314 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8315 | { | |
8316 | uint32_t tmp; | |
dde86e2d PZ |
8317 | |
8318 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8319 | tmp &= ~(0xFF << 24); | |
8320 | tmp |= (0x12 << 24); | |
8321 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8322 | ||
dde86e2d PZ |
8323 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8324 | tmp |= (1 << 11); | |
8325 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8326 | ||
8327 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8328 | tmp |= (1 << 11); | |
8329 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8330 | ||
dde86e2d PZ |
8331 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8332 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8333 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8334 | ||
8335 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8336 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8337 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8338 | ||
0ff066a9 PZ |
8339 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8340 | tmp &= ~(7 << 13); | |
8341 | tmp |= (5 << 13); | |
8342 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8343 | |
0ff066a9 PZ |
8344 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8345 | tmp &= ~(7 << 13); | |
8346 | tmp |= (5 << 13); | |
8347 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8348 | |
8349 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8350 | tmp &= ~0xFF; | |
8351 | tmp |= 0x1C; | |
8352 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8353 | ||
8354 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8355 | tmp &= ~0xFF; | |
8356 | tmp |= 0x1C; | |
8357 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8358 | ||
8359 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8360 | tmp &= ~(0xFF << 16); | |
8361 | tmp |= (0x1C << 16); | |
8362 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8363 | ||
8364 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8365 | tmp &= ~(0xFF << 16); | |
8366 | tmp |= (0x1C << 16); | |
8367 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8368 | ||
0ff066a9 PZ |
8369 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8370 | tmp |= (1 << 27); | |
8371 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8372 | |
0ff066a9 PZ |
8373 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8374 | tmp |= (1 << 27); | |
8375 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8376 | |
0ff066a9 PZ |
8377 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8378 | tmp &= ~(0xF << 28); | |
8379 | tmp |= (4 << 28); | |
8380 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8381 | |
0ff066a9 PZ |
8382 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8383 | tmp &= ~(0xF << 28); | |
8384 | tmp |= (4 << 28); | |
8385 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8386 | } |
8387 | ||
2fa86a1f PZ |
8388 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8389 | * Programming" based on the parameters passed: | |
8390 | * - Sequence to enable CLKOUT_DP | |
8391 | * - Sequence to enable CLKOUT_DP without spread | |
8392 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8393 | */ | |
8394 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8395 | bool with_fdi) | |
f31f2d55 PZ |
8396 | { |
8397 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8398 | uint32_t reg, tmp; |
8399 | ||
8400 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8401 | with_spread = true; | |
c2699524 | 8402 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8403 | with_fdi = false; |
f31f2d55 | 8404 | |
a580516d | 8405 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8406 | |
8407 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8408 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8409 | tmp |= SBI_SSCCTL_PATHALT; | |
8410 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8411 | ||
8412 | udelay(24); | |
8413 | ||
2fa86a1f PZ |
8414 | if (with_spread) { |
8415 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8416 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8417 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8418 | |
2fa86a1f PZ |
8419 | if (with_fdi) { |
8420 | lpt_reset_fdi_mphy(dev_priv); | |
8421 | lpt_program_fdi_mphy(dev_priv); | |
8422 | } | |
8423 | } | |
dde86e2d | 8424 | |
c2699524 | 8425 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8426 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8427 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8428 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8429 | |
a580516d | 8430 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8431 | } |
8432 | ||
47701c3b PZ |
8433 | /* Sequence to disable CLKOUT_DP */ |
8434 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8435 | { | |
8436 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8437 | uint32_t reg, tmp; | |
8438 | ||
a580516d | 8439 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8440 | |
c2699524 | 8441 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8442 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8443 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8444 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8445 | ||
8446 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8447 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8448 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8449 | tmp |= SBI_SSCCTL_PATHALT; | |
8450 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8451 | udelay(32); | |
8452 | } | |
8453 | tmp |= SBI_SSCCTL_DISABLE; | |
8454 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8455 | } | |
8456 | ||
a580516d | 8457 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8458 | } |
8459 | ||
bf8fa3d3 PZ |
8460 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8461 | { | |
bf8fa3d3 PZ |
8462 | struct intel_encoder *encoder; |
8463 | bool has_vga = false; | |
8464 | ||
b2784e15 | 8465 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8466 | switch (encoder->type) { |
8467 | case INTEL_OUTPUT_ANALOG: | |
8468 | has_vga = true; | |
8469 | break; | |
6847d71b PZ |
8470 | default: |
8471 | break; | |
bf8fa3d3 PZ |
8472 | } |
8473 | } | |
8474 | ||
47701c3b PZ |
8475 | if (has_vga) |
8476 | lpt_enable_clkout_dp(dev, true, true); | |
8477 | else | |
8478 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8479 | } |
8480 | ||
dde86e2d PZ |
8481 | /* |
8482 | * Initialize reference clocks when the driver loads | |
8483 | */ | |
8484 | void intel_init_pch_refclk(struct drm_device *dev) | |
8485 | { | |
8486 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8487 | ironlake_init_pch_refclk(dev); | |
8488 | else if (HAS_PCH_LPT(dev)) | |
8489 | lpt_init_pch_refclk(dev); | |
8490 | } | |
8491 | ||
55bb9992 | 8492 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8493 | { |
55bb9992 | 8494 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8495 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8496 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8497 | struct drm_connector *connector; |
55bb9992 | 8498 | struct drm_connector_state *connector_state; |
d9d444cb | 8499 | struct intel_encoder *encoder; |
55bb9992 | 8500 | int num_connectors = 0, i; |
d9d444cb JB |
8501 | bool is_lvds = false; |
8502 | ||
da3ced29 | 8503 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8504 | if (connector_state->crtc != crtc_state->base.crtc) |
8505 | continue; | |
8506 | ||
8507 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8508 | ||
d9d444cb JB |
8509 | switch (encoder->type) { |
8510 | case INTEL_OUTPUT_LVDS: | |
8511 | is_lvds = true; | |
8512 | break; | |
6847d71b PZ |
8513 | default: |
8514 | break; | |
d9d444cb JB |
8515 | } |
8516 | num_connectors++; | |
8517 | } | |
8518 | ||
8519 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8520 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8521 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8522 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8523 | } |
8524 | ||
8525 | return 120000; | |
8526 | } | |
8527 | ||
6ff93609 | 8528 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8529 | { |
c8203565 | 8530 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8531 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8532 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8533 | uint32_t val; |
8534 | ||
78114071 | 8535 | val = 0; |
c8203565 | 8536 | |
6e3c9717 | 8537 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8538 | case 18: |
dfd07d72 | 8539 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8540 | break; |
8541 | case 24: | |
dfd07d72 | 8542 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8543 | break; |
8544 | case 30: | |
dfd07d72 | 8545 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8546 | break; |
8547 | case 36: | |
dfd07d72 | 8548 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8549 | break; |
8550 | default: | |
cc769b62 PZ |
8551 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8552 | BUG(); | |
c8203565 PZ |
8553 | } |
8554 | ||
6e3c9717 | 8555 | if (intel_crtc->config->dither) |
c8203565 PZ |
8556 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8557 | ||
6e3c9717 | 8558 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8559 | val |= PIPECONF_INTERLACED_ILK; |
8560 | else | |
8561 | val |= PIPECONF_PROGRESSIVE; | |
8562 | ||
6e3c9717 | 8563 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8564 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8565 | |
c8203565 PZ |
8566 | I915_WRITE(PIPECONF(pipe), val); |
8567 | POSTING_READ(PIPECONF(pipe)); | |
8568 | } | |
8569 | ||
86d3efce VS |
8570 | /* |
8571 | * Set up the pipe CSC unit. | |
8572 | * | |
8573 | * Currently only full range RGB to limited range RGB conversion | |
8574 | * is supported, but eventually this should handle various | |
8575 | * RGB<->YCbCr scenarios as well. | |
8576 | */ | |
50f3b016 | 8577 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8578 | { |
8579 | struct drm_device *dev = crtc->dev; | |
8580 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8581 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8582 | int pipe = intel_crtc->pipe; | |
8583 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8584 | ||
8585 | /* | |
8586 | * TODO: Check what kind of values actually come out of the pipe | |
8587 | * with these coeff/postoff values and adjust to get the best | |
8588 | * accuracy. Perhaps we even need to take the bpc value into | |
8589 | * consideration. | |
8590 | */ | |
8591 | ||
6e3c9717 | 8592 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8593 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8594 | ||
8595 | /* | |
8596 | * GY/GU and RY/RU should be the other way around according | |
8597 | * to BSpec, but reality doesn't agree. Just set them up in | |
8598 | * a way that results in the correct picture. | |
8599 | */ | |
8600 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8601 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8602 | ||
8603 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8604 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8605 | ||
8606 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8607 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8608 | ||
8609 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8610 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8611 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8612 | ||
8613 | if (INTEL_INFO(dev)->gen > 6) { | |
8614 | uint16_t postoff = 0; | |
8615 | ||
6e3c9717 | 8616 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8617 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8618 | |
8619 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8620 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8621 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8622 | ||
8623 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8624 | } else { | |
8625 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8626 | ||
6e3c9717 | 8627 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8628 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8629 | ||
8630 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8631 | } | |
8632 | } | |
8633 | ||
6ff93609 | 8634 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8635 | { |
756f85cf PZ |
8636 | struct drm_device *dev = crtc->dev; |
8637 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8638 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8639 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8640 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8641 | uint32_t val; |
8642 | ||
3eff4faa | 8643 | val = 0; |
ee2b0b38 | 8644 | |
6e3c9717 | 8645 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8646 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8647 | ||
6e3c9717 | 8648 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8649 | val |= PIPECONF_INTERLACED_ILK; |
8650 | else | |
8651 | val |= PIPECONF_PROGRESSIVE; | |
8652 | ||
702e7a56 PZ |
8653 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8654 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8655 | |
8656 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8657 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8658 | |
3cdf122c | 8659 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8660 | val = 0; |
8661 | ||
6e3c9717 | 8662 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8663 | case 18: |
8664 | val |= PIPEMISC_DITHER_6_BPC; | |
8665 | break; | |
8666 | case 24: | |
8667 | val |= PIPEMISC_DITHER_8_BPC; | |
8668 | break; | |
8669 | case 30: | |
8670 | val |= PIPEMISC_DITHER_10_BPC; | |
8671 | break; | |
8672 | case 36: | |
8673 | val |= PIPEMISC_DITHER_12_BPC; | |
8674 | break; | |
8675 | default: | |
8676 | /* Case prevented by pipe_config_set_bpp. */ | |
8677 | BUG(); | |
8678 | } | |
8679 | ||
6e3c9717 | 8680 | if (intel_crtc->config->dither) |
756f85cf PZ |
8681 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8682 | ||
8683 | I915_WRITE(PIPEMISC(pipe), val); | |
8684 | } | |
ee2b0b38 PZ |
8685 | } |
8686 | ||
6591c6e4 | 8687 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8688 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8689 | intel_clock_t *clock, |
8690 | bool *has_reduced_clock, | |
8691 | intel_clock_t *reduced_clock) | |
8692 | { | |
8693 | struct drm_device *dev = crtc->dev; | |
8694 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8695 | int refclk; |
d4906093 | 8696 | const intel_limit_t *limit; |
c329a4ec | 8697 | bool ret; |
79e53945 | 8698 | |
55bb9992 | 8699 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8700 | |
d4906093 ML |
8701 | /* |
8702 | * Returns a set of divisors for the desired target clock with the given | |
8703 | * refclk, or FALSE. The returned values represent the clock equation: | |
8704 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8705 | */ | |
a93e255f ACO |
8706 | limit = intel_limit(crtc_state, refclk); |
8707 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8708 | crtc_state->port_clock, |
ee9300bb | 8709 | refclk, NULL, clock); |
6591c6e4 PZ |
8710 | if (!ret) |
8711 | return false; | |
cda4b7d3 | 8712 | |
6591c6e4 PZ |
8713 | return true; |
8714 | } | |
8715 | ||
d4b1931c PZ |
8716 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8717 | { | |
8718 | /* | |
8719 | * Account for spread spectrum to avoid | |
8720 | * oversubscribing the link. Max center spread | |
8721 | * is 2.5%; use 5% for safety's sake. | |
8722 | */ | |
8723 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8724 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8725 | } |
8726 | ||
7429e9d4 | 8727 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8728 | { |
7429e9d4 | 8729 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8730 | } |
8731 | ||
de13a2e3 | 8732 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8733 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8734 | u32 *fp, |
9a7c7890 | 8735 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8736 | { |
de13a2e3 | 8737 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8738 | struct drm_device *dev = crtc->dev; |
8739 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8740 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8741 | struct drm_connector *connector; |
55bb9992 ACO |
8742 | struct drm_connector_state *connector_state; |
8743 | struct intel_encoder *encoder; | |
de13a2e3 | 8744 | uint32_t dpll; |
55bb9992 | 8745 | int factor, num_connectors = 0, i; |
09ede541 | 8746 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8747 | |
da3ced29 | 8748 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8749 | if (connector_state->crtc != crtc_state->base.crtc) |
8750 | continue; | |
8751 | ||
8752 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8753 | ||
8754 | switch (encoder->type) { | |
79e53945 JB |
8755 | case INTEL_OUTPUT_LVDS: |
8756 | is_lvds = true; | |
8757 | break; | |
8758 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8759 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8760 | is_sdvo = true; |
79e53945 | 8761 | break; |
6847d71b PZ |
8762 | default: |
8763 | break; | |
79e53945 | 8764 | } |
43565a06 | 8765 | |
c751ce4f | 8766 | num_connectors++; |
79e53945 | 8767 | } |
79e53945 | 8768 | |
c1858123 | 8769 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8770 | factor = 21; |
8771 | if (is_lvds) { | |
8772 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8773 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8774 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8775 | factor = 25; |
190f68c5 | 8776 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8777 | factor = 20; |
c1858123 | 8778 | |
190f68c5 | 8779 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8780 | *fp |= FP_CB_TUNE; |
2c07245f | 8781 | |
9a7c7890 DV |
8782 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8783 | *fp2 |= FP_CB_TUNE; | |
8784 | ||
5eddb70b | 8785 | dpll = 0; |
2c07245f | 8786 | |
a07d6787 EA |
8787 | if (is_lvds) |
8788 | dpll |= DPLLB_MODE_LVDS; | |
8789 | else | |
8790 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8791 | |
190f68c5 | 8792 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8793 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8794 | |
8795 | if (is_sdvo) | |
4a33e48d | 8796 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8797 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8798 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8799 | |
a07d6787 | 8800 | /* compute bitmask from p1 value */ |
190f68c5 | 8801 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8802 | /* also FPA1 */ |
190f68c5 | 8803 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8804 | |
190f68c5 | 8805 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8806 | case 5: |
8807 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8808 | break; | |
8809 | case 7: | |
8810 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8811 | break; | |
8812 | case 10: | |
8813 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8814 | break; | |
8815 | case 14: | |
8816 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8817 | break; | |
79e53945 JB |
8818 | } |
8819 | ||
b4c09f3b | 8820 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8821 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8822 | else |
8823 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8824 | ||
959e16d6 | 8825 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8826 | } |
8827 | ||
190f68c5 ACO |
8828 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8829 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8830 | { |
c7653199 | 8831 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8832 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8833 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8834 | bool ok, has_reduced_clock = false; |
8b47047b | 8835 | bool is_lvds = false; |
e2b78267 | 8836 | struct intel_shared_dpll *pll; |
de13a2e3 | 8837 | |
dd3cd74a ACO |
8838 | memset(&crtc_state->dpll_hw_state, 0, |
8839 | sizeof(crtc_state->dpll_hw_state)); | |
8840 | ||
409ee761 | 8841 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8842 | |
5dc5298b PZ |
8843 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8844 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8845 | |
190f68c5 | 8846 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8847 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8848 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8849 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8850 | return -EINVAL; | |
79e53945 | 8851 | } |
f47709a9 | 8852 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8853 | if (!crtc_state->clock_set) { |
8854 | crtc_state->dpll.n = clock.n; | |
8855 | crtc_state->dpll.m1 = clock.m1; | |
8856 | crtc_state->dpll.m2 = clock.m2; | |
8857 | crtc_state->dpll.p1 = clock.p1; | |
8858 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8859 | } |
79e53945 | 8860 | |
5dc5298b | 8861 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8862 | if (crtc_state->has_pch_encoder) { |
8863 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8864 | if (has_reduced_clock) |
7429e9d4 | 8865 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8866 | |
190f68c5 | 8867 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8868 | &fp, &reduced_clock, |
8869 | has_reduced_clock ? &fp2 : NULL); | |
8870 | ||
190f68c5 ACO |
8871 | crtc_state->dpll_hw_state.dpll = dpll; |
8872 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8873 | if (has_reduced_clock) |
190f68c5 | 8874 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8875 | else |
190f68c5 | 8876 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8877 | |
190f68c5 | 8878 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8879 | if (pll == NULL) { |
84f44ce7 | 8880 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8881 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8882 | return -EINVAL; |
8883 | } | |
3fb37703 | 8884 | } |
79e53945 | 8885 | |
ab585dea | 8886 | if (is_lvds && has_reduced_clock) |
c7653199 | 8887 | crtc->lowfreq_avail = true; |
bcd644e0 | 8888 | else |
c7653199 | 8889 | crtc->lowfreq_avail = false; |
e2b78267 | 8890 | |
c8f7a0db | 8891 | return 0; |
79e53945 JB |
8892 | } |
8893 | ||
eb14cb74 VS |
8894 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8895 | struct intel_link_m_n *m_n) | |
8896 | { | |
8897 | struct drm_device *dev = crtc->base.dev; | |
8898 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8899 | enum pipe pipe = crtc->pipe; | |
8900 | ||
8901 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8902 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8903 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8904 | & ~TU_SIZE_MASK; | |
8905 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8906 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8907 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8908 | } | |
8909 | ||
8910 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8911 | enum transcoder transcoder, | |
b95af8be VK |
8912 | struct intel_link_m_n *m_n, |
8913 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
8914 | { |
8915 | struct drm_device *dev = crtc->base.dev; | |
8916 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 8917 | enum pipe pipe = crtc->pipe; |
72419203 | 8918 | |
eb14cb74 VS |
8919 | if (INTEL_INFO(dev)->gen >= 5) { |
8920 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
8921 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8922 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8923 | & ~TU_SIZE_MASK; | |
8924 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8925 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8926 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8927 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8928 | * gen < 8) and if DRRS is supported (to make sure the | |
8929 | * registers are not unnecessarily read). | |
8930 | */ | |
8931 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 8932 | crtc->config->has_drrs) { |
b95af8be VK |
8933 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8934 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8935 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8936 | & ~TU_SIZE_MASK; | |
8937 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8938 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8939 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8940 | } | |
eb14cb74 VS |
8941 | } else { |
8942 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8943 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8944 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8945 | & ~TU_SIZE_MASK; | |
8946 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8947 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8948 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8949 | } | |
8950 | } | |
8951 | ||
8952 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8953 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8954 | { |
681a8504 | 8955 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8956 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8957 | else | |
8958 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8959 | &pipe_config->dp_m_n, |
8960 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8961 | } |
72419203 | 8962 | |
eb14cb74 | 8963 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 8964 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
8965 | { |
8966 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 8967 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
8968 | } |
8969 | ||
bd2e244f | 8970 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8971 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
8972 | { |
8973 | struct drm_device *dev = crtc->base.dev; | |
8974 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
8975 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
8976 | uint32_t ps_ctrl = 0; | |
8977 | int id = -1; | |
8978 | int i; | |
bd2e244f | 8979 | |
a1b2278e CK |
8980 | /* find scaler attached to this pipe */ |
8981 | for (i = 0; i < crtc->num_scalers; i++) { | |
8982 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
8983 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
8984 | id = i; | |
8985 | pipe_config->pch_pfit.enabled = true; | |
8986 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
8987 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
8988 | break; | |
8989 | } | |
8990 | } | |
bd2e244f | 8991 | |
a1b2278e CK |
8992 | scaler_state->scaler_id = id; |
8993 | if (id >= 0) { | |
8994 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
8995 | } else { | |
8996 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
8997 | } |
8998 | } | |
8999 | ||
5724dbd1 DL |
9000 | static void |
9001 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9002 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9003 | { |
9004 | struct drm_device *dev = crtc->base.dev; | |
9005 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9006 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9007 | int pipe = crtc->pipe; |
9008 | int fourcc, pixel_format; | |
6761dd31 | 9009 | unsigned int aligned_height; |
bc8d7dff | 9010 | struct drm_framebuffer *fb; |
1b842c89 | 9011 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9012 | |
d9806c9f | 9013 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9014 | if (!intel_fb) { |
bc8d7dff DL |
9015 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9016 | return; | |
9017 | } | |
9018 | ||
1b842c89 DL |
9019 | fb = &intel_fb->base; |
9020 | ||
bc8d7dff | 9021 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9022 | if (!(val & PLANE_CTL_ENABLE)) |
9023 | goto error; | |
9024 | ||
bc8d7dff DL |
9025 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9026 | fourcc = skl_format_to_fourcc(pixel_format, | |
9027 | val & PLANE_CTL_ORDER_RGBX, | |
9028 | val & PLANE_CTL_ALPHA_MASK); | |
9029 | fb->pixel_format = fourcc; | |
9030 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9031 | ||
40f46283 DL |
9032 | tiling = val & PLANE_CTL_TILED_MASK; |
9033 | switch (tiling) { | |
9034 | case PLANE_CTL_TILED_LINEAR: | |
9035 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9036 | break; | |
9037 | case PLANE_CTL_TILED_X: | |
9038 | plane_config->tiling = I915_TILING_X; | |
9039 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9040 | break; | |
9041 | case PLANE_CTL_TILED_Y: | |
9042 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9043 | break; | |
9044 | case PLANE_CTL_TILED_YF: | |
9045 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9046 | break; | |
9047 | default: | |
9048 | MISSING_CASE(tiling); | |
9049 | goto error; | |
9050 | } | |
9051 | ||
bc8d7dff DL |
9052 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9053 | plane_config->base = base; | |
9054 | ||
9055 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9056 | ||
9057 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9058 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9059 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9060 | ||
9061 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9062 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9063 | fb->pixel_format); | |
bc8d7dff DL |
9064 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9065 | ||
9066 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9067 | fb->pixel_format, |
9068 | fb->modifier[0]); | |
bc8d7dff | 9069 | |
f37b5c2b | 9070 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9071 | |
9072 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9073 | pipe_name(pipe), fb->width, fb->height, | |
9074 | fb->bits_per_pixel, base, fb->pitches[0], | |
9075 | plane_config->size); | |
9076 | ||
2d14030b | 9077 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9078 | return; |
9079 | ||
9080 | error: | |
9081 | kfree(fb); | |
9082 | } | |
9083 | ||
2fa2fe9a | 9084 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9085 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9086 | { |
9087 | struct drm_device *dev = crtc->base.dev; | |
9088 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9089 | uint32_t tmp; | |
9090 | ||
9091 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9092 | ||
9093 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9094 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9095 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9096 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9097 | |
9098 | /* We currently do not free assignements of panel fitters on | |
9099 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9100 | * differentiates them) so just WARN about this case for now. */ | |
9101 | if (IS_GEN7(dev)) { | |
9102 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9103 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9104 | } | |
2fa2fe9a | 9105 | } |
79e53945 JB |
9106 | } |
9107 | ||
5724dbd1 DL |
9108 | static void |
9109 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9110 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9111 | { |
9112 | struct drm_device *dev = crtc->base.dev; | |
9113 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9114 | u32 val, base, offset; | |
aeee5a49 | 9115 | int pipe = crtc->pipe; |
4c6baa59 | 9116 | int fourcc, pixel_format; |
6761dd31 | 9117 | unsigned int aligned_height; |
b113d5ee | 9118 | struct drm_framebuffer *fb; |
1b842c89 | 9119 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9120 | |
42a7b088 DL |
9121 | val = I915_READ(DSPCNTR(pipe)); |
9122 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9123 | return; | |
9124 | ||
d9806c9f | 9125 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9126 | if (!intel_fb) { |
4c6baa59 JB |
9127 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9128 | return; | |
9129 | } | |
9130 | ||
1b842c89 DL |
9131 | fb = &intel_fb->base; |
9132 | ||
18c5247e DV |
9133 | if (INTEL_INFO(dev)->gen >= 4) { |
9134 | if (val & DISPPLANE_TILED) { | |
49af449b | 9135 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9136 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9137 | } | |
9138 | } | |
4c6baa59 JB |
9139 | |
9140 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9141 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9142 | fb->pixel_format = fourcc; |
9143 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9144 | |
aeee5a49 | 9145 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9146 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9147 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9148 | } else { |
49af449b | 9149 | if (plane_config->tiling) |
aeee5a49 | 9150 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9151 | else |
aeee5a49 | 9152 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9153 | } |
9154 | plane_config->base = base; | |
9155 | ||
9156 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9157 | fb->width = ((val >> 16) & 0xfff) + 1; |
9158 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9159 | |
9160 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9161 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9162 | |
b113d5ee | 9163 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9164 | fb->pixel_format, |
9165 | fb->modifier[0]); | |
4c6baa59 | 9166 | |
f37b5c2b | 9167 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9168 | |
2844a921 DL |
9169 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9170 | pipe_name(pipe), fb->width, fb->height, | |
9171 | fb->bits_per_pixel, base, fb->pitches[0], | |
9172 | plane_config->size); | |
b113d5ee | 9173 | |
2d14030b | 9174 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9175 | } |
9176 | ||
0e8ffe1b | 9177 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9178 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9179 | { |
9180 | struct drm_device *dev = crtc->base.dev; | |
9181 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9182 | uint32_t tmp; | |
9183 | ||
f458ebbc DV |
9184 | if (!intel_display_power_is_enabled(dev_priv, |
9185 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9186 | return false; |
9187 | ||
e143a21c | 9188 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9189 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9190 | |
0e8ffe1b DV |
9191 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9192 | if (!(tmp & PIPECONF_ENABLE)) | |
9193 | return false; | |
9194 | ||
42571aef VS |
9195 | switch (tmp & PIPECONF_BPC_MASK) { |
9196 | case PIPECONF_6BPC: | |
9197 | pipe_config->pipe_bpp = 18; | |
9198 | break; | |
9199 | case PIPECONF_8BPC: | |
9200 | pipe_config->pipe_bpp = 24; | |
9201 | break; | |
9202 | case PIPECONF_10BPC: | |
9203 | pipe_config->pipe_bpp = 30; | |
9204 | break; | |
9205 | case PIPECONF_12BPC: | |
9206 | pipe_config->pipe_bpp = 36; | |
9207 | break; | |
9208 | default: | |
9209 | break; | |
9210 | } | |
9211 | ||
b5a9fa09 DV |
9212 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9213 | pipe_config->limited_color_range = true; | |
9214 | ||
ab9412ba | 9215 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9216 | struct intel_shared_dpll *pll; |
9217 | ||
88adfff1 DV |
9218 | pipe_config->has_pch_encoder = true; |
9219 | ||
627eb5a3 DV |
9220 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9221 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9222 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9223 | |
9224 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9225 | |
c0d43d62 | 9226 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9227 | pipe_config->shared_dpll = |
9228 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9229 | } else { |
9230 | tmp = I915_READ(PCH_DPLL_SEL); | |
9231 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9232 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9233 | else | |
9234 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9235 | } | |
66e985c0 DV |
9236 | |
9237 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9238 | ||
9239 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9240 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9241 | |
9242 | tmp = pipe_config->dpll_hw_state.dpll; | |
9243 | pipe_config->pixel_multiplier = | |
9244 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9245 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9246 | |
9247 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9248 | } else { |
9249 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9250 | } |
9251 | ||
1bd1bd80 DV |
9252 | intel_get_pipe_timings(crtc, pipe_config); |
9253 | ||
2fa2fe9a DV |
9254 | ironlake_get_pfit_config(crtc, pipe_config); |
9255 | ||
0e8ffe1b DV |
9256 | return true; |
9257 | } | |
9258 | ||
be256dc7 PZ |
9259 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9260 | { | |
9261 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9262 | struct intel_crtc *crtc; |
be256dc7 | 9263 | |
d3fcc808 | 9264 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9265 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9266 | pipe_name(crtc->pipe)); |
9267 | ||
e2c719b7 RC |
9268 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9269 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9270 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9271 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9272 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9273 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9274 | "CPU PWM1 enabled\n"); |
c5107b87 | 9275 | if (IS_HASWELL(dev)) |
e2c719b7 | 9276 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9277 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9278 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9279 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9280 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9281 | "Utility pin enabled\n"); |
e2c719b7 | 9282 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9283 | |
9926ada1 PZ |
9284 | /* |
9285 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9286 | * interrupts remain enabled. We used to check for that, but since it's | |
9287 | * gen-specific and since we only disable LCPLL after we fully disable | |
9288 | * the interrupts, the check below should be enough. | |
9289 | */ | |
e2c719b7 | 9290 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9291 | } |
9292 | ||
9ccd5aeb PZ |
9293 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9294 | { | |
9295 | struct drm_device *dev = dev_priv->dev; | |
9296 | ||
9297 | if (IS_HASWELL(dev)) | |
9298 | return I915_READ(D_COMP_HSW); | |
9299 | else | |
9300 | return I915_READ(D_COMP_BDW); | |
9301 | } | |
9302 | ||
3c4c9b81 PZ |
9303 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9304 | { | |
9305 | struct drm_device *dev = dev_priv->dev; | |
9306 | ||
9307 | if (IS_HASWELL(dev)) { | |
9308 | mutex_lock(&dev_priv->rps.hw_lock); | |
9309 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9310 | val)) | |
f475dadf | 9311 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9312 | mutex_unlock(&dev_priv->rps.hw_lock); |
9313 | } else { | |
9ccd5aeb PZ |
9314 | I915_WRITE(D_COMP_BDW, val); |
9315 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9316 | } |
be256dc7 PZ |
9317 | } |
9318 | ||
9319 | /* | |
9320 | * This function implements pieces of two sequences from BSpec: | |
9321 | * - Sequence for display software to disable LCPLL | |
9322 | * - Sequence for display software to allow package C8+ | |
9323 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9324 | * register. Callers should take care of disabling all the display engine | |
9325 | * functions, doing the mode unset, fixing interrupts, etc. | |
9326 | */ | |
6ff58d53 PZ |
9327 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9328 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9329 | { |
9330 | uint32_t val; | |
9331 | ||
9332 | assert_can_disable_lcpll(dev_priv); | |
9333 | ||
9334 | val = I915_READ(LCPLL_CTL); | |
9335 | ||
9336 | if (switch_to_fclk) { | |
9337 | val |= LCPLL_CD_SOURCE_FCLK; | |
9338 | I915_WRITE(LCPLL_CTL, val); | |
9339 | ||
9340 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9341 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9342 | DRM_ERROR("Switching to FCLK failed\n"); | |
9343 | ||
9344 | val = I915_READ(LCPLL_CTL); | |
9345 | } | |
9346 | ||
9347 | val |= LCPLL_PLL_DISABLE; | |
9348 | I915_WRITE(LCPLL_CTL, val); | |
9349 | POSTING_READ(LCPLL_CTL); | |
9350 | ||
9351 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9352 | DRM_ERROR("LCPLL still locked\n"); | |
9353 | ||
9ccd5aeb | 9354 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9355 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9356 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9357 | ndelay(100); |
9358 | ||
9ccd5aeb PZ |
9359 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9360 | 1)) | |
be256dc7 PZ |
9361 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9362 | ||
9363 | if (allow_power_down) { | |
9364 | val = I915_READ(LCPLL_CTL); | |
9365 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9366 | I915_WRITE(LCPLL_CTL, val); | |
9367 | POSTING_READ(LCPLL_CTL); | |
9368 | } | |
9369 | } | |
9370 | ||
9371 | /* | |
9372 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9373 | * source. | |
9374 | */ | |
6ff58d53 | 9375 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9376 | { |
9377 | uint32_t val; | |
9378 | ||
9379 | val = I915_READ(LCPLL_CTL); | |
9380 | ||
9381 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9382 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9383 | return; | |
9384 | ||
a8a8bd54 PZ |
9385 | /* |
9386 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9387 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9388 | */ |
59bad947 | 9389 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9390 | |
be256dc7 PZ |
9391 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9392 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9393 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9394 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9395 | } |
9396 | ||
9ccd5aeb | 9397 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9398 | val |= D_COMP_COMP_FORCE; |
9399 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9400 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9401 | |
9402 | val = I915_READ(LCPLL_CTL); | |
9403 | val &= ~LCPLL_PLL_DISABLE; | |
9404 | I915_WRITE(LCPLL_CTL, val); | |
9405 | ||
9406 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9407 | DRM_ERROR("LCPLL not locked yet\n"); | |
9408 | ||
9409 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9410 | val = I915_READ(LCPLL_CTL); | |
9411 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9412 | I915_WRITE(LCPLL_CTL, val); | |
9413 | ||
9414 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9415 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9416 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9417 | } | |
215733fa | 9418 | |
59bad947 | 9419 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9420 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9421 | } |
9422 | ||
765dab67 PZ |
9423 | /* |
9424 | * Package states C8 and deeper are really deep PC states that can only be | |
9425 | * reached when all the devices on the system allow it, so even if the graphics | |
9426 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9427 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9428 | * | |
9429 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9430 | * well is disabled and most interrupts are disabled, and these are also | |
9431 | * requirements for runtime PM. When these conditions are met, we manually do | |
9432 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9433 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9434 | * hang the machine. | |
9435 | * | |
9436 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9437 | * the state of some registers, so when we come back from PC8+ we need to | |
9438 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9439 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9440 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9441 | * because of the runtime PM support). | |
9442 | * | |
9443 | * For more, read "Display Sequences for Package C8" on the hardware | |
9444 | * documentation. | |
9445 | */ | |
a14cb6fc | 9446 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9447 | { |
c67a470b PZ |
9448 | struct drm_device *dev = dev_priv->dev; |
9449 | uint32_t val; | |
9450 | ||
c67a470b PZ |
9451 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9452 | ||
c2699524 | 9453 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9454 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9455 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9456 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9457 | } | |
9458 | ||
9459 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9460 | hsw_disable_lcpll(dev_priv, true, true); |
9461 | } | |
9462 | ||
a14cb6fc | 9463 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9464 | { |
9465 | struct drm_device *dev = dev_priv->dev; | |
9466 | uint32_t val; | |
9467 | ||
c67a470b PZ |
9468 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9469 | ||
9470 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9471 | lpt_init_pch_refclk(dev); |
9472 | ||
c2699524 | 9473 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9474 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9475 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9476 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9477 | } | |
9478 | ||
9479 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9480 | } |
9481 | ||
27c329ed | 9482 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9483 | { |
a821fc46 | 9484 | struct drm_device *dev = old_state->dev; |
27c329ed | 9485 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
f8437dd1 | 9486 | |
27c329ed | 9487 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9488 | } |
9489 | ||
b432e5cf | 9490 | /* compute the max rate for new configuration */ |
27c329ed | 9491 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9492 | { |
b432e5cf | 9493 | struct intel_crtc *intel_crtc; |
27c329ed | 9494 | struct intel_crtc_state *crtc_state; |
b432e5cf | 9495 | int max_pixel_rate = 0; |
b432e5cf | 9496 | |
27c329ed ML |
9497 | for_each_intel_crtc(state->dev, intel_crtc) { |
9498 | int pixel_rate; | |
9499 | ||
9500 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
9501 | if (IS_ERR(crtc_state)) | |
9502 | return PTR_ERR(crtc_state); | |
9503 | ||
9504 | if (!crtc_state->base.enable) | |
b432e5cf VS |
9505 | continue; |
9506 | ||
27c329ed | 9507 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9508 | |
9509 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
27c329ed | 9510 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
b432e5cf VS |
9511 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9512 | ||
9513 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9514 | } | |
9515 | ||
9516 | return max_pixel_rate; | |
9517 | } | |
9518 | ||
9519 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9520 | { | |
9521 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9522 | uint32_t val, data; | |
9523 | int ret; | |
9524 | ||
9525 | if (WARN((I915_READ(LCPLL_CTL) & | |
9526 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9527 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9528 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9529 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9530 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9531 | return; | |
9532 | ||
9533 | mutex_lock(&dev_priv->rps.hw_lock); | |
9534 | ret = sandybridge_pcode_write(dev_priv, | |
9535 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9536 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9537 | if (ret) { | |
9538 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9539 | return; | |
9540 | } | |
9541 | ||
9542 | val = I915_READ(LCPLL_CTL); | |
9543 | val |= LCPLL_CD_SOURCE_FCLK; | |
9544 | I915_WRITE(LCPLL_CTL, val); | |
9545 | ||
9546 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9547 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9548 | DRM_ERROR("Switching to FCLK failed\n"); | |
9549 | ||
9550 | val = I915_READ(LCPLL_CTL); | |
9551 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9552 | ||
9553 | switch (cdclk) { | |
9554 | case 450000: | |
9555 | val |= LCPLL_CLK_FREQ_450; | |
9556 | data = 0; | |
9557 | break; | |
9558 | case 540000: | |
9559 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9560 | data = 1; | |
9561 | break; | |
9562 | case 337500: | |
9563 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9564 | data = 2; | |
9565 | break; | |
9566 | case 675000: | |
9567 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9568 | data = 3; | |
9569 | break; | |
9570 | default: | |
9571 | WARN(1, "invalid cdclk frequency\n"); | |
9572 | return; | |
9573 | } | |
9574 | ||
9575 | I915_WRITE(LCPLL_CTL, val); | |
9576 | ||
9577 | val = I915_READ(LCPLL_CTL); | |
9578 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9579 | I915_WRITE(LCPLL_CTL, val); | |
9580 | ||
9581 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9582 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9583 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9584 | ||
9585 | mutex_lock(&dev_priv->rps.hw_lock); | |
9586 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9587 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9588 | ||
9589 | intel_update_cdclk(dev); | |
9590 | ||
9591 | WARN(cdclk != dev_priv->cdclk_freq, | |
9592 | "cdclk requested %d kHz but got %d kHz\n", | |
9593 | cdclk, dev_priv->cdclk_freq); | |
9594 | } | |
9595 | ||
27c329ed | 9596 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9597 | { |
27c329ed ML |
9598 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
9599 | int max_pixclk = ilk_max_pixel_rate(state); | |
b432e5cf VS |
9600 | int cdclk; |
9601 | ||
9602 | /* | |
9603 | * FIXME should also account for plane ratio | |
9604 | * once 64bpp pixel formats are supported. | |
9605 | */ | |
27c329ed | 9606 | if (max_pixclk > 540000) |
b432e5cf | 9607 | cdclk = 675000; |
27c329ed | 9608 | else if (max_pixclk > 450000) |
b432e5cf | 9609 | cdclk = 540000; |
27c329ed | 9610 | else if (max_pixclk > 337500) |
b432e5cf VS |
9611 | cdclk = 450000; |
9612 | else | |
9613 | cdclk = 337500; | |
9614 | ||
9615 | /* | |
9616 | * FIXME move the cdclk caclulation to | |
9617 | * compute_config() so we can fail gracegully. | |
9618 | */ | |
9619 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9620 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9621 | cdclk, dev_priv->max_cdclk_freq); | |
9622 | cdclk = dev_priv->max_cdclk_freq; | |
9623 | } | |
9624 | ||
27c329ed | 9625 | to_intel_atomic_state(state)->cdclk = cdclk; |
b432e5cf VS |
9626 | |
9627 | return 0; | |
9628 | } | |
9629 | ||
27c329ed | 9630 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9631 | { |
27c329ed ML |
9632 | struct drm_device *dev = old_state->dev; |
9633 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; | |
b432e5cf | 9634 | |
27c329ed | 9635 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9636 | } |
9637 | ||
190f68c5 ACO |
9638 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9639 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9640 | { |
190f68c5 | 9641 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9642 | return -EINVAL; |
716c2e55 | 9643 | |
c7653199 | 9644 | crtc->lowfreq_avail = false; |
644cef34 | 9645 | |
c8f7a0db | 9646 | return 0; |
79e53945 JB |
9647 | } |
9648 | ||
3760b59c S |
9649 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9650 | enum port port, | |
9651 | struct intel_crtc_state *pipe_config) | |
9652 | { | |
9653 | switch (port) { | |
9654 | case PORT_A: | |
9655 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9656 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9657 | break; | |
9658 | case PORT_B: | |
9659 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9660 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9661 | break; | |
9662 | case PORT_C: | |
9663 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9664 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9665 | break; | |
9666 | default: | |
9667 | DRM_ERROR("Incorrect port type\n"); | |
9668 | } | |
9669 | } | |
9670 | ||
96b7dfb7 S |
9671 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9672 | enum port port, | |
5cec258b | 9673 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9674 | { |
3148ade7 | 9675 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9676 | |
9677 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9678 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9679 | ||
9680 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9681 | case SKL_DPLL0: |
9682 | /* | |
9683 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9684 | * of the shared DPLL framework and thus needs to be read out | |
9685 | * separately | |
9686 | */ | |
9687 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9688 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9689 | break; | |
96b7dfb7 S |
9690 | case SKL_DPLL1: |
9691 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9692 | break; | |
9693 | case SKL_DPLL2: | |
9694 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9695 | break; | |
9696 | case SKL_DPLL3: | |
9697 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9698 | break; | |
96b7dfb7 S |
9699 | } |
9700 | } | |
9701 | ||
7d2c8175 DL |
9702 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9703 | enum port port, | |
5cec258b | 9704 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9705 | { |
9706 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9707 | ||
9708 | switch (pipe_config->ddi_pll_sel) { | |
9709 | case PORT_CLK_SEL_WRPLL1: | |
9710 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9711 | break; | |
9712 | case PORT_CLK_SEL_WRPLL2: | |
9713 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9714 | break; | |
9715 | } | |
9716 | } | |
9717 | ||
26804afd | 9718 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9719 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9720 | { |
9721 | struct drm_device *dev = crtc->base.dev; | |
9722 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9723 | struct intel_shared_dpll *pll; |
26804afd DV |
9724 | enum port port; |
9725 | uint32_t tmp; | |
9726 | ||
9727 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9728 | ||
9729 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9730 | ||
ef11bdb3 | 9731 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 9732 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
9733 | else if (IS_BROXTON(dev)) |
9734 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9735 | else |
9736 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9737 | |
d452c5b6 DV |
9738 | if (pipe_config->shared_dpll >= 0) { |
9739 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9740 | ||
9741 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9742 | &pipe_config->dpll_hw_state)); | |
9743 | } | |
9744 | ||
26804afd DV |
9745 | /* |
9746 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9747 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9748 | * the PCH transcoder is on. | |
9749 | */ | |
ca370455 DL |
9750 | if (INTEL_INFO(dev)->gen < 9 && |
9751 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9752 | pipe_config->has_pch_encoder = true; |
9753 | ||
9754 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9755 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9756 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9757 | ||
9758 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9759 | } | |
9760 | } | |
9761 | ||
0e8ffe1b | 9762 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9763 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9764 | { |
9765 | struct drm_device *dev = crtc->base.dev; | |
9766 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9767 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9768 | uint32_t tmp; |
9769 | ||
f458ebbc | 9770 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9771 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9772 | return false; | |
9773 | ||
e143a21c | 9774 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9775 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9776 | ||
eccb140b DV |
9777 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9778 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9779 | enum pipe trans_edp_pipe; | |
9780 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9781 | default: | |
9782 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9783 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9784 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9785 | trans_edp_pipe = PIPE_A; | |
9786 | break; | |
9787 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9788 | trans_edp_pipe = PIPE_B; | |
9789 | break; | |
9790 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9791 | trans_edp_pipe = PIPE_C; | |
9792 | break; | |
9793 | } | |
9794 | ||
9795 | if (trans_edp_pipe == crtc->pipe) | |
9796 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9797 | } | |
9798 | ||
f458ebbc | 9799 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9800 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9801 | return false; |
9802 | ||
eccb140b | 9803 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9804 | if (!(tmp & PIPECONF_ENABLE)) |
9805 | return false; | |
9806 | ||
26804afd | 9807 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9808 | |
1bd1bd80 DV |
9809 | intel_get_pipe_timings(crtc, pipe_config); |
9810 | ||
a1b2278e CK |
9811 | if (INTEL_INFO(dev)->gen >= 9) { |
9812 | skl_init_scalers(dev, crtc, pipe_config); | |
9813 | } | |
9814 | ||
2fa2fe9a | 9815 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9816 | |
9817 | if (INTEL_INFO(dev)->gen >= 9) { | |
9818 | pipe_config->scaler_state.scaler_id = -1; | |
9819 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9820 | } | |
9821 | ||
bd2e244f | 9822 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
1c132b44 | 9823 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 9824 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9825 | else |
1c132b44 | 9826 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 9827 | } |
88adfff1 | 9828 | |
e59150dc JB |
9829 | if (IS_HASWELL(dev)) |
9830 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9831 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9832 | |
ebb69c95 CT |
9833 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9834 | pipe_config->pixel_multiplier = | |
9835 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9836 | } else { | |
9837 | pipe_config->pixel_multiplier = 1; | |
9838 | } | |
6c49f241 | 9839 | |
0e8ffe1b DV |
9840 | return true; |
9841 | } | |
9842 | ||
560b85bb CW |
9843 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9844 | { | |
9845 | struct drm_device *dev = crtc->dev; | |
9846 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9847 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9848 | uint32_t cntl = 0, size = 0; |
560b85bb | 9849 | |
dc41c154 | 9850 | if (base) { |
3dd512fb MR |
9851 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9852 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9853 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9854 | ||
9855 | switch (stride) { | |
9856 | default: | |
9857 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9858 | width, stride); | |
9859 | stride = 256; | |
9860 | /* fallthrough */ | |
9861 | case 256: | |
9862 | case 512: | |
9863 | case 1024: | |
9864 | case 2048: | |
9865 | break; | |
4b0e333e CW |
9866 | } |
9867 | ||
dc41c154 VS |
9868 | cntl |= CURSOR_ENABLE | |
9869 | CURSOR_GAMMA_ENABLE | | |
9870 | CURSOR_FORMAT_ARGB | | |
9871 | CURSOR_STRIDE(stride); | |
9872 | ||
9873 | size = (height << 12) | width; | |
4b0e333e | 9874 | } |
560b85bb | 9875 | |
dc41c154 VS |
9876 | if (intel_crtc->cursor_cntl != 0 && |
9877 | (intel_crtc->cursor_base != base || | |
9878 | intel_crtc->cursor_size != size || | |
9879 | intel_crtc->cursor_cntl != cntl)) { | |
9880 | /* On these chipsets we can only modify the base/size/stride | |
9881 | * whilst the cursor is disabled. | |
9882 | */ | |
0b87c24e VS |
9883 | I915_WRITE(CURCNTR(PIPE_A), 0); |
9884 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 9885 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9886 | } |
560b85bb | 9887 | |
99d1f387 | 9888 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 9889 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
9890 | intel_crtc->cursor_base = base; |
9891 | } | |
4726e0b0 | 9892 | |
dc41c154 VS |
9893 | if (intel_crtc->cursor_size != size) { |
9894 | I915_WRITE(CURSIZE, size); | |
9895 | intel_crtc->cursor_size = size; | |
4b0e333e | 9896 | } |
560b85bb | 9897 | |
4b0e333e | 9898 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
9899 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
9900 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 9901 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 9902 | } |
560b85bb CW |
9903 | } |
9904 | ||
560b85bb | 9905 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
9906 | { |
9907 | struct drm_device *dev = crtc->dev; | |
9908 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9909 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9910 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
9911 | uint32_t cntl; |
9912 | ||
9913 | cntl = 0; | |
9914 | if (base) { | |
9915 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 9916 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
9917 | case 64: |
9918 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9919 | break; | |
9920 | case 128: | |
9921 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9922 | break; | |
9923 | case 256: | |
9924 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
9925 | break; | |
9926 | default: | |
3dd512fb | 9927 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 9928 | return; |
65a21cd6 | 9929 | } |
4b0e333e | 9930 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 9931 | |
fc6f93bc | 9932 | if (HAS_DDI(dev)) |
47bf17a7 | 9933 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
4b0e333e | 9934 | } |
65a21cd6 | 9935 | |
8e7d688b | 9936 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
9937 | cntl |= CURSOR_ROTATE_180; |
9938 | ||
4b0e333e CW |
9939 | if (intel_crtc->cursor_cntl != cntl) { |
9940 | I915_WRITE(CURCNTR(pipe), cntl); | |
9941 | POSTING_READ(CURCNTR(pipe)); | |
9942 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 9943 | } |
4b0e333e | 9944 | |
65a21cd6 | 9945 | /* and commit changes on next vblank */ |
5efb3e28 VS |
9946 | I915_WRITE(CURBASE(pipe), base); |
9947 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
9948 | |
9949 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
9950 | } |
9951 | ||
cda4b7d3 | 9952 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
9953 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
9954 | bool on) | |
cda4b7d3 CW |
9955 | { |
9956 | struct drm_device *dev = crtc->dev; | |
9957 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9959 | int pipe = intel_crtc->pipe; | |
9b4101be ML |
9960 | struct drm_plane_state *cursor_state = crtc->cursor->state; |
9961 | int x = cursor_state->crtc_x; | |
9962 | int y = cursor_state->crtc_y; | |
d6e4db15 | 9963 | u32 base = 0, pos = 0; |
cda4b7d3 | 9964 | |
d6e4db15 | 9965 | if (on) |
cda4b7d3 | 9966 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 9967 | |
6e3c9717 | 9968 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
9969 | base = 0; |
9970 | ||
6e3c9717 | 9971 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
9972 | base = 0; |
9973 | ||
9974 | if (x < 0) { | |
9b4101be | 9975 | if (x + cursor_state->crtc_w <= 0) |
cda4b7d3 CW |
9976 | base = 0; |
9977 | ||
9978 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
9979 | x = -x; | |
9980 | } | |
9981 | pos |= x << CURSOR_X_SHIFT; | |
9982 | ||
9983 | if (y < 0) { | |
9b4101be | 9984 | if (y + cursor_state->crtc_h <= 0) |
cda4b7d3 CW |
9985 | base = 0; |
9986 | ||
9987 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
9988 | y = -y; | |
9989 | } | |
9990 | pos |= y << CURSOR_Y_SHIFT; | |
9991 | ||
4b0e333e | 9992 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
9993 | return; |
9994 | ||
5efb3e28 VS |
9995 | I915_WRITE(CURPOS(pipe), pos); |
9996 | ||
4398ad45 VS |
9997 | /* ILK+ do this automagically */ |
9998 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 9999 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
9b4101be ML |
10000 | base += (cursor_state->crtc_h * |
10001 | cursor_state->crtc_w - 1) * 4; | |
4398ad45 VS |
10002 | } |
10003 | ||
8ac54669 | 10004 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10005 | i845_update_cursor(crtc, base); |
10006 | else | |
10007 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10008 | } |
10009 | ||
dc41c154 VS |
10010 | static bool cursor_size_ok(struct drm_device *dev, |
10011 | uint32_t width, uint32_t height) | |
10012 | { | |
10013 | if (width == 0 || height == 0) | |
10014 | return false; | |
10015 | ||
10016 | /* | |
10017 | * 845g/865g are special in that they are only limited by | |
10018 | * the width of their cursors, the height is arbitrary up to | |
10019 | * the precision of the register. Everything else requires | |
10020 | * square cursors, limited to a few power-of-two sizes. | |
10021 | */ | |
10022 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10023 | if ((width & 63) != 0) | |
10024 | return false; | |
10025 | ||
10026 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10027 | return false; | |
10028 | ||
10029 | if (height > 1023) | |
10030 | return false; | |
10031 | } else { | |
10032 | switch (width | height) { | |
10033 | case 256: | |
10034 | case 128: | |
10035 | if (IS_GEN2(dev)) | |
10036 | return false; | |
10037 | case 64: | |
10038 | break; | |
10039 | default: | |
10040 | return false; | |
10041 | } | |
10042 | } | |
10043 | ||
10044 | return true; | |
10045 | } | |
10046 | ||
79e53945 | 10047 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10048 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10049 | { |
7203425a | 10050 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10051 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10052 | |
7203425a | 10053 | for (i = start; i < end; i++) { |
79e53945 JB |
10054 | intel_crtc->lut_r[i] = red[i] >> 8; |
10055 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10056 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10057 | } | |
10058 | ||
10059 | intel_crtc_load_lut(crtc); | |
10060 | } | |
10061 | ||
79e53945 JB |
10062 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10063 | static struct drm_display_mode load_detect_mode = { | |
10064 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10065 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10066 | }; | |
10067 | ||
a8bb6818 DV |
10068 | struct drm_framebuffer * |
10069 | __intel_framebuffer_create(struct drm_device *dev, | |
10070 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10071 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10072 | { |
10073 | struct intel_framebuffer *intel_fb; | |
10074 | int ret; | |
10075 | ||
10076 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10077 | if (!intel_fb) |
d2dff872 | 10078 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10079 | |
10080 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10081 | if (ret) |
10082 | goto err; | |
d2dff872 CW |
10083 | |
10084 | return &intel_fb->base; | |
dcb1394e | 10085 | |
dd4916c5 | 10086 | err: |
dd4916c5 | 10087 | kfree(intel_fb); |
dd4916c5 | 10088 | return ERR_PTR(ret); |
d2dff872 CW |
10089 | } |
10090 | ||
b5ea642a | 10091 | static struct drm_framebuffer * |
a8bb6818 DV |
10092 | intel_framebuffer_create(struct drm_device *dev, |
10093 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10094 | struct drm_i915_gem_object *obj) | |
10095 | { | |
10096 | struct drm_framebuffer *fb; | |
10097 | int ret; | |
10098 | ||
10099 | ret = i915_mutex_lock_interruptible(dev); | |
10100 | if (ret) | |
10101 | return ERR_PTR(ret); | |
10102 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10103 | mutex_unlock(&dev->struct_mutex); | |
10104 | ||
10105 | return fb; | |
10106 | } | |
10107 | ||
d2dff872 CW |
10108 | static u32 |
10109 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10110 | { | |
10111 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10112 | return ALIGN(pitch, 64); | |
10113 | } | |
10114 | ||
10115 | static u32 | |
10116 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10117 | { | |
10118 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10119 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10120 | } |
10121 | ||
10122 | static struct drm_framebuffer * | |
10123 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10124 | struct drm_display_mode *mode, | |
10125 | int depth, int bpp) | |
10126 | { | |
dcb1394e | 10127 | struct drm_framebuffer *fb; |
d2dff872 | 10128 | struct drm_i915_gem_object *obj; |
0fed39bd | 10129 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10130 | |
10131 | obj = i915_gem_alloc_object(dev, | |
10132 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10133 | if (obj == NULL) | |
10134 | return ERR_PTR(-ENOMEM); | |
10135 | ||
10136 | mode_cmd.width = mode->hdisplay; | |
10137 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10138 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10139 | bpp); | |
5ca0c34a | 10140 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10141 | |
dcb1394e LW |
10142 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10143 | if (IS_ERR(fb)) | |
10144 | drm_gem_object_unreference_unlocked(&obj->base); | |
10145 | ||
10146 | return fb; | |
d2dff872 CW |
10147 | } |
10148 | ||
10149 | static struct drm_framebuffer * | |
10150 | mode_fits_in_fbdev(struct drm_device *dev, | |
10151 | struct drm_display_mode *mode) | |
10152 | { | |
0695726e | 10153 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10154 | struct drm_i915_private *dev_priv = dev->dev_private; |
10155 | struct drm_i915_gem_object *obj; | |
10156 | struct drm_framebuffer *fb; | |
10157 | ||
4c0e5528 | 10158 | if (!dev_priv->fbdev) |
d2dff872 CW |
10159 | return NULL; |
10160 | ||
4c0e5528 | 10161 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10162 | return NULL; |
10163 | ||
4c0e5528 DV |
10164 | obj = dev_priv->fbdev->fb->obj; |
10165 | BUG_ON(!obj); | |
10166 | ||
8bcd4553 | 10167 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10168 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10169 | fb->bits_per_pixel)) | |
d2dff872 CW |
10170 | return NULL; |
10171 | ||
01f2c773 | 10172 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10173 | return NULL; |
10174 | ||
10175 | return fb; | |
4520f53a DV |
10176 | #else |
10177 | return NULL; | |
10178 | #endif | |
d2dff872 CW |
10179 | } |
10180 | ||
d3a40d1b ACO |
10181 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10182 | struct drm_crtc *crtc, | |
10183 | struct drm_display_mode *mode, | |
10184 | struct drm_framebuffer *fb, | |
10185 | int x, int y) | |
10186 | { | |
10187 | struct drm_plane_state *plane_state; | |
10188 | int hdisplay, vdisplay; | |
10189 | int ret; | |
10190 | ||
10191 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10192 | if (IS_ERR(plane_state)) | |
10193 | return PTR_ERR(plane_state); | |
10194 | ||
10195 | if (mode) | |
10196 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10197 | else | |
10198 | hdisplay = vdisplay = 0; | |
10199 | ||
10200 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10201 | if (ret) | |
10202 | return ret; | |
10203 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10204 | plane_state->crtc_x = 0; | |
10205 | plane_state->crtc_y = 0; | |
10206 | plane_state->crtc_w = hdisplay; | |
10207 | plane_state->crtc_h = vdisplay; | |
10208 | plane_state->src_x = x << 16; | |
10209 | plane_state->src_y = y << 16; | |
10210 | plane_state->src_w = hdisplay << 16; | |
10211 | plane_state->src_h = vdisplay << 16; | |
10212 | ||
10213 | return 0; | |
10214 | } | |
10215 | ||
d2434ab7 | 10216 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10217 | struct drm_display_mode *mode, |
51fd371b RC |
10218 | struct intel_load_detect_pipe *old, |
10219 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10220 | { |
10221 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10222 | struct intel_encoder *intel_encoder = |
10223 | intel_attached_encoder(connector); | |
79e53945 | 10224 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10225 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10226 | struct drm_crtc *crtc = NULL; |
10227 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10228 | struct drm_framebuffer *fb; |
51fd371b | 10229 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10230 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10231 | struct drm_connector_state *connector_state; |
4be07317 | 10232 | struct intel_crtc_state *crtc_state; |
51fd371b | 10233 | int ret, i = -1; |
79e53945 | 10234 | |
d2dff872 | 10235 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10236 | connector->base.id, connector->name, |
8e329a03 | 10237 | encoder->base.id, encoder->name); |
d2dff872 | 10238 | |
51fd371b RC |
10239 | retry: |
10240 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10241 | if (ret) | |
ad3c558f | 10242 | goto fail; |
6e9f798d | 10243 | |
79e53945 JB |
10244 | /* |
10245 | * Algorithm gets a little messy: | |
7a5e4805 | 10246 | * |
79e53945 JB |
10247 | * - if the connector already has an assigned crtc, use it (but make |
10248 | * sure it's on first) | |
7a5e4805 | 10249 | * |
79e53945 JB |
10250 | * - try to find the first unused crtc that can drive this connector, |
10251 | * and use that if we find one | |
79e53945 JB |
10252 | */ |
10253 | ||
10254 | /* See if we already have a CRTC for this connector */ | |
10255 | if (encoder->crtc) { | |
10256 | crtc = encoder->crtc; | |
8261b191 | 10257 | |
51fd371b | 10258 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10259 | if (ret) |
ad3c558f | 10260 | goto fail; |
4d02e2de | 10261 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
51fd371b | 10262 | if (ret) |
ad3c558f | 10263 | goto fail; |
7b24056b | 10264 | |
24218aac | 10265 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10266 | old->load_detect_temp = false; |
10267 | ||
10268 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10269 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10270 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10271 | |
7173188d | 10272 | return true; |
79e53945 JB |
10273 | } |
10274 | ||
10275 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10276 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10277 | i++; |
10278 | if (!(encoder->possible_crtcs & (1 << i))) | |
10279 | continue; | |
83d65738 | 10280 | if (possible_crtc->state->enable) |
a459249c | 10281 | continue; |
a459249c VS |
10282 | |
10283 | crtc = possible_crtc; | |
10284 | break; | |
79e53945 JB |
10285 | } |
10286 | ||
10287 | /* | |
10288 | * If we didn't find an unused CRTC, don't use any. | |
10289 | */ | |
10290 | if (!crtc) { | |
7173188d | 10291 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10292 | goto fail; |
79e53945 JB |
10293 | } |
10294 | ||
51fd371b RC |
10295 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10296 | if (ret) | |
ad3c558f | 10297 | goto fail; |
4d02e2de DV |
10298 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10299 | if (ret) | |
ad3c558f | 10300 | goto fail; |
79e53945 JB |
10301 | |
10302 | intel_crtc = to_intel_crtc(crtc); | |
24218aac | 10303 | old->dpms_mode = connector->dpms; |
8261b191 | 10304 | old->load_detect_temp = true; |
d2dff872 | 10305 | old->release_fb = NULL; |
79e53945 | 10306 | |
83a57153 ACO |
10307 | state = drm_atomic_state_alloc(dev); |
10308 | if (!state) | |
10309 | return false; | |
10310 | ||
10311 | state->acquire_ctx = ctx; | |
10312 | ||
944b0c76 ACO |
10313 | connector_state = drm_atomic_get_connector_state(state, connector); |
10314 | if (IS_ERR(connector_state)) { | |
10315 | ret = PTR_ERR(connector_state); | |
10316 | goto fail; | |
10317 | } | |
10318 | ||
10319 | connector_state->crtc = crtc; | |
10320 | connector_state->best_encoder = &intel_encoder->base; | |
10321 | ||
4be07317 ACO |
10322 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10323 | if (IS_ERR(crtc_state)) { | |
10324 | ret = PTR_ERR(crtc_state); | |
10325 | goto fail; | |
10326 | } | |
10327 | ||
49d6fa21 | 10328 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10329 | |
6492711d CW |
10330 | if (!mode) |
10331 | mode = &load_detect_mode; | |
79e53945 | 10332 | |
d2dff872 CW |
10333 | /* We need a framebuffer large enough to accommodate all accesses |
10334 | * that the plane may generate whilst we perform load detection. | |
10335 | * We can not rely on the fbcon either being present (we get called | |
10336 | * during its initialisation to detect all boot displays, or it may | |
10337 | * not even exist) or that it is large enough to satisfy the | |
10338 | * requested mode. | |
10339 | */ | |
94352cf9 DV |
10340 | fb = mode_fits_in_fbdev(dev, mode); |
10341 | if (fb == NULL) { | |
d2dff872 | 10342 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10343 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10344 | old->release_fb = fb; | |
d2dff872 CW |
10345 | } else |
10346 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10347 | if (IS_ERR(fb)) { |
d2dff872 | 10348 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10349 | goto fail; |
79e53945 | 10350 | } |
79e53945 | 10351 | |
d3a40d1b ACO |
10352 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10353 | if (ret) | |
10354 | goto fail; | |
10355 | ||
8c7b5ccb ACO |
10356 | drm_mode_copy(&crtc_state->base.mode, mode); |
10357 | ||
74c090b1 | 10358 | if (drm_atomic_commit(state)) { |
6492711d | 10359 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10360 | if (old->release_fb) |
10361 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10362 | goto fail; |
79e53945 | 10363 | } |
9128b040 | 10364 | crtc->primary->crtc = crtc; |
7173188d | 10365 | |
79e53945 | 10366 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10367 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10368 | return true; |
412b61d8 | 10369 | |
ad3c558f | 10370 | fail: |
e5d958ef ACO |
10371 | drm_atomic_state_free(state); |
10372 | state = NULL; | |
83a57153 | 10373 | |
51fd371b RC |
10374 | if (ret == -EDEADLK) { |
10375 | drm_modeset_backoff(ctx); | |
10376 | goto retry; | |
10377 | } | |
10378 | ||
412b61d8 | 10379 | return false; |
79e53945 JB |
10380 | } |
10381 | ||
d2434ab7 | 10382 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10383 | struct intel_load_detect_pipe *old, |
10384 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10385 | { |
83a57153 | 10386 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10387 | struct intel_encoder *intel_encoder = |
10388 | intel_attached_encoder(connector); | |
4ef69c7a | 10389 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10390 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10391 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10392 | struct drm_atomic_state *state; |
944b0c76 | 10393 | struct drm_connector_state *connector_state; |
4be07317 | 10394 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10395 | int ret; |
79e53945 | 10396 | |
d2dff872 | 10397 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10398 | connector->base.id, connector->name, |
8e329a03 | 10399 | encoder->base.id, encoder->name); |
d2dff872 | 10400 | |
8261b191 | 10401 | if (old->load_detect_temp) { |
83a57153 | 10402 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10403 | if (!state) |
10404 | goto fail; | |
83a57153 ACO |
10405 | |
10406 | state->acquire_ctx = ctx; | |
10407 | ||
944b0c76 ACO |
10408 | connector_state = drm_atomic_get_connector_state(state, connector); |
10409 | if (IS_ERR(connector_state)) | |
10410 | goto fail; | |
10411 | ||
4be07317 ACO |
10412 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10413 | if (IS_ERR(crtc_state)) | |
10414 | goto fail; | |
10415 | ||
944b0c76 ACO |
10416 | connector_state->best_encoder = NULL; |
10417 | connector_state->crtc = NULL; | |
10418 | ||
49d6fa21 | 10419 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10420 | |
d3a40d1b ACO |
10421 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10422 | 0, 0); | |
10423 | if (ret) | |
10424 | goto fail; | |
10425 | ||
74c090b1 | 10426 | ret = drm_atomic_commit(state); |
2bfb4627 ACO |
10427 | if (ret) |
10428 | goto fail; | |
d2dff872 | 10429 | |
36206361 DV |
10430 | if (old->release_fb) { |
10431 | drm_framebuffer_unregister_private(old->release_fb); | |
10432 | drm_framebuffer_unreference(old->release_fb); | |
10433 | } | |
d2dff872 | 10434 | |
0622a53c | 10435 | return; |
79e53945 JB |
10436 | } |
10437 | ||
c751ce4f | 10438 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10439 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10440 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10441 | |
10442 | return; | |
10443 | fail: | |
10444 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10445 | drm_atomic_state_free(state); | |
79e53945 JB |
10446 | } |
10447 | ||
da4a1efa | 10448 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10449 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10450 | { |
10451 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10452 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10453 | ||
10454 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10455 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10456 | else if (HAS_PCH_SPLIT(dev)) |
10457 | return 120000; | |
10458 | else if (!IS_GEN2(dev)) | |
10459 | return 96000; | |
10460 | else | |
10461 | return 48000; | |
10462 | } | |
10463 | ||
79e53945 | 10464 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10465 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10466 | struct intel_crtc_state *pipe_config) |
79e53945 | 10467 | { |
f1f644dc | 10468 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10469 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10470 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10471 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10472 | u32 fp; |
10473 | intel_clock_t clock; | |
dccbea3b | 10474 | int port_clock; |
da4a1efa | 10475 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10476 | |
10477 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10478 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10479 | else |
293623f7 | 10480 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10481 | |
10482 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10483 | if (IS_PINEVIEW(dev)) { |
10484 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10485 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10486 | } else { |
10487 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10488 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10489 | } | |
10490 | ||
a6c45cf0 | 10491 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10492 | if (IS_PINEVIEW(dev)) |
10493 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10494 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10495 | else |
10496 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10497 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10498 | ||
10499 | switch (dpll & DPLL_MODE_MASK) { | |
10500 | case DPLLB_MODE_DAC_SERIAL: | |
10501 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10502 | 5 : 10; | |
10503 | break; | |
10504 | case DPLLB_MODE_LVDS: | |
10505 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10506 | 7 : 14; | |
10507 | break; | |
10508 | default: | |
28c97730 | 10509 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10510 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10511 | return; |
79e53945 JB |
10512 | } |
10513 | ||
ac58c3f0 | 10514 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10515 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10516 | else |
dccbea3b | 10517 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10518 | } else { |
0fb58223 | 10519 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10520 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10521 | |
10522 | if (is_lvds) { | |
10523 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10524 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10525 | |
10526 | if (lvds & LVDS_CLKB_POWER_UP) | |
10527 | clock.p2 = 7; | |
10528 | else | |
10529 | clock.p2 = 14; | |
79e53945 JB |
10530 | } else { |
10531 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10532 | clock.p1 = 2; | |
10533 | else { | |
10534 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10535 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10536 | } | |
10537 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10538 | clock.p2 = 4; | |
10539 | else | |
10540 | clock.p2 = 2; | |
79e53945 | 10541 | } |
da4a1efa | 10542 | |
dccbea3b | 10543 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10544 | } |
10545 | ||
18442d08 VS |
10546 | /* |
10547 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10548 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10549 | * encoder's get_config() function. |
10550 | */ | |
dccbea3b | 10551 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10552 | } |
10553 | ||
6878da05 VS |
10554 | int intel_dotclock_calculate(int link_freq, |
10555 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10556 | { |
f1f644dc JB |
10557 | /* |
10558 | * The calculation for the data clock is: | |
1041a02f | 10559 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10560 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10561 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10562 | * |
10563 | * and the link clock is simpler: | |
1041a02f | 10564 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10565 | */ |
10566 | ||
6878da05 VS |
10567 | if (!m_n->link_n) |
10568 | return 0; | |
f1f644dc | 10569 | |
6878da05 VS |
10570 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10571 | } | |
f1f644dc | 10572 | |
18442d08 | 10573 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10574 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10575 | { |
10576 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10577 | |
18442d08 VS |
10578 | /* read out port_clock from the DPLL */ |
10579 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10580 | |
f1f644dc | 10581 | /* |
18442d08 | 10582 | * This value does not include pixel_multiplier. |
241bfc38 | 10583 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10584 | * agree once we know their relationship in the encoder's |
10585 | * get_config() function. | |
79e53945 | 10586 | */ |
2d112de7 | 10587 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10588 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10589 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10590 | } |
10591 | ||
10592 | /** Returns the currently programmed mode of the given pipe. */ | |
10593 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10594 | struct drm_crtc *crtc) | |
10595 | { | |
548f245b | 10596 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10597 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10598 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10599 | struct drm_display_mode *mode; |
5cec258b | 10600 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10601 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10602 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10603 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10604 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10605 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10606 | |
10607 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10608 | if (!mode) | |
10609 | return NULL; | |
10610 | ||
f1f644dc JB |
10611 | /* |
10612 | * Construct a pipe_config sufficient for getting the clock info | |
10613 | * back out of crtc_clock_get. | |
10614 | * | |
10615 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10616 | * to use a real value here instead. | |
10617 | */ | |
293623f7 | 10618 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10619 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10620 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10621 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10622 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10623 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10624 | ||
773ae034 | 10625 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10626 | mode->hdisplay = (htot & 0xffff) + 1; |
10627 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10628 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10629 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10630 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10631 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10632 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10633 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10634 | ||
10635 | drm_mode_set_name(mode); | |
79e53945 JB |
10636 | |
10637 | return mode; | |
10638 | } | |
10639 | ||
f047e395 CW |
10640 | void intel_mark_busy(struct drm_device *dev) |
10641 | { | |
c67a470b PZ |
10642 | struct drm_i915_private *dev_priv = dev->dev_private; |
10643 | ||
f62a0076 CW |
10644 | if (dev_priv->mm.busy) |
10645 | return; | |
10646 | ||
43694d69 | 10647 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10648 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10649 | if (INTEL_INFO(dev)->gen >= 6) |
10650 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10651 | dev_priv->mm.busy = true; |
f047e395 CW |
10652 | } |
10653 | ||
10654 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10655 | { |
c67a470b | 10656 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10657 | |
f62a0076 CW |
10658 | if (!dev_priv->mm.busy) |
10659 | return; | |
10660 | ||
10661 | dev_priv->mm.busy = false; | |
10662 | ||
3d13ef2e | 10663 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10664 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10665 | |
43694d69 | 10666 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10667 | } |
10668 | ||
79e53945 JB |
10669 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10670 | { | |
10671 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10672 | struct drm_device *dev = crtc->dev; |
10673 | struct intel_unpin_work *work; | |
67e77c5a | 10674 | |
5e2d7afc | 10675 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10676 | work = intel_crtc->unpin_work; |
10677 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10678 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10679 | |
10680 | if (work) { | |
10681 | cancel_work_sync(&work->work); | |
10682 | kfree(work); | |
10683 | } | |
79e53945 JB |
10684 | |
10685 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10686 | |
79e53945 JB |
10687 | kfree(intel_crtc); |
10688 | } | |
10689 | ||
6b95a207 KH |
10690 | static void intel_unpin_work_fn(struct work_struct *__work) |
10691 | { | |
10692 | struct intel_unpin_work *work = | |
10693 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10694 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10695 | struct drm_device *dev = crtc->base.dev; | |
10696 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10697 | |
b4a98e57 | 10698 | mutex_lock(&dev->struct_mutex); |
a9ff8714 | 10699 | intel_unpin_fb_obj(work->old_fb, primary->state); |
05394f39 | 10700 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10701 | |
f06cc1b9 | 10702 | if (work->flip_queued_req) |
146d84f0 | 10703 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10704 | mutex_unlock(&dev->struct_mutex); |
10705 | ||
a9ff8714 | 10706 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
89ed88ba | 10707 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10708 | |
a9ff8714 VS |
10709 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10710 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10711 | |
6b95a207 KH |
10712 | kfree(work); |
10713 | } | |
10714 | ||
1afe3e9d | 10715 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10716 | struct drm_crtc *crtc) |
6b95a207 | 10717 | { |
6b95a207 KH |
10718 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10719 | struct intel_unpin_work *work; | |
6b95a207 KH |
10720 | unsigned long flags; |
10721 | ||
10722 | /* Ignore early vblank irqs */ | |
10723 | if (intel_crtc == NULL) | |
10724 | return; | |
10725 | ||
f326038a DV |
10726 | /* |
10727 | * This is called both by irq handlers and the reset code (to complete | |
10728 | * lost pageflips) so needs the full irqsave spinlocks. | |
10729 | */ | |
6b95a207 KH |
10730 | spin_lock_irqsave(&dev->event_lock, flags); |
10731 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10732 | |
10733 | /* Ensure we don't miss a work->pending update ... */ | |
10734 | smp_rmb(); | |
10735 | ||
10736 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10737 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10738 | return; | |
10739 | } | |
10740 | ||
d6bbafa1 | 10741 | page_flip_completed(intel_crtc); |
0af7e4df | 10742 | |
6b95a207 | 10743 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10744 | } |
10745 | ||
1afe3e9d JB |
10746 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10747 | { | |
fbee40df | 10748 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10749 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10750 | ||
49b14a5c | 10751 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10752 | } |
10753 | ||
10754 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10755 | { | |
fbee40df | 10756 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10757 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10758 | ||
49b14a5c | 10759 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10760 | } |
10761 | ||
75f7f3ec VS |
10762 | /* Is 'a' after or equal to 'b'? */ |
10763 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10764 | { | |
10765 | return !((a - b) & 0x80000000); | |
10766 | } | |
10767 | ||
10768 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10769 | { | |
10770 | struct drm_device *dev = crtc->base.dev; | |
10771 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10772 | ||
bdfa7542 VS |
10773 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10774 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10775 | return true; | |
10776 | ||
75f7f3ec VS |
10777 | /* |
10778 | * The relevant registers doen't exist on pre-ctg. | |
10779 | * As the flip done interrupt doesn't trigger for mmio | |
10780 | * flips on gmch platforms, a flip count check isn't | |
10781 | * really needed there. But since ctg has the registers, | |
10782 | * include it in the check anyway. | |
10783 | */ | |
10784 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10785 | return true; | |
10786 | ||
10787 | /* | |
10788 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10789 | * used the same base address. In that case the mmio flip might | |
10790 | * have completed, but the CS hasn't even executed the flip yet. | |
10791 | * | |
10792 | * A flip count check isn't enough as the CS might have updated | |
10793 | * the base address just after start of vblank, but before we | |
10794 | * managed to process the interrupt. This means we'd complete the | |
10795 | * CS flip too soon. | |
10796 | * | |
10797 | * Combining both checks should get us a good enough result. It may | |
10798 | * still happen that the CS flip has been executed, but has not | |
10799 | * yet actually completed. But in case the base address is the same | |
10800 | * anyway, we don't really care. | |
10801 | */ | |
10802 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10803 | crtc->unpin_work->gtt_offset && | |
fd8f507c | 10804 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
75f7f3ec VS |
10805 | crtc->unpin_work->flip_count); |
10806 | } | |
10807 | ||
6b95a207 KH |
10808 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10809 | { | |
fbee40df | 10810 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10811 | struct intel_crtc *intel_crtc = |
10812 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10813 | unsigned long flags; | |
10814 | ||
f326038a DV |
10815 | |
10816 | /* | |
10817 | * This is called both by irq handlers and the reset code (to complete | |
10818 | * lost pageflips) so needs the full irqsave spinlocks. | |
10819 | * | |
10820 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10821 | * generate a page-flip completion irq, i.e. every modeset |
10822 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10823 | */ | |
6b95a207 | 10824 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10825 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10826 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10827 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10828 | } | |
10829 | ||
6042639c | 10830 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
e7d841ca CW |
10831 | { |
10832 | /* Ensure that the work item is consistent when activating it ... */ | |
10833 | smp_wmb(); | |
6042639c | 10834 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
e7d841ca CW |
10835 | /* and that it is marked active as soon as the irq could fire. */ |
10836 | smp_wmb(); | |
10837 | } | |
10838 | ||
8c9f3aaf JB |
10839 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10840 | struct drm_crtc *crtc, | |
10841 | struct drm_framebuffer *fb, | |
ed8d1975 | 10842 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10843 | struct drm_i915_gem_request *req, |
ed8d1975 | 10844 | uint32_t flags) |
8c9f3aaf | 10845 | { |
6258fbe2 | 10846 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10847 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10848 | u32 flip_mask; |
10849 | int ret; | |
10850 | ||
5fb9de1a | 10851 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10852 | if (ret) |
4fa62c89 | 10853 | return ret; |
8c9f3aaf JB |
10854 | |
10855 | /* Can't queue multiple flips, so wait for the previous | |
10856 | * one to finish before executing the next. | |
10857 | */ | |
10858 | if (intel_crtc->plane) | |
10859 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10860 | else | |
10861 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10862 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10863 | intel_ring_emit(ring, MI_NOOP); | |
10864 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10865 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10866 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10867 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10868 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca | 10869 | |
6042639c | 10870 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10871 | return 0; |
8c9f3aaf JB |
10872 | } |
10873 | ||
10874 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10875 | struct drm_crtc *crtc, | |
10876 | struct drm_framebuffer *fb, | |
ed8d1975 | 10877 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10878 | struct drm_i915_gem_request *req, |
ed8d1975 | 10879 | uint32_t flags) |
8c9f3aaf | 10880 | { |
6258fbe2 | 10881 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10882 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10883 | u32 flip_mask; |
10884 | int ret; | |
10885 | ||
5fb9de1a | 10886 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10887 | if (ret) |
4fa62c89 | 10888 | return ret; |
8c9f3aaf JB |
10889 | |
10890 | if (intel_crtc->plane) | |
10891 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10892 | else | |
10893 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10894 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10895 | intel_ring_emit(ring, MI_NOOP); | |
10896 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
10897 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10898 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10899 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
10900 | intel_ring_emit(ring, MI_NOOP); |
10901 | ||
6042639c | 10902 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10903 | return 0; |
8c9f3aaf JB |
10904 | } |
10905 | ||
10906 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
10907 | struct drm_crtc *crtc, | |
10908 | struct drm_framebuffer *fb, | |
ed8d1975 | 10909 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10910 | struct drm_i915_gem_request *req, |
ed8d1975 | 10911 | uint32_t flags) |
8c9f3aaf | 10912 | { |
6258fbe2 | 10913 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10914 | struct drm_i915_private *dev_priv = dev->dev_private; |
10915 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10916 | uint32_t pf, pipesrc; | |
10917 | int ret; | |
10918 | ||
5fb9de1a | 10919 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10920 | if (ret) |
4fa62c89 | 10921 | return ret; |
8c9f3aaf JB |
10922 | |
10923 | /* i965+ uses the linear or tiled offsets from the | |
10924 | * Display Registers (which do not change across a page-flip) | |
10925 | * so we need only reprogram the base address. | |
10926 | */ | |
6d90c952 DV |
10927 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10928 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10929 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10930 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 10931 | obj->tiling_mode); |
8c9f3aaf JB |
10932 | |
10933 | /* XXX Enabling the panel-fitter across page-flip is so far | |
10934 | * untested on non-native modes, so ignore it for now. | |
10935 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
10936 | */ | |
10937 | pf = 0; | |
10938 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 10939 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 10940 | |
6042639c | 10941 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10942 | return 0; |
8c9f3aaf JB |
10943 | } |
10944 | ||
10945 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
10946 | struct drm_crtc *crtc, | |
10947 | struct drm_framebuffer *fb, | |
ed8d1975 | 10948 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10949 | struct drm_i915_gem_request *req, |
ed8d1975 | 10950 | uint32_t flags) |
8c9f3aaf | 10951 | { |
6258fbe2 | 10952 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10953 | struct drm_i915_private *dev_priv = dev->dev_private; |
10954 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10955 | uint32_t pf, pipesrc; | |
10956 | int ret; | |
10957 | ||
5fb9de1a | 10958 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10959 | if (ret) |
4fa62c89 | 10960 | return ret; |
8c9f3aaf | 10961 | |
6d90c952 DV |
10962 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10963 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10964 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 10965 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 10966 | |
dc257cf1 DV |
10967 | /* Contrary to the suggestions in the documentation, |
10968 | * "Enable Panel Fitter" does not seem to be required when page | |
10969 | * flipping with a non-native mode, and worse causes a normal | |
10970 | * modeset to fail. | |
10971 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
10972 | */ | |
10973 | pf = 0; | |
8c9f3aaf | 10974 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 10975 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 10976 | |
6042639c | 10977 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10978 | return 0; |
8c9f3aaf JB |
10979 | } |
10980 | ||
7c9017e5 JB |
10981 | static int intel_gen7_queue_flip(struct drm_device *dev, |
10982 | struct drm_crtc *crtc, | |
10983 | struct drm_framebuffer *fb, | |
ed8d1975 | 10984 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10985 | struct drm_i915_gem_request *req, |
ed8d1975 | 10986 | uint32_t flags) |
7c9017e5 | 10987 | { |
6258fbe2 | 10988 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 10989 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 10990 | uint32_t plane_bit = 0; |
ffe74d75 CW |
10991 | int len, ret; |
10992 | ||
eba905b2 | 10993 | switch (intel_crtc->plane) { |
cb05d8de DV |
10994 | case PLANE_A: |
10995 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
10996 | break; | |
10997 | case PLANE_B: | |
10998 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
10999 | break; | |
11000 | case PLANE_C: | |
11001 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11002 | break; | |
11003 | default: | |
11004 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11005 | return -ENODEV; |
cb05d8de DV |
11006 | } |
11007 | ||
ffe74d75 | 11008 | len = 4; |
f476828a | 11009 | if (ring->id == RCS) { |
ffe74d75 | 11010 | len += 6; |
f476828a DL |
11011 | /* |
11012 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11013 | * 48bits addresses, and we need a NOOP for the batch size to | |
11014 | * stay even. | |
11015 | */ | |
11016 | if (IS_GEN8(dev)) | |
11017 | len += 2; | |
11018 | } | |
ffe74d75 | 11019 | |
f66fab8e VS |
11020 | /* |
11021 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11022 | * "The full packet must be contained within the same cache line." | |
11023 | * | |
11024 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11025 | * cacheline, if we ever start emitting more commands before | |
11026 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11027 | * then do the cacheline alignment, and finally emit the | |
11028 | * MI_DISPLAY_FLIP. | |
11029 | */ | |
bba09b12 | 11030 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 11031 | if (ret) |
4fa62c89 | 11032 | return ret; |
f66fab8e | 11033 | |
5fb9de1a | 11034 | ret = intel_ring_begin(req, len); |
7c9017e5 | 11035 | if (ret) |
4fa62c89 | 11036 | return ret; |
7c9017e5 | 11037 | |
ffe74d75 CW |
11038 | /* Unmask the flip-done completion message. Note that the bspec says that |
11039 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11040 | * more than one flip event at any time (or ensure that one flip message | |
11041 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11042 | * Experimentation says that BCS works despite DERRMR masking all | |
11043 | * flip-done completion events and that unmasking all planes at once | |
11044 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11045 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11046 | */ | |
11047 | if (ring->id == RCS) { | |
11048 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11049 | intel_ring_emit(ring, DERRMR); | |
11050 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11051 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11052 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11053 | if (IS_GEN8(dev)) |
f1afe24f | 11054 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11055 | MI_SRM_LRM_GLOBAL_GTT); |
11056 | else | |
f1afe24f | 11057 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11058 | MI_SRM_LRM_GLOBAL_GTT); |
ffe74d75 CW |
11059 | intel_ring_emit(ring, DERRMR); |
11060 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
11061 | if (IS_GEN8(dev)) { |
11062 | intel_ring_emit(ring, 0); | |
11063 | intel_ring_emit(ring, MI_NOOP); | |
11064 | } | |
ffe74d75 CW |
11065 | } |
11066 | ||
cb05d8de | 11067 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11068 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11069 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11070 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca | 11071 | |
6042639c | 11072 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11073 | return 0; |
7c9017e5 JB |
11074 | } |
11075 | ||
84c33a64 SG |
11076 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11077 | struct drm_i915_gem_object *obj) | |
11078 | { | |
11079 | /* | |
11080 | * This is not being used for older platforms, because | |
11081 | * non-availability of flip done interrupt forces us to use | |
11082 | * CS flips. Older platforms derive flip done using some clever | |
11083 | * tricks involving the flip_pending status bits and vblank irqs. | |
11084 | * So using MMIO flips there would disrupt this mechanism. | |
11085 | */ | |
11086 | ||
8e09bf83 CW |
11087 | if (ring == NULL) |
11088 | return true; | |
11089 | ||
84c33a64 SG |
11090 | if (INTEL_INFO(ring->dev)->gen < 5) |
11091 | return false; | |
11092 | ||
11093 | if (i915.use_mmio_flip < 0) | |
11094 | return false; | |
11095 | else if (i915.use_mmio_flip > 0) | |
11096 | return true; | |
14bf993e OM |
11097 | else if (i915.enable_execlists) |
11098 | return true; | |
84c33a64 | 11099 | else |
b4716185 | 11100 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11101 | } |
11102 | ||
6042639c | 11103 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
86efe24a | 11104 | unsigned int rotation, |
6042639c | 11105 | struct intel_unpin_work *work) |
ff944564 DL |
11106 | { |
11107 | struct drm_device *dev = intel_crtc->base.dev; | |
11108 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11109 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 | 11110 | const enum pipe pipe = intel_crtc->pipe; |
86efe24a | 11111 | u32 ctl, stride, tile_height; |
ff944564 DL |
11112 | |
11113 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11114 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11115 | switch (fb->modifier[0]) { |
11116 | case DRM_FORMAT_MOD_NONE: | |
11117 | break; | |
11118 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11119 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11120 | break; |
11121 | case I915_FORMAT_MOD_Y_TILED: | |
11122 | ctl |= PLANE_CTL_TILED_Y; | |
11123 | break; | |
11124 | case I915_FORMAT_MOD_Yf_TILED: | |
11125 | ctl |= PLANE_CTL_TILED_YF; | |
11126 | break; | |
11127 | default: | |
11128 | MISSING_CASE(fb->modifier[0]); | |
11129 | } | |
ff944564 DL |
11130 | |
11131 | /* | |
11132 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11133 | * linear buffers or in number of tiles for tiled buffers. | |
11134 | */ | |
86efe24a TU |
11135 | if (intel_rotation_90_or_270(rotation)) { |
11136 | /* stride = Surface height in tiles */ | |
11137 | tile_height = intel_tile_height(dev, fb->pixel_format, | |
11138 | fb->modifier[0], 0); | |
11139 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11140 | } else { | |
11141 | stride = fb->pitches[0] / | |
11142 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11143 | fb->pixel_format); | |
11144 | } | |
ff944564 DL |
11145 | |
11146 | /* | |
11147 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11148 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11149 | */ | |
11150 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11151 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11152 | ||
6042639c | 11153 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
ff944564 DL |
11154 | POSTING_READ(PLANE_SURF(pipe, 0)); |
11155 | } | |
11156 | ||
6042639c CW |
11157 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
11158 | struct intel_unpin_work *work) | |
84c33a64 SG |
11159 | { |
11160 | struct drm_device *dev = intel_crtc->base.dev; | |
11161 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11162 | struct intel_framebuffer *intel_fb = | |
11163 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11164 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11165 | u32 dspcntr; | |
11166 | u32 reg; | |
11167 | ||
84c33a64 SG |
11168 | reg = DSPCNTR(intel_crtc->plane); |
11169 | dspcntr = I915_READ(reg); | |
11170 | ||
c5d97472 DL |
11171 | if (obj->tiling_mode != I915_TILING_NONE) |
11172 | dspcntr |= DISPPLANE_TILED; | |
11173 | else | |
11174 | dspcntr &= ~DISPPLANE_TILED; | |
11175 | ||
84c33a64 SG |
11176 | I915_WRITE(reg, dspcntr); |
11177 | ||
6042639c | 11178 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
84c33a64 | 11179 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
ff944564 DL |
11180 | } |
11181 | ||
11182 | /* | |
11183 | * XXX: This is the temporary way to update the plane registers until we get | |
11184 | * around to using the usual plane update functions for MMIO flips | |
11185 | */ | |
6042639c | 11186 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
ff944564 | 11187 | { |
6042639c CW |
11188 | struct intel_crtc *crtc = mmio_flip->crtc; |
11189 | struct intel_unpin_work *work; | |
11190 | ||
11191 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11192 | work = crtc->unpin_work; | |
11193 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11194 | if (work == NULL) | |
11195 | return; | |
ff944564 | 11196 | |
6042639c | 11197 | intel_mark_page_flip_active(work); |
ff944564 | 11198 | |
6042639c | 11199 | intel_pipe_update_start(crtc); |
ff944564 | 11200 | |
6042639c | 11201 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
86efe24a | 11202 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
ff944564 DL |
11203 | else |
11204 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
6042639c | 11205 | ilk_do_mmio_flip(crtc, work); |
ff944564 | 11206 | |
6042639c | 11207 | intel_pipe_update_end(crtc); |
84c33a64 SG |
11208 | } |
11209 | ||
9362c7c5 | 11210 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11211 | { |
b2cfe0ab CW |
11212 | struct intel_mmio_flip *mmio_flip = |
11213 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11214 | |
6042639c | 11215 | if (mmio_flip->req) { |
eed29a5b | 11216 | WARN_ON(__i915_wait_request(mmio_flip->req, |
b2cfe0ab | 11217 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11218 | false, NULL, |
11219 | &mmio_flip->i915->rps.mmioflips)); | |
6042639c CW |
11220 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
11221 | } | |
84c33a64 | 11222 | |
6042639c | 11223 | intel_do_mmio_flip(mmio_flip); |
b2cfe0ab | 11224 | kfree(mmio_flip); |
84c33a64 SG |
11225 | } |
11226 | ||
11227 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11228 | struct drm_crtc *crtc, | |
86efe24a | 11229 | struct drm_i915_gem_object *obj) |
84c33a64 | 11230 | { |
b2cfe0ab CW |
11231 | struct intel_mmio_flip *mmio_flip; |
11232 | ||
11233 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11234 | if (mmio_flip == NULL) | |
11235 | return -ENOMEM; | |
84c33a64 | 11236 | |
bcafc4e3 | 11237 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11238 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11239 | mmio_flip->crtc = to_intel_crtc(crtc); |
86efe24a | 11240 | mmio_flip->rotation = crtc->primary->state->rotation; |
536f5b5e | 11241 | |
b2cfe0ab CW |
11242 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11243 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11244 | |
84c33a64 SG |
11245 | return 0; |
11246 | } | |
11247 | ||
8c9f3aaf JB |
11248 | static int intel_default_queue_flip(struct drm_device *dev, |
11249 | struct drm_crtc *crtc, | |
11250 | struct drm_framebuffer *fb, | |
ed8d1975 | 11251 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11252 | struct drm_i915_gem_request *req, |
ed8d1975 | 11253 | uint32_t flags) |
8c9f3aaf JB |
11254 | { |
11255 | return -ENODEV; | |
11256 | } | |
11257 | ||
d6bbafa1 CW |
11258 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11259 | struct drm_crtc *crtc) | |
11260 | { | |
11261 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11262 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11263 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11264 | u32 addr; | |
11265 | ||
11266 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11267 | return true; | |
11268 | ||
908565c2 CW |
11269 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11270 | return false; | |
11271 | ||
d6bbafa1 CW |
11272 | if (!work->enable_stall_check) |
11273 | return false; | |
11274 | ||
11275 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11276 | if (work->flip_queued_req && |
11277 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11278 | return false; |
11279 | ||
1e3feefd | 11280 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11281 | } |
11282 | ||
1e3feefd | 11283 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11284 | return false; |
11285 | ||
11286 | /* Potential stall - if we see that the flip has happened, | |
11287 | * assume a missed interrupt. */ | |
11288 | if (INTEL_INFO(dev)->gen >= 4) | |
11289 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11290 | else | |
11291 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11292 | ||
11293 | /* There is a potential issue here with a false positive after a flip | |
11294 | * to the same address. We could address this by checking for a | |
11295 | * non-incrementing frame counter. | |
11296 | */ | |
11297 | return addr == work->gtt_offset; | |
11298 | } | |
11299 | ||
11300 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11301 | { | |
11302 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11303 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11304 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11305 | struct intel_unpin_work *work; |
f326038a | 11306 | |
6c51d46f | 11307 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11308 | |
11309 | if (crtc == NULL) | |
11310 | return; | |
11311 | ||
f326038a | 11312 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11313 | work = intel_crtc->unpin_work; |
11314 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11315 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11316 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11317 | page_flip_completed(intel_crtc); |
6ad790c0 | 11318 | work = NULL; |
d6bbafa1 | 11319 | } |
6ad790c0 CW |
11320 | if (work != NULL && |
11321 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11322 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11323 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11324 | } |
11325 | ||
6b95a207 KH |
11326 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11327 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11328 | struct drm_pending_vblank_event *event, |
11329 | uint32_t page_flip_flags) | |
6b95a207 KH |
11330 | { |
11331 | struct drm_device *dev = crtc->dev; | |
11332 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11333 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11334 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11335 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11336 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11337 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11338 | struct intel_unpin_work *work; |
a4872ba6 | 11339 | struct intel_engine_cs *ring; |
cf5d8a46 | 11340 | bool mmio_flip; |
91af127f | 11341 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11342 | int ret; |
6b95a207 | 11343 | |
2ff8fde1 MR |
11344 | /* |
11345 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11346 | * check to be safe. In the future we may enable pageflipping from | |
11347 | * a disabled primary plane. | |
11348 | */ | |
11349 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11350 | return -EBUSY; | |
11351 | ||
e6a595d2 | 11352 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11353 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11354 | return -EINVAL; |
11355 | ||
11356 | /* | |
11357 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11358 | * Note that pitch changes could also affect these register. | |
11359 | */ | |
11360 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11361 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11362 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11363 | return -EINVAL; |
11364 | ||
f900db47 CW |
11365 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11366 | goto out_hang; | |
11367 | ||
b14c5679 | 11368 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11369 | if (work == NULL) |
11370 | return -ENOMEM; | |
11371 | ||
6b95a207 | 11372 | work->event = event; |
b4a98e57 | 11373 | work->crtc = crtc; |
ab8d6675 | 11374 | work->old_fb = old_fb; |
6b95a207 KH |
11375 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11376 | ||
87b6b101 | 11377 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11378 | if (ret) |
11379 | goto free_work; | |
11380 | ||
6b95a207 | 11381 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11382 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11383 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11384 | /* Before declaring the flip queue wedged, check if |
11385 | * the hardware completed the operation behind our backs. | |
11386 | */ | |
11387 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11388 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11389 | page_flip_completed(intel_crtc); | |
11390 | } else { | |
11391 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11392 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11393 | |
d6bbafa1 CW |
11394 | drm_crtc_vblank_put(crtc); |
11395 | kfree(work); | |
11396 | return -EBUSY; | |
11397 | } | |
6b95a207 KH |
11398 | } |
11399 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11400 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11401 | |
b4a98e57 CW |
11402 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11403 | flush_workqueue(dev_priv->wq); | |
11404 | ||
75dfca80 | 11405 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11406 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11407 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11408 | |
f4510a27 | 11409 | crtc->primary->fb = fb; |
afd65eb4 | 11410 | update_state_fb(crtc->primary); |
1ed1f968 | 11411 | |
e1f99ce6 | 11412 | work->pending_flip_obj = obj; |
e1f99ce6 | 11413 | |
89ed88ba CW |
11414 | ret = i915_mutex_lock_interruptible(dev); |
11415 | if (ret) | |
11416 | goto cleanup; | |
11417 | ||
b4a98e57 | 11418 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11419 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11420 | |
75f7f3ec | 11421 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
fd8f507c | 11422 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
75f7f3ec | 11423 | |
4fa62c89 VS |
11424 | if (IS_VALLEYVIEW(dev)) { |
11425 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11426 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11427 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11428 | ring = NULL; | |
48bf5b2d | 11429 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11430 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11431 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11432 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11433 | if (ring == NULL || ring->id != RCS) |
11434 | ring = &dev_priv->ring[BCS]; | |
11435 | } else { | |
11436 | ring = &dev_priv->ring[RCS]; | |
11437 | } | |
11438 | ||
cf5d8a46 CW |
11439 | mmio_flip = use_mmio_flip(ring, obj); |
11440 | ||
11441 | /* When using CS flips, we want to emit semaphores between rings. | |
11442 | * However, when using mmio flips we will create a task to do the | |
11443 | * synchronisation, so all we want here is to pin the framebuffer | |
11444 | * into the display plane and skip any waits. | |
11445 | */ | |
7580d774 ML |
11446 | if (!mmio_flip) { |
11447 | ret = i915_gem_object_sync(obj, ring, &request); | |
11448 | if (ret) | |
11449 | goto cleanup_pending; | |
11450 | } | |
11451 | ||
82bc3b2d | 11452 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
7580d774 | 11453 | crtc->primary->state); |
8c9f3aaf JB |
11454 | if (ret) |
11455 | goto cleanup_pending; | |
6b95a207 | 11456 | |
dedf278c TU |
11457 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
11458 | obj, 0); | |
11459 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
4fa62c89 | 11460 | |
cf5d8a46 | 11461 | if (mmio_flip) { |
86efe24a | 11462 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
d6bbafa1 CW |
11463 | if (ret) |
11464 | goto cleanup_unpin; | |
11465 | ||
f06cc1b9 JH |
11466 | i915_gem_request_assign(&work->flip_queued_req, |
11467 | obj->last_write_req); | |
d6bbafa1 | 11468 | } else { |
6258fbe2 JH |
11469 | if (!request) { |
11470 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); | |
11471 | if (ret) | |
11472 | goto cleanup_unpin; | |
11473 | } | |
11474 | ||
11475 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11476 | page_flip_flags); |
11477 | if (ret) | |
11478 | goto cleanup_unpin; | |
11479 | ||
6258fbe2 | 11480 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11481 | } |
11482 | ||
91af127f | 11483 | if (request) |
75289874 | 11484 | i915_add_request_no_flush(request); |
91af127f | 11485 | |
1e3feefd | 11486 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11487 | work->enable_stall_check = true; |
4fa62c89 | 11488 | |
ab8d6675 | 11489 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11490 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11491 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11492 | |
4e1e26f1 | 11493 | intel_fbc_disable_crtc(intel_crtc); |
a9ff8714 VS |
11494 | intel_frontbuffer_flip_prepare(dev, |
11495 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11496 | |
e5510fac JB |
11497 | trace_i915_flip_request(intel_crtc->plane, obj); |
11498 | ||
6b95a207 | 11499 | return 0; |
96b099fd | 11500 | |
4fa62c89 | 11501 | cleanup_unpin: |
82bc3b2d | 11502 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11503 | cleanup_pending: |
91af127f JH |
11504 | if (request) |
11505 | i915_gem_request_cancel(request); | |
b4a98e57 | 11506 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11507 | mutex_unlock(&dev->struct_mutex); |
11508 | cleanup: | |
f4510a27 | 11509 | crtc->primary->fb = old_fb; |
afd65eb4 | 11510 | update_state_fb(crtc->primary); |
89ed88ba CW |
11511 | |
11512 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11513 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11514 | |
5e2d7afc | 11515 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11516 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11517 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11518 | |
87b6b101 | 11519 | drm_crtc_vblank_put(crtc); |
7317c75e | 11520 | free_work: |
96b099fd CW |
11521 | kfree(work); |
11522 | ||
f900db47 | 11523 | if (ret == -EIO) { |
02e0efb5 ML |
11524 | struct drm_atomic_state *state; |
11525 | struct drm_plane_state *plane_state; | |
11526 | ||
f900db47 | 11527 | out_hang: |
02e0efb5 ML |
11528 | state = drm_atomic_state_alloc(dev); |
11529 | if (!state) | |
11530 | return -ENOMEM; | |
11531 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11532 | ||
11533 | retry: | |
11534 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11535 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11536 | if (!ret) { | |
11537 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11538 | ||
11539 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11540 | if (!ret) | |
11541 | ret = drm_atomic_commit(state); | |
11542 | } | |
11543 | ||
11544 | if (ret == -EDEADLK) { | |
11545 | drm_modeset_backoff(state->acquire_ctx); | |
11546 | drm_atomic_state_clear(state); | |
11547 | goto retry; | |
11548 | } | |
11549 | ||
11550 | if (ret) | |
11551 | drm_atomic_state_free(state); | |
11552 | ||
f0d3dad3 | 11553 | if (ret == 0 && event) { |
5e2d7afc | 11554 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11555 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11556 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11557 | } |
f900db47 | 11558 | } |
96b099fd | 11559 | return ret; |
6b95a207 KH |
11560 | } |
11561 | ||
da20eabd ML |
11562 | |
11563 | /** | |
11564 | * intel_wm_need_update - Check whether watermarks need updating | |
11565 | * @plane: drm plane | |
11566 | * @state: new plane state | |
11567 | * | |
11568 | * Check current plane state versus the new one to determine whether | |
11569 | * watermarks need to be recalculated. | |
11570 | * | |
11571 | * Returns true or false. | |
11572 | */ | |
11573 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11574 | struct drm_plane_state *state) | |
11575 | { | |
d21fbe87 MR |
11576 | struct intel_plane_state *new = to_intel_plane_state(state); |
11577 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11578 | ||
11579 | /* Update watermarks on tiling or size changes. */ | |
da20eabd ML |
11580 | if (!plane->state->fb || !state->fb || |
11581 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
d21fbe87 MR |
11582 | plane->state->rotation != state->rotation || |
11583 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11584 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11585 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11586 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
2791a16c | 11587 | return true; |
7809e5ae | 11588 | |
2791a16c | 11589 | return false; |
7809e5ae MR |
11590 | } |
11591 | ||
d21fbe87 MR |
11592 | static bool needs_scaling(struct intel_plane_state *state) |
11593 | { | |
11594 | int src_w = drm_rect_width(&state->src) >> 16; | |
11595 | int src_h = drm_rect_height(&state->src) >> 16; | |
11596 | int dst_w = drm_rect_width(&state->dst); | |
11597 | int dst_h = drm_rect_height(&state->dst); | |
11598 | ||
11599 | return (src_w != dst_w || src_h != dst_h); | |
11600 | } | |
11601 | ||
da20eabd ML |
11602 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11603 | struct drm_plane_state *plane_state) | |
11604 | { | |
11605 | struct drm_crtc *crtc = crtc_state->crtc; | |
11606 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11607 | struct drm_plane *plane = plane_state->plane; | |
11608 | struct drm_device *dev = crtc->dev; | |
11609 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11610 | struct intel_plane_state *old_plane_state = | |
11611 | to_intel_plane_state(plane->state); | |
11612 | int idx = intel_crtc->base.base.id, ret; | |
11613 | int i = drm_plane_index(plane); | |
11614 | bool mode_changed = needs_modeset(crtc_state); | |
11615 | bool was_crtc_enabled = crtc->state->active; | |
11616 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11617 | bool turn_off, turn_on, visible, was_visible; |
11618 | struct drm_framebuffer *fb = plane_state->fb; | |
11619 | ||
11620 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11621 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11622 | ret = skl_update_scaler_plane( | |
11623 | to_intel_crtc_state(crtc_state), | |
11624 | to_intel_plane_state(plane_state)); | |
11625 | if (ret) | |
11626 | return ret; | |
11627 | } | |
11628 | ||
da20eabd ML |
11629 | was_visible = old_plane_state->visible; |
11630 | visible = to_intel_plane_state(plane_state)->visible; | |
11631 | ||
11632 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11633 | was_visible = false; | |
11634 | ||
11635 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11636 | visible = false; | |
11637 | ||
11638 | if (!was_visible && !visible) | |
11639 | return 0; | |
11640 | ||
11641 | turn_off = was_visible && (!visible || mode_changed); | |
11642 | turn_on = visible && (!was_visible || mode_changed); | |
11643 | ||
11644 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11645 | plane->base.id, fb ? fb->base.id : -1); | |
11646 | ||
11647 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11648 | plane->base.id, was_visible, visible, | |
11649 | turn_off, turn_on, mode_changed); | |
11650 | ||
852eb00d | 11651 | if (turn_on) { |
f015c551 | 11652 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d VS |
11653 | /* must disable cxsr around plane enable/disable */ |
11654 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11655 | intel_crtc->atomic.disable_cxsr = true; | |
11656 | /* to potentially re-enable cxsr */ | |
11657 | intel_crtc->atomic.wait_vblank = true; | |
11658 | intel_crtc->atomic.update_wm_post = true; | |
11659 | } | |
11660 | } else if (turn_off) { | |
f015c551 | 11661 | intel_crtc->atomic.update_wm_post = true; |
852eb00d VS |
11662 | /* must disable cxsr around plane enable/disable */ |
11663 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11664 | if (is_crtc_enabled) | |
11665 | intel_crtc->atomic.wait_vblank = true; | |
11666 | intel_crtc->atomic.disable_cxsr = true; | |
11667 | } | |
11668 | } else if (intel_wm_need_update(plane, plane_state)) { | |
f015c551 | 11669 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d | 11670 | } |
da20eabd | 11671 | |
8be6ca85 | 11672 | if (visible || was_visible) |
a9ff8714 VS |
11673 | intel_crtc->atomic.fb_bits |= |
11674 | to_intel_plane(plane)->frontbuffer_bit; | |
11675 | ||
da20eabd ML |
11676 | switch (plane->type) { |
11677 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd ML |
11678 | intel_crtc->atomic.pre_disable_primary = turn_off; |
11679 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11680 | ||
066cf55b RV |
11681 | if (turn_off) { |
11682 | /* | |
11683 | * FIXME: Actually if we will still have any other | |
11684 | * plane enabled on the pipe we could let IPS enabled | |
11685 | * still, but for now lets consider that when we make | |
11686 | * primary invisible by setting DSPCNTR to 0 on | |
11687 | * update_primary_plane function IPS needs to be | |
11688 | * disable. | |
11689 | */ | |
11690 | intel_crtc->atomic.disable_ips = true; | |
11691 | ||
da20eabd | 11692 | intel_crtc->atomic.disable_fbc = true; |
066cf55b | 11693 | } |
da20eabd ML |
11694 | |
11695 | /* | |
11696 | * FBC does not work on some platforms for rotated | |
11697 | * planes, so disable it when rotation is not 0 and | |
11698 | * update it when rotation is set back to 0. | |
11699 | * | |
11700 | * FIXME: This is redundant with the fbc update done in | |
11701 | * the primary plane enable function except that that | |
11702 | * one is done too late. We eventually need to unify | |
11703 | * this. | |
11704 | */ | |
11705 | ||
11706 | if (visible && | |
11707 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11708 | dev_priv->fbc.crtc == intel_crtc && | |
11709 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11710 | intel_crtc->atomic.disable_fbc = true; | |
11711 | ||
11712 | /* | |
11713 | * BDW signals flip done immediately if the plane | |
11714 | * is disabled, even if the plane enable is already | |
11715 | * armed to occur at the next vblank :( | |
11716 | */ | |
11717 | if (turn_on && IS_BROADWELL(dev)) | |
11718 | intel_crtc->atomic.wait_vblank = true; | |
11719 | ||
11720 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11721 | break; | |
11722 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11723 | break; |
11724 | case DRM_PLANE_TYPE_OVERLAY: | |
d21fbe87 MR |
11725 | /* |
11726 | * WaCxSRDisabledForSpriteScaling:ivb | |
11727 | * | |
11728 | * cstate->update_wm was already set above, so this flag will | |
11729 | * take effect when we commit and program watermarks. | |
11730 | */ | |
11731 | if (IS_IVYBRIDGE(dev) && | |
11732 | needs_scaling(to_intel_plane_state(plane_state)) && | |
11733 | !needs_scaling(old_plane_state)) { | |
11734 | to_intel_crtc_state(crtc_state)->disable_lp_wm = true; | |
11735 | } else if (turn_off && !mode_changed) { | |
da20eabd ML |
11736 | intel_crtc->atomic.wait_vblank = true; |
11737 | intel_crtc->atomic.update_sprite_watermarks |= | |
11738 | 1 << i; | |
11739 | } | |
d21fbe87 MR |
11740 | |
11741 | break; | |
da20eabd ML |
11742 | } |
11743 | return 0; | |
11744 | } | |
11745 | ||
6d3a1ce7 ML |
11746 | static bool encoders_cloneable(const struct intel_encoder *a, |
11747 | const struct intel_encoder *b) | |
11748 | { | |
11749 | /* masks could be asymmetric, so check both ways */ | |
11750 | return a == b || (a->cloneable & (1 << b->type) && | |
11751 | b->cloneable & (1 << a->type)); | |
11752 | } | |
11753 | ||
11754 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11755 | struct intel_crtc *crtc, | |
11756 | struct intel_encoder *encoder) | |
11757 | { | |
11758 | struct intel_encoder *source_encoder; | |
11759 | struct drm_connector *connector; | |
11760 | struct drm_connector_state *connector_state; | |
11761 | int i; | |
11762 | ||
11763 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11764 | if (connector_state->crtc != &crtc->base) | |
11765 | continue; | |
11766 | ||
11767 | source_encoder = | |
11768 | to_intel_encoder(connector_state->best_encoder); | |
11769 | if (!encoders_cloneable(encoder, source_encoder)) | |
11770 | return false; | |
11771 | } | |
11772 | ||
11773 | return true; | |
11774 | } | |
11775 | ||
11776 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11777 | struct intel_crtc *crtc) | |
11778 | { | |
11779 | struct intel_encoder *encoder; | |
11780 | struct drm_connector *connector; | |
11781 | struct drm_connector_state *connector_state; | |
11782 | int i; | |
11783 | ||
11784 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11785 | if (connector_state->crtc != &crtc->base) | |
11786 | continue; | |
11787 | ||
11788 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11789 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11790 | return false; | |
11791 | } | |
11792 | ||
11793 | return true; | |
11794 | } | |
11795 | ||
11796 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11797 | struct drm_crtc_state *crtc_state) | |
11798 | { | |
cf5a15be | 11799 | struct drm_device *dev = crtc->dev; |
ad421372 | 11800 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11801 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11802 | struct intel_crtc_state *pipe_config = |
11803 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11804 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 11805 | int ret; |
6d3a1ce7 ML |
11806 | bool mode_changed = needs_modeset(crtc_state); |
11807 | ||
11808 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11809 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11810 | return -EINVAL; | |
11811 | } | |
11812 | ||
852eb00d VS |
11813 | if (mode_changed && !crtc_state->active) |
11814 | intel_crtc->atomic.update_wm_post = true; | |
eddfcbcd | 11815 | |
ad421372 ML |
11816 | if (mode_changed && crtc_state->enable && |
11817 | dev_priv->display.crtc_compute_clock && | |
11818 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11819 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11820 | pipe_config); | |
11821 | if (ret) | |
11822 | return ret; | |
11823 | } | |
11824 | ||
e435d6e5 | 11825 | ret = 0; |
86c8bbbe MR |
11826 | if (dev_priv->display.compute_pipe_wm) { |
11827 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
11828 | if (ret) | |
11829 | return ret; | |
11830 | } | |
11831 | ||
e435d6e5 ML |
11832 | if (INTEL_INFO(dev)->gen >= 9) { |
11833 | if (mode_changed) | |
11834 | ret = skl_update_scaler_crtc(pipe_config); | |
11835 | ||
11836 | if (!ret) | |
11837 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
11838 | pipe_config); | |
11839 | } | |
11840 | ||
11841 | return ret; | |
6d3a1ce7 ML |
11842 | } |
11843 | ||
65b38e0d | 11844 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11845 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11846 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11847 | .atomic_begin = intel_begin_crtc_commit, |
11848 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11849 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11850 | }; |
11851 | ||
d29b2f9d ACO |
11852 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
11853 | { | |
11854 | struct intel_connector *connector; | |
11855 | ||
11856 | for_each_intel_connector(dev, connector) { | |
11857 | if (connector->base.encoder) { | |
11858 | connector->base.state->best_encoder = | |
11859 | connector->base.encoder; | |
11860 | connector->base.state->crtc = | |
11861 | connector->base.encoder->crtc; | |
11862 | } else { | |
11863 | connector->base.state->best_encoder = NULL; | |
11864 | connector->base.state->crtc = NULL; | |
11865 | } | |
11866 | } | |
11867 | } | |
11868 | ||
050f7aeb | 11869 | static void |
eba905b2 | 11870 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11871 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11872 | { |
11873 | int bpp = pipe_config->pipe_bpp; | |
11874 | ||
11875 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11876 | connector->base.base.id, | |
c23cc417 | 11877 | connector->base.name); |
050f7aeb DV |
11878 | |
11879 | /* Don't use an invalid EDID bpc value */ | |
11880 | if (connector->base.display_info.bpc && | |
11881 | connector->base.display_info.bpc * 3 < bpp) { | |
11882 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11883 | bpp, connector->base.display_info.bpc*3); | |
11884 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11885 | } | |
11886 | ||
11887 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11888 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11889 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11890 | bpp); | |
11891 | pipe_config->pipe_bpp = 24; | |
11892 | } | |
11893 | } | |
11894 | ||
4e53c2e0 | 11895 | static int |
050f7aeb | 11896 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 11897 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 11898 | { |
050f7aeb | 11899 | struct drm_device *dev = crtc->base.dev; |
1486017f | 11900 | struct drm_atomic_state *state; |
da3ced29 ACO |
11901 | struct drm_connector *connector; |
11902 | struct drm_connector_state *connector_state; | |
1486017f | 11903 | int bpp, i; |
4e53c2e0 | 11904 | |
d328c9d7 | 11905 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 11906 | bpp = 10*3; |
d328c9d7 DV |
11907 | else if (INTEL_INFO(dev)->gen >= 5) |
11908 | bpp = 12*3; | |
11909 | else | |
11910 | bpp = 8*3; | |
11911 | ||
4e53c2e0 | 11912 | |
4e53c2e0 DV |
11913 | pipe_config->pipe_bpp = bpp; |
11914 | ||
1486017f ACO |
11915 | state = pipe_config->base.state; |
11916 | ||
4e53c2e0 | 11917 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
11918 | for_each_connector_in_state(state, connector, connector_state, i) { |
11919 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
11920 | continue; |
11921 | ||
da3ced29 ACO |
11922 | connected_sink_compute_bpp(to_intel_connector(connector), |
11923 | pipe_config); | |
4e53c2e0 DV |
11924 | } |
11925 | ||
11926 | return bpp; | |
11927 | } | |
11928 | ||
644db711 DV |
11929 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
11930 | { | |
11931 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
11932 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 11933 | mode->crtc_clock, |
644db711 DV |
11934 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
11935 | mode->crtc_hsync_end, mode->crtc_htotal, | |
11936 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
11937 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
11938 | } | |
11939 | ||
c0b03411 | 11940 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 11941 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
11942 | const char *context) |
11943 | { | |
6a60cd87 CK |
11944 | struct drm_device *dev = crtc->base.dev; |
11945 | struct drm_plane *plane; | |
11946 | struct intel_plane *intel_plane; | |
11947 | struct intel_plane_state *state; | |
11948 | struct drm_framebuffer *fb; | |
11949 | ||
11950 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
11951 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
11952 | |
11953 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
11954 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
11955 | pipe_config->pipe_bpp, pipe_config->dither); | |
11956 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
11957 | pipe_config->has_pch_encoder, | |
11958 | pipe_config->fdi_lanes, | |
11959 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
11960 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
11961 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 11962 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 11963 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11964 | pipe_config->lane_count, |
eb14cb74 VS |
11965 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
11966 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
11967 | pipe_config->dp_m_n.tu); | |
b95af8be | 11968 | |
90a6b7b0 | 11969 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 11970 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11971 | pipe_config->lane_count, |
b95af8be VK |
11972 | pipe_config->dp_m2_n2.gmch_m, |
11973 | pipe_config->dp_m2_n2.gmch_n, | |
11974 | pipe_config->dp_m2_n2.link_m, | |
11975 | pipe_config->dp_m2_n2.link_n, | |
11976 | pipe_config->dp_m2_n2.tu); | |
11977 | ||
55072d19 DV |
11978 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
11979 | pipe_config->has_audio, | |
11980 | pipe_config->has_infoframe); | |
11981 | ||
c0b03411 | 11982 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 11983 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 11984 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
11985 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
11986 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 11987 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
11988 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
11989 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
11990 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
11991 | crtc->num_scalers, | |
11992 | pipe_config->scaler_state.scaler_users, | |
11993 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
11994 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
11995 | pipe_config->gmch_pfit.control, | |
11996 | pipe_config->gmch_pfit.pgm_ratios, | |
11997 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 11998 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 11999 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12000 | pipe_config->pch_pfit.size, |
12001 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12002 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12003 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12004 | |
415ff0f6 | 12005 | if (IS_BROXTON(dev)) { |
05712c15 | 12006 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12007 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12008 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12009 | pipe_config->ddi_pll_sel, |
12010 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12011 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12012 | pipe_config->dpll_hw_state.pll0, |
12013 | pipe_config->dpll_hw_state.pll1, | |
12014 | pipe_config->dpll_hw_state.pll2, | |
12015 | pipe_config->dpll_hw_state.pll3, | |
12016 | pipe_config->dpll_hw_state.pll6, | |
12017 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12018 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12019 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12020 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12021 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12022 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12023 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12024 | pipe_config->ddi_pll_sel, | |
12025 | pipe_config->dpll_hw_state.ctrl1, | |
12026 | pipe_config->dpll_hw_state.cfgcr1, | |
12027 | pipe_config->dpll_hw_state.cfgcr2); | |
12028 | } else if (HAS_DDI(dev)) { | |
12029 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
12030 | pipe_config->ddi_pll_sel, | |
12031 | pipe_config->dpll_hw_state.wrpll); | |
12032 | } else { | |
12033 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12034 | "fp0: 0x%x, fp1: 0x%x\n", | |
12035 | pipe_config->dpll_hw_state.dpll, | |
12036 | pipe_config->dpll_hw_state.dpll_md, | |
12037 | pipe_config->dpll_hw_state.fp0, | |
12038 | pipe_config->dpll_hw_state.fp1); | |
12039 | } | |
12040 | ||
6a60cd87 CK |
12041 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12042 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12043 | intel_plane = to_intel_plane(plane); | |
12044 | if (intel_plane->pipe != crtc->pipe) | |
12045 | continue; | |
12046 | ||
12047 | state = to_intel_plane_state(plane->state); | |
12048 | fb = state->base.fb; | |
12049 | if (!fb) { | |
12050 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12051 | "disabled, scaler_id = %d\n", | |
12052 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12053 | plane->base.id, intel_plane->pipe, | |
12054 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12055 | drm_plane_index(plane), state->scaler_id); | |
12056 | continue; | |
12057 | } | |
12058 | ||
12059 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12060 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12061 | plane->base.id, intel_plane->pipe, | |
12062 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12063 | drm_plane_index(plane)); | |
12064 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12065 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12066 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12067 | state->scaler_id, | |
12068 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12069 | drm_rect_width(&state->src) >> 16, | |
12070 | drm_rect_height(&state->src) >> 16, | |
12071 | state->dst.x1, state->dst.y1, | |
12072 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12073 | } | |
c0b03411 DV |
12074 | } |
12075 | ||
5448a00d | 12076 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12077 | { |
5448a00d ACO |
12078 | struct drm_device *dev = state->dev; |
12079 | struct intel_encoder *encoder; | |
da3ced29 | 12080 | struct drm_connector *connector; |
5448a00d | 12081 | struct drm_connector_state *connector_state; |
00f0b378 | 12082 | unsigned int used_ports = 0; |
5448a00d | 12083 | int i; |
00f0b378 VS |
12084 | |
12085 | /* | |
12086 | * Walk the connector list instead of the encoder | |
12087 | * list to detect the problem on ddi platforms | |
12088 | * where there's just one encoder per digital port. | |
12089 | */ | |
da3ced29 | 12090 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12091 | if (!connector_state->best_encoder) |
00f0b378 VS |
12092 | continue; |
12093 | ||
5448a00d ACO |
12094 | encoder = to_intel_encoder(connector_state->best_encoder); |
12095 | ||
12096 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12097 | |
12098 | switch (encoder->type) { | |
12099 | unsigned int port_mask; | |
12100 | case INTEL_OUTPUT_UNKNOWN: | |
12101 | if (WARN_ON(!HAS_DDI(dev))) | |
12102 | break; | |
12103 | case INTEL_OUTPUT_DISPLAYPORT: | |
12104 | case INTEL_OUTPUT_HDMI: | |
12105 | case INTEL_OUTPUT_EDP: | |
12106 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12107 | ||
12108 | /* the same port mustn't appear more than once */ | |
12109 | if (used_ports & port_mask) | |
12110 | return false; | |
12111 | ||
12112 | used_ports |= port_mask; | |
12113 | default: | |
12114 | break; | |
12115 | } | |
12116 | } | |
12117 | ||
12118 | return true; | |
12119 | } | |
12120 | ||
83a57153 ACO |
12121 | static void |
12122 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12123 | { | |
12124 | struct drm_crtc_state tmp_state; | |
663a3640 | 12125 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12126 | struct intel_dpll_hw_state dpll_hw_state; |
12127 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12128 | uint32_t ddi_pll_sel; |
c4e2d043 | 12129 | bool force_thru; |
83a57153 | 12130 | |
7546a384 ACO |
12131 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12132 | * kzalloc'd. Code that depends on any field being zero should be | |
12133 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12134 | * only fields that are know to not cause problems are preserved. */ | |
12135 | ||
83a57153 | 12136 | tmp_state = crtc_state->base; |
663a3640 | 12137 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12138 | shared_dpll = crtc_state->shared_dpll; |
12139 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12140 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12141 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12142 | |
83a57153 | 12143 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12144 | |
83a57153 | 12145 | crtc_state->base = tmp_state; |
663a3640 | 12146 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12147 | crtc_state->shared_dpll = shared_dpll; |
12148 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12149 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12150 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12151 | } |
12152 | ||
548ee15b | 12153 | static int |
b8cecdf5 | 12154 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12155 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12156 | { |
b359283a | 12157 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12158 | struct intel_encoder *encoder; |
da3ced29 | 12159 | struct drm_connector *connector; |
0b901879 | 12160 | struct drm_connector_state *connector_state; |
d328c9d7 | 12161 | int base_bpp, ret = -EINVAL; |
0b901879 | 12162 | int i; |
e29c22c0 | 12163 | bool retry = true; |
ee7b9f93 | 12164 | |
83a57153 | 12165 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12166 | |
e143a21c DV |
12167 | pipe_config->cpu_transcoder = |
12168 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12169 | |
2960bc9c ID |
12170 | /* |
12171 | * Sanitize sync polarity flags based on requested ones. If neither | |
12172 | * positive or negative polarity is requested, treat this as meaning | |
12173 | * negative polarity. | |
12174 | */ | |
2d112de7 | 12175 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12176 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12177 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12178 | |
2d112de7 | 12179 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12180 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12181 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12182 | |
d328c9d7 DV |
12183 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12184 | pipe_config); | |
12185 | if (base_bpp < 0) | |
4e53c2e0 DV |
12186 | goto fail; |
12187 | ||
e41a56be VS |
12188 | /* |
12189 | * Determine the real pipe dimensions. Note that stereo modes can | |
12190 | * increase the actual pipe size due to the frame doubling and | |
12191 | * insertion of additional space for blanks between the frame. This | |
12192 | * is stored in the crtc timings. We use the requested mode to do this | |
12193 | * computation to clearly distinguish it from the adjusted mode, which | |
12194 | * can be changed by the connectors in the below retry loop. | |
12195 | */ | |
2d112de7 | 12196 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12197 | &pipe_config->pipe_src_w, |
12198 | &pipe_config->pipe_src_h); | |
e41a56be | 12199 | |
e29c22c0 | 12200 | encoder_retry: |
ef1b460d | 12201 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12202 | pipe_config->port_clock = 0; |
ef1b460d | 12203 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12204 | |
135c81b8 | 12205 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12206 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12207 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12208 | |
7758a113 DV |
12209 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12210 | * adjust it according to limitations or connector properties, and also | |
12211 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12212 | */ |
da3ced29 | 12213 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12214 | if (connector_state->crtc != crtc) |
7758a113 | 12215 | continue; |
7ae89233 | 12216 | |
0b901879 ACO |
12217 | encoder = to_intel_encoder(connector_state->best_encoder); |
12218 | ||
efea6e8e DV |
12219 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12220 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12221 | goto fail; |
12222 | } | |
ee7b9f93 | 12223 | } |
47f1c6c9 | 12224 | |
ff9a6750 DV |
12225 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12226 | * done afterwards in case the encoder adjusts the mode. */ | |
12227 | if (!pipe_config->port_clock) | |
2d112de7 | 12228 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12229 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12230 | |
a43f6e0f | 12231 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12232 | if (ret < 0) { |
7758a113 DV |
12233 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12234 | goto fail; | |
ee7b9f93 | 12235 | } |
e29c22c0 DV |
12236 | |
12237 | if (ret == RETRY) { | |
12238 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12239 | ret = -EINVAL; | |
12240 | goto fail; | |
12241 | } | |
12242 | ||
12243 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12244 | retry = false; | |
12245 | goto encoder_retry; | |
12246 | } | |
12247 | ||
e8fa4270 DV |
12248 | /* Dithering seems to not pass-through bits correctly when it should, so |
12249 | * only enable it on 6bpc panels. */ | |
12250 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12251 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12252 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12253 | |
7758a113 | 12254 | fail: |
548ee15b | 12255 | return ret; |
ee7b9f93 | 12256 | } |
47f1c6c9 | 12257 | |
ea9d758d | 12258 | static void |
4740b0f2 | 12259 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12260 | { |
0a9ab303 ACO |
12261 | struct drm_crtc *crtc; |
12262 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12263 | int i; |
ea9d758d | 12264 | |
7668851f | 12265 | /* Double check state. */ |
8a75d157 | 12266 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12267 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12268 | |
12269 | /* Update hwmode for vblank functions */ | |
12270 | if (crtc->state->active) | |
12271 | crtc->hwmode = crtc->state->adjusted_mode; | |
12272 | else | |
12273 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12274 | |
12275 | /* | |
12276 | * Update legacy state to satisfy fbc code. This can | |
12277 | * be removed when fbc uses the atomic state. | |
12278 | */ | |
12279 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12280 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12281 | ||
12282 | crtc->primary->fb = plane_state->fb; | |
12283 | crtc->x = plane_state->src_x >> 16; | |
12284 | crtc->y = plane_state->src_y >> 16; | |
12285 | } | |
ea9d758d | 12286 | } |
ea9d758d DV |
12287 | } |
12288 | ||
3bd26263 | 12289 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12290 | { |
3bd26263 | 12291 | int diff; |
f1f644dc JB |
12292 | |
12293 | if (clock1 == clock2) | |
12294 | return true; | |
12295 | ||
12296 | if (!clock1 || !clock2) | |
12297 | return false; | |
12298 | ||
12299 | diff = abs(clock1 - clock2); | |
12300 | ||
12301 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12302 | return true; | |
12303 | ||
12304 | return false; | |
12305 | } | |
12306 | ||
25c5b266 DV |
12307 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12308 | list_for_each_entry((intel_crtc), \ | |
12309 | &(dev)->mode_config.crtc_list, \ | |
12310 | base.head) \ | |
0973f18f | 12311 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12312 | |
cfb23ed6 ML |
12313 | static bool |
12314 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12315 | unsigned int m2, unsigned int n2, | |
12316 | bool exact) | |
12317 | { | |
12318 | if (m == m2 && n == n2) | |
12319 | return true; | |
12320 | ||
12321 | if (exact || !m || !n || !m2 || !n2) | |
12322 | return false; | |
12323 | ||
12324 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12325 | ||
12326 | if (m > m2) { | |
12327 | while (m > m2) { | |
12328 | m2 <<= 1; | |
12329 | n2 <<= 1; | |
12330 | } | |
12331 | } else if (m < m2) { | |
12332 | while (m < m2) { | |
12333 | m <<= 1; | |
12334 | n <<= 1; | |
12335 | } | |
12336 | } | |
12337 | ||
12338 | return m == m2 && n == n2; | |
12339 | } | |
12340 | ||
12341 | static bool | |
12342 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12343 | struct intel_link_m_n *m2_n2, | |
12344 | bool adjust) | |
12345 | { | |
12346 | if (m_n->tu == m2_n2->tu && | |
12347 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12348 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12349 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12350 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12351 | if (adjust) | |
12352 | *m2_n2 = *m_n; | |
12353 | ||
12354 | return true; | |
12355 | } | |
12356 | ||
12357 | return false; | |
12358 | } | |
12359 | ||
0e8ffe1b | 12360 | static bool |
2fa2fe9a | 12361 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12362 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12363 | struct intel_crtc_state *pipe_config, |
12364 | bool adjust) | |
0e8ffe1b | 12365 | { |
cfb23ed6 ML |
12366 | bool ret = true; |
12367 | ||
12368 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12369 | do { \ | |
12370 | if (!adjust) \ | |
12371 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12372 | else \ | |
12373 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12374 | } while (0) | |
12375 | ||
66e985c0 DV |
12376 | #define PIPE_CONF_CHECK_X(name) \ |
12377 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12378 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12379 | "(expected 0x%08x, found 0x%08x)\n", \ |
12380 | current_config->name, \ | |
12381 | pipe_config->name); \ | |
cfb23ed6 | 12382 | ret = false; \ |
66e985c0 DV |
12383 | } |
12384 | ||
08a24034 DV |
12385 | #define PIPE_CONF_CHECK_I(name) \ |
12386 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12387 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12388 | "(expected %i, found %i)\n", \ |
12389 | current_config->name, \ | |
12390 | pipe_config->name); \ | |
cfb23ed6 ML |
12391 | ret = false; \ |
12392 | } | |
12393 | ||
12394 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12395 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12396 | &pipe_config->name,\ | |
12397 | adjust)) { \ | |
12398 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12399 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12400 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12401 | current_config->name.tu, \ | |
12402 | current_config->name.gmch_m, \ | |
12403 | current_config->name.gmch_n, \ | |
12404 | current_config->name.link_m, \ | |
12405 | current_config->name.link_n, \ | |
12406 | pipe_config->name.tu, \ | |
12407 | pipe_config->name.gmch_m, \ | |
12408 | pipe_config->name.gmch_n, \ | |
12409 | pipe_config->name.link_m, \ | |
12410 | pipe_config->name.link_n); \ | |
12411 | ret = false; \ | |
12412 | } | |
12413 | ||
12414 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12415 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12416 | &pipe_config->name, adjust) && \ | |
12417 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12418 | &pipe_config->name, adjust)) { \ | |
12419 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12420 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12421 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12422 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12423 | current_config->name.tu, \ | |
12424 | current_config->name.gmch_m, \ | |
12425 | current_config->name.gmch_n, \ | |
12426 | current_config->name.link_m, \ | |
12427 | current_config->name.link_n, \ | |
12428 | current_config->alt_name.tu, \ | |
12429 | current_config->alt_name.gmch_m, \ | |
12430 | current_config->alt_name.gmch_n, \ | |
12431 | current_config->alt_name.link_m, \ | |
12432 | current_config->alt_name.link_n, \ | |
12433 | pipe_config->name.tu, \ | |
12434 | pipe_config->name.gmch_m, \ | |
12435 | pipe_config->name.gmch_n, \ | |
12436 | pipe_config->name.link_m, \ | |
12437 | pipe_config->name.link_n); \ | |
12438 | ret = false; \ | |
88adfff1 DV |
12439 | } |
12440 | ||
b95af8be VK |
12441 | /* This is required for BDW+ where there is only one set of registers for |
12442 | * switching between high and low RR. | |
12443 | * This macro can be used whenever a comparison has to be made between one | |
12444 | * hw state and multiple sw state variables. | |
12445 | */ | |
12446 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12447 | if ((current_config->name != pipe_config->name) && \ | |
12448 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12449 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12450 | "(expected %i or %i, found %i)\n", \ |
12451 | current_config->name, \ | |
12452 | current_config->alt_name, \ | |
12453 | pipe_config->name); \ | |
cfb23ed6 | 12454 | ret = false; \ |
b95af8be VK |
12455 | } |
12456 | ||
1bd1bd80 DV |
12457 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12458 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12459 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12460 | "(expected %i, found %i)\n", \ |
12461 | current_config->name & (mask), \ | |
12462 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12463 | ret = false; \ |
1bd1bd80 DV |
12464 | } |
12465 | ||
5e550656 VS |
12466 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12467 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12468 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12469 | "(expected %i, found %i)\n", \ |
12470 | current_config->name, \ | |
12471 | pipe_config->name); \ | |
cfb23ed6 | 12472 | ret = false; \ |
5e550656 VS |
12473 | } |
12474 | ||
bb760063 DV |
12475 | #define PIPE_CONF_QUIRK(quirk) \ |
12476 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12477 | ||
eccb140b DV |
12478 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12479 | ||
08a24034 DV |
12480 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12481 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12482 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12483 | |
eb14cb74 | 12484 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12485 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12486 | |
12487 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12488 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12489 | ||
12490 | PIPE_CONF_CHECK_I(has_drrs); | |
12491 | if (current_config->has_drrs) | |
12492 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12493 | } else | |
12494 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12495 | |
2d112de7 ACO |
12496 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12497 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12498 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12499 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12500 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12501 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12502 | |
2d112de7 ACO |
12503 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12504 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12505 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12506 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12507 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12508 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12509 | |
c93f54cf | 12510 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12511 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12512 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12513 | IS_VALLEYVIEW(dev)) | |
12514 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12515 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12516 | |
9ed109a7 DV |
12517 | PIPE_CONF_CHECK_I(has_audio); |
12518 | ||
2d112de7 | 12519 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12520 | DRM_MODE_FLAG_INTERLACE); |
12521 | ||
bb760063 | 12522 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12523 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12524 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12525 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12526 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12527 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12528 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12529 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12530 | DRM_MODE_FLAG_NVSYNC); |
12531 | } | |
045ac3b5 | 12532 | |
333b8ca8 | 12533 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12534 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12535 | if (INTEL_INFO(dev)->gen < 4) | |
12536 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
333b8ca8 | 12537 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12538 | |
bfd16b2a ML |
12539 | if (!adjust) { |
12540 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12541 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12542 | ||
12543 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12544 | if (current_config->pch_pfit.enabled) { | |
12545 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12546 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12547 | } | |
2fa2fe9a | 12548 | |
7aefe2b5 ML |
12549 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12550 | } | |
a1b2278e | 12551 | |
e59150dc JB |
12552 | /* BDW+ don't expose a synchronous way to read the state */ |
12553 | if (IS_HASWELL(dev)) | |
12554 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12555 | |
282740f7 VS |
12556 | PIPE_CONF_CHECK_I(double_wide); |
12557 | ||
26804afd DV |
12558 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12559 | ||
c0d43d62 | 12560 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12561 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12562 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12563 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12564 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12565 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
12566 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12567 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12568 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12569 | |
42571aef VS |
12570 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12571 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12572 | ||
2d112de7 | 12573 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12574 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12575 | |
66e985c0 | 12576 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12577 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12578 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12579 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12580 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12581 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12582 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12583 | |
cfb23ed6 | 12584 | return ret; |
0e8ffe1b DV |
12585 | } |
12586 | ||
08db6652 DL |
12587 | static void check_wm_state(struct drm_device *dev) |
12588 | { | |
12589 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12590 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12591 | struct intel_crtc *intel_crtc; | |
12592 | int plane; | |
12593 | ||
12594 | if (INTEL_INFO(dev)->gen < 9) | |
12595 | return; | |
12596 | ||
12597 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12598 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12599 | ||
12600 | for_each_intel_crtc(dev, intel_crtc) { | |
12601 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12602 | const enum pipe pipe = intel_crtc->pipe; | |
12603 | ||
12604 | if (!intel_crtc->active) | |
12605 | continue; | |
12606 | ||
12607 | /* planes */ | |
dd740780 | 12608 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12609 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12610 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12611 | ||
12612 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12613 | continue; | |
12614 | ||
12615 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12616 | "(expected (%u,%u), found (%u,%u))\n", | |
12617 | pipe_name(pipe), plane + 1, | |
12618 | sw_entry->start, sw_entry->end, | |
12619 | hw_entry->start, hw_entry->end); | |
12620 | } | |
12621 | ||
12622 | /* cursor */ | |
4969d33e MR |
12623 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
12624 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 DL |
12625 | |
12626 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12627 | continue; | |
12628 | ||
12629 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12630 | "(expected (%u,%u), found (%u,%u))\n", | |
12631 | pipe_name(pipe), | |
12632 | sw_entry->start, sw_entry->end, | |
12633 | hw_entry->start, hw_entry->end); | |
12634 | } | |
12635 | } | |
12636 | ||
91d1b4bd | 12637 | static void |
35dd3c64 ML |
12638 | check_connector_state(struct drm_device *dev, |
12639 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12640 | { |
35dd3c64 ML |
12641 | struct drm_connector_state *old_conn_state; |
12642 | struct drm_connector *connector; | |
12643 | int i; | |
8af6cf88 | 12644 | |
35dd3c64 ML |
12645 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12646 | struct drm_encoder *encoder = connector->encoder; | |
12647 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12648 | |
8af6cf88 DV |
12649 | /* This also checks the encoder/connector hw state with the |
12650 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12651 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12652 | |
ad3c558f | 12653 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12654 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12655 | } |
91d1b4bd DV |
12656 | } |
12657 | ||
12658 | static void | |
12659 | check_encoder_state(struct drm_device *dev) | |
12660 | { | |
12661 | struct intel_encoder *encoder; | |
12662 | struct intel_connector *connector; | |
8af6cf88 | 12663 | |
b2784e15 | 12664 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12665 | bool enabled = false; |
4d20cd86 | 12666 | enum pipe pipe; |
8af6cf88 DV |
12667 | |
12668 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12669 | encoder->base.base.id, | |
8e329a03 | 12670 | encoder->base.name); |
8af6cf88 | 12671 | |
3a3371ff | 12672 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12673 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12674 | continue; |
12675 | enabled = true; | |
ad3c558f ML |
12676 | |
12677 | I915_STATE_WARN(connector->base.state->crtc != | |
12678 | encoder->base.crtc, | |
12679 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12680 | } |
0e32b39c | 12681 | |
e2c719b7 | 12682 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12683 | "encoder's enabled state mismatch " |
12684 | "(expected %i, found %i)\n", | |
12685 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12686 | |
12687 | if (!encoder->base.crtc) { | |
4d20cd86 | 12688 | bool active; |
7c60d198 | 12689 | |
4d20cd86 ML |
12690 | active = encoder->get_hw_state(encoder, &pipe); |
12691 | I915_STATE_WARN(active, | |
12692 | "encoder detached but still enabled on pipe %c.\n", | |
12693 | pipe_name(pipe)); | |
7c60d198 | 12694 | } |
8af6cf88 | 12695 | } |
91d1b4bd DV |
12696 | } |
12697 | ||
12698 | static void | |
4d20cd86 | 12699 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12700 | { |
fbee40df | 12701 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12702 | struct intel_encoder *encoder; |
4d20cd86 ML |
12703 | struct drm_crtc_state *old_crtc_state; |
12704 | struct drm_crtc *crtc; | |
12705 | int i; | |
8af6cf88 | 12706 | |
4d20cd86 ML |
12707 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12708 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12709 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12710 | bool active; |
8af6cf88 | 12711 | |
bfd16b2a ML |
12712 | if (!needs_modeset(crtc->state) && |
12713 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
4d20cd86 | 12714 | continue; |
045ac3b5 | 12715 | |
4d20cd86 ML |
12716 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
12717 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
12718 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
12719 | pipe_config->base.crtc = crtc; | |
12720 | pipe_config->base.state = old_state; | |
8af6cf88 | 12721 | |
4d20cd86 ML |
12722 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12723 | crtc->base.id); | |
8af6cf88 | 12724 | |
4d20cd86 ML |
12725 | active = dev_priv->display.get_pipe_config(intel_crtc, |
12726 | pipe_config); | |
d62cf62a | 12727 | |
b6b5d049 | 12728 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
12729 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
12730 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
12731 | active = crtc->state->active; | |
6c49f241 | 12732 | |
4d20cd86 | 12733 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 12734 | "crtc active state doesn't match with hw state " |
4d20cd86 | 12735 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 12736 | |
4d20cd86 | 12737 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 12738 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
12739 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
12740 | ||
12741 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
12742 | enum pipe pipe; | |
12743 | ||
12744 | active = encoder->get_hw_state(encoder, &pipe); | |
12745 | I915_STATE_WARN(active != crtc->state->active, | |
12746 | "[ENCODER:%i] active %i with crtc active %i\n", | |
12747 | encoder->base.base.id, active, crtc->state->active); | |
12748 | ||
12749 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
12750 | "Encoder connected to wrong pipe %c\n", | |
12751 | pipe_name(pipe)); | |
12752 | ||
12753 | if (active) | |
12754 | encoder->get_config(encoder, pipe_config); | |
12755 | } | |
53d9f4e9 | 12756 | |
4d20cd86 | 12757 | if (!crtc->state->active) |
cfb23ed6 ML |
12758 | continue; |
12759 | ||
4d20cd86 ML |
12760 | sw_config = to_intel_crtc_state(crtc->state); |
12761 | if (!intel_pipe_config_compare(dev, sw_config, | |
12762 | pipe_config, false)) { | |
e2c719b7 | 12763 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 12764 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 12765 | "[hw state]"); |
4d20cd86 | 12766 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
12767 | "[sw state]"); |
12768 | } | |
8af6cf88 DV |
12769 | } |
12770 | } | |
12771 | ||
91d1b4bd DV |
12772 | static void |
12773 | check_shared_dpll_state(struct drm_device *dev) | |
12774 | { | |
fbee40df | 12775 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12776 | struct intel_crtc *crtc; |
12777 | struct intel_dpll_hw_state dpll_hw_state; | |
12778 | int i; | |
5358901f DV |
12779 | |
12780 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12781 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12782 | int enabled_crtcs = 0, active_crtcs = 0; | |
12783 | bool active; | |
12784 | ||
12785 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12786 | ||
12787 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12788 | ||
12789 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12790 | ||
e2c719b7 | 12791 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12792 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12793 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12794 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12795 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12796 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12797 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12798 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12799 | "pll on state mismatch (expected %i, found %i)\n", |
12800 | pll->on, active); | |
12801 | ||
d3fcc808 | 12802 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12803 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12804 | enabled_crtcs++; |
12805 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12806 | active_crtcs++; | |
12807 | } | |
e2c719b7 | 12808 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12809 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12810 | pll->active, active_crtcs); | |
e2c719b7 | 12811 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12812 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12813 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12814 | |
e2c719b7 | 12815 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12816 | sizeof(dpll_hw_state)), |
12817 | "pll hw state mismatch\n"); | |
5358901f | 12818 | } |
8af6cf88 DV |
12819 | } |
12820 | ||
ee165b1a ML |
12821 | static void |
12822 | intel_modeset_check_state(struct drm_device *dev, | |
12823 | struct drm_atomic_state *old_state) | |
91d1b4bd | 12824 | { |
08db6652 | 12825 | check_wm_state(dev); |
35dd3c64 | 12826 | check_connector_state(dev, old_state); |
91d1b4bd | 12827 | check_encoder_state(dev); |
4d20cd86 | 12828 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
12829 | check_shared_dpll_state(dev); |
12830 | } | |
12831 | ||
5cec258b | 12832 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12833 | int dotclock) |
12834 | { | |
12835 | /* | |
12836 | * FDI already provided one idea for the dotclock. | |
12837 | * Yell if the encoder disagrees. | |
12838 | */ | |
2d112de7 | 12839 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12840 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12841 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12842 | } |
12843 | ||
80715b2f VS |
12844 | static void update_scanline_offset(struct intel_crtc *crtc) |
12845 | { | |
12846 | struct drm_device *dev = crtc->base.dev; | |
12847 | ||
12848 | /* | |
12849 | * The scanline counter increments at the leading edge of hsync. | |
12850 | * | |
12851 | * On most platforms it starts counting from vtotal-1 on the | |
12852 | * first active line. That means the scanline counter value is | |
12853 | * always one less than what we would expect. Ie. just after | |
12854 | * start of vblank, which also occurs at start of hsync (on the | |
12855 | * last active line), the scanline counter will read vblank_start-1. | |
12856 | * | |
12857 | * On gen2 the scanline counter starts counting from 1 instead | |
12858 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12859 | * to keep the value positive), instead of adding one. | |
12860 | * | |
12861 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12862 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12863 | * there's an extra 1 line difference. So we need to add two instead of | |
12864 | * one to the value. | |
12865 | */ | |
12866 | if (IS_GEN2(dev)) { | |
124abe07 | 12867 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12868 | int vtotal; |
12869 | ||
124abe07 VS |
12870 | vtotal = adjusted_mode->crtc_vtotal; |
12871 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
12872 | vtotal /= 2; |
12873 | ||
12874 | crtc->scanline_offset = vtotal - 1; | |
12875 | } else if (HAS_DDI(dev) && | |
409ee761 | 12876 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12877 | crtc->scanline_offset = 2; |
12878 | } else | |
12879 | crtc->scanline_offset = 1; | |
12880 | } | |
12881 | ||
ad421372 | 12882 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 12883 | { |
225da59b | 12884 | struct drm_device *dev = state->dev; |
ed6739ef | 12885 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 12886 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 12887 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12888 | struct intel_crtc_state *intel_crtc_state; |
12889 | struct drm_crtc *crtc; | |
12890 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 12891 | int i; |
ed6739ef ACO |
12892 | |
12893 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 12894 | return; |
ed6739ef | 12895 | |
0a9ab303 | 12896 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
12897 | int dpll; |
12898 | ||
0a9ab303 | 12899 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 12900 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 12901 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 12902 | |
ad421372 | 12903 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
12904 | continue; |
12905 | ||
ad421372 | 12906 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 12907 | |
ad421372 ML |
12908 | if (!shared_dpll) |
12909 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 12910 | |
ad421372 ML |
12911 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
12912 | } | |
ed6739ef ACO |
12913 | } |
12914 | ||
99d736a2 ML |
12915 | /* |
12916 | * This implements the workaround described in the "notes" section of the mode | |
12917 | * set sequence documentation. When going from no pipes or single pipe to | |
12918 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
12919 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
12920 | */ | |
12921 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
12922 | { | |
12923 | struct drm_crtc_state *crtc_state; | |
12924 | struct intel_crtc *intel_crtc; | |
12925 | struct drm_crtc *crtc; | |
12926 | struct intel_crtc_state *first_crtc_state = NULL; | |
12927 | struct intel_crtc_state *other_crtc_state = NULL; | |
12928 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
12929 | int i; | |
12930 | ||
12931 | /* look at all crtc's that are going to be enabled in during modeset */ | |
12932 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
12933 | intel_crtc = to_intel_crtc(crtc); | |
12934 | ||
12935 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
12936 | continue; | |
12937 | ||
12938 | if (first_crtc_state) { | |
12939 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
12940 | break; | |
12941 | } else { | |
12942 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
12943 | first_pipe = intel_crtc->pipe; | |
12944 | } | |
12945 | } | |
12946 | ||
12947 | /* No workaround needed? */ | |
12948 | if (!first_crtc_state) | |
12949 | return 0; | |
12950 | ||
12951 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
12952 | for_each_intel_crtc(state->dev, intel_crtc) { | |
12953 | struct intel_crtc_state *pipe_config; | |
12954 | ||
12955 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
12956 | if (IS_ERR(pipe_config)) | |
12957 | return PTR_ERR(pipe_config); | |
12958 | ||
12959 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
12960 | ||
12961 | if (!pipe_config->base.active || | |
12962 | needs_modeset(&pipe_config->base)) | |
12963 | continue; | |
12964 | ||
12965 | /* 2 or more enabled crtcs means no need for w/a */ | |
12966 | if (enabled_pipe != INVALID_PIPE) | |
12967 | return 0; | |
12968 | ||
12969 | enabled_pipe = intel_crtc->pipe; | |
12970 | } | |
12971 | ||
12972 | if (enabled_pipe != INVALID_PIPE) | |
12973 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
12974 | else if (other_crtc_state) | |
12975 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
12976 | ||
12977 | return 0; | |
12978 | } | |
12979 | ||
27c329ed ML |
12980 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
12981 | { | |
12982 | struct drm_crtc *crtc; | |
12983 | struct drm_crtc_state *crtc_state; | |
12984 | int ret = 0; | |
12985 | ||
12986 | /* add all active pipes to the state */ | |
12987 | for_each_crtc(state->dev, crtc) { | |
12988 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
12989 | if (IS_ERR(crtc_state)) | |
12990 | return PTR_ERR(crtc_state); | |
12991 | ||
12992 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
12993 | continue; | |
12994 | ||
12995 | crtc_state->mode_changed = true; | |
12996 | ||
12997 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
12998 | if (ret) | |
12999 | break; | |
13000 | ||
13001 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13002 | if (ret) | |
13003 | break; | |
13004 | } | |
13005 | ||
13006 | return ret; | |
13007 | } | |
13008 | ||
c347a676 | 13009 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
13010 | { |
13011 | struct drm_device *dev = state->dev; | |
27c329ed | 13012 | struct drm_i915_private *dev_priv = dev->dev_private; |
054518dd ACO |
13013 | int ret; |
13014 | ||
b359283a ML |
13015 | if (!check_digital_port_conflicts(state)) { |
13016 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13017 | return -EINVAL; | |
13018 | } | |
13019 | ||
054518dd ACO |
13020 | /* |
13021 | * See if the config requires any additional preparation, e.g. | |
13022 | * to adjust global state with pipes off. We need to do this | |
13023 | * here so we can get the modeset_pipe updated config for the new | |
13024 | * mode set on this crtc. For other crtcs we need to use the | |
13025 | * adjusted_mode bits in the crtc directly. | |
13026 | */ | |
27c329ed ML |
13027 | if (dev_priv->display.modeset_calc_cdclk) { |
13028 | unsigned int cdclk; | |
b432e5cf | 13029 | |
27c329ed ML |
13030 | ret = dev_priv->display.modeset_calc_cdclk(state); |
13031 | ||
13032 | cdclk = to_intel_atomic_state(state)->cdclk; | |
13033 | if (!ret && cdclk != dev_priv->cdclk_freq) | |
13034 | ret = intel_modeset_all_pipes(state); | |
13035 | ||
13036 | if (ret < 0) | |
054518dd | 13037 | return ret; |
27c329ed ML |
13038 | } else |
13039 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; | |
054518dd | 13040 | |
ad421372 | 13041 | intel_modeset_clear_plls(state); |
054518dd | 13042 | |
99d736a2 | 13043 | if (IS_HASWELL(dev)) |
ad421372 | 13044 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13045 | |
ad421372 | 13046 | return 0; |
c347a676 ACO |
13047 | } |
13048 | ||
aa363136 MR |
13049 | /* |
13050 | * Handle calculation of various watermark data at the end of the atomic check | |
13051 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13052 | * handlers to ensure that all derived state has been updated. | |
13053 | */ | |
13054 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13055 | { | |
13056 | struct drm_device *dev = state->dev; | |
13057 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13058 | struct drm_crtc *crtc; | |
13059 | struct drm_crtc_state *cstate; | |
13060 | struct drm_plane *plane; | |
13061 | struct drm_plane_state *pstate; | |
13062 | ||
13063 | /* | |
13064 | * Calculate watermark configuration details now that derived | |
13065 | * plane/crtc state is all properly updated. | |
13066 | */ | |
13067 | drm_for_each_crtc(crtc, dev) { | |
13068 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13069 | crtc->state; | |
13070 | ||
13071 | if (cstate->active) | |
13072 | intel_state->wm_config.num_pipes_active++; | |
13073 | } | |
13074 | drm_for_each_legacy_plane(plane, dev) { | |
13075 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13076 | plane->state; | |
13077 | ||
13078 | if (!to_intel_plane_state(pstate)->visible) | |
13079 | continue; | |
13080 | ||
13081 | intel_state->wm_config.sprites_enabled = true; | |
13082 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13083 | pstate->crtc_h != pstate->src_h >> 16) | |
13084 | intel_state->wm_config.sprites_scaled = true; | |
13085 | } | |
13086 | } | |
13087 | ||
74c090b1 ML |
13088 | /** |
13089 | * intel_atomic_check - validate state object | |
13090 | * @dev: drm device | |
13091 | * @state: state to validate | |
13092 | */ | |
13093 | static int intel_atomic_check(struct drm_device *dev, | |
13094 | struct drm_atomic_state *state) | |
c347a676 | 13095 | { |
aa363136 | 13096 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13097 | struct drm_crtc *crtc; |
13098 | struct drm_crtc_state *crtc_state; | |
13099 | int ret, i; | |
61333b60 | 13100 | bool any_ms = false; |
c347a676 | 13101 | |
74c090b1 | 13102 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13103 | if (ret) |
13104 | return ret; | |
13105 | ||
c347a676 | 13106 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13107 | struct intel_crtc_state *pipe_config = |
13108 | to_intel_crtc_state(crtc_state); | |
1ed51de9 DV |
13109 | |
13110 | /* Catch I915_MODE_FLAG_INHERITED */ | |
13111 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13112 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13113 | |
61333b60 ML |
13114 | if (!crtc_state->enable) { |
13115 | if (needs_modeset(crtc_state)) | |
13116 | any_ms = true; | |
c347a676 | 13117 | continue; |
61333b60 | 13118 | } |
c347a676 | 13119 | |
26495481 | 13120 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
13121 | continue; |
13122 | ||
26495481 DV |
13123 | /* FIXME: For only active_changed we shouldn't need to do any |
13124 | * state recomputation at all. */ | |
13125 | ||
1ed51de9 DV |
13126 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13127 | if (ret) | |
13128 | return ret; | |
b359283a | 13129 | |
cfb23ed6 | 13130 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13131 | if (ret) |
13132 | return ret; | |
13133 | ||
6764e9f8 | 13134 | if (intel_pipe_config_compare(state->dev, |
cfb23ed6 | 13135 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13136 | pipe_config, true)) { |
26495481 | 13137 | crtc_state->mode_changed = false; |
bfd16b2a | 13138 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13139 | } |
13140 | ||
13141 | if (needs_modeset(crtc_state)) { | |
13142 | any_ms = true; | |
cfb23ed6 ML |
13143 | |
13144 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13145 | if (ret) | |
13146 | return ret; | |
13147 | } | |
61333b60 | 13148 | |
26495481 DV |
13149 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13150 | needs_modeset(crtc_state) ? | |
13151 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13152 | } |
13153 | ||
61333b60 ML |
13154 | if (any_ms) { |
13155 | ret = intel_modeset_checks(state); | |
13156 | ||
13157 | if (ret) | |
13158 | return ret; | |
27c329ed | 13159 | } else |
aa363136 | 13160 | intel_state->cdclk = to_i915(state->dev)->cdclk_freq; |
76305b1a | 13161 | |
aa363136 MR |
13162 | ret = drm_atomic_helper_check_planes(state->dev, state); |
13163 | if (ret) | |
13164 | return ret; | |
13165 | ||
13166 | calc_watermark_data(state); | |
13167 | ||
13168 | return 0; | |
054518dd ACO |
13169 | } |
13170 | ||
5008e874 ML |
13171 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13172 | struct drm_atomic_state *state, | |
13173 | bool async) | |
13174 | { | |
7580d774 ML |
13175 | struct drm_i915_private *dev_priv = dev->dev_private; |
13176 | struct drm_plane_state *plane_state; | |
5008e874 | 13177 | struct drm_crtc_state *crtc_state; |
7580d774 | 13178 | struct drm_plane *plane; |
5008e874 ML |
13179 | struct drm_crtc *crtc; |
13180 | int i, ret; | |
13181 | ||
13182 | if (async) { | |
13183 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13184 | return -EINVAL; | |
13185 | } | |
13186 | ||
13187 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13188 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13189 | if (ret) | |
13190 | return ret; | |
7580d774 ML |
13191 | |
13192 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13193 | flush_workqueue(dev_priv->wq); | |
5008e874 ML |
13194 | } |
13195 | ||
f935675f ML |
13196 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13197 | if (ret) | |
13198 | return ret; | |
13199 | ||
5008e874 | 13200 | ret = drm_atomic_helper_prepare_planes(dev, state); |
7580d774 ML |
13201 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
13202 | u32 reset_counter; | |
13203 | ||
13204 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13205 | mutex_unlock(&dev->struct_mutex); | |
13206 | ||
13207 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13208 | struct intel_plane_state *intel_plane_state = | |
13209 | to_intel_plane_state(plane_state); | |
13210 | ||
13211 | if (!intel_plane_state->wait_req) | |
13212 | continue; | |
13213 | ||
13214 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13215 | reset_counter, true, | |
13216 | NULL, NULL); | |
13217 | ||
13218 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13219 | if (ret == -EIO) | |
13220 | ret = 0; | |
13221 | ||
13222 | if (ret) | |
13223 | break; | |
13224 | } | |
13225 | ||
13226 | if (!ret) | |
13227 | return 0; | |
13228 | ||
13229 | mutex_lock(&dev->struct_mutex); | |
13230 | drm_atomic_helper_cleanup_planes(dev, state); | |
13231 | } | |
5008e874 | 13232 | |
f935675f | 13233 | mutex_unlock(&dev->struct_mutex); |
5008e874 ML |
13234 | return ret; |
13235 | } | |
13236 | ||
74c090b1 ML |
13237 | /** |
13238 | * intel_atomic_commit - commit validated state object | |
13239 | * @dev: DRM device | |
13240 | * @state: the top-level driver state object | |
13241 | * @async: asynchronous commit | |
13242 | * | |
13243 | * This function commits a top-level state object that has been validated | |
13244 | * with drm_atomic_helper_check(). | |
13245 | * | |
13246 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13247 | * we can only handle plane-related operations and do not yet support | |
13248 | * asynchronous commit. | |
13249 | * | |
13250 | * RETURNS | |
13251 | * Zero for success or -errno. | |
13252 | */ | |
13253 | static int intel_atomic_commit(struct drm_device *dev, | |
13254 | struct drm_atomic_state *state, | |
13255 | bool async) | |
a6778b3c | 13256 | { |
fbee40df | 13257 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 | 13258 | struct drm_crtc_state *crtc_state; |
7580d774 | 13259 | struct drm_crtc *crtc; |
c0c36b94 | 13260 | int ret = 0; |
0a9ab303 | 13261 | int i; |
61333b60 | 13262 | bool any_ms = false; |
a6778b3c | 13263 | |
5008e874 | 13264 | ret = intel_atomic_prepare_commit(dev, state, async); |
7580d774 ML |
13265 | if (ret) { |
13266 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
d4afb8cc | 13267 | return ret; |
7580d774 | 13268 | } |
d4afb8cc | 13269 | |
1c5e19f8 | 13270 | drm_atomic_helper_swap_state(dev, state); |
aa363136 | 13271 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; |
1c5e19f8 | 13272 | |
0a9ab303 | 13273 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13274 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13275 | ||
61333b60 ML |
13276 | if (!needs_modeset(crtc->state)) |
13277 | continue; | |
13278 | ||
13279 | any_ms = true; | |
a539205a | 13280 | intel_pre_plane_update(intel_crtc); |
460da916 | 13281 | |
a539205a ML |
13282 | if (crtc_state->active) { |
13283 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13284 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd ML |
13285 | intel_crtc->active = false; |
13286 | intel_disable_shared_dpll(intel_crtc); | |
a539205a | 13287 | } |
b8cecdf5 | 13288 | } |
7758a113 | 13289 | |
ea9d758d DV |
13290 | /* Only after disabling all output pipelines that will be changed can we |
13291 | * update the the output configuration. */ | |
4740b0f2 | 13292 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13293 | |
4740b0f2 ML |
13294 | if (any_ms) { |
13295 | intel_shared_dpll_commit(state); | |
13296 | ||
13297 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
61333b60 | 13298 | modeset_update_crtc_power_domains(state); |
4740b0f2 | 13299 | } |
47fab737 | 13300 | |
a6778b3c | 13301 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13302 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13303 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13304 | bool modeset = needs_modeset(crtc->state); | |
bfd16b2a ML |
13305 | bool update_pipe = !modeset && |
13306 | to_intel_crtc_state(crtc->state)->update_pipe; | |
13307 | unsigned long put_domains = 0; | |
f6ac4b2a ML |
13308 | |
13309 | if (modeset && crtc->state->active) { | |
a539205a ML |
13310 | update_scanline_offset(to_intel_crtc(crtc)); |
13311 | dev_priv->display.crtc_enable(crtc); | |
13312 | } | |
80715b2f | 13313 | |
bfd16b2a ML |
13314 | if (update_pipe) { |
13315 | put_domains = modeset_get_crtc_power_domains(crtc); | |
13316 | ||
13317 | /* make sure intel_modeset_check_state runs */ | |
13318 | any_ms = true; | |
13319 | } | |
13320 | ||
f6ac4b2a ML |
13321 | if (!modeset) |
13322 | intel_pre_plane_update(intel_crtc); | |
13323 | ||
6173ee28 ML |
13324 | if (crtc->state->active && |
13325 | (crtc->state->planes_changed || update_pipe)) | |
62852622 | 13326 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
bfd16b2a ML |
13327 | |
13328 | if (put_domains) | |
13329 | modeset_put_power_domains(dev_priv, put_domains); | |
13330 | ||
f6ac4b2a | 13331 | intel_post_plane_update(intel_crtc); |
80715b2f | 13332 | } |
a6778b3c | 13333 | |
a6778b3c | 13334 | /* FIXME: add subpixel order */ |
83a57153 | 13335 | |
74c090b1 | 13336 | drm_atomic_helper_wait_for_vblanks(dev, state); |
f935675f ML |
13337 | |
13338 | mutex_lock(&dev->struct_mutex); | |
d4afb8cc | 13339 | drm_atomic_helper_cleanup_planes(dev, state); |
f935675f | 13340 | mutex_unlock(&dev->struct_mutex); |
2bfb4627 | 13341 | |
74c090b1 | 13342 | if (any_ms) |
ee165b1a ML |
13343 | intel_modeset_check_state(dev, state); |
13344 | ||
13345 | drm_atomic_state_free(state); | |
f30da187 | 13346 | |
74c090b1 | 13347 | return 0; |
7f27126e JB |
13348 | } |
13349 | ||
c0c36b94 CW |
13350 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13351 | { | |
83a57153 ACO |
13352 | struct drm_device *dev = crtc->dev; |
13353 | struct drm_atomic_state *state; | |
e694eb02 | 13354 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13355 | int ret; |
83a57153 ACO |
13356 | |
13357 | state = drm_atomic_state_alloc(dev); | |
13358 | if (!state) { | |
e694eb02 | 13359 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13360 | crtc->base.id); |
13361 | return; | |
13362 | } | |
13363 | ||
e694eb02 | 13364 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13365 | |
e694eb02 ML |
13366 | retry: |
13367 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13368 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13369 | if (!ret) { | |
13370 | if (!crtc_state->active) | |
13371 | goto out; | |
83a57153 | 13372 | |
e694eb02 | 13373 | crtc_state->mode_changed = true; |
74c090b1 | 13374 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13375 | } |
13376 | ||
e694eb02 ML |
13377 | if (ret == -EDEADLK) { |
13378 | drm_atomic_state_clear(state); | |
13379 | drm_modeset_backoff(state->acquire_ctx); | |
13380 | goto retry; | |
4ed9fb37 | 13381 | } |
4be07317 | 13382 | |
2bfb4627 | 13383 | if (ret) |
e694eb02 | 13384 | out: |
2bfb4627 | 13385 | drm_atomic_state_free(state); |
c0c36b94 CW |
13386 | } |
13387 | ||
25c5b266 DV |
13388 | #undef for_each_intel_crtc_masked |
13389 | ||
f6e5b160 | 13390 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13391 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13392 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13393 | .destroy = intel_crtc_destroy, |
13394 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13395 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13396 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13397 | }; |
13398 | ||
5358901f DV |
13399 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13400 | struct intel_shared_dpll *pll, | |
13401 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13402 | { |
5358901f | 13403 | uint32_t val; |
ee7b9f93 | 13404 | |
f458ebbc | 13405 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13406 | return false; |
13407 | ||
5358901f | 13408 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13409 | hw_state->dpll = val; |
13410 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13411 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13412 | |
13413 | return val & DPLL_VCO_ENABLE; | |
13414 | } | |
13415 | ||
15bdd4cf DV |
13416 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13417 | struct intel_shared_dpll *pll) | |
13418 | { | |
3e369b76 ACO |
13419 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13420 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13421 | } |
13422 | ||
e7b903d2 DV |
13423 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13424 | struct intel_shared_dpll *pll) | |
13425 | { | |
e7b903d2 | 13426 | /* PCH refclock must be enabled first */ |
89eff4be | 13427 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13428 | |
3e369b76 | 13429 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13430 | |
13431 | /* Wait for the clocks to stabilize. */ | |
13432 | POSTING_READ(PCH_DPLL(pll->id)); | |
13433 | udelay(150); | |
13434 | ||
13435 | /* The pixel multiplier can only be updated once the | |
13436 | * DPLL is enabled and the clocks are stable. | |
13437 | * | |
13438 | * So write it again. | |
13439 | */ | |
3e369b76 | 13440 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13441 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13442 | udelay(200); |
13443 | } | |
13444 | ||
13445 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13446 | struct intel_shared_dpll *pll) | |
13447 | { | |
13448 | struct drm_device *dev = dev_priv->dev; | |
13449 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13450 | |
13451 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13452 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13453 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13454 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13455 | } |
13456 | ||
15bdd4cf DV |
13457 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13458 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13459 | udelay(200); |
13460 | } | |
13461 | ||
46edb027 DV |
13462 | static char *ibx_pch_dpll_names[] = { |
13463 | "PCH DPLL A", | |
13464 | "PCH DPLL B", | |
13465 | }; | |
13466 | ||
7c74ade1 | 13467 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13468 | { |
e7b903d2 | 13469 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13470 | int i; |
13471 | ||
7c74ade1 | 13472 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13473 | |
e72f9fbf | 13474 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13475 | dev_priv->shared_dplls[i].id = i; |
13476 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13477 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13478 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13479 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13480 | dev_priv->shared_dplls[i].get_hw_state = |
13481 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13482 | } |
13483 | } | |
13484 | ||
7c74ade1 DV |
13485 | static void intel_shared_dpll_init(struct drm_device *dev) |
13486 | { | |
e7b903d2 | 13487 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13488 | |
9cd86933 DV |
13489 | if (HAS_DDI(dev)) |
13490 | intel_ddi_pll_init(dev); | |
13491 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13492 | ibx_pch_dpll_init(dev); |
13493 | else | |
13494 | dev_priv->num_shared_dpll = 0; | |
13495 | ||
13496 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13497 | } |
13498 | ||
6beb8c23 MR |
13499 | /** |
13500 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13501 | * @plane: drm plane to prepare for | |
13502 | * @fb: framebuffer to prepare for presentation | |
13503 | * | |
13504 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13505 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13506 | * bits. Some older platforms need special physical address handling for | |
13507 | * cursor planes. | |
13508 | * | |
f935675f ML |
13509 | * Must be called with struct_mutex held. |
13510 | * | |
6beb8c23 MR |
13511 | * Returns 0 on success, negative error code on failure. |
13512 | */ | |
13513 | int | |
13514 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 13515 | const struct drm_plane_state *new_state) |
465c120c MR |
13516 | { |
13517 | struct drm_device *dev = plane->dev; | |
844f9111 | 13518 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 13519 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 | 13520 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 13521 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
6beb8c23 | 13522 | int ret = 0; |
465c120c | 13523 | |
1ee49399 | 13524 | if (!obj && !old_obj) |
465c120c MR |
13525 | return 0; |
13526 | ||
5008e874 ML |
13527 | if (old_obj) { |
13528 | struct drm_crtc_state *crtc_state = | |
13529 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13530 | ||
13531 | /* Big Hammer, we also need to ensure that any pending | |
13532 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13533 | * current scanout is retired before unpinning the old | |
13534 | * framebuffer. Note that we rely on userspace rendering | |
13535 | * into the buffer attached to the pipe they are waiting | |
13536 | * on. If not, userspace generates a GPU hang with IPEHR | |
13537 | * point to the MI_WAIT_FOR_EVENT. | |
13538 | * | |
13539 | * This should only fail upon a hung GPU, in which case we | |
13540 | * can safely continue. | |
13541 | */ | |
13542 | if (needs_modeset(crtc_state)) | |
13543 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13544 | ||
13545 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13546 | if (ret && ret != -EIO) | |
f935675f | 13547 | return ret; |
5008e874 ML |
13548 | } |
13549 | ||
1ee49399 ML |
13550 | if (!obj) { |
13551 | ret = 0; | |
13552 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
6beb8c23 MR |
13553 | INTEL_INFO(dev)->cursor_needs_physical) { |
13554 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13555 | ret = i915_gem_object_attach_phys(obj, align); | |
13556 | if (ret) | |
13557 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13558 | } else { | |
7580d774 | 13559 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state); |
6beb8c23 | 13560 | } |
465c120c | 13561 | |
7580d774 ML |
13562 | if (ret == 0) { |
13563 | if (obj) { | |
13564 | struct intel_plane_state *plane_state = | |
13565 | to_intel_plane_state(new_state); | |
13566 | ||
13567 | i915_gem_request_assign(&plane_state->wait_req, | |
13568 | obj->last_write_req); | |
13569 | } | |
13570 | ||
a9ff8714 | 13571 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
7580d774 | 13572 | } |
fdd508a6 | 13573 | |
6beb8c23 MR |
13574 | return ret; |
13575 | } | |
13576 | ||
38f3ce3a MR |
13577 | /** |
13578 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13579 | * @plane: drm plane to clean up for | |
13580 | * @fb: old framebuffer that was on plane | |
13581 | * | |
13582 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
13583 | * |
13584 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
13585 | */ |
13586 | void | |
13587 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 13588 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
13589 | { |
13590 | struct drm_device *dev = plane->dev; | |
1ee49399 | 13591 | struct intel_plane *intel_plane = to_intel_plane(plane); |
7580d774 | 13592 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
13593 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
13594 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 13595 | |
7580d774 ML |
13596 | old_intel_state = to_intel_plane_state(old_state); |
13597 | ||
1ee49399 | 13598 | if (!obj && !old_obj) |
38f3ce3a MR |
13599 | return; |
13600 | ||
1ee49399 ML |
13601 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
13602 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
844f9111 | 13603 | intel_unpin_fb_obj(old_state->fb, old_state); |
1ee49399 ML |
13604 | |
13605 | /* prepare_fb aborted? */ | |
13606 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
13607 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
13608 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
7580d774 ML |
13609 | |
13610 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
13611 | ||
465c120c MR |
13612 | } |
13613 | ||
6156a456 CK |
13614 | int |
13615 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13616 | { | |
13617 | int max_scale; | |
13618 | struct drm_device *dev; | |
13619 | struct drm_i915_private *dev_priv; | |
13620 | int crtc_clock, cdclk; | |
13621 | ||
13622 | if (!intel_crtc || !crtc_state) | |
13623 | return DRM_PLANE_HELPER_NO_SCALING; | |
13624 | ||
13625 | dev = intel_crtc->base.dev; | |
13626 | dev_priv = dev->dev_private; | |
13627 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 13628 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 13629 | |
54bf1ce6 | 13630 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
13631 | return DRM_PLANE_HELPER_NO_SCALING; |
13632 | ||
13633 | /* | |
13634 | * skl max scale is lower of: | |
13635 | * close to 3 but not 3, -1 is for that purpose | |
13636 | * or | |
13637 | * cdclk/crtc_clock | |
13638 | */ | |
13639 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13640 | ||
13641 | return max_scale; | |
13642 | } | |
13643 | ||
465c120c | 13644 | static int |
3c692a41 | 13645 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13646 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13647 | struct intel_plane_state *state) |
13648 | { | |
2b875c22 MR |
13649 | struct drm_crtc *crtc = state->base.crtc; |
13650 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13651 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13652 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13653 | bool can_position = false; | |
465c120c | 13654 | |
061e4b8d ML |
13655 | /* use scaler when colorkey is not required */ |
13656 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
818ed961 | 13657 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
061e4b8d ML |
13658 | min_scale = 1; |
13659 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13660 | can_position = true; |
6156a456 | 13661 | } |
d8106366 | 13662 | |
061e4b8d ML |
13663 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13664 | &state->dst, &state->clip, | |
da20eabd ML |
13665 | min_scale, max_scale, |
13666 | can_position, true, | |
13667 | &state->visible); | |
14af293f GP |
13668 | } |
13669 | ||
13670 | static void | |
13671 | intel_commit_primary_plane(struct drm_plane *plane, | |
13672 | struct intel_plane_state *state) | |
13673 | { | |
2b875c22 MR |
13674 | struct drm_crtc *crtc = state->base.crtc; |
13675 | struct drm_framebuffer *fb = state->base.fb; | |
13676 | struct drm_device *dev = plane->dev; | |
14af293f | 13677 | struct drm_i915_private *dev_priv = dev->dev_private; |
14af293f | 13678 | |
ea2c67bb | 13679 | crtc = crtc ? crtc : plane->crtc; |
ccc759dc | 13680 | |
d4b08630 ML |
13681 | dev_priv->display.update_primary_plane(crtc, fb, |
13682 | state->src.x1 >> 16, | |
13683 | state->src.y1 >> 16); | |
465c120c MR |
13684 | } |
13685 | ||
a8ad0d8e ML |
13686 | static void |
13687 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13688 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13689 | { |
13690 | struct drm_device *dev = plane->dev; | |
13691 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13692 | ||
a8ad0d8e ML |
13693 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13694 | } | |
13695 | ||
613d2b27 ML |
13696 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
13697 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 13698 | { |
32b7eeec | 13699 | struct drm_device *dev = crtc->dev; |
3c692a41 | 13700 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
bfd16b2a ML |
13701 | struct intel_crtc_state *old_intel_state = |
13702 | to_intel_crtc_state(old_crtc_state); | |
13703 | bool modeset = needs_modeset(crtc->state); | |
3c692a41 | 13704 | |
f015c551 | 13705 | if (intel_crtc->atomic.update_wm_pre) |
32b7eeec | 13706 | intel_update_watermarks(crtc); |
3c692a41 | 13707 | |
c34c9ee4 | 13708 | /* Perform vblank evasion around commit operation */ |
62852622 | 13709 | intel_pipe_update_start(intel_crtc); |
0583236e | 13710 | |
bfd16b2a ML |
13711 | if (modeset) |
13712 | return; | |
13713 | ||
13714 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
13715 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
13716 | else if (INTEL_INFO(dev)->gen >= 9) | |
0583236e | 13717 | skl_detach_scalers(intel_crtc); |
32b7eeec MR |
13718 | } |
13719 | ||
613d2b27 ML |
13720 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
13721 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 13722 | { |
32b7eeec | 13723 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 13724 | |
62852622 | 13725 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
13726 | } |
13727 | ||
cf4c7c12 | 13728 | /** |
4a3b8769 MR |
13729 | * intel_plane_destroy - destroy a plane |
13730 | * @plane: plane to destroy | |
cf4c7c12 | 13731 | * |
4a3b8769 MR |
13732 | * Common destruction function for all types of planes (primary, cursor, |
13733 | * sprite). | |
cf4c7c12 | 13734 | */ |
4a3b8769 | 13735 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13736 | { |
13737 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13738 | drm_plane_cleanup(plane); | |
13739 | kfree(intel_plane); | |
13740 | } | |
13741 | ||
65a3fea0 | 13742 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13743 | .update_plane = drm_atomic_helper_update_plane, |
13744 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13745 | .destroy = intel_plane_destroy, |
c196e1d6 | 13746 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13747 | .atomic_get_property = intel_plane_atomic_get_property, |
13748 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13749 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13750 | .atomic_destroy_state = intel_plane_destroy_state, | |
13751 | ||
465c120c MR |
13752 | }; |
13753 | ||
13754 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13755 | int pipe) | |
13756 | { | |
13757 | struct intel_plane *primary; | |
8e7d688b | 13758 | struct intel_plane_state *state; |
465c120c | 13759 | const uint32_t *intel_primary_formats; |
45e3743a | 13760 | unsigned int num_formats; |
465c120c MR |
13761 | |
13762 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13763 | if (primary == NULL) | |
13764 | return NULL; | |
13765 | ||
8e7d688b MR |
13766 | state = intel_create_plane_state(&primary->base); |
13767 | if (!state) { | |
ea2c67bb MR |
13768 | kfree(primary); |
13769 | return NULL; | |
13770 | } | |
8e7d688b | 13771 | primary->base.state = &state->base; |
ea2c67bb | 13772 | |
465c120c MR |
13773 | primary->can_scale = false; |
13774 | primary->max_downscale = 1; | |
6156a456 CK |
13775 | if (INTEL_INFO(dev)->gen >= 9) { |
13776 | primary->can_scale = true; | |
af99ceda | 13777 | state->scaler_id = -1; |
6156a456 | 13778 | } |
465c120c MR |
13779 | primary->pipe = pipe; |
13780 | primary->plane = pipe; | |
a9ff8714 | 13781 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 MR |
13782 | primary->check_plane = intel_check_primary_plane; |
13783 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13784 | primary->disable_plane = intel_disable_primary_plane; |
465c120c MR |
13785 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13786 | primary->plane = !pipe; | |
13787 | ||
6c0fd451 DL |
13788 | if (INTEL_INFO(dev)->gen >= 9) { |
13789 | intel_primary_formats = skl_primary_formats; | |
13790 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13791 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13792 | intel_primary_formats = i965_primary_formats; |
13793 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13794 | } else { |
13795 | intel_primary_formats = i8xx_primary_formats; | |
13796 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13797 | } |
13798 | ||
13799 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13800 | &intel_plane_funcs, |
465c120c MR |
13801 | intel_primary_formats, num_formats, |
13802 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13803 | |
3b7a5119 SJ |
13804 | if (INTEL_INFO(dev)->gen >= 4) |
13805 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13806 | |
ea2c67bb MR |
13807 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13808 | ||
465c120c MR |
13809 | return &primary->base; |
13810 | } | |
13811 | ||
3b7a5119 SJ |
13812 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13813 | { | |
13814 | if (!dev->mode_config.rotation_property) { | |
13815 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13816 | BIT(DRM_ROTATE_180); | |
13817 | ||
13818 | if (INTEL_INFO(dev)->gen >= 9) | |
13819 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13820 | ||
13821 | dev->mode_config.rotation_property = | |
13822 | drm_mode_create_rotation_property(dev, flags); | |
13823 | } | |
13824 | if (dev->mode_config.rotation_property) | |
13825 | drm_object_attach_property(&plane->base.base, | |
13826 | dev->mode_config.rotation_property, | |
13827 | plane->base.state->rotation); | |
13828 | } | |
13829 | ||
3d7d6510 | 13830 | static int |
852e787c | 13831 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 13832 | struct intel_crtc_state *crtc_state, |
852e787c | 13833 | struct intel_plane_state *state) |
3d7d6510 | 13834 | { |
061e4b8d | 13835 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 13836 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 13837 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
13838 | unsigned stride; |
13839 | int ret; | |
3d7d6510 | 13840 | |
061e4b8d ML |
13841 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13842 | &state->dst, &state->clip, | |
3d7d6510 MR |
13843 | DRM_PLANE_HELPER_NO_SCALING, |
13844 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13845 | true, true, &state->visible); |
757f9a3e GP |
13846 | if (ret) |
13847 | return ret; | |
13848 | ||
757f9a3e GP |
13849 | /* if we want to turn off the cursor ignore width and height */ |
13850 | if (!obj) | |
da20eabd | 13851 | return 0; |
757f9a3e | 13852 | |
757f9a3e | 13853 | /* Check for which cursor types we support */ |
061e4b8d | 13854 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
13855 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
13856 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13857 | return -EINVAL; |
13858 | } | |
13859 | ||
ea2c67bb MR |
13860 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13861 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13862 | DRM_DEBUG_KMS("buffer is too small\n"); |
13863 | return -ENOMEM; | |
13864 | } | |
13865 | ||
3a656b54 | 13866 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 13867 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 13868 | return -EINVAL; |
32b7eeec MR |
13869 | } |
13870 | ||
da20eabd | 13871 | return 0; |
852e787c | 13872 | } |
3d7d6510 | 13873 | |
a8ad0d8e ML |
13874 | static void |
13875 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 13876 | struct drm_crtc *crtc) |
a8ad0d8e | 13877 | { |
a8ad0d8e ML |
13878 | intel_crtc_update_cursor(crtc, false); |
13879 | } | |
13880 | ||
f4a2cf29 | 13881 | static void |
852e787c GP |
13882 | intel_commit_cursor_plane(struct drm_plane *plane, |
13883 | struct intel_plane_state *state) | |
13884 | { | |
2b875c22 | 13885 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
13886 | struct drm_device *dev = plane->dev; |
13887 | struct intel_crtc *intel_crtc; | |
2b875c22 | 13888 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 13889 | uint32_t addr; |
852e787c | 13890 | |
ea2c67bb MR |
13891 | crtc = crtc ? crtc : plane->crtc; |
13892 | intel_crtc = to_intel_crtc(crtc); | |
13893 | ||
a912f12f GP |
13894 | if (intel_crtc->cursor_bo == obj) |
13895 | goto update; | |
4ed91096 | 13896 | |
f4a2cf29 | 13897 | if (!obj) |
a912f12f | 13898 | addr = 0; |
f4a2cf29 | 13899 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 13900 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 13901 | else |
a912f12f | 13902 | addr = obj->phys_handle->busaddr; |
852e787c | 13903 | |
a912f12f GP |
13904 | intel_crtc->cursor_addr = addr; |
13905 | intel_crtc->cursor_bo = obj; | |
852e787c | 13906 | |
302d19ac | 13907 | update: |
62852622 | 13908 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
13909 | } |
13910 | ||
3d7d6510 MR |
13911 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
13912 | int pipe) | |
13913 | { | |
13914 | struct intel_plane *cursor; | |
8e7d688b | 13915 | struct intel_plane_state *state; |
3d7d6510 MR |
13916 | |
13917 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
13918 | if (cursor == NULL) | |
13919 | return NULL; | |
13920 | ||
8e7d688b MR |
13921 | state = intel_create_plane_state(&cursor->base); |
13922 | if (!state) { | |
ea2c67bb MR |
13923 | kfree(cursor); |
13924 | return NULL; | |
13925 | } | |
8e7d688b | 13926 | cursor->base.state = &state->base; |
ea2c67bb | 13927 | |
3d7d6510 MR |
13928 | cursor->can_scale = false; |
13929 | cursor->max_downscale = 1; | |
13930 | cursor->pipe = pipe; | |
13931 | cursor->plane = pipe; | |
a9ff8714 | 13932 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 MR |
13933 | cursor->check_plane = intel_check_cursor_plane; |
13934 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 13935 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
13936 | |
13937 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 13938 | &intel_plane_funcs, |
3d7d6510 MR |
13939 | intel_cursor_formats, |
13940 | ARRAY_SIZE(intel_cursor_formats), | |
13941 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
13942 | |
13943 | if (INTEL_INFO(dev)->gen >= 4) { | |
13944 | if (!dev->mode_config.rotation_property) | |
13945 | dev->mode_config.rotation_property = | |
13946 | drm_mode_create_rotation_property(dev, | |
13947 | BIT(DRM_ROTATE_0) | | |
13948 | BIT(DRM_ROTATE_180)); | |
13949 | if (dev->mode_config.rotation_property) | |
13950 | drm_object_attach_property(&cursor->base.base, | |
13951 | dev->mode_config.rotation_property, | |
8e7d688b | 13952 | state->base.rotation); |
4398ad45 VS |
13953 | } |
13954 | ||
af99ceda CK |
13955 | if (INTEL_INFO(dev)->gen >=9) |
13956 | state->scaler_id = -1; | |
13957 | ||
ea2c67bb MR |
13958 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
13959 | ||
3d7d6510 MR |
13960 | return &cursor->base; |
13961 | } | |
13962 | ||
549e2bfb CK |
13963 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
13964 | struct intel_crtc_state *crtc_state) | |
13965 | { | |
13966 | int i; | |
13967 | struct intel_scaler *intel_scaler; | |
13968 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
13969 | ||
13970 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
13971 | intel_scaler = &scaler_state->scalers[i]; | |
13972 | intel_scaler->in_use = 0; | |
549e2bfb CK |
13973 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
13974 | } | |
13975 | ||
13976 | scaler_state->scaler_id = -1; | |
13977 | } | |
13978 | ||
b358d0a6 | 13979 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 13980 | { |
fbee40df | 13981 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 13982 | struct intel_crtc *intel_crtc; |
f5de6e07 | 13983 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
13984 | struct drm_plane *primary = NULL; |
13985 | struct drm_plane *cursor = NULL; | |
465c120c | 13986 | int i, ret; |
79e53945 | 13987 | |
955382f3 | 13988 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
13989 | if (intel_crtc == NULL) |
13990 | return; | |
13991 | ||
f5de6e07 ACO |
13992 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
13993 | if (!crtc_state) | |
13994 | goto fail; | |
550acefd ACO |
13995 | intel_crtc->config = crtc_state; |
13996 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 13997 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 13998 | |
549e2bfb CK |
13999 | /* initialize shared scalers */ |
14000 | if (INTEL_INFO(dev)->gen >= 9) { | |
14001 | if (pipe == PIPE_C) | |
14002 | intel_crtc->num_scalers = 1; | |
14003 | else | |
14004 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14005 | ||
14006 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14007 | } | |
14008 | ||
465c120c | 14009 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14010 | if (!primary) |
14011 | goto fail; | |
14012 | ||
14013 | cursor = intel_cursor_plane_create(dev, pipe); | |
14014 | if (!cursor) | |
14015 | goto fail; | |
14016 | ||
465c120c | 14017 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14018 | cursor, &intel_crtc_funcs); |
14019 | if (ret) | |
14020 | goto fail; | |
79e53945 JB |
14021 | |
14022 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14023 | for (i = 0; i < 256; i++) { |
14024 | intel_crtc->lut_r[i] = i; | |
14025 | intel_crtc->lut_g[i] = i; | |
14026 | intel_crtc->lut_b[i] = i; | |
14027 | } | |
14028 | ||
1f1c2e24 VS |
14029 | /* |
14030 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14031 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14032 | */ |
80824003 JB |
14033 | intel_crtc->pipe = pipe; |
14034 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14035 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14036 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14037 | intel_crtc->plane = !pipe; |
80824003 JB |
14038 | } |
14039 | ||
4b0e333e CW |
14040 | intel_crtc->cursor_base = ~0; |
14041 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14042 | intel_crtc->cursor_size = ~0; |
8d7849db | 14043 | |
852eb00d VS |
14044 | intel_crtc->wm.cxsr_allowed = true; |
14045 | ||
22fd0fab JB |
14046 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14047 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14048 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14049 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14050 | ||
79e53945 | 14051 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14052 | |
14053 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14054 | return; |
14055 | ||
14056 | fail: | |
14057 | if (primary) | |
14058 | drm_plane_cleanup(primary); | |
14059 | if (cursor) | |
14060 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14061 | kfree(crtc_state); |
3d7d6510 | 14062 | kfree(intel_crtc); |
79e53945 JB |
14063 | } |
14064 | ||
752aa88a JB |
14065 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14066 | { | |
14067 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14068 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14069 | |
51fd371b | 14070 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14071 | |
d3babd3f | 14072 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14073 | return INVALID_PIPE; |
14074 | ||
14075 | return to_intel_crtc(encoder->crtc)->pipe; | |
14076 | } | |
14077 | ||
08d7b3d1 | 14078 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14079 | struct drm_file *file) |
08d7b3d1 | 14080 | { |
08d7b3d1 | 14081 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14082 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14083 | struct intel_crtc *crtc; |
08d7b3d1 | 14084 | |
7707e653 | 14085 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14086 | |
7707e653 | 14087 | if (!drmmode_crtc) { |
08d7b3d1 | 14088 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14089 | return -ENOENT; |
08d7b3d1 CW |
14090 | } |
14091 | ||
7707e653 | 14092 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14093 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14094 | |
c05422d5 | 14095 | return 0; |
08d7b3d1 CW |
14096 | } |
14097 | ||
66a9278e | 14098 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14099 | { |
66a9278e DV |
14100 | struct drm_device *dev = encoder->base.dev; |
14101 | struct intel_encoder *source_encoder; | |
79e53945 | 14102 | int index_mask = 0; |
79e53945 JB |
14103 | int entry = 0; |
14104 | ||
b2784e15 | 14105 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14106 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14107 | index_mask |= (1 << entry); |
14108 | ||
79e53945 JB |
14109 | entry++; |
14110 | } | |
4ef69c7a | 14111 | |
79e53945 JB |
14112 | return index_mask; |
14113 | } | |
14114 | ||
4d302442 CW |
14115 | static bool has_edp_a(struct drm_device *dev) |
14116 | { | |
14117 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14118 | ||
14119 | if (!IS_MOBILE(dev)) | |
14120 | return false; | |
14121 | ||
14122 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14123 | return false; | |
14124 | ||
e3589908 | 14125 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14126 | return false; |
14127 | ||
14128 | return true; | |
14129 | } | |
14130 | ||
84b4e042 JB |
14131 | static bool intel_crt_present(struct drm_device *dev) |
14132 | { | |
14133 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14134 | ||
884497ed DL |
14135 | if (INTEL_INFO(dev)->gen >= 9) |
14136 | return false; | |
14137 | ||
cf404ce4 | 14138 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14139 | return false; |
14140 | ||
14141 | if (IS_CHERRYVIEW(dev)) | |
14142 | return false; | |
14143 | ||
14144 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
14145 | return false; | |
14146 | ||
14147 | return true; | |
14148 | } | |
14149 | ||
79e53945 JB |
14150 | static void intel_setup_outputs(struct drm_device *dev) |
14151 | { | |
725e30ad | 14152 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14153 | struct intel_encoder *encoder; |
cb0953d7 | 14154 | bool dpd_is_edp = false; |
79e53945 | 14155 | |
c9093354 | 14156 | intel_lvds_init(dev); |
79e53945 | 14157 | |
84b4e042 | 14158 | if (intel_crt_present(dev)) |
79935fca | 14159 | intel_crt_init(dev); |
cb0953d7 | 14160 | |
c776eb2e VK |
14161 | if (IS_BROXTON(dev)) { |
14162 | /* | |
14163 | * FIXME: Broxton doesn't support port detection via the | |
14164 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14165 | * detect the ports. | |
14166 | */ | |
14167 | intel_ddi_init(dev, PORT_A); | |
14168 | intel_ddi_init(dev, PORT_B); | |
14169 | intel_ddi_init(dev, PORT_C); | |
14170 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14171 | int found; |
14172 | ||
de31facd JB |
14173 | /* |
14174 | * Haswell uses DDI functions to detect digital outputs. | |
14175 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14176 | * it's there. | |
14177 | */ | |
77179400 | 14178 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14179 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14180 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14181 | intel_ddi_init(dev, PORT_A); |
14182 | ||
14183 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14184 | * register */ | |
14185 | found = I915_READ(SFUSE_STRAP); | |
14186 | ||
14187 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14188 | intel_ddi_init(dev, PORT_B); | |
14189 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14190 | intel_ddi_init(dev, PORT_C); | |
14191 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14192 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14193 | /* |
14194 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14195 | */ | |
ef11bdb3 | 14196 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14197 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14198 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14199 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14200 | intel_ddi_init(dev, PORT_E); | |
14201 | ||
0e72a5b5 | 14202 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14203 | int found; |
5d8a7752 | 14204 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14205 | |
14206 | if (has_edp_a(dev)) | |
14207 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14208 | |
dc0fa718 | 14209 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14210 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 14211 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 14212 | if (!found) |
e2debe91 | 14213 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14214 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14215 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14216 | } |
14217 | ||
dc0fa718 | 14218 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14219 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14220 | |
dc0fa718 | 14221 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14222 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14223 | |
5eb08b69 | 14224 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14225 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14226 | |
270b3042 | 14227 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14228 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14229 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14230 | /* |
14231 | * The DP_DETECTED bit is the latched state of the DDC | |
14232 | * SDA pin at boot. However since eDP doesn't require DDC | |
14233 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14234 | * eDP ports may have been muxed to an alternate function. | |
14235 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14236 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14237 | * detect eDP ports. | |
14238 | */ | |
e66eb81d | 14239 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
d2182a66 | 14240 | !intel_dp_is_edp(dev, PORT_B)) |
e66eb81d VS |
14241 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
14242 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
e17ac6db | 14243 | intel_dp_is_edp(dev, PORT_B)) |
e66eb81d | 14244 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
585a94b8 | 14245 | |
e66eb81d | 14246 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
d2182a66 | 14247 | !intel_dp_is_edp(dev, PORT_C)) |
e66eb81d VS |
14248 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
14249 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
e17ac6db | 14250 | intel_dp_is_edp(dev, PORT_C)) |
e66eb81d | 14251 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
19c03924 | 14252 | |
9418c1f1 | 14253 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14254 | /* eDP not supported on port D, so don't check VBT */ |
e66eb81d VS |
14255 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
14256 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14257 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14258 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
9418c1f1 VS |
14259 | } |
14260 | ||
3cfca973 | 14261 | intel_dsi_init(dev); |
09da55dc | 14262 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14263 | bool found = false; |
7d57382e | 14264 | |
e2debe91 | 14265 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14266 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 14267 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
3fec3d2f | 14268 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14269 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14270 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14271 | } |
27185ae1 | 14272 | |
3fec3d2f | 14273 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14274 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14275 | } |
13520b05 KH |
14276 | |
14277 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14278 | |
e2debe91 | 14279 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14280 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 14281 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 14282 | } |
27185ae1 | 14283 | |
e2debe91 | 14284 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14285 | |
3fec3d2f | 14286 | if (IS_G4X(dev)) { |
b01f2c3a | 14287 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14288 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14289 | } |
3fec3d2f | 14290 | if (IS_G4X(dev)) |
ab9d7c30 | 14291 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14292 | } |
27185ae1 | 14293 | |
3fec3d2f | 14294 | if (IS_G4X(dev) && |
e7281eab | 14295 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14296 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14297 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14298 | intel_dvo_init(dev); |
14299 | ||
103a196f | 14300 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14301 | intel_tv_init(dev); |
14302 | ||
0bc12bcb | 14303 | intel_psr_init(dev); |
7c8f8a70 | 14304 | |
b2784e15 | 14305 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14306 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14307 | encoder->base.possible_clones = | |
66a9278e | 14308 | intel_encoder_clones(encoder); |
79e53945 | 14309 | } |
47356eb6 | 14310 | |
dde86e2d | 14311 | intel_init_pch_refclk(dev); |
270b3042 DV |
14312 | |
14313 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14314 | } |
14315 | ||
14316 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14317 | { | |
60a5ca01 | 14318 | struct drm_device *dev = fb->dev; |
79e53945 | 14319 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14320 | |
ef2d633e | 14321 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14322 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14323 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14324 | drm_gem_object_unreference(&intel_fb->obj->base); |
14325 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14326 | kfree(intel_fb); |
14327 | } | |
14328 | ||
14329 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14330 | struct drm_file *file, |
79e53945 JB |
14331 | unsigned int *handle) |
14332 | { | |
14333 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14334 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14335 | |
05394f39 | 14336 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14337 | } |
14338 | ||
86c98588 RV |
14339 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14340 | struct drm_file *file, | |
14341 | unsigned flags, unsigned color, | |
14342 | struct drm_clip_rect *clips, | |
14343 | unsigned num_clips) | |
14344 | { | |
14345 | struct drm_device *dev = fb->dev; | |
14346 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14347 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14348 | ||
14349 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14350 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14351 | mutex_unlock(&dev->struct_mutex); |
14352 | ||
14353 | return 0; | |
14354 | } | |
14355 | ||
79e53945 JB |
14356 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14357 | .destroy = intel_user_framebuffer_destroy, | |
14358 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14359 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14360 | }; |
14361 | ||
b321803d DL |
14362 | static |
14363 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14364 | uint32_t pixel_format) | |
14365 | { | |
14366 | u32 gen = INTEL_INFO(dev)->gen; | |
14367 | ||
14368 | if (gen >= 9) { | |
14369 | /* "The stride in bytes must not exceed the of the size of 8K | |
14370 | * pixels and 32K bytes." | |
14371 | */ | |
14372 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14373 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14374 | return 32*1024; | |
14375 | } else if (gen >= 4) { | |
14376 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14377 | return 16*1024; | |
14378 | else | |
14379 | return 32*1024; | |
14380 | } else if (gen >= 3) { | |
14381 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14382 | return 8*1024; | |
14383 | else | |
14384 | return 16*1024; | |
14385 | } else { | |
14386 | /* XXX DSPC is limited to 4k tiled */ | |
14387 | return 8*1024; | |
14388 | } | |
14389 | } | |
14390 | ||
b5ea642a DV |
14391 | static int intel_framebuffer_init(struct drm_device *dev, |
14392 | struct intel_framebuffer *intel_fb, | |
14393 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14394 | struct drm_i915_gem_object *obj) | |
79e53945 | 14395 | { |
6761dd31 | 14396 | unsigned int aligned_height; |
79e53945 | 14397 | int ret; |
b321803d | 14398 | u32 pitch_limit, stride_alignment; |
79e53945 | 14399 | |
dd4916c5 DV |
14400 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14401 | ||
2a80eada DV |
14402 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14403 | /* Enforce that fb modifier and tiling mode match, but only for | |
14404 | * X-tiled. This is needed for FBC. */ | |
14405 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14406 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14407 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14408 | return -EINVAL; | |
14409 | } | |
14410 | } else { | |
14411 | if (obj->tiling_mode == I915_TILING_X) | |
14412 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14413 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14414 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14415 | return -EINVAL; | |
14416 | } | |
14417 | } | |
14418 | ||
9a8f0a12 TU |
14419 | /* Passed in modifier sanity checking. */ |
14420 | switch (mode_cmd->modifier[0]) { | |
14421 | case I915_FORMAT_MOD_Y_TILED: | |
14422 | case I915_FORMAT_MOD_Yf_TILED: | |
14423 | if (INTEL_INFO(dev)->gen < 9) { | |
14424 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14425 | mode_cmd->modifier[0]); | |
14426 | return -EINVAL; | |
14427 | } | |
14428 | case DRM_FORMAT_MOD_NONE: | |
14429 | case I915_FORMAT_MOD_X_TILED: | |
14430 | break; | |
14431 | default: | |
c0f40428 JB |
14432 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14433 | mode_cmd->modifier[0]); | |
57cd6508 | 14434 | return -EINVAL; |
c16ed4be | 14435 | } |
57cd6508 | 14436 | |
b321803d DL |
14437 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14438 | mode_cmd->pixel_format); | |
14439 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14440 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14441 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14442 | return -EINVAL; |
c16ed4be | 14443 | } |
57cd6508 | 14444 | |
b321803d DL |
14445 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14446 | mode_cmd->pixel_format); | |
a35cdaa0 | 14447 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14448 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14449 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14450 | "tiled" : "linear", |
a35cdaa0 | 14451 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14452 | return -EINVAL; |
c16ed4be | 14453 | } |
5d7bd705 | 14454 | |
2a80eada | 14455 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14456 | mode_cmd->pitches[0] != obj->stride) { |
14457 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14458 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14459 | return -EINVAL; |
c16ed4be | 14460 | } |
5d7bd705 | 14461 | |
57779d06 | 14462 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14463 | switch (mode_cmd->pixel_format) { |
57779d06 | 14464 | case DRM_FORMAT_C8: |
04b3924d VS |
14465 | case DRM_FORMAT_RGB565: |
14466 | case DRM_FORMAT_XRGB8888: | |
14467 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14468 | break; |
14469 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14470 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14471 | DRM_DEBUG("unsupported pixel format: %s\n", |
14472 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14473 | return -EINVAL; |
c16ed4be | 14474 | } |
57779d06 | 14475 | break; |
57779d06 | 14476 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14477 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14478 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14479 | drm_get_format_name(mode_cmd->pixel_format)); | |
14480 | return -EINVAL; | |
14481 | } | |
14482 | break; | |
14483 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14484 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14485 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14486 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14487 | DRM_DEBUG("unsupported pixel format: %s\n", |
14488 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14489 | return -EINVAL; |
c16ed4be | 14490 | } |
b5626747 | 14491 | break; |
7531208b DL |
14492 | case DRM_FORMAT_ABGR2101010: |
14493 | if (!IS_VALLEYVIEW(dev)) { | |
14494 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14495 | drm_get_format_name(mode_cmd->pixel_format)); | |
14496 | return -EINVAL; | |
14497 | } | |
14498 | break; | |
04b3924d VS |
14499 | case DRM_FORMAT_YUYV: |
14500 | case DRM_FORMAT_UYVY: | |
14501 | case DRM_FORMAT_YVYU: | |
14502 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14503 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14504 | DRM_DEBUG("unsupported pixel format: %s\n", |
14505 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14506 | return -EINVAL; |
c16ed4be | 14507 | } |
57cd6508 CW |
14508 | break; |
14509 | default: | |
4ee62c76 VS |
14510 | DRM_DEBUG("unsupported pixel format: %s\n", |
14511 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14512 | return -EINVAL; |
14513 | } | |
14514 | ||
90f9a336 VS |
14515 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14516 | if (mode_cmd->offsets[0] != 0) | |
14517 | return -EINVAL; | |
14518 | ||
ec2c981e | 14519 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14520 | mode_cmd->pixel_format, |
14521 | mode_cmd->modifier[0]); | |
53155c0a DV |
14522 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14523 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14524 | return -EINVAL; | |
14525 | ||
c7d73f6a DV |
14526 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14527 | intel_fb->obj = obj; | |
80075d49 | 14528 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14529 | |
79e53945 JB |
14530 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14531 | if (ret) { | |
14532 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14533 | return ret; | |
14534 | } | |
14535 | ||
79e53945 JB |
14536 | return 0; |
14537 | } | |
14538 | ||
79e53945 JB |
14539 | static struct drm_framebuffer * |
14540 | intel_user_framebuffer_create(struct drm_device *dev, | |
14541 | struct drm_file *filp, | |
308e5bcb | 14542 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14543 | { |
dcb1394e | 14544 | struct drm_framebuffer *fb; |
05394f39 | 14545 | struct drm_i915_gem_object *obj; |
79e53945 | 14546 | |
308e5bcb JB |
14547 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14548 | mode_cmd->handles[0])); | |
c8725226 | 14549 | if (&obj->base == NULL) |
cce13ff7 | 14550 | return ERR_PTR(-ENOENT); |
79e53945 | 14551 | |
dcb1394e LW |
14552 | fb = intel_framebuffer_create(dev, mode_cmd, obj); |
14553 | if (IS_ERR(fb)) | |
14554 | drm_gem_object_unreference_unlocked(&obj->base); | |
14555 | ||
14556 | return fb; | |
79e53945 JB |
14557 | } |
14558 | ||
0695726e | 14559 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 14560 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14561 | { |
14562 | } | |
14563 | #endif | |
14564 | ||
79e53945 | 14565 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14566 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14567 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14568 | .atomic_check = intel_atomic_check, |
14569 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14570 | .atomic_state_alloc = intel_atomic_state_alloc, |
14571 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14572 | }; |
14573 | ||
e70236a8 JB |
14574 | /* Set up chip specific display functions */ |
14575 | static void intel_init_display(struct drm_device *dev) | |
14576 | { | |
14577 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14578 | ||
ee9300bb DV |
14579 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14580 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14581 | else if (IS_CHERRYVIEW(dev)) |
14582 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14583 | else if (IS_VALLEYVIEW(dev)) |
14584 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14585 | else if (IS_PINEVIEW(dev)) | |
14586 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14587 | else | |
14588 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14589 | ||
bc8d7dff DL |
14590 | if (INTEL_INFO(dev)->gen >= 9) { |
14591 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14592 | dev_priv->display.get_initial_plane_config = |
14593 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14594 | dev_priv->display.crtc_compute_clock = |
14595 | haswell_crtc_compute_clock; | |
14596 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14597 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14598 | dev_priv->display.update_primary_plane = |
14599 | skylake_update_primary_plane; | |
14600 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14601 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14602 | dev_priv->display.get_initial_plane_config = |
14603 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14604 | dev_priv->display.crtc_compute_clock = |
14605 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14606 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14607 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14608 | dev_priv->display.update_primary_plane = |
14609 | ironlake_update_primary_plane; | |
09b4ddf9 | 14610 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14611 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14612 | dev_priv->display.get_initial_plane_config = |
14613 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14614 | dev_priv->display.crtc_compute_clock = |
14615 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14616 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14617 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14618 | dev_priv->display.update_primary_plane = |
14619 | ironlake_update_primary_plane; | |
89b667f8 JB |
14620 | } else if (IS_VALLEYVIEW(dev)) { |
14621 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14622 | dev_priv->display.get_initial_plane_config = |
14623 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14624 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14625 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14626 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14627 | dev_priv->display.update_primary_plane = |
14628 | i9xx_update_primary_plane; | |
f564048e | 14629 | } else { |
0e8ffe1b | 14630 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14631 | dev_priv->display.get_initial_plane_config = |
14632 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14633 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14634 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14635 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14636 | dev_priv->display.update_primary_plane = |
14637 | i9xx_update_primary_plane; | |
f564048e | 14638 | } |
e70236a8 | 14639 | |
e70236a8 | 14640 | /* Returns the core display clock speed */ |
ef11bdb3 | 14641 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
1652d19e VS |
14642 | dev_priv->display.get_display_clock_speed = |
14643 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
14644 | else if (IS_BROXTON(dev)) |
14645 | dev_priv->display.get_display_clock_speed = | |
14646 | broxton_get_display_clock_speed; | |
1652d19e VS |
14647 | else if (IS_BROADWELL(dev)) |
14648 | dev_priv->display.get_display_clock_speed = | |
14649 | broadwell_get_display_clock_speed; | |
14650 | else if (IS_HASWELL(dev)) | |
14651 | dev_priv->display.get_display_clock_speed = | |
14652 | haswell_get_display_clock_speed; | |
14653 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14654 | dev_priv->display.get_display_clock_speed = |
14655 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14656 | else if (IS_GEN5(dev)) |
14657 | dev_priv->display.get_display_clock_speed = | |
14658 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14659 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14660 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14661 | dev_priv->display.get_display_clock_speed = |
14662 | i945_get_display_clock_speed; | |
34edce2f VS |
14663 | else if (IS_GM45(dev)) |
14664 | dev_priv->display.get_display_clock_speed = | |
14665 | gm45_get_display_clock_speed; | |
14666 | else if (IS_CRESTLINE(dev)) | |
14667 | dev_priv->display.get_display_clock_speed = | |
14668 | i965gm_get_display_clock_speed; | |
14669 | else if (IS_PINEVIEW(dev)) | |
14670 | dev_priv->display.get_display_clock_speed = | |
14671 | pnv_get_display_clock_speed; | |
14672 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14673 | dev_priv->display.get_display_clock_speed = | |
14674 | g33_get_display_clock_speed; | |
e70236a8 JB |
14675 | else if (IS_I915G(dev)) |
14676 | dev_priv->display.get_display_clock_speed = | |
14677 | i915_get_display_clock_speed; | |
257a7ffc | 14678 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14679 | dev_priv->display.get_display_clock_speed = |
14680 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14681 | else if (IS_PINEVIEW(dev)) |
14682 | dev_priv->display.get_display_clock_speed = | |
14683 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14684 | else if (IS_I915GM(dev)) |
14685 | dev_priv->display.get_display_clock_speed = | |
14686 | i915gm_get_display_clock_speed; | |
14687 | else if (IS_I865G(dev)) | |
14688 | dev_priv->display.get_display_clock_speed = | |
14689 | i865_get_display_clock_speed; | |
f0f8a9ce | 14690 | else if (IS_I85X(dev)) |
e70236a8 | 14691 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14692 | i85x_get_display_clock_speed; |
623e01e5 VS |
14693 | else { /* 830 */ |
14694 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14695 | dev_priv->display.get_display_clock_speed = |
14696 | i830_get_display_clock_speed; | |
623e01e5 | 14697 | } |
e70236a8 | 14698 | |
7c10a2b5 | 14699 | if (IS_GEN5(dev)) { |
3bb11b53 | 14700 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14701 | } else if (IS_GEN6(dev)) { |
14702 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14703 | } else if (IS_IVYBRIDGE(dev)) { |
14704 | /* FIXME: detect B0+ stepping and use auto training */ | |
14705 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14706 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14707 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
14708 | if (IS_BROADWELL(dev)) { |
14709 | dev_priv->display.modeset_commit_cdclk = | |
14710 | broadwell_modeset_commit_cdclk; | |
14711 | dev_priv->display.modeset_calc_cdclk = | |
14712 | broadwell_modeset_calc_cdclk; | |
14713 | } | |
30a970c6 | 14714 | } else if (IS_VALLEYVIEW(dev)) { |
27c329ed ML |
14715 | dev_priv->display.modeset_commit_cdclk = |
14716 | valleyview_modeset_commit_cdclk; | |
14717 | dev_priv->display.modeset_calc_cdclk = | |
14718 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 14719 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
14720 | dev_priv->display.modeset_commit_cdclk = |
14721 | broxton_modeset_commit_cdclk; | |
14722 | dev_priv->display.modeset_calc_cdclk = | |
14723 | broxton_modeset_calc_cdclk; | |
e70236a8 | 14724 | } |
8c9f3aaf | 14725 | |
8c9f3aaf JB |
14726 | switch (INTEL_INFO(dev)->gen) { |
14727 | case 2: | |
14728 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14729 | break; | |
14730 | ||
14731 | case 3: | |
14732 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14733 | break; | |
14734 | ||
14735 | case 4: | |
14736 | case 5: | |
14737 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14738 | break; | |
14739 | ||
14740 | case 6: | |
14741 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14742 | break; | |
7c9017e5 | 14743 | case 7: |
4e0bbc31 | 14744 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14745 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14746 | break; | |
830c81db | 14747 | case 9: |
ba343e02 TU |
14748 | /* Drop through - unsupported since execlist only. */ |
14749 | default: | |
14750 | /* Default just returns -ENODEV to indicate unsupported */ | |
14751 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14752 | } |
7bd688cd | 14753 | |
e39b999a | 14754 | mutex_init(&dev_priv->pps_mutex); |
e70236a8 JB |
14755 | } |
14756 | ||
b690e96c JB |
14757 | /* |
14758 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14759 | * resume, or other times. This quirk makes sure that's the case for | |
14760 | * affected systems. | |
14761 | */ | |
0206e353 | 14762 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14763 | { |
14764 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14765 | ||
14766 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14767 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14768 | } |
14769 | ||
b6b5d049 VS |
14770 | static void quirk_pipeb_force(struct drm_device *dev) |
14771 | { | |
14772 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14773 | ||
14774 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14775 | DRM_INFO("applying pipe b force quirk\n"); | |
14776 | } | |
14777 | ||
435793df KP |
14778 | /* |
14779 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14780 | */ | |
14781 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14782 | { | |
14783 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14784 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14785 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14786 | } |
14787 | ||
4dca20ef | 14788 | /* |
5a15ab5b CE |
14789 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14790 | * brightness value | |
4dca20ef CE |
14791 | */ |
14792 | static void quirk_invert_brightness(struct drm_device *dev) | |
14793 | { | |
14794 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14795 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14796 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14797 | } |
14798 | ||
9c72cc6f SD |
14799 | /* Some VBT's incorrectly indicate no backlight is present */ |
14800 | static void quirk_backlight_present(struct drm_device *dev) | |
14801 | { | |
14802 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14803 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14804 | DRM_INFO("applying backlight present quirk\n"); | |
14805 | } | |
14806 | ||
b690e96c JB |
14807 | struct intel_quirk { |
14808 | int device; | |
14809 | int subsystem_vendor; | |
14810 | int subsystem_device; | |
14811 | void (*hook)(struct drm_device *dev); | |
14812 | }; | |
14813 | ||
5f85f176 EE |
14814 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14815 | struct intel_dmi_quirk { | |
14816 | void (*hook)(struct drm_device *dev); | |
14817 | const struct dmi_system_id (*dmi_id_list)[]; | |
14818 | }; | |
14819 | ||
14820 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14821 | { | |
14822 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14823 | return 1; | |
14824 | } | |
14825 | ||
14826 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14827 | { | |
14828 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14829 | { | |
14830 | .callback = intel_dmi_reverse_brightness, | |
14831 | .ident = "NCR Corporation", | |
14832 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14833 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14834 | }, | |
14835 | }, | |
14836 | { } /* terminating entry */ | |
14837 | }, | |
14838 | .hook = quirk_invert_brightness, | |
14839 | }, | |
14840 | }; | |
14841 | ||
c43b5634 | 14842 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14843 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14844 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14845 | ||
b690e96c JB |
14846 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14847 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14848 | ||
5f080c0f VS |
14849 | /* 830 needs to leave pipe A & dpll A up */ |
14850 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14851 | ||
b6b5d049 VS |
14852 | /* 830 needs to leave pipe B & dpll B up */ |
14853 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14854 | ||
435793df KP |
14855 | /* Lenovo U160 cannot use SSC on LVDS */ |
14856 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14857 | |
14858 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14859 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14860 | |
be505f64 AH |
14861 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14862 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14863 | ||
14864 | /* Acer/eMachines G725 */ | |
14865 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14866 | ||
14867 | /* Acer/eMachines e725 */ | |
14868 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14869 | ||
14870 | /* Acer/Packard Bell NCL20 */ | |
14871 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14872 | ||
14873 | /* Acer Aspire 4736Z */ | |
14874 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14875 | |
14876 | /* Acer Aspire 5336 */ | |
14877 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14878 | |
14879 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14880 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14881 | |
dfb3d47b SD |
14882 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14883 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14884 | ||
b2a9601c | 14885 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14886 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14887 | ||
d4967d8c SD |
14888 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14889 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14890 | |
14891 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14892 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14893 | |
14894 | /* Dell Chromebook 11 */ | |
14895 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
14896 | }; |
14897 | ||
14898 | static void intel_init_quirks(struct drm_device *dev) | |
14899 | { | |
14900 | struct pci_dev *d = dev->pdev; | |
14901 | int i; | |
14902 | ||
14903 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14904 | struct intel_quirk *q = &intel_quirks[i]; | |
14905 | ||
14906 | if (d->device == q->device && | |
14907 | (d->subsystem_vendor == q->subsystem_vendor || | |
14908 | q->subsystem_vendor == PCI_ANY_ID) && | |
14909 | (d->subsystem_device == q->subsystem_device || | |
14910 | q->subsystem_device == PCI_ANY_ID)) | |
14911 | q->hook(dev); | |
14912 | } | |
5f85f176 EE |
14913 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14914 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14915 | intel_dmi_quirks[i].hook(dev); | |
14916 | } | |
b690e96c JB |
14917 | } |
14918 | ||
9cce37f4 JB |
14919 | /* Disable the VGA plane that we never use */ |
14920 | static void i915_disable_vga(struct drm_device *dev) | |
14921 | { | |
14922 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14923 | u8 sr1; | |
766aa1c4 | 14924 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 14925 | |
2b37c616 | 14926 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 14927 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 14928 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
14929 | sr1 = inb(VGA_SR_DATA); |
14930 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
14931 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
14932 | udelay(300); | |
14933 | ||
01f5a626 | 14934 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
14935 | POSTING_READ(vga_reg); |
14936 | } | |
14937 | ||
f817586c DV |
14938 | void intel_modeset_init_hw(struct drm_device *dev) |
14939 | { | |
b6283055 | 14940 | intel_update_cdclk(dev); |
a8f78b58 | 14941 | intel_prepare_ddi(dev); |
f817586c | 14942 | intel_init_clock_gating(dev); |
8090c6b9 | 14943 | intel_enable_gt_powersave(dev); |
f817586c DV |
14944 | } |
14945 | ||
79e53945 JB |
14946 | void intel_modeset_init(struct drm_device *dev) |
14947 | { | |
652c393a | 14948 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 14949 | int sprite, ret; |
8cc87b75 | 14950 | enum pipe pipe; |
46f297fb | 14951 | struct intel_crtc *crtc; |
79e53945 JB |
14952 | |
14953 | drm_mode_config_init(dev); | |
14954 | ||
14955 | dev->mode_config.min_width = 0; | |
14956 | dev->mode_config.min_height = 0; | |
14957 | ||
019d96cb DA |
14958 | dev->mode_config.preferred_depth = 24; |
14959 | dev->mode_config.prefer_shadow = 1; | |
14960 | ||
25bab385 TU |
14961 | dev->mode_config.allow_fb_modifiers = true; |
14962 | ||
e6ecefaa | 14963 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 14964 | |
b690e96c JB |
14965 | intel_init_quirks(dev); |
14966 | ||
1fa61106 ED |
14967 | intel_init_pm(dev); |
14968 | ||
e3c74757 BW |
14969 | if (INTEL_INFO(dev)->num_pipes == 0) |
14970 | return; | |
14971 | ||
69f92f67 LW |
14972 | /* |
14973 | * There may be no VBT; and if the BIOS enabled SSC we can | |
14974 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
14975 | * BIOS isn't using it, don't assume it will work even if the VBT | |
14976 | * indicates as much. | |
14977 | */ | |
14978 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
14979 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
14980 | DREF_SSC1_ENABLE); | |
14981 | ||
14982 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
14983 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
14984 | bios_lvds_use_ssc ? "en" : "dis", | |
14985 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
14986 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
14987 | } | |
14988 | } | |
14989 | ||
e70236a8 | 14990 | intel_init_display(dev); |
7c10a2b5 | 14991 | intel_init_audio(dev); |
e70236a8 | 14992 | |
a6c45cf0 CW |
14993 | if (IS_GEN2(dev)) { |
14994 | dev->mode_config.max_width = 2048; | |
14995 | dev->mode_config.max_height = 2048; | |
14996 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
14997 | dev->mode_config.max_width = 4096; |
14998 | dev->mode_config.max_height = 4096; | |
79e53945 | 14999 | } else { |
a6c45cf0 CW |
15000 | dev->mode_config.max_width = 8192; |
15001 | dev->mode_config.max_height = 8192; | |
79e53945 | 15002 | } |
068be561 | 15003 | |
dc41c154 VS |
15004 | if (IS_845G(dev) || IS_I865G(dev)) { |
15005 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15006 | dev->mode_config.cursor_height = 1023; | |
15007 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15008 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15009 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15010 | } else { | |
15011 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15012 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15013 | } | |
15014 | ||
5d4545ae | 15015 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15016 | |
28c97730 | 15017 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15018 | INTEL_INFO(dev)->num_pipes, |
15019 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15020 | |
055e393f | 15021 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15022 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15023 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15024 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15025 | if (ret) |
06da8da2 | 15026 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15027 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15028 | } |
79e53945 JB |
15029 | } |
15030 | ||
bfa7df01 VS |
15031 | intel_update_czclk(dev_priv); |
15032 | intel_update_cdclk(dev); | |
15033 | ||
e72f9fbf | 15034 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15035 | |
9cce37f4 JB |
15036 | /* Just disable it once at startup */ |
15037 | i915_disable_vga(dev); | |
79e53945 | 15038 | intel_setup_outputs(dev); |
11be49eb | 15039 | |
6e9f798d | 15040 | drm_modeset_lock_all(dev); |
043e9bda | 15041 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15042 | drm_modeset_unlock_all(dev); |
46f297fb | 15043 | |
d3fcc808 | 15044 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15045 | struct intel_initial_plane_config plane_config = {}; |
15046 | ||
46f297fb JB |
15047 | if (!crtc->active) |
15048 | continue; | |
15049 | ||
46f297fb | 15050 | /* |
46f297fb JB |
15051 | * Note that reserving the BIOS fb up front prevents us |
15052 | * from stuffing other stolen allocations like the ring | |
15053 | * on top. This prevents some ugliness at boot time, and | |
15054 | * can even allow for smooth boot transitions if the BIOS | |
15055 | * fb is large enough for the active pipe configuration. | |
15056 | */ | |
eeebeac5 ML |
15057 | dev_priv->display.get_initial_plane_config(crtc, |
15058 | &plane_config); | |
15059 | ||
15060 | /* | |
15061 | * If the fb is shared between multiple heads, we'll | |
15062 | * just get the first one. | |
15063 | */ | |
15064 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15065 | } |
2c7111db CW |
15066 | } |
15067 | ||
7fad798e DV |
15068 | static void intel_enable_pipe_a(struct drm_device *dev) |
15069 | { | |
15070 | struct intel_connector *connector; | |
15071 | struct drm_connector *crt = NULL; | |
15072 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15073 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15074 | |
15075 | /* We can't just switch on the pipe A, we need to set things up with a | |
15076 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15077 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15078 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15079 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15080 | crt = &connector->base; | |
15081 | break; | |
15082 | } | |
15083 | } | |
15084 | ||
15085 | if (!crt) | |
15086 | return; | |
15087 | ||
208bf9fd | 15088 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15089 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15090 | } |
15091 | ||
fa555837 DV |
15092 | static bool |
15093 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15094 | { | |
7eb552ae BW |
15095 | struct drm_device *dev = crtc->base.dev; |
15096 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15097 | u32 val; |
fa555837 | 15098 | |
7eb552ae | 15099 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15100 | return true; |
15101 | ||
649636ef | 15102 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15103 | |
15104 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15105 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15106 | return false; | |
15107 | ||
15108 | return true; | |
15109 | } | |
15110 | ||
02e93c35 VS |
15111 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15112 | { | |
15113 | struct drm_device *dev = crtc->base.dev; | |
15114 | struct intel_encoder *encoder; | |
15115 | ||
15116 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15117 | return true; | |
15118 | ||
15119 | return false; | |
15120 | } | |
15121 | ||
24929352 DV |
15122 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15123 | { | |
15124 | struct drm_device *dev = crtc->base.dev; | |
15125 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 | 15126 | u32 reg; |
24929352 | 15127 | |
24929352 | 15128 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 15129 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
15130 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15131 | ||
d3eaf884 | 15132 | /* restore vblank interrupts to correct state */ |
9625604c | 15133 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15134 | if (crtc->active) { |
f9cd7b88 VS |
15135 | struct intel_plane *plane; |
15136 | ||
9625604c | 15137 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15138 | |
15139 | /* Disable everything but the primary plane */ | |
15140 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15141 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15142 | continue; | |
15143 | ||
15144 | plane->disable_plane(&plane->base, &crtc->base); | |
15145 | } | |
9625604c | 15146 | } |
d3eaf884 | 15147 | |
24929352 | 15148 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15149 | * disable the crtc (and hence change the state) if it is wrong. Note |
15150 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15151 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15152 | bool plane; |
15153 | ||
24929352 DV |
15154 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15155 | crtc->base.base.id); | |
15156 | ||
15157 | /* Pipe has the wrong plane attached and the plane is active. | |
15158 | * Temporarily change the plane mapping and disable everything | |
15159 | * ... */ | |
15160 | plane = crtc->plane; | |
b70709a6 | 15161 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15162 | crtc->plane = !plane; |
b17d48e2 | 15163 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15164 | crtc->plane = plane; |
24929352 | 15165 | } |
24929352 | 15166 | |
7fad798e DV |
15167 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15168 | crtc->pipe == PIPE_A && !crtc->active) { | |
15169 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15170 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15171 | * call below we restore the pipe to the right state, but leave | |
15172 | * the required bits on. */ | |
15173 | intel_enable_pipe_a(dev); | |
15174 | } | |
15175 | ||
24929352 DV |
15176 | /* Adjust the state of the output pipe according to whether we |
15177 | * have active connectors/encoders. */ | |
02e93c35 | 15178 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15179 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15180 | |
53d9f4e9 | 15181 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 15182 | struct intel_encoder *encoder; |
24929352 DV |
15183 | |
15184 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15185 | * functions or because of calls to intel_crtc_disable_noatomic, |
15186 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15187 | * pipe A quirk. */ |
15188 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15189 | crtc->base.base.id, | |
83d65738 | 15190 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15191 | crtc->active ? "enabled" : "disabled"); |
15192 | ||
4be40c98 | 15193 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 15194 | crtc->base.state->active = crtc->active; |
24929352 DV |
15195 | crtc->base.enabled = crtc->active; |
15196 | ||
15197 | /* Because we only establish the connector -> encoder -> | |
15198 | * crtc links if something is active, this means the | |
15199 | * crtc is now deactivated. Break the links. connector | |
15200 | * -> encoder links are only establish when things are | |
15201 | * actually up, hence no need to break them. */ | |
15202 | WARN_ON(crtc->active); | |
15203 | ||
2d406bb0 | 15204 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 15205 | encoder->base.crtc = NULL; |
24929352 | 15206 | } |
c5ab3bc0 | 15207 | |
a3ed6aad | 15208 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15209 | /* |
15210 | * We start out with underrun reporting disabled to avoid races. | |
15211 | * For correct bookkeeping mark this on active crtcs. | |
15212 | * | |
c5ab3bc0 DV |
15213 | * Also on gmch platforms we dont have any hardware bits to |
15214 | * disable the underrun reporting. Which means we need to start | |
15215 | * out with underrun reporting disabled also on inactive pipes, | |
15216 | * since otherwise we'll complain about the garbage we read when | |
15217 | * e.g. coming up after runtime pm. | |
15218 | * | |
4cc31489 DV |
15219 | * No protection against concurrent access is required - at |
15220 | * worst a fifo underrun happens which also sets this to false. | |
15221 | */ | |
15222 | crtc->cpu_fifo_underrun_disabled = true; | |
15223 | crtc->pch_fifo_underrun_disabled = true; | |
15224 | } | |
24929352 DV |
15225 | } |
15226 | ||
15227 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15228 | { | |
15229 | struct intel_connector *connector; | |
15230 | struct drm_device *dev = encoder->base.dev; | |
873ffe69 | 15231 | bool active = false; |
24929352 DV |
15232 | |
15233 | /* We need to check both for a crtc link (meaning that the | |
15234 | * encoder is active and trying to read from a pipe) and the | |
15235 | * pipe itself being active. */ | |
15236 | bool has_active_crtc = encoder->base.crtc && | |
15237 | to_intel_crtc(encoder->base.crtc)->active; | |
15238 | ||
873ffe69 ML |
15239 | for_each_intel_connector(dev, connector) { |
15240 | if (connector->base.encoder != &encoder->base) | |
15241 | continue; | |
15242 | ||
15243 | active = true; | |
15244 | break; | |
15245 | } | |
15246 | ||
15247 | if (active && !has_active_crtc) { | |
24929352 DV |
15248 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15249 | encoder->base.base.id, | |
8e329a03 | 15250 | encoder->base.name); |
24929352 DV |
15251 | |
15252 | /* Connector is active, but has no active pipe. This is | |
15253 | * fallout from our resume register restoring. Disable | |
15254 | * the encoder manually again. */ | |
15255 | if (encoder->base.crtc) { | |
15256 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15257 | encoder->base.base.id, | |
8e329a03 | 15258 | encoder->base.name); |
24929352 | 15259 | encoder->disable(encoder); |
a62d1497 VS |
15260 | if (encoder->post_disable) |
15261 | encoder->post_disable(encoder); | |
24929352 | 15262 | } |
7f1950fb | 15263 | encoder->base.crtc = NULL; |
24929352 DV |
15264 | |
15265 | /* Inconsistent output/port/pipe state happens presumably due to | |
15266 | * a bug in one of the get_hw_state functions. Or someplace else | |
15267 | * in our code, like the register restore mess on resume. Clamp | |
15268 | * things to off as a safer default. */ | |
3a3371ff | 15269 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15270 | if (connector->encoder != encoder) |
15271 | continue; | |
7f1950fb EE |
15272 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15273 | connector->base.encoder = NULL; | |
24929352 DV |
15274 | } |
15275 | } | |
15276 | /* Enabled encoders without active connectors will be fixed in | |
15277 | * the crtc fixup. */ | |
15278 | } | |
15279 | ||
04098753 | 15280 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15281 | { |
15282 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 15283 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15284 | |
04098753 ID |
15285 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15286 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15287 | i915_disable_vga(dev); | |
15288 | } | |
15289 | } | |
15290 | ||
15291 | void i915_redisable_vga(struct drm_device *dev) | |
15292 | { | |
15293 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15294 | ||
8dc8a27c PZ |
15295 | /* This function can be called both from intel_modeset_setup_hw_state or |
15296 | * at a very early point in our resume sequence, where the power well | |
15297 | * structures are not yet restored. Since this function is at a very | |
15298 | * paranoid "someone might have enabled VGA while we were not looking" | |
15299 | * level, just check if the power well is enabled instead of trying to | |
15300 | * follow the "don't touch the power well if we don't need it" policy | |
15301 | * the rest of the driver uses. */ | |
f458ebbc | 15302 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15303 | return; |
15304 | ||
04098753 | 15305 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15306 | } |
15307 | ||
f9cd7b88 | 15308 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15309 | { |
f9cd7b88 | 15310 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15311 | |
f9cd7b88 | 15312 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15313 | } |
15314 | ||
f9cd7b88 VS |
15315 | /* FIXME read out full plane state for all planes */ |
15316 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15317 | { |
b26d3ea3 | 15318 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15319 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15320 | to_intel_plane_state(primary->state); |
d032ffa0 | 15321 | |
19b8d387 | 15322 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
15323 | primary_get_hw_state(to_intel_plane(primary)); |
15324 | ||
15325 | if (plane_state->visible) | |
15326 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
15327 | } |
15328 | ||
30e984df | 15329 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15330 | { |
15331 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15332 | enum pipe pipe; | |
24929352 DV |
15333 | struct intel_crtc *crtc; |
15334 | struct intel_encoder *encoder; | |
15335 | struct intel_connector *connector; | |
5358901f | 15336 | int i; |
24929352 | 15337 | |
d3fcc808 | 15338 | for_each_intel_crtc(dev, crtc) { |
b06f8b0d | 15339 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
6e3c9717 | 15340 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15341 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15342 | |
0e8ffe1b | 15343 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15344 | crtc->config); |
24929352 | 15345 | |
49d6fa21 | 15346 | crtc->base.state->active = crtc->active; |
24929352 | 15347 | crtc->base.enabled = crtc->active; |
b70709a6 | 15348 | |
f9cd7b88 | 15349 | readout_plane_state(crtc); |
24929352 DV |
15350 | |
15351 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15352 | crtc->base.base.id, | |
15353 | crtc->active ? "enabled" : "disabled"); | |
15354 | } | |
15355 | ||
5358901f DV |
15356 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15357 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15358 | ||
3e369b76 ACO |
15359 | pll->on = pll->get_hw_state(dev_priv, pll, |
15360 | &pll->config.hw_state); | |
5358901f | 15361 | pll->active = 0; |
3e369b76 | 15362 | pll->config.crtc_mask = 0; |
d3fcc808 | 15363 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15364 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15365 | pll->active++; |
3e369b76 | 15366 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15367 | } |
5358901f | 15368 | } |
5358901f | 15369 | |
1e6f2ddc | 15370 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15371 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15372 | |
3e369b76 | 15373 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15374 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15375 | } |
15376 | ||
b2784e15 | 15377 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15378 | pipe = 0; |
15379 | ||
15380 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15381 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15382 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15383 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15384 | } else { |
15385 | encoder->base.crtc = NULL; | |
15386 | } | |
15387 | ||
6f2bcceb | 15388 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15389 | encoder->base.base.id, |
8e329a03 | 15390 | encoder->base.name, |
24929352 | 15391 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15392 | pipe_name(pipe)); |
24929352 DV |
15393 | } |
15394 | ||
3a3371ff | 15395 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15396 | if (connector->get_hw_state(connector)) { |
15397 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
24929352 DV |
15398 | connector->base.encoder = &connector->encoder->base; |
15399 | } else { | |
15400 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15401 | connector->base.encoder = NULL; | |
15402 | } | |
15403 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15404 | connector->base.base.id, | |
c23cc417 | 15405 | connector->base.name, |
24929352 DV |
15406 | connector->base.encoder ? "enabled" : "disabled"); |
15407 | } | |
7f4c6284 VS |
15408 | |
15409 | for_each_intel_crtc(dev, crtc) { | |
15410 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
15411 | ||
15412 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
15413 | if (crtc->base.state->active) { | |
15414 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
15415 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
15416 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
15417 | ||
15418 | /* | |
15419 | * The initial mode needs to be set in order to keep | |
15420 | * the atomic core happy. It wants a valid mode if the | |
15421 | * crtc's enabled, so we do the above call. | |
15422 | * | |
15423 | * At this point some state updated by the connectors | |
15424 | * in their ->detect() callback has not run yet, so | |
15425 | * no recalculation can be done yet. | |
15426 | * | |
15427 | * Even if we could do a recalculation and modeset | |
15428 | * right now it would cause a double modeset if | |
15429 | * fbdev or userspace chooses a different initial mode. | |
15430 | * | |
15431 | * If that happens, someone indicated they wanted a | |
15432 | * mode change, which means it's safe to do a full | |
15433 | * recalculation. | |
15434 | */ | |
15435 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
15436 | |
15437 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
15438 | update_scanline_offset(crtc); | |
7f4c6284 VS |
15439 | } |
15440 | } | |
30e984df DV |
15441 | } |
15442 | ||
043e9bda ML |
15443 | /* Scan out the current hw modeset state, |
15444 | * and sanitizes it to the current state | |
15445 | */ | |
15446 | static void | |
15447 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
15448 | { |
15449 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15450 | enum pipe pipe; | |
30e984df DV |
15451 | struct intel_crtc *crtc; |
15452 | struct intel_encoder *encoder; | |
35c95375 | 15453 | int i; |
30e984df DV |
15454 | |
15455 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
15456 | |
15457 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 15458 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15459 | intel_sanitize_encoder(encoder); |
15460 | } | |
15461 | ||
055e393f | 15462 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15463 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15464 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15465 | intel_dump_pipe_config(crtc, crtc->config, |
15466 | "[setup_hw_state]"); | |
24929352 | 15467 | } |
9a935856 | 15468 | |
d29b2f9d ACO |
15469 | intel_modeset_update_connector_atomic_state(dev); |
15470 | ||
35c95375 DV |
15471 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15472 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15473 | ||
15474 | if (!pll->on || pll->active) | |
15475 | continue; | |
15476 | ||
15477 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15478 | ||
15479 | pll->disable(dev_priv, pll); | |
15480 | pll->on = false; | |
15481 | } | |
15482 | ||
26e1fe4f | 15483 | if (IS_VALLEYVIEW(dev)) |
6eb1a681 VS |
15484 | vlv_wm_get_hw_state(dev); |
15485 | else if (IS_GEN9(dev)) | |
3078999f PB |
15486 | skl_wm_get_hw_state(dev); |
15487 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 15488 | ilk_wm_get_hw_state(dev); |
292b990e ML |
15489 | |
15490 | for_each_intel_crtc(dev, crtc) { | |
15491 | unsigned long put_domains; | |
15492 | ||
15493 | put_domains = modeset_get_crtc_power_domains(&crtc->base); | |
15494 | if (WARN_ON(put_domains)) | |
15495 | modeset_put_power_domains(dev_priv, put_domains); | |
15496 | } | |
15497 | intel_display_set_init_power(dev_priv, false); | |
043e9bda | 15498 | } |
7d0bc1ea | 15499 | |
043e9bda ML |
15500 | void intel_display_resume(struct drm_device *dev) |
15501 | { | |
15502 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); | |
15503 | struct intel_connector *conn; | |
15504 | struct intel_plane *plane; | |
15505 | struct drm_crtc *crtc; | |
15506 | int ret; | |
f30da187 | 15507 | |
043e9bda ML |
15508 | if (!state) |
15509 | return; | |
15510 | ||
15511 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
15512 | ||
15513 | /* preserve complete old state, including dpll */ | |
15514 | intel_atomic_get_shared_dpll_state(state); | |
15515 | ||
15516 | for_each_crtc(dev, crtc) { | |
15517 | struct drm_crtc_state *crtc_state = | |
15518 | drm_atomic_get_crtc_state(state, crtc); | |
15519 | ||
15520 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
15521 | if (ret) | |
15522 | goto err; | |
15523 | ||
15524 | /* force a restore */ | |
15525 | crtc_state->mode_changed = true; | |
45e2b5f6 | 15526 | } |
8af6cf88 | 15527 | |
043e9bda ML |
15528 | for_each_intel_plane(dev, plane) { |
15529 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); | |
15530 | if (ret) | |
15531 | goto err; | |
15532 | } | |
15533 | ||
15534 | for_each_intel_connector(dev, conn) { | |
15535 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); | |
15536 | if (ret) | |
15537 | goto err; | |
15538 | } | |
15539 | ||
15540 | intel_modeset_setup_hw_state(dev); | |
15541 | ||
15542 | i915_redisable_vga(dev); | |
74c090b1 | 15543 | ret = drm_atomic_commit(state); |
043e9bda ML |
15544 | if (!ret) |
15545 | return; | |
15546 | ||
15547 | err: | |
15548 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
15549 | drm_atomic_state_free(state); | |
2c7111db CW |
15550 | } |
15551 | ||
15552 | void intel_modeset_gem_init(struct drm_device *dev) | |
15553 | { | |
484b41dd | 15554 | struct drm_crtc *c; |
2ff8fde1 | 15555 | struct drm_i915_gem_object *obj; |
e0d6149b | 15556 | int ret; |
484b41dd | 15557 | |
ae48434c ID |
15558 | mutex_lock(&dev->struct_mutex); |
15559 | intel_init_gt_powersave(dev); | |
15560 | mutex_unlock(&dev->struct_mutex); | |
15561 | ||
1833b134 | 15562 | intel_modeset_init_hw(dev); |
02e792fb DV |
15563 | |
15564 | intel_setup_overlay(dev); | |
484b41dd JB |
15565 | |
15566 | /* | |
15567 | * Make sure any fbs we allocated at startup are properly | |
15568 | * pinned & fenced. When we do the allocation it's too early | |
15569 | * for this. | |
15570 | */ | |
70e1e0ec | 15571 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15572 | obj = intel_fb_obj(c->primary->fb); |
15573 | if (obj == NULL) | |
484b41dd JB |
15574 | continue; |
15575 | ||
e0d6149b TU |
15576 | mutex_lock(&dev->struct_mutex); |
15577 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15578 | c->primary->fb, | |
7580d774 | 15579 | c->primary->state); |
e0d6149b TU |
15580 | mutex_unlock(&dev->struct_mutex); |
15581 | if (ret) { | |
484b41dd JB |
15582 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15583 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15584 | drm_framebuffer_unreference(c->primary->fb); |
15585 | c->primary->fb = NULL; | |
36750f28 | 15586 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15587 | update_state_fb(c->primary); |
36750f28 | 15588 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15589 | } |
15590 | } | |
0962c3c9 VS |
15591 | |
15592 | intel_backlight_register(dev); | |
79e53945 JB |
15593 | } |
15594 | ||
4932e2c3 ID |
15595 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15596 | { | |
15597 | struct drm_connector *connector = &intel_connector->base; | |
15598 | ||
15599 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15600 | drm_connector_unregister(connector); |
4932e2c3 ID |
15601 | } |
15602 | ||
79e53945 JB |
15603 | void intel_modeset_cleanup(struct drm_device *dev) |
15604 | { | |
652c393a | 15605 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15606 | struct drm_connector *connector; |
652c393a | 15607 | |
2eb5252e ID |
15608 | intel_disable_gt_powersave(dev); |
15609 | ||
0962c3c9 VS |
15610 | intel_backlight_unregister(dev); |
15611 | ||
fd0c0642 DV |
15612 | /* |
15613 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15614 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15615 | * experience fancy races otherwise. |
15616 | */ | |
2aeb7d3a | 15617 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15618 | |
fd0c0642 DV |
15619 | /* |
15620 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15621 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15622 | */ | |
f87ea761 | 15623 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15624 | |
723bfd70 JB |
15625 | intel_unregister_dsm_handler(); |
15626 | ||
7733b49b | 15627 | intel_fbc_disable(dev_priv); |
69341a5e | 15628 | |
1630fe75 CW |
15629 | /* flush any delayed tasks or pending work */ |
15630 | flush_scheduled_work(); | |
15631 | ||
db31af1d JN |
15632 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15633 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15634 | struct intel_connector *intel_connector; |
15635 | ||
15636 | intel_connector = to_intel_connector(connector); | |
15637 | intel_connector->unregister(intel_connector); | |
db31af1d | 15638 | } |
d9255d57 | 15639 | |
79e53945 | 15640 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15641 | |
15642 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15643 | |
15644 | mutex_lock(&dev->struct_mutex); | |
15645 | intel_cleanup_gt_powersave(dev); | |
15646 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15647 | } |
15648 | ||
f1c79df3 ZW |
15649 | /* |
15650 | * Return which encoder is currently attached for connector. | |
15651 | */ | |
df0e9248 | 15652 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15653 | { |
df0e9248 CW |
15654 | return &intel_attached_encoder(connector)->base; |
15655 | } | |
f1c79df3 | 15656 | |
df0e9248 CW |
15657 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15658 | struct intel_encoder *encoder) | |
15659 | { | |
15660 | connector->encoder = encoder; | |
15661 | drm_mode_connector_attach_encoder(&connector->base, | |
15662 | &encoder->base); | |
79e53945 | 15663 | } |
28d52043 DA |
15664 | |
15665 | /* | |
15666 | * set vga decode state - true == enable VGA decode | |
15667 | */ | |
15668 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15669 | { | |
15670 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15671 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15672 | u16 gmch_ctrl; |
15673 | ||
75fa041d CW |
15674 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15675 | DRM_ERROR("failed to read control word\n"); | |
15676 | return -EIO; | |
15677 | } | |
15678 | ||
c0cc8a55 CW |
15679 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15680 | return 0; | |
15681 | ||
28d52043 DA |
15682 | if (state) |
15683 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15684 | else | |
15685 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15686 | |
15687 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15688 | DRM_ERROR("failed to write control word\n"); | |
15689 | return -EIO; | |
15690 | } | |
15691 | ||
28d52043 DA |
15692 | return 0; |
15693 | } | |
c4a1d9e4 | 15694 | |
c4a1d9e4 | 15695 | struct intel_display_error_state { |
ff57f1b0 PZ |
15696 | |
15697 | u32 power_well_driver; | |
15698 | ||
63b66e5b CW |
15699 | int num_transcoders; |
15700 | ||
c4a1d9e4 CW |
15701 | struct intel_cursor_error_state { |
15702 | u32 control; | |
15703 | u32 position; | |
15704 | u32 base; | |
15705 | u32 size; | |
52331309 | 15706 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15707 | |
15708 | struct intel_pipe_error_state { | |
ddf9c536 | 15709 | bool power_domain_on; |
c4a1d9e4 | 15710 | u32 source; |
f301b1e1 | 15711 | u32 stat; |
52331309 | 15712 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15713 | |
15714 | struct intel_plane_error_state { | |
15715 | u32 control; | |
15716 | u32 stride; | |
15717 | u32 size; | |
15718 | u32 pos; | |
15719 | u32 addr; | |
15720 | u32 surface; | |
15721 | u32 tile_offset; | |
52331309 | 15722 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15723 | |
15724 | struct intel_transcoder_error_state { | |
ddf9c536 | 15725 | bool power_domain_on; |
63b66e5b CW |
15726 | enum transcoder cpu_transcoder; |
15727 | ||
15728 | u32 conf; | |
15729 | ||
15730 | u32 htotal; | |
15731 | u32 hblank; | |
15732 | u32 hsync; | |
15733 | u32 vtotal; | |
15734 | u32 vblank; | |
15735 | u32 vsync; | |
15736 | } transcoder[4]; | |
c4a1d9e4 CW |
15737 | }; |
15738 | ||
15739 | struct intel_display_error_state * | |
15740 | intel_display_capture_error_state(struct drm_device *dev) | |
15741 | { | |
fbee40df | 15742 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15743 | struct intel_display_error_state *error; |
63b66e5b CW |
15744 | int transcoders[] = { |
15745 | TRANSCODER_A, | |
15746 | TRANSCODER_B, | |
15747 | TRANSCODER_C, | |
15748 | TRANSCODER_EDP, | |
15749 | }; | |
c4a1d9e4 CW |
15750 | int i; |
15751 | ||
63b66e5b CW |
15752 | if (INTEL_INFO(dev)->num_pipes == 0) |
15753 | return NULL; | |
15754 | ||
9d1cb914 | 15755 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15756 | if (error == NULL) |
15757 | return NULL; | |
15758 | ||
190be112 | 15759 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15760 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15761 | ||
055e393f | 15762 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15763 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15764 | __intel_display_power_is_enabled(dev_priv, |
15765 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15766 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15767 | continue; |
15768 | ||
5efb3e28 VS |
15769 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15770 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15771 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15772 | |
15773 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15774 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15775 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15776 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15777 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15778 | } | |
ca291363 PZ |
15779 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15780 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15781 | if (INTEL_INFO(dev)->gen >= 4) { |
15782 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15783 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15784 | } | |
15785 | ||
c4a1d9e4 | 15786 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15787 | |
3abfce77 | 15788 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15789 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15790 | } |
15791 | ||
15792 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15793 | if (HAS_DDI(dev_priv->dev)) | |
15794 | error->num_transcoders++; /* Account for eDP. */ | |
15795 | ||
15796 | for (i = 0; i < error->num_transcoders; i++) { | |
15797 | enum transcoder cpu_transcoder = transcoders[i]; | |
15798 | ||
ddf9c536 | 15799 | error->transcoder[i].power_domain_on = |
f458ebbc | 15800 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15801 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15802 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15803 | continue; |
15804 | ||
63b66e5b CW |
15805 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15806 | ||
15807 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15808 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15809 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15810 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15811 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15812 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15813 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15814 | } |
15815 | ||
15816 | return error; | |
15817 | } | |
15818 | ||
edc3d884 MK |
15819 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15820 | ||
c4a1d9e4 | 15821 | void |
edc3d884 | 15822 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15823 | struct drm_device *dev, |
15824 | struct intel_display_error_state *error) | |
15825 | { | |
055e393f | 15826 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15827 | int i; |
15828 | ||
63b66e5b CW |
15829 | if (!error) |
15830 | return; | |
15831 | ||
edc3d884 | 15832 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15833 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15834 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15835 | error->power_well_driver); |
055e393f | 15836 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15837 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15838 | err_printf(m, " Power: %s\n", |
15839 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15840 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15841 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15842 | |
15843 | err_printf(m, "Plane [%d]:\n", i); | |
15844 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15845 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15846 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15847 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15848 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15849 | } |
4b71a570 | 15850 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15851 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15852 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15853 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15854 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15855 | } |
15856 | ||
edc3d884 MK |
15857 | err_printf(m, "Cursor [%d]:\n", i); |
15858 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15859 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15860 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15861 | } |
63b66e5b CW |
15862 | |
15863 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15864 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15865 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15866 | err_printf(m, " Power: %s\n", |
15867 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15868 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15869 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15870 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15871 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15872 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15873 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15874 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15875 | } | |
c4a1d9e4 | 15876 | } |
e2fcdaa9 VS |
15877 | |
15878 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
15879 | { | |
15880 | struct intel_crtc *crtc; | |
15881 | ||
15882 | for_each_intel_crtc(dev, crtc) { | |
15883 | struct intel_unpin_work *work; | |
e2fcdaa9 | 15884 | |
5e2d7afc | 15885 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15886 | |
15887 | work = crtc->unpin_work; | |
15888 | ||
15889 | if (work && work->event && | |
15890 | work->event->base.file_priv == file) { | |
15891 | kfree(work->event); | |
15892 | work->event = NULL; | |
15893 | } | |
15894 | ||
5e2d7afc | 15895 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15896 | } |
15897 | } |