]>
Commit | Line | Data |
---|---|---|
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 | ||
27 | #include <linux/dmi.h> | |
28 | #include <linux/module.h> | |
29 | #include <linux/input.h> | |
30 | #include <linux/i2c.h> | |
31 | #include <linux/kernel.h> | |
32 | #include <linux/slab.h> | |
33 | #include <linux/vgaarb.h> | |
34 | #include <drm/drm_edid.h> | |
35 | #include <drm/drmP.h> | |
36 | #include "intel_drv.h" | |
37 | #include <drm/i915_drm.h> | |
38 | #include "i915_drv.h" | |
39 | #include "i915_trace.h" | |
40 | #include <drm/drm_atomic.h> | |
41 | #include <drm/drm_atomic_helper.h> | |
42 | #include <drm/drm_dp_helper.h> | |
43 | #include <drm/drm_crtc_helper.h> | |
44 | #include <drm/drm_plane_helper.h> | |
45 | #include <drm/drm_rect.h> | |
46 | #include <linux/dma_remapping.h> | |
47 | #include <linux/reservation.h> | |
48 | #include <linux/dma-buf.h> | |
49 | ||
50 | /* Primary plane formats for gen <= 3 */ | |
51 | static const uint32_t i8xx_primary_formats[] = { | |
52 | DRM_FORMAT_C8, | |
53 | DRM_FORMAT_RGB565, | |
54 | DRM_FORMAT_XRGB1555, | |
55 | DRM_FORMAT_XRGB8888, | |
56 | }; | |
57 | ||
58 | /* Primary plane formats for gen >= 4 */ | |
59 | static const uint32_t i965_primary_formats[] = { | |
60 | DRM_FORMAT_C8, | |
61 | DRM_FORMAT_RGB565, | |
62 | DRM_FORMAT_XRGB8888, | |
63 | DRM_FORMAT_XBGR8888, | |
64 | DRM_FORMAT_XRGB2101010, | |
65 | DRM_FORMAT_XBGR2101010, | |
66 | }; | |
67 | ||
68 | static const uint32_t skl_primary_formats[] = { | |
69 | DRM_FORMAT_C8, | |
70 | DRM_FORMAT_RGB565, | |
71 | DRM_FORMAT_XRGB8888, | |
72 | DRM_FORMAT_XBGR8888, | |
73 | DRM_FORMAT_ARGB8888, | |
74 | DRM_FORMAT_ABGR8888, | |
75 | DRM_FORMAT_XRGB2101010, | |
76 | DRM_FORMAT_XBGR2101010, | |
77 | DRM_FORMAT_YUYV, | |
78 | DRM_FORMAT_YVYU, | |
79 | DRM_FORMAT_UYVY, | |
80 | DRM_FORMAT_VYUY, | |
81 | }; | |
82 | ||
83 | /* Cursor formats */ | |
84 | static const uint32_t intel_cursor_formats[] = { | |
85 | DRM_FORMAT_ARGB8888, | |
86 | }; | |
87 | ||
88 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, | |
89 | struct intel_crtc_state *pipe_config); | |
90 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, | |
91 | struct intel_crtc_state *pipe_config); | |
92 | ||
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); | |
97 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); | |
98 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
99 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
100 | struct intel_link_m_n *m_n, | |
101 | struct intel_link_m_n *m2_n2); | |
102 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); | |
103 | static void haswell_set_pipeconf(struct drm_crtc *crtc); | |
104 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
105 | static void vlv_prepare_pll(struct intel_crtc *crtc, | |
106 | const struct intel_crtc_state *pipe_config); | |
107 | static void chv_prepare_pll(struct intel_crtc *crtc, | |
108 | const struct intel_crtc_state *pipe_config); | |
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 *); | |
111 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, | |
112 | struct intel_crtc_state *crtc_state); | |
113 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, | |
114 | int num_connectors); | |
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); | |
118 | static void intel_modeset_setup_hw_state(struct drm_device *dev); | |
119 | static void intel_pre_disable_primary(struct drm_crtc *crtc); | |
120 | ||
121 | typedef struct { | |
122 | int min, max; | |
123 | } intel_range_t; | |
124 | ||
125 | typedef struct { | |
126 | int dot_limit; | |
127 | int p2_slow, p2_fast; | |
128 | } intel_p2_t; | |
129 | ||
130 | typedef struct intel_limit intel_limit_t; | |
131 | struct intel_limit { | |
132 | intel_range_t dot, vco, n, m, m1, m2, p, p1; | |
133 | intel_p2_t p2; | |
134 | }; | |
135 | ||
136 | /* returns HPLL frequency in kHz */ | |
137 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) | |
138 | { | |
139 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; | |
140 | ||
141 | /* Obtain SKU information */ | |
142 | mutex_lock(&dev_priv->sb_lock); | |
143 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
144 | CCK_FUSE_HPLL_FREQ_MASK; | |
145 | mutex_unlock(&dev_priv->sb_lock); | |
146 | ||
147 | return vco_freq[hpll_freq] * 1000; | |
148 | } | |
149 | ||
150 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, | |
151 | const char *name, u32 reg) | |
152 | { | |
153 | u32 val; | |
154 | int divider; | |
155 | ||
156 | if (dev_priv->hpll_freq == 0) | |
157 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
158 | ||
159 | mutex_lock(&dev_priv->sb_lock); | |
160 | val = vlv_cck_read(dev_priv, reg); | |
161 | mutex_unlock(&dev_priv->sb_lock); | |
162 | ||
163 | divider = val & CCK_FREQUENCY_VALUES; | |
164 | ||
165 | WARN((val & CCK_FREQUENCY_STATUS) != | |
166 | (divider << CCK_FREQUENCY_STATUS_SHIFT), | |
167 | "%s change in progress\n", name); | |
168 | ||
169 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); | |
170 | } | |
171 | ||
172 | int | |
173 | intel_pch_rawclk(struct drm_device *dev) | |
174 | { | |
175 | struct drm_i915_private *dev_priv = dev->dev_private; | |
176 | ||
177 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
178 | ||
179 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
180 | } | |
181 | ||
182 | /* hrawclock is 1/4 the FSB frequency */ | |
183 | int intel_hrawclk(struct drm_device *dev) | |
184 | { | |
185 | struct drm_i915_private *dev_priv = dev->dev_private; | |
186 | uint32_t clkcfg; | |
187 | ||
188 | /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */ | |
189 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) | |
190 | return 200; | |
191 | ||
192 | clkcfg = I915_READ(CLKCFG); | |
193 | switch (clkcfg & CLKCFG_FSB_MASK) { | |
194 | case CLKCFG_FSB_400: | |
195 | return 100; | |
196 | case CLKCFG_FSB_533: | |
197 | return 133; | |
198 | case CLKCFG_FSB_667: | |
199 | return 166; | |
200 | case CLKCFG_FSB_800: | |
201 | return 200; | |
202 | case CLKCFG_FSB_1067: | |
203 | return 266; | |
204 | case CLKCFG_FSB_1333: | |
205 | return 333; | |
206 | /* these two are just a guess; one of them might be right */ | |
207 | case CLKCFG_FSB_1600: | |
208 | case CLKCFG_FSB_1600_ALT: | |
209 | return 400; | |
210 | default: | |
211 | return 133; | |
212 | } | |
213 | } | |
214 | ||
215 | static void intel_update_czclk(struct drm_i915_private *dev_priv) | |
216 | { | |
217 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) | |
218 | return; | |
219 | ||
220 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", | |
221 | CCK_CZ_CLOCK_CONTROL); | |
222 | ||
223 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); | |
224 | } | |
225 | ||
226 | static inline u32 /* units of 100MHz */ | |
227 | intel_fdi_link_freq(struct drm_device *dev) | |
228 | { | |
229 | if (IS_GEN5(dev)) { | |
230 | struct drm_i915_private *dev_priv = dev->dev_private; | |
231 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
232 | } else | |
233 | return 27; | |
234 | } | |
235 | ||
236 | static const intel_limit_t intel_limits_i8xx_dac = { | |
237 | .dot = { .min = 25000, .max = 350000 }, | |
238 | .vco = { .min = 908000, .max = 1512000 }, | |
239 | .n = { .min = 2, .max = 16 }, | |
240 | .m = { .min = 96, .max = 140 }, | |
241 | .m1 = { .min = 18, .max = 26 }, | |
242 | .m2 = { .min = 6, .max = 16 }, | |
243 | .p = { .min = 4, .max = 128 }, | |
244 | .p1 = { .min = 2, .max = 33 }, | |
245 | .p2 = { .dot_limit = 165000, | |
246 | .p2_slow = 4, .p2_fast = 2 }, | |
247 | }; | |
248 | ||
249 | static const intel_limit_t intel_limits_i8xx_dvo = { | |
250 | .dot = { .min = 25000, .max = 350000 }, | |
251 | .vco = { .min = 908000, .max = 1512000 }, | |
252 | .n = { .min = 2, .max = 16 }, | |
253 | .m = { .min = 96, .max = 140 }, | |
254 | .m1 = { .min = 18, .max = 26 }, | |
255 | .m2 = { .min = 6, .max = 16 }, | |
256 | .p = { .min = 4, .max = 128 }, | |
257 | .p1 = { .min = 2, .max = 33 }, | |
258 | .p2 = { .dot_limit = 165000, | |
259 | .p2_slow = 4, .p2_fast = 4 }, | |
260 | }; | |
261 | ||
262 | static const intel_limit_t intel_limits_i8xx_lvds = { | |
263 | .dot = { .min = 25000, .max = 350000 }, | |
264 | .vco = { .min = 908000, .max = 1512000 }, | |
265 | .n = { .min = 2, .max = 16 }, | |
266 | .m = { .min = 96, .max = 140 }, | |
267 | .m1 = { .min = 18, .max = 26 }, | |
268 | .m2 = { .min = 6, .max = 16 }, | |
269 | .p = { .min = 4, .max = 128 }, | |
270 | .p1 = { .min = 1, .max = 6 }, | |
271 | .p2 = { .dot_limit = 165000, | |
272 | .p2_slow = 14, .p2_fast = 7 }, | |
273 | }; | |
274 | ||
275 | static const intel_limit_t intel_limits_i9xx_sdvo = { | |
276 | .dot = { .min = 20000, .max = 400000 }, | |
277 | .vco = { .min = 1400000, .max = 2800000 }, | |
278 | .n = { .min = 1, .max = 6 }, | |
279 | .m = { .min = 70, .max = 120 }, | |
280 | .m1 = { .min = 8, .max = 18 }, | |
281 | .m2 = { .min = 3, .max = 7 }, | |
282 | .p = { .min = 5, .max = 80 }, | |
283 | .p1 = { .min = 1, .max = 8 }, | |
284 | .p2 = { .dot_limit = 200000, | |
285 | .p2_slow = 10, .p2_fast = 5 }, | |
286 | }; | |
287 | ||
288 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
289 | .dot = { .min = 20000, .max = 400000 }, | |
290 | .vco = { .min = 1400000, .max = 2800000 }, | |
291 | .n = { .min = 1, .max = 6 }, | |
292 | .m = { .min = 70, .max = 120 }, | |
293 | .m1 = { .min = 8, .max = 18 }, | |
294 | .m2 = { .min = 3, .max = 7 }, | |
295 | .p = { .min = 7, .max = 98 }, | |
296 | .p1 = { .min = 1, .max = 8 }, | |
297 | .p2 = { .dot_limit = 112000, | |
298 | .p2_slow = 14, .p2_fast = 7 }, | |
299 | }; | |
300 | ||
301 | ||
302 | static const intel_limit_t intel_limits_g4x_sdvo = { | |
303 | .dot = { .min = 25000, .max = 270000 }, | |
304 | .vco = { .min = 1750000, .max = 3500000}, | |
305 | .n = { .min = 1, .max = 4 }, | |
306 | .m = { .min = 104, .max = 138 }, | |
307 | .m1 = { .min = 17, .max = 23 }, | |
308 | .m2 = { .min = 5, .max = 11 }, | |
309 | .p = { .min = 10, .max = 30 }, | |
310 | .p1 = { .min = 1, .max = 3}, | |
311 | .p2 = { .dot_limit = 270000, | |
312 | .p2_slow = 10, | |
313 | .p2_fast = 10 | |
314 | }, | |
315 | }; | |
316 | ||
317 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
318 | .dot = { .min = 22000, .max = 400000 }, | |
319 | .vco = { .min = 1750000, .max = 3500000}, | |
320 | .n = { .min = 1, .max = 4 }, | |
321 | .m = { .min = 104, .max = 138 }, | |
322 | .m1 = { .min = 16, .max = 23 }, | |
323 | .m2 = { .min = 5, .max = 11 }, | |
324 | .p = { .min = 5, .max = 80 }, | |
325 | .p1 = { .min = 1, .max = 8}, | |
326 | .p2 = { .dot_limit = 165000, | |
327 | .p2_slow = 10, .p2_fast = 5 }, | |
328 | }; | |
329 | ||
330 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
331 | .dot = { .min = 20000, .max = 115000 }, | |
332 | .vco = { .min = 1750000, .max = 3500000 }, | |
333 | .n = { .min = 1, .max = 3 }, | |
334 | .m = { .min = 104, .max = 138 }, | |
335 | .m1 = { .min = 17, .max = 23 }, | |
336 | .m2 = { .min = 5, .max = 11 }, | |
337 | .p = { .min = 28, .max = 112 }, | |
338 | .p1 = { .min = 2, .max = 8 }, | |
339 | .p2 = { .dot_limit = 0, | |
340 | .p2_slow = 14, .p2_fast = 14 | |
341 | }, | |
342 | }; | |
343 | ||
344 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
345 | .dot = { .min = 80000, .max = 224000 }, | |
346 | .vco = { .min = 1750000, .max = 3500000 }, | |
347 | .n = { .min = 1, .max = 3 }, | |
348 | .m = { .min = 104, .max = 138 }, | |
349 | .m1 = { .min = 17, .max = 23 }, | |
350 | .m2 = { .min = 5, .max = 11 }, | |
351 | .p = { .min = 14, .max = 42 }, | |
352 | .p1 = { .min = 2, .max = 6 }, | |
353 | .p2 = { .dot_limit = 0, | |
354 | .p2_slow = 7, .p2_fast = 7 | |
355 | }, | |
356 | }; | |
357 | ||
358 | static const intel_limit_t intel_limits_pineview_sdvo = { | |
359 | .dot = { .min = 20000, .max = 400000}, | |
360 | .vco = { .min = 1700000, .max = 3500000 }, | |
361 | /* Pineview's Ncounter is a ring counter */ | |
362 | .n = { .min = 3, .max = 6 }, | |
363 | .m = { .min = 2, .max = 256 }, | |
364 | /* Pineview only has one combined m divider, which we treat as m2. */ | |
365 | .m1 = { .min = 0, .max = 0 }, | |
366 | .m2 = { .min = 0, .max = 254 }, | |
367 | .p = { .min = 5, .max = 80 }, | |
368 | .p1 = { .min = 1, .max = 8 }, | |
369 | .p2 = { .dot_limit = 200000, | |
370 | .p2_slow = 10, .p2_fast = 5 }, | |
371 | }; | |
372 | ||
373 | static const intel_limit_t intel_limits_pineview_lvds = { | |
374 | .dot = { .min = 20000, .max = 400000 }, | |
375 | .vco = { .min = 1700000, .max = 3500000 }, | |
376 | .n = { .min = 3, .max = 6 }, | |
377 | .m = { .min = 2, .max = 256 }, | |
378 | .m1 = { .min = 0, .max = 0 }, | |
379 | .m2 = { .min = 0, .max = 254 }, | |
380 | .p = { .min = 7, .max = 112 }, | |
381 | .p1 = { .min = 1, .max = 8 }, | |
382 | .p2 = { .dot_limit = 112000, | |
383 | .p2_slow = 14, .p2_fast = 14 }, | |
384 | }; | |
385 | ||
386 | /* Ironlake / Sandybridge | |
387 | * | |
388 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
389 | * the range value for them is (actual_value - 2). | |
390 | */ | |
391 | static const intel_limit_t intel_limits_ironlake_dac = { | |
392 | .dot = { .min = 25000, .max = 350000 }, | |
393 | .vco = { .min = 1760000, .max = 3510000 }, | |
394 | .n = { .min = 1, .max = 5 }, | |
395 | .m = { .min = 79, .max = 127 }, | |
396 | .m1 = { .min = 12, .max = 22 }, | |
397 | .m2 = { .min = 5, .max = 9 }, | |
398 | .p = { .min = 5, .max = 80 }, | |
399 | .p1 = { .min = 1, .max = 8 }, | |
400 | .p2 = { .dot_limit = 225000, | |
401 | .p2_slow = 10, .p2_fast = 5 }, | |
402 | }; | |
403 | ||
404 | static const intel_limit_t intel_limits_ironlake_single_lvds = { | |
405 | .dot = { .min = 25000, .max = 350000 }, | |
406 | .vco = { .min = 1760000, .max = 3510000 }, | |
407 | .n = { .min = 1, .max = 3 }, | |
408 | .m = { .min = 79, .max = 118 }, | |
409 | .m1 = { .min = 12, .max = 22 }, | |
410 | .m2 = { .min = 5, .max = 9 }, | |
411 | .p = { .min = 28, .max = 112 }, | |
412 | .p1 = { .min = 2, .max = 8 }, | |
413 | .p2 = { .dot_limit = 225000, | |
414 | .p2_slow = 14, .p2_fast = 14 }, | |
415 | }; | |
416 | ||
417 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
418 | .dot = { .min = 25000, .max = 350000 }, | |
419 | .vco = { .min = 1760000, .max = 3510000 }, | |
420 | .n = { .min = 1, .max = 3 }, | |
421 | .m = { .min = 79, .max = 127 }, | |
422 | .m1 = { .min = 12, .max = 22 }, | |
423 | .m2 = { .min = 5, .max = 9 }, | |
424 | .p = { .min = 14, .max = 56 }, | |
425 | .p1 = { .min = 2, .max = 8 }, | |
426 | .p2 = { .dot_limit = 225000, | |
427 | .p2_slow = 7, .p2_fast = 7 }, | |
428 | }; | |
429 | ||
430 | /* LVDS 100mhz refclk limits. */ | |
431 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { | |
432 | .dot = { .min = 25000, .max = 350000 }, | |
433 | .vco = { .min = 1760000, .max = 3510000 }, | |
434 | .n = { .min = 1, .max = 2 }, | |
435 | .m = { .min = 79, .max = 126 }, | |
436 | .m1 = { .min = 12, .max = 22 }, | |
437 | .m2 = { .min = 5, .max = 9 }, | |
438 | .p = { .min = 28, .max = 112 }, | |
439 | .p1 = { .min = 2, .max = 8 }, | |
440 | .p2 = { .dot_limit = 225000, | |
441 | .p2_slow = 14, .p2_fast = 14 }, | |
442 | }; | |
443 | ||
444 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
445 | .dot = { .min = 25000, .max = 350000 }, | |
446 | .vco = { .min = 1760000, .max = 3510000 }, | |
447 | .n = { .min = 1, .max = 3 }, | |
448 | .m = { .min = 79, .max = 126 }, | |
449 | .m1 = { .min = 12, .max = 22 }, | |
450 | .m2 = { .min = 5, .max = 9 }, | |
451 | .p = { .min = 14, .max = 42 }, | |
452 | .p1 = { .min = 2, .max = 6 }, | |
453 | .p2 = { .dot_limit = 225000, | |
454 | .p2_slow = 7, .p2_fast = 7 }, | |
455 | }; | |
456 | ||
457 | static const intel_limit_t intel_limits_vlv = { | |
458 | /* | |
459 | * These are the data rate limits (measured in fast clocks) | |
460 | * since those are the strictest limits we have. The fast | |
461 | * clock and actual rate limits are more relaxed, so checking | |
462 | * them would make no difference. | |
463 | */ | |
464 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
465 | .vco = { .min = 4000000, .max = 6000000 }, | |
466 | .n = { .min = 1, .max = 7 }, | |
467 | .m1 = { .min = 2, .max = 3 }, | |
468 | .m2 = { .min = 11, .max = 156 }, | |
469 | .p1 = { .min = 2, .max = 3 }, | |
470 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ | |
471 | }; | |
472 | ||
473 | static const intel_limit_t intel_limits_chv = { | |
474 | /* | |
475 | * These are the data rate limits (measured in fast clocks) | |
476 | * since those are the strictest limits we have. The fast | |
477 | * clock and actual rate limits are more relaxed, so checking | |
478 | * them would make no difference. | |
479 | */ | |
480 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
481 | .vco = { .min = 4800000, .max = 6480000 }, | |
482 | .n = { .min = 1, .max = 1 }, | |
483 | .m1 = { .min = 2, .max = 2 }, | |
484 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
485 | .p1 = { .min = 2, .max = 4 }, | |
486 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
487 | }; | |
488 | ||
489 | static const intel_limit_t intel_limits_bxt = { | |
490 | /* FIXME: find real dot limits */ | |
491 | .dot = { .min = 0, .max = INT_MAX }, | |
492 | .vco = { .min = 4800000, .max = 6700000 }, | |
493 | .n = { .min = 1, .max = 1 }, | |
494 | .m1 = { .min = 2, .max = 2 }, | |
495 | /* FIXME: find real m2 limits */ | |
496 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
497 | .p1 = { .min = 2, .max = 4 }, | |
498 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
499 | }; | |
500 | ||
501 | static bool | |
502 | needs_modeset(struct drm_crtc_state *state) | |
503 | { | |
504 | return drm_atomic_crtc_needs_modeset(state); | |
505 | } | |
506 | ||
507 | /** | |
508 | * Returns whether any output on the specified pipe is of the specified type | |
509 | */ | |
510 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) | |
511 | { | |
512 | struct drm_device *dev = crtc->base.dev; | |
513 | struct intel_encoder *encoder; | |
514 | ||
515 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
516 | if (encoder->type == type) | |
517 | return true; | |
518 | ||
519 | return false; | |
520 | } | |
521 | ||
522 | /** | |
523 | * Returns whether any output on the specified pipe will have the specified | |
524 | * type after a staged modeset is complete, i.e., the same as | |
525 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
526 | * encoder->crtc. | |
527 | */ | |
528 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, | |
529 | int type) | |
530 | { | |
531 | struct drm_atomic_state *state = crtc_state->base.state; | |
532 | struct drm_connector *connector; | |
533 | struct drm_connector_state *connector_state; | |
534 | struct intel_encoder *encoder; | |
535 | int i, num_connectors = 0; | |
536 | ||
537 | for_each_connector_in_state(state, connector, connector_state, i) { | |
538 | if (connector_state->crtc != crtc_state->base.crtc) | |
539 | continue; | |
540 | ||
541 | num_connectors++; | |
542 | ||
543 | encoder = to_intel_encoder(connector_state->best_encoder); | |
544 | if (encoder->type == type) | |
545 | return true; | |
546 | } | |
547 | ||
548 | WARN_ON(num_connectors == 0); | |
549 | ||
550 | return false; | |
551 | } | |
552 | ||
553 | static const intel_limit_t * | |
554 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
555 | { | |
556 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
557 | const intel_limit_t *limit; | |
558 | ||
559 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
560 | if (intel_is_dual_link_lvds(dev)) { | |
561 | if (refclk == 100000) | |
562 | limit = &intel_limits_ironlake_dual_lvds_100m; | |
563 | else | |
564 | limit = &intel_limits_ironlake_dual_lvds; | |
565 | } else { | |
566 | if (refclk == 100000) | |
567 | limit = &intel_limits_ironlake_single_lvds_100m; | |
568 | else | |
569 | limit = &intel_limits_ironlake_single_lvds; | |
570 | } | |
571 | } else | |
572 | limit = &intel_limits_ironlake_dac; | |
573 | ||
574 | return limit; | |
575 | } | |
576 | ||
577 | static const intel_limit_t * | |
578 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
579 | { | |
580 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
581 | const intel_limit_t *limit; | |
582 | ||
583 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
584 | if (intel_is_dual_link_lvds(dev)) | |
585 | limit = &intel_limits_g4x_dual_channel_lvds; | |
586 | else | |
587 | limit = &intel_limits_g4x_single_channel_lvds; | |
588 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || | |
589 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
590 | limit = &intel_limits_g4x_hdmi; | |
591 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { | |
592 | limit = &intel_limits_g4x_sdvo; | |
593 | } else /* The option is for other outputs */ | |
594 | limit = &intel_limits_i9xx_sdvo; | |
595 | ||
596 | return limit; | |
597 | } | |
598 | ||
599 | static const intel_limit_t * | |
600 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
601 | { | |
602 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
603 | const intel_limit_t *limit; | |
604 | ||
605 | if (IS_BROXTON(dev)) | |
606 | limit = &intel_limits_bxt; | |
607 | else if (HAS_PCH_SPLIT(dev)) | |
608 | limit = intel_ironlake_limit(crtc_state, refclk); | |
609 | else if (IS_G4X(dev)) { | |
610 | limit = intel_g4x_limit(crtc_state); | |
611 | } else if (IS_PINEVIEW(dev)) { | |
612 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) | |
613 | limit = &intel_limits_pineview_lvds; | |
614 | else | |
615 | limit = &intel_limits_pineview_sdvo; | |
616 | } else if (IS_CHERRYVIEW(dev)) { | |
617 | limit = &intel_limits_chv; | |
618 | } else if (IS_VALLEYVIEW(dev)) { | |
619 | limit = &intel_limits_vlv; | |
620 | } else if (!IS_GEN2(dev)) { | |
621 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) | |
622 | limit = &intel_limits_i9xx_lvds; | |
623 | else | |
624 | limit = &intel_limits_i9xx_sdvo; | |
625 | } else { | |
626 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) | |
627 | limit = &intel_limits_i8xx_lvds; | |
628 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) | |
629 | limit = &intel_limits_i8xx_dvo; | |
630 | else | |
631 | limit = &intel_limits_i8xx_dac; | |
632 | } | |
633 | return limit; | |
634 | } | |
635 | ||
636 | /* | |
637 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
638 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
639 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
640 | * The helpers' return value is the rate of the clock that is fed to the | |
641 | * display engine's pipe which can be the above fast dot clock rate or a | |
642 | * divided-down version of it. | |
643 | */ | |
644 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ | |
645 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) | |
646 | { | |
647 | clock->m = clock->m2 + 2; | |
648 | clock->p = clock->p1 * clock->p2; | |
649 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
650 | return 0; | |
651 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); | |
652 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
653 | ||
654 | return clock->dot; | |
655 | } | |
656 | ||
657 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) | |
658 | { | |
659 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
660 | } | |
661 | ||
662 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) | |
663 | { | |
664 | clock->m = i9xx_dpll_compute_m(clock); | |
665 | clock->p = clock->p1 * clock->p2; | |
666 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) | |
667 | return 0; | |
668 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); | |
669 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
670 | ||
671 | return clock->dot; | |
672 | } | |
673 | ||
674 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) | |
675 | { | |
676 | clock->m = clock->m1 * clock->m2; | |
677 | clock->p = clock->p1 * clock->p2; | |
678 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
679 | return 0; | |
680 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); | |
681 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
682 | ||
683 | return clock->dot / 5; | |
684 | } | |
685 | ||
686 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) | |
687 | { | |
688 | clock->m = clock->m1 * clock->m2; | |
689 | clock->p = clock->p1 * clock->p2; | |
690 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
691 | return 0; | |
692 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, | |
693 | clock->n << 22); | |
694 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
695 | ||
696 | return clock->dot / 5; | |
697 | } | |
698 | ||
699 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) | |
700 | /** | |
701 | * Returns whether the given set of divisors are valid for a given refclk with | |
702 | * the given connectors. | |
703 | */ | |
704 | ||
705 | static bool intel_PLL_is_valid(struct drm_device *dev, | |
706 | const intel_limit_t *limit, | |
707 | const intel_clock_t *clock) | |
708 | { | |
709 | if (clock->n < limit->n.min || limit->n.max < clock->n) | |
710 | INTELPllInvalid("n out of range\n"); | |
711 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) | |
712 | INTELPllInvalid("p1 out of range\n"); | |
713 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) | |
714 | INTELPllInvalid("m2 out of range\n"); | |
715 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) | |
716 | INTELPllInvalid("m1 out of range\n"); | |
717 | ||
718 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && | |
719 | !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) | |
720 | if (clock->m1 <= clock->m2) | |
721 | INTELPllInvalid("m1 <= m2\n"); | |
722 | ||
723 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) { | |
724 | if (clock->p < limit->p.min || limit->p.max < clock->p) | |
725 | INTELPllInvalid("p out of range\n"); | |
726 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
727 | INTELPllInvalid("m out of range\n"); | |
728 | } | |
729 | ||
730 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) | |
731 | INTELPllInvalid("vco out of range\n"); | |
732 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, | |
733 | * connector, etc., rather than just a single range. | |
734 | */ | |
735 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
736 | INTELPllInvalid("dot out of range\n"); | |
737 | ||
738 | return true; | |
739 | } | |
740 | ||
741 | static int | |
742 | i9xx_select_p2_div(const intel_limit_t *limit, | |
743 | const struct intel_crtc_state *crtc_state, | |
744 | int target) | |
745 | { | |
746 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
747 | ||
748 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
749 | /* | |
750 | * For LVDS just rely on its current settings for dual-channel. | |
751 | * We haven't figured out how to reliably set up different | |
752 | * single/dual channel state, if we even can. | |
753 | */ | |
754 | if (intel_is_dual_link_lvds(dev)) | |
755 | return limit->p2.p2_fast; | |
756 | else | |
757 | return limit->p2.p2_slow; | |
758 | } else { | |
759 | if (target < limit->p2.dot_limit) | |
760 | return limit->p2.p2_slow; | |
761 | else | |
762 | return limit->p2.p2_fast; | |
763 | } | |
764 | } | |
765 | ||
766 | static bool | |
767 | i9xx_find_best_dpll(const intel_limit_t *limit, | |
768 | struct intel_crtc_state *crtc_state, | |
769 | int target, int refclk, intel_clock_t *match_clock, | |
770 | intel_clock_t *best_clock) | |
771 | { | |
772 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
773 | intel_clock_t clock; | |
774 | int err = target; | |
775 | ||
776 | memset(best_clock, 0, sizeof(*best_clock)); | |
777 | ||
778 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
779 | ||
780 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; | |
781 | clock.m1++) { | |
782 | for (clock.m2 = limit->m2.min; | |
783 | clock.m2 <= limit->m2.max; clock.m2++) { | |
784 | if (clock.m2 >= clock.m1) | |
785 | break; | |
786 | for (clock.n = limit->n.min; | |
787 | clock.n <= limit->n.max; clock.n++) { | |
788 | for (clock.p1 = limit->p1.min; | |
789 | clock.p1 <= limit->p1.max; clock.p1++) { | |
790 | int this_err; | |
791 | ||
792 | i9xx_calc_dpll_params(refclk, &clock); | |
793 | if (!intel_PLL_is_valid(dev, limit, | |
794 | &clock)) | |
795 | continue; | |
796 | if (match_clock && | |
797 | clock.p != match_clock->p) | |
798 | continue; | |
799 | ||
800 | this_err = abs(clock.dot - target); | |
801 | if (this_err < err) { | |
802 | *best_clock = clock; | |
803 | err = this_err; | |
804 | } | |
805 | } | |
806 | } | |
807 | } | |
808 | } | |
809 | ||
810 | return (err != target); | |
811 | } | |
812 | ||
813 | static bool | |
814 | pnv_find_best_dpll(const intel_limit_t *limit, | |
815 | struct intel_crtc_state *crtc_state, | |
816 | int target, int refclk, intel_clock_t *match_clock, | |
817 | intel_clock_t *best_clock) | |
818 | { | |
819 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
820 | intel_clock_t clock; | |
821 | int err = target; | |
822 | ||
823 | memset(best_clock, 0, sizeof(*best_clock)); | |
824 | ||
825 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
826 | ||
827 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; | |
828 | clock.m1++) { | |
829 | for (clock.m2 = limit->m2.min; | |
830 | clock.m2 <= limit->m2.max; clock.m2++) { | |
831 | for (clock.n = limit->n.min; | |
832 | clock.n <= limit->n.max; clock.n++) { | |
833 | for (clock.p1 = limit->p1.min; | |
834 | clock.p1 <= limit->p1.max; clock.p1++) { | |
835 | int this_err; | |
836 | ||
837 | pnv_calc_dpll_params(refclk, &clock); | |
838 | if (!intel_PLL_is_valid(dev, limit, | |
839 | &clock)) | |
840 | continue; | |
841 | if (match_clock && | |
842 | clock.p != match_clock->p) | |
843 | continue; | |
844 | ||
845 | this_err = abs(clock.dot - target); | |
846 | if (this_err < err) { | |
847 | *best_clock = clock; | |
848 | err = this_err; | |
849 | } | |
850 | } | |
851 | } | |
852 | } | |
853 | } | |
854 | ||
855 | return (err != target); | |
856 | } | |
857 | ||
858 | static bool | |
859 | g4x_find_best_dpll(const intel_limit_t *limit, | |
860 | struct intel_crtc_state *crtc_state, | |
861 | int target, int refclk, intel_clock_t *match_clock, | |
862 | intel_clock_t *best_clock) | |
863 | { | |
864 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
865 | intel_clock_t clock; | |
866 | int max_n; | |
867 | bool found = false; | |
868 | /* approximately equals target * 0.00585 */ | |
869 | int err_most = (target >> 8) + (target >> 9); | |
870 | ||
871 | memset(best_clock, 0, sizeof(*best_clock)); | |
872 | ||
873 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
874 | ||
875 | max_n = limit->n.max; | |
876 | /* based on hardware requirement, prefer smaller n to precision */ | |
877 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { | |
878 | /* based on hardware requirement, prefere larger m1,m2 */ | |
879 | for (clock.m1 = limit->m1.max; | |
880 | clock.m1 >= limit->m1.min; clock.m1--) { | |
881 | for (clock.m2 = limit->m2.max; | |
882 | clock.m2 >= limit->m2.min; clock.m2--) { | |
883 | for (clock.p1 = limit->p1.max; | |
884 | clock.p1 >= limit->p1.min; clock.p1--) { | |
885 | int this_err; | |
886 | ||
887 | i9xx_calc_dpll_params(refclk, &clock); | |
888 | if (!intel_PLL_is_valid(dev, limit, | |
889 | &clock)) | |
890 | continue; | |
891 | ||
892 | this_err = abs(clock.dot - target); | |
893 | if (this_err < err_most) { | |
894 | *best_clock = clock; | |
895 | err_most = this_err; | |
896 | max_n = clock.n; | |
897 | found = true; | |
898 | } | |
899 | } | |
900 | } | |
901 | } | |
902 | } | |
903 | return found; | |
904 | } | |
905 | ||
906 | /* | |
907 | * Check if the calculated PLL configuration is more optimal compared to the | |
908 | * best configuration and error found so far. Return the calculated error. | |
909 | */ | |
910 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
911 | const intel_clock_t *calculated_clock, | |
912 | const intel_clock_t *best_clock, | |
913 | unsigned int best_error_ppm, | |
914 | unsigned int *error_ppm) | |
915 | { | |
916 | /* | |
917 | * For CHV ignore the error and consider only the P value. | |
918 | * Prefer a bigger P value based on HW requirements. | |
919 | */ | |
920 | if (IS_CHERRYVIEW(dev)) { | |
921 | *error_ppm = 0; | |
922 | ||
923 | return calculated_clock->p > best_clock->p; | |
924 | } | |
925 | ||
926 | if (WARN_ON_ONCE(!target_freq)) | |
927 | return false; | |
928 | ||
929 | *error_ppm = div_u64(1000000ULL * | |
930 | abs(target_freq - calculated_clock->dot), | |
931 | target_freq); | |
932 | /* | |
933 | * Prefer a better P value over a better (smaller) error if the error | |
934 | * is small. Ensure this preference for future configurations too by | |
935 | * setting the error to 0. | |
936 | */ | |
937 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
938 | *error_ppm = 0; | |
939 | ||
940 | return true; | |
941 | } | |
942 | ||
943 | return *error_ppm + 10 < best_error_ppm; | |
944 | } | |
945 | ||
946 | static bool | |
947 | vlv_find_best_dpll(const intel_limit_t *limit, | |
948 | struct intel_crtc_state *crtc_state, | |
949 | int target, int refclk, intel_clock_t *match_clock, | |
950 | intel_clock_t *best_clock) | |
951 | { | |
952 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); | |
953 | struct drm_device *dev = crtc->base.dev; | |
954 | intel_clock_t clock; | |
955 | unsigned int bestppm = 1000000; | |
956 | /* min update 19.2 MHz */ | |
957 | int max_n = min(limit->n.max, refclk / 19200); | |
958 | bool found = false; | |
959 | ||
960 | target *= 5; /* fast clock */ | |
961 | ||
962 | memset(best_clock, 0, sizeof(*best_clock)); | |
963 | ||
964 | /* based on hardware requirement, prefer smaller n to precision */ | |
965 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { | |
966 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
967 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; | |
968 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
969 | clock.p = clock.p1 * clock.p2; | |
970 | /* based on hardware requirement, prefer bigger m1,m2 values */ | |
971 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { | |
972 | unsigned int ppm; | |
973 | ||
974 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, | |
975 | refclk * clock.m1); | |
976 | ||
977 | vlv_calc_dpll_params(refclk, &clock); | |
978 | ||
979 | if (!intel_PLL_is_valid(dev, limit, | |
980 | &clock)) | |
981 | continue; | |
982 | ||
983 | if (!vlv_PLL_is_optimal(dev, target, | |
984 | &clock, | |
985 | best_clock, | |
986 | bestppm, &ppm)) | |
987 | continue; | |
988 | ||
989 | *best_clock = clock; | |
990 | bestppm = ppm; | |
991 | found = true; | |
992 | } | |
993 | } | |
994 | } | |
995 | } | |
996 | ||
997 | return found; | |
998 | } | |
999 | ||
1000 | static bool | |
1001 | chv_find_best_dpll(const intel_limit_t *limit, | |
1002 | struct intel_crtc_state *crtc_state, | |
1003 | int target, int refclk, intel_clock_t *match_clock, | |
1004 | intel_clock_t *best_clock) | |
1005 | { | |
1006 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); | |
1007 | struct drm_device *dev = crtc->base.dev; | |
1008 | unsigned int best_error_ppm; | |
1009 | intel_clock_t clock; | |
1010 | uint64_t m2; | |
1011 | int found = false; | |
1012 | ||
1013 | memset(best_clock, 0, sizeof(*best_clock)); | |
1014 | best_error_ppm = 1000000; | |
1015 | ||
1016 | /* | |
1017 | * Based on hardware doc, the n always set to 1, and m1 always | |
1018 | * set to 2. If requires to support 200Mhz refclk, we need to | |
1019 | * revisit this because n may not 1 anymore. | |
1020 | */ | |
1021 | clock.n = 1, clock.m1 = 2; | |
1022 | target *= 5; /* fast clock */ | |
1023 | ||
1024 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
1025 | for (clock.p2 = limit->p2.p2_fast; | |
1026 | clock.p2 >= limit->p2.p2_slow; | |
1027 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
1028 | unsigned int error_ppm; | |
1029 | ||
1030 | clock.p = clock.p1 * clock.p2; | |
1031 | ||
1032 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
1033 | clock.n) << 22, refclk * clock.m1); | |
1034 | ||
1035 | if (m2 > INT_MAX/clock.m1) | |
1036 | continue; | |
1037 | ||
1038 | clock.m2 = m2; | |
1039 | ||
1040 | chv_calc_dpll_params(refclk, &clock); | |
1041 | ||
1042 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
1043 | continue; | |
1044 | ||
1045 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, | |
1046 | best_error_ppm, &error_ppm)) | |
1047 | continue; | |
1048 | ||
1049 | *best_clock = clock; | |
1050 | best_error_ppm = error_ppm; | |
1051 | found = true; | |
1052 | } | |
1053 | } | |
1054 | ||
1055 | return found; | |
1056 | } | |
1057 | ||
1058 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, | |
1059 | intel_clock_t *best_clock) | |
1060 | { | |
1061 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
1062 | ||
1063 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
1064 | target_clock, refclk, NULL, best_clock); | |
1065 | } | |
1066 | ||
1067 | bool intel_crtc_active(struct drm_crtc *crtc) | |
1068 | { | |
1069 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1070 | ||
1071 | /* Be paranoid as we can arrive here with only partial | |
1072 | * state retrieved from the hardware during setup. | |
1073 | * | |
1074 | * We can ditch the adjusted_mode.crtc_clock check as soon | |
1075 | * as Haswell has gained clock readout/fastboot support. | |
1076 | * | |
1077 | * We can ditch the crtc->primary->fb check as soon as we can | |
1078 | * properly reconstruct framebuffers. | |
1079 | * | |
1080 | * FIXME: The intel_crtc->active here should be switched to | |
1081 | * crtc->state->active once we have proper CRTC states wired up | |
1082 | * for atomic. | |
1083 | */ | |
1084 | return intel_crtc->active && crtc->primary->state->fb && | |
1085 | intel_crtc->config->base.adjusted_mode.crtc_clock; | |
1086 | } | |
1087 | ||
1088 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, | |
1089 | enum pipe pipe) | |
1090 | { | |
1091 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1092 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1093 | ||
1094 | return intel_crtc->config->cpu_transcoder; | |
1095 | } | |
1096 | ||
1097 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) | |
1098 | { | |
1099 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1100 | i915_reg_t reg = PIPEDSL(pipe); | |
1101 | u32 line1, line2; | |
1102 | u32 line_mask; | |
1103 | ||
1104 | if (IS_GEN2(dev)) | |
1105 | line_mask = DSL_LINEMASK_GEN2; | |
1106 | else | |
1107 | line_mask = DSL_LINEMASK_GEN3; | |
1108 | ||
1109 | line1 = I915_READ(reg) & line_mask; | |
1110 | msleep(5); | |
1111 | line2 = I915_READ(reg) & line_mask; | |
1112 | ||
1113 | return line1 == line2; | |
1114 | } | |
1115 | ||
1116 | /* | |
1117 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
1118 | * @crtc: crtc whose pipe to wait for | |
1119 | * | |
1120 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1121 | * spinning on the vblank interrupt status bit, since we won't actually | |
1122 | * see an interrupt when the pipe is disabled. | |
1123 | * | |
1124 | * On Gen4 and above: | |
1125 | * wait for the pipe register state bit to turn off | |
1126 | * | |
1127 | * Otherwise: | |
1128 | * wait for the display line value to settle (it usually | |
1129 | * ends up stopping at the start of the next frame). | |
1130 | * | |
1131 | */ | |
1132 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) | |
1133 | { | |
1134 | struct drm_device *dev = crtc->base.dev; | |
1135 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1136 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; | |
1137 | enum pipe pipe = crtc->pipe; | |
1138 | ||
1139 | if (INTEL_INFO(dev)->gen >= 4) { | |
1140 | i915_reg_t reg = PIPECONF(cpu_transcoder); | |
1141 | ||
1142 | /* Wait for the Pipe State to go off */ | |
1143 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, | |
1144 | 100)) | |
1145 | WARN(1, "pipe_off wait timed out\n"); | |
1146 | } else { | |
1147 | /* Wait for the display line to settle */ | |
1148 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) | |
1149 | WARN(1, "pipe_off wait timed out\n"); | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | /* Only for pre-ILK configs */ | |
1154 | void assert_pll(struct drm_i915_private *dev_priv, | |
1155 | enum pipe pipe, bool state) | |
1156 | { | |
1157 | u32 val; | |
1158 | bool cur_state; | |
1159 | ||
1160 | val = I915_READ(DPLL(pipe)); | |
1161 | cur_state = !!(val & DPLL_VCO_ENABLE); | |
1162 | I915_STATE_WARN(cur_state != state, | |
1163 | "PLL state assertion failure (expected %s, current %s)\n", | |
1164 | onoff(state), onoff(cur_state)); | |
1165 | } | |
1166 | ||
1167 | /* XXX: the dsi pll is shared between MIPI DSI ports */ | |
1168 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1169 | { | |
1170 | u32 val; | |
1171 | bool cur_state; | |
1172 | ||
1173 | mutex_lock(&dev_priv->sb_lock); | |
1174 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); | |
1175 | mutex_unlock(&dev_priv->sb_lock); | |
1176 | ||
1177 | cur_state = val & DSI_PLL_VCO_EN; | |
1178 | I915_STATE_WARN(cur_state != state, | |
1179 | "DSI PLL state assertion failure (expected %s, current %s)\n", | |
1180 | onoff(state), onoff(cur_state)); | |
1181 | } | |
1182 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1183 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1184 | ||
1185 | struct intel_shared_dpll * | |
1186 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) | |
1187 | { | |
1188 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1189 | ||
1190 | if (crtc->config->shared_dpll < 0) | |
1191 | return NULL; | |
1192 | ||
1193 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; | |
1194 | } | |
1195 | ||
1196 | /* For ILK+ */ | |
1197 | void assert_shared_dpll(struct drm_i915_private *dev_priv, | |
1198 | struct intel_shared_dpll *pll, | |
1199 | bool state) | |
1200 | { | |
1201 | bool cur_state; | |
1202 | struct intel_dpll_hw_state hw_state; | |
1203 | ||
1204 | if (WARN(!pll, "asserting DPLL %s with no DPLL\n", onoff(state))) | |
1205 | return; | |
1206 | ||
1207 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); | |
1208 | I915_STATE_WARN(cur_state != state, | |
1209 | "%s assertion failure (expected %s, current %s)\n", | |
1210 | pll->name, onoff(state), onoff(cur_state)); | |
1211 | } | |
1212 | ||
1213 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1214 | enum pipe pipe, bool state) | |
1215 | { | |
1216 | bool cur_state; | |
1217 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, | |
1218 | pipe); | |
1219 | ||
1220 | if (HAS_DDI(dev_priv->dev)) { | |
1221 | /* DDI does not have a specific FDI_TX register */ | |
1222 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); | |
1223 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); | |
1224 | } else { | |
1225 | u32 val = I915_READ(FDI_TX_CTL(pipe)); | |
1226 | cur_state = !!(val & FDI_TX_ENABLE); | |
1227 | } | |
1228 | I915_STATE_WARN(cur_state != state, | |
1229 | "FDI TX state assertion failure (expected %s, current %s)\n", | |
1230 | onoff(state), onoff(cur_state)); | |
1231 | } | |
1232 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1233 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1234 | ||
1235 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1236 | enum pipe pipe, bool state) | |
1237 | { | |
1238 | u32 val; | |
1239 | bool cur_state; | |
1240 | ||
1241 | val = I915_READ(FDI_RX_CTL(pipe)); | |
1242 | cur_state = !!(val & FDI_RX_ENABLE); | |
1243 | I915_STATE_WARN(cur_state != state, | |
1244 | "FDI RX state assertion failure (expected %s, current %s)\n", | |
1245 | onoff(state), onoff(cur_state)); | |
1246 | } | |
1247 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1248 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1249 | ||
1250 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1251 | enum pipe pipe) | |
1252 | { | |
1253 | u32 val; | |
1254 | ||
1255 | /* ILK FDI PLL is always enabled */ | |
1256 | if (INTEL_INFO(dev_priv->dev)->gen == 5) | |
1257 | return; | |
1258 | ||
1259 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ | |
1260 | if (HAS_DDI(dev_priv->dev)) | |
1261 | return; | |
1262 | ||
1263 | val = I915_READ(FDI_TX_CTL(pipe)); | |
1264 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); | |
1265 | } | |
1266 | ||
1267 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, | |
1268 | enum pipe pipe, bool state) | |
1269 | { | |
1270 | u32 val; | |
1271 | bool cur_state; | |
1272 | ||
1273 | val = I915_READ(FDI_RX_CTL(pipe)); | |
1274 | cur_state = !!(val & FDI_RX_PLL_ENABLE); | |
1275 | I915_STATE_WARN(cur_state != state, | |
1276 | "FDI RX PLL assertion failure (expected %s, current %s)\n", | |
1277 | onoff(state), onoff(cur_state)); | |
1278 | } | |
1279 | ||
1280 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, | |
1281 | enum pipe pipe) | |
1282 | { | |
1283 | struct drm_device *dev = dev_priv->dev; | |
1284 | i915_reg_t pp_reg; | |
1285 | u32 val; | |
1286 | enum pipe panel_pipe = PIPE_A; | |
1287 | bool locked = true; | |
1288 | ||
1289 | if (WARN_ON(HAS_DDI(dev))) | |
1290 | return; | |
1291 | ||
1292 | if (HAS_PCH_SPLIT(dev)) { | |
1293 | u32 port_sel; | |
1294 | ||
1295 | pp_reg = PCH_PP_CONTROL; | |
1296 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; | |
1297 | ||
1298 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1299 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1300 | panel_pipe = PIPE_B; | |
1301 | /* XXX: else fix for eDP */ | |
1302 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
1303 | /* presumably write lock depends on pipe, not port select */ | |
1304 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1305 | panel_pipe = pipe; | |
1306 | } else { | |
1307 | pp_reg = PP_CONTROL; | |
1308 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) | |
1309 | panel_pipe = PIPE_B; | |
1310 | } | |
1311 | ||
1312 | val = I915_READ(pp_reg); | |
1313 | if (!(val & PANEL_POWER_ON) || | |
1314 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) | |
1315 | locked = false; | |
1316 | ||
1317 | I915_STATE_WARN(panel_pipe == pipe && locked, | |
1318 | "panel assertion failure, pipe %c regs locked\n", | |
1319 | pipe_name(pipe)); | |
1320 | } | |
1321 | ||
1322 | static void assert_cursor(struct drm_i915_private *dev_priv, | |
1323 | enum pipe pipe, bool state) | |
1324 | { | |
1325 | struct drm_device *dev = dev_priv->dev; | |
1326 | bool cur_state; | |
1327 | ||
1328 | if (IS_845G(dev) || IS_I865G(dev)) | |
1329 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; | |
1330 | else | |
1331 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; | |
1332 | ||
1333 | I915_STATE_WARN(cur_state != state, | |
1334 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", | |
1335 | pipe_name(pipe), onoff(state), onoff(cur_state)); | |
1336 | } | |
1337 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1338 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1339 | ||
1340 | void assert_pipe(struct drm_i915_private *dev_priv, | |
1341 | enum pipe pipe, bool state) | |
1342 | { | |
1343 | bool cur_state; | |
1344 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, | |
1345 | pipe); | |
1346 | enum intel_display_power_domain power_domain; | |
1347 | ||
1348 | /* if we need the pipe quirk it must be always on */ | |
1349 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1350 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
1351 | state = true; | |
1352 | ||
1353 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); | |
1354 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
1355 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); | |
1356 | cur_state = !!(val & PIPECONF_ENABLE); | |
1357 | ||
1358 | intel_display_power_put(dev_priv, power_domain); | |
1359 | } else { | |
1360 | cur_state = false; | |
1361 | } | |
1362 | ||
1363 | I915_STATE_WARN(cur_state != state, | |
1364 | "pipe %c assertion failure (expected %s, current %s)\n", | |
1365 | pipe_name(pipe), onoff(state), onoff(cur_state)); | |
1366 | } | |
1367 | ||
1368 | static void assert_plane(struct drm_i915_private *dev_priv, | |
1369 | enum plane plane, bool state) | |
1370 | { | |
1371 | u32 val; | |
1372 | bool cur_state; | |
1373 | ||
1374 | val = I915_READ(DSPCNTR(plane)); | |
1375 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); | |
1376 | I915_STATE_WARN(cur_state != state, | |
1377 | "plane %c assertion failure (expected %s, current %s)\n", | |
1378 | plane_name(plane), onoff(state), onoff(cur_state)); | |
1379 | } | |
1380 | ||
1381 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) | |
1382 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1383 | ||
1384 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, | |
1385 | enum pipe pipe) | |
1386 | { | |
1387 | struct drm_device *dev = dev_priv->dev; | |
1388 | int i; | |
1389 | ||
1390 | /* Primary planes are fixed to pipes on gen4+ */ | |
1391 | if (INTEL_INFO(dev)->gen >= 4) { | |
1392 | u32 val = I915_READ(DSPCNTR(pipe)); | |
1393 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, | |
1394 | "plane %c assertion failure, should be disabled but not\n", | |
1395 | plane_name(pipe)); | |
1396 | return; | |
1397 | } | |
1398 | ||
1399 | /* Need to check both planes against the pipe */ | |
1400 | for_each_pipe(dev_priv, i) { | |
1401 | u32 val = I915_READ(DSPCNTR(i)); | |
1402 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
1403 | DISPPLANE_SEL_PIPE_SHIFT; | |
1404 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, | |
1405 | "plane %c assertion failure, should be off on pipe %c but is still active\n", | |
1406 | plane_name(i), pipe_name(pipe)); | |
1407 | } | |
1408 | } | |
1409 | ||
1410 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, | |
1411 | enum pipe pipe) | |
1412 | { | |
1413 | struct drm_device *dev = dev_priv->dev; | |
1414 | int sprite; | |
1415 | ||
1416 | if (INTEL_INFO(dev)->gen >= 9) { | |
1417 | for_each_sprite(dev_priv, pipe, sprite) { | |
1418 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); | |
1419 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, | |
1420 | "plane %d assertion failure, should be off on pipe %c but is still active\n", | |
1421 | sprite, pipe_name(pipe)); | |
1422 | } | |
1423 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
1424 | for_each_sprite(dev_priv, pipe, sprite) { | |
1425 | u32 val = I915_READ(SPCNTR(pipe, sprite)); | |
1426 | I915_STATE_WARN(val & SP_ENABLE, | |
1427 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", | |
1428 | sprite_name(pipe, sprite), pipe_name(pipe)); | |
1429 | } | |
1430 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
1431 | u32 val = I915_READ(SPRCTL(pipe)); | |
1432 | I915_STATE_WARN(val & SPRITE_ENABLE, | |
1433 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", | |
1434 | plane_name(pipe), pipe_name(pipe)); | |
1435 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
1436 | u32 val = I915_READ(DVSCNTR(pipe)); | |
1437 | I915_STATE_WARN(val & DVS_ENABLE, | |
1438 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", | |
1439 | plane_name(pipe), pipe_name(pipe)); | |
1440 | } | |
1441 | } | |
1442 | ||
1443 | static void assert_vblank_disabled(struct drm_crtc *crtc) | |
1444 | { | |
1445 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) | |
1446 | drm_crtc_vblank_put(crtc); | |
1447 | } | |
1448 | ||
1449 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) | |
1450 | { | |
1451 | u32 val; | |
1452 | bool enabled; | |
1453 | ||
1454 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); | |
1455 | ||
1456 | val = I915_READ(PCH_DREF_CONTROL); | |
1457 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1458 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
1459 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); | |
1460 | } | |
1461 | ||
1462 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, | |
1463 | enum pipe pipe) | |
1464 | { | |
1465 | u32 val; | |
1466 | bool enabled; | |
1467 | ||
1468 | val = I915_READ(PCH_TRANSCONF(pipe)); | |
1469 | enabled = !!(val & TRANS_ENABLE); | |
1470 | I915_STATE_WARN(enabled, | |
1471 | "transcoder assertion failed, should be off on pipe %c but is still active\n", | |
1472 | pipe_name(pipe)); | |
1473 | } | |
1474 | ||
1475 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, | |
1476 | enum pipe pipe, u32 port_sel, u32 val) | |
1477 | { | |
1478 | if ((val & DP_PORT_EN) == 0) | |
1479 | return false; | |
1480 | ||
1481 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1482 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); | |
1483 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1484 | return false; | |
1485 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { | |
1486 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1487 | return false; | |
1488 | } else { | |
1489 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1490 | return false; | |
1491 | } | |
1492 | return true; | |
1493 | } | |
1494 | ||
1495 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, | |
1496 | enum pipe pipe, u32 val) | |
1497 | { | |
1498 | if ((val & SDVO_ENABLE) == 0) | |
1499 | return false; | |
1500 | ||
1501 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1502 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) | |
1503 | return false; | |
1504 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { | |
1505 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1506 | return false; | |
1507 | } else { | |
1508 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) | |
1509 | return false; | |
1510 | } | |
1511 | return true; | |
1512 | } | |
1513 | ||
1514 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1515 | enum pipe pipe, u32 val) | |
1516 | { | |
1517 | if ((val & LVDS_PORT_EN) == 0) | |
1518 | return false; | |
1519 | ||
1520 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1521 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1522 | return false; | |
1523 | } else { | |
1524 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1525 | return false; | |
1526 | } | |
1527 | return true; | |
1528 | } | |
1529 | ||
1530 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1531 | enum pipe pipe, u32 val) | |
1532 | { | |
1533 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1534 | return false; | |
1535 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1536 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1537 | return false; | |
1538 | } else { | |
1539 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1540 | return false; | |
1541 | } | |
1542 | return true; | |
1543 | } | |
1544 | ||
1545 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, | |
1546 | enum pipe pipe, i915_reg_t reg, | |
1547 | u32 port_sel) | |
1548 | { | |
1549 | u32 val = I915_READ(reg); | |
1550 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), | |
1551 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", | |
1552 | i915_mmio_reg_offset(reg), pipe_name(pipe)); | |
1553 | ||
1554 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 | |
1555 | && (val & DP_PIPEB_SELECT), | |
1556 | "IBX PCH dp port still using transcoder B\n"); | |
1557 | } | |
1558 | ||
1559 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1560 | enum pipe pipe, i915_reg_t reg) | |
1561 | { | |
1562 | u32 val = I915_READ(reg); | |
1563 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), | |
1564 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", | |
1565 | i915_mmio_reg_offset(reg), pipe_name(pipe)); | |
1566 | ||
1567 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 | |
1568 | && (val & SDVO_PIPE_B_SELECT), | |
1569 | "IBX PCH hdmi port still using transcoder B\n"); | |
1570 | } | |
1571 | ||
1572 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1573 | enum pipe pipe) | |
1574 | { | |
1575 | u32 val; | |
1576 | ||
1577 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); | |
1578 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1579 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
1580 | ||
1581 | val = I915_READ(PCH_ADPA); | |
1582 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), | |
1583 | "PCH VGA enabled on transcoder %c, should be disabled\n", | |
1584 | pipe_name(pipe)); | |
1585 | ||
1586 | val = I915_READ(PCH_LVDS); | |
1587 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), | |
1588 | "PCH LVDS enabled on transcoder %c, should be disabled\n", | |
1589 | pipe_name(pipe)); | |
1590 | ||
1591 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); | |
1592 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1593 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
1594 | } | |
1595 | ||
1596 | static void vlv_enable_pll(struct intel_crtc *crtc, | |
1597 | const struct intel_crtc_state *pipe_config) | |
1598 | { | |
1599 | struct drm_device *dev = crtc->base.dev; | |
1600 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1601 | i915_reg_t reg = DPLL(crtc->pipe); | |
1602 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
1603 | ||
1604 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1605 | ||
1606 | /* PLL is protected by panel, make sure we can write it */ | |
1607 | if (IS_MOBILE(dev_priv->dev)) | |
1608 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
1609 | ||
1610 | I915_WRITE(reg, dpll); | |
1611 | POSTING_READ(reg); | |
1612 | udelay(150); | |
1613 | ||
1614 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1615 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1616 | ||
1617 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); | |
1618 | POSTING_READ(DPLL_MD(crtc->pipe)); | |
1619 | ||
1620 | /* We do this three times for luck */ | |
1621 | I915_WRITE(reg, dpll); | |
1622 | POSTING_READ(reg); | |
1623 | udelay(150); /* wait for warmup */ | |
1624 | I915_WRITE(reg, dpll); | |
1625 | POSTING_READ(reg); | |
1626 | udelay(150); /* wait for warmup */ | |
1627 | I915_WRITE(reg, dpll); | |
1628 | POSTING_READ(reg); | |
1629 | udelay(150); /* wait for warmup */ | |
1630 | } | |
1631 | ||
1632 | static void chv_enable_pll(struct intel_crtc *crtc, | |
1633 | const struct intel_crtc_state *pipe_config) | |
1634 | { | |
1635 | struct drm_device *dev = crtc->base.dev; | |
1636 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1637 | int pipe = crtc->pipe; | |
1638 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
1639 | u32 tmp; | |
1640 | ||
1641 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1642 | ||
1643 | mutex_lock(&dev_priv->sb_lock); | |
1644 | ||
1645 | /* Enable back the 10bit clock to display controller */ | |
1646 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1647 | tmp |= DPIO_DCLKP_EN; | |
1648 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1649 | ||
1650 | mutex_unlock(&dev_priv->sb_lock); | |
1651 | ||
1652 | /* | |
1653 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1654 | */ | |
1655 | udelay(1); | |
1656 | ||
1657 | /* Enable PLL */ | |
1658 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); | |
1659 | ||
1660 | /* Check PLL is locked */ | |
1661 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1662 | DRM_ERROR("PLL %d failed to lock\n", pipe); | |
1663 | ||
1664 | /* not sure when this should be written */ | |
1665 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); | |
1666 | POSTING_READ(DPLL_MD(pipe)); | |
1667 | } | |
1668 | ||
1669 | static int intel_num_dvo_pipes(struct drm_device *dev) | |
1670 | { | |
1671 | struct intel_crtc *crtc; | |
1672 | int count = 0; | |
1673 | ||
1674 | for_each_intel_crtc(dev, crtc) | |
1675 | count += crtc->base.state->active && | |
1676 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); | |
1677 | ||
1678 | return count; | |
1679 | } | |
1680 | ||
1681 | static void i9xx_enable_pll(struct intel_crtc *crtc) | |
1682 | { | |
1683 | struct drm_device *dev = crtc->base.dev; | |
1684 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1685 | i915_reg_t reg = DPLL(crtc->pipe); | |
1686 | u32 dpll = crtc->config->dpll_hw_state.dpll; | |
1687 | ||
1688 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1689 | ||
1690 | /* No really, not for ILK+ */ | |
1691 | BUG_ON(INTEL_INFO(dev)->gen >= 5); | |
1692 | ||
1693 | /* PLL is protected by panel, make sure we can write it */ | |
1694 | if (IS_MOBILE(dev) && !IS_I830(dev)) | |
1695 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
1696 | ||
1697 | /* Enable DVO 2x clock on both PLLs if necessary */ | |
1698 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1699 | /* | |
1700 | * It appears to be important that we don't enable this | |
1701 | * for the current pipe before otherwise configuring the | |
1702 | * PLL. No idea how this should be handled if multiple | |
1703 | * DVO outputs are enabled simultaneosly. | |
1704 | */ | |
1705 | dpll |= DPLL_DVO_2X_MODE; | |
1706 | I915_WRITE(DPLL(!crtc->pipe), | |
1707 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1708 | } | |
1709 | ||
1710 | /* | |
1711 | * Apparently we need to have VGA mode enabled prior to changing | |
1712 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old | |
1713 | * dividers, even though the register value does change. | |
1714 | */ | |
1715 | I915_WRITE(reg, 0); | |
1716 | ||
1717 | I915_WRITE(reg, dpll); | |
1718 | ||
1719 | /* Wait for the clocks to stabilize. */ | |
1720 | POSTING_READ(reg); | |
1721 | udelay(150); | |
1722 | ||
1723 | if (INTEL_INFO(dev)->gen >= 4) { | |
1724 | I915_WRITE(DPLL_MD(crtc->pipe), | |
1725 | crtc->config->dpll_hw_state.dpll_md); | |
1726 | } else { | |
1727 | /* The pixel multiplier can only be updated once the | |
1728 | * DPLL is enabled and the clocks are stable. | |
1729 | * | |
1730 | * So write it again. | |
1731 | */ | |
1732 | I915_WRITE(reg, dpll); | |
1733 | } | |
1734 | ||
1735 | /* We do this three times for luck */ | |
1736 | I915_WRITE(reg, dpll); | |
1737 | POSTING_READ(reg); | |
1738 | udelay(150); /* wait for warmup */ | |
1739 | I915_WRITE(reg, dpll); | |
1740 | POSTING_READ(reg); | |
1741 | udelay(150); /* wait for warmup */ | |
1742 | I915_WRITE(reg, dpll); | |
1743 | POSTING_READ(reg); | |
1744 | udelay(150); /* wait for warmup */ | |
1745 | } | |
1746 | ||
1747 | /** | |
1748 | * i9xx_disable_pll - disable a PLL | |
1749 | * @dev_priv: i915 private structure | |
1750 | * @pipe: pipe PLL to disable | |
1751 | * | |
1752 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1753 | * | |
1754 | * Note! This is for pre-ILK only. | |
1755 | */ | |
1756 | static void i9xx_disable_pll(struct intel_crtc *crtc) | |
1757 | { | |
1758 | struct drm_device *dev = crtc->base.dev; | |
1759 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1760 | enum pipe pipe = crtc->pipe; | |
1761 | ||
1762 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1763 | if (IS_I830(dev) && | |
1764 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && | |
1765 | !intel_num_dvo_pipes(dev)) { | |
1766 | I915_WRITE(DPLL(PIPE_B), | |
1767 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1768 | I915_WRITE(DPLL(PIPE_A), | |
1769 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1770 | } | |
1771 | ||
1772 | /* Don't disable pipe or pipe PLLs if needed */ | |
1773 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1774 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
1775 | return; | |
1776 | ||
1777 | /* Make sure the pipe isn't still relying on us */ | |
1778 | assert_pipe_disabled(dev_priv, pipe); | |
1779 | ||
1780 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); | |
1781 | POSTING_READ(DPLL(pipe)); | |
1782 | } | |
1783 | ||
1784 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1785 | { | |
1786 | u32 val; | |
1787 | ||
1788 | /* Make sure the pipe isn't still relying on us */ | |
1789 | assert_pipe_disabled(dev_priv, pipe); | |
1790 | ||
1791 | /* | |
1792 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1793 | * The latter is needed for VGA hotplug / manual detection. | |
1794 | */ | |
1795 | val = DPLL_VGA_MODE_DIS; | |
1796 | if (pipe == PIPE_B) | |
1797 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; | |
1798 | I915_WRITE(DPLL(pipe), val); | |
1799 | POSTING_READ(DPLL(pipe)); | |
1800 | ||
1801 | } | |
1802 | ||
1803 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1804 | { | |
1805 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
1806 | u32 val; | |
1807 | ||
1808 | /* Make sure the pipe isn't still relying on us */ | |
1809 | assert_pipe_disabled(dev_priv, pipe); | |
1810 | ||
1811 | /* Set PLL en = 0 */ | |
1812 | val = DPLL_SSC_REF_CLK_CHV | | |
1813 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
1814 | if (pipe != PIPE_A) | |
1815 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1816 | I915_WRITE(DPLL(pipe), val); | |
1817 | POSTING_READ(DPLL(pipe)); | |
1818 | ||
1819 | mutex_lock(&dev_priv->sb_lock); | |
1820 | ||
1821 | /* Disable 10bit clock to display controller */ | |
1822 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1823 | val &= ~DPIO_DCLKP_EN; | |
1824 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1825 | ||
1826 | mutex_unlock(&dev_priv->sb_lock); | |
1827 | } | |
1828 | ||
1829 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, | |
1830 | struct intel_digital_port *dport, | |
1831 | unsigned int expected_mask) | |
1832 | { | |
1833 | u32 port_mask; | |
1834 | i915_reg_t dpll_reg; | |
1835 | ||
1836 | switch (dport->port) { | |
1837 | case PORT_B: | |
1838 | port_mask = DPLL_PORTB_READY_MASK; | |
1839 | dpll_reg = DPLL(0); | |
1840 | break; | |
1841 | case PORT_C: | |
1842 | port_mask = DPLL_PORTC_READY_MASK; | |
1843 | dpll_reg = DPLL(0); | |
1844 | expected_mask <<= 4; | |
1845 | break; | |
1846 | case PORT_D: | |
1847 | port_mask = DPLL_PORTD_READY_MASK; | |
1848 | dpll_reg = DPIO_PHY_STATUS; | |
1849 | break; | |
1850 | default: | |
1851 | BUG(); | |
1852 | } | |
1853 | ||
1854 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) | |
1855 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1856 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
1857 | } | |
1858 | ||
1859 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) | |
1860 | { | |
1861 | struct drm_device *dev = crtc->base.dev; | |
1862 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1863 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1864 | ||
1865 | if (WARN_ON(pll == NULL)) | |
1866 | return; | |
1867 | ||
1868 | WARN_ON(!pll->config.crtc_mask); | |
1869 | if (pll->active == 0) { | |
1870 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1871 | WARN_ON(pll->on); | |
1872 | assert_shared_dpll_disabled(dev_priv, pll); | |
1873 | ||
1874 | pll->mode_set(dev_priv, pll); | |
1875 | } | |
1876 | } | |
1877 | ||
1878 | /** | |
1879 | * intel_enable_shared_dpll - enable PCH PLL | |
1880 | * @dev_priv: i915 private structure | |
1881 | * @pipe: pipe PLL to enable | |
1882 | * | |
1883 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1884 | * drives the transcoder clock. | |
1885 | */ | |
1886 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) | |
1887 | { | |
1888 | struct drm_device *dev = crtc->base.dev; | |
1889 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1890 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1891 | ||
1892 | if (WARN_ON(pll == NULL)) | |
1893 | return; | |
1894 | ||
1895 | if (WARN_ON(pll->config.crtc_mask == 0)) | |
1896 | return; | |
1897 | ||
1898 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", | |
1899 | pll->name, pll->active, pll->on, | |
1900 | crtc->base.base.id); | |
1901 | ||
1902 | if (pll->active++) { | |
1903 | WARN_ON(!pll->on); | |
1904 | assert_shared_dpll_enabled(dev_priv, pll); | |
1905 | return; | |
1906 | } | |
1907 | WARN_ON(pll->on); | |
1908 | ||
1909 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
1910 | ||
1911 | DRM_DEBUG_KMS("enabling %s\n", pll->name); | |
1912 | pll->enable(dev_priv, pll); | |
1913 | pll->on = true; | |
1914 | } | |
1915 | ||
1916 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) | |
1917 | { | |
1918 | struct drm_device *dev = crtc->base.dev; | |
1919 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1920 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1921 | ||
1922 | /* PCH only available on ILK+ */ | |
1923 | if (INTEL_INFO(dev)->gen < 5) | |
1924 | return; | |
1925 | ||
1926 | if (pll == NULL) | |
1927 | return; | |
1928 | ||
1929 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) | |
1930 | return; | |
1931 | ||
1932 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", | |
1933 | pll->name, pll->active, pll->on, | |
1934 | crtc->base.base.id); | |
1935 | ||
1936 | if (WARN_ON(pll->active == 0)) { | |
1937 | assert_shared_dpll_disabled(dev_priv, pll); | |
1938 | return; | |
1939 | } | |
1940 | ||
1941 | assert_shared_dpll_enabled(dev_priv, pll); | |
1942 | WARN_ON(!pll->on); | |
1943 | if (--pll->active) | |
1944 | return; | |
1945 | ||
1946 | DRM_DEBUG_KMS("disabling %s\n", pll->name); | |
1947 | pll->disable(dev_priv, pll); | |
1948 | pll->on = false; | |
1949 | ||
1950 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
1951 | } | |
1952 | ||
1953 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, | |
1954 | enum pipe pipe) | |
1955 | { | |
1956 | struct drm_device *dev = dev_priv->dev; | |
1957 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1959 | i915_reg_t reg; | |
1960 | uint32_t val, pipeconf_val; | |
1961 | ||
1962 | /* PCH only available on ILK+ */ | |
1963 | BUG_ON(!HAS_PCH_SPLIT(dev)); | |
1964 | ||
1965 | /* Make sure PCH DPLL is enabled */ | |
1966 | assert_shared_dpll_enabled(dev_priv, | |
1967 | intel_crtc_to_shared_dpll(intel_crtc)); | |
1968 | ||
1969 | /* FDI must be feeding us bits for PCH ports */ | |
1970 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1971 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1972 | ||
1973 | if (HAS_PCH_CPT(dev)) { | |
1974 | /* Workaround: Set the timing override bit before enabling the | |
1975 | * pch transcoder. */ | |
1976 | reg = TRANS_CHICKEN2(pipe); | |
1977 | val = I915_READ(reg); | |
1978 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1979 | I915_WRITE(reg, val); | |
1980 | } | |
1981 | ||
1982 | reg = PCH_TRANSCONF(pipe); | |
1983 | val = I915_READ(reg); | |
1984 | pipeconf_val = I915_READ(PIPECONF(pipe)); | |
1985 | ||
1986 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
1987 | /* | |
1988 | * Make the BPC in transcoder be consistent with | |
1989 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1990 | * here for both 8bpc and 12bpc. | |
1991 | */ | |
1992 | val &= ~PIPECONF_BPC_MASK; | |
1993 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) | |
1994 | val |= PIPECONF_8BPC; | |
1995 | else | |
1996 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
1997 | } | |
1998 | ||
1999 | val &= ~TRANS_INTERLACE_MASK; | |
2000 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
2001 | if (HAS_PCH_IBX(dev_priv->dev) && | |
2002 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) | |
2003 | val |= TRANS_LEGACY_INTERLACED_ILK; | |
2004 | else | |
2005 | val |= TRANS_INTERLACED; | |
2006 | else | |
2007 | val |= TRANS_PROGRESSIVE; | |
2008 | ||
2009 | I915_WRITE(reg, val | TRANS_ENABLE); | |
2010 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
2011 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); | |
2012 | } | |
2013 | ||
2014 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, | |
2015 | enum transcoder cpu_transcoder) | |
2016 | { | |
2017 | u32 val, pipeconf_val; | |
2018 | ||
2019 | /* PCH only available on ILK+ */ | |
2020 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); | |
2021 | ||
2022 | /* FDI must be feeding us bits for PCH ports */ | |
2023 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); | |
2024 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); | |
2025 | ||
2026 | /* Workaround: set timing override bit. */ | |
2027 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); | |
2028 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2029 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); | |
2030 | ||
2031 | val = TRANS_ENABLE; | |
2032 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); | |
2033 | ||
2034 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == | |
2035 | PIPECONF_INTERLACED_ILK) | |
2036 | val |= TRANS_INTERLACED; | |
2037 | else | |
2038 | val |= TRANS_PROGRESSIVE; | |
2039 | ||
2040 | I915_WRITE(LPT_TRANSCONF, val); | |
2041 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
2042 | DRM_ERROR("Failed to enable PCH transcoder\n"); | |
2043 | } | |
2044 | ||
2045 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, | |
2046 | enum pipe pipe) | |
2047 | { | |
2048 | struct drm_device *dev = dev_priv->dev; | |
2049 | i915_reg_t reg; | |
2050 | uint32_t val; | |
2051 | ||
2052 | /* FDI relies on the transcoder */ | |
2053 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2054 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2055 | ||
2056 | /* Ports must be off as well */ | |
2057 | assert_pch_ports_disabled(dev_priv, pipe); | |
2058 | ||
2059 | reg = PCH_TRANSCONF(pipe); | |
2060 | val = I915_READ(reg); | |
2061 | val &= ~TRANS_ENABLE; | |
2062 | I915_WRITE(reg, val); | |
2063 | /* wait for PCH transcoder off, transcoder state */ | |
2064 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
2065 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); | |
2066 | ||
2067 | if (HAS_PCH_CPT(dev)) { | |
2068 | /* Workaround: Clear the timing override chicken bit again. */ | |
2069 | reg = TRANS_CHICKEN2(pipe); | |
2070 | val = I915_READ(reg); | |
2071 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2072 | I915_WRITE(reg, val); | |
2073 | } | |
2074 | } | |
2075 | ||
2076 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) | |
2077 | { | |
2078 | u32 val; | |
2079 | ||
2080 | val = I915_READ(LPT_TRANSCONF); | |
2081 | val &= ~TRANS_ENABLE; | |
2082 | I915_WRITE(LPT_TRANSCONF, val); | |
2083 | /* wait for PCH transcoder off, transcoder state */ | |
2084 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) | |
2085 | DRM_ERROR("Failed to disable PCH transcoder\n"); | |
2086 | ||
2087 | /* Workaround: clear timing override bit. */ | |
2088 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); | |
2089 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2090 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); | |
2091 | } | |
2092 | ||
2093 | /** | |
2094 | * intel_enable_pipe - enable a pipe, asserting requirements | |
2095 | * @crtc: crtc responsible for the pipe | |
2096 | * | |
2097 | * Enable @crtc's pipe, making sure that various hardware specific requirements | |
2098 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. | |
2099 | */ | |
2100 | static void intel_enable_pipe(struct intel_crtc *crtc) | |
2101 | { | |
2102 | struct drm_device *dev = crtc->base.dev; | |
2103 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2104 | enum pipe pipe = crtc->pipe; | |
2105 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; | |
2106 | enum pipe pch_transcoder; | |
2107 | i915_reg_t reg; | |
2108 | u32 val; | |
2109 | ||
2110 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); | |
2111 | ||
2112 | assert_planes_disabled(dev_priv, pipe); | |
2113 | assert_cursor_disabled(dev_priv, pipe); | |
2114 | assert_sprites_disabled(dev_priv, pipe); | |
2115 | ||
2116 | if (HAS_PCH_LPT(dev_priv->dev)) | |
2117 | pch_transcoder = TRANSCODER_A; | |
2118 | else | |
2119 | pch_transcoder = pipe; | |
2120 | ||
2121 | /* | |
2122 | * A pipe without a PLL won't actually be able to drive bits from | |
2123 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2124 | * need the check. | |
2125 | */ | |
2126 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) | |
2127 | if (crtc->config->has_dsi_encoder) | |
2128 | assert_dsi_pll_enabled(dev_priv); | |
2129 | else | |
2130 | assert_pll_enabled(dev_priv, pipe); | |
2131 | else { | |
2132 | if (crtc->config->has_pch_encoder) { | |
2133 | /* if driving the PCH, we need FDI enabled */ | |
2134 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); | |
2135 | assert_fdi_tx_pll_enabled(dev_priv, | |
2136 | (enum pipe) cpu_transcoder); | |
2137 | } | |
2138 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2139 | } | |
2140 | ||
2141 | reg = PIPECONF(cpu_transcoder); | |
2142 | val = I915_READ(reg); | |
2143 | if (val & PIPECONF_ENABLE) { | |
2144 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
2145 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
2146 | return; | |
2147 | } | |
2148 | ||
2149 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
2150 | POSTING_READ(reg); | |
2151 | ||
2152 | /* | |
2153 | * Until the pipe starts DSL will read as 0, which would cause | |
2154 | * an apparent vblank timestamp jump, which messes up also the | |
2155 | * frame count when it's derived from the timestamps. So let's | |
2156 | * wait for the pipe to start properly before we call | |
2157 | * drm_crtc_vblank_on() | |
2158 | */ | |
2159 | if (dev->max_vblank_count == 0 && | |
2160 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) | |
2161 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); | |
2162 | } | |
2163 | ||
2164 | /** | |
2165 | * intel_disable_pipe - disable a pipe, asserting requirements | |
2166 | * @crtc: crtc whose pipes is to be disabled | |
2167 | * | |
2168 | * Disable the pipe of @crtc, making sure that various hardware | |
2169 | * specific requirements are met, if applicable, e.g. plane | |
2170 | * disabled, panel fitter off, etc. | |
2171 | * | |
2172 | * Will wait until the pipe has shut down before returning. | |
2173 | */ | |
2174 | static void intel_disable_pipe(struct intel_crtc *crtc) | |
2175 | { | |
2176 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
2177 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; | |
2178 | enum pipe pipe = crtc->pipe; | |
2179 | i915_reg_t reg; | |
2180 | u32 val; | |
2181 | ||
2182 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); | |
2183 | ||
2184 | /* | |
2185 | * Make sure planes won't keep trying to pump pixels to us, | |
2186 | * or we might hang the display. | |
2187 | */ | |
2188 | assert_planes_disabled(dev_priv, pipe); | |
2189 | assert_cursor_disabled(dev_priv, pipe); | |
2190 | assert_sprites_disabled(dev_priv, pipe); | |
2191 | ||
2192 | reg = PIPECONF(cpu_transcoder); | |
2193 | val = I915_READ(reg); | |
2194 | if ((val & PIPECONF_ENABLE) == 0) | |
2195 | return; | |
2196 | ||
2197 | /* | |
2198 | * Double wide has implications for planes | |
2199 | * so best keep it disabled when not needed. | |
2200 | */ | |
2201 | if (crtc->config->double_wide) | |
2202 | val &= ~PIPECONF_DOUBLE_WIDE; | |
2203 | ||
2204 | /* Don't disable pipe or pipe PLLs if needed */ | |
2205 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && | |
2206 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
2207 | val &= ~PIPECONF_ENABLE; | |
2208 | ||
2209 | I915_WRITE(reg, val); | |
2210 | if ((val & PIPECONF_ENABLE) == 0) | |
2211 | intel_wait_for_pipe_off(crtc); | |
2212 | } | |
2213 | ||
2214 | static bool need_vtd_wa(struct drm_device *dev) | |
2215 | { | |
2216 | #ifdef CONFIG_INTEL_IOMMU | |
2217 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2218 | return true; | |
2219 | #endif | |
2220 | return false; | |
2221 | } | |
2222 | ||
2223 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) | |
2224 | { | |
2225 | return IS_GEN2(dev_priv) ? 2048 : 4096; | |
2226 | } | |
2227 | ||
2228 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, | |
2229 | uint64_t fb_modifier, unsigned int cpp) | |
2230 | { | |
2231 | switch (fb_modifier) { | |
2232 | case DRM_FORMAT_MOD_NONE: | |
2233 | return cpp; | |
2234 | case I915_FORMAT_MOD_X_TILED: | |
2235 | if (IS_GEN2(dev_priv)) | |
2236 | return 128; | |
2237 | else | |
2238 | return 512; | |
2239 | case I915_FORMAT_MOD_Y_TILED: | |
2240 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) | |
2241 | return 128; | |
2242 | else | |
2243 | return 512; | |
2244 | case I915_FORMAT_MOD_Yf_TILED: | |
2245 | switch (cpp) { | |
2246 | case 1: | |
2247 | return 64; | |
2248 | case 2: | |
2249 | case 4: | |
2250 | return 128; | |
2251 | case 8: | |
2252 | case 16: | |
2253 | return 256; | |
2254 | default: | |
2255 | MISSING_CASE(cpp); | |
2256 | return cpp; | |
2257 | } | |
2258 | break; | |
2259 | default: | |
2260 | MISSING_CASE(fb_modifier); | |
2261 | return cpp; | |
2262 | } | |
2263 | } | |
2264 | ||
2265 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, | |
2266 | uint64_t fb_modifier, unsigned int cpp) | |
2267 | { | |
2268 | if (fb_modifier == DRM_FORMAT_MOD_NONE) | |
2269 | return 1; | |
2270 | else | |
2271 | return intel_tile_size(dev_priv) / | |
2272 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); | |
2273 | } | |
2274 | ||
2275 | /* Return the tile dimensions in pixel units */ | |
2276 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, | |
2277 | unsigned int *tile_width, | |
2278 | unsigned int *tile_height, | |
2279 | uint64_t fb_modifier, | |
2280 | unsigned int cpp) | |
2281 | { | |
2282 | unsigned int tile_width_bytes = | |
2283 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); | |
2284 | ||
2285 | *tile_width = tile_width_bytes / cpp; | |
2286 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; | |
2287 | } | |
2288 | ||
2289 | unsigned int | |
2290 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2291 | uint32_t pixel_format, uint64_t fb_modifier) | |
2292 | { | |
2293 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); | |
2294 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); | |
2295 | ||
2296 | return ALIGN(height, tile_height); | |
2297 | } | |
2298 | ||
2299 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) | |
2300 | { | |
2301 | unsigned int size = 0; | |
2302 | int i; | |
2303 | ||
2304 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) | |
2305 | size += rot_info->plane[i].width * rot_info->plane[i].height; | |
2306 | ||
2307 | return size; | |
2308 | } | |
2309 | ||
2310 | static void | |
2311 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, | |
2312 | const struct drm_framebuffer *fb, | |
2313 | unsigned int rotation) | |
2314 | { | |
2315 | struct drm_i915_private *dev_priv = to_i915(fb->dev); | |
2316 | struct intel_rotation_info *info = &view->params.rotated; | |
2317 | unsigned int tile_size, tile_width, tile_height, cpp; | |
2318 | ||
2319 | *view = i915_ggtt_view_normal; | |
2320 | ||
2321 | if (!intel_rotation_90_or_270(rotation)) | |
2322 | return; | |
2323 | ||
2324 | *view = i915_ggtt_view_rotated; | |
2325 | ||
2326 | info->uv_offset = fb->offsets[1]; | |
2327 | ||
2328 | tile_size = intel_tile_size(dev_priv); | |
2329 | ||
2330 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); | |
2331 | intel_tile_dims(dev_priv, &tile_width, &tile_height, | |
2332 | fb->modifier[0], cpp); | |
2333 | ||
2334 | info->plane[0].width = DIV_ROUND_UP(fb->pitches[0], tile_width * cpp); | |
2335 | info->plane[0].height = DIV_ROUND_UP(fb->height, tile_height); | |
2336 | ||
2337 | if (info->pixel_format == DRM_FORMAT_NV12) { | |
2338 | cpp = drm_format_plane_cpp(fb->pixel_format, 1); | |
2339 | intel_tile_dims(dev_priv, &tile_width, &tile_height, | |
2340 | fb->modifier[1], cpp); | |
2341 | ||
2342 | info->plane[1].width = DIV_ROUND_UP(fb->pitches[1], tile_width * cpp); | |
2343 | info->plane[1].height = DIV_ROUND_UP(fb->height / 2, tile_height); | |
2344 | } | |
2345 | } | |
2346 | ||
2347 | static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv) | |
2348 | { | |
2349 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2350 | return 256 * 1024; | |
2351 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || | |
2352 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) | |
2353 | return 128 * 1024; | |
2354 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2355 | return 4 * 1024; | |
2356 | else | |
2357 | return 0; | |
2358 | } | |
2359 | ||
2360 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, | |
2361 | uint64_t fb_modifier) | |
2362 | { | |
2363 | switch (fb_modifier) { | |
2364 | case DRM_FORMAT_MOD_NONE: | |
2365 | return intel_linear_alignment(dev_priv); | |
2366 | case I915_FORMAT_MOD_X_TILED: | |
2367 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2368 | return 256 * 1024; | |
2369 | return 0; | |
2370 | case I915_FORMAT_MOD_Y_TILED: | |
2371 | case I915_FORMAT_MOD_Yf_TILED: | |
2372 | return 1 * 1024 * 1024; | |
2373 | default: | |
2374 | MISSING_CASE(fb_modifier); | |
2375 | return 0; | |
2376 | } | |
2377 | } | |
2378 | ||
2379 | int | |
2380 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, | |
2381 | unsigned int rotation) | |
2382 | { | |
2383 | struct drm_device *dev = fb->dev; | |
2384 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2385 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
2386 | struct i915_ggtt_view view; | |
2387 | u32 alignment; | |
2388 | int ret; | |
2389 | ||
2390 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); | |
2391 | ||
2392 | alignment = intel_surf_alignment(dev_priv, fb->modifier[0]); | |
2393 | ||
2394 | intel_fill_fb_ggtt_view(&view, fb, rotation); | |
2395 | ||
2396 | /* Note that the w/a also requires 64 PTE of padding following the | |
2397 | * bo. We currently fill all unused PTE with the shadow page and so | |
2398 | * we should always have valid PTE following the scanout preventing | |
2399 | * the VT-d warning. | |
2400 | */ | |
2401 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2402 | alignment = 256 * 1024; | |
2403 | ||
2404 | /* | |
2405 | * Global gtt pte registers are special registers which actually forward | |
2406 | * writes to a chunk of system memory. Which means that there is no risk | |
2407 | * that the register values disappear as soon as we call | |
2408 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2409 | * pin/unpin/fence and not more. | |
2410 | */ | |
2411 | intel_runtime_pm_get(dev_priv); | |
2412 | ||
2413 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, | |
2414 | &view); | |
2415 | if (ret) | |
2416 | goto err_pm; | |
2417 | ||
2418 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2419 | * fence, whereas 965+ only requires a fence if using | |
2420 | * framebuffer compression. For simplicity, we always install | |
2421 | * a fence as the cost is not that onerous. | |
2422 | */ | |
2423 | if (view.type == I915_GGTT_VIEW_NORMAL) { | |
2424 | ret = i915_gem_object_get_fence(obj); | |
2425 | if (ret == -EDEADLK) { | |
2426 | /* | |
2427 | * -EDEADLK means there are no free fences | |
2428 | * no pending flips. | |
2429 | * | |
2430 | * This is propagated to atomic, but it uses | |
2431 | * -EDEADLK to force a locking recovery, so | |
2432 | * change the returned error to -EBUSY. | |
2433 | */ | |
2434 | ret = -EBUSY; | |
2435 | goto err_unpin; | |
2436 | } else if (ret) | |
2437 | goto err_unpin; | |
2438 | ||
2439 | i915_gem_object_pin_fence(obj); | |
2440 | } | |
2441 | ||
2442 | intel_runtime_pm_put(dev_priv); | |
2443 | return 0; | |
2444 | ||
2445 | err_unpin: | |
2446 | i915_gem_object_unpin_from_display_plane(obj, &view); | |
2447 | err_pm: | |
2448 | intel_runtime_pm_put(dev_priv); | |
2449 | return ret; | |
2450 | } | |
2451 | ||
2452 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) | |
2453 | { | |
2454 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
2455 | struct i915_ggtt_view view; | |
2456 | ||
2457 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); | |
2458 | ||
2459 | intel_fill_fb_ggtt_view(&view, fb, rotation); | |
2460 | ||
2461 | if (view.type == I915_GGTT_VIEW_NORMAL) | |
2462 | i915_gem_object_unpin_fence(obj); | |
2463 | ||
2464 | i915_gem_object_unpin_from_display_plane(obj, &view); | |
2465 | } | |
2466 | ||
2467 | /* | |
2468 | * Adjust the tile offset by moving the difference into | |
2469 | * the x/y offsets. | |
2470 | * | |
2471 | * Input tile dimensions and pitch must already be | |
2472 | * rotated to match x and y, and in pixel units. | |
2473 | */ | |
2474 | static u32 intel_adjust_tile_offset(int *x, int *y, | |
2475 | unsigned int tile_width, | |
2476 | unsigned int tile_height, | |
2477 | unsigned int tile_size, | |
2478 | unsigned int pitch_tiles, | |
2479 | u32 old_offset, | |
2480 | u32 new_offset) | |
2481 | { | |
2482 | unsigned int tiles; | |
2483 | ||
2484 | WARN_ON(old_offset & (tile_size - 1)); | |
2485 | WARN_ON(new_offset & (tile_size - 1)); | |
2486 | WARN_ON(new_offset > old_offset); | |
2487 | ||
2488 | tiles = (old_offset - new_offset) / tile_size; | |
2489 | ||
2490 | *y += tiles / pitch_tiles * tile_height; | |
2491 | *x += tiles % pitch_tiles * tile_width; | |
2492 | ||
2493 | return new_offset; | |
2494 | } | |
2495 | ||
2496 | /* | |
2497 | * Computes the linear offset to the base tile and adjusts | |
2498 | * x, y. bytes per pixel is assumed to be a power-of-two. | |
2499 | * | |
2500 | * In the 90/270 rotated case, x and y are assumed | |
2501 | * to be already rotated to match the rotated GTT view, and | |
2502 | * pitch is the tile_height aligned framebuffer height. | |
2503 | */ | |
2504 | u32 intel_compute_tile_offset(int *x, int *y, | |
2505 | const struct drm_framebuffer *fb, int plane, | |
2506 | unsigned int pitch, | |
2507 | unsigned int rotation) | |
2508 | { | |
2509 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); | |
2510 | uint64_t fb_modifier = fb->modifier[plane]; | |
2511 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); | |
2512 | u32 offset, offset_aligned, alignment; | |
2513 | ||
2514 | alignment = intel_surf_alignment(dev_priv, fb_modifier); | |
2515 | if (alignment) | |
2516 | alignment--; | |
2517 | ||
2518 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { | |
2519 | unsigned int tile_size, tile_width, tile_height; | |
2520 | unsigned int tile_rows, tiles, pitch_tiles; | |
2521 | ||
2522 | tile_size = intel_tile_size(dev_priv); | |
2523 | intel_tile_dims(dev_priv, &tile_width, &tile_height, | |
2524 | fb_modifier, cpp); | |
2525 | ||
2526 | if (intel_rotation_90_or_270(rotation)) { | |
2527 | pitch_tiles = pitch / tile_height; | |
2528 | swap(tile_width, tile_height); | |
2529 | } else { | |
2530 | pitch_tiles = pitch / (tile_width * cpp); | |
2531 | } | |
2532 | ||
2533 | tile_rows = *y / tile_height; | |
2534 | *y %= tile_height; | |
2535 | ||
2536 | tiles = *x / tile_width; | |
2537 | *x %= tile_width; | |
2538 | ||
2539 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; | |
2540 | offset_aligned = offset & ~alignment; | |
2541 | ||
2542 | intel_adjust_tile_offset(x, y, tile_width, tile_height, | |
2543 | tile_size, pitch_tiles, | |
2544 | offset, offset_aligned); | |
2545 | } else { | |
2546 | offset = *y * pitch + *x * cpp; | |
2547 | offset_aligned = offset & ~alignment; | |
2548 | ||
2549 | *y = (offset & alignment) / pitch; | |
2550 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2551 | } | |
2552 | ||
2553 | return offset_aligned; | |
2554 | } | |
2555 | ||
2556 | static int i9xx_format_to_fourcc(int format) | |
2557 | { | |
2558 | switch (format) { | |
2559 | case DISPPLANE_8BPP: | |
2560 | return DRM_FORMAT_C8; | |
2561 | case DISPPLANE_BGRX555: | |
2562 | return DRM_FORMAT_XRGB1555; | |
2563 | case DISPPLANE_BGRX565: | |
2564 | return DRM_FORMAT_RGB565; | |
2565 | default: | |
2566 | case DISPPLANE_BGRX888: | |
2567 | return DRM_FORMAT_XRGB8888; | |
2568 | case DISPPLANE_RGBX888: | |
2569 | return DRM_FORMAT_XBGR8888; | |
2570 | case DISPPLANE_BGRX101010: | |
2571 | return DRM_FORMAT_XRGB2101010; | |
2572 | case DISPPLANE_RGBX101010: | |
2573 | return DRM_FORMAT_XBGR2101010; | |
2574 | } | |
2575 | } | |
2576 | ||
2577 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) | |
2578 | { | |
2579 | switch (format) { | |
2580 | case PLANE_CTL_FORMAT_RGB_565: | |
2581 | return DRM_FORMAT_RGB565; | |
2582 | default: | |
2583 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2584 | if (rgb_order) { | |
2585 | if (alpha) | |
2586 | return DRM_FORMAT_ABGR8888; | |
2587 | else | |
2588 | return DRM_FORMAT_XBGR8888; | |
2589 | } else { | |
2590 | if (alpha) | |
2591 | return DRM_FORMAT_ARGB8888; | |
2592 | else | |
2593 | return DRM_FORMAT_XRGB8888; | |
2594 | } | |
2595 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2596 | if (rgb_order) | |
2597 | return DRM_FORMAT_XBGR2101010; | |
2598 | else | |
2599 | return DRM_FORMAT_XRGB2101010; | |
2600 | } | |
2601 | } | |
2602 | ||
2603 | static bool | |
2604 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, | |
2605 | struct intel_initial_plane_config *plane_config) | |
2606 | { | |
2607 | struct drm_device *dev = crtc->base.dev; | |
2608 | struct drm_i915_private *dev_priv = to_i915(dev); | |
2609 | struct drm_i915_gem_object *obj = NULL; | |
2610 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2611 | struct drm_framebuffer *fb = &plane_config->fb->base; | |
2612 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); | |
2613 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2614 | PAGE_SIZE); | |
2615 | ||
2616 | size_aligned -= base_aligned; | |
2617 | ||
2618 | if (plane_config->size == 0) | |
2619 | return false; | |
2620 | ||
2621 | /* If the FB is too big, just don't use it since fbdev is not very | |
2622 | * important and we should probably use that space with FBC or other | |
2623 | * features. */ | |
2624 | if (size_aligned * 2 > dev_priv->gtt.stolen_usable_size) | |
2625 | return false; | |
2626 | ||
2627 | mutex_lock(&dev->struct_mutex); | |
2628 | ||
2629 | obj = i915_gem_object_create_stolen_for_preallocated(dev, | |
2630 | base_aligned, | |
2631 | base_aligned, | |
2632 | size_aligned); | |
2633 | if (!obj) { | |
2634 | mutex_unlock(&dev->struct_mutex); | |
2635 | return false; | |
2636 | } | |
2637 | ||
2638 | obj->tiling_mode = plane_config->tiling; | |
2639 | if (obj->tiling_mode == I915_TILING_X) | |
2640 | obj->stride = fb->pitches[0]; | |
2641 | ||
2642 | mode_cmd.pixel_format = fb->pixel_format; | |
2643 | mode_cmd.width = fb->width; | |
2644 | mode_cmd.height = fb->height; | |
2645 | mode_cmd.pitches[0] = fb->pitches[0]; | |
2646 | mode_cmd.modifier[0] = fb->modifier[0]; | |
2647 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
2648 | ||
2649 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), | |
2650 | &mode_cmd, obj)) { | |
2651 | DRM_DEBUG_KMS("intel fb init failed\n"); | |
2652 | goto out_unref_obj; | |
2653 | } | |
2654 | ||
2655 | mutex_unlock(&dev->struct_mutex); | |
2656 | ||
2657 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); | |
2658 | return true; | |
2659 | ||
2660 | out_unref_obj: | |
2661 | drm_gem_object_unreference(&obj->base); | |
2662 | mutex_unlock(&dev->struct_mutex); | |
2663 | return false; | |
2664 | } | |
2665 | ||
2666 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ | |
2667 | static void | |
2668 | update_state_fb(struct drm_plane *plane) | |
2669 | { | |
2670 | if (plane->fb == plane->state->fb) | |
2671 | return; | |
2672 | ||
2673 | if (plane->state->fb) | |
2674 | drm_framebuffer_unreference(plane->state->fb); | |
2675 | plane->state->fb = plane->fb; | |
2676 | if (plane->state->fb) | |
2677 | drm_framebuffer_reference(plane->state->fb); | |
2678 | } | |
2679 | ||
2680 | static void | |
2681 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, | |
2682 | struct intel_initial_plane_config *plane_config) | |
2683 | { | |
2684 | struct drm_device *dev = intel_crtc->base.dev; | |
2685 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2686 | struct drm_crtc *c; | |
2687 | struct intel_crtc *i; | |
2688 | struct drm_i915_gem_object *obj; | |
2689 | struct drm_plane *primary = intel_crtc->base.primary; | |
2690 | struct drm_plane_state *plane_state = primary->state; | |
2691 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; | |
2692 | struct intel_plane *intel_plane = to_intel_plane(primary); | |
2693 | struct intel_plane_state *intel_state = | |
2694 | to_intel_plane_state(plane_state); | |
2695 | struct drm_framebuffer *fb; | |
2696 | ||
2697 | if (!plane_config->fb) | |
2698 | return; | |
2699 | ||
2700 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { | |
2701 | fb = &plane_config->fb->base; | |
2702 | goto valid_fb; | |
2703 | } | |
2704 | ||
2705 | kfree(plane_config->fb); | |
2706 | ||
2707 | /* | |
2708 | * Failed to alloc the obj, check to see if we should share | |
2709 | * an fb with another CRTC instead | |
2710 | */ | |
2711 | for_each_crtc(dev, c) { | |
2712 | i = to_intel_crtc(c); | |
2713 | ||
2714 | if (c == &intel_crtc->base) | |
2715 | continue; | |
2716 | ||
2717 | if (!i->active) | |
2718 | continue; | |
2719 | ||
2720 | fb = c->primary->fb; | |
2721 | if (!fb) | |
2722 | continue; | |
2723 | ||
2724 | obj = intel_fb_obj(fb); | |
2725 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { | |
2726 | drm_framebuffer_reference(fb); | |
2727 | goto valid_fb; | |
2728 | } | |
2729 | } | |
2730 | ||
2731 | /* | |
2732 | * We've failed to reconstruct the BIOS FB. Current display state | |
2733 | * indicates that the primary plane is visible, but has a NULL FB, | |
2734 | * which will lead to problems later if we don't fix it up. The | |
2735 | * simplest solution is to just disable the primary plane now and | |
2736 | * pretend the BIOS never had it enabled. | |
2737 | */ | |
2738 | to_intel_plane_state(plane_state)->visible = false; | |
2739 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); | |
2740 | intel_pre_disable_primary(&intel_crtc->base); | |
2741 | intel_plane->disable_plane(primary, &intel_crtc->base); | |
2742 | ||
2743 | return; | |
2744 | ||
2745 | valid_fb: | |
2746 | plane_state->src_x = 0; | |
2747 | plane_state->src_y = 0; | |
2748 | plane_state->src_w = fb->width << 16; | |
2749 | plane_state->src_h = fb->height << 16; | |
2750 | ||
2751 | plane_state->crtc_x = 0; | |
2752 | plane_state->crtc_y = 0; | |
2753 | plane_state->crtc_w = fb->width; | |
2754 | plane_state->crtc_h = fb->height; | |
2755 | ||
2756 | intel_state->src.x1 = plane_state->src_x; | |
2757 | intel_state->src.y1 = plane_state->src_y; | |
2758 | intel_state->src.x2 = plane_state->src_x + plane_state->src_w; | |
2759 | intel_state->src.y2 = plane_state->src_y + plane_state->src_h; | |
2760 | intel_state->dst.x1 = plane_state->crtc_x; | |
2761 | intel_state->dst.y1 = plane_state->crtc_y; | |
2762 | intel_state->dst.x2 = plane_state->crtc_x + plane_state->crtc_w; | |
2763 | intel_state->dst.y2 = plane_state->crtc_y + plane_state->crtc_h; | |
2764 | ||
2765 | obj = intel_fb_obj(fb); | |
2766 | if (obj->tiling_mode != I915_TILING_NONE) | |
2767 | dev_priv->preserve_bios_swizzle = true; | |
2768 | ||
2769 | drm_framebuffer_reference(fb); | |
2770 | primary->fb = primary->state->fb = fb; | |
2771 | primary->crtc = primary->state->crtc = &intel_crtc->base; | |
2772 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); | |
2773 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; | |
2774 | } | |
2775 | ||
2776 | static void i9xx_update_primary_plane(struct drm_plane *primary, | |
2777 | const struct intel_crtc_state *crtc_state, | |
2778 | const struct intel_plane_state *plane_state) | |
2779 | { | |
2780 | struct drm_device *dev = primary->dev; | |
2781 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2782 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
2783 | struct drm_framebuffer *fb = plane_state->base.fb; | |
2784 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
2785 | int plane = intel_crtc->plane; | |
2786 | u32 linear_offset; | |
2787 | u32 dspcntr; | |
2788 | i915_reg_t reg = DSPCNTR(plane); | |
2789 | unsigned int rotation = plane_state->base.rotation; | |
2790 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); | |
2791 | int x = plane_state->src.x1 >> 16; | |
2792 | int y = plane_state->src.y1 >> 16; | |
2793 | ||
2794 | dspcntr = DISPPLANE_GAMMA_ENABLE; | |
2795 | ||
2796 | dspcntr |= DISPLAY_PLANE_ENABLE; | |
2797 | ||
2798 | if (INTEL_INFO(dev)->gen < 4) { | |
2799 | if (intel_crtc->pipe == PIPE_B) | |
2800 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2801 | ||
2802 | /* pipesrc and dspsize control the size that is scaled from, | |
2803 | * which should always be the user's requested size. | |
2804 | */ | |
2805 | I915_WRITE(DSPSIZE(plane), | |
2806 | ((crtc_state->pipe_src_h - 1) << 16) | | |
2807 | (crtc_state->pipe_src_w - 1)); | |
2808 | I915_WRITE(DSPPOS(plane), 0); | |
2809 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { | |
2810 | I915_WRITE(PRIMSIZE(plane), | |
2811 | ((crtc_state->pipe_src_h - 1) << 16) | | |
2812 | (crtc_state->pipe_src_w - 1)); | |
2813 | I915_WRITE(PRIMPOS(plane), 0); | |
2814 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
2815 | } | |
2816 | ||
2817 | switch (fb->pixel_format) { | |
2818 | case DRM_FORMAT_C8: | |
2819 | dspcntr |= DISPPLANE_8BPP; | |
2820 | break; | |
2821 | case DRM_FORMAT_XRGB1555: | |
2822 | dspcntr |= DISPPLANE_BGRX555; | |
2823 | break; | |
2824 | case DRM_FORMAT_RGB565: | |
2825 | dspcntr |= DISPPLANE_BGRX565; | |
2826 | break; | |
2827 | case DRM_FORMAT_XRGB8888: | |
2828 | dspcntr |= DISPPLANE_BGRX888; | |
2829 | break; | |
2830 | case DRM_FORMAT_XBGR8888: | |
2831 | dspcntr |= DISPPLANE_RGBX888; | |
2832 | break; | |
2833 | case DRM_FORMAT_XRGB2101010: | |
2834 | dspcntr |= DISPPLANE_BGRX101010; | |
2835 | break; | |
2836 | case DRM_FORMAT_XBGR2101010: | |
2837 | dspcntr |= DISPPLANE_RGBX101010; | |
2838 | break; | |
2839 | default: | |
2840 | BUG(); | |
2841 | } | |
2842 | ||
2843 | if (INTEL_INFO(dev)->gen >= 4 && | |
2844 | obj->tiling_mode != I915_TILING_NONE) | |
2845 | dspcntr |= DISPPLANE_TILED; | |
2846 | ||
2847 | if (IS_G4X(dev)) | |
2848 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2849 | ||
2850 | linear_offset = y * fb->pitches[0] + x * cpp; | |
2851 | ||
2852 | if (INTEL_INFO(dev)->gen >= 4) { | |
2853 | intel_crtc->dspaddr_offset = | |
2854 | intel_compute_tile_offset(&x, &y, fb, 0, | |
2855 | fb->pitches[0], rotation); | |
2856 | linear_offset -= intel_crtc->dspaddr_offset; | |
2857 | } else { | |
2858 | intel_crtc->dspaddr_offset = linear_offset; | |
2859 | } | |
2860 | ||
2861 | if (rotation == BIT(DRM_ROTATE_180)) { | |
2862 | dspcntr |= DISPPLANE_ROTATE_180; | |
2863 | ||
2864 | x += (crtc_state->pipe_src_w - 1); | |
2865 | y += (crtc_state->pipe_src_h - 1); | |
2866 | ||
2867 | /* Finding the last pixel of the last line of the display | |
2868 | data and adding to linear_offset*/ | |
2869 | linear_offset += | |
2870 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + | |
2871 | (crtc_state->pipe_src_w - 1) * cpp; | |
2872 | } | |
2873 | ||
2874 | intel_crtc->adjusted_x = x; | |
2875 | intel_crtc->adjusted_y = y; | |
2876 | ||
2877 | I915_WRITE(reg, dspcntr); | |
2878 | ||
2879 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); | |
2880 | if (INTEL_INFO(dev)->gen >= 4) { | |
2881 | I915_WRITE(DSPSURF(plane), | |
2882 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
2883 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2884 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2885 | } else | |
2886 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); | |
2887 | POSTING_READ(reg); | |
2888 | } | |
2889 | ||
2890 | static void i9xx_disable_primary_plane(struct drm_plane *primary, | |
2891 | struct drm_crtc *crtc) | |
2892 | { | |
2893 | struct drm_device *dev = crtc->dev; | |
2894 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2895 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2896 | int plane = intel_crtc->plane; | |
2897 | ||
2898 | I915_WRITE(DSPCNTR(plane), 0); | |
2899 | if (INTEL_INFO(dev_priv)->gen >= 4) | |
2900 | I915_WRITE(DSPSURF(plane), 0); | |
2901 | else | |
2902 | I915_WRITE(DSPADDR(plane), 0); | |
2903 | POSTING_READ(DSPCNTR(plane)); | |
2904 | } | |
2905 | ||
2906 | static void ironlake_update_primary_plane(struct drm_plane *primary, | |
2907 | const struct intel_crtc_state *crtc_state, | |
2908 | const struct intel_plane_state *plane_state) | |
2909 | { | |
2910 | struct drm_device *dev = primary->dev; | |
2911 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2912 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
2913 | struct drm_framebuffer *fb = plane_state->base.fb; | |
2914 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
2915 | int plane = intel_crtc->plane; | |
2916 | u32 linear_offset; | |
2917 | u32 dspcntr; | |
2918 | i915_reg_t reg = DSPCNTR(plane); | |
2919 | unsigned int rotation = plane_state->base.rotation; | |
2920 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); | |
2921 | int x = plane_state->src.x1 >> 16; | |
2922 | int y = plane_state->src.y1 >> 16; | |
2923 | ||
2924 | dspcntr = DISPPLANE_GAMMA_ENABLE; | |
2925 | dspcntr |= DISPLAY_PLANE_ENABLE; | |
2926 | ||
2927 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2928 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
2929 | ||
2930 | switch (fb->pixel_format) { | |
2931 | case DRM_FORMAT_C8: | |
2932 | dspcntr |= DISPPLANE_8BPP; | |
2933 | break; | |
2934 | case DRM_FORMAT_RGB565: | |
2935 | dspcntr |= DISPPLANE_BGRX565; | |
2936 | break; | |
2937 | case DRM_FORMAT_XRGB8888: | |
2938 | dspcntr |= DISPPLANE_BGRX888; | |
2939 | break; | |
2940 | case DRM_FORMAT_XBGR8888: | |
2941 | dspcntr |= DISPPLANE_RGBX888; | |
2942 | break; | |
2943 | case DRM_FORMAT_XRGB2101010: | |
2944 | dspcntr |= DISPPLANE_BGRX101010; | |
2945 | break; | |
2946 | case DRM_FORMAT_XBGR2101010: | |
2947 | dspcntr |= DISPPLANE_RGBX101010; | |
2948 | break; | |
2949 | default: | |
2950 | BUG(); | |
2951 | } | |
2952 | ||
2953 | if (obj->tiling_mode != I915_TILING_NONE) | |
2954 | dspcntr |= DISPPLANE_TILED; | |
2955 | ||
2956 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) | |
2957 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2958 | ||
2959 | linear_offset = y * fb->pitches[0] + x * cpp; | |
2960 | intel_crtc->dspaddr_offset = | |
2961 | intel_compute_tile_offset(&x, &y, fb, 0, | |
2962 | fb->pitches[0], rotation); | |
2963 | linear_offset -= intel_crtc->dspaddr_offset; | |
2964 | if (rotation == BIT(DRM_ROTATE_180)) { | |
2965 | dspcntr |= DISPPLANE_ROTATE_180; | |
2966 | ||
2967 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
2968 | x += (crtc_state->pipe_src_w - 1); | |
2969 | y += (crtc_state->pipe_src_h - 1); | |
2970 | ||
2971 | /* Finding the last pixel of the last line of the display | |
2972 | data and adding to linear_offset*/ | |
2973 | linear_offset += | |
2974 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + | |
2975 | (crtc_state->pipe_src_w - 1) * cpp; | |
2976 | } | |
2977 | } | |
2978 | ||
2979 | intel_crtc->adjusted_x = x; | |
2980 | intel_crtc->adjusted_y = y; | |
2981 | ||
2982 | I915_WRITE(reg, dspcntr); | |
2983 | ||
2984 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); | |
2985 | I915_WRITE(DSPSURF(plane), | |
2986 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
2987 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
2988 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); | |
2989 | } else { | |
2990 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2991 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2992 | } | |
2993 | POSTING_READ(reg); | |
2994 | } | |
2995 | ||
2996 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, | |
2997 | uint64_t fb_modifier, uint32_t pixel_format) | |
2998 | { | |
2999 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { | |
3000 | return 64; | |
3001 | } else { | |
3002 | int cpp = drm_format_plane_cpp(pixel_format, 0); | |
3003 | ||
3004 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); | |
3005 | } | |
3006 | } | |
3007 | ||
3008 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, | |
3009 | struct drm_i915_gem_object *obj, | |
3010 | unsigned int plane) | |
3011 | { | |
3012 | struct i915_ggtt_view view; | |
3013 | struct i915_vma *vma; | |
3014 | u64 offset; | |
3015 | ||
3016 | intel_fill_fb_ggtt_view(&view, intel_plane->base.state->fb, | |
3017 | intel_plane->base.state->rotation); | |
3018 | ||
3019 | vma = i915_gem_obj_to_ggtt_view(obj, &view); | |
3020 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", | |
3021 | view.type)) | |
3022 | return -1; | |
3023 | ||
3024 | offset = vma->node.start; | |
3025 | ||
3026 | if (plane == 1) { | |
3027 | offset += vma->ggtt_view.params.rotated.uv_start_page * | |
3028 | PAGE_SIZE; | |
3029 | } | |
3030 | ||
3031 | WARN_ON(upper_32_bits(offset)); | |
3032 | ||
3033 | return lower_32_bits(offset); | |
3034 | } | |
3035 | ||
3036 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) | |
3037 | { | |
3038 | struct drm_device *dev = intel_crtc->base.dev; | |
3039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3040 | ||
3041 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
3042 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
3043 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
3044 | } | |
3045 | ||
3046 | /* | |
3047 | * This function detaches (aka. unbinds) unused scalers in hardware | |
3048 | */ | |
3049 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) | |
3050 | { | |
3051 | struct intel_crtc_scaler_state *scaler_state; | |
3052 | int i; | |
3053 | ||
3054 | scaler_state = &intel_crtc->config->scaler_state; | |
3055 | ||
3056 | /* loop through and disable scalers that aren't in use */ | |
3057 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
3058 | if (!scaler_state->scalers[i].in_use) | |
3059 | skl_detach_scaler(intel_crtc, i); | |
3060 | } | |
3061 | } | |
3062 | ||
3063 | u32 skl_plane_ctl_format(uint32_t pixel_format) | |
3064 | { | |
3065 | switch (pixel_format) { | |
3066 | case DRM_FORMAT_C8: | |
3067 | return PLANE_CTL_FORMAT_INDEXED; | |
3068 | case DRM_FORMAT_RGB565: | |
3069 | return PLANE_CTL_FORMAT_RGB_565; | |
3070 | case DRM_FORMAT_XBGR8888: | |
3071 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; | |
3072 | case DRM_FORMAT_XRGB8888: | |
3073 | return PLANE_CTL_FORMAT_XRGB_8888; | |
3074 | /* | |
3075 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
3076 | * to be already pre-multiplied. We need to add a knob (or a different | |
3077 | * DRM_FORMAT) for user-space to configure that. | |
3078 | */ | |
3079 | case DRM_FORMAT_ABGR8888: | |
3080 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | | |
3081 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; | |
3082 | case DRM_FORMAT_ARGB8888: | |
3083 | return PLANE_CTL_FORMAT_XRGB_8888 | | |
3084 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; | |
3085 | case DRM_FORMAT_XRGB2101010: | |
3086 | return PLANE_CTL_FORMAT_XRGB_2101010; | |
3087 | case DRM_FORMAT_XBGR2101010: | |
3088 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; | |
3089 | case DRM_FORMAT_YUYV: | |
3090 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; | |
3091 | case DRM_FORMAT_YVYU: | |
3092 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; | |
3093 | case DRM_FORMAT_UYVY: | |
3094 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; | |
3095 | case DRM_FORMAT_VYUY: | |
3096 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; | |
3097 | default: | |
3098 | MISSING_CASE(pixel_format); | |
3099 | } | |
3100 | ||
3101 | return 0; | |
3102 | } | |
3103 | ||
3104 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) | |
3105 | { | |
3106 | switch (fb_modifier) { | |
3107 | case DRM_FORMAT_MOD_NONE: | |
3108 | break; | |
3109 | case I915_FORMAT_MOD_X_TILED: | |
3110 | return PLANE_CTL_TILED_X; | |
3111 | case I915_FORMAT_MOD_Y_TILED: | |
3112 | return PLANE_CTL_TILED_Y; | |
3113 | case I915_FORMAT_MOD_Yf_TILED: | |
3114 | return PLANE_CTL_TILED_YF; | |
3115 | default: | |
3116 | MISSING_CASE(fb_modifier); | |
3117 | } | |
3118 | ||
3119 | return 0; | |
3120 | } | |
3121 | ||
3122 | u32 skl_plane_ctl_rotation(unsigned int rotation) | |
3123 | { | |
3124 | switch (rotation) { | |
3125 | case BIT(DRM_ROTATE_0): | |
3126 | break; | |
3127 | /* | |
3128 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3129 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3130 | */ | |
3131 | case BIT(DRM_ROTATE_90): | |
3132 | return PLANE_CTL_ROTATE_270; | |
3133 | case BIT(DRM_ROTATE_180): | |
3134 | return PLANE_CTL_ROTATE_180; | |
3135 | case BIT(DRM_ROTATE_270): | |
3136 | return PLANE_CTL_ROTATE_90; | |
3137 | default: | |
3138 | MISSING_CASE(rotation); | |
3139 | } | |
3140 | ||
3141 | return 0; | |
3142 | } | |
3143 | ||
3144 | static void skylake_update_primary_plane(struct drm_plane *plane, | |
3145 | const struct intel_crtc_state *crtc_state, | |
3146 | const struct intel_plane_state *plane_state) | |
3147 | { | |
3148 | struct drm_device *dev = plane->dev; | |
3149 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3150 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
3151 | struct drm_framebuffer *fb = plane_state->base.fb; | |
3152 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
3153 | int pipe = intel_crtc->pipe; | |
3154 | u32 plane_ctl, stride_div, stride; | |
3155 | u32 tile_height, plane_offset, plane_size; | |
3156 | unsigned int rotation = plane_state->base.rotation; | |
3157 | int x_offset, y_offset; | |
3158 | u32 surf_addr; | |
3159 | int scaler_id = plane_state->scaler_id; | |
3160 | int src_x = plane_state->src.x1 >> 16; | |
3161 | int src_y = plane_state->src.y1 >> 16; | |
3162 | int src_w = drm_rect_width(&plane_state->src) >> 16; | |
3163 | int src_h = drm_rect_height(&plane_state->src) >> 16; | |
3164 | int dst_x = plane_state->dst.x1; | |
3165 | int dst_y = plane_state->dst.y1; | |
3166 | int dst_w = drm_rect_width(&plane_state->dst); | |
3167 | int dst_h = drm_rect_height(&plane_state->dst); | |
3168 | ||
3169 | plane_ctl = PLANE_CTL_ENABLE | | |
3170 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3171 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3172 | ||
3173 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3174 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3175 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3176 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3177 | ||
3178 | stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0], | |
3179 | fb->pixel_format); | |
3180 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); | |
3181 | ||
3182 | WARN_ON(drm_rect_width(&plane_state->src) == 0); | |
3183 | ||
3184 | if (intel_rotation_90_or_270(rotation)) { | |
3185 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); | |
3186 | ||
3187 | /* stride = Surface height in tiles */ | |
3188 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp); | |
3189 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
3190 | x_offset = stride * tile_height - src_y - src_h; | |
3191 | y_offset = src_x; | |
3192 | plane_size = (src_w - 1) << 16 | (src_h - 1); | |
3193 | } else { | |
3194 | stride = fb->pitches[0] / stride_div; | |
3195 | x_offset = src_x; | |
3196 | y_offset = src_y; | |
3197 | plane_size = (src_h - 1) << 16 | (src_w - 1); | |
3198 | } | |
3199 | plane_offset = y_offset << 16 | x_offset; | |
3200 | ||
3201 | intel_crtc->adjusted_x = x_offset; | |
3202 | intel_crtc->adjusted_y = y_offset; | |
3203 | ||
3204 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); | |
3205 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); | |
3206 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3207 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
3208 | ||
3209 | if (scaler_id >= 0) { | |
3210 | uint32_t ps_ctrl = 0; | |
3211 | ||
3212 | WARN_ON(!dst_w || !dst_h); | |
3213 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3214 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3215 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3216 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3217 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3218 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3219 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3220 | } else { | |
3221 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3222 | } | |
3223 | ||
3224 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); | |
3225 | ||
3226 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3227 | } | |
3228 | ||
3229 | static void skylake_disable_primary_plane(struct drm_plane *primary, | |
3230 | struct drm_crtc *crtc) | |
3231 | { | |
3232 | struct drm_device *dev = crtc->dev; | |
3233 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3234 | int pipe = to_intel_crtc(crtc)->pipe; | |
3235 | ||
3236 | I915_WRITE(PLANE_CTL(pipe, 0), 0); | |
3237 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3238 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3239 | } | |
3240 | ||
3241 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ | |
3242 | static int | |
3243 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3244 | int x, int y, enum mode_set_atomic state) | |
3245 | { | |
3246 | /* Support for kgdboc is disabled, this needs a major rework. */ | |
3247 | DRM_ERROR("legacy panic handler not supported any more.\n"); | |
3248 | ||
3249 | return -ENODEV; | |
3250 | } | |
3251 | ||
3252 | static void intel_complete_page_flips(struct drm_device *dev) | |
3253 | { | |
3254 | struct drm_crtc *crtc; | |
3255 | ||
3256 | for_each_crtc(dev, crtc) { | |
3257 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3258 | enum plane plane = intel_crtc->plane; | |
3259 | ||
3260 | intel_prepare_page_flip(dev, plane); | |
3261 | intel_finish_page_flip_plane(dev, plane); | |
3262 | } | |
3263 | } | |
3264 | ||
3265 | static void intel_update_primary_planes(struct drm_device *dev) | |
3266 | { | |
3267 | struct drm_crtc *crtc; | |
3268 | ||
3269 | for_each_crtc(dev, crtc) { | |
3270 | struct intel_plane *plane = to_intel_plane(crtc->primary); | |
3271 | struct intel_plane_state *plane_state; | |
3272 | ||
3273 | drm_modeset_lock_crtc(crtc, &plane->base); | |
3274 | plane_state = to_intel_plane_state(plane->base.state); | |
3275 | ||
3276 | if (plane_state->visible) | |
3277 | plane->update_plane(&plane->base, | |
3278 | to_intel_crtc_state(crtc->state), | |
3279 | plane_state); | |
3280 | ||
3281 | drm_modeset_unlock_crtc(crtc); | |
3282 | } | |
3283 | } | |
3284 | ||
3285 | void intel_prepare_reset(struct drm_device *dev) | |
3286 | { | |
3287 | /* no reset support for gen2 */ | |
3288 | if (IS_GEN2(dev)) | |
3289 | return; | |
3290 | ||
3291 | /* reset doesn't touch the display */ | |
3292 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3293 | return; | |
3294 | ||
3295 | drm_modeset_lock_all(dev); | |
3296 | /* | |
3297 | * Disabling the crtcs gracefully seems nicer. Also the | |
3298 | * g33 docs say we should at least disable all the planes. | |
3299 | */ | |
3300 | intel_display_suspend(dev); | |
3301 | } | |
3302 | ||
3303 | void intel_finish_reset(struct drm_device *dev) | |
3304 | { | |
3305 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3306 | ||
3307 | /* | |
3308 | * Flips in the rings will be nuked by the reset, | |
3309 | * so complete all pending flips so that user space | |
3310 | * will get its events and not get stuck. | |
3311 | */ | |
3312 | intel_complete_page_flips(dev); | |
3313 | ||
3314 | /* no reset support for gen2 */ | |
3315 | if (IS_GEN2(dev)) | |
3316 | return; | |
3317 | ||
3318 | /* reset doesn't touch the display */ | |
3319 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3320 | /* | |
3321 | * Flips in the rings have been nuked by the reset, | |
3322 | * so update the base address of all primary | |
3323 | * planes to the the last fb to make sure we're | |
3324 | * showing the correct fb after a reset. | |
3325 | * | |
3326 | * FIXME: Atomic will make this obsolete since we won't schedule | |
3327 | * CS-based flips (which might get lost in gpu resets) any more. | |
3328 | */ | |
3329 | intel_update_primary_planes(dev); | |
3330 | return; | |
3331 | } | |
3332 | ||
3333 | /* | |
3334 | * The display has been reset as well, | |
3335 | * so need a full re-initialization. | |
3336 | */ | |
3337 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3338 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3339 | ||
3340 | intel_modeset_init_hw(dev); | |
3341 | ||
3342 | spin_lock_irq(&dev_priv->irq_lock); | |
3343 | if (dev_priv->display.hpd_irq_setup) | |
3344 | dev_priv->display.hpd_irq_setup(dev); | |
3345 | spin_unlock_irq(&dev_priv->irq_lock); | |
3346 | ||
3347 | intel_display_resume(dev); | |
3348 | ||
3349 | intel_hpd_init(dev_priv); | |
3350 | ||
3351 | drm_modeset_unlock_all(dev); | |
3352 | } | |
3353 | ||
3354 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) | |
3355 | { | |
3356 | struct drm_device *dev = crtc->dev; | |
3357 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3358 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3359 | bool pending; | |
3360 | ||
3361 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3362 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3363 | return false; | |
3364 | ||
3365 | spin_lock_irq(&dev->event_lock); | |
3366 | pending = to_intel_crtc(crtc)->unpin_work != NULL; | |
3367 | spin_unlock_irq(&dev->event_lock); | |
3368 | ||
3369 | return pending; | |
3370 | } | |
3371 | ||
3372 | static void intel_update_pipe_config(struct intel_crtc *crtc, | |
3373 | struct intel_crtc_state *old_crtc_state) | |
3374 | { | |
3375 | struct drm_device *dev = crtc->base.dev; | |
3376 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3377 | struct intel_crtc_state *pipe_config = | |
3378 | to_intel_crtc_state(crtc->base.state); | |
3379 | ||
3380 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ | |
3381 | crtc->base.mode = crtc->base.state->mode; | |
3382 | ||
3383 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", | |
3384 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, | |
3385 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
3386 | ||
3387 | if (HAS_DDI(dev)) | |
3388 | intel_set_pipe_csc(&crtc->base); | |
3389 | ||
3390 | /* | |
3391 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3392 | * that in compute_mode_changes we check the native mode (not the pfit | |
3393 | * mode) to see if we can flip rather than do a full mode set. In the | |
3394 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3395 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3396 | * sized surface. | |
3397 | */ | |
3398 | ||
3399 | I915_WRITE(PIPESRC(crtc->pipe), | |
3400 | ((pipe_config->pipe_src_w - 1) << 16) | | |
3401 | (pipe_config->pipe_src_h - 1)); | |
3402 | ||
3403 | /* on skylake this is done by detaching scalers */ | |
3404 | if (INTEL_INFO(dev)->gen >= 9) { | |
3405 | skl_detach_scalers(crtc); | |
3406 | ||
3407 | if (pipe_config->pch_pfit.enabled) | |
3408 | skylake_pfit_enable(crtc); | |
3409 | } else if (HAS_PCH_SPLIT(dev)) { | |
3410 | if (pipe_config->pch_pfit.enabled) | |
3411 | ironlake_pfit_enable(crtc); | |
3412 | else if (old_crtc_state->pch_pfit.enabled) | |
3413 | ironlake_pfit_disable(crtc, true); | |
3414 | } | |
3415 | } | |
3416 | ||
3417 | static void intel_fdi_normal_train(struct drm_crtc *crtc) | |
3418 | { | |
3419 | struct drm_device *dev = crtc->dev; | |
3420 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3422 | int pipe = intel_crtc->pipe; | |
3423 | i915_reg_t reg; | |
3424 | u32 temp; | |
3425 | ||
3426 | /* enable normal train */ | |
3427 | reg = FDI_TX_CTL(pipe); | |
3428 | temp = I915_READ(reg); | |
3429 | if (IS_IVYBRIDGE(dev)) { | |
3430 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; | |
3431 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
3432 | } else { | |
3433 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3434 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
3435 | } | |
3436 | I915_WRITE(reg, temp); | |
3437 | ||
3438 | reg = FDI_RX_CTL(pipe); | |
3439 | temp = I915_READ(reg); | |
3440 | if (HAS_PCH_CPT(dev)) { | |
3441 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3442 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3443 | } else { | |
3444 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3445 | temp |= FDI_LINK_TRAIN_NONE; | |
3446 | } | |
3447 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3448 | ||
3449 | /* wait one idle pattern time */ | |
3450 | POSTING_READ(reg); | |
3451 | udelay(1000); | |
3452 | ||
3453 | /* IVB wants error correction enabled */ | |
3454 | if (IS_IVYBRIDGE(dev)) | |
3455 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3456 | FDI_FE_ERRC_ENABLE); | |
3457 | } | |
3458 | ||
3459 | /* The FDI link training functions for ILK/Ibexpeak. */ | |
3460 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3461 | { | |
3462 | struct drm_device *dev = crtc->dev; | |
3463 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3464 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3465 | int pipe = intel_crtc->pipe; | |
3466 | i915_reg_t reg; | |
3467 | u32 temp, tries; | |
3468 | ||
3469 | /* FDI needs bits from pipe first */ | |
3470 | assert_pipe_enabled(dev_priv, pipe); | |
3471 | ||
3472 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3473 | for train result */ | |
3474 | reg = FDI_RX_IMR(pipe); | |
3475 | temp = I915_READ(reg); | |
3476 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3477 | temp &= ~FDI_RX_BIT_LOCK; | |
3478 | I915_WRITE(reg, temp); | |
3479 | I915_READ(reg); | |
3480 | udelay(150); | |
3481 | ||
3482 | /* enable CPU FDI TX and PCH FDI RX */ | |
3483 | reg = FDI_TX_CTL(pipe); | |
3484 | temp = I915_READ(reg); | |
3485 | temp &= ~FDI_DP_PORT_WIDTH_MASK; | |
3486 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); | |
3487 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3488 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3489 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
3490 | ||
3491 | reg = FDI_RX_CTL(pipe); | |
3492 | temp = I915_READ(reg); | |
3493 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3494 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3495 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
3496 | ||
3497 | POSTING_READ(reg); | |
3498 | udelay(150); | |
3499 | ||
3500 | /* Ironlake workaround, enable clock pointer after FDI enable*/ | |
3501 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); | |
3502 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3503 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
3504 | ||
3505 | reg = FDI_RX_IIR(pipe); | |
3506 | for (tries = 0; tries < 5; tries++) { | |
3507 | temp = I915_READ(reg); | |
3508 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3509 | ||
3510 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3511 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3512 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3513 | break; | |
3514 | } | |
3515 | } | |
3516 | if (tries == 5) | |
3517 | DRM_ERROR("FDI train 1 fail!\n"); | |
3518 | ||
3519 | /* Train 2 */ | |
3520 | reg = FDI_TX_CTL(pipe); | |
3521 | temp = I915_READ(reg); | |
3522 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3523 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3524 | I915_WRITE(reg, temp); | |
3525 | ||
3526 | reg = FDI_RX_CTL(pipe); | |
3527 | temp = I915_READ(reg); | |
3528 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3529 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3530 | I915_WRITE(reg, temp); | |
3531 | ||
3532 | POSTING_READ(reg); | |
3533 | udelay(150); | |
3534 | ||
3535 | reg = FDI_RX_IIR(pipe); | |
3536 | for (tries = 0; tries < 5; tries++) { | |
3537 | temp = I915_READ(reg); | |
3538 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3539 | ||
3540 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3541 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3542 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3543 | break; | |
3544 | } | |
3545 | } | |
3546 | if (tries == 5) | |
3547 | DRM_ERROR("FDI train 2 fail!\n"); | |
3548 | ||
3549 | DRM_DEBUG_KMS("FDI train done\n"); | |
3550 | ||
3551 | } | |
3552 | ||
3553 | static const int snb_b_fdi_train_param[] = { | |
3554 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, | |
3555 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3556 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3557 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3558 | }; | |
3559 | ||
3560 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3561 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3562 | { | |
3563 | struct drm_device *dev = crtc->dev; | |
3564 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3565 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3566 | int pipe = intel_crtc->pipe; | |
3567 | i915_reg_t reg; | |
3568 | u32 temp, i, retry; | |
3569 | ||
3570 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3571 | for train result */ | |
3572 | reg = FDI_RX_IMR(pipe); | |
3573 | temp = I915_READ(reg); | |
3574 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3575 | temp &= ~FDI_RX_BIT_LOCK; | |
3576 | I915_WRITE(reg, temp); | |
3577 | ||
3578 | POSTING_READ(reg); | |
3579 | udelay(150); | |
3580 | ||
3581 | /* enable CPU FDI TX and PCH FDI RX */ | |
3582 | reg = FDI_TX_CTL(pipe); | |
3583 | temp = I915_READ(reg); | |
3584 | temp &= ~FDI_DP_PORT_WIDTH_MASK; | |
3585 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); | |
3586 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3587 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3588 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3589 | /* SNB-B */ | |
3590 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3591 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
3592 | ||
3593 | I915_WRITE(FDI_RX_MISC(pipe), | |
3594 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3595 | ||
3596 | reg = FDI_RX_CTL(pipe); | |
3597 | temp = I915_READ(reg); | |
3598 | if (HAS_PCH_CPT(dev)) { | |
3599 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3600 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3601 | } else { | |
3602 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3603 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3604 | } | |
3605 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
3606 | ||
3607 | POSTING_READ(reg); | |
3608 | udelay(150); | |
3609 | ||
3610 | for (i = 0; i < 4; i++) { | |
3611 | reg = FDI_TX_CTL(pipe); | |
3612 | temp = I915_READ(reg); | |
3613 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3614 | temp |= snb_b_fdi_train_param[i]; | |
3615 | I915_WRITE(reg, temp); | |
3616 | ||
3617 | POSTING_READ(reg); | |
3618 | udelay(500); | |
3619 | ||
3620 | for (retry = 0; retry < 5; retry++) { | |
3621 | reg = FDI_RX_IIR(pipe); | |
3622 | temp = I915_READ(reg); | |
3623 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3624 | if (temp & FDI_RX_BIT_LOCK) { | |
3625 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3626 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3627 | break; | |
3628 | } | |
3629 | udelay(50); | |
3630 | } | |
3631 | if (retry < 5) | |
3632 | break; | |
3633 | } | |
3634 | if (i == 4) | |
3635 | DRM_ERROR("FDI train 1 fail!\n"); | |
3636 | ||
3637 | /* Train 2 */ | |
3638 | reg = FDI_TX_CTL(pipe); | |
3639 | temp = I915_READ(reg); | |
3640 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3641 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3642 | if (IS_GEN6(dev)) { | |
3643 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3644 | /* SNB-B */ | |
3645 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3646 | } | |
3647 | I915_WRITE(reg, temp); | |
3648 | ||
3649 | reg = FDI_RX_CTL(pipe); | |
3650 | temp = I915_READ(reg); | |
3651 | if (HAS_PCH_CPT(dev)) { | |
3652 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3653 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3654 | } else { | |
3655 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3656 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3657 | } | |
3658 | I915_WRITE(reg, temp); | |
3659 | ||
3660 | POSTING_READ(reg); | |
3661 | udelay(150); | |
3662 | ||
3663 | for (i = 0; i < 4; i++) { | |
3664 | reg = FDI_TX_CTL(pipe); | |
3665 | temp = I915_READ(reg); | |
3666 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3667 | temp |= snb_b_fdi_train_param[i]; | |
3668 | I915_WRITE(reg, temp); | |
3669 | ||
3670 | POSTING_READ(reg); | |
3671 | udelay(500); | |
3672 | ||
3673 | for (retry = 0; retry < 5; retry++) { | |
3674 | reg = FDI_RX_IIR(pipe); | |
3675 | temp = I915_READ(reg); | |
3676 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3677 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3678 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3679 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3680 | break; | |
3681 | } | |
3682 | udelay(50); | |
3683 | } | |
3684 | if (retry < 5) | |
3685 | break; | |
3686 | } | |
3687 | if (i == 4) | |
3688 | DRM_ERROR("FDI train 2 fail!\n"); | |
3689 | ||
3690 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3691 | } | |
3692 | ||
3693 | /* Manual link training for Ivy Bridge A0 parts */ | |
3694 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3695 | { | |
3696 | struct drm_device *dev = crtc->dev; | |
3697 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3698 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3699 | int pipe = intel_crtc->pipe; | |
3700 | i915_reg_t reg; | |
3701 | u32 temp, i, j; | |
3702 | ||
3703 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3704 | for train result */ | |
3705 | reg = FDI_RX_IMR(pipe); | |
3706 | temp = I915_READ(reg); | |
3707 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3708 | temp &= ~FDI_RX_BIT_LOCK; | |
3709 | I915_WRITE(reg, temp); | |
3710 | ||
3711 | POSTING_READ(reg); | |
3712 | udelay(150); | |
3713 | ||
3714 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", | |
3715 | I915_READ(FDI_RX_IIR(pipe))); | |
3716 | ||
3717 | /* Try each vswing and preemphasis setting twice before moving on */ | |
3718 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3719 | /* disable first in case we need to retry */ | |
3720 | reg = FDI_TX_CTL(pipe); | |
3721 | temp = I915_READ(reg); | |
3722 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3723 | temp &= ~FDI_TX_ENABLE; | |
3724 | I915_WRITE(reg, temp); | |
3725 | ||
3726 | reg = FDI_RX_CTL(pipe); | |
3727 | temp = I915_READ(reg); | |
3728 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3729 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3730 | temp &= ~FDI_RX_ENABLE; | |
3731 | I915_WRITE(reg, temp); | |
3732 | ||
3733 | /* enable CPU FDI TX and PCH FDI RX */ | |
3734 | reg = FDI_TX_CTL(pipe); | |
3735 | temp = I915_READ(reg); | |
3736 | temp &= ~FDI_DP_PORT_WIDTH_MASK; | |
3737 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); | |
3738 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; | |
3739 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3740 | temp |= snb_b_fdi_train_param[j/2]; | |
3741 | temp |= FDI_COMPOSITE_SYNC; | |
3742 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
3743 | ||
3744 | I915_WRITE(FDI_RX_MISC(pipe), | |
3745 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3746 | ||
3747 | reg = FDI_RX_CTL(pipe); | |
3748 | temp = I915_READ(reg); | |
3749 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3750 | temp |= FDI_COMPOSITE_SYNC; | |
3751 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
3752 | ||
3753 | POSTING_READ(reg); | |
3754 | udelay(1); /* should be 0.5us */ | |
3755 | ||
3756 | for (i = 0; i < 4; i++) { | |
3757 | reg = FDI_RX_IIR(pipe); | |
3758 | temp = I915_READ(reg); | |
3759 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3760 | ||
3761 | if (temp & FDI_RX_BIT_LOCK || | |
3762 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3763 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3764 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3765 | i); | |
3766 | break; | |
3767 | } | |
3768 | udelay(1); /* should be 0.5us */ | |
3769 | } | |
3770 | if (i == 4) { | |
3771 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3772 | continue; | |
3773 | } | |
3774 | ||
3775 | /* Train 2 */ | |
3776 | reg = FDI_TX_CTL(pipe); | |
3777 | temp = I915_READ(reg); | |
3778 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; | |
3779 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3780 | I915_WRITE(reg, temp); | |
3781 | ||
3782 | reg = FDI_RX_CTL(pipe); | |
3783 | temp = I915_READ(reg); | |
3784 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3785 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3786 | I915_WRITE(reg, temp); | |
3787 | ||
3788 | POSTING_READ(reg); | |
3789 | udelay(2); /* should be 1.5us */ | |
3790 | ||
3791 | for (i = 0; i < 4; i++) { | |
3792 | reg = FDI_RX_IIR(pipe); | |
3793 | temp = I915_READ(reg); | |
3794 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3795 | ||
3796 | if (temp & FDI_RX_SYMBOL_LOCK || | |
3797 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3798 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3799 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3800 | i); | |
3801 | goto train_done; | |
3802 | } | |
3803 | udelay(2); /* should be 1.5us */ | |
3804 | } | |
3805 | if (i == 4) | |
3806 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
3807 | } | |
3808 | ||
3809 | train_done: | |
3810 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3811 | } | |
3812 | ||
3813 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) | |
3814 | { | |
3815 | struct drm_device *dev = intel_crtc->base.dev; | |
3816 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3817 | int pipe = intel_crtc->pipe; | |
3818 | i915_reg_t reg; | |
3819 | u32 temp; | |
3820 | ||
3821 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ | |
3822 | reg = FDI_RX_CTL(pipe); | |
3823 | temp = I915_READ(reg); | |
3824 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); | |
3825 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); | |
3826 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; | |
3827 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); | |
3828 | ||
3829 | POSTING_READ(reg); | |
3830 | udelay(200); | |
3831 | ||
3832 | /* Switch from Rawclk to PCDclk */ | |
3833 | temp = I915_READ(reg); | |
3834 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3835 | ||
3836 | POSTING_READ(reg); | |
3837 | udelay(200); | |
3838 | ||
3839 | /* Enable CPU FDI TX PLL, always on for Ironlake */ | |
3840 | reg = FDI_TX_CTL(pipe); | |
3841 | temp = I915_READ(reg); | |
3842 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3843 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
3844 | ||
3845 | POSTING_READ(reg); | |
3846 | udelay(100); | |
3847 | } | |
3848 | } | |
3849 | ||
3850 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) | |
3851 | { | |
3852 | struct drm_device *dev = intel_crtc->base.dev; | |
3853 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3854 | int pipe = intel_crtc->pipe; | |
3855 | i915_reg_t reg; | |
3856 | u32 temp; | |
3857 | ||
3858 | /* Switch from PCDclk to Rawclk */ | |
3859 | reg = FDI_RX_CTL(pipe); | |
3860 | temp = I915_READ(reg); | |
3861 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3862 | ||
3863 | /* Disable CPU FDI TX PLL */ | |
3864 | reg = FDI_TX_CTL(pipe); | |
3865 | temp = I915_READ(reg); | |
3866 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3867 | ||
3868 | POSTING_READ(reg); | |
3869 | udelay(100); | |
3870 | ||
3871 | reg = FDI_RX_CTL(pipe); | |
3872 | temp = I915_READ(reg); | |
3873 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3874 | ||
3875 | /* Wait for the clocks to turn off. */ | |
3876 | POSTING_READ(reg); | |
3877 | udelay(100); | |
3878 | } | |
3879 | ||
3880 | static void ironlake_fdi_disable(struct drm_crtc *crtc) | |
3881 | { | |
3882 | struct drm_device *dev = crtc->dev; | |
3883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3884 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3885 | int pipe = intel_crtc->pipe; | |
3886 | i915_reg_t reg; | |
3887 | u32 temp; | |
3888 | ||
3889 | /* disable CPU FDI tx and PCH FDI rx */ | |
3890 | reg = FDI_TX_CTL(pipe); | |
3891 | temp = I915_READ(reg); | |
3892 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3893 | POSTING_READ(reg); | |
3894 | ||
3895 | reg = FDI_RX_CTL(pipe); | |
3896 | temp = I915_READ(reg); | |
3897 | temp &= ~(0x7 << 16); | |
3898 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; | |
3899 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); | |
3900 | ||
3901 | POSTING_READ(reg); | |
3902 | udelay(100); | |
3903 | ||
3904 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
3905 | if (HAS_PCH_IBX(dev)) | |
3906 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); | |
3907 | ||
3908 | /* still set train pattern 1 */ | |
3909 | reg = FDI_TX_CTL(pipe); | |
3910 | temp = I915_READ(reg); | |
3911 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3912 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3913 | I915_WRITE(reg, temp); | |
3914 | ||
3915 | reg = FDI_RX_CTL(pipe); | |
3916 | temp = I915_READ(reg); | |
3917 | if (HAS_PCH_CPT(dev)) { | |
3918 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3919 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3920 | } else { | |
3921 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3922 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3923 | } | |
3924 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3925 | temp &= ~(0x07 << 16); | |
3926 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; | |
3927 | I915_WRITE(reg, temp); | |
3928 | ||
3929 | POSTING_READ(reg); | |
3930 | udelay(100); | |
3931 | } | |
3932 | ||
3933 | bool intel_has_pending_fb_unpin(struct drm_device *dev) | |
3934 | { | |
3935 | struct intel_crtc *crtc; | |
3936 | ||
3937 | /* Note that we don't need to be called with mode_config.lock here | |
3938 | * as our list of CRTC objects is static for the lifetime of the | |
3939 | * device and so cannot disappear as we iterate. Similarly, we can | |
3940 | * happily treat the predicates as racy, atomic checks as userspace | |
3941 | * cannot claim and pin a new fb without at least acquring the | |
3942 | * struct_mutex and so serialising with us. | |
3943 | */ | |
3944 | for_each_intel_crtc(dev, crtc) { | |
3945 | if (atomic_read(&crtc->unpin_work_count) == 0) | |
3946 | continue; | |
3947 | ||
3948 | if (crtc->unpin_work) | |
3949 | intel_wait_for_vblank(dev, crtc->pipe); | |
3950 | ||
3951 | return true; | |
3952 | } | |
3953 | ||
3954 | return false; | |
3955 | } | |
3956 | ||
3957 | static void page_flip_completed(struct intel_crtc *intel_crtc) | |
3958 | { | |
3959 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3960 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3961 | ||
3962 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3963 | smp_rmb(); | |
3964 | intel_crtc->unpin_work = NULL; | |
3965 | ||
3966 | if (work->event) | |
3967 | drm_send_vblank_event(intel_crtc->base.dev, | |
3968 | intel_crtc->pipe, | |
3969 | work->event); | |
3970 | ||
3971 | drm_crtc_vblank_put(&intel_crtc->base); | |
3972 | ||
3973 | wake_up_all(&dev_priv->pending_flip_queue); | |
3974 | queue_work(dev_priv->wq, &work->work); | |
3975 | ||
3976 | trace_i915_flip_complete(intel_crtc->plane, | |
3977 | work->pending_flip_obj); | |
3978 | } | |
3979 | ||
3980 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) | |
3981 | { | |
3982 | struct drm_device *dev = crtc->dev; | |
3983 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3984 | long ret; | |
3985 | ||
3986 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); | |
3987 | ||
3988 | ret = wait_event_interruptible_timeout( | |
3989 | dev_priv->pending_flip_queue, | |
3990 | !intel_crtc_has_pending_flip(crtc), | |
3991 | 60*HZ); | |
3992 | ||
3993 | if (ret < 0) | |
3994 | return ret; | |
3995 | ||
3996 | if (ret == 0) { | |
3997 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3998 | ||
3999 | spin_lock_irq(&dev->event_lock); | |
4000 | if (intel_crtc->unpin_work) { | |
4001 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
4002 | page_flip_completed(intel_crtc); | |
4003 | } | |
4004 | spin_unlock_irq(&dev->event_lock); | |
4005 | } | |
4006 | ||
4007 | return 0; | |
4008 | } | |
4009 | ||
4010 | static void lpt_disable_iclkip(struct drm_i915_private *dev_priv) | |
4011 | { | |
4012 | u32 temp; | |
4013 | ||
4014 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
4015 | ||
4016 | mutex_lock(&dev_priv->sb_lock); | |
4017 | ||
4018 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
4019 | temp |= SBI_SSCCTL_DISABLE; | |
4020 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); | |
4021 | ||
4022 | mutex_unlock(&dev_priv->sb_lock); | |
4023 | } | |
4024 | ||
4025 | /* Program iCLKIP clock to the desired frequency */ | |
4026 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
4027 | { | |
4028 | struct drm_device *dev = crtc->dev; | |
4029 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4030 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; | |
4031 | u32 divsel, phaseinc, auxdiv, phasedir = 0; | |
4032 | u32 temp; | |
4033 | ||
4034 | lpt_disable_iclkip(dev_priv); | |
4035 | ||
4036 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
4037 | if (clock == 20000) { | |
4038 | auxdiv = 1; | |
4039 | divsel = 0x41; | |
4040 | phaseinc = 0x20; | |
4041 | } else { | |
4042 | /* The iCLK virtual clock root frequency is in MHz, | |
4043 | * but the adjusted_mode->crtc_clock in in KHz. To get the | |
4044 | * divisors, it is necessary to divide one by another, so we | |
4045 | * convert the virtual clock precision to KHz here for higher | |
4046 | * precision. | |
4047 | */ | |
4048 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
4049 | u32 iclk_pi_range = 64; | |
4050 | u32 desired_divisor, msb_divisor_value, pi_value; | |
4051 | ||
4052 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, clock); | |
4053 | msb_divisor_value = desired_divisor / iclk_pi_range; | |
4054 | pi_value = desired_divisor % iclk_pi_range; | |
4055 | ||
4056 | auxdiv = 0; | |
4057 | divsel = msb_divisor_value - 2; | |
4058 | phaseinc = pi_value; | |
4059 | } | |
4060 | ||
4061 | /* This should not happen with any sane values */ | |
4062 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
4063 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
4064 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
4065 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
4066 | ||
4067 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
4068 | clock, | |
4069 | auxdiv, | |
4070 | divsel, | |
4071 | phasedir, | |
4072 | phaseinc); | |
4073 | ||
4074 | mutex_lock(&dev_priv->sb_lock); | |
4075 | ||
4076 | /* Program SSCDIVINTPHASE6 */ | |
4077 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); | |
4078 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; | |
4079 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
4080 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
4081 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
4082 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
4083 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
4084 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); | |
4085 | ||
4086 | /* Program SSCAUXDIV */ | |
4087 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); | |
4088 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); | |
4089 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
4090 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); | |
4091 | ||
4092 | /* Enable modulator and associated divider */ | |
4093 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
4094 | temp &= ~SBI_SSCCTL_DISABLE; | |
4095 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); | |
4096 | ||
4097 | mutex_unlock(&dev_priv->sb_lock); | |
4098 | ||
4099 | /* Wait for initialization time */ | |
4100 | udelay(24); | |
4101 | ||
4102 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
4103 | } | |
4104 | ||
4105 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, | |
4106 | enum pipe pch_transcoder) | |
4107 | { | |
4108 | struct drm_device *dev = crtc->base.dev; | |
4109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4110 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; | |
4111 | ||
4112 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4113 | I915_READ(HTOTAL(cpu_transcoder))); | |
4114 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4115 | I915_READ(HBLANK(cpu_transcoder))); | |
4116 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4117 | I915_READ(HSYNC(cpu_transcoder))); | |
4118 | ||
4119 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4120 | I915_READ(VTOTAL(cpu_transcoder))); | |
4121 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4122 | I915_READ(VBLANK(cpu_transcoder))); | |
4123 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4124 | I915_READ(VSYNC(cpu_transcoder))); | |
4125 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4126 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4127 | } | |
4128 | ||
4129 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) | |
4130 | { | |
4131 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4132 | uint32_t temp; | |
4133 | ||
4134 | temp = I915_READ(SOUTH_CHICKEN1); | |
4135 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) | |
4136 | return; | |
4137 | ||
4138 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4139 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4140 | ||
4141 | temp &= ~FDI_BC_BIFURCATION_SELECT; | |
4142 | if (enable) | |
4143 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4144 | ||
4145 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
4146 | I915_WRITE(SOUTH_CHICKEN1, temp); | |
4147 | POSTING_READ(SOUTH_CHICKEN1); | |
4148 | } | |
4149 | ||
4150 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4151 | { | |
4152 | struct drm_device *dev = intel_crtc->base.dev; | |
4153 | ||
4154 | switch (intel_crtc->pipe) { | |
4155 | case PIPE_A: | |
4156 | break; | |
4157 | case PIPE_B: | |
4158 | if (intel_crtc->config->fdi_lanes > 2) | |
4159 | cpt_set_fdi_bc_bifurcation(dev, false); | |
4160 | else | |
4161 | cpt_set_fdi_bc_bifurcation(dev, true); | |
4162 | ||
4163 | break; | |
4164 | case PIPE_C: | |
4165 | cpt_set_fdi_bc_bifurcation(dev, true); | |
4166 | ||
4167 | break; | |
4168 | default: | |
4169 | BUG(); | |
4170 | } | |
4171 | } | |
4172 | ||
4173 | /* Return which DP Port should be selected for Transcoder DP control */ | |
4174 | static enum port | |
4175 | intel_trans_dp_port_sel(struct drm_crtc *crtc) | |
4176 | { | |
4177 | struct drm_device *dev = crtc->dev; | |
4178 | struct intel_encoder *encoder; | |
4179 | ||
4180 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
4181 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || | |
4182 | encoder->type == INTEL_OUTPUT_EDP) | |
4183 | return enc_to_dig_port(&encoder->base)->port; | |
4184 | } | |
4185 | ||
4186 | return -1; | |
4187 | } | |
4188 | ||
4189 | /* | |
4190 | * Enable PCH resources required for PCH ports: | |
4191 | * - PCH PLLs | |
4192 | * - FDI training & RX/TX | |
4193 | * - update transcoder timings | |
4194 | * - DP transcoding bits | |
4195 | * - transcoder | |
4196 | */ | |
4197 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
4198 | { | |
4199 | struct drm_device *dev = crtc->dev; | |
4200 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4201 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4202 | int pipe = intel_crtc->pipe; | |
4203 | u32 temp; | |
4204 | ||
4205 | assert_pch_transcoder_disabled(dev_priv, pipe); | |
4206 | ||
4207 | if (IS_IVYBRIDGE(dev)) | |
4208 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4209 | ||
4210 | /* Write the TU size bits before fdi link training, so that error | |
4211 | * detection works. */ | |
4212 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4213 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4214 | ||
4215 | /* | |
4216 | * Sometimes spurious CPU pipe underruns happen during FDI | |
4217 | * training, at least with VGA+HDMI cloning. Suppress them. | |
4218 | */ | |
4219 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
4220 | ||
4221 | /* For PCH output, training FDI link */ | |
4222 | dev_priv->display.fdi_link_train(crtc); | |
4223 | ||
4224 | /* We need to program the right clock selection before writing the pixel | |
4225 | * mutliplier into the DPLL. */ | |
4226 | if (HAS_PCH_CPT(dev)) { | |
4227 | u32 sel; | |
4228 | ||
4229 | temp = I915_READ(PCH_DPLL_SEL); | |
4230 | temp |= TRANS_DPLL_ENABLE(pipe); | |
4231 | sel = TRANS_DPLLB_SEL(pipe); | |
4232 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) | |
4233 | temp |= sel; | |
4234 | else | |
4235 | temp &= ~sel; | |
4236 | I915_WRITE(PCH_DPLL_SEL, temp); | |
4237 | } | |
4238 | ||
4239 | /* XXX: pch pll's can be enabled any time before we enable the PCH | |
4240 | * transcoder, and we actually should do this to not upset any PCH | |
4241 | * transcoder that already use the clock when we share it. | |
4242 | * | |
4243 | * Note that enable_shared_dpll tries to do the right thing, but | |
4244 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4245 | * the right LVDS enable sequence. */ | |
4246 | intel_enable_shared_dpll(intel_crtc); | |
4247 | ||
4248 | /* set transcoder timing, panel must allow it */ | |
4249 | assert_panel_unlocked(dev_priv, pipe); | |
4250 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); | |
4251 | ||
4252 | intel_fdi_normal_train(crtc); | |
4253 | ||
4254 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4255 | ||
4256 | /* For PCH DP, enable TRANS_DP_CTL */ | |
4257 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { | |
4258 | const struct drm_display_mode *adjusted_mode = | |
4259 | &intel_crtc->config->base.adjusted_mode; | |
4260 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; | |
4261 | i915_reg_t reg = TRANS_DP_CTL(pipe); | |
4262 | temp = I915_READ(reg); | |
4263 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
4264 | TRANS_DP_SYNC_MASK | | |
4265 | TRANS_DP_BPC_MASK); | |
4266 | temp |= TRANS_DP_OUTPUT_ENABLE; | |
4267 | temp |= bpc << 9; /* same format but at 11:9 */ | |
4268 | ||
4269 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) | |
4270 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; | |
4271 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) | |
4272 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; | |
4273 | ||
4274 | switch (intel_trans_dp_port_sel(crtc)) { | |
4275 | case PORT_B: | |
4276 | temp |= TRANS_DP_PORT_SEL_B; | |
4277 | break; | |
4278 | case PORT_C: | |
4279 | temp |= TRANS_DP_PORT_SEL_C; | |
4280 | break; | |
4281 | case PORT_D: | |
4282 | temp |= TRANS_DP_PORT_SEL_D; | |
4283 | break; | |
4284 | default: | |
4285 | BUG(); | |
4286 | } | |
4287 | ||
4288 | I915_WRITE(reg, temp); | |
4289 | } | |
4290 | ||
4291 | ironlake_enable_pch_transcoder(dev_priv, pipe); | |
4292 | } | |
4293 | ||
4294 | static void lpt_pch_enable(struct drm_crtc *crtc) | |
4295 | { | |
4296 | struct drm_device *dev = crtc->dev; | |
4297 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4298 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4299 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; | |
4300 | ||
4301 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); | |
4302 | ||
4303 | lpt_program_iclkip(crtc); | |
4304 | ||
4305 | /* Set transcoder timing. */ | |
4306 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); | |
4307 | ||
4308 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); | |
4309 | } | |
4310 | ||
4311 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, | |
4312 | struct intel_crtc_state *crtc_state) | |
4313 | { | |
4314 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
4315 | struct intel_shared_dpll *pll; | |
4316 | struct intel_shared_dpll_config *shared_dpll; | |
4317 | enum intel_dpll_id i; | |
4318 | int max = dev_priv->num_shared_dpll; | |
4319 | ||
4320 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); | |
4321 | ||
4322 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
4323 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
4324 | i = (enum intel_dpll_id) crtc->pipe; | |
4325 | pll = &dev_priv->shared_dplls[i]; | |
4326 | ||
4327 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4328 | crtc->base.base.id, pll->name); | |
4329 | ||
4330 | WARN_ON(shared_dpll[i].crtc_mask); | |
4331 | ||
4332 | goto found; | |
4333 | } | |
4334 | ||
4335 | if (IS_BROXTON(dev_priv->dev)) { | |
4336 | /* PLL is attached to port in bxt */ | |
4337 | struct intel_encoder *encoder; | |
4338 | struct intel_digital_port *intel_dig_port; | |
4339 | ||
4340 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4341 | if (WARN_ON(!encoder)) | |
4342 | return NULL; | |
4343 | ||
4344 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4345 | /* 1:1 mapping between ports and PLLs */ | |
4346 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4347 | pll = &dev_priv->shared_dplls[i]; | |
4348 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4349 | crtc->base.base.id, pll->name); | |
4350 | WARN_ON(shared_dpll[i].crtc_mask); | |
4351 | ||
4352 | goto found; | |
4353 | } else if (INTEL_INFO(dev_priv)->gen < 9 && HAS_DDI(dev_priv)) | |
4354 | /* Do not consider SPLL */ | |
4355 | max = 2; | |
4356 | ||
4357 | for (i = 0; i < max; i++) { | |
4358 | pll = &dev_priv->shared_dplls[i]; | |
4359 | ||
4360 | /* Only want to check enabled timings first */ | |
4361 | if (shared_dpll[i].crtc_mask == 0) | |
4362 | continue; | |
4363 | ||
4364 | if (memcmp(&crtc_state->dpll_hw_state, | |
4365 | &shared_dpll[i].hw_state, | |
4366 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
4367 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", | |
4368 | crtc->base.base.id, pll->name, | |
4369 | shared_dpll[i].crtc_mask, | |
4370 | pll->active); | |
4371 | goto found; | |
4372 | } | |
4373 | } | |
4374 | ||
4375 | /* Ok no matching timings, maybe there's a free one? */ | |
4376 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
4377 | pll = &dev_priv->shared_dplls[i]; | |
4378 | if (shared_dpll[i].crtc_mask == 0) { | |
4379 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", | |
4380 | crtc->base.base.id, pll->name); | |
4381 | goto found; | |
4382 | } | |
4383 | } | |
4384 | ||
4385 | return NULL; | |
4386 | ||
4387 | found: | |
4388 | if (shared_dpll[i].crtc_mask == 0) | |
4389 | shared_dpll[i].hw_state = | |
4390 | crtc_state->dpll_hw_state; | |
4391 | ||
4392 | crtc_state->shared_dpll = i; | |
4393 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, | |
4394 | pipe_name(crtc->pipe)); | |
4395 | ||
4396 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; | |
4397 | ||
4398 | return pll; | |
4399 | } | |
4400 | ||
4401 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) | |
4402 | { | |
4403 | struct drm_i915_private *dev_priv = to_i915(state->dev); | |
4404 | struct intel_shared_dpll_config *shared_dpll; | |
4405 | struct intel_shared_dpll *pll; | |
4406 | enum intel_dpll_id i; | |
4407 | ||
4408 | if (!to_intel_atomic_state(state)->dpll_set) | |
4409 | return; | |
4410 | ||
4411 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; | |
4412 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
4413 | pll = &dev_priv->shared_dplls[i]; | |
4414 | pll->config = shared_dpll[i]; | |
4415 | } | |
4416 | } | |
4417 | ||
4418 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) | |
4419 | { | |
4420 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4421 | i915_reg_t dslreg = PIPEDSL(pipe); | |
4422 | u32 temp; | |
4423 | ||
4424 | temp = I915_READ(dslreg); | |
4425 | udelay(500); | |
4426 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
4427 | if (wait_for(I915_READ(dslreg) != temp, 5)) | |
4428 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); | |
4429 | } | |
4430 | } | |
4431 | ||
4432 | static int | |
4433 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4434 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4435 | int src_w, int src_h, int dst_w, int dst_h) | |
4436 | { | |
4437 | struct intel_crtc_scaler_state *scaler_state = | |
4438 | &crtc_state->scaler_state; | |
4439 | struct intel_crtc *intel_crtc = | |
4440 | to_intel_crtc(crtc_state->base.crtc); | |
4441 | int need_scaling; | |
4442 | ||
4443 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4444 | (src_h != dst_w || src_w != dst_h): | |
4445 | (src_w != dst_w || src_h != dst_h); | |
4446 | ||
4447 | /* | |
4448 | * if plane is being disabled or scaler is no more required or force detach | |
4449 | * - free scaler binded to this plane/crtc | |
4450 | * - in order to do this, update crtc->scaler_usage | |
4451 | * | |
4452 | * Here scaler state in crtc_state is set free so that | |
4453 | * scaler can be assigned to other user. Actual register | |
4454 | * update to free the scaler is done in plane/panel-fit programming. | |
4455 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4456 | */ | |
4457 | if (force_detach || !need_scaling) { | |
4458 | if (*scaler_id >= 0) { | |
4459 | scaler_state->scaler_users &= ~(1 << scaler_user); | |
4460 | scaler_state->scalers[*scaler_id].in_use = 0; | |
4461 | ||
4462 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4463 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4464 | intel_crtc->pipe, scaler_user, *scaler_id, | |
4465 | scaler_state->scaler_users); | |
4466 | *scaler_id = -1; | |
4467 | } | |
4468 | return 0; | |
4469 | } | |
4470 | ||
4471 | /* range checks */ | |
4472 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4473 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4474 | ||
4475 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4476 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
4477 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " | |
4478 | "size is out of scaler range\n", | |
4479 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); | |
4480 | return -EINVAL; | |
4481 | } | |
4482 | ||
4483 | /* mark this plane as a scaler user in crtc_state */ | |
4484 | scaler_state->scaler_users |= (1 << scaler_user); | |
4485 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4486 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4487 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4488 | scaler_state->scaler_users); | |
4489 | ||
4490 | return 0; | |
4491 | } | |
4492 | ||
4493 | /** | |
4494 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4495 | * | |
4496 | * @state: crtc's scaler state | |
4497 | * | |
4498 | * Return | |
4499 | * 0 - scaler_usage updated successfully | |
4500 | * error - requested scaling cannot be supported or other error condition | |
4501 | */ | |
4502 | int skl_update_scaler_crtc(struct intel_crtc_state *state) | |
4503 | { | |
4504 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
4505 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; | |
4506 | ||
4507 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4508 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4509 | ||
4510 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, | |
4511 | &state->scaler_state.scaler_id, BIT(DRM_ROTATE_0), | |
4512 | state->pipe_src_w, state->pipe_src_h, | |
4513 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); | |
4514 | } | |
4515 | ||
4516 | /** | |
4517 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4518 | * | |
4519 | * @state: crtc's scaler state | |
4520 | * @plane_state: atomic plane state to update | |
4521 | * | |
4522 | * Return | |
4523 | * 0 - scaler_usage updated successfully | |
4524 | * error - requested scaling cannot be supported or other error condition | |
4525 | */ | |
4526 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, | |
4527 | struct intel_plane_state *plane_state) | |
4528 | { | |
4529 | ||
4530 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
4531 | struct intel_plane *intel_plane = | |
4532 | to_intel_plane(plane_state->base.plane); | |
4533 | struct drm_framebuffer *fb = plane_state->base.fb; | |
4534 | int ret; | |
4535 | ||
4536 | bool force_detach = !fb || !plane_state->visible; | |
4537 | ||
4538 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4539 | intel_plane->base.base.id, intel_crtc->pipe, | |
4540 | drm_plane_index(&intel_plane->base)); | |
4541 | ||
4542 | ret = skl_update_scaler(crtc_state, force_detach, | |
4543 | drm_plane_index(&intel_plane->base), | |
4544 | &plane_state->scaler_id, | |
4545 | plane_state->base.rotation, | |
4546 | drm_rect_width(&plane_state->src) >> 16, | |
4547 | drm_rect_height(&plane_state->src) >> 16, | |
4548 | drm_rect_width(&plane_state->dst), | |
4549 | drm_rect_height(&plane_state->dst)); | |
4550 | ||
4551 | if (ret || plane_state->scaler_id < 0) | |
4552 | return ret; | |
4553 | ||
4554 | /* check colorkey */ | |
4555 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { | |
4556 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", | |
4557 | intel_plane->base.base.id); | |
4558 | return -EINVAL; | |
4559 | } | |
4560 | ||
4561 | /* Check src format */ | |
4562 | switch (fb->pixel_format) { | |
4563 | case DRM_FORMAT_RGB565: | |
4564 | case DRM_FORMAT_XBGR8888: | |
4565 | case DRM_FORMAT_XRGB8888: | |
4566 | case DRM_FORMAT_ABGR8888: | |
4567 | case DRM_FORMAT_ARGB8888: | |
4568 | case DRM_FORMAT_XRGB2101010: | |
4569 | case DRM_FORMAT_XBGR2101010: | |
4570 | case DRM_FORMAT_YUYV: | |
4571 | case DRM_FORMAT_YVYU: | |
4572 | case DRM_FORMAT_UYVY: | |
4573 | case DRM_FORMAT_VYUY: | |
4574 | break; | |
4575 | default: | |
4576 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4577 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4578 | return -EINVAL; | |
4579 | } | |
4580 | ||
4581 | return 0; | |
4582 | } | |
4583 | ||
4584 | static void skylake_scaler_disable(struct intel_crtc *crtc) | |
4585 | { | |
4586 | int i; | |
4587 | ||
4588 | for (i = 0; i < crtc->num_scalers; i++) | |
4589 | skl_detach_scaler(crtc, i); | |
4590 | } | |
4591 | ||
4592 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
4593 | { | |
4594 | struct drm_device *dev = crtc->base.dev; | |
4595 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4596 | int pipe = crtc->pipe; | |
4597 | struct intel_crtc_scaler_state *scaler_state = | |
4598 | &crtc->config->scaler_state; | |
4599 | ||
4600 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4601 | ||
4602 | if (crtc->config->pch_pfit.enabled) { | |
4603 | int id; | |
4604 | ||
4605 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4606 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4607 | return; | |
4608 | } | |
4609 | ||
4610 | id = scaler_state->scaler_id; | |
4611 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4612 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4613 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4614 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4615 | ||
4616 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
4617 | } | |
4618 | } | |
4619 | ||
4620 | static void ironlake_pfit_enable(struct intel_crtc *crtc) | |
4621 | { | |
4622 | struct drm_device *dev = crtc->base.dev; | |
4623 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4624 | int pipe = crtc->pipe; | |
4625 | ||
4626 | if (crtc->config->pch_pfit.enabled) { | |
4627 | /* Force use of hard-coded filter coefficients | |
4628 | * as some pre-programmed values are broken, | |
4629 | * e.g. x201. | |
4630 | */ | |
4631 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4632 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4633 | PF_PIPE_SEL_IVB(pipe)); | |
4634 | else | |
4635 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
4636 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); | |
4637 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
4638 | } | |
4639 | } | |
4640 | ||
4641 | void hsw_enable_ips(struct intel_crtc *crtc) | |
4642 | { | |
4643 | struct drm_device *dev = crtc->base.dev; | |
4644 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4645 | ||
4646 | if (!crtc->config->ips_enabled) | |
4647 | return; | |
4648 | ||
4649 | /* We can only enable IPS after we enable a plane and wait for a vblank */ | |
4650 | intel_wait_for_vblank(dev, crtc->pipe); | |
4651 | ||
4652 | assert_plane_enabled(dev_priv, crtc->plane); | |
4653 | if (IS_BROADWELL(dev)) { | |
4654 | mutex_lock(&dev_priv->rps.hw_lock); | |
4655 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4656 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4657 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4658 | * value in IPS_CTL bit 31 after enabling IPS through the | |
4659 | * mailbox." Moreover, the mailbox may return a bogus state, | |
4660 | * so we need to just enable it and continue on. | |
4661 | */ | |
4662 | } else { | |
4663 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4664 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4665 | * is essentially intel_wait_for_vblank. If we don't have this | |
4666 | * and don't wait for vblanks until the end of crtc_enable, then | |
4667 | * the HW state readout code will complain that the expected | |
4668 | * IPS_CTL value is not the one we read. */ | |
4669 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4670 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4671 | } | |
4672 | } | |
4673 | ||
4674 | void hsw_disable_ips(struct intel_crtc *crtc) | |
4675 | { | |
4676 | struct drm_device *dev = crtc->base.dev; | |
4677 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4678 | ||
4679 | if (!crtc->config->ips_enabled) | |
4680 | return; | |
4681 | ||
4682 | assert_plane_enabled(dev_priv, crtc->plane); | |
4683 | if (IS_BROADWELL(dev)) { | |
4684 | mutex_lock(&dev_priv->rps.hw_lock); | |
4685 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4686 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4687 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ | |
4688 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4689 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
4690 | } else { | |
4691 | I915_WRITE(IPS_CTL, 0); | |
4692 | POSTING_READ(IPS_CTL); | |
4693 | } | |
4694 | ||
4695 | /* We need to wait for a vblank before we can disable the plane. */ | |
4696 | intel_wait_for_vblank(dev, crtc->pipe); | |
4697 | } | |
4698 | ||
4699 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4700 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4701 | { | |
4702 | struct drm_device *dev = crtc->dev; | |
4703 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4704 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4705 | enum pipe pipe = intel_crtc->pipe; | |
4706 | int i; | |
4707 | bool reenable_ips = false; | |
4708 | ||
4709 | /* The clocks have to be on to load the palette. */ | |
4710 | if (!crtc->state->active) | |
4711 | return; | |
4712 | ||
4713 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { | |
4714 | if (intel_crtc->config->has_dsi_encoder) | |
4715 | assert_dsi_pll_enabled(dev_priv); | |
4716 | else | |
4717 | assert_pll_enabled(dev_priv, pipe); | |
4718 | } | |
4719 | ||
4720 | /* Workaround : Do not read or write the pipe palette/gamma data while | |
4721 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4722 | */ | |
4723 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && | |
4724 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == | |
4725 | GAMMA_MODE_MODE_SPLIT)) { | |
4726 | hsw_disable_ips(intel_crtc); | |
4727 | reenable_ips = true; | |
4728 | } | |
4729 | ||
4730 | for (i = 0; i < 256; i++) { | |
4731 | i915_reg_t palreg; | |
4732 | ||
4733 | if (HAS_GMCH_DISPLAY(dev)) | |
4734 | palreg = PALETTE(pipe, i); | |
4735 | else | |
4736 | palreg = LGC_PALETTE(pipe, i); | |
4737 | ||
4738 | I915_WRITE(palreg, | |
4739 | (intel_crtc->lut_r[i] << 16) | | |
4740 | (intel_crtc->lut_g[i] << 8) | | |
4741 | intel_crtc->lut_b[i]); | |
4742 | } | |
4743 | ||
4744 | if (reenable_ips) | |
4745 | hsw_enable_ips(intel_crtc); | |
4746 | } | |
4747 | ||
4748 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) | |
4749 | { | |
4750 | if (intel_crtc->overlay) { | |
4751 | struct drm_device *dev = intel_crtc->base.dev; | |
4752 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4753 | ||
4754 | mutex_lock(&dev->struct_mutex); | |
4755 | dev_priv->mm.interruptible = false; | |
4756 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4757 | dev_priv->mm.interruptible = true; | |
4758 | mutex_unlock(&dev->struct_mutex); | |
4759 | } | |
4760 | ||
4761 | /* Let userspace switch the overlay on again. In most cases userspace | |
4762 | * has to recompute where to put it anyway. | |
4763 | */ | |
4764 | } | |
4765 | ||
4766 | /** | |
4767 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4768 | * @crtc: the CRTC whose primary plane was just enabled | |
4769 | * | |
4770 | * Performs potentially sleeping operations that must be done after the primary | |
4771 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4772 | * called due to an explicit primary plane update, or due to an implicit | |
4773 | * re-enable that is caused when a sprite plane is updated to no longer | |
4774 | * completely hide the primary plane. | |
4775 | */ | |
4776 | static void | |
4777 | intel_post_enable_primary(struct drm_crtc *crtc) | |
4778 | { | |
4779 | struct drm_device *dev = crtc->dev; | |
4780 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4781 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4782 | int pipe = intel_crtc->pipe; | |
4783 | ||
4784 | /* | |
4785 | * FIXME IPS should be fine as long as one plane is | |
4786 | * enabled, but in practice it seems to have problems | |
4787 | * when going from primary only to sprite only and vice | |
4788 | * versa. | |
4789 | */ | |
4790 | hsw_enable_ips(intel_crtc); | |
4791 | ||
4792 | /* | |
4793 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4794 | * So don't enable underrun reporting before at least some planes | |
4795 | * are enabled. | |
4796 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4797 | * but leave the pipe running. | |
4798 | */ | |
4799 | if (IS_GEN2(dev)) | |
4800 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4801 | ||
4802 | /* Underruns don't always raise interrupts, so check manually. */ | |
4803 | intel_check_cpu_fifo_underruns(dev_priv); | |
4804 | intel_check_pch_fifo_underruns(dev_priv); | |
4805 | } | |
4806 | ||
4807 | /** | |
4808 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4809 | * @crtc: the CRTC whose primary plane is to be disabled | |
4810 | * | |
4811 | * Performs potentially sleeping operations that must be done before the | |
4812 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4813 | * be called due to an explicit primary plane update, or due to an implicit | |
4814 | * disable that is caused when a sprite plane completely hides the primary | |
4815 | * plane. | |
4816 | */ | |
4817 | static void | |
4818 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
4819 | { | |
4820 | struct drm_device *dev = crtc->dev; | |
4821 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4823 | int pipe = intel_crtc->pipe; | |
4824 | ||
4825 | /* | |
4826 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4827 | * So diasble underrun reporting before all the planes get disabled. | |
4828 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4829 | * but leave the pipe running. | |
4830 | */ | |
4831 | if (IS_GEN2(dev)) | |
4832 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
4833 | ||
4834 | /* | |
4835 | * Vblank time updates from the shadow to live plane control register | |
4836 | * are blocked if the memory self-refresh mode is active at that | |
4837 | * moment. So to make sure the plane gets truly disabled, disable | |
4838 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4839 | * will be checked/applied by the HW only at the next frame start | |
4840 | * event which is after the vblank start event, so we need to have a | |
4841 | * wait-for-vblank between disabling the plane and the pipe. | |
4842 | */ | |
4843 | if (HAS_GMCH_DISPLAY(dev)) { | |
4844 | intel_set_memory_cxsr(dev_priv, false); | |
4845 | dev_priv->wm.vlv.cxsr = false; | |
4846 | intel_wait_for_vblank(dev, pipe); | |
4847 | } | |
4848 | ||
4849 | /* | |
4850 | * FIXME IPS should be fine as long as one plane is | |
4851 | * enabled, but in practice it seems to have problems | |
4852 | * when going from primary only to sprite only and vice | |
4853 | * versa. | |
4854 | */ | |
4855 | hsw_disable_ips(intel_crtc); | |
4856 | } | |
4857 | ||
4858 | static void intel_post_plane_update(struct intel_crtc *crtc) | |
4859 | { | |
4860 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4861 | struct intel_crtc_state *pipe_config = | |
4862 | to_intel_crtc_state(crtc->base.state); | |
4863 | struct drm_device *dev = crtc->base.dev; | |
4864 | ||
4865 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4866 | ||
4867 | crtc->wm.cxsr_allowed = true; | |
4868 | ||
4869 | if (pipe_config->wm_changed && pipe_config->base.active) | |
4870 | intel_update_watermarks(&crtc->base); | |
4871 | ||
4872 | if (atomic->update_fbc) | |
4873 | intel_fbc_post_update(crtc); | |
4874 | ||
4875 | if (atomic->post_enable_primary) | |
4876 | intel_post_enable_primary(&crtc->base); | |
4877 | ||
4878 | memset(atomic, 0, sizeof(*atomic)); | |
4879 | } | |
4880 | ||
4881 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state) | |
4882 | { | |
4883 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); | |
4884 | struct drm_device *dev = crtc->base.dev; | |
4885 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4886 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4887 | struct intel_crtc_state *pipe_config = | |
4888 | to_intel_crtc_state(crtc->base.state); | |
4889 | struct drm_atomic_state *old_state = old_crtc_state->base.state; | |
4890 | struct drm_plane *primary = crtc->base.primary; | |
4891 | struct drm_plane_state *old_pri_state = | |
4892 | drm_atomic_get_existing_plane_state(old_state, primary); | |
4893 | bool modeset = needs_modeset(&pipe_config->base); | |
4894 | ||
4895 | if (atomic->update_fbc) | |
4896 | intel_fbc_pre_update(crtc); | |
4897 | ||
4898 | if (old_pri_state) { | |
4899 | struct intel_plane_state *primary_state = | |
4900 | to_intel_plane_state(primary->state); | |
4901 | struct intel_plane_state *old_primary_state = | |
4902 | to_intel_plane_state(old_pri_state); | |
4903 | ||
4904 | if (old_primary_state->visible && | |
4905 | (modeset || !primary_state->visible)) | |
4906 | intel_pre_disable_primary(&crtc->base); | |
4907 | } | |
4908 | ||
4909 | if (pipe_config->disable_cxsr) { | |
4910 | crtc->wm.cxsr_allowed = false; | |
4911 | ||
4912 | if (old_crtc_state->base.active) | |
4913 | intel_set_memory_cxsr(dev_priv, false); | |
4914 | } | |
4915 | ||
4916 | /* | |
4917 | * IVB workaround: must disable low power watermarks for at least | |
4918 | * one frame before enabling scaling. LP watermarks can be re-enabled | |
4919 | * when scaling is disabled. | |
4920 | * | |
4921 | * WaCxSRDisabledForSpriteScaling:ivb | |
4922 | */ | |
4923 | if (pipe_config->disable_lp_wm) { | |
4924 | ilk_disable_lp_wm(dev); | |
4925 | intel_wait_for_vblank(dev, crtc->pipe); | |
4926 | } | |
4927 | ||
4928 | /* | |
4929 | * If we're doing a modeset, we're done. No need to do any pre-vblank | |
4930 | * watermark programming here. | |
4931 | */ | |
4932 | if (needs_modeset(&pipe_config->base)) | |
4933 | return; | |
4934 | ||
4935 | /* | |
4936 | * For platforms that support atomic watermarks, program the | |
4937 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these | |
4938 | * will be the intermediate values that are safe for both pre- and | |
4939 | * post- vblank; when vblank happens, the 'active' values will be set | |
4940 | * to the final 'target' values and we'll do this again to get the | |
4941 | * optimal watermarks. For gen9+ platforms, the values we program here | |
4942 | * will be the final target values which will get automatically latched | |
4943 | * at vblank time; no further programming will be necessary. | |
4944 | * | |
4945 | * If a platform hasn't been transitioned to atomic watermarks yet, | |
4946 | * we'll continue to update watermarks the old way, if flags tell | |
4947 | * us to. | |
4948 | */ | |
4949 | if (dev_priv->display.initial_watermarks != NULL) | |
4950 | dev_priv->display.initial_watermarks(pipe_config); | |
4951 | else if (pipe_config->wm_changed) | |
4952 | intel_update_watermarks(&crtc->base); | |
4953 | } | |
4954 | ||
4955 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) | |
4956 | { | |
4957 | struct drm_device *dev = crtc->dev; | |
4958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4959 | struct drm_plane *p; | |
4960 | int pipe = intel_crtc->pipe; | |
4961 | ||
4962 | intel_crtc_dpms_overlay_disable(intel_crtc); | |
4963 | ||
4964 | drm_for_each_plane_mask(p, dev, plane_mask) | |
4965 | to_intel_plane(p)->disable_plane(p, crtc); | |
4966 | ||
4967 | /* | |
4968 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4969 | * to compute the mask of flip planes precisely. For the time being | |
4970 | * consider this a flip to a NULL plane. | |
4971 | */ | |
4972 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
4973 | } | |
4974 | ||
4975 | static void ironlake_crtc_enable(struct drm_crtc *crtc) | |
4976 | { | |
4977 | struct drm_device *dev = crtc->dev; | |
4978 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4979 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4980 | struct intel_encoder *encoder; | |
4981 | int pipe = intel_crtc->pipe; | |
4982 | ||
4983 | if (WARN_ON(intel_crtc->active)) | |
4984 | return; | |
4985 | ||
4986 | if (intel_crtc->config->has_pch_encoder) | |
4987 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
4988 | ||
4989 | if (intel_crtc->config->has_pch_encoder) | |
4990 | intel_prepare_shared_dpll(intel_crtc); | |
4991 | ||
4992 | if (intel_crtc->config->has_dp_encoder) | |
4993 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
4994 | ||
4995 | intel_set_pipe_timings(intel_crtc); | |
4996 | ||
4997 | if (intel_crtc->config->has_pch_encoder) { | |
4998 | intel_cpu_transcoder_set_m_n(intel_crtc, | |
4999 | &intel_crtc->config->fdi_m_n, NULL); | |
5000 | } | |
5001 | ||
5002 | ironlake_set_pipeconf(crtc); | |
5003 | ||
5004 | intel_crtc->active = true; | |
5005 | ||
5006 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
5007 | ||
5008 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
5009 | if (encoder->pre_enable) | |
5010 | encoder->pre_enable(encoder); | |
5011 | ||
5012 | if (intel_crtc->config->has_pch_encoder) { | |
5013 | /* Note: FDI PLL enabling _must_ be done before we enable the | |
5014 | * cpu pipes, hence this is separate from all the other fdi/pch | |
5015 | * enabling. */ | |
5016 | ironlake_fdi_pll_enable(intel_crtc); | |
5017 | } else { | |
5018 | assert_fdi_tx_disabled(dev_priv, pipe); | |
5019 | assert_fdi_rx_disabled(dev_priv, pipe); | |
5020 | } | |
5021 | ||
5022 | ironlake_pfit_enable(intel_crtc); | |
5023 | ||
5024 | /* | |
5025 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5026 | * clocks enabled | |
5027 | */ | |
5028 | intel_crtc_load_lut(crtc); | |
5029 | ||
5030 | if (dev_priv->display.initial_watermarks != NULL) | |
5031 | dev_priv->display.initial_watermarks(intel_crtc->config); | |
5032 | intel_enable_pipe(intel_crtc); | |
5033 | ||
5034 | if (intel_crtc->config->has_pch_encoder) | |
5035 | ironlake_pch_enable(crtc); | |
5036 | ||
5037 | assert_vblank_disabled(crtc); | |
5038 | drm_crtc_vblank_on(crtc); | |
5039 | ||
5040 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
5041 | encoder->enable(encoder); | |
5042 | ||
5043 | if (HAS_PCH_CPT(dev)) | |
5044 | cpt_verify_modeset(dev, intel_crtc->pipe); | |
5045 | ||
5046 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
5047 | if (intel_crtc->config->has_pch_encoder) | |
5048 | intel_wait_for_vblank(dev, pipe); | |
5049 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
5050 | } | |
5051 | ||
5052 | /* IPS only exists on ULT machines and is tied to pipe A. */ | |
5053 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
5054 | { | |
5055 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; | |
5056 | } | |
5057 | ||
5058 | static void haswell_crtc_enable(struct drm_crtc *crtc) | |
5059 | { | |
5060 | struct drm_device *dev = crtc->dev; | |
5061 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5063 | struct intel_encoder *encoder; | |
5064 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; | |
5065 | struct intel_crtc_state *pipe_config = | |
5066 | to_intel_crtc_state(crtc->state); | |
5067 | ||
5068 | if (WARN_ON(intel_crtc->active)) | |
5069 | return; | |
5070 | ||
5071 | if (intel_crtc->config->has_pch_encoder) | |
5072 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5073 | false); | |
5074 | ||
5075 | if (intel_crtc_to_shared_dpll(intel_crtc)) | |
5076 | intel_enable_shared_dpll(intel_crtc); | |
5077 | ||
5078 | if (intel_crtc->config->has_dp_encoder) | |
5079 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
5080 | ||
5081 | intel_set_pipe_timings(intel_crtc); | |
5082 | ||
5083 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { | |
5084 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
5085 | intel_crtc->config->pixel_multiplier - 1); | |
5086 | } | |
5087 | ||
5088 | if (intel_crtc->config->has_pch_encoder) { | |
5089 | intel_cpu_transcoder_set_m_n(intel_crtc, | |
5090 | &intel_crtc->config->fdi_m_n, NULL); | |
5091 | } | |
5092 | ||
5093 | haswell_set_pipeconf(crtc); | |
5094 | ||
5095 | intel_set_pipe_csc(crtc); | |
5096 | ||
5097 | intel_crtc->active = true; | |
5098 | ||
5099 | if (intel_crtc->config->has_pch_encoder) | |
5100 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
5101 | else | |
5102 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
5103 | ||
5104 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
5105 | if (encoder->pre_enable) | |
5106 | encoder->pre_enable(encoder); | |
5107 | } | |
5108 | ||
5109 | if (intel_crtc->config->has_pch_encoder) | |
5110 | dev_priv->display.fdi_link_train(crtc); | |
5111 | ||
5112 | if (!intel_crtc->config->has_dsi_encoder) | |
5113 | intel_ddi_enable_pipe_clock(intel_crtc); | |
5114 | ||
5115 | if (INTEL_INFO(dev)->gen >= 9) | |
5116 | skylake_pfit_enable(intel_crtc); | |
5117 | else | |
5118 | ironlake_pfit_enable(intel_crtc); | |
5119 | ||
5120 | /* | |
5121 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5122 | * clocks enabled | |
5123 | */ | |
5124 | intel_crtc_load_lut(crtc); | |
5125 | ||
5126 | intel_ddi_set_pipe_settings(crtc); | |
5127 | if (!intel_crtc->config->has_dsi_encoder) | |
5128 | intel_ddi_enable_transcoder_func(crtc); | |
5129 | ||
5130 | if (dev_priv->display.initial_watermarks != NULL) | |
5131 | dev_priv->display.initial_watermarks(pipe_config); | |
5132 | else | |
5133 | intel_update_watermarks(crtc); | |
5134 | intel_enable_pipe(intel_crtc); | |
5135 | ||
5136 | if (intel_crtc->config->has_pch_encoder) | |
5137 | lpt_pch_enable(crtc); | |
5138 | ||
5139 | if (intel_crtc->config->dp_encoder_is_mst) | |
5140 | intel_ddi_set_vc_payload_alloc(crtc, true); | |
5141 | ||
5142 | assert_vblank_disabled(crtc); | |
5143 | drm_crtc_vblank_on(crtc); | |
5144 | ||
5145 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
5146 | encoder->enable(encoder); | |
5147 | intel_opregion_notify_encoder(encoder, true); | |
5148 | } | |
5149 | ||
5150 | if (intel_crtc->config->has_pch_encoder) { | |
5151 | intel_wait_for_vblank(dev, pipe); | |
5152 | intel_wait_for_vblank(dev, pipe); | |
5153 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
5154 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5155 | true); | |
5156 | } | |
5157 | ||
5158 | /* If we change the relative order between pipe/planes enabling, we need | |
5159 | * to change the workaround. */ | |
5160 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; | |
5161 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
5162 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5163 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5164 | } | |
5165 | } | |
5166 | ||
5167 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) | |
5168 | { | |
5169 | struct drm_device *dev = crtc->base.dev; | |
5170 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5171 | int pipe = crtc->pipe; | |
5172 | ||
5173 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5174 | * it's in use. The hw state code will make sure we get this right. */ | |
5175 | if (force || crtc->config->pch_pfit.enabled) { | |
5176 | I915_WRITE(PF_CTL(pipe), 0); | |
5177 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5178 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5179 | } | |
5180 | } | |
5181 | ||
5182 | static void ironlake_crtc_disable(struct drm_crtc *crtc) | |
5183 | { | |
5184 | struct drm_device *dev = crtc->dev; | |
5185 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5186 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5187 | struct intel_encoder *encoder; | |
5188 | int pipe = intel_crtc->pipe; | |
5189 | ||
5190 | if (intel_crtc->config->has_pch_encoder) | |
5191 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
5192 | ||
5193 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
5194 | encoder->disable(encoder); | |
5195 | ||
5196 | drm_crtc_vblank_off(crtc); | |
5197 | assert_vblank_disabled(crtc); | |
5198 | ||
5199 | /* | |
5200 | * Sometimes spurious CPU pipe underruns happen when the | |
5201 | * pipe is already disabled, but FDI RX/TX is still enabled. | |
5202 | * Happens at least with VGA+HDMI cloning. Suppress them. | |
5203 | */ | |
5204 | if (intel_crtc->config->has_pch_encoder) | |
5205 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
5206 | ||
5207 | intel_disable_pipe(intel_crtc); | |
5208 | ||
5209 | ironlake_pfit_disable(intel_crtc, false); | |
5210 | ||
5211 | if (intel_crtc->config->has_pch_encoder) { | |
5212 | ironlake_fdi_disable(crtc); | |
5213 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
5214 | } | |
5215 | ||
5216 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
5217 | if (encoder->post_disable) | |
5218 | encoder->post_disable(encoder); | |
5219 | ||
5220 | if (intel_crtc->config->has_pch_encoder) { | |
5221 | ironlake_disable_pch_transcoder(dev_priv, pipe); | |
5222 | ||
5223 | if (HAS_PCH_CPT(dev)) { | |
5224 | i915_reg_t reg; | |
5225 | u32 temp; | |
5226 | ||
5227 | /* disable TRANS_DP_CTL */ | |
5228 | reg = TRANS_DP_CTL(pipe); | |
5229 | temp = I915_READ(reg); | |
5230 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5231 | TRANS_DP_PORT_SEL_MASK); | |
5232 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5233 | I915_WRITE(reg, temp); | |
5234 | ||
5235 | /* disable DPLL_SEL */ | |
5236 | temp = I915_READ(PCH_DPLL_SEL); | |
5237 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); | |
5238 | I915_WRITE(PCH_DPLL_SEL, temp); | |
5239 | } | |
5240 | ||
5241 | ironlake_fdi_pll_disable(intel_crtc); | |
5242 | } | |
5243 | ||
5244 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
5245 | } | |
5246 | ||
5247 | static void haswell_crtc_disable(struct drm_crtc *crtc) | |
5248 | { | |
5249 | struct drm_device *dev = crtc->dev; | |
5250 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5251 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5252 | struct intel_encoder *encoder; | |
5253 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; | |
5254 | ||
5255 | if (intel_crtc->config->has_pch_encoder) | |
5256 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5257 | false); | |
5258 | ||
5259 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
5260 | intel_opregion_notify_encoder(encoder, false); | |
5261 | encoder->disable(encoder); | |
5262 | } | |
5263 | ||
5264 | drm_crtc_vblank_off(crtc); | |
5265 | assert_vblank_disabled(crtc); | |
5266 | ||
5267 | intel_disable_pipe(intel_crtc); | |
5268 | ||
5269 | if (intel_crtc->config->dp_encoder_is_mst) | |
5270 | intel_ddi_set_vc_payload_alloc(crtc, false); | |
5271 | ||
5272 | if (!intel_crtc->config->has_dsi_encoder) | |
5273 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); | |
5274 | ||
5275 | if (INTEL_INFO(dev)->gen >= 9) | |
5276 | skylake_scaler_disable(intel_crtc); | |
5277 | else | |
5278 | ironlake_pfit_disable(intel_crtc, false); | |
5279 | ||
5280 | if (!intel_crtc->config->has_dsi_encoder) | |
5281 | intel_ddi_disable_pipe_clock(intel_crtc); | |
5282 | ||
5283 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
5284 | if (encoder->post_disable) | |
5285 | encoder->post_disable(encoder); | |
5286 | ||
5287 | if (intel_crtc->config->has_pch_encoder) { | |
5288 | lpt_disable_pch_transcoder(dev_priv); | |
5289 | lpt_disable_iclkip(dev_priv); | |
5290 | intel_ddi_fdi_disable(crtc); | |
5291 | ||
5292 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5293 | true); | |
5294 | } | |
5295 | } | |
5296 | ||
5297 | static void i9xx_pfit_enable(struct intel_crtc *crtc) | |
5298 | { | |
5299 | struct drm_device *dev = crtc->base.dev; | |
5300 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5301 | struct intel_crtc_state *pipe_config = crtc->config; | |
5302 | ||
5303 | if (!pipe_config->gmch_pfit.control) | |
5304 | return; | |
5305 | ||
5306 | /* | |
5307 | * The panel fitter should only be adjusted whilst the pipe is disabled, | |
5308 | * according to register description and PRM. | |
5309 | */ | |
5310 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); | |
5311 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
5312 | ||
5313 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); | |
5314 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5315 | ||
5316 | /* Border color in case we don't scale up to the full screen. Black by | |
5317 | * default, change to something else for debugging. */ | |
5318 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
5319 | } | |
5320 | ||
5321 | static enum intel_display_power_domain port_to_power_domain(enum port port) | |
5322 | { | |
5323 | switch (port) { | |
5324 | case PORT_A: | |
5325 | return POWER_DOMAIN_PORT_DDI_A_LANES; | |
5326 | case PORT_B: | |
5327 | return POWER_DOMAIN_PORT_DDI_B_LANES; | |
5328 | case PORT_C: | |
5329 | return POWER_DOMAIN_PORT_DDI_C_LANES; | |
5330 | case PORT_D: | |
5331 | return POWER_DOMAIN_PORT_DDI_D_LANES; | |
5332 | case PORT_E: | |
5333 | return POWER_DOMAIN_PORT_DDI_E_LANES; | |
5334 | default: | |
5335 | MISSING_CASE(port); | |
5336 | return POWER_DOMAIN_PORT_OTHER; | |
5337 | } | |
5338 | } | |
5339 | ||
5340 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) | |
5341 | { | |
5342 | switch (port) { | |
5343 | case PORT_A: | |
5344 | return POWER_DOMAIN_AUX_A; | |
5345 | case PORT_B: | |
5346 | return POWER_DOMAIN_AUX_B; | |
5347 | case PORT_C: | |
5348 | return POWER_DOMAIN_AUX_C; | |
5349 | case PORT_D: | |
5350 | return POWER_DOMAIN_AUX_D; | |
5351 | case PORT_E: | |
5352 | /* FIXME: Check VBT for actual wiring of PORT E */ | |
5353 | return POWER_DOMAIN_AUX_D; | |
5354 | default: | |
5355 | MISSING_CASE(port); | |
5356 | return POWER_DOMAIN_AUX_A; | |
5357 | } | |
5358 | } | |
5359 | ||
5360 | enum intel_display_power_domain | |
5361 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5362 | { | |
5363 | struct drm_device *dev = intel_encoder->base.dev; | |
5364 | struct intel_digital_port *intel_dig_port; | |
5365 | ||
5366 | switch (intel_encoder->type) { | |
5367 | case INTEL_OUTPUT_UNKNOWN: | |
5368 | /* Only DDI platforms should ever use this output type */ | |
5369 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5370 | case INTEL_OUTPUT_DISPLAYPORT: | |
5371 | case INTEL_OUTPUT_HDMI: | |
5372 | case INTEL_OUTPUT_EDP: | |
5373 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
5374 | return port_to_power_domain(intel_dig_port->port); | |
5375 | case INTEL_OUTPUT_DP_MST: | |
5376 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5377 | return port_to_power_domain(intel_dig_port->port); | |
5378 | case INTEL_OUTPUT_ANALOG: | |
5379 | return POWER_DOMAIN_PORT_CRT; | |
5380 | case INTEL_OUTPUT_DSI: | |
5381 | return POWER_DOMAIN_PORT_DSI; | |
5382 | default: | |
5383 | return POWER_DOMAIN_PORT_OTHER; | |
5384 | } | |
5385 | } | |
5386 | ||
5387 | enum intel_display_power_domain | |
5388 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) | |
5389 | { | |
5390 | struct drm_device *dev = intel_encoder->base.dev; | |
5391 | struct intel_digital_port *intel_dig_port; | |
5392 | ||
5393 | switch (intel_encoder->type) { | |
5394 | case INTEL_OUTPUT_UNKNOWN: | |
5395 | case INTEL_OUTPUT_HDMI: | |
5396 | /* | |
5397 | * Only DDI platforms should ever use these output types. | |
5398 | * We can get here after the HDMI detect code has already set | |
5399 | * the type of the shared encoder. Since we can't be sure | |
5400 | * what's the status of the given connectors, play safe and | |
5401 | * run the DP detection too. | |
5402 | */ | |
5403 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5404 | case INTEL_OUTPUT_DISPLAYPORT: | |
5405 | case INTEL_OUTPUT_EDP: | |
5406 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
5407 | return port_to_aux_power_domain(intel_dig_port->port); | |
5408 | case INTEL_OUTPUT_DP_MST: | |
5409 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5410 | return port_to_aux_power_domain(intel_dig_port->port); | |
5411 | default: | |
5412 | MISSING_CASE(intel_encoder->type); | |
5413 | return POWER_DOMAIN_AUX_A; | |
5414 | } | |
5415 | } | |
5416 | ||
5417 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, | |
5418 | struct intel_crtc_state *crtc_state) | |
5419 | { | |
5420 | struct drm_device *dev = crtc->dev; | |
5421 | struct drm_encoder *encoder; | |
5422 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5423 | enum pipe pipe = intel_crtc->pipe; | |
5424 | unsigned long mask; | |
5425 | enum transcoder transcoder = crtc_state->cpu_transcoder; | |
5426 | ||
5427 | if (!crtc_state->base.active) | |
5428 | return 0; | |
5429 | ||
5430 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); | |
5431 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
5432 | if (crtc_state->pch_pfit.enabled || | |
5433 | crtc_state->pch_pfit.force_thru) | |
5434 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); | |
5435 | ||
5436 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { | |
5437 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); | |
5438 | ||
5439 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5440 | } | |
5441 | ||
5442 | return mask; | |
5443 | } | |
5444 | ||
5445 | static unsigned long | |
5446 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, | |
5447 | struct intel_crtc_state *crtc_state) | |
5448 | { | |
5449 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; | |
5450 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5451 | enum intel_display_power_domain domain; | |
5452 | unsigned long domains, new_domains, old_domains; | |
5453 | ||
5454 | old_domains = intel_crtc->enabled_power_domains; | |
5455 | intel_crtc->enabled_power_domains = new_domains = | |
5456 | get_crtc_power_domains(crtc, crtc_state); | |
5457 | ||
5458 | domains = new_domains & ~old_domains; | |
5459 | ||
5460 | for_each_power_domain(domain, domains) | |
5461 | intel_display_power_get(dev_priv, domain); | |
5462 | ||
5463 | return old_domains & ~new_domains; | |
5464 | } | |
5465 | ||
5466 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5467 | unsigned long domains) | |
5468 | { | |
5469 | enum intel_display_power_domain domain; | |
5470 | ||
5471 | for_each_power_domain(domain, domains) | |
5472 | intel_display_power_put(dev_priv, domain); | |
5473 | } | |
5474 | ||
5475 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) | |
5476 | { | |
5477 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5478 | ||
5479 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5480 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5481 | return max_cdclk_freq; | |
5482 | else if (IS_CHERRYVIEW(dev_priv)) | |
5483 | return max_cdclk_freq*95/100; | |
5484 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5485 | return 2*max_cdclk_freq*90/100; | |
5486 | else | |
5487 | return max_cdclk_freq*90/100; | |
5488 | } | |
5489 | ||
5490 | static void intel_update_max_cdclk(struct drm_device *dev) | |
5491 | { | |
5492 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5493 | ||
5494 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { | |
5495 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; | |
5496 | ||
5497 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5498 | dev_priv->max_cdclk_freq = 675000; | |
5499 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5500 | dev_priv->max_cdclk_freq = 540000; | |
5501 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5502 | dev_priv->max_cdclk_freq = 450000; | |
5503 | else | |
5504 | dev_priv->max_cdclk_freq = 337500; | |
5505 | } else if (IS_BROADWELL(dev)) { | |
5506 | /* | |
5507 | * FIXME with extra cooling we can allow | |
5508 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5509 | * How can we know if extra cooling is | |
5510 | * available? PCI ID, VTB, something else? | |
5511 | */ | |
5512 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5513 | dev_priv->max_cdclk_freq = 450000; | |
5514 | else if (IS_BDW_ULX(dev)) | |
5515 | dev_priv->max_cdclk_freq = 450000; | |
5516 | else if (IS_BDW_ULT(dev)) | |
5517 | dev_priv->max_cdclk_freq = 540000; | |
5518 | else | |
5519 | dev_priv->max_cdclk_freq = 675000; | |
5520 | } else if (IS_CHERRYVIEW(dev)) { | |
5521 | dev_priv->max_cdclk_freq = 320000; | |
5522 | } else if (IS_VALLEYVIEW(dev)) { | |
5523 | dev_priv->max_cdclk_freq = 400000; | |
5524 | } else { | |
5525 | /* otherwise assume cdclk is fixed */ | |
5526 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5527 | } | |
5528 | ||
5529 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); | |
5530 | ||
5531 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", | |
5532 | dev_priv->max_cdclk_freq); | |
5533 | ||
5534 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5535 | dev_priv->max_dotclk_freq); | |
5536 | } | |
5537 | ||
5538 | static void intel_update_cdclk(struct drm_device *dev) | |
5539 | { | |
5540 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5541 | ||
5542 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5543 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5544 | dev_priv->cdclk_freq); | |
5545 | ||
5546 | /* | |
5547 | * Program the gmbus_freq based on the cdclk frequency. | |
5548 | * BSpec erroneously claims we should aim for 4MHz, but | |
5549 | * in fact 1MHz is the correct frequency. | |
5550 | */ | |
5551 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
5552 | /* | |
5553 | * Program the gmbus_freq based on the cdclk frequency. | |
5554 | * BSpec erroneously claims we should aim for 4MHz, but | |
5555 | * in fact 1MHz is the correct frequency. | |
5556 | */ | |
5557 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5558 | } | |
5559 | ||
5560 | if (dev_priv->max_cdclk_freq == 0) | |
5561 | intel_update_max_cdclk(dev); | |
5562 | } | |
5563 | ||
5564 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) | |
5565 | { | |
5566 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5567 | uint32_t divider; | |
5568 | uint32_t ratio; | |
5569 | uint32_t current_freq; | |
5570 | int ret; | |
5571 | ||
5572 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5573 | switch (frequency) { | |
5574 | case 144000: | |
5575 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5576 | ratio = BXT_DE_PLL_RATIO(60); | |
5577 | break; | |
5578 | case 288000: | |
5579 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5580 | ratio = BXT_DE_PLL_RATIO(60); | |
5581 | break; | |
5582 | case 384000: | |
5583 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5584 | ratio = BXT_DE_PLL_RATIO(60); | |
5585 | break; | |
5586 | case 576000: | |
5587 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5588 | ratio = BXT_DE_PLL_RATIO(60); | |
5589 | break; | |
5590 | case 624000: | |
5591 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5592 | ratio = BXT_DE_PLL_RATIO(65); | |
5593 | break; | |
5594 | case 19200: | |
5595 | /* | |
5596 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5597 | * to suppress GCC warning. | |
5598 | */ | |
5599 | ratio = 0; | |
5600 | divider = 0; | |
5601 | break; | |
5602 | default: | |
5603 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5604 | ||
5605 | return; | |
5606 | } | |
5607 | ||
5608 | mutex_lock(&dev_priv->rps.hw_lock); | |
5609 | /* Inform power controller of upcoming frequency change */ | |
5610 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5611 | 0x80000000); | |
5612 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5613 | ||
5614 | if (ret) { | |
5615 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5616 | ret, frequency); | |
5617 | return; | |
5618 | } | |
5619 | ||
5620 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5621 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5622 | current_freq = current_freq * 500 + 1000; | |
5623 | ||
5624 | /* | |
5625 | * DE PLL has to be disabled when | |
5626 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5627 | * - before setting to 624MHz (PLL needs toggling) | |
5628 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5629 | */ | |
5630 | if (frequency == 19200 || frequency == 624000 || | |
5631 | current_freq == 624000) { | |
5632 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5633 | /* Timeout 200us */ | |
5634 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5635 | 1)) | |
5636 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5637 | } | |
5638 | ||
5639 | if (frequency != 19200) { | |
5640 | uint32_t val; | |
5641 | ||
5642 | val = I915_READ(BXT_DE_PLL_CTL); | |
5643 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5644 | val |= ratio; | |
5645 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5646 | ||
5647 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5648 | /* Timeout 200us */ | |
5649 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5650 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5651 | ||
5652 | val = I915_READ(CDCLK_CTL); | |
5653 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5654 | val |= divider; | |
5655 | /* | |
5656 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5657 | * enable otherwise. | |
5658 | */ | |
5659 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5660 | if (frequency >= 500000) | |
5661 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5662 | ||
5663 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5664 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5665 | val |= (frequency - 1000) / 500; | |
5666 | I915_WRITE(CDCLK_CTL, val); | |
5667 | } | |
5668 | ||
5669 | mutex_lock(&dev_priv->rps.hw_lock); | |
5670 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5671 | DIV_ROUND_UP(frequency, 25000)); | |
5672 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5673 | ||
5674 | if (ret) { | |
5675 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5676 | ret, frequency); | |
5677 | return; | |
5678 | } | |
5679 | ||
5680 | intel_update_cdclk(dev); | |
5681 | } | |
5682 | ||
5683 | void broxton_init_cdclk(struct drm_device *dev) | |
5684 | { | |
5685 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5686 | uint32_t val; | |
5687 | ||
5688 | /* | |
5689 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5690 | * or else the reset will hang because there is no PCH to respond. | |
5691 | * Move the handshake programming to initialization sequence. | |
5692 | * Previously was left up to BIOS. | |
5693 | */ | |
5694 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5695 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5696 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5697 | ||
5698 | /* Enable PG1 for cdclk */ | |
5699 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5700 | ||
5701 | /* check if cd clock is enabled */ | |
5702 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5703 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5704 | return; | |
5705 | } | |
5706 | ||
5707 | /* | |
5708 | * FIXME: | |
5709 | * - The initial CDCLK needs to be read from VBT. | |
5710 | * Need to make this change after VBT has changes for BXT. | |
5711 | * - check if setting the max (or any) cdclk freq is really necessary | |
5712 | * here, it belongs to modeset time | |
5713 | */ | |
5714 | broxton_set_cdclk(dev, 624000); | |
5715 | ||
5716 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5717 | POSTING_READ(DBUF_CTL); | |
5718 | ||
5719 | udelay(10); | |
5720 | ||
5721 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5722 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5723 | } | |
5724 | ||
5725 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5726 | { | |
5727 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5728 | ||
5729 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5730 | POSTING_READ(DBUF_CTL); | |
5731 | ||
5732 | udelay(10); | |
5733 | ||
5734 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5735 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5736 | ||
5737 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5738 | broxton_set_cdclk(dev, 19200); | |
5739 | ||
5740 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5741 | } | |
5742 | ||
5743 | static const struct skl_cdclk_entry { | |
5744 | unsigned int freq; | |
5745 | unsigned int vco; | |
5746 | } skl_cdclk_frequencies[] = { | |
5747 | { .freq = 308570, .vco = 8640 }, | |
5748 | { .freq = 337500, .vco = 8100 }, | |
5749 | { .freq = 432000, .vco = 8640 }, | |
5750 | { .freq = 450000, .vco = 8100 }, | |
5751 | { .freq = 540000, .vco = 8100 }, | |
5752 | { .freq = 617140, .vco = 8640 }, | |
5753 | { .freq = 675000, .vco = 8100 }, | |
5754 | }; | |
5755 | ||
5756 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5757 | { | |
5758 | return (freq - 1000) / 500; | |
5759 | } | |
5760 | ||
5761 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5762 | { | |
5763 | unsigned int i; | |
5764 | ||
5765 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5766 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5767 | ||
5768 | if (e->freq == freq) | |
5769 | return e->vco; | |
5770 | } | |
5771 | ||
5772 | return 8100; | |
5773 | } | |
5774 | ||
5775 | static void | |
5776 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5777 | { | |
5778 | unsigned int min_freq; | |
5779 | u32 val; | |
5780 | ||
5781 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5782 | val = I915_READ(CDCLK_CTL); | |
5783 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5784 | val |= CDCLK_FREQ_337_308; | |
5785 | ||
5786 | if (required_vco == 8640) | |
5787 | min_freq = 308570; | |
5788 | else | |
5789 | min_freq = 337500; | |
5790 | ||
5791 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5792 | ||
5793 | I915_WRITE(CDCLK_CTL, val); | |
5794 | POSTING_READ(CDCLK_CTL); | |
5795 | ||
5796 | /* | |
5797 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5798 | * taking into account the VCO required to operate the eDP panel at the | |
5799 | * desired frequency. The usual DP link rates operate with a VCO of | |
5800 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5801 | * The modeset code is responsible for the selection of the exact link | |
5802 | * rate later on, with the constraint of choosing a frequency that | |
5803 | * works with required_vco. | |
5804 | */ | |
5805 | val = I915_READ(DPLL_CTRL1); | |
5806 | ||
5807 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5808 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5809 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5810 | if (required_vco == 8640) | |
5811 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5812 | SKL_DPLL0); | |
5813 | else | |
5814 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5815 | SKL_DPLL0); | |
5816 | ||
5817 | I915_WRITE(DPLL_CTRL1, val); | |
5818 | POSTING_READ(DPLL_CTRL1); | |
5819 | ||
5820 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5821 | ||
5822 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5823 | DRM_ERROR("DPLL0 not locked\n"); | |
5824 | } | |
5825 | ||
5826 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5827 | { | |
5828 | int ret; | |
5829 | u32 val; | |
5830 | ||
5831 | /* inform PCU we want to change CDCLK */ | |
5832 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5833 | mutex_lock(&dev_priv->rps.hw_lock); | |
5834 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5835 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5836 | ||
5837 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5838 | } | |
5839 | ||
5840 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5841 | { | |
5842 | unsigned int i; | |
5843 | ||
5844 | for (i = 0; i < 15; i++) { | |
5845 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5846 | return true; | |
5847 | udelay(10); | |
5848 | } | |
5849 | ||
5850 | return false; | |
5851 | } | |
5852 | ||
5853 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5854 | { | |
5855 | struct drm_device *dev = dev_priv->dev; | |
5856 | u32 freq_select, pcu_ack; | |
5857 | ||
5858 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5859 | ||
5860 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5861 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5862 | return; | |
5863 | } | |
5864 | ||
5865 | /* set CDCLK_CTL */ | |
5866 | switch(freq) { | |
5867 | case 450000: | |
5868 | case 432000: | |
5869 | freq_select = CDCLK_FREQ_450_432; | |
5870 | pcu_ack = 1; | |
5871 | break; | |
5872 | case 540000: | |
5873 | freq_select = CDCLK_FREQ_540; | |
5874 | pcu_ack = 2; | |
5875 | break; | |
5876 | case 308570: | |
5877 | case 337500: | |
5878 | default: | |
5879 | freq_select = CDCLK_FREQ_337_308; | |
5880 | pcu_ack = 0; | |
5881 | break; | |
5882 | case 617140: | |
5883 | case 675000: | |
5884 | freq_select = CDCLK_FREQ_675_617; | |
5885 | pcu_ack = 3; | |
5886 | break; | |
5887 | } | |
5888 | ||
5889 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5890 | POSTING_READ(CDCLK_CTL); | |
5891 | ||
5892 | /* inform PCU of the change */ | |
5893 | mutex_lock(&dev_priv->rps.hw_lock); | |
5894 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5895 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5896 | ||
5897 | intel_update_cdclk(dev); | |
5898 | } | |
5899 | ||
5900 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5901 | { | |
5902 | /* disable DBUF power */ | |
5903 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5904 | POSTING_READ(DBUF_CTL); | |
5905 | ||
5906 | udelay(10); | |
5907 | ||
5908 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5909 | DRM_ERROR("DBuf power disable timeout\n"); | |
5910 | ||
5911 | /* disable DPLL0 */ | |
5912 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5913 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5914 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5915 | } | |
5916 | ||
5917 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5918 | { | |
5919 | unsigned int required_vco; | |
5920 | ||
5921 | /* DPLL0 not enabled (happens on early BIOS versions) */ | |
5922 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5923 | /* enable DPLL0 */ | |
5924 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5925 | skl_dpll0_enable(dev_priv, required_vco); | |
5926 | } | |
5927 | ||
5928 | /* set CDCLK to the frequency the BIOS chose */ | |
5929 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5930 | ||
5931 | /* enable DBUF power */ | |
5932 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5933 | POSTING_READ(DBUF_CTL); | |
5934 | ||
5935 | udelay(10); | |
5936 | ||
5937 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5938 | DRM_ERROR("DBuf power enable timeout\n"); | |
5939 | } | |
5940 | ||
5941 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) | |
5942 | { | |
5943 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5944 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5945 | int freq = dev_priv->skl_boot_cdclk; | |
5946 | ||
5947 | /* | |
5948 | * check if the pre-os intialized the display | |
5949 | * There is SWF18 scratchpad register defined which is set by the | |
5950 | * pre-os which can be used by the OS drivers to check the status | |
5951 | */ | |
5952 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5953 | goto sanitize; | |
5954 | ||
5955 | /* Is PLL enabled and locked ? */ | |
5956 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5957 | goto sanitize; | |
5958 | ||
5959 | /* DPLL okay; verify the cdclock | |
5960 | * | |
5961 | * Noticed in some instances that the freq selection is correct but | |
5962 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5963 | * enable display. Verify the same as well. | |
5964 | */ | |
5965 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5966 | /* All well; nothing to sanitize */ | |
5967 | return false; | |
5968 | sanitize: | |
5969 | /* | |
5970 | * As of now initialize with max cdclk till | |
5971 | * we get dynamic cdclk support | |
5972 | * */ | |
5973 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5974 | skl_init_cdclk(dev_priv); | |
5975 | ||
5976 | /* we did have to sanitize */ | |
5977 | return true; | |
5978 | } | |
5979 | ||
5980 | /* Adjust CDclk dividers to allow high res or save power if possible */ | |
5981 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5982 | { | |
5983 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5984 | u32 val, cmd; | |
5985 | ||
5986 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) | |
5987 | != dev_priv->cdclk_freq); | |
5988 | ||
5989 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ | |
5990 | cmd = 2; | |
5991 | else if (cdclk == 266667) | |
5992 | cmd = 1; | |
5993 | else | |
5994 | cmd = 0; | |
5995 | ||
5996 | mutex_lock(&dev_priv->rps.hw_lock); | |
5997 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5998 | val &= ~DSPFREQGUAR_MASK; | |
5999 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
6000 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
6001 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
6002 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
6003 | 50)) { | |
6004 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
6005 | } | |
6006 | mutex_unlock(&dev_priv->rps.hw_lock); | |
6007 | ||
6008 | mutex_lock(&dev_priv->sb_lock); | |
6009 | ||
6010 | if (cdclk == 400000) { | |
6011 | u32 divider; | |
6012 | ||
6013 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
6014 | ||
6015 | /* adjust cdclk divider */ | |
6016 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
6017 | val &= ~CCK_FREQUENCY_VALUES; | |
6018 | val |= divider; | |
6019 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
6020 | ||
6021 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
6022 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), | |
6023 | 50)) | |
6024 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
6025 | } | |
6026 | ||
6027 | /* adjust self-refresh exit latency value */ | |
6028 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
6029 | val &= ~0x7f; | |
6030 | ||
6031 | /* | |
6032 | * For high bandwidth configs, we set a higher latency in the bunit | |
6033 | * so that the core display fetch happens in time to avoid underruns. | |
6034 | */ | |
6035 | if (cdclk == 400000) | |
6036 | val |= 4500 / 250; /* 4.5 usec */ | |
6037 | else | |
6038 | val |= 3000 / 250; /* 3.0 usec */ | |
6039 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
6040 | ||
6041 | mutex_unlock(&dev_priv->sb_lock); | |
6042 | ||
6043 | intel_update_cdclk(dev); | |
6044 | } | |
6045 | ||
6046 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) | |
6047 | { | |
6048 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6049 | u32 val, cmd; | |
6050 | ||
6051 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) | |
6052 | != dev_priv->cdclk_freq); | |
6053 | ||
6054 | switch (cdclk) { | |
6055 | case 333333: | |
6056 | case 320000: | |
6057 | case 266667: | |
6058 | case 200000: | |
6059 | break; | |
6060 | default: | |
6061 | MISSING_CASE(cdclk); | |
6062 | return; | |
6063 | } | |
6064 | ||
6065 | /* | |
6066 | * Specs are full of misinformation, but testing on actual | |
6067 | * hardware has shown that we just need to write the desired | |
6068 | * CCK divider into the Punit register. | |
6069 | */ | |
6070 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
6071 | ||
6072 | mutex_lock(&dev_priv->rps.hw_lock); | |
6073 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
6074 | val &= ~DSPFREQGUAR_MASK_CHV; | |
6075 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
6076 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
6077 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
6078 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
6079 | 50)) { | |
6080 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
6081 | } | |
6082 | mutex_unlock(&dev_priv->rps.hw_lock); | |
6083 | ||
6084 | intel_update_cdclk(dev); | |
6085 | } | |
6086 | ||
6087 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, | |
6088 | int max_pixclk) | |
6089 | { | |
6090 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; | |
6091 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; | |
6092 | ||
6093 | /* | |
6094 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
6095 | * 200MHz | |
6096 | * 267MHz | |
6097 | * 320/333MHz (depends on HPLL freq) | |
6098 | * 400MHz (VLV only) | |
6099 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
6100 | * of the lower bin and adjust if needed. | |
6101 | * | |
6102 | * We seem to get an unstable or solid color picture at 200MHz. | |
6103 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
6104 | * are off. | |
6105 | */ | |
6106 | if (!IS_CHERRYVIEW(dev_priv) && | |
6107 | max_pixclk > freq_320*limit/100) | |
6108 | return 400000; | |
6109 | else if (max_pixclk > 266667*limit/100) | |
6110 | return freq_320; | |
6111 | else if (max_pixclk > 0) | |
6112 | return 266667; | |
6113 | else | |
6114 | return 200000; | |
6115 | } | |
6116 | ||
6117 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, | |
6118 | int max_pixclk) | |
6119 | { | |
6120 | /* | |
6121 | * FIXME: | |
6122 | * - remove the guardband, it's not needed on BXT | |
6123 | * - set 19.2MHz bypass frequency if there are no active pipes | |
6124 | */ | |
6125 | if (max_pixclk > 576000*9/10) | |
6126 | return 624000; | |
6127 | else if (max_pixclk > 384000*9/10) | |
6128 | return 576000; | |
6129 | else if (max_pixclk > 288000*9/10) | |
6130 | return 384000; | |
6131 | else if (max_pixclk > 144000*9/10) | |
6132 | return 288000; | |
6133 | else | |
6134 | return 144000; | |
6135 | } | |
6136 | ||
6137 | /* Compute the max pixel clock for new configuration. */ | |
6138 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
6139 | struct drm_atomic_state *state) | |
6140 | { | |
6141 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
6142 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6143 | struct drm_crtc *crtc; | |
6144 | struct drm_crtc_state *crtc_state; | |
6145 | unsigned max_pixclk = 0, i; | |
6146 | enum pipe pipe; | |
6147 | ||
6148 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, | |
6149 | sizeof(intel_state->min_pixclk)); | |
6150 | ||
6151 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
6152 | int pixclk = 0; | |
6153 | ||
6154 | if (crtc_state->enable) | |
6155 | pixclk = crtc_state->adjusted_mode.crtc_clock; | |
6156 | ||
6157 | intel_state->min_pixclk[i] = pixclk; | |
6158 | } | |
6159 | ||
6160 | for_each_pipe(dev_priv, pipe) | |
6161 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); | |
6162 | ||
6163 | return max_pixclk; | |
6164 | } | |
6165 | ||
6166 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) | |
6167 | { | |
6168 | struct drm_device *dev = state->dev; | |
6169 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6170 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
6171 | struct intel_atomic_state *intel_state = | |
6172 | to_intel_atomic_state(state); | |
6173 | ||
6174 | if (max_pixclk < 0) | |
6175 | return max_pixclk; | |
6176 | ||
6177 | intel_state->cdclk = intel_state->dev_cdclk = | |
6178 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
6179 | ||
6180 | if (!intel_state->active_crtcs) | |
6181 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); | |
6182 | ||
6183 | return 0; | |
6184 | } | |
6185 | ||
6186 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) | |
6187 | { | |
6188 | struct drm_device *dev = state->dev; | |
6189 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6190 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
6191 | struct intel_atomic_state *intel_state = | |
6192 | to_intel_atomic_state(state); | |
6193 | ||
6194 | if (max_pixclk < 0) | |
6195 | return max_pixclk; | |
6196 | ||
6197 | intel_state->cdclk = intel_state->dev_cdclk = | |
6198 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
6199 | ||
6200 | if (!intel_state->active_crtcs) | |
6201 | intel_state->dev_cdclk = broxton_calc_cdclk(dev_priv, 0); | |
6202 | ||
6203 | return 0; | |
6204 | } | |
6205 | ||
6206 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) | |
6207 | { | |
6208 | unsigned int credits, default_credits; | |
6209 | ||
6210 | if (IS_CHERRYVIEW(dev_priv)) | |
6211 | default_credits = PFI_CREDIT(12); | |
6212 | else | |
6213 | default_credits = PFI_CREDIT(8); | |
6214 | ||
6215 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { | |
6216 | /* CHV suggested value is 31 or 63 */ | |
6217 | if (IS_CHERRYVIEW(dev_priv)) | |
6218 | credits = PFI_CREDIT_63; | |
6219 | else | |
6220 | credits = PFI_CREDIT(15); | |
6221 | } else { | |
6222 | credits = default_credits; | |
6223 | } | |
6224 | ||
6225 | /* | |
6226 | * WA - write default credits before re-programming | |
6227 | * FIXME: should we also set the resend bit here? | |
6228 | */ | |
6229 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6230 | default_credits); | |
6231 | ||
6232 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6233 | credits | PFI_CREDIT_RESEND); | |
6234 | ||
6235 | /* | |
6236 | * FIXME is this guaranteed to clear | |
6237 | * immediately or should we poll for it? | |
6238 | */ | |
6239 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6240 | } | |
6241 | ||
6242 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) | |
6243 | { | |
6244 | struct drm_device *dev = old_state->dev; | |
6245 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6246 | struct intel_atomic_state *old_intel_state = | |
6247 | to_intel_atomic_state(old_state); | |
6248 | unsigned req_cdclk = old_intel_state->dev_cdclk; | |
6249 | ||
6250 | /* | |
6251 | * FIXME: We can end up here with all power domains off, yet | |
6252 | * with a CDCLK frequency other than the minimum. To account | |
6253 | * for this take the PIPE-A power domain, which covers the HW | |
6254 | * blocks needed for the following programming. This can be | |
6255 | * removed once it's guaranteed that we get here either with | |
6256 | * the minimum CDCLK set, or the required power domains | |
6257 | * enabled. | |
6258 | */ | |
6259 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
6260 | ||
6261 | if (IS_CHERRYVIEW(dev)) | |
6262 | cherryview_set_cdclk(dev, req_cdclk); | |
6263 | else | |
6264 | valleyview_set_cdclk(dev, req_cdclk); | |
6265 | ||
6266 | vlv_program_pfi_credits(dev_priv); | |
6267 | ||
6268 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); | |
6269 | } | |
6270 | ||
6271 | static void valleyview_crtc_enable(struct drm_crtc *crtc) | |
6272 | { | |
6273 | struct drm_device *dev = crtc->dev; | |
6274 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6275 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6276 | struct intel_encoder *encoder; | |
6277 | int pipe = intel_crtc->pipe; | |
6278 | ||
6279 | if (WARN_ON(intel_crtc->active)) | |
6280 | return; | |
6281 | ||
6282 | if (intel_crtc->config->has_dp_encoder) | |
6283 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
6284 | ||
6285 | intel_set_pipe_timings(intel_crtc); | |
6286 | ||
6287 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { | |
6288 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6289 | ||
6290 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6291 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6292 | } | |
6293 | ||
6294 | i9xx_set_pipeconf(intel_crtc); | |
6295 | ||
6296 | intel_crtc->active = true; | |
6297 | ||
6298 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
6299 | ||
6300 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6301 | if (encoder->pre_pll_enable) | |
6302 | encoder->pre_pll_enable(encoder); | |
6303 | ||
6304 | if (!intel_crtc->config->has_dsi_encoder) { | |
6305 | if (IS_CHERRYVIEW(dev)) { | |
6306 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6307 | chv_enable_pll(intel_crtc, intel_crtc->config); | |
6308 | } else { | |
6309 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6310 | vlv_enable_pll(intel_crtc, intel_crtc->config); | |
6311 | } | |
6312 | } | |
6313 | ||
6314 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6315 | if (encoder->pre_enable) | |
6316 | encoder->pre_enable(encoder); | |
6317 | ||
6318 | i9xx_pfit_enable(intel_crtc); | |
6319 | ||
6320 | intel_crtc_load_lut(crtc); | |
6321 | ||
6322 | intel_enable_pipe(intel_crtc); | |
6323 | ||
6324 | assert_vblank_disabled(crtc); | |
6325 | drm_crtc_vblank_on(crtc); | |
6326 | ||
6327 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6328 | encoder->enable(encoder); | |
6329 | } | |
6330 | ||
6331 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) | |
6332 | { | |
6333 | struct drm_device *dev = crtc->base.dev; | |
6334 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6335 | ||
6336 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); | |
6337 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
6338 | } | |
6339 | ||
6340 | static void i9xx_crtc_enable(struct drm_crtc *crtc) | |
6341 | { | |
6342 | struct drm_device *dev = crtc->dev; | |
6343 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6344 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6345 | struct intel_encoder *encoder; | |
6346 | int pipe = intel_crtc->pipe; | |
6347 | ||
6348 | if (WARN_ON(intel_crtc->active)) | |
6349 | return; | |
6350 | ||
6351 | i9xx_set_pll_dividers(intel_crtc); | |
6352 | ||
6353 | if (intel_crtc->config->has_dp_encoder) | |
6354 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
6355 | ||
6356 | intel_set_pipe_timings(intel_crtc); | |
6357 | ||
6358 | i9xx_set_pipeconf(intel_crtc); | |
6359 | ||
6360 | intel_crtc->active = true; | |
6361 | ||
6362 | if (!IS_GEN2(dev)) | |
6363 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
6364 | ||
6365 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6366 | if (encoder->pre_enable) | |
6367 | encoder->pre_enable(encoder); | |
6368 | ||
6369 | i9xx_enable_pll(intel_crtc); | |
6370 | ||
6371 | i9xx_pfit_enable(intel_crtc); | |
6372 | ||
6373 | intel_crtc_load_lut(crtc); | |
6374 | ||
6375 | intel_update_watermarks(crtc); | |
6376 | intel_enable_pipe(intel_crtc); | |
6377 | ||
6378 | assert_vblank_disabled(crtc); | |
6379 | drm_crtc_vblank_on(crtc); | |
6380 | ||
6381 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6382 | encoder->enable(encoder); | |
6383 | } | |
6384 | ||
6385 | static void i9xx_pfit_disable(struct intel_crtc *crtc) | |
6386 | { | |
6387 | struct drm_device *dev = crtc->base.dev; | |
6388 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6389 | ||
6390 | if (!crtc->config->gmch_pfit.control) | |
6391 | return; | |
6392 | ||
6393 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
6394 | ||
6395 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", | |
6396 | I915_READ(PFIT_CONTROL)); | |
6397 | I915_WRITE(PFIT_CONTROL, 0); | |
6398 | } | |
6399 | ||
6400 | static void i9xx_crtc_disable(struct drm_crtc *crtc) | |
6401 | { | |
6402 | struct drm_device *dev = crtc->dev; | |
6403 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6404 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6405 | struct intel_encoder *encoder; | |
6406 | int pipe = intel_crtc->pipe; | |
6407 | ||
6408 | /* | |
6409 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6410 | * wait for planes to fully turn off before disabling the pipe. | |
6411 | * We also need to wait on all gmch platforms because of the | |
6412 | * self-refresh mode constraint explained above. | |
6413 | */ | |
6414 | intel_wait_for_vblank(dev, pipe); | |
6415 | ||
6416 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6417 | encoder->disable(encoder); | |
6418 | ||
6419 | drm_crtc_vblank_off(crtc); | |
6420 | assert_vblank_disabled(crtc); | |
6421 | ||
6422 | intel_disable_pipe(intel_crtc); | |
6423 | ||
6424 | i9xx_pfit_disable(intel_crtc); | |
6425 | ||
6426 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6427 | if (encoder->post_disable) | |
6428 | encoder->post_disable(encoder); | |
6429 | ||
6430 | if (!intel_crtc->config->has_dsi_encoder) { | |
6431 | if (IS_CHERRYVIEW(dev)) | |
6432 | chv_disable_pll(dev_priv, pipe); | |
6433 | else if (IS_VALLEYVIEW(dev)) | |
6434 | vlv_disable_pll(dev_priv, pipe); | |
6435 | else | |
6436 | i9xx_disable_pll(intel_crtc); | |
6437 | } | |
6438 | ||
6439 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6440 | if (encoder->post_pll_disable) | |
6441 | encoder->post_pll_disable(encoder); | |
6442 | ||
6443 | if (!IS_GEN2(dev)) | |
6444 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
6445 | } | |
6446 | ||
6447 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) | |
6448 | { | |
6449 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6450 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6451 | enum intel_display_power_domain domain; | |
6452 | unsigned long domains; | |
6453 | ||
6454 | if (!intel_crtc->active) | |
6455 | return; | |
6456 | ||
6457 | if (to_intel_plane_state(crtc->primary->state)->visible) { | |
6458 | WARN_ON(intel_crtc->unpin_work); | |
6459 | ||
6460 | intel_pre_disable_primary(crtc); | |
6461 | ||
6462 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); | |
6463 | to_intel_plane_state(crtc->primary->state)->visible = false; | |
6464 | } | |
6465 | ||
6466 | dev_priv->display.crtc_disable(crtc); | |
6467 | intel_crtc->active = false; | |
6468 | intel_fbc_disable(intel_crtc); | |
6469 | intel_update_watermarks(crtc); | |
6470 | intel_disable_shared_dpll(intel_crtc); | |
6471 | ||
6472 | domains = intel_crtc->enabled_power_domains; | |
6473 | for_each_power_domain(domain, domains) | |
6474 | intel_display_power_put(dev_priv, domain); | |
6475 | intel_crtc->enabled_power_domains = 0; | |
6476 | ||
6477 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); | |
6478 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; | |
6479 | } | |
6480 | ||
6481 | /* | |
6482 | * turn all crtc's off, but do not adjust state | |
6483 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6484 | */ | |
6485 | int intel_display_suspend(struct drm_device *dev) | |
6486 | { | |
6487 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6488 | struct drm_atomic_state *state; | |
6489 | int ret; | |
6490 | ||
6491 | state = drm_atomic_helper_suspend(dev); | |
6492 | ret = PTR_ERR_OR_ZERO(state); | |
6493 | if (ret) | |
6494 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6495 | else | |
6496 | dev_priv->modeset_restore_state = state; | |
6497 | return ret; | |
6498 | } | |
6499 | ||
6500 | void intel_encoder_destroy(struct drm_encoder *encoder) | |
6501 | { | |
6502 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); | |
6503 | ||
6504 | drm_encoder_cleanup(encoder); | |
6505 | kfree(intel_encoder); | |
6506 | } | |
6507 | ||
6508 | /* Cross check the actual hw state with our own modeset state tracking (and it's | |
6509 | * internal consistency). */ | |
6510 | static void intel_connector_check_state(struct intel_connector *connector) | |
6511 | { | |
6512 | struct drm_crtc *crtc = connector->base.state->crtc; | |
6513 | ||
6514 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6515 | connector->base.base.id, | |
6516 | connector->base.name); | |
6517 | ||
6518 | if (connector->get_hw_state(connector)) { | |
6519 | struct intel_encoder *encoder = connector->encoder; | |
6520 | struct drm_connector_state *conn_state = connector->base.state; | |
6521 | ||
6522 | I915_STATE_WARN(!crtc, | |
6523 | "connector enabled without attached crtc\n"); | |
6524 | ||
6525 | if (!crtc) | |
6526 | return; | |
6527 | ||
6528 | I915_STATE_WARN(!crtc->state->active, | |
6529 | "connector is active, but attached crtc isn't\n"); | |
6530 | ||
6531 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) | |
6532 | return; | |
6533 | ||
6534 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, | |
6535 | "atomic encoder doesn't match attached encoder\n"); | |
6536 | ||
6537 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, | |
6538 | "attached encoder crtc differs from connector crtc\n"); | |
6539 | } else { | |
6540 | I915_STATE_WARN(crtc && crtc->state->active, | |
6541 | "attached crtc is active, but connector isn't\n"); | |
6542 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, | |
6543 | "best encoder set without crtc!\n"); | |
6544 | } | |
6545 | } | |
6546 | ||
6547 | int intel_connector_init(struct intel_connector *connector) | |
6548 | { | |
6549 | drm_atomic_helper_connector_reset(&connector->base); | |
6550 | ||
6551 | if (!connector->base.state) | |
6552 | return -ENOMEM; | |
6553 | ||
6554 | return 0; | |
6555 | } | |
6556 | ||
6557 | struct intel_connector *intel_connector_alloc(void) | |
6558 | { | |
6559 | struct intel_connector *connector; | |
6560 | ||
6561 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6562 | if (!connector) | |
6563 | return NULL; | |
6564 | ||
6565 | if (intel_connector_init(connector) < 0) { | |
6566 | kfree(connector); | |
6567 | return NULL; | |
6568 | } | |
6569 | ||
6570 | return connector; | |
6571 | } | |
6572 | ||
6573 | /* Simple connector->get_hw_state implementation for encoders that support only | |
6574 | * one connector and no cloning and hence the encoder state determines the state | |
6575 | * of the connector. */ | |
6576 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
6577 | { | |
6578 | enum pipe pipe = 0; | |
6579 | struct intel_encoder *encoder = connector->encoder; | |
6580 | ||
6581 | return encoder->get_hw_state(encoder, &pipe); | |
6582 | } | |
6583 | ||
6584 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) | |
6585 | { | |
6586 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) | |
6587 | return crtc_state->fdi_lanes; | |
6588 | ||
6589 | return 0; | |
6590 | } | |
6591 | ||
6592 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, | |
6593 | struct intel_crtc_state *pipe_config) | |
6594 | { | |
6595 | struct drm_atomic_state *state = pipe_config->base.state; | |
6596 | struct intel_crtc *other_crtc; | |
6597 | struct intel_crtc_state *other_crtc_state; | |
6598 | ||
6599 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", | |
6600 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6601 | if (pipe_config->fdi_lanes > 4) { | |
6602 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6603 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6604 | return -EINVAL; | |
6605 | } | |
6606 | ||
6607 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
6608 | if (pipe_config->fdi_lanes > 2) { | |
6609 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6610 | pipe_config->fdi_lanes); | |
6611 | return -EINVAL; | |
6612 | } else { | |
6613 | return 0; | |
6614 | } | |
6615 | } | |
6616 | ||
6617 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6618 | return 0; | |
6619 | ||
6620 | /* Ivybridge 3 pipe is really complicated */ | |
6621 | switch (pipe) { | |
6622 | case PIPE_A: | |
6623 | return 0; | |
6624 | case PIPE_B: | |
6625 | if (pipe_config->fdi_lanes <= 2) | |
6626 | return 0; | |
6627 | ||
6628 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6629 | other_crtc_state = | |
6630 | intel_atomic_get_crtc_state(state, other_crtc); | |
6631 | if (IS_ERR(other_crtc_state)) | |
6632 | return PTR_ERR(other_crtc_state); | |
6633 | ||
6634 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
6635 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", | |
6636 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6637 | return -EINVAL; | |
6638 | } | |
6639 | return 0; | |
6640 | case PIPE_C: | |
6641 | if (pipe_config->fdi_lanes > 2) { | |
6642 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6643 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6644 | return -EINVAL; | |
6645 | } | |
6646 | ||
6647 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6648 | other_crtc_state = | |
6649 | intel_atomic_get_crtc_state(state, other_crtc); | |
6650 | if (IS_ERR(other_crtc_state)) | |
6651 | return PTR_ERR(other_crtc_state); | |
6652 | ||
6653 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
6654 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); | |
6655 | return -EINVAL; | |
6656 | } | |
6657 | return 0; | |
6658 | default: | |
6659 | BUG(); | |
6660 | } | |
6661 | } | |
6662 | ||
6663 | #define RETRY 1 | |
6664 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
6665 | struct intel_crtc_state *pipe_config) | |
6666 | { | |
6667 | struct drm_device *dev = intel_crtc->base.dev; | |
6668 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; | |
6669 | int lane, link_bw, fdi_dotclock, ret; | |
6670 | bool needs_recompute = false; | |
6671 | ||
6672 | retry: | |
6673 | /* FDI is a binary signal running at ~2.7GHz, encoding | |
6674 | * each output octet as 10 bits. The actual frequency | |
6675 | * is stored as a divider into a 100MHz clock, and the | |
6676 | * mode pixel clock is stored in units of 1KHz. | |
6677 | * Hence the bw of each lane in terms of the mode signal | |
6678 | * is: | |
6679 | */ | |
6680 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6681 | ||
6682 | fdi_dotclock = adjusted_mode->crtc_clock; | |
6683 | ||
6684 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, | |
6685 | pipe_config->pipe_bpp); | |
6686 | ||
6687 | pipe_config->fdi_lanes = lane; | |
6688 | ||
6689 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, | |
6690 | link_bw, &pipe_config->fdi_m_n); | |
6691 | ||
6692 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, | |
6693 | intel_crtc->pipe, pipe_config); | |
6694 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
6695 | pipe_config->pipe_bpp -= 2*3; | |
6696 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6697 | pipe_config->pipe_bpp); | |
6698 | needs_recompute = true; | |
6699 | pipe_config->bw_constrained = true; | |
6700 | ||
6701 | goto retry; | |
6702 | } | |
6703 | ||
6704 | if (needs_recompute) | |
6705 | return RETRY; | |
6706 | ||
6707 | return ret; | |
6708 | } | |
6709 | ||
6710 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, | |
6711 | struct intel_crtc_state *pipe_config) | |
6712 | { | |
6713 | if (pipe_config->pipe_bpp > 24) | |
6714 | return false; | |
6715 | ||
6716 | /* HSW can handle pixel rate up to cdclk? */ | |
6717 | if (IS_HASWELL(dev_priv->dev)) | |
6718 | return true; | |
6719 | ||
6720 | /* | |
6721 | * We compare against max which means we must take | |
6722 | * the increased cdclk requirement into account when | |
6723 | * calculating the new cdclk. | |
6724 | * | |
6725 | * Should measure whether using a lower cdclk w/o IPS | |
6726 | */ | |
6727 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6728 | dev_priv->max_cdclk_freq * 95 / 100; | |
6729 | } | |
6730 | ||
6731 | static void hsw_compute_ips_config(struct intel_crtc *crtc, | |
6732 | struct intel_crtc_state *pipe_config) | |
6733 | { | |
6734 | struct drm_device *dev = crtc->base.dev; | |
6735 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6736 | ||
6737 | pipe_config->ips_enabled = i915.enable_ips && | |
6738 | hsw_crtc_supports_ips(crtc) && | |
6739 | pipe_config_supports_ips(dev_priv, pipe_config); | |
6740 | } | |
6741 | ||
6742 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) | |
6743 | { | |
6744 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6745 | ||
6746 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6747 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6748 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6749 | } | |
6750 | ||
6751 | static int intel_crtc_compute_config(struct intel_crtc *crtc, | |
6752 | struct intel_crtc_state *pipe_config) | |
6753 | { | |
6754 | struct drm_device *dev = crtc->base.dev; | |
6755 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6756 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; | |
6757 | ||
6758 | /* FIXME should check pixel clock limits on all platforms */ | |
6759 | if (INTEL_INFO(dev)->gen < 4) { | |
6760 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; | |
6761 | ||
6762 | /* | |
6763 | * Enable double wide mode when the dot clock | |
6764 | * is > 90% of the (display) core speed. | |
6765 | */ | |
6766 | if (intel_crtc_supports_double_wide(crtc) && | |
6767 | adjusted_mode->crtc_clock > clock_limit) { | |
6768 | clock_limit *= 2; | |
6769 | pipe_config->double_wide = true; | |
6770 | } | |
6771 | ||
6772 | if (adjusted_mode->crtc_clock > clock_limit) { | |
6773 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6774 | adjusted_mode->crtc_clock, clock_limit, | |
6775 | yesno(pipe_config->double_wide)); | |
6776 | return -EINVAL; | |
6777 | } | |
6778 | } | |
6779 | ||
6780 | /* | |
6781 | * Pipe horizontal size must be even in: | |
6782 | * - DVO ganged mode | |
6783 | * - LVDS dual channel mode | |
6784 | * - Double wide pipe | |
6785 | */ | |
6786 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && | |
6787 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) | |
6788 | pipe_config->pipe_src_w &= ~1; | |
6789 | ||
6790 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. | |
6791 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
6792 | */ | |
6793 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
6794 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) | |
6795 | return -EINVAL; | |
6796 | ||
6797 | if (HAS_IPS(dev)) | |
6798 | hsw_compute_ips_config(crtc, pipe_config); | |
6799 | ||
6800 | if (pipe_config->has_pch_encoder) | |
6801 | return ironlake_fdi_compute_config(crtc, pipe_config); | |
6802 | ||
6803 | return 0; | |
6804 | } | |
6805 | ||
6806 | static int skylake_get_display_clock_speed(struct drm_device *dev) | |
6807 | { | |
6808 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6809 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6810 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6811 | uint32_t linkrate; | |
6812 | ||
6813 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) | |
6814 | return 24000; /* 24MHz is the cd freq with NSSC ref */ | |
6815 | ||
6816 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6817 | return 540000; | |
6818 | ||
6819 | linkrate = (I915_READ(DPLL_CTRL1) & | |
6820 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; | |
6821 | ||
6822 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || | |
6823 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
6824 | /* vco 8640 */ | |
6825 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6826 | case CDCLK_FREQ_450_432: | |
6827 | return 432000; | |
6828 | case CDCLK_FREQ_337_308: | |
6829 | return 308570; | |
6830 | case CDCLK_FREQ_675_617: | |
6831 | return 617140; | |
6832 | default: | |
6833 | WARN(1, "Unknown cd freq selection\n"); | |
6834 | } | |
6835 | } else { | |
6836 | /* vco 8100 */ | |
6837 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6838 | case CDCLK_FREQ_450_432: | |
6839 | return 450000; | |
6840 | case CDCLK_FREQ_337_308: | |
6841 | return 337500; | |
6842 | case CDCLK_FREQ_675_617: | |
6843 | return 675000; | |
6844 | default: | |
6845 | WARN(1, "Unknown cd freq selection\n"); | |
6846 | } | |
6847 | } | |
6848 | ||
6849 | /* error case, do as if DPLL0 isn't enabled */ | |
6850 | return 24000; | |
6851 | } | |
6852 | ||
6853 | static int broxton_get_display_clock_speed(struct drm_device *dev) | |
6854 | { | |
6855 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6856 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6857 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6858 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6859 | int cdclk; | |
6860 | ||
6861 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6862 | return 19200; | |
6863 | ||
6864 | cdclk = 19200 * pll_ratio / 2; | |
6865 | ||
6866 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6867 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6868 | return cdclk; /* 576MHz or 624MHz */ | |
6869 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6870 | return cdclk * 2 / 3; /* 384MHz */ | |
6871 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6872 | return cdclk / 2; /* 288MHz */ | |
6873 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6874 | return cdclk / 4; /* 144MHz */ | |
6875 | } | |
6876 | ||
6877 | /* error case, do as if DE PLL isn't enabled */ | |
6878 | return 19200; | |
6879 | } | |
6880 | ||
6881 | static int broadwell_get_display_clock_speed(struct drm_device *dev) | |
6882 | { | |
6883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6884 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6885 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6886 | ||
6887 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6888 | return 800000; | |
6889 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6890 | return 450000; | |
6891 | else if (freq == LCPLL_CLK_FREQ_450) | |
6892 | return 450000; | |
6893 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6894 | return 540000; | |
6895 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6896 | return 337500; | |
6897 | else | |
6898 | return 675000; | |
6899 | } | |
6900 | ||
6901 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6902 | { | |
6903 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6904 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6905 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6906 | ||
6907 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6908 | return 800000; | |
6909 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6910 | return 450000; | |
6911 | else if (freq == LCPLL_CLK_FREQ_450) | |
6912 | return 450000; | |
6913 | else if (IS_HSW_ULT(dev)) | |
6914 | return 337500; | |
6915 | else | |
6916 | return 540000; | |
6917 | } | |
6918 | ||
6919 | static int valleyview_get_display_clock_speed(struct drm_device *dev) | |
6920 | { | |
6921 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", | |
6922 | CCK_DISPLAY_CLOCK_CONTROL); | |
6923 | } | |
6924 | ||
6925 | static int ilk_get_display_clock_speed(struct drm_device *dev) | |
6926 | { | |
6927 | return 450000; | |
6928 | } | |
6929 | ||
6930 | static int i945_get_display_clock_speed(struct drm_device *dev) | |
6931 | { | |
6932 | return 400000; | |
6933 | } | |
6934 | ||
6935 | static int i915_get_display_clock_speed(struct drm_device *dev) | |
6936 | { | |
6937 | return 333333; | |
6938 | } | |
6939 | ||
6940 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) | |
6941 | { | |
6942 | return 200000; | |
6943 | } | |
6944 | ||
6945 | static int pnv_get_display_clock_speed(struct drm_device *dev) | |
6946 | { | |
6947 | u16 gcfgc = 0; | |
6948 | ||
6949 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6950 | ||
6951 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6952 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
6953 | return 266667; | |
6954 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: | |
6955 | return 333333; | |
6956 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: | |
6957 | return 444444; | |
6958 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: | |
6959 | return 200000; | |
6960 | default: | |
6961 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6962 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
6963 | return 133333; | |
6964 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: | |
6965 | return 166667; | |
6966 | } | |
6967 | } | |
6968 | ||
6969 | static int i915gm_get_display_clock_speed(struct drm_device *dev) | |
6970 | { | |
6971 | u16 gcfgc = 0; | |
6972 | ||
6973 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6974 | ||
6975 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
6976 | return 133333; | |
6977 | else { | |
6978 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6979 | case GC_DISPLAY_CLOCK_333_MHZ: | |
6980 | return 333333; | |
6981 | default: | |
6982 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6983 | return 190000; | |
6984 | } | |
6985 | } | |
6986 | } | |
6987 | ||
6988 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6989 | { | |
6990 | return 266667; | |
6991 | } | |
6992 | ||
6993 | static int i85x_get_display_clock_speed(struct drm_device *dev) | |
6994 | { | |
6995 | u16 hpllcc = 0; | |
6996 | ||
6997 | /* | |
6998 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6999 | * encoding is different :( | |
7000 | * FIXME is this the right way to detect 852GM/852GMV? | |
7001 | */ | |
7002 | if (dev->pdev->revision == 0x1) | |
7003 | return 133333; | |
7004 | ||
7005 | pci_bus_read_config_word(dev->pdev->bus, | |
7006 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
7007 | ||
7008 | /* Assume that the hardware is in the high speed state. This | |
7009 | * should be the default. | |
7010 | */ | |
7011 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
7012 | case GC_CLOCK_133_200: | |
7013 | case GC_CLOCK_133_200_2: | |
7014 | case GC_CLOCK_100_200: | |
7015 | return 200000; | |
7016 | case GC_CLOCK_166_250: | |
7017 | return 250000; | |
7018 | case GC_CLOCK_100_133: | |
7019 | return 133333; | |
7020 | case GC_CLOCK_133_266: | |
7021 | case GC_CLOCK_133_266_2: | |
7022 | case GC_CLOCK_166_266: | |
7023 | return 266667; | |
7024 | } | |
7025 | ||
7026 | /* Shouldn't happen */ | |
7027 | return 0; | |
7028 | } | |
7029 | ||
7030 | static int i830_get_display_clock_speed(struct drm_device *dev) | |
7031 | { | |
7032 | return 133333; | |
7033 | } | |
7034 | ||
7035 | static unsigned int intel_hpll_vco(struct drm_device *dev) | |
7036 | { | |
7037 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7038 | static const unsigned int blb_vco[8] = { | |
7039 | [0] = 3200000, | |
7040 | [1] = 4000000, | |
7041 | [2] = 5333333, | |
7042 | [3] = 4800000, | |
7043 | [4] = 6400000, | |
7044 | }; | |
7045 | static const unsigned int pnv_vco[8] = { | |
7046 | [0] = 3200000, | |
7047 | [1] = 4000000, | |
7048 | [2] = 5333333, | |
7049 | [3] = 4800000, | |
7050 | [4] = 2666667, | |
7051 | }; | |
7052 | static const unsigned int cl_vco[8] = { | |
7053 | [0] = 3200000, | |
7054 | [1] = 4000000, | |
7055 | [2] = 5333333, | |
7056 | [3] = 6400000, | |
7057 | [4] = 3333333, | |
7058 | [5] = 3566667, | |
7059 | [6] = 4266667, | |
7060 | }; | |
7061 | static const unsigned int elk_vco[8] = { | |
7062 | [0] = 3200000, | |
7063 | [1] = 4000000, | |
7064 | [2] = 5333333, | |
7065 | [3] = 4800000, | |
7066 | }; | |
7067 | static const unsigned int ctg_vco[8] = { | |
7068 | [0] = 3200000, | |
7069 | [1] = 4000000, | |
7070 | [2] = 5333333, | |
7071 | [3] = 6400000, | |
7072 | [4] = 2666667, | |
7073 | [5] = 4266667, | |
7074 | }; | |
7075 | const unsigned int *vco_table; | |
7076 | unsigned int vco; | |
7077 | uint8_t tmp = 0; | |
7078 | ||
7079 | /* FIXME other chipsets? */ | |
7080 | if (IS_GM45(dev)) | |
7081 | vco_table = ctg_vco; | |
7082 | else if (IS_G4X(dev)) | |
7083 | vco_table = elk_vco; | |
7084 | else if (IS_CRESTLINE(dev)) | |
7085 | vco_table = cl_vco; | |
7086 | else if (IS_PINEVIEW(dev)) | |
7087 | vco_table = pnv_vco; | |
7088 | else if (IS_G33(dev)) | |
7089 | vco_table = blb_vco; | |
7090 | else | |
7091 | return 0; | |
7092 | ||
7093 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
7094 | ||
7095 | vco = vco_table[tmp & 0x7]; | |
7096 | if (vco == 0) | |
7097 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
7098 | else | |
7099 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
7100 | ||
7101 | return vco; | |
7102 | } | |
7103 | ||
7104 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
7105 | { | |
7106 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7107 | uint16_t tmp = 0; | |
7108 | ||
7109 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7110 | ||
7111 | cdclk_sel = (tmp >> 12) & 0x1; | |
7112 | ||
7113 | switch (vco) { | |
7114 | case 2666667: | |
7115 | case 4000000: | |
7116 | case 5333333: | |
7117 | return cdclk_sel ? 333333 : 222222; | |
7118 | case 3200000: | |
7119 | return cdclk_sel ? 320000 : 228571; | |
7120 | default: | |
7121 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
7122 | return 222222; | |
7123 | } | |
7124 | } | |
7125 | ||
7126 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
7127 | { | |
7128 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
7129 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
7130 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
7131 | const uint8_t *div_table; | |
7132 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7133 | uint16_t tmp = 0; | |
7134 | ||
7135 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7136 | ||
7137 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
7138 | ||
7139 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7140 | goto fail; | |
7141 | ||
7142 | switch (vco) { | |
7143 | case 3200000: | |
7144 | div_table = div_3200; | |
7145 | break; | |
7146 | case 4000000: | |
7147 | div_table = div_4000; | |
7148 | break; | |
7149 | case 5333333: | |
7150 | div_table = div_5333; | |
7151 | break; | |
7152 | default: | |
7153 | goto fail; | |
7154 | } | |
7155 | ||
7156 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7157 | ||
7158 | fail: | |
7159 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); | |
7160 | return 200000; | |
7161 | } | |
7162 | ||
7163 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
7164 | { | |
7165 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
7166 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
7167 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
7168 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
7169 | const uint8_t *div_table; | |
7170 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7171 | uint16_t tmp = 0; | |
7172 | ||
7173 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7174 | ||
7175 | cdclk_sel = (tmp >> 4) & 0x7; | |
7176 | ||
7177 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7178 | goto fail; | |
7179 | ||
7180 | switch (vco) { | |
7181 | case 3200000: | |
7182 | div_table = div_3200; | |
7183 | break; | |
7184 | case 4000000: | |
7185 | div_table = div_4000; | |
7186 | break; | |
7187 | case 4800000: | |
7188 | div_table = div_4800; | |
7189 | break; | |
7190 | case 5333333: | |
7191 | div_table = div_5333; | |
7192 | break; | |
7193 | default: | |
7194 | goto fail; | |
7195 | } | |
7196 | ||
7197 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7198 | ||
7199 | fail: | |
7200 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); | |
7201 | return 190476; | |
7202 | } | |
7203 | ||
7204 | static void | |
7205 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) | |
7206 | { | |
7207 | while (*num > DATA_LINK_M_N_MASK || | |
7208 | *den > DATA_LINK_M_N_MASK) { | |
7209 | *num >>= 1; | |
7210 | *den >>= 1; | |
7211 | } | |
7212 | } | |
7213 | ||
7214 | static void compute_m_n(unsigned int m, unsigned int n, | |
7215 | uint32_t *ret_m, uint32_t *ret_n) | |
7216 | { | |
7217 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7218 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7219 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7220 | } | |
7221 | ||
7222 | void | |
7223 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7224 | int pixel_clock, int link_clock, | |
7225 | struct intel_link_m_n *m_n) | |
7226 | { | |
7227 | m_n->tu = 64; | |
7228 | ||
7229 | compute_m_n(bits_per_pixel * pixel_clock, | |
7230 | link_clock * nlanes * 8, | |
7231 | &m_n->gmch_m, &m_n->gmch_n); | |
7232 | ||
7233 | compute_m_n(pixel_clock, link_clock, | |
7234 | &m_n->link_m, &m_n->link_n); | |
7235 | } | |
7236 | ||
7237 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) | |
7238 | { | |
7239 | if (i915.panel_use_ssc >= 0) | |
7240 | return i915.panel_use_ssc != 0; | |
7241 | return dev_priv->vbt.lvds_use_ssc | |
7242 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); | |
7243 | } | |
7244 | ||
7245 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, | |
7246 | int num_connectors) | |
7247 | { | |
7248 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
7249 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7250 | int refclk; | |
7251 | ||
7252 | WARN_ON(!crtc_state->base.state); | |
7253 | ||
7254 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev) || IS_BROXTON(dev)) { | |
7255 | refclk = 100000; | |
7256 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && | |
7257 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
7258 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7259 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7260 | } else if (!IS_GEN2(dev)) { | |
7261 | refclk = 96000; | |
7262 | } else { | |
7263 | refclk = 48000; | |
7264 | } | |
7265 | ||
7266 | return refclk; | |
7267 | } | |
7268 | ||
7269 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) | |
7270 | { | |
7271 | return (1 << dpll->n) << 16 | dpll->m2; | |
7272 | } | |
7273 | ||
7274 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) | |
7275 | { | |
7276 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
7277 | } | |
7278 | ||
7279 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, | |
7280 | struct intel_crtc_state *crtc_state, | |
7281 | intel_clock_t *reduced_clock) | |
7282 | { | |
7283 | struct drm_device *dev = crtc->base.dev; | |
7284 | u32 fp, fp2 = 0; | |
7285 | ||
7286 | if (IS_PINEVIEW(dev)) { | |
7287 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); | |
7288 | if (reduced_clock) | |
7289 | fp2 = pnv_dpll_compute_fp(reduced_clock); | |
7290 | } else { | |
7291 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
7292 | if (reduced_clock) | |
7293 | fp2 = i9xx_dpll_compute_fp(reduced_clock); | |
7294 | } | |
7295 | ||
7296 | crtc_state->dpll_hw_state.fp0 = fp; | |
7297 | ||
7298 | crtc->lowfreq_avail = false; | |
7299 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && | |
7300 | reduced_clock) { | |
7301 | crtc_state->dpll_hw_state.fp1 = fp2; | |
7302 | crtc->lowfreq_avail = true; | |
7303 | } else { | |
7304 | crtc_state->dpll_hw_state.fp1 = fp; | |
7305 | } | |
7306 | } | |
7307 | ||
7308 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe | |
7309 | pipe) | |
7310 | { | |
7311 | u32 reg_val; | |
7312 | ||
7313 | /* | |
7314 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7315 | * and set it to a reasonable value instead. | |
7316 | */ | |
7317 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); | |
7318 | reg_val &= 0xffffff00; | |
7319 | reg_val |= 0x00000030; | |
7320 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); | |
7321 | ||
7322 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); | |
7323 | reg_val &= 0x8cffffff; | |
7324 | reg_val = 0x8c000000; | |
7325 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); | |
7326 | ||
7327 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); | |
7328 | reg_val &= 0xffffff00; | |
7329 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); | |
7330 | ||
7331 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); | |
7332 | reg_val &= 0x00ffffff; | |
7333 | reg_val |= 0xb0000000; | |
7334 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); | |
7335 | } | |
7336 | ||
7337 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, | |
7338 | struct intel_link_m_n *m_n) | |
7339 | { | |
7340 | struct drm_device *dev = crtc->base.dev; | |
7341 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7342 | int pipe = crtc->pipe; | |
7343 | ||
7344 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7345 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7346 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7347 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
7348 | } | |
7349 | ||
7350 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
7351 | struct intel_link_m_n *m_n, | |
7352 | struct intel_link_m_n *m2_n2) | |
7353 | { | |
7354 | struct drm_device *dev = crtc->base.dev; | |
7355 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7356 | int pipe = crtc->pipe; | |
7357 | enum transcoder transcoder = crtc->config->cpu_transcoder; | |
7358 | ||
7359 | if (INTEL_INFO(dev)->gen >= 5) { | |
7360 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7361 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7362 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7363 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
7364 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available | |
7365 | * for gen < 8) and if DRRS is supported (to make sure the | |
7366 | * registers are not unnecessarily accessed). | |
7367 | */ | |
7368 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && | |
7369 | crtc->config->has_drrs) { | |
7370 | I915_WRITE(PIPE_DATA_M2(transcoder), | |
7371 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7372 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7373 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7374 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7375 | } | |
7376 | } else { | |
7377 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7378 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7379 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7380 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
7381 | } | |
7382 | } | |
7383 | ||
7384 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) | |
7385 | { | |
7386 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; | |
7387 | ||
7388 | if (m_n == M1_N1) { | |
7389 | dp_m_n = &crtc->config->dp_m_n; | |
7390 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7391 | } else if (m_n == M2_N2) { | |
7392 | ||
7393 | /* | |
7394 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7395 | * needs to be programmed into M1_N1. | |
7396 | */ | |
7397 | dp_m_n = &crtc->config->dp_m2_n2; | |
7398 | } else { | |
7399 | DRM_ERROR("Unsupported divider value\n"); | |
7400 | return; | |
7401 | } | |
7402 | ||
7403 | if (crtc->config->has_pch_encoder) | |
7404 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
7405 | else | |
7406 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); | |
7407 | } | |
7408 | ||
7409 | static void vlv_compute_dpll(struct intel_crtc *crtc, | |
7410 | struct intel_crtc_state *pipe_config) | |
7411 | { | |
7412 | u32 dpll, dpll_md; | |
7413 | ||
7414 | /* | |
7415 | * Enable DPIO clock input. We should never disable the reference | |
7416 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7417 | * on it. | |
7418 | */ | |
7419 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | | |
7420 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
7421 | /* We should never disable this, set it here for state tracking */ | |
7422 | if (crtc->pipe == PIPE_B) | |
7423 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7424 | dpll |= DPLL_VCO_ENABLE; | |
7425 | pipe_config->dpll_hw_state.dpll = dpll; | |
7426 | ||
7427 | dpll_md = (pipe_config->pixel_multiplier - 1) | |
7428 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
7429 | pipe_config->dpll_hw_state.dpll_md = dpll_md; | |
7430 | } | |
7431 | ||
7432 | static void vlv_prepare_pll(struct intel_crtc *crtc, | |
7433 | const struct intel_crtc_state *pipe_config) | |
7434 | { | |
7435 | struct drm_device *dev = crtc->base.dev; | |
7436 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7437 | int pipe = crtc->pipe; | |
7438 | u32 mdiv; | |
7439 | u32 bestn, bestm1, bestm2, bestp1, bestp2; | |
7440 | u32 coreclk, reg_val; | |
7441 | ||
7442 | mutex_lock(&dev_priv->sb_lock); | |
7443 | ||
7444 | bestn = pipe_config->dpll.n; | |
7445 | bestm1 = pipe_config->dpll.m1; | |
7446 | bestm2 = pipe_config->dpll.m2; | |
7447 | bestp1 = pipe_config->dpll.p1; | |
7448 | bestp2 = pipe_config->dpll.p2; | |
7449 | ||
7450 | /* See eDP HDMI DPIO driver vbios notes doc */ | |
7451 | ||
7452 | /* PLL B needs special handling */ | |
7453 | if (pipe == PIPE_B) | |
7454 | vlv_pllb_recal_opamp(dev_priv, pipe); | |
7455 | ||
7456 | /* Set up Tx target for periodic Rcomp update */ | |
7457 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); | |
7458 | ||
7459 | /* Disable target IRef on PLL */ | |
7460 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); | |
7461 | reg_val &= 0x00ffffff; | |
7462 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); | |
7463 | ||
7464 | /* Disable fast lock */ | |
7465 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); | |
7466 | ||
7467 | /* Set idtafcrecal before PLL is enabled */ | |
7468 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); | |
7469 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7470 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
7471 | mdiv |= (1 << DPIO_K_SHIFT); | |
7472 | ||
7473 | /* | |
7474 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7475 | * but we don't support that). | |
7476 | * Note: don't use the DAC post divider as it seems unstable. | |
7477 | */ | |
7478 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
7479 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); | |
7480 | ||
7481 | mdiv |= DPIO_ENABLE_CALIBRATION; | |
7482 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); | |
7483 | ||
7484 | /* Set HBR and RBR LPF coefficients */ | |
7485 | if (pipe_config->port_clock == 162000 || | |
7486 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || | |
7487 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
7488 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), | |
7489 | 0x009f0003); | |
7490 | else | |
7491 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), | |
7492 | 0x00d0000f); | |
7493 | ||
7494 | if (pipe_config->has_dp_encoder) { | |
7495 | /* Use SSC source */ | |
7496 | if (pipe == PIPE_A) | |
7497 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), | |
7498 | 0x0df40000); | |
7499 | else | |
7500 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), | |
7501 | 0x0df70000); | |
7502 | } else { /* HDMI or VGA */ | |
7503 | /* Use bend source */ | |
7504 | if (pipe == PIPE_A) | |
7505 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), | |
7506 | 0x0df70000); | |
7507 | else | |
7508 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), | |
7509 | 0x0df40000); | |
7510 | } | |
7511 | ||
7512 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); | |
7513 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; | |
7514 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || | |
7515 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
7516 | coreclk |= 0x01000000; | |
7517 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); | |
7518 | ||
7519 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); | |
7520 | mutex_unlock(&dev_priv->sb_lock); | |
7521 | } | |
7522 | ||
7523 | static void chv_compute_dpll(struct intel_crtc *crtc, | |
7524 | struct intel_crtc_state *pipe_config) | |
7525 | { | |
7526 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | | |
7527 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
7528 | DPLL_VCO_ENABLE; | |
7529 | if (crtc->pipe != PIPE_A) | |
7530 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7531 | ||
7532 | pipe_config->dpll_hw_state.dpll_md = | |
7533 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
7534 | } | |
7535 | ||
7536 | static void chv_prepare_pll(struct intel_crtc *crtc, | |
7537 | const struct intel_crtc_state *pipe_config) | |
7538 | { | |
7539 | struct drm_device *dev = crtc->base.dev; | |
7540 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7541 | int pipe = crtc->pipe; | |
7542 | i915_reg_t dpll_reg = DPLL(crtc->pipe); | |
7543 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
7544 | u32 loopfilter, tribuf_calcntr; | |
7545 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; | |
7546 | u32 dpio_val; | |
7547 | int vco; | |
7548 | ||
7549 | bestn = pipe_config->dpll.n; | |
7550 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7551 | bestm1 = pipe_config->dpll.m1; | |
7552 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7553 | bestp1 = pipe_config->dpll.p1; | |
7554 | bestp2 = pipe_config->dpll.p2; | |
7555 | vco = pipe_config->dpll.vco; | |
7556 | dpio_val = 0; | |
7557 | loopfilter = 0; | |
7558 | ||
7559 | /* | |
7560 | * Enable Refclk and SSC | |
7561 | */ | |
7562 | I915_WRITE(dpll_reg, | |
7563 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); | |
7564 | ||
7565 | mutex_lock(&dev_priv->sb_lock); | |
7566 | ||
7567 | /* p1 and p2 divider */ | |
7568 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7569 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7570 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7571 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7572 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7573 | ||
7574 | /* Feedback post-divider - m2 */ | |
7575 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7576 | ||
7577 | /* Feedback refclk divider - n and m1 */ | |
7578 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7579 | DPIO_CHV_M1_DIV_BY_2 | | |
7580 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7581 | ||
7582 | /* M2 fraction division */ | |
7583 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); | |
7584 | ||
7585 | /* M2 fraction division enable */ | |
7586 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); | |
7587 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7588 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7589 | if (bestm2_frac) | |
7590 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7591 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
7592 | ||
7593 | /* Program digital lock detect threshold */ | |
7594 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7595 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7596 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7597 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7598 | if (!bestm2_frac) | |
7599 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7600 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7601 | ||
7602 | /* Loop filter */ | |
7603 | if (vco == 5400000) { | |
7604 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7605 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7606 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7607 | tribuf_calcntr = 0x9; | |
7608 | } else if (vco <= 6200000) { | |
7609 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7610 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7611 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7612 | tribuf_calcntr = 0x9; | |
7613 | } else if (vco <= 6480000) { | |
7614 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7615 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7616 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7617 | tribuf_calcntr = 0x8; | |
7618 | } else { | |
7619 | /* Not supported. Apply the same limits as in the max case */ | |
7620 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7621 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7622 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7623 | tribuf_calcntr = 0; | |
7624 | } | |
7625 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); | |
7626 | ||
7627 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); | |
7628 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; | |
7629 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7630 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7631 | ||
7632 | /* AFC Recal */ | |
7633 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7634 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7635 | DPIO_AFC_RECAL); | |
7636 | ||
7637 | mutex_unlock(&dev_priv->sb_lock); | |
7638 | } | |
7639 | ||
7640 | /** | |
7641 | * vlv_force_pll_on - forcibly enable just the PLL | |
7642 | * @dev_priv: i915 private structure | |
7643 | * @pipe: pipe PLL to enable | |
7644 | * @dpll: PLL configuration | |
7645 | * | |
7646 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7647 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7648 | * be enabled. | |
7649 | */ | |
7650 | int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7651 | const struct dpll *dpll) | |
7652 | { | |
7653 | struct intel_crtc *crtc = | |
7654 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
7655 | struct intel_crtc_state *pipe_config; | |
7656 | ||
7657 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); | |
7658 | if (!pipe_config) | |
7659 | return -ENOMEM; | |
7660 | ||
7661 | pipe_config->base.crtc = &crtc->base; | |
7662 | pipe_config->pixel_multiplier = 1; | |
7663 | pipe_config->dpll = *dpll; | |
7664 | ||
7665 | if (IS_CHERRYVIEW(dev)) { | |
7666 | chv_compute_dpll(crtc, pipe_config); | |
7667 | chv_prepare_pll(crtc, pipe_config); | |
7668 | chv_enable_pll(crtc, pipe_config); | |
7669 | } else { | |
7670 | vlv_compute_dpll(crtc, pipe_config); | |
7671 | vlv_prepare_pll(crtc, pipe_config); | |
7672 | vlv_enable_pll(crtc, pipe_config); | |
7673 | } | |
7674 | ||
7675 | kfree(pipe_config); | |
7676 | ||
7677 | return 0; | |
7678 | } | |
7679 | ||
7680 | /** | |
7681 | * vlv_force_pll_off - forcibly disable just the PLL | |
7682 | * @dev_priv: i915 private structure | |
7683 | * @pipe: pipe PLL to disable | |
7684 | * | |
7685 | * Disable the PLL for @pipe. To be used in cases where we need | |
7686 | * the PLL enabled even when @pipe is not going to be enabled. | |
7687 | */ | |
7688 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7689 | { | |
7690 | if (IS_CHERRYVIEW(dev)) | |
7691 | chv_disable_pll(to_i915(dev), pipe); | |
7692 | else | |
7693 | vlv_disable_pll(to_i915(dev), pipe); | |
7694 | } | |
7695 | ||
7696 | static void i9xx_compute_dpll(struct intel_crtc *crtc, | |
7697 | struct intel_crtc_state *crtc_state, | |
7698 | intel_clock_t *reduced_clock, | |
7699 | int num_connectors) | |
7700 | { | |
7701 | struct drm_device *dev = crtc->base.dev; | |
7702 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7703 | u32 dpll; | |
7704 | bool is_sdvo; | |
7705 | struct dpll *clock = &crtc_state->dpll; | |
7706 | ||
7707 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); | |
7708 | ||
7709 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || | |
7710 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
7711 | ||
7712 | dpll = DPLL_VGA_MODE_DIS; | |
7713 | ||
7714 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) | |
7715 | dpll |= DPLLB_MODE_LVDS; | |
7716 | else | |
7717 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
7718 | ||
7719 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { | |
7720 | dpll |= (crtc_state->pixel_multiplier - 1) | |
7721 | << SDVO_MULTIPLIER_SHIFT_HIRES; | |
7722 | } | |
7723 | ||
7724 | if (is_sdvo) | |
7725 | dpll |= DPLL_SDVO_HIGH_SPEED; | |
7726 | ||
7727 | if (crtc_state->has_dp_encoder) | |
7728 | dpll |= DPLL_SDVO_HIGH_SPEED; | |
7729 | ||
7730 | /* compute bitmask from p1 value */ | |
7731 | if (IS_PINEVIEW(dev)) | |
7732 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7733 | else { | |
7734 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7735 | if (IS_G4X(dev) && reduced_clock) | |
7736 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7737 | } | |
7738 | switch (clock->p2) { | |
7739 | case 5: | |
7740 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7741 | break; | |
7742 | case 7: | |
7743 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7744 | break; | |
7745 | case 10: | |
7746 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7747 | break; | |
7748 | case 14: | |
7749 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7750 | break; | |
7751 | } | |
7752 | if (INTEL_INFO(dev)->gen >= 4) | |
7753 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7754 | ||
7755 | if (crtc_state->sdvo_tv_clock) | |
7756 | dpll |= PLL_REF_INPUT_TVCLKINBC; | |
7757 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && | |
7758 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) | |
7759 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7760 | else | |
7761 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7762 | ||
7763 | dpll |= DPLL_VCO_ENABLE; | |
7764 | crtc_state->dpll_hw_state.dpll = dpll; | |
7765 | ||
7766 | if (INTEL_INFO(dev)->gen >= 4) { | |
7767 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) | |
7768 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
7769 | crtc_state->dpll_hw_state.dpll_md = dpll_md; | |
7770 | } | |
7771 | } | |
7772 | ||
7773 | static void i8xx_compute_dpll(struct intel_crtc *crtc, | |
7774 | struct intel_crtc_state *crtc_state, | |
7775 | intel_clock_t *reduced_clock, | |
7776 | int num_connectors) | |
7777 | { | |
7778 | struct drm_device *dev = crtc->base.dev; | |
7779 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7780 | u32 dpll; | |
7781 | struct dpll *clock = &crtc_state->dpll; | |
7782 | ||
7783 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); | |
7784 | ||
7785 | dpll = DPLL_VGA_MODE_DIS; | |
7786 | ||
7787 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
7788 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7789 | } else { | |
7790 | if (clock->p1 == 2) | |
7791 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7792 | else | |
7793 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7794 | if (clock->p2 == 4) | |
7795 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7796 | } | |
7797 | ||
7798 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) | |
7799 | dpll |= DPLL_DVO_2X_MODE; | |
7800 | ||
7801 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && | |
7802 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) | |
7803 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7804 | else | |
7805 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7806 | ||
7807 | dpll |= DPLL_VCO_ENABLE; | |
7808 | crtc_state->dpll_hw_state.dpll = dpll; | |
7809 | } | |
7810 | ||
7811 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) | |
7812 | { | |
7813 | struct drm_device *dev = intel_crtc->base.dev; | |
7814 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7815 | enum pipe pipe = intel_crtc->pipe; | |
7816 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; | |
7817 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; | |
7818 | uint32_t crtc_vtotal, crtc_vblank_end; | |
7819 | int vsyncshift = 0; | |
7820 | ||
7821 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7822 | * the hw state checker will get angry at the mismatch. */ | |
7823 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7824 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
7825 | ||
7826 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { | |
7827 | /* the chip adds 2 halflines automatically */ | |
7828 | crtc_vtotal -= 1; | |
7829 | crtc_vblank_end -= 1; | |
7830 | ||
7831 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) | |
7832 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; | |
7833 | else | |
7834 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7835 | adjusted_mode->crtc_htotal / 2; | |
7836 | if (vsyncshift < 0) | |
7837 | vsyncshift += adjusted_mode->crtc_htotal; | |
7838 | } | |
7839 | ||
7840 | if (INTEL_INFO(dev)->gen > 3) | |
7841 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); | |
7842 | ||
7843 | I915_WRITE(HTOTAL(cpu_transcoder), | |
7844 | (adjusted_mode->crtc_hdisplay - 1) | | |
7845 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
7846 | I915_WRITE(HBLANK(cpu_transcoder), | |
7847 | (adjusted_mode->crtc_hblank_start - 1) | | |
7848 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
7849 | I915_WRITE(HSYNC(cpu_transcoder), | |
7850 | (adjusted_mode->crtc_hsync_start - 1) | | |
7851 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7852 | ||
7853 | I915_WRITE(VTOTAL(cpu_transcoder), | |
7854 | (adjusted_mode->crtc_vdisplay - 1) | | |
7855 | ((crtc_vtotal - 1) << 16)); | |
7856 | I915_WRITE(VBLANK(cpu_transcoder), | |
7857 | (adjusted_mode->crtc_vblank_start - 1) | | |
7858 | ((crtc_vblank_end - 1) << 16)); | |
7859 | I915_WRITE(VSYNC(cpu_transcoder), | |
7860 | (adjusted_mode->crtc_vsync_start - 1) | | |
7861 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7862 | ||
7863 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be | |
7864 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7865 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7866 | * bits. */ | |
7867 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7868 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7869 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7870 | ||
7871 | /* pipesrc controls the size that is scaled from, which should | |
7872 | * always be the user's requested size. | |
7873 | */ | |
7874 | I915_WRITE(PIPESRC(pipe), | |
7875 | ((intel_crtc->config->pipe_src_w - 1) << 16) | | |
7876 | (intel_crtc->config->pipe_src_h - 1)); | |
7877 | } | |
7878 | ||
7879 | static void intel_get_pipe_timings(struct intel_crtc *crtc, | |
7880 | struct intel_crtc_state *pipe_config) | |
7881 | { | |
7882 | struct drm_device *dev = crtc->base.dev; | |
7883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7884 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7885 | uint32_t tmp; | |
7886 | ||
7887 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
7888 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; | |
7889 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
7890 | tmp = I915_READ(HBLANK(cpu_transcoder)); | |
7891 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; | |
7892 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
7893 | tmp = I915_READ(HSYNC(cpu_transcoder)); | |
7894 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; | |
7895 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
7896 | ||
7897 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
7898 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; | |
7899 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
7900 | tmp = I915_READ(VBLANK(cpu_transcoder)); | |
7901 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; | |
7902 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
7903 | tmp = I915_READ(VSYNC(cpu_transcoder)); | |
7904 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; | |
7905 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
7906 | ||
7907 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
7908 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; | |
7909 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7910 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
7911 | } | |
7912 | ||
7913 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
7914 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; | |
7915 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7916 | ||
7917 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; | |
7918 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
7919 | } | |
7920 | ||
7921 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, | |
7922 | struct intel_crtc_state *pipe_config) | |
7923 | { | |
7924 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; | |
7925 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7926 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7927 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
7928 | ||
7929 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; | |
7930 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7931 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7932 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
7933 | ||
7934 | mode->flags = pipe_config->base.adjusted_mode.flags; | |
7935 | mode->type = DRM_MODE_TYPE_DRIVER; | |
7936 | ||
7937 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; | |
7938 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
7939 | ||
7940 | mode->hsync = drm_mode_hsync(mode); | |
7941 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7942 | drm_mode_set_name(mode); | |
7943 | } | |
7944 | ||
7945 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) | |
7946 | { | |
7947 | struct drm_device *dev = intel_crtc->base.dev; | |
7948 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7949 | uint32_t pipeconf; | |
7950 | ||
7951 | pipeconf = 0; | |
7952 | ||
7953 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
7954 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7955 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
7956 | ||
7957 | if (intel_crtc->config->double_wide) | |
7958 | pipeconf |= PIPECONF_DOUBLE_WIDE; | |
7959 | ||
7960 | /* only g4x and later have fancy bpc/dither controls */ | |
7961 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
7962 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ | |
7963 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) | |
7964 | pipeconf |= PIPECONF_DITHER_EN | | |
7965 | PIPECONF_DITHER_TYPE_SP; | |
7966 | ||
7967 | switch (intel_crtc->config->pipe_bpp) { | |
7968 | case 18: | |
7969 | pipeconf |= PIPECONF_6BPC; | |
7970 | break; | |
7971 | case 24: | |
7972 | pipeconf |= PIPECONF_8BPC; | |
7973 | break; | |
7974 | case 30: | |
7975 | pipeconf |= PIPECONF_10BPC; | |
7976 | break; | |
7977 | default: | |
7978 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7979 | BUG(); | |
7980 | } | |
7981 | } | |
7982 | ||
7983 | if (HAS_PIPE_CXSR(dev)) { | |
7984 | if (intel_crtc->lowfreq_avail) { | |
7985 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7986 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7987 | } else { | |
7988 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
7989 | } | |
7990 | } | |
7991 | ||
7992 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { | |
7993 | if (INTEL_INFO(dev)->gen < 4 || | |
7994 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) | |
7995 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; | |
7996 | else | |
7997 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7998 | } else | |
7999 | pipeconf |= PIPECONF_PROGRESSIVE; | |
8000 | ||
8001 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && | |
8002 | intel_crtc->config->limited_color_range) | |
8003 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; | |
8004 | ||
8005 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); | |
8006 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
8007 | } | |
8008 | ||
8009 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, | |
8010 | struct intel_crtc_state *crtc_state) | |
8011 | { | |
8012 | struct drm_device *dev = crtc->base.dev; | |
8013 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8014 | int refclk, num_connectors = 0; | |
8015 | intel_clock_t clock; | |
8016 | bool ok; | |
8017 | const intel_limit_t *limit; | |
8018 | struct drm_atomic_state *state = crtc_state->base.state; | |
8019 | struct drm_connector *connector; | |
8020 | struct drm_connector_state *connector_state; | |
8021 | int i; | |
8022 | ||
8023 | memset(&crtc_state->dpll_hw_state, 0, | |
8024 | sizeof(crtc_state->dpll_hw_state)); | |
8025 | ||
8026 | if (crtc_state->has_dsi_encoder) | |
8027 | return 0; | |
8028 | ||
8029 | for_each_connector_in_state(state, connector, connector_state, i) { | |
8030 | if (connector_state->crtc == &crtc->base) | |
8031 | num_connectors++; | |
8032 | } | |
8033 | ||
8034 | if (!crtc_state->clock_set) { | |
8035 | refclk = i9xx_get_refclk(crtc_state, num_connectors); | |
8036 | ||
8037 | /* | |
8038 | * Returns a set of divisors for the desired target clock with | |
8039 | * the given refclk, or FALSE. The returned values represent | |
8040 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
8041 | * 2) / p1 / p2. | |
8042 | */ | |
8043 | limit = intel_limit(crtc_state, refclk); | |
8044 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
8045 | crtc_state->port_clock, | |
8046 | refclk, NULL, &clock); | |
8047 | if (!ok) { | |
8048 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
8049 | return -EINVAL; | |
8050 | } | |
8051 | ||
8052 | /* Compat-code for transition, will disappear. */ | |
8053 | crtc_state->dpll.n = clock.n; | |
8054 | crtc_state->dpll.m1 = clock.m1; | |
8055 | crtc_state->dpll.m2 = clock.m2; | |
8056 | crtc_state->dpll.p1 = clock.p1; | |
8057 | crtc_state->dpll.p2 = clock.p2; | |
8058 | } | |
8059 | ||
8060 | if (IS_GEN2(dev)) { | |
8061 | i8xx_compute_dpll(crtc, crtc_state, NULL, | |
8062 | num_connectors); | |
8063 | } else if (IS_CHERRYVIEW(dev)) { | |
8064 | chv_compute_dpll(crtc, crtc_state); | |
8065 | } else if (IS_VALLEYVIEW(dev)) { | |
8066 | vlv_compute_dpll(crtc, crtc_state); | |
8067 | } else { | |
8068 | i9xx_compute_dpll(crtc, crtc_state, NULL, | |
8069 | num_connectors); | |
8070 | } | |
8071 | ||
8072 | return 0; | |
8073 | } | |
8074 | ||
8075 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, | |
8076 | struct intel_crtc_state *pipe_config) | |
8077 | { | |
8078 | struct drm_device *dev = crtc->base.dev; | |
8079 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8080 | uint32_t tmp; | |
8081 | ||
8082 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) | |
8083 | return; | |
8084 | ||
8085 | tmp = I915_READ(PFIT_CONTROL); | |
8086 | if (!(tmp & PFIT_ENABLE)) | |
8087 | return; | |
8088 | ||
8089 | /* Check whether the pfit is attached to our pipe. */ | |
8090 | if (INTEL_INFO(dev)->gen < 4) { | |
8091 | if (crtc->pipe != PIPE_B) | |
8092 | return; | |
8093 | } else { | |
8094 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
8095 | return; | |
8096 | } | |
8097 | ||
8098 | pipe_config->gmch_pfit.control = tmp; | |
8099 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); | |
8100 | if (INTEL_INFO(dev)->gen < 5) | |
8101 | pipe_config->gmch_pfit.lvds_border_bits = | |
8102 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
8103 | } | |
8104 | ||
8105 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, | |
8106 | struct intel_crtc_state *pipe_config) | |
8107 | { | |
8108 | struct drm_device *dev = crtc->base.dev; | |
8109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8110 | int pipe = pipe_config->cpu_transcoder; | |
8111 | intel_clock_t clock; | |
8112 | u32 mdiv; | |
8113 | int refclk = 100000; | |
8114 | ||
8115 | /* In case of MIPI DPLL will not even be used */ | |
8116 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
8117 | return; | |
8118 | ||
8119 | mutex_lock(&dev_priv->sb_lock); | |
8120 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); | |
8121 | mutex_unlock(&dev_priv->sb_lock); | |
8122 | ||
8123 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
8124 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
8125 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
8126 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
8127 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
8128 | ||
8129 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); | |
8130 | } | |
8131 | ||
8132 | static void | |
8133 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
8134 | struct intel_initial_plane_config *plane_config) | |
8135 | { | |
8136 | struct drm_device *dev = crtc->base.dev; | |
8137 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8138 | u32 val, base, offset; | |
8139 | int pipe = crtc->pipe, plane = crtc->plane; | |
8140 | int fourcc, pixel_format; | |
8141 | unsigned int aligned_height; | |
8142 | struct drm_framebuffer *fb; | |
8143 | struct intel_framebuffer *intel_fb; | |
8144 | ||
8145 | val = I915_READ(DSPCNTR(plane)); | |
8146 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8147 | return; | |
8148 | ||
8149 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
8150 | if (!intel_fb) { | |
8151 | DRM_DEBUG_KMS("failed to alloc fb\n"); | |
8152 | return; | |
8153 | } | |
8154 | ||
8155 | fb = &intel_fb->base; | |
8156 | ||
8157 | if (INTEL_INFO(dev)->gen >= 4) { | |
8158 | if (val & DISPPLANE_TILED) { | |
8159 | plane_config->tiling = I915_TILING_X; | |
8160 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
8161 | } | |
8162 | } | |
8163 | ||
8164 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
8165 | fourcc = i9xx_format_to_fourcc(pixel_format); | |
8166 | fb->pixel_format = fourcc; | |
8167 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
8168 | ||
8169 | if (INTEL_INFO(dev)->gen >= 4) { | |
8170 | if (plane_config->tiling) | |
8171 | offset = I915_READ(DSPTILEOFF(plane)); | |
8172 | else | |
8173 | offset = I915_READ(DSPLINOFF(plane)); | |
8174 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8175 | } else { | |
8176 | base = I915_READ(DSPADDR(plane)); | |
8177 | } | |
8178 | plane_config->base = base; | |
8179 | ||
8180 | val = I915_READ(PIPESRC(pipe)); | |
8181 | fb->width = ((val >> 16) & 0xfff) + 1; | |
8182 | fb->height = ((val >> 0) & 0xfff) + 1; | |
8183 | ||
8184 | val = I915_READ(DSPSTRIDE(pipe)); | |
8185 | fb->pitches[0] = val & 0xffffffc0; | |
8186 | ||
8187 | aligned_height = intel_fb_align_height(dev, fb->height, | |
8188 | fb->pixel_format, | |
8189 | fb->modifier[0]); | |
8190 | ||
8191 | plane_config->size = fb->pitches[0] * aligned_height; | |
8192 | ||
8193 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
8194 | pipe_name(pipe), plane, fb->width, fb->height, | |
8195 | fb->bits_per_pixel, base, fb->pitches[0], | |
8196 | plane_config->size); | |
8197 | ||
8198 | plane_config->fb = intel_fb; | |
8199 | } | |
8200 | ||
8201 | static void chv_crtc_clock_get(struct intel_crtc *crtc, | |
8202 | struct intel_crtc_state *pipe_config) | |
8203 | { | |
8204 | struct drm_device *dev = crtc->base.dev; | |
8205 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8206 | int pipe = pipe_config->cpu_transcoder; | |
8207 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8208 | intel_clock_t clock; | |
8209 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; | |
8210 | int refclk = 100000; | |
8211 | ||
8212 | mutex_lock(&dev_priv->sb_lock); | |
8213 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); | |
8214 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8215 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8216 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
8217 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); | |
8218 | mutex_unlock(&dev_priv->sb_lock); | |
8219 | ||
8220 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
8221 | clock.m2 = (pll_dw0 & 0xff) << 22; | |
8222 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8223 | clock.m2 |= pll_dw2 & 0x3fffff; | |
8224 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; | |
8225 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8226 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8227 | ||
8228 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); | |
8229 | } | |
8230 | ||
8231 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, | |
8232 | struct intel_crtc_state *pipe_config) | |
8233 | { | |
8234 | struct drm_device *dev = crtc->base.dev; | |
8235 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8236 | enum intel_display_power_domain power_domain; | |
8237 | uint32_t tmp; | |
8238 | bool ret; | |
8239 | ||
8240 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); | |
8241 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
8242 | return false; | |
8243 | ||
8244 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; | |
8245 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; | |
8246 | ||
8247 | ret = false; | |
8248 | ||
8249 | tmp = I915_READ(PIPECONF(crtc->pipe)); | |
8250 | if (!(tmp & PIPECONF_ENABLE)) | |
8251 | goto out; | |
8252 | ||
8253 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
8254 | switch (tmp & PIPECONF_BPC_MASK) { | |
8255 | case PIPECONF_6BPC: | |
8256 | pipe_config->pipe_bpp = 18; | |
8257 | break; | |
8258 | case PIPECONF_8BPC: | |
8259 | pipe_config->pipe_bpp = 24; | |
8260 | break; | |
8261 | case PIPECONF_10BPC: | |
8262 | pipe_config->pipe_bpp = 30; | |
8263 | break; | |
8264 | default: | |
8265 | break; | |
8266 | } | |
8267 | } | |
8268 | ||
8269 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && | |
8270 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) | |
8271 | pipe_config->limited_color_range = true; | |
8272 | ||
8273 | if (INTEL_INFO(dev)->gen < 4) | |
8274 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8275 | ||
8276 | intel_get_pipe_timings(crtc, pipe_config); | |
8277 | ||
8278 | i9xx_get_pfit_config(crtc, pipe_config); | |
8279 | ||
8280 | if (INTEL_INFO(dev)->gen >= 4) { | |
8281 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8282 | pipe_config->pixel_multiplier = | |
8283 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8284 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8285 | pipe_config->dpll_hw_state.dpll_md = tmp; | |
8286 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { | |
8287 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8288 | pipe_config->pixel_multiplier = | |
8289 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8290 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8291 | } else { | |
8292 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8293 | * port and will be fixed up in the encoder->get_config | |
8294 | * function. */ | |
8295 | pipe_config->pixel_multiplier = 1; | |
8296 | } | |
8297 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); | |
8298 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { | |
8299 | /* | |
8300 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8301 | * on 830. Filter it out here so that we don't | |
8302 | * report errors due to that. | |
8303 | */ | |
8304 | if (IS_I830(dev)) | |
8305 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8306 | ||
8307 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); | |
8308 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
8309 | } else { | |
8310 | /* Mask out read-only status bits. */ | |
8311 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8312 | DPLL_PORTC_READY_MASK | | |
8313 | DPLL_PORTB_READY_MASK); | |
8314 | } | |
8315 | ||
8316 | if (IS_CHERRYVIEW(dev)) | |
8317 | chv_crtc_clock_get(crtc, pipe_config); | |
8318 | else if (IS_VALLEYVIEW(dev)) | |
8319 | vlv_crtc_clock_get(crtc, pipe_config); | |
8320 | else | |
8321 | i9xx_crtc_clock_get(crtc, pipe_config); | |
8322 | ||
8323 | /* | |
8324 | * Normally the dotclock is filled in by the encoder .get_config() | |
8325 | * but in case the pipe is enabled w/o any ports we need a sane | |
8326 | * default. | |
8327 | */ | |
8328 | pipe_config->base.adjusted_mode.crtc_clock = | |
8329 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8330 | ||
8331 | ret = true; | |
8332 | ||
8333 | out: | |
8334 | intel_display_power_put(dev_priv, power_domain); | |
8335 | ||
8336 | return ret; | |
8337 | } | |
8338 | ||
8339 | static void ironlake_init_pch_refclk(struct drm_device *dev) | |
8340 | { | |
8341 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8342 | struct intel_encoder *encoder; | |
8343 | u32 val, final; | |
8344 | bool has_lvds = false; | |
8345 | bool has_cpu_edp = false; | |
8346 | bool has_panel = false; | |
8347 | bool has_ck505 = false; | |
8348 | bool can_ssc = false; | |
8349 | ||
8350 | /* We need to take the global config into account */ | |
8351 | for_each_intel_encoder(dev, encoder) { | |
8352 | switch (encoder->type) { | |
8353 | case INTEL_OUTPUT_LVDS: | |
8354 | has_panel = true; | |
8355 | has_lvds = true; | |
8356 | break; | |
8357 | case INTEL_OUTPUT_EDP: | |
8358 | has_panel = true; | |
8359 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) | |
8360 | has_cpu_edp = true; | |
8361 | break; | |
8362 | default: | |
8363 | break; | |
8364 | } | |
8365 | } | |
8366 | ||
8367 | if (HAS_PCH_IBX(dev)) { | |
8368 | has_ck505 = dev_priv->vbt.display_clock_mode; | |
8369 | can_ssc = has_ck505; | |
8370 | } else { | |
8371 | has_ck505 = false; | |
8372 | can_ssc = true; | |
8373 | } | |
8374 | ||
8375 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", | |
8376 | has_panel, has_lvds, has_ck505); | |
8377 | ||
8378 | /* Ironlake: try to setup display ref clock before DPLL | |
8379 | * enabling. This is only under driver's control after | |
8380 | * PCH B stepping, previous chipset stepping should be | |
8381 | * ignoring this setting. | |
8382 | */ | |
8383 | val = I915_READ(PCH_DREF_CONTROL); | |
8384 | ||
8385 | /* As we must carefully and slowly disable/enable each source in turn, | |
8386 | * compute the final state we want first and check if we need to | |
8387 | * make any changes at all. | |
8388 | */ | |
8389 | final = val; | |
8390 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8391 | if (has_ck505) | |
8392 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8393 | else | |
8394 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8395 | ||
8396 | final &= ~DREF_SSC_SOURCE_MASK; | |
8397 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8398 | final &= ~DREF_SSC1_ENABLE; | |
8399 | ||
8400 | if (has_panel) { | |
8401 | final |= DREF_SSC_SOURCE_ENABLE; | |
8402 | ||
8403 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8404 | final |= DREF_SSC1_ENABLE; | |
8405 | ||
8406 | if (has_cpu_edp) { | |
8407 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8408 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8409 | else | |
8410 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8411 | } else | |
8412 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8413 | } else { | |
8414 | final |= DREF_SSC_SOURCE_DISABLE; | |
8415 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8416 | } | |
8417 | ||
8418 | if (final == val) | |
8419 | return; | |
8420 | ||
8421 | /* Always enable nonspread source */ | |
8422 | val &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8423 | ||
8424 | if (has_ck505) | |
8425 | val |= DREF_NONSPREAD_CK505_ENABLE; | |
8426 | else | |
8427 | val |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8428 | ||
8429 | if (has_panel) { | |
8430 | val &= ~DREF_SSC_SOURCE_MASK; | |
8431 | val |= DREF_SSC_SOURCE_ENABLE; | |
8432 | ||
8433 | /* SSC must be turned on before enabling the CPU output */ | |
8434 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { | |
8435 | DRM_DEBUG_KMS("Using SSC on panel\n"); | |
8436 | val |= DREF_SSC1_ENABLE; | |
8437 | } else | |
8438 | val &= ~DREF_SSC1_ENABLE; | |
8439 | ||
8440 | /* Get SSC going before enabling the outputs */ | |
8441 | I915_WRITE(PCH_DREF_CONTROL, val); | |
8442 | POSTING_READ(PCH_DREF_CONTROL); | |
8443 | udelay(200); | |
8444 | ||
8445 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8446 | ||
8447 | /* Enable CPU source on CPU attached eDP */ | |
8448 | if (has_cpu_edp) { | |
8449 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { | |
8450 | DRM_DEBUG_KMS("Using SSC on eDP\n"); | |
8451 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8452 | } else | |
8453 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8454 | } else | |
8455 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8456 | ||
8457 | I915_WRITE(PCH_DREF_CONTROL, val); | |
8458 | POSTING_READ(PCH_DREF_CONTROL); | |
8459 | udelay(200); | |
8460 | } else { | |
8461 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8462 | ||
8463 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8464 | ||
8465 | /* Turn off CPU output */ | |
8466 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8467 | ||
8468 | I915_WRITE(PCH_DREF_CONTROL, val); | |
8469 | POSTING_READ(PCH_DREF_CONTROL); | |
8470 | udelay(200); | |
8471 | ||
8472 | /* Turn off the SSC source */ | |
8473 | val &= ~DREF_SSC_SOURCE_MASK; | |
8474 | val |= DREF_SSC_SOURCE_DISABLE; | |
8475 | ||
8476 | /* Turn off SSC1 */ | |
8477 | val &= ~DREF_SSC1_ENABLE; | |
8478 | ||
8479 | I915_WRITE(PCH_DREF_CONTROL, val); | |
8480 | POSTING_READ(PCH_DREF_CONTROL); | |
8481 | udelay(200); | |
8482 | } | |
8483 | ||
8484 | BUG_ON(val != final); | |
8485 | } | |
8486 | ||
8487 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) | |
8488 | { | |
8489 | uint32_t tmp; | |
8490 | ||
8491 | tmp = I915_READ(SOUTH_CHICKEN2); | |
8492 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8493 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
8494 | ||
8495 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & | |
8496 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8497 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
8498 | ||
8499 | tmp = I915_READ(SOUTH_CHICKEN2); | |
8500 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8501 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
8502 | ||
8503 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & | |
8504 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8505 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
8506 | } | |
8507 | ||
8508 | /* WaMPhyProgramming:hsw */ | |
8509 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8510 | { | |
8511 | uint32_t tmp; | |
8512 | ||
8513 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8514 | tmp &= ~(0xFF << 24); | |
8515 | tmp |= (0x12 << 24); | |
8516 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8517 | ||
8518 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); | |
8519 | tmp |= (1 << 11); | |
8520 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8521 | ||
8522 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8523 | tmp |= (1 << 11); | |
8524 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8525 | ||
8526 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); | |
8527 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8528 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8529 | ||
8530 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8531 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8532 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8533 | ||
8534 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); | |
8535 | tmp &= ~(7 << 13); | |
8536 | tmp |= (5 << 13); | |
8537 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
8538 | ||
8539 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); | |
8540 | tmp &= ~(7 << 13); | |
8541 | tmp |= (5 << 13); | |
8542 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
8543 | ||
8544 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8545 | tmp &= ~0xFF; | |
8546 | tmp |= 0x1C; | |
8547 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8548 | ||
8549 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8550 | tmp &= ~0xFF; | |
8551 | tmp |= 0x1C; | |
8552 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8553 | ||
8554 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8555 | tmp &= ~(0xFF << 16); | |
8556 | tmp |= (0x1C << 16); | |
8557 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8558 | ||
8559 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8560 | tmp &= ~(0xFF << 16); | |
8561 | tmp |= (0x1C << 16); | |
8562 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8563 | ||
8564 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); | |
8565 | tmp |= (1 << 27); | |
8566 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
8567 | ||
8568 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); | |
8569 | tmp |= (1 << 27); | |
8570 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
8571 | ||
8572 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); | |
8573 | tmp &= ~(0xF << 28); | |
8574 | tmp |= (4 << 28); | |
8575 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
8576 | ||
8577 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); | |
8578 | tmp &= ~(0xF << 28); | |
8579 | tmp |= (4 << 28); | |
8580 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
8581 | } | |
8582 | ||
8583 | /* Implements 3 different sequences from BSpec chapter "Display iCLK | |
8584 | * Programming" based on the parameters passed: | |
8585 | * - Sequence to enable CLKOUT_DP | |
8586 | * - Sequence to enable CLKOUT_DP without spread | |
8587 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8588 | */ | |
8589 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8590 | bool with_fdi) | |
8591 | { | |
8592 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8593 | uint32_t reg, tmp; | |
8594 | ||
8595 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8596 | with_spread = true; | |
8597 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) | |
8598 | with_fdi = false; | |
8599 | ||
8600 | mutex_lock(&dev_priv->sb_lock); | |
8601 | ||
8602 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8603 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8604 | tmp |= SBI_SSCCTL_PATHALT; | |
8605 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8606 | ||
8607 | udelay(24); | |
8608 | ||
8609 | if (with_spread) { | |
8610 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8611 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8612 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8613 | ||
8614 | if (with_fdi) { | |
8615 | lpt_reset_fdi_mphy(dev_priv); | |
8616 | lpt_program_fdi_mphy(dev_priv); | |
8617 | } | |
8618 | } | |
8619 | ||
8620 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; | |
8621 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8622 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8623 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8624 | ||
8625 | mutex_unlock(&dev_priv->sb_lock); | |
8626 | } | |
8627 | ||
8628 | /* Sequence to disable CLKOUT_DP */ | |
8629 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8630 | { | |
8631 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8632 | uint32_t reg, tmp; | |
8633 | ||
8634 | mutex_lock(&dev_priv->sb_lock); | |
8635 | ||
8636 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; | |
8637 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8638 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8639 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8640 | ||
8641 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8642 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8643 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8644 | tmp |= SBI_SSCCTL_PATHALT; | |
8645 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8646 | udelay(32); | |
8647 | } | |
8648 | tmp |= SBI_SSCCTL_DISABLE; | |
8649 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8650 | } | |
8651 | ||
8652 | mutex_unlock(&dev_priv->sb_lock); | |
8653 | } | |
8654 | ||
8655 | #define BEND_IDX(steps) ((50 + (steps)) / 5) | |
8656 | ||
8657 | static const uint16_t sscdivintphase[] = { | |
8658 | [BEND_IDX( 50)] = 0x3B23, | |
8659 | [BEND_IDX( 45)] = 0x3B23, | |
8660 | [BEND_IDX( 40)] = 0x3C23, | |
8661 | [BEND_IDX( 35)] = 0x3C23, | |
8662 | [BEND_IDX( 30)] = 0x3D23, | |
8663 | [BEND_IDX( 25)] = 0x3D23, | |
8664 | [BEND_IDX( 20)] = 0x3E23, | |
8665 | [BEND_IDX( 15)] = 0x3E23, | |
8666 | [BEND_IDX( 10)] = 0x3F23, | |
8667 | [BEND_IDX( 5)] = 0x3F23, | |
8668 | [BEND_IDX( 0)] = 0x0025, | |
8669 | [BEND_IDX( -5)] = 0x0025, | |
8670 | [BEND_IDX(-10)] = 0x0125, | |
8671 | [BEND_IDX(-15)] = 0x0125, | |
8672 | [BEND_IDX(-20)] = 0x0225, | |
8673 | [BEND_IDX(-25)] = 0x0225, | |
8674 | [BEND_IDX(-30)] = 0x0325, | |
8675 | [BEND_IDX(-35)] = 0x0325, | |
8676 | [BEND_IDX(-40)] = 0x0425, | |
8677 | [BEND_IDX(-45)] = 0x0425, | |
8678 | [BEND_IDX(-50)] = 0x0525, | |
8679 | }; | |
8680 | ||
8681 | /* | |
8682 | * Bend CLKOUT_DP | |
8683 | * steps -50 to 50 inclusive, in steps of 5 | |
8684 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) | |
8685 | * change in clock period = -(steps / 10) * 5.787 ps | |
8686 | */ | |
8687 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) | |
8688 | { | |
8689 | uint32_t tmp; | |
8690 | int idx = BEND_IDX(steps); | |
8691 | ||
8692 | if (WARN_ON(steps % 5 != 0)) | |
8693 | return; | |
8694 | ||
8695 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) | |
8696 | return; | |
8697 | ||
8698 | mutex_lock(&dev_priv->sb_lock); | |
8699 | ||
8700 | if (steps % 10 != 0) | |
8701 | tmp = 0xAAAAAAAB; | |
8702 | else | |
8703 | tmp = 0x00000000; | |
8704 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); | |
8705 | ||
8706 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); | |
8707 | tmp &= 0xffff0000; | |
8708 | tmp |= sscdivintphase[idx]; | |
8709 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); | |
8710 | ||
8711 | mutex_unlock(&dev_priv->sb_lock); | |
8712 | } | |
8713 | ||
8714 | #undef BEND_IDX | |
8715 | ||
8716 | static void lpt_init_pch_refclk(struct drm_device *dev) | |
8717 | { | |
8718 | struct intel_encoder *encoder; | |
8719 | bool has_vga = false; | |
8720 | ||
8721 | for_each_intel_encoder(dev, encoder) { | |
8722 | switch (encoder->type) { | |
8723 | case INTEL_OUTPUT_ANALOG: | |
8724 | has_vga = true; | |
8725 | break; | |
8726 | default: | |
8727 | break; | |
8728 | } | |
8729 | } | |
8730 | ||
8731 | if (has_vga) { | |
8732 | lpt_bend_clkout_dp(to_i915(dev), 0); | |
8733 | lpt_enable_clkout_dp(dev, true, true); | |
8734 | } else { | |
8735 | lpt_disable_clkout_dp(dev); | |
8736 | } | |
8737 | } | |
8738 | ||
8739 | /* | |
8740 | * Initialize reference clocks when the driver loads | |
8741 | */ | |
8742 | void intel_init_pch_refclk(struct drm_device *dev) | |
8743 | { | |
8744 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8745 | ironlake_init_pch_refclk(dev); | |
8746 | else if (HAS_PCH_LPT(dev)) | |
8747 | lpt_init_pch_refclk(dev); | |
8748 | } | |
8749 | ||
8750 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) | |
8751 | { | |
8752 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
8753 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8754 | struct drm_atomic_state *state = crtc_state->base.state; | |
8755 | struct drm_connector *connector; | |
8756 | struct drm_connector_state *connector_state; | |
8757 | struct intel_encoder *encoder; | |
8758 | int num_connectors = 0, i; | |
8759 | bool is_lvds = false; | |
8760 | ||
8761 | for_each_connector_in_state(state, connector, connector_state, i) { | |
8762 | if (connector_state->crtc != crtc_state->base.crtc) | |
8763 | continue; | |
8764 | ||
8765 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8766 | ||
8767 | switch (encoder->type) { | |
8768 | case INTEL_OUTPUT_LVDS: | |
8769 | is_lvds = true; | |
8770 | break; | |
8771 | default: | |
8772 | break; | |
8773 | } | |
8774 | num_connectors++; | |
8775 | } | |
8776 | ||
8777 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
8778 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", | |
8779 | dev_priv->vbt.lvds_ssc_freq); | |
8780 | return dev_priv->vbt.lvds_ssc_freq; | |
8781 | } | |
8782 | ||
8783 | return 120000; | |
8784 | } | |
8785 | ||
8786 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) | |
8787 | { | |
8788 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; | |
8789 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8790 | int pipe = intel_crtc->pipe; | |
8791 | uint32_t val; | |
8792 | ||
8793 | val = 0; | |
8794 | ||
8795 | switch (intel_crtc->config->pipe_bpp) { | |
8796 | case 18: | |
8797 | val |= PIPECONF_6BPC; | |
8798 | break; | |
8799 | case 24: | |
8800 | val |= PIPECONF_8BPC; | |
8801 | break; | |
8802 | case 30: | |
8803 | val |= PIPECONF_10BPC; | |
8804 | break; | |
8805 | case 36: | |
8806 | val |= PIPECONF_12BPC; | |
8807 | break; | |
8808 | default: | |
8809 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
8810 | BUG(); | |
8811 | } | |
8812 | ||
8813 | if (intel_crtc->config->dither) | |
8814 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); | |
8815 | ||
8816 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) | |
8817 | val |= PIPECONF_INTERLACED_ILK; | |
8818 | else | |
8819 | val |= PIPECONF_PROGRESSIVE; | |
8820 | ||
8821 | if (intel_crtc->config->limited_color_range) | |
8822 | val |= PIPECONF_COLOR_RANGE_SELECT; | |
8823 | ||
8824 | I915_WRITE(PIPECONF(pipe), val); | |
8825 | POSTING_READ(PIPECONF(pipe)); | |
8826 | } | |
8827 | ||
8828 | /* | |
8829 | * Set up the pipe CSC unit. | |
8830 | * | |
8831 | * Currently only full range RGB to limited range RGB conversion | |
8832 | * is supported, but eventually this should handle various | |
8833 | * RGB<->YCbCr scenarios as well. | |
8834 | */ | |
8835 | static void intel_set_pipe_csc(struct drm_crtc *crtc) | |
8836 | { | |
8837 | struct drm_device *dev = crtc->dev; | |
8838 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8839 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8840 | int pipe = intel_crtc->pipe; | |
8841 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8842 | ||
8843 | /* | |
8844 | * TODO: Check what kind of values actually come out of the pipe | |
8845 | * with these coeff/postoff values and adjust to get the best | |
8846 | * accuracy. Perhaps we even need to take the bpc value into | |
8847 | * consideration. | |
8848 | */ | |
8849 | ||
8850 | if (intel_crtc->config->limited_color_range) | |
8851 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ | |
8852 | ||
8853 | /* | |
8854 | * GY/GU and RY/RU should be the other way around according | |
8855 | * to BSpec, but reality doesn't agree. Just set them up in | |
8856 | * a way that results in the correct picture. | |
8857 | */ | |
8858 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8859 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8860 | ||
8861 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8862 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8863 | ||
8864 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8865 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8866 | ||
8867 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8868 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8869 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8870 | ||
8871 | if (INTEL_INFO(dev)->gen > 6) { | |
8872 | uint16_t postoff = 0; | |
8873 | ||
8874 | if (intel_crtc->config->limited_color_range) | |
8875 | postoff = (16 * (1 << 12) / 255) & 0x1fff; | |
8876 | ||
8877 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8878 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8879 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8880 | ||
8881 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8882 | } else { | |
8883 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8884 | ||
8885 | if (intel_crtc->config->limited_color_range) | |
8886 | mode |= CSC_BLACK_SCREEN_OFFSET; | |
8887 | ||
8888 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8889 | } | |
8890 | } | |
8891 | ||
8892 | static void haswell_set_pipeconf(struct drm_crtc *crtc) | |
8893 | { | |
8894 | struct drm_device *dev = crtc->dev; | |
8895 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8896 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8897 | enum pipe pipe = intel_crtc->pipe; | |
8898 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; | |
8899 | uint32_t val; | |
8900 | ||
8901 | val = 0; | |
8902 | ||
8903 | if (IS_HASWELL(dev) && intel_crtc->config->dither) | |
8904 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); | |
8905 | ||
8906 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) | |
8907 | val |= PIPECONF_INTERLACED_ILK; | |
8908 | else | |
8909 | val |= PIPECONF_PROGRESSIVE; | |
8910 | ||
8911 | I915_WRITE(PIPECONF(cpu_transcoder), val); | |
8912 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
8913 | ||
8914 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8915 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
8916 | ||
8917 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { | |
8918 | val = 0; | |
8919 | ||
8920 | switch (intel_crtc->config->pipe_bpp) { | |
8921 | case 18: | |
8922 | val |= PIPEMISC_DITHER_6_BPC; | |
8923 | break; | |
8924 | case 24: | |
8925 | val |= PIPEMISC_DITHER_8_BPC; | |
8926 | break; | |
8927 | case 30: | |
8928 | val |= PIPEMISC_DITHER_10_BPC; | |
8929 | break; | |
8930 | case 36: | |
8931 | val |= PIPEMISC_DITHER_12_BPC; | |
8932 | break; | |
8933 | default: | |
8934 | /* Case prevented by pipe_config_set_bpp. */ | |
8935 | BUG(); | |
8936 | } | |
8937 | ||
8938 | if (intel_crtc->config->dither) | |
8939 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; | |
8940 | ||
8941 | I915_WRITE(PIPEMISC(pipe), val); | |
8942 | } | |
8943 | } | |
8944 | ||
8945 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, | |
8946 | struct intel_crtc_state *crtc_state, | |
8947 | intel_clock_t *clock, | |
8948 | bool *has_reduced_clock, | |
8949 | intel_clock_t *reduced_clock) | |
8950 | { | |
8951 | struct drm_device *dev = crtc->dev; | |
8952 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8953 | int refclk; | |
8954 | const intel_limit_t *limit; | |
8955 | bool ret; | |
8956 | ||
8957 | refclk = ironlake_get_refclk(crtc_state); | |
8958 | ||
8959 | /* | |
8960 | * Returns a set of divisors for the desired target clock with the given | |
8961 | * refclk, or FALSE. The returned values represent the clock equation: | |
8962 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8963 | */ | |
8964 | limit = intel_limit(crtc_state, refclk); | |
8965 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
8966 | crtc_state->port_clock, | |
8967 | refclk, NULL, clock); | |
8968 | if (!ret) | |
8969 | return false; | |
8970 | ||
8971 | return true; | |
8972 | } | |
8973 | ||
8974 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) | |
8975 | { | |
8976 | /* | |
8977 | * Account for spread spectrum to avoid | |
8978 | * oversubscribing the link. Max center spread | |
8979 | * is 2.5%; use 5% for safety's sake. | |
8980 | */ | |
8981 | u32 bps = target_clock * bpp * 21 / 20; | |
8982 | return DIV_ROUND_UP(bps, link_bw * 8); | |
8983 | } | |
8984 | ||
8985 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) | |
8986 | { | |
8987 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; | |
8988 | } | |
8989 | ||
8990 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, | |
8991 | struct intel_crtc_state *crtc_state, | |
8992 | u32 *fp, | |
8993 | intel_clock_t *reduced_clock, u32 *fp2) | |
8994 | { | |
8995 | struct drm_crtc *crtc = &intel_crtc->base; | |
8996 | struct drm_device *dev = crtc->dev; | |
8997 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8998 | struct drm_atomic_state *state = crtc_state->base.state; | |
8999 | struct drm_connector *connector; | |
9000 | struct drm_connector_state *connector_state; | |
9001 | struct intel_encoder *encoder; | |
9002 | uint32_t dpll; | |
9003 | int factor, num_connectors = 0, i; | |
9004 | bool is_lvds = false, is_sdvo = false; | |
9005 | ||
9006 | for_each_connector_in_state(state, connector, connector_state, i) { | |
9007 | if (connector_state->crtc != crtc_state->base.crtc) | |
9008 | continue; | |
9009 | ||
9010 | encoder = to_intel_encoder(connector_state->best_encoder); | |
9011 | ||
9012 | switch (encoder->type) { | |
9013 | case INTEL_OUTPUT_LVDS: | |
9014 | is_lvds = true; | |
9015 | break; | |
9016 | case INTEL_OUTPUT_SDVO: | |
9017 | case INTEL_OUTPUT_HDMI: | |
9018 | is_sdvo = true; | |
9019 | break; | |
9020 | default: | |
9021 | break; | |
9022 | } | |
9023 | ||
9024 | num_connectors++; | |
9025 | } | |
9026 | ||
9027 | /* Enable autotuning of the PLL clock (if permissible) */ | |
9028 | factor = 21; | |
9029 | if (is_lvds) { | |
9030 | if ((intel_panel_use_ssc(dev_priv) && | |
9031 | dev_priv->vbt.lvds_ssc_freq == 100000) || | |
9032 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) | |
9033 | factor = 25; | |
9034 | } else if (crtc_state->sdvo_tv_clock) | |
9035 | factor = 20; | |
9036 | ||
9037 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) | |
9038 | *fp |= FP_CB_TUNE; | |
9039 | ||
9040 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) | |
9041 | *fp2 |= FP_CB_TUNE; | |
9042 | ||
9043 | dpll = 0; | |
9044 | ||
9045 | if (is_lvds) | |
9046 | dpll |= DPLLB_MODE_LVDS; | |
9047 | else | |
9048 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
9049 | ||
9050 | dpll |= (crtc_state->pixel_multiplier - 1) | |
9051 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; | |
9052 | ||
9053 | if (is_sdvo) | |
9054 | dpll |= DPLL_SDVO_HIGH_SPEED; | |
9055 | if (crtc_state->has_dp_encoder) | |
9056 | dpll |= DPLL_SDVO_HIGH_SPEED; | |
9057 | ||
9058 | /* compute bitmask from p1 value */ | |
9059 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
9060 | /* also FPA1 */ | |
9061 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
9062 | ||
9063 | switch (crtc_state->dpll.p2) { | |
9064 | case 5: | |
9065 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
9066 | break; | |
9067 | case 7: | |
9068 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
9069 | break; | |
9070 | case 10: | |
9071 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
9072 | break; | |
9073 | case 14: | |
9074 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
9075 | break; | |
9076 | } | |
9077 | ||
9078 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) | |
9079 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
9080 | else | |
9081 | dpll |= PLL_REF_INPUT_DREFCLK; | |
9082 | ||
9083 | return dpll | DPLL_VCO_ENABLE; | |
9084 | } | |
9085 | ||
9086 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, | |
9087 | struct intel_crtc_state *crtc_state) | |
9088 | { | |
9089 | struct drm_device *dev = crtc->base.dev; | |
9090 | intel_clock_t clock, reduced_clock; | |
9091 | u32 dpll = 0, fp = 0, fp2 = 0; | |
9092 | bool ok, has_reduced_clock = false; | |
9093 | bool is_lvds = false; | |
9094 | struct intel_shared_dpll *pll; | |
9095 | ||
9096 | memset(&crtc_state->dpll_hw_state, 0, | |
9097 | sizeof(crtc_state->dpll_hw_state)); | |
9098 | ||
9099 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); | |
9100 | ||
9101 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), | |
9102 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
9103 | ||
9104 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, | |
9105 | &has_reduced_clock, &reduced_clock); | |
9106 | if (!ok && !crtc_state->clock_set) { | |
9107 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
9108 | return -EINVAL; | |
9109 | } | |
9110 | /* Compat-code for transition, will disappear. */ | |
9111 | if (!crtc_state->clock_set) { | |
9112 | crtc_state->dpll.n = clock.n; | |
9113 | crtc_state->dpll.m1 = clock.m1; | |
9114 | crtc_state->dpll.m2 = clock.m2; | |
9115 | crtc_state->dpll.p1 = clock.p1; | |
9116 | crtc_state->dpll.p2 = clock.p2; | |
9117 | } | |
9118 | ||
9119 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ | |
9120 | if (crtc_state->has_pch_encoder) { | |
9121 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
9122 | if (has_reduced_clock) | |
9123 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); | |
9124 | ||
9125 | dpll = ironlake_compute_dpll(crtc, crtc_state, | |
9126 | &fp, &reduced_clock, | |
9127 | has_reduced_clock ? &fp2 : NULL); | |
9128 | ||
9129 | crtc_state->dpll_hw_state.dpll = dpll; | |
9130 | crtc_state->dpll_hw_state.fp0 = fp; | |
9131 | if (has_reduced_clock) | |
9132 | crtc_state->dpll_hw_state.fp1 = fp2; | |
9133 | else | |
9134 | crtc_state->dpll_hw_state.fp1 = fp; | |
9135 | ||
9136 | pll = intel_get_shared_dpll(crtc, crtc_state); | |
9137 | if (pll == NULL) { | |
9138 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", | |
9139 | pipe_name(crtc->pipe)); | |
9140 | return -EINVAL; | |
9141 | } | |
9142 | } | |
9143 | ||
9144 | if (is_lvds && has_reduced_clock) | |
9145 | crtc->lowfreq_avail = true; | |
9146 | else | |
9147 | crtc->lowfreq_avail = false; | |
9148 | ||
9149 | return 0; | |
9150 | } | |
9151 | ||
9152 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, | |
9153 | struct intel_link_m_n *m_n) | |
9154 | { | |
9155 | struct drm_device *dev = crtc->base.dev; | |
9156 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9157 | enum pipe pipe = crtc->pipe; | |
9158 | ||
9159 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
9160 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
9161 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9162 | & ~TU_SIZE_MASK; | |
9163 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
9164 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9165 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9166 | } | |
9167 | ||
9168 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
9169 | enum transcoder transcoder, | |
9170 | struct intel_link_m_n *m_n, | |
9171 | struct intel_link_m_n *m2_n2) | |
9172 | { | |
9173 | struct drm_device *dev = crtc->base.dev; | |
9174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9175 | enum pipe pipe = crtc->pipe; | |
9176 | ||
9177 | if (INTEL_INFO(dev)->gen >= 5) { | |
9178 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
9179 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
9180 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
9181 | & ~TU_SIZE_MASK; | |
9182 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
9183 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
9184 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9185 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for | |
9186 | * gen < 8) and if DRRS is supported (to make sure the | |
9187 | * registers are not unnecessarily read). | |
9188 | */ | |
9189 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
9190 | crtc->config->has_drrs) { | |
9191 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); | |
9192 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
9193 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
9194 | & ~TU_SIZE_MASK; | |
9195 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
9196 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
9197 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9198 | } | |
9199 | } else { | |
9200 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
9201 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
9202 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9203 | & ~TU_SIZE_MASK; | |
9204 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
9205 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9206 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9207 | } | |
9208 | } | |
9209 | ||
9210 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
9211 | struct intel_crtc_state *pipe_config) | |
9212 | { | |
9213 | if (pipe_config->has_pch_encoder) | |
9214 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); | |
9215 | else | |
9216 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
9217 | &pipe_config->dp_m_n, | |
9218 | &pipe_config->dp_m2_n2); | |
9219 | } | |
9220 | ||
9221 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, | |
9222 | struct intel_crtc_state *pipe_config) | |
9223 | { | |
9224 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
9225 | &pipe_config->fdi_m_n, NULL); | |
9226 | } | |
9227 | ||
9228 | static void skylake_get_pfit_config(struct intel_crtc *crtc, | |
9229 | struct intel_crtc_state *pipe_config) | |
9230 | { | |
9231 | struct drm_device *dev = crtc->base.dev; | |
9232 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9233 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; | |
9234 | uint32_t ps_ctrl = 0; | |
9235 | int id = -1; | |
9236 | int i; | |
9237 | ||
9238 | /* find scaler attached to this pipe */ | |
9239 | for (i = 0; i < crtc->num_scalers; i++) { | |
9240 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9241 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9242 | id = i; | |
9243 | pipe_config->pch_pfit.enabled = true; | |
9244 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9245 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9246 | break; | |
9247 | } | |
9248 | } | |
9249 | ||
9250 | scaler_state->scaler_id = id; | |
9251 | if (id >= 0) { | |
9252 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9253 | } else { | |
9254 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9255 | } | |
9256 | } | |
9257 | ||
9258 | static void | |
9259 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9260 | struct intel_initial_plane_config *plane_config) | |
9261 | { | |
9262 | struct drm_device *dev = crtc->base.dev; | |
9263 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9264 | u32 val, base, offset, stride_mult, tiling; | |
9265 | int pipe = crtc->pipe; | |
9266 | int fourcc, pixel_format; | |
9267 | unsigned int aligned_height; | |
9268 | struct drm_framebuffer *fb; | |
9269 | struct intel_framebuffer *intel_fb; | |
9270 | ||
9271 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
9272 | if (!intel_fb) { | |
9273 | DRM_DEBUG_KMS("failed to alloc fb\n"); | |
9274 | return; | |
9275 | } | |
9276 | ||
9277 | fb = &intel_fb->base; | |
9278 | ||
9279 | val = I915_READ(PLANE_CTL(pipe, 0)); | |
9280 | if (!(val & PLANE_CTL_ENABLE)) | |
9281 | goto error; | |
9282 | ||
9283 | pixel_format = val & PLANE_CTL_FORMAT_MASK; | |
9284 | fourcc = skl_format_to_fourcc(pixel_format, | |
9285 | val & PLANE_CTL_ORDER_RGBX, | |
9286 | val & PLANE_CTL_ALPHA_MASK); | |
9287 | fb->pixel_format = fourcc; | |
9288 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9289 | ||
9290 | tiling = val & PLANE_CTL_TILED_MASK; | |
9291 | switch (tiling) { | |
9292 | case PLANE_CTL_TILED_LINEAR: | |
9293 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9294 | break; | |
9295 | case PLANE_CTL_TILED_X: | |
9296 | plane_config->tiling = I915_TILING_X; | |
9297 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9298 | break; | |
9299 | case PLANE_CTL_TILED_Y: | |
9300 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9301 | break; | |
9302 | case PLANE_CTL_TILED_YF: | |
9303 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9304 | break; | |
9305 | default: | |
9306 | MISSING_CASE(tiling); | |
9307 | goto error; | |
9308 | } | |
9309 | ||
9310 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; | |
9311 | plane_config->base = base; | |
9312 | ||
9313 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9314 | ||
9315 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9316 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9317 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9318 | ||
9319 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
9320 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier[0], | |
9321 | fb->pixel_format); | |
9322 | fb->pitches[0] = (val & 0x3ff) * stride_mult; | |
9323 | ||
9324 | aligned_height = intel_fb_align_height(dev, fb->height, | |
9325 | fb->pixel_format, | |
9326 | fb->modifier[0]); | |
9327 | ||
9328 | plane_config->size = fb->pitches[0] * aligned_height; | |
9329 | ||
9330 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9331 | pipe_name(pipe), fb->width, fb->height, | |
9332 | fb->bits_per_pixel, base, fb->pitches[0], | |
9333 | plane_config->size); | |
9334 | ||
9335 | plane_config->fb = intel_fb; | |
9336 | return; | |
9337 | ||
9338 | error: | |
9339 | kfree(fb); | |
9340 | } | |
9341 | ||
9342 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, | |
9343 | struct intel_crtc_state *pipe_config) | |
9344 | { | |
9345 | struct drm_device *dev = crtc->base.dev; | |
9346 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9347 | uint32_t tmp; | |
9348 | ||
9349 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9350 | ||
9351 | if (tmp & PF_ENABLE) { | |
9352 | pipe_config->pch_pfit.enabled = true; | |
9353 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); | |
9354 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
9355 | ||
9356 | /* We currently do not free assignements of panel fitters on | |
9357 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9358 | * differentiates them) so just WARN about this case for now. */ | |
9359 | if (IS_GEN7(dev)) { | |
9360 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9361 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9362 | } | |
9363 | } | |
9364 | } | |
9365 | ||
9366 | static void | |
9367 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9368 | struct intel_initial_plane_config *plane_config) | |
9369 | { | |
9370 | struct drm_device *dev = crtc->base.dev; | |
9371 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9372 | u32 val, base, offset; | |
9373 | int pipe = crtc->pipe; | |
9374 | int fourcc, pixel_format; | |
9375 | unsigned int aligned_height; | |
9376 | struct drm_framebuffer *fb; | |
9377 | struct intel_framebuffer *intel_fb; | |
9378 | ||
9379 | val = I915_READ(DSPCNTR(pipe)); | |
9380 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9381 | return; | |
9382 | ||
9383 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
9384 | if (!intel_fb) { | |
9385 | DRM_DEBUG_KMS("failed to alloc fb\n"); | |
9386 | return; | |
9387 | } | |
9388 | ||
9389 | fb = &intel_fb->base; | |
9390 | ||
9391 | if (INTEL_INFO(dev)->gen >= 4) { | |
9392 | if (val & DISPPLANE_TILED) { | |
9393 | plane_config->tiling = I915_TILING_X; | |
9394 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9395 | } | |
9396 | } | |
9397 | ||
9398 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
9399 | fourcc = i9xx_format_to_fourcc(pixel_format); | |
9400 | fb->pixel_format = fourcc; | |
9401 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9402 | ||
9403 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; | |
9404 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
9405 | offset = I915_READ(DSPOFFSET(pipe)); | |
9406 | } else { | |
9407 | if (plane_config->tiling) | |
9408 | offset = I915_READ(DSPTILEOFF(pipe)); | |
9409 | else | |
9410 | offset = I915_READ(DSPLINOFF(pipe)); | |
9411 | } | |
9412 | plane_config->base = base; | |
9413 | ||
9414 | val = I915_READ(PIPESRC(pipe)); | |
9415 | fb->width = ((val >> 16) & 0xfff) + 1; | |
9416 | fb->height = ((val >> 0) & 0xfff) + 1; | |
9417 | ||
9418 | val = I915_READ(DSPSTRIDE(pipe)); | |
9419 | fb->pitches[0] = val & 0xffffffc0; | |
9420 | ||
9421 | aligned_height = intel_fb_align_height(dev, fb->height, | |
9422 | fb->pixel_format, | |
9423 | fb->modifier[0]); | |
9424 | ||
9425 | plane_config->size = fb->pitches[0] * aligned_height; | |
9426 | ||
9427 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9428 | pipe_name(pipe), fb->width, fb->height, | |
9429 | fb->bits_per_pixel, base, fb->pitches[0], | |
9430 | plane_config->size); | |
9431 | ||
9432 | plane_config->fb = intel_fb; | |
9433 | } | |
9434 | ||
9435 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, | |
9436 | struct intel_crtc_state *pipe_config) | |
9437 | { | |
9438 | struct drm_device *dev = crtc->base.dev; | |
9439 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9440 | enum intel_display_power_domain power_domain; | |
9441 | uint32_t tmp; | |
9442 | bool ret; | |
9443 | ||
9444 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); | |
9445 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
9446 | return false; | |
9447 | ||
9448 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; | |
9449 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; | |
9450 | ||
9451 | ret = false; | |
9452 | tmp = I915_READ(PIPECONF(crtc->pipe)); | |
9453 | if (!(tmp & PIPECONF_ENABLE)) | |
9454 | goto out; | |
9455 | ||
9456 | switch (tmp & PIPECONF_BPC_MASK) { | |
9457 | case PIPECONF_6BPC: | |
9458 | pipe_config->pipe_bpp = 18; | |
9459 | break; | |
9460 | case PIPECONF_8BPC: | |
9461 | pipe_config->pipe_bpp = 24; | |
9462 | break; | |
9463 | case PIPECONF_10BPC: | |
9464 | pipe_config->pipe_bpp = 30; | |
9465 | break; | |
9466 | case PIPECONF_12BPC: | |
9467 | pipe_config->pipe_bpp = 36; | |
9468 | break; | |
9469 | default: | |
9470 | break; | |
9471 | } | |
9472 | ||
9473 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) | |
9474 | pipe_config->limited_color_range = true; | |
9475 | ||
9476 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { | |
9477 | struct intel_shared_dpll *pll; | |
9478 | ||
9479 | pipe_config->has_pch_encoder = true; | |
9480 | ||
9481 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); | |
9482 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9483 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9484 | ||
9485 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9486 | ||
9487 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
9488 | pipe_config->shared_dpll = | |
9489 | (enum intel_dpll_id) crtc->pipe; | |
9490 | } else { | |
9491 | tmp = I915_READ(PCH_DPLL_SEL); | |
9492 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9493 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9494 | else | |
9495 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9496 | } | |
9497 | ||
9498 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9499 | ||
9500 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9501 | &pipe_config->dpll_hw_state)); | |
9502 | ||
9503 | tmp = pipe_config->dpll_hw_state.dpll; | |
9504 | pipe_config->pixel_multiplier = | |
9505 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9506 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
9507 | ||
9508 | ironlake_pch_clock_get(crtc, pipe_config); | |
9509 | } else { | |
9510 | pipe_config->pixel_multiplier = 1; | |
9511 | } | |
9512 | ||
9513 | intel_get_pipe_timings(crtc, pipe_config); | |
9514 | ||
9515 | ironlake_get_pfit_config(crtc, pipe_config); | |
9516 | ||
9517 | ret = true; | |
9518 | ||
9519 | out: | |
9520 | intel_display_power_put(dev_priv, power_domain); | |
9521 | ||
9522 | return ret; | |
9523 | } | |
9524 | ||
9525 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) | |
9526 | { | |
9527 | struct drm_device *dev = dev_priv->dev; | |
9528 | struct intel_crtc *crtc; | |
9529 | ||
9530 | for_each_intel_crtc(dev, crtc) | |
9531 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", | |
9532 | pipe_name(crtc->pipe)); | |
9533 | ||
9534 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); | |
9535 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
9536 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); | |
9537 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
9538 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); | |
9539 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
9540 | "CPU PWM1 enabled\n"); | |
9541 | if (IS_HASWELL(dev)) | |
9542 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, | |
9543 | "CPU PWM2 enabled\n"); | |
9544 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, | |
9545 | "PCH PWM1 enabled\n"); | |
9546 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, | |
9547 | "Utility pin enabled\n"); | |
9548 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); | |
9549 | ||
9550 | /* | |
9551 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9552 | * interrupts remain enabled. We used to check for that, but since it's | |
9553 | * gen-specific and since we only disable LCPLL after we fully disable | |
9554 | * the interrupts, the check below should be enough. | |
9555 | */ | |
9556 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); | |
9557 | } | |
9558 | ||
9559 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) | |
9560 | { | |
9561 | struct drm_device *dev = dev_priv->dev; | |
9562 | ||
9563 | if (IS_HASWELL(dev)) | |
9564 | return I915_READ(D_COMP_HSW); | |
9565 | else | |
9566 | return I915_READ(D_COMP_BDW); | |
9567 | } | |
9568 | ||
9569 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) | |
9570 | { | |
9571 | struct drm_device *dev = dev_priv->dev; | |
9572 | ||
9573 | if (IS_HASWELL(dev)) { | |
9574 | mutex_lock(&dev_priv->rps.hw_lock); | |
9575 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9576 | val)) | |
9577 | DRM_ERROR("Failed to write to D_COMP\n"); | |
9578 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9579 | } else { | |
9580 | I915_WRITE(D_COMP_BDW, val); | |
9581 | POSTING_READ(D_COMP_BDW); | |
9582 | } | |
9583 | } | |
9584 | ||
9585 | /* | |
9586 | * This function implements pieces of two sequences from BSpec: | |
9587 | * - Sequence for display software to disable LCPLL | |
9588 | * - Sequence for display software to allow package C8+ | |
9589 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9590 | * register. Callers should take care of disabling all the display engine | |
9591 | * functions, doing the mode unset, fixing interrupts, etc. | |
9592 | */ | |
9593 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, | |
9594 | bool switch_to_fclk, bool allow_power_down) | |
9595 | { | |
9596 | uint32_t val; | |
9597 | ||
9598 | assert_can_disable_lcpll(dev_priv); | |
9599 | ||
9600 | val = I915_READ(LCPLL_CTL); | |
9601 | ||
9602 | if (switch_to_fclk) { | |
9603 | val |= LCPLL_CD_SOURCE_FCLK; | |
9604 | I915_WRITE(LCPLL_CTL, val); | |
9605 | ||
9606 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9607 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9608 | DRM_ERROR("Switching to FCLK failed\n"); | |
9609 | ||
9610 | val = I915_READ(LCPLL_CTL); | |
9611 | } | |
9612 | ||
9613 | val |= LCPLL_PLL_DISABLE; | |
9614 | I915_WRITE(LCPLL_CTL, val); | |
9615 | POSTING_READ(LCPLL_CTL); | |
9616 | ||
9617 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9618 | DRM_ERROR("LCPLL still locked\n"); | |
9619 | ||
9620 | val = hsw_read_dcomp(dev_priv); | |
9621 | val |= D_COMP_COMP_DISABLE; | |
9622 | hsw_write_dcomp(dev_priv, val); | |
9623 | ndelay(100); | |
9624 | ||
9625 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, | |
9626 | 1)) | |
9627 | DRM_ERROR("D_COMP RCOMP still in progress\n"); | |
9628 | ||
9629 | if (allow_power_down) { | |
9630 | val = I915_READ(LCPLL_CTL); | |
9631 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9632 | I915_WRITE(LCPLL_CTL, val); | |
9633 | POSTING_READ(LCPLL_CTL); | |
9634 | } | |
9635 | } | |
9636 | ||
9637 | /* | |
9638 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9639 | * source. | |
9640 | */ | |
9641 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) | |
9642 | { | |
9643 | uint32_t val; | |
9644 | ||
9645 | val = I915_READ(LCPLL_CTL); | |
9646 | ||
9647 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9648 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9649 | return; | |
9650 | ||
9651 | /* | |
9652 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9653 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
9654 | */ | |
9655 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); | |
9656 | ||
9657 | if (val & LCPLL_POWER_DOWN_ALLOW) { | |
9658 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9659 | I915_WRITE(LCPLL_CTL, val); | |
9660 | POSTING_READ(LCPLL_CTL); | |
9661 | } | |
9662 | ||
9663 | val = hsw_read_dcomp(dev_priv); | |
9664 | val |= D_COMP_COMP_FORCE; | |
9665 | val &= ~D_COMP_COMP_DISABLE; | |
9666 | hsw_write_dcomp(dev_priv, val); | |
9667 | ||
9668 | val = I915_READ(LCPLL_CTL); | |
9669 | val &= ~LCPLL_PLL_DISABLE; | |
9670 | I915_WRITE(LCPLL_CTL, val); | |
9671 | ||
9672 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9673 | DRM_ERROR("LCPLL not locked yet\n"); | |
9674 | ||
9675 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9676 | val = I915_READ(LCPLL_CTL); | |
9677 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9678 | I915_WRITE(LCPLL_CTL, val); | |
9679 | ||
9680 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9681 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9682 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9683 | } | |
9684 | ||
9685 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); | |
9686 | intel_update_cdclk(dev_priv->dev); | |
9687 | } | |
9688 | ||
9689 | /* | |
9690 | * Package states C8 and deeper are really deep PC states that can only be | |
9691 | * reached when all the devices on the system allow it, so even if the graphics | |
9692 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9693 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9694 | * | |
9695 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9696 | * well is disabled and most interrupts are disabled, and these are also | |
9697 | * requirements for runtime PM. When these conditions are met, we manually do | |
9698 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9699 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9700 | * hang the machine. | |
9701 | * | |
9702 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9703 | * the state of some registers, so when we come back from PC8+ we need to | |
9704 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9705 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9706 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9707 | * because of the runtime PM support). | |
9708 | * | |
9709 | * For more, read "Display Sequences for Package C8" on the hardware | |
9710 | * documentation. | |
9711 | */ | |
9712 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) | |
9713 | { | |
9714 | struct drm_device *dev = dev_priv->dev; | |
9715 | uint32_t val; | |
9716 | ||
9717 | DRM_DEBUG_KMS("Enabling package C8+\n"); | |
9718 | ||
9719 | if (HAS_PCH_LPT_LP(dev)) { | |
9720 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9721 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9722 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9723 | } | |
9724 | ||
9725 | lpt_disable_clkout_dp(dev); | |
9726 | hsw_disable_lcpll(dev_priv, true, true); | |
9727 | } | |
9728 | ||
9729 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) | |
9730 | { | |
9731 | struct drm_device *dev = dev_priv->dev; | |
9732 | uint32_t val; | |
9733 | ||
9734 | DRM_DEBUG_KMS("Disabling package C8+\n"); | |
9735 | ||
9736 | hsw_restore_lcpll(dev_priv); | |
9737 | lpt_init_pch_refclk(dev); | |
9738 | ||
9739 | if (HAS_PCH_LPT_LP(dev)) { | |
9740 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9741 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9742 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9743 | } | |
9744 | } | |
9745 | ||
9746 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) | |
9747 | { | |
9748 | struct drm_device *dev = old_state->dev; | |
9749 | struct intel_atomic_state *old_intel_state = | |
9750 | to_intel_atomic_state(old_state); | |
9751 | unsigned int req_cdclk = old_intel_state->dev_cdclk; | |
9752 | ||
9753 | broxton_set_cdclk(dev, req_cdclk); | |
9754 | } | |
9755 | ||
9756 | /* compute the max rate for new configuration */ | |
9757 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) | |
9758 | { | |
9759 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
9760 | struct drm_i915_private *dev_priv = state->dev->dev_private; | |
9761 | struct drm_crtc *crtc; | |
9762 | struct drm_crtc_state *cstate; | |
9763 | struct intel_crtc_state *crtc_state; | |
9764 | unsigned max_pixel_rate = 0, i; | |
9765 | enum pipe pipe; | |
9766 | ||
9767 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, | |
9768 | sizeof(intel_state->min_pixclk)); | |
9769 | ||
9770 | for_each_crtc_in_state(state, crtc, cstate, i) { | |
9771 | int pixel_rate; | |
9772 | ||
9773 | crtc_state = to_intel_crtc_state(cstate); | |
9774 | if (!crtc_state->base.enable) { | |
9775 | intel_state->min_pixclk[i] = 0; | |
9776 | continue; | |
9777 | } | |
9778 | ||
9779 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); | |
9780 | ||
9781 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
9782 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) | |
9783 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); | |
9784 | ||
9785 | intel_state->min_pixclk[i] = pixel_rate; | |
9786 | } | |
9787 | ||
9788 | for_each_pipe(dev_priv, pipe) | |
9789 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); | |
9790 | ||
9791 | return max_pixel_rate; | |
9792 | } | |
9793 | ||
9794 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9795 | { | |
9796 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9797 | uint32_t val, data; | |
9798 | int ret; | |
9799 | ||
9800 | if (WARN((I915_READ(LCPLL_CTL) & | |
9801 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9802 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9803 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9804 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9805 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9806 | return; | |
9807 | ||
9808 | mutex_lock(&dev_priv->rps.hw_lock); | |
9809 | ret = sandybridge_pcode_write(dev_priv, | |
9810 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9811 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9812 | if (ret) { | |
9813 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9814 | return; | |
9815 | } | |
9816 | ||
9817 | val = I915_READ(LCPLL_CTL); | |
9818 | val |= LCPLL_CD_SOURCE_FCLK; | |
9819 | I915_WRITE(LCPLL_CTL, val); | |
9820 | ||
9821 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9822 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9823 | DRM_ERROR("Switching to FCLK failed\n"); | |
9824 | ||
9825 | val = I915_READ(LCPLL_CTL); | |
9826 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9827 | ||
9828 | switch (cdclk) { | |
9829 | case 450000: | |
9830 | val |= LCPLL_CLK_FREQ_450; | |
9831 | data = 0; | |
9832 | break; | |
9833 | case 540000: | |
9834 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9835 | data = 1; | |
9836 | break; | |
9837 | case 337500: | |
9838 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9839 | data = 2; | |
9840 | break; | |
9841 | case 675000: | |
9842 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9843 | data = 3; | |
9844 | break; | |
9845 | default: | |
9846 | WARN(1, "invalid cdclk frequency\n"); | |
9847 | return; | |
9848 | } | |
9849 | ||
9850 | I915_WRITE(LCPLL_CTL, val); | |
9851 | ||
9852 | val = I915_READ(LCPLL_CTL); | |
9853 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9854 | I915_WRITE(LCPLL_CTL, val); | |
9855 | ||
9856 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9857 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9858 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9859 | ||
9860 | mutex_lock(&dev_priv->rps.hw_lock); | |
9861 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9862 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9863 | ||
9864 | intel_update_cdclk(dev); | |
9865 | ||
9866 | WARN(cdclk != dev_priv->cdclk_freq, | |
9867 | "cdclk requested %d kHz but got %d kHz\n", | |
9868 | cdclk, dev_priv->cdclk_freq); | |
9869 | } | |
9870 | ||
9871 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) | |
9872 | { | |
9873 | struct drm_i915_private *dev_priv = to_i915(state->dev); | |
9874 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
9875 | int max_pixclk = ilk_max_pixel_rate(state); | |
9876 | int cdclk; | |
9877 | ||
9878 | /* | |
9879 | * FIXME should also account for plane ratio | |
9880 | * once 64bpp pixel formats are supported. | |
9881 | */ | |
9882 | if (max_pixclk > 540000) | |
9883 | cdclk = 675000; | |
9884 | else if (max_pixclk > 450000) | |
9885 | cdclk = 540000; | |
9886 | else if (max_pixclk > 337500) | |
9887 | cdclk = 450000; | |
9888 | else | |
9889 | cdclk = 337500; | |
9890 | ||
9891 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9892 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9893 | cdclk, dev_priv->max_cdclk_freq); | |
9894 | return -EINVAL; | |
9895 | } | |
9896 | ||
9897 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; | |
9898 | if (!intel_state->active_crtcs) | |
9899 | intel_state->dev_cdclk = 337500; | |
9900 | ||
9901 | return 0; | |
9902 | } | |
9903 | ||
9904 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) | |
9905 | { | |
9906 | struct drm_device *dev = old_state->dev; | |
9907 | struct intel_atomic_state *old_intel_state = | |
9908 | to_intel_atomic_state(old_state); | |
9909 | unsigned req_cdclk = old_intel_state->dev_cdclk; | |
9910 | ||
9911 | broadwell_set_cdclk(dev, req_cdclk); | |
9912 | } | |
9913 | ||
9914 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, | |
9915 | struct intel_crtc_state *crtc_state) | |
9916 | { | |
9917 | struct intel_encoder *intel_encoder = | |
9918 | intel_ddi_get_crtc_new_encoder(crtc_state); | |
9919 | ||
9920 | if (intel_encoder->type != INTEL_OUTPUT_DSI) { | |
9921 | if (!intel_ddi_pll_select(crtc, crtc_state)) | |
9922 | return -EINVAL; | |
9923 | } | |
9924 | ||
9925 | crtc->lowfreq_avail = false; | |
9926 | ||
9927 | return 0; | |
9928 | } | |
9929 | ||
9930 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, | |
9931 | enum port port, | |
9932 | struct intel_crtc_state *pipe_config) | |
9933 | { | |
9934 | switch (port) { | |
9935 | case PORT_A: | |
9936 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9937 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9938 | break; | |
9939 | case PORT_B: | |
9940 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9941 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9942 | break; | |
9943 | case PORT_C: | |
9944 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9945 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9946 | break; | |
9947 | default: | |
9948 | DRM_ERROR("Incorrect port type\n"); | |
9949 | } | |
9950 | } | |
9951 | ||
9952 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, | |
9953 | enum port port, | |
9954 | struct intel_crtc_state *pipe_config) | |
9955 | { | |
9956 | u32 temp, dpll_ctl1; | |
9957 | ||
9958 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9959 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9960 | ||
9961 | switch (pipe_config->ddi_pll_sel) { | |
9962 | case SKL_DPLL0: | |
9963 | /* | |
9964 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9965 | * of the shared DPLL framework and thus needs to be read out | |
9966 | * separately | |
9967 | */ | |
9968 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9969 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9970 | break; | |
9971 | case SKL_DPLL1: | |
9972 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9973 | break; | |
9974 | case SKL_DPLL2: | |
9975 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9976 | break; | |
9977 | case SKL_DPLL3: | |
9978 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9979 | break; | |
9980 | } | |
9981 | } | |
9982 | ||
9983 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, | |
9984 | enum port port, | |
9985 | struct intel_crtc_state *pipe_config) | |
9986 | { | |
9987 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9988 | ||
9989 | switch (pipe_config->ddi_pll_sel) { | |
9990 | case PORT_CLK_SEL_WRPLL1: | |
9991 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9992 | break; | |
9993 | case PORT_CLK_SEL_WRPLL2: | |
9994 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9995 | break; | |
9996 | case PORT_CLK_SEL_SPLL: | |
9997 | pipe_config->shared_dpll = DPLL_ID_SPLL; | |
9998 | break; | |
9999 | } | |
10000 | } | |
10001 | ||
10002 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, | |
10003 | struct intel_crtc_state *pipe_config) | |
10004 | { | |
10005 | struct drm_device *dev = crtc->base.dev; | |
10006 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10007 | struct intel_shared_dpll *pll; | |
10008 | enum port port; | |
10009 | uint32_t tmp; | |
10010 | ||
10011 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
10012 | ||
10013 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
10014 | ||
10015 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) | |
10016 | skylake_get_ddi_pll(dev_priv, port, pipe_config); | |
10017 | else if (IS_BROXTON(dev)) | |
10018 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
10019 | else | |
10020 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
10021 | ||
10022 | if (pipe_config->shared_dpll >= 0) { | |
10023 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
10024 | ||
10025 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
10026 | &pipe_config->dpll_hw_state)); | |
10027 | } | |
10028 | ||
10029 | /* | |
10030 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
10031 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
10032 | * the PCH transcoder is on. | |
10033 | */ | |
10034 | if (INTEL_INFO(dev)->gen < 9 && | |
10035 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
10036 | pipe_config->has_pch_encoder = true; | |
10037 | ||
10038 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
10039 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
10040 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
10041 | ||
10042 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
10043 | } | |
10044 | } | |
10045 | ||
10046 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, | |
10047 | struct intel_crtc_state *pipe_config) | |
10048 | { | |
10049 | struct drm_device *dev = crtc->base.dev; | |
10050 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10051 | enum intel_display_power_domain power_domain; | |
10052 | unsigned long power_domain_mask; | |
10053 | uint32_t tmp; | |
10054 | bool ret; | |
10055 | ||
10056 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); | |
10057 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
10058 | return false; | |
10059 | power_domain_mask = BIT(power_domain); | |
10060 | ||
10061 | ret = false; | |
10062 | ||
10063 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; | |
10064 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; | |
10065 | ||
10066 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); | |
10067 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
10068 | enum pipe trans_edp_pipe; | |
10069 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
10070 | default: | |
10071 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
10072 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
10073 | case TRANS_DDI_EDP_INPUT_A_ON: | |
10074 | trans_edp_pipe = PIPE_A; | |
10075 | break; | |
10076 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
10077 | trans_edp_pipe = PIPE_B; | |
10078 | break; | |
10079 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
10080 | trans_edp_pipe = PIPE_C; | |
10081 | break; | |
10082 | } | |
10083 | ||
10084 | if (trans_edp_pipe == crtc->pipe) | |
10085 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
10086 | } | |
10087 | ||
10088 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); | |
10089 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
10090 | goto out; | |
10091 | power_domain_mask |= BIT(power_domain); | |
10092 | ||
10093 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); | |
10094 | if (!(tmp & PIPECONF_ENABLE)) | |
10095 | goto out; | |
10096 | ||
10097 | haswell_get_ddi_port_state(crtc, pipe_config); | |
10098 | ||
10099 | intel_get_pipe_timings(crtc, pipe_config); | |
10100 | ||
10101 | if (INTEL_INFO(dev)->gen >= 9) { | |
10102 | skl_init_scalers(dev, crtc, pipe_config); | |
10103 | } | |
10104 | ||
10105 | if (INTEL_INFO(dev)->gen >= 9) { | |
10106 | pipe_config->scaler_state.scaler_id = -1; | |
10107 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
10108 | } | |
10109 | ||
10110 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); | |
10111 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
10112 | power_domain_mask |= BIT(power_domain); | |
10113 | if (INTEL_INFO(dev)->gen >= 9) | |
10114 | skylake_get_pfit_config(crtc, pipe_config); | |
10115 | else | |
10116 | ironlake_get_pfit_config(crtc, pipe_config); | |
10117 | } | |
10118 | ||
10119 | if (IS_HASWELL(dev)) | |
10120 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
10121 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
10122 | ||
10123 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { | |
10124 | pipe_config->pixel_multiplier = | |
10125 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
10126 | } else { | |
10127 | pipe_config->pixel_multiplier = 1; | |
10128 | } | |
10129 | ||
10130 | ret = true; | |
10131 | ||
10132 | out: | |
10133 | for_each_power_domain(power_domain, power_domain_mask) | |
10134 | intel_display_power_put(dev_priv, power_domain); | |
10135 | ||
10136 | return ret; | |
10137 | } | |
10138 | ||
10139 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, | |
10140 | const struct intel_plane_state *plane_state) | |
10141 | { | |
10142 | struct drm_device *dev = crtc->dev; | |
10143 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10144 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10145 | uint32_t cntl = 0, size = 0; | |
10146 | ||
10147 | if (plane_state && plane_state->visible) { | |
10148 | unsigned int width = plane_state->base.crtc_w; | |
10149 | unsigned int height = plane_state->base.crtc_h; | |
10150 | unsigned int stride = roundup_pow_of_two(width) * 4; | |
10151 | ||
10152 | switch (stride) { | |
10153 | default: | |
10154 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
10155 | width, stride); | |
10156 | stride = 256; | |
10157 | /* fallthrough */ | |
10158 | case 256: | |
10159 | case 512: | |
10160 | case 1024: | |
10161 | case 2048: | |
10162 | break; | |
10163 | } | |
10164 | ||
10165 | cntl |= CURSOR_ENABLE | | |
10166 | CURSOR_GAMMA_ENABLE | | |
10167 | CURSOR_FORMAT_ARGB | | |
10168 | CURSOR_STRIDE(stride); | |
10169 | ||
10170 | size = (height << 12) | width; | |
10171 | } | |
10172 | ||
10173 | if (intel_crtc->cursor_cntl != 0 && | |
10174 | (intel_crtc->cursor_base != base || | |
10175 | intel_crtc->cursor_size != size || | |
10176 | intel_crtc->cursor_cntl != cntl)) { | |
10177 | /* On these chipsets we can only modify the base/size/stride | |
10178 | * whilst the cursor is disabled. | |
10179 | */ | |
10180 | I915_WRITE(CURCNTR(PIPE_A), 0); | |
10181 | POSTING_READ(CURCNTR(PIPE_A)); | |
10182 | intel_crtc->cursor_cntl = 0; | |
10183 | } | |
10184 | ||
10185 | if (intel_crtc->cursor_base != base) { | |
10186 | I915_WRITE(CURBASE(PIPE_A), base); | |
10187 | intel_crtc->cursor_base = base; | |
10188 | } | |
10189 | ||
10190 | if (intel_crtc->cursor_size != size) { | |
10191 | I915_WRITE(CURSIZE, size); | |
10192 | intel_crtc->cursor_size = size; | |
10193 | } | |
10194 | ||
10195 | if (intel_crtc->cursor_cntl != cntl) { | |
10196 | I915_WRITE(CURCNTR(PIPE_A), cntl); | |
10197 | POSTING_READ(CURCNTR(PIPE_A)); | |
10198 | intel_crtc->cursor_cntl = cntl; | |
10199 | } | |
10200 | } | |
10201 | ||
10202 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, | |
10203 | const struct intel_plane_state *plane_state) | |
10204 | { | |
10205 | struct drm_device *dev = crtc->dev; | |
10206 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10207 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10208 | int pipe = intel_crtc->pipe; | |
10209 | uint32_t cntl = 0; | |
10210 | ||
10211 | if (plane_state && plane_state->visible) { | |
10212 | cntl = MCURSOR_GAMMA_ENABLE; | |
10213 | switch (plane_state->base.crtc_w) { | |
10214 | case 64: | |
10215 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
10216 | break; | |
10217 | case 128: | |
10218 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
10219 | break; | |
10220 | case 256: | |
10221 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10222 | break; | |
10223 | default: | |
10224 | MISSING_CASE(plane_state->base.crtc_w); | |
10225 | return; | |
10226 | } | |
10227 | cntl |= pipe << 28; /* Connect to correct pipe */ | |
10228 | ||
10229 | if (HAS_DDI(dev)) | |
10230 | cntl |= CURSOR_PIPE_CSC_ENABLE; | |
10231 | ||
10232 | if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) | |
10233 | cntl |= CURSOR_ROTATE_180; | |
10234 | } | |
10235 | ||
10236 | if (intel_crtc->cursor_cntl != cntl) { | |
10237 | I915_WRITE(CURCNTR(pipe), cntl); | |
10238 | POSTING_READ(CURCNTR(pipe)); | |
10239 | intel_crtc->cursor_cntl = cntl; | |
10240 | } | |
10241 | ||
10242 | /* and commit changes on next vblank */ | |
10243 | I915_WRITE(CURBASE(pipe), base); | |
10244 | POSTING_READ(CURBASE(pipe)); | |
10245 | ||
10246 | intel_crtc->cursor_base = base; | |
10247 | } | |
10248 | ||
10249 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ | |
10250 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, | |
10251 | const struct intel_plane_state *plane_state) | |
10252 | { | |
10253 | struct drm_device *dev = crtc->dev; | |
10254 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10255 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10256 | int pipe = intel_crtc->pipe; | |
10257 | u32 base = intel_crtc->cursor_addr; | |
10258 | u32 pos = 0; | |
10259 | ||
10260 | if (plane_state) { | |
10261 | int x = plane_state->base.crtc_x; | |
10262 | int y = plane_state->base.crtc_y; | |
10263 | ||
10264 | if (x < 0) { | |
10265 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10266 | x = -x; | |
10267 | } | |
10268 | pos |= x << CURSOR_X_SHIFT; | |
10269 | ||
10270 | if (y < 0) { | |
10271 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10272 | y = -y; | |
10273 | } | |
10274 | pos |= y << CURSOR_Y_SHIFT; | |
10275 | ||
10276 | /* ILK+ do this automagically */ | |
10277 | if (HAS_GMCH_DISPLAY(dev) && | |
10278 | plane_state->base.rotation == BIT(DRM_ROTATE_180)) { | |
10279 | base += (plane_state->base.crtc_h * | |
10280 | plane_state->base.crtc_w - 1) * 4; | |
10281 | } | |
10282 | } | |
10283 | ||
10284 | I915_WRITE(CURPOS(pipe), pos); | |
10285 | ||
10286 | if (IS_845G(dev) || IS_I865G(dev)) | |
10287 | i845_update_cursor(crtc, base, plane_state); | |
10288 | else | |
10289 | i9xx_update_cursor(crtc, base, plane_state); | |
10290 | } | |
10291 | ||
10292 | static bool cursor_size_ok(struct drm_device *dev, | |
10293 | uint32_t width, uint32_t height) | |
10294 | { | |
10295 | if (width == 0 || height == 0) | |
10296 | return false; | |
10297 | ||
10298 | /* | |
10299 | * 845g/865g are special in that they are only limited by | |
10300 | * the width of their cursors, the height is arbitrary up to | |
10301 | * the precision of the register. Everything else requires | |
10302 | * square cursors, limited to a few power-of-two sizes. | |
10303 | */ | |
10304 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10305 | if ((width & 63) != 0) | |
10306 | return false; | |
10307 | ||
10308 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10309 | return false; | |
10310 | ||
10311 | if (height > 1023) | |
10312 | return false; | |
10313 | } else { | |
10314 | switch (width | height) { | |
10315 | case 256: | |
10316 | case 128: | |
10317 | if (IS_GEN2(dev)) | |
10318 | return false; | |
10319 | case 64: | |
10320 | break; | |
10321 | default: | |
10322 | return false; | |
10323 | } | |
10324 | } | |
10325 | ||
10326 | return true; | |
10327 | } | |
10328 | ||
10329 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, | |
10330 | u16 *blue, uint32_t start, uint32_t size) | |
10331 | { | |
10332 | int end = (start + size > 256) ? 256 : start + size, i; | |
10333 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10334 | ||
10335 | for (i = start; i < end; i++) { | |
10336 | intel_crtc->lut_r[i] = red[i] >> 8; | |
10337 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10338 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10339 | } | |
10340 | ||
10341 | intel_crtc_load_lut(crtc); | |
10342 | } | |
10343 | ||
10344 | /* VESA 640x480x72Hz mode to set on the pipe */ | |
10345 | static struct drm_display_mode load_detect_mode = { | |
10346 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10347 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10348 | }; | |
10349 | ||
10350 | struct drm_framebuffer * | |
10351 | __intel_framebuffer_create(struct drm_device *dev, | |
10352 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10353 | struct drm_i915_gem_object *obj) | |
10354 | { | |
10355 | struct intel_framebuffer *intel_fb; | |
10356 | int ret; | |
10357 | ||
10358 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
10359 | if (!intel_fb) | |
10360 | return ERR_PTR(-ENOMEM); | |
10361 | ||
10362 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
10363 | if (ret) | |
10364 | goto err; | |
10365 | ||
10366 | return &intel_fb->base; | |
10367 | ||
10368 | err: | |
10369 | kfree(intel_fb); | |
10370 | return ERR_PTR(ret); | |
10371 | } | |
10372 | ||
10373 | static struct drm_framebuffer * | |
10374 | intel_framebuffer_create(struct drm_device *dev, | |
10375 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10376 | struct drm_i915_gem_object *obj) | |
10377 | { | |
10378 | struct drm_framebuffer *fb; | |
10379 | int ret; | |
10380 | ||
10381 | ret = i915_mutex_lock_interruptible(dev); | |
10382 | if (ret) | |
10383 | return ERR_PTR(ret); | |
10384 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10385 | mutex_unlock(&dev->struct_mutex); | |
10386 | ||
10387 | return fb; | |
10388 | } | |
10389 | ||
10390 | static u32 | |
10391 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10392 | { | |
10393 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10394 | return ALIGN(pitch, 64); | |
10395 | } | |
10396 | ||
10397 | static u32 | |
10398 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10399 | { | |
10400 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
10401 | return PAGE_ALIGN(pitch * mode->vdisplay); | |
10402 | } | |
10403 | ||
10404 | static struct drm_framebuffer * | |
10405 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10406 | struct drm_display_mode *mode, | |
10407 | int depth, int bpp) | |
10408 | { | |
10409 | struct drm_framebuffer *fb; | |
10410 | struct drm_i915_gem_object *obj; | |
10411 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
10412 | ||
10413 | obj = i915_gem_alloc_object(dev, | |
10414 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10415 | if (obj == NULL) | |
10416 | return ERR_PTR(-ENOMEM); | |
10417 | ||
10418 | mode_cmd.width = mode->hdisplay; | |
10419 | mode_cmd.height = mode->vdisplay; | |
10420 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, | |
10421 | bpp); | |
10422 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); | |
10423 | ||
10424 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); | |
10425 | if (IS_ERR(fb)) | |
10426 | drm_gem_object_unreference_unlocked(&obj->base); | |
10427 | ||
10428 | return fb; | |
10429 | } | |
10430 | ||
10431 | static struct drm_framebuffer * | |
10432 | mode_fits_in_fbdev(struct drm_device *dev, | |
10433 | struct drm_display_mode *mode) | |
10434 | { | |
10435 | #ifdef CONFIG_DRM_FBDEV_EMULATION | |
10436 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10437 | struct drm_i915_gem_object *obj; | |
10438 | struct drm_framebuffer *fb; | |
10439 | ||
10440 | if (!dev_priv->fbdev) | |
10441 | return NULL; | |
10442 | ||
10443 | if (!dev_priv->fbdev->fb) | |
10444 | return NULL; | |
10445 | ||
10446 | obj = dev_priv->fbdev->fb->obj; | |
10447 | BUG_ON(!obj); | |
10448 | ||
10449 | fb = &dev_priv->fbdev->fb->base; | |
10450 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, | |
10451 | fb->bits_per_pixel)) | |
10452 | return NULL; | |
10453 | ||
10454 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) | |
10455 | return NULL; | |
10456 | ||
10457 | drm_framebuffer_reference(fb); | |
10458 | return fb; | |
10459 | #else | |
10460 | return NULL; | |
10461 | #endif | |
10462 | } | |
10463 | ||
10464 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, | |
10465 | struct drm_crtc *crtc, | |
10466 | struct drm_display_mode *mode, | |
10467 | struct drm_framebuffer *fb, | |
10468 | int x, int y) | |
10469 | { | |
10470 | struct drm_plane_state *plane_state; | |
10471 | int hdisplay, vdisplay; | |
10472 | int ret; | |
10473 | ||
10474 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10475 | if (IS_ERR(plane_state)) | |
10476 | return PTR_ERR(plane_state); | |
10477 | ||
10478 | if (mode) | |
10479 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10480 | else | |
10481 | hdisplay = vdisplay = 0; | |
10482 | ||
10483 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10484 | if (ret) | |
10485 | return ret; | |
10486 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10487 | plane_state->crtc_x = 0; | |
10488 | plane_state->crtc_y = 0; | |
10489 | plane_state->crtc_w = hdisplay; | |
10490 | plane_state->crtc_h = vdisplay; | |
10491 | plane_state->src_x = x << 16; | |
10492 | plane_state->src_y = y << 16; | |
10493 | plane_state->src_w = hdisplay << 16; | |
10494 | plane_state->src_h = vdisplay << 16; | |
10495 | ||
10496 | return 0; | |
10497 | } | |
10498 | ||
10499 | bool intel_get_load_detect_pipe(struct drm_connector *connector, | |
10500 | struct drm_display_mode *mode, | |
10501 | struct intel_load_detect_pipe *old, | |
10502 | struct drm_modeset_acquire_ctx *ctx) | |
10503 | { | |
10504 | struct intel_crtc *intel_crtc; | |
10505 | struct intel_encoder *intel_encoder = | |
10506 | intel_attached_encoder(connector); | |
10507 | struct drm_crtc *possible_crtc; | |
10508 | struct drm_encoder *encoder = &intel_encoder->base; | |
10509 | struct drm_crtc *crtc = NULL; | |
10510 | struct drm_device *dev = encoder->dev; | |
10511 | struct drm_framebuffer *fb; | |
10512 | struct drm_mode_config *config = &dev->mode_config; | |
10513 | struct drm_atomic_state *state = NULL, *restore_state = NULL; | |
10514 | struct drm_connector_state *connector_state; | |
10515 | struct intel_crtc_state *crtc_state; | |
10516 | int ret, i = -1; | |
10517 | ||
10518 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", | |
10519 | connector->base.id, connector->name, | |
10520 | encoder->base.id, encoder->name); | |
10521 | ||
10522 | old->restore_state = NULL; | |
10523 | ||
10524 | retry: | |
10525 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10526 | if (ret) | |
10527 | goto fail; | |
10528 | ||
10529 | /* | |
10530 | * Algorithm gets a little messy: | |
10531 | * | |
10532 | * - if the connector already has an assigned crtc, use it (but make | |
10533 | * sure it's on first) | |
10534 | * | |
10535 | * - try to find the first unused crtc that can drive this connector, | |
10536 | * and use that if we find one | |
10537 | */ | |
10538 | ||
10539 | /* See if we already have a CRTC for this connector */ | |
10540 | if (connector->state->crtc) { | |
10541 | crtc = connector->state->crtc; | |
10542 | ||
10543 | ret = drm_modeset_lock(&crtc->mutex, ctx); | |
10544 | if (ret) | |
10545 | goto fail; | |
10546 | ||
10547 | /* Make sure the crtc and connector are running */ | |
10548 | goto found; | |
10549 | } | |
10550 | ||
10551 | /* Find an unused one (if possible) */ | |
10552 | for_each_crtc(dev, possible_crtc) { | |
10553 | i++; | |
10554 | if (!(encoder->possible_crtcs & (1 << i))) | |
10555 | continue; | |
10556 | ||
10557 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); | |
10558 | if (ret) | |
10559 | goto fail; | |
10560 | ||
10561 | if (possible_crtc->state->enable) { | |
10562 | drm_modeset_unlock(&possible_crtc->mutex); | |
10563 | continue; | |
10564 | } | |
10565 | ||
10566 | crtc = possible_crtc; | |
10567 | break; | |
10568 | } | |
10569 | ||
10570 | /* | |
10571 | * If we didn't find an unused CRTC, don't use any. | |
10572 | */ | |
10573 | if (!crtc) { | |
10574 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); | |
10575 | goto fail; | |
10576 | } | |
10577 | ||
10578 | found: | |
10579 | intel_crtc = to_intel_crtc(crtc); | |
10580 | ||
10581 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
10582 | if (ret) | |
10583 | goto fail; | |
10584 | ||
10585 | state = drm_atomic_state_alloc(dev); | |
10586 | restore_state = drm_atomic_state_alloc(dev); | |
10587 | if (!state || !restore_state) { | |
10588 | ret = -ENOMEM; | |
10589 | goto fail; | |
10590 | } | |
10591 | ||
10592 | state->acquire_ctx = ctx; | |
10593 | restore_state->acquire_ctx = ctx; | |
10594 | ||
10595 | connector_state = drm_atomic_get_connector_state(state, connector); | |
10596 | if (IS_ERR(connector_state)) { | |
10597 | ret = PTR_ERR(connector_state); | |
10598 | goto fail; | |
10599 | } | |
10600 | ||
10601 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); | |
10602 | if (ret) | |
10603 | goto fail; | |
10604 | ||
10605 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
10606 | if (IS_ERR(crtc_state)) { | |
10607 | ret = PTR_ERR(crtc_state); | |
10608 | goto fail; | |
10609 | } | |
10610 | ||
10611 | crtc_state->base.active = crtc_state->base.enable = true; | |
10612 | ||
10613 | if (!mode) | |
10614 | mode = &load_detect_mode; | |
10615 | ||
10616 | /* We need a framebuffer large enough to accommodate all accesses | |
10617 | * that the plane may generate whilst we perform load detection. | |
10618 | * We can not rely on the fbcon either being present (we get called | |
10619 | * during its initialisation to detect all boot displays, or it may | |
10620 | * not even exist) or that it is large enough to satisfy the | |
10621 | * requested mode. | |
10622 | */ | |
10623 | fb = mode_fits_in_fbdev(dev, mode); | |
10624 | if (fb == NULL) { | |
10625 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); | |
10626 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); | |
10627 | } else | |
10628 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
10629 | if (IS_ERR(fb)) { | |
10630 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); | |
10631 | goto fail; | |
10632 | } | |
10633 | ||
10634 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); | |
10635 | if (ret) | |
10636 | goto fail; | |
10637 | ||
10638 | drm_framebuffer_unreference(fb); | |
10639 | ||
10640 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); | |
10641 | if (ret) | |
10642 | goto fail; | |
10643 | ||
10644 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); | |
10645 | if (!ret) | |
10646 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); | |
10647 | if (!ret) | |
10648 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); | |
10649 | if (ret) { | |
10650 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); | |
10651 | goto fail; | |
10652 | } | |
10653 | ||
10654 | ret = drm_atomic_commit(state); | |
10655 | if (ret) { | |
10656 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); | |
10657 | goto fail; | |
10658 | } | |
10659 | ||
10660 | old->restore_state = restore_state; | |
10661 | ||
10662 | /* let the connector get through one full cycle before testing */ | |
10663 | intel_wait_for_vblank(dev, intel_crtc->pipe); | |
10664 | return true; | |
10665 | ||
10666 | fail: | |
10667 | drm_atomic_state_free(state); | |
10668 | drm_atomic_state_free(restore_state); | |
10669 | restore_state = state = NULL; | |
10670 | ||
10671 | if (ret == -EDEADLK) { | |
10672 | drm_modeset_backoff(ctx); | |
10673 | goto retry; | |
10674 | } | |
10675 | ||
10676 | return false; | |
10677 | } | |
10678 | ||
10679 | void intel_release_load_detect_pipe(struct drm_connector *connector, | |
10680 | struct intel_load_detect_pipe *old, | |
10681 | struct drm_modeset_acquire_ctx *ctx) | |
10682 | { | |
10683 | struct intel_encoder *intel_encoder = | |
10684 | intel_attached_encoder(connector); | |
10685 | struct drm_encoder *encoder = &intel_encoder->base; | |
10686 | struct drm_atomic_state *state = old->restore_state; | |
10687 | int ret; | |
10688 | ||
10689 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", | |
10690 | connector->base.id, connector->name, | |
10691 | encoder->base.id, encoder->name); | |
10692 | ||
10693 | if (!state) | |
10694 | return; | |
10695 | ||
10696 | ret = drm_atomic_commit(state); | |
10697 | if (ret) { | |
10698 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); | |
10699 | drm_atomic_state_free(state); | |
10700 | } | |
10701 | } | |
10702 | ||
10703 | static int i9xx_pll_refclk(struct drm_device *dev, | |
10704 | const struct intel_crtc_state *pipe_config) | |
10705 | { | |
10706 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10707 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10708 | ||
10709 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
10710 | return dev_priv->vbt.lvds_ssc_freq; | |
10711 | else if (HAS_PCH_SPLIT(dev)) | |
10712 | return 120000; | |
10713 | else if (!IS_GEN2(dev)) | |
10714 | return 96000; | |
10715 | else | |
10716 | return 48000; | |
10717 | } | |
10718 | ||
10719 | /* Returns the clock of the currently programmed mode of the given pipe. */ | |
10720 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, | |
10721 | struct intel_crtc_state *pipe_config) | |
10722 | { | |
10723 | struct drm_device *dev = crtc->base.dev; | |
10724 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10725 | int pipe = pipe_config->cpu_transcoder; | |
10726 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10727 | u32 fp; | |
10728 | intel_clock_t clock; | |
10729 | int port_clock; | |
10730 | int refclk = i9xx_pll_refclk(dev, pipe_config); | |
10731 | ||
10732 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
10733 | fp = pipe_config->dpll_hw_state.fp0; | |
10734 | else | |
10735 | fp = pipe_config->dpll_hw_state.fp1; | |
10736 | ||
10737 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
10738 | if (IS_PINEVIEW(dev)) { | |
10739 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10740 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10741 | } else { | |
10742 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10743 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10744 | } | |
10745 | ||
10746 | if (!IS_GEN2(dev)) { | |
10747 | if (IS_PINEVIEW(dev)) | |
10748 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10749 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
10750 | else | |
10751 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
10752 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
10753 | ||
10754 | switch (dpll & DPLL_MODE_MASK) { | |
10755 | case DPLLB_MODE_DAC_SERIAL: | |
10756 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10757 | 5 : 10; | |
10758 | break; | |
10759 | case DPLLB_MODE_LVDS: | |
10760 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10761 | 7 : 14; | |
10762 | break; | |
10763 | default: | |
10764 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " | |
10765 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); | |
10766 | return; | |
10767 | } | |
10768 | ||
10769 | if (IS_PINEVIEW(dev)) | |
10770 | port_clock = pnv_calc_dpll_params(refclk, &clock); | |
10771 | else | |
10772 | port_clock = i9xx_calc_dpll_params(refclk, &clock); | |
10773 | } else { | |
10774 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); | |
10775 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); | |
10776 | ||
10777 | if (is_lvds) { | |
10778 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10779 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
10780 | ||
10781 | if (lvds & LVDS_CLKB_POWER_UP) | |
10782 | clock.p2 = 7; | |
10783 | else | |
10784 | clock.p2 = 14; | |
10785 | } else { | |
10786 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10787 | clock.p1 = 2; | |
10788 | else { | |
10789 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10790 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10791 | } | |
10792 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10793 | clock.p2 = 4; | |
10794 | else | |
10795 | clock.p2 = 2; | |
10796 | } | |
10797 | ||
10798 | port_clock = i9xx_calc_dpll_params(refclk, &clock); | |
10799 | } | |
10800 | ||
10801 | /* | |
10802 | * This value includes pixel_multiplier. We will use | |
10803 | * port_clock to compute adjusted_mode.crtc_clock in the | |
10804 | * encoder's get_config() function. | |
10805 | */ | |
10806 | pipe_config->port_clock = port_clock; | |
10807 | } | |
10808 | ||
10809 | int intel_dotclock_calculate(int link_freq, | |
10810 | const struct intel_link_m_n *m_n) | |
10811 | { | |
10812 | /* | |
10813 | * The calculation for the data clock is: | |
10814 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp | |
10815 | * But we want to avoid losing precison if possible, so: | |
10816 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) | |
10817 | * | |
10818 | * and the link clock is simpler: | |
10819 | * link_clock = (m * link_clock) / n | |
10820 | */ | |
10821 | ||
10822 | if (!m_n->link_n) | |
10823 | return 0; | |
10824 | ||
10825 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); | |
10826 | } | |
10827 | ||
10828 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, | |
10829 | struct intel_crtc_state *pipe_config) | |
10830 | { | |
10831 | struct drm_device *dev = crtc->base.dev; | |
10832 | ||
10833 | /* read out port_clock from the DPLL */ | |
10834 | i9xx_crtc_clock_get(crtc, pipe_config); | |
10835 | ||
10836 | /* | |
10837 | * This value does not include pixel_multiplier. | |
10838 | * We will check that port_clock and adjusted_mode.crtc_clock | |
10839 | * agree once we know their relationship in the encoder's | |
10840 | * get_config() function. | |
10841 | */ | |
10842 | pipe_config->base.adjusted_mode.crtc_clock = | |
10843 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, | |
10844 | &pipe_config->fdi_m_n); | |
10845 | } | |
10846 | ||
10847 | /** Returns the currently programmed mode of the given pipe. */ | |
10848 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10849 | struct drm_crtc *crtc) | |
10850 | { | |
10851 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10852 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10853 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; | |
10854 | struct drm_display_mode *mode; | |
10855 | struct intel_crtc_state *pipe_config; | |
10856 | int htot = I915_READ(HTOTAL(cpu_transcoder)); | |
10857 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10858 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10859 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
10860 | enum pipe pipe = intel_crtc->pipe; | |
10861 | ||
10862 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10863 | if (!mode) | |
10864 | return NULL; | |
10865 | ||
10866 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); | |
10867 | if (!pipe_config) { | |
10868 | kfree(mode); | |
10869 | return NULL; | |
10870 | } | |
10871 | ||
10872 | /* | |
10873 | * Construct a pipe_config sufficient for getting the clock info | |
10874 | * back out of crtc_clock_get. | |
10875 | * | |
10876 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10877 | * to use a real value here instead. | |
10878 | */ | |
10879 | pipe_config->cpu_transcoder = (enum transcoder) pipe; | |
10880 | pipe_config->pixel_multiplier = 1; | |
10881 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); | |
10882 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10883 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
10884 | i9xx_crtc_clock_get(intel_crtc, pipe_config); | |
10885 | ||
10886 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; | |
10887 | mode->hdisplay = (htot & 0xffff) + 1; | |
10888 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10889 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10890 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10891 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10892 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10893 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10894 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10895 | ||
10896 | drm_mode_set_name(mode); | |
10897 | ||
10898 | kfree(pipe_config); | |
10899 | ||
10900 | return mode; | |
10901 | } | |
10902 | ||
10903 | void intel_mark_busy(struct drm_device *dev) | |
10904 | { | |
10905 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10906 | ||
10907 | if (dev_priv->mm.busy) | |
10908 | return; | |
10909 | ||
10910 | intel_runtime_pm_get(dev_priv); | |
10911 | i915_update_gfx_val(dev_priv); | |
10912 | if (INTEL_INFO(dev)->gen >= 6) | |
10913 | gen6_rps_busy(dev_priv); | |
10914 | dev_priv->mm.busy = true; | |
10915 | } | |
10916 | ||
10917 | void intel_mark_idle(struct drm_device *dev) | |
10918 | { | |
10919 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10920 | ||
10921 | if (!dev_priv->mm.busy) | |
10922 | return; | |
10923 | ||
10924 | dev_priv->mm.busy = false; | |
10925 | ||
10926 | if (INTEL_INFO(dev)->gen >= 6) | |
10927 | gen6_rps_idle(dev->dev_private); | |
10928 | ||
10929 | intel_runtime_pm_put(dev_priv); | |
10930 | } | |
10931 | ||
10932 | static void intel_crtc_destroy(struct drm_crtc *crtc) | |
10933 | { | |
10934 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10935 | struct drm_device *dev = crtc->dev; | |
10936 | struct intel_unpin_work *work; | |
10937 | ||
10938 | spin_lock_irq(&dev->event_lock); | |
10939 | work = intel_crtc->unpin_work; | |
10940 | intel_crtc->unpin_work = NULL; | |
10941 | spin_unlock_irq(&dev->event_lock); | |
10942 | ||
10943 | if (work) { | |
10944 | cancel_work_sync(&work->work); | |
10945 | kfree(work); | |
10946 | } | |
10947 | ||
10948 | drm_crtc_cleanup(crtc); | |
10949 | ||
10950 | kfree(intel_crtc); | |
10951 | } | |
10952 | ||
10953 | static void intel_unpin_work_fn(struct work_struct *__work) | |
10954 | { | |
10955 | struct intel_unpin_work *work = | |
10956 | container_of(__work, struct intel_unpin_work, work); | |
10957 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); | |
10958 | struct drm_device *dev = crtc->base.dev; | |
10959 | struct drm_plane *primary = crtc->base.primary; | |
10960 | ||
10961 | mutex_lock(&dev->struct_mutex); | |
10962 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); | |
10963 | drm_gem_object_unreference(&work->pending_flip_obj->base); | |
10964 | ||
10965 | if (work->flip_queued_req) | |
10966 | i915_gem_request_assign(&work->flip_queued_req, NULL); | |
10967 | mutex_unlock(&dev->struct_mutex); | |
10968 | ||
10969 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); | |
10970 | intel_fbc_post_update(crtc); | |
10971 | drm_framebuffer_unreference(work->old_fb); | |
10972 | ||
10973 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); | |
10974 | atomic_dec(&crtc->unpin_work_count); | |
10975 | ||
10976 | kfree(work); | |
10977 | } | |
10978 | ||
10979 | static void do_intel_finish_page_flip(struct drm_device *dev, | |
10980 | struct drm_crtc *crtc) | |
10981 | { | |
10982 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10983 | struct intel_unpin_work *work; | |
10984 | unsigned long flags; | |
10985 | ||
10986 | /* Ignore early vblank irqs */ | |
10987 | if (intel_crtc == NULL) | |
10988 | return; | |
10989 | ||
10990 | /* | |
10991 | * This is called both by irq handlers and the reset code (to complete | |
10992 | * lost pageflips) so needs the full irqsave spinlocks. | |
10993 | */ | |
10994 | spin_lock_irqsave(&dev->event_lock, flags); | |
10995 | work = intel_crtc->unpin_work; | |
10996 | ||
10997 | /* Ensure we don't miss a work->pending update ... */ | |
10998 | smp_rmb(); | |
10999 | ||
11000 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
11001 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
11002 | return; | |
11003 | } | |
11004 | ||
11005 | page_flip_completed(intel_crtc); | |
11006 | ||
11007 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
11008 | } | |
11009 | ||
11010 | void intel_finish_page_flip(struct drm_device *dev, int pipe) | |
11011 | { | |
11012 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11013 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11014 | ||
11015 | do_intel_finish_page_flip(dev, crtc); | |
11016 | } | |
11017 | ||
11018 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
11019 | { | |
11020 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11021 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; | |
11022 | ||
11023 | do_intel_finish_page_flip(dev, crtc); | |
11024 | } | |
11025 | ||
11026 | /* Is 'a' after or equal to 'b'? */ | |
11027 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
11028 | { | |
11029 | return !((a - b) & 0x80000000); | |
11030 | } | |
11031 | ||
11032 | static bool page_flip_finished(struct intel_crtc *crtc) | |
11033 | { | |
11034 | struct drm_device *dev = crtc->base.dev; | |
11035 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11036 | ||
11037 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
11038 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
11039 | return true; | |
11040 | ||
11041 | /* | |
11042 | * The relevant registers doen't exist on pre-ctg. | |
11043 | * As the flip done interrupt doesn't trigger for mmio | |
11044 | * flips on gmch platforms, a flip count check isn't | |
11045 | * really needed there. But since ctg has the registers, | |
11046 | * include it in the check anyway. | |
11047 | */ | |
11048 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
11049 | return true; | |
11050 | ||
11051 | /* | |
11052 | * BDW signals flip done immediately if the plane | |
11053 | * is disabled, even if the plane enable is already | |
11054 | * armed to occur at the next vblank :( | |
11055 | */ | |
11056 | ||
11057 | /* | |
11058 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
11059 | * used the same base address. In that case the mmio flip might | |
11060 | * have completed, but the CS hasn't even executed the flip yet. | |
11061 | * | |
11062 | * A flip count check isn't enough as the CS might have updated | |
11063 | * the base address just after start of vblank, but before we | |
11064 | * managed to process the interrupt. This means we'd complete the | |
11065 | * CS flip too soon. | |
11066 | * | |
11067 | * Combining both checks should get us a good enough result. It may | |
11068 | * still happen that the CS flip has been executed, but has not | |
11069 | * yet actually completed. But in case the base address is the same | |
11070 | * anyway, we don't really care. | |
11071 | */ | |
11072 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
11073 | crtc->unpin_work->gtt_offset && | |
11074 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), | |
11075 | crtc->unpin_work->flip_count); | |
11076 | } | |
11077 | ||
11078 | void intel_prepare_page_flip(struct drm_device *dev, int plane) | |
11079 | { | |
11080 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11081 | struct intel_crtc *intel_crtc = | |
11082 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
11083 | unsigned long flags; | |
11084 | ||
11085 | ||
11086 | /* | |
11087 | * This is called both by irq handlers and the reset code (to complete | |
11088 | * lost pageflips) so needs the full irqsave spinlocks. | |
11089 | * | |
11090 | * NB: An MMIO update of the plane base pointer will also | |
11091 | * generate a page-flip completion irq, i.e. every modeset | |
11092 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
11093 | */ | |
11094 | spin_lock_irqsave(&dev->event_lock, flags); | |
11095 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) | |
11096 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); | |
11097 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
11098 | } | |
11099 | ||
11100 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) | |
11101 | { | |
11102 | /* Ensure that the work item is consistent when activating it ... */ | |
11103 | smp_wmb(); | |
11104 | atomic_set(&work->pending, INTEL_FLIP_PENDING); | |
11105 | /* and that it is marked active as soon as the irq could fire. */ | |
11106 | smp_wmb(); | |
11107 | } | |
11108 | ||
11109 | static int intel_gen2_queue_flip(struct drm_device *dev, | |
11110 | struct drm_crtc *crtc, | |
11111 | struct drm_framebuffer *fb, | |
11112 | struct drm_i915_gem_object *obj, | |
11113 | struct drm_i915_gem_request *req, | |
11114 | uint32_t flags) | |
11115 | { | |
11116 | struct intel_engine_cs *ring = req->ring; | |
11117 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11118 | u32 flip_mask; | |
11119 | int ret; | |
11120 | ||
11121 | ret = intel_ring_begin(req, 6); | |
11122 | if (ret) | |
11123 | return ret; | |
11124 | ||
11125 | /* Can't queue multiple flips, so wait for the previous | |
11126 | * one to finish before executing the next. | |
11127 | */ | |
11128 | if (intel_crtc->plane) | |
11129 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11130 | else | |
11131 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
11132 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); | |
11133 | intel_ring_emit(ring, MI_NOOP); | |
11134 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
11135 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11136 | intel_ring_emit(ring, fb->pitches[0]); | |
11137 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); | |
11138 | intel_ring_emit(ring, 0); /* aux display base address, unused */ | |
11139 | ||
11140 | intel_mark_page_flip_active(intel_crtc->unpin_work); | |
11141 | return 0; | |
11142 | } | |
11143 | ||
11144 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
11145 | struct drm_crtc *crtc, | |
11146 | struct drm_framebuffer *fb, | |
11147 | struct drm_i915_gem_object *obj, | |
11148 | struct drm_i915_gem_request *req, | |
11149 | uint32_t flags) | |
11150 | { | |
11151 | struct intel_engine_cs *ring = req->ring; | |
11152 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11153 | u32 flip_mask; | |
11154 | int ret; | |
11155 | ||
11156 | ret = intel_ring_begin(req, 6); | |
11157 | if (ret) | |
11158 | return ret; | |
11159 | ||
11160 | if (intel_crtc->plane) | |
11161 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11162 | else | |
11163 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
11164 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); | |
11165 | intel_ring_emit(ring, MI_NOOP); | |
11166 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
11167 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11168 | intel_ring_emit(ring, fb->pitches[0]); | |
11169 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); | |
11170 | intel_ring_emit(ring, MI_NOOP); | |
11171 | ||
11172 | intel_mark_page_flip_active(intel_crtc->unpin_work); | |
11173 | return 0; | |
11174 | } | |
11175 | ||
11176 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
11177 | struct drm_crtc *crtc, | |
11178 | struct drm_framebuffer *fb, | |
11179 | struct drm_i915_gem_object *obj, | |
11180 | struct drm_i915_gem_request *req, | |
11181 | uint32_t flags) | |
11182 | { | |
11183 | struct intel_engine_cs *ring = req->ring; | |
11184 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11185 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11186 | uint32_t pf, pipesrc; | |
11187 | int ret; | |
11188 | ||
11189 | ret = intel_ring_begin(req, 4); | |
11190 | if (ret) | |
11191 | return ret; | |
11192 | ||
11193 | /* i965+ uses the linear or tiled offsets from the | |
11194 | * Display Registers (which do not change across a page-flip) | |
11195 | * so we need only reprogram the base address. | |
11196 | */ | |
11197 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
11198 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11199 | intel_ring_emit(ring, fb->pitches[0]); | |
11200 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | | |
11201 | obj->tiling_mode); | |
11202 | ||
11203 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11204 | * untested on non-native modes, so ignore it for now. | |
11205 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11206 | */ | |
11207 | pf = 0; | |
11208 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
11209 | intel_ring_emit(ring, pf | pipesrc); | |
11210 | ||
11211 | intel_mark_page_flip_active(intel_crtc->unpin_work); | |
11212 | return 0; | |
11213 | } | |
11214 | ||
11215 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
11216 | struct drm_crtc *crtc, | |
11217 | struct drm_framebuffer *fb, | |
11218 | struct drm_i915_gem_object *obj, | |
11219 | struct drm_i915_gem_request *req, | |
11220 | uint32_t flags) | |
11221 | { | |
11222 | struct intel_engine_cs *ring = req->ring; | |
11223 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11224 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11225 | uint32_t pf, pipesrc; | |
11226 | int ret; | |
11227 | ||
11228 | ret = intel_ring_begin(req, 4); | |
11229 | if (ret) | |
11230 | return ret; | |
11231 | ||
11232 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
11233 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11234 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
11235 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); | |
11236 | ||
11237 | /* Contrary to the suggestions in the documentation, | |
11238 | * "Enable Panel Fitter" does not seem to be required when page | |
11239 | * flipping with a non-native mode, and worse causes a normal | |
11240 | * modeset to fail. | |
11241 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11242 | */ | |
11243 | pf = 0; | |
11244 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
11245 | intel_ring_emit(ring, pf | pipesrc); | |
11246 | ||
11247 | intel_mark_page_flip_active(intel_crtc->unpin_work); | |
11248 | return 0; | |
11249 | } | |
11250 | ||
11251 | static int intel_gen7_queue_flip(struct drm_device *dev, | |
11252 | struct drm_crtc *crtc, | |
11253 | struct drm_framebuffer *fb, | |
11254 | struct drm_i915_gem_object *obj, | |
11255 | struct drm_i915_gem_request *req, | |
11256 | uint32_t flags) | |
11257 | { | |
11258 | struct intel_engine_cs *ring = req->ring; | |
11259 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11260 | uint32_t plane_bit = 0; | |
11261 | int len, ret; | |
11262 | ||
11263 | switch (intel_crtc->plane) { | |
11264 | case PLANE_A: | |
11265 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11266 | break; | |
11267 | case PLANE_B: | |
11268 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11269 | break; | |
11270 | case PLANE_C: | |
11271 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11272 | break; | |
11273 | default: | |
11274 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
11275 | return -ENODEV; | |
11276 | } | |
11277 | ||
11278 | len = 4; | |
11279 | if (ring->id == RCS) { | |
11280 | len += 6; | |
11281 | /* | |
11282 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11283 | * 48bits addresses, and we need a NOOP for the batch size to | |
11284 | * stay even. | |
11285 | */ | |
11286 | if (IS_GEN8(dev)) | |
11287 | len += 2; | |
11288 | } | |
11289 | ||
11290 | /* | |
11291 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11292 | * "The full packet must be contained within the same cache line." | |
11293 | * | |
11294 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11295 | * cacheline, if we ever start emitting more commands before | |
11296 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11297 | * then do the cacheline alignment, and finally emit the | |
11298 | * MI_DISPLAY_FLIP. | |
11299 | */ | |
11300 | ret = intel_ring_cacheline_align(req); | |
11301 | if (ret) | |
11302 | return ret; | |
11303 | ||
11304 | ret = intel_ring_begin(req, len); | |
11305 | if (ret) | |
11306 | return ret; | |
11307 | ||
11308 | /* Unmask the flip-done completion message. Note that the bspec says that | |
11309 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11310 | * more than one flip event at any time (or ensure that one flip message | |
11311 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11312 | * Experimentation says that BCS works despite DERRMR masking all | |
11313 | * flip-done completion events and that unmasking all planes at once | |
11314 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11315 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11316 | */ | |
11317 | if (ring->id == RCS) { | |
11318 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11319 | intel_ring_emit_reg(ring, DERRMR); | |
11320 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11321 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11322 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
11323 | if (IS_GEN8(dev)) | |
11324 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | | |
11325 | MI_SRM_LRM_GLOBAL_GTT); | |
11326 | else | |
11327 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | | |
11328 | MI_SRM_LRM_GLOBAL_GTT); | |
11329 | intel_ring_emit_reg(ring, DERRMR); | |
11330 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
11331 | if (IS_GEN8(dev)) { | |
11332 | intel_ring_emit(ring, 0); | |
11333 | intel_ring_emit(ring, MI_NOOP); | |
11334 | } | |
11335 | } | |
11336 | ||
11337 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); | |
11338 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); | |
11339 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); | |
11340 | intel_ring_emit(ring, (MI_NOOP)); | |
11341 | ||
11342 | intel_mark_page_flip_active(intel_crtc->unpin_work); | |
11343 | return 0; | |
11344 | } | |
11345 | ||
11346 | static bool use_mmio_flip(struct intel_engine_cs *ring, | |
11347 | struct drm_i915_gem_object *obj) | |
11348 | { | |
11349 | /* | |
11350 | * This is not being used for older platforms, because | |
11351 | * non-availability of flip done interrupt forces us to use | |
11352 | * CS flips. Older platforms derive flip done using some clever | |
11353 | * tricks involving the flip_pending status bits and vblank irqs. | |
11354 | * So using MMIO flips there would disrupt this mechanism. | |
11355 | */ | |
11356 | ||
11357 | if (ring == NULL) | |
11358 | return true; | |
11359 | ||
11360 | if (INTEL_INFO(ring->dev)->gen < 5) | |
11361 | return false; | |
11362 | ||
11363 | if (i915.use_mmio_flip < 0) | |
11364 | return false; | |
11365 | else if (i915.use_mmio_flip > 0) | |
11366 | return true; | |
11367 | else if (i915.enable_execlists) | |
11368 | return true; | |
11369 | else if (obj->base.dma_buf && | |
11370 | !reservation_object_test_signaled_rcu(obj->base.dma_buf->resv, | |
11371 | false)) | |
11372 | return true; | |
11373 | else | |
11374 | return ring != i915_gem_request_get_ring(obj->last_write_req); | |
11375 | } | |
11376 | ||
11377 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, | |
11378 | unsigned int rotation, | |
11379 | struct intel_unpin_work *work) | |
11380 | { | |
11381 | struct drm_device *dev = intel_crtc->base.dev; | |
11382 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11383 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
11384 | const enum pipe pipe = intel_crtc->pipe; | |
11385 | u32 ctl, stride, tile_height; | |
11386 | ||
11387 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11388 | ctl &= ~PLANE_CTL_TILED_MASK; | |
11389 | switch (fb->modifier[0]) { | |
11390 | case DRM_FORMAT_MOD_NONE: | |
11391 | break; | |
11392 | case I915_FORMAT_MOD_X_TILED: | |
11393 | ctl |= PLANE_CTL_TILED_X; | |
11394 | break; | |
11395 | case I915_FORMAT_MOD_Y_TILED: | |
11396 | ctl |= PLANE_CTL_TILED_Y; | |
11397 | break; | |
11398 | case I915_FORMAT_MOD_Yf_TILED: | |
11399 | ctl |= PLANE_CTL_TILED_YF; | |
11400 | break; | |
11401 | default: | |
11402 | MISSING_CASE(fb->modifier[0]); | |
11403 | } | |
11404 | ||
11405 | /* | |
11406 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11407 | * linear buffers or in number of tiles for tiled buffers. | |
11408 | */ | |
11409 | if (intel_rotation_90_or_270(rotation)) { | |
11410 | /* stride = Surface height in tiles */ | |
11411 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0); | |
11412 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11413 | } else { | |
11414 | stride = fb->pitches[0] / | |
11415 | intel_fb_stride_alignment(dev_priv, fb->modifier[0], | |
11416 | fb->pixel_format); | |
11417 | } | |
11418 | ||
11419 | /* | |
11420 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11421 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11422 | */ | |
11423 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11424 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11425 | ||
11426 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); | |
11427 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
11428 | } | |
11429 | ||
11430 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, | |
11431 | struct intel_unpin_work *work) | |
11432 | { | |
11433 | struct drm_device *dev = intel_crtc->base.dev; | |
11434 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11435 | struct intel_framebuffer *intel_fb = | |
11436 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11437 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11438 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); | |
11439 | u32 dspcntr; | |
11440 | ||
11441 | dspcntr = I915_READ(reg); | |
11442 | ||
11443 | if (obj->tiling_mode != I915_TILING_NONE) | |
11444 | dspcntr |= DISPPLANE_TILED; | |
11445 | else | |
11446 | dspcntr &= ~DISPPLANE_TILED; | |
11447 | ||
11448 | I915_WRITE(reg, dspcntr); | |
11449 | ||
11450 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); | |
11451 | POSTING_READ(DSPSURF(intel_crtc->plane)); | |
11452 | } | |
11453 | ||
11454 | /* | |
11455 | * XXX: This is the temporary way to update the plane registers until we get | |
11456 | * around to using the usual plane update functions for MMIO flips | |
11457 | */ | |
11458 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) | |
11459 | { | |
11460 | struct intel_crtc *crtc = mmio_flip->crtc; | |
11461 | struct intel_unpin_work *work; | |
11462 | ||
11463 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11464 | work = crtc->unpin_work; | |
11465 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11466 | if (work == NULL) | |
11467 | return; | |
11468 | ||
11469 | intel_mark_page_flip_active(work); | |
11470 | ||
11471 | intel_pipe_update_start(crtc); | |
11472 | ||
11473 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) | |
11474 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); | |
11475 | else | |
11476 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
11477 | ilk_do_mmio_flip(crtc, work); | |
11478 | ||
11479 | intel_pipe_update_end(crtc); | |
11480 | } | |
11481 | ||
11482 | static void intel_mmio_flip_work_func(struct work_struct *work) | |
11483 | { | |
11484 | struct intel_mmio_flip *mmio_flip = | |
11485 | container_of(work, struct intel_mmio_flip, work); | |
11486 | struct intel_framebuffer *intel_fb = | |
11487 | to_intel_framebuffer(mmio_flip->crtc->base.primary->fb); | |
11488 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11489 | ||
11490 | if (mmio_flip->req) { | |
11491 | WARN_ON(__i915_wait_request(mmio_flip->req, | |
11492 | mmio_flip->crtc->reset_counter, | |
11493 | false, NULL, | |
11494 | &mmio_flip->i915->rps.mmioflips)); | |
11495 | i915_gem_request_unreference__unlocked(mmio_flip->req); | |
11496 | } | |
11497 | ||
11498 | /* For framebuffer backed by dmabuf, wait for fence */ | |
11499 | if (obj->base.dma_buf) | |
11500 | WARN_ON(reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, | |
11501 | false, false, | |
11502 | MAX_SCHEDULE_TIMEOUT) < 0); | |
11503 | ||
11504 | intel_do_mmio_flip(mmio_flip); | |
11505 | kfree(mmio_flip); | |
11506 | } | |
11507 | ||
11508 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11509 | struct drm_crtc *crtc, | |
11510 | struct drm_i915_gem_object *obj) | |
11511 | { | |
11512 | struct intel_mmio_flip *mmio_flip; | |
11513 | ||
11514 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11515 | if (mmio_flip == NULL) | |
11516 | return -ENOMEM; | |
11517 | ||
11518 | mmio_flip->i915 = to_i915(dev); | |
11519 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); | |
11520 | mmio_flip->crtc = to_intel_crtc(crtc); | |
11521 | mmio_flip->rotation = crtc->primary->state->rotation; | |
11522 | ||
11523 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); | |
11524 | schedule_work(&mmio_flip->work); | |
11525 | ||
11526 | return 0; | |
11527 | } | |
11528 | ||
11529 | static int intel_default_queue_flip(struct drm_device *dev, | |
11530 | struct drm_crtc *crtc, | |
11531 | struct drm_framebuffer *fb, | |
11532 | struct drm_i915_gem_object *obj, | |
11533 | struct drm_i915_gem_request *req, | |
11534 | uint32_t flags) | |
11535 | { | |
11536 | return -ENODEV; | |
11537 | } | |
11538 | ||
11539 | static bool __intel_pageflip_stall_check(struct drm_device *dev, | |
11540 | struct drm_crtc *crtc) | |
11541 | { | |
11542 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11543 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11544 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11545 | u32 addr; | |
11546 | ||
11547 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11548 | return true; | |
11549 | ||
11550 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) | |
11551 | return false; | |
11552 | ||
11553 | if (!work->enable_stall_check) | |
11554 | return false; | |
11555 | ||
11556 | if (work->flip_ready_vblank == 0) { | |
11557 | if (work->flip_queued_req && | |
11558 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
11559 | return false; | |
11560 | ||
11561 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); | |
11562 | } | |
11563 | ||
11564 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) | |
11565 | return false; | |
11566 | ||
11567 | /* Potential stall - if we see that the flip has happened, | |
11568 | * assume a missed interrupt. */ | |
11569 | if (INTEL_INFO(dev)->gen >= 4) | |
11570 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11571 | else | |
11572 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11573 | ||
11574 | /* There is a potential issue here with a false positive after a flip | |
11575 | * to the same address. We could address this by checking for a | |
11576 | * non-incrementing frame counter. | |
11577 | */ | |
11578 | return addr == work->gtt_offset; | |
11579 | } | |
11580 | ||
11581 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11582 | { | |
11583 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11584 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11585 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11586 | struct intel_unpin_work *work; | |
11587 | ||
11588 | WARN_ON(!in_interrupt()); | |
11589 | ||
11590 | if (crtc == NULL) | |
11591 | return; | |
11592 | ||
11593 | spin_lock(&dev->event_lock); | |
11594 | work = intel_crtc->unpin_work; | |
11595 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
11596 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", | |
11597 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); | |
11598 | page_flip_completed(intel_crtc); | |
11599 | work = NULL; | |
11600 | } | |
11601 | if (work != NULL && | |
11602 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11603 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
11604 | spin_unlock(&dev->event_lock); | |
11605 | } | |
11606 | ||
11607 | static int intel_crtc_page_flip(struct drm_crtc *crtc, | |
11608 | struct drm_framebuffer *fb, | |
11609 | struct drm_pending_vblank_event *event, | |
11610 | uint32_t page_flip_flags) | |
11611 | { | |
11612 | struct drm_device *dev = crtc->dev; | |
11613 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11614 | struct drm_framebuffer *old_fb = crtc->primary->fb; | |
11615 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
11616 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11617 | struct drm_plane *primary = crtc->primary; | |
11618 | enum pipe pipe = intel_crtc->pipe; | |
11619 | struct intel_unpin_work *work; | |
11620 | struct intel_engine_cs *ring; | |
11621 | bool mmio_flip; | |
11622 | struct drm_i915_gem_request *request = NULL; | |
11623 | int ret; | |
11624 | ||
11625 | /* | |
11626 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11627 | * check to be safe. In the future we may enable pageflipping from | |
11628 | * a disabled primary plane. | |
11629 | */ | |
11630 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11631 | return -EBUSY; | |
11632 | ||
11633 | /* Can't change pixel format via MI display flips. */ | |
11634 | if (fb->pixel_format != crtc->primary->fb->pixel_format) | |
11635 | return -EINVAL; | |
11636 | ||
11637 | /* | |
11638 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11639 | * Note that pitch changes could also affect these register. | |
11640 | */ | |
11641 | if (INTEL_INFO(dev)->gen > 3 && | |
11642 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || | |
11643 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
11644 | return -EINVAL; | |
11645 | ||
11646 | if (i915_terminally_wedged(&dev_priv->gpu_error)) | |
11647 | goto out_hang; | |
11648 | ||
11649 | work = kzalloc(sizeof(*work), GFP_KERNEL); | |
11650 | if (work == NULL) | |
11651 | return -ENOMEM; | |
11652 | ||
11653 | work->event = event; | |
11654 | work->crtc = crtc; | |
11655 | work->old_fb = old_fb; | |
11656 | INIT_WORK(&work->work, intel_unpin_work_fn); | |
11657 | ||
11658 | ret = drm_crtc_vblank_get(crtc); | |
11659 | if (ret) | |
11660 | goto free_work; | |
11661 | ||
11662 | /* We borrow the event spin lock for protecting unpin_work */ | |
11663 | spin_lock_irq(&dev->event_lock); | |
11664 | if (intel_crtc->unpin_work) { | |
11665 | /* Before declaring the flip queue wedged, check if | |
11666 | * the hardware completed the operation behind our backs. | |
11667 | */ | |
11668 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11669 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11670 | page_flip_completed(intel_crtc); | |
11671 | } else { | |
11672 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
11673 | spin_unlock_irq(&dev->event_lock); | |
11674 | ||
11675 | drm_crtc_vblank_put(crtc); | |
11676 | kfree(work); | |
11677 | return -EBUSY; | |
11678 | } | |
11679 | } | |
11680 | intel_crtc->unpin_work = work; | |
11681 | spin_unlock_irq(&dev->event_lock); | |
11682 | ||
11683 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) | |
11684 | flush_workqueue(dev_priv->wq); | |
11685 | ||
11686 | /* Reference the objects for the scheduled work. */ | |
11687 | drm_framebuffer_reference(work->old_fb); | |
11688 | drm_gem_object_reference(&obj->base); | |
11689 | ||
11690 | crtc->primary->fb = fb; | |
11691 | update_state_fb(crtc->primary); | |
11692 | intel_fbc_pre_update(intel_crtc); | |
11693 | ||
11694 | work->pending_flip_obj = obj; | |
11695 | ||
11696 | ret = i915_mutex_lock_interruptible(dev); | |
11697 | if (ret) | |
11698 | goto cleanup; | |
11699 | ||
11700 | atomic_inc(&intel_crtc->unpin_work_count); | |
11701 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
11702 | ||
11703 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
11704 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; | |
11705 | ||
11706 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
11707 | ring = &dev_priv->ring[BCS]; | |
11708 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) | |
11709 | /* vlv: DISPLAY_FLIP fails to change tiling */ | |
11710 | ring = NULL; | |
11711 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { | |
11712 | ring = &dev_priv->ring[BCS]; | |
11713 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
11714 | ring = i915_gem_request_get_ring(obj->last_write_req); | |
11715 | if (ring == NULL || ring->id != RCS) | |
11716 | ring = &dev_priv->ring[BCS]; | |
11717 | } else { | |
11718 | ring = &dev_priv->ring[RCS]; | |
11719 | } | |
11720 | ||
11721 | mmio_flip = use_mmio_flip(ring, obj); | |
11722 | ||
11723 | /* When using CS flips, we want to emit semaphores between rings. | |
11724 | * However, when using mmio flips we will create a task to do the | |
11725 | * synchronisation, so all we want here is to pin the framebuffer | |
11726 | * into the display plane and skip any waits. | |
11727 | */ | |
11728 | if (!mmio_flip) { | |
11729 | ret = i915_gem_object_sync(obj, ring, &request); | |
11730 | if (ret) | |
11731 | goto cleanup_pending; | |
11732 | } | |
11733 | ||
11734 | ret = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); | |
11735 | if (ret) | |
11736 | goto cleanup_pending; | |
11737 | ||
11738 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), | |
11739 | obj, 0); | |
11740 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
11741 | ||
11742 | if (mmio_flip) { | |
11743 | ret = intel_queue_mmio_flip(dev, crtc, obj); | |
11744 | if (ret) | |
11745 | goto cleanup_unpin; | |
11746 | ||
11747 | i915_gem_request_assign(&work->flip_queued_req, | |
11748 | obj->last_write_req); | |
11749 | } else { | |
11750 | if (!request) { | |
11751 | request = i915_gem_request_alloc(ring, NULL); | |
11752 | if (IS_ERR(request)) { | |
11753 | ret = PTR_ERR(request); | |
11754 | goto cleanup_unpin; | |
11755 | } | |
11756 | } | |
11757 | ||
11758 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
11759 | page_flip_flags); | |
11760 | if (ret) | |
11761 | goto cleanup_unpin; | |
11762 | ||
11763 | i915_gem_request_assign(&work->flip_queued_req, request); | |
11764 | } | |
11765 | ||
11766 | if (request) | |
11767 | i915_add_request_no_flush(request); | |
11768 | ||
11769 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); | |
11770 | work->enable_stall_check = true; | |
11771 | ||
11772 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, | |
11773 | to_intel_plane(primary)->frontbuffer_bit); | |
11774 | mutex_unlock(&dev->struct_mutex); | |
11775 | ||
11776 | intel_frontbuffer_flip_prepare(dev, | |
11777 | to_intel_plane(primary)->frontbuffer_bit); | |
11778 | ||
11779 | trace_i915_flip_request(intel_crtc->plane, obj); | |
11780 | ||
11781 | return 0; | |
11782 | ||
11783 | cleanup_unpin: | |
11784 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); | |
11785 | cleanup_pending: | |
11786 | if (!IS_ERR_OR_NULL(request)) | |
11787 | i915_gem_request_cancel(request); | |
11788 | atomic_dec(&intel_crtc->unpin_work_count); | |
11789 | mutex_unlock(&dev->struct_mutex); | |
11790 | cleanup: | |
11791 | crtc->primary->fb = old_fb; | |
11792 | update_state_fb(crtc->primary); | |
11793 | ||
11794 | drm_gem_object_unreference_unlocked(&obj->base); | |
11795 | drm_framebuffer_unreference(work->old_fb); | |
11796 | ||
11797 | spin_lock_irq(&dev->event_lock); | |
11798 | intel_crtc->unpin_work = NULL; | |
11799 | spin_unlock_irq(&dev->event_lock); | |
11800 | ||
11801 | drm_crtc_vblank_put(crtc); | |
11802 | free_work: | |
11803 | kfree(work); | |
11804 | ||
11805 | if (ret == -EIO) { | |
11806 | struct drm_atomic_state *state; | |
11807 | struct drm_plane_state *plane_state; | |
11808 | ||
11809 | out_hang: | |
11810 | state = drm_atomic_state_alloc(dev); | |
11811 | if (!state) | |
11812 | return -ENOMEM; | |
11813 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11814 | ||
11815 | retry: | |
11816 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11817 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11818 | if (!ret) { | |
11819 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11820 | ||
11821 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11822 | if (!ret) | |
11823 | ret = drm_atomic_commit(state); | |
11824 | } | |
11825 | ||
11826 | if (ret == -EDEADLK) { | |
11827 | drm_modeset_backoff(state->acquire_ctx); | |
11828 | drm_atomic_state_clear(state); | |
11829 | goto retry; | |
11830 | } | |
11831 | ||
11832 | if (ret) | |
11833 | drm_atomic_state_free(state); | |
11834 | ||
11835 | if (ret == 0 && event) { | |
11836 | spin_lock_irq(&dev->event_lock); | |
11837 | drm_send_vblank_event(dev, pipe, event); | |
11838 | spin_unlock_irq(&dev->event_lock); | |
11839 | } | |
11840 | } | |
11841 | return ret; | |
11842 | } | |
11843 | ||
11844 | ||
11845 | /** | |
11846 | * intel_wm_need_update - Check whether watermarks need updating | |
11847 | * @plane: drm plane | |
11848 | * @state: new plane state | |
11849 | * | |
11850 | * Check current plane state versus the new one to determine whether | |
11851 | * watermarks need to be recalculated. | |
11852 | * | |
11853 | * Returns true or false. | |
11854 | */ | |
11855 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11856 | struct drm_plane_state *state) | |
11857 | { | |
11858 | struct intel_plane_state *new = to_intel_plane_state(state); | |
11859 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11860 | ||
11861 | /* Update watermarks on tiling or size changes. */ | |
11862 | if (new->visible != cur->visible) | |
11863 | return true; | |
11864 | ||
11865 | if (!cur->base.fb || !new->base.fb) | |
11866 | return false; | |
11867 | ||
11868 | if (cur->base.fb->modifier[0] != new->base.fb->modifier[0] || | |
11869 | cur->base.rotation != new->base.rotation || | |
11870 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11871 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11872 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11873 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
11874 | return true; | |
11875 | ||
11876 | return false; | |
11877 | } | |
11878 | ||
11879 | static bool needs_scaling(struct intel_plane_state *state) | |
11880 | { | |
11881 | int src_w = drm_rect_width(&state->src) >> 16; | |
11882 | int src_h = drm_rect_height(&state->src) >> 16; | |
11883 | int dst_w = drm_rect_width(&state->dst); | |
11884 | int dst_h = drm_rect_height(&state->dst); | |
11885 | ||
11886 | return (src_w != dst_w || src_h != dst_h); | |
11887 | } | |
11888 | ||
11889 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, | |
11890 | struct drm_plane_state *plane_state) | |
11891 | { | |
11892 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); | |
11893 | struct drm_crtc *crtc = crtc_state->crtc; | |
11894 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11895 | struct drm_plane *plane = plane_state->plane; | |
11896 | struct drm_device *dev = crtc->dev; | |
11897 | struct drm_i915_private *dev_priv = to_i915(dev); | |
11898 | struct intel_plane_state *old_plane_state = | |
11899 | to_intel_plane_state(plane->state); | |
11900 | int idx = intel_crtc->base.base.id, ret; | |
11901 | bool mode_changed = needs_modeset(crtc_state); | |
11902 | bool was_crtc_enabled = crtc->state->active; | |
11903 | bool is_crtc_enabled = crtc_state->active; | |
11904 | bool turn_off, turn_on, visible, was_visible; | |
11905 | struct drm_framebuffer *fb = plane_state->fb; | |
11906 | ||
11907 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11908 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11909 | ret = skl_update_scaler_plane( | |
11910 | to_intel_crtc_state(crtc_state), | |
11911 | to_intel_plane_state(plane_state)); | |
11912 | if (ret) | |
11913 | return ret; | |
11914 | } | |
11915 | ||
11916 | was_visible = old_plane_state->visible; | |
11917 | visible = to_intel_plane_state(plane_state)->visible; | |
11918 | ||
11919 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11920 | was_visible = false; | |
11921 | ||
11922 | /* | |
11923 | * Visibility is calculated as if the crtc was on, but | |
11924 | * after scaler setup everything depends on it being off | |
11925 | * when the crtc isn't active. | |
11926 | */ | |
11927 | if (!is_crtc_enabled) | |
11928 | to_intel_plane_state(plane_state)->visible = visible = false; | |
11929 | ||
11930 | if (!was_visible && !visible) | |
11931 | return 0; | |
11932 | ||
11933 | if (fb != old_plane_state->base.fb) | |
11934 | pipe_config->fb_changed = true; | |
11935 | ||
11936 | turn_off = was_visible && (!visible || mode_changed); | |
11937 | turn_on = visible && (!was_visible || mode_changed); | |
11938 | ||
11939 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11940 | plane->base.id, fb ? fb->base.id : -1); | |
11941 | ||
11942 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11943 | plane->base.id, was_visible, visible, | |
11944 | turn_off, turn_on, mode_changed); | |
11945 | ||
11946 | if (turn_on || turn_off) { | |
11947 | pipe_config->wm_changed = true; | |
11948 | ||
11949 | /* must disable cxsr around plane enable/disable */ | |
11950 | if (plane->type != DRM_PLANE_TYPE_CURSOR) | |
11951 | pipe_config->disable_cxsr = true; | |
11952 | } else if (intel_wm_need_update(plane, plane_state)) { | |
11953 | pipe_config->wm_changed = true; | |
11954 | } | |
11955 | ||
11956 | /* Pre-gen9 platforms need two-step watermark updates */ | |
11957 | if (pipe_config->wm_changed && INTEL_INFO(dev)->gen < 9 && | |
11958 | dev_priv->display.optimize_watermarks) | |
11959 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; | |
11960 | ||
11961 | if (visible || was_visible) | |
11962 | intel_crtc->atomic.fb_bits |= | |
11963 | to_intel_plane(plane)->frontbuffer_bit; | |
11964 | ||
11965 | switch (plane->type) { | |
11966 | case DRM_PLANE_TYPE_PRIMARY: | |
11967 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11968 | intel_crtc->atomic.update_fbc = true; | |
11969 | ||
11970 | break; | |
11971 | case DRM_PLANE_TYPE_CURSOR: | |
11972 | break; | |
11973 | case DRM_PLANE_TYPE_OVERLAY: | |
11974 | /* | |
11975 | * WaCxSRDisabledForSpriteScaling:ivb | |
11976 | * | |
11977 | * cstate->update_wm was already set above, so this flag will | |
11978 | * take effect when we commit and program watermarks. | |
11979 | */ | |
11980 | if (IS_IVYBRIDGE(dev) && | |
11981 | needs_scaling(to_intel_plane_state(plane_state)) && | |
11982 | !needs_scaling(old_plane_state)) | |
11983 | pipe_config->disable_lp_wm = true; | |
11984 | ||
11985 | break; | |
11986 | } | |
11987 | return 0; | |
11988 | } | |
11989 | ||
11990 | static bool encoders_cloneable(const struct intel_encoder *a, | |
11991 | const struct intel_encoder *b) | |
11992 | { | |
11993 | /* masks could be asymmetric, so check both ways */ | |
11994 | return a == b || (a->cloneable & (1 << b->type) && | |
11995 | b->cloneable & (1 << a->type)); | |
11996 | } | |
11997 | ||
11998 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11999 | struct intel_crtc *crtc, | |
12000 | struct intel_encoder *encoder) | |
12001 | { | |
12002 | struct intel_encoder *source_encoder; | |
12003 | struct drm_connector *connector; | |
12004 | struct drm_connector_state *connector_state; | |
12005 | int i; | |
12006 | ||
12007 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12008 | if (connector_state->crtc != &crtc->base) | |
12009 | continue; | |
12010 | ||
12011 | source_encoder = | |
12012 | to_intel_encoder(connector_state->best_encoder); | |
12013 | if (!encoders_cloneable(encoder, source_encoder)) | |
12014 | return false; | |
12015 | } | |
12016 | ||
12017 | return true; | |
12018 | } | |
12019 | ||
12020 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
12021 | struct intel_crtc *crtc) | |
12022 | { | |
12023 | struct intel_encoder *encoder; | |
12024 | struct drm_connector *connector; | |
12025 | struct drm_connector_state *connector_state; | |
12026 | int i; | |
12027 | ||
12028 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12029 | if (connector_state->crtc != &crtc->base) | |
12030 | continue; | |
12031 | ||
12032 | encoder = to_intel_encoder(connector_state->best_encoder); | |
12033 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
12034 | return false; | |
12035 | } | |
12036 | ||
12037 | return true; | |
12038 | } | |
12039 | ||
12040 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
12041 | struct drm_crtc_state *crtc_state) | |
12042 | { | |
12043 | struct drm_device *dev = crtc->dev; | |
12044 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12045 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12046 | struct intel_crtc_state *pipe_config = | |
12047 | to_intel_crtc_state(crtc_state); | |
12048 | struct drm_atomic_state *state = crtc_state->state; | |
12049 | int ret; | |
12050 | bool mode_changed = needs_modeset(crtc_state); | |
12051 | ||
12052 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
12053 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
12054 | return -EINVAL; | |
12055 | } | |
12056 | ||
12057 | if (mode_changed && !crtc_state->active) | |
12058 | pipe_config->wm_changed = true; | |
12059 | ||
12060 | if (mode_changed && crtc_state->enable && | |
12061 | dev_priv->display.crtc_compute_clock && | |
12062 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
12063 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
12064 | pipe_config); | |
12065 | if (ret) | |
12066 | return ret; | |
12067 | } | |
12068 | ||
12069 | ret = 0; | |
12070 | if (dev_priv->display.compute_pipe_wm) { | |
12071 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
12072 | if (ret) { | |
12073 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); | |
12074 | return ret; | |
12075 | } | |
12076 | } | |
12077 | ||
12078 | if (dev_priv->display.compute_intermediate_wm && | |
12079 | !to_intel_atomic_state(state)->skip_intermediate_wm) { | |
12080 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) | |
12081 | return 0; | |
12082 | ||
12083 | /* | |
12084 | * Calculate 'intermediate' watermarks that satisfy both the | |
12085 | * old state and the new state. We can program these | |
12086 | * immediately. | |
12087 | */ | |
12088 | ret = dev_priv->display.compute_intermediate_wm(crtc->dev, | |
12089 | intel_crtc, | |
12090 | pipe_config); | |
12091 | if (ret) { | |
12092 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); | |
12093 | return ret; | |
12094 | } | |
12095 | } | |
12096 | ||
12097 | if (INTEL_INFO(dev)->gen >= 9) { | |
12098 | if (mode_changed) | |
12099 | ret = skl_update_scaler_crtc(pipe_config); | |
12100 | ||
12101 | if (!ret) | |
12102 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
12103 | pipe_config); | |
12104 | } | |
12105 | ||
12106 | return ret; | |
12107 | } | |
12108 | ||
12109 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { | |
12110 | .mode_set_base_atomic = intel_pipe_set_base_atomic, | |
12111 | .load_lut = intel_crtc_load_lut, | |
12112 | .atomic_begin = intel_begin_crtc_commit, | |
12113 | .atomic_flush = intel_finish_crtc_commit, | |
12114 | .atomic_check = intel_crtc_atomic_check, | |
12115 | }; | |
12116 | ||
12117 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) | |
12118 | { | |
12119 | struct intel_connector *connector; | |
12120 | ||
12121 | for_each_intel_connector(dev, connector) { | |
12122 | if (connector->base.encoder) { | |
12123 | connector->base.state->best_encoder = | |
12124 | connector->base.encoder; | |
12125 | connector->base.state->crtc = | |
12126 | connector->base.encoder->crtc; | |
12127 | } else { | |
12128 | connector->base.state->best_encoder = NULL; | |
12129 | connector->base.state->crtc = NULL; | |
12130 | } | |
12131 | } | |
12132 | } | |
12133 | ||
12134 | static void | |
12135 | connected_sink_compute_bpp(struct intel_connector *connector, | |
12136 | struct intel_crtc_state *pipe_config) | |
12137 | { | |
12138 | int bpp = pipe_config->pipe_bpp; | |
12139 | ||
12140 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
12141 | connector->base.base.id, | |
12142 | connector->base.name); | |
12143 | ||
12144 | /* Don't use an invalid EDID bpc value */ | |
12145 | if (connector->base.display_info.bpc && | |
12146 | connector->base.display_info.bpc * 3 < bpp) { | |
12147 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
12148 | bpp, connector->base.display_info.bpc*3); | |
12149 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
12150 | } | |
12151 | ||
12152 | /* Clamp bpp to default limit on screens without EDID 1.4 */ | |
12153 | if (connector->base.display_info.bpc == 0) { | |
12154 | int type = connector->base.connector_type; | |
12155 | int clamp_bpp = 24; | |
12156 | ||
12157 | /* Fall back to 18 bpp when DP sink capability is unknown. */ | |
12158 | if (type == DRM_MODE_CONNECTOR_DisplayPort || | |
12159 | type == DRM_MODE_CONNECTOR_eDP) | |
12160 | clamp_bpp = 18; | |
12161 | ||
12162 | if (bpp > clamp_bpp) { | |
12163 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n", | |
12164 | bpp, clamp_bpp); | |
12165 | pipe_config->pipe_bpp = clamp_bpp; | |
12166 | } | |
12167 | } | |
12168 | } | |
12169 | ||
12170 | static int | |
12171 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, | |
12172 | struct intel_crtc_state *pipe_config) | |
12173 | { | |
12174 | struct drm_device *dev = crtc->base.dev; | |
12175 | struct drm_atomic_state *state; | |
12176 | struct drm_connector *connector; | |
12177 | struct drm_connector_state *connector_state; | |
12178 | int bpp, i; | |
12179 | ||
12180 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))) | |
12181 | bpp = 10*3; | |
12182 | else if (INTEL_INFO(dev)->gen >= 5) | |
12183 | bpp = 12*3; | |
12184 | else | |
12185 | bpp = 8*3; | |
12186 | ||
12187 | ||
12188 | pipe_config->pipe_bpp = bpp; | |
12189 | ||
12190 | state = pipe_config->base.state; | |
12191 | ||
12192 | /* Clamp display bpp to EDID value */ | |
12193 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12194 | if (connector_state->crtc != &crtc->base) | |
12195 | continue; | |
12196 | ||
12197 | connected_sink_compute_bpp(to_intel_connector(connector), | |
12198 | pipe_config); | |
12199 | } | |
12200 | ||
12201 | return bpp; | |
12202 | } | |
12203 | ||
12204 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) | |
12205 | { | |
12206 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
12207 | "type: 0x%x flags: 0x%x\n", | |
12208 | mode->crtc_clock, | |
12209 | mode->crtc_hdisplay, mode->crtc_hsync_start, | |
12210 | mode->crtc_hsync_end, mode->crtc_htotal, | |
12211 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
12212 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
12213 | } | |
12214 | ||
12215 | static void intel_dump_pipe_config(struct intel_crtc *crtc, | |
12216 | struct intel_crtc_state *pipe_config, | |
12217 | const char *context) | |
12218 | { | |
12219 | struct drm_device *dev = crtc->base.dev; | |
12220 | struct drm_plane *plane; | |
12221 | struct intel_plane *intel_plane; | |
12222 | struct intel_plane_state *state; | |
12223 | struct drm_framebuffer *fb; | |
12224 | ||
12225 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
12226 | context, pipe_config, pipe_name(crtc->pipe)); | |
12227 | ||
12228 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
12229 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
12230 | pipe_config->pipe_bpp, pipe_config->dither); | |
12231 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12232 | pipe_config->has_pch_encoder, | |
12233 | pipe_config->fdi_lanes, | |
12234 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
12235 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
12236 | pipe_config->fdi_m_n.tu); | |
12237 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12238 | pipe_config->has_dp_encoder, | |
12239 | pipe_config->lane_count, | |
12240 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, | |
12241 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
12242 | pipe_config->dp_m_n.tu); | |
12243 | ||
12244 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", | |
12245 | pipe_config->has_dp_encoder, | |
12246 | pipe_config->lane_count, | |
12247 | pipe_config->dp_m2_n2.gmch_m, | |
12248 | pipe_config->dp_m2_n2.gmch_n, | |
12249 | pipe_config->dp_m2_n2.link_m, | |
12250 | pipe_config->dp_m2_n2.link_n, | |
12251 | pipe_config->dp_m2_n2.tu); | |
12252 | ||
12253 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", | |
12254 | pipe_config->has_audio, | |
12255 | pipe_config->has_infoframe); | |
12256 | ||
12257 | DRM_DEBUG_KMS("requested mode:\n"); | |
12258 | drm_mode_debug_printmodeline(&pipe_config->base.mode); | |
12259 | DRM_DEBUG_KMS("adjusted mode:\n"); | |
12260 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); | |
12261 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
12262 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); | |
12263 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", | |
12264 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
12265 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", | |
12266 | crtc->num_scalers, | |
12267 | pipe_config->scaler_state.scaler_users, | |
12268 | pipe_config->scaler_state.scaler_id); | |
12269 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", | |
12270 | pipe_config->gmch_pfit.control, | |
12271 | pipe_config->gmch_pfit.pgm_ratios, | |
12272 | pipe_config->gmch_pfit.lvds_border_bits); | |
12273 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", | |
12274 | pipe_config->pch_pfit.pos, | |
12275 | pipe_config->pch_pfit.size, | |
12276 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
12277 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); | |
12278 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); | |
12279 | ||
12280 | if (IS_BROXTON(dev)) { | |
12281 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," | |
12282 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " | |
12283 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", | |
12284 | pipe_config->ddi_pll_sel, | |
12285 | pipe_config->dpll_hw_state.ebb0, | |
12286 | pipe_config->dpll_hw_state.ebb4, | |
12287 | pipe_config->dpll_hw_state.pll0, | |
12288 | pipe_config->dpll_hw_state.pll1, | |
12289 | pipe_config->dpll_hw_state.pll2, | |
12290 | pipe_config->dpll_hw_state.pll3, | |
12291 | pipe_config->dpll_hw_state.pll6, | |
12292 | pipe_config->dpll_hw_state.pll8, | |
12293 | pipe_config->dpll_hw_state.pll9, | |
12294 | pipe_config->dpll_hw_state.pll10, | |
12295 | pipe_config->dpll_hw_state.pcsdw12); | |
12296 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { | |
12297 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " | |
12298 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12299 | pipe_config->ddi_pll_sel, | |
12300 | pipe_config->dpll_hw_state.ctrl1, | |
12301 | pipe_config->dpll_hw_state.cfgcr1, | |
12302 | pipe_config->dpll_hw_state.cfgcr2); | |
12303 | } else if (HAS_DDI(dev)) { | |
12304 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", | |
12305 | pipe_config->ddi_pll_sel, | |
12306 | pipe_config->dpll_hw_state.wrpll, | |
12307 | pipe_config->dpll_hw_state.spll); | |
12308 | } else { | |
12309 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12310 | "fp0: 0x%x, fp1: 0x%x\n", | |
12311 | pipe_config->dpll_hw_state.dpll, | |
12312 | pipe_config->dpll_hw_state.dpll_md, | |
12313 | pipe_config->dpll_hw_state.fp0, | |
12314 | pipe_config->dpll_hw_state.fp1); | |
12315 | } | |
12316 | ||
12317 | DRM_DEBUG_KMS("planes on this crtc\n"); | |
12318 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12319 | intel_plane = to_intel_plane(plane); | |
12320 | if (intel_plane->pipe != crtc->pipe) | |
12321 | continue; | |
12322 | ||
12323 | state = to_intel_plane_state(plane->state); | |
12324 | fb = state->base.fb; | |
12325 | if (!fb) { | |
12326 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12327 | "disabled, scaler_id = %d\n", | |
12328 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12329 | plane->base.id, intel_plane->pipe, | |
12330 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12331 | drm_plane_index(plane), state->scaler_id); | |
12332 | continue; | |
12333 | } | |
12334 | ||
12335 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12336 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12337 | plane->base.id, intel_plane->pipe, | |
12338 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12339 | drm_plane_index(plane)); | |
12340 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12341 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12342 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12343 | state->scaler_id, | |
12344 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12345 | drm_rect_width(&state->src) >> 16, | |
12346 | drm_rect_height(&state->src) >> 16, | |
12347 | state->dst.x1, state->dst.y1, | |
12348 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12349 | } | |
12350 | } | |
12351 | ||
12352 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) | |
12353 | { | |
12354 | struct drm_device *dev = state->dev; | |
12355 | struct drm_connector *connector; | |
12356 | unsigned int used_ports = 0; | |
12357 | ||
12358 | /* | |
12359 | * Walk the connector list instead of the encoder | |
12360 | * list to detect the problem on ddi platforms | |
12361 | * where there's just one encoder per digital port. | |
12362 | */ | |
12363 | drm_for_each_connector(connector, dev) { | |
12364 | struct drm_connector_state *connector_state; | |
12365 | struct intel_encoder *encoder; | |
12366 | ||
12367 | connector_state = drm_atomic_get_existing_connector_state(state, connector); | |
12368 | if (!connector_state) | |
12369 | connector_state = connector->state; | |
12370 | ||
12371 | if (!connector_state->best_encoder) | |
12372 | continue; | |
12373 | ||
12374 | encoder = to_intel_encoder(connector_state->best_encoder); | |
12375 | ||
12376 | WARN_ON(!connector_state->crtc); | |
12377 | ||
12378 | switch (encoder->type) { | |
12379 | unsigned int port_mask; | |
12380 | case INTEL_OUTPUT_UNKNOWN: | |
12381 | if (WARN_ON(!HAS_DDI(dev))) | |
12382 | break; | |
12383 | case INTEL_OUTPUT_DISPLAYPORT: | |
12384 | case INTEL_OUTPUT_HDMI: | |
12385 | case INTEL_OUTPUT_EDP: | |
12386 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12387 | ||
12388 | /* the same port mustn't appear more than once */ | |
12389 | if (used_ports & port_mask) | |
12390 | return false; | |
12391 | ||
12392 | used_ports |= port_mask; | |
12393 | default: | |
12394 | break; | |
12395 | } | |
12396 | } | |
12397 | ||
12398 | return true; | |
12399 | } | |
12400 | ||
12401 | static void | |
12402 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12403 | { | |
12404 | struct drm_crtc_state tmp_state; | |
12405 | struct intel_crtc_scaler_state scaler_state; | |
12406 | struct intel_dpll_hw_state dpll_hw_state; | |
12407 | enum intel_dpll_id shared_dpll; | |
12408 | uint32_t ddi_pll_sel; | |
12409 | bool force_thru; | |
12410 | ||
12411 | /* FIXME: before the switch to atomic started, a new pipe_config was | |
12412 | * kzalloc'd. Code that depends on any field being zero should be | |
12413 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12414 | * only fields that are know to not cause problems are preserved. */ | |
12415 | ||
12416 | tmp_state = crtc_state->base; | |
12417 | scaler_state = crtc_state->scaler_state; | |
12418 | shared_dpll = crtc_state->shared_dpll; | |
12419 | dpll_hw_state = crtc_state->dpll_hw_state; | |
12420 | ddi_pll_sel = crtc_state->ddi_pll_sel; | |
12421 | force_thru = crtc_state->pch_pfit.force_thru; | |
12422 | ||
12423 | memset(crtc_state, 0, sizeof *crtc_state); | |
12424 | ||
12425 | crtc_state->base = tmp_state; | |
12426 | crtc_state->scaler_state = scaler_state; | |
12427 | crtc_state->shared_dpll = shared_dpll; | |
12428 | crtc_state->dpll_hw_state = dpll_hw_state; | |
12429 | crtc_state->ddi_pll_sel = ddi_pll_sel; | |
12430 | crtc_state->pch_pfit.force_thru = force_thru; | |
12431 | } | |
12432 | ||
12433 | static int | |
12434 | intel_modeset_pipe_config(struct drm_crtc *crtc, | |
12435 | struct intel_crtc_state *pipe_config) | |
12436 | { | |
12437 | struct drm_atomic_state *state = pipe_config->base.state; | |
12438 | struct intel_encoder *encoder; | |
12439 | struct drm_connector *connector; | |
12440 | struct drm_connector_state *connector_state; | |
12441 | int base_bpp, ret = -EINVAL; | |
12442 | int i; | |
12443 | bool retry = true; | |
12444 | ||
12445 | clear_intel_crtc_state(pipe_config); | |
12446 | ||
12447 | pipe_config->cpu_transcoder = | |
12448 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
12449 | ||
12450 | /* | |
12451 | * Sanitize sync polarity flags based on requested ones. If neither | |
12452 | * positive or negative polarity is requested, treat this as meaning | |
12453 | * negative polarity. | |
12454 | */ | |
12455 | if (!(pipe_config->base.adjusted_mode.flags & | |
12456 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) | |
12457 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; | |
12458 | ||
12459 | if (!(pipe_config->base.adjusted_mode.flags & | |
12460 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) | |
12461 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; | |
12462 | ||
12463 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), | |
12464 | pipe_config); | |
12465 | if (base_bpp < 0) | |
12466 | goto fail; | |
12467 | ||
12468 | /* | |
12469 | * Determine the real pipe dimensions. Note that stereo modes can | |
12470 | * increase the actual pipe size due to the frame doubling and | |
12471 | * insertion of additional space for blanks between the frame. This | |
12472 | * is stored in the crtc timings. We use the requested mode to do this | |
12473 | * computation to clearly distinguish it from the adjusted mode, which | |
12474 | * can be changed by the connectors in the below retry loop. | |
12475 | */ | |
12476 | drm_crtc_get_hv_timing(&pipe_config->base.mode, | |
12477 | &pipe_config->pipe_src_w, | |
12478 | &pipe_config->pipe_src_h); | |
12479 | ||
12480 | encoder_retry: | |
12481 | /* Ensure the port clock defaults are reset when retrying. */ | |
12482 | pipe_config->port_clock = 0; | |
12483 | pipe_config->pixel_multiplier = 1; | |
12484 | ||
12485 | /* Fill in default crtc timings, allow encoders to overwrite them. */ | |
12486 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, | |
12487 | CRTC_STEREO_DOUBLE); | |
12488 | ||
12489 | /* Pass our mode to the connectors and the CRTC to give them a chance to | |
12490 | * adjust it according to limitations or connector properties, and also | |
12491 | * a chance to reject the mode entirely. | |
12492 | */ | |
12493 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12494 | if (connector_state->crtc != crtc) | |
12495 | continue; | |
12496 | ||
12497 | encoder = to_intel_encoder(connector_state->best_encoder); | |
12498 | ||
12499 | if (!(encoder->compute_config(encoder, pipe_config))) { | |
12500 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
12501 | goto fail; | |
12502 | } | |
12503 | } | |
12504 | ||
12505 | /* Set default port clock if not overwritten by the encoder. Needs to be | |
12506 | * done afterwards in case the encoder adjusts the mode. */ | |
12507 | if (!pipe_config->port_clock) | |
12508 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock | |
12509 | * pipe_config->pixel_multiplier; | |
12510 | ||
12511 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); | |
12512 | if (ret < 0) { | |
12513 | DRM_DEBUG_KMS("CRTC fixup failed\n"); | |
12514 | goto fail; | |
12515 | } | |
12516 | ||
12517 | if (ret == RETRY) { | |
12518 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12519 | ret = -EINVAL; | |
12520 | goto fail; | |
12521 | } | |
12522 | ||
12523 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12524 | retry = false; | |
12525 | goto encoder_retry; | |
12526 | } | |
12527 | ||
12528 | /* Dithering seems to not pass-through bits correctly when it should, so | |
12529 | * only enable it on 6bpc panels. */ | |
12530 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
12531 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", | |
12532 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); | |
12533 | ||
12534 | fail: | |
12535 | return ret; | |
12536 | } | |
12537 | ||
12538 | static void | |
12539 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) | |
12540 | { | |
12541 | struct drm_crtc *crtc; | |
12542 | struct drm_crtc_state *crtc_state; | |
12543 | int i; | |
12544 | ||
12545 | /* Double check state. */ | |
12546 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
12547 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); | |
12548 | ||
12549 | /* Update hwmode for vblank functions */ | |
12550 | if (crtc->state->active) | |
12551 | crtc->hwmode = crtc->state->adjusted_mode; | |
12552 | else | |
12553 | crtc->hwmode.crtc_clock = 0; | |
12554 | ||
12555 | /* | |
12556 | * Update legacy state to satisfy fbc code. This can | |
12557 | * be removed when fbc uses the atomic state. | |
12558 | */ | |
12559 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12560 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12561 | ||
12562 | crtc->primary->fb = plane_state->fb; | |
12563 | crtc->x = plane_state->src_x >> 16; | |
12564 | crtc->y = plane_state->src_y >> 16; | |
12565 | } | |
12566 | } | |
12567 | } | |
12568 | ||
12569 | static bool intel_fuzzy_clock_check(int clock1, int clock2) | |
12570 | { | |
12571 | int diff; | |
12572 | ||
12573 | if (clock1 == clock2) | |
12574 | return true; | |
12575 | ||
12576 | if (!clock1 || !clock2) | |
12577 | return false; | |
12578 | ||
12579 | diff = abs(clock1 - clock2); | |
12580 | ||
12581 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12582 | return true; | |
12583 | ||
12584 | return false; | |
12585 | } | |
12586 | ||
12587 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ | |
12588 | list_for_each_entry((intel_crtc), \ | |
12589 | &(dev)->mode_config.crtc_list, \ | |
12590 | base.head) \ | |
12591 | for_each_if (mask & (1 <<(intel_crtc)->pipe)) | |
12592 | ||
12593 | static bool | |
12594 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12595 | unsigned int m2, unsigned int n2, | |
12596 | bool exact) | |
12597 | { | |
12598 | if (m == m2 && n == n2) | |
12599 | return true; | |
12600 | ||
12601 | if (exact || !m || !n || !m2 || !n2) | |
12602 | return false; | |
12603 | ||
12604 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12605 | ||
12606 | if (n > n2) { | |
12607 | while (n > n2) { | |
12608 | m2 <<= 1; | |
12609 | n2 <<= 1; | |
12610 | } | |
12611 | } else if (n < n2) { | |
12612 | while (n < n2) { | |
12613 | m <<= 1; | |
12614 | n <<= 1; | |
12615 | } | |
12616 | } | |
12617 | ||
12618 | if (n != n2) | |
12619 | return false; | |
12620 | ||
12621 | return intel_fuzzy_clock_check(m, m2); | |
12622 | } | |
12623 | ||
12624 | static bool | |
12625 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12626 | struct intel_link_m_n *m2_n2, | |
12627 | bool adjust) | |
12628 | { | |
12629 | if (m_n->tu == m2_n2->tu && | |
12630 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12631 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12632 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12633 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12634 | if (adjust) | |
12635 | *m2_n2 = *m_n; | |
12636 | ||
12637 | return true; | |
12638 | } | |
12639 | ||
12640 | return false; | |
12641 | } | |
12642 | ||
12643 | static bool | |
12644 | intel_pipe_config_compare(struct drm_device *dev, | |
12645 | struct intel_crtc_state *current_config, | |
12646 | struct intel_crtc_state *pipe_config, | |
12647 | bool adjust) | |
12648 | { | |
12649 | bool ret = true; | |
12650 | ||
12651 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12652 | do { \ | |
12653 | if (!adjust) \ | |
12654 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12655 | else \ | |
12656 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12657 | } while (0) | |
12658 | ||
12659 | #define PIPE_CONF_CHECK_X(name) \ | |
12660 | if (current_config->name != pipe_config->name) { \ | |
12661 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12662 | "(expected 0x%08x, found 0x%08x)\n", \ | |
12663 | current_config->name, \ | |
12664 | pipe_config->name); \ | |
12665 | ret = false; \ | |
12666 | } | |
12667 | ||
12668 | #define PIPE_CONF_CHECK_I(name) \ | |
12669 | if (current_config->name != pipe_config->name) { \ | |
12670 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12671 | "(expected %i, found %i)\n", \ | |
12672 | current_config->name, \ | |
12673 | pipe_config->name); \ | |
12674 | ret = false; \ | |
12675 | } | |
12676 | ||
12677 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12678 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12679 | &pipe_config->name,\ | |
12680 | adjust)) { \ | |
12681 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12682 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12683 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12684 | current_config->name.tu, \ | |
12685 | current_config->name.gmch_m, \ | |
12686 | current_config->name.gmch_n, \ | |
12687 | current_config->name.link_m, \ | |
12688 | current_config->name.link_n, \ | |
12689 | pipe_config->name.tu, \ | |
12690 | pipe_config->name.gmch_m, \ | |
12691 | pipe_config->name.gmch_n, \ | |
12692 | pipe_config->name.link_m, \ | |
12693 | pipe_config->name.link_n); \ | |
12694 | ret = false; \ | |
12695 | } | |
12696 | ||
12697 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12698 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12699 | &pipe_config->name, adjust) && \ | |
12700 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12701 | &pipe_config->name, adjust)) { \ | |
12702 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12703 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12704 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12705 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12706 | current_config->name.tu, \ | |
12707 | current_config->name.gmch_m, \ | |
12708 | current_config->name.gmch_n, \ | |
12709 | current_config->name.link_m, \ | |
12710 | current_config->name.link_n, \ | |
12711 | current_config->alt_name.tu, \ | |
12712 | current_config->alt_name.gmch_m, \ | |
12713 | current_config->alt_name.gmch_n, \ | |
12714 | current_config->alt_name.link_m, \ | |
12715 | current_config->alt_name.link_n, \ | |
12716 | pipe_config->name.tu, \ | |
12717 | pipe_config->name.gmch_m, \ | |
12718 | pipe_config->name.gmch_n, \ | |
12719 | pipe_config->name.link_m, \ | |
12720 | pipe_config->name.link_n); \ | |
12721 | ret = false; \ | |
12722 | } | |
12723 | ||
12724 | /* This is required for BDW+ where there is only one set of registers for | |
12725 | * switching between high and low RR. | |
12726 | * This macro can be used whenever a comparison has to be made between one | |
12727 | * hw state and multiple sw state variables. | |
12728 | */ | |
12729 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12730 | if ((current_config->name != pipe_config->name) && \ | |
12731 | (current_config->alt_name != pipe_config->name)) { \ | |
12732 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12733 | "(expected %i or %i, found %i)\n", \ | |
12734 | current_config->name, \ | |
12735 | current_config->alt_name, \ | |
12736 | pipe_config->name); \ | |
12737 | ret = false; \ | |
12738 | } | |
12739 | ||
12740 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ | |
12741 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
12742 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ | |
12743 | "(expected %i, found %i)\n", \ | |
12744 | current_config->name & (mask), \ | |
12745 | pipe_config->name & (mask)); \ | |
12746 | ret = false; \ | |
12747 | } | |
12748 | ||
12749 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ | |
12750 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
12751 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12752 | "(expected %i, found %i)\n", \ | |
12753 | current_config->name, \ | |
12754 | pipe_config->name); \ | |
12755 | ret = false; \ | |
12756 | } | |
12757 | ||
12758 | #define PIPE_CONF_QUIRK(quirk) \ | |
12759 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12760 | ||
12761 | PIPE_CONF_CHECK_I(cpu_transcoder); | |
12762 | ||
12763 | PIPE_CONF_CHECK_I(has_pch_encoder); | |
12764 | PIPE_CONF_CHECK_I(fdi_lanes); | |
12765 | PIPE_CONF_CHECK_M_N(fdi_m_n); | |
12766 | ||
12767 | PIPE_CONF_CHECK_I(has_dp_encoder); | |
12768 | PIPE_CONF_CHECK_I(lane_count); | |
12769 | ||
12770 | if (INTEL_INFO(dev)->gen < 8) { | |
12771 | PIPE_CONF_CHECK_M_N(dp_m_n); | |
12772 | ||
12773 | if (current_config->has_drrs) | |
12774 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12775 | } else | |
12776 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
12777 | ||
12778 | PIPE_CONF_CHECK_I(has_dsi_encoder); | |
12779 | ||
12780 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); | |
12781 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12782 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12783 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12784 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12785 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
12786 | ||
12787 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); | |
12788 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12789 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12790 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12791 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12792 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
12793 | ||
12794 | PIPE_CONF_CHECK_I(pixel_multiplier); | |
12795 | PIPE_CONF_CHECK_I(has_hdmi_sink); | |
12796 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || | |
12797 | IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) | |
12798 | PIPE_CONF_CHECK_I(limited_color_range); | |
12799 | PIPE_CONF_CHECK_I(has_infoframe); | |
12800 | ||
12801 | PIPE_CONF_CHECK_I(has_audio); | |
12802 | ||
12803 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, | |
12804 | DRM_MODE_FLAG_INTERLACE); | |
12805 | ||
12806 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { | |
12807 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, | |
12808 | DRM_MODE_FLAG_PHSYNC); | |
12809 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, | |
12810 | DRM_MODE_FLAG_NHSYNC); | |
12811 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, | |
12812 | DRM_MODE_FLAG_PVSYNC); | |
12813 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, | |
12814 | DRM_MODE_FLAG_NVSYNC); | |
12815 | } | |
12816 | ||
12817 | PIPE_CONF_CHECK_X(gmch_pfit.control); | |
12818 | /* pfit ratios are autocomputed by the hw on gen4+ */ | |
12819 | if (INTEL_INFO(dev)->gen < 4) | |
12820 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
12821 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); | |
12822 | ||
12823 | if (!adjust) { | |
12824 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12825 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12826 | ||
12827 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12828 | if (current_config->pch_pfit.enabled) { | |
12829 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12830 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12831 | } | |
12832 | ||
12833 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); | |
12834 | } | |
12835 | ||
12836 | /* BDW+ don't expose a synchronous way to read the state */ | |
12837 | if (IS_HASWELL(dev)) | |
12838 | PIPE_CONF_CHECK_I(ips_enabled); | |
12839 | ||
12840 | PIPE_CONF_CHECK_I(double_wide); | |
12841 | ||
12842 | PIPE_CONF_CHECK_X(ddi_pll_sel); | |
12843 | ||
12844 | PIPE_CONF_CHECK_I(shared_dpll); | |
12845 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); | |
12846 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); | |
12847 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); | |
12848 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
12849 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); | |
12850 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); | |
12851 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); | |
12852 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12853 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
12854 | ||
12855 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) | |
12856 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12857 | ||
12858 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); | |
12859 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); | |
12860 | ||
12861 | #undef PIPE_CONF_CHECK_X | |
12862 | #undef PIPE_CONF_CHECK_I | |
12863 | #undef PIPE_CONF_CHECK_I_ALT | |
12864 | #undef PIPE_CONF_CHECK_FLAGS | |
12865 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY | |
12866 | #undef PIPE_CONF_QUIRK | |
12867 | #undef INTEL_ERR_OR_DBG_KMS | |
12868 | ||
12869 | return ret; | |
12870 | } | |
12871 | ||
12872 | static void check_wm_state(struct drm_device *dev) | |
12873 | { | |
12874 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12875 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12876 | struct intel_crtc *intel_crtc; | |
12877 | int plane; | |
12878 | ||
12879 | if (INTEL_INFO(dev)->gen < 9) | |
12880 | return; | |
12881 | ||
12882 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12883 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12884 | ||
12885 | for_each_intel_crtc(dev, intel_crtc) { | |
12886 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12887 | const enum pipe pipe = intel_crtc->pipe; | |
12888 | ||
12889 | if (!intel_crtc->active) | |
12890 | continue; | |
12891 | ||
12892 | /* planes */ | |
12893 | for_each_plane(dev_priv, pipe, plane) { | |
12894 | hw_entry = &hw_ddb.plane[pipe][plane]; | |
12895 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12896 | ||
12897 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12898 | continue; | |
12899 | ||
12900 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12901 | "(expected (%u,%u), found (%u,%u))\n", | |
12902 | pipe_name(pipe), plane + 1, | |
12903 | sw_entry->start, sw_entry->end, | |
12904 | hw_entry->start, hw_entry->end); | |
12905 | } | |
12906 | ||
12907 | /* cursor */ | |
12908 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; | |
12909 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
12910 | ||
12911 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12912 | continue; | |
12913 | ||
12914 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12915 | "(expected (%u,%u), found (%u,%u))\n", | |
12916 | pipe_name(pipe), | |
12917 | sw_entry->start, sw_entry->end, | |
12918 | hw_entry->start, hw_entry->end); | |
12919 | } | |
12920 | } | |
12921 | ||
12922 | static void | |
12923 | check_connector_state(struct drm_device *dev, | |
12924 | struct drm_atomic_state *old_state) | |
12925 | { | |
12926 | struct drm_connector_state *old_conn_state; | |
12927 | struct drm_connector *connector; | |
12928 | int i; | |
12929 | ||
12930 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { | |
12931 | struct drm_encoder *encoder = connector->encoder; | |
12932 | struct drm_connector_state *state = connector->state; | |
12933 | ||
12934 | /* This also checks the encoder/connector hw state with the | |
12935 | * ->get_hw_state callbacks. */ | |
12936 | intel_connector_check_state(to_intel_connector(connector)); | |
12937 | ||
12938 | I915_STATE_WARN(state->best_encoder != encoder, | |
12939 | "connector's atomic encoder doesn't match legacy encoder\n"); | |
12940 | } | |
12941 | } | |
12942 | ||
12943 | static void | |
12944 | check_encoder_state(struct drm_device *dev) | |
12945 | { | |
12946 | struct intel_encoder *encoder; | |
12947 | struct intel_connector *connector; | |
12948 | ||
12949 | for_each_intel_encoder(dev, encoder) { | |
12950 | bool enabled = false; | |
12951 | enum pipe pipe; | |
12952 | ||
12953 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12954 | encoder->base.base.id, | |
12955 | encoder->base.name); | |
12956 | ||
12957 | for_each_intel_connector(dev, connector) { | |
12958 | if (connector->base.state->best_encoder != &encoder->base) | |
12959 | continue; | |
12960 | enabled = true; | |
12961 | ||
12962 | I915_STATE_WARN(connector->base.state->crtc != | |
12963 | encoder->base.crtc, | |
12964 | "connector's crtc doesn't match encoder crtc\n"); | |
12965 | } | |
12966 | ||
12967 | I915_STATE_WARN(!!encoder->base.crtc != enabled, | |
12968 | "encoder's enabled state mismatch " | |
12969 | "(expected %i, found %i)\n", | |
12970 | !!encoder->base.crtc, enabled); | |
12971 | ||
12972 | if (!encoder->base.crtc) { | |
12973 | bool active; | |
12974 | ||
12975 | active = encoder->get_hw_state(encoder, &pipe); | |
12976 | I915_STATE_WARN(active, | |
12977 | "encoder detached but still enabled on pipe %c.\n", | |
12978 | pipe_name(pipe)); | |
12979 | } | |
12980 | } | |
12981 | } | |
12982 | ||
12983 | static void | |
12984 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) | |
12985 | { | |
12986 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12987 | struct intel_encoder *encoder; | |
12988 | struct drm_crtc_state *old_crtc_state; | |
12989 | struct drm_crtc *crtc; | |
12990 | int i; | |
12991 | ||
12992 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { | |
12993 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12994 | struct intel_crtc_state *pipe_config, *sw_config; | |
12995 | bool active; | |
12996 | ||
12997 | if (!needs_modeset(crtc->state) && | |
12998 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
12999 | continue; | |
13000 | ||
13001 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); | |
13002 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
13003 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
13004 | pipe_config->base.crtc = crtc; | |
13005 | pipe_config->base.state = old_state; | |
13006 | ||
13007 | DRM_DEBUG_KMS("[CRTC:%d]\n", | |
13008 | crtc->base.id); | |
13009 | ||
13010 | active = dev_priv->display.get_pipe_config(intel_crtc, | |
13011 | pipe_config); | |
13012 | ||
13013 | /* hw state is inconsistent with the pipe quirk */ | |
13014 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
13015 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
13016 | active = crtc->state->active; | |
13017 | ||
13018 | I915_STATE_WARN(crtc->state->active != active, | |
13019 | "crtc active state doesn't match with hw state " | |
13020 | "(expected %i, found %i)\n", crtc->state->active, active); | |
13021 | ||
13022 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, | |
13023 | "transitional active state does not match atomic hw state " | |
13024 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); | |
13025 | ||
13026 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
13027 | enum pipe pipe; | |
13028 | ||
13029 | active = encoder->get_hw_state(encoder, &pipe); | |
13030 | I915_STATE_WARN(active != crtc->state->active, | |
13031 | "[ENCODER:%i] active %i with crtc active %i\n", | |
13032 | encoder->base.base.id, active, crtc->state->active); | |
13033 | ||
13034 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
13035 | "Encoder connected to wrong pipe %c\n", | |
13036 | pipe_name(pipe)); | |
13037 | ||
13038 | if (active) | |
13039 | encoder->get_config(encoder, pipe_config); | |
13040 | } | |
13041 | ||
13042 | if (!crtc->state->active) | |
13043 | continue; | |
13044 | ||
13045 | sw_config = to_intel_crtc_state(crtc->state); | |
13046 | if (!intel_pipe_config_compare(dev, sw_config, | |
13047 | pipe_config, false)) { | |
13048 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); | |
13049 | intel_dump_pipe_config(intel_crtc, pipe_config, | |
13050 | "[hw state]"); | |
13051 | intel_dump_pipe_config(intel_crtc, sw_config, | |
13052 | "[sw state]"); | |
13053 | } | |
13054 | } | |
13055 | } | |
13056 | ||
13057 | static void | |
13058 | check_shared_dpll_state(struct drm_device *dev) | |
13059 | { | |
13060 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13061 | struct intel_crtc *crtc; | |
13062 | struct intel_dpll_hw_state dpll_hw_state; | |
13063 | int i; | |
13064 | ||
13065 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
13066 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
13067 | int enabled_crtcs = 0, active_crtcs = 0; | |
13068 | bool active; | |
13069 | ||
13070 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
13071 | ||
13072 | DRM_DEBUG_KMS("%s\n", pll->name); | |
13073 | ||
13074 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
13075 | ||
13076 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), | |
13077 | "more active pll users than references: %i vs %i\n", | |
13078 | pll->active, hweight32(pll->config.crtc_mask)); | |
13079 | I915_STATE_WARN(pll->active && !pll->on, | |
13080 | "pll in active use but not on in sw tracking\n"); | |
13081 | I915_STATE_WARN(pll->on && !pll->active, | |
13082 | "pll in on but not on in use in sw tracking\n"); | |
13083 | I915_STATE_WARN(pll->on != active, | |
13084 | "pll on state mismatch (expected %i, found %i)\n", | |
13085 | pll->on, active); | |
13086 | ||
13087 | for_each_intel_crtc(dev, crtc) { | |
13088 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) | |
13089 | enabled_crtcs++; | |
13090 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
13091 | active_crtcs++; | |
13092 | } | |
13093 | I915_STATE_WARN(pll->active != active_crtcs, | |
13094 | "pll active crtcs mismatch (expected %i, found %i)\n", | |
13095 | pll->active, active_crtcs); | |
13096 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, | |
13097 | "pll enabled crtcs mismatch (expected %i, found %i)\n", | |
13098 | hweight32(pll->config.crtc_mask), enabled_crtcs); | |
13099 | ||
13100 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, | |
13101 | sizeof(dpll_hw_state)), | |
13102 | "pll hw state mismatch\n"); | |
13103 | } | |
13104 | } | |
13105 | ||
13106 | static void | |
13107 | intel_modeset_check_state(struct drm_device *dev, | |
13108 | struct drm_atomic_state *old_state) | |
13109 | { | |
13110 | check_wm_state(dev); | |
13111 | check_connector_state(dev, old_state); | |
13112 | check_encoder_state(dev); | |
13113 | check_crtc_state(dev, old_state); | |
13114 | check_shared_dpll_state(dev); | |
13115 | } | |
13116 | ||
13117 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, | |
13118 | int dotclock) | |
13119 | { | |
13120 | /* | |
13121 | * FDI already provided one idea for the dotclock. | |
13122 | * Yell if the encoder disagrees. | |
13123 | */ | |
13124 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), | |
13125 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", | |
13126 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); | |
13127 | } | |
13128 | ||
13129 | static void update_scanline_offset(struct intel_crtc *crtc) | |
13130 | { | |
13131 | struct drm_device *dev = crtc->base.dev; | |
13132 | ||
13133 | /* | |
13134 | * The scanline counter increments at the leading edge of hsync. | |
13135 | * | |
13136 | * On most platforms it starts counting from vtotal-1 on the | |
13137 | * first active line. That means the scanline counter value is | |
13138 | * always one less than what we would expect. Ie. just after | |
13139 | * start of vblank, which also occurs at start of hsync (on the | |
13140 | * last active line), the scanline counter will read vblank_start-1. | |
13141 | * | |
13142 | * On gen2 the scanline counter starts counting from 1 instead | |
13143 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
13144 | * to keep the value positive), instead of adding one. | |
13145 | * | |
13146 | * On HSW+ the behaviour of the scanline counter depends on the output | |
13147 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
13148 | * there's an extra 1 line difference. So we need to add two instead of | |
13149 | * one to the value. | |
13150 | */ | |
13151 | if (IS_GEN2(dev)) { | |
13152 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; | |
13153 | int vtotal; | |
13154 | ||
13155 | vtotal = adjusted_mode->crtc_vtotal; | |
13156 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
13157 | vtotal /= 2; | |
13158 | ||
13159 | crtc->scanline_offset = vtotal - 1; | |
13160 | } else if (HAS_DDI(dev) && | |
13161 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { | |
13162 | crtc->scanline_offset = 2; | |
13163 | } else | |
13164 | crtc->scanline_offset = 1; | |
13165 | } | |
13166 | ||
13167 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) | |
13168 | { | |
13169 | struct drm_device *dev = state->dev; | |
13170 | struct drm_i915_private *dev_priv = to_i915(dev); | |
13171 | struct intel_shared_dpll_config *shared_dpll = NULL; | |
13172 | struct drm_crtc *crtc; | |
13173 | struct drm_crtc_state *crtc_state; | |
13174 | int i; | |
13175 | ||
13176 | if (!dev_priv->display.crtc_compute_clock) | |
13177 | return; | |
13178 | ||
13179 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13181 | int old_dpll = to_intel_crtc_state(crtc->state)->shared_dpll; | |
13182 | ||
13183 | if (!needs_modeset(crtc_state)) | |
13184 | continue; | |
13185 | ||
13186 | to_intel_crtc_state(crtc_state)->shared_dpll = DPLL_ID_PRIVATE; | |
13187 | ||
13188 | if (old_dpll == DPLL_ID_PRIVATE) | |
13189 | continue; | |
13190 | ||
13191 | if (!shared_dpll) | |
13192 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
13193 | ||
13194 | shared_dpll[old_dpll].crtc_mask &= ~(1 << intel_crtc->pipe); | |
13195 | } | |
13196 | } | |
13197 | ||
13198 | /* | |
13199 | * This implements the workaround described in the "notes" section of the mode | |
13200 | * set sequence documentation. When going from no pipes or single pipe to | |
13201 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
13202 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
13203 | */ | |
13204 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
13205 | { | |
13206 | struct drm_crtc_state *crtc_state; | |
13207 | struct intel_crtc *intel_crtc; | |
13208 | struct drm_crtc *crtc; | |
13209 | struct intel_crtc_state *first_crtc_state = NULL; | |
13210 | struct intel_crtc_state *other_crtc_state = NULL; | |
13211 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
13212 | int i; | |
13213 | ||
13214 | /* look at all crtc's that are going to be enabled in during modeset */ | |
13215 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13216 | intel_crtc = to_intel_crtc(crtc); | |
13217 | ||
13218 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
13219 | continue; | |
13220 | ||
13221 | if (first_crtc_state) { | |
13222 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
13223 | break; | |
13224 | } else { | |
13225 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
13226 | first_pipe = intel_crtc->pipe; | |
13227 | } | |
13228 | } | |
13229 | ||
13230 | /* No workaround needed? */ | |
13231 | if (!first_crtc_state) | |
13232 | return 0; | |
13233 | ||
13234 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
13235 | for_each_intel_crtc(state->dev, intel_crtc) { | |
13236 | struct intel_crtc_state *pipe_config; | |
13237 | ||
13238 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
13239 | if (IS_ERR(pipe_config)) | |
13240 | return PTR_ERR(pipe_config); | |
13241 | ||
13242 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
13243 | ||
13244 | if (!pipe_config->base.active || | |
13245 | needs_modeset(&pipe_config->base)) | |
13246 | continue; | |
13247 | ||
13248 | /* 2 or more enabled crtcs means no need for w/a */ | |
13249 | if (enabled_pipe != INVALID_PIPE) | |
13250 | return 0; | |
13251 | ||
13252 | enabled_pipe = intel_crtc->pipe; | |
13253 | } | |
13254 | ||
13255 | if (enabled_pipe != INVALID_PIPE) | |
13256 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
13257 | else if (other_crtc_state) | |
13258 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
13259 | ||
13260 | return 0; | |
13261 | } | |
13262 | ||
13263 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) | |
13264 | { | |
13265 | struct drm_crtc *crtc; | |
13266 | struct drm_crtc_state *crtc_state; | |
13267 | int ret = 0; | |
13268 | ||
13269 | /* add all active pipes to the state */ | |
13270 | for_each_crtc(state->dev, crtc) { | |
13271 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13272 | if (IS_ERR(crtc_state)) | |
13273 | return PTR_ERR(crtc_state); | |
13274 | ||
13275 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
13276 | continue; | |
13277 | ||
13278 | crtc_state->mode_changed = true; | |
13279 | ||
13280 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13281 | if (ret) | |
13282 | break; | |
13283 | ||
13284 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13285 | if (ret) | |
13286 | break; | |
13287 | } | |
13288 | ||
13289 | return ret; | |
13290 | } | |
13291 | ||
13292 | static int intel_modeset_checks(struct drm_atomic_state *state) | |
13293 | { | |
13294 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13295 | struct drm_i915_private *dev_priv = state->dev->dev_private; | |
13296 | struct drm_crtc *crtc; | |
13297 | struct drm_crtc_state *crtc_state; | |
13298 | int ret = 0, i; | |
13299 | ||
13300 | if (!check_digital_port_conflicts(state)) { | |
13301 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13302 | return -EINVAL; | |
13303 | } | |
13304 | ||
13305 | intel_state->modeset = true; | |
13306 | intel_state->active_crtcs = dev_priv->active_crtcs; | |
13307 | ||
13308 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13309 | if (crtc_state->active) | |
13310 | intel_state->active_crtcs |= 1 << i; | |
13311 | else | |
13312 | intel_state->active_crtcs &= ~(1 << i); | |
13313 | } | |
13314 | ||
13315 | /* | |
13316 | * See if the config requires any additional preparation, e.g. | |
13317 | * to adjust global state with pipes off. We need to do this | |
13318 | * here so we can get the modeset_pipe updated config for the new | |
13319 | * mode set on this crtc. For other crtcs we need to use the | |
13320 | * adjusted_mode bits in the crtc directly. | |
13321 | */ | |
13322 | if (dev_priv->display.modeset_calc_cdclk) { | |
13323 | ret = dev_priv->display.modeset_calc_cdclk(state); | |
13324 | ||
13325 | if (!ret && intel_state->dev_cdclk != dev_priv->cdclk_freq) | |
13326 | ret = intel_modeset_all_pipes(state); | |
13327 | ||
13328 | if (ret < 0) | |
13329 | return ret; | |
13330 | ||
13331 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", | |
13332 | intel_state->cdclk, intel_state->dev_cdclk); | |
13333 | } else | |
13334 | to_intel_atomic_state(state)->cdclk = dev_priv->atomic_cdclk_freq; | |
13335 | ||
13336 | intel_modeset_clear_plls(state); | |
13337 | ||
13338 | if (IS_HASWELL(dev_priv)) | |
13339 | return haswell_mode_set_planes_workaround(state); | |
13340 | ||
13341 | return 0; | |
13342 | } | |
13343 | ||
13344 | /* | |
13345 | * Handle calculation of various watermark data at the end of the atomic check | |
13346 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13347 | * handlers to ensure that all derived state has been updated. | |
13348 | */ | |
13349 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13350 | { | |
13351 | struct drm_device *dev = state->dev; | |
13352 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13353 | struct drm_crtc *crtc; | |
13354 | struct drm_crtc_state *cstate; | |
13355 | struct drm_plane *plane; | |
13356 | struct drm_plane_state *pstate; | |
13357 | ||
13358 | /* | |
13359 | * Calculate watermark configuration details now that derived | |
13360 | * plane/crtc state is all properly updated. | |
13361 | */ | |
13362 | drm_for_each_crtc(crtc, dev) { | |
13363 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13364 | crtc->state; | |
13365 | ||
13366 | if (cstate->active) | |
13367 | intel_state->wm_config.num_pipes_active++; | |
13368 | } | |
13369 | drm_for_each_legacy_plane(plane, dev) { | |
13370 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13371 | plane->state; | |
13372 | ||
13373 | if (!to_intel_plane_state(pstate)->visible) | |
13374 | continue; | |
13375 | ||
13376 | intel_state->wm_config.sprites_enabled = true; | |
13377 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13378 | pstate->crtc_h != pstate->src_h >> 16) | |
13379 | intel_state->wm_config.sprites_scaled = true; | |
13380 | } | |
13381 | } | |
13382 | ||
13383 | /** | |
13384 | * intel_atomic_check - validate state object | |
13385 | * @dev: drm device | |
13386 | * @state: state to validate | |
13387 | */ | |
13388 | static int intel_atomic_check(struct drm_device *dev, | |
13389 | struct drm_atomic_state *state) | |
13390 | { | |
13391 | struct drm_i915_private *dev_priv = to_i915(dev); | |
13392 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13393 | struct drm_crtc *crtc; | |
13394 | struct drm_crtc_state *crtc_state; | |
13395 | int ret, i; | |
13396 | bool any_ms = false; | |
13397 | ||
13398 | ret = drm_atomic_helper_check_modeset(dev, state); | |
13399 | if (ret) | |
13400 | return ret; | |
13401 | ||
13402 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13403 | struct intel_crtc_state *pipe_config = | |
13404 | to_intel_crtc_state(crtc_state); | |
13405 | ||
13406 | memset(&to_intel_crtc(crtc)->atomic, 0, | |
13407 | sizeof(struct intel_crtc_atomic_commit)); | |
13408 | ||
13409 | /* Catch I915_MODE_FLAG_INHERITED */ | |
13410 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13411 | crtc_state->mode_changed = true; | |
13412 | ||
13413 | if (!crtc_state->enable) { | |
13414 | if (needs_modeset(crtc_state)) | |
13415 | any_ms = true; | |
13416 | continue; | |
13417 | } | |
13418 | ||
13419 | if (!needs_modeset(crtc_state)) | |
13420 | continue; | |
13421 | ||
13422 | /* FIXME: For only active_changed we shouldn't need to do any | |
13423 | * state recomputation at all. */ | |
13424 | ||
13425 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13426 | if (ret) | |
13427 | return ret; | |
13428 | ||
13429 | ret = intel_modeset_pipe_config(crtc, pipe_config); | |
13430 | if (ret) | |
13431 | return ret; | |
13432 | ||
13433 | if (i915.fastboot && | |
13434 | intel_pipe_config_compare(dev, | |
13435 | to_intel_crtc_state(crtc->state), | |
13436 | pipe_config, true)) { | |
13437 | crtc_state->mode_changed = false; | |
13438 | to_intel_crtc_state(crtc_state)->update_pipe = true; | |
13439 | } | |
13440 | ||
13441 | if (needs_modeset(crtc_state)) { | |
13442 | any_ms = true; | |
13443 | ||
13444 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13445 | if (ret) | |
13446 | return ret; | |
13447 | } | |
13448 | ||
13449 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, | |
13450 | needs_modeset(crtc_state) ? | |
13451 | "[modeset]" : "[fastset]"); | |
13452 | } | |
13453 | ||
13454 | if (any_ms) { | |
13455 | ret = intel_modeset_checks(state); | |
13456 | ||
13457 | if (ret) | |
13458 | return ret; | |
13459 | } else | |
13460 | intel_state->cdclk = dev_priv->cdclk_freq; | |
13461 | ||
13462 | ret = drm_atomic_helper_check_planes(dev, state); | |
13463 | if (ret) | |
13464 | return ret; | |
13465 | ||
13466 | intel_fbc_choose_crtc(dev_priv, state); | |
13467 | calc_watermark_data(state); | |
13468 | ||
13469 | return 0; | |
13470 | } | |
13471 | ||
13472 | static int intel_atomic_prepare_commit(struct drm_device *dev, | |
13473 | struct drm_atomic_state *state, | |
13474 | bool async) | |
13475 | { | |
13476 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13477 | struct drm_plane_state *plane_state; | |
13478 | struct drm_crtc_state *crtc_state; | |
13479 | struct drm_plane *plane; | |
13480 | struct drm_crtc *crtc; | |
13481 | int i, ret; | |
13482 | ||
13483 | if (async) { | |
13484 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13485 | return -EINVAL; | |
13486 | } | |
13487 | ||
13488 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13489 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13490 | if (ret) | |
13491 | return ret; | |
13492 | ||
13493 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13494 | flush_workqueue(dev_priv->wq); | |
13495 | } | |
13496 | ||
13497 | ret = mutex_lock_interruptible(&dev->struct_mutex); | |
13498 | if (ret) | |
13499 | return ret; | |
13500 | ||
13501 | ret = drm_atomic_helper_prepare_planes(dev, state); | |
13502 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { | |
13503 | u32 reset_counter; | |
13504 | ||
13505 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13506 | mutex_unlock(&dev->struct_mutex); | |
13507 | ||
13508 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13509 | struct intel_plane_state *intel_plane_state = | |
13510 | to_intel_plane_state(plane_state); | |
13511 | ||
13512 | if (!intel_plane_state->wait_req) | |
13513 | continue; | |
13514 | ||
13515 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13516 | reset_counter, true, | |
13517 | NULL, NULL); | |
13518 | ||
13519 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13520 | if (ret == -EIO) | |
13521 | ret = 0; | |
13522 | ||
13523 | if (ret) | |
13524 | break; | |
13525 | } | |
13526 | ||
13527 | if (!ret) | |
13528 | return 0; | |
13529 | ||
13530 | mutex_lock(&dev->struct_mutex); | |
13531 | drm_atomic_helper_cleanup_planes(dev, state); | |
13532 | } | |
13533 | ||
13534 | mutex_unlock(&dev->struct_mutex); | |
13535 | return ret; | |
13536 | } | |
13537 | ||
13538 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, | |
13539 | struct drm_i915_private *dev_priv, | |
13540 | unsigned crtc_mask) | |
13541 | { | |
13542 | unsigned last_vblank_count[I915_MAX_PIPES]; | |
13543 | enum pipe pipe; | |
13544 | int ret; | |
13545 | ||
13546 | if (!crtc_mask) | |
13547 | return; | |
13548 | ||
13549 | for_each_pipe(dev_priv, pipe) { | |
13550 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
13551 | ||
13552 | if (!((1 << pipe) & crtc_mask)) | |
13553 | continue; | |
13554 | ||
13555 | ret = drm_crtc_vblank_get(crtc); | |
13556 | if (WARN_ON(ret != 0)) { | |
13557 | crtc_mask &= ~(1 << pipe); | |
13558 | continue; | |
13559 | } | |
13560 | ||
13561 | last_vblank_count[pipe] = drm_crtc_vblank_count(crtc); | |
13562 | } | |
13563 | ||
13564 | for_each_pipe(dev_priv, pipe) { | |
13565 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
13566 | long lret; | |
13567 | ||
13568 | if (!((1 << pipe) & crtc_mask)) | |
13569 | continue; | |
13570 | ||
13571 | lret = wait_event_timeout(dev->vblank[pipe].queue, | |
13572 | last_vblank_count[pipe] != | |
13573 | drm_crtc_vblank_count(crtc), | |
13574 | msecs_to_jiffies(50)); | |
13575 | ||
13576 | WARN_ON(!lret); | |
13577 | ||
13578 | drm_crtc_vblank_put(crtc); | |
13579 | } | |
13580 | } | |
13581 | ||
13582 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) | |
13583 | { | |
13584 | /* fb updated, need to unpin old fb */ | |
13585 | if (crtc_state->fb_changed) | |
13586 | return true; | |
13587 | ||
13588 | /* wm changes, need vblank before final wm's */ | |
13589 | if (crtc_state->wm_changed) | |
13590 | return true; | |
13591 | ||
13592 | /* | |
13593 | * cxsr is re-enabled after vblank. | |
13594 | * This is already handled by crtc_state->wm_changed, | |
13595 | * but added for clarity. | |
13596 | */ | |
13597 | if (crtc_state->disable_cxsr) | |
13598 | return true; | |
13599 | ||
13600 | return false; | |
13601 | } | |
13602 | ||
13603 | /** | |
13604 | * intel_atomic_commit - commit validated state object | |
13605 | * @dev: DRM device | |
13606 | * @state: the top-level driver state object | |
13607 | * @async: asynchronous commit | |
13608 | * | |
13609 | * This function commits a top-level state object that has been validated | |
13610 | * with drm_atomic_helper_check(). | |
13611 | * | |
13612 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13613 | * we can only handle plane-related operations and do not yet support | |
13614 | * asynchronous commit. | |
13615 | * | |
13616 | * RETURNS | |
13617 | * Zero for success or -errno. | |
13618 | */ | |
13619 | static int intel_atomic_commit(struct drm_device *dev, | |
13620 | struct drm_atomic_state *state, | |
13621 | bool async) | |
13622 | { | |
13623 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13624 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13625 | struct drm_crtc_state *crtc_state; | |
13626 | struct drm_crtc *crtc; | |
13627 | struct intel_crtc_state *intel_cstate; | |
13628 | int ret = 0, i; | |
13629 | bool hw_check = intel_state->modeset; | |
13630 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
13631 | unsigned crtc_vblank_mask = 0; | |
13632 | ||
13633 | ret = intel_atomic_prepare_commit(dev, state, async); | |
13634 | if (ret) { | |
13635 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
13636 | return ret; | |
13637 | } | |
13638 | ||
13639 | drm_atomic_helper_swap_state(dev, state); | |
13640 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; | |
13641 | ||
13642 | if (intel_state->modeset) { | |
13643 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, | |
13644 | sizeof(intel_state->min_pixclk)); | |
13645 | dev_priv->active_crtcs = intel_state->active_crtcs; | |
13646 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; | |
13647 | ||
13648 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); | |
13649 | } | |
13650 | ||
13651 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13652 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13653 | ||
13654 | if (needs_modeset(crtc->state) || | |
13655 | to_intel_crtc_state(crtc->state)->update_pipe) { | |
13656 | hw_check = true; | |
13657 | ||
13658 | put_domains[to_intel_crtc(crtc)->pipe] = | |
13659 | modeset_get_crtc_power_domains(crtc, | |
13660 | to_intel_crtc_state(crtc->state)); | |
13661 | } | |
13662 | ||
13663 | if (!needs_modeset(crtc->state)) | |
13664 | continue; | |
13665 | ||
13666 | intel_pre_plane_update(to_intel_crtc_state(crtc_state)); | |
13667 | ||
13668 | if (crtc_state->active) { | |
13669 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13670 | dev_priv->display.crtc_disable(crtc); | |
13671 | intel_crtc->active = false; | |
13672 | intel_fbc_disable(intel_crtc); | |
13673 | intel_disable_shared_dpll(intel_crtc); | |
13674 | ||
13675 | /* | |
13676 | * Underruns don't always raise | |
13677 | * interrupts, so check manually. | |
13678 | */ | |
13679 | intel_check_cpu_fifo_underruns(dev_priv); | |
13680 | intel_check_pch_fifo_underruns(dev_priv); | |
13681 | ||
13682 | if (!crtc->state->active) | |
13683 | intel_update_watermarks(crtc); | |
13684 | } | |
13685 | } | |
13686 | ||
13687 | /* Only after disabling all output pipelines that will be changed can we | |
13688 | * update the the output configuration. */ | |
13689 | intel_modeset_update_crtc_state(state); | |
13690 | ||
13691 | if (intel_state->modeset) { | |
13692 | intel_shared_dpll_commit(state); | |
13693 | ||
13694 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
13695 | ||
13696 | if (dev_priv->display.modeset_commit_cdclk && | |
13697 | intel_state->dev_cdclk != dev_priv->cdclk_freq) | |
13698 | dev_priv->display.modeset_commit_cdclk(state); | |
13699 | } | |
13700 | ||
13701 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ | |
13702 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13703 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13704 | bool modeset = needs_modeset(crtc->state); | |
13705 | struct intel_crtc_state *pipe_config = | |
13706 | to_intel_crtc_state(crtc->state); | |
13707 | bool update_pipe = !modeset && pipe_config->update_pipe; | |
13708 | ||
13709 | if (modeset && crtc->state->active) { | |
13710 | update_scanline_offset(to_intel_crtc(crtc)); | |
13711 | dev_priv->display.crtc_enable(crtc); | |
13712 | } | |
13713 | ||
13714 | if (!modeset) | |
13715 | intel_pre_plane_update(to_intel_crtc_state(crtc_state)); | |
13716 | ||
13717 | if (crtc->state->active && intel_crtc->atomic.update_fbc) | |
13718 | intel_fbc_enable(intel_crtc); | |
13719 | ||
13720 | if (crtc->state->active && | |
13721 | (crtc->state->planes_changed || update_pipe)) | |
13722 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); | |
13723 | ||
13724 | if (pipe_config->base.active && needs_vblank_wait(pipe_config)) | |
13725 | crtc_vblank_mask |= 1 << i; | |
13726 | } | |
13727 | ||
13728 | /* FIXME: add subpixel order */ | |
13729 | ||
13730 | if (!state->legacy_cursor_update) | |
13731 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); | |
13732 | ||
13733 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13734 | intel_post_plane_update(to_intel_crtc(crtc)); | |
13735 | ||
13736 | if (put_domains[i]) | |
13737 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
13738 | } | |
13739 | ||
13740 | if (intel_state->modeset) | |
13741 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); | |
13742 | ||
13743 | /* | |
13744 | * Now that the vblank has passed, we can go ahead and program the | |
13745 | * optimal watermarks on platforms that need two-step watermark | |
13746 | * programming. | |
13747 | * | |
13748 | * TODO: Move this (and other cleanup) to an async worker eventually. | |
13749 | */ | |
13750 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13751 | intel_cstate = to_intel_crtc_state(crtc->state); | |
13752 | ||
13753 | if (dev_priv->display.optimize_watermarks) | |
13754 | dev_priv->display.optimize_watermarks(intel_cstate); | |
13755 | } | |
13756 | ||
13757 | mutex_lock(&dev->struct_mutex); | |
13758 | drm_atomic_helper_cleanup_planes(dev, state); | |
13759 | mutex_unlock(&dev->struct_mutex); | |
13760 | ||
13761 | if (hw_check) | |
13762 | intel_modeset_check_state(dev, state); | |
13763 | ||
13764 | drm_atomic_state_free(state); | |
13765 | ||
13766 | /* As one of the primary mmio accessors, KMS has a high likelihood | |
13767 | * of triggering bugs in unclaimed access. After we finish | |
13768 | * modesetting, see if an error has been flagged, and if so | |
13769 | * enable debugging for the next modeset - and hope we catch | |
13770 | * the culprit. | |
13771 | * | |
13772 | * XXX note that we assume display power is on at this point. | |
13773 | * This might hold true now but we need to add pm helper to check | |
13774 | * unclaimed only when the hardware is on, as atomic commits | |
13775 | * can happen also when the device is completely off. | |
13776 | */ | |
13777 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); | |
13778 | ||
13779 | return 0; | |
13780 | } | |
13781 | ||
13782 | void intel_crtc_restore_mode(struct drm_crtc *crtc) | |
13783 | { | |
13784 | struct drm_device *dev = crtc->dev; | |
13785 | struct drm_atomic_state *state; | |
13786 | struct drm_crtc_state *crtc_state; | |
13787 | int ret; | |
13788 | ||
13789 | state = drm_atomic_state_alloc(dev); | |
13790 | if (!state) { | |
13791 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", | |
13792 | crtc->base.id); | |
13793 | return; | |
13794 | } | |
13795 | ||
13796 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
13797 | ||
13798 | retry: | |
13799 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13800 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13801 | if (!ret) { | |
13802 | if (!crtc_state->active) | |
13803 | goto out; | |
13804 | ||
13805 | crtc_state->mode_changed = true; | |
13806 | ret = drm_atomic_commit(state); | |
13807 | } | |
13808 | ||
13809 | if (ret == -EDEADLK) { | |
13810 | drm_atomic_state_clear(state); | |
13811 | drm_modeset_backoff(state->acquire_ctx); | |
13812 | goto retry; | |
13813 | } | |
13814 | ||
13815 | if (ret) | |
13816 | out: | |
13817 | drm_atomic_state_free(state); | |
13818 | } | |
13819 | ||
13820 | #undef for_each_intel_crtc_masked | |
13821 | ||
13822 | static const struct drm_crtc_funcs intel_crtc_funcs = { | |
13823 | .gamma_set = intel_crtc_gamma_set, | |
13824 | .set_config = drm_atomic_helper_set_config, | |
13825 | .destroy = intel_crtc_destroy, | |
13826 | .page_flip = intel_crtc_page_flip, | |
13827 | .atomic_duplicate_state = intel_crtc_duplicate_state, | |
13828 | .atomic_destroy_state = intel_crtc_destroy_state, | |
13829 | }; | |
13830 | ||
13831 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, | |
13832 | struct intel_shared_dpll *pll, | |
13833 | struct intel_dpll_hw_state *hw_state) | |
13834 | { | |
13835 | uint32_t val; | |
13836 | ||
13837 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_PLLS)) | |
13838 | return false; | |
13839 | ||
13840 | val = I915_READ(PCH_DPLL(pll->id)); | |
13841 | hw_state->dpll = val; | |
13842 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13843 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
13844 | ||
13845 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
13846 | ||
13847 | return val & DPLL_VCO_ENABLE; | |
13848 | } | |
13849 | ||
13850 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, | |
13851 | struct intel_shared_dpll *pll) | |
13852 | { | |
13853 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); | |
13854 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
13855 | } | |
13856 | ||
13857 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, | |
13858 | struct intel_shared_dpll *pll) | |
13859 | { | |
13860 | /* PCH refclock must be enabled first */ | |
13861 | ibx_assert_pch_refclk_enabled(dev_priv); | |
13862 | ||
13863 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); | |
13864 | ||
13865 | /* Wait for the clocks to stabilize. */ | |
13866 | POSTING_READ(PCH_DPLL(pll->id)); | |
13867 | udelay(150); | |
13868 | ||
13869 | /* The pixel multiplier can only be updated once the | |
13870 | * DPLL is enabled and the clocks are stable. | |
13871 | * | |
13872 | * So write it again. | |
13873 | */ | |
13874 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); | |
13875 | POSTING_READ(PCH_DPLL(pll->id)); | |
13876 | udelay(200); | |
13877 | } | |
13878 | ||
13879 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13880 | struct intel_shared_dpll *pll) | |
13881 | { | |
13882 | struct drm_device *dev = dev_priv->dev; | |
13883 | struct intel_crtc *crtc; | |
13884 | ||
13885 | /* Make sure no transcoder isn't still depending on us. */ | |
13886 | for_each_intel_crtc(dev, crtc) { | |
13887 | if (intel_crtc_to_shared_dpll(crtc) == pll) | |
13888 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
13889 | } | |
13890 | ||
13891 | I915_WRITE(PCH_DPLL(pll->id), 0); | |
13892 | POSTING_READ(PCH_DPLL(pll->id)); | |
13893 | udelay(200); | |
13894 | } | |
13895 | ||
13896 | static char *ibx_pch_dpll_names[] = { | |
13897 | "PCH DPLL A", | |
13898 | "PCH DPLL B", | |
13899 | }; | |
13900 | ||
13901 | static void ibx_pch_dpll_init(struct drm_device *dev) | |
13902 | { | |
13903 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13904 | int i; | |
13905 | ||
13906 | dev_priv->num_shared_dpll = 2; | |
13907 | ||
13908 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
13909 | dev_priv->shared_dplls[i].id = i; | |
13910 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
13911 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; | |
13912 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; | |
13913 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
13914 | dev_priv->shared_dplls[i].get_hw_state = | |
13915 | ibx_pch_dpll_get_hw_state; | |
13916 | } | |
13917 | } | |
13918 | ||
13919 | static void intel_shared_dpll_init(struct drm_device *dev) | |
13920 | { | |
13921 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13922 | ||
13923 | if (HAS_DDI(dev)) | |
13924 | intel_ddi_pll_init(dev); | |
13925 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
13926 | ibx_pch_dpll_init(dev); | |
13927 | else | |
13928 | dev_priv->num_shared_dpll = 0; | |
13929 | ||
13930 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
13931 | } | |
13932 | ||
13933 | /** | |
13934 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13935 | * @plane: drm plane to prepare for | |
13936 | * @fb: framebuffer to prepare for presentation | |
13937 | * | |
13938 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13939 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13940 | * bits. Some older platforms need special physical address handling for | |
13941 | * cursor planes. | |
13942 | * | |
13943 | * Must be called with struct_mutex held. | |
13944 | * | |
13945 | * Returns 0 on success, negative error code on failure. | |
13946 | */ | |
13947 | int | |
13948 | intel_prepare_plane_fb(struct drm_plane *plane, | |
13949 | const struct drm_plane_state *new_state) | |
13950 | { | |
13951 | struct drm_device *dev = plane->dev; | |
13952 | struct drm_framebuffer *fb = new_state->fb; | |
13953 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13954 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
13955 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); | |
13956 | int ret = 0; | |
13957 | ||
13958 | if (!obj && !old_obj) | |
13959 | return 0; | |
13960 | ||
13961 | if (old_obj) { | |
13962 | struct drm_crtc_state *crtc_state = | |
13963 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13964 | ||
13965 | /* Big Hammer, we also need to ensure that any pending | |
13966 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13967 | * current scanout is retired before unpinning the old | |
13968 | * framebuffer. Note that we rely on userspace rendering | |
13969 | * into the buffer attached to the pipe they are waiting | |
13970 | * on. If not, userspace generates a GPU hang with IPEHR | |
13971 | * point to the MI_WAIT_FOR_EVENT. | |
13972 | * | |
13973 | * This should only fail upon a hung GPU, in which case we | |
13974 | * can safely continue. | |
13975 | */ | |
13976 | if (needs_modeset(crtc_state)) | |
13977 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13978 | ||
13979 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13980 | if (ret && ret != -EIO) | |
13981 | return ret; | |
13982 | } | |
13983 | ||
13984 | /* For framebuffer backed by dmabuf, wait for fence */ | |
13985 | if (obj && obj->base.dma_buf) { | |
13986 | long lret; | |
13987 | ||
13988 | lret = reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, | |
13989 | false, true, | |
13990 | MAX_SCHEDULE_TIMEOUT); | |
13991 | if (lret == -ERESTARTSYS) | |
13992 | return lret; | |
13993 | ||
13994 | WARN(lret < 0, "waiting returns %li\n", lret); | |
13995 | } | |
13996 | ||
13997 | if (!obj) { | |
13998 | ret = 0; | |
13999 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
14000 | INTEL_INFO(dev)->cursor_needs_physical) { | |
14001 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
14002 | ret = i915_gem_object_attach_phys(obj, align); | |
14003 | if (ret) | |
14004 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
14005 | } else { | |
14006 | ret = intel_pin_and_fence_fb_obj(fb, new_state->rotation); | |
14007 | } | |
14008 | ||
14009 | if (ret == 0) { | |
14010 | if (obj) { | |
14011 | struct intel_plane_state *plane_state = | |
14012 | to_intel_plane_state(new_state); | |
14013 | ||
14014 | i915_gem_request_assign(&plane_state->wait_req, | |
14015 | obj->last_write_req); | |
14016 | } | |
14017 | ||
14018 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
14019 | } | |
14020 | ||
14021 | return ret; | |
14022 | } | |
14023 | ||
14024 | /** | |
14025 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
14026 | * @plane: drm plane to clean up for | |
14027 | * @fb: old framebuffer that was on plane | |
14028 | * | |
14029 | * Cleans up a framebuffer that has just been removed from a plane. | |
14030 | * | |
14031 | * Must be called with struct_mutex held. | |
14032 | */ | |
14033 | void | |
14034 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
14035 | const struct drm_plane_state *old_state) | |
14036 | { | |
14037 | struct drm_device *dev = plane->dev; | |
14038 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
14039 | struct intel_plane_state *old_intel_state; | |
14040 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); | |
14041 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
14042 | ||
14043 | old_intel_state = to_intel_plane_state(old_state); | |
14044 | ||
14045 | if (!obj && !old_obj) | |
14046 | return; | |
14047 | ||
14048 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || | |
14049 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
14050 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); | |
14051 | ||
14052 | /* prepare_fb aborted? */ | |
14053 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
14054 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
14055 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
14056 | ||
14057 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
14058 | } | |
14059 | ||
14060 | int | |
14061 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
14062 | { | |
14063 | int max_scale; | |
14064 | struct drm_device *dev; | |
14065 | struct drm_i915_private *dev_priv; | |
14066 | int crtc_clock, cdclk; | |
14067 | ||
14068 | if (!intel_crtc || !crtc_state->base.enable) | |
14069 | return DRM_PLANE_HELPER_NO_SCALING; | |
14070 | ||
14071 | dev = intel_crtc->base.dev; | |
14072 | dev_priv = dev->dev_private; | |
14073 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
14074 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; | |
14075 | ||
14076 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) | |
14077 | return DRM_PLANE_HELPER_NO_SCALING; | |
14078 | ||
14079 | /* | |
14080 | * skl max scale is lower of: | |
14081 | * close to 3 but not 3, -1 is for that purpose | |
14082 | * or | |
14083 | * cdclk/crtc_clock | |
14084 | */ | |
14085 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
14086 | ||
14087 | return max_scale; | |
14088 | } | |
14089 | ||
14090 | static int | |
14091 | intel_check_primary_plane(struct drm_plane *plane, | |
14092 | struct intel_crtc_state *crtc_state, | |
14093 | struct intel_plane_state *state) | |
14094 | { | |
14095 | struct drm_crtc *crtc = state->base.crtc; | |
14096 | struct drm_framebuffer *fb = state->base.fb; | |
14097 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; | |
14098 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; | |
14099 | bool can_position = false; | |
14100 | ||
14101 | if (INTEL_INFO(plane->dev)->gen >= 9) { | |
14102 | /* use scaler when colorkey is not required */ | |
14103 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { | |
14104 | min_scale = 1; | |
14105 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
14106 | } | |
14107 | can_position = true; | |
14108 | } | |
14109 | ||
14110 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, | |
14111 | &state->dst, &state->clip, | |
14112 | min_scale, max_scale, | |
14113 | can_position, true, | |
14114 | &state->visible); | |
14115 | } | |
14116 | ||
14117 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, | |
14118 | struct drm_crtc_state *old_crtc_state) | |
14119 | { | |
14120 | struct drm_device *dev = crtc->dev; | |
14121 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
14122 | struct intel_crtc_state *old_intel_state = | |
14123 | to_intel_crtc_state(old_crtc_state); | |
14124 | bool modeset = needs_modeset(crtc->state); | |
14125 | ||
14126 | /* Perform vblank evasion around commit operation */ | |
14127 | intel_pipe_update_start(intel_crtc); | |
14128 | ||
14129 | if (modeset) | |
14130 | return; | |
14131 | ||
14132 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
14133 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
14134 | else if (INTEL_INFO(dev)->gen >= 9) | |
14135 | skl_detach_scalers(intel_crtc); | |
14136 | } | |
14137 | ||
14138 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, | |
14139 | struct drm_crtc_state *old_crtc_state) | |
14140 | { | |
14141 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
14142 | ||
14143 | intel_pipe_update_end(intel_crtc); | |
14144 | } | |
14145 | ||
14146 | /** | |
14147 | * intel_plane_destroy - destroy a plane | |
14148 | * @plane: plane to destroy | |
14149 | * | |
14150 | * Common destruction function for all types of planes (primary, cursor, | |
14151 | * sprite). | |
14152 | */ | |
14153 | void intel_plane_destroy(struct drm_plane *plane) | |
14154 | { | |
14155 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
14156 | drm_plane_cleanup(plane); | |
14157 | kfree(intel_plane); | |
14158 | } | |
14159 | ||
14160 | const struct drm_plane_funcs intel_plane_funcs = { | |
14161 | .update_plane = drm_atomic_helper_update_plane, | |
14162 | .disable_plane = drm_atomic_helper_disable_plane, | |
14163 | .destroy = intel_plane_destroy, | |
14164 | .set_property = drm_atomic_helper_plane_set_property, | |
14165 | .atomic_get_property = intel_plane_atomic_get_property, | |
14166 | .atomic_set_property = intel_plane_atomic_set_property, | |
14167 | .atomic_duplicate_state = intel_plane_duplicate_state, | |
14168 | .atomic_destroy_state = intel_plane_destroy_state, | |
14169 | ||
14170 | }; | |
14171 | ||
14172 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
14173 | int pipe) | |
14174 | { | |
14175 | struct intel_plane *primary; | |
14176 | struct intel_plane_state *state; | |
14177 | const uint32_t *intel_primary_formats; | |
14178 | unsigned int num_formats; | |
14179 | ||
14180 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
14181 | if (primary == NULL) | |
14182 | return NULL; | |
14183 | ||
14184 | state = intel_create_plane_state(&primary->base); | |
14185 | if (!state) { | |
14186 | kfree(primary); | |
14187 | return NULL; | |
14188 | } | |
14189 | primary->base.state = &state->base; | |
14190 | ||
14191 | primary->can_scale = false; | |
14192 | primary->max_downscale = 1; | |
14193 | if (INTEL_INFO(dev)->gen >= 9) { | |
14194 | primary->can_scale = true; | |
14195 | state->scaler_id = -1; | |
14196 | } | |
14197 | primary->pipe = pipe; | |
14198 | primary->plane = pipe; | |
14199 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); | |
14200 | primary->check_plane = intel_check_primary_plane; | |
14201 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) | |
14202 | primary->plane = !pipe; | |
14203 | ||
14204 | if (INTEL_INFO(dev)->gen >= 9) { | |
14205 | intel_primary_formats = skl_primary_formats; | |
14206 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
14207 | ||
14208 | primary->update_plane = skylake_update_primary_plane; | |
14209 | primary->disable_plane = skylake_disable_primary_plane; | |
14210 | } else if (HAS_PCH_SPLIT(dev)) { | |
14211 | intel_primary_formats = i965_primary_formats; | |
14212 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
14213 | ||
14214 | primary->update_plane = ironlake_update_primary_plane; | |
14215 | primary->disable_plane = i9xx_disable_primary_plane; | |
14216 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
14217 | intel_primary_formats = i965_primary_formats; | |
14218 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
14219 | ||
14220 | primary->update_plane = i9xx_update_primary_plane; | |
14221 | primary->disable_plane = i9xx_disable_primary_plane; | |
14222 | } else { | |
14223 | intel_primary_formats = i8xx_primary_formats; | |
14224 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
14225 | ||
14226 | primary->update_plane = i9xx_update_primary_plane; | |
14227 | primary->disable_plane = i9xx_disable_primary_plane; | |
14228 | } | |
14229 | ||
14230 | drm_universal_plane_init(dev, &primary->base, 0, | |
14231 | &intel_plane_funcs, | |
14232 | intel_primary_formats, num_formats, | |
14233 | DRM_PLANE_TYPE_PRIMARY, NULL); | |
14234 | ||
14235 | if (INTEL_INFO(dev)->gen >= 4) | |
14236 | intel_create_rotation_property(dev, primary); | |
14237 | ||
14238 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); | |
14239 | ||
14240 | return &primary->base; | |
14241 | } | |
14242 | ||
14243 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) | |
14244 | { | |
14245 | if (!dev->mode_config.rotation_property) { | |
14246 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
14247 | BIT(DRM_ROTATE_180); | |
14248 | ||
14249 | if (INTEL_INFO(dev)->gen >= 9) | |
14250 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
14251 | ||
14252 | dev->mode_config.rotation_property = | |
14253 | drm_mode_create_rotation_property(dev, flags); | |
14254 | } | |
14255 | if (dev->mode_config.rotation_property) | |
14256 | drm_object_attach_property(&plane->base.base, | |
14257 | dev->mode_config.rotation_property, | |
14258 | plane->base.state->rotation); | |
14259 | } | |
14260 | ||
14261 | static int | |
14262 | intel_check_cursor_plane(struct drm_plane *plane, | |
14263 | struct intel_crtc_state *crtc_state, | |
14264 | struct intel_plane_state *state) | |
14265 | { | |
14266 | struct drm_crtc *crtc = crtc_state->base.crtc; | |
14267 | struct drm_framebuffer *fb = state->base.fb; | |
14268 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
14269 | enum pipe pipe = to_intel_plane(plane)->pipe; | |
14270 | unsigned stride; | |
14271 | int ret; | |
14272 | ||
14273 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, | |
14274 | &state->dst, &state->clip, | |
14275 | DRM_PLANE_HELPER_NO_SCALING, | |
14276 | DRM_PLANE_HELPER_NO_SCALING, | |
14277 | true, true, &state->visible); | |
14278 | if (ret) | |
14279 | return ret; | |
14280 | ||
14281 | /* if we want to turn off the cursor ignore width and height */ | |
14282 | if (!obj) | |
14283 | return 0; | |
14284 | ||
14285 | /* Check for which cursor types we support */ | |
14286 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { | |
14287 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", | |
14288 | state->base.crtc_w, state->base.crtc_h); | |
14289 | return -EINVAL; | |
14290 | } | |
14291 | ||
14292 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; | |
14293 | if (obj->base.size < stride * state->base.crtc_h) { | |
14294 | DRM_DEBUG_KMS("buffer is too small\n"); | |
14295 | return -ENOMEM; | |
14296 | } | |
14297 | ||
14298 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { | |
14299 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); | |
14300 | return -EINVAL; | |
14301 | } | |
14302 | ||
14303 | /* | |
14304 | * There's something wrong with the cursor on CHV pipe C. | |
14305 | * If it straddles the left edge of the screen then | |
14306 | * moving it away from the edge or disabling it often | |
14307 | * results in a pipe underrun, and often that can lead to | |
14308 | * dead pipe (constant underrun reported, and it scans | |
14309 | * out just a solid color). To recover from that, the | |
14310 | * display power well must be turned off and on again. | |
14311 | * Refuse the put the cursor into that compromised position. | |
14312 | */ | |
14313 | if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C && | |
14314 | state->visible && state->base.crtc_x < 0) { | |
14315 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); | |
14316 | return -EINVAL; | |
14317 | } | |
14318 | ||
14319 | return 0; | |
14320 | } | |
14321 | ||
14322 | static void | |
14323 | intel_disable_cursor_plane(struct drm_plane *plane, | |
14324 | struct drm_crtc *crtc) | |
14325 | { | |
14326 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
14327 | ||
14328 | intel_crtc->cursor_addr = 0; | |
14329 | intel_crtc_update_cursor(crtc, NULL); | |
14330 | } | |
14331 | ||
14332 | static void | |
14333 | intel_update_cursor_plane(struct drm_plane *plane, | |
14334 | const struct intel_crtc_state *crtc_state, | |
14335 | const struct intel_plane_state *state) | |
14336 | { | |
14337 | struct drm_crtc *crtc = crtc_state->base.crtc; | |
14338 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
14339 | struct drm_device *dev = plane->dev; | |
14340 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); | |
14341 | uint32_t addr; | |
14342 | ||
14343 | if (!obj) | |
14344 | addr = 0; | |
14345 | else if (!INTEL_INFO(dev)->cursor_needs_physical) | |
14346 | addr = i915_gem_obj_ggtt_offset(obj); | |
14347 | else | |
14348 | addr = obj->phys_handle->busaddr; | |
14349 | ||
14350 | intel_crtc->cursor_addr = addr; | |
14351 | intel_crtc_update_cursor(crtc, state); | |
14352 | } | |
14353 | ||
14354 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, | |
14355 | int pipe) | |
14356 | { | |
14357 | struct intel_plane *cursor; | |
14358 | struct intel_plane_state *state; | |
14359 | ||
14360 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
14361 | if (cursor == NULL) | |
14362 | return NULL; | |
14363 | ||
14364 | state = intel_create_plane_state(&cursor->base); | |
14365 | if (!state) { | |
14366 | kfree(cursor); | |
14367 | return NULL; | |
14368 | } | |
14369 | cursor->base.state = &state->base; | |
14370 | ||
14371 | cursor->can_scale = false; | |
14372 | cursor->max_downscale = 1; | |
14373 | cursor->pipe = pipe; | |
14374 | cursor->plane = pipe; | |
14375 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); | |
14376 | cursor->check_plane = intel_check_cursor_plane; | |
14377 | cursor->update_plane = intel_update_cursor_plane; | |
14378 | cursor->disable_plane = intel_disable_cursor_plane; | |
14379 | ||
14380 | drm_universal_plane_init(dev, &cursor->base, 0, | |
14381 | &intel_plane_funcs, | |
14382 | intel_cursor_formats, | |
14383 | ARRAY_SIZE(intel_cursor_formats), | |
14384 | DRM_PLANE_TYPE_CURSOR, NULL); | |
14385 | ||
14386 | if (INTEL_INFO(dev)->gen >= 4) { | |
14387 | if (!dev->mode_config.rotation_property) | |
14388 | dev->mode_config.rotation_property = | |
14389 | drm_mode_create_rotation_property(dev, | |
14390 | BIT(DRM_ROTATE_0) | | |
14391 | BIT(DRM_ROTATE_180)); | |
14392 | if (dev->mode_config.rotation_property) | |
14393 | drm_object_attach_property(&cursor->base.base, | |
14394 | dev->mode_config.rotation_property, | |
14395 | state->base.rotation); | |
14396 | } | |
14397 | ||
14398 | if (INTEL_INFO(dev)->gen >=9) | |
14399 | state->scaler_id = -1; | |
14400 | ||
14401 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); | |
14402 | ||
14403 | return &cursor->base; | |
14404 | } | |
14405 | ||
14406 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, | |
14407 | struct intel_crtc_state *crtc_state) | |
14408 | { | |
14409 | int i; | |
14410 | struct intel_scaler *intel_scaler; | |
14411 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14412 | ||
14413 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14414 | intel_scaler = &scaler_state->scalers[i]; | |
14415 | intel_scaler->in_use = 0; | |
14416 | intel_scaler->mode = PS_SCALER_MODE_DYN; | |
14417 | } | |
14418 | ||
14419 | scaler_state->scaler_id = -1; | |
14420 | } | |
14421 | ||
14422 | static void intel_crtc_init(struct drm_device *dev, int pipe) | |
14423 | { | |
14424 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14425 | struct intel_crtc *intel_crtc; | |
14426 | struct intel_crtc_state *crtc_state = NULL; | |
14427 | struct drm_plane *primary = NULL; | |
14428 | struct drm_plane *cursor = NULL; | |
14429 | int i, ret; | |
14430 | ||
14431 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); | |
14432 | if (intel_crtc == NULL) | |
14433 | return; | |
14434 | ||
14435 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); | |
14436 | if (!crtc_state) | |
14437 | goto fail; | |
14438 | intel_crtc->config = crtc_state; | |
14439 | intel_crtc->base.state = &crtc_state->base; | |
14440 | crtc_state->base.crtc = &intel_crtc->base; | |
14441 | ||
14442 | /* initialize shared scalers */ | |
14443 | if (INTEL_INFO(dev)->gen >= 9) { | |
14444 | if (pipe == PIPE_C) | |
14445 | intel_crtc->num_scalers = 1; | |
14446 | else | |
14447 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14448 | ||
14449 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14450 | } | |
14451 | ||
14452 | primary = intel_primary_plane_create(dev, pipe); | |
14453 | if (!primary) | |
14454 | goto fail; | |
14455 | ||
14456 | cursor = intel_cursor_plane_create(dev, pipe); | |
14457 | if (!cursor) | |
14458 | goto fail; | |
14459 | ||
14460 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, | |
14461 | cursor, &intel_crtc_funcs, NULL); | |
14462 | if (ret) | |
14463 | goto fail; | |
14464 | ||
14465 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
14466 | for (i = 0; i < 256; i++) { | |
14467 | intel_crtc->lut_r[i] = i; | |
14468 | intel_crtc->lut_g[i] = i; | |
14469 | intel_crtc->lut_b[i] = i; | |
14470 | } | |
14471 | ||
14472 | /* | |
14473 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
14474 | * is hooked to pipe B. Hence we want plane A feeding pipe B. | |
14475 | */ | |
14476 | intel_crtc->pipe = pipe; | |
14477 | intel_crtc->plane = pipe; | |
14478 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { | |
14479 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); | |
14480 | intel_crtc->plane = !pipe; | |
14481 | } | |
14482 | ||
14483 | intel_crtc->cursor_base = ~0; | |
14484 | intel_crtc->cursor_cntl = ~0; | |
14485 | intel_crtc->cursor_size = ~0; | |
14486 | ||
14487 | intel_crtc->wm.cxsr_allowed = true; | |
14488 | ||
14489 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || | |
14490 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14491 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14492 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14493 | ||
14494 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); | |
14495 | ||
14496 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
14497 | return; | |
14498 | ||
14499 | fail: | |
14500 | if (primary) | |
14501 | drm_plane_cleanup(primary); | |
14502 | if (cursor) | |
14503 | drm_plane_cleanup(cursor); | |
14504 | kfree(crtc_state); | |
14505 | kfree(intel_crtc); | |
14506 | } | |
14507 | ||
14508 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) | |
14509 | { | |
14510 | struct drm_encoder *encoder = connector->base.encoder; | |
14511 | struct drm_device *dev = connector->base.dev; | |
14512 | ||
14513 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); | |
14514 | ||
14515 | if (!encoder || WARN_ON(!encoder->crtc)) | |
14516 | return INVALID_PIPE; | |
14517 | ||
14518 | return to_intel_crtc(encoder->crtc)->pipe; | |
14519 | } | |
14520 | ||
14521 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, | |
14522 | struct drm_file *file) | |
14523 | { | |
14524 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; | |
14525 | struct drm_crtc *drmmode_crtc; | |
14526 | struct intel_crtc *crtc; | |
14527 | ||
14528 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); | |
14529 | ||
14530 | if (!drmmode_crtc) { | |
14531 | DRM_ERROR("no such CRTC id\n"); | |
14532 | return -ENOENT; | |
14533 | } | |
14534 | ||
14535 | crtc = to_intel_crtc(drmmode_crtc); | |
14536 | pipe_from_crtc_id->pipe = crtc->pipe; | |
14537 | ||
14538 | return 0; | |
14539 | } | |
14540 | ||
14541 | static int intel_encoder_clones(struct intel_encoder *encoder) | |
14542 | { | |
14543 | struct drm_device *dev = encoder->base.dev; | |
14544 | struct intel_encoder *source_encoder; | |
14545 | int index_mask = 0; | |
14546 | int entry = 0; | |
14547 | ||
14548 | for_each_intel_encoder(dev, source_encoder) { | |
14549 | if (encoders_cloneable(encoder, source_encoder)) | |
14550 | index_mask |= (1 << entry); | |
14551 | ||
14552 | entry++; | |
14553 | } | |
14554 | ||
14555 | return index_mask; | |
14556 | } | |
14557 | ||
14558 | static bool has_edp_a(struct drm_device *dev) | |
14559 | { | |
14560 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14561 | ||
14562 | if (!IS_MOBILE(dev)) | |
14563 | return false; | |
14564 | ||
14565 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14566 | return false; | |
14567 | ||
14568 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) | |
14569 | return false; | |
14570 | ||
14571 | return true; | |
14572 | } | |
14573 | ||
14574 | static bool intel_crt_present(struct drm_device *dev) | |
14575 | { | |
14576 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14577 | ||
14578 | if (INTEL_INFO(dev)->gen >= 9) | |
14579 | return false; | |
14580 | ||
14581 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) | |
14582 | return false; | |
14583 | ||
14584 | if (IS_CHERRYVIEW(dev)) | |
14585 | return false; | |
14586 | ||
14587 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) | |
14588 | return false; | |
14589 | ||
14590 | /* DDI E can't be used if DDI A requires 4 lanes */ | |
14591 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) | |
14592 | return false; | |
14593 | ||
14594 | if (!dev_priv->vbt.int_crt_support) | |
14595 | return false; | |
14596 | ||
14597 | return true; | |
14598 | } | |
14599 | ||
14600 | static void intel_setup_outputs(struct drm_device *dev) | |
14601 | { | |
14602 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14603 | struct intel_encoder *encoder; | |
14604 | bool dpd_is_edp = false; | |
14605 | ||
14606 | intel_lvds_init(dev); | |
14607 | ||
14608 | if (intel_crt_present(dev)) | |
14609 | intel_crt_init(dev); | |
14610 | ||
14611 | if (IS_BROXTON(dev)) { | |
14612 | /* | |
14613 | * FIXME: Broxton doesn't support port detection via the | |
14614 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14615 | * detect the ports. | |
14616 | */ | |
14617 | intel_ddi_init(dev, PORT_A); | |
14618 | intel_ddi_init(dev, PORT_B); | |
14619 | intel_ddi_init(dev, PORT_C); | |
14620 | } else if (HAS_DDI(dev)) { | |
14621 | int found; | |
14622 | ||
14623 | /* | |
14624 | * Haswell uses DDI functions to detect digital outputs. | |
14625 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14626 | * it's there. | |
14627 | */ | |
14628 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; | |
14629 | /* WaIgnoreDDIAStrap: skl */ | |
14630 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) | |
14631 | intel_ddi_init(dev, PORT_A); | |
14632 | ||
14633 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14634 | * register */ | |
14635 | found = I915_READ(SFUSE_STRAP); | |
14636 | ||
14637 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14638 | intel_ddi_init(dev, PORT_B); | |
14639 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14640 | intel_ddi_init(dev, PORT_C); | |
14641 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14642 | intel_ddi_init(dev, PORT_D); | |
14643 | /* | |
14644 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14645 | */ | |
14646 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && | |
14647 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || | |
14648 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14649 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14650 | intel_ddi_init(dev, PORT_E); | |
14651 | ||
14652 | } else if (HAS_PCH_SPLIT(dev)) { | |
14653 | int found; | |
14654 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); | |
14655 | ||
14656 | if (has_edp_a(dev)) | |
14657 | intel_dp_init(dev, DP_A, PORT_A); | |
14658 | ||
14659 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { | |
14660 | /* PCH SDVOB multiplex with HDMIB */ | |
14661 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); | |
14662 | if (!found) | |
14663 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); | |
14664 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) | |
14665 | intel_dp_init(dev, PCH_DP_B, PORT_B); | |
14666 | } | |
14667 | ||
14668 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) | |
14669 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); | |
14670 | ||
14671 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) | |
14672 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); | |
14673 | ||
14674 | if (I915_READ(PCH_DP_C) & DP_DETECTED) | |
14675 | intel_dp_init(dev, PCH_DP_C, PORT_C); | |
14676 | ||
14677 | if (I915_READ(PCH_DP_D) & DP_DETECTED) | |
14678 | intel_dp_init(dev, PCH_DP_D, PORT_D); | |
14679 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
14680 | /* | |
14681 | * The DP_DETECTED bit is the latched state of the DDC | |
14682 | * SDA pin at boot. However since eDP doesn't require DDC | |
14683 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14684 | * eDP ports may have been muxed to an alternate function. | |
14685 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14686 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14687 | * detect eDP ports. | |
14688 | */ | |
14689 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && | |
14690 | !intel_dp_is_edp(dev, PORT_B)) | |
14691 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); | |
14692 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
14693 | intel_dp_is_edp(dev, PORT_B)) | |
14694 | intel_dp_init(dev, VLV_DP_B, PORT_B); | |
14695 | ||
14696 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && | |
14697 | !intel_dp_is_edp(dev, PORT_C)) | |
14698 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); | |
14699 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
14700 | intel_dp_is_edp(dev, PORT_C)) | |
14701 | intel_dp_init(dev, VLV_DP_C, PORT_C); | |
14702 | ||
14703 | if (IS_CHERRYVIEW(dev)) { | |
14704 | /* eDP not supported on port D, so don't check VBT */ | |
14705 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) | |
14706 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14707 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14708 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
14709 | } | |
14710 | ||
14711 | intel_dsi_init(dev); | |
14712 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { | |
14713 | bool found = false; | |
14714 | ||
14715 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { | |
14716 | DRM_DEBUG_KMS("probing SDVOB\n"); | |
14717 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); | |
14718 | if (!found && IS_G4X(dev)) { | |
14719 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); | |
14720 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); | |
14721 | } | |
14722 | ||
14723 | if (!found && IS_G4X(dev)) | |
14724 | intel_dp_init(dev, DP_B, PORT_B); | |
14725 | } | |
14726 | ||
14727 | /* Before G4X SDVOC doesn't have its own detect register */ | |
14728 | ||
14729 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { | |
14730 | DRM_DEBUG_KMS("probing SDVOC\n"); | |
14731 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); | |
14732 | } | |
14733 | ||
14734 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { | |
14735 | ||
14736 | if (IS_G4X(dev)) { | |
14737 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); | |
14738 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); | |
14739 | } | |
14740 | if (IS_G4X(dev)) | |
14741 | intel_dp_init(dev, DP_C, PORT_C); | |
14742 | } | |
14743 | ||
14744 | if (IS_G4X(dev) && | |
14745 | (I915_READ(DP_D) & DP_DETECTED)) | |
14746 | intel_dp_init(dev, DP_D, PORT_D); | |
14747 | } else if (IS_GEN2(dev)) | |
14748 | intel_dvo_init(dev); | |
14749 | ||
14750 | if (SUPPORTS_TV(dev)) | |
14751 | intel_tv_init(dev); | |
14752 | ||
14753 | intel_psr_init(dev); | |
14754 | ||
14755 | for_each_intel_encoder(dev, encoder) { | |
14756 | encoder->base.possible_crtcs = encoder->crtc_mask; | |
14757 | encoder->base.possible_clones = | |
14758 | intel_encoder_clones(encoder); | |
14759 | } | |
14760 | ||
14761 | intel_init_pch_refclk(dev); | |
14762 | ||
14763 | drm_helper_move_panel_connectors_to_head(dev); | |
14764 | } | |
14765 | ||
14766 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14767 | { | |
14768 | struct drm_device *dev = fb->dev; | |
14769 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14770 | ||
14771 | drm_framebuffer_cleanup(fb); | |
14772 | mutex_lock(&dev->struct_mutex); | |
14773 | WARN_ON(!intel_fb->obj->framebuffer_references--); | |
14774 | drm_gem_object_unreference(&intel_fb->obj->base); | |
14775 | mutex_unlock(&dev->struct_mutex); | |
14776 | kfree(intel_fb); | |
14777 | } | |
14778 | ||
14779 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
14780 | struct drm_file *file, | |
14781 | unsigned int *handle) | |
14782 | { | |
14783 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14784 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14785 | ||
14786 | if (obj->userptr.mm) { | |
14787 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); | |
14788 | return -EINVAL; | |
14789 | } | |
14790 | ||
14791 | return drm_gem_handle_create(file, &obj->base, handle); | |
14792 | } | |
14793 | ||
14794 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, | |
14795 | struct drm_file *file, | |
14796 | unsigned flags, unsigned color, | |
14797 | struct drm_clip_rect *clips, | |
14798 | unsigned num_clips) | |
14799 | { | |
14800 | struct drm_device *dev = fb->dev; | |
14801 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14802 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14803 | ||
14804 | mutex_lock(&dev->struct_mutex); | |
14805 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); | |
14806 | mutex_unlock(&dev->struct_mutex); | |
14807 | ||
14808 | return 0; | |
14809 | } | |
14810 | ||
14811 | static const struct drm_framebuffer_funcs intel_fb_funcs = { | |
14812 | .destroy = intel_user_framebuffer_destroy, | |
14813 | .create_handle = intel_user_framebuffer_create_handle, | |
14814 | .dirty = intel_user_framebuffer_dirty, | |
14815 | }; | |
14816 | ||
14817 | static | |
14818 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14819 | uint32_t pixel_format) | |
14820 | { | |
14821 | u32 gen = INTEL_INFO(dev)->gen; | |
14822 | ||
14823 | if (gen >= 9) { | |
14824 | int cpp = drm_format_plane_cpp(pixel_format, 0); | |
14825 | ||
14826 | /* "The stride in bytes must not exceed the of the size of 8K | |
14827 | * pixels and 32K bytes." | |
14828 | */ | |
14829 | return min(8192 * cpp, 32768); | |
14830 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { | |
14831 | return 32*1024; | |
14832 | } else if (gen >= 4) { | |
14833 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14834 | return 16*1024; | |
14835 | else | |
14836 | return 32*1024; | |
14837 | } else if (gen >= 3) { | |
14838 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14839 | return 8*1024; | |
14840 | else | |
14841 | return 16*1024; | |
14842 | } else { | |
14843 | /* XXX DSPC is limited to 4k tiled */ | |
14844 | return 8*1024; | |
14845 | } | |
14846 | } | |
14847 | ||
14848 | static int intel_framebuffer_init(struct drm_device *dev, | |
14849 | struct intel_framebuffer *intel_fb, | |
14850 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14851 | struct drm_i915_gem_object *obj) | |
14852 | { | |
14853 | struct drm_i915_private *dev_priv = to_i915(dev); | |
14854 | unsigned int aligned_height; | |
14855 | int ret; | |
14856 | u32 pitch_limit, stride_alignment; | |
14857 | ||
14858 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); | |
14859 | ||
14860 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { | |
14861 | /* Enforce that fb modifier and tiling mode match, but only for | |
14862 | * X-tiled. This is needed for FBC. */ | |
14863 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14864 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14865 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14866 | return -EINVAL; | |
14867 | } | |
14868 | } else { | |
14869 | if (obj->tiling_mode == I915_TILING_X) | |
14870 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14871 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14872 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14873 | return -EINVAL; | |
14874 | } | |
14875 | } | |
14876 | ||
14877 | /* Passed in modifier sanity checking. */ | |
14878 | switch (mode_cmd->modifier[0]) { | |
14879 | case I915_FORMAT_MOD_Y_TILED: | |
14880 | case I915_FORMAT_MOD_Yf_TILED: | |
14881 | if (INTEL_INFO(dev)->gen < 9) { | |
14882 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14883 | mode_cmd->modifier[0]); | |
14884 | return -EINVAL; | |
14885 | } | |
14886 | case DRM_FORMAT_MOD_NONE: | |
14887 | case I915_FORMAT_MOD_X_TILED: | |
14888 | break; | |
14889 | default: | |
14890 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", | |
14891 | mode_cmd->modifier[0]); | |
14892 | return -EINVAL; | |
14893 | } | |
14894 | ||
14895 | stride_alignment = intel_fb_stride_alignment(dev_priv, | |
14896 | mode_cmd->modifier[0], | |
14897 | mode_cmd->pixel_format); | |
14898 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14899 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14900 | mode_cmd->pitches[0], stride_alignment); | |
14901 | return -EINVAL; | |
14902 | } | |
14903 | ||
14904 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], | |
14905 | mode_cmd->pixel_format); | |
14906 | if (mode_cmd->pitches[0] > pitch_limit) { | |
14907 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", | |
14908 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
14909 | "tiled" : "linear", | |
14910 | mode_cmd->pitches[0], pitch_limit); | |
14911 | return -EINVAL; | |
14912 | } | |
14913 | ||
14914 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && | |
14915 | mode_cmd->pitches[0] != obj->stride) { | |
14916 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14917 | mode_cmd->pitches[0], obj->stride); | |
14918 | return -EINVAL; | |
14919 | } | |
14920 | ||
14921 | /* Reject formats not supported by any plane early. */ | |
14922 | switch (mode_cmd->pixel_format) { | |
14923 | case DRM_FORMAT_C8: | |
14924 | case DRM_FORMAT_RGB565: | |
14925 | case DRM_FORMAT_XRGB8888: | |
14926 | case DRM_FORMAT_ARGB8888: | |
14927 | break; | |
14928 | case DRM_FORMAT_XRGB1555: | |
14929 | if (INTEL_INFO(dev)->gen > 3) { | |
14930 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14931 | drm_get_format_name(mode_cmd->pixel_format)); | |
14932 | return -EINVAL; | |
14933 | } | |
14934 | break; | |
14935 | case DRM_FORMAT_ABGR8888: | |
14936 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && | |
14937 | INTEL_INFO(dev)->gen < 9) { | |
14938 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14939 | drm_get_format_name(mode_cmd->pixel_format)); | |
14940 | return -EINVAL; | |
14941 | } | |
14942 | break; | |
14943 | case DRM_FORMAT_XBGR8888: | |
14944 | case DRM_FORMAT_XRGB2101010: | |
14945 | case DRM_FORMAT_XBGR2101010: | |
14946 | if (INTEL_INFO(dev)->gen < 4) { | |
14947 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14948 | drm_get_format_name(mode_cmd->pixel_format)); | |
14949 | return -EINVAL; | |
14950 | } | |
14951 | break; | |
14952 | case DRM_FORMAT_ABGR2101010: | |
14953 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { | |
14954 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14955 | drm_get_format_name(mode_cmd->pixel_format)); | |
14956 | return -EINVAL; | |
14957 | } | |
14958 | break; | |
14959 | case DRM_FORMAT_YUYV: | |
14960 | case DRM_FORMAT_UYVY: | |
14961 | case DRM_FORMAT_YVYU: | |
14962 | case DRM_FORMAT_VYUY: | |
14963 | if (INTEL_INFO(dev)->gen < 5) { | |
14964 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14965 | drm_get_format_name(mode_cmd->pixel_format)); | |
14966 | return -EINVAL; | |
14967 | } | |
14968 | break; | |
14969 | default: | |
14970 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14971 | drm_get_format_name(mode_cmd->pixel_format)); | |
14972 | return -EINVAL; | |
14973 | } | |
14974 | ||
14975 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ | |
14976 | if (mode_cmd->offsets[0] != 0) | |
14977 | return -EINVAL; | |
14978 | ||
14979 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, | |
14980 | mode_cmd->pixel_format, | |
14981 | mode_cmd->modifier[0]); | |
14982 | /* FIXME drm helper for size checks (especially planar formats)? */ | |
14983 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14984 | return -EINVAL; | |
14985 | ||
14986 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); | |
14987 | intel_fb->obj = obj; | |
14988 | ||
14989 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); | |
14990 | if (ret) { | |
14991 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14992 | return ret; | |
14993 | } | |
14994 | ||
14995 | intel_fb->obj->framebuffer_references++; | |
14996 | ||
14997 | return 0; | |
14998 | } | |
14999 | ||
15000 | static struct drm_framebuffer * | |
15001 | intel_user_framebuffer_create(struct drm_device *dev, | |
15002 | struct drm_file *filp, | |
15003 | const struct drm_mode_fb_cmd2 *user_mode_cmd) | |
15004 | { | |
15005 | struct drm_framebuffer *fb; | |
15006 | struct drm_i915_gem_object *obj; | |
15007 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; | |
15008 | ||
15009 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, | |
15010 | mode_cmd.handles[0])); | |
15011 | if (&obj->base == NULL) | |
15012 | return ERR_PTR(-ENOENT); | |
15013 | ||
15014 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); | |
15015 | if (IS_ERR(fb)) | |
15016 | drm_gem_object_unreference_unlocked(&obj->base); | |
15017 | ||
15018 | return fb; | |
15019 | } | |
15020 | ||
15021 | #ifndef CONFIG_DRM_FBDEV_EMULATION | |
15022 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) | |
15023 | { | |
15024 | } | |
15025 | #endif | |
15026 | ||
15027 | static const struct drm_mode_config_funcs intel_mode_funcs = { | |
15028 | .fb_create = intel_user_framebuffer_create, | |
15029 | .output_poll_changed = intel_fbdev_output_poll_changed, | |
15030 | .atomic_check = intel_atomic_check, | |
15031 | .atomic_commit = intel_atomic_commit, | |
15032 | .atomic_state_alloc = intel_atomic_state_alloc, | |
15033 | .atomic_state_clear = intel_atomic_state_clear, | |
15034 | }; | |
15035 | ||
15036 | /* Set up chip specific display functions */ | |
15037 | static void intel_init_display(struct drm_device *dev) | |
15038 | { | |
15039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15040 | ||
15041 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) | |
15042 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
15043 | else if (IS_CHERRYVIEW(dev)) | |
15044 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
15045 | else if (IS_VALLEYVIEW(dev)) | |
15046 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
15047 | else if (IS_PINEVIEW(dev)) | |
15048 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
15049 | else | |
15050 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
15051 | ||
15052 | if (INTEL_INFO(dev)->gen >= 9) { | |
15053 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
15054 | dev_priv->display.get_initial_plane_config = | |
15055 | skylake_get_initial_plane_config; | |
15056 | dev_priv->display.crtc_compute_clock = | |
15057 | haswell_crtc_compute_clock; | |
15058 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
15059 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
15060 | } else if (HAS_DDI(dev)) { | |
15061 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
15062 | dev_priv->display.get_initial_plane_config = | |
15063 | ironlake_get_initial_plane_config; | |
15064 | dev_priv->display.crtc_compute_clock = | |
15065 | haswell_crtc_compute_clock; | |
15066 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
15067 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
15068 | } else if (HAS_PCH_SPLIT(dev)) { | |
15069 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; | |
15070 | dev_priv->display.get_initial_plane_config = | |
15071 | ironlake_get_initial_plane_config; | |
15072 | dev_priv->display.crtc_compute_clock = | |
15073 | ironlake_crtc_compute_clock; | |
15074 | dev_priv->display.crtc_enable = ironlake_crtc_enable; | |
15075 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
15076 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
15077 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
15078 | dev_priv->display.get_initial_plane_config = | |
15079 | i9xx_get_initial_plane_config; | |
15080 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; | |
15081 | dev_priv->display.crtc_enable = valleyview_crtc_enable; | |
15082 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
15083 | } else { | |
15084 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
15085 | dev_priv->display.get_initial_plane_config = | |
15086 | i9xx_get_initial_plane_config; | |
15087 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; | |
15088 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
15089 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
15090 | } | |
15091 | ||
15092 | /* Returns the core display clock speed */ | |
15093 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) | |
15094 | dev_priv->display.get_display_clock_speed = | |
15095 | skylake_get_display_clock_speed; | |
15096 | else if (IS_BROXTON(dev)) | |
15097 | dev_priv->display.get_display_clock_speed = | |
15098 | broxton_get_display_clock_speed; | |
15099 | else if (IS_BROADWELL(dev)) | |
15100 | dev_priv->display.get_display_clock_speed = | |
15101 | broadwell_get_display_clock_speed; | |
15102 | else if (IS_HASWELL(dev)) | |
15103 | dev_priv->display.get_display_clock_speed = | |
15104 | haswell_get_display_clock_speed; | |
15105 | else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) | |
15106 | dev_priv->display.get_display_clock_speed = | |
15107 | valleyview_get_display_clock_speed; | |
15108 | else if (IS_GEN5(dev)) | |
15109 | dev_priv->display.get_display_clock_speed = | |
15110 | ilk_get_display_clock_speed; | |
15111 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || | |
15112 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) | |
15113 | dev_priv->display.get_display_clock_speed = | |
15114 | i945_get_display_clock_speed; | |
15115 | else if (IS_GM45(dev)) | |
15116 | dev_priv->display.get_display_clock_speed = | |
15117 | gm45_get_display_clock_speed; | |
15118 | else if (IS_CRESTLINE(dev)) | |
15119 | dev_priv->display.get_display_clock_speed = | |
15120 | i965gm_get_display_clock_speed; | |
15121 | else if (IS_PINEVIEW(dev)) | |
15122 | dev_priv->display.get_display_clock_speed = | |
15123 | pnv_get_display_clock_speed; | |
15124 | else if (IS_G33(dev) || IS_G4X(dev)) | |
15125 | dev_priv->display.get_display_clock_speed = | |
15126 | g33_get_display_clock_speed; | |
15127 | else if (IS_I915G(dev)) | |
15128 | dev_priv->display.get_display_clock_speed = | |
15129 | i915_get_display_clock_speed; | |
15130 | else if (IS_I945GM(dev) || IS_845G(dev)) | |
15131 | dev_priv->display.get_display_clock_speed = | |
15132 | i9xx_misc_get_display_clock_speed; | |
15133 | else if (IS_I915GM(dev)) | |
15134 | dev_priv->display.get_display_clock_speed = | |
15135 | i915gm_get_display_clock_speed; | |
15136 | else if (IS_I865G(dev)) | |
15137 | dev_priv->display.get_display_clock_speed = | |
15138 | i865_get_display_clock_speed; | |
15139 | else if (IS_I85X(dev)) | |
15140 | dev_priv->display.get_display_clock_speed = | |
15141 | i85x_get_display_clock_speed; | |
15142 | else { /* 830 */ | |
15143 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
15144 | dev_priv->display.get_display_clock_speed = | |
15145 | i830_get_display_clock_speed; | |
15146 | } | |
15147 | ||
15148 | if (IS_GEN5(dev)) { | |
15149 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; | |
15150 | } else if (IS_GEN6(dev)) { | |
15151 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
15152 | } else if (IS_IVYBRIDGE(dev)) { | |
15153 | /* FIXME: detect B0+ stepping and use auto training */ | |
15154 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
15155 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
15156 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; | |
15157 | if (IS_BROADWELL(dev)) { | |
15158 | dev_priv->display.modeset_commit_cdclk = | |
15159 | broadwell_modeset_commit_cdclk; | |
15160 | dev_priv->display.modeset_calc_cdclk = | |
15161 | broadwell_modeset_calc_cdclk; | |
15162 | } | |
15163 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
15164 | dev_priv->display.modeset_commit_cdclk = | |
15165 | valleyview_modeset_commit_cdclk; | |
15166 | dev_priv->display.modeset_calc_cdclk = | |
15167 | valleyview_modeset_calc_cdclk; | |
15168 | } else if (IS_BROXTON(dev)) { | |
15169 | dev_priv->display.modeset_commit_cdclk = | |
15170 | broxton_modeset_commit_cdclk; | |
15171 | dev_priv->display.modeset_calc_cdclk = | |
15172 | broxton_modeset_calc_cdclk; | |
15173 | } | |
15174 | ||
15175 | switch (INTEL_INFO(dev)->gen) { | |
15176 | case 2: | |
15177 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
15178 | break; | |
15179 | ||
15180 | case 3: | |
15181 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
15182 | break; | |
15183 | ||
15184 | case 4: | |
15185 | case 5: | |
15186 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
15187 | break; | |
15188 | ||
15189 | case 6: | |
15190 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
15191 | break; | |
15192 | case 7: | |
15193 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ | |
15194 | dev_priv->display.queue_flip = intel_gen7_queue_flip; | |
15195 | break; | |
15196 | case 9: | |
15197 | /* Drop through - unsupported since execlist only. */ | |
15198 | default: | |
15199 | /* Default just returns -ENODEV to indicate unsupported */ | |
15200 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
15201 | } | |
15202 | ||
15203 | mutex_init(&dev_priv->pps_mutex); | |
15204 | } | |
15205 | ||
15206 | /* | |
15207 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
15208 | * resume, or other times. This quirk makes sure that's the case for | |
15209 | * affected systems. | |
15210 | */ | |
15211 | static void quirk_pipea_force(struct drm_device *dev) | |
15212 | { | |
15213 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15214 | ||
15215 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
15216 | DRM_INFO("applying pipe a force quirk\n"); | |
15217 | } | |
15218 | ||
15219 | static void quirk_pipeb_force(struct drm_device *dev) | |
15220 | { | |
15221 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15222 | ||
15223 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
15224 | DRM_INFO("applying pipe b force quirk\n"); | |
15225 | } | |
15226 | ||
15227 | /* | |
15228 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
15229 | */ | |
15230 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
15231 | { | |
15232 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15233 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
15234 | DRM_INFO("applying lvds SSC disable quirk\n"); | |
15235 | } | |
15236 | ||
15237 | /* | |
15238 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight | |
15239 | * brightness value | |
15240 | */ | |
15241 | static void quirk_invert_brightness(struct drm_device *dev) | |
15242 | { | |
15243 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15244 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
15245 | DRM_INFO("applying inverted panel brightness quirk\n"); | |
15246 | } | |
15247 | ||
15248 | /* Some VBT's incorrectly indicate no backlight is present */ | |
15249 | static void quirk_backlight_present(struct drm_device *dev) | |
15250 | { | |
15251 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15252 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
15253 | DRM_INFO("applying backlight present quirk\n"); | |
15254 | } | |
15255 | ||
15256 | struct intel_quirk { | |
15257 | int device; | |
15258 | int subsystem_vendor; | |
15259 | int subsystem_device; | |
15260 | void (*hook)(struct drm_device *dev); | |
15261 | }; | |
15262 | ||
15263 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ | |
15264 | struct intel_dmi_quirk { | |
15265 | void (*hook)(struct drm_device *dev); | |
15266 | const struct dmi_system_id (*dmi_id_list)[]; | |
15267 | }; | |
15268 | ||
15269 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
15270 | { | |
15271 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
15272 | return 1; | |
15273 | } | |
15274 | ||
15275 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
15276 | { | |
15277 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
15278 | { | |
15279 | .callback = intel_dmi_reverse_brightness, | |
15280 | .ident = "NCR Corporation", | |
15281 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
15282 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
15283 | }, | |
15284 | }, | |
15285 | { } /* terminating entry */ | |
15286 | }, | |
15287 | .hook = quirk_invert_brightness, | |
15288 | }, | |
15289 | }; | |
15290 | ||
15291 | static struct intel_quirk intel_quirks[] = { | |
15292 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ | |
15293 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
15294 | ||
15295 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ | |
15296 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
15297 | ||
15298 | /* 830 needs to leave pipe A & dpll A up */ | |
15299 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
15300 | ||
15301 | /* 830 needs to leave pipe B & dpll B up */ | |
15302 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
15303 | ||
15304 | /* Lenovo U160 cannot use SSC on LVDS */ | |
15305 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
15306 | ||
15307 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
15308 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
15309 | ||
15310 | /* Acer Aspire 5734Z must invert backlight brightness */ | |
15311 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
15312 | ||
15313 | /* Acer/eMachines G725 */ | |
15314 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
15315 | ||
15316 | /* Acer/eMachines e725 */ | |
15317 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
15318 | ||
15319 | /* Acer/Packard Bell NCL20 */ | |
15320 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
15321 | ||
15322 | /* Acer Aspire 4736Z */ | |
15323 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
15324 | ||
15325 | /* Acer Aspire 5336 */ | |
15326 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
15327 | ||
15328 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
15329 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
15330 | ||
15331 | /* Acer C720 Chromebook (Core i3 4005U) */ | |
15332 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
15333 | ||
15334 | /* Apple Macbook 2,1 (Core 2 T7400) */ | |
15335 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
15336 | ||
15337 | /* Apple Macbook 4,1 */ | |
15338 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, | |
15339 | ||
15340 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ | |
15341 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
15342 | ||
15343 | /* HP Chromebook 14 (Celeron 2955U) */ | |
15344 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
15345 | ||
15346 | /* Dell Chromebook 11 */ | |
15347 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
15348 | ||
15349 | /* Dell Chromebook 11 (2015 version) */ | |
15350 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, | |
15351 | }; | |
15352 | ||
15353 | static void intel_init_quirks(struct drm_device *dev) | |
15354 | { | |
15355 | struct pci_dev *d = dev->pdev; | |
15356 | int i; | |
15357 | ||
15358 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
15359 | struct intel_quirk *q = &intel_quirks[i]; | |
15360 | ||
15361 | if (d->device == q->device && | |
15362 | (d->subsystem_vendor == q->subsystem_vendor || | |
15363 | q->subsystem_vendor == PCI_ANY_ID) && | |
15364 | (d->subsystem_device == q->subsystem_device || | |
15365 | q->subsystem_device == PCI_ANY_ID)) | |
15366 | q->hook(dev); | |
15367 | } | |
15368 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { | |
15369 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
15370 | intel_dmi_quirks[i].hook(dev); | |
15371 | } | |
15372 | } | |
15373 | ||
15374 | /* Disable the VGA plane that we never use */ | |
15375 | static void i915_disable_vga(struct drm_device *dev) | |
15376 | { | |
15377 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15378 | u8 sr1; | |
15379 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); | |
15380 | ||
15381 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ | |
15382 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15383 | outb(SR01, VGA_SR_INDEX); | |
15384 | sr1 = inb(VGA_SR_DATA); | |
15385 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15386 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15387 | udelay(300); | |
15388 | ||
15389 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); | |
15390 | POSTING_READ(vga_reg); | |
15391 | } | |
15392 | ||
15393 | void intel_modeset_init_hw(struct drm_device *dev) | |
15394 | { | |
15395 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15396 | ||
15397 | intel_update_cdclk(dev); | |
15398 | ||
15399 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; | |
15400 | ||
15401 | intel_init_clock_gating(dev); | |
15402 | intel_enable_gt_powersave(dev); | |
15403 | } | |
15404 | ||
15405 | /* | |
15406 | * Calculate what we think the watermarks should be for the state we've read | |
15407 | * out of the hardware and then immediately program those watermarks so that | |
15408 | * we ensure the hardware settings match our internal state. | |
15409 | * | |
15410 | * We can calculate what we think WM's should be by creating a duplicate of the | |
15411 | * current state (which was constructed during hardware readout) and running it | |
15412 | * through the atomic check code to calculate new watermark values in the | |
15413 | * state object. | |
15414 | */ | |
15415 | static void sanitize_watermarks(struct drm_device *dev) | |
15416 | { | |
15417 | struct drm_i915_private *dev_priv = to_i915(dev); | |
15418 | struct drm_atomic_state *state; | |
15419 | struct drm_crtc *crtc; | |
15420 | struct drm_crtc_state *cstate; | |
15421 | struct drm_modeset_acquire_ctx ctx; | |
15422 | int ret; | |
15423 | int i; | |
15424 | ||
15425 | /* Only supported on platforms that use atomic watermark design */ | |
15426 | if (!dev_priv->display.optimize_watermarks) | |
15427 | return; | |
15428 | ||
15429 | /* | |
15430 | * We need to hold connection_mutex before calling duplicate_state so | |
15431 | * that the connector loop is protected. | |
15432 | */ | |
15433 | drm_modeset_acquire_init(&ctx, 0); | |
15434 | retry: | |
15435 | ret = drm_modeset_lock_all_ctx(dev, &ctx); | |
15436 | if (ret == -EDEADLK) { | |
15437 | drm_modeset_backoff(&ctx); | |
15438 | goto retry; | |
15439 | } else if (WARN_ON(ret)) { | |
15440 | goto fail; | |
15441 | } | |
15442 | ||
15443 | state = drm_atomic_helper_duplicate_state(dev, &ctx); | |
15444 | if (WARN_ON(IS_ERR(state))) | |
15445 | goto fail; | |
15446 | ||
15447 | /* | |
15448 | * Hardware readout is the only time we don't want to calculate | |
15449 | * intermediate watermarks (since we don't trust the current | |
15450 | * watermarks). | |
15451 | */ | |
15452 | to_intel_atomic_state(state)->skip_intermediate_wm = true; | |
15453 | ||
15454 | ret = intel_atomic_check(dev, state); | |
15455 | if (ret) { | |
15456 | /* | |
15457 | * If we fail here, it means that the hardware appears to be | |
15458 | * programmed in a way that shouldn't be possible, given our | |
15459 | * understanding of watermark requirements. This might mean a | |
15460 | * mistake in the hardware readout code or a mistake in the | |
15461 | * watermark calculations for a given platform. Raise a WARN | |
15462 | * so that this is noticeable. | |
15463 | * | |
15464 | * If this actually happens, we'll have to just leave the | |
15465 | * BIOS-programmed watermarks untouched and hope for the best. | |
15466 | */ | |
15467 | WARN(true, "Could not determine valid watermarks for inherited state\n"); | |
15468 | goto fail; | |
15469 | } | |
15470 | ||
15471 | /* Write calculated watermark values back */ | |
15472 | to_i915(dev)->wm.config = to_intel_atomic_state(state)->wm_config; | |
15473 | for_each_crtc_in_state(state, crtc, cstate, i) { | |
15474 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); | |
15475 | ||
15476 | cs->wm.need_postvbl_update = true; | |
15477 | dev_priv->display.optimize_watermarks(cs); | |
15478 | } | |
15479 | ||
15480 | drm_atomic_state_free(state); | |
15481 | fail: | |
15482 | drm_modeset_drop_locks(&ctx); | |
15483 | drm_modeset_acquire_fini(&ctx); | |
15484 | } | |
15485 | ||
15486 | void intel_modeset_init(struct drm_device *dev) | |
15487 | { | |
15488 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15489 | int sprite, ret; | |
15490 | enum pipe pipe; | |
15491 | struct intel_crtc *crtc; | |
15492 | ||
15493 | drm_mode_config_init(dev); | |
15494 | ||
15495 | dev->mode_config.min_width = 0; | |
15496 | dev->mode_config.min_height = 0; | |
15497 | ||
15498 | dev->mode_config.preferred_depth = 24; | |
15499 | dev->mode_config.prefer_shadow = 1; | |
15500 | ||
15501 | dev->mode_config.allow_fb_modifiers = true; | |
15502 | ||
15503 | dev->mode_config.funcs = &intel_mode_funcs; | |
15504 | ||
15505 | intel_init_quirks(dev); | |
15506 | ||
15507 | intel_init_pm(dev); | |
15508 | ||
15509 | if (INTEL_INFO(dev)->num_pipes == 0) | |
15510 | return; | |
15511 | ||
15512 | /* | |
15513 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15514 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15515 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15516 | * indicates as much. | |
15517 | */ | |
15518 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
15519 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15520 | DREF_SSC1_ENABLE); | |
15521 | ||
15522 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
15523 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
15524 | bios_lvds_use_ssc ? "en" : "dis", | |
15525 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
15526 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
15527 | } | |
15528 | } | |
15529 | ||
15530 | intel_init_display(dev); | |
15531 | intel_init_audio(dev); | |
15532 | ||
15533 | if (IS_GEN2(dev)) { | |
15534 | dev->mode_config.max_width = 2048; | |
15535 | dev->mode_config.max_height = 2048; | |
15536 | } else if (IS_GEN3(dev)) { | |
15537 | dev->mode_config.max_width = 4096; | |
15538 | dev->mode_config.max_height = 4096; | |
15539 | } else { | |
15540 | dev->mode_config.max_width = 8192; | |
15541 | dev->mode_config.max_height = 8192; | |
15542 | } | |
15543 | ||
15544 | if (IS_845G(dev) || IS_I865G(dev)) { | |
15545 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15546 | dev->mode_config.cursor_height = 1023; | |
15547 | } else if (IS_GEN2(dev)) { | |
15548 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; | |
15549 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15550 | } else { | |
15551 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15552 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15553 | } | |
15554 | ||
15555 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; | |
15556 | ||
15557 | DRM_DEBUG_KMS("%d display pipe%s available.\n", | |
15558 | INTEL_INFO(dev)->num_pipes, | |
15559 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
15560 | ||
15561 | for_each_pipe(dev_priv, pipe) { | |
15562 | intel_crtc_init(dev, pipe); | |
15563 | for_each_sprite(dev_priv, pipe, sprite) { | |
15564 | ret = intel_plane_init(dev, pipe, sprite); | |
15565 | if (ret) | |
15566 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", | |
15567 | pipe_name(pipe), sprite_name(pipe, sprite), ret); | |
15568 | } | |
15569 | } | |
15570 | ||
15571 | intel_update_czclk(dev_priv); | |
15572 | intel_update_cdclk(dev); | |
15573 | ||
15574 | intel_shared_dpll_init(dev); | |
15575 | ||
15576 | /* Just disable it once at startup */ | |
15577 | i915_disable_vga(dev); | |
15578 | intel_setup_outputs(dev); | |
15579 | ||
15580 | drm_modeset_lock_all(dev); | |
15581 | intel_modeset_setup_hw_state(dev); | |
15582 | drm_modeset_unlock_all(dev); | |
15583 | ||
15584 | for_each_intel_crtc(dev, crtc) { | |
15585 | struct intel_initial_plane_config plane_config = {}; | |
15586 | ||
15587 | if (!crtc->active) | |
15588 | continue; | |
15589 | ||
15590 | /* | |
15591 | * Note that reserving the BIOS fb up front prevents us | |
15592 | * from stuffing other stolen allocations like the ring | |
15593 | * on top. This prevents some ugliness at boot time, and | |
15594 | * can even allow for smooth boot transitions if the BIOS | |
15595 | * fb is large enough for the active pipe configuration. | |
15596 | */ | |
15597 | dev_priv->display.get_initial_plane_config(crtc, | |
15598 | &plane_config); | |
15599 | ||
15600 | /* | |
15601 | * If the fb is shared between multiple heads, we'll | |
15602 | * just get the first one. | |
15603 | */ | |
15604 | intel_find_initial_plane_obj(crtc, &plane_config); | |
15605 | } | |
15606 | ||
15607 | /* | |
15608 | * Make sure hardware watermarks really match the state we read out. | |
15609 | * Note that we need to do this after reconstructing the BIOS fb's | |
15610 | * since the watermark calculation done here will use pstate->fb. | |
15611 | */ | |
15612 | sanitize_watermarks(dev); | |
15613 | } | |
15614 | ||
15615 | static void intel_enable_pipe_a(struct drm_device *dev) | |
15616 | { | |
15617 | struct intel_connector *connector; | |
15618 | struct drm_connector *crt = NULL; | |
15619 | struct intel_load_detect_pipe load_detect_temp; | |
15620 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; | |
15621 | ||
15622 | /* We can't just switch on the pipe A, we need to set things up with a | |
15623 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15624 | * by enabling the load detect pipe once. */ | |
15625 | for_each_intel_connector(dev, connector) { | |
15626 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { | |
15627 | crt = &connector->base; | |
15628 | break; | |
15629 | } | |
15630 | } | |
15631 | ||
15632 | if (!crt) | |
15633 | return; | |
15634 | ||
15635 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) | |
15636 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); | |
15637 | } | |
15638 | ||
15639 | static bool | |
15640 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15641 | { | |
15642 | struct drm_device *dev = crtc->base.dev; | |
15643 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15644 | u32 val; | |
15645 | ||
15646 | if (INTEL_INFO(dev)->num_pipes == 1) | |
15647 | return true; | |
15648 | ||
15649 | val = I915_READ(DSPCNTR(!crtc->plane)); | |
15650 | ||
15651 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15652 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15653 | return false; | |
15654 | ||
15655 | return true; | |
15656 | } | |
15657 | ||
15658 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) | |
15659 | { | |
15660 | struct drm_device *dev = crtc->base.dev; | |
15661 | struct intel_encoder *encoder; | |
15662 | ||
15663 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15664 | return true; | |
15665 | ||
15666 | return false; | |
15667 | } | |
15668 | ||
15669 | static bool intel_encoder_has_connectors(struct intel_encoder *encoder) | |
15670 | { | |
15671 | struct drm_device *dev = encoder->base.dev; | |
15672 | struct intel_connector *connector; | |
15673 | ||
15674 | for_each_connector_on_encoder(dev, &encoder->base, connector) | |
15675 | return true; | |
15676 | ||
15677 | return false; | |
15678 | } | |
15679 | ||
15680 | static void intel_sanitize_crtc(struct intel_crtc *crtc) | |
15681 | { | |
15682 | struct drm_device *dev = crtc->base.dev; | |
15683 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15684 | i915_reg_t reg = PIPECONF(crtc->config->cpu_transcoder); | |
15685 | ||
15686 | /* Clear any frame start delays used for debugging left by the BIOS */ | |
15687 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); | |
15688 | ||
15689 | /* restore vblank interrupts to correct state */ | |
15690 | drm_crtc_vblank_reset(&crtc->base); | |
15691 | if (crtc->active) { | |
15692 | struct intel_plane *plane; | |
15693 | ||
15694 | drm_crtc_vblank_on(&crtc->base); | |
15695 | ||
15696 | /* Disable everything but the primary plane */ | |
15697 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15698 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15699 | continue; | |
15700 | ||
15701 | plane->disable_plane(&plane->base, &crtc->base); | |
15702 | } | |
15703 | } | |
15704 | ||
15705 | /* We need to sanitize the plane -> pipe mapping first because this will | |
15706 | * disable the crtc (and hence change the state) if it is wrong. Note | |
15707 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15708 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
15709 | bool plane; | |
15710 | ||
15711 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", | |
15712 | crtc->base.base.id); | |
15713 | ||
15714 | /* Pipe has the wrong plane attached and the plane is active. | |
15715 | * Temporarily change the plane mapping and disable everything | |
15716 | * ... */ | |
15717 | plane = crtc->plane; | |
15718 | to_intel_plane_state(crtc->base.primary->state)->visible = true; | |
15719 | crtc->plane = !plane; | |
15720 | intel_crtc_disable_noatomic(&crtc->base); | |
15721 | crtc->plane = plane; | |
15722 | } | |
15723 | ||
15724 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && | |
15725 | crtc->pipe == PIPE_A && !crtc->active) { | |
15726 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15727 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15728 | * call below we restore the pipe to the right state, but leave | |
15729 | * the required bits on. */ | |
15730 | intel_enable_pipe_a(dev); | |
15731 | } | |
15732 | ||
15733 | /* Adjust the state of the output pipe according to whether we | |
15734 | * have active connectors/encoders. */ | |
15735 | if (!intel_crtc_has_encoders(crtc)) | |
15736 | intel_crtc_disable_noatomic(&crtc->base); | |
15737 | ||
15738 | if (crtc->active != crtc->base.state->active) { | |
15739 | struct intel_encoder *encoder; | |
15740 | ||
15741 | /* This can happen either due to bugs in the get_hw_state | |
15742 | * functions or because of calls to intel_crtc_disable_noatomic, | |
15743 | * or because the pipe is force-enabled due to the | |
15744 | * pipe A quirk. */ | |
15745 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15746 | crtc->base.base.id, | |
15747 | crtc->base.state->enable ? "enabled" : "disabled", | |
15748 | crtc->active ? "enabled" : "disabled"); | |
15749 | ||
15750 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); | |
15751 | crtc->base.state->active = crtc->active; | |
15752 | crtc->base.enabled = crtc->active; | |
15753 | crtc->base.state->connector_mask = 0; | |
15754 | crtc->base.state->encoder_mask = 0; | |
15755 | ||
15756 | /* Because we only establish the connector -> encoder -> | |
15757 | * crtc links if something is active, this means the | |
15758 | * crtc is now deactivated. Break the links. connector | |
15759 | * -> encoder links are only establish when things are | |
15760 | * actually up, hence no need to break them. */ | |
15761 | WARN_ON(crtc->active); | |
15762 | ||
15763 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15764 | encoder->base.crtc = NULL; | |
15765 | } | |
15766 | ||
15767 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { | |
15768 | /* | |
15769 | * We start out with underrun reporting disabled to avoid races. | |
15770 | * For correct bookkeeping mark this on active crtcs. | |
15771 | * | |
15772 | * Also on gmch platforms we dont have any hardware bits to | |
15773 | * disable the underrun reporting. Which means we need to start | |
15774 | * out with underrun reporting disabled also on inactive pipes, | |
15775 | * since otherwise we'll complain about the garbage we read when | |
15776 | * e.g. coming up after runtime pm. | |
15777 | * | |
15778 | * No protection against concurrent access is required - at | |
15779 | * worst a fifo underrun happens which also sets this to false. | |
15780 | */ | |
15781 | crtc->cpu_fifo_underrun_disabled = true; | |
15782 | crtc->pch_fifo_underrun_disabled = true; | |
15783 | } | |
15784 | } | |
15785 | ||
15786 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15787 | { | |
15788 | struct intel_connector *connector; | |
15789 | struct drm_device *dev = encoder->base.dev; | |
15790 | ||
15791 | /* We need to check both for a crtc link (meaning that the | |
15792 | * encoder is active and trying to read from a pipe) and the | |
15793 | * pipe itself being active. */ | |
15794 | bool has_active_crtc = encoder->base.crtc && | |
15795 | to_intel_crtc(encoder->base.crtc)->active; | |
15796 | ||
15797 | if (intel_encoder_has_connectors(encoder) && !has_active_crtc) { | |
15798 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", | |
15799 | encoder->base.base.id, | |
15800 | encoder->base.name); | |
15801 | ||
15802 | /* Connector is active, but has no active pipe. This is | |
15803 | * fallout from our resume register restoring. Disable | |
15804 | * the encoder manually again. */ | |
15805 | if (encoder->base.crtc) { | |
15806 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15807 | encoder->base.base.id, | |
15808 | encoder->base.name); | |
15809 | encoder->disable(encoder); | |
15810 | if (encoder->post_disable) | |
15811 | encoder->post_disable(encoder); | |
15812 | } | |
15813 | encoder->base.crtc = NULL; | |
15814 | ||
15815 | /* Inconsistent output/port/pipe state happens presumably due to | |
15816 | * a bug in one of the get_hw_state functions. Or someplace else | |
15817 | * in our code, like the register restore mess on resume. Clamp | |
15818 | * things to off as a safer default. */ | |
15819 | for_each_intel_connector(dev, connector) { | |
15820 | if (connector->encoder != encoder) | |
15821 | continue; | |
15822 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15823 | connector->base.encoder = NULL; | |
15824 | } | |
15825 | } | |
15826 | /* Enabled encoders without active connectors will be fixed in | |
15827 | * the crtc fixup. */ | |
15828 | } | |
15829 | ||
15830 | void i915_redisable_vga_power_on(struct drm_device *dev) | |
15831 | { | |
15832 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15833 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); | |
15834 | ||
15835 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { | |
15836 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15837 | i915_disable_vga(dev); | |
15838 | } | |
15839 | } | |
15840 | ||
15841 | void i915_redisable_vga(struct drm_device *dev) | |
15842 | { | |
15843 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15844 | ||
15845 | /* This function can be called both from intel_modeset_setup_hw_state or | |
15846 | * at a very early point in our resume sequence, where the power well | |
15847 | * structures are not yet restored. Since this function is at a very | |
15848 | * paranoid "someone might have enabled VGA while we were not looking" | |
15849 | * level, just check if the power well is enabled instead of trying to | |
15850 | * follow the "don't touch the power well if we don't need it" policy | |
15851 | * the rest of the driver uses. */ | |
15852 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) | |
15853 | return; | |
15854 | ||
15855 | i915_redisable_vga_power_on(dev); | |
15856 | ||
15857 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); | |
15858 | } | |
15859 | ||
15860 | static bool primary_get_hw_state(struct intel_plane *plane) | |
15861 | { | |
15862 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
15863 | ||
15864 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; | |
15865 | } | |
15866 | ||
15867 | /* FIXME read out full plane state for all planes */ | |
15868 | static void readout_plane_state(struct intel_crtc *crtc) | |
15869 | { | |
15870 | struct drm_plane *primary = crtc->base.primary; | |
15871 | struct intel_plane_state *plane_state = | |
15872 | to_intel_plane_state(primary->state); | |
15873 | ||
15874 | plane_state->visible = crtc->active && | |
15875 | primary_get_hw_state(to_intel_plane(primary)); | |
15876 | ||
15877 | if (plane_state->visible) | |
15878 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
15879 | } | |
15880 | ||
15881 | static void intel_modeset_readout_hw_state(struct drm_device *dev) | |
15882 | { | |
15883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15884 | enum pipe pipe; | |
15885 | struct intel_crtc *crtc; | |
15886 | struct intel_encoder *encoder; | |
15887 | struct intel_connector *connector; | |
15888 | int i; | |
15889 | ||
15890 | dev_priv->active_crtcs = 0; | |
15891 | ||
15892 | for_each_intel_crtc(dev, crtc) { | |
15893 | struct intel_crtc_state *crtc_state = crtc->config; | |
15894 | int pixclk = 0; | |
15895 | ||
15896 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, &crtc_state->base); | |
15897 | memset(crtc_state, 0, sizeof(*crtc_state)); | |
15898 | crtc_state->base.crtc = &crtc->base; | |
15899 | ||
15900 | crtc_state->base.active = crtc_state->base.enable = | |
15901 | dev_priv->display.get_pipe_config(crtc, crtc_state); | |
15902 | ||
15903 | crtc->base.enabled = crtc_state->base.enable; | |
15904 | crtc->active = crtc_state->base.active; | |
15905 | ||
15906 | if (crtc_state->base.active) { | |
15907 | dev_priv->active_crtcs |= 1 << crtc->pipe; | |
15908 | ||
15909 | if (IS_BROADWELL(dev_priv)) { | |
15910 | pixclk = ilk_pipe_pixel_rate(crtc_state); | |
15911 | ||
15912 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
15913 | if (crtc_state->ips_enabled) | |
15914 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); | |
15915 | } else if (IS_VALLEYVIEW(dev_priv) || | |
15916 | IS_CHERRYVIEW(dev_priv) || | |
15917 | IS_BROXTON(dev_priv)) | |
15918 | pixclk = crtc_state->base.adjusted_mode.crtc_clock; | |
15919 | else | |
15920 | WARN_ON(dev_priv->display.modeset_calc_cdclk); | |
15921 | } | |
15922 | ||
15923 | dev_priv->min_pixclk[crtc->pipe] = pixclk; | |
15924 | ||
15925 | readout_plane_state(crtc); | |
15926 | ||
15927 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15928 | crtc->base.base.id, | |
15929 | crtc->active ? "enabled" : "disabled"); | |
15930 | } | |
15931 | ||
15932 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
15933 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15934 | ||
15935 | pll->on = pll->get_hw_state(dev_priv, pll, | |
15936 | &pll->config.hw_state); | |
15937 | pll->active = 0; | |
15938 | pll->config.crtc_mask = 0; | |
15939 | for_each_intel_crtc(dev, crtc) { | |
15940 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { | |
15941 | pll->active++; | |
15942 | pll->config.crtc_mask |= 1 << crtc->pipe; | |
15943 | } | |
15944 | } | |
15945 | ||
15946 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", | |
15947 | pll->name, pll->config.crtc_mask, pll->on); | |
15948 | ||
15949 | if (pll->config.crtc_mask) | |
15950 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
15951 | } | |
15952 | ||
15953 | for_each_intel_encoder(dev, encoder) { | |
15954 | pipe = 0; | |
15955 | ||
15956 | if (encoder->get_hw_state(encoder, &pipe)) { | |
15957 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); | |
15958 | encoder->base.crtc = &crtc->base; | |
15959 | encoder->get_config(encoder, crtc->config); | |
15960 | } else { | |
15961 | encoder->base.crtc = NULL; | |
15962 | } | |
15963 | ||
15964 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", | |
15965 | encoder->base.base.id, | |
15966 | encoder->base.name, | |
15967 | encoder->base.crtc ? "enabled" : "disabled", | |
15968 | pipe_name(pipe)); | |
15969 | } | |
15970 | ||
15971 | for_each_intel_connector(dev, connector) { | |
15972 | if (connector->get_hw_state(connector)) { | |
15973 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
15974 | ||
15975 | encoder = connector->encoder; | |
15976 | connector->base.encoder = &encoder->base; | |
15977 | ||
15978 | if (encoder->base.crtc && | |
15979 | encoder->base.crtc->state->active) { | |
15980 | /* | |
15981 | * This has to be done during hardware readout | |
15982 | * because anything calling .crtc_disable may | |
15983 | * rely on the connector_mask being accurate. | |
15984 | */ | |
15985 | encoder->base.crtc->state->connector_mask |= | |
15986 | 1 << drm_connector_index(&connector->base); | |
15987 | encoder->base.crtc->state->encoder_mask |= | |
15988 | 1 << drm_encoder_index(&encoder->base); | |
15989 | } | |
15990 | ||
15991 | } else { | |
15992 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15993 | connector->base.encoder = NULL; | |
15994 | } | |
15995 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15996 | connector->base.base.id, | |
15997 | connector->base.name, | |
15998 | connector->base.encoder ? "enabled" : "disabled"); | |
15999 | } | |
16000 | ||
16001 | for_each_intel_crtc(dev, crtc) { | |
16002 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
16003 | ||
16004 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
16005 | if (crtc->base.state->active) { | |
16006 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
16007 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
16008 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
16009 | ||
16010 | /* | |
16011 | * The initial mode needs to be set in order to keep | |
16012 | * the atomic core happy. It wants a valid mode if the | |
16013 | * crtc's enabled, so we do the above call. | |
16014 | * | |
16015 | * At this point some state updated by the connectors | |
16016 | * in their ->detect() callback has not run yet, so | |
16017 | * no recalculation can be done yet. | |
16018 | * | |
16019 | * Even if we could do a recalculation and modeset | |
16020 | * right now it would cause a double modeset if | |
16021 | * fbdev or userspace chooses a different initial mode. | |
16022 | * | |
16023 | * If that happens, someone indicated they wanted a | |
16024 | * mode change, which means it's safe to do a full | |
16025 | * recalculation. | |
16026 | */ | |
16027 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
16028 | ||
16029 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
16030 | update_scanline_offset(crtc); | |
16031 | } | |
16032 | } | |
16033 | } | |
16034 | ||
16035 | /* Scan out the current hw modeset state, | |
16036 | * and sanitizes it to the current state | |
16037 | */ | |
16038 | static void | |
16039 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
16040 | { | |
16041 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16042 | enum pipe pipe; | |
16043 | struct intel_crtc *crtc; | |
16044 | struct intel_encoder *encoder; | |
16045 | int i; | |
16046 | ||
16047 | intel_modeset_readout_hw_state(dev); | |
16048 | ||
16049 | /* HW state is read out, now we need to sanitize this mess. */ | |
16050 | for_each_intel_encoder(dev, encoder) { | |
16051 | intel_sanitize_encoder(encoder); | |
16052 | } | |
16053 | ||
16054 | for_each_pipe(dev_priv, pipe) { | |
16055 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); | |
16056 | intel_sanitize_crtc(crtc); | |
16057 | intel_dump_pipe_config(crtc, crtc->config, | |
16058 | "[setup_hw_state]"); | |
16059 | } | |
16060 | ||
16061 | intel_modeset_update_connector_atomic_state(dev); | |
16062 | ||
16063 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
16064 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
16065 | ||
16066 | if (!pll->on || pll->active) | |
16067 | continue; | |
16068 | ||
16069 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
16070 | ||
16071 | pll->disable(dev_priv, pll); | |
16072 | pll->on = false; | |
16073 | } | |
16074 | ||
16075 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) | |
16076 | vlv_wm_get_hw_state(dev); | |
16077 | else if (IS_GEN9(dev)) | |
16078 | skl_wm_get_hw_state(dev); | |
16079 | else if (HAS_PCH_SPLIT(dev)) | |
16080 | ilk_wm_get_hw_state(dev); | |
16081 | ||
16082 | for_each_intel_crtc(dev, crtc) { | |
16083 | unsigned long put_domains; | |
16084 | ||
16085 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); | |
16086 | if (WARN_ON(put_domains)) | |
16087 | modeset_put_power_domains(dev_priv, put_domains); | |
16088 | } | |
16089 | intel_display_set_init_power(dev_priv, false); | |
16090 | ||
16091 | intel_fbc_init_pipe_state(dev_priv); | |
16092 | } | |
16093 | ||
16094 | void intel_display_resume(struct drm_device *dev) | |
16095 | { | |
16096 | struct drm_i915_private *dev_priv = to_i915(dev); | |
16097 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; | |
16098 | struct drm_modeset_acquire_ctx ctx; | |
16099 | int ret; | |
16100 | bool setup = false; | |
16101 | ||
16102 | dev_priv->modeset_restore_state = NULL; | |
16103 | ||
16104 | /* | |
16105 | * This is a cludge because with real atomic modeset mode_config.mutex | |
16106 | * won't be taken. Unfortunately some probed state like | |
16107 | * audio_codec_enable is still protected by mode_config.mutex, so lock | |
16108 | * it here for now. | |
16109 | */ | |
16110 | mutex_lock(&dev->mode_config.mutex); | |
16111 | drm_modeset_acquire_init(&ctx, 0); | |
16112 | ||
16113 | retry: | |
16114 | ret = drm_modeset_lock_all_ctx(dev, &ctx); | |
16115 | ||
16116 | if (ret == 0 && !setup) { | |
16117 | setup = true; | |
16118 | ||
16119 | intel_modeset_setup_hw_state(dev); | |
16120 | i915_redisable_vga(dev); | |
16121 | } | |
16122 | ||
16123 | if (ret == 0 && state) { | |
16124 | struct drm_crtc_state *crtc_state; | |
16125 | struct drm_crtc *crtc; | |
16126 | int i; | |
16127 | ||
16128 | state->acquire_ctx = &ctx; | |
16129 | ||
16130 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
16131 | /* | |
16132 | * Force recalculation even if we restore | |
16133 | * current state. With fast modeset this may not result | |
16134 | * in a modeset when the state is compatible. | |
16135 | */ | |
16136 | crtc_state->mode_changed = true; | |
16137 | } | |
16138 | ||
16139 | ret = drm_atomic_commit(state); | |
16140 | } | |
16141 | ||
16142 | if (ret == -EDEADLK) { | |
16143 | drm_modeset_backoff(&ctx); | |
16144 | goto retry; | |
16145 | } | |
16146 | ||
16147 | drm_modeset_drop_locks(&ctx); | |
16148 | drm_modeset_acquire_fini(&ctx); | |
16149 | mutex_unlock(&dev->mode_config.mutex); | |
16150 | ||
16151 | if (ret) { | |
16152 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
16153 | drm_atomic_state_free(state); | |
16154 | } | |
16155 | } | |
16156 | ||
16157 | void intel_modeset_gem_init(struct drm_device *dev) | |
16158 | { | |
16159 | struct drm_crtc *c; | |
16160 | struct drm_i915_gem_object *obj; | |
16161 | int ret; | |
16162 | ||
16163 | intel_init_gt_powersave(dev); | |
16164 | ||
16165 | intel_modeset_init_hw(dev); | |
16166 | ||
16167 | intel_setup_overlay(dev); | |
16168 | ||
16169 | /* | |
16170 | * Make sure any fbs we allocated at startup are properly | |
16171 | * pinned & fenced. When we do the allocation it's too early | |
16172 | * for this. | |
16173 | */ | |
16174 | for_each_crtc(dev, c) { | |
16175 | obj = intel_fb_obj(c->primary->fb); | |
16176 | if (obj == NULL) | |
16177 | continue; | |
16178 | ||
16179 | mutex_lock(&dev->struct_mutex); | |
16180 | ret = intel_pin_and_fence_fb_obj(c->primary->fb, | |
16181 | c->primary->state->rotation); | |
16182 | mutex_unlock(&dev->struct_mutex); | |
16183 | if (ret) { | |
16184 | DRM_ERROR("failed to pin boot fb on pipe %d\n", | |
16185 | to_intel_crtc(c)->pipe); | |
16186 | drm_framebuffer_unreference(c->primary->fb); | |
16187 | c->primary->fb = NULL; | |
16188 | c->primary->crtc = c->primary->state->crtc = NULL; | |
16189 | update_state_fb(c->primary); | |
16190 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); | |
16191 | } | |
16192 | } | |
16193 | ||
16194 | intel_backlight_register(dev); | |
16195 | } | |
16196 | ||
16197 | void intel_connector_unregister(struct intel_connector *intel_connector) | |
16198 | { | |
16199 | struct drm_connector *connector = &intel_connector->base; | |
16200 | ||
16201 | intel_panel_destroy_backlight(connector); | |
16202 | drm_connector_unregister(connector); | |
16203 | } | |
16204 | ||
16205 | void intel_modeset_cleanup(struct drm_device *dev) | |
16206 | { | |
16207 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16208 | struct intel_connector *connector; | |
16209 | ||
16210 | intel_disable_gt_powersave(dev); | |
16211 | ||
16212 | intel_backlight_unregister(dev); | |
16213 | ||
16214 | /* | |
16215 | * Interrupts and polling as the first thing to avoid creating havoc. | |
16216 | * Too much stuff here (turning of connectors, ...) would | |
16217 | * experience fancy races otherwise. | |
16218 | */ | |
16219 | intel_irq_uninstall(dev_priv); | |
16220 | ||
16221 | /* | |
16222 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
16223 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
16224 | */ | |
16225 | drm_kms_helper_poll_fini(dev); | |
16226 | ||
16227 | intel_unregister_dsm_handler(); | |
16228 | ||
16229 | intel_fbc_global_disable(dev_priv); | |
16230 | ||
16231 | /* flush any delayed tasks or pending work */ | |
16232 | flush_scheduled_work(); | |
16233 | ||
16234 | /* destroy the backlight and sysfs files before encoders/connectors */ | |
16235 | for_each_intel_connector(dev, connector) | |
16236 | connector->unregister(connector); | |
16237 | ||
16238 | drm_mode_config_cleanup(dev); | |
16239 | ||
16240 | intel_cleanup_overlay(dev); | |
16241 | ||
16242 | intel_cleanup_gt_powersave(dev); | |
16243 | ||
16244 | intel_teardown_gmbus(dev); | |
16245 | } | |
16246 | ||
16247 | /* | |
16248 | * Return which encoder is currently attached for connector. | |
16249 | */ | |
16250 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) | |
16251 | { | |
16252 | return &intel_attached_encoder(connector)->base; | |
16253 | } | |
16254 | ||
16255 | void intel_connector_attach_encoder(struct intel_connector *connector, | |
16256 | struct intel_encoder *encoder) | |
16257 | { | |
16258 | connector->encoder = encoder; | |
16259 | drm_mode_connector_attach_encoder(&connector->base, | |
16260 | &encoder->base); | |
16261 | } | |
16262 | ||
16263 | /* | |
16264 | * set vga decode state - true == enable VGA decode | |
16265 | */ | |
16266 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
16267 | { | |
16268 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16269 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; | |
16270 | u16 gmch_ctrl; | |
16271 | ||
16272 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { | |
16273 | DRM_ERROR("failed to read control word\n"); | |
16274 | return -EIO; | |
16275 | } | |
16276 | ||
16277 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) | |
16278 | return 0; | |
16279 | ||
16280 | if (state) | |
16281 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
16282 | else | |
16283 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
16284 | ||
16285 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
16286 | DRM_ERROR("failed to write control word\n"); | |
16287 | return -EIO; | |
16288 | } | |
16289 | ||
16290 | return 0; | |
16291 | } | |
16292 | ||
16293 | struct intel_display_error_state { | |
16294 | ||
16295 | u32 power_well_driver; | |
16296 | ||
16297 | int num_transcoders; | |
16298 | ||
16299 | struct intel_cursor_error_state { | |
16300 | u32 control; | |
16301 | u32 position; | |
16302 | u32 base; | |
16303 | u32 size; | |
16304 | } cursor[I915_MAX_PIPES]; | |
16305 | ||
16306 | struct intel_pipe_error_state { | |
16307 | bool power_domain_on; | |
16308 | u32 source; | |
16309 | u32 stat; | |
16310 | } pipe[I915_MAX_PIPES]; | |
16311 | ||
16312 | struct intel_plane_error_state { | |
16313 | u32 control; | |
16314 | u32 stride; | |
16315 | u32 size; | |
16316 | u32 pos; | |
16317 | u32 addr; | |
16318 | u32 surface; | |
16319 | u32 tile_offset; | |
16320 | } plane[I915_MAX_PIPES]; | |
16321 | ||
16322 | struct intel_transcoder_error_state { | |
16323 | bool power_domain_on; | |
16324 | enum transcoder cpu_transcoder; | |
16325 | ||
16326 | u32 conf; | |
16327 | ||
16328 | u32 htotal; | |
16329 | u32 hblank; | |
16330 | u32 hsync; | |
16331 | u32 vtotal; | |
16332 | u32 vblank; | |
16333 | u32 vsync; | |
16334 | } transcoder[4]; | |
16335 | }; | |
16336 | ||
16337 | struct intel_display_error_state * | |
16338 | intel_display_capture_error_state(struct drm_device *dev) | |
16339 | { | |
16340 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16341 | struct intel_display_error_state *error; | |
16342 | int transcoders[] = { | |
16343 | TRANSCODER_A, | |
16344 | TRANSCODER_B, | |
16345 | TRANSCODER_C, | |
16346 | TRANSCODER_EDP, | |
16347 | }; | |
16348 | int i; | |
16349 | ||
16350 | if (INTEL_INFO(dev)->num_pipes == 0) | |
16351 | return NULL; | |
16352 | ||
16353 | error = kzalloc(sizeof(*error), GFP_ATOMIC); | |
16354 | if (error == NULL) | |
16355 | return NULL; | |
16356 | ||
16357 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
16358 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); | |
16359 | ||
16360 | for_each_pipe(dev_priv, i) { | |
16361 | error->pipe[i].power_domain_on = | |
16362 | __intel_display_power_is_enabled(dev_priv, | |
16363 | POWER_DOMAIN_PIPE(i)); | |
16364 | if (!error->pipe[i].power_domain_on) | |
16365 | continue; | |
16366 | ||
16367 | error->cursor[i].control = I915_READ(CURCNTR(i)); | |
16368 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
16369 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
16370 | ||
16371 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
16372 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
16373 | if (INTEL_INFO(dev)->gen <= 3) { | |
16374 | error->plane[i].size = I915_READ(DSPSIZE(i)); | |
16375 | error->plane[i].pos = I915_READ(DSPPOS(i)); | |
16376 | } | |
16377 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) | |
16378 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
16379 | if (INTEL_INFO(dev)->gen >= 4) { | |
16380 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
16381 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
16382 | } | |
16383 | ||
16384 | error->pipe[i].source = I915_READ(PIPESRC(i)); | |
16385 | ||
16386 | if (HAS_GMCH_DISPLAY(dev)) | |
16387 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); | |
16388 | } | |
16389 | ||
16390 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
16391 | if (HAS_DDI(dev_priv->dev)) | |
16392 | error->num_transcoders++; /* Account for eDP. */ | |
16393 | ||
16394 | for (i = 0; i < error->num_transcoders; i++) { | |
16395 | enum transcoder cpu_transcoder = transcoders[i]; | |
16396 | ||
16397 | error->transcoder[i].power_domain_on = | |
16398 | __intel_display_power_is_enabled(dev_priv, | |
16399 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); | |
16400 | if (!error->transcoder[i].power_domain_on) | |
16401 | continue; | |
16402 | ||
16403 | error->transcoder[i].cpu_transcoder = cpu_transcoder; | |
16404 | ||
16405 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
16406 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
16407 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
16408 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
16409 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
16410 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
16411 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
16412 | } | |
16413 | ||
16414 | return error; | |
16415 | } | |
16416 | ||
16417 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) | |
16418 | ||
16419 | void | |
16420 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, | |
16421 | struct drm_device *dev, | |
16422 | struct intel_display_error_state *error) | |
16423 | { | |
16424 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16425 | int i; | |
16426 | ||
16427 | if (!error) | |
16428 | return; | |
16429 | ||
16430 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); | |
16431 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
16432 | err_printf(m, "PWR_WELL_CTL2: %08x\n", | |
16433 | error->power_well_driver); | |
16434 | for_each_pipe(dev_priv, i) { | |
16435 | err_printf(m, "Pipe [%d]:\n", i); | |
16436 | err_printf(m, " Power: %s\n", | |
16437 | onoff(error->pipe[i].power_domain_on)); | |
16438 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); | |
16439 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); | |
16440 | ||
16441 | err_printf(m, "Plane [%d]:\n", i); | |
16442 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
16443 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
16444 | if (INTEL_INFO(dev)->gen <= 3) { | |
16445 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); | |
16446 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
16447 | } | |
16448 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) | |
16449 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); | |
16450 | if (INTEL_INFO(dev)->gen >= 4) { | |
16451 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); | |
16452 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
16453 | } | |
16454 | ||
16455 | err_printf(m, "Cursor [%d]:\n", i); | |
16456 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
16457 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
16458 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
16459 | } | |
16460 | ||
16461 | for (i = 0; i < error->num_transcoders; i++) { | |
16462 | err_printf(m, "CPU transcoder: %c\n", | |
16463 | transcoder_name(error->transcoder[i].cpu_transcoder)); | |
16464 | err_printf(m, " Power: %s\n", | |
16465 | onoff(error->transcoder[i].power_domain_on)); | |
16466 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); | |
16467 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
16468 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
16469 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
16470 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
16471 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
16472 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
16473 | } | |
16474 | } |