Commit | Line | Data |
---|---|---|
79e53945 JB |
1 | /* |
2 | * Copyright © 2006-2007 Intel Corporation | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * Eric Anholt <eric@anholt.net> | |
25 | */ | |
26 | ||
618563e3 | 27 | #include <linux/dmi.h> |
c1c7af60 JB |
28 | #include <linux/module.h> |
29 | #include <linux/input.h> | |
79e53945 | 30 | #include <linux/i2c.h> |
7662c8bd | 31 | #include <linux/kernel.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
9cce37f4 | 33 | #include <linux/vgaarb.h> |
e0dac65e | 34 | #include <drm/drm_edid.h> |
760285e7 | 35 | #include <drm/drmP.h> |
79e53945 | 36 | #include "intel_drv.h" |
760285e7 | 37 | #include <drm/i915_drm.h> |
79e53945 | 38 | #include "i915_drv.h" |
e5510fac | 39 | #include "i915_trace.h" |
319c1d42 | 40 | #include <drm/drm_atomic.h> |
c196e1d6 | 41 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
42 | #include <drm/drm_dp_helper.h> |
43 | #include <drm/drm_crtc_helper.h> | |
465c120c MR |
44 | #include <drm/drm_plane_helper.h> |
45 | #include <drm/drm_rect.h> | |
c0f372b3 | 46 | #include <linux/dma_remapping.h> |
79e53945 | 47 | |
465c120c | 48 | /* Primary plane formats for gen <= 3 */ |
568db4f2 | 49 | static const uint32_t i8xx_primary_formats[] = { |
67fe7dc5 DL |
50 | DRM_FORMAT_C8, |
51 | DRM_FORMAT_RGB565, | |
465c120c | 52 | DRM_FORMAT_XRGB1555, |
67fe7dc5 | 53 | DRM_FORMAT_XRGB8888, |
465c120c MR |
54 | }; |
55 | ||
56 | /* Primary plane formats for gen >= 4 */ | |
568db4f2 | 57 | static const uint32_t i965_primary_formats[] = { |
6c0fd451 DL |
58 | DRM_FORMAT_C8, |
59 | DRM_FORMAT_RGB565, | |
60 | DRM_FORMAT_XRGB8888, | |
61 | DRM_FORMAT_XBGR8888, | |
62 | DRM_FORMAT_XRGB2101010, | |
63 | DRM_FORMAT_XBGR2101010, | |
64 | }; | |
65 | ||
66 | static const uint32_t skl_primary_formats[] = { | |
67fe7dc5 DL |
67 | DRM_FORMAT_C8, |
68 | DRM_FORMAT_RGB565, | |
69 | DRM_FORMAT_XRGB8888, | |
465c120c | 70 | DRM_FORMAT_XBGR8888, |
67fe7dc5 | 71 | DRM_FORMAT_ARGB8888, |
465c120c MR |
72 | DRM_FORMAT_ABGR8888, |
73 | DRM_FORMAT_XRGB2101010, | |
465c120c | 74 | DRM_FORMAT_XBGR2101010, |
ea916ea0 KM |
75 | DRM_FORMAT_YUYV, |
76 | DRM_FORMAT_YVYU, | |
77 | DRM_FORMAT_UYVY, | |
78 | DRM_FORMAT_VYUY, | |
465c120c MR |
79 | }; |
80 | ||
3d7d6510 MR |
81 | /* Cursor formats */ |
82 | static const uint32_t intel_cursor_formats[] = { | |
83 | DRM_FORMAT_ARGB8888, | |
84 | }; | |
85 | ||
6b383a7f | 86 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
79e53945 | 87 | |
f1f644dc | 88 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 89 | struct intel_crtc_state *pipe_config); |
18442d08 | 90 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 91 | struct intel_crtc_state *pipe_config); |
f1f644dc | 92 | |
eb1bfe80 JB |
93 | static int intel_framebuffer_init(struct drm_device *dev, |
94 | struct intel_framebuffer *ifb, | |
95 | struct drm_mode_fb_cmd2 *mode_cmd, | |
96 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
97 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
98 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
29407aab | 99 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
100 | struct intel_link_m_n *m_n, |
101 | struct intel_link_m_n *m2_n2); | |
29407aab | 102 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 DV |
103 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
104 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
d288f65f | 105 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 106 | const struct intel_crtc_state *pipe_config); |
d288f65f | 107 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 108 | const struct intel_crtc_state *pipe_config); |
613d2b27 ML |
109 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
110 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); | |
549e2bfb CK |
111 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
112 | struct intel_crtc_state *crtc_state); | |
5ab7b0b7 ID |
113 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
114 | int num_connectors); | |
bfd16b2a ML |
115 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
116 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); | |
117 | static void ironlake_pfit_enable(struct intel_crtc *crtc); | |
043e9bda | 118 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
e7457a9a | 119 | |
79e53945 | 120 | typedef struct { |
0206e353 | 121 | int min, max; |
79e53945 JB |
122 | } intel_range_t; |
123 | ||
124 | typedef struct { | |
0206e353 AJ |
125 | int dot_limit; |
126 | int p2_slow, p2_fast; | |
79e53945 JB |
127 | } intel_p2_t; |
128 | ||
d4906093 ML |
129 | typedef struct intel_limit intel_limit_t; |
130 | struct intel_limit { | |
0206e353 AJ |
131 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
132 | intel_p2_t p2; | |
d4906093 | 133 | }; |
79e53945 | 134 | |
bfa7df01 VS |
135 | /* returns HPLL frequency in kHz */ |
136 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) | |
137 | { | |
138 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; | |
139 | ||
140 | /* Obtain SKU information */ | |
141 | mutex_lock(&dev_priv->sb_lock); | |
142 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
143 | CCK_FUSE_HPLL_FREQ_MASK; | |
144 | mutex_unlock(&dev_priv->sb_lock); | |
145 | ||
146 | return vco_freq[hpll_freq] * 1000; | |
147 | } | |
148 | ||
149 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, | |
150 | const char *name, u32 reg) | |
151 | { | |
152 | u32 val; | |
153 | int divider; | |
154 | ||
155 | if (dev_priv->hpll_freq == 0) | |
156 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
157 | ||
158 | mutex_lock(&dev_priv->sb_lock); | |
159 | val = vlv_cck_read(dev_priv, reg); | |
160 | mutex_unlock(&dev_priv->sb_lock); | |
161 | ||
162 | divider = val & CCK_FREQUENCY_VALUES; | |
163 | ||
164 | WARN((val & CCK_FREQUENCY_STATUS) != | |
165 | (divider << CCK_FREQUENCY_STATUS_SHIFT), | |
166 | "%s change in progress\n", name); | |
167 | ||
168 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); | |
169 | } | |
170 | ||
d2acd215 DV |
171 | int |
172 | intel_pch_rawclk(struct drm_device *dev) | |
173 | { | |
174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
175 | ||
176 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
177 | ||
178 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
179 | } | |
180 | ||
79e50a4f JN |
181 | /* hrawclock is 1/4 the FSB frequency */ |
182 | int intel_hrawclk(struct drm_device *dev) | |
183 | { | |
184 | struct drm_i915_private *dev_priv = dev->dev_private; | |
185 | uint32_t clkcfg; | |
186 | ||
187 | /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */ | |
188 | if (IS_VALLEYVIEW(dev)) | |
189 | return 200; | |
190 | ||
191 | clkcfg = I915_READ(CLKCFG); | |
192 | switch (clkcfg & CLKCFG_FSB_MASK) { | |
193 | case CLKCFG_FSB_400: | |
194 | return 100; | |
195 | case CLKCFG_FSB_533: | |
196 | return 133; | |
197 | case CLKCFG_FSB_667: | |
198 | return 166; | |
199 | case CLKCFG_FSB_800: | |
200 | return 200; | |
201 | case CLKCFG_FSB_1067: | |
202 | return 266; | |
203 | case CLKCFG_FSB_1333: | |
204 | return 333; | |
205 | /* these two are just a guess; one of them might be right */ | |
206 | case CLKCFG_FSB_1600: | |
207 | case CLKCFG_FSB_1600_ALT: | |
208 | return 400; | |
209 | default: | |
210 | return 133; | |
211 | } | |
212 | } | |
213 | ||
bfa7df01 VS |
214 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
215 | { | |
216 | if (!IS_VALLEYVIEW(dev_priv)) | |
217 | return; | |
218 | ||
219 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", | |
220 | CCK_CZ_CLOCK_CONTROL); | |
221 | ||
222 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); | |
223 | } | |
224 | ||
021357ac CW |
225 | static inline u32 /* units of 100MHz */ |
226 | intel_fdi_link_freq(struct drm_device *dev) | |
227 | { | |
8b99e68c CW |
228 | if (IS_GEN5(dev)) { |
229 | struct drm_i915_private *dev_priv = dev->dev_private; | |
230 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
231 | } else | |
232 | return 27; | |
021357ac CW |
233 | } |
234 | ||
5d536e28 | 235 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 236 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 237 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 238 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
239 | .m = { .min = 96, .max = 140 }, |
240 | .m1 = { .min = 18, .max = 26 }, | |
241 | .m2 = { .min = 6, .max = 16 }, | |
242 | .p = { .min = 4, .max = 128 }, | |
243 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
244 | .p2 = { .dot_limit = 165000, |
245 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
246 | }; |
247 | ||
5d536e28 DV |
248 | static const intel_limit_t intel_limits_i8xx_dvo = { |
249 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 250 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 251 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
252 | .m = { .min = 96, .max = 140 }, |
253 | .m1 = { .min = 18, .max = 26 }, | |
254 | .m2 = { .min = 6, .max = 16 }, | |
255 | .p = { .min = 4, .max = 128 }, | |
256 | .p1 = { .min = 2, .max = 33 }, | |
257 | .p2 = { .dot_limit = 165000, | |
258 | .p2_slow = 4, .p2_fast = 4 }, | |
259 | }; | |
260 | ||
e4b36699 | 261 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 262 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 263 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 264 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
265 | .m = { .min = 96, .max = 140 }, |
266 | .m1 = { .min = 18, .max = 26 }, | |
267 | .m2 = { .min = 6, .max = 16 }, | |
268 | .p = { .min = 4, .max = 128 }, | |
269 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
270 | .p2 = { .dot_limit = 165000, |
271 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 272 | }; |
273e27ca | 273 | |
e4b36699 | 274 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
275 | .dot = { .min = 20000, .max = 400000 }, |
276 | .vco = { .min = 1400000, .max = 2800000 }, | |
277 | .n = { .min = 1, .max = 6 }, | |
278 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
279 | .m1 = { .min = 8, .max = 18 }, |
280 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
281 | .p = { .min = 5, .max = 80 }, |
282 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
283 | .p2 = { .dot_limit = 200000, |
284 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
285 | }; |
286 | ||
287 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
288 | .dot = { .min = 20000, .max = 400000 }, |
289 | .vco = { .min = 1400000, .max = 2800000 }, | |
290 | .n = { .min = 1, .max = 6 }, | |
291 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
292 | .m1 = { .min = 8, .max = 18 }, |
293 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
294 | .p = { .min = 7, .max = 98 }, |
295 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
296 | .p2 = { .dot_limit = 112000, |
297 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
298 | }; |
299 | ||
273e27ca | 300 | |
e4b36699 | 301 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
302 | .dot = { .min = 25000, .max = 270000 }, |
303 | .vco = { .min = 1750000, .max = 3500000}, | |
304 | .n = { .min = 1, .max = 4 }, | |
305 | .m = { .min = 104, .max = 138 }, | |
306 | .m1 = { .min = 17, .max = 23 }, | |
307 | .m2 = { .min = 5, .max = 11 }, | |
308 | .p = { .min = 10, .max = 30 }, | |
309 | .p1 = { .min = 1, .max = 3}, | |
310 | .p2 = { .dot_limit = 270000, | |
311 | .p2_slow = 10, | |
312 | .p2_fast = 10 | |
044c7c41 | 313 | }, |
e4b36699 KP |
314 | }; |
315 | ||
316 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
317 | .dot = { .min = 22000, .max = 400000 }, |
318 | .vco = { .min = 1750000, .max = 3500000}, | |
319 | .n = { .min = 1, .max = 4 }, | |
320 | .m = { .min = 104, .max = 138 }, | |
321 | .m1 = { .min = 16, .max = 23 }, | |
322 | .m2 = { .min = 5, .max = 11 }, | |
323 | .p = { .min = 5, .max = 80 }, | |
324 | .p1 = { .min = 1, .max = 8}, | |
325 | .p2 = { .dot_limit = 165000, | |
326 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
327 | }; |
328 | ||
329 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
330 | .dot = { .min = 20000, .max = 115000 }, |
331 | .vco = { .min = 1750000, .max = 3500000 }, | |
332 | .n = { .min = 1, .max = 3 }, | |
333 | .m = { .min = 104, .max = 138 }, | |
334 | .m1 = { .min = 17, .max = 23 }, | |
335 | .m2 = { .min = 5, .max = 11 }, | |
336 | .p = { .min = 28, .max = 112 }, | |
337 | .p1 = { .min = 2, .max = 8 }, | |
338 | .p2 = { .dot_limit = 0, | |
339 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 340 | }, |
e4b36699 KP |
341 | }; |
342 | ||
343 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
344 | .dot = { .min = 80000, .max = 224000 }, |
345 | .vco = { .min = 1750000, .max = 3500000 }, | |
346 | .n = { .min = 1, .max = 3 }, | |
347 | .m = { .min = 104, .max = 138 }, | |
348 | .m1 = { .min = 17, .max = 23 }, | |
349 | .m2 = { .min = 5, .max = 11 }, | |
350 | .p = { .min = 14, .max = 42 }, | |
351 | .p1 = { .min = 2, .max = 6 }, | |
352 | .p2 = { .dot_limit = 0, | |
353 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 354 | }, |
e4b36699 KP |
355 | }; |
356 | ||
f2b115e6 | 357 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
358 | .dot = { .min = 20000, .max = 400000}, |
359 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 360 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
361 | .n = { .min = 3, .max = 6 }, |
362 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 363 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
364 | .m1 = { .min = 0, .max = 0 }, |
365 | .m2 = { .min = 0, .max = 254 }, | |
366 | .p = { .min = 5, .max = 80 }, | |
367 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
368 | .p2 = { .dot_limit = 200000, |
369 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
370 | }; |
371 | ||
f2b115e6 | 372 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
373 | .dot = { .min = 20000, .max = 400000 }, |
374 | .vco = { .min = 1700000, .max = 3500000 }, | |
375 | .n = { .min = 3, .max = 6 }, | |
376 | .m = { .min = 2, .max = 256 }, | |
377 | .m1 = { .min = 0, .max = 0 }, | |
378 | .m2 = { .min = 0, .max = 254 }, | |
379 | .p = { .min = 7, .max = 112 }, | |
380 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
381 | .p2 = { .dot_limit = 112000, |
382 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
383 | }; |
384 | ||
273e27ca EA |
385 | /* Ironlake / Sandybridge |
386 | * | |
387 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
388 | * the range value for them is (actual_value - 2). | |
389 | */ | |
b91ad0ec | 390 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
391 | .dot = { .min = 25000, .max = 350000 }, |
392 | .vco = { .min = 1760000, .max = 3510000 }, | |
393 | .n = { .min = 1, .max = 5 }, | |
394 | .m = { .min = 79, .max = 127 }, | |
395 | .m1 = { .min = 12, .max = 22 }, | |
396 | .m2 = { .min = 5, .max = 9 }, | |
397 | .p = { .min = 5, .max = 80 }, | |
398 | .p1 = { .min = 1, .max = 8 }, | |
399 | .p2 = { .dot_limit = 225000, | |
400 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
401 | }; |
402 | ||
b91ad0ec | 403 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
404 | .dot = { .min = 25000, .max = 350000 }, |
405 | .vco = { .min = 1760000, .max = 3510000 }, | |
406 | .n = { .min = 1, .max = 3 }, | |
407 | .m = { .min = 79, .max = 118 }, | |
408 | .m1 = { .min = 12, .max = 22 }, | |
409 | .m2 = { .min = 5, .max = 9 }, | |
410 | .p = { .min = 28, .max = 112 }, | |
411 | .p1 = { .min = 2, .max = 8 }, | |
412 | .p2 = { .dot_limit = 225000, | |
413 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
414 | }; |
415 | ||
416 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
417 | .dot = { .min = 25000, .max = 350000 }, |
418 | .vco = { .min = 1760000, .max = 3510000 }, | |
419 | .n = { .min = 1, .max = 3 }, | |
420 | .m = { .min = 79, .max = 127 }, | |
421 | .m1 = { .min = 12, .max = 22 }, | |
422 | .m2 = { .min = 5, .max = 9 }, | |
423 | .p = { .min = 14, .max = 56 }, | |
424 | .p1 = { .min = 2, .max = 8 }, | |
425 | .p2 = { .dot_limit = 225000, | |
426 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
427 | }; |
428 | ||
273e27ca | 429 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 430 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
431 | .dot = { .min = 25000, .max = 350000 }, |
432 | .vco = { .min = 1760000, .max = 3510000 }, | |
433 | .n = { .min = 1, .max = 2 }, | |
434 | .m = { .min = 79, .max = 126 }, | |
435 | .m1 = { .min = 12, .max = 22 }, | |
436 | .m2 = { .min = 5, .max = 9 }, | |
437 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 438 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
439 | .p2 = { .dot_limit = 225000, |
440 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
441 | }; |
442 | ||
443 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
444 | .dot = { .min = 25000, .max = 350000 }, |
445 | .vco = { .min = 1760000, .max = 3510000 }, | |
446 | .n = { .min = 1, .max = 3 }, | |
447 | .m = { .min = 79, .max = 126 }, | |
448 | .m1 = { .min = 12, .max = 22 }, | |
449 | .m2 = { .min = 5, .max = 9 }, | |
450 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 451 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
452 | .p2 = { .dot_limit = 225000, |
453 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
454 | }; |
455 | ||
dc730512 | 456 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
457 | /* |
458 | * These are the data rate limits (measured in fast clocks) | |
459 | * since those are the strictest limits we have. The fast | |
460 | * clock and actual rate limits are more relaxed, so checking | |
461 | * them would make no difference. | |
462 | */ | |
463 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 464 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 465 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
466 | .m1 = { .min = 2, .max = 3 }, |
467 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 468 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 469 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
470 | }; |
471 | ||
ef9348c8 CML |
472 | static const intel_limit_t intel_limits_chv = { |
473 | /* | |
474 | * These are the data rate limits (measured in fast clocks) | |
475 | * since those are the strictest limits we have. The fast | |
476 | * clock and actual rate limits are more relaxed, so checking | |
477 | * them would make no difference. | |
478 | */ | |
479 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 480 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
481 | .n = { .min = 1, .max = 1 }, |
482 | .m1 = { .min = 2, .max = 2 }, | |
483 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
484 | .p1 = { .min = 2, .max = 4 }, | |
485 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
486 | }; | |
487 | ||
5ab7b0b7 ID |
488 | static const intel_limit_t intel_limits_bxt = { |
489 | /* FIXME: find real dot limits */ | |
490 | .dot = { .min = 0, .max = INT_MAX }, | |
e6292556 | 491 | .vco = { .min = 4800000, .max = 6700000 }, |
5ab7b0b7 ID |
492 | .n = { .min = 1, .max = 1 }, |
493 | .m1 = { .min = 2, .max = 2 }, | |
494 | /* FIXME: find real m2 limits */ | |
495 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
496 | .p1 = { .min = 2, .max = 4 }, | |
497 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
498 | }; | |
499 | ||
cdba954e ACO |
500 | static bool |
501 | needs_modeset(struct drm_crtc_state *state) | |
502 | { | |
fc596660 | 503 | return drm_atomic_crtc_needs_modeset(state); |
cdba954e ACO |
504 | } |
505 | ||
e0638cdf PZ |
506 | /** |
507 | * Returns whether any output on the specified pipe is of the specified type | |
508 | */ | |
4093561b | 509 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 510 | { |
409ee761 | 511 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
512 | struct intel_encoder *encoder; |
513 | ||
409ee761 | 514 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
515 | if (encoder->type == type) |
516 | return true; | |
517 | ||
518 | return false; | |
519 | } | |
520 | ||
d0737e1d ACO |
521 | /** |
522 | * Returns whether any output on the specified pipe will have the specified | |
523 | * type after a staged modeset is complete, i.e., the same as | |
524 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
525 | * encoder->crtc. | |
526 | */ | |
a93e255f ACO |
527 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
528 | int type) | |
d0737e1d | 529 | { |
a93e255f | 530 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 531 | struct drm_connector *connector; |
a93e255f | 532 | struct drm_connector_state *connector_state; |
d0737e1d | 533 | struct intel_encoder *encoder; |
a93e255f ACO |
534 | int i, num_connectors = 0; |
535 | ||
da3ced29 | 536 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
537 | if (connector_state->crtc != crtc_state->base.crtc) |
538 | continue; | |
539 | ||
540 | num_connectors++; | |
d0737e1d | 541 | |
a93e255f ACO |
542 | encoder = to_intel_encoder(connector_state->best_encoder); |
543 | if (encoder->type == type) | |
d0737e1d | 544 | return true; |
a93e255f ACO |
545 | } |
546 | ||
547 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
548 | |
549 | return false; | |
550 | } | |
551 | ||
a93e255f ACO |
552 | static const intel_limit_t * |
553 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 554 | { |
a93e255f | 555 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 556 | const intel_limit_t *limit; |
b91ad0ec | 557 | |
a93e255f | 558 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 559 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 560 | if (refclk == 100000) |
b91ad0ec ZW |
561 | limit = &intel_limits_ironlake_dual_lvds_100m; |
562 | else | |
563 | limit = &intel_limits_ironlake_dual_lvds; | |
564 | } else { | |
1b894b59 | 565 | if (refclk == 100000) |
b91ad0ec ZW |
566 | limit = &intel_limits_ironlake_single_lvds_100m; |
567 | else | |
568 | limit = &intel_limits_ironlake_single_lvds; | |
569 | } | |
c6bb3538 | 570 | } else |
b91ad0ec | 571 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
572 | |
573 | return limit; | |
574 | } | |
575 | ||
a93e255f ACO |
576 | static const intel_limit_t * |
577 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 578 | { |
a93e255f | 579 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
580 | const intel_limit_t *limit; |
581 | ||
a93e255f | 582 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 583 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 584 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 585 | else |
e4b36699 | 586 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
587 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
588 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 589 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 590 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 591 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 592 | } else /* The option is for other outputs */ |
e4b36699 | 593 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
594 | |
595 | return limit; | |
596 | } | |
597 | ||
a93e255f ACO |
598 | static const intel_limit_t * |
599 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 600 | { |
a93e255f | 601 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
602 | const intel_limit_t *limit; |
603 | ||
5ab7b0b7 ID |
604 | if (IS_BROXTON(dev)) |
605 | limit = &intel_limits_bxt; | |
606 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 607 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 608 | else if (IS_G4X(dev)) { |
a93e255f | 609 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 610 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 611 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 612 | limit = &intel_limits_pineview_lvds; |
2177832f | 613 | else |
f2b115e6 | 614 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
615 | } else if (IS_CHERRYVIEW(dev)) { |
616 | limit = &intel_limits_chv; | |
a0c4da24 | 617 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 618 | limit = &intel_limits_vlv; |
a6c45cf0 | 619 | } else if (!IS_GEN2(dev)) { |
a93e255f | 620 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
621 | limit = &intel_limits_i9xx_lvds; |
622 | else | |
623 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 624 | } else { |
a93e255f | 625 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 626 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 627 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 628 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
629 | else |
630 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
631 | } |
632 | return limit; | |
633 | } | |
634 | ||
dccbea3b ID |
635 | /* |
636 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
637 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
638 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
639 | * The helpers' return value is the rate of the clock that is fed to the | |
640 | * display engine's pipe which can be the above fast dot clock rate or a | |
641 | * divided-down version of it. | |
642 | */ | |
f2b115e6 | 643 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
dccbea3b | 644 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
79e53945 | 645 | { |
2177832f SL |
646 | clock->m = clock->m2 + 2; |
647 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e | 648 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
dccbea3b | 649 | return 0; |
fb03ac01 VS |
650 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
651 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
652 | |
653 | return clock->dot; | |
2177832f SL |
654 | } |
655 | ||
7429e9d4 DV |
656 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
657 | { | |
658 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
659 | } | |
660 | ||
dccbea3b | 661 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
2177832f | 662 | { |
7429e9d4 | 663 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 664 | clock->p = clock->p1 * clock->p2; |
ed5ca77e | 665 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
dccbea3b | 666 | return 0; |
fb03ac01 VS |
667 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
668 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
669 | |
670 | return clock->dot; | |
79e53945 JB |
671 | } |
672 | ||
dccbea3b | 673 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
589eca67 ID |
674 | { |
675 | clock->m = clock->m1 * clock->m2; | |
676 | clock->p = clock->p1 * clock->p2; | |
677 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 678 | return 0; |
589eca67 ID |
679 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
680 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
681 | |
682 | return clock->dot / 5; | |
589eca67 ID |
683 | } |
684 | ||
dccbea3b | 685 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
ef9348c8 CML |
686 | { |
687 | clock->m = clock->m1 * clock->m2; | |
688 | clock->p = clock->p1 * clock->p2; | |
689 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 690 | return 0; |
ef9348c8 CML |
691 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
692 | clock->n << 22); | |
693 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
694 | |
695 | return clock->dot / 5; | |
ef9348c8 CML |
696 | } |
697 | ||
7c04d1d9 | 698 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
699 | /** |
700 | * Returns whether the given set of divisors are valid for a given refclk with | |
701 | * the given connectors. | |
702 | */ | |
703 | ||
1b894b59 CW |
704 | static bool intel_PLL_is_valid(struct drm_device *dev, |
705 | const intel_limit_t *limit, | |
706 | const intel_clock_t *clock) | |
79e53945 | 707 | { |
f01b7962 VS |
708 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
709 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 710 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 711 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 712 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 713 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 714 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 715 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 716 | |
5ab7b0b7 | 717 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
f01b7962 VS |
718 | if (clock->m1 <= clock->m2) |
719 | INTELPllInvalid("m1 <= m2\n"); | |
720 | ||
5ab7b0b7 | 721 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
722 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
723 | INTELPllInvalid("p out of range\n"); | |
724 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
725 | INTELPllInvalid("m out of range\n"); | |
726 | } | |
727 | ||
79e53945 | 728 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 729 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
730 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
731 | * connector, etc., rather than just a single range. | |
732 | */ | |
733 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 734 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
735 | |
736 | return true; | |
737 | } | |
738 | ||
3b1429d9 VS |
739 | static int |
740 | i9xx_select_p2_div(const intel_limit_t *limit, | |
741 | const struct intel_crtc_state *crtc_state, | |
742 | int target) | |
79e53945 | 743 | { |
3b1429d9 | 744 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 745 | |
a93e255f | 746 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 747 | /* |
a210b028 DV |
748 | * For LVDS just rely on its current settings for dual-channel. |
749 | * We haven't figured out how to reliably set up different | |
750 | * single/dual channel state, if we even can. | |
79e53945 | 751 | */ |
1974cad0 | 752 | if (intel_is_dual_link_lvds(dev)) |
3b1429d9 | 753 | return limit->p2.p2_fast; |
79e53945 | 754 | else |
3b1429d9 | 755 | return limit->p2.p2_slow; |
79e53945 JB |
756 | } else { |
757 | if (target < limit->p2.dot_limit) | |
3b1429d9 | 758 | return limit->p2.p2_slow; |
79e53945 | 759 | else |
3b1429d9 | 760 | return limit->p2.p2_fast; |
79e53945 | 761 | } |
3b1429d9 VS |
762 | } |
763 | ||
764 | static bool | |
765 | i9xx_find_best_dpll(const intel_limit_t *limit, | |
766 | struct intel_crtc_state *crtc_state, | |
767 | int target, int refclk, intel_clock_t *match_clock, | |
768 | intel_clock_t *best_clock) | |
769 | { | |
770 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
771 | intel_clock_t clock; | |
772 | int err = target; | |
79e53945 | 773 | |
0206e353 | 774 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 775 | |
3b1429d9 VS |
776 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
777 | ||
42158660 ZY |
778 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
779 | clock.m1++) { | |
780 | for (clock.m2 = limit->m2.min; | |
781 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 782 | if (clock.m2 >= clock.m1) |
42158660 ZY |
783 | break; |
784 | for (clock.n = limit->n.min; | |
785 | clock.n <= limit->n.max; clock.n++) { | |
786 | for (clock.p1 = limit->p1.min; | |
787 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
788 | int this_err; |
789 | ||
dccbea3b | 790 | i9xx_calc_dpll_params(refclk, &clock); |
ac58c3f0 DV |
791 | if (!intel_PLL_is_valid(dev, limit, |
792 | &clock)) | |
793 | continue; | |
794 | if (match_clock && | |
795 | clock.p != match_clock->p) | |
796 | continue; | |
797 | ||
798 | this_err = abs(clock.dot - target); | |
799 | if (this_err < err) { | |
800 | *best_clock = clock; | |
801 | err = this_err; | |
802 | } | |
803 | } | |
804 | } | |
805 | } | |
806 | } | |
807 | ||
808 | return (err != target); | |
809 | } | |
810 | ||
811 | static bool | |
a93e255f ACO |
812 | pnv_find_best_dpll(const intel_limit_t *limit, |
813 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
814 | int target, int refclk, intel_clock_t *match_clock, |
815 | intel_clock_t *best_clock) | |
79e53945 | 816 | { |
3b1429d9 | 817 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 818 | intel_clock_t clock; |
79e53945 JB |
819 | int err = target; |
820 | ||
0206e353 | 821 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 822 | |
3b1429d9 VS |
823 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
824 | ||
42158660 ZY |
825 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
826 | clock.m1++) { | |
827 | for (clock.m2 = limit->m2.min; | |
828 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
829 | for (clock.n = limit->n.min; |
830 | clock.n <= limit->n.max; clock.n++) { | |
831 | for (clock.p1 = limit->p1.min; | |
832 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
833 | int this_err; |
834 | ||
dccbea3b | 835 | pnv_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
836 | if (!intel_PLL_is_valid(dev, limit, |
837 | &clock)) | |
79e53945 | 838 | continue; |
cec2f356 SP |
839 | if (match_clock && |
840 | clock.p != match_clock->p) | |
841 | continue; | |
79e53945 JB |
842 | |
843 | this_err = abs(clock.dot - target); | |
844 | if (this_err < err) { | |
845 | *best_clock = clock; | |
846 | err = this_err; | |
847 | } | |
848 | } | |
849 | } | |
850 | } | |
851 | } | |
852 | ||
853 | return (err != target); | |
854 | } | |
855 | ||
d4906093 | 856 | static bool |
a93e255f ACO |
857 | g4x_find_best_dpll(const intel_limit_t *limit, |
858 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
859 | int target, int refclk, intel_clock_t *match_clock, |
860 | intel_clock_t *best_clock) | |
d4906093 | 861 | { |
3b1429d9 | 862 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d4906093 ML |
863 | intel_clock_t clock; |
864 | int max_n; | |
3b1429d9 | 865 | bool found = false; |
6ba770dc AJ |
866 | /* approximately equals target * 0.00585 */ |
867 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
868 | |
869 | memset(best_clock, 0, sizeof(*best_clock)); | |
3b1429d9 VS |
870 | |
871 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
872 | ||
d4906093 | 873 | max_n = limit->n.max; |
f77f13e2 | 874 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 875 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 876 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
877 | for (clock.m1 = limit->m1.max; |
878 | clock.m1 >= limit->m1.min; clock.m1--) { | |
879 | for (clock.m2 = limit->m2.max; | |
880 | clock.m2 >= limit->m2.min; clock.m2--) { | |
881 | for (clock.p1 = limit->p1.max; | |
882 | clock.p1 >= limit->p1.min; clock.p1--) { | |
883 | int this_err; | |
884 | ||
dccbea3b | 885 | i9xx_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
886 | if (!intel_PLL_is_valid(dev, limit, |
887 | &clock)) | |
d4906093 | 888 | continue; |
1b894b59 CW |
889 | |
890 | this_err = abs(clock.dot - target); | |
d4906093 ML |
891 | if (this_err < err_most) { |
892 | *best_clock = clock; | |
893 | err_most = this_err; | |
894 | max_n = clock.n; | |
895 | found = true; | |
896 | } | |
897 | } | |
898 | } | |
899 | } | |
900 | } | |
2c07245f ZW |
901 | return found; |
902 | } | |
903 | ||
d5dd62bd ID |
904 | /* |
905 | * Check if the calculated PLL configuration is more optimal compared to the | |
906 | * best configuration and error found so far. Return the calculated error. | |
907 | */ | |
908 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
909 | const intel_clock_t *calculated_clock, | |
910 | const intel_clock_t *best_clock, | |
911 | unsigned int best_error_ppm, | |
912 | unsigned int *error_ppm) | |
913 | { | |
9ca3ba01 ID |
914 | /* |
915 | * For CHV ignore the error and consider only the P value. | |
916 | * Prefer a bigger P value based on HW requirements. | |
917 | */ | |
918 | if (IS_CHERRYVIEW(dev)) { | |
919 | *error_ppm = 0; | |
920 | ||
921 | return calculated_clock->p > best_clock->p; | |
922 | } | |
923 | ||
24be4e46 ID |
924 | if (WARN_ON_ONCE(!target_freq)) |
925 | return false; | |
926 | ||
d5dd62bd ID |
927 | *error_ppm = div_u64(1000000ULL * |
928 | abs(target_freq - calculated_clock->dot), | |
929 | target_freq); | |
930 | /* | |
931 | * Prefer a better P value over a better (smaller) error if the error | |
932 | * is small. Ensure this preference for future configurations too by | |
933 | * setting the error to 0. | |
934 | */ | |
935 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
936 | *error_ppm = 0; | |
937 | ||
938 | return true; | |
939 | } | |
940 | ||
941 | return *error_ppm + 10 < best_error_ppm; | |
942 | } | |
943 | ||
a0c4da24 | 944 | static bool |
a93e255f ACO |
945 | vlv_find_best_dpll(const intel_limit_t *limit, |
946 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
947 | int target, int refclk, intel_clock_t *match_clock, |
948 | intel_clock_t *best_clock) | |
a0c4da24 | 949 | { |
a93e255f | 950 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 951 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 952 | intel_clock_t clock; |
69e4f900 | 953 | unsigned int bestppm = 1000000; |
27e639bf VS |
954 | /* min update 19.2 MHz */ |
955 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 956 | bool found = false; |
a0c4da24 | 957 | |
6b4bf1c4 VS |
958 | target *= 5; /* fast clock */ |
959 | ||
960 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
961 | |
962 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 963 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 964 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 965 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 966 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 967 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 968 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 969 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 970 | unsigned int ppm; |
69e4f900 | 971 | |
6b4bf1c4 VS |
972 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
973 | refclk * clock.m1); | |
974 | ||
dccbea3b | 975 | vlv_calc_dpll_params(refclk, &clock); |
43b0ac53 | 976 | |
f01b7962 VS |
977 | if (!intel_PLL_is_valid(dev, limit, |
978 | &clock)) | |
43b0ac53 VS |
979 | continue; |
980 | ||
d5dd62bd ID |
981 | if (!vlv_PLL_is_optimal(dev, target, |
982 | &clock, | |
983 | best_clock, | |
984 | bestppm, &ppm)) | |
985 | continue; | |
6b4bf1c4 | 986 | |
d5dd62bd ID |
987 | *best_clock = clock; |
988 | bestppm = ppm; | |
989 | found = true; | |
a0c4da24 JB |
990 | } |
991 | } | |
992 | } | |
993 | } | |
a0c4da24 | 994 | |
49e497ef | 995 | return found; |
a0c4da24 | 996 | } |
a4fc5ed6 | 997 | |
ef9348c8 | 998 | static bool |
a93e255f ACO |
999 | chv_find_best_dpll(const intel_limit_t *limit, |
1000 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
1001 | int target, int refclk, intel_clock_t *match_clock, |
1002 | intel_clock_t *best_clock) | |
1003 | { | |
a93e255f | 1004 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 1005 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 1006 | unsigned int best_error_ppm; |
ef9348c8 CML |
1007 | intel_clock_t clock; |
1008 | uint64_t m2; | |
1009 | int found = false; | |
1010 | ||
1011 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 1012 | best_error_ppm = 1000000; |
ef9348c8 CML |
1013 | |
1014 | /* | |
1015 | * Based on hardware doc, the n always set to 1, and m1 always | |
1016 | * set to 2. If requires to support 200Mhz refclk, we need to | |
1017 | * revisit this because n may not 1 anymore. | |
1018 | */ | |
1019 | clock.n = 1, clock.m1 = 2; | |
1020 | target *= 5; /* fast clock */ | |
1021 | ||
1022 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
1023 | for (clock.p2 = limit->p2.p2_fast; | |
1024 | clock.p2 >= limit->p2.p2_slow; | |
1025 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 1026 | unsigned int error_ppm; |
ef9348c8 CML |
1027 | |
1028 | clock.p = clock.p1 * clock.p2; | |
1029 | ||
1030 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
1031 | clock.n) << 22, refclk * clock.m1); | |
1032 | ||
1033 | if (m2 > INT_MAX/clock.m1) | |
1034 | continue; | |
1035 | ||
1036 | clock.m2 = m2; | |
1037 | ||
dccbea3b | 1038 | chv_calc_dpll_params(refclk, &clock); |
ef9348c8 CML |
1039 | |
1040 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
1041 | continue; | |
1042 | ||
9ca3ba01 ID |
1043 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
1044 | best_error_ppm, &error_ppm)) | |
1045 | continue; | |
1046 | ||
1047 | *best_clock = clock; | |
1048 | best_error_ppm = error_ppm; | |
1049 | found = true; | |
ef9348c8 CML |
1050 | } |
1051 | } | |
1052 | ||
1053 | return found; | |
1054 | } | |
1055 | ||
5ab7b0b7 ID |
1056 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
1057 | intel_clock_t *best_clock) | |
1058 | { | |
1059 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
1060 | ||
1061 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
1062 | target_clock, refclk, NULL, best_clock); | |
1063 | } | |
1064 | ||
20ddf665 VS |
1065 | bool intel_crtc_active(struct drm_crtc *crtc) |
1066 | { | |
1067 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1068 | ||
1069 | /* Be paranoid as we can arrive here with only partial | |
1070 | * state retrieved from the hardware during setup. | |
1071 | * | |
241bfc38 | 1072 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
1073 | * as Haswell has gained clock readout/fastboot support. |
1074 | * | |
66e514c1 | 1075 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 1076 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1077 | * |
1078 | * FIXME: The intel_crtc->active here should be switched to | |
1079 | * crtc->state->active once we have proper CRTC states wired up | |
1080 | * for atomic. | |
20ddf665 | 1081 | */ |
c3d1f436 | 1082 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1083 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1084 | } |
1085 | ||
a5c961d1 PZ |
1086 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1087 | enum pipe pipe) | |
1088 | { | |
1089 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1090 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1091 | ||
6e3c9717 | 1092 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1093 | } |
1094 | ||
fbf49ea2 VS |
1095 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1096 | { | |
1097 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1098 | u32 reg = PIPEDSL(pipe); | |
1099 | u32 line1, line2; | |
1100 | u32 line_mask; | |
1101 | ||
1102 | if (IS_GEN2(dev)) | |
1103 | line_mask = DSL_LINEMASK_GEN2; | |
1104 | else | |
1105 | line_mask = DSL_LINEMASK_GEN3; | |
1106 | ||
1107 | line1 = I915_READ(reg) & line_mask; | |
6adfb1ef | 1108 | msleep(5); |
fbf49ea2 VS |
1109 | line2 = I915_READ(reg) & line_mask; |
1110 | ||
1111 | return line1 == line2; | |
1112 | } | |
1113 | ||
ab7ad7f6 KP |
1114 | /* |
1115 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1116 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1117 | * |
1118 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1119 | * spinning on the vblank interrupt status bit, since we won't actually | |
1120 | * see an interrupt when the pipe is disabled. | |
1121 | * | |
ab7ad7f6 KP |
1122 | * On Gen4 and above: |
1123 | * wait for the pipe register state bit to turn off | |
1124 | * | |
1125 | * Otherwise: | |
1126 | * wait for the display line value to settle (it usually | |
1127 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1128 | * |
9d0498a2 | 1129 | */ |
575f7ab7 | 1130 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1131 | { |
575f7ab7 | 1132 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1133 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1134 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1135 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1136 | |
1137 | if (INTEL_INFO(dev)->gen >= 4) { | |
702e7a56 | 1138 | int reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1139 | |
1140 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1141 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1142 | 100)) | |
284637d9 | 1143 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1144 | } else { |
ab7ad7f6 | 1145 | /* Wait for the display line to settle */ |
fbf49ea2 | 1146 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1147 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1148 | } |
79e53945 JB |
1149 | } |
1150 | ||
b24e7179 JB |
1151 | static const char *state_string(bool enabled) |
1152 | { | |
1153 | return enabled ? "on" : "off"; | |
1154 | } | |
1155 | ||
1156 | /* Only for pre-ILK configs */ | |
55607e8a DV |
1157 | void assert_pll(struct drm_i915_private *dev_priv, |
1158 | enum pipe pipe, bool state) | |
b24e7179 | 1159 | { |
b24e7179 JB |
1160 | u32 val; |
1161 | bool cur_state; | |
1162 | ||
649636ef | 1163 | val = I915_READ(DPLL(pipe)); |
b24e7179 | 1164 | cur_state = !!(val & DPLL_VCO_ENABLE); |
e2c719b7 | 1165 | I915_STATE_WARN(cur_state != state, |
b24e7179 JB |
1166 | "PLL state assertion failure (expected %s, current %s)\n", |
1167 | state_string(state), state_string(cur_state)); | |
1168 | } | |
b24e7179 | 1169 | |
23538ef1 JN |
1170 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1171 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1172 | { | |
1173 | u32 val; | |
1174 | bool cur_state; | |
1175 | ||
a580516d | 1176 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1177 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1178 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1179 | |
1180 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1181 | I915_STATE_WARN(cur_state != state, |
23538ef1 JN |
1182 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
1183 | state_string(state), state_string(cur_state)); | |
1184 | } | |
1185 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1186 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1187 | ||
55607e8a | 1188 | struct intel_shared_dpll * |
e2b78267 DV |
1189 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1190 | { | |
1191 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1192 | ||
6e3c9717 | 1193 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1194 | return NULL; |
1195 | ||
6e3c9717 | 1196 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1197 | } |
1198 | ||
040484af | 1199 | /* For ILK+ */ |
55607e8a DV |
1200 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1201 | struct intel_shared_dpll *pll, | |
1202 | bool state) | |
040484af | 1203 | { |
040484af | 1204 | bool cur_state; |
5358901f | 1205 | struct intel_dpll_hw_state hw_state; |
040484af | 1206 | |
92b27b08 | 1207 | if (WARN (!pll, |
46edb027 | 1208 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
ee7b9f93 | 1209 | return; |
ee7b9f93 | 1210 | |
5358901f | 1211 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1212 | I915_STATE_WARN(cur_state != state, |
5358901f DV |
1213 | "%s assertion failure (expected %s, current %s)\n", |
1214 | pll->name, state_string(state), state_string(cur_state)); | |
040484af | 1215 | } |
040484af JB |
1216 | |
1217 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1218 | enum pipe pipe, bool state) | |
1219 | { | |
040484af | 1220 | bool cur_state; |
ad80a810 PZ |
1221 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1222 | pipe); | |
040484af | 1223 | |
affa9354 PZ |
1224 | if (HAS_DDI(dev_priv->dev)) { |
1225 | /* DDI does not have a specific FDI_TX register */ | |
649636ef | 1226 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
ad80a810 | 1227 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 | 1228 | } else { |
649636ef | 1229 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
bf507ef7 ED |
1230 | cur_state = !!(val & FDI_TX_ENABLE); |
1231 | } | |
e2c719b7 | 1232 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1233 | "FDI TX state assertion failure (expected %s, current %s)\n", |
1234 | state_string(state), state_string(cur_state)); | |
1235 | } | |
1236 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1237 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1238 | ||
1239 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1240 | enum pipe pipe, bool state) | |
1241 | { | |
040484af JB |
1242 | u32 val; |
1243 | bool cur_state; | |
1244 | ||
649636ef | 1245 | val = I915_READ(FDI_RX_CTL(pipe)); |
d63fa0dc | 1246 | cur_state = !!(val & FDI_RX_ENABLE); |
e2c719b7 | 1247 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1248 | "FDI RX state assertion failure (expected %s, current %s)\n", |
1249 | state_string(state), state_string(cur_state)); | |
1250 | } | |
1251 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1252 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1253 | ||
1254 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1255 | enum pipe pipe) | |
1256 | { | |
040484af JB |
1257 | u32 val; |
1258 | ||
1259 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1260 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1261 | return; |
1262 | ||
bf507ef7 | 1263 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1264 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1265 | return; |
1266 | ||
649636ef | 1267 | val = I915_READ(FDI_TX_CTL(pipe)); |
e2c719b7 | 1268 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1269 | } |
1270 | ||
55607e8a DV |
1271 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1272 | enum pipe pipe, bool state) | |
040484af | 1273 | { |
040484af | 1274 | u32 val; |
55607e8a | 1275 | bool cur_state; |
040484af | 1276 | |
649636ef | 1277 | val = I915_READ(FDI_RX_CTL(pipe)); |
55607e8a | 1278 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1279 | I915_STATE_WARN(cur_state != state, |
55607e8a DV |
1280 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
1281 | state_string(state), state_string(cur_state)); | |
040484af JB |
1282 | } |
1283 | ||
b680c37a DV |
1284 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1285 | enum pipe pipe) | |
ea0760cf | 1286 | { |
bedd4dba JN |
1287 | struct drm_device *dev = dev_priv->dev; |
1288 | int pp_reg; | |
ea0760cf JB |
1289 | u32 val; |
1290 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1291 | bool locked = true; |
ea0760cf | 1292 | |
bedd4dba JN |
1293 | if (WARN_ON(HAS_DDI(dev))) |
1294 | return; | |
1295 | ||
1296 | if (HAS_PCH_SPLIT(dev)) { | |
1297 | u32 port_sel; | |
1298 | ||
ea0760cf | 1299 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1300 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1301 | ||
1302 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1303 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1304 | panel_pipe = PIPE_B; | |
1305 | /* XXX: else fix for eDP */ | |
1306 | } else if (IS_VALLEYVIEW(dev)) { | |
1307 | /* presumably write lock depends on pipe, not port select */ | |
1308 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1309 | panel_pipe = pipe; | |
ea0760cf JB |
1310 | } else { |
1311 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1312 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1313 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1314 | } |
1315 | ||
1316 | val = I915_READ(pp_reg); | |
1317 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1318 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1319 | locked = false; |
1320 | ||
e2c719b7 | 1321 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1322 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1323 | pipe_name(pipe)); |
ea0760cf JB |
1324 | } |
1325 | ||
93ce0ba6 JN |
1326 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1327 | enum pipe pipe, bool state) | |
1328 | { | |
1329 | struct drm_device *dev = dev_priv->dev; | |
1330 | bool cur_state; | |
1331 | ||
d9d82081 | 1332 | if (IS_845G(dev) || IS_I865G(dev)) |
0b87c24e | 1333 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
d9d82081 | 1334 | else |
5efb3e28 | 1335 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1336 | |
e2c719b7 | 1337 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 JN |
1338 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
1339 | pipe_name(pipe), state_string(state), state_string(cur_state)); | |
1340 | } | |
1341 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1342 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1343 | ||
b840d907 JB |
1344 | void assert_pipe(struct drm_i915_private *dev_priv, |
1345 | enum pipe pipe, bool state) | |
b24e7179 | 1346 | { |
63d7bbe9 | 1347 | bool cur_state; |
702e7a56 PZ |
1348 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1349 | pipe); | |
b24e7179 | 1350 | |
b6b5d049 VS |
1351 | /* if we need the pipe quirk it must be always on */ |
1352 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1353 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1354 | state = true; |
1355 | ||
f458ebbc | 1356 | if (!intel_display_power_is_enabled(dev_priv, |
b97186f0 | 1357 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
69310161 PZ |
1358 | cur_state = false; |
1359 | } else { | |
649636ef | 1360 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
69310161 PZ |
1361 | cur_state = !!(val & PIPECONF_ENABLE); |
1362 | } | |
1363 | ||
e2c719b7 | 1364 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1365 | "pipe %c assertion failure (expected %s, current %s)\n", |
9db4a9c7 | 1366 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
b24e7179 JB |
1367 | } |
1368 | ||
931872fc CW |
1369 | static void assert_plane(struct drm_i915_private *dev_priv, |
1370 | enum plane plane, bool state) | |
b24e7179 | 1371 | { |
b24e7179 | 1372 | u32 val; |
931872fc | 1373 | bool cur_state; |
b24e7179 | 1374 | |
649636ef | 1375 | val = I915_READ(DSPCNTR(plane)); |
931872fc | 1376 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1377 | I915_STATE_WARN(cur_state != state, |
931872fc CW |
1378 | "plane %c assertion failure (expected %s, current %s)\n", |
1379 | plane_name(plane), state_string(state), state_string(cur_state)); | |
b24e7179 JB |
1380 | } |
1381 | ||
931872fc CW |
1382 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1383 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1384 | ||
b24e7179 JB |
1385 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1386 | enum pipe pipe) | |
1387 | { | |
653e1026 | 1388 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1389 | int i; |
b24e7179 | 1390 | |
653e1026 VS |
1391 | /* Primary planes are fixed to pipes on gen4+ */ |
1392 | if (INTEL_INFO(dev)->gen >= 4) { | |
649636ef | 1393 | u32 val = I915_READ(DSPCNTR(pipe)); |
e2c719b7 | 1394 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1395 | "plane %c assertion failure, should be disabled but not\n", |
1396 | plane_name(pipe)); | |
19ec1358 | 1397 | return; |
28c05794 | 1398 | } |
19ec1358 | 1399 | |
b24e7179 | 1400 | /* Need to check both planes against the pipe */ |
055e393f | 1401 | for_each_pipe(dev_priv, i) { |
649636ef VS |
1402 | u32 val = I915_READ(DSPCNTR(i)); |
1403 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
b24e7179 | 1404 | DISPPLANE_SEL_PIPE_SHIFT; |
e2c719b7 | 1405 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1406 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1407 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1408 | } |
1409 | } | |
1410 | ||
19332d7a JB |
1411 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1412 | enum pipe pipe) | |
1413 | { | |
20674eef | 1414 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1415 | int sprite; |
19332d7a | 1416 | |
7feb8b88 | 1417 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1418 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1419 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1420 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1421 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1422 | sprite, pipe_name(pipe)); | |
1423 | } | |
1424 | } else if (IS_VALLEYVIEW(dev)) { | |
3bdcfc0c | 1425 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1426 | u32 val = I915_READ(SPCNTR(pipe, sprite)); |
e2c719b7 | 1427 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1428 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1429 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1430 | } |
1431 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
649636ef | 1432 | u32 val = I915_READ(SPRCTL(pipe)); |
e2c719b7 | 1433 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1434 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1435 | plane_name(pipe), pipe_name(pipe)); |
1436 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
649636ef | 1437 | u32 val = I915_READ(DVSCNTR(pipe)); |
e2c719b7 | 1438 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1439 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1440 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1441 | } |
1442 | } | |
1443 | ||
08c71e5e VS |
1444 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1445 | { | |
e2c719b7 | 1446 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1447 | drm_crtc_vblank_put(crtc); |
1448 | } | |
1449 | ||
89eff4be | 1450 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1451 | { |
1452 | u32 val; | |
1453 | bool enabled; | |
1454 | ||
e2c719b7 | 1455 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1456 | |
92f2584a JB |
1457 | val = I915_READ(PCH_DREF_CONTROL); |
1458 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1459 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1460 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1461 | } |
1462 | ||
ab9412ba DV |
1463 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1464 | enum pipe pipe) | |
92f2584a | 1465 | { |
92f2584a JB |
1466 | u32 val; |
1467 | bool enabled; | |
1468 | ||
649636ef | 1469 | val = I915_READ(PCH_TRANSCONF(pipe)); |
92f2584a | 1470 | enabled = !!(val & TRANS_ENABLE); |
e2c719b7 | 1471 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1472 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1473 | pipe_name(pipe)); | |
92f2584a JB |
1474 | } |
1475 | ||
4e634389 KP |
1476 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1477 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1478 | { |
1479 | if ((val & DP_PORT_EN) == 0) | |
1480 | return false; | |
1481 | ||
1482 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1483 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); | |
1484 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); | |
1485 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1486 | return false; | |
44f37d1f CML |
1487 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1488 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1489 | return false; | |
f0575e92 KP |
1490 | } else { |
1491 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1492 | return false; | |
1493 | } | |
1494 | return true; | |
1495 | } | |
1496 | ||
1519b995 KP |
1497 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1498 | enum pipe pipe, u32 val) | |
1499 | { | |
dc0fa718 | 1500 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1501 | return false; |
1502 | ||
1503 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1504 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1505 | return false; |
44f37d1f CML |
1506 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1507 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1508 | return false; | |
1519b995 | 1509 | } else { |
dc0fa718 | 1510 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1511 | return false; |
1512 | } | |
1513 | return true; | |
1514 | } | |
1515 | ||
1516 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1517 | enum pipe pipe, u32 val) | |
1518 | { | |
1519 | if ((val & LVDS_PORT_EN) == 0) | |
1520 | return false; | |
1521 | ||
1522 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1523 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1524 | return false; | |
1525 | } else { | |
1526 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1527 | return false; | |
1528 | } | |
1529 | return true; | |
1530 | } | |
1531 | ||
1532 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1533 | enum pipe pipe, u32 val) | |
1534 | { | |
1535 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1536 | return false; | |
1537 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1538 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1539 | return false; | |
1540 | } else { | |
1541 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1542 | return false; | |
1543 | } | |
1544 | return true; | |
1545 | } | |
1546 | ||
291906f1 | 1547 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0575e92 | 1548 | enum pipe pipe, int reg, u32 port_sel) |
291906f1 | 1549 | { |
47a05eca | 1550 | u32 val = I915_READ(reg); |
e2c719b7 | 1551 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1552 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1553 | reg, pipe_name(pipe)); |
de9a35ab | 1554 | |
e2c719b7 | 1555 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1556 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1557 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1558 | } |
1559 | ||
1560 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1561 | enum pipe pipe, int reg) | |
1562 | { | |
47a05eca | 1563 | u32 val = I915_READ(reg); |
e2c719b7 | 1564 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1565 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1566 | reg, pipe_name(pipe)); |
de9a35ab | 1567 | |
e2c719b7 | 1568 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1569 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1570 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1571 | } |
1572 | ||
1573 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1574 | enum pipe pipe) | |
1575 | { | |
291906f1 | 1576 | u32 val; |
291906f1 | 1577 | |
f0575e92 KP |
1578 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1579 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1580 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 | 1581 | |
649636ef | 1582 | val = I915_READ(PCH_ADPA); |
e2c719b7 | 1583 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1584 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1585 | pipe_name(pipe)); |
291906f1 | 1586 | |
649636ef | 1587 | val = I915_READ(PCH_LVDS); |
e2c719b7 | 1588 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1589 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1590 | pipe_name(pipe)); |
291906f1 | 1591 | |
e2debe91 PZ |
1592 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1593 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1594 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1595 | } |
1596 | ||
d288f65f | 1597 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1598 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1599 | { |
426115cf DV |
1600 | struct drm_device *dev = crtc->base.dev; |
1601 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1602 | int reg = DPLL(crtc->pipe); | |
d288f65f | 1603 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1604 | |
426115cf | 1605 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 DV |
1606 | |
1607 | /* No really, not for ILK+ */ | |
1608 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); | |
1609 | ||
1610 | /* PLL is protected by panel, make sure we can write it */ | |
6a9e7363 | 1611 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1612 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1613 | |
426115cf DV |
1614 | I915_WRITE(reg, dpll); |
1615 | POSTING_READ(reg); | |
1616 | udelay(150); | |
1617 | ||
1618 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1619 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1620 | ||
d288f65f | 1621 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1622 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1623 | |
1624 | /* We do this three times for luck */ | |
426115cf | 1625 | I915_WRITE(reg, dpll); |
87442f73 DV |
1626 | POSTING_READ(reg); |
1627 | udelay(150); /* wait for warmup */ | |
426115cf | 1628 | I915_WRITE(reg, dpll); |
87442f73 DV |
1629 | POSTING_READ(reg); |
1630 | udelay(150); /* wait for warmup */ | |
426115cf | 1631 | I915_WRITE(reg, dpll); |
87442f73 DV |
1632 | POSTING_READ(reg); |
1633 | udelay(150); /* wait for warmup */ | |
1634 | } | |
1635 | ||
d288f65f | 1636 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1637 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1638 | { |
1639 | struct drm_device *dev = crtc->base.dev; | |
1640 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1641 | int pipe = crtc->pipe; | |
1642 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1643 | u32 tmp; |
1644 | ||
1645 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1646 | ||
1647 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); | |
1648 | ||
a580516d | 1649 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1650 | |
1651 | /* Enable back the 10bit clock to display controller */ | |
1652 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1653 | tmp |= DPIO_DCLKP_EN; | |
1654 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1655 | ||
54433e91 VS |
1656 | mutex_unlock(&dev_priv->sb_lock); |
1657 | ||
9d556c99 CML |
1658 | /* |
1659 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1660 | */ | |
1661 | udelay(1); | |
1662 | ||
1663 | /* Enable PLL */ | |
d288f65f | 1664 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1665 | |
1666 | /* Check PLL is locked */ | |
a11b0703 | 1667 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1668 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1669 | ||
a11b0703 | 1670 | /* not sure when this should be written */ |
d288f65f | 1671 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 | 1672 | POSTING_READ(DPLL_MD(pipe)); |
9d556c99 CML |
1673 | } |
1674 | ||
1c4e0274 VS |
1675 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1676 | { | |
1677 | struct intel_crtc *crtc; | |
1678 | int count = 0; | |
1679 | ||
1680 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1681 | count += crtc->base.state->active && |
409ee761 | 1682 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1683 | |
1684 | return count; | |
1685 | } | |
1686 | ||
66e3d5c0 | 1687 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1688 | { |
66e3d5c0 DV |
1689 | struct drm_device *dev = crtc->base.dev; |
1690 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1691 | int reg = DPLL(crtc->pipe); | |
6e3c9717 | 1692 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1693 | |
66e3d5c0 | 1694 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1695 | |
63d7bbe9 | 1696 | /* No really, not for ILK+ */ |
3d13ef2e | 1697 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1698 | |
1699 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1700 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1701 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1702 | |
1c4e0274 VS |
1703 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1704 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1705 | /* | |
1706 | * It appears to be important that we don't enable this | |
1707 | * for the current pipe before otherwise configuring the | |
1708 | * PLL. No idea how this should be handled if multiple | |
1709 | * DVO outputs are enabled simultaneosly. | |
1710 | */ | |
1711 | dpll |= DPLL_DVO_2X_MODE; | |
1712 | I915_WRITE(DPLL(!crtc->pipe), | |
1713 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1714 | } | |
66e3d5c0 DV |
1715 | |
1716 | /* Wait for the clocks to stabilize. */ | |
1717 | POSTING_READ(reg); | |
1718 | udelay(150); | |
1719 | ||
1720 | if (INTEL_INFO(dev)->gen >= 4) { | |
1721 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1722 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1723 | } else { |
1724 | /* The pixel multiplier can only be updated once the | |
1725 | * DPLL is enabled and the clocks are stable. | |
1726 | * | |
1727 | * So write it again. | |
1728 | */ | |
1729 | I915_WRITE(reg, dpll); | |
1730 | } | |
63d7bbe9 JB |
1731 | |
1732 | /* We do this three times for luck */ | |
66e3d5c0 | 1733 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1734 | POSTING_READ(reg); |
1735 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1736 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1737 | POSTING_READ(reg); |
1738 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1739 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1740 | POSTING_READ(reg); |
1741 | udelay(150); /* wait for warmup */ | |
1742 | } | |
1743 | ||
1744 | /** | |
50b44a44 | 1745 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1746 | * @dev_priv: i915 private structure |
1747 | * @pipe: pipe PLL to disable | |
1748 | * | |
1749 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1750 | * | |
1751 | * Note! This is for pre-ILK only. | |
1752 | */ | |
1c4e0274 | 1753 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1754 | { |
1c4e0274 VS |
1755 | struct drm_device *dev = crtc->base.dev; |
1756 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1757 | enum pipe pipe = crtc->pipe; | |
1758 | ||
1759 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1760 | if (IS_I830(dev) && | |
409ee761 | 1761 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1762 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1763 | I915_WRITE(DPLL(PIPE_B), |
1764 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1765 | I915_WRITE(DPLL(PIPE_A), | |
1766 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1767 | } | |
1768 | ||
b6b5d049 VS |
1769 | /* Don't disable pipe or pipe PLLs if needed */ |
1770 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1771 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1772 | return; |
1773 | ||
1774 | /* Make sure the pipe isn't still relying on us */ | |
1775 | assert_pipe_disabled(dev_priv, pipe); | |
1776 | ||
b8afb911 | 1777 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1778 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1779 | } |
1780 | ||
f6071166 JB |
1781 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1782 | { | |
b8afb911 | 1783 | u32 val; |
f6071166 JB |
1784 | |
1785 | /* Make sure the pipe isn't still relying on us */ | |
1786 | assert_pipe_disabled(dev_priv, pipe); | |
1787 | ||
e5cbfbfb ID |
1788 | /* |
1789 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1790 | * The latter is needed for VGA hotplug / manual detection. | |
1791 | */ | |
b8afb911 | 1792 | val = DPLL_VGA_MODE_DIS; |
f6071166 | 1793 | if (pipe == PIPE_B) |
60bfe44f | 1794 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
f6071166 JB |
1795 | I915_WRITE(DPLL(pipe), val); |
1796 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1797 | |
1798 | } | |
1799 | ||
1800 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1801 | { | |
d752048d | 1802 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1803 | u32 val; |
1804 | ||
a11b0703 VS |
1805 | /* Make sure the pipe isn't still relying on us */ |
1806 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1807 | |
a11b0703 | 1808 | /* Set PLL en = 0 */ |
60bfe44f VS |
1809 | val = DPLL_SSC_REF_CLK_CHV | |
1810 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1811 | if (pipe != PIPE_A) |
1812 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1813 | I915_WRITE(DPLL(pipe), val); | |
1814 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1815 | |
a580516d | 1816 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1817 | |
1818 | /* Disable 10bit clock to display controller */ | |
1819 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1820 | val &= ~DPIO_DCLKP_EN; | |
1821 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1822 | ||
a580516d | 1823 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1824 | } |
1825 | ||
e4607fcf | 1826 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1827 | struct intel_digital_port *dport, |
1828 | unsigned int expected_mask) | |
89b667f8 JB |
1829 | { |
1830 | u32 port_mask; | |
00fc31b7 | 1831 | int dpll_reg; |
89b667f8 | 1832 | |
e4607fcf CML |
1833 | switch (dport->port) { |
1834 | case PORT_B: | |
89b667f8 | 1835 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1836 | dpll_reg = DPLL(0); |
e4607fcf CML |
1837 | break; |
1838 | case PORT_C: | |
89b667f8 | 1839 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1840 | dpll_reg = DPLL(0); |
9b6de0a1 | 1841 | expected_mask <<= 4; |
00fc31b7 CML |
1842 | break; |
1843 | case PORT_D: | |
1844 | port_mask = DPLL_PORTD_READY_MASK; | |
1845 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1846 | break; |
1847 | default: | |
1848 | BUG(); | |
1849 | } | |
89b667f8 | 1850 | |
9b6de0a1 VS |
1851 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1852 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1853 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1854 | } |
1855 | ||
b14b1055 DV |
1856 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1857 | { | |
1858 | struct drm_device *dev = crtc->base.dev; | |
1859 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1860 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1861 | ||
be19f0ff CW |
1862 | if (WARN_ON(pll == NULL)) |
1863 | return; | |
1864 | ||
3e369b76 | 1865 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1866 | if (pll->active == 0) { |
1867 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1868 | WARN_ON(pll->on); | |
1869 | assert_shared_dpll_disabled(dev_priv, pll); | |
1870 | ||
1871 | pll->mode_set(dev_priv, pll); | |
1872 | } | |
1873 | } | |
1874 | ||
92f2584a | 1875 | /** |
85b3894f | 1876 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1877 | * @dev_priv: i915 private structure |
1878 | * @pipe: pipe PLL to enable | |
1879 | * | |
1880 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1881 | * drives the transcoder clock. | |
1882 | */ | |
85b3894f | 1883 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1884 | { |
3d13ef2e DL |
1885 | struct drm_device *dev = crtc->base.dev; |
1886 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1887 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1888 | |
87a875bb | 1889 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1890 | return; |
1891 | ||
3e369b76 | 1892 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1893 | return; |
ee7b9f93 | 1894 | |
74dd6928 | 1895 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1896 | pll->name, pll->active, pll->on, |
e2b78267 | 1897 | crtc->base.base.id); |
92f2584a | 1898 | |
cdbd2316 DV |
1899 | if (pll->active++) { |
1900 | WARN_ON(!pll->on); | |
e9d6944e | 1901 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1902 | return; |
1903 | } | |
f4a091c7 | 1904 | WARN_ON(pll->on); |
ee7b9f93 | 1905 | |
bd2bb1b9 PZ |
1906 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1907 | ||
46edb027 | 1908 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1909 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1910 | pll->on = true; |
92f2584a JB |
1911 | } |
1912 | ||
f6daaec2 | 1913 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1914 | { |
3d13ef2e DL |
1915 | struct drm_device *dev = crtc->base.dev; |
1916 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1917 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1918 | |
92f2584a | 1919 | /* PCH only available on ILK+ */ |
80aa9312 JB |
1920 | if (INTEL_INFO(dev)->gen < 5) |
1921 | return; | |
1922 | ||
eddfcbcd ML |
1923 | if (pll == NULL) |
1924 | return; | |
92f2584a | 1925 | |
eddfcbcd | 1926 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) |
48da64a8 | 1927 | return; |
7a419866 | 1928 | |
46edb027 DV |
1929 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1930 | pll->name, pll->active, pll->on, | |
e2b78267 | 1931 | crtc->base.base.id); |
7a419866 | 1932 | |
48da64a8 | 1933 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1934 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1935 | return; |
1936 | } | |
1937 | ||
e9d6944e | 1938 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1939 | WARN_ON(!pll->on); |
cdbd2316 | 1940 | if (--pll->active) |
7a419866 | 1941 | return; |
ee7b9f93 | 1942 | |
46edb027 | 1943 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1944 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1945 | pll->on = false; |
bd2bb1b9 PZ |
1946 | |
1947 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1948 | } |
1949 | ||
b8a4f404 PZ |
1950 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1951 | enum pipe pipe) | |
040484af | 1952 | { |
23670b32 | 1953 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1954 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1955 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
23670b32 | 1956 | uint32_t reg, val, pipeconf_val; |
040484af JB |
1957 | |
1958 | /* PCH only available on ILK+ */ | |
55522f37 | 1959 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1960 | |
1961 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1962 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1963 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1964 | |
1965 | /* FDI must be feeding us bits for PCH ports */ | |
1966 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1967 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1968 | ||
23670b32 DV |
1969 | if (HAS_PCH_CPT(dev)) { |
1970 | /* Workaround: Set the timing override bit before enabling the | |
1971 | * pch transcoder. */ | |
1972 | reg = TRANS_CHICKEN2(pipe); | |
1973 | val = I915_READ(reg); | |
1974 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1975 | I915_WRITE(reg, val); | |
59c859d6 | 1976 | } |
23670b32 | 1977 | |
ab9412ba | 1978 | reg = PCH_TRANSCONF(pipe); |
040484af | 1979 | val = I915_READ(reg); |
5f7f726d | 1980 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
1981 | |
1982 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
1983 | /* | |
c5de7c6f VS |
1984 | * Make the BPC in transcoder be consistent with |
1985 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1986 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1987 | */ |
dfd07d72 | 1988 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
1989 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
1990 | val |= PIPECONF_8BPC; | |
1991 | else | |
1992 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 1993 | } |
5f7f726d PZ |
1994 | |
1995 | val &= ~TRANS_INTERLACE_MASK; | |
1996 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 1997 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 1998 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
1999 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2000 | else | |
2001 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2002 | else |
2003 | val |= TRANS_PROGRESSIVE; | |
2004 | ||
040484af JB |
2005 | I915_WRITE(reg, val | TRANS_ENABLE); |
2006 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2007 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2008 | } |
2009 | ||
8fb033d7 | 2010 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2011 | enum transcoder cpu_transcoder) |
040484af | 2012 | { |
8fb033d7 | 2013 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2014 | |
2015 | /* PCH only available on ILK+ */ | |
55522f37 | 2016 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2017 | |
8fb033d7 | 2018 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2019 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2020 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2021 | |
223a6fdf | 2022 | /* Workaround: set timing override bit. */ |
36c0d0cf | 2023 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2024 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2025 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
223a6fdf | 2026 | |
25f3ef11 | 2027 | val = TRANS_ENABLE; |
937bb610 | 2028 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2029 | |
9a76b1c6 PZ |
2030 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2031 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2032 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2033 | else |
2034 | val |= TRANS_PROGRESSIVE; | |
2035 | ||
ab9412ba DV |
2036 | I915_WRITE(LPT_TRANSCONF, val); |
2037 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2038 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2039 | } |
2040 | ||
b8a4f404 PZ |
2041 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2042 | enum pipe pipe) | |
040484af | 2043 | { |
23670b32 DV |
2044 | struct drm_device *dev = dev_priv->dev; |
2045 | uint32_t reg, val; | |
040484af JB |
2046 | |
2047 | /* FDI relies on the transcoder */ | |
2048 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2049 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2050 | ||
291906f1 JB |
2051 | /* Ports must be off as well */ |
2052 | assert_pch_ports_disabled(dev_priv, pipe); | |
2053 | ||
ab9412ba | 2054 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2055 | val = I915_READ(reg); |
2056 | val &= ~TRANS_ENABLE; | |
2057 | I915_WRITE(reg, val); | |
2058 | /* wait for PCH transcoder off, transcoder state */ | |
2059 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2060 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 | 2061 | |
c465613b | 2062 | if (HAS_PCH_CPT(dev)) { |
23670b32 DV |
2063 | /* Workaround: Clear the timing override chicken bit again. */ |
2064 | reg = TRANS_CHICKEN2(pipe); | |
2065 | val = I915_READ(reg); | |
2066 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2067 | I915_WRITE(reg, val); | |
2068 | } | |
040484af JB |
2069 | } |
2070 | ||
ab4d966c | 2071 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2072 | { |
8fb033d7 PZ |
2073 | u32 val; |
2074 | ||
ab9412ba | 2075 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2076 | val &= ~TRANS_ENABLE; |
ab9412ba | 2077 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2078 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2079 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2080 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2081 | |
2082 | /* Workaround: clear timing override bit. */ | |
36c0d0cf | 2083 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2084 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2085 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
040484af JB |
2086 | } |
2087 | ||
b24e7179 | 2088 | /** |
309cfea8 | 2089 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2090 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2091 | * |
0372264a | 2092 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2093 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2094 | */ |
e1fdc473 | 2095 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2096 | { |
0372264a PZ |
2097 | struct drm_device *dev = crtc->base.dev; |
2098 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2099 | enum pipe pipe = crtc->pipe; | |
1a70a728 | 2100 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
1a240d4d | 2101 | enum pipe pch_transcoder; |
b24e7179 JB |
2102 | int reg; |
2103 | u32 val; | |
2104 | ||
9e2ee2dd VS |
2105 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
2106 | ||
58c6eaa2 | 2107 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2108 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2109 | assert_sprites_disabled(dev_priv, pipe); |
2110 | ||
681e5811 | 2111 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2112 | pch_transcoder = TRANSCODER_A; |
2113 | else | |
2114 | pch_transcoder = pipe; | |
2115 | ||
b24e7179 JB |
2116 | /* |
2117 | * A pipe without a PLL won't actually be able to drive bits from | |
2118 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2119 | * need the check. | |
2120 | */ | |
50360403 | 2121 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
409ee761 | 2122 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
2123 | assert_dsi_pll_enabled(dev_priv); |
2124 | else | |
2125 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2126 | else { |
6e3c9717 | 2127 | if (crtc->config->has_pch_encoder) { |
040484af | 2128 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2129 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2130 | assert_fdi_tx_pll_enabled(dev_priv, |
2131 | (enum pipe) cpu_transcoder); | |
040484af JB |
2132 | } |
2133 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2134 | } | |
b24e7179 | 2135 | |
702e7a56 | 2136 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2137 | val = I915_READ(reg); |
7ad25d48 | 2138 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2139 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2140 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2141 | return; |
7ad25d48 | 2142 | } |
00d70b15 CW |
2143 | |
2144 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2145 | POSTING_READ(reg); |
b24e7179 JB |
2146 | } |
2147 | ||
2148 | /** | |
309cfea8 | 2149 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2150 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2151 | * |
575f7ab7 VS |
2152 | * Disable the pipe of @crtc, making sure that various hardware |
2153 | * specific requirements are met, if applicable, e.g. plane | |
2154 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2155 | * |
2156 | * Will wait until the pipe has shut down before returning. | |
2157 | */ | |
575f7ab7 | 2158 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2159 | { |
575f7ab7 | 2160 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2161 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2162 | enum pipe pipe = crtc->pipe; |
b24e7179 JB |
2163 | int reg; |
2164 | u32 val; | |
2165 | ||
9e2ee2dd VS |
2166 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
2167 | ||
b24e7179 JB |
2168 | /* |
2169 | * Make sure planes won't keep trying to pump pixels to us, | |
2170 | * or we might hang the display. | |
2171 | */ | |
2172 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2173 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2174 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2175 | |
702e7a56 | 2176 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2177 | val = I915_READ(reg); |
00d70b15 CW |
2178 | if ((val & PIPECONF_ENABLE) == 0) |
2179 | return; | |
2180 | ||
67adc644 VS |
2181 | /* |
2182 | * Double wide has implications for planes | |
2183 | * so best keep it disabled when not needed. | |
2184 | */ | |
6e3c9717 | 2185 | if (crtc->config->double_wide) |
67adc644 VS |
2186 | val &= ~PIPECONF_DOUBLE_WIDE; |
2187 | ||
2188 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2189 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2190 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2191 | val &= ~PIPECONF_ENABLE; |
2192 | ||
2193 | I915_WRITE(reg, val); | |
2194 | if ((val & PIPECONF_ENABLE) == 0) | |
2195 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2196 | } |
2197 | ||
693db184 CW |
2198 | static bool need_vtd_wa(struct drm_device *dev) |
2199 | { | |
2200 | #ifdef CONFIG_INTEL_IOMMU | |
2201 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2202 | return true; | |
2203 | #endif | |
2204 | return false; | |
2205 | } | |
2206 | ||
50470bb0 | 2207 | unsigned int |
6761dd31 | 2208 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
fe47ea0c | 2209 | uint64_t fb_format_modifier, unsigned int plane) |
a57ce0b2 | 2210 | { |
6761dd31 TU |
2211 | unsigned int tile_height; |
2212 | uint32_t pixel_bytes; | |
a57ce0b2 | 2213 | |
b5d0e9bf DL |
2214 | switch (fb_format_modifier) { |
2215 | case DRM_FORMAT_MOD_NONE: | |
2216 | tile_height = 1; | |
2217 | break; | |
2218 | case I915_FORMAT_MOD_X_TILED: | |
2219 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2220 | break; | |
2221 | case I915_FORMAT_MOD_Y_TILED: | |
2222 | tile_height = 32; | |
2223 | break; | |
2224 | case I915_FORMAT_MOD_Yf_TILED: | |
fe47ea0c | 2225 | pixel_bytes = drm_format_plane_cpp(pixel_format, plane); |
6761dd31 | 2226 | switch (pixel_bytes) { |
b5d0e9bf | 2227 | default: |
6761dd31 | 2228 | case 1: |
b5d0e9bf DL |
2229 | tile_height = 64; |
2230 | break; | |
6761dd31 TU |
2231 | case 2: |
2232 | case 4: | |
b5d0e9bf DL |
2233 | tile_height = 32; |
2234 | break; | |
6761dd31 | 2235 | case 8: |
b5d0e9bf DL |
2236 | tile_height = 16; |
2237 | break; | |
6761dd31 | 2238 | case 16: |
b5d0e9bf DL |
2239 | WARN_ONCE(1, |
2240 | "128-bit pixels are not supported for display!"); | |
2241 | tile_height = 16; | |
2242 | break; | |
2243 | } | |
2244 | break; | |
2245 | default: | |
2246 | MISSING_CASE(fb_format_modifier); | |
2247 | tile_height = 1; | |
2248 | break; | |
2249 | } | |
091df6cb | 2250 | |
6761dd31 TU |
2251 | return tile_height; |
2252 | } | |
2253 | ||
2254 | unsigned int | |
2255 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2256 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2257 | { | |
2258 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
fe47ea0c | 2259 | fb_format_modifier, 0)); |
a57ce0b2 JB |
2260 | } |
2261 | ||
f64b98cd TU |
2262 | static int |
2263 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, | |
2264 | const struct drm_plane_state *plane_state) | |
2265 | { | |
50470bb0 | 2266 | struct intel_rotation_info *info = &view->rotation_info; |
84fe03f7 | 2267 | unsigned int tile_height, tile_pitch; |
50470bb0 | 2268 | |
f64b98cd TU |
2269 | *view = i915_ggtt_view_normal; |
2270 | ||
50470bb0 TU |
2271 | if (!plane_state) |
2272 | return 0; | |
2273 | ||
121920fa | 2274 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
50470bb0 TU |
2275 | return 0; |
2276 | ||
9abc4648 | 2277 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2278 | |
2279 | info->height = fb->height; | |
2280 | info->pixel_format = fb->pixel_format; | |
2281 | info->pitch = fb->pitches[0]; | |
89e3e142 | 2282 | info->uv_offset = fb->offsets[1]; |
50470bb0 TU |
2283 | info->fb_modifier = fb->modifier[0]; |
2284 | ||
84fe03f7 | 2285 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, |
fe47ea0c | 2286 | fb->modifier[0], 0); |
84fe03f7 TU |
2287 | tile_pitch = PAGE_SIZE / tile_height; |
2288 | info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2289 | info->height_pages = DIV_ROUND_UP(fb->height, tile_height); | |
2290 | info->size = info->width_pages * info->height_pages * PAGE_SIZE; | |
2291 | ||
89e3e142 TU |
2292 | if (info->pixel_format == DRM_FORMAT_NV12) { |
2293 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, | |
2294 | fb->modifier[0], 1); | |
2295 | tile_pitch = PAGE_SIZE / tile_height; | |
2296 | info->width_pages_uv = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2297 | info->height_pages_uv = DIV_ROUND_UP(fb->height / 2, | |
2298 | tile_height); | |
2299 | info->size_uv = info->width_pages_uv * info->height_pages_uv * | |
2300 | PAGE_SIZE; | |
2301 | } | |
2302 | ||
f64b98cd TU |
2303 | return 0; |
2304 | } | |
2305 | ||
4e9a86b6 VS |
2306 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
2307 | { | |
2308 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2309 | return 256 * 1024; | |
985b8bb4 VS |
2310 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
2311 | IS_VALLEYVIEW(dev_priv)) | |
4e9a86b6 VS |
2312 | return 128 * 1024; |
2313 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2314 | return 4 * 1024; | |
2315 | else | |
44c5905e | 2316 | return 0; |
4e9a86b6 VS |
2317 | } |
2318 | ||
127bd2ac | 2319 | int |
850c4cdc TU |
2320 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2321 | struct drm_framebuffer *fb, | |
7580d774 | 2322 | const struct drm_plane_state *plane_state) |
6b95a207 | 2323 | { |
850c4cdc | 2324 | struct drm_device *dev = fb->dev; |
ce453d81 | 2325 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2326 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2327 | struct i915_ggtt_view view; |
6b95a207 KH |
2328 | u32 alignment; |
2329 | int ret; | |
2330 | ||
ebcdd39e MR |
2331 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2332 | ||
7b911adc TU |
2333 | switch (fb->modifier[0]) { |
2334 | case DRM_FORMAT_MOD_NONE: | |
4e9a86b6 | 2335 | alignment = intel_linear_alignment(dev_priv); |
6b95a207 | 2336 | break; |
7b911adc | 2337 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2338 | if (INTEL_INFO(dev)->gen >= 9) |
2339 | alignment = 256 * 1024; | |
2340 | else { | |
2341 | /* pin() will align the object as required by fence */ | |
2342 | alignment = 0; | |
2343 | } | |
6b95a207 | 2344 | break; |
7b911adc | 2345 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2346 | case I915_FORMAT_MOD_Yf_TILED: |
2347 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2348 | "Y tiling bo slipped through, driver bug!\n")) | |
2349 | return -EINVAL; | |
2350 | alignment = 1 * 1024 * 1024; | |
2351 | break; | |
6b95a207 | 2352 | default: |
7b911adc TU |
2353 | MISSING_CASE(fb->modifier[0]); |
2354 | return -EINVAL; | |
6b95a207 KH |
2355 | } |
2356 | ||
f64b98cd TU |
2357 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2358 | if (ret) | |
2359 | return ret; | |
2360 | ||
693db184 CW |
2361 | /* Note that the w/a also requires 64 PTE of padding following the |
2362 | * bo. We currently fill all unused PTE with the shadow page and so | |
2363 | * we should always have valid PTE following the scanout preventing | |
2364 | * the VT-d warning. | |
2365 | */ | |
2366 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2367 | alignment = 256 * 1024; | |
2368 | ||
d6dd6843 PZ |
2369 | /* |
2370 | * Global gtt pte registers are special registers which actually forward | |
2371 | * writes to a chunk of system memory. Which means that there is no risk | |
2372 | * that the register values disappear as soon as we call | |
2373 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2374 | * pin/unpin/fence and not more. | |
2375 | */ | |
2376 | intel_runtime_pm_get(dev_priv); | |
2377 | ||
7580d774 ML |
2378 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
2379 | &view); | |
48b956c5 | 2380 | if (ret) |
b26a6b35 | 2381 | goto err_pm; |
6b95a207 KH |
2382 | |
2383 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2384 | * fence, whereas 965+ only requires a fence if using | |
2385 | * framebuffer compression. For simplicity, we always install | |
2386 | * a fence as the cost is not that onerous. | |
2387 | */ | |
06d98131 | 2388 | ret = i915_gem_object_get_fence(obj); |
842315ee ML |
2389 | if (ret == -EDEADLK) { |
2390 | /* | |
2391 | * -EDEADLK means there are no free fences | |
2392 | * no pending flips. | |
2393 | * | |
2394 | * This is propagated to atomic, but it uses | |
2395 | * -EDEADLK to force a locking recovery, so | |
2396 | * change the returned error to -EBUSY. | |
2397 | */ | |
2398 | ret = -EBUSY; | |
2399 | goto err_unpin; | |
2400 | } else if (ret) | |
9a5a53b3 | 2401 | goto err_unpin; |
1690e1eb | 2402 | |
9a5a53b3 | 2403 | i915_gem_object_pin_fence(obj); |
6b95a207 | 2404 | |
d6dd6843 | 2405 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2406 | return 0; |
48b956c5 CW |
2407 | |
2408 | err_unpin: | |
f64b98cd | 2409 | i915_gem_object_unpin_from_display_plane(obj, &view); |
b26a6b35 | 2410 | err_pm: |
d6dd6843 | 2411 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2412 | return ret; |
6b95a207 KH |
2413 | } |
2414 | ||
82bc3b2d TU |
2415 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2416 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2417 | { |
82bc3b2d | 2418 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd TU |
2419 | struct i915_ggtt_view view; |
2420 | int ret; | |
82bc3b2d | 2421 | |
ebcdd39e MR |
2422 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2423 | ||
f64b98cd TU |
2424 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2425 | WARN_ONCE(ret, "Couldn't get view from plane state!"); | |
2426 | ||
1690e1eb | 2427 | i915_gem_object_unpin_fence(obj); |
f64b98cd | 2428 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2429 | } |
2430 | ||
c2c75131 DV |
2431 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2432 | * is assumed to be a power-of-two. */ | |
4e9a86b6 VS |
2433 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
2434 | int *x, int *y, | |
bc752862 CW |
2435 | unsigned int tiling_mode, |
2436 | unsigned int cpp, | |
2437 | unsigned int pitch) | |
c2c75131 | 2438 | { |
bc752862 CW |
2439 | if (tiling_mode != I915_TILING_NONE) { |
2440 | unsigned int tile_rows, tiles; | |
c2c75131 | 2441 | |
bc752862 CW |
2442 | tile_rows = *y / 8; |
2443 | *y %= 8; | |
c2c75131 | 2444 | |
bc752862 CW |
2445 | tiles = *x / (512/cpp); |
2446 | *x %= 512/cpp; | |
2447 | ||
2448 | return tile_rows * pitch * 8 + tiles * 4096; | |
2449 | } else { | |
4e9a86b6 | 2450 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
bc752862 CW |
2451 | unsigned int offset; |
2452 | ||
2453 | offset = *y * pitch + *x * cpp; | |
4e9a86b6 VS |
2454 | *y = (offset & alignment) / pitch; |
2455 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2456 | return offset & ~alignment; | |
bc752862 | 2457 | } |
c2c75131 DV |
2458 | } |
2459 | ||
b35d63fa | 2460 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2461 | { |
2462 | switch (format) { | |
2463 | case DISPPLANE_8BPP: | |
2464 | return DRM_FORMAT_C8; | |
2465 | case DISPPLANE_BGRX555: | |
2466 | return DRM_FORMAT_XRGB1555; | |
2467 | case DISPPLANE_BGRX565: | |
2468 | return DRM_FORMAT_RGB565; | |
2469 | default: | |
2470 | case DISPPLANE_BGRX888: | |
2471 | return DRM_FORMAT_XRGB8888; | |
2472 | case DISPPLANE_RGBX888: | |
2473 | return DRM_FORMAT_XBGR8888; | |
2474 | case DISPPLANE_BGRX101010: | |
2475 | return DRM_FORMAT_XRGB2101010; | |
2476 | case DISPPLANE_RGBX101010: | |
2477 | return DRM_FORMAT_XBGR2101010; | |
2478 | } | |
2479 | } | |
2480 | ||
bc8d7dff DL |
2481 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2482 | { | |
2483 | switch (format) { | |
2484 | case PLANE_CTL_FORMAT_RGB_565: | |
2485 | return DRM_FORMAT_RGB565; | |
2486 | default: | |
2487 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2488 | if (rgb_order) { | |
2489 | if (alpha) | |
2490 | return DRM_FORMAT_ABGR8888; | |
2491 | else | |
2492 | return DRM_FORMAT_XBGR8888; | |
2493 | } else { | |
2494 | if (alpha) | |
2495 | return DRM_FORMAT_ARGB8888; | |
2496 | else | |
2497 | return DRM_FORMAT_XRGB8888; | |
2498 | } | |
2499 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2500 | if (rgb_order) | |
2501 | return DRM_FORMAT_XBGR2101010; | |
2502 | else | |
2503 | return DRM_FORMAT_XRGB2101010; | |
2504 | } | |
2505 | } | |
2506 | ||
5724dbd1 | 2507 | static bool |
f6936e29 DV |
2508 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2509 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2510 | { |
2511 | struct drm_device *dev = crtc->base.dev; | |
3badb49f | 2512 | struct drm_i915_private *dev_priv = to_i915(dev); |
46f297fb JB |
2513 | struct drm_i915_gem_object *obj = NULL; |
2514 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2515 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2516 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2517 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2518 | PAGE_SIZE); | |
2519 | ||
2520 | size_aligned -= base_aligned; | |
46f297fb | 2521 | |
ff2652ea CW |
2522 | if (plane_config->size == 0) |
2523 | return false; | |
2524 | ||
3badb49f PZ |
2525 | /* If the FB is too big, just don't use it since fbdev is not very |
2526 | * important and we should probably use that space with FBC or other | |
2527 | * features. */ | |
2528 | if (size_aligned * 2 > dev_priv->gtt.stolen_usable_size) | |
2529 | return false; | |
2530 | ||
f37b5c2b DV |
2531 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2532 | base_aligned, | |
2533 | base_aligned, | |
2534 | size_aligned); | |
46f297fb | 2535 | if (!obj) |
484b41dd | 2536 | return false; |
46f297fb | 2537 | |
49af449b DL |
2538 | obj->tiling_mode = plane_config->tiling; |
2539 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2540 | obj->stride = fb->pitches[0]; |
46f297fb | 2541 | |
6bf129df DL |
2542 | mode_cmd.pixel_format = fb->pixel_format; |
2543 | mode_cmd.width = fb->width; | |
2544 | mode_cmd.height = fb->height; | |
2545 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2546 | mode_cmd.modifier[0] = fb->modifier[0]; |
2547 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2548 | |
2549 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2550 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2551 | &mode_cmd, obj)) { |
46f297fb JB |
2552 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2553 | goto out_unref_obj; | |
2554 | } | |
46f297fb | 2555 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2556 | |
f6936e29 | 2557 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2558 | return true; |
46f297fb JB |
2559 | |
2560 | out_unref_obj: | |
2561 | drm_gem_object_unreference(&obj->base); | |
2562 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2563 | return false; |
2564 | } | |
2565 | ||
afd65eb4 MR |
2566 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2567 | static void | |
2568 | update_state_fb(struct drm_plane *plane) | |
2569 | { | |
2570 | if (plane->fb == plane->state->fb) | |
2571 | return; | |
2572 | ||
2573 | if (plane->state->fb) | |
2574 | drm_framebuffer_unreference(plane->state->fb); | |
2575 | plane->state->fb = plane->fb; | |
2576 | if (plane->state->fb) | |
2577 | drm_framebuffer_reference(plane->state->fb); | |
2578 | } | |
2579 | ||
5724dbd1 | 2580 | static void |
f6936e29 DV |
2581 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2582 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2583 | { |
2584 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2585 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2586 | struct drm_crtc *c; |
2587 | struct intel_crtc *i; | |
2ff8fde1 | 2588 | struct drm_i915_gem_object *obj; |
88595ac9 | 2589 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2590 | struct drm_plane_state *plane_state = primary->state; |
88595ac9 | 2591 | struct drm_framebuffer *fb; |
484b41dd | 2592 | |
2d14030b | 2593 | if (!plane_config->fb) |
484b41dd JB |
2594 | return; |
2595 | ||
f6936e29 | 2596 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2597 | fb = &plane_config->fb->base; |
2598 | goto valid_fb; | |
f55548b5 | 2599 | } |
484b41dd | 2600 | |
2d14030b | 2601 | kfree(plane_config->fb); |
484b41dd JB |
2602 | |
2603 | /* | |
2604 | * Failed to alloc the obj, check to see if we should share | |
2605 | * an fb with another CRTC instead | |
2606 | */ | |
70e1e0ec | 2607 | for_each_crtc(dev, c) { |
484b41dd JB |
2608 | i = to_intel_crtc(c); |
2609 | ||
2610 | if (c == &intel_crtc->base) | |
2611 | continue; | |
2612 | ||
2ff8fde1 MR |
2613 | if (!i->active) |
2614 | continue; | |
2615 | ||
88595ac9 DV |
2616 | fb = c->primary->fb; |
2617 | if (!fb) | |
484b41dd JB |
2618 | continue; |
2619 | ||
88595ac9 | 2620 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2621 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2622 | drm_framebuffer_reference(fb); |
2623 | goto valid_fb; | |
484b41dd JB |
2624 | } |
2625 | } | |
88595ac9 DV |
2626 | |
2627 | return; | |
2628 | ||
2629 | valid_fb: | |
be5651f2 ML |
2630 | plane_state->src_x = plane_state->src_y = 0; |
2631 | plane_state->src_w = fb->width << 16; | |
2632 | plane_state->src_h = fb->height << 16; | |
2633 | ||
2634 | plane_state->crtc_x = plane_state->src_y = 0; | |
2635 | plane_state->crtc_w = fb->width; | |
2636 | plane_state->crtc_h = fb->height; | |
2637 | ||
88595ac9 DV |
2638 | obj = intel_fb_obj(fb); |
2639 | if (obj->tiling_mode != I915_TILING_NONE) | |
2640 | dev_priv->preserve_bios_swizzle = true; | |
2641 | ||
be5651f2 ML |
2642 | drm_framebuffer_reference(fb); |
2643 | primary->fb = primary->state->fb = fb; | |
36750f28 | 2644 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
36750f28 | 2645 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
a9ff8714 | 2646 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
46f297fb JB |
2647 | } |
2648 | ||
29b9bde6 DV |
2649 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2650 | struct drm_framebuffer *fb, | |
2651 | int x, int y) | |
81255565 JB |
2652 | { |
2653 | struct drm_device *dev = crtc->dev; | |
2654 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2655 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2656 | struct drm_plane *primary = crtc->primary; |
2657 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2658 | struct drm_i915_gem_object *obj; |
81255565 | 2659 | int plane = intel_crtc->plane; |
e506a0c6 | 2660 | unsigned long linear_offset; |
81255565 | 2661 | u32 dspcntr; |
f45651ba | 2662 | u32 reg = DSPCNTR(plane); |
48404c1e | 2663 | int pixel_size; |
f45651ba | 2664 | |
b70709a6 | 2665 | if (!visible || !fb) { |
fdd508a6 VS |
2666 | I915_WRITE(reg, 0); |
2667 | if (INTEL_INFO(dev)->gen >= 4) | |
2668 | I915_WRITE(DSPSURF(plane), 0); | |
2669 | else | |
2670 | I915_WRITE(DSPADDR(plane), 0); | |
2671 | POSTING_READ(reg); | |
2672 | return; | |
2673 | } | |
2674 | ||
c9ba6fad VS |
2675 | obj = intel_fb_obj(fb); |
2676 | if (WARN_ON(obj == NULL)) | |
2677 | return; | |
2678 | ||
2679 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2680 | ||
f45651ba VS |
2681 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2682 | ||
fdd508a6 | 2683 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2684 | |
2685 | if (INTEL_INFO(dev)->gen < 4) { | |
2686 | if (intel_crtc->pipe == PIPE_B) | |
2687 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2688 | ||
2689 | /* pipesrc and dspsize control the size that is scaled from, | |
2690 | * which should always be the user's requested size. | |
2691 | */ | |
2692 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2693 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2694 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2695 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2696 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2697 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2698 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2699 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2700 | I915_WRITE(PRIMPOS(plane), 0); |
2701 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2702 | } |
81255565 | 2703 | |
57779d06 VS |
2704 | switch (fb->pixel_format) { |
2705 | case DRM_FORMAT_C8: | |
81255565 JB |
2706 | dspcntr |= DISPPLANE_8BPP; |
2707 | break; | |
57779d06 | 2708 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2709 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2710 | break; |
57779d06 VS |
2711 | case DRM_FORMAT_RGB565: |
2712 | dspcntr |= DISPPLANE_BGRX565; | |
2713 | break; | |
2714 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2715 | dspcntr |= DISPPLANE_BGRX888; |
2716 | break; | |
2717 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2718 | dspcntr |= DISPPLANE_RGBX888; |
2719 | break; | |
2720 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2721 | dspcntr |= DISPPLANE_BGRX101010; |
2722 | break; | |
2723 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2724 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2725 | break; |
2726 | default: | |
baba133a | 2727 | BUG(); |
81255565 | 2728 | } |
57779d06 | 2729 | |
f45651ba VS |
2730 | if (INTEL_INFO(dev)->gen >= 4 && |
2731 | obj->tiling_mode != I915_TILING_NONE) | |
2732 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2733 | |
de1aa629 VS |
2734 | if (IS_G4X(dev)) |
2735 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2736 | ||
b9897127 | 2737 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2738 | |
c2c75131 DV |
2739 | if (INTEL_INFO(dev)->gen >= 4) { |
2740 | intel_crtc->dspaddr_offset = | |
4e9a86b6 VS |
2741 | intel_gen4_compute_page_offset(dev_priv, |
2742 | &x, &y, obj->tiling_mode, | |
b9897127 | 2743 | pixel_size, |
bc752862 | 2744 | fb->pitches[0]); |
c2c75131 DV |
2745 | linear_offset -= intel_crtc->dspaddr_offset; |
2746 | } else { | |
e506a0c6 | 2747 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2748 | } |
e506a0c6 | 2749 | |
8e7d688b | 2750 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2751 | dspcntr |= DISPPLANE_ROTATE_180; |
2752 | ||
6e3c9717 ACO |
2753 | x += (intel_crtc->config->pipe_src_w - 1); |
2754 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2755 | |
2756 | /* Finding the last pixel of the last line of the display | |
2757 | data and adding to linear_offset*/ | |
2758 | linear_offset += | |
6e3c9717 ACO |
2759 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2760 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2761 | } |
2762 | ||
2db3366b PZ |
2763 | intel_crtc->adjusted_x = x; |
2764 | intel_crtc->adjusted_y = y; | |
2765 | ||
48404c1e SJ |
2766 | I915_WRITE(reg, dspcntr); |
2767 | ||
01f2c773 | 2768 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2769 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2770 | I915_WRITE(DSPSURF(plane), |
2771 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2772 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2773 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2774 | } else |
f343c5f6 | 2775 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2776 | POSTING_READ(reg); |
17638cd6 JB |
2777 | } |
2778 | ||
29b9bde6 DV |
2779 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2780 | struct drm_framebuffer *fb, | |
2781 | int x, int y) | |
17638cd6 JB |
2782 | { |
2783 | struct drm_device *dev = crtc->dev; | |
2784 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2785 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2786 | struct drm_plane *primary = crtc->primary; |
2787 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2788 | struct drm_i915_gem_object *obj; |
17638cd6 | 2789 | int plane = intel_crtc->plane; |
e506a0c6 | 2790 | unsigned long linear_offset; |
17638cd6 | 2791 | u32 dspcntr; |
f45651ba | 2792 | u32 reg = DSPCNTR(plane); |
48404c1e | 2793 | int pixel_size; |
f45651ba | 2794 | |
b70709a6 | 2795 | if (!visible || !fb) { |
fdd508a6 VS |
2796 | I915_WRITE(reg, 0); |
2797 | I915_WRITE(DSPSURF(plane), 0); | |
2798 | POSTING_READ(reg); | |
2799 | return; | |
2800 | } | |
2801 | ||
c9ba6fad VS |
2802 | obj = intel_fb_obj(fb); |
2803 | if (WARN_ON(obj == NULL)) | |
2804 | return; | |
2805 | ||
2806 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2807 | ||
f45651ba VS |
2808 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2809 | ||
fdd508a6 | 2810 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2811 | |
2812 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2813 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2814 | |
57779d06 VS |
2815 | switch (fb->pixel_format) { |
2816 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2817 | dspcntr |= DISPPLANE_8BPP; |
2818 | break; | |
57779d06 VS |
2819 | case DRM_FORMAT_RGB565: |
2820 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2821 | break; |
57779d06 | 2822 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2823 | dspcntr |= DISPPLANE_BGRX888; |
2824 | break; | |
2825 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2826 | dspcntr |= DISPPLANE_RGBX888; |
2827 | break; | |
2828 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2829 | dspcntr |= DISPPLANE_BGRX101010; |
2830 | break; | |
2831 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2832 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2833 | break; |
2834 | default: | |
baba133a | 2835 | BUG(); |
17638cd6 JB |
2836 | } |
2837 | ||
2838 | if (obj->tiling_mode != I915_TILING_NONE) | |
2839 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2840 | |
f45651ba | 2841 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2842 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2843 | |
b9897127 | 2844 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2845 | intel_crtc->dspaddr_offset = |
4e9a86b6 VS |
2846 | intel_gen4_compute_page_offset(dev_priv, |
2847 | &x, &y, obj->tiling_mode, | |
b9897127 | 2848 | pixel_size, |
bc752862 | 2849 | fb->pitches[0]); |
c2c75131 | 2850 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2851 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2852 | dspcntr |= DISPPLANE_ROTATE_180; |
2853 | ||
2854 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2855 | x += (intel_crtc->config->pipe_src_w - 1); |
2856 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2857 | |
2858 | /* Finding the last pixel of the last line of the display | |
2859 | data and adding to linear_offset*/ | |
2860 | linear_offset += | |
6e3c9717 ACO |
2861 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2862 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2863 | } |
2864 | } | |
2865 | ||
2db3366b PZ |
2866 | intel_crtc->adjusted_x = x; |
2867 | intel_crtc->adjusted_y = y; | |
2868 | ||
48404c1e | 2869 | I915_WRITE(reg, dspcntr); |
17638cd6 | 2870 | |
01f2c773 | 2871 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2872 | I915_WRITE(DSPSURF(plane), |
2873 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2874 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2875 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2876 | } else { | |
2877 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2878 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2879 | } | |
17638cd6 | 2880 | POSTING_READ(reg); |
17638cd6 JB |
2881 | } |
2882 | ||
b321803d DL |
2883 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2884 | uint32_t pixel_format) | |
2885 | { | |
2886 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2887 | ||
2888 | /* | |
2889 | * The stride is either expressed as a multiple of 64 bytes | |
2890 | * chunks for linear buffers or in number of tiles for tiled | |
2891 | * buffers. | |
2892 | */ | |
2893 | switch (fb_modifier) { | |
2894 | case DRM_FORMAT_MOD_NONE: | |
2895 | return 64; | |
2896 | case I915_FORMAT_MOD_X_TILED: | |
2897 | if (INTEL_INFO(dev)->gen == 2) | |
2898 | return 128; | |
2899 | return 512; | |
2900 | case I915_FORMAT_MOD_Y_TILED: | |
2901 | /* No need to check for old gens and Y tiling since this is | |
2902 | * about the display engine and those will be blocked before | |
2903 | * we get here. | |
2904 | */ | |
2905 | return 128; | |
2906 | case I915_FORMAT_MOD_Yf_TILED: | |
2907 | if (bits_per_pixel == 8) | |
2908 | return 64; | |
2909 | else | |
2910 | return 128; | |
2911 | default: | |
2912 | MISSING_CASE(fb_modifier); | |
2913 | return 64; | |
2914 | } | |
2915 | } | |
2916 | ||
44eb0cb9 MK |
2917 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
2918 | struct drm_i915_gem_object *obj, | |
2919 | unsigned int plane) | |
121920fa | 2920 | { |
9abc4648 | 2921 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
dedf278c | 2922 | struct i915_vma *vma; |
44eb0cb9 | 2923 | u64 offset; |
121920fa TU |
2924 | |
2925 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) | |
9abc4648 | 2926 | view = &i915_ggtt_view_rotated; |
121920fa | 2927 | |
dedf278c TU |
2928 | vma = i915_gem_obj_to_ggtt_view(obj, view); |
2929 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", | |
2930 | view->type)) | |
2931 | return -1; | |
2932 | ||
44eb0cb9 | 2933 | offset = vma->node.start; |
dedf278c TU |
2934 | |
2935 | if (plane == 1) { | |
2936 | offset += vma->ggtt_view.rotation_info.uv_start_page * | |
2937 | PAGE_SIZE; | |
2938 | } | |
2939 | ||
44eb0cb9 MK |
2940 | WARN_ON(upper_32_bits(offset)); |
2941 | ||
2942 | return lower_32_bits(offset); | |
121920fa TU |
2943 | } |
2944 | ||
e435d6e5 ML |
2945 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
2946 | { | |
2947 | struct drm_device *dev = intel_crtc->base.dev; | |
2948 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2949 | ||
2950 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
2951 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
2952 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
2953 | } |
2954 | ||
a1b2278e CK |
2955 | /* |
2956 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2957 | */ | |
0583236e | 2958 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 2959 | { |
a1b2278e CK |
2960 | struct intel_crtc_scaler_state *scaler_state; |
2961 | int i; | |
2962 | ||
a1b2278e CK |
2963 | scaler_state = &intel_crtc->config->scaler_state; |
2964 | ||
2965 | /* loop through and disable scalers that aren't in use */ | |
2966 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
2967 | if (!scaler_state->scalers[i].in_use) |
2968 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
2969 | } |
2970 | } | |
2971 | ||
6156a456 | 2972 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2973 | { |
6156a456 | 2974 | switch (pixel_format) { |
d161cf7a | 2975 | case DRM_FORMAT_C8: |
c34ce3d1 | 2976 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2977 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2978 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2979 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2980 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2981 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2982 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2983 | /* |
2984 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2985 | * to be already pre-multiplied. We need to add a knob (or a different | |
2986 | * DRM_FORMAT) for user-space to configure that. | |
2987 | */ | |
f75fb42a | 2988 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 2989 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 2990 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 2991 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 2992 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 2993 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 2994 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 2995 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 2996 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 2997 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 2998 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 2999 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 3000 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 3001 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 3002 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 3003 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 3004 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 3005 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 3006 | default: |
4249eeef | 3007 | MISSING_CASE(pixel_format); |
70d21f0e | 3008 | } |
8cfcba41 | 3009 | |
c34ce3d1 | 3010 | return 0; |
6156a456 | 3011 | } |
70d21f0e | 3012 | |
6156a456 CK |
3013 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
3014 | { | |
6156a456 | 3015 | switch (fb_modifier) { |
30af77c4 | 3016 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 3017 | break; |
30af77c4 | 3018 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 3019 | return PLANE_CTL_TILED_X; |
b321803d | 3020 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 3021 | return PLANE_CTL_TILED_Y; |
b321803d | 3022 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3023 | return PLANE_CTL_TILED_YF; |
70d21f0e | 3024 | default: |
6156a456 | 3025 | MISSING_CASE(fb_modifier); |
70d21f0e | 3026 | } |
8cfcba41 | 3027 | |
c34ce3d1 | 3028 | return 0; |
6156a456 | 3029 | } |
70d21f0e | 3030 | |
6156a456 CK |
3031 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
3032 | { | |
3b7a5119 | 3033 | switch (rotation) { |
6156a456 CK |
3034 | case BIT(DRM_ROTATE_0): |
3035 | break; | |
1e8df167 SJ |
3036 | /* |
3037 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3038 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3039 | */ | |
3b7a5119 | 3040 | case BIT(DRM_ROTATE_90): |
1e8df167 | 3041 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 3042 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3043 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3044 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3045 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3046 | default: |
3047 | MISSING_CASE(rotation); | |
3048 | } | |
3049 | ||
c34ce3d1 | 3050 | return 0; |
6156a456 CK |
3051 | } |
3052 | ||
3053 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
3054 | struct drm_framebuffer *fb, | |
3055 | int x, int y) | |
3056 | { | |
3057 | struct drm_device *dev = crtc->dev; | |
3058 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3059 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3060 | struct drm_plane *plane = crtc->primary; |
3061 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3062 | struct drm_i915_gem_object *obj; |
3063 | int pipe = intel_crtc->pipe; | |
3064 | u32 plane_ctl, stride_div, stride; | |
3065 | u32 tile_height, plane_offset, plane_size; | |
3066 | unsigned int rotation; | |
3067 | int x_offset, y_offset; | |
44eb0cb9 | 3068 | u32 surf_addr; |
6156a456 CK |
3069 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3070 | struct intel_plane_state *plane_state; | |
3071 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3072 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3073 | int scaler_id = -1; | |
3074 | ||
6156a456 CK |
3075 | plane_state = to_intel_plane_state(plane->state); |
3076 | ||
b70709a6 | 3077 | if (!visible || !fb) { |
6156a456 CK |
3078 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3079 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3080 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3081 | return; | |
3b7a5119 | 3082 | } |
70d21f0e | 3083 | |
6156a456 CK |
3084 | plane_ctl = PLANE_CTL_ENABLE | |
3085 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3086 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3087 | ||
3088 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3089 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3090 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3091 | ||
3092 | rotation = plane->state->rotation; | |
3093 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3094 | ||
b321803d DL |
3095 | obj = intel_fb_obj(fb); |
3096 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3097 | fb->pixel_format); | |
dedf278c | 3098 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
3b7a5119 | 3099 | |
a42e5a23 PZ |
3100 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
3101 | ||
3102 | scaler_id = plane_state->scaler_id; | |
3103 | src_x = plane_state->src.x1 >> 16; | |
3104 | src_y = plane_state->src.y1 >> 16; | |
3105 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3106 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3107 | dst_x = plane_state->dst.x1; | |
3108 | dst_y = plane_state->dst.y1; | |
3109 | dst_w = drm_rect_width(&plane_state->dst); | |
3110 | dst_h = drm_rect_height(&plane_state->dst); | |
3111 | ||
3112 | WARN_ON(x != src_x || y != src_y); | |
6156a456 | 3113 | |
3b7a5119 SJ |
3114 | if (intel_rotation_90_or_270(rotation)) { |
3115 | /* stride = Surface height in tiles */ | |
2614f17d | 3116 | tile_height = intel_tile_height(dev, fb->pixel_format, |
fe47ea0c | 3117 | fb->modifier[0], 0); |
3b7a5119 | 3118 | stride = DIV_ROUND_UP(fb->height, tile_height); |
6156a456 | 3119 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3120 | y_offset = x; |
6156a456 | 3121 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3122 | } else { |
3123 | stride = fb->pitches[0] / stride_div; | |
3124 | x_offset = x; | |
3125 | y_offset = y; | |
6156a456 | 3126 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3127 | } |
3128 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3129 | |
2db3366b PZ |
3130 | intel_crtc->adjusted_x = x_offset; |
3131 | intel_crtc->adjusted_y = y_offset; | |
3132 | ||
70d21f0e | 3133 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3134 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3135 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3136 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3137 | |
3138 | if (scaler_id >= 0) { | |
3139 | uint32_t ps_ctrl = 0; | |
3140 | ||
3141 | WARN_ON(!dst_w || !dst_h); | |
3142 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3143 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3144 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3145 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3146 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3147 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3148 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3149 | } else { | |
3150 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3151 | } | |
3152 | ||
121920fa | 3153 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3154 | |
3155 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3156 | } | |
3157 | ||
17638cd6 JB |
3158 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3159 | static int | |
3160 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3161 | int x, int y, enum mode_set_atomic state) | |
3162 | { | |
3163 | struct drm_device *dev = crtc->dev; | |
3164 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3165 | |
ff2a3117 | 3166 | if (dev_priv->fbc.disable_fbc) |
7733b49b | 3167 | dev_priv->fbc.disable_fbc(dev_priv); |
81255565 | 3168 | |
29b9bde6 DV |
3169 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3170 | ||
3171 | return 0; | |
81255565 JB |
3172 | } |
3173 | ||
7514747d | 3174 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3175 | { |
96a02917 VS |
3176 | struct drm_crtc *crtc; |
3177 | ||
70e1e0ec | 3178 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3180 | enum plane plane = intel_crtc->plane; | |
3181 | ||
3182 | intel_prepare_page_flip(dev, plane); | |
3183 | intel_finish_page_flip_plane(dev, plane); | |
3184 | } | |
7514747d VS |
3185 | } |
3186 | ||
3187 | static void intel_update_primary_planes(struct drm_device *dev) | |
3188 | { | |
7514747d | 3189 | struct drm_crtc *crtc; |
96a02917 | 3190 | |
70e1e0ec | 3191 | for_each_crtc(dev, crtc) { |
11c22da6 ML |
3192 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
3193 | struct intel_plane_state *plane_state; | |
96a02917 | 3194 | |
11c22da6 | 3195 | drm_modeset_lock_crtc(crtc, &plane->base); |
11c22da6 ML |
3196 | plane_state = to_intel_plane_state(plane->base.state); |
3197 | ||
f029ee82 | 3198 | if (crtc->state->active && plane_state->base.fb) |
11c22da6 ML |
3199 | plane->commit_plane(&plane->base, plane_state); |
3200 | ||
3201 | drm_modeset_unlock_crtc(crtc); | |
96a02917 VS |
3202 | } |
3203 | } | |
3204 | ||
7514747d VS |
3205 | void intel_prepare_reset(struct drm_device *dev) |
3206 | { | |
3207 | /* no reset support for gen2 */ | |
3208 | if (IS_GEN2(dev)) | |
3209 | return; | |
3210 | ||
3211 | /* reset doesn't touch the display */ | |
3212 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3213 | return; | |
3214 | ||
3215 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3216 | /* |
3217 | * Disabling the crtcs gracefully seems nicer. Also the | |
3218 | * g33 docs say we should at least disable all the planes. | |
3219 | */ | |
6b72d486 | 3220 | intel_display_suspend(dev); |
7514747d VS |
3221 | } |
3222 | ||
3223 | void intel_finish_reset(struct drm_device *dev) | |
3224 | { | |
3225 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3226 | ||
3227 | /* | |
3228 | * Flips in the rings will be nuked by the reset, | |
3229 | * so complete all pending flips so that user space | |
3230 | * will get its events and not get stuck. | |
3231 | */ | |
3232 | intel_complete_page_flips(dev); | |
3233 | ||
3234 | /* no reset support for gen2 */ | |
3235 | if (IS_GEN2(dev)) | |
3236 | return; | |
3237 | ||
3238 | /* reset doesn't touch the display */ | |
3239 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3240 | /* | |
3241 | * Flips in the rings have been nuked by the reset, | |
3242 | * so update the base address of all primary | |
3243 | * planes to the the last fb to make sure we're | |
3244 | * showing the correct fb after a reset. | |
11c22da6 ML |
3245 | * |
3246 | * FIXME: Atomic will make this obsolete since we won't schedule | |
3247 | * CS-based flips (which might get lost in gpu resets) any more. | |
7514747d VS |
3248 | */ |
3249 | intel_update_primary_planes(dev); | |
3250 | return; | |
3251 | } | |
3252 | ||
3253 | /* | |
3254 | * The display has been reset as well, | |
3255 | * so need a full re-initialization. | |
3256 | */ | |
3257 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3258 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3259 | ||
3260 | intel_modeset_init_hw(dev); | |
3261 | ||
3262 | spin_lock_irq(&dev_priv->irq_lock); | |
3263 | if (dev_priv->display.hpd_irq_setup) | |
3264 | dev_priv->display.hpd_irq_setup(dev); | |
3265 | spin_unlock_irq(&dev_priv->irq_lock); | |
3266 | ||
043e9bda | 3267 | intel_display_resume(dev); |
7514747d VS |
3268 | |
3269 | intel_hpd_init(dev_priv); | |
3270 | ||
3271 | drm_modeset_unlock_all(dev); | |
3272 | } | |
3273 | ||
7d5e3799 CW |
3274 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3275 | { | |
3276 | struct drm_device *dev = crtc->dev; | |
3277 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3278 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3279 | bool pending; |
3280 | ||
3281 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3282 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3283 | return false; | |
3284 | ||
5e2d7afc | 3285 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3286 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3287 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3288 | |
3289 | return pending; | |
3290 | } | |
3291 | ||
bfd16b2a ML |
3292 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
3293 | struct intel_crtc_state *old_crtc_state) | |
e30e8f75 GP |
3294 | { |
3295 | struct drm_device *dev = crtc->base.dev; | |
3296 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bfd16b2a ML |
3297 | struct intel_crtc_state *pipe_config = |
3298 | to_intel_crtc_state(crtc->base.state); | |
e30e8f75 | 3299 | |
bfd16b2a ML |
3300 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
3301 | crtc->base.mode = crtc->base.state->mode; | |
3302 | ||
3303 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", | |
3304 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, | |
3305 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
e30e8f75 | 3306 | |
44522d85 ML |
3307 | if (HAS_DDI(dev)) |
3308 | intel_set_pipe_csc(&crtc->base); | |
3309 | ||
e30e8f75 GP |
3310 | /* |
3311 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3312 | * that in compute_mode_changes we check the native mode (not the pfit | |
3313 | * mode) to see if we can flip rather than do a full mode set. In the | |
3314 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3315 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3316 | * sized surface. | |
e30e8f75 GP |
3317 | */ |
3318 | ||
e30e8f75 | 3319 | I915_WRITE(PIPESRC(crtc->pipe), |
bfd16b2a ML |
3320 | ((pipe_config->pipe_src_w - 1) << 16) | |
3321 | (pipe_config->pipe_src_h - 1)); | |
3322 | ||
3323 | /* on skylake this is done by detaching scalers */ | |
3324 | if (INTEL_INFO(dev)->gen >= 9) { | |
3325 | skl_detach_scalers(crtc); | |
3326 | ||
3327 | if (pipe_config->pch_pfit.enabled) | |
3328 | skylake_pfit_enable(crtc); | |
3329 | } else if (HAS_PCH_SPLIT(dev)) { | |
3330 | if (pipe_config->pch_pfit.enabled) | |
3331 | ironlake_pfit_enable(crtc); | |
3332 | else if (old_crtc_state->pch_pfit.enabled) | |
3333 | ironlake_pfit_disable(crtc, true); | |
e30e8f75 | 3334 | } |
e30e8f75 GP |
3335 | } |
3336 | ||
5e84e1a4 ZW |
3337 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3338 | { | |
3339 | struct drm_device *dev = crtc->dev; | |
3340 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3341 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3342 | int pipe = intel_crtc->pipe; | |
3343 | u32 reg, temp; | |
3344 | ||
3345 | /* enable normal train */ | |
3346 | reg = FDI_TX_CTL(pipe); | |
3347 | temp = I915_READ(reg); | |
61e499bf | 3348 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3349 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3350 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3351 | } else { |
3352 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3353 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3354 | } |
5e84e1a4 ZW |
3355 | I915_WRITE(reg, temp); |
3356 | ||
3357 | reg = FDI_RX_CTL(pipe); | |
3358 | temp = I915_READ(reg); | |
3359 | if (HAS_PCH_CPT(dev)) { | |
3360 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3361 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3362 | } else { | |
3363 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3364 | temp |= FDI_LINK_TRAIN_NONE; | |
3365 | } | |
3366 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3367 | ||
3368 | /* wait one idle pattern time */ | |
3369 | POSTING_READ(reg); | |
3370 | udelay(1000); | |
357555c0 JB |
3371 | |
3372 | /* IVB wants error correction enabled */ | |
3373 | if (IS_IVYBRIDGE(dev)) | |
3374 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3375 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3376 | } |
3377 | ||
8db9d77b ZW |
3378 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3379 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3380 | { | |
3381 | struct drm_device *dev = crtc->dev; | |
3382 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3383 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3384 | int pipe = intel_crtc->pipe; | |
5eddb70b | 3385 | u32 reg, temp, tries; |
8db9d77b | 3386 | |
1c8562f6 | 3387 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3388 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3389 | |
e1a44743 AJ |
3390 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3391 | for train result */ | |
5eddb70b CW |
3392 | reg = FDI_RX_IMR(pipe); |
3393 | temp = I915_READ(reg); | |
e1a44743 AJ |
3394 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3395 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3396 | I915_WRITE(reg, temp); |
3397 | I915_READ(reg); | |
e1a44743 AJ |
3398 | udelay(150); |
3399 | ||
8db9d77b | 3400 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3401 | reg = FDI_TX_CTL(pipe); |
3402 | temp = I915_READ(reg); | |
627eb5a3 | 3403 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3404 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3405 | temp &= ~FDI_LINK_TRAIN_NONE; |
3406 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3407 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3408 | |
5eddb70b CW |
3409 | reg = FDI_RX_CTL(pipe); |
3410 | temp = I915_READ(reg); | |
8db9d77b ZW |
3411 | temp &= ~FDI_LINK_TRAIN_NONE; |
3412 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3413 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3414 | ||
3415 | POSTING_READ(reg); | |
8db9d77b ZW |
3416 | udelay(150); |
3417 | ||
5b2adf89 | 3418 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3419 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3420 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3421 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3422 | |
5eddb70b | 3423 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3424 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3425 | temp = I915_READ(reg); |
8db9d77b ZW |
3426 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3427 | ||
3428 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3429 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3430 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3431 | break; |
3432 | } | |
8db9d77b | 3433 | } |
e1a44743 | 3434 | if (tries == 5) |
5eddb70b | 3435 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3436 | |
3437 | /* Train 2 */ | |
5eddb70b CW |
3438 | reg = FDI_TX_CTL(pipe); |
3439 | temp = I915_READ(reg); | |
8db9d77b ZW |
3440 | temp &= ~FDI_LINK_TRAIN_NONE; |
3441 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3442 | I915_WRITE(reg, temp); |
8db9d77b | 3443 | |
5eddb70b CW |
3444 | reg = FDI_RX_CTL(pipe); |
3445 | temp = I915_READ(reg); | |
8db9d77b ZW |
3446 | temp &= ~FDI_LINK_TRAIN_NONE; |
3447 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3448 | I915_WRITE(reg, temp); |
8db9d77b | 3449 | |
5eddb70b CW |
3450 | POSTING_READ(reg); |
3451 | udelay(150); | |
8db9d77b | 3452 | |
5eddb70b | 3453 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3454 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3455 | temp = I915_READ(reg); |
8db9d77b ZW |
3456 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3457 | ||
3458 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3459 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3460 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3461 | break; | |
3462 | } | |
8db9d77b | 3463 | } |
e1a44743 | 3464 | if (tries == 5) |
5eddb70b | 3465 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3466 | |
3467 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3468 | |
8db9d77b ZW |
3469 | } |
3470 | ||
0206e353 | 3471 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3472 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3473 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3474 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3475 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3476 | }; | |
3477 | ||
3478 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3479 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3480 | { | |
3481 | struct drm_device *dev = crtc->dev; | |
3482 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3483 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3484 | int pipe = intel_crtc->pipe; | |
fa37d39e | 3485 | u32 reg, temp, i, retry; |
8db9d77b | 3486 | |
e1a44743 AJ |
3487 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3488 | for train result */ | |
5eddb70b CW |
3489 | reg = FDI_RX_IMR(pipe); |
3490 | temp = I915_READ(reg); | |
e1a44743 AJ |
3491 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3492 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3493 | I915_WRITE(reg, temp); |
3494 | ||
3495 | POSTING_READ(reg); | |
e1a44743 AJ |
3496 | udelay(150); |
3497 | ||
8db9d77b | 3498 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3499 | reg = FDI_TX_CTL(pipe); |
3500 | temp = I915_READ(reg); | |
627eb5a3 | 3501 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3502 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3503 | temp &= ~FDI_LINK_TRAIN_NONE; |
3504 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3505 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3506 | /* SNB-B */ | |
3507 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3508 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3509 | |
d74cf324 DV |
3510 | I915_WRITE(FDI_RX_MISC(pipe), |
3511 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3512 | ||
5eddb70b CW |
3513 | reg = FDI_RX_CTL(pipe); |
3514 | temp = I915_READ(reg); | |
8db9d77b ZW |
3515 | if (HAS_PCH_CPT(dev)) { |
3516 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3517 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3518 | } else { | |
3519 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3520 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3521 | } | |
5eddb70b CW |
3522 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3523 | ||
3524 | POSTING_READ(reg); | |
8db9d77b ZW |
3525 | udelay(150); |
3526 | ||
0206e353 | 3527 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3528 | reg = FDI_TX_CTL(pipe); |
3529 | temp = I915_READ(reg); | |
8db9d77b ZW |
3530 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3531 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3532 | I915_WRITE(reg, temp); |
3533 | ||
3534 | POSTING_READ(reg); | |
8db9d77b ZW |
3535 | udelay(500); |
3536 | ||
fa37d39e SP |
3537 | for (retry = 0; retry < 5; retry++) { |
3538 | reg = FDI_RX_IIR(pipe); | |
3539 | temp = I915_READ(reg); | |
3540 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3541 | if (temp & FDI_RX_BIT_LOCK) { | |
3542 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3543 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3544 | break; | |
3545 | } | |
3546 | udelay(50); | |
8db9d77b | 3547 | } |
fa37d39e SP |
3548 | if (retry < 5) |
3549 | break; | |
8db9d77b ZW |
3550 | } |
3551 | if (i == 4) | |
5eddb70b | 3552 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3553 | |
3554 | /* Train 2 */ | |
5eddb70b CW |
3555 | reg = FDI_TX_CTL(pipe); |
3556 | temp = I915_READ(reg); | |
8db9d77b ZW |
3557 | temp &= ~FDI_LINK_TRAIN_NONE; |
3558 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3559 | if (IS_GEN6(dev)) { | |
3560 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3561 | /* SNB-B */ | |
3562 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3563 | } | |
5eddb70b | 3564 | I915_WRITE(reg, temp); |
8db9d77b | 3565 | |
5eddb70b CW |
3566 | reg = FDI_RX_CTL(pipe); |
3567 | temp = I915_READ(reg); | |
8db9d77b ZW |
3568 | if (HAS_PCH_CPT(dev)) { |
3569 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3570 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3571 | } else { | |
3572 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3573 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3574 | } | |
5eddb70b CW |
3575 | I915_WRITE(reg, temp); |
3576 | ||
3577 | POSTING_READ(reg); | |
8db9d77b ZW |
3578 | udelay(150); |
3579 | ||
0206e353 | 3580 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3581 | reg = FDI_TX_CTL(pipe); |
3582 | temp = I915_READ(reg); | |
8db9d77b ZW |
3583 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3584 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3585 | I915_WRITE(reg, temp); |
3586 | ||
3587 | POSTING_READ(reg); | |
8db9d77b ZW |
3588 | udelay(500); |
3589 | ||
fa37d39e SP |
3590 | for (retry = 0; retry < 5; retry++) { |
3591 | reg = FDI_RX_IIR(pipe); | |
3592 | temp = I915_READ(reg); | |
3593 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3594 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3595 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3596 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3597 | break; | |
3598 | } | |
3599 | udelay(50); | |
8db9d77b | 3600 | } |
fa37d39e SP |
3601 | if (retry < 5) |
3602 | break; | |
8db9d77b ZW |
3603 | } |
3604 | if (i == 4) | |
5eddb70b | 3605 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3606 | |
3607 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3608 | } | |
3609 | ||
357555c0 JB |
3610 | /* Manual link training for Ivy Bridge A0 parts */ |
3611 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3612 | { | |
3613 | struct drm_device *dev = crtc->dev; | |
3614 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3615 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3616 | int pipe = intel_crtc->pipe; | |
139ccd3f | 3617 | u32 reg, temp, i, j; |
357555c0 JB |
3618 | |
3619 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3620 | for train result */ | |
3621 | reg = FDI_RX_IMR(pipe); | |
3622 | temp = I915_READ(reg); | |
3623 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3624 | temp &= ~FDI_RX_BIT_LOCK; | |
3625 | I915_WRITE(reg, temp); | |
3626 | ||
3627 | POSTING_READ(reg); | |
3628 | udelay(150); | |
3629 | ||
01a415fd DV |
3630 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3631 | I915_READ(FDI_RX_IIR(pipe))); | |
3632 | ||
139ccd3f JB |
3633 | /* Try each vswing and preemphasis setting twice before moving on */ |
3634 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3635 | /* disable first in case we need to retry */ | |
3636 | reg = FDI_TX_CTL(pipe); | |
3637 | temp = I915_READ(reg); | |
3638 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3639 | temp &= ~FDI_TX_ENABLE; | |
3640 | I915_WRITE(reg, temp); | |
357555c0 | 3641 | |
139ccd3f JB |
3642 | reg = FDI_RX_CTL(pipe); |
3643 | temp = I915_READ(reg); | |
3644 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3645 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3646 | temp &= ~FDI_RX_ENABLE; | |
3647 | I915_WRITE(reg, temp); | |
357555c0 | 3648 | |
139ccd3f | 3649 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3650 | reg = FDI_TX_CTL(pipe); |
3651 | temp = I915_READ(reg); | |
139ccd3f | 3652 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3653 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3654 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3655 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3656 | temp |= snb_b_fdi_train_param[j/2]; |
3657 | temp |= FDI_COMPOSITE_SYNC; | |
3658 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3659 | |
139ccd3f JB |
3660 | I915_WRITE(FDI_RX_MISC(pipe), |
3661 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3662 | |
139ccd3f | 3663 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3664 | temp = I915_READ(reg); |
139ccd3f JB |
3665 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3666 | temp |= FDI_COMPOSITE_SYNC; | |
3667 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3668 | |
139ccd3f JB |
3669 | POSTING_READ(reg); |
3670 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3671 | |
139ccd3f JB |
3672 | for (i = 0; i < 4; i++) { |
3673 | reg = FDI_RX_IIR(pipe); | |
3674 | temp = I915_READ(reg); | |
3675 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3676 | |
139ccd3f JB |
3677 | if (temp & FDI_RX_BIT_LOCK || |
3678 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3679 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3680 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3681 | i); | |
3682 | break; | |
3683 | } | |
3684 | udelay(1); /* should be 0.5us */ | |
3685 | } | |
3686 | if (i == 4) { | |
3687 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3688 | continue; | |
3689 | } | |
357555c0 | 3690 | |
139ccd3f | 3691 | /* Train 2 */ |
357555c0 JB |
3692 | reg = FDI_TX_CTL(pipe); |
3693 | temp = I915_READ(reg); | |
139ccd3f JB |
3694 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3695 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3696 | I915_WRITE(reg, temp); | |
3697 | ||
3698 | reg = FDI_RX_CTL(pipe); | |
3699 | temp = I915_READ(reg); | |
3700 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3701 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3702 | I915_WRITE(reg, temp); |
3703 | ||
3704 | POSTING_READ(reg); | |
139ccd3f | 3705 | udelay(2); /* should be 1.5us */ |
357555c0 | 3706 | |
139ccd3f JB |
3707 | for (i = 0; i < 4; i++) { |
3708 | reg = FDI_RX_IIR(pipe); | |
3709 | temp = I915_READ(reg); | |
3710 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3711 | |
139ccd3f JB |
3712 | if (temp & FDI_RX_SYMBOL_LOCK || |
3713 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3714 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3715 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3716 | i); | |
3717 | goto train_done; | |
3718 | } | |
3719 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3720 | } |
139ccd3f JB |
3721 | if (i == 4) |
3722 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3723 | } |
357555c0 | 3724 | |
139ccd3f | 3725 | train_done: |
357555c0 JB |
3726 | DRM_DEBUG_KMS("FDI train done.\n"); |
3727 | } | |
3728 | ||
88cefb6c | 3729 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3730 | { |
88cefb6c | 3731 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3732 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3733 | int pipe = intel_crtc->pipe; |
5eddb70b | 3734 | u32 reg, temp; |
79e53945 | 3735 | |
c64e311e | 3736 | |
c98e9dcf | 3737 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3738 | reg = FDI_RX_CTL(pipe); |
3739 | temp = I915_READ(reg); | |
627eb5a3 | 3740 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3741 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3742 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3743 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3744 | ||
3745 | POSTING_READ(reg); | |
c98e9dcf JB |
3746 | udelay(200); |
3747 | ||
3748 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3749 | temp = I915_READ(reg); |
3750 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3751 | ||
3752 | POSTING_READ(reg); | |
c98e9dcf JB |
3753 | udelay(200); |
3754 | ||
20749730 PZ |
3755 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3756 | reg = FDI_TX_CTL(pipe); | |
3757 | temp = I915_READ(reg); | |
3758 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3759 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3760 | |
20749730 PZ |
3761 | POSTING_READ(reg); |
3762 | udelay(100); | |
6be4a607 | 3763 | } |
0e23b99d JB |
3764 | } |
3765 | ||
88cefb6c DV |
3766 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3767 | { | |
3768 | struct drm_device *dev = intel_crtc->base.dev; | |
3769 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3770 | int pipe = intel_crtc->pipe; | |
3771 | u32 reg, temp; | |
3772 | ||
3773 | /* Switch from PCDclk to Rawclk */ | |
3774 | reg = FDI_RX_CTL(pipe); | |
3775 | temp = I915_READ(reg); | |
3776 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3777 | ||
3778 | /* Disable CPU FDI TX PLL */ | |
3779 | reg = FDI_TX_CTL(pipe); | |
3780 | temp = I915_READ(reg); | |
3781 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3782 | ||
3783 | POSTING_READ(reg); | |
3784 | udelay(100); | |
3785 | ||
3786 | reg = FDI_RX_CTL(pipe); | |
3787 | temp = I915_READ(reg); | |
3788 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3789 | ||
3790 | /* Wait for the clocks to turn off. */ | |
3791 | POSTING_READ(reg); | |
3792 | udelay(100); | |
3793 | } | |
3794 | ||
0fc932b8 JB |
3795 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3796 | { | |
3797 | struct drm_device *dev = crtc->dev; | |
3798 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3799 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3800 | int pipe = intel_crtc->pipe; | |
3801 | u32 reg, temp; | |
3802 | ||
3803 | /* disable CPU FDI tx and PCH FDI rx */ | |
3804 | reg = FDI_TX_CTL(pipe); | |
3805 | temp = I915_READ(reg); | |
3806 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3807 | POSTING_READ(reg); | |
3808 | ||
3809 | reg = FDI_RX_CTL(pipe); | |
3810 | temp = I915_READ(reg); | |
3811 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3812 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3813 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3814 | ||
3815 | POSTING_READ(reg); | |
3816 | udelay(100); | |
3817 | ||
3818 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3819 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3820 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3821 | |
3822 | /* still set train pattern 1 */ | |
3823 | reg = FDI_TX_CTL(pipe); | |
3824 | temp = I915_READ(reg); | |
3825 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3826 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3827 | I915_WRITE(reg, temp); | |
3828 | ||
3829 | reg = FDI_RX_CTL(pipe); | |
3830 | temp = I915_READ(reg); | |
3831 | if (HAS_PCH_CPT(dev)) { | |
3832 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3833 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3834 | } else { | |
3835 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3836 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3837 | } | |
3838 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3839 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3840 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3841 | I915_WRITE(reg, temp); |
3842 | ||
3843 | POSTING_READ(reg); | |
3844 | udelay(100); | |
3845 | } | |
3846 | ||
5dce5b93 CW |
3847 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3848 | { | |
3849 | struct intel_crtc *crtc; | |
3850 | ||
3851 | /* Note that we don't need to be called with mode_config.lock here | |
3852 | * as our list of CRTC objects is static for the lifetime of the | |
3853 | * device and so cannot disappear as we iterate. Similarly, we can | |
3854 | * happily treat the predicates as racy, atomic checks as userspace | |
3855 | * cannot claim and pin a new fb without at least acquring the | |
3856 | * struct_mutex and so serialising with us. | |
3857 | */ | |
d3fcc808 | 3858 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3859 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3860 | continue; | |
3861 | ||
3862 | if (crtc->unpin_work) | |
3863 | intel_wait_for_vblank(dev, crtc->pipe); | |
3864 | ||
3865 | return true; | |
3866 | } | |
3867 | ||
3868 | return false; | |
3869 | } | |
3870 | ||
d6bbafa1 CW |
3871 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3872 | { | |
3873 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3874 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3875 | ||
3876 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3877 | smp_rmb(); | |
3878 | intel_crtc->unpin_work = NULL; | |
3879 | ||
3880 | if (work->event) | |
3881 | drm_send_vblank_event(intel_crtc->base.dev, | |
3882 | intel_crtc->pipe, | |
3883 | work->event); | |
3884 | ||
3885 | drm_crtc_vblank_put(&intel_crtc->base); | |
3886 | ||
3887 | wake_up_all(&dev_priv->pending_flip_queue); | |
3888 | queue_work(dev_priv->wq, &work->work); | |
3889 | ||
3890 | trace_i915_flip_complete(intel_crtc->plane, | |
3891 | work->pending_flip_obj); | |
3892 | } | |
3893 | ||
5008e874 | 3894 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3895 | { |
0f91128d | 3896 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3897 | struct drm_i915_private *dev_priv = dev->dev_private; |
5008e874 | 3898 | long ret; |
e6c3a2a6 | 3899 | |
2c10d571 | 3900 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
5008e874 ML |
3901 | |
3902 | ret = wait_event_interruptible_timeout( | |
3903 | dev_priv->pending_flip_queue, | |
3904 | !intel_crtc_has_pending_flip(crtc), | |
3905 | 60*HZ); | |
3906 | ||
3907 | if (ret < 0) | |
3908 | return ret; | |
3909 | ||
3910 | if (ret == 0) { | |
9c787942 | 3911 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
2c10d571 | 3912 | |
5e2d7afc | 3913 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3914 | if (intel_crtc->unpin_work) { |
3915 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3916 | page_flip_completed(intel_crtc); | |
3917 | } | |
5e2d7afc | 3918 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3919 | } |
5bb61643 | 3920 | |
5008e874 | 3921 | return 0; |
e6c3a2a6 CW |
3922 | } |
3923 | ||
e615efe4 ED |
3924 | /* Program iCLKIP clock to the desired frequency */ |
3925 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3926 | { | |
3927 | struct drm_device *dev = crtc->dev; | |
3928 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3929 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3930 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3931 | u32 temp; | |
3932 | ||
a580516d | 3933 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 3934 | |
e615efe4 ED |
3935 | /* It is necessary to ungate the pixclk gate prior to programming |
3936 | * the divisors, and gate it back when it is done. | |
3937 | */ | |
3938 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3939 | ||
3940 | /* Disable SSCCTL */ | |
3941 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3942 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3943 | SBI_SSCCTL_DISABLE, | |
3944 | SBI_ICLK); | |
e615efe4 ED |
3945 | |
3946 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3947 | if (clock == 20000) { |
e615efe4 ED |
3948 | auxdiv = 1; |
3949 | divsel = 0x41; | |
3950 | phaseinc = 0x20; | |
3951 | } else { | |
3952 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3953 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3954 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3955 | * convert the virtual clock precision to KHz here for higher |
3956 | * precision. | |
3957 | */ | |
3958 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3959 | u32 iclk_pi_range = 64; | |
3960 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3961 | ||
12d7ceed | 3962 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3963 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3964 | pi_value = desired_divisor % iclk_pi_range; | |
3965 | ||
3966 | auxdiv = 0; | |
3967 | divsel = msb_divisor_value - 2; | |
3968 | phaseinc = pi_value; | |
3969 | } | |
3970 | ||
3971 | /* This should not happen with any sane values */ | |
3972 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3973 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3974 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3975 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3976 | ||
3977 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3978 | clock, |
e615efe4 ED |
3979 | auxdiv, |
3980 | divsel, | |
3981 | phasedir, | |
3982 | phaseinc); | |
3983 | ||
3984 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 3985 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
3986 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
3987 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
3988 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
3989 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
3990 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
3991 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 3992 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
3993 | |
3994 | /* Program SSCAUXDIV */ | |
988d6ee8 | 3995 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
3996 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
3997 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 3998 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
3999 | |
4000 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4001 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4002 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4003 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
4004 | |
4005 | /* Wait for initialization time */ | |
4006 | udelay(24); | |
4007 | ||
4008 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 | 4009 | |
a580516d | 4010 | mutex_unlock(&dev_priv->sb_lock); |
e615efe4 ED |
4011 | } |
4012 | ||
275f01b2 DV |
4013 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4014 | enum pipe pch_transcoder) | |
4015 | { | |
4016 | struct drm_device *dev = crtc->base.dev; | |
4017 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4018 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4019 | |
4020 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4021 | I915_READ(HTOTAL(cpu_transcoder))); | |
4022 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4023 | I915_READ(HBLANK(cpu_transcoder))); | |
4024 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4025 | I915_READ(HSYNC(cpu_transcoder))); | |
4026 | ||
4027 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4028 | I915_READ(VTOTAL(cpu_transcoder))); | |
4029 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4030 | I915_READ(VBLANK(cpu_transcoder))); | |
4031 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4032 | I915_READ(VSYNC(cpu_transcoder))); | |
4033 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4034 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4035 | } | |
4036 | ||
003632d9 | 4037 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4038 | { |
4039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4040 | uint32_t temp; | |
4041 | ||
4042 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4043 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4044 | return; |
4045 | ||
4046 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4047 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4048 | ||
003632d9 ACO |
4049 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4050 | if (enable) | |
4051 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4052 | ||
4053 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4054 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4055 | POSTING_READ(SOUTH_CHICKEN1); | |
4056 | } | |
4057 | ||
4058 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4059 | { | |
4060 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4061 | |
4062 | switch (intel_crtc->pipe) { | |
4063 | case PIPE_A: | |
4064 | break; | |
4065 | case PIPE_B: | |
6e3c9717 | 4066 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4067 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4068 | else |
003632d9 | 4069 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4070 | |
4071 | break; | |
4072 | case PIPE_C: | |
003632d9 | 4073 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4074 | |
4075 | break; | |
4076 | default: | |
4077 | BUG(); | |
4078 | } | |
4079 | } | |
4080 | ||
f67a559d JB |
4081 | /* |
4082 | * Enable PCH resources required for PCH ports: | |
4083 | * - PCH PLLs | |
4084 | * - FDI training & RX/TX | |
4085 | * - update transcoder timings | |
4086 | * - DP transcoding bits | |
4087 | * - transcoder | |
4088 | */ | |
4089 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4090 | { |
4091 | struct drm_device *dev = crtc->dev; | |
4092 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4093 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4094 | int pipe = intel_crtc->pipe; | |
ee7b9f93 | 4095 | u32 reg, temp; |
2c07245f | 4096 | |
ab9412ba | 4097 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4098 | |
1fbc0d78 DV |
4099 | if (IS_IVYBRIDGE(dev)) |
4100 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4101 | ||
cd986abb DV |
4102 | /* Write the TU size bits before fdi link training, so that error |
4103 | * detection works. */ | |
4104 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4105 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4106 | ||
c98e9dcf | 4107 | /* For PCH output, training FDI link */ |
674cf967 | 4108 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4109 | |
3ad8a208 DV |
4110 | /* We need to program the right clock selection before writing the pixel |
4111 | * mutliplier into the DPLL. */ | |
303b81e0 | 4112 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4113 | u32 sel; |
4b645f14 | 4114 | |
c98e9dcf | 4115 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4116 | temp |= TRANS_DPLL_ENABLE(pipe); |
4117 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4118 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4119 | temp |= sel; |
4120 | else | |
4121 | temp &= ~sel; | |
c98e9dcf | 4122 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4123 | } |
5eddb70b | 4124 | |
3ad8a208 DV |
4125 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4126 | * transcoder, and we actually should do this to not upset any PCH | |
4127 | * transcoder that already use the clock when we share it. | |
4128 | * | |
4129 | * Note that enable_shared_dpll tries to do the right thing, but | |
4130 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4131 | * the right LVDS enable sequence. */ | |
85b3894f | 4132 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4133 | |
d9b6cb56 JB |
4134 | /* set transcoder timing, panel must allow it */ |
4135 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4136 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4137 | |
303b81e0 | 4138 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4139 | |
c98e9dcf | 4140 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4141 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
9c4edaee VS |
4142 | const struct drm_display_mode *adjusted_mode = |
4143 | &intel_crtc->config->base.adjusted_mode; | |
dfd07d72 | 4144 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
5eddb70b CW |
4145 | reg = TRANS_DP_CTL(pipe); |
4146 | temp = I915_READ(reg); | |
4147 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4148 | TRANS_DP_SYNC_MASK | |
4149 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4150 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4151 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf | 4152 | |
9c4edaee | 4153 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
5eddb70b | 4154 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
9c4edaee | 4155 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4156 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4157 | |
4158 | switch (intel_trans_dp_port_sel(crtc)) { | |
4159 | case PCH_DP_B: | |
5eddb70b | 4160 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf JB |
4161 | break; |
4162 | case PCH_DP_C: | |
5eddb70b | 4163 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf JB |
4164 | break; |
4165 | case PCH_DP_D: | |
5eddb70b | 4166 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4167 | break; |
4168 | default: | |
e95d41e1 | 4169 | BUG(); |
32f9d658 | 4170 | } |
2c07245f | 4171 | |
5eddb70b | 4172 | I915_WRITE(reg, temp); |
6be4a607 | 4173 | } |
b52eb4dc | 4174 | |
b8a4f404 | 4175 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4176 | } |
4177 | ||
1507e5bd PZ |
4178 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4179 | { | |
4180 | struct drm_device *dev = crtc->dev; | |
4181 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4182 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4183 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4184 | |
ab9412ba | 4185 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4186 | |
8c52b5e8 | 4187 | lpt_program_iclkip(crtc); |
1507e5bd | 4188 | |
0540e488 | 4189 | /* Set transcoder timing. */ |
275f01b2 | 4190 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4191 | |
937bb610 | 4192 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4193 | } |
4194 | ||
190f68c5 ACO |
4195 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4196 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4197 | { |
e2b78267 | 4198 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4199 | struct intel_shared_dpll *pll; |
de419ab6 | 4200 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4201 | enum intel_dpll_id i; |
ee7b9f93 | 4202 | |
de419ab6 ML |
4203 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4204 | ||
98b6bd99 DV |
4205 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4206 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4207 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4208 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4209 | |
46edb027 DV |
4210 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4211 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4212 | |
de419ab6 | 4213 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4214 | |
98b6bd99 DV |
4215 | goto found; |
4216 | } | |
4217 | ||
bcddf610 S |
4218 | if (IS_BROXTON(dev_priv->dev)) { |
4219 | /* PLL is attached to port in bxt */ | |
4220 | struct intel_encoder *encoder; | |
4221 | struct intel_digital_port *intel_dig_port; | |
4222 | ||
4223 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4224 | if (WARN_ON(!encoder)) | |
4225 | return NULL; | |
4226 | ||
4227 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4228 | /* 1:1 mapping between ports and PLLs */ | |
4229 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4230 | pll = &dev_priv->shared_dplls[i]; | |
4231 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4232 | crtc->base.base.id, pll->name); | |
de419ab6 | 4233 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4234 | |
4235 | goto found; | |
4236 | } | |
4237 | ||
e72f9fbf DV |
4238 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4239 | pll = &dev_priv->shared_dplls[i]; | |
ee7b9f93 JB |
4240 | |
4241 | /* Only want to check enabled timings first */ | |
de419ab6 | 4242 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4243 | continue; |
4244 | ||
190f68c5 | 4245 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4246 | &shared_dpll[i].hw_state, |
4247 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4248 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4249 | crtc->base.base.id, pll->name, |
de419ab6 | 4250 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4251 | pll->active); |
ee7b9f93 JB |
4252 | goto found; |
4253 | } | |
4254 | } | |
4255 | ||
4256 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4257 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4258 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4259 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4260 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4261 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4262 | goto found; |
4263 | } | |
4264 | } | |
4265 | ||
4266 | return NULL; | |
4267 | ||
4268 | found: | |
de419ab6 ML |
4269 | if (shared_dpll[i].crtc_mask == 0) |
4270 | shared_dpll[i].hw_state = | |
4271 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4272 | |
190f68c5 | 4273 | crtc_state->shared_dpll = i; |
46edb027 DV |
4274 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4275 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4276 | |
de419ab6 | 4277 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4278 | |
ee7b9f93 JB |
4279 | return pll; |
4280 | } | |
4281 | ||
de419ab6 | 4282 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4283 | { |
de419ab6 ML |
4284 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4285 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4286 | struct intel_shared_dpll *pll; |
4287 | enum intel_dpll_id i; | |
4288 | ||
de419ab6 ML |
4289 | if (!to_intel_atomic_state(state)->dpll_set) |
4290 | return; | |
8bd31e67 | 4291 | |
de419ab6 | 4292 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4293 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4294 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4295 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4296 | } |
4297 | } | |
4298 | ||
a1520318 | 4299 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4300 | { |
4301 | struct drm_i915_private *dev_priv = dev->dev_private; | |
23670b32 | 4302 | int dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4303 | u32 temp; |
4304 | ||
4305 | temp = I915_READ(dslreg); | |
4306 | udelay(500); | |
4307 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4308 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4309 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4310 | } |
4311 | } | |
4312 | ||
86adf9d7 ML |
4313 | static int |
4314 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4315 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4316 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4317 | { |
86adf9d7 ML |
4318 | struct intel_crtc_scaler_state *scaler_state = |
4319 | &crtc_state->scaler_state; | |
4320 | struct intel_crtc *intel_crtc = | |
4321 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4322 | int need_scaling; |
6156a456 CK |
4323 | |
4324 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4325 | (src_h != dst_w || src_w != dst_h): | |
4326 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4327 | |
4328 | /* | |
4329 | * if plane is being disabled or scaler is no more required or force detach | |
4330 | * - free scaler binded to this plane/crtc | |
4331 | * - in order to do this, update crtc->scaler_usage | |
4332 | * | |
4333 | * Here scaler state in crtc_state is set free so that | |
4334 | * scaler can be assigned to other user. Actual register | |
4335 | * update to free the scaler is done in plane/panel-fit programming. | |
4336 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4337 | */ | |
86adf9d7 | 4338 | if (force_detach || !need_scaling) { |
a1b2278e | 4339 | if (*scaler_id >= 0) { |
86adf9d7 | 4340 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4341 | scaler_state->scalers[*scaler_id].in_use = 0; |
4342 | ||
86adf9d7 ML |
4343 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4344 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4345 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4346 | scaler_state->scaler_users); |
4347 | *scaler_id = -1; | |
4348 | } | |
4349 | return 0; | |
4350 | } | |
4351 | ||
4352 | /* range checks */ | |
4353 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4354 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4355 | ||
4356 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4357 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4358 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4359 | "size is out of scaler range\n", |
86adf9d7 | 4360 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4361 | return -EINVAL; |
4362 | } | |
4363 | ||
86adf9d7 ML |
4364 | /* mark this plane as a scaler user in crtc_state */ |
4365 | scaler_state->scaler_users |= (1 << scaler_user); | |
4366 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4367 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4368 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4369 | scaler_state->scaler_users); | |
4370 | ||
4371 | return 0; | |
4372 | } | |
4373 | ||
4374 | /** | |
4375 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4376 | * | |
4377 | * @state: crtc's scaler state | |
86adf9d7 ML |
4378 | * |
4379 | * Return | |
4380 | * 0 - scaler_usage updated successfully | |
4381 | * error - requested scaling cannot be supported or other error condition | |
4382 | */ | |
e435d6e5 | 4383 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 ML |
4384 | { |
4385 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
7c5f93b0 | 4386 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
86adf9d7 ML |
4387 | |
4388 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4389 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4390 | ||
e435d6e5 | 4391 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
86adf9d7 ML |
4392 | &state->scaler_state.scaler_id, DRM_ROTATE_0, |
4393 | state->pipe_src_w, state->pipe_src_h, | |
aad941d5 | 4394 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
86adf9d7 ML |
4395 | } |
4396 | ||
4397 | /** | |
4398 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4399 | * | |
4400 | * @state: crtc's scaler state | |
86adf9d7 ML |
4401 | * @plane_state: atomic plane state to update |
4402 | * | |
4403 | * Return | |
4404 | * 0 - scaler_usage updated successfully | |
4405 | * error - requested scaling cannot be supported or other error condition | |
4406 | */ | |
da20eabd ML |
4407 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4408 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4409 | { |
4410 | ||
4411 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4412 | struct intel_plane *intel_plane = |
4413 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4414 | struct drm_framebuffer *fb = plane_state->base.fb; |
4415 | int ret; | |
4416 | ||
4417 | bool force_detach = !fb || !plane_state->visible; | |
4418 | ||
4419 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4420 | intel_plane->base.base.id, intel_crtc->pipe, | |
4421 | drm_plane_index(&intel_plane->base)); | |
4422 | ||
4423 | ret = skl_update_scaler(crtc_state, force_detach, | |
4424 | drm_plane_index(&intel_plane->base), | |
4425 | &plane_state->scaler_id, | |
4426 | plane_state->base.rotation, | |
4427 | drm_rect_width(&plane_state->src) >> 16, | |
4428 | drm_rect_height(&plane_state->src) >> 16, | |
4429 | drm_rect_width(&plane_state->dst), | |
4430 | drm_rect_height(&plane_state->dst)); | |
4431 | ||
4432 | if (ret || plane_state->scaler_id < 0) | |
4433 | return ret; | |
4434 | ||
a1b2278e | 4435 | /* check colorkey */ |
818ed961 | 4436 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
86adf9d7 | 4437 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
818ed961 | 4438 | intel_plane->base.base.id); |
a1b2278e CK |
4439 | return -EINVAL; |
4440 | } | |
4441 | ||
4442 | /* Check src format */ | |
86adf9d7 ML |
4443 | switch (fb->pixel_format) { |
4444 | case DRM_FORMAT_RGB565: | |
4445 | case DRM_FORMAT_XBGR8888: | |
4446 | case DRM_FORMAT_XRGB8888: | |
4447 | case DRM_FORMAT_ABGR8888: | |
4448 | case DRM_FORMAT_ARGB8888: | |
4449 | case DRM_FORMAT_XRGB2101010: | |
4450 | case DRM_FORMAT_XBGR2101010: | |
4451 | case DRM_FORMAT_YUYV: | |
4452 | case DRM_FORMAT_YVYU: | |
4453 | case DRM_FORMAT_UYVY: | |
4454 | case DRM_FORMAT_VYUY: | |
4455 | break; | |
4456 | default: | |
4457 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4458 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4459 | return -EINVAL; | |
a1b2278e CK |
4460 | } |
4461 | ||
a1b2278e CK |
4462 | return 0; |
4463 | } | |
4464 | ||
e435d6e5 ML |
4465 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4466 | { | |
4467 | int i; | |
4468 | ||
4469 | for (i = 0; i < crtc->num_scalers; i++) | |
4470 | skl_detach_scaler(crtc, i); | |
4471 | } | |
4472 | ||
4473 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4474 | { |
4475 | struct drm_device *dev = crtc->base.dev; | |
4476 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4477 | int pipe = crtc->pipe; | |
a1b2278e CK |
4478 | struct intel_crtc_scaler_state *scaler_state = |
4479 | &crtc->config->scaler_state; | |
4480 | ||
4481 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4482 | ||
6e3c9717 | 4483 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4484 | int id; |
4485 | ||
4486 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4487 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4488 | return; | |
4489 | } | |
4490 | ||
4491 | id = scaler_state->scaler_id; | |
4492 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4493 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4494 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4495 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4496 | ||
4497 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4498 | } |
4499 | } | |
4500 | ||
b074cec8 JB |
4501 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4502 | { | |
4503 | struct drm_device *dev = crtc->base.dev; | |
4504 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4505 | int pipe = crtc->pipe; | |
4506 | ||
6e3c9717 | 4507 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4508 | /* Force use of hard-coded filter coefficients |
4509 | * as some pre-programmed values are broken, | |
4510 | * e.g. x201. | |
4511 | */ | |
4512 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4513 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4514 | PF_PIPE_SEL_IVB(pipe)); | |
4515 | else | |
4516 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4517 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4518 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4519 | } |
4520 | } | |
4521 | ||
20bc8673 | 4522 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4523 | { |
cea165c3 VS |
4524 | struct drm_device *dev = crtc->base.dev; |
4525 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4526 | |
6e3c9717 | 4527 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4528 | return; |
4529 | ||
cea165c3 VS |
4530 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4531 | intel_wait_for_vblank(dev, crtc->pipe); | |
4532 | ||
d77e4531 | 4533 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4534 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4535 | mutex_lock(&dev_priv->rps.hw_lock); |
4536 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4537 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4538 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4539 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4540 | * mailbox." Moreover, the mailbox may return a bogus state, |
4541 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4542 | */ |
4543 | } else { | |
4544 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4545 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4546 | * is essentially intel_wait_for_vblank. If we don't have this | |
4547 | * and don't wait for vblanks until the end of crtc_enable, then | |
4548 | * the HW state readout code will complain that the expected | |
4549 | * IPS_CTL value is not the one we read. */ | |
4550 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4551 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4552 | } | |
d77e4531 PZ |
4553 | } |
4554 | ||
20bc8673 | 4555 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4556 | { |
4557 | struct drm_device *dev = crtc->base.dev; | |
4558 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4559 | ||
6e3c9717 | 4560 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4561 | return; |
4562 | ||
4563 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4564 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4565 | mutex_lock(&dev_priv->rps.hw_lock); |
4566 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4567 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4568 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4569 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4570 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4571 | } else { |
2a114cc1 | 4572 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4573 | POSTING_READ(IPS_CTL); |
4574 | } | |
d77e4531 PZ |
4575 | |
4576 | /* We need to wait for a vblank before we can disable the plane. */ | |
4577 | intel_wait_for_vblank(dev, crtc->pipe); | |
4578 | } | |
4579 | ||
4580 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4581 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4582 | { | |
4583 | struct drm_device *dev = crtc->dev; | |
4584 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4585 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4586 | enum pipe pipe = intel_crtc->pipe; | |
d77e4531 PZ |
4587 | int i; |
4588 | bool reenable_ips = false; | |
4589 | ||
4590 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4591 | if (!crtc->state->active) |
d77e4531 PZ |
4592 | return; |
4593 | ||
50360403 | 4594 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
409ee761 | 4595 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
d77e4531 PZ |
4596 | assert_dsi_pll_enabled(dev_priv); |
4597 | else | |
4598 | assert_pll_enabled(dev_priv, pipe); | |
4599 | } | |
4600 | ||
d77e4531 PZ |
4601 | /* Workaround : Do not read or write the pipe palette/gamma data while |
4602 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4603 | */ | |
6e3c9717 | 4604 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4605 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4606 | GAMMA_MODE_MODE_SPLIT)) { | |
4607 | hsw_disable_ips(intel_crtc); | |
4608 | reenable_ips = true; | |
4609 | } | |
4610 | ||
4611 | for (i = 0; i < 256; i++) { | |
f65a9c5b VS |
4612 | u32 palreg; |
4613 | ||
4614 | if (HAS_GMCH_DISPLAY(dev)) | |
4615 | palreg = PALETTE(pipe, i); | |
4616 | else | |
4617 | palreg = LGC_PALETTE(pipe, i); | |
4618 | ||
4619 | I915_WRITE(palreg, | |
d77e4531 PZ |
4620 | (intel_crtc->lut_r[i] << 16) | |
4621 | (intel_crtc->lut_g[i] << 8) | | |
4622 | intel_crtc->lut_b[i]); | |
4623 | } | |
4624 | ||
4625 | if (reenable_ips) | |
4626 | hsw_enable_ips(intel_crtc); | |
4627 | } | |
4628 | ||
7cac945f | 4629 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4630 | { |
7cac945f | 4631 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4632 | struct drm_device *dev = intel_crtc->base.dev; |
4633 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4634 | ||
4635 | mutex_lock(&dev->struct_mutex); | |
4636 | dev_priv->mm.interruptible = false; | |
4637 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4638 | dev_priv->mm.interruptible = true; | |
4639 | mutex_unlock(&dev->struct_mutex); | |
4640 | } | |
4641 | ||
4642 | /* Let userspace switch the overlay on again. In most cases userspace | |
4643 | * has to recompute where to put it anyway. | |
4644 | */ | |
4645 | } | |
4646 | ||
87d4300a ML |
4647 | /** |
4648 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4649 | * @crtc: the CRTC whose primary plane was just enabled | |
4650 | * | |
4651 | * Performs potentially sleeping operations that must be done after the primary | |
4652 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4653 | * called due to an explicit primary plane update, or due to an implicit | |
4654 | * re-enable that is caused when a sprite plane is updated to no longer | |
4655 | * completely hide the primary plane. | |
4656 | */ | |
4657 | static void | |
4658 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4659 | { |
4660 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4661 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4662 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4663 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4664 | |
87d4300a ML |
4665 | /* |
4666 | * BDW signals flip done immediately if the plane | |
4667 | * is disabled, even if the plane enable is already | |
4668 | * armed to occur at the next vblank :( | |
4669 | */ | |
4670 | if (IS_BROADWELL(dev)) | |
4671 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4672 | |
87d4300a ML |
4673 | /* |
4674 | * FIXME IPS should be fine as long as one plane is | |
4675 | * enabled, but in practice it seems to have problems | |
4676 | * when going from primary only to sprite only and vice | |
4677 | * versa. | |
4678 | */ | |
a5c4d7bc VS |
4679 | hsw_enable_ips(intel_crtc); |
4680 | ||
f99d7069 | 4681 | /* |
87d4300a ML |
4682 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4683 | * So don't enable underrun reporting before at least some planes | |
4684 | * are enabled. | |
4685 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4686 | * but leave the pipe running. | |
f99d7069 | 4687 | */ |
87d4300a ML |
4688 | if (IS_GEN2(dev)) |
4689 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4690 | ||
aca7b684 VS |
4691 | /* Underruns don't always raise interrupts, so check manually. */ |
4692 | intel_check_cpu_fifo_underruns(dev_priv); | |
4693 | intel_check_pch_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4694 | } |
4695 | ||
87d4300a ML |
4696 | /** |
4697 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4698 | * @crtc: the CRTC whose primary plane is to be disabled | |
4699 | * | |
4700 | * Performs potentially sleeping operations that must be done before the | |
4701 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4702 | * be called due to an explicit primary plane update, or due to an implicit | |
4703 | * disable that is caused when a sprite plane completely hides the primary | |
4704 | * plane. | |
4705 | */ | |
4706 | static void | |
4707 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4708 | { |
4709 | struct drm_device *dev = crtc->dev; | |
4710 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4711 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4712 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4713 | |
87d4300a ML |
4714 | /* |
4715 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4716 | * So diasble underrun reporting before all the planes get disabled. | |
4717 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4718 | * but leave the pipe running. | |
4719 | */ | |
4720 | if (IS_GEN2(dev)) | |
4721 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4722 | |
87d4300a ML |
4723 | /* |
4724 | * Vblank time updates from the shadow to live plane control register | |
4725 | * are blocked if the memory self-refresh mode is active at that | |
4726 | * moment. So to make sure the plane gets truly disabled, disable | |
4727 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4728 | * will be checked/applied by the HW only at the next frame start | |
4729 | * event which is after the vblank start event, so we need to have a | |
4730 | * wait-for-vblank between disabling the plane and the pipe. | |
4731 | */ | |
262cd2e1 | 4732 | if (HAS_GMCH_DISPLAY(dev)) { |
87d4300a | 4733 | intel_set_memory_cxsr(dev_priv, false); |
262cd2e1 VS |
4734 | dev_priv->wm.vlv.cxsr = false; |
4735 | intel_wait_for_vblank(dev, pipe); | |
4736 | } | |
87d4300a | 4737 | |
87d4300a ML |
4738 | /* |
4739 | * FIXME IPS should be fine as long as one plane is | |
4740 | * enabled, but in practice it seems to have problems | |
4741 | * when going from primary only to sprite only and vice | |
4742 | * versa. | |
4743 | */ | |
a5c4d7bc | 4744 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4745 | } |
4746 | ||
ac21b225 ML |
4747 | static void intel_post_plane_update(struct intel_crtc *crtc) |
4748 | { | |
4749 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4750 | struct drm_device *dev = crtc->base.dev; | |
7733b49b | 4751 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 ML |
4752 | |
4753 | if (atomic->wait_vblank) | |
4754 | intel_wait_for_vblank(dev, crtc->pipe); | |
4755 | ||
4756 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4757 | ||
852eb00d VS |
4758 | if (atomic->disable_cxsr) |
4759 | crtc->wm.cxsr_allowed = true; | |
4760 | ||
f015c551 VS |
4761 | if (crtc->atomic.update_wm_post) |
4762 | intel_update_watermarks(&crtc->base); | |
4763 | ||
c80ac854 | 4764 | if (atomic->update_fbc) |
7733b49b | 4765 | intel_fbc_update(dev_priv); |
ac21b225 ML |
4766 | |
4767 | if (atomic->post_enable_primary) | |
4768 | intel_post_enable_primary(&crtc->base); | |
4769 | ||
ac21b225 ML |
4770 | memset(atomic, 0, sizeof(*atomic)); |
4771 | } | |
4772 | ||
4773 | static void intel_pre_plane_update(struct intel_crtc *crtc) | |
4774 | { | |
4775 | struct drm_device *dev = crtc->base.dev; | |
eddfcbcd | 4776 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 | 4777 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
ac21b225 | 4778 | |
c80ac854 | 4779 | if (atomic->disable_fbc) |
25ad93fd | 4780 | intel_fbc_disable_crtc(crtc); |
ac21b225 | 4781 | |
066cf55b RV |
4782 | if (crtc->atomic.disable_ips) |
4783 | hsw_disable_ips(crtc); | |
4784 | ||
ac21b225 ML |
4785 | if (atomic->pre_disable_primary) |
4786 | intel_pre_disable_primary(&crtc->base); | |
852eb00d VS |
4787 | |
4788 | if (atomic->disable_cxsr) { | |
4789 | crtc->wm.cxsr_allowed = false; | |
4790 | intel_set_memory_cxsr(dev_priv, false); | |
4791 | } | |
ac21b225 ML |
4792 | } |
4793 | ||
d032ffa0 | 4794 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4795 | { |
4796 | struct drm_device *dev = crtc->dev; | |
4797 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4798 | struct drm_plane *p; |
87d4300a ML |
4799 | int pipe = intel_crtc->pipe; |
4800 | ||
7cac945f | 4801 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4802 | |
d032ffa0 ML |
4803 | drm_for_each_plane_mask(p, dev, plane_mask) |
4804 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4805 | |
f99d7069 DV |
4806 | /* |
4807 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4808 | * to compute the mask of flip planes precisely. For the time being | |
4809 | * consider this a flip to a NULL plane. | |
4810 | */ | |
4811 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4812 | } |
4813 | ||
f67a559d JB |
4814 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4815 | { | |
4816 | struct drm_device *dev = crtc->dev; | |
4817 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4818 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4819 | struct intel_encoder *encoder; |
f67a559d | 4820 | int pipe = intel_crtc->pipe; |
f67a559d | 4821 | |
53d9f4e9 | 4822 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4823 | return; |
4824 | ||
81b088ca VS |
4825 | if (intel_crtc->config->has_pch_encoder) |
4826 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
4827 | ||
6e3c9717 | 4828 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4829 | intel_prepare_shared_dpll(intel_crtc); |
4830 | ||
6e3c9717 | 4831 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4832 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4833 | |
4834 | intel_set_pipe_timings(intel_crtc); | |
4835 | ||
6e3c9717 | 4836 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4837 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4838 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4839 | } |
4840 | ||
4841 | ironlake_set_pipeconf(crtc); | |
4842 | ||
f67a559d | 4843 | intel_crtc->active = true; |
8664281b | 4844 | |
a72e4c9f | 4845 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
8664281b | 4846 | |
f6736a1a | 4847 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4848 | if (encoder->pre_enable) |
4849 | encoder->pre_enable(encoder); | |
f67a559d | 4850 | |
6e3c9717 | 4851 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4852 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4853 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4854 | * enabling. */ | |
88cefb6c | 4855 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4856 | } else { |
4857 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4858 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4859 | } | |
f67a559d | 4860 | |
b074cec8 | 4861 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4862 | |
9c54c0dd JB |
4863 | /* |
4864 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4865 | * clocks enabled | |
4866 | */ | |
4867 | intel_crtc_load_lut(crtc); | |
4868 | ||
f37fcc2a | 4869 | intel_update_watermarks(crtc); |
e1fdc473 | 4870 | intel_enable_pipe(intel_crtc); |
f67a559d | 4871 | |
6e3c9717 | 4872 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4873 | ironlake_pch_enable(crtc); |
c98e9dcf | 4874 | |
f9b61ff6 DV |
4875 | assert_vblank_disabled(crtc); |
4876 | drm_crtc_vblank_on(crtc); | |
4877 | ||
fa5c73b1 DV |
4878 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4879 | encoder->enable(encoder); | |
61b77ddd DV |
4880 | |
4881 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4882 | cpt_verify_modeset(dev, intel_crtc->pipe); |
37ca8d4c VS |
4883 | |
4884 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
4885 | if (intel_crtc->config->has_pch_encoder) | |
4886 | intel_wait_for_vblank(dev, pipe); | |
4887 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
6be4a607 JB |
4888 | } |
4889 | ||
42db64ef PZ |
4890 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4891 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4892 | { | |
f5adf94e | 4893 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4894 | } |
4895 | ||
4f771f10 PZ |
4896 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4897 | { | |
4898 | struct drm_device *dev = crtc->dev; | |
4899 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4900 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4901 | struct intel_encoder *encoder; | |
99d736a2 ML |
4902 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4903 | struct intel_crtc_state *pipe_config = | |
4904 | to_intel_crtc_state(crtc->state); | |
7d4aefd0 | 4905 | bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
4f771f10 | 4906 | |
53d9f4e9 | 4907 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4908 | return; |
4909 | ||
81b088ca VS |
4910 | if (intel_crtc->config->has_pch_encoder) |
4911 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
4912 | false); | |
4913 | ||
df8ad70c DV |
4914 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4915 | intel_enable_shared_dpll(intel_crtc); | |
4916 | ||
6e3c9717 | 4917 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4918 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
4919 | |
4920 | intel_set_pipe_timings(intel_crtc); | |
4921 | ||
6e3c9717 ACO |
4922 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
4923 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
4924 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
4925 | } |
4926 | ||
6e3c9717 | 4927 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4928 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4929 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4930 | } |
4931 | ||
4932 | haswell_set_pipeconf(crtc); | |
4933 | ||
4934 | intel_set_pipe_csc(crtc); | |
4935 | ||
4f771f10 | 4936 | intel_crtc->active = true; |
8664281b | 4937 | |
a72e4c9f | 4938 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
7d4aefd0 SS |
4939 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4940 | if (encoder->pre_pll_enable) | |
4941 | encoder->pre_pll_enable(encoder); | |
4f771f10 PZ |
4942 | if (encoder->pre_enable) |
4943 | encoder->pre_enable(encoder); | |
7d4aefd0 | 4944 | } |
4f771f10 | 4945 | |
d2d65408 | 4946 | if (intel_crtc->config->has_pch_encoder) |
4fe9467d | 4947 | dev_priv->display.fdi_link_train(crtc); |
4fe9467d | 4948 | |
7d4aefd0 SS |
4949 | if (!is_dsi) |
4950 | intel_ddi_enable_pipe_clock(intel_crtc); | |
4f771f10 | 4951 | |
1c132b44 | 4952 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 4953 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 4954 | else |
1c132b44 | 4955 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
4956 | |
4957 | /* | |
4958 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4959 | * clocks enabled | |
4960 | */ | |
4961 | intel_crtc_load_lut(crtc); | |
4962 | ||
1f544388 | 4963 | intel_ddi_set_pipe_settings(crtc); |
7d4aefd0 SS |
4964 | if (!is_dsi) |
4965 | intel_ddi_enable_transcoder_func(crtc); | |
4f771f10 | 4966 | |
f37fcc2a | 4967 | intel_update_watermarks(crtc); |
e1fdc473 | 4968 | intel_enable_pipe(intel_crtc); |
42db64ef | 4969 | |
6e3c9717 | 4970 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 4971 | lpt_pch_enable(crtc); |
4f771f10 | 4972 | |
7d4aefd0 | 4973 | if (intel_crtc->config->dp_encoder_is_mst && !is_dsi) |
0e32b39c DA |
4974 | intel_ddi_set_vc_payload_alloc(crtc, true); |
4975 | ||
f9b61ff6 DV |
4976 | assert_vblank_disabled(crtc); |
4977 | drm_crtc_vblank_on(crtc); | |
4978 | ||
8807e55b | 4979 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 4980 | encoder->enable(encoder); |
8807e55b JN |
4981 | intel_opregion_notify_encoder(encoder, true); |
4982 | } | |
4f771f10 | 4983 | |
d2d65408 VS |
4984 | if (intel_crtc->config->has_pch_encoder) |
4985 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
4986 | true); | |
4987 | ||
e4916946 PZ |
4988 | /* If we change the relative order between pipe/planes enabling, we need |
4989 | * to change the workaround. */ | |
99d736a2 ML |
4990 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
4991 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
4992 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4993 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4994 | } | |
4f771f10 PZ |
4995 | } |
4996 | ||
bfd16b2a | 4997 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
4998 | { |
4999 | struct drm_device *dev = crtc->base.dev; | |
5000 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5001 | int pipe = crtc->pipe; | |
5002 | ||
5003 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5004 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 5005 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5006 | I915_WRITE(PF_CTL(pipe), 0); |
5007 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5008 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5009 | } | |
5010 | } | |
5011 | ||
6be4a607 JB |
5012 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
5013 | { | |
5014 | struct drm_device *dev = crtc->dev; | |
5015 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5016 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5017 | struct intel_encoder *encoder; |
6be4a607 | 5018 | int pipe = intel_crtc->pipe; |
5eddb70b | 5019 | u32 reg, temp; |
b52eb4dc | 5020 | |
37ca8d4c VS |
5021 | if (intel_crtc->config->has_pch_encoder) |
5022 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
5023 | ||
ea9d758d DV |
5024 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5025 | encoder->disable(encoder); | |
5026 | ||
f9b61ff6 DV |
5027 | drm_crtc_vblank_off(crtc); |
5028 | assert_vblank_disabled(crtc); | |
5029 | ||
575f7ab7 | 5030 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5031 | |
bfd16b2a | 5032 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 5033 | |
5a74f70a VS |
5034 | if (intel_crtc->config->has_pch_encoder) |
5035 | ironlake_fdi_disable(crtc); | |
5036 | ||
bf49ec8c DV |
5037 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5038 | if (encoder->post_disable) | |
5039 | encoder->post_disable(encoder); | |
2c07245f | 5040 | |
6e3c9717 | 5041 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5042 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5043 | |
d925c59a DV |
5044 | if (HAS_PCH_CPT(dev)) { |
5045 | /* disable TRANS_DP_CTL */ | |
5046 | reg = TRANS_DP_CTL(pipe); | |
5047 | temp = I915_READ(reg); | |
5048 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5049 | TRANS_DP_PORT_SEL_MASK); | |
5050 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5051 | I915_WRITE(reg, temp); | |
5052 | ||
5053 | /* disable DPLL_SEL */ | |
5054 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5055 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5056 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5057 | } |
e3421a18 | 5058 | |
d925c59a DV |
5059 | ironlake_fdi_pll_disable(intel_crtc); |
5060 | } | |
81b088ca VS |
5061 | |
5062 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
6be4a607 | 5063 | } |
1b3c7a47 | 5064 | |
4f771f10 | 5065 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5066 | { |
4f771f10 PZ |
5067 | struct drm_device *dev = crtc->dev; |
5068 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5069 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5070 | struct intel_encoder *encoder; |
6e3c9717 | 5071 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7d4aefd0 | 5072 | bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
ee7b9f93 | 5073 | |
d2d65408 VS |
5074 | if (intel_crtc->config->has_pch_encoder) |
5075 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5076 | false); | |
5077 | ||
8807e55b JN |
5078 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5079 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5080 | encoder->disable(encoder); |
8807e55b | 5081 | } |
4f771f10 | 5082 | |
f9b61ff6 DV |
5083 | drm_crtc_vblank_off(crtc); |
5084 | assert_vblank_disabled(crtc); | |
5085 | ||
575f7ab7 | 5086 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5087 | |
6e3c9717 | 5088 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5089 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5090 | ||
7d4aefd0 SS |
5091 | if (!is_dsi) |
5092 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); | |
4f771f10 | 5093 | |
1c132b44 | 5094 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5095 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5096 | else |
bfd16b2a | 5097 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5098 | |
7d4aefd0 SS |
5099 | if (!is_dsi) |
5100 | intel_ddi_disable_pipe_clock(intel_crtc); | |
4f771f10 | 5101 | |
6e3c9717 | 5102 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5103 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5104 | intel_ddi_fdi_disable(crtc); |
83616634 | 5105 | } |
4f771f10 | 5106 | |
97b040aa ID |
5107 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5108 | if (encoder->post_disable) | |
5109 | encoder->post_disable(encoder); | |
81b088ca VS |
5110 | |
5111 | if (intel_crtc->config->has_pch_encoder) | |
5112 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5113 | true); | |
4f771f10 PZ |
5114 | } |
5115 | ||
2dd24552 JB |
5116 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5117 | { | |
5118 | struct drm_device *dev = crtc->base.dev; | |
5119 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5120 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5121 | |
681a8504 | 5122 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5123 | return; |
5124 | ||
2dd24552 | 5125 | /* |
c0b03411 DV |
5126 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5127 | * according to register description and PRM. | |
2dd24552 | 5128 | */ |
c0b03411 DV |
5129 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5130 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5131 | |
b074cec8 JB |
5132 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5133 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5134 | |
5135 | /* Border color in case we don't scale up to the full screen. Black by | |
5136 | * default, change to something else for debugging. */ | |
5137 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5138 | } |
5139 | ||
d05410f9 DA |
5140 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5141 | { | |
5142 | switch (port) { | |
5143 | case PORT_A: | |
5144 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; | |
5145 | case PORT_B: | |
5146 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; | |
5147 | case PORT_C: | |
5148 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; | |
5149 | case PORT_D: | |
5150 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; | |
d8e19f99 XZ |
5151 | case PORT_E: |
5152 | return POWER_DOMAIN_PORT_DDI_E_2_LANES; | |
d05410f9 DA |
5153 | default: |
5154 | WARN_ON_ONCE(1); | |
5155 | return POWER_DOMAIN_PORT_OTHER; | |
5156 | } | |
5157 | } | |
5158 | ||
77d22dca ID |
5159 | #define for_each_power_domain(domain, mask) \ |
5160 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5161 | if ((1 << (domain)) & (mask)) | |
5162 | ||
319be8ae ID |
5163 | enum intel_display_power_domain |
5164 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5165 | { | |
5166 | struct drm_device *dev = intel_encoder->base.dev; | |
5167 | struct intel_digital_port *intel_dig_port; | |
5168 | ||
5169 | switch (intel_encoder->type) { | |
5170 | case INTEL_OUTPUT_UNKNOWN: | |
5171 | /* Only DDI platforms should ever use this output type */ | |
5172 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5173 | case INTEL_OUTPUT_DISPLAYPORT: | |
5174 | case INTEL_OUTPUT_HDMI: | |
5175 | case INTEL_OUTPUT_EDP: | |
5176 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5177 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5178 | case INTEL_OUTPUT_DP_MST: |
5179 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5180 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5181 | case INTEL_OUTPUT_ANALOG: |
5182 | return POWER_DOMAIN_PORT_CRT; | |
5183 | case INTEL_OUTPUT_DSI: | |
5184 | return POWER_DOMAIN_PORT_DSI; | |
5185 | default: | |
5186 | return POWER_DOMAIN_PORT_OTHER; | |
5187 | } | |
5188 | } | |
5189 | ||
5190 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) | |
77d22dca | 5191 | { |
319be8ae ID |
5192 | struct drm_device *dev = crtc->dev; |
5193 | struct intel_encoder *intel_encoder; | |
5194 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5195 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca | 5196 | unsigned long mask; |
1a70a728 | 5197 | enum transcoder transcoder = intel_crtc->config->cpu_transcoder; |
77d22dca | 5198 | |
292b990e ML |
5199 | if (!crtc->state->active) |
5200 | return 0; | |
5201 | ||
77d22dca ID |
5202 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5203 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5204 | if (intel_crtc->config->pch_pfit.enabled || |
5205 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5206 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5207 | ||
319be8ae ID |
5208 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5209 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5210 | ||
77d22dca ID |
5211 | return mask; |
5212 | } | |
5213 | ||
292b990e | 5214 | static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5215 | { |
292b990e ML |
5216 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5217 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5218 | enum intel_display_power_domain domain; | |
5219 | unsigned long domains, new_domains, old_domains; | |
77d22dca | 5220 | |
292b990e ML |
5221 | old_domains = intel_crtc->enabled_power_domains; |
5222 | intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc); | |
77d22dca | 5223 | |
292b990e ML |
5224 | domains = new_domains & ~old_domains; |
5225 | ||
5226 | for_each_power_domain(domain, domains) | |
5227 | intel_display_power_get(dev_priv, domain); | |
5228 | ||
5229 | return old_domains & ~new_domains; | |
5230 | } | |
5231 | ||
5232 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5233 | unsigned long domains) | |
5234 | { | |
5235 | enum intel_display_power_domain domain; | |
5236 | ||
5237 | for_each_power_domain(domain, domains) | |
5238 | intel_display_power_put(dev_priv, domain); | |
5239 | } | |
77d22dca | 5240 | |
292b990e ML |
5241 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
5242 | { | |
5243 | struct drm_device *dev = state->dev; | |
5244 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5245 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
5246 | struct drm_crtc_state *crtc_state; | |
5247 | struct drm_crtc *crtc; | |
5248 | int i; | |
77d22dca | 5249 | |
292b990e ML |
5250 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5251 | if (needs_modeset(crtc->state)) | |
5252 | put_domains[to_intel_crtc(crtc)->pipe] = | |
5253 | modeset_get_crtc_power_domains(crtc); | |
77d22dca ID |
5254 | } |
5255 | ||
27c329ed ML |
5256 | if (dev_priv->display.modeset_commit_cdclk) { |
5257 | unsigned int cdclk = to_intel_atomic_state(state)->cdclk; | |
5258 | ||
5259 | if (cdclk != dev_priv->cdclk_freq && | |
5260 | !WARN_ON(!state->allow_modeset)) | |
5261 | dev_priv->display.modeset_commit_cdclk(state); | |
5262 | } | |
50f6e502 | 5263 | |
292b990e ML |
5264 | for (i = 0; i < I915_MAX_PIPES; i++) |
5265 | if (put_domains[i]) | |
5266 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
77d22dca ID |
5267 | } |
5268 | ||
adafdc6f MK |
5269 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5270 | { | |
5271 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5272 | ||
5273 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5274 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5275 | return max_cdclk_freq; | |
5276 | else if (IS_CHERRYVIEW(dev_priv)) | |
5277 | return max_cdclk_freq*95/100; | |
5278 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5279 | return 2*max_cdclk_freq*90/100; | |
5280 | else | |
5281 | return max_cdclk_freq*90/100; | |
5282 | } | |
5283 | ||
560a7ae4 DL |
5284 | static void intel_update_max_cdclk(struct drm_device *dev) |
5285 | { | |
5286 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5287 | ||
ef11bdb3 | 5288 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
560a7ae4 DL |
5289 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
5290 | ||
5291 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5292 | dev_priv->max_cdclk_freq = 675000; | |
5293 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5294 | dev_priv->max_cdclk_freq = 540000; | |
5295 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5296 | dev_priv->max_cdclk_freq = 450000; | |
5297 | else | |
5298 | dev_priv->max_cdclk_freq = 337500; | |
5299 | } else if (IS_BROADWELL(dev)) { | |
5300 | /* | |
5301 | * FIXME with extra cooling we can allow | |
5302 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5303 | * How can we know if extra cooling is | |
5304 | * available? PCI ID, VTB, something else? | |
5305 | */ | |
5306 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5307 | dev_priv->max_cdclk_freq = 450000; | |
5308 | else if (IS_BDW_ULX(dev)) | |
5309 | dev_priv->max_cdclk_freq = 450000; | |
5310 | else if (IS_BDW_ULT(dev)) | |
5311 | dev_priv->max_cdclk_freq = 540000; | |
5312 | else | |
5313 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5314 | } else if (IS_CHERRYVIEW(dev)) { |
5315 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5316 | } else if (IS_VALLEYVIEW(dev)) { |
5317 | dev_priv->max_cdclk_freq = 400000; | |
5318 | } else { | |
5319 | /* otherwise assume cdclk is fixed */ | |
5320 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5321 | } | |
5322 | ||
adafdc6f MK |
5323 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5324 | ||
560a7ae4 DL |
5325 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5326 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5327 | |
5328 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5329 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5330 | } |
5331 | ||
5332 | static void intel_update_cdclk(struct drm_device *dev) | |
5333 | { | |
5334 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5335 | ||
5336 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5337 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5338 | dev_priv->cdclk_freq); | |
5339 | ||
5340 | /* | |
5341 | * Program the gmbus_freq based on the cdclk frequency. | |
5342 | * BSpec erroneously claims we should aim for 4MHz, but | |
5343 | * in fact 1MHz is the correct frequency. | |
5344 | */ | |
5345 | if (IS_VALLEYVIEW(dev)) { | |
5346 | /* | |
5347 | * Program the gmbus_freq based on the cdclk frequency. | |
5348 | * BSpec erroneously claims we should aim for 4MHz, but | |
5349 | * in fact 1MHz is the correct frequency. | |
5350 | */ | |
5351 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5352 | } | |
5353 | ||
5354 | if (dev_priv->max_cdclk_freq == 0) | |
5355 | intel_update_max_cdclk(dev); | |
5356 | } | |
5357 | ||
70d0c574 | 5358 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5359 | { |
5360 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5361 | uint32_t divider; | |
5362 | uint32_t ratio; | |
5363 | uint32_t current_freq; | |
5364 | int ret; | |
5365 | ||
5366 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5367 | switch (frequency) { | |
5368 | case 144000: | |
5369 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5370 | ratio = BXT_DE_PLL_RATIO(60); | |
5371 | break; | |
5372 | case 288000: | |
5373 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5374 | ratio = BXT_DE_PLL_RATIO(60); | |
5375 | break; | |
5376 | case 384000: | |
5377 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5378 | ratio = BXT_DE_PLL_RATIO(60); | |
5379 | break; | |
5380 | case 576000: | |
5381 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5382 | ratio = BXT_DE_PLL_RATIO(60); | |
5383 | break; | |
5384 | case 624000: | |
5385 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5386 | ratio = BXT_DE_PLL_RATIO(65); | |
5387 | break; | |
5388 | case 19200: | |
5389 | /* | |
5390 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5391 | * to suppress GCC warning. | |
5392 | */ | |
5393 | ratio = 0; | |
5394 | divider = 0; | |
5395 | break; | |
5396 | default: | |
5397 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5398 | ||
5399 | return; | |
5400 | } | |
5401 | ||
5402 | mutex_lock(&dev_priv->rps.hw_lock); | |
5403 | /* Inform power controller of upcoming frequency change */ | |
5404 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5405 | 0x80000000); | |
5406 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5407 | ||
5408 | if (ret) { | |
5409 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5410 | ret, frequency); | |
5411 | return; | |
5412 | } | |
5413 | ||
5414 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5415 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5416 | current_freq = current_freq * 500 + 1000; | |
5417 | ||
5418 | /* | |
5419 | * DE PLL has to be disabled when | |
5420 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5421 | * - before setting to 624MHz (PLL needs toggling) | |
5422 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5423 | */ | |
5424 | if (frequency == 19200 || frequency == 624000 || | |
5425 | current_freq == 624000) { | |
5426 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5427 | /* Timeout 200us */ | |
5428 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5429 | 1)) | |
5430 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5431 | } | |
5432 | ||
5433 | if (frequency != 19200) { | |
5434 | uint32_t val; | |
5435 | ||
5436 | val = I915_READ(BXT_DE_PLL_CTL); | |
5437 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5438 | val |= ratio; | |
5439 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5440 | ||
5441 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5442 | /* Timeout 200us */ | |
5443 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5444 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5445 | ||
5446 | val = I915_READ(CDCLK_CTL); | |
5447 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5448 | val |= divider; | |
5449 | /* | |
5450 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5451 | * enable otherwise. | |
5452 | */ | |
5453 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5454 | if (frequency >= 500000) | |
5455 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5456 | ||
5457 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5458 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5459 | val |= (frequency - 1000) / 500; | |
5460 | I915_WRITE(CDCLK_CTL, val); | |
5461 | } | |
5462 | ||
5463 | mutex_lock(&dev_priv->rps.hw_lock); | |
5464 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5465 | DIV_ROUND_UP(frequency, 25000)); | |
5466 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5467 | ||
5468 | if (ret) { | |
5469 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5470 | ret, frequency); | |
5471 | return; | |
5472 | } | |
5473 | ||
a47871bd | 5474 | intel_update_cdclk(dev); |
f8437dd1 VK |
5475 | } |
5476 | ||
5477 | void broxton_init_cdclk(struct drm_device *dev) | |
5478 | { | |
5479 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5480 | uint32_t val; | |
5481 | ||
5482 | /* | |
5483 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5484 | * or else the reset will hang because there is no PCH to respond. | |
5485 | * Move the handshake programming to initialization sequence. | |
5486 | * Previously was left up to BIOS. | |
5487 | */ | |
5488 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5489 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5490 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5491 | ||
5492 | /* Enable PG1 for cdclk */ | |
5493 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5494 | ||
5495 | /* check if cd clock is enabled */ | |
5496 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5497 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5498 | return; | |
5499 | } | |
5500 | ||
5501 | /* | |
5502 | * FIXME: | |
5503 | * - The initial CDCLK needs to be read from VBT. | |
5504 | * Need to make this change after VBT has changes for BXT. | |
5505 | * - check if setting the max (or any) cdclk freq is really necessary | |
5506 | * here, it belongs to modeset time | |
5507 | */ | |
5508 | broxton_set_cdclk(dev, 624000); | |
5509 | ||
5510 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5511 | POSTING_READ(DBUF_CTL); |
5512 | ||
f8437dd1 VK |
5513 | udelay(10); |
5514 | ||
5515 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5516 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5517 | } | |
5518 | ||
5519 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5520 | { | |
5521 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5522 | ||
5523 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5524 | POSTING_READ(DBUF_CTL); |
5525 | ||
f8437dd1 VK |
5526 | udelay(10); |
5527 | ||
5528 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5529 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5530 | ||
5531 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5532 | broxton_set_cdclk(dev, 19200); | |
5533 | ||
5534 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5535 | } | |
5536 | ||
5d96d8af DL |
5537 | static const struct skl_cdclk_entry { |
5538 | unsigned int freq; | |
5539 | unsigned int vco; | |
5540 | } skl_cdclk_frequencies[] = { | |
5541 | { .freq = 308570, .vco = 8640 }, | |
5542 | { .freq = 337500, .vco = 8100 }, | |
5543 | { .freq = 432000, .vco = 8640 }, | |
5544 | { .freq = 450000, .vco = 8100 }, | |
5545 | { .freq = 540000, .vco = 8100 }, | |
5546 | { .freq = 617140, .vco = 8640 }, | |
5547 | { .freq = 675000, .vco = 8100 }, | |
5548 | }; | |
5549 | ||
5550 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5551 | { | |
5552 | return (freq - 1000) / 500; | |
5553 | } | |
5554 | ||
5555 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5556 | { | |
5557 | unsigned int i; | |
5558 | ||
5559 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5560 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5561 | ||
5562 | if (e->freq == freq) | |
5563 | return e->vco; | |
5564 | } | |
5565 | ||
5566 | return 8100; | |
5567 | } | |
5568 | ||
5569 | static void | |
5570 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5571 | { | |
5572 | unsigned int min_freq; | |
5573 | u32 val; | |
5574 | ||
5575 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5576 | val = I915_READ(CDCLK_CTL); | |
5577 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5578 | val |= CDCLK_FREQ_337_308; | |
5579 | ||
5580 | if (required_vco == 8640) | |
5581 | min_freq = 308570; | |
5582 | else | |
5583 | min_freq = 337500; | |
5584 | ||
5585 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5586 | ||
5587 | I915_WRITE(CDCLK_CTL, val); | |
5588 | POSTING_READ(CDCLK_CTL); | |
5589 | ||
5590 | /* | |
5591 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5592 | * taking into account the VCO required to operate the eDP panel at the | |
5593 | * desired frequency. The usual DP link rates operate with a VCO of | |
5594 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5595 | * The modeset code is responsible for the selection of the exact link | |
5596 | * rate later on, with the constraint of choosing a frequency that | |
5597 | * works with required_vco. | |
5598 | */ | |
5599 | val = I915_READ(DPLL_CTRL1); | |
5600 | ||
5601 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5602 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5603 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5604 | if (required_vco == 8640) | |
5605 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5606 | SKL_DPLL0); | |
5607 | else | |
5608 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5609 | SKL_DPLL0); | |
5610 | ||
5611 | I915_WRITE(DPLL_CTRL1, val); | |
5612 | POSTING_READ(DPLL_CTRL1); | |
5613 | ||
5614 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5615 | ||
5616 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5617 | DRM_ERROR("DPLL0 not locked\n"); | |
5618 | } | |
5619 | ||
5620 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5621 | { | |
5622 | int ret; | |
5623 | u32 val; | |
5624 | ||
5625 | /* inform PCU we want to change CDCLK */ | |
5626 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5627 | mutex_lock(&dev_priv->rps.hw_lock); | |
5628 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5629 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5630 | ||
5631 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5632 | } | |
5633 | ||
5634 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5635 | { | |
5636 | unsigned int i; | |
5637 | ||
5638 | for (i = 0; i < 15; i++) { | |
5639 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5640 | return true; | |
5641 | udelay(10); | |
5642 | } | |
5643 | ||
5644 | return false; | |
5645 | } | |
5646 | ||
5647 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5648 | { | |
560a7ae4 | 5649 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5650 | u32 freq_select, pcu_ack; |
5651 | ||
5652 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5653 | ||
5654 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5655 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5656 | return; | |
5657 | } | |
5658 | ||
5659 | /* set CDCLK_CTL */ | |
5660 | switch(freq) { | |
5661 | case 450000: | |
5662 | case 432000: | |
5663 | freq_select = CDCLK_FREQ_450_432; | |
5664 | pcu_ack = 1; | |
5665 | break; | |
5666 | case 540000: | |
5667 | freq_select = CDCLK_FREQ_540; | |
5668 | pcu_ack = 2; | |
5669 | break; | |
5670 | case 308570: | |
5671 | case 337500: | |
5672 | default: | |
5673 | freq_select = CDCLK_FREQ_337_308; | |
5674 | pcu_ack = 0; | |
5675 | break; | |
5676 | case 617140: | |
5677 | case 675000: | |
5678 | freq_select = CDCLK_FREQ_675_617; | |
5679 | pcu_ack = 3; | |
5680 | break; | |
5681 | } | |
5682 | ||
5683 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5684 | POSTING_READ(CDCLK_CTL); | |
5685 | ||
5686 | /* inform PCU of the change */ | |
5687 | mutex_lock(&dev_priv->rps.hw_lock); | |
5688 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5689 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5690 | |
5691 | intel_update_cdclk(dev); | |
5d96d8af DL |
5692 | } |
5693 | ||
5694 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5695 | { | |
5696 | /* disable DBUF power */ | |
5697 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5698 | POSTING_READ(DBUF_CTL); | |
5699 | ||
5700 | udelay(10); | |
5701 | ||
5702 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5703 | DRM_ERROR("DBuf power disable timeout\n"); | |
5704 | ||
ab96c1ee ID |
5705 | /* disable DPLL0 */ |
5706 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5707 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5708 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5d96d8af DL |
5709 | } |
5710 | ||
5711 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5712 | { | |
5d96d8af DL |
5713 | unsigned int required_vco; |
5714 | ||
39d9b85a GW |
5715 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5716 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5717 | /* enable DPLL0 */ | |
5718 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5719 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5720 | } |
5721 | ||
5d96d8af DL |
5722 | /* set CDCLK to the frequency the BIOS chose */ |
5723 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5724 | ||
5725 | /* enable DBUF power */ | |
5726 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5727 | POSTING_READ(DBUF_CTL); | |
5728 | ||
5729 | udelay(10); | |
5730 | ||
5731 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5732 | DRM_ERROR("DBuf power enable timeout\n"); | |
5733 | } | |
5734 | ||
c73666f3 SK |
5735 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
5736 | { | |
5737 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5738 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5739 | int freq = dev_priv->skl_boot_cdclk; | |
5740 | ||
f1b391a5 SK |
5741 | /* |
5742 | * check if the pre-os intialized the display | |
5743 | * There is SWF18 scratchpad register defined which is set by the | |
5744 | * pre-os which can be used by the OS drivers to check the status | |
5745 | */ | |
5746 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5747 | goto sanitize; | |
5748 | ||
c73666f3 SK |
5749 | /* Is PLL enabled and locked ? */ |
5750 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5751 | goto sanitize; | |
5752 | ||
5753 | /* DPLL okay; verify the cdclock | |
5754 | * | |
5755 | * Noticed in some instances that the freq selection is correct but | |
5756 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5757 | * enable display. Verify the same as well. | |
5758 | */ | |
5759 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5760 | /* All well; nothing to sanitize */ | |
5761 | return false; | |
5762 | sanitize: | |
5763 | /* | |
5764 | * As of now initialize with max cdclk till | |
5765 | * we get dynamic cdclk support | |
5766 | * */ | |
5767 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5768 | skl_init_cdclk(dev_priv); | |
5769 | ||
5770 | /* we did have to sanitize */ | |
5771 | return true; | |
5772 | } | |
5773 | ||
30a970c6 JB |
5774 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5775 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5776 | { | |
5777 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5778 | u32 val, cmd; | |
5779 | ||
164dfd28 VK |
5780 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5781 | != dev_priv->cdclk_freq); | |
d60c4473 | 5782 | |
dfcab17e | 5783 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5784 | cmd = 2; |
dfcab17e | 5785 | else if (cdclk == 266667) |
30a970c6 JB |
5786 | cmd = 1; |
5787 | else | |
5788 | cmd = 0; | |
5789 | ||
5790 | mutex_lock(&dev_priv->rps.hw_lock); | |
5791 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5792 | val &= ~DSPFREQGUAR_MASK; | |
5793 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5794 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5795 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5796 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5797 | 50)) { | |
5798 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5799 | } | |
5800 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5801 | ||
54433e91 VS |
5802 | mutex_lock(&dev_priv->sb_lock); |
5803 | ||
dfcab17e | 5804 | if (cdclk == 400000) { |
6bcda4f0 | 5805 | u32 divider; |
30a970c6 | 5806 | |
6bcda4f0 | 5807 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5808 | |
30a970c6 JB |
5809 | /* adjust cdclk divider */ |
5810 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 5811 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
5812 | val |= divider; |
5813 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5814 | |
5815 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 5816 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
5817 | 50)) |
5818 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5819 | } |
5820 | ||
30a970c6 JB |
5821 | /* adjust self-refresh exit latency value */ |
5822 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5823 | val &= ~0x7f; | |
5824 | ||
5825 | /* | |
5826 | * For high bandwidth configs, we set a higher latency in the bunit | |
5827 | * so that the core display fetch happens in time to avoid underruns. | |
5828 | */ | |
dfcab17e | 5829 | if (cdclk == 400000) |
30a970c6 JB |
5830 | val |= 4500 / 250; /* 4.5 usec */ |
5831 | else | |
5832 | val |= 3000 / 250; /* 3.0 usec */ | |
5833 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5834 | |
a580516d | 5835 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5836 | |
b6283055 | 5837 | intel_update_cdclk(dev); |
30a970c6 JB |
5838 | } |
5839 | ||
383c5a6a VS |
5840 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5841 | { | |
5842 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5843 | u32 val, cmd; | |
5844 | ||
164dfd28 VK |
5845 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5846 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5847 | |
5848 | switch (cdclk) { | |
383c5a6a VS |
5849 | case 333333: |
5850 | case 320000: | |
383c5a6a | 5851 | case 266667: |
383c5a6a | 5852 | case 200000: |
383c5a6a VS |
5853 | break; |
5854 | default: | |
5f77eeb0 | 5855 | MISSING_CASE(cdclk); |
383c5a6a VS |
5856 | return; |
5857 | } | |
5858 | ||
9d0d3fda VS |
5859 | /* |
5860 | * Specs are full of misinformation, but testing on actual | |
5861 | * hardware has shown that we just need to write the desired | |
5862 | * CCK divider into the Punit register. | |
5863 | */ | |
5864 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5865 | ||
383c5a6a VS |
5866 | mutex_lock(&dev_priv->rps.hw_lock); |
5867 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5868 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5869 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5870 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5871 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5872 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5873 | 50)) { | |
5874 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5875 | } | |
5876 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5877 | ||
b6283055 | 5878 | intel_update_cdclk(dev); |
383c5a6a VS |
5879 | } |
5880 | ||
30a970c6 JB |
5881 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5882 | int max_pixclk) | |
5883 | { | |
6bcda4f0 | 5884 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5885 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5886 | |
30a970c6 JB |
5887 | /* |
5888 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5889 | * 200MHz | |
5890 | * 267MHz | |
29dc7ef3 | 5891 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5892 | * 400MHz (VLV only) |
5893 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5894 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5895 | * |
5896 | * We seem to get an unstable or solid color picture at 200MHz. | |
5897 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5898 | * are off. | |
30a970c6 | 5899 | */ |
6cca3195 VS |
5900 | if (!IS_CHERRYVIEW(dev_priv) && |
5901 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5902 | return 400000; |
6cca3195 | 5903 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5904 | return freq_320; |
e37c67a1 | 5905 | else if (max_pixclk > 0) |
dfcab17e | 5906 | return 266667; |
e37c67a1 VS |
5907 | else |
5908 | return 200000; | |
30a970c6 JB |
5909 | } |
5910 | ||
f8437dd1 VK |
5911 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5912 | int max_pixclk) | |
5913 | { | |
5914 | /* | |
5915 | * FIXME: | |
5916 | * - remove the guardband, it's not needed on BXT | |
5917 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5918 | */ | |
5919 | if (max_pixclk > 576000*9/10) | |
5920 | return 624000; | |
5921 | else if (max_pixclk > 384000*9/10) | |
5922 | return 576000; | |
5923 | else if (max_pixclk > 288000*9/10) | |
5924 | return 384000; | |
5925 | else if (max_pixclk > 144000*9/10) | |
5926 | return 288000; | |
5927 | else | |
5928 | return 144000; | |
5929 | } | |
5930 | ||
a821fc46 ACO |
5931 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5932 | * that's non-NULL, look at current state otherwise. */ | |
5933 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5934 | struct drm_atomic_state *state) | |
30a970c6 | 5935 | { |
30a970c6 | 5936 | struct intel_crtc *intel_crtc; |
304603f4 | 5937 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5938 | int max_pixclk = 0; |
5939 | ||
d3fcc808 | 5940 | for_each_intel_crtc(dev, intel_crtc) { |
27c329ed | 5941 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
304603f4 ACO |
5942 | if (IS_ERR(crtc_state)) |
5943 | return PTR_ERR(crtc_state); | |
5944 | ||
5945 | if (!crtc_state->base.enable) | |
5946 | continue; | |
5947 | ||
5948 | max_pixclk = max(max_pixclk, | |
5949 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5950 | } |
5951 | ||
5952 | return max_pixclk; | |
5953 | } | |
5954 | ||
27c329ed | 5955 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 5956 | { |
27c329ed ML |
5957 | struct drm_device *dev = state->dev; |
5958 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5959 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
30a970c6 | 5960 | |
304603f4 ACO |
5961 | if (max_pixclk < 0) |
5962 | return max_pixclk; | |
30a970c6 | 5963 | |
27c329ed ML |
5964 | to_intel_atomic_state(state)->cdclk = |
5965 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
0a9ab303 | 5966 | |
27c329ed ML |
5967 | return 0; |
5968 | } | |
304603f4 | 5969 | |
27c329ed ML |
5970 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
5971 | { | |
5972 | struct drm_device *dev = state->dev; | |
5973 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5974 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
85a96e7a | 5975 | |
27c329ed ML |
5976 | if (max_pixclk < 0) |
5977 | return max_pixclk; | |
85a96e7a | 5978 | |
27c329ed ML |
5979 | to_intel_atomic_state(state)->cdclk = |
5980 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
85a96e7a | 5981 | |
27c329ed | 5982 | return 0; |
30a970c6 JB |
5983 | } |
5984 | ||
1e69cd74 VS |
5985 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
5986 | { | |
5987 | unsigned int credits, default_credits; | |
5988 | ||
5989 | if (IS_CHERRYVIEW(dev_priv)) | |
5990 | default_credits = PFI_CREDIT(12); | |
5991 | else | |
5992 | default_credits = PFI_CREDIT(8); | |
5993 | ||
bfa7df01 | 5994 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
5995 | /* CHV suggested value is 31 or 63 */ |
5996 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 5997 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
5998 | else |
5999 | credits = PFI_CREDIT(15); | |
6000 | } else { | |
6001 | credits = default_credits; | |
6002 | } | |
6003 | ||
6004 | /* | |
6005 | * WA - write default credits before re-programming | |
6006 | * FIXME: should we also set the resend bit here? | |
6007 | */ | |
6008 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6009 | default_credits); | |
6010 | ||
6011 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6012 | credits | PFI_CREDIT_RESEND); | |
6013 | ||
6014 | /* | |
6015 | * FIXME is this guaranteed to clear | |
6016 | * immediately or should we poll for it? | |
6017 | */ | |
6018 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6019 | } | |
6020 | ||
27c329ed | 6021 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6022 | { |
a821fc46 | 6023 | struct drm_device *dev = old_state->dev; |
27c329ed | 6024 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
30a970c6 | 6025 | struct drm_i915_private *dev_priv = dev->dev_private; |
30a970c6 | 6026 | |
27c329ed ML |
6027 | /* |
6028 | * FIXME: We can end up here with all power domains off, yet | |
6029 | * with a CDCLK frequency other than the minimum. To account | |
6030 | * for this take the PIPE-A power domain, which covers the HW | |
6031 | * blocks needed for the following programming. This can be | |
6032 | * removed once it's guaranteed that we get here either with | |
6033 | * the minimum CDCLK set, or the required power domains | |
6034 | * enabled. | |
6035 | */ | |
6036 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6037 | |
27c329ed ML |
6038 | if (IS_CHERRYVIEW(dev)) |
6039 | cherryview_set_cdclk(dev, req_cdclk); | |
6040 | else | |
6041 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6042 | |
27c329ed | 6043 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6044 | |
27c329ed | 6045 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6046 | } |
6047 | ||
89b667f8 JB |
6048 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6049 | { | |
6050 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6051 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6052 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6053 | struct intel_encoder *encoder; | |
6054 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6055 | bool is_dsi; |
89b667f8 | 6056 | |
53d9f4e9 | 6057 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6058 | return; |
6059 | ||
409ee761 | 6060 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6061 | |
6e3c9717 | 6062 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6063 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6064 | |
6065 | intel_set_pipe_timings(intel_crtc); | |
6066 | ||
c14b0485 VS |
6067 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6068 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6069 | ||
6070 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6071 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6072 | } | |
6073 | ||
5b18e57c DV |
6074 | i9xx_set_pipeconf(intel_crtc); |
6075 | ||
89b667f8 | 6076 | intel_crtc->active = true; |
89b667f8 | 6077 | |
a72e4c9f | 6078 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6079 | |
89b667f8 JB |
6080 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6081 | if (encoder->pre_pll_enable) | |
6082 | encoder->pre_pll_enable(encoder); | |
6083 | ||
9d556c99 | 6084 | if (!is_dsi) { |
c0b4c660 VS |
6085 | if (IS_CHERRYVIEW(dev)) { |
6086 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6087 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6088 | } else { |
6089 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6090 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6091 | } |
9d556c99 | 6092 | } |
89b667f8 JB |
6093 | |
6094 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6095 | if (encoder->pre_enable) | |
6096 | encoder->pre_enable(encoder); | |
6097 | ||
2dd24552 JB |
6098 | i9xx_pfit_enable(intel_crtc); |
6099 | ||
63cbb074 VS |
6100 | intel_crtc_load_lut(crtc); |
6101 | ||
e1fdc473 | 6102 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6103 | |
4b3a9526 VS |
6104 | assert_vblank_disabled(crtc); |
6105 | drm_crtc_vblank_on(crtc); | |
6106 | ||
f9b61ff6 DV |
6107 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6108 | encoder->enable(encoder); | |
89b667f8 JB |
6109 | } |
6110 | ||
f13c2ef3 DV |
6111 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6112 | { | |
6113 | struct drm_device *dev = crtc->base.dev; | |
6114 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6115 | ||
6e3c9717 ACO |
6116 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6117 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6118 | } |
6119 | ||
0b8765c6 | 6120 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6121 | { |
6122 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6123 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6124 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6125 | struct intel_encoder *encoder; |
79e53945 | 6126 | int pipe = intel_crtc->pipe; |
79e53945 | 6127 | |
53d9f4e9 | 6128 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6129 | return; |
6130 | ||
f13c2ef3 DV |
6131 | i9xx_set_pll_dividers(intel_crtc); |
6132 | ||
6e3c9717 | 6133 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6134 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6135 | |
6136 | intel_set_pipe_timings(intel_crtc); | |
6137 | ||
5b18e57c DV |
6138 | i9xx_set_pipeconf(intel_crtc); |
6139 | ||
f7abfe8b | 6140 | intel_crtc->active = true; |
6b383a7f | 6141 | |
4a3436e8 | 6142 | if (!IS_GEN2(dev)) |
a72e4c9f | 6143 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6144 | |
9d6d9f19 MK |
6145 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6146 | if (encoder->pre_enable) | |
6147 | encoder->pre_enable(encoder); | |
6148 | ||
f6736a1a DV |
6149 | i9xx_enable_pll(intel_crtc); |
6150 | ||
2dd24552 JB |
6151 | i9xx_pfit_enable(intel_crtc); |
6152 | ||
63cbb074 VS |
6153 | intel_crtc_load_lut(crtc); |
6154 | ||
f37fcc2a | 6155 | intel_update_watermarks(crtc); |
e1fdc473 | 6156 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6157 | |
4b3a9526 VS |
6158 | assert_vblank_disabled(crtc); |
6159 | drm_crtc_vblank_on(crtc); | |
6160 | ||
f9b61ff6 DV |
6161 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6162 | encoder->enable(encoder); | |
0b8765c6 | 6163 | } |
79e53945 | 6164 | |
87476d63 DV |
6165 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6166 | { | |
6167 | struct drm_device *dev = crtc->base.dev; | |
6168 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6169 | |
6e3c9717 | 6170 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6171 | return; |
87476d63 | 6172 | |
328d8e82 | 6173 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6174 | |
328d8e82 DV |
6175 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6176 | I915_READ(PFIT_CONTROL)); | |
6177 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6178 | } |
6179 | ||
0b8765c6 JB |
6180 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6181 | { | |
6182 | struct drm_device *dev = crtc->dev; | |
6183 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6184 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6185 | struct intel_encoder *encoder; |
0b8765c6 | 6186 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6187 | |
6304cd91 VS |
6188 | /* |
6189 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6190 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6191 | * We also need to wait on all gmch platforms because of the |
6192 | * self-refresh mode constraint explained above. | |
6304cd91 | 6193 | */ |
564ed191 | 6194 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6195 | |
4b3a9526 VS |
6196 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6197 | encoder->disable(encoder); | |
6198 | ||
f9b61ff6 DV |
6199 | drm_crtc_vblank_off(crtc); |
6200 | assert_vblank_disabled(crtc); | |
6201 | ||
575f7ab7 | 6202 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6203 | |
87476d63 | 6204 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6205 | |
89b667f8 JB |
6206 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6207 | if (encoder->post_disable) | |
6208 | encoder->post_disable(encoder); | |
6209 | ||
409ee761 | 6210 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6211 | if (IS_CHERRYVIEW(dev)) |
6212 | chv_disable_pll(dev_priv, pipe); | |
6213 | else if (IS_VALLEYVIEW(dev)) | |
6214 | vlv_disable_pll(dev_priv, pipe); | |
6215 | else | |
1c4e0274 | 6216 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6217 | } |
0b8765c6 | 6218 | |
d6db995f VS |
6219 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6220 | if (encoder->post_pll_disable) | |
6221 | encoder->post_pll_disable(encoder); | |
6222 | ||
4a3436e8 | 6223 | if (!IS_GEN2(dev)) |
a72e4c9f | 6224 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
0b8765c6 JB |
6225 | } |
6226 | ||
b17d48e2 ML |
6227 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6228 | { | |
6229 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6230 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6231 | enum intel_display_power_domain domain; | |
6232 | unsigned long domains; | |
6233 | ||
6234 | if (!intel_crtc->active) | |
6235 | return; | |
6236 | ||
a539205a | 6237 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
fc32b1fd ML |
6238 | WARN_ON(intel_crtc->unpin_work); |
6239 | ||
a539205a ML |
6240 | intel_pre_disable_primary(crtc); |
6241 | } | |
6242 | ||
d032ffa0 | 6243 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 | 6244 | dev_priv->display.crtc_disable(crtc); |
37d9078b MR |
6245 | intel_crtc->active = false; |
6246 | intel_update_watermarks(crtc); | |
1f7457b1 | 6247 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6248 | |
6249 | domains = intel_crtc->enabled_power_domains; | |
6250 | for_each_power_domain(domain, domains) | |
6251 | intel_display_power_put(dev_priv, domain); | |
6252 | intel_crtc->enabled_power_domains = 0; | |
6253 | } | |
6254 | ||
6b72d486 ML |
6255 | /* |
6256 | * turn all crtc's off, but do not adjust state | |
6257 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6258 | */ | |
70e0bd74 | 6259 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6260 | { |
70e0bd74 ML |
6261 | struct drm_mode_config *config = &dev->mode_config; |
6262 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
6263 | struct drm_atomic_state *state; | |
6b72d486 | 6264 | struct drm_crtc *crtc; |
70e0bd74 ML |
6265 | unsigned crtc_mask = 0; |
6266 | int ret = 0; | |
6267 | ||
6268 | if (WARN_ON(!ctx)) | |
6269 | return 0; | |
6270 | ||
6271 | lockdep_assert_held(&ctx->ww_ctx); | |
6272 | state = drm_atomic_state_alloc(dev); | |
6273 | if (WARN_ON(!state)) | |
6274 | return -ENOMEM; | |
6275 | ||
6276 | state->acquire_ctx = ctx; | |
6277 | state->allow_modeset = true; | |
6278 | ||
6279 | for_each_crtc(dev, crtc) { | |
6280 | struct drm_crtc_state *crtc_state = | |
6281 | drm_atomic_get_crtc_state(state, crtc); | |
6b72d486 | 6282 | |
70e0bd74 ML |
6283 | ret = PTR_ERR_OR_ZERO(crtc_state); |
6284 | if (ret) | |
6285 | goto free; | |
6286 | ||
6287 | if (!crtc_state->active) | |
6288 | continue; | |
6289 | ||
6290 | crtc_state->active = false; | |
6291 | crtc_mask |= 1 << drm_crtc_index(crtc); | |
6292 | } | |
6293 | ||
6294 | if (crtc_mask) { | |
74c090b1 | 6295 | ret = drm_atomic_commit(state); |
70e0bd74 ML |
6296 | |
6297 | if (!ret) { | |
6298 | for_each_crtc(dev, crtc) | |
6299 | if (crtc_mask & (1 << drm_crtc_index(crtc))) | |
6300 | crtc->state->active = true; | |
6301 | ||
6302 | return ret; | |
6303 | } | |
6304 | } | |
6305 | ||
6306 | free: | |
6307 | if (ret) | |
6308 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6309 | drm_atomic_state_free(state); | |
6310 | return ret; | |
ee7b9f93 JB |
6311 | } |
6312 | ||
ea5b213a | 6313 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6314 | { |
4ef69c7a | 6315 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6316 | |
ea5b213a CW |
6317 | drm_encoder_cleanup(encoder); |
6318 | kfree(intel_encoder); | |
7e7d76c3 JB |
6319 | } |
6320 | ||
0a91ca29 DV |
6321 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6322 | * internal consistency). */ | |
b980514c | 6323 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6324 | { |
35dd3c64 ML |
6325 | struct drm_crtc *crtc = connector->base.state->crtc; |
6326 | ||
6327 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6328 | connector->base.base.id, | |
6329 | connector->base.name); | |
6330 | ||
0a91ca29 | 6331 | if (connector->get_hw_state(connector)) { |
e85376cb | 6332 | struct intel_encoder *encoder = connector->encoder; |
35dd3c64 | 6333 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6334 | |
35dd3c64 ML |
6335 | I915_STATE_WARN(!crtc, |
6336 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6337 | |
35dd3c64 ML |
6338 | if (!crtc) |
6339 | return; | |
6340 | ||
6341 | I915_STATE_WARN(!crtc->state->active, | |
6342 | "connector is active, but attached crtc isn't\n"); | |
6343 | ||
e85376cb | 6344 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6345 | return; |
6346 | ||
e85376cb | 6347 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6348 | "atomic encoder doesn't match attached encoder\n"); |
6349 | ||
e85376cb | 6350 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6351 | "attached encoder crtc differs from connector crtc\n"); |
6352 | } else { | |
4d688a2a ML |
6353 | I915_STATE_WARN(crtc && crtc->state->active, |
6354 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6355 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6356 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6357 | } |
79e53945 JB |
6358 | } |
6359 | ||
08d9bc92 ACO |
6360 | int intel_connector_init(struct intel_connector *connector) |
6361 | { | |
6362 | struct drm_connector_state *connector_state; | |
6363 | ||
6364 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6365 | if (!connector_state) | |
6366 | return -ENOMEM; | |
6367 | ||
6368 | connector->base.state = connector_state; | |
6369 | return 0; | |
6370 | } | |
6371 | ||
6372 | struct intel_connector *intel_connector_alloc(void) | |
6373 | { | |
6374 | struct intel_connector *connector; | |
6375 | ||
6376 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6377 | if (!connector) | |
6378 | return NULL; | |
6379 | ||
6380 | if (intel_connector_init(connector) < 0) { | |
6381 | kfree(connector); | |
6382 | return NULL; | |
6383 | } | |
6384 | ||
6385 | return connector; | |
6386 | } | |
6387 | ||
f0947c37 DV |
6388 | /* Simple connector->get_hw_state implementation for encoders that support only |
6389 | * one connector and no cloning and hence the encoder state determines the state | |
6390 | * of the connector. */ | |
6391 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6392 | { |
24929352 | 6393 | enum pipe pipe = 0; |
f0947c37 | 6394 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6395 | |
f0947c37 | 6396 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6397 | } |
6398 | ||
6d293983 | 6399 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6400 | { |
6d293983 ACO |
6401 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6402 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6403 | |
6404 | return 0; | |
6405 | } | |
6406 | ||
6d293983 | 6407 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6408 | struct intel_crtc_state *pipe_config) |
1857e1da | 6409 | { |
6d293983 ACO |
6410 | struct drm_atomic_state *state = pipe_config->base.state; |
6411 | struct intel_crtc *other_crtc; | |
6412 | struct intel_crtc_state *other_crtc_state; | |
6413 | ||
1857e1da DV |
6414 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6415 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6416 | if (pipe_config->fdi_lanes > 4) { | |
6417 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6418 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6419 | return -EINVAL; |
1857e1da DV |
6420 | } |
6421 | ||
bafb6553 | 6422 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6423 | if (pipe_config->fdi_lanes > 2) { |
6424 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6425 | pipe_config->fdi_lanes); | |
6d293983 | 6426 | return -EINVAL; |
1857e1da | 6427 | } else { |
6d293983 | 6428 | return 0; |
1857e1da DV |
6429 | } |
6430 | } | |
6431 | ||
6432 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6433 | return 0; |
1857e1da DV |
6434 | |
6435 | /* Ivybridge 3 pipe is really complicated */ | |
6436 | switch (pipe) { | |
6437 | case PIPE_A: | |
6d293983 | 6438 | return 0; |
1857e1da | 6439 | case PIPE_B: |
6d293983 ACO |
6440 | if (pipe_config->fdi_lanes <= 2) |
6441 | return 0; | |
6442 | ||
6443 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6444 | other_crtc_state = | |
6445 | intel_atomic_get_crtc_state(state, other_crtc); | |
6446 | if (IS_ERR(other_crtc_state)) | |
6447 | return PTR_ERR(other_crtc_state); | |
6448 | ||
6449 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6450 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6451 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6452 | return -EINVAL; |
1857e1da | 6453 | } |
6d293983 | 6454 | return 0; |
1857e1da | 6455 | case PIPE_C: |
251cc67c VS |
6456 | if (pipe_config->fdi_lanes > 2) { |
6457 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6458 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6459 | return -EINVAL; |
251cc67c | 6460 | } |
6d293983 ACO |
6461 | |
6462 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6463 | other_crtc_state = | |
6464 | intel_atomic_get_crtc_state(state, other_crtc); | |
6465 | if (IS_ERR(other_crtc_state)) | |
6466 | return PTR_ERR(other_crtc_state); | |
6467 | ||
6468 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6469 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6470 | return -EINVAL; |
1857e1da | 6471 | } |
6d293983 | 6472 | return 0; |
1857e1da DV |
6473 | default: |
6474 | BUG(); | |
6475 | } | |
6476 | } | |
6477 | ||
e29c22c0 DV |
6478 | #define RETRY 1 |
6479 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6480 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6481 | { |
1857e1da | 6482 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6483 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6484 | int lane, link_bw, fdi_dotclock, ret; |
6485 | bool needs_recompute = false; | |
877d48d5 | 6486 | |
e29c22c0 | 6487 | retry: |
877d48d5 DV |
6488 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6489 | * each output octet as 10 bits. The actual frequency | |
6490 | * is stored as a divider into a 100MHz clock, and the | |
6491 | * mode pixel clock is stored in units of 1KHz. | |
6492 | * Hence the bw of each lane in terms of the mode signal | |
6493 | * is: | |
6494 | */ | |
6495 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6496 | ||
241bfc38 | 6497 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6498 | |
2bd89a07 | 6499 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6500 | pipe_config->pipe_bpp); |
6501 | ||
6502 | pipe_config->fdi_lanes = lane; | |
6503 | ||
2bd89a07 | 6504 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6505 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6506 | |
6d293983 ACO |
6507 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6508 | intel_crtc->pipe, pipe_config); | |
6509 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6510 | pipe_config->pipe_bpp -= 2*3; |
6511 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6512 | pipe_config->pipe_bpp); | |
6513 | needs_recompute = true; | |
6514 | pipe_config->bw_constrained = true; | |
6515 | ||
6516 | goto retry; | |
6517 | } | |
6518 | ||
6519 | if (needs_recompute) | |
6520 | return RETRY; | |
6521 | ||
6d293983 | 6522 | return ret; |
877d48d5 DV |
6523 | } |
6524 | ||
8cfb3407 VS |
6525 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6526 | struct intel_crtc_state *pipe_config) | |
6527 | { | |
6528 | if (pipe_config->pipe_bpp > 24) | |
6529 | return false; | |
6530 | ||
6531 | /* HSW can handle pixel rate up to cdclk? */ | |
6532 | if (IS_HASWELL(dev_priv->dev)) | |
6533 | return true; | |
6534 | ||
6535 | /* | |
b432e5cf VS |
6536 | * We compare against max which means we must take |
6537 | * the increased cdclk requirement into account when | |
6538 | * calculating the new cdclk. | |
6539 | * | |
6540 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6541 | */ |
6542 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6543 | dev_priv->max_cdclk_freq * 95 / 100; | |
6544 | } | |
6545 | ||
42db64ef | 6546 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6547 | struct intel_crtc_state *pipe_config) |
42db64ef | 6548 | { |
8cfb3407 VS |
6549 | struct drm_device *dev = crtc->base.dev; |
6550 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6551 | ||
d330a953 | 6552 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6553 | hsw_crtc_supports_ips(crtc) && |
6554 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6555 | } |
6556 | ||
39acb4aa VS |
6557 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6558 | { | |
6559 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6560 | ||
6561 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6562 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6563 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6564 | } | |
6565 | ||
a43f6e0f | 6566 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6567 | struct intel_crtc_state *pipe_config) |
79e53945 | 6568 | { |
a43f6e0f | 6569 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6570 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6571 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6572 | |
ad3a4479 | 6573 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6574 | if (INTEL_INFO(dev)->gen < 4) { |
39acb4aa | 6575 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6576 | |
6577 | /* | |
39acb4aa | 6578 | * Enable double wide mode when the dot clock |
cf532bb2 | 6579 | * is > 90% of the (display) core speed. |
cf532bb2 | 6580 | */ |
39acb4aa VS |
6581 | if (intel_crtc_supports_double_wide(crtc) && |
6582 | adjusted_mode->crtc_clock > clock_limit) { | |
ad3a4479 | 6583 | clock_limit *= 2; |
cf532bb2 | 6584 | pipe_config->double_wide = true; |
ad3a4479 VS |
6585 | } |
6586 | ||
39acb4aa VS |
6587 | if (adjusted_mode->crtc_clock > clock_limit) { |
6588 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6589 | adjusted_mode->crtc_clock, clock_limit, | |
6590 | yesno(pipe_config->double_wide)); | |
e29c22c0 | 6591 | return -EINVAL; |
39acb4aa | 6592 | } |
2c07245f | 6593 | } |
89749350 | 6594 | |
1d1d0e27 VS |
6595 | /* |
6596 | * Pipe horizontal size must be even in: | |
6597 | * - DVO ganged mode | |
6598 | * - LVDS dual channel mode | |
6599 | * - Double wide pipe | |
6600 | */ | |
a93e255f | 6601 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6602 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6603 | pipe_config->pipe_src_w &= ~1; | |
6604 | ||
8693a824 DL |
6605 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6606 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6607 | */ |
6608 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6609 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6610 | return -EINVAL; |
44f46b42 | 6611 | |
f5adf94e | 6612 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6613 | hsw_compute_ips_config(crtc, pipe_config); |
6614 | ||
877d48d5 | 6615 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6616 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6617 | |
cf5a15be | 6618 | return 0; |
79e53945 JB |
6619 | } |
6620 | ||
1652d19e VS |
6621 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6622 | { | |
6623 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6624 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6625 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6626 | uint32_t linkrate; | |
6627 | ||
414355a7 | 6628 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6629 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6630 | |
6631 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6632 | return 540000; | |
6633 | ||
6634 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6635 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6636 | |
71cd8423 DL |
6637 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6638 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6639 | /* vco 8640 */ |
6640 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6641 | case CDCLK_FREQ_450_432: | |
6642 | return 432000; | |
6643 | case CDCLK_FREQ_337_308: | |
6644 | return 308570; | |
6645 | case CDCLK_FREQ_675_617: | |
6646 | return 617140; | |
6647 | default: | |
6648 | WARN(1, "Unknown cd freq selection\n"); | |
6649 | } | |
6650 | } else { | |
6651 | /* vco 8100 */ | |
6652 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6653 | case CDCLK_FREQ_450_432: | |
6654 | return 450000; | |
6655 | case CDCLK_FREQ_337_308: | |
6656 | return 337500; | |
6657 | case CDCLK_FREQ_675_617: | |
6658 | return 675000; | |
6659 | default: | |
6660 | WARN(1, "Unknown cd freq selection\n"); | |
6661 | } | |
6662 | } | |
6663 | ||
6664 | /* error case, do as if DPLL0 isn't enabled */ | |
6665 | return 24000; | |
6666 | } | |
6667 | ||
acd3f3d3 BP |
6668 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6669 | { | |
6670 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6671 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6672 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6673 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6674 | int cdclk; | |
6675 | ||
6676 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6677 | return 19200; | |
6678 | ||
6679 | cdclk = 19200 * pll_ratio / 2; | |
6680 | ||
6681 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6682 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6683 | return cdclk; /* 576MHz or 624MHz */ | |
6684 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6685 | return cdclk * 2 / 3; /* 384MHz */ | |
6686 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6687 | return cdclk / 2; /* 288MHz */ | |
6688 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6689 | return cdclk / 4; /* 144MHz */ | |
6690 | } | |
6691 | ||
6692 | /* error case, do as if DE PLL isn't enabled */ | |
6693 | return 19200; | |
6694 | } | |
6695 | ||
1652d19e VS |
6696 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6697 | { | |
6698 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6699 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6700 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6701 | ||
6702 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6703 | return 800000; | |
6704 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6705 | return 450000; | |
6706 | else if (freq == LCPLL_CLK_FREQ_450) | |
6707 | return 450000; | |
6708 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6709 | return 540000; | |
6710 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6711 | return 337500; | |
6712 | else | |
6713 | return 675000; | |
6714 | } | |
6715 | ||
6716 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6717 | { | |
6718 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6719 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6720 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6721 | ||
6722 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6723 | return 800000; | |
6724 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6725 | return 450000; | |
6726 | else if (freq == LCPLL_CLK_FREQ_450) | |
6727 | return 450000; | |
6728 | else if (IS_HSW_ULT(dev)) | |
6729 | return 337500; | |
6730 | else | |
6731 | return 540000; | |
79e53945 JB |
6732 | } |
6733 | ||
25eb05fc JB |
6734 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6735 | { | |
bfa7df01 VS |
6736 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6737 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6738 | } |
6739 | ||
b37a6434 VS |
6740 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6741 | { | |
6742 | return 450000; | |
6743 | } | |
6744 | ||
e70236a8 JB |
6745 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6746 | { | |
6747 | return 400000; | |
6748 | } | |
79e53945 | 6749 | |
e70236a8 | 6750 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6751 | { |
e907f170 | 6752 | return 333333; |
e70236a8 | 6753 | } |
79e53945 | 6754 | |
e70236a8 JB |
6755 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6756 | { | |
6757 | return 200000; | |
6758 | } | |
79e53945 | 6759 | |
257a7ffc DV |
6760 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6761 | { | |
6762 | u16 gcfgc = 0; | |
6763 | ||
6764 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6765 | ||
6766 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6767 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6768 | return 266667; |
257a7ffc | 6769 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6770 | return 333333; |
257a7ffc | 6771 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6772 | return 444444; |
257a7ffc DV |
6773 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6774 | return 200000; | |
6775 | default: | |
6776 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6777 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6778 | return 133333; |
257a7ffc | 6779 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6780 | return 166667; |
257a7ffc DV |
6781 | } |
6782 | } | |
6783 | ||
e70236a8 JB |
6784 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6785 | { | |
6786 | u16 gcfgc = 0; | |
79e53945 | 6787 | |
e70236a8 JB |
6788 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6789 | ||
6790 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6791 | return 133333; |
e70236a8 JB |
6792 | else { |
6793 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6794 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6795 | return 333333; |
e70236a8 JB |
6796 | default: |
6797 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6798 | return 190000; | |
79e53945 | 6799 | } |
e70236a8 JB |
6800 | } |
6801 | } | |
6802 | ||
6803 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6804 | { | |
e907f170 | 6805 | return 266667; |
e70236a8 JB |
6806 | } |
6807 | ||
1b1d2716 | 6808 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6809 | { |
6810 | u16 hpllcc = 0; | |
1b1d2716 | 6811 | |
65cd2b3f VS |
6812 | /* |
6813 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6814 | * encoding is different :( | |
6815 | * FIXME is this the right way to detect 852GM/852GMV? | |
6816 | */ | |
6817 | if (dev->pdev->revision == 0x1) | |
6818 | return 133333; | |
6819 | ||
1b1d2716 VS |
6820 | pci_bus_read_config_word(dev->pdev->bus, |
6821 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6822 | ||
e70236a8 JB |
6823 | /* Assume that the hardware is in the high speed state. This |
6824 | * should be the default. | |
6825 | */ | |
6826 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6827 | case GC_CLOCK_133_200: | |
1b1d2716 | 6828 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6829 | case GC_CLOCK_100_200: |
6830 | return 200000; | |
6831 | case GC_CLOCK_166_250: | |
6832 | return 250000; | |
6833 | case GC_CLOCK_100_133: | |
e907f170 | 6834 | return 133333; |
1b1d2716 VS |
6835 | case GC_CLOCK_133_266: |
6836 | case GC_CLOCK_133_266_2: | |
6837 | case GC_CLOCK_166_266: | |
6838 | return 266667; | |
e70236a8 | 6839 | } |
79e53945 | 6840 | |
e70236a8 JB |
6841 | /* Shouldn't happen */ |
6842 | return 0; | |
6843 | } | |
79e53945 | 6844 | |
e70236a8 JB |
6845 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6846 | { | |
e907f170 | 6847 | return 133333; |
79e53945 JB |
6848 | } |
6849 | ||
34edce2f VS |
6850 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6851 | { | |
6852 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6853 | static const unsigned int blb_vco[8] = { | |
6854 | [0] = 3200000, | |
6855 | [1] = 4000000, | |
6856 | [2] = 5333333, | |
6857 | [3] = 4800000, | |
6858 | [4] = 6400000, | |
6859 | }; | |
6860 | static const unsigned int pnv_vco[8] = { | |
6861 | [0] = 3200000, | |
6862 | [1] = 4000000, | |
6863 | [2] = 5333333, | |
6864 | [3] = 4800000, | |
6865 | [4] = 2666667, | |
6866 | }; | |
6867 | static const unsigned int cl_vco[8] = { | |
6868 | [0] = 3200000, | |
6869 | [1] = 4000000, | |
6870 | [2] = 5333333, | |
6871 | [3] = 6400000, | |
6872 | [4] = 3333333, | |
6873 | [5] = 3566667, | |
6874 | [6] = 4266667, | |
6875 | }; | |
6876 | static const unsigned int elk_vco[8] = { | |
6877 | [0] = 3200000, | |
6878 | [1] = 4000000, | |
6879 | [2] = 5333333, | |
6880 | [3] = 4800000, | |
6881 | }; | |
6882 | static const unsigned int ctg_vco[8] = { | |
6883 | [0] = 3200000, | |
6884 | [1] = 4000000, | |
6885 | [2] = 5333333, | |
6886 | [3] = 6400000, | |
6887 | [4] = 2666667, | |
6888 | [5] = 4266667, | |
6889 | }; | |
6890 | const unsigned int *vco_table; | |
6891 | unsigned int vco; | |
6892 | uint8_t tmp = 0; | |
6893 | ||
6894 | /* FIXME other chipsets? */ | |
6895 | if (IS_GM45(dev)) | |
6896 | vco_table = ctg_vco; | |
6897 | else if (IS_G4X(dev)) | |
6898 | vco_table = elk_vco; | |
6899 | else if (IS_CRESTLINE(dev)) | |
6900 | vco_table = cl_vco; | |
6901 | else if (IS_PINEVIEW(dev)) | |
6902 | vco_table = pnv_vco; | |
6903 | else if (IS_G33(dev)) | |
6904 | vco_table = blb_vco; | |
6905 | else | |
6906 | return 0; | |
6907 | ||
6908 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6909 | ||
6910 | vco = vco_table[tmp & 0x7]; | |
6911 | if (vco == 0) | |
6912 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6913 | else | |
6914 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6915 | ||
6916 | return vco; | |
6917 | } | |
6918 | ||
6919 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
6920 | { | |
6921 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6922 | uint16_t tmp = 0; | |
6923 | ||
6924 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6925 | ||
6926 | cdclk_sel = (tmp >> 12) & 0x1; | |
6927 | ||
6928 | switch (vco) { | |
6929 | case 2666667: | |
6930 | case 4000000: | |
6931 | case 5333333: | |
6932 | return cdclk_sel ? 333333 : 222222; | |
6933 | case 3200000: | |
6934 | return cdclk_sel ? 320000 : 228571; | |
6935 | default: | |
6936 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
6937 | return 222222; | |
6938 | } | |
6939 | } | |
6940 | ||
6941 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
6942 | { | |
6943 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
6944 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
6945 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
6946 | const uint8_t *div_table; | |
6947 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6948 | uint16_t tmp = 0; | |
6949 | ||
6950 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6951 | ||
6952 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
6953 | ||
6954 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6955 | goto fail; | |
6956 | ||
6957 | switch (vco) { | |
6958 | case 3200000: | |
6959 | div_table = div_3200; | |
6960 | break; | |
6961 | case 4000000: | |
6962 | div_table = div_4000; | |
6963 | break; | |
6964 | case 5333333: | |
6965 | div_table = div_5333; | |
6966 | break; | |
6967 | default: | |
6968 | goto fail; | |
6969 | } | |
6970 | ||
6971 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
6972 | ||
caf4e252 | 6973 | fail: |
34edce2f VS |
6974 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
6975 | return 200000; | |
6976 | } | |
6977 | ||
6978 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
6979 | { | |
6980 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
6981 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
6982 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
6983 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
6984 | const uint8_t *div_table; | |
6985 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6986 | uint16_t tmp = 0; | |
6987 | ||
6988 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6989 | ||
6990 | cdclk_sel = (tmp >> 4) & 0x7; | |
6991 | ||
6992 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6993 | goto fail; | |
6994 | ||
6995 | switch (vco) { | |
6996 | case 3200000: | |
6997 | div_table = div_3200; | |
6998 | break; | |
6999 | case 4000000: | |
7000 | div_table = div_4000; | |
7001 | break; | |
7002 | case 4800000: | |
7003 | div_table = div_4800; | |
7004 | break; | |
7005 | case 5333333: | |
7006 | div_table = div_5333; | |
7007 | break; | |
7008 | default: | |
7009 | goto fail; | |
7010 | } | |
7011 | ||
7012 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7013 | ||
caf4e252 | 7014 | fail: |
34edce2f VS |
7015 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7016 | return 190476; | |
7017 | } | |
7018 | ||
2c07245f | 7019 | static void |
a65851af | 7020 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7021 | { |
a65851af VS |
7022 | while (*num > DATA_LINK_M_N_MASK || |
7023 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7024 | *num >>= 1; |
7025 | *den >>= 1; | |
7026 | } | |
7027 | } | |
7028 | ||
a65851af VS |
7029 | static void compute_m_n(unsigned int m, unsigned int n, |
7030 | uint32_t *ret_m, uint32_t *ret_n) | |
7031 | { | |
7032 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7033 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7034 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7035 | } | |
7036 | ||
e69d0bc1 DV |
7037 | void |
7038 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7039 | int pixel_clock, int link_clock, | |
7040 | struct intel_link_m_n *m_n) | |
2c07245f | 7041 | { |
e69d0bc1 | 7042 | m_n->tu = 64; |
a65851af VS |
7043 | |
7044 | compute_m_n(bits_per_pixel * pixel_clock, | |
7045 | link_clock * nlanes * 8, | |
7046 | &m_n->gmch_m, &m_n->gmch_n); | |
7047 | ||
7048 | compute_m_n(pixel_clock, link_clock, | |
7049 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7050 | } |
7051 | ||
a7615030 CW |
7052 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7053 | { | |
d330a953 JN |
7054 | if (i915.panel_use_ssc >= 0) |
7055 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7056 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7057 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7058 | } |
7059 | ||
a93e255f ACO |
7060 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7061 | int num_connectors) | |
c65d77d8 | 7062 | { |
a93e255f | 7063 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7064 | struct drm_i915_private *dev_priv = dev->dev_private; |
7065 | int refclk; | |
7066 | ||
a93e255f ACO |
7067 | WARN_ON(!crtc_state->base.state); |
7068 | ||
5ab7b0b7 | 7069 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7070 | refclk = 100000; |
a93e255f | 7071 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7072 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7073 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7074 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7075 | } else if (!IS_GEN2(dev)) { |
7076 | refclk = 96000; | |
7077 | } else { | |
7078 | refclk = 48000; | |
7079 | } | |
7080 | ||
7081 | return refclk; | |
7082 | } | |
7083 | ||
7429e9d4 | 7084 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7085 | { |
7df00d7a | 7086 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7087 | } |
f47709a9 | 7088 | |
7429e9d4 DV |
7089 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7090 | { | |
7091 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7092 | } |
7093 | ||
f47709a9 | 7094 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7095 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7096 | intel_clock_t *reduced_clock) |
7097 | { | |
f47709a9 | 7098 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7099 | u32 fp, fp2 = 0; |
7100 | ||
7101 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7102 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7103 | if (reduced_clock) |
7429e9d4 | 7104 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7105 | } else { |
190f68c5 | 7106 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7107 | if (reduced_clock) |
7429e9d4 | 7108 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7109 | } |
7110 | ||
190f68c5 | 7111 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7112 | |
f47709a9 | 7113 | crtc->lowfreq_avail = false; |
a93e255f | 7114 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7115 | reduced_clock) { |
190f68c5 | 7116 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7117 | crtc->lowfreq_avail = true; |
a7516a05 | 7118 | } else { |
190f68c5 | 7119 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7120 | } |
7121 | } | |
7122 | ||
5e69f97f CML |
7123 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7124 | pipe) | |
89b667f8 JB |
7125 | { |
7126 | u32 reg_val; | |
7127 | ||
7128 | /* | |
7129 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7130 | * and set it to a reasonable value instead. | |
7131 | */ | |
ab3c759a | 7132 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7133 | reg_val &= 0xffffff00; |
7134 | reg_val |= 0x00000030; | |
ab3c759a | 7135 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7136 | |
ab3c759a | 7137 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7138 | reg_val &= 0x8cffffff; |
7139 | reg_val = 0x8c000000; | |
ab3c759a | 7140 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7141 | |
ab3c759a | 7142 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7143 | reg_val &= 0xffffff00; |
ab3c759a | 7144 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7145 | |
ab3c759a | 7146 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7147 | reg_val &= 0x00ffffff; |
7148 | reg_val |= 0xb0000000; | |
ab3c759a | 7149 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7150 | } |
7151 | ||
b551842d DV |
7152 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7153 | struct intel_link_m_n *m_n) | |
7154 | { | |
7155 | struct drm_device *dev = crtc->base.dev; | |
7156 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7157 | int pipe = crtc->pipe; | |
7158 | ||
e3b95f1e DV |
7159 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7160 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7161 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7162 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7163 | } |
7164 | ||
7165 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7166 | struct intel_link_m_n *m_n, |
7167 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7168 | { |
7169 | struct drm_device *dev = crtc->base.dev; | |
7170 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7171 | int pipe = crtc->pipe; | |
6e3c9717 | 7172 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7173 | |
7174 | if (INTEL_INFO(dev)->gen >= 5) { | |
7175 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7176 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7177 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7178 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7179 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7180 | * for gen < 8) and if DRRS is supported (to make sure the | |
7181 | * registers are not unnecessarily accessed). | |
7182 | */ | |
44395bfe | 7183 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7184 | crtc->config->has_drrs) { |
f769cd24 VK |
7185 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7186 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7187 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7188 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7189 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7190 | } | |
b551842d | 7191 | } else { |
e3b95f1e DV |
7192 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7193 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7194 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7195 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7196 | } |
7197 | } | |
7198 | ||
fe3cd48d | 7199 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7200 | { |
fe3cd48d R |
7201 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7202 | ||
7203 | if (m_n == M1_N1) { | |
7204 | dp_m_n = &crtc->config->dp_m_n; | |
7205 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7206 | } else if (m_n == M2_N2) { | |
7207 | ||
7208 | /* | |
7209 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7210 | * needs to be programmed into M1_N1. | |
7211 | */ | |
7212 | dp_m_n = &crtc->config->dp_m2_n2; | |
7213 | } else { | |
7214 | DRM_ERROR("Unsupported divider value\n"); | |
7215 | return; | |
7216 | } | |
7217 | ||
6e3c9717 ACO |
7218 | if (crtc->config->has_pch_encoder) |
7219 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7220 | else |
fe3cd48d | 7221 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7222 | } |
7223 | ||
251ac862 DV |
7224 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7225 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7226 | { |
7227 | u32 dpll, dpll_md; | |
7228 | ||
7229 | /* | |
7230 | * Enable DPIO clock input. We should never disable the reference | |
7231 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7232 | * on it. | |
7233 | */ | |
60bfe44f VS |
7234 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7235 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7236 | /* We should never disable this, set it here for state tracking */ |
7237 | if (crtc->pipe == PIPE_B) | |
7238 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7239 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7240 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7241 | |
d288f65f | 7242 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7243 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7244 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7245 | } |
7246 | ||
d288f65f | 7247 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7248 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7249 | { |
f47709a9 | 7250 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7251 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7252 | int pipe = crtc->pipe; |
bdd4b6a6 | 7253 | u32 mdiv; |
a0c4da24 | 7254 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7255 | u32 coreclk, reg_val; |
a0c4da24 | 7256 | |
a580516d | 7257 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7258 | |
d288f65f VS |
7259 | bestn = pipe_config->dpll.n; |
7260 | bestm1 = pipe_config->dpll.m1; | |
7261 | bestm2 = pipe_config->dpll.m2; | |
7262 | bestp1 = pipe_config->dpll.p1; | |
7263 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7264 | |
89b667f8 JB |
7265 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7266 | ||
7267 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7268 | if (pipe == PIPE_B) |
5e69f97f | 7269 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7270 | |
7271 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7272 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7273 | |
7274 | /* Disable target IRef on PLL */ | |
ab3c759a | 7275 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7276 | reg_val &= 0x00ffffff; |
ab3c759a | 7277 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7278 | |
7279 | /* Disable fast lock */ | |
ab3c759a | 7280 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7281 | |
7282 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7283 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7284 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7285 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7286 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7287 | |
7288 | /* | |
7289 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7290 | * but we don't support that). | |
7291 | * Note: don't use the DAC post divider as it seems unstable. | |
7292 | */ | |
7293 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7294 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7295 | |
a0c4da24 | 7296 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7297 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7298 | |
89b667f8 | 7299 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7300 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7301 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7302 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7303 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7304 | 0x009f0003); |
89b667f8 | 7305 | else |
ab3c759a | 7306 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7307 | 0x00d0000f); |
7308 | ||
681a8504 | 7309 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7310 | /* Use SSC source */ |
bdd4b6a6 | 7311 | if (pipe == PIPE_A) |
ab3c759a | 7312 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7313 | 0x0df40000); |
7314 | else | |
ab3c759a | 7315 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7316 | 0x0df70000); |
7317 | } else { /* HDMI or VGA */ | |
7318 | /* Use bend source */ | |
bdd4b6a6 | 7319 | if (pipe == PIPE_A) |
ab3c759a | 7320 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7321 | 0x0df70000); |
7322 | else | |
ab3c759a | 7323 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7324 | 0x0df40000); |
7325 | } | |
a0c4da24 | 7326 | |
ab3c759a | 7327 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7328 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7329 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7330 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7331 | coreclk |= 0x01000000; |
ab3c759a | 7332 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7333 | |
ab3c759a | 7334 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7335 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7336 | } |
7337 | ||
251ac862 DV |
7338 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7339 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7340 | { |
60bfe44f VS |
7341 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7342 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7343 | DPLL_VCO_ENABLE; |
7344 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7345 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7346 | |
d288f65f VS |
7347 | pipe_config->dpll_hw_state.dpll_md = |
7348 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7349 | } |
7350 | ||
d288f65f | 7351 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7352 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
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 | int dpll_reg = DPLL(crtc->pipe); | |
7358 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 7359 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7360 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7361 | u32 dpio_val; |
9cbe40c1 | 7362 | int vco; |
9d556c99 | 7363 | |
d288f65f VS |
7364 | bestn = pipe_config->dpll.n; |
7365 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7366 | bestm1 = pipe_config->dpll.m1; | |
7367 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7368 | bestp1 = pipe_config->dpll.p1; | |
7369 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7370 | vco = pipe_config->dpll.vco; |
a945ce7e | 7371 | dpio_val = 0; |
9cbe40c1 | 7372 | loopfilter = 0; |
9d556c99 CML |
7373 | |
7374 | /* | |
7375 | * Enable Refclk and SSC | |
7376 | */ | |
a11b0703 | 7377 | I915_WRITE(dpll_reg, |
d288f65f | 7378 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7379 | |
a580516d | 7380 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7381 | |
9d556c99 CML |
7382 | /* p1 and p2 divider */ |
7383 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7384 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7385 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7386 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7387 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7388 | ||
7389 | /* Feedback post-divider - m2 */ | |
7390 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7391 | ||
7392 | /* Feedback refclk divider - n and m1 */ | |
7393 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7394 | DPIO_CHV_M1_DIV_BY_2 | | |
7395 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7396 | ||
7397 | /* M2 fraction division */ | |
25a25dfc | 7398 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7399 | |
7400 | /* M2 fraction division enable */ | |
a945ce7e VP |
7401 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7402 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7403 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7404 | if (bestm2_frac) | |
7405 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7406 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7407 | |
de3a0fde VP |
7408 | /* Program digital lock detect threshold */ |
7409 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7410 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7411 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7412 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7413 | if (!bestm2_frac) | |
7414 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7415 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7416 | ||
9d556c99 | 7417 | /* Loop filter */ |
9cbe40c1 VP |
7418 | if (vco == 5400000) { |
7419 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7420 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7421 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7422 | tribuf_calcntr = 0x9; | |
7423 | } else if (vco <= 6200000) { | |
7424 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7425 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7426 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7427 | tribuf_calcntr = 0x9; | |
7428 | } else if (vco <= 6480000) { | |
7429 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7430 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7431 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7432 | tribuf_calcntr = 0x8; | |
7433 | } else { | |
7434 | /* Not supported. Apply the same limits as in the max case */ | |
7435 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7436 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7437 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7438 | tribuf_calcntr = 0; | |
7439 | } | |
9d556c99 CML |
7440 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7441 | ||
968040b2 | 7442 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7443 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7444 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7445 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7446 | ||
9d556c99 CML |
7447 | /* AFC Recal */ |
7448 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7449 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7450 | DPIO_AFC_RECAL); | |
7451 | ||
a580516d | 7452 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7453 | } |
7454 | ||
d288f65f VS |
7455 | /** |
7456 | * vlv_force_pll_on - forcibly enable just the PLL | |
7457 | * @dev_priv: i915 private structure | |
7458 | * @pipe: pipe PLL to enable | |
7459 | * @dpll: PLL configuration | |
7460 | * | |
7461 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7462 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7463 | * be enabled. | |
7464 | */ | |
7465 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7466 | const struct dpll *dpll) | |
7467 | { | |
7468 | struct intel_crtc *crtc = | |
7469 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7470 | struct intel_crtc_state pipe_config = { |
a93e255f | 7471 | .base.crtc = &crtc->base, |
d288f65f VS |
7472 | .pixel_multiplier = 1, |
7473 | .dpll = *dpll, | |
7474 | }; | |
7475 | ||
7476 | if (IS_CHERRYVIEW(dev)) { | |
251ac862 | 7477 | chv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7478 | chv_prepare_pll(crtc, &pipe_config); |
7479 | chv_enable_pll(crtc, &pipe_config); | |
7480 | } else { | |
251ac862 | 7481 | vlv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7482 | vlv_prepare_pll(crtc, &pipe_config); |
7483 | vlv_enable_pll(crtc, &pipe_config); | |
7484 | } | |
7485 | } | |
7486 | ||
7487 | /** | |
7488 | * vlv_force_pll_off - forcibly disable just the PLL | |
7489 | * @dev_priv: i915 private structure | |
7490 | * @pipe: pipe PLL to disable | |
7491 | * | |
7492 | * Disable the PLL for @pipe. To be used in cases where we need | |
7493 | * the PLL enabled even when @pipe is not going to be enabled. | |
7494 | */ | |
7495 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7496 | { | |
7497 | if (IS_CHERRYVIEW(dev)) | |
7498 | chv_disable_pll(to_i915(dev), pipe); | |
7499 | else | |
7500 | vlv_disable_pll(to_i915(dev), pipe); | |
7501 | } | |
7502 | ||
251ac862 DV |
7503 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7504 | struct intel_crtc_state *crtc_state, | |
7505 | intel_clock_t *reduced_clock, | |
7506 | int num_connectors) | |
eb1cbe48 | 7507 | { |
f47709a9 | 7508 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7509 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7510 | u32 dpll; |
7511 | bool is_sdvo; | |
190f68c5 | 7512 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7513 | |
190f68c5 | 7514 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7515 | |
a93e255f ACO |
7516 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7517 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7518 | |
7519 | dpll = DPLL_VGA_MODE_DIS; | |
7520 | ||
a93e255f | 7521 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7522 | dpll |= DPLLB_MODE_LVDS; |
7523 | else | |
7524 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7525 | |
ef1b460d | 7526 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7527 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7528 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7529 | } |
198a037f DV |
7530 | |
7531 | if (is_sdvo) | |
4a33e48d | 7532 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7533 | |
190f68c5 | 7534 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7535 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7536 | |
7537 | /* compute bitmask from p1 value */ | |
7538 | if (IS_PINEVIEW(dev)) | |
7539 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7540 | else { | |
7541 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7542 | if (IS_G4X(dev) && reduced_clock) | |
7543 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7544 | } | |
7545 | switch (clock->p2) { | |
7546 | case 5: | |
7547 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7548 | break; | |
7549 | case 7: | |
7550 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7551 | break; | |
7552 | case 10: | |
7553 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7554 | break; | |
7555 | case 14: | |
7556 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7557 | break; | |
7558 | } | |
7559 | if (INTEL_INFO(dev)->gen >= 4) | |
7560 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7561 | ||
190f68c5 | 7562 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7563 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7564 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7565 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7566 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7567 | else | |
7568 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7569 | ||
7570 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7571 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7572 | |
eb1cbe48 | 7573 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7574 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7575 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7576 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7577 | } |
7578 | } | |
7579 | ||
251ac862 DV |
7580 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7581 | struct intel_crtc_state *crtc_state, | |
7582 | intel_clock_t *reduced_clock, | |
7583 | int num_connectors) | |
eb1cbe48 | 7584 | { |
f47709a9 | 7585 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7586 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7587 | u32 dpll; |
190f68c5 | 7588 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7589 | |
190f68c5 | 7590 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7591 | |
eb1cbe48 DV |
7592 | dpll = DPLL_VGA_MODE_DIS; |
7593 | ||
a93e255f | 7594 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7595 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7596 | } else { | |
7597 | if (clock->p1 == 2) | |
7598 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7599 | else | |
7600 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7601 | if (clock->p2 == 4) | |
7602 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7603 | } | |
7604 | ||
a93e255f | 7605 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7606 | dpll |= DPLL_DVO_2X_MODE; |
7607 | ||
a93e255f | 7608 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7609 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7610 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7611 | else | |
7612 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7613 | ||
7614 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7615 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7616 | } |
7617 | ||
8a654f3b | 7618 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7619 | { |
7620 | struct drm_device *dev = intel_crtc->base.dev; | |
7621 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7622 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7623 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7624 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7625 | uint32_t crtc_vtotal, crtc_vblank_end; |
7626 | int vsyncshift = 0; | |
4d8a62ea DV |
7627 | |
7628 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7629 | * the hw state checker will get angry at the mismatch. */ | |
7630 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7631 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7632 | |
609aeaca | 7633 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7634 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7635 | crtc_vtotal -= 1; |
7636 | crtc_vblank_end -= 1; | |
609aeaca | 7637 | |
409ee761 | 7638 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7639 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7640 | else | |
7641 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7642 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7643 | if (vsyncshift < 0) |
7644 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7645 | } |
7646 | ||
7647 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7648 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7649 | |
fe2b8f9d | 7650 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7651 | (adjusted_mode->crtc_hdisplay - 1) | |
7652 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7653 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7654 | (adjusted_mode->crtc_hblank_start - 1) | |
7655 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7656 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7657 | (adjusted_mode->crtc_hsync_start - 1) | |
7658 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7659 | ||
fe2b8f9d | 7660 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7661 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7662 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7663 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7664 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7665 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7666 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7667 | (adjusted_mode->crtc_vsync_start - 1) | |
7668 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7669 | ||
b5e508d4 PZ |
7670 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7671 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7672 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7673 | * bits. */ | |
7674 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7675 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7676 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7677 | ||
b0e77b9c PZ |
7678 | /* pipesrc controls the size that is scaled from, which should |
7679 | * always be the user's requested size. | |
7680 | */ | |
7681 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7682 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7683 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7684 | } |
7685 | ||
1bd1bd80 | 7686 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7687 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7688 | { |
7689 | struct drm_device *dev = crtc->base.dev; | |
7690 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7691 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7692 | uint32_t tmp; | |
7693 | ||
7694 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7695 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7696 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7697 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7698 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7699 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7700 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7701 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7702 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7703 | |
7704 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7705 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7706 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7707 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7708 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7709 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7710 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7711 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7712 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7713 | |
7714 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7715 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7716 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7717 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7718 | } |
7719 | ||
7720 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7721 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7722 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7723 | ||
2d112de7 ACO |
7724 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7725 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7726 | } |
7727 | ||
f6a83288 | 7728 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7729 | struct intel_crtc_state *pipe_config) |
babea61d | 7730 | { |
2d112de7 ACO |
7731 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7732 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7733 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7734 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7735 | |
2d112de7 ACO |
7736 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7737 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7738 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7739 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7740 | |
2d112de7 | 7741 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7742 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7743 | |
2d112de7 ACO |
7744 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7745 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7746 | |
7747 | mode->hsync = drm_mode_hsync(mode); | |
7748 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7749 | drm_mode_set_name(mode); | |
babea61d JB |
7750 | } |
7751 | ||
84b046f3 DV |
7752 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7753 | { | |
7754 | struct drm_device *dev = intel_crtc->base.dev; | |
7755 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7756 | uint32_t pipeconf; | |
7757 | ||
9f11a9e4 | 7758 | pipeconf = 0; |
84b046f3 | 7759 | |
b6b5d049 VS |
7760 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7761 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7762 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7763 | |
6e3c9717 | 7764 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7765 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7766 | |
ff9ce46e DV |
7767 | /* only g4x and later have fancy bpc/dither controls */ |
7768 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7769 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7770 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7771 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7772 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7773 | |
6e3c9717 | 7774 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7775 | case 18: |
7776 | pipeconf |= PIPECONF_6BPC; | |
7777 | break; | |
7778 | case 24: | |
7779 | pipeconf |= PIPECONF_8BPC; | |
7780 | break; | |
7781 | case 30: | |
7782 | pipeconf |= PIPECONF_10BPC; | |
7783 | break; | |
7784 | default: | |
7785 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7786 | BUG(); | |
84b046f3 DV |
7787 | } |
7788 | } | |
7789 | ||
7790 | if (HAS_PIPE_CXSR(dev)) { | |
7791 | if (intel_crtc->lowfreq_avail) { | |
7792 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7793 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7794 | } else { | |
7795 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7796 | } |
7797 | } | |
7798 | ||
6e3c9717 | 7799 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7800 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7801 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7802 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7803 | else | |
7804 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7805 | } else | |
84b046f3 DV |
7806 | pipeconf |= PIPECONF_PROGRESSIVE; |
7807 | ||
6e3c9717 | 7808 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7809 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7810 | |
84b046f3 DV |
7811 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7812 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7813 | } | |
7814 | ||
190f68c5 ACO |
7815 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7816 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7817 | { |
c7653199 | 7818 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7819 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7820 | int refclk, num_connectors = 0; |
c329a4ec DV |
7821 | intel_clock_t clock; |
7822 | bool ok; | |
7823 | bool is_dsi = false; | |
5eddb70b | 7824 | struct intel_encoder *encoder; |
d4906093 | 7825 | const intel_limit_t *limit; |
55bb9992 | 7826 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7827 | struct drm_connector *connector; |
55bb9992 ACO |
7828 | struct drm_connector_state *connector_state; |
7829 | int i; | |
79e53945 | 7830 | |
dd3cd74a ACO |
7831 | memset(&crtc_state->dpll_hw_state, 0, |
7832 | sizeof(crtc_state->dpll_hw_state)); | |
7833 | ||
da3ced29 | 7834 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7835 | if (connector_state->crtc != &crtc->base) |
7836 | continue; | |
7837 | ||
7838 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7839 | ||
5eddb70b | 7840 | switch (encoder->type) { |
e9fd1c02 JN |
7841 | case INTEL_OUTPUT_DSI: |
7842 | is_dsi = true; | |
7843 | break; | |
6847d71b PZ |
7844 | default: |
7845 | break; | |
79e53945 | 7846 | } |
43565a06 | 7847 | |
c751ce4f | 7848 | num_connectors++; |
79e53945 JB |
7849 | } |
7850 | ||
f2335330 | 7851 | if (is_dsi) |
5b18e57c | 7852 | return 0; |
f2335330 | 7853 | |
190f68c5 | 7854 | if (!crtc_state->clock_set) { |
a93e255f | 7855 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7856 | |
e9fd1c02 JN |
7857 | /* |
7858 | * Returns a set of divisors for the desired target clock with | |
7859 | * the given refclk, or FALSE. The returned values represent | |
7860 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7861 | * 2) / p1 / p2. | |
7862 | */ | |
a93e255f ACO |
7863 | limit = intel_limit(crtc_state, refclk); |
7864 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7865 | crtc_state->port_clock, |
e9fd1c02 | 7866 | refclk, NULL, &clock); |
f2335330 | 7867 | if (!ok) { |
e9fd1c02 JN |
7868 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7869 | return -EINVAL; | |
7870 | } | |
79e53945 | 7871 | |
f2335330 | 7872 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
7873 | crtc_state->dpll.n = clock.n; |
7874 | crtc_state->dpll.m1 = clock.m1; | |
7875 | crtc_state->dpll.m2 = clock.m2; | |
7876 | crtc_state->dpll.p1 = clock.p1; | |
7877 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7878 | } |
7026d4ac | 7879 | |
e9fd1c02 | 7880 | if (IS_GEN2(dev)) { |
c329a4ec | 7881 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7882 | num_connectors); |
9d556c99 | 7883 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 7884 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7885 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 7886 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7887 | } else { |
c329a4ec | 7888 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7889 | num_connectors); |
e9fd1c02 | 7890 | } |
79e53945 | 7891 | |
c8f7a0db | 7892 | return 0; |
f564048e EA |
7893 | } |
7894 | ||
2fa2fe9a | 7895 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7896 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7897 | { |
7898 | struct drm_device *dev = crtc->base.dev; | |
7899 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7900 | uint32_t tmp; | |
7901 | ||
dc9e7dec VS |
7902 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7903 | return; | |
7904 | ||
2fa2fe9a | 7905 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7906 | if (!(tmp & PFIT_ENABLE)) |
7907 | return; | |
2fa2fe9a | 7908 | |
06922821 | 7909 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7910 | if (INTEL_INFO(dev)->gen < 4) { |
7911 | if (crtc->pipe != PIPE_B) | |
7912 | return; | |
2fa2fe9a DV |
7913 | } else { |
7914 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7915 | return; | |
7916 | } | |
7917 | ||
06922821 | 7918 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
7919 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
7920 | if (INTEL_INFO(dev)->gen < 5) | |
7921 | pipe_config->gmch_pfit.lvds_border_bits = | |
7922 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
7923 | } | |
7924 | ||
acbec814 | 7925 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7926 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7927 | { |
7928 | struct drm_device *dev = crtc->base.dev; | |
7929 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7930 | int pipe = pipe_config->cpu_transcoder; | |
7931 | intel_clock_t clock; | |
7932 | u32 mdiv; | |
662c6ecb | 7933 | int refclk = 100000; |
acbec814 | 7934 | |
f573de5a SK |
7935 | /* In case of MIPI DPLL will not even be used */ |
7936 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
7937 | return; | |
7938 | ||
a580516d | 7939 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 7940 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 7941 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
7942 | |
7943 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7944 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7945 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7946 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7947 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7948 | ||
dccbea3b | 7949 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
7950 | } |
7951 | ||
5724dbd1 DL |
7952 | static void |
7953 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7954 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7955 | { |
7956 | struct drm_device *dev = crtc->base.dev; | |
7957 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7958 | u32 val, base, offset; | |
7959 | int pipe = crtc->pipe, plane = crtc->plane; | |
7960 | int fourcc, pixel_format; | |
6761dd31 | 7961 | unsigned int aligned_height; |
b113d5ee | 7962 | struct drm_framebuffer *fb; |
1b842c89 | 7963 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7964 | |
42a7b088 DL |
7965 | val = I915_READ(DSPCNTR(plane)); |
7966 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7967 | return; | |
7968 | ||
d9806c9f | 7969 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7970 | if (!intel_fb) { |
1ad292b5 JB |
7971 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7972 | return; | |
7973 | } | |
7974 | ||
1b842c89 DL |
7975 | fb = &intel_fb->base; |
7976 | ||
18c5247e DV |
7977 | if (INTEL_INFO(dev)->gen >= 4) { |
7978 | if (val & DISPPLANE_TILED) { | |
49af449b | 7979 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
7980 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
7981 | } | |
7982 | } | |
1ad292b5 JB |
7983 | |
7984 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 7985 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
7986 | fb->pixel_format = fourcc; |
7987 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
7988 | |
7989 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 7990 | if (plane_config->tiling) |
1ad292b5 JB |
7991 | offset = I915_READ(DSPTILEOFF(plane)); |
7992 | else | |
7993 | offset = I915_READ(DSPLINOFF(plane)); | |
7994 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
7995 | } else { | |
7996 | base = I915_READ(DSPADDR(plane)); | |
7997 | } | |
7998 | plane_config->base = base; | |
7999 | ||
8000 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8001 | fb->width = ((val >> 16) & 0xfff) + 1; |
8002 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8003 | |
8004 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8005 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8006 | |
b113d5ee | 8007 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8008 | fb->pixel_format, |
8009 | fb->modifier[0]); | |
1ad292b5 | 8010 | |
f37b5c2b | 8011 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8012 | |
2844a921 DL |
8013 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8014 | pipe_name(pipe), plane, fb->width, fb->height, | |
8015 | fb->bits_per_pixel, base, fb->pitches[0], | |
8016 | plane_config->size); | |
1ad292b5 | 8017 | |
2d14030b | 8018 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8019 | } |
8020 | ||
70b23a98 | 8021 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8022 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8023 | { |
8024 | struct drm_device *dev = crtc->base.dev; | |
8025 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8026 | int pipe = pipe_config->cpu_transcoder; | |
8027 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8028 | intel_clock_t clock; | |
0d7b6b11 | 8029 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8030 | int refclk = 100000; |
8031 | ||
a580516d | 8032 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8033 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8034 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8035 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8036 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8037 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8038 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8039 | |
8040 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8041 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8042 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8043 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8044 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8045 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8046 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8047 | ||
dccbea3b | 8048 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8049 | } |
8050 | ||
0e8ffe1b | 8051 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8052 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8053 | { |
8054 | struct drm_device *dev = crtc->base.dev; | |
8055 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8056 | uint32_t tmp; | |
8057 | ||
f458ebbc DV |
8058 | if (!intel_display_power_is_enabled(dev_priv, |
8059 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8060 | return false; |
8061 | ||
e143a21c | 8062 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8063 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8064 | |
0e8ffe1b DV |
8065 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8066 | if (!(tmp & PIPECONF_ENABLE)) | |
8067 | return false; | |
8068 | ||
42571aef VS |
8069 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8070 | switch (tmp & PIPECONF_BPC_MASK) { | |
8071 | case PIPECONF_6BPC: | |
8072 | pipe_config->pipe_bpp = 18; | |
8073 | break; | |
8074 | case PIPECONF_8BPC: | |
8075 | pipe_config->pipe_bpp = 24; | |
8076 | break; | |
8077 | case PIPECONF_10BPC: | |
8078 | pipe_config->pipe_bpp = 30; | |
8079 | break; | |
8080 | default: | |
8081 | break; | |
8082 | } | |
8083 | } | |
8084 | ||
b5a9fa09 DV |
8085 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8086 | pipe_config->limited_color_range = true; | |
8087 | ||
282740f7 VS |
8088 | if (INTEL_INFO(dev)->gen < 4) |
8089 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8090 | ||
1bd1bd80 DV |
8091 | intel_get_pipe_timings(crtc, pipe_config); |
8092 | ||
2fa2fe9a DV |
8093 | i9xx_get_pfit_config(crtc, pipe_config); |
8094 | ||
6c49f241 DV |
8095 | if (INTEL_INFO(dev)->gen >= 4) { |
8096 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8097 | pipe_config->pixel_multiplier = | |
8098 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8099 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8100 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8101 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8102 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8103 | pipe_config->pixel_multiplier = | |
8104 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8105 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8106 | } else { | |
8107 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8108 | * port and will be fixed up in the encoder->get_config | |
8109 | * function. */ | |
8110 | pipe_config->pixel_multiplier = 1; | |
8111 | } | |
8bcc2795 DV |
8112 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8113 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8114 | /* |
8115 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8116 | * on 830. Filter it out here so that we don't | |
8117 | * report errors due to that. | |
8118 | */ | |
8119 | if (IS_I830(dev)) | |
8120 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8121 | ||
8bcc2795 DV |
8122 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8123 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8124 | } else { |
8125 | /* Mask out read-only status bits. */ | |
8126 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8127 | DPLL_PORTC_READY_MASK | | |
8128 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8129 | } |
6c49f241 | 8130 | |
70b23a98 VS |
8131 | if (IS_CHERRYVIEW(dev)) |
8132 | chv_crtc_clock_get(crtc, pipe_config); | |
8133 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8134 | vlv_crtc_clock_get(crtc, pipe_config); |
8135 | else | |
8136 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8137 | |
0f64614d VS |
8138 | /* |
8139 | * Normally the dotclock is filled in by the encoder .get_config() | |
8140 | * but in case the pipe is enabled w/o any ports we need a sane | |
8141 | * default. | |
8142 | */ | |
8143 | pipe_config->base.adjusted_mode.crtc_clock = | |
8144 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8145 | ||
0e8ffe1b DV |
8146 | return true; |
8147 | } | |
8148 | ||
dde86e2d | 8149 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8150 | { |
8151 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8152 | struct intel_encoder *encoder; |
74cfd7ac | 8153 | u32 val, final; |
13d83a67 | 8154 | bool has_lvds = false; |
199e5d79 | 8155 | bool has_cpu_edp = false; |
199e5d79 | 8156 | bool has_panel = false; |
99eb6a01 KP |
8157 | bool has_ck505 = false; |
8158 | bool can_ssc = false; | |
13d83a67 JB |
8159 | |
8160 | /* We need to take the global config into account */ | |
b2784e15 | 8161 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8162 | switch (encoder->type) { |
8163 | case INTEL_OUTPUT_LVDS: | |
8164 | has_panel = true; | |
8165 | has_lvds = true; | |
8166 | break; | |
8167 | case INTEL_OUTPUT_EDP: | |
8168 | has_panel = true; | |
2de6905f | 8169 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8170 | has_cpu_edp = true; |
8171 | break; | |
6847d71b PZ |
8172 | default: |
8173 | break; | |
13d83a67 JB |
8174 | } |
8175 | } | |
8176 | ||
99eb6a01 | 8177 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8178 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8179 | can_ssc = has_ck505; |
8180 | } else { | |
8181 | has_ck505 = false; | |
8182 | can_ssc = true; | |
8183 | } | |
8184 | ||
2de6905f ID |
8185 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8186 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8187 | |
8188 | /* Ironlake: try to setup display ref clock before DPLL | |
8189 | * enabling. This is only under driver's control after | |
8190 | * PCH B stepping, previous chipset stepping should be | |
8191 | * ignoring this setting. | |
8192 | */ | |
74cfd7ac CW |
8193 | val = I915_READ(PCH_DREF_CONTROL); |
8194 | ||
8195 | /* As we must carefully and slowly disable/enable each source in turn, | |
8196 | * compute the final state we want first and check if we need to | |
8197 | * make any changes at all. | |
8198 | */ | |
8199 | final = val; | |
8200 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8201 | if (has_ck505) | |
8202 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8203 | else | |
8204 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8205 | ||
8206 | final &= ~DREF_SSC_SOURCE_MASK; | |
8207 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8208 | final &= ~DREF_SSC1_ENABLE; | |
8209 | ||
8210 | if (has_panel) { | |
8211 | final |= DREF_SSC_SOURCE_ENABLE; | |
8212 | ||
8213 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8214 | final |= DREF_SSC1_ENABLE; | |
8215 | ||
8216 | if (has_cpu_edp) { | |
8217 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8218 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8219 | else | |
8220 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8221 | } else | |
8222 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8223 | } else { | |
8224 | final |= DREF_SSC_SOURCE_DISABLE; | |
8225 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8226 | } | |
8227 | ||
8228 | if (final == val) | |
8229 | return; | |
8230 | ||
13d83a67 | 8231 | /* Always enable nonspread source */ |
74cfd7ac | 8232 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8233 | |
99eb6a01 | 8234 | if (has_ck505) |
74cfd7ac | 8235 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8236 | else |
74cfd7ac | 8237 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8238 | |
199e5d79 | 8239 | if (has_panel) { |
74cfd7ac CW |
8240 | val &= ~DREF_SSC_SOURCE_MASK; |
8241 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8242 | |
199e5d79 | 8243 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8244 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8245 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8246 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8247 | } else |
74cfd7ac | 8248 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8249 | |
8250 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8251 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8252 | POSTING_READ(PCH_DREF_CONTROL); |
8253 | udelay(200); | |
8254 | ||
74cfd7ac | 8255 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8256 | |
8257 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8258 | if (has_cpu_edp) { |
99eb6a01 | 8259 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8260 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8261 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8262 | } else |
74cfd7ac | 8263 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8264 | } else |
74cfd7ac | 8265 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8266 | |
74cfd7ac | 8267 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8268 | POSTING_READ(PCH_DREF_CONTROL); |
8269 | udelay(200); | |
8270 | } else { | |
8271 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8272 | ||
74cfd7ac | 8273 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8274 | |
8275 | /* Turn off CPU output */ | |
74cfd7ac | 8276 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8277 | |
74cfd7ac | 8278 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8279 | POSTING_READ(PCH_DREF_CONTROL); |
8280 | udelay(200); | |
8281 | ||
8282 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8283 | val &= ~DREF_SSC_SOURCE_MASK; |
8284 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8285 | |
8286 | /* Turn off SSC1 */ | |
74cfd7ac | 8287 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8288 | |
74cfd7ac | 8289 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8290 | POSTING_READ(PCH_DREF_CONTROL); |
8291 | udelay(200); | |
8292 | } | |
74cfd7ac CW |
8293 | |
8294 | BUG_ON(val != final); | |
13d83a67 JB |
8295 | } |
8296 | ||
f31f2d55 | 8297 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8298 | { |
f31f2d55 | 8299 | uint32_t tmp; |
dde86e2d | 8300 | |
0ff066a9 PZ |
8301 | tmp = I915_READ(SOUTH_CHICKEN2); |
8302 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8303 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8304 | |
0ff066a9 PZ |
8305 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8306 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8307 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8308 | |
0ff066a9 PZ |
8309 | tmp = I915_READ(SOUTH_CHICKEN2); |
8310 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8311 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8312 | |
0ff066a9 PZ |
8313 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8314 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8315 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8316 | } |
8317 | ||
8318 | /* WaMPhyProgramming:hsw */ | |
8319 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8320 | { | |
8321 | uint32_t tmp; | |
dde86e2d PZ |
8322 | |
8323 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8324 | tmp &= ~(0xFF << 24); | |
8325 | tmp |= (0x12 << 24); | |
8326 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8327 | ||
dde86e2d PZ |
8328 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8329 | tmp |= (1 << 11); | |
8330 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8331 | ||
8332 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8333 | tmp |= (1 << 11); | |
8334 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8335 | ||
dde86e2d PZ |
8336 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8337 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8338 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8339 | ||
8340 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8341 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8342 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8343 | ||
0ff066a9 PZ |
8344 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8345 | tmp &= ~(7 << 13); | |
8346 | tmp |= (5 << 13); | |
8347 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8348 | |
0ff066a9 PZ |
8349 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8350 | tmp &= ~(7 << 13); | |
8351 | tmp |= (5 << 13); | |
8352 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8353 | |
8354 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8355 | tmp &= ~0xFF; | |
8356 | tmp |= 0x1C; | |
8357 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8358 | ||
8359 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8360 | tmp &= ~0xFF; | |
8361 | tmp |= 0x1C; | |
8362 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8363 | ||
8364 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8365 | tmp &= ~(0xFF << 16); | |
8366 | tmp |= (0x1C << 16); | |
8367 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8368 | ||
8369 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8370 | tmp &= ~(0xFF << 16); | |
8371 | tmp |= (0x1C << 16); | |
8372 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8373 | ||
0ff066a9 PZ |
8374 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8375 | tmp |= (1 << 27); | |
8376 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8377 | |
0ff066a9 PZ |
8378 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8379 | tmp |= (1 << 27); | |
8380 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8381 | |
0ff066a9 PZ |
8382 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8383 | tmp &= ~(0xF << 28); | |
8384 | tmp |= (4 << 28); | |
8385 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8386 | |
0ff066a9 PZ |
8387 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8388 | tmp &= ~(0xF << 28); | |
8389 | tmp |= (4 << 28); | |
8390 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8391 | } |
8392 | ||
2fa86a1f PZ |
8393 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8394 | * Programming" based on the parameters passed: | |
8395 | * - Sequence to enable CLKOUT_DP | |
8396 | * - Sequence to enable CLKOUT_DP without spread | |
8397 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8398 | */ | |
8399 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8400 | bool with_fdi) | |
f31f2d55 PZ |
8401 | { |
8402 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8403 | uint32_t reg, tmp; |
8404 | ||
8405 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8406 | with_spread = true; | |
c2699524 | 8407 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8408 | with_fdi = false; |
f31f2d55 | 8409 | |
a580516d | 8410 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8411 | |
8412 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8413 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8414 | tmp |= SBI_SSCCTL_PATHALT; | |
8415 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8416 | ||
8417 | udelay(24); | |
8418 | ||
2fa86a1f PZ |
8419 | if (with_spread) { |
8420 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8421 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8422 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8423 | |
2fa86a1f PZ |
8424 | if (with_fdi) { |
8425 | lpt_reset_fdi_mphy(dev_priv); | |
8426 | lpt_program_fdi_mphy(dev_priv); | |
8427 | } | |
8428 | } | |
dde86e2d | 8429 | |
c2699524 | 8430 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8431 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8432 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8433 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8434 | |
a580516d | 8435 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8436 | } |
8437 | ||
47701c3b PZ |
8438 | /* Sequence to disable CLKOUT_DP */ |
8439 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8440 | { | |
8441 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8442 | uint32_t reg, tmp; | |
8443 | ||
a580516d | 8444 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8445 | |
c2699524 | 8446 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8447 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8448 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8449 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8450 | ||
8451 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8452 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8453 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8454 | tmp |= SBI_SSCCTL_PATHALT; | |
8455 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8456 | udelay(32); | |
8457 | } | |
8458 | tmp |= SBI_SSCCTL_DISABLE; | |
8459 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8460 | } | |
8461 | ||
a580516d | 8462 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8463 | } |
8464 | ||
bf8fa3d3 PZ |
8465 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8466 | { | |
bf8fa3d3 PZ |
8467 | struct intel_encoder *encoder; |
8468 | bool has_vga = false; | |
8469 | ||
b2784e15 | 8470 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8471 | switch (encoder->type) { |
8472 | case INTEL_OUTPUT_ANALOG: | |
8473 | has_vga = true; | |
8474 | break; | |
6847d71b PZ |
8475 | default: |
8476 | break; | |
bf8fa3d3 PZ |
8477 | } |
8478 | } | |
8479 | ||
47701c3b PZ |
8480 | if (has_vga) |
8481 | lpt_enable_clkout_dp(dev, true, true); | |
8482 | else | |
8483 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8484 | } |
8485 | ||
dde86e2d PZ |
8486 | /* |
8487 | * Initialize reference clocks when the driver loads | |
8488 | */ | |
8489 | void intel_init_pch_refclk(struct drm_device *dev) | |
8490 | { | |
8491 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8492 | ironlake_init_pch_refclk(dev); | |
8493 | else if (HAS_PCH_LPT(dev)) | |
8494 | lpt_init_pch_refclk(dev); | |
8495 | } | |
8496 | ||
55bb9992 | 8497 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8498 | { |
55bb9992 | 8499 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8500 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8501 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8502 | struct drm_connector *connector; |
55bb9992 | 8503 | struct drm_connector_state *connector_state; |
d9d444cb | 8504 | struct intel_encoder *encoder; |
55bb9992 | 8505 | int num_connectors = 0, i; |
d9d444cb JB |
8506 | bool is_lvds = false; |
8507 | ||
da3ced29 | 8508 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8509 | if (connector_state->crtc != crtc_state->base.crtc) |
8510 | continue; | |
8511 | ||
8512 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8513 | ||
d9d444cb JB |
8514 | switch (encoder->type) { |
8515 | case INTEL_OUTPUT_LVDS: | |
8516 | is_lvds = true; | |
8517 | break; | |
6847d71b PZ |
8518 | default: |
8519 | break; | |
d9d444cb JB |
8520 | } |
8521 | num_connectors++; | |
8522 | } | |
8523 | ||
8524 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8525 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8526 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8527 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8528 | } |
8529 | ||
8530 | return 120000; | |
8531 | } | |
8532 | ||
6ff93609 | 8533 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8534 | { |
c8203565 | 8535 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8536 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8537 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8538 | uint32_t val; |
8539 | ||
78114071 | 8540 | val = 0; |
c8203565 | 8541 | |
6e3c9717 | 8542 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8543 | case 18: |
dfd07d72 | 8544 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8545 | break; |
8546 | case 24: | |
dfd07d72 | 8547 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8548 | break; |
8549 | case 30: | |
dfd07d72 | 8550 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8551 | break; |
8552 | case 36: | |
dfd07d72 | 8553 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8554 | break; |
8555 | default: | |
cc769b62 PZ |
8556 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8557 | BUG(); | |
c8203565 PZ |
8558 | } |
8559 | ||
6e3c9717 | 8560 | if (intel_crtc->config->dither) |
c8203565 PZ |
8561 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8562 | ||
6e3c9717 | 8563 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8564 | val |= PIPECONF_INTERLACED_ILK; |
8565 | else | |
8566 | val |= PIPECONF_PROGRESSIVE; | |
8567 | ||
6e3c9717 | 8568 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8569 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8570 | |
c8203565 PZ |
8571 | I915_WRITE(PIPECONF(pipe), val); |
8572 | POSTING_READ(PIPECONF(pipe)); | |
8573 | } | |
8574 | ||
86d3efce VS |
8575 | /* |
8576 | * Set up the pipe CSC unit. | |
8577 | * | |
8578 | * Currently only full range RGB to limited range RGB conversion | |
8579 | * is supported, but eventually this should handle various | |
8580 | * RGB<->YCbCr scenarios as well. | |
8581 | */ | |
50f3b016 | 8582 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8583 | { |
8584 | struct drm_device *dev = crtc->dev; | |
8585 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8586 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8587 | int pipe = intel_crtc->pipe; | |
8588 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8589 | ||
8590 | /* | |
8591 | * TODO: Check what kind of values actually come out of the pipe | |
8592 | * with these coeff/postoff values and adjust to get the best | |
8593 | * accuracy. Perhaps we even need to take the bpc value into | |
8594 | * consideration. | |
8595 | */ | |
8596 | ||
6e3c9717 | 8597 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8598 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8599 | ||
8600 | /* | |
8601 | * GY/GU and RY/RU should be the other way around according | |
8602 | * to BSpec, but reality doesn't agree. Just set them up in | |
8603 | * a way that results in the correct picture. | |
8604 | */ | |
8605 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8606 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8607 | ||
8608 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8609 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8610 | ||
8611 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8612 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8613 | ||
8614 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8615 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8616 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8617 | ||
8618 | if (INTEL_INFO(dev)->gen > 6) { | |
8619 | uint16_t postoff = 0; | |
8620 | ||
6e3c9717 | 8621 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8622 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8623 | |
8624 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8625 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8626 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8627 | ||
8628 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8629 | } else { | |
8630 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8631 | ||
6e3c9717 | 8632 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8633 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8634 | ||
8635 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8636 | } | |
8637 | } | |
8638 | ||
6ff93609 | 8639 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8640 | { |
756f85cf PZ |
8641 | struct drm_device *dev = crtc->dev; |
8642 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8643 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8644 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8645 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8646 | uint32_t val; |
8647 | ||
3eff4faa | 8648 | val = 0; |
ee2b0b38 | 8649 | |
6e3c9717 | 8650 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8651 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8652 | ||
6e3c9717 | 8653 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8654 | val |= PIPECONF_INTERLACED_ILK; |
8655 | else | |
8656 | val |= PIPECONF_PROGRESSIVE; | |
8657 | ||
702e7a56 PZ |
8658 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8659 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8660 | |
8661 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8662 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8663 | |
3cdf122c | 8664 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8665 | val = 0; |
8666 | ||
6e3c9717 | 8667 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8668 | case 18: |
8669 | val |= PIPEMISC_DITHER_6_BPC; | |
8670 | break; | |
8671 | case 24: | |
8672 | val |= PIPEMISC_DITHER_8_BPC; | |
8673 | break; | |
8674 | case 30: | |
8675 | val |= PIPEMISC_DITHER_10_BPC; | |
8676 | break; | |
8677 | case 36: | |
8678 | val |= PIPEMISC_DITHER_12_BPC; | |
8679 | break; | |
8680 | default: | |
8681 | /* Case prevented by pipe_config_set_bpp. */ | |
8682 | BUG(); | |
8683 | } | |
8684 | ||
6e3c9717 | 8685 | if (intel_crtc->config->dither) |
756f85cf PZ |
8686 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8687 | ||
8688 | I915_WRITE(PIPEMISC(pipe), val); | |
8689 | } | |
ee2b0b38 PZ |
8690 | } |
8691 | ||
6591c6e4 | 8692 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8693 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8694 | intel_clock_t *clock, |
8695 | bool *has_reduced_clock, | |
8696 | intel_clock_t *reduced_clock) | |
8697 | { | |
8698 | struct drm_device *dev = crtc->dev; | |
8699 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8700 | int refclk; |
d4906093 | 8701 | const intel_limit_t *limit; |
c329a4ec | 8702 | bool ret; |
79e53945 | 8703 | |
55bb9992 | 8704 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8705 | |
d4906093 ML |
8706 | /* |
8707 | * Returns a set of divisors for the desired target clock with the given | |
8708 | * refclk, or FALSE. The returned values represent the clock equation: | |
8709 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8710 | */ | |
a93e255f ACO |
8711 | limit = intel_limit(crtc_state, refclk); |
8712 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8713 | crtc_state->port_clock, |
ee9300bb | 8714 | refclk, NULL, clock); |
6591c6e4 PZ |
8715 | if (!ret) |
8716 | return false; | |
cda4b7d3 | 8717 | |
6591c6e4 PZ |
8718 | return true; |
8719 | } | |
8720 | ||
d4b1931c PZ |
8721 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8722 | { | |
8723 | /* | |
8724 | * Account for spread spectrum to avoid | |
8725 | * oversubscribing the link. Max center spread | |
8726 | * is 2.5%; use 5% for safety's sake. | |
8727 | */ | |
8728 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8729 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8730 | } |
8731 | ||
7429e9d4 | 8732 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8733 | { |
7429e9d4 | 8734 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8735 | } |
8736 | ||
de13a2e3 | 8737 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8738 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8739 | u32 *fp, |
9a7c7890 | 8740 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8741 | { |
de13a2e3 | 8742 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8743 | struct drm_device *dev = crtc->dev; |
8744 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8745 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8746 | struct drm_connector *connector; |
55bb9992 ACO |
8747 | struct drm_connector_state *connector_state; |
8748 | struct intel_encoder *encoder; | |
de13a2e3 | 8749 | uint32_t dpll; |
55bb9992 | 8750 | int factor, num_connectors = 0, i; |
09ede541 | 8751 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8752 | |
da3ced29 | 8753 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8754 | if (connector_state->crtc != crtc_state->base.crtc) |
8755 | continue; | |
8756 | ||
8757 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8758 | ||
8759 | switch (encoder->type) { | |
79e53945 JB |
8760 | case INTEL_OUTPUT_LVDS: |
8761 | is_lvds = true; | |
8762 | break; | |
8763 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8764 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8765 | is_sdvo = true; |
79e53945 | 8766 | break; |
6847d71b PZ |
8767 | default: |
8768 | break; | |
79e53945 | 8769 | } |
43565a06 | 8770 | |
c751ce4f | 8771 | num_connectors++; |
79e53945 | 8772 | } |
79e53945 | 8773 | |
c1858123 | 8774 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8775 | factor = 21; |
8776 | if (is_lvds) { | |
8777 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8778 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8779 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8780 | factor = 25; |
190f68c5 | 8781 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8782 | factor = 20; |
c1858123 | 8783 | |
190f68c5 | 8784 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8785 | *fp |= FP_CB_TUNE; |
2c07245f | 8786 | |
9a7c7890 DV |
8787 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8788 | *fp2 |= FP_CB_TUNE; | |
8789 | ||
5eddb70b | 8790 | dpll = 0; |
2c07245f | 8791 | |
a07d6787 EA |
8792 | if (is_lvds) |
8793 | dpll |= DPLLB_MODE_LVDS; | |
8794 | else | |
8795 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8796 | |
190f68c5 | 8797 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8798 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8799 | |
8800 | if (is_sdvo) | |
4a33e48d | 8801 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8802 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8803 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8804 | |
a07d6787 | 8805 | /* compute bitmask from p1 value */ |
190f68c5 | 8806 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8807 | /* also FPA1 */ |
190f68c5 | 8808 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8809 | |
190f68c5 | 8810 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8811 | case 5: |
8812 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8813 | break; | |
8814 | case 7: | |
8815 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8816 | break; | |
8817 | case 10: | |
8818 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8819 | break; | |
8820 | case 14: | |
8821 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8822 | break; | |
79e53945 JB |
8823 | } |
8824 | ||
b4c09f3b | 8825 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8826 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8827 | else |
8828 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8829 | ||
959e16d6 | 8830 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8831 | } |
8832 | ||
190f68c5 ACO |
8833 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8834 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8835 | { |
c7653199 | 8836 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8837 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8838 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8839 | bool ok, has_reduced_clock = false; |
8b47047b | 8840 | bool is_lvds = false; |
e2b78267 | 8841 | struct intel_shared_dpll *pll; |
de13a2e3 | 8842 | |
dd3cd74a ACO |
8843 | memset(&crtc_state->dpll_hw_state, 0, |
8844 | sizeof(crtc_state->dpll_hw_state)); | |
8845 | ||
409ee761 | 8846 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8847 | |
5dc5298b PZ |
8848 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8849 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8850 | |
190f68c5 | 8851 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8852 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8853 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8854 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8855 | return -EINVAL; | |
79e53945 | 8856 | } |
f47709a9 | 8857 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8858 | if (!crtc_state->clock_set) { |
8859 | crtc_state->dpll.n = clock.n; | |
8860 | crtc_state->dpll.m1 = clock.m1; | |
8861 | crtc_state->dpll.m2 = clock.m2; | |
8862 | crtc_state->dpll.p1 = clock.p1; | |
8863 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8864 | } |
79e53945 | 8865 | |
5dc5298b | 8866 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8867 | if (crtc_state->has_pch_encoder) { |
8868 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8869 | if (has_reduced_clock) |
7429e9d4 | 8870 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8871 | |
190f68c5 | 8872 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8873 | &fp, &reduced_clock, |
8874 | has_reduced_clock ? &fp2 : NULL); | |
8875 | ||
190f68c5 ACO |
8876 | crtc_state->dpll_hw_state.dpll = dpll; |
8877 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8878 | if (has_reduced_clock) |
190f68c5 | 8879 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8880 | else |
190f68c5 | 8881 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8882 | |
190f68c5 | 8883 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8884 | if (pll == NULL) { |
84f44ce7 | 8885 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8886 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8887 | return -EINVAL; |
8888 | } | |
3fb37703 | 8889 | } |
79e53945 | 8890 | |
ab585dea | 8891 | if (is_lvds && has_reduced_clock) |
c7653199 | 8892 | crtc->lowfreq_avail = true; |
bcd644e0 | 8893 | else |
c7653199 | 8894 | crtc->lowfreq_avail = false; |
e2b78267 | 8895 | |
c8f7a0db | 8896 | return 0; |
79e53945 JB |
8897 | } |
8898 | ||
eb14cb74 VS |
8899 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8900 | struct intel_link_m_n *m_n) | |
8901 | { | |
8902 | struct drm_device *dev = crtc->base.dev; | |
8903 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8904 | enum pipe pipe = crtc->pipe; | |
8905 | ||
8906 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8907 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8908 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8909 | & ~TU_SIZE_MASK; | |
8910 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8911 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8912 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8913 | } | |
8914 | ||
8915 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8916 | enum transcoder transcoder, | |
b95af8be VK |
8917 | struct intel_link_m_n *m_n, |
8918 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
8919 | { |
8920 | struct drm_device *dev = crtc->base.dev; | |
8921 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 8922 | enum pipe pipe = crtc->pipe; |
72419203 | 8923 | |
eb14cb74 VS |
8924 | if (INTEL_INFO(dev)->gen >= 5) { |
8925 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
8926 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8927 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8928 | & ~TU_SIZE_MASK; | |
8929 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8930 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8931 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8932 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8933 | * gen < 8) and if DRRS is supported (to make sure the | |
8934 | * registers are not unnecessarily read). | |
8935 | */ | |
8936 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 8937 | crtc->config->has_drrs) { |
b95af8be VK |
8938 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8939 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8940 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8941 | & ~TU_SIZE_MASK; | |
8942 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8943 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8944 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8945 | } | |
eb14cb74 VS |
8946 | } else { |
8947 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8948 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8949 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8950 | & ~TU_SIZE_MASK; | |
8951 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8952 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8953 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8954 | } | |
8955 | } | |
8956 | ||
8957 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8958 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8959 | { |
681a8504 | 8960 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8961 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8962 | else | |
8963 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8964 | &pipe_config->dp_m_n, |
8965 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8966 | } |
72419203 | 8967 | |
eb14cb74 | 8968 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 8969 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
8970 | { |
8971 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 8972 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
8973 | } |
8974 | ||
bd2e244f | 8975 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8976 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
8977 | { |
8978 | struct drm_device *dev = crtc->base.dev; | |
8979 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
8980 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
8981 | uint32_t ps_ctrl = 0; | |
8982 | int id = -1; | |
8983 | int i; | |
bd2e244f | 8984 | |
a1b2278e CK |
8985 | /* find scaler attached to this pipe */ |
8986 | for (i = 0; i < crtc->num_scalers; i++) { | |
8987 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
8988 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
8989 | id = i; | |
8990 | pipe_config->pch_pfit.enabled = true; | |
8991 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
8992 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
8993 | break; | |
8994 | } | |
8995 | } | |
bd2e244f | 8996 | |
a1b2278e CK |
8997 | scaler_state->scaler_id = id; |
8998 | if (id >= 0) { | |
8999 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9000 | } else { | |
9001 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9002 | } |
9003 | } | |
9004 | ||
5724dbd1 DL |
9005 | static void |
9006 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9007 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9008 | { |
9009 | struct drm_device *dev = crtc->base.dev; | |
9010 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9011 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9012 | int pipe = crtc->pipe; |
9013 | int fourcc, pixel_format; | |
6761dd31 | 9014 | unsigned int aligned_height; |
bc8d7dff | 9015 | struct drm_framebuffer *fb; |
1b842c89 | 9016 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9017 | |
d9806c9f | 9018 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9019 | if (!intel_fb) { |
bc8d7dff DL |
9020 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9021 | return; | |
9022 | } | |
9023 | ||
1b842c89 DL |
9024 | fb = &intel_fb->base; |
9025 | ||
bc8d7dff | 9026 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9027 | if (!(val & PLANE_CTL_ENABLE)) |
9028 | goto error; | |
9029 | ||
bc8d7dff DL |
9030 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9031 | fourcc = skl_format_to_fourcc(pixel_format, | |
9032 | val & PLANE_CTL_ORDER_RGBX, | |
9033 | val & PLANE_CTL_ALPHA_MASK); | |
9034 | fb->pixel_format = fourcc; | |
9035 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9036 | ||
40f46283 DL |
9037 | tiling = val & PLANE_CTL_TILED_MASK; |
9038 | switch (tiling) { | |
9039 | case PLANE_CTL_TILED_LINEAR: | |
9040 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9041 | break; | |
9042 | case PLANE_CTL_TILED_X: | |
9043 | plane_config->tiling = I915_TILING_X; | |
9044 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9045 | break; | |
9046 | case PLANE_CTL_TILED_Y: | |
9047 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9048 | break; | |
9049 | case PLANE_CTL_TILED_YF: | |
9050 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9051 | break; | |
9052 | default: | |
9053 | MISSING_CASE(tiling); | |
9054 | goto error; | |
9055 | } | |
9056 | ||
bc8d7dff DL |
9057 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9058 | plane_config->base = base; | |
9059 | ||
9060 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9061 | ||
9062 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9063 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9064 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9065 | ||
9066 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9067 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9068 | fb->pixel_format); | |
bc8d7dff DL |
9069 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9070 | ||
9071 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9072 | fb->pixel_format, |
9073 | fb->modifier[0]); | |
bc8d7dff | 9074 | |
f37b5c2b | 9075 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9076 | |
9077 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9078 | pipe_name(pipe), fb->width, fb->height, | |
9079 | fb->bits_per_pixel, base, fb->pitches[0], | |
9080 | plane_config->size); | |
9081 | ||
2d14030b | 9082 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9083 | return; |
9084 | ||
9085 | error: | |
9086 | kfree(fb); | |
9087 | } | |
9088 | ||
2fa2fe9a | 9089 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9090 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9091 | { |
9092 | struct drm_device *dev = crtc->base.dev; | |
9093 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9094 | uint32_t tmp; | |
9095 | ||
9096 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9097 | ||
9098 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9099 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9100 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9101 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9102 | |
9103 | /* We currently do not free assignements of panel fitters on | |
9104 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9105 | * differentiates them) so just WARN about this case for now. */ | |
9106 | if (IS_GEN7(dev)) { | |
9107 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9108 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9109 | } | |
2fa2fe9a | 9110 | } |
79e53945 JB |
9111 | } |
9112 | ||
5724dbd1 DL |
9113 | static void |
9114 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9115 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9116 | { |
9117 | struct drm_device *dev = crtc->base.dev; | |
9118 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9119 | u32 val, base, offset; | |
aeee5a49 | 9120 | int pipe = crtc->pipe; |
4c6baa59 | 9121 | int fourcc, pixel_format; |
6761dd31 | 9122 | unsigned int aligned_height; |
b113d5ee | 9123 | struct drm_framebuffer *fb; |
1b842c89 | 9124 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9125 | |
42a7b088 DL |
9126 | val = I915_READ(DSPCNTR(pipe)); |
9127 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9128 | return; | |
9129 | ||
d9806c9f | 9130 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9131 | if (!intel_fb) { |
4c6baa59 JB |
9132 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9133 | return; | |
9134 | } | |
9135 | ||
1b842c89 DL |
9136 | fb = &intel_fb->base; |
9137 | ||
18c5247e DV |
9138 | if (INTEL_INFO(dev)->gen >= 4) { |
9139 | if (val & DISPPLANE_TILED) { | |
49af449b | 9140 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9141 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9142 | } | |
9143 | } | |
4c6baa59 JB |
9144 | |
9145 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9146 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9147 | fb->pixel_format = fourcc; |
9148 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9149 | |
aeee5a49 | 9150 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9151 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9152 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9153 | } else { |
49af449b | 9154 | if (plane_config->tiling) |
aeee5a49 | 9155 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9156 | else |
aeee5a49 | 9157 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9158 | } |
9159 | plane_config->base = base; | |
9160 | ||
9161 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9162 | fb->width = ((val >> 16) & 0xfff) + 1; |
9163 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9164 | |
9165 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9166 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9167 | |
b113d5ee | 9168 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9169 | fb->pixel_format, |
9170 | fb->modifier[0]); | |
4c6baa59 | 9171 | |
f37b5c2b | 9172 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9173 | |
2844a921 DL |
9174 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9175 | pipe_name(pipe), fb->width, fb->height, | |
9176 | fb->bits_per_pixel, base, fb->pitches[0], | |
9177 | plane_config->size); | |
b113d5ee | 9178 | |
2d14030b | 9179 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9180 | } |
9181 | ||
0e8ffe1b | 9182 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9183 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9184 | { |
9185 | struct drm_device *dev = crtc->base.dev; | |
9186 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9187 | uint32_t tmp; | |
9188 | ||
f458ebbc DV |
9189 | if (!intel_display_power_is_enabled(dev_priv, |
9190 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9191 | return false; |
9192 | ||
e143a21c | 9193 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9194 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9195 | |
0e8ffe1b DV |
9196 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9197 | if (!(tmp & PIPECONF_ENABLE)) | |
9198 | return false; | |
9199 | ||
42571aef VS |
9200 | switch (tmp & PIPECONF_BPC_MASK) { |
9201 | case PIPECONF_6BPC: | |
9202 | pipe_config->pipe_bpp = 18; | |
9203 | break; | |
9204 | case PIPECONF_8BPC: | |
9205 | pipe_config->pipe_bpp = 24; | |
9206 | break; | |
9207 | case PIPECONF_10BPC: | |
9208 | pipe_config->pipe_bpp = 30; | |
9209 | break; | |
9210 | case PIPECONF_12BPC: | |
9211 | pipe_config->pipe_bpp = 36; | |
9212 | break; | |
9213 | default: | |
9214 | break; | |
9215 | } | |
9216 | ||
b5a9fa09 DV |
9217 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9218 | pipe_config->limited_color_range = true; | |
9219 | ||
ab9412ba | 9220 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9221 | struct intel_shared_dpll *pll; |
9222 | ||
88adfff1 DV |
9223 | pipe_config->has_pch_encoder = true; |
9224 | ||
627eb5a3 DV |
9225 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9226 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9227 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9228 | |
9229 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9230 | |
c0d43d62 | 9231 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9232 | pipe_config->shared_dpll = |
9233 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9234 | } else { |
9235 | tmp = I915_READ(PCH_DPLL_SEL); | |
9236 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9237 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9238 | else | |
9239 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9240 | } | |
66e985c0 DV |
9241 | |
9242 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9243 | ||
9244 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9245 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9246 | |
9247 | tmp = pipe_config->dpll_hw_state.dpll; | |
9248 | pipe_config->pixel_multiplier = | |
9249 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9250 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9251 | |
9252 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9253 | } else { |
9254 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9255 | } |
9256 | ||
1bd1bd80 DV |
9257 | intel_get_pipe_timings(crtc, pipe_config); |
9258 | ||
2fa2fe9a DV |
9259 | ironlake_get_pfit_config(crtc, pipe_config); |
9260 | ||
0e8ffe1b DV |
9261 | return true; |
9262 | } | |
9263 | ||
be256dc7 PZ |
9264 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9265 | { | |
9266 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9267 | struct intel_crtc *crtc; |
be256dc7 | 9268 | |
d3fcc808 | 9269 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9270 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9271 | pipe_name(crtc->pipe)); |
9272 | ||
e2c719b7 RC |
9273 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9274 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9275 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9276 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9277 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9278 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9279 | "CPU PWM1 enabled\n"); |
c5107b87 | 9280 | if (IS_HASWELL(dev)) |
e2c719b7 | 9281 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9282 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9283 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9284 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9285 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9286 | "Utility pin enabled\n"); |
e2c719b7 | 9287 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9288 | |
9926ada1 PZ |
9289 | /* |
9290 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9291 | * interrupts remain enabled. We used to check for that, but since it's | |
9292 | * gen-specific and since we only disable LCPLL after we fully disable | |
9293 | * the interrupts, the check below should be enough. | |
9294 | */ | |
e2c719b7 | 9295 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9296 | } |
9297 | ||
9ccd5aeb PZ |
9298 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9299 | { | |
9300 | struct drm_device *dev = dev_priv->dev; | |
9301 | ||
9302 | if (IS_HASWELL(dev)) | |
9303 | return I915_READ(D_COMP_HSW); | |
9304 | else | |
9305 | return I915_READ(D_COMP_BDW); | |
9306 | } | |
9307 | ||
3c4c9b81 PZ |
9308 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9309 | { | |
9310 | struct drm_device *dev = dev_priv->dev; | |
9311 | ||
9312 | if (IS_HASWELL(dev)) { | |
9313 | mutex_lock(&dev_priv->rps.hw_lock); | |
9314 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9315 | val)) | |
f475dadf | 9316 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9317 | mutex_unlock(&dev_priv->rps.hw_lock); |
9318 | } else { | |
9ccd5aeb PZ |
9319 | I915_WRITE(D_COMP_BDW, val); |
9320 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9321 | } |
be256dc7 PZ |
9322 | } |
9323 | ||
9324 | /* | |
9325 | * This function implements pieces of two sequences from BSpec: | |
9326 | * - Sequence for display software to disable LCPLL | |
9327 | * - Sequence for display software to allow package C8+ | |
9328 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9329 | * register. Callers should take care of disabling all the display engine | |
9330 | * functions, doing the mode unset, fixing interrupts, etc. | |
9331 | */ | |
6ff58d53 PZ |
9332 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9333 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9334 | { |
9335 | uint32_t val; | |
9336 | ||
9337 | assert_can_disable_lcpll(dev_priv); | |
9338 | ||
9339 | val = I915_READ(LCPLL_CTL); | |
9340 | ||
9341 | if (switch_to_fclk) { | |
9342 | val |= LCPLL_CD_SOURCE_FCLK; | |
9343 | I915_WRITE(LCPLL_CTL, val); | |
9344 | ||
9345 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9346 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9347 | DRM_ERROR("Switching to FCLK failed\n"); | |
9348 | ||
9349 | val = I915_READ(LCPLL_CTL); | |
9350 | } | |
9351 | ||
9352 | val |= LCPLL_PLL_DISABLE; | |
9353 | I915_WRITE(LCPLL_CTL, val); | |
9354 | POSTING_READ(LCPLL_CTL); | |
9355 | ||
9356 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9357 | DRM_ERROR("LCPLL still locked\n"); | |
9358 | ||
9ccd5aeb | 9359 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9360 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9361 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9362 | ndelay(100); |
9363 | ||
9ccd5aeb PZ |
9364 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9365 | 1)) | |
be256dc7 PZ |
9366 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9367 | ||
9368 | if (allow_power_down) { | |
9369 | val = I915_READ(LCPLL_CTL); | |
9370 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9371 | I915_WRITE(LCPLL_CTL, val); | |
9372 | POSTING_READ(LCPLL_CTL); | |
9373 | } | |
9374 | } | |
9375 | ||
9376 | /* | |
9377 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9378 | * source. | |
9379 | */ | |
6ff58d53 | 9380 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9381 | { |
9382 | uint32_t val; | |
9383 | ||
9384 | val = I915_READ(LCPLL_CTL); | |
9385 | ||
9386 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9387 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9388 | return; | |
9389 | ||
a8a8bd54 PZ |
9390 | /* |
9391 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9392 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9393 | */ |
59bad947 | 9394 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9395 | |
be256dc7 PZ |
9396 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9397 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9398 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9399 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9400 | } |
9401 | ||
9ccd5aeb | 9402 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9403 | val |= D_COMP_COMP_FORCE; |
9404 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9405 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9406 | |
9407 | val = I915_READ(LCPLL_CTL); | |
9408 | val &= ~LCPLL_PLL_DISABLE; | |
9409 | I915_WRITE(LCPLL_CTL, val); | |
9410 | ||
9411 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9412 | DRM_ERROR("LCPLL not locked yet\n"); | |
9413 | ||
9414 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9415 | val = I915_READ(LCPLL_CTL); | |
9416 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9417 | I915_WRITE(LCPLL_CTL, val); | |
9418 | ||
9419 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9420 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9421 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9422 | } | |
215733fa | 9423 | |
59bad947 | 9424 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9425 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9426 | } |
9427 | ||
765dab67 PZ |
9428 | /* |
9429 | * Package states C8 and deeper are really deep PC states that can only be | |
9430 | * reached when all the devices on the system allow it, so even if the graphics | |
9431 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9432 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9433 | * | |
9434 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9435 | * well is disabled and most interrupts are disabled, and these are also | |
9436 | * requirements for runtime PM. When these conditions are met, we manually do | |
9437 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9438 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9439 | * hang the machine. | |
9440 | * | |
9441 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9442 | * the state of some registers, so when we come back from PC8+ we need to | |
9443 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9444 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9445 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9446 | * because of the runtime PM support). | |
9447 | * | |
9448 | * For more, read "Display Sequences for Package C8" on the hardware | |
9449 | * documentation. | |
9450 | */ | |
a14cb6fc | 9451 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9452 | { |
c67a470b PZ |
9453 | struct drm_device *dev = dev_priv->dev; |
9454 | uint32_t val; | |
9455 | ||
c67a470b PZ |
9456 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9457 | ||
c2699524 | 9458 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9459 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9460 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9461 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9462 | } | |
9463 | ||
9464 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9465 | hsw_disable_lcpll(dev_priv, true, true); |
9466 | } | |
9467 | ||
a14cb6fc | 9468 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9469 | { |
9470 | struct drm_device *dev = dev_priv->dev; | |
9471 | uint32_t val; | |
9472 | ||
c67a470b PZ |
9473 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9474 | ||
9475 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9476 | lpt_init_pch_refclk(dev); |
9477 | ||
c2699524 | 9478 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9479 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9480 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9481 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9482 | } | |
9483 | ||
9484 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9485 | } |
9486 | ||
27c329ed | 9487 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9488 | { |
a821fc46 | 9489 | struct drm_device *dev = old_state->dev; |
27c329ed | 9490 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
f8437dd1 | 9491 | |
27c329ed | 9492 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9493 | } |
9494 | ||
b432e5cf | 9495 | /* compute the max rate for new configuration */ |
27c329ed | 9496 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9497 | { |
b432e5cf | 9498 | struct intel_crtc *intel_crtc; |
27c329ed | 9499 | struct intel_crtc_state *crtc_state; |
b432e5cf | 9500 | int max_pixel_rate = 0; |
b432e5cf | 9501 | |
27c329ed ML |
9502 | for_each_intel_crtc(state->dev, intel_crtc) { |
9503 | int pixel_rate; | |
9504 | ||
9505 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
9506 | if (IS_ERR(crtc_state)) | |
9507 | return PTR_ERR(crtc_state); | |
9508 | ||
9509 | if (!crtc_state->base.enable) | |
b432e5cf VS |
9510 | continue; |
9511 | ||
27c329ed | 9512 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9513 | |
9514 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
27c329ed | 9515 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
b432e5cf VS |
9516 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9517 | ||
9518 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9519 | } | |
9520 | ||
9521 | return max_pixel_rate; | |
9522 | } | |
9523 | ||
9524 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9525 | { | |
9526 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9527 | uint32_t val, data; | |
9528 | int ret; | |
9529 | ||
9530 | if (WARN((I915_READ(LCPLL_CTL) & | |
9531 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9532 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9533 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9534 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9535 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9536 | return; | |
9537 | ||
9538 | mutex_lock(&dev_priv->rps.hw_lock); | |
9539 | ret = sandybridge_pcode_write(dev_priv, | |
9540 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9541 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9542 | if (ret) { | |
9543 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9544 | return; | |
9545 | } | |
9546 | ||
9547 | val = I915_READ(LCPLL_CTL); | |
9548 | val |= LCPLL_CD_SOURCE_FCLK; | |
9549 | I915_WRITE(LCPLL_CTL, val); | |
9550 | ||
9551 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9552 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9553 | DRM_ERROR("Switching to FCLK failed\n"); | |
9554 | ||
9555 | val = I915_READ(LCPLL_CTL); | |
9556 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9557 | ||
9558 | switch (cdclk) { | |
9559 | case 450000: | |
9560 | val |= LCPLL_CLK_FREQ_450; | |
9561 | data = 0; | |
9562 | break; | |
9563 | case 540000: | |
9564 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9565 | data = 1; | |
9566 | break; | |
9567 | case 337500: | |
9568 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9569 | data = 2; | |
9570 | break; | |
9571 | case 675000: | |
9572 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9573 | data = 3; | |
9574 | break; | |
9575 | default: | |
9576 | WARN(1, "invalid cdclk frequency\n"); | |
9577 | return; | |
9578 | } | |
9579 | ||
9580 | I915_WRITE(LCPLL_CTL, val); | |
9581 | ||
9582 | val = I915_READ(LCPLL_CTL); | |
9583 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9584 | I915_WRITE(LCPLL_CTL, val); | |
9585 | ||
9586 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9587 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9588 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9589 | ||
9590 | mutex_lock(&dev_priv->rps.hw_lock); | |
9591 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9592 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9593 | ||
9594 | intel_update_cdclk(dev); | |
9595 | ||
9596 | WARN(cdclk != dev_priv->cdclk_freq, | |
9597 | "cdclk requested %d kHz but got %d kHz\n", | |
9598 | cdclk, dev_priv->cdclk_freq); | |
9599 | } | |
9600 | ||
27c329ed | 9601 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9602 | { |
27c329ed ML |
9603 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
9604 | int max_pixclk = ilk_max_pixel_rate(state); | |
b432e5cf VS |
9605 | int cdclk; |
9606 | ||
9607 | /* | |
9608 | * FIXME should also account for plane ratio | |
9609 | * once 64bpp pixel formats are supported. | |
9610 | */ | |
27c329ed | 9611 | if (max_pixclk > 540000) |
b432e5cf | 9612 | cdclk = 675000; |
27c329ed | 9613 | else if (max_pixclk > 450000) |
b432e5cf | 9614 | cdclk = 540000; |
27c329ed | 9615 | else if (max_pixclk > 337500) |
b432e5cf VS |
9616 | cdclk = 450000; |
9617 | else | |
9618 | cdclk = 337500; | |
9619 | ||
9620 | /* | |
9621 | * FIXME move the cdclk caclulation to | |
9622 | * compute_config() so we can fail gracegully. | |
9623 | */ | |
9624 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9625 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9626 | cdclk, dev_priv->max_cdclk_freq); | |
9627 | cdclk = dev_priv->max_cdclk_freq; | |
9628 | } | |
9629 | ||
27c329ed | 9630 | to_intel_atomic_state(state)->cdclk = cdclk; |
b432e5cf VS |
9631 | |
9632 | return 0; | |
9633 | } | |
9634 | ||
27c329ed | 9635 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9636 | { |
27c329ed ML |
9637 | struct drm_device *dev = old_state->dev; |
9638 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; | |
b432e5cf | 9639 | |
27c329ed | 9640 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9641 | } |
9642 | ||
190f68c5 ACO |
9643 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9644 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9645 | { |
190f68c5 | 9646 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9647 | return -EINVAL; |
716c2e55 | 9648 | |
c7653199 | 9649 | crtc->lowfreq_avail = false; |
644cef34 | 9650 | |
c8f7a0db | 9651 | return 0; |
79e53945 JB |
9652 | } |
9653 | ||
3760b59c S |
9654 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9655 | enum port port, | |
9656 | struct intel_crtc_state *pipe_config) | |
9657 | { | |
9658 | switch (port) { | |
9659 | case PORT_A: | |
9660 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9661 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9662 | break; | |
9663 | case PORT_B: | |
9664 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9665 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9666 | break; | |
9667 | case PORT_C: | |
9668 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9669 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9670 | break; | |
9671 | default: | |
9672 | DRM_ERROR("Incorrect port type\n"); | |
9673 | } | |
9674 | } | |
9675 | ||
96b7dfb7 S |
9676 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9677 | enum port port, | |
5cec258b | 9678 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9679 | { |
3148ade7 | 9680 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9681 | |
9682 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9683 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9684 | ||
9685 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9686 | case SKL_DPLL0: |
9687 | /* | |
9688 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9689 | * of the shared DPLL framework and thus needs to be read out | |
9690 | * separately | |
9691 | */ | |
9692 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9693 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9694 | break; | |
96b7dfb7 S |
9695 | case SKL_DPLL1: |
9696 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9697 | break; | |
9698 | case SKL_DPLL2: | |
9699 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9700 | break; | |
9701 | case SKL_DPLL3: | |
9702 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9703 | break; | |
96b7dfb7 S |
9704 | } |
9705 | } | |
9706 | ||
7d2c8175 DL |
9707 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9708 | enum port port, | |
5cec258b | 9709 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9710 | { |
9711 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9712 | ||
9713 | switch (pipe_config->ddi_pll_sel) { | |
9714 | case PORT_CLK_SEL_WRPLL1: | |
9715 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9716 | break; | |
9717 | case PORT_CLK_SEL_WRPLL2: | |
9718 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9719 | break; | |
9720 | } | |
9721 | } | |
9722 | ||
26804afd | 9723 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9724 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9725 | { |
9726 | struct drm_device *dev = crtc->base.dev; | |
9727 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9728 | struct intel_shared_dpll *pll; |
26804afd DV |
9729 | enum port port; |
9730 | uint32_t tmp; | |
9731 | ||
9732 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9733 | ||
9734 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9735 | ||
ef11bdb3 | 9736 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 9737 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
9738 | else if (IS_BROXTON(dev)) |
9739 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9740 | else |
9741 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9742 | |
d452c5b6 DV |
9743 | if (pipe_config->shared_dpll >= 0) { |
9744 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9745 | ||
9746 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9747 | &pipe_config->dpll_hw_state)); | |
9748 | } | |
9749 | ||
26804afd DV |
9750 | /* |
9751 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9752 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9753 | * the PCH transcoder is on. | |
9754 | */ | |
ca370455 DL |
9755 | if (INTEL_INFO(dev)->gen < 9 && |
9756 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9757 | pipe_config->has_pch_encoder = true; |
9758 | ||
9759 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9760 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9761 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9762 | ||
9763 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9764 | } | |
9765 | } | |
9766 | ||
0e8ffe1b | 9767 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9768 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9769 | { |
9770 | struct drm_device *dev = crtc->base.dev; | |
9771 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9772 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9773 | uint32_t tmp; |
9774 | ||
f458ebbc | 9775 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9776 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9777 | return false; | |
9778 | ||
e143a21c | 9779 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9780 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9781 | ||
eccb140b DV |
9782 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9783 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9784 | enum pipe trans_edp_pipe; | |
9785 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9786 | default: | |
9787 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9788 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9789 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9790 | trans_edp_pipe = PIPE_A; | |
9791 | break; | |
9792 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9793 | trans_edp_pipe = PIPE_B; | |
9794 | break; | |
9795 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9796 | trans_edp_pipe = PIPE_C; | |
9797 | break; | |
9798 | } | |
9799 | ||
9800 | if (trans_edp_pipe == crtc->pipe) | |
9801 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9802 | } | |
9803 | ||
f458ebbc | 9804 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9805 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9806 | return false; |
9807 | ||
eccb140b | 9808 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9809 | if (!(tmp & PIPECONF_ENABLE)) |
9810 | return false; | |
9811 | ||
26804afd | 9812 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9813 | |
1bd1bd80 DV |
9814 | intel_get_pipe_timings(crtc, pipe_config); |
9815 | ||
a1b2278e CK |
9816 | if (INTEL_INFO(dev)->gen >= 9) { |
9817 | skl_init_scalers(dev, crtc, pipe_config); | |
9818 | } | |
9819 | ||
2fa2fe9a | 9820 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9821 | |
9822 | if (INTEL_INFO(dev)->gen >= 9) { | |
9823 | pipe_config->scaler_state.scaler_id = -1; | |
9824 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9825 | } | |
9826 | ||
bd2e244f | 9827 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
1c132b44 | 9828 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 9829 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9830 | else |
1c132b44 | 9831 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 9832 | } |
88adfff1 | 9833 | |
e59150dc JB |
9834 | if (IS_HASWELL(dev)) |
9835 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9836 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9837 | |
ebb69c95 CT |
9838 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9839 | pipe_config->pixel_multiplier = | |
9840 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9841 | } else { | |
9842 | pipe_config->pixel_multiplier = 1; | |
9843 | } | |
6c49f241 | 9844 | |
0e8ffe1b DV |
9845 | return true; |
9846 | } | |
9847 | ||
560b85bb CW |
9848 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9849 | { | |
9850 | struct drm_device *dev = crtc->dev; | |
9851 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9852 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9853 | uint32_t cntl = 0, size = 0; |
560b85bb | 9854 | |
dc41c154 | 9855 | if (base) { |
3dd512fb MR |
9856 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9857 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9858 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9859 | ||
9860 | switch (stride) { | |
9861 | default: | |
9862 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9863 | width, stride); | |
9864 | stride = 256; | |
9865 | /* fallthrough */ | |
9866 | case 256: | |
9867 | case 512: | |
9868 | case 1024: | |
9869 | case 2048: | |
9870 | break; | |
4b0e333e CW |
9871 | } |
9872 | ||
dc41c154 VS |
9873 | cntl |= CURSOR_ENABLE | |
9874 | CURSOR_GAMMA_ENABLE | | |
9875 | CURSOR_FORMAT_ARGB | | |
9876 | CURSOR_STRIDE(stride); | |
9877 | ||
9878 | size = (height << 12) | width; | |
4b0e333e | 9879 | } |
560b85bb | 9880 | |
dc41c154 VS |
9881 | if (intel_crtc->cursor_cntl != 0 && |
9882 | (intel_crtc->cursor_base != base || | |
9883 | intel_crtc->cursor_size != size || | |
9884 | intel_crtc->cursor_cntl != cntl)) { | |
9885 | /* On these chipsets we can only modify the base/size/stride | |
9886 | * whilst the cursor is disabled. | |
9887 | */ | |
0b87c24e VS |
9888 | I915_WRITE(CURCNTR(PIPE_A), 0); |
9889 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 9890 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9891 | } |
560b85bb | 9892 | |
99d1f387 | 9893 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 9894 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
9895 | intel_crtc->cursor_base = base; |
9896 | } | |
4726e0b0 | 9897 | |
dc41c154 VS |
9898 | if (intel_crtc->cursor_size != size) { |
9899 | I915_WRITE(CURSIZE, size); | |
9900 | intel_crtc->cursor_size = size; | |
4b0e333e | 9901 | } |
560b85bb | 9902 | |
4b0e333e | 9903 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
9904 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
9905 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 9906 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 9907 | } |
560b85bb CW |
9908 | } |
9909 | ||
560b85bb | 9910 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
9911 | { |
9912 | struct drm_device *dev = crtc->dev; | |
9913 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9914 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9915 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
9916 | uint32_t cntl; |
9917 | ||
9918 | cntl = 0; | |
9919 | if (base) { | |
9920 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 9921 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
9922 | case 64: |
9923 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9924 | break; | |
9925 | case 128: | |
9926 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9927 | break; | |
9928 | case 256: | |
9929 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
9930 | break; | |
9931 | default: | |
3dd512fb | 9932 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 9933 | return; |
65a21cd6 | 9934 | } |
4b0e333e | 9935 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 9936 | |
fc6f93bc | 9937 | if (HAS_DDI(dev)) |
47bf17a7 | 9938 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
4b0e333e | 9939 | } |
65a21cd6 | 9940 | |
8e7d688b | 9941 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
9942 | cntl |= CURSOR_ROTATE_180; |
9943 | ||
4b0e333e CW |
9944 | if (intel_crtc->cursor_cntl != cntl) { |
9945 | I915_WRITE(CURCNTR(pipe), cntl); | |
9946 | POSTING_READ(CURCNTR(pipe)); | |
9947 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 9948 | } |
4b0e333e | 9949 | |
65a21cd6 | 9950 | /* and commit changes on next vblank */ |
5efb3e28 VS |
9951 | I915_WRITE(CURBASE(pipe), base); |
9952 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
9953 | |
9954 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
9955 | } |
9956 | ||
cda4b7d3 | 9957 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
9958 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
9959 | bool on) | |
cda4b7d3 CW |
9960 | { |
9961 | struct drm_device *dev = crtc->dev; | |
9962 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9963 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9964 | int pipe = intel_crtc->pipe; | |
9b4101be ML |
9965 | struct drm_plane_state *cursor_state = crtc->cursor->state; |
9966 | int x = cursor_state->crtc_x; | |
9967 | int y = cursor_state->crtc_y; | |
d6e4db15 | 9968 | u32 base = 0, pos = 0; |
cda4b7d3 | 9969 | |
d6e4db15 | 9970 | if (on) |
cda4b7d3 | 9971 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 9972 | |
6e3c9717 | 9973 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
9974 | base = 0; |
9975 | ||
6e3c9717 | 9976 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
9977 | base = 0; |
9978 | ||
9979 | if (x < 0) { | |
9b4101be | 9980 | if (x + cursor_state->crtc_w <= 0) |
cda4b7d3 CW |
9981 | base = 0; |
9982 | ||
9983 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
9984 | x = -x; | |
9985 | } | |
9986 | pos |= x << CURSOR_X_SHIFT; | |
9987 | ||
9988 | if (y < 0) { | |
9b4101be | 9989 | if (y + cursor_state->crtc_h <= 0) |
cda4b7d3 CW |
9990 | base = 0; |
9991 | ||
9992 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
9993 | y = -y; | |
9994 | } | |
9995 | pos |= y << CURSOR_Y_SHIFT; | |
9996 | ||
4b0e333e | 9997 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
9998 | return; |
9999 | ||
5efb3e28 VS |
10000 | I915_WRITE(CURPOS(pipe), pos); |
10001 | ||
4398ad45 VS |
10002 | /* ILK+ do this automagically */ |
10003 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 10004 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
9b4101be ML |
10005 | base += (cursor_state->crtc_h * |
10006 | cursor_state->crtc_w - 1) * 4; | |
4398ad45 VS |
10007 | } |
10008 | ||
8ac54669 | 10009 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10010 | i845_update_cursor(crtc, base); |
10011 | else | |
10012 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10013 | } |
10014 | ||
dc41c154 VS |
10015 | static bool cursor_size_ok(struct drm_device *dev, |
10016 | uint32_t width, uint32_t height) | |
10017 | { | |
10018 | if (width == 0 || height == 0) | |
10019 | return false; | |
10020 | ||
10021 | /* | |
10022 | * 845g/865g are special in that they are only limited by | |
10023 | * the width of their cursors, the height is arbitrary up to | |
10024 | * the precision of the register. Everything else requires | |
10025 | * square cursors, limited to a few power-of-two sizes. | |
10026 | */ | |
10027 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10028 | if ((width & 63) != 0) | |
10029 | return false; | |
10030 | ||
10031 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10032 | return false; | |
10033 | ||
10034 | if (height > 1023) | |
10035 | return false; | |
10036 | } else { | |
10037 | switch (width | height) { | |
10038 | case 256: | |
10039 | case 128: | |
10040 | if (IS_GEN2(dev)) | |
10041 | return false; | |
10042 | case 64: | |
10043 | break; | |
10044 | default: | |
10045 | return false; | |
10046 | } | |
10047 | } | |
10048 | ||
10049 | return true; | |
10050 | } | |
10051 | ||
79e53945 | 10052 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10053 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10054 | { |
7203425a | 10055 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10056 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10057 | |
7203425a | 10058 | for (i = start; i < end; i++) { |
79e53945 JB |
10059 | intel_crtc->lut_r[i] = red[i] >> 8; |
10060 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10061 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10062 | } | |
10063 | ||
10064 | intel_crtc_load_lut(crtc); | |
10065 | } | |
10066 | ||
79e53945 JB |
10067 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10068 | static struct drm_display_mode load_detect_mode = { | |
10069 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10070 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10071 | }; | |
10072 | ||
a8bb6818 DV |
10073 | struct drm_framebuffer * |
10074 | __intel_framebuffer_create(struct drm_device *dev, | |
10075 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10076 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10077 | { |
10078 | struct intel_framebuffer *intel_fb; | |
10079 | int ret; | |
10080 | ||
10081 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10082 | if (!intel_fb) |
d2dff872 | 10083 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10084 | |
10085 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10086 | if (ret) |
10087 | goto err; | |
d2dff872 CW |
10088 | |
10089 | return &intel_fb->base; | |
dcb1394e | 10090 | |
dd4916c5 | 10091 | err: |
dd4916c5 | 10092 | kfree(intel_fb); |
dd4916c5 | 10093 | return ERR_PTR(ret); |
d2dff872 CW |
10094 | } |
10095 | ||
b5ea642a | 10096 | static struct drm_framebuffer * |
a8bb6818 DV |
10097 | intel_framebuffer_create(struct drm_device *dev, |
10098 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10099 | struct drm_i915_gem_object *obj) | |
10100 | { | |
10101 | struct drm_framebuffer *fb; | |
10102 | int ret; | |
10103 | ||
10104 | ret = i915_mutex_lock_interruptible(dev); | |
10105 | if (ret) | |
10106 | return ERR_PTR(ret); | |
10107 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10108 | mutex_unlock(&dev->struct_mutex); | |
10109 | ||
10110 | return fb; | |
10111 | } | |
10112 | ||
d2dff872 CW |
10113 | static u32 |
10114 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10115 | { | |
10116 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10117 | return ALIGN(pitch, 64); | |
10118 | } | |
10119 | ||
10120 | static u32 | |
10121 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10122 | { | |
10123 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10124 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10125 | } |
10126 | ||
10127 | static struct drm_framebuffer * | |
10128 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10129 | struct drm_display_mode *mode, | |
10130 | int depth, int bpp) | |
10131 | { | |
dcb1394e | 10132 | struct drm_framebuffer *fb; |
d2dff872 | 10133 | struct drm_i915_gem_object *obj; |
0fed39bd | 10134 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10135 | |
10136 | obj = i915_gem_alloc_object(dev, | |
10137 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10138 | if (obj == NULL) | |
10139 | return ERR_PTR(-ENOMEM); | |
10140 | ||
10141 | mode_cmd.width = mode->hdisplay; | |
10142 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10143 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10144 | bpp); | |
5ca0c34a | 10145 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10146 | |
dcb1394e LW |
10147 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10148 | if (IS_ERR(fb)) | |
10149 | drm_gem_object_unreference_unlocked(&obj->base); | |
10150 | ||
10151 | return fb; | |
d2dff872 CW |
10152 | } |
10153 | ||
10154 | static struct drm_framebuffer * | |
10155 | mode_fits_in_fbdev(struct drm_device *dev, | |
10156 | struct drm_display_mode *mode) | |
10157 | { | |
0695726e | 10158 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10159 | struct drm_i915_private *dev_priv = dev->dev_private; |
10160 | struct drm_i915_gem_object *obj; | |
10161 | struct drm_framebuffer *fb; | |
10162 | ||
4c0e5528 | 10163 | if (!dev_priv->fbdev) |
d2dff872 CW |
10164 | return NULL; |
10165 | ||
4c0e5528 | 10166 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10167 | return NULL; |
10168 | ||
4c0e5528 DV |
10169 | obj = dev_priv->fbdev->fb->obj; |
10170 | BUG_ON(!obj); | |
10171 | ||
8bcd4553 | 10172 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10173 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10174 | fb->bits_per_pixel)) | |
d2dff872 CW |
10175 | return NULL; |
10176 | ||
01f2c773 | 10177 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10178 | return NULL; |
10179 | ||
10180 | return fb; | |
4520f53a DV |
10181 | #else |
10182 | return NULL; | |
10183 | #endif | |
d2dff872 CW |
10184 | } |
10185 | ||
d3a40d1b ACO |
10186 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10187 | struct drm_crtc *crtc, | |
10188 | struct drm_display_mode *mode, | |
10189 | struct drm_framebuffer *fb, | |
10190 | int x, int y) | |
10191 | { | |
10192 | struct drm_plane_state *plane_state; | |
10193 | int hdisplay, vdisplay; | |
10194 | int ret; | |
10195 | ||
10196 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10197 | if (IS_ERR(plane_state)) | |
10198 | return PTR_ERR(plane_state); | |
10199 | ||
10200 | if (mode) | |
10201 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10202 | else | |
10203 | hdisplay = vdisplay = 0; | |
10204 | ||
10205 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10206 | if (ret) | |
10207 | return ret; | |
10208 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10209 | plane_state->crtc_x = 0; | |
10210 | plane_state->crtc_y = 0; | |
10211 | plane_state->crtc_w = hdisplay; | |
10212 | plane_state->crtc_h = vdisplay; | |
10213 | plane_state->src_x = x << 16; | |
10214 | plane_state->src_y = y << 16; | |
10215 | plane_state->src_w = hdisplay << 16; | |
10216 | plane_state->src_h = vdisplay << 16; | |
10217 | ||
10218 | return 0; | |
10219 | } | |
10220 | ||
d2434ab7 | 10221 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10222 | struct drm_display_mode *mode, |
51fd371b RC |
10223 | struct intel_load_detect_pipe *old, |
10224 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10225 | { |
10226 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10227 | struct intel_encoder *intel_encoder = |
10228 | intel_attached_encoder(connector); | |
79e53945 | 10229 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10230 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10231 | struct drm_crtc *crtc = NULL; |
10232 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10233 | struct drm_framebuffer *fb; |
51fd371b | 10234 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10235 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10236 | struct drm_connector_state *connector_state; |
4be07317 | 10237 | struct intel_crtc_state *crtc_state; |
51fd371b | 10238 | int ret, i = -1; |
79e53945 | 10239 | |
d2dff872 | 10240 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10241 | connector->base.id, connector->name, |
8e329a03 | 10242 | encoder->base.id, encoder->name); |
d2dff872 | 10243 | |
51fd371b RC |
10244 | retry: |
10245 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10246 | if (ret) | |
ad3c558f | 10247 | goto fail; |
6e9f798d | 10248 | |
79e53945 JB |
10249 | /* |
10250 | * Algorithm gets a little messy: | |
7a5e4805 | 10251 | * |
79e53945 JB |
10252 | * - if the connector already has an assigned crtc, use it (but make |
10253 | * sure it's on first) | |
7a5e4805 | 10254 | * |
79e53945 JB |
10255 | * - try to find the first unused crtc that can drive this connector, |
10256 | * and use that if we find one | |
79e53945 JB |
10257 | */ |
10258 | ||
10259 | /* See if we already have a CRTC for this connector */ | |
10260 | if (encoder->crtc) { | |
10261 | crtc = encoder->crtc; | |
8261b191 | 10262 | |
51fd371b | 10263 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10264 | if (ret) |
ad3c558f | 10265 | goto fail; |
4d02e2de | 10266 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
51fd371b | 10267 | if (ret) |
ad3c558f | 10268 | goto fail; |
7b24056b | 10269 | |
24218aac | 10270 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10271 | old->load_detect_temp = false; |
10272 | ||
10273 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10274 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10275 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10276 | |
7173188d | 10277 | return true; |
79e53945 JB |
10278 | } |
10279 | ||
10280 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10281 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10282 | i++; |
10283 | if (!(encoder->possible_crtcs & (1 << i))) | |
10284 | continue; | |
83d65738 | 10285 | if (possible_crtc->state->enable) |
a459249c | 10286 | continue; |
a459249c VS |
10287 | |
10288 | crtc = possible_crtc; | |
10289 | break; | |
79e53945 JB |
10290 | } |
10291 | ||
10292 | /* | |
10293 | * If we didn't find an unused CRTC, don't use any. | |
10294 | */ | |
10295 | if (!crtc) { | |
7173188d | 10296 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10297 | goto fail; |
79e53945 JB |
10298 | } |
10299 | ||
51fd371b RC |
10300 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10301 | if (ret) | |
ad3c558f | 10302 | goto fail; |
4d02e2de DV |
10303 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10304 | if (ret) | |
ad3c558f | 10305 | goto fail; |
79e53945 JB |
10306 | |
10307 | intel_crtc = to_intel_crtc(crtc); | |
24218aac | 10308 | old->dpms_mode = connector->dpms; |
8261b191 | 10309 | old->load_detect_temp = true; |
d2dff872 | 10310 | old->release_fb = NULL; |
79e53945 | 10311 | |
83a57153 ACO |
10312 | state = drm_atomic_state_alloc(dev); |
10313 | if (!state) | |
10314 | return false; | |
10315 | ||
10316 | state->acquire_ctx = ctx; | |
10317 | ||
944b0c76 ACO |
10318 | connector_state = drm_atomic_get_connector_state(state, connector); |
10319 | if (IS_ERR(connector_state)) { | |
10320 | ret = PTR_ERR(connector_state); | |
10321 | goto fail; | |
10322 | } | |
10323 | ||
10324 | connector_state->crtc = crtc; | |
10325 | connector_state->best_encoder = &intel_encoder->base; | |
10326 | ||
4be07317 ACO |
10327 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10328 | if (IS_ERR(crtc_state)) { | |
10329 | ret = PTR_ERR(crtc_state); | |
10330 | goto fail; | |
10331 | } | |
10332 | ||
49d6fa21 | 10333 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10334 | |
6492711d CW |
10335 | if (!mode) |
10336 | mode = &load_detect_mode; | |
79e53945 | 10337 | |
d2dff872 CW |
10338 | /* We need a framebuffer large enough to accommodate all accesses |
10339 | * that the plane may generate whilst we perform load detection. | |
10340 | * We can not rely on the fbcon either being present (we get called | |
10341 | * during its initialisation to detect all boot displays, or it may | |
10342 | * not even exist) or that it is large enough to satisfy the | |
10343 | * requested mode. | |
10344 | */ | |
94352cf9 DV |
10345 | fb = mode_fits_in_fbdev(dev, mode); |
10346 | if (fb == NULL) { | |
d2dff872 | 10347 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10348 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10349 | old->release_fb = fb; | |
d2dff872 CW |
10350 | } else |
10351 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10352 | if (IS_ERR(fb)) { |
d2dff872 | 10353 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10354 | goto fail; |
79e53945 | 10355 | } |
79e53945 | 10356 | |
d3a40d1b ACO |
10357 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10358 | if (ret) | |
10359 | goto fail; | |
10360 | ||
8c7b5ccb ACO |
10361 | drm_mode_copy(&crtc_state->base.mode, mode); |
10362 | ||
74c090b1 | 10363 | if (drm_atomic_commit(state)) { |
6492711d | 10364 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10365 | if (old->release_fb) |
10366 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10367 | goto fail; |
79e53945 | 10368 | } |
9128b040 | 10369 | crtc->primary->crtc = crtc; |
7173188d | 10370 | |
79e53945 | 10371 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10372 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10373 | return true; |
412b61d8 | 10374 | |
ad3c558f | 10375 | fail: |
e5d958ef ACO |
10376 | drm_atomic_state_free(state); |
10377 | state = NULL; | |
83a57153 | 10378 | |
51fd371b RC |
10379 | if (ret == -EDEADLK) { |
10380 | drm_modeset_backoff(ctx); | |
10381 | goto retry; | |
10382 | } | |
10383 | ||
412b61d8 | 10384 | return false; |
79e53945 JB |
10385 | } |
10386 | ||
d2434ab7 | 10387 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10388 | struct intel_load_detect_pipe *old, |
10389 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10390 | { |
83a57153 | 10391 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10392 | struct intel_encoder *intel_encoder = |
10393 | intel_attached_encoder(connector); | |
4ef69c7a | 10394 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10395 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10396 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10397 | struct drm_atomic_state *state; |
944b0c76 | 10398 | struct drm_connector_state *connector_state; |
4be07317 | 10399 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10400 | int ret; |
79e53945 | 10401 | |
d2dff872 | 10402 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10403 | connector->base.id, connector->name, |
8e329a03 | 10404 | encoder->base.id, encoder->name); |
d2dff872 | 10405 | |
8261b191 | 10406 | if (old->load_detect_temp) { |
83a57153 | 10407 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10408 | if (!state) |
10409 | goto fail; | |
83a57153 ACO |
10410 | |
10411 | state->acquire_ctx = ctx; | |
10412 | ||
944b0c76 ACO |
10413 | connector_state = drm_atomic_get_connector_state(state, connector); |
10414 | if (IS_ERR(connector_state)) | |
10415 | goto fail; | |
10416 | ||
4be07317 ACO |
10417 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10418 | if (IS_ERR(crtc_state)) | |
10419 | goto fail; | |
10420 | ||
944b0c76 ACO |
10421 | connector_state->best_encoder = NULL; |
10422 | connector_state->crtc = NULL; | |
10423 | ||
49d6fa21 | 10424 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10425 | |
d3a40d1b ACO |
10426 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10427 | 0, 0); | |
10428 | if (ret) | |
10429 | goto fail; | |
10430 | ||
74c090b1 | 10431 | ret = drm_atomic_commit(state); |
2bfb4627 ACO |
10432 | if (ret) |
10433 | goto fail; | |
d2dff872 | 10434 | |
36206361 DV |
10435 | if (old->release_fb) { |
10436 | drm_framebuffer_unregister_private(old->release_fb); | |
10437 | drm_framebuffer_unreference(old->release_fb); | |
10438 | } | |
d2dff872 | 10439 | |
0622a53c | 10440 | return; |
79e53945 JB |
10441 | } |
10442 | ||
c751ce4f | 10443 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10444 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10445 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10446 | |
10447 | return; | |
10448 | fail: | |
10449 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10450 | drm_atomic_state_free(state); | |
79e53945 JB |
10451 | } |
10452 | ||
da4a1efa | 10453 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10454 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10455 | { |
10456 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10457 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10458 | ||
10459 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10460 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10461 | else if (HAS_PCH_SPLIT(dev)) |
10462 | return 120000; | |
10463 | else if (!IS_GEN2(dev)) | |
10464 | return 96000; | |
10465 | else | |
10466 | return 48000; | |
10467 | } | |
10468 | ||
79e53945 | 10469 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10470 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10471 | struct intel_crtc_state *pipe_config) |
79e53945 | 10472 | { |
f1f644dc | 10473 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10474 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10475 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10476 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10477 | u32 fp; |
10478 | intel_clock_t clock; | |
dccbea3b | 10479 | int port_clock; |
da4a1efa | 10480 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10481 | |
10482 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10483 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10484 | else |
293623f7 | 10485 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10486 | |
10487 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10488 | if (IS_PINEVIEW(dev)) { |
10489 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10490 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10491 | } else { |
10492 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10493 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10494 | } | |
10495 | ||
a6c45cf0 | 10496 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10497 | if (IS_PINEVIEW(dev)) |
10498 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10499 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10500 | else |
10501 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10502 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10503 | ||
10504 | switch (dpll & DPLL_MODE_MASK) { | |
10505 | case DPLLB_MODE_DAC_SERIAL: | |
10506 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10507 | 5 : 10; | |
10508 | break; | |
10509 | case DPLLB_MODE_LVDS: | |
10510 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10511 | 7 : 14; | |
10512 | break; | |
10513 | default: | |
28c97730 | 10514 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10515 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10516 | return; |
79e53945 JB |
10517 | } |
10518 | ||
ac58c3f0 | 10519 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10520 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10521 | else |
dccbea3b | 10522 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10523 | } else { |
0fb58223 | 10524 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10525 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10526 | |
10527 | if (is_lvds) { | |
10528 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10529 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10530 | |
10531 | if (lvds & LVDS_CLKB_POWER_UP) | |
10532 | clock.p2 = 7; | |
10533 | else | |
10534 | clock.p2 = 14; | |
79e53945 JB |
10535 | } else { |
10536 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10537 | clock.p1 = 2; | |
10538 | else { | |
10539 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10540 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10541 | } | |
10542 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10543 | clock.p2 = 4; | |
10544 | else | |
10545 | clock.p2 = 2; | |
79e53945 | 10546 | } |
da4a1efa | 10547 | |
dccbea3b | 10548 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10549 | } |
10550 | ||
18442d08 VS |
10551 | /* |
10552 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10553 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10554 | * encoder's get_config() function. |
10555 | */ | |
dccbea3b | 10556 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10557 | } |
10558 | ||
6878da05 VS |
10559 | int intel_dotclock_calculate(int link_freq, |
10560 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10561 | { |
f1f644dc JB |
10562 | /* |
10563 | * The calculation for the data clock is: | |
1041a02f | 10564 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10565 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10566 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10567 | * |
10568 | * and the link clock is simpler: | |
1041a02f | 10569 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10570 | */ |
10571 | ||
6878da05 VS |
10572 | if (!m_n->link_n) |
10573 | return 0; | |
f1f644dc | 10574 | |
6878da05 VS |
10575 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10576 | } | |
f1f644dc | 10577 | |
18442d08 | 10578 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10579 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10580 | { |
10581 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10582 | |
18442d08 VS |
10583 | /* read out port_clock from the DPLL */ |
10584 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10585 | |
f1f644dc | 10586 | /* |
18442d08 | 10587 | * This value does not include pixel_multiplier. |
241bfc38 | 10588 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10589 | * agree once we know their relationship in the encoder's |
10590 | * get_config() function. | |
79e53945 | 10591 | */ |
2d112de7 | 10592 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10593 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10594 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10595 | } |
10596 | ||
10597 | /** Returns the currently programmed mode of the given pipe. */ | |
10598 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10599 | struct drm_crtc *crtc) | |
10600 | { | |
548f245b | 10601 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10602 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10603 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10604 | struct drm_display_mode *mode; |
5cec258b | 10605 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10606 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10607 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10608 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10609 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10610 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10611 | |
10612 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10613 | if (!mode) | |
10614 | return NULL; | |
10615 | ||
f1f644dc JB |
10616 | /* |
10617 | * Construct a pipe_config sufficient for getting the clock info | |
10618 | * back out of crtc_clock_get. | |
10619 | * | |
10620 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10621 | * to use a real value here instead. | |
10622 | */ | |
293623f7 | 10623 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10624 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10625 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10626 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10627 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10628 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10629 | ||
773ae034 | 10630 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10631 | mode->hdisplay = (htot & 0xffff) + 1; |
10632 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10633 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10634 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10635 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10636 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10637 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10638 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10639 | ||
10640 | drm_mode_set_name(mode); | |
79e53945 JB |
10641 | |
10642 | return mode; | |
10643 | } | |
10644 | ||
f047e395 CW |
10645 | void intel_mark_busy(struct drm_device *dev) |
10646 | { | |
c67a470b PZ |
10647 | struct drm_i915_private *dev_priv = dev->dev_private; |
10648 | ||
f62a0076 CW |
10649 | if (dev_priv->mm.busy) |
10650 | return; | |
10651 | ||
43694d69 | 10652 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10653 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10654 | if (INTEL_INFO(dev)->gen >= 6) |
10655 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10656 | dev_priv->mm.busy = true; |
f047e395 CW |
10657 | } |
10658 | ||
10659 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10660 | { |
c67a470b | 10661 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10662 | |
f62a0076 CW |
10663 | if (!dev_priv->mm.busy) |
10664 | return; | |
10665 | ||
10666 | dev_priv->mm.busy = false; | |
10667 | ||
3d13ef2e | 10668 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10669 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10670 | |
43694d69 | 10671 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10672 | } |
10673 | ||
79e53945 JB |
10674 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10675 | { | |
10676 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10677 | struct drm_device *dev = crtc->dev; |
10678 | struct intel_unpin_work *work; | |
67e77c5a | 10679 | |
5e2d7afc | 10680 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10681 | work = intel_crtc->unpin_work; |
10682 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10683 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10684 | |
10685 | if (work) { | |
10686 | cancel_work_sync(&work->work); | |
10687 | kfree(work); | |
10688 | } | |
79e53945 JB |
10689 | |
10690 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10691 | |
79e53945 JB |
10692 | kfree(intel_crtc); |
10693 | } | |
10694 | ||
6b95a207 KH |
10695 | static void intel_unpin_work_fn(struct work_struct *__work) |
10696 | { | |
10697 | struct intel_unpin_work *work = | |
10698 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10699 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10700 | struct drm_device *dev = crtc->base.dev; | |
10701 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10702 | |
b4a98e57 | 10703 | mutex_lock(&dev->struct_mutex); |
a9ff8714 | 10704 | intel_unpin_fb_obj(work->old_fb, primary->state); |
05394f39 | 10705 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10706 | |
f06cc1b9 | 10707 | if (work->flip_queued_req) |
146d84f0 | 10708 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10709 | mutex_unlock(&dev->struct_mutex); |
10710 | ||
a9ff8714 | 10711 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
89ed88ba | 10712 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10713 | |
a9ff8714 VS |
10714 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10715 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10716 | |
6b95a207 KH |
10717 | kfree(work); |
10718 | } | |
10719 | ||
1afe3e9d | 10720 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10721 | struct drm_crtc *crtc) |
6b95a207 | 10722 | { |
6b95a207 KH |
10723 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10724 | struct intel_unpin_work *work; | |
6b95a207 KH |
10725 | unsigned long flags; |
10726 | ||
10727 | /* Ignore early vblank irqs */ | |
10728 | if (intel_crtc == NULL) | |
10729 | return; | |
10730 | ||
f326038a DV |
10731 | /* |
10732 | * This is called both by irq handlers and the reset code (to complete | |
10733 | * lost pageflips) so needs the full irqsave spinlocks. | |
10734 | */ | |
6b95a207 KH |
10735 | spin_lock_irqsave(&dev->event_lock, flags); |
10736 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10737 | |
10738 | /* Ensure we don't miss a work->pending update ... */ | |
10739 | smp_rmb(); | |
10740 | ||
10741 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10742 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10743 | return; | |
10744 | } | |
10745 | ||
d6bbafa1 | 10746 | page_flip_completed(intel_crtc); |
0af7e4df | 10747 | |
6b95a207 | 10748 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10749 | } |
10750 | ||
1afe3e9d JB |
10751 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10752 | { | |
fbee40df | 10753 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10754 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10755 | ||
49b14a5c | 10756 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10757 | } |
10758 | ||
10759 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10760 | { | |
fbee40df | 10761 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10762 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10763 | ||
49b14a5c | 10764 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10765 | } |
10766 | ||
75f7f3ec VS |
10767 | /* Is 'a' after or equal to 'b'? */ |
10768 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10769 | { | |
10770 | return !((a - b) & 0x80000000); | |
10771 | } | |
10772 | ||
10773 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10774 | { | |
10775 | struct drm_device *dev = crtc->base.dev; | |
10776 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10777 | ||
bdfa7542 VS |
10778 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10779 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10780 | return true; | |
10781 | ||
75f7f3ec VS |
10782 | /* |
10783 | * The relevant registers doen't exist on pre-ctg. | |
10784 | * As the flip done interrupt doesn't trigger for mmio | |
10785 | * flips on gmch platforms, a flip count check isn't | |
10786 | * really needed there. But since ctg has the registers, | |
10787 | * include it in the check anyway. | |
10788 | */ | |
10789 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10790 | return true; | |
10791 | ||
10792 | /* | |
10793 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10794 | * used the same base address. In that case the mmio flip might | |
10795 | * have completed, but the CS hasn't even executed the flip yet. | |
10796 | * | |
10797 | * A flip count check isn't enough as the CS might have updated | |
10798 | * the base address just after start of vblank, but before we | |
10799 | * managed to process the interrupt. This means we'd complete the | |
10800 | * CS flip too soon. | |
10801 | * | |
10802 | * Combining both checks should get us a good enough result. It may | |
10803 | * still happen that the CS flip has been executed, but has not | |
10804 | * yet actually completed. But in case the base address is the same | |
10805 | * anyway, we don't really care. | |
10806 | */ | |
10807 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10808 | crtc->unpin_work->gtt_offset && | |
fd8f507c | 10809 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
75f7f3ec VS |
10810 | crtc->unpin_work->flip_count); |
10811 | } | |
10812 | ||
6b95a207 KH |
10813 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10814 | { | |
fbee40df | 10815 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10816 | struct intel_crtc *intel_crtc = |
10817 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10818 | unsigned long flags; | |
10819 | ||
f326038a DV |
10820 | |
10821 | /* | |
10822 | * This is called both by irq handlers and the reset code (to complete | |
10823 | * lost pageflips) so needs the full irqsave spinlocks. | |
10824 | * | |
10825 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10826 | * generate a page-flip completion irq, i.e. every modeset |
10827 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10828 | */ | |
6b95a207 | 10829 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10830 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10831 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10832 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10833 | } | |
10834 | ||
6042639c | 10835 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
e7d841ca CW |
10836 | { |
10837 | /* Ensure that the work item is consistent when activating it ... */ | |
10838 | smp_wmb(); | |
6042639c | 10839 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
e7d841ca CW |
10840 | /* and that it is marked active as soon as the irq could fire. */ |
10841 | smp_wmb(); | |
10842 | } | |
10843 | ||
8c9f3aaf JB |
10844 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10845 | struct drm_crtc *crtc, | |
10846 | struct drm_framebuffer *fb, | |
ed8d1975 | 10847 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10848 | struct drm_i915_gem_request *req, |
ed8d1975 | 10849 | uint32_t flags) |
8c9f3aaf | 10850 | { |
6258fbe2 | 10851 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10852 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10853 | u32 flip_mask; |
10854 | int ret; | |
10855 | ||
5fb9de1a | 10856 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10857 | if (ret) |
4fa62c89 | 10858 | return ret; |
8c9f3aaf JB |
10859 | |
10860 | /* Can't queue multiple flips, so wait for the previous | |
10861 | * one to finish before executing the next. | |
10862 | */ | |
10863 | if (intel_crtc->plane) | |
10864 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10865 | else | |
10866 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10867 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10868 | intel_ring_emit(ring, MI_NOOP); | |
10869 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10870 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10871 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10872 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10873 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca | 10874 | |
6042639c | 10875 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10876 | return 0; |
8c9f3aaf JB |
10877 | } |
10878 | ||
10879 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10880 | struct drm_crtc *crtc, | |
10881 | struct drm_framebuffer *fb, | |
ed8d1975 | 10882 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10883 | struct drm_i915_gem_request *req, |
ed8d1975 | 10884 | uint32_t flags) |
8c9f3aaf | 10885 | { |
6258fbe2 | 10886 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10887 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10888 | u32 flip_mask; |
10889 | int ret; | |
10890 | ||
5fb9de1a | 10891 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10892 | if (ret) |
4fa62c89 | 10893 | return ret; |
8c9f3aaf JB |
10894 | |
10895 | if (intel_crtc->plane) | |
10896 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10897 | else | |
10898 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10899 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10900 | intel_ring_emit(ring, MI_NOOP); | |
10901 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
10902 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10903 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10904 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
10905 | intel_ring_emit(ring, MI_NOOP); |
10906 | ||
6042639c | 10907 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10908 | return 0; |
8c9f3aaf JB |
10909 | } |
10910 | ||
10911 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
10912 | struct drm_crtc *crtc, | |
10913 | struct drm_framebuffer *fb, | |
ed8d1975 | 10914 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10915 | struct drm_i915_gem_request *req, |
ed8d1975 | 10916 | uint32_t flags) |
8c9f3aaf | 10917 | { |
6258fbe2 | 10918 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10919 | struct drm_i915_private *dev_priv = dev->dev_private; |
10920 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10921 | uint32_t pf, pipesrc; | |
10922 | int ret; | |
10923 | ||
5fb9de1a | 10924 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10925 | if (ret) |
4fa62c89 | 10926 | return ret; |
8c9f3aaf JB |
10927 | |
10928 | /* i965+ uses the linear or tiled offsets from the | |
10929 | * Display Registers (which do not change across a page-flip) | |
10930 | * so we need only reprogram the base address. | |
10931 | */ | |
6d90c952 DV |
10932 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10933 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10934 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10935 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 10936 | obj->tiling_mode); |
8c9f3aaf JB |
10937 | |
10938 | /* XXX Enabling the panel-fitter across page-flip is so far | |
10939 | * untested on non-native modes, so ignore it for now. | |
10940 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
10941 | */ | |
10942 | pf = 0; | |
10943 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 10944 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 10945 | |
6042639c | 10946 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10947 | return 0; |
8c9f3aaf JB |
10948 | } |
10949 | ||
10950 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
10951 | struct drm_crtc *crtc, | |
10952 | struct drm_framebuffer *fb, | |
ed8d1975 | 10953 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10954 | struct drm_i915_gem_request *req, |
ed8d1975 | 10955 | uint32_t flags) |
8c9f3aaf | 10956 | { |
6258fbe2 | 10957 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10958 | struct drm_i915_private *dev_priv = dev->dev_private; |
10959 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10960 | uint32_t pf, pipesrc; | |
10961 | int ret; | |
10962 | ||
5fb9de1a | 10963 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10964 | if (ret) |
4fa62c89 | 10965 | return ret; |
8c9f3aaf | 10966 | |
6d90c952 DV |
10967 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10968 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10969 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 10970 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 10971 | |
dc257cf1 DV |
10972 | /* Contrary to the suggestions in the documentation, |
10973 | * "Enable Panel Fitter" does not seem to be required when page | |
10974 | * flipping with a non-native mode, and worse causes a normal | |
10975 | * modeset to fail. | |
10976 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
10977 | */ | |
10978 | pf = 0; | |
8c9f3aaf | 10979 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 10980 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 10981 | |
6042639c | 10982 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10983 | return 0; |
8c9f3aaf JB |
10984 | } |
10985 | ||
7c9017e5 JB |
10986 | static int intel_gen7_queue_flip(struct drm_device *dev, |
10987 | struct drm_crtc *crtc, | |
10988 | struct drm_framebuffer *fb, | |
ed8d1975 | 10989 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10990 | struct drm_i915_gem_request *req, |
ed8d1975 | 10991 | uint32_t flags) |
7c9017e5 | 10992 | { |
6258fbe2 | 10993 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 10994 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 10995 | uint32_t plane_bit = 0; |
ffe74d75 CW |
10996 | int len, ret; |
10997 | ||
eba905b2 | 10998 | switch (intel_crtc->plane) { |
cb05d8de DV |
10999 | case PLANE_A: |
11000 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11001 | break; | |
11002 | case PLANE_B: | |
11003 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11004 | break; | |
11005 | case PLANE_C: | |
11006 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11007 | break; | |
11008 | default: | |
11009 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11010 | return -ENODEV; |
cb05d8de DV |
11011 | } |
11012 | ||
ffe74d75 | 11013 | len = 4; |
f476828a | 11014 | if (ring->id == RCS) { |
ffe74d75 | 11015 | len += 6; |
f476828a DL |
11016 | /* |
11017 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11018 | * 48bits addresses, and we need a NOOP for the batch size to | |
11019 | * stay even. | |
11020 | */ | |
11021 | if (IS_GEN8(dev)) | |
11022 | len += 2; | |
11023 | } | |
ffe74d75 | 11024 | |
f66fab8e VS |
11025 | /* |
11026 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11027 | * "The full packet must be contained within the same cache line." | |
11028 | * | |
11029 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11030 | * cacheline, if we ever start emitting more commands before | |
11031 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11032 | * then do the cacheline alignment, and finally emit the | |
11033 | * MI_DISPLAY_FLIP. | |
11034 | */ | |
bba09b12 | 11035 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 11036 | if (ret) |
4fa62c89 | 11037 | return ret; |
f66fab8e | 11038 | |
5fb9de1a | 11039 | ret = intel_ring_begin(req, len); |
7c9017e5 | 11040 | if (ret) |
4fa62c89 | 11041 | return ret; |
7c9017e5 | 11042 | |
ffe74d75 CW |
11043 | /* Unmask the flip-done completion message. Note that the bspec says that |
11044 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11045 | * more than one flip event at any time (or ensure that one flip message | |
11046 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11047 | * Experimentation says that BCS works despite DERRMR masking all | |
11048 | * flip-done completion events and that unmasking all planes at once | |
11049 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11050 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11051 | */ | |
11052 | if (ring->id == RCS) { | |
11053 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11054 | intel_ring_emit(ring, DERRMR); | |
11055 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11056 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11057 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11058 | if (IS_GEN8(dev)) |
f1afe24f | 11059 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11060 | MI_SRM_LRM_GLOBAL_GTT); |
11061 | else | |
f1afe24f | 11062 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11063 | MI_SRM_LRM_GLOBAL_GTT); |
ffe74d75 CW |
11064 | intel_ring_emit(ring, DERRMR); |
11065 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
11066 | if (IS_GEN8(dev)) { |
11067 | intel_ring_emit(ring, 0); | |
11068 | intel_ring_emit(ring, MI_NOOP); | |
11069 | } | |
ffe74d75 CW |
11070 | } |
11071 | ||
cb05d8de | 11072 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11073 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11074 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11075 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca | 11076 | |
6042639c | 11077 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11078 | return 0; |
7c9017e5 JB |
11079 | } |
11080 | ||
84c33a64 SG |
11081 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11082 | struct drm_i915_gem_object *obj) | |
11083 | { | |
11084 | /* | |
11085 | * This is not being used for older platforms, because | |
11086 | * non-availability of flip done interrupt forces us to use | |
11087 | * CS flips. Older platforms derive flip done using some clever | |
11088 | * tricks involving the flip_pending status bits and vblank irqs. | |
11089 | * So using MMIO flips there would disrupt this mechanism. | |
11090 | */ | |
11091 | ||
8e09bf83 CW |
11092 | if (ring == NULL) |
11093 | return true; | |
11094 | ||
84c33a64 SG |
11095 | if (INTEL_INFO(ring->dev)->gen < 5) |
11096 | return false; | |
11097 | ||
11098 | if (i915.use_mmio_flip < 0) | |
11099 | return false; | |
11100 | else if (i915.use_mmio_flip > 0) | |
11101 | return true; | |
14bf993e OM |
11102 | else if (i915.enable_execlists) |
11103 | return true; | |
84c33a64 | 11104 | else |
b4716185 | 11105 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11106 | } |
11107 | ||
6042639c | 11108 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
86efe24a | 11109 | unsigned int rotation, |
6042639c | 11110 | struct intel_unpin_work *work) |
ff944564 DL |
11111 | { |
11112 | struct drm_device *dev = intel_crtc->base.dev; | |
11113 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11114 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 | 11115 | const enum pipe pipe = intel_crtc->pipe; |
86efe24a | 11116 | u32 ctl, stride, tile_height; |
ff944564 DL |
11117 | |
11118 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11119 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11120 | switch (fb->modifier[0]) { |
11121 | case DRM_FORMAT_MOD_NONE: | |
11122 | break; | |
11123 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11124 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11125 | break; |
11126 | case I915_FORMAT_MOD_Y_TILED: | |
11127 | ctl |= PLANE_CTL_TILED_Y; | |
11128 | break; | |
11129 | case I915_FORMAT_MOD_Yf_TILED: | |
11130 | ctl |= PLANE_CTL_TILED_YF; | |
11131 | break; | |
11132 | default: | |
11133 | MISSING_CASE(fb->modifier[0]); | |
11134 | } | |
ff944564 DL |
11135 | |
11136 | /* | |
11137 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11138 | * linear buffers or in number of tiles for tiled buffers. | |
11139 | */ | |
86efe24a TU |
11140 | if (intel_rotation_90_or_270(rotation)) { |
11141 | /* stride = Surface height in tiles */ | |
11142 | tile_height = intel_tile_height(dev, fb->pixel_format, | |
11143 | fb->modifier[0], 0); | |
11144 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11145 | } else { | |
11146 | stride = fb->pitches[0] / | |
11147 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11148 | fb->pixel_format); | |
11149 | } | |
ff944564 DL |
11150 | |
11151 | /* | |
11152 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11153 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11154 | */ | |
11155 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11156 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11157 | ||
6042639c | 11158 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
ff944564 DL |
11159 | POSTING_READ(PLANE_SURF(pipe, 0)); |
11160 | } | |
11161 | ||
6042639c CW |
11162 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
11163 | struct intel_unpin_work *work) | |
84c33a64 SG |
11164 | { |
11165 | struct drm_device *dev = intel_crtc->base.dev; | |
11166 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11167 | struct intel_framebuffer *intel_fb = | |
11168 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11169 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11170 | u32 dspcntr; | |
11171 | u32 reg; | |
11172 | ||
84c33a64 SG |
11173 | reg = DSPCNTR(intel_crtc->plane); |
11174 | dspcntr = I915_READ(reg); | |
11175 | ||
c5d97472 DL |
11176 | if (obj->tiling_mode != I915_TILING_NONE) |
11177 | dspcntr |= DISPPLANE_TILED; | |
11178 | else | |
11179 | dspcntr &= ~DISPPLANE_TILED; | |
11180 | ||
84c33a64 SG |
11181 | I915_WRITE(reg, dspcntr); |
11182 | ||
6042639c | 11183 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
84c33a64 | 11184 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
ff944564 DL |
11185 | } |
11186 | ||
11187 | /* | |
11188 | * XXX: This is the temporary way to update the plane registers until we get | |
11189 | * around to using the usual plane update functions for MMIO flips | |
11190 | */ | |
6042639c | 11191 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
ff944564 | 11192 | { |
6042639c CW |
11193 | struct intel_crtc *crtc = mmio_flip->crtc; |
11194 | struct intel_unpin_work *work; | |
11195 | ||
11196 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11197 | work = crtc->unpin_work; | |
11198 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11199 | if (work == NULL) | |
11200 | return; | |
ff944564 | 11201 | |
6042639c | 11202 | intel_mark_page_flip_active(work); |
ff944564 | 11203 | |
6042639c | 11204 | intel_pipe_update_start(crtc); |
ff944564 | 11205 | |
6042639c | 11206 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
86efe24a | 11207 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
ff944564 DL |
11208 | else |
11209 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
6042639c | 11210 | ilk_do_mmio_flip(crtc, work); |
ff944564 | 11211 | |
6042639c | 11212 | intel_pipe_update_end(crtc); |
84c33a64 SG |
11213 | } |
11214 | ||
9362c7c5 | 11215 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11216 | { |
b2cfe0ab CW |
11217 | struct intel_mmio_flip *mmio_flip = |
11218 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11219 | |
6042639c | 11220 | if (mmio_flip->req) { |
eed29a5b | 11221 | WARN_ON(__i915_wait_request(mmio_flip->req, |
b2cfe0ab | 11222 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11223 | false, NULL, |
11224 | &mmio_flip->i915->rps.mmioflips)); | |
6042639c CW |
11225 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
11226 | } | |
84c33a64 | 11227 | |
6042639c | 11228 | intel_do_mmio_flip(mmio_flip); |
b2cfe0ab | 11229 | kfree(mmio_flip); |
84c33a64 SG |
11230 | } |
11231 | ||
11232 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11233 | struct drm_crtc *crtc, | |
86efe24a | 11234 | struct drm_i915_gem_object *obj) |
84c33a64 | 11235 | { |
b2cfe0ab CW |
11236 | struct intel_mmio_flip *mmio_flip; |
11237 | ||
11238 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11239 | if (mmio_flip == NULL) | |
11240 | return -ENOMEM; | |
84c33a64 | 11241 | |
bcafc4e3 | 11242 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11243 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11244 | mmio_flip->crtc = to_intel_crtc(crtc); |
86efe24a | 11245 | mmio_flip->rotation = crtc->primary->state->rotation; |
536f5b5e | 11246 | |
b2cfe0ab CW |
11247 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11248 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11249 | |
84c33a64 SG |
11250 | return 0; |
11251 | } | |
11252 | ||
8c9f3aaf JB |
11253 | static int intel_default_queue_flip(struct drm_device *dev, |
11254 | struct drm_crtc *crtc, | |
11255 | struct drm_framebuffer *fb, | |
ed8d1975 | 11256 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11257 | struct drm_i915_gem_request *req, |
ed8d1975 | 11258 | uint32_t flags) |
8c9f3aaf JB |
11259 | { |
11260 | return -ENODEV; | |
11261 | } | |
11262 | ||
d6bbafa1 CW |
11263 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11264 | struct drm_crtc *crtc) | |
11265 | { | |
11266 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11267 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11268 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11269 | u32 addr; | |
11270 | ||
11271 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11272 | return true; | |
11273 | ||
908565c2 CW |
11274 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11275 | return false; | |
11276 | ||
d6bbafa1 CW |
11277 | if (!work->enable_stall_check) |
11278 | return false; | |
11279 | ||
11280 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11281 | if (work->flip_queued_req && |
11282 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11283 | return false; |
11284 | ||
1e3feefd | 11285 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11286 | } |
11287 | ||
1e3feefd | 11288 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11289 | return false; |
11290 | ||
11291 | /* Potential stall - if we see that the flip has happened, | |
11292 | * assume a missed interrupt. */ | |
11293 | if (INTEL_INFO(dev)->gen >= 4) | |
11294 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11295 | else | |
11296 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11297 | ||
11298 | /* There is a potential issue here with a false positive after a flip | |
11299 | * to the same address. We could address this by checking for a | |
11300 | * non-incrementing frame counter. | |
11301 | */ | |
11302 | return addr == work->gtt_offset; | |
11303 | } | |
11304 | ||
11305 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11306 | { | |
11307 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11308 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11309 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11310 | struct intel_unpin_work *work; |
f326038a | 11311 | |
6c51d46f | 11312 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11313 | |
11314 | if (crtc == NULL) | |
11315 | return; | |
11316 | ||
f326038a | 11317 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11318 | work = intel_crtc->unpin_work; |
11319 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11320 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11321 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11322 | page_flip_completed(intel_crtc); |
6ad790c0 | 11323 | work = NULL; |
d6bbafa1 | 11324 | } |
6ad790c0 CW |
11325 | if (work != NULL && |
11326 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11327 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11328 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11329 | } |
11330 | ||
6b95a207 KH |
11331 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11332 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11333 | struct drm_pending_vblank_event *event, |
11334 | uint32_t page_flip_flags) | |
6b95a207 KH |
11335 | { |
11336 | struct drm_device *dev = crtc->dev; | |
11337 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11338 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11339 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11340 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11341 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11342 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11343 | struct intel_unpin_work *work; |
a4872ba6 | 11344 | struct intel_engine_cs *ring; |
cf5d8a46 | 11345 | bool mmio_flip; |
91af127f | 11346 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11347 | int ret; |
6b95a207 | 11348 | |
2ff8fde1 MR |
11349 | /* |
11350 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11351 | * check to be safe. In the future we may enable pageflipping from | |
11352 | * a disabled primary plane. | |
11353 | */ | |
11354 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11355 | return -EBUSY; | |
11356 | ||
e6a595d2 | 11357 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11358 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11359 | return -EINVAL; |
11360 | ||
11361 | /* | |
11362 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11363 | * Note that pitch changes could also affect these register. | |
11364 | */ | |
11365 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11366 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11367 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11368 | return -EINVAL; |
11369 | ||
f900db47 CW |
11370 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11371 | goto out_hang; | |
11372 | ||
b14c5679 | 11373 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11374 | if (work == NULL) |
11375 | return -ENOMEM; | |
11376 | ||
6b95a207 | 11377 | work->event = event; |
b4a98e57 | 11378 | work->crtc = crtc; |
ab8d6675 | 11379 | work->old_fb = old_fb; |
6b95a207 KH |
11380 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11381 | ||
87b6b101 | 11382 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11383 | if (ret) |
11384 | goto free_work; | |
11385 | ||
6b95a207 | 11386 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11387 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11388 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11389 | /* Before declaring the flip queue wedged, check if |
11390 | * the hardware completed the operation behind our backs. | |
11391 | */ | |
11392 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11393 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11394 | page_flip_completed(intel_crtc); | |
11395 | } else { | |
11396 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11397 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11398 | |
d6bbafa1 CW |
11399 | drm_crtc_vblank_put(crtc); |
11400 | kfree(work); | |
11401 | return -EBUSY; | |
11402 | } | |
6b95a207 KH |
11403 | } |
11404 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11405 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11406 | |
b4a98e57 CW |
11407 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11408 | flush_workqueue(dev_priv->wq); | |
11409 | ||
75dfca80 | 11410 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11411 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11412 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11413 | |
f4510a27 | 11414 | crtc->primary->fb = fb; |
afd65eb4 | 11415 | update_state_fb(crtc->primary); |
1ed1f968 | 11416 | |
e1f99ce6 | 11417 | work->pending_flip_obj = obj; |
e1f99ce6 | 11418 | |
89ed88ba CW |
11419 | ret = i915_mutex_lock_interruptible(dev); |
11420 | if (ret) | |
11421 | goto cleanup; | |
11422 | ||
b4a98e57 | 11423 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11424 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11425 | |
75f7f3ec | 11426 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
fd8f507c | 11427 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
75f7f3ec | 11428 | |
4fa62c89 VS |
11429 | if (IS_VALLEYVIEW(dev)) { |
11430 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11431 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11432 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11433 | ring = NULL; | |
48bf5b2d | 11434 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11435 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11436 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11437 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11438 | if (ring == NULL || ring->id != RCS) |
11439 | ring = &dev_priv->ring[BCS]; | |
11440 | } else { | |
11441 | ring = &dev_priv->ring[RCS]; | |
11442 | } | |
11443 | ||
cf5d8a46 CW |
11444 | mmio_flip = use_mmio_flip(ring, obj); |
11445 | ||
11446 | /* When using CS flips, we want to emit semaphores between rings. | |
11447 | * However, when using mmio flips we will create a task to do the | |
11448 | * synchronisation, so all we want here is to pin the framebuffer | |
11449 | * into the display plane and skip any waits. | |
11450 | */ | |
7580d774 ML |
11451 | if (!mmio_flip) { |
11452 | ret = i915_gem_object_sync(obj, ring, &request); | |
11453 | if (ret) | |
11454 | goto cleanup_pending; | |
11455 | } | |
11456 | ||
82bc3b2d | 11457 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
7580d774 | 11458 | crtc->primary->state); |
8c9f3aaf JB |
11459 | if (ret) |
11460 | goto cleanup_pending; | |
6b95a207 | 11461 | |
dedf278c TU |
11462 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
11463 | obj, 0); | |
11464 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
4fa62c89 | 11465 | |
cf5d8a46 | 11466 | if (mmio_flip) { |
86efe24a | 11467 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
d6bbafa1 CW |
11468 | if (ret) |
11469 | goto cleanup_unpin; | |
11470 | ||
f06cc1b9 JH |
11471 | i915_gem_request_assign(&work->flip_queued_req, |
11472 | obj->last_write_req); | |
d6bbafa1 | 11473 | } else { |
6258fbe2 JH |
11474 | if (!request) { |
11475 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); | |
11476 | if (ret) | |
11477 | goto cleanup_unpin; | |
11478 | } | |
11479 | ||
11480 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11481 | page_flip_flags); |
11482 | if (ret) | |
11483 | goto cleanup_unpin; | |
11484 | ||
6258fbe2 | 11485 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11486 | } |
11487 | ||
91af127f | 11488 | if (request) |
75289874 | 11489 | i915_add_request_no_flush(request); |
91af127f | 11490 | |
1e3feefd | 11491 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11492 | work->enable_stall_check = true; |
4fa62c89 | 11493 | |
ab8d6675 | 11494 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11495 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11496 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11497 | |
4e1e26f1 | 11498 | intel_fbc_disable_crtc(intel_crtc); |
a9ff8714 VS |
11499 | intel_frontbuffer_flip_prepare(dev, |
11500 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11501 | |
e5510fac JB |
11502 | trace_i915_flip_request(intel_crtc->plane, obj); |
11503 | ||
6b95a207 | 11504 | return 0; |
96b099fd | 11505 | |
4fa62c89 | 11506 | cleanup_unpin: |
82bc3b2d | 11507 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11508 | cleanup_pending: |
91af127f JH |
11509 | if (request) |
11510 | i915_gem_request_cancel(request); | |
b4a98e57 | 11511 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11512 | mutex_unlock(&dev->struct_mutex); |
11513 | cleanup: | |
f4510a27 | 11514 | crtc->primary->fb = old_fb; |
afd65eb4 | 11515 | update_state_fb(crtc->primary); |
89ed88ba CW |
11516 | |
11517 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11518 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11519 | |
5e2d7afc | 11520 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11521 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11522 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11523 | |
87b6b101 | 11524 | drm_crtc_vblank_put(crtc); |
7317c75e | 11525 | free_work: |
96b099fd CW |
11526 | kfree(work); |
11527 | ||
f900db47 | 11528 | if (ret == -EIO) { |
02e0efb5 ML |
11529 | struct drm_atomic_state *state; |
11530 | struct drm_plane_state *plane_state; | |
11531 | ||
f900db47 | 11532 | out_hang: |
02e0efb5 ML |
11533 | state = drm_atomic_state_alloc(dev); |
11534 | if (!state) | |
11535 | return -ENOMEM; | |
11536 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11537 | ||
11538 | retry: | |
11539 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11540 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11541 | if (!ret) { | |
11542 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11543 | ||
11544 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11545 | if (!ret) | |
11546 | ret = drm_atomic_commit(state); | |
11547 | } | |
11548 | ||
11549 | if (ret == -EDEADLK) { | |
11550 | drm_modeset_backoff(state->acquire_ctx); | |
11551 | drm_atomic_state_clear(state); | |
11552 | goto retry; | |
11553 | } | |
11554 | ||
11555 | if (ret) | |
11556 | drm_atomic_state_free(state); | |
11557 | ||
f0d3dad3 | 11558 | if (ret == 0 && event) { |
5e2d7afc | 11559 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11560 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11561 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11562 | } |
f900db47 | 11563 | } |
96b099fd | 11564 | return ret; |
6b95a207 KH |
11565 | } |
11566 | ||
da20eabd ML |
11567 | |
11568 | /** | |
11569 | * intel_wm_need_update - Check whether watermarks need updating | |
11570 | * @plane: drm plane | |
11571 | * @state: new plane state | |
11572 | * | |
11573 | * Check current plane state versus the new one to determine whether | |
11574 | * watermarks need to be recalculated. | |
11575 | * | |
11576 | * Returns true or false. | |
11577 | */ | |
11578 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11579 | struct drm_plane_state *state) | |
11580 | { | |
d21fbe87 MR |
11581 | struct intel_plane_state *new = to_intel_plane_state(state); |
11582 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11583 | ||
11584 | /* Update watermarks on tiling or size changes. */ | |
da20eabd ML |
11585 | if (!plane->state->fb || !state->fb || |
11586 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
d21fbe87 MR |
11587 | plane->state->rotation != state->rotation || |
11588 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11589 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11590 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11591 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
2791a16c | 11592 | return true; |
7809e5ae | 11593 | |
2791a16c | 11594 | return false; |
7809e5ae MR |
11595 | } |
11596 | ||
d21fbe87 MR |
11597 | static bool needs_scaling(struct intel_plane_state *state) |
11598 | { | |
11599 | int src_w = drm_rect_width(&state->src) >> 16; | |
11600 | int src_h = drm_rect_height(&state->src) >> 16; | |
11601 | int dst_w = drm_rect_width(&state->dst); | |
11602 | int dst_h = drm_rect_height(&state->dst); | |
11603 | ||
11604 | return (src_w != dst_w || src_h != dst_h); | |
11605 | } | |
11606 | ||
da20eabd ML |
11607 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11608 | struct drm_plane_state *plane_state) | |
11609 | { | |
11610 | struct drm_crtc *crtc = crtc_state->crtc; | |
11611 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11612 | struct drm_plane *plane = plane_state->plane; | |
11613 | struct drm_device *dev = crtc->dev; | |
11614 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11615 | struct intel_plane_state *old_plane_state = | |
11616 | to_intel_plane_state(plane->state); | |
11617 | int idx = intel_crtc->base.base.id, ret; | |
11618 | int i = drm_plane_index(plane); | |
11619 | bool mode_changed = needs_modeset(crtc_state); | |
11620 | bool was_crtc_enabled = crtc->state->active; | |
11621 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11622 | bool turn_off, turn_on, visible, was_visible; |
11623 | struct drm_framebuffer *fb = plane_state->fb; | |
11624 | ||
11625 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11626 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11627 | ret = skl_update_scaler_plane( | |
11628 | to_intel_crtc_state(crtc_state), | |
11629 | to_intel_plane_state(plane_state)); | |
11630 | if (ret) | |
11631 | return ret; | |
11632 | } | |
11633 | ||
da20eabd ML |
11634 | was_visible = old_plane_state->visible; |
11635 | visible = to_intel_plane_state(plane_state)->visible; | |
11636 | ||
11637 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11638 | was_visible = false; | |
11639 | ||
11640 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11641 | visible = false; | |
11642 | ||
11643 | if (!was_visible && !visible) | |
11644 | return 0; | |
11645 | ||
11646 | turn_off = was_visible && (!visible || mode_changed); | |
11647 | turn_on = visible && (!was_visible || mode_changed); | |
11648 | ||
11649 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11650 | plane->base.id, fb ? fb->base.id : -1); | |
11651 | ||
11652 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11653 | plane->base.id, was_visible, visible, | |
11654 | turn_off, turn_on, mode_changed); | |
11655 | ||
852eb00d | 11656 | if (turn_on) { |
f015c551 | 11657 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d VS |
11658 | /* must disable cxsr around plane enable/disable */ |
11659 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11660 | intel_crtc->atomic.disable_cxsr = true; | |
11661 | /* to potentially re-enable cxsr */ | |
11662 | intel_crtc->atomic.wait_vblank = true; | |
11663 | intel_crtc->atomic.update_wm_post = true; | |
11664 | } | |
11665 | } else if (turn_off) { | |
f015c551 | 11666 | intel_crtc->atomic.update_wm_post = true; |
852eb00d VS |
11667 | /* must disable cxsr around plane enable/disable */ |
11668 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11669 | if (is_crtc_enabled) | |
11670 | intel_crtc->atomic.wait_vblank = true; | |
11671 | intel_crtc->atomic.disable_cxsr = true; | |
11672 | } | |
11673 | } else if (intel_wm_need_update(plane, plane_state)) { | |
f015c551 | 11674 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d | 11675 | } |
da20eabd | 11676 | |
8be6ca85 | 11677 | if (visible || was_visible) |
a9ff8714 VS |
11678 | intel_crtc->atomic.fb_bits |= |
11679 | to_intel_plane(plane)->frontbuffer_bit; | |
11680 | ||
da20eabd ML |
11681 | switch (plane->type) { |
11682 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd ML |
11683 | intel_crtc->atomic.pre_disable_primary = turn_off; |
11684 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11685 | ||
066cf55b RV |
11686 | if (turn_off) { |
11687 | /* | |
11688 | * FIXME: Actually if we will still have any other | |
11689 | * plane enabled on the pipe we could let IPS enabled | |
11690 | * still, but for now lets consider that when we make | |
11691 | * primary invisible by setting DSPCNTR to 0 on | |
11692 | * update_primary_plane function IPS needs to be | |
11693 | * disable. | |
11694 | */ | |
11695 | intel_crtc->atomic.disable_ips = true; | |
11696 | ||
da20eabd | 11697 | intel_crtc->atomic.disable_fbc = true; |
066cf55b | 11698 | } |
da20eabd ML |
11699 | |
11700 | /* | |
11701 | * FBC does not work on some platforms for rotated | |
11702 | * planes, so disable it when rotation is not 0 and | |
11703 | * update it when rotation is set back to 0. | |
11704 | * | |
11705 | * FIXME: This is redundant with the fbc update done in | |
11706 | * the primary plane enable function except that that | |
11707 | * one is done too late. We eventually need to unify | |
11708 | * this. | |
11709 | */ | |
11710 | ||
11711 | if (visible && | |
11712 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11713 | dev_priv->fbc.crtc == intel_crtc && | |
11714 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11715 | intel_crtc->atomic.disable_fbc = true; | |
11716 | ||
11717 | /* | |
11718 | * BDW signals flip done immediately if the plane | |
11719 | * is disabled, even if the plane enable is already | |
11720 | * armed to occur at the next vblank :( | |
11721 | */ | |
11722 | if (turn_on && IS_BROADWELL(dev)) | |
11723 | intel_crtc->atomic.wait_vblank = true; | |
11724 | ||
11725 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11726 | break; | |
11727 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11728 | break; |
11729 | case DRM_PLANE_TYPE_OVERLAY: | |
d21fbe87 MR |
11730 | /* |
11731 | * WaCxSRDisabledForSpriteScaling:ivb | |
11732 | * | |
11733 | * cstate->update_wm was already set above, so this flag will | |
11734 | * take effect when we commit and program watermarks. | |
11735 | */ | |
11736 | if (IS_IVYBRIDGE(dev) && | |
11737 | needs_scaling(to_intel_plane_state(plane_state)) && | |
11738 | !needs_scaling(old_plane_state)) { | |
11739 | to_intel_crtc_state(crtc_state)->disable_lp_wm = true; | |
11740 | } else if (turn_off && !mode_changed) { | |
da20eabd ML |
11741 | intel_crtc->atomic.wait_vblank = true; |
11742 | intel_crtc->atomic.update_sprite_watermarks |= | |
11743 | 1 << i; | |
11744 | } | |
d21fbe87 MR |
11745 | |
11746 | break; | |
da20eabd ML |
11747 | } |
11748 | return 0; | |
11749 | } | |
11750 | ||
6d3a1ce7 ML |
11751 | static bool encoders_cloneable(const struct intel_encoder *a, |
11752 | const struct intel_encoder *b) | |
11753 | { | |
11754 | /* masks could be asymmetric, so check both ways */ | |
11755 | return a == b || (a->cloneable & (1 << b->type) && | |
11756 | b->cloneable & (1 << a->type)); | |
11757 | } | |
11758 | ||
11759 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11760 | struct intel_crtc *crtc, | |
11761 | struct intel_encoder *encoder) | |
11762 | { | |
11763 | struct intel_encoder *source_encoder; | |
11764 | struct drm_connector *connector; | |
11765 | struct drm_connector_state *connector_state; | |
11766 | int i; | |
11767 | ||
11768 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11769 | if (connector_state->crtc != &crtc->base) | |
11770 | continue; | |
11771 | ||
11772 | source_encoder = | |
11773 | to_intel_encoder(connector_state->best_encoder); | |
11774 | if (!encoders_cloneable(encoder, source_encoder)) | |
11775 | return false; | |
11776 | } | |
11777 | ||
11778 | return true; | |
11779 | } | |
11780 | ||
11781 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11782 | struct intel_crtc *crtc) | |
11783 | { | |
11784 | struct intel_encoder *encoder; | |
11785 | struct drm_connector *connector; | |
11786 | struct drm_connector_state *connector_state; | |
11787 | int i; | |
11788 | ||
11789 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11790 | if (connector_state->crtc != &crtc->base) | |
11791 | continue; | |
11792 | ||
11793 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11794 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11795 | return false; | |
11796 | } | |
11797 | ||
11798 | return true; | |
11799 | } | |
11800 | ||
11801 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11802 | struct drm_crtc_state *crtc_state) | |
11803 | { | |
cf5a15be | 11804 | struct drm_device *dev = crtc->dev; |
ad421372 | 11805 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11806 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11807 | struct intel_crtc_state *pipe_config = |
11808 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11809 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 11810 | int ret; |
6d3a1ce7 ML |
11811 | bool mode_changed = needs_modeset(crtc_state); |
11812 | ||
11813 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11814 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11815 | return -EINVAL; | |
11816 | } | |
11817 | ||
852eb00d VS |
11818 | if (mode_changed && !crtc_state->active) |
11819 | intel_crtc->atomic.update_wm_post = true; | |
eddfcbcd | 11820 | |
ad421372 ML |
11821 | if (mode_changed && crtc_state->enable && |
11822 | dev_priv->display.crtc_compute_clock && | |
11823 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11824 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11825 | pipe_config); | |
11826 | if (ret) | |
11827 | return ret; | |
11828 | } | |
11829 | ||
e435d6e5 | 11830 | ret = 0; |
86c8bbbe MR |
11831 | if (dev_priv->display.compute_pipe_wm) { |
11832 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
11833 | if (ret) | |
11834 | return ret; | |
11835 | } | |
11836 | ||
e435d6e5 ML |
11837 | if (INTEL_INFO(dev)->gen >= 9) { |
11838 | if (mode_changed) | |
11839 | ret = skl_update_scaler_crtc(pipe_config); | |
11840 | ||
11841 | if (!ret) | |
11842 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
11843 | pipe_config); | |
11844 | } | |
11845 | ||
11846 | return ret; | |
6d3a1ce7 ML |
11847 | } |
11848 | ||
65b38e0d | 11849 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11850 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11851 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11852 | .atomic_begin = intel_begin_crtc_commit, |
11853 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11854 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11855 | }; |
11856 | ||
d29b2f9d ACO |
11857 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
11858 | { | |
11859 | struct intel_connector *connector; | |
11860 | ||
11861 | for_each_intel_connector(dev, connector) { | |
11862 | if (connector->base.encoder) { | |
11863 | connector->base.state->best_encoder = | |
11864 | connector->base.encoder; | |
11865 | connector->base.state->crtc = | |
11866 | connector->base.encoder->crtc; | |
11867 | } else { | |
11868 | connector->base.state->best_encoder = NULL; | |
11869 | connector->base.state->crtc = NULL; | |
11870 | } | |
11871 | } | |
11872 | } | |
11873 | ||
050f7aeb | 11874 | static void |
eba905b2 | 11875 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11876 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11877 | { |
11878 | int bpp = pipe_config->pipe_bpp; | |
11879 | ||
11880 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11881 | connector->base.base.id, | |
c23cc417 | 11882 | connector->base.name); |
050f7aeb DV |
11883 | |
11884 | /* Don't use an invalid EDID bpc value */ | |
11885 | if (connector->base.display_info.bpc && | |
11886 | connector->base.display_info.bpc * 3 < bpp) { | |
11887 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11888 | bpp, connector->base.display_info.bpc*3); | |
11889 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11890 | } | |
11891 | ||
11892 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11893 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11894 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11895 | bpp); | |
11896 | pipe_config->pipe_bpp = 24; | |
11897 | } | |
11898 | } | |
11899 | ||
4e53c2e0 | 11900 | static int |
050f7aeb | 11901 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 11902 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 11903 | { |
050f7aeb | 11904 | struct drm_device *dev = crtc->base.dev; |
1486017f | 11905 | struct drm_atomic_state *state; |
da3ced29 ACO |
11906 | struct drm_connector *connector; |
11907 | struct drm_connector_state *connector_state; | |
1486017f | 11908 | int bpp, i; |
4e53c2e0 | 11909 | |
d328c9d7 | 11910 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 11911 | bpp = 10*3; |
d328c9d7 DV |
11912 | else if (INTEL_INFO(dev)->gen >= 5) |
11913 | bpp = 12*3; | |
11914 | else | |
11915 | bpp = 8*3; | |
11916 | ||
4e53c2e0 | 11917 | |
4e53c2e0 DV |
11918 | pipe_config->pipe_bpp = bpp; |
11919 | ||
1486017f ACO |
11920 | state = pipe_config->base.state; |
11921 | ||
4e53c2e0 | 11922 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
11923 | for_each_connector_in_state(state, connector, connector_state, i) { |
11924 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
11925 | continue; |
11926 | ||
da3ced29 ACO |
11927 | connected_sink_compute_bpp(to_intel_connector(connector), |
11928 | pipe_config); | |
4e53c2e0 DV |
11929 | } |
11930 | ||
11931 | return bpp; | |
11932 | } | |
11933 | ||
644db711 DV |
11934 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
11935 | { | |
11936 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
11937 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 11938 | mode->crtc_clock, |
644db711 DV |
11939 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
11940 | mode->crtc_hsync_end, mode->crtc_htotal, | |
11941 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
11942 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
11943 | } | |
11944 | ||
c0b03411 | 11945 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 11946 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
11947 | const char *context) |
11948 | { | |
6a60cd87 CK |
11949 | struct drm_device *dev = crtc->base.dev; |
11950 | struct drm_plane *plane; | |
11951 | struct intel_plane *intel_plane; | |
11952 | struct intel_plane_state *state; | |
11953 | struct drm_framebuffer *fb; | |
11954 | ||
11955 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
11956 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
11957 | |
11958 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
11959 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
11960 | pipe_config->pipe_bpp, pipe_config->dither); | |
11961 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
11962 | pipe_config->has_pch_encoder, | |
11963 | pipe_config->fdi_lanes, | |
11964 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
11965 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
11966 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 11967 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 11968 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11969 | pipe_config->lane_count, |
eb14cb74 VS |
11970 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
11971 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
11972 | pipe_config->dp_m_n.tu); | |
b95af8be | 11973 | |
90a6b7b0 | 11974 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 11975 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11976 | pipe_config->lane_count, |
b95af8be VK |
11977 | pipe_config->dp_m2_n2.gmch_m, |
11978 | pipe_config->dp_m2_n2.gmch_n, | |
11979 | pipe_config->dp_m2_n2.link_m, | |
11980 | pipe_config->dp_m2_n2.link_n, | |
11981 | pipe_config->dp_m2_n2.tu); | |
11982 | ||
55072d19 DV |
11983 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
11984 | pipe_config->has_audio, | |
11985 | pipe_config->has_infoframe); | |
11986 | ||
c0b03411 | 11987 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 11988 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 11989 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
11990 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
11991 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 11992 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
11993 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
11994 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
11995 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
11996 | crtc->num_scalers, | |
11997 | pipe_config->scaler_state.scaler_users, | |
11998 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
11999 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12000 | pipe_config->gmch_pfit.control, | |
12001 | pipe_config->gmch_pfit.pgm_ratios, | |
12002 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12003 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12004 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12005 | pipe_config->pch_pfit.size, |
12006 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12007 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12008 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12009 | |
415ff0f6 | 12010 | if (IS_BROXTON(dev)) { |
05712c15 | 12011 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12012 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12013 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12014 | pipe_config->ddi_pll_sel, |
12015 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12016 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12017 | pipe_config->dpll_hw_state.pll0, |
12018 | pipe_config->dpll_hw_state.pll1, | |
12019 | pipe_config->dpll_hw_state.pll2, | |
12020 | pipe_config->dpll_hw_state.pll3, | |
12021 | pipe_config->dpll_hw_state.pll6, | |
12022 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12023 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12024 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12025 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12026 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12027 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12028 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12029 | pipe_config->ddi_pll_sel, | |
12030 | pipe_config->dpll_hw_state.ctrl1, | |
12031 | pipe_config->dpll_hw_state.cfgcr1, | |
12032 | pipe_config->dpll_hw_state.cfgcr2); | |
12033 | } else if (HAS_DDI(dev)) { | |
12034 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
12035 | pipe_config->ddi_pll_sel, | |
12036 | pipe_config->dpll_hw_state.wrpll); | |
12037 | } else { | |
12038 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12039 | "fp0: 0x%x, fp1: 0x%x\n", | |
12040 | pipe_config->dpll_hw_state.dpll, | |
12041 | pipe_config->dpll_hw_state.dpll_md, | |
12042 | pipe_config->dpll_hw_state.fp0, | |
12043 | pipe_config->dpll_hw_state.fp1); | |
12044 | } | |
12045 | ||
6a60cd87 CK |
12046 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12047 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12048 | intel_plane = to_intel_plane(plane); | |
12049 | if (intel_plane->pipe != crtc->pipe) | |
12050 | continue; | |
12051 | ||
12052 | state = to_intel_plane_state(plane->state); | |
12053 | fb = state->base.fb; | |
12054 | if (!fb) { | |
12055 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12056 | "disabled, scaler_id = %d\n", | |
12057 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12058 | plane->base.id, intel_plane->pipe, | |
12059 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12060 | drm_plane_index(plane), state->scaler_id); | |
12061 | continue; | |
12062 | } | |
12063 | ||
12064 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12065 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12066 | plane->base.id, intel_plane->pipe, | |
12067 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12068 | drm_plane_index(plane)); | |
12069 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12070 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12071 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12072 | state->scaler_id, | |
12073 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12074 | drm_rect_width(&state->src) >> 16, | |
12075 | drm_rect_height(&state->src) >> 16, | |
12076 | state->dst.x1, state->dst.y1, | |
12077 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12078 | } | |
c0b03411 DV |
12079 | } |
12080 | ||
5448a00d | 12081 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12082 | { |
5448a00d ACO |
12083 | struct drm_device *dev = state->dev; |
12084 | struct intel_encoder *encoder; | |
da3ced29 | 12085 | struct drm_connector *connector; |
5448a00d | 12086 | struct drm_connector_state *connector_state; |
00f0b378 | 12087 | unsigned int used_ports = 0; |
5448a00d | 12088 | int i; |
00f0b378 VS |
12089 | |
12090 | /* | |
12091 | * Walk the connector list instead of the encoder | |
12092 | * list to detect the problem on ddi platforms | |
12093 | * where there's just one encoder per digital port. | |
12094 | */ | |
da3ced29 | 12095 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12096 | if (!connector_state->best_encoder) |
00f0b378 VS |
12097 | continue; |
12098 | ||
5448a00d ACO |
12099 | encoder = to_intel_encoder(connector_state->best_encoder); |
12100 | ||
12101 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12102 | |
12103 | switch (encoder->type) { | |
12104 | unsigned int port_mask; | |
12105 | case INTEL_OUTPUT_UNKNOWN: | |
12106 | if (WARN_ON(!HAS_DDI(dev))) | |
12107 | break; | |
12108 | case INTEL_OUTPUT_DISPLAYPORT: | |
12109 | case INTEL_OUTPUT_HDMI: | |
12110 | case INTEL_OUTPUT_EDP: | |
12111 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12112 | ||
12113 | /* the same port mustn't appear more than once */ | |
12114 | if (used_ports & port_mask) | |
12115 | return false; | |
12116 | ||
12117 | used_ports |= port_mask; | |
12118 | default: | |
12119 | break; | |
12120 | } | |
12121 | } | |
12122 | ||
12123 | return true; | |
12124 | } | |
12125 | ||
83a57153 ACO |
12126 | static void |
12127 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12128 | { | |
12129 | struct drm_crtc_state tmp_state; | |
663a3640 | 12130 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12131 | struct intel_dpll_hw_state dpll_hw_state; |
12132 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12133 | uint32_t ddi_pll_sel; |
c4e2d043 | 12134 | bool force_thru; |
83a57153 | 12135 | |
7546a384 ACO |
12136 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12137 | * kzalloc'd. Code that depends on any field being zero should be | |
12138 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12139 | * only fields that are know to not cause problems are preserved. */ | |
12140 | ||
83a57153 | 12141 | tmp_state = crtc_state->base; |
663a3640 | 12142 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12143 | shared_dpll = crtc_state->shared_dpll; |
12144 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12145 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12146 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12147 | |
83a57153 | 12148 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12149 | |
83a57153 | 12150 | crtc_state->base = tmp_state; |
663a3640 | 12151 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12152 | crtc_state->shared_dpll = shared_dpll; |
12153 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12154 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12155 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12156 | } |
12157 | ||
548ee15b | 12158 | static int |
b8cecdf5 | 12159 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12160 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12161 | { |
b359283a | 12162 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12163 | struct intel_encoder *encoder; |
da3ced29 | 12164 | struct drm_connector *connector; |
0b901879 | 12165 | struct drm_connector_state *connector_state; |
d328c9d7 | 12166 | int base_bpp, ret = -EINVAL; |
0b901879 | 12167 | int i; |
e29c22c0 | 12168 | bool retry = true; |
ee7b9f93 | 12169 | |
83a57153 | 12170 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12171 | |
e143a21c DV |
12172 | pipe_config->cpu_transcoder = |
12173 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12174 | |
2960bc9c ID |
12175 | /* |
12176 | * Sanitize sync polarity flags based on requested ones. If neither | |
12177 | * positive or negative polarity is requested, treat this as meaning | |
12178 | * negative polarity. | |
12179 | */ | |
2d112de7 | 12180 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12181 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12182 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12183 | |
2d112de7 | 12184 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12185 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12186 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12187 | |
d328c9d7 DV |
12188 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12189 | pipe_config); | |
12190 | if (base_bpp < 0) | |
4e53c2e0 DV |
12191 | goto fail; |
12192 | ||
e41a56be VS |
12193 | /* |
12194 | * Determine the real pipe dimensions. Note that stereo modes can | |
12195 | * increase the actual pipe size due to the frame doubling and | |
12196 | * insertion of additional space for blanks between the frame. This | |
12197 | * is stored in the crtc timings. We use the requested mode to do this | |
12198 | * computation to clearly distinguish it from the adjusted mode, which | |
12199 | * can be changed by the connectors in the below retry loop. | |
12200 | */ | |
2d112de7 | 12201 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12202 | &pipe_config->pipe_src_w, |
12203 | &pipe_config->pipe_src_h); | |
e41a56be | 12204 | |
e29c22c0 | 12205 | encoder_retry: |
ef1b460d | 12206 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12207 | pipe_config->port_clock = 0; |
ef1b460d | 12208 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12209 | |
135c81b8 | 12210 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12211 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12212 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12213 | |
7758a113 DV |
12214 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12215 | * adjust it according to limitations or connector properties, and also | |
12216 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12217 | */ |
da3ced29 | 12218 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12219 | if (connector_state->crtc != crtc) |
7758a113 | 12220 | continue; |
7ae89233 | 12221 | |
0b901879 ACO |
12222 | encoder = to_intel_encoder(connector_state->best_encoder); |
12223 | ||
efea6e8e DV |
12224 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12225 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12226 | goto fail; |
12227 | } | |
ee7b9f93 | 12228 | } |
47f1c6c9 | 12229 | |
ff9a6750 DV |
12230 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12231 | * done afterwards in case the encoder adjusts the mode. */ | |
12232 | if (!pipe_config->port_clock) | |
2d112de7 | 12233 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12234 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12235 | |
a43f6e0f | 12236 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12237 | if (ret < 0) { |
7758a113 DV |
12238 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12239 | goto fail; | |
ee7b9f93 | 12240 | } |
e29c22c0 DV |
12241 | |
12242 | if (ret == RETRY) { | |
12243 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12244 | ret = -EINVAL; | |
12245 | goto fail; | |
12246 | } | |
12247 | ||
12248 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12249 | retry = false; | |
12250 | goto encoder_retry; | |
12251 | } | |
12252 | ||
e8fa4270 DV |
12253 | /* Dithering seems to not pass-through bits correctly when it should, so |
12254 | * only enable it on 6bpc panels. */ | |
12255 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12256 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12257 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12258 | |
7758a113 | 12259 | fail: |
548ee15b | 12260 | return ret; |
ee7b9f93 | 12261 | } |
47f1c6c9 | 12262 | |
ea9d758d | 12263 | static void |
4740b0f2 | 12264 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12265 | { |
0a9ab303 ACO |
12266 | struct drm_crtc *crtc; |
12267 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12268 | int i; |
ea9d758d | 12269 | |
7668851f | 12270 | /* Double check state. */ |
8a75d157 | 12271 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12272 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12273 | |
12274 | /* Update hwmode for vblank functions */ | |
12275 | if (crtc->state->active) | |
12276 | crtc->hwmode = crtc->state->adjusted_mode; | |
12277 | else | |
12278 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12279 | |
12280 | /* | |
12281 | * Update legacy state to satisfy fbc code. This can | |
12282 | * be removed when fbc uses the atomic state. | |
12283 | */ | |
12284 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12285 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12286 | ||
12287 | crtc->primary->fb = plane_state->fb; | |
12288 | crtc->x = plane_state->src_x >> 16; | |
12289 | crtc->y = plane_state->src_y >> 16; | |
12290 | } | |
ea9d758d | 12291 | } |
ea9d758d DV |
12292 | } |
12293 | ||
3bd26263 | 12294 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12295 | { |
3bd26263 | 12296 | int diff; |
f1f644dc JB |
12297 | |
12298 | if (clock1 == clock2) | |
12299 | return true; | |
12300 | ||
12301 | if (!clock1 || !clock2) | |
12302 | return false; | |
12303 | ||
12304 | diff = abs(clock1 - clock2); | |
12305 | ||
12306 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12307 | return true; | |
12308 | ||
12309 | return false; | |
12310 | } | |
12311 | ||
25c5b266 DV |
12312 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12313 | list_for_each_entry((intel_crtc), \ | |
12314 | &(dev)->mode_config.crtc_list, \ | |
12315 | base.head) \ | |
0973f18f | 12316 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12317 | |
cfb23ed6 ML |
12318 | static bool |
12319 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12320 | unsigned int m2, unsigned int n2, | |
12321 | bool exact) | |
12322 | { | |
12323 | if (m == m2 && n == n2) | |
12324 | return true; | |
12325 | ||
12326 | if (exact || !m || !n || !m2 || !n2) | |
12327 | return false; | |
12328 | ||
12329 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12330 | ||
12331 | if (m > m2) { | |
12332 | while (m > m2) { | |
12333 | m2 <<= 1; | |
12334 | n2 <<= 1; | |
12335 | } | |
12336 | } else if (m < m2) { | |
12337 | while (m < m2) { | |
12338 | m <<= 1; | |
12339 | n <<= 1; | |
12340 | } | |
12341 | } | |
12342 | ||
12343 | return m == m2 && n == n2; | |
12344 | } | |
12345 | ||
12346 | static bool | |
12347 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12348 | struct intel_link_m_n *m2_n2, | |
12349 | bool adjust) | |
12350 | { | |
12351 | if (m_n->tu == m2_n2->tu && | |
12352 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12353 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12354 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12355 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12356 | if (adjust) | |
12357 | *m2_n2 = *m_n; | |
12358 | ||
12359 | return true; | |
12360 | } | |
12361 | ||
12362 | return false; | |
12363 | } | |
12364 | ||
0e8ffe1b | 12365 | static bool |
2fa2fe9a | 12366 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12367 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12368 | struct intel_crtc_state *pipe_config, |
12369 | bool adjust) | |
0e8ffe1b | 12370 | { |
cfb23ed6 ML |
12371 | bool ret = true; |
12372 | ||
12373 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12374 | do { \ | |
12375 | if (!adjust) \ | |
12376 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12377 | else \ | |
12378 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12379 | } while (0) | |
12380 | ||
66e985c0 DV |
12381 | #define PIPE_CONF_CHECK_X(name) \ |
12382 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12383 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12384 | "(expected 0x%08x, found 0x%08x)\n", \ |
12385 | current_config->name, \ | |
12386 | pipe_config->name); \ | |
cfb23ed6 | 12387 | ret = false; \ |
66e985c0 DV |
12388 | } |
12389 | ||
08a24034 DV |
12390 | #define PIPE_CONF_CHECK_I(name) \ |
12391 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12392 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12393 | "(expected %i, found %i)\n", \ |
12394 | current_config->name, \ | |
12395 | pipe_config->name); \ | |
cfb23ed6 ML |
12396 | ret = false; \ |
12397 | } | |
12398 | ||
12399 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12400 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12401 | &pipe_config->name,\ | |
12402 | adjust)) { \ | |
12403 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12404 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12405 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12406 | current_config->name.tu, \ | |
12407 | current_config->name.gmch_m, \ | |
12408 | current_config->name.gmch_n, \ | |
12409 | current_config->name.link_m, \ | |
12410 | current_config->name.link_n, \ | |
12411 | pipe_config->name.tu, \ | |
12412 | pipe_config->name.gmch_m, \ | |
12413 | pipe_config->name.gmch_n, \ | |
12414 | pipe_config->name.link_m, \ | |
12415 | pipe_config->name.link_n); \ | |
12416 | ret = false; \ | |
12417 | } | |
12418 | ||
12419 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12420 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12421 | &pipe_config->name, adjust) && \ | |
12422 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12423 | &pipe_config->name, adjust)) { \ | |
12424 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12425 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12426 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12427 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12428 | current_config->name.tu, \ | |
12429 | current_config->name.gmch_m, \ | |
12430 | current_config->name.gmch_n, \ | |
12431 | current_config->name.link_m, \ | |
12432 | current_config->name.link_n, \ | |
12433 | current_config->alt_name.tu, \ | |
12434 | current_config->alt_name.gmch_m, \ | |
12435 | current_config->alt_name.gmch_n, \ | |
12436 | current_config->alt_name.link_m, \ | |
12437 | current_config->alt_name.link_n, \ | |
12438 | pipe_config->name.tu, \ | |
12439 | pipe_config->name.gmch_m, \ | |
12440 | pipe_config->name.gmch_n, \ | |
12441 | pipe_config->name.link_m, \ | |
12442 | pipe_config->name.link_n); \ | |
12443 | ret = false; \ | |
88adfff1 DV |
12444 | } |
12445 | ||
b95af8be VK |
12446 | /* This is required for BDW+ where there is only one set of registers for |
12447 | * switching between high and low RR. | |
12448 | * This macro can be used whenever a comparison has to be made between one | |
12449 | * hw state and multiple sw state variables. | |
12450 | */ | |
12451 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12452 | if ((current_config->name != pipe_config->name) && \ | |
12453 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12454 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12455 | "(expected %i or %i, found %i)\n", \ |
12456 | current_config->name, \ | |
12457 | current_config->alt_name, \ | |
12458 | pipe_config->name); \ | |
cfb23ed6 | 12459 | ret = false; \ |
b95af8be VK |
12460 | } |
12461 | ||
1bd1bd80 DV |
12462 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12463 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12464 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12465 | "(expected %i, found %i)\n", \ |
12466 | current_config->name & (mask), \ | |
12467 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12468 | ret = false; \ |
1bd1bd80 DV |
12469 | } |
12470 | ||
5e550656 VS |
12471 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12472 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12473 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12474 | "(expected %i, found %i)\n", \ |
12475 | current_config->name, \ | |
12476 | pipe_config->name); \ | |
cfb23ed6 | 12477 | ret = false; \ |
5e550656 VS |
12478 | } |
12479 | ||
bb760063 DV |
12480 | #define PIPE_CONF_QUIRK(quirk) \ |
12481 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12482 | ||
eccb140b DV |
12483 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12484 | ||
08a24034 DV |
12485 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12486 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12487 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12488 | |
eb14cb74 | 12489 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12490 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12491 | |
12492 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12493 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12494 | ||
12495 | PIPE_CONF_CHECK_I(has_drrs); | |
12496 | if (current_config->has_drrs) | |
12497 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12498 | } else | |
12499 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12500 | |
2d112de7 ACO |
12501 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12502 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12503 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12504 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12505 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12506 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12507 | |
2d112de7 ACO |
12508 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12509 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12510 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12511 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12512 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12513 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12514 | |
c93f54cf | 12515 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12516 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12517 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12518 | IS_VALLEYVIEW(dev)) | |
12519 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12520 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12521 | |
9ed109a7 DV |
12522 | PIPE_CONF_CHECK_I(has_audio); |
12523 | ||
2d112de7 | 12524 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12525 | DRM_MODE_FLAG_INTERLACE); |
12526 | ||
bb760063 | 12527 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12528 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12529 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12530 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12531 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12532 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12533 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12534 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12535 | DRM_MODE_FLAG_NVSYNC); |
12536 | } | |
045ac3b5 | 12537 | |
333b8ca8 | 12538 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12539 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12540 | if (INTEL_INFO(dev)->gen < 4) | |
12541 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
333b8ca8 | 12542 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12543 | |
bfd16b2a ML |
12544 | if (!adjust) { |
12545 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12546 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12547 | ||
12548 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12549 | if (current_config->pch_pfit.enabled) { | |
12550 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12551 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12552 | } | |
2fa2fe9a | 12553 | |
7aefe2b5 ML |
12554 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12555 | } | |
a1b2278e | 12556 | |
e59150dc JB |
12557 | /* BDW+ don't expose a synchronous way to read the state */ |
12558 | if (IS_HASWELL(dev)) | |
12559 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12560 | |
282740f7 VS |
12561 | PIPE_CONF_CHECK_I(double_wide); |
12562 | ||
26804afd DV |
12563 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12564 | ||
c0d43d62 | 12565 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12566 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12567 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12568 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12569 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12570 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
12571 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12572 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12573 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12574 | |
42571aef VS |
12575 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12576 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12577 | ||
2d112de7 | 12578 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12579 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12580 | |
66e985c0 | 12581 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12582 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12583 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12584 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12585 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12586 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12587 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12588 | |
cfb23ed6 | 12589 | return ret; |
0e8ffe1b DV |
12590 | } |
12591 | ||
08db6652 DL |
12592 | static void check_wm_state(struct drm_device *dev) |
12593 | { | |
12594 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12595 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12596 | struct intel_crtc *intel_crtc; | |
12597 | int plane; | |
12598 | ||
12599 | if (INTEL_INFO(dev)->gen < 9) | |
12600 | return; | |
12601 | ||
12602 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12603 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12604 | ||
12605 | for_each_intel_crtc(dev, intel_crtc) { | |
12606 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12607 | const enum pipe pipe = intel_crtc->pipe; | |
12608 | ||
12609 | if (!intel_crtc->active) | |
12610 | continue; | |
12611 | ||
12612 | /* planes */ | |
dd740780 | 12613 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12614 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12615 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12616 | ||
12617 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12618 | continue; | |
12619 | ||
12620 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12621 | "(expected (%u,%u), found (%u,%u))\n", | |
12622 | pipe_name(pipe), plane + 1, | |
12623 | sw_entry->start, sw_entry->end, | |
12624 | hw_entry->start, hw_entry->end); | |
12625 | } | |
12626 | ||
12627 | /* cursor */ | |
4969d33e MR |
12628 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
12629 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 DL |
12630 | |
12631 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12632 | continue; | |
12633 | ||
12634 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12635 | "(expected (%u,%u), found (%u,%u))\n", | |
12636 | pipe_name(pipe), | |
12637 | sw_entry->start, sw_entry->end, | |
12638 | hw_entry->start, hw_entry->end); | |
12639 | } | |
12640 | } | |
12641 | ||
91d1b4bd | 12642 | static void |
35dd3c64 ML |
12643 | check_connector_state(struct drm_device *dev, |
12644 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12645 | { |
35dd3c64 ML |
12646 | struct drm_connector_state *old_conn_state; |
12647 | struct drm_connector *connector; | |
12648 | int i; | |
8af6cf88 | 12649 | |
35dd3c64 ML |
12650 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12651 | struct drm_encoder *encoder = connector->encoder; | |
12652 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12653 | |
8af6cf88 DV |
12654 | /* This also checks the encoder/connector hw state with the |
12655 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12656 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12657 | |
ad3c558f | 12658 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12659 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12660 | } |
91d1b4bd DV |
12661 | } |
12662 | ||
12663 | static void | |
12664 | check_encoder_state(struct drm_device *dev) | |
12665 | { | |
12666 | struct intel_encoder *encoder; | |
12667 | struct intel_connector *connector; | |
8af6cf88 | 12668 | |
b2784e15 | 12669 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12670 | bool enabled = false; |
4d20cd86 | 12671 | enum pipe pipe; |
8af6cf88 DV |
12672 | |
12673 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12674 | encoder->base.base.id, | |
8e329a03 | 12675 | encoder->base.name); |
8af6cf88 | 12676 | |
3a3371ff | 12677 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12678 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12679 | continue; |
12680 | enabled = true; | |
ad3c558f ML |
12681 | |
12682 | I915_STATE_WARN(connector->base.state->crtc != | |
12683 | encoder->base.crtc, | |
12684 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12685 | } |
0e32b39c | 12686 | |
e2c719b7 | 12687 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12688 | "encoder's enabled state mismatch " |
12689 | "(expected %i, found %i)\n", | |
12690 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12691 | |
12692 | if (!encoder->base.crtc) { | |
4d20cd86 | 12693 | bool active; |
7c60d198 | 12694 | |
4d20cd86 ML |
12695 | active = encoder->get_hw_state(encoder, &pipe); |
12696 | I915_STATE_WARN(active, | |
12697 | "encoder detached but still enabled on pipe %c.\n", | |
12698 | pipe_name(pipe)); | |
7c60d198 | 12699 | } |
8af6cf88 | 12700 | } |
91d1b4bd DV |
12701 | } |
12702 | ||
12703 | static void | |
4d20cd86 | 12704 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12705 | { |
fbee40df | 12706 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12707 | struct intel_encoder *encoder; |
4d20cd86 ML |
12708 | struct drm_crtc_state *old_crtc_state; |
12709 | struct drm_crtc *crtc; | |
12710 | int i; | |
8af6cf88 | 12711 | |
4d20cd86 ML |
12712 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12713 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12714 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12715 | bool active; |
8af6cf88 | 12716 | |
bfd16b2a ML |
12717 | if (!needs_modeset(crtc->state) && |
12718 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
4d20cd86 | 12719 | continue; |
045ac3b5 | 12720 | |
4d20cd86 ML |
12721 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
12722 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
12723 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
12724 | pipe_config->base.crtc = crtc; | |
12725 | pipe_config->base.state = old_state; | |
8af6cf88 | 12726 | |
4d20cd86 ML |
12727 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12728 | crtc->base.id); | |
8af6cf88 | 12729 | |
4d20cd86 ML |
12730 | active = dev_priv->display.get_pipe_config(intel_crtc, |
12731 | pipe_config); | |
d62cf62a | 12732 | |
b6b5d049 | 12733 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
12734 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
12735 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
12736 | active = crtc->state->active; | |
6c49f241 | 12737 | |
4d20cd86 | 12738 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 12739 | "crtc active state doesn't match with hw state " |
4d20cd86 | 12740 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 12741 | |
4d20cd86 | 12742 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 12743 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
12744 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
12745 | ||
12746 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
12747 | enum pipe pipe; | |
12748 | ||
12749 | active = encoder->get_hw_state(encoder, &pipe); | |
12750 | I915_STATE_WARN(active != crtc->state->active, | |
12751 | "[ENCODER:%i] active %i with crtc active %i\n", | |
12752 | encoder->base.base.id, active, crtc->state->active); | |
12753 | ||
12754 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
12755 | "Encoder connected to wrong pipe %c\n", | |
12756 | pipe_name(pipe)); | |
12757 | ||
12758 | if (active) | |
12759 | encoder->get_config(encoder, pipe_config); | |
12760 | } | |
53d9f4e9 | 12761 | |
4d20cd86 | 12762 | if (!crtc->state->active) |
cfb23ed6 ML |
12763 | continue; |
12764 | ||
4d20cd86 ML |
12765 | sw_config = to_intel_crtc_state(crtc->state); |
12766 | if (!intel_pipe_config_compare(dev, sw_config, | |
12767 | pipe_config, false)) { | |
e2c719b7 | 12768 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 12769 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 12770 | "[hw state]"); |
4d20cd86 | 12771 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
12772 | "[sw state]"); |
12773 | } | |
8af6cf88 DV |
12774 | } |
12775 | } | |
12776 | ||
91d1b4bd DV |
12777 | static void |
12778 | check_shared_dpll_state(struct drm_device *dev) | |
12779 | { | |
fbee40df | 12780 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12781 | struct intel_crtc *crtc; |
12782 | struct intel_dpll_hw_state dpll_hw_state; | |
12783 | int i; | |
5358901f DV |
12784 | |
12785 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12786 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12787 | int enabled_crtcs = 0, active_crtcs = 0; | |
12788 | bool active; | |
12789 | ||
12790 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12791 | ||
12792 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12793 | ||
12794 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12795 | ||
e2c719b7 | 12796 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12797 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12798 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12799 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12800 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12801 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12802 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12803 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12804 | "pll on state mismatch (expected %i, found %i)\n", |
12805 | pll->on, active); | |
12806 | ||
d3fcc808 | 12807 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12808 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12809 | enabled_crtcs++; |
12810 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12811 | active_crtcs++; | |
12812 | } | |
e2c719b7 | 12813 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12814 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12815 | pll->active, active_crtcs); | |
e2c719b7 | 12816 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12817 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12818 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12819 | |
e2c719b7 | 12820 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12821 | sizeof(dpll_hw_state)), |
12822 | "pll hw state mismatch\n"); | |
5358901f | 12823 | } |
8af6cf88 DV |
12824 | } |
12825 | ||
ee165b1a ML |
12826 | static void |
12827 | intel_modeset_check_state(struct drm_device *dev, | |
12828 | struct drm_atomic_state *old_state) | |
91d1b4bd | 12829 | { |
08db6652 | 12830 | check_wm_state(dev); |
35dd3c64 | 12831 | check_connector_state(dev, old_state); |
91d1b4bd | 12832 | check_encoder_state(dev); |
4d20cd86 | 12833 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
12834 | check_shared_dpll_state(dev); |
12835 | } | |
12836 | ||
5cec258b | 12837 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12838 | int dotclock) |
12839 | { | |
12840 | /* | |
12841 | * FDI already provided one idea for the dotclock. | |
12842 | * Yell if the encoder disagrees. | |
12843 | */ | |
2d112de7 | 12844 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12845 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12846 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12847 | } |
12848 | ||
80715b2f VS |
12849 | static void update_scanline_offset(struct intel_crtc *crtc) |
12850 | { | |
12851 | struct drm_device *dev = crtc->base.dev; | |
12852 | ||
12853 | /* | |
12854 | * The scanline counter increments at the leading edge of hsync. | |
12855 | * | |
12856 | * On most platforms it starts counting from vtotal-1 on the | |
12857 | * first active line. That means the scanline counter value is | |
12858 | * always one less than what we would expect. Ie. just after | |
12859 | * start of vblank, which also occurs at start of hsync (on the | |
12860 | * last active line), the scanline counter will read vblank_start-1. | |
12861 | * | |
12862 | * On gen2 the scanline counter starts counting from 1 instead | |
12863 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12864 | * to keep the value positive), instead of adding one. | |
12865 | * | |
12866 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12867 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12868 | * there's an extra 1 line difference. So we need to add two instead of | |
12869 | * one to the value. | |
12870 | */ | |
12871 | if (IS_GEN2(dev)) { | |
124abe07 | 12872 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12873 | int vtotal; |
12874 | ||
124abe07 VS |
12875 | vtotal = adjusted_mode->crtc_vtotal; |
12876 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
12877 | vtotal /= 2; |
12878 | ||
12879 | crtc->scanline_offset = vtotal - 1; | |
12880 | } else if (HAS_DDI(dev) && | |
409ee761 | 12881 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12882 | crtc->scanline_offset = 2; |
12883 | } else | |
12884 | crtc->scanline_offset = 1; | |
12885 | } | |
12886 | ||
ad421372 | 12887 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 12888 | { |
225da59b | 12889 | struct drm_device *dev = state->dev; |
ed6739ef | 12890 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 12891 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 12892 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12893 | struct intel_crtc_state *intel_crtc_state; |
12894 | struct drm_crtc *crtc; | |
12895 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 12896 | int i; |
ed6739ef ACO |
12897 | |
12898 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 12899 | return; |
ed6739ef | 12900 | |
0a9ab303 | 12901 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
12902 | int dpll; |
12903 | ||
0a9ab303 | 12904 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 12905 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 12906 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 12907 | |
ad421372 | 12908 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
12909 | continue; |
12910 | ||
ad421372 | 12911 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 12912 | |
ad421372 ML |
12913 | if (!shared_dpll) |
12914 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 12915 | |
ad421372 ML |
12916 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
12917 | } | |
ed6739ef ACO |
12918 | } |
12919 | ||
99d736a2 ML |
12920 | /* |
12921 | * This implements the workaround described in the "notes" section of the mode | |
12922 | * set sequence documentation. When going from no pipes or single pipe to | |
12923 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
12924 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
12925 | */ | |
12926 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
12927 | { | |
12928 | struct drm_crtc_state *crtc_state; | |
12929 | struct intel_crtc *intel_crtc; | |
12930 | struct drm_crtc *crtc; | |
12931 | struct intel_crtc_state *first_crtc_state = NULL; | |
12932 | struct intel_crtc_state *other_crtc_state = NULL; | |
12933 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
12934 | int i; | |
12935 | ||
12936 | /* look at all crtc's that are going to be enabled in during modeset */ | |
12937 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
12938 | intel_crtc = to_intel_crtc(crtc); | |
12939 | ||
12940 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
12941 | continue; | |
12942 | ||
12943 | if (first_crtc_state) { | |
12944 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
12945 | break; | |
12946 | } else { | |
12947 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
12948 | first_pipe = intel_crtc->pipe; | |
12949 | } | |
12950 | } | |
12951 | ||
12952 | /* No workaround needed? */ | |
12953 | if (!first_crtc_state) | |
12954 | return 0; | |
12955 | ||
12956 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
12957 | for_each_intel_crtc(state->dev, intel_crtc) { | |
12958 | struct intel_crtc_state *pipe_config; | |
12959 | ||
12960 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
12961 | if (IS_ERR(pipe_config)) | |
12962 | return PTR_ERR(pipe_config); | |
12963 | ||
12964 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
12965 | ||
12966 | if (!pipe_config->base.active || | |
12967 | needs_modeset(&pipe_config->base)) | |
12968 | continue; | |
12969 | ||
12970 | /* 2 or more enabled crtcs means no need for w/a */ | |
12971 | if (enabled_pipe != INVALID_PIPE) | |
12972 | return 0; | |
12973 | ||
12974 | enabled_pipe = intel_crtc->pipe; | |
12975 | } | |
12976 | ||
12977 | if (enabled_pipe != INVALID_PIPE) | |
12978 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
12979 | else if (other_crtc_state) | |
12980 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
12981 | ||
12982 | return 0; | |
12983 | } | |
12984 | ||
27c329ed ML |
12985 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
12986 | { | |
12987 | struct drm_crtc *crtc; | |
12988 | struct drm_crtc_state *crtc_state; | |
12989 | int ret = 0; | |
12990 | ||
12991 | /* add all active pipes to the state */ | |
12992 | for_each_crtc(state->dev, crtc) { | |
12993 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
12994 | if (IS_ERR(crtc_state)) | |
12995 | return PTR_ERR(crtc_state); | |
12996 | ||
12997 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
12998 | continue; | |
12999 | ||
13000 | crtc_state->mode_changed = true; | |
13001 | ||
13002 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13003 | if (ret) | |
13004 | break; | |
13005 | ||
13006 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13007 | if (ret) | |
13008 | break; | |
13009 | } | |
13010 | ||
13011 | return ret; | |
13012 | } | |
13013 | ||
c347a676 | 13014 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
13015 | { |
13016 | struct drm_device *dev = state->dev; | |
27c329ed | 13017 | struct drm_i915_private *dev_priv = dev->dev_private; |
054518dd ACO |
13018 | int ret; |
13019 | ||
b359283a ML |
13020 | if (!check_digital_port_conflicts(state)) { |
13021 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13022 | return -EINVAL; | |
13023 | } | |
13024 | ||
054518dd ACO |
13025 | /* |
13026 | * See if the config requires any additional preparation, e.g. | |
13027 | * to adjust global state with pipes off. We need to do this | |
13028 | * here so we can get the modeset_pipe updated config for the new | |
13029 | * mode set on this crtc. For other crtcs we need to use the | |
13030 | * adjusted_mode bits in the crtc directly. | |
13031 | */ | |
27c329ed ML |
13032 | if (dev_priv->display.modeset_calc_cdclk) { |
13033 | unsigned int cdclk; | |
b432e5cf | 13034 | |
27c329ed ML |
13035 | ret = dev_priv->display.modeset_calc_cdclk(state); |
13036 | ||
13037 | cdclk = to_intel_atomic_state(state)->cdclk; | |
13038 | if (!ret && cdclk != dev_priv->cdclk_freq) | |
13039 | ret = intel_modeset_all_pipes(state); | |
13040 | ||
13041 | if (ret < 0) | |
054518dd | 13042 | return ret; |
27c329ed ML |
13043 | } else |
13044 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; | |
054518dd | 13045 | |
ad421372 | 13046 | intel_modeset_clear_plls(state); |
054518dd | 13047 | |
99d736a2 | 13048 | if (IS_HASWELL(dev)) |
ad421372 | 13049 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13050 | |
ad421372 | 13051 | return 0; |
c347a676 ACO |
13052 | } |
13053 | ||
aa363136 MR |
13054 | /* |
13055 | * Handle calculation of various watermark data at the end of the atomic check | |
13056 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13057 | * handlers to ensure that all derived state has been updated. | |
13058 | */ | |
13059 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13060 | { | |
13061 | struct drm_device *dev = state->dev; | |
13062 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13063 | struct drm_crtc *crtc; | |
13064 | struct drm_crtc_state *cstate; | |
13065 | struct drm_plane *plane; | |
13066 | struct drm_plane_state *pstate; | |
13067 | ||
13068 | /* | |
13069 | * Calculate watermark configuration details now that derived | |
13070 | * plane/crtc state is all properly updated. | |
13071 | */ | |
13072 | drm_for_each_crtc(crtc, dev) { | |
13073 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13074 | crtc->state; | |
13075 | ||
13076 | if (cstate->active) | |
13077 | intel_state->wm_config.num_pipes_active++; | |
13078 | } | |
13079 | drm_for_each_legacy_plane(plane, dev) { | |
13080 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13081 | plane->state; | |
13082 | ||
13083 | if (!to_intel_plane_state(pstate)->visible) | |
13084 | continue; | |
13085 | ||
13086 | intel_state->wm_config.sprites_enabled = true; | |
13087 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13088 | pstate->crtc_h != pstate->src_h >> 16) | |
13089 | intel_state->wm_config.sprites_scaled = true; | |
13090 | } | |
13091 | } | |
13092 | ||
74c090b1 ML |
13093 | /** |
13094 | * intel_atomic_check - validate state object | |
13095 | * @dev: drm device | |
13096 | * @state: state to validate | |
13097 | */ | |
13098 | static int intel_atomic_check(struct drm_device *dev, | |
13099 | struct drm_atomic_state *state) | |
c347a676 | 13100 | { |
aa363136 | 13101 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13102 | struct drm_crtc *crtc; |
13103 | struct drm_crtc_state *crtc_state; | |
13104 | int ret, i; | |
61333b60 | 13105 | bool any_ms = false; |
c347a676 | 13106 | |
74c090b1 | 13107 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13108 | if (ret) |
13109 | return ret; | |
13110 | ||
c347a676 | 13111 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13112 | struct intel_crtc_state *pipe_config = |
13113 | to_intel_crtc_state(crtc_state); | |
1ed51de9 DV |
13114 | |
13115 | /* Catch I915_MODE_FLAG_INHERITED */ | |
13116 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13117 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13118 | |
61333b60 ML |
13119 | if (!crtc_state->enable) { |
13120 | if (needs_modeset(crtc_state)) | |
13121 | any_ms = true; | |
c347a676 | 13122 | continue; |
61333b60 | 13123 | } |
c347a676 | 13124 | |
26495481 | 13125 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
13126 | continue; |
13127 | ||
26495481 DV |
13128 | /* FIXME: For only active_changed we shouldn't need to do any |
13129 | * state recomputation at all. */ | |
13130 | ||
1ed51de9 DV |
13131 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13132 | if (ret) | |
13133 | return ret; | |
b359283a | 13134 | |
cfb23ed6 | 13135 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13136 | if (ret) |
13137 | return ret; | |
13138 | ||
6764e9f8 | 13139 | if (intel_pipe_config_compare(state->dev, |
cfb23ed6 | 13140 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13141 | pipe_config, true)) { |
26495481 | 13142 | crtc_state->mode_changed = false; |
bfd16b2a | 13143 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13144 | } |
13145 | ||
13146 | if (needs_modeset(crtc_state)) { | |
13147 | any_ms = true; | |
cfb23ed6 ML |
13148 | |
13149 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13150 | if (ret) | |
13151 | return ret; | |
13152 | } | |
61333b60 | 13153 | |
26495481 DV |
13154 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13155 | needs_modeset(crtc_state) ? | |
13156 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13157 | } |
13158 | ||
61333b60 ML |
13159 | if (any_ms) { |
13160 | ret = intel_modeset_checks(state); | |
13161 | ||
13162 | if (ret) | |
13163 | return ret; | |
27c329ed | 13164 | } else |
aa363136 | 13165 | intel_state->cdclk = to_i915(state->dev)->cdclk_freq; |
76305b1a | 13166 | |
aa363136 MR |
13167 | ret = drm_atomic_helper_check_planes(state->dev, state); |
13168 | if (ret) | |
13169 | return ret; | |
13170 | ||
13171 | calc_watermark_data(state); | |
13172 | ||
13173 | return 0; | |
054518dd ACO |
13174 | } |
13175 | ||
5008e874 ML |
13176 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13177 | struct drm_atomic_state *state, | |
13178 | bool async) | |
13179 | { | |
7580d774 ML |
13180 | struct drm_i915_private *dev_priv = dev->dev_private; |
13181 | struct drm_plane_state *plane_state; | |
5008e874 | 13182 | struct drm_crtc_state *crtc_state; |
7580d774 | 13183 | struct drm_plane *plane; |
5008e874 ML |
13184 | struct drm_crtc *crtc; |
13185 | int i, ret; | |
13186 | ||
13187 | if (async) { | |
13188 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13189 | return -EINVAL; | |
13190 | } | |
13191 | ||
13192 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13193 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13194 | if (ret) | |
13195 | return ret; | |
7580d774 ML |
13196 | |
13197 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13198 | flush_workqueue(dev_priv->wq); | |
5008e874 ML |
13199 | } |
13200 | ||
f935675f ML |
13201 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13202 | if (ret) | |
13203 | return ret; | |
13204 | ||
5008e874 | 13205 | ret = drm_atomic_helper_prepare_planes(dev, state); |
7580d774 ML |
13206 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
13207 | u32 reset_counter; | |
13208 | ||
13209 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13210 | mutex_unlock(&dev->struct_mutex); | |
13211 | ||
13212 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13213 | struct intel_plane_state *intel_plane_state = | |
13214 | to_intel_plane_state(plane_state); | |
13215 | ||
13216 | if (!intel_plane_state->wait_req) | |
13217 | continue; | |
13218 | ||
13219 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13220 | reset_counter, true, | |
13221 | NULL, NULL); | |
13222 | ||
13223 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13224 | if (ret == -EIO) | |
13225 | ret = 0; | |
13226 | ||
13227 | if (ret) | |
13228 | break; | |
13229 | } | |
13230 | ||
13231 | if (!ret) | |
13232 | return 0; | |
13233 | ||
13234 | mutex_lock(&dev->struct_mutex); | |
13235 | drm_atomic_helper_cleanup_planes(dev, state); | |
13236 | } | |
5008e874 | 13237 | |
f935675f | 13238 | mutex_unlock(&dev->struct_mutex); |
5008e874 ML |
13239 | return ret; |
13240 | } | |
13241 | ||
74c090b1 ML |
13242 | /** |
13243 | * intel_atomic_commit - commit validated state object | |
13244 | * @dev: DRM device | |
13245 | * @state: the top-level driver state object | |
13246 | * @async: asynchronous commit | |
13247 | * | |
13248 | * This function commits a top-level state object that has been validated | |
13249 | * with drm_atomic_helper_check(). | |
13250 | * | |
13251 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13252 | * we can only handle plane-related operations and do not yet support | |
13253 | * asynchronous commit. | |
13254 | * | |
13255 | * RETURNS | |
13256 | * Zero for success or -errno. | |
13257 | */ | |
13258 | static int intel_atomic_commit(struct drm_device *dev, | |
13259 | struct drm_atomic_state *state, | |
13260 | bool async) | |
a6778b3c | 13261 | { |
fbee40df | 13262 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 | 13263 | struct drm_crtc_state *crtc_state; |
7580d774 | 13264 | struct drm_crtc *crtc; |
c0c36b94 | 13265 | int ret = 0; |
0a9ab303 | 13266 | int i; |
61333b60 | 13267 | bool any_ms = false; |
a6778b3c | 13268 | |
5008e874 | 13269 | ret = intel_atomic_prepare_commit(dev, state, async); |
7580d774 ML |
13270 | if (ret) { |
13271 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
d4afb8cc | 13272 | return ret; |
7580d774 | 13273 | } |
d4afb8cc | 13274 | |
1c5e19f8 | 13275 | drm_atomic_helper_swap_state(dev, state); |
aa363136 | 13276 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; |
1c5e19f8 | 13277 | |
0a9ab303 | 13278 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13279 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13280 | ||
61333b60 ML |
13281 | if (!needs_modeset(crtc->state)) |
13282 | continue; | |
13283 | ||
13284 | any_ms = true; | |
a539205a | 13285 | intel_pre_plane_update(intel_crtc); |
460da916 | 13286 | |
a539205a ML |
13287 | if (crtc_state->active) { |
13288 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13289 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd ML |
13290 | intel_crtc->active = false; |
13291 | intel_disable_shared_dpll(intel_crtc); | |
a539205a | 13292 | } |
b8cecdf5 | 13293 | } |
7758a113 | 13294 | |
ea9d758d DV |
13295 | /* Only after disabling all output pipelines that will be changed can we |
13296 | * update the the output configuration. */ | |
4740b0f2 | 13297 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13298 | |
4740b0f2 ML |
13299 | if (any_ms) { |
13300 | intel_shared_dpll_commit(state); | |
13301 | ||
13302 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
61333b60 | 13303 | modeset_update_crtc_power_domains(state); |
4740b0f2 | 13304 | } |
47fab737 | 13305 | |
a6778b3c | 13306 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13307 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13308 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13309 | bool modeset = needs_modeset(crtc->state); | |
bfd16b2a ML |
13310 | bool update_pipe = !modeset && |
13311 | to_intel_crtc_state(crtc->state)->update_pipe; | |
13312 | unsigned long put_domains = 0; | |
f6ac4b2a ML |
13313 | |
13314 | if (modeset && crtc->state->active) { | |
a539205a ML |
13315 | update_scanline_offset(to_intel_crtc(crtc)); |
13316 | dev_priv->display.crtc_enable(crtc); | |
13317 | } | |
80715b2f | 13318 | |
bfd16b2a ML |
13319 | if (update_pipe) { |
13320 | put_domains = modeset_get_crtc_power_domains(crtc); | |
13321 | ||
13322 | /* make sure intel_modeset_check_state runs */ | |
13323 | any_ms = true; | |
13324 | } | |
13325 | ||
f6ac4b2a ML |
13326 | if (!modeset) |
13327 | intel_pre_plane_update(intel_crtc); | |
13328 | ||
6173ee28 ML |
13329 | if (crtc->state->active && |
13330 | (crtc->state->planes_changed || update_pipe)) | |
62852622 | 13331 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
bfd16b2a ML |
13332 | |
13333 | if (put_domains) | |
13334 | modeset_put_power_domains(dev_priv, put_domains); | |
13335 | ||
f6ac4b2a | 13336 | intel_post_plane_update(intel_crtc); |
80715b2f | 13337 | } |
a6778b3c | 13338 | |
a6778b3c | 13339 | /* FIXME: add subpixel order */ |
83a57153 | 13340 | |
74c090b1 | 13341 | drm_atomic_helper_wait_for_vblanks(dev, state); |
f935675f ML |
13342 | |
13343 | mutex_lock(&dev->struct_mutex); | |
d4afb8cc | 13344 | drm_atomic_helper_cleanup_planes(dev, state); |
f935675f | 13345 | mutex_unlock(&dev->struct_mutex); |
2bfb4627 | 13346 | |
74c090b1 | 13347 | if (any_ms) |
ee165b1a ML |
13348 | intel_modeset_check_state(dev, state); |
13349 | ||
13350 | drm_atomic_state_free(state); | |
f30da187 | 13351 | |
74c090b1 | 13352 | return 0; |
7f27126e JB |
13353 | } |
13354 | ||
c0c36b94 CW |
13355 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13356 | { | |
83a57153 ACO |
13357 | struct drm_device *dev = crtc->dev; |
13358 | struct drm_atomic_state *state; | |
e694eb02 | 13359 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13360 | int ret; |
83a57153 ACO |
13361 | |
13362 | state = drm_atomic_state_alloc(dev); | |
13363 | if (!state) { | |
e694eb02 | 13364 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13365 | crtc->base.id); |
13366 | return; | |
13367 | } | |
13368 | ||
e694eb02 | 13369 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13370 | |
e694eb02 ML |
13371 | retry: |
13372 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13373 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13374 | if (!ret) { | |
13375 | if (!crtc_state->active) | |
13376 | goto out; | |
83a57153 | 13377 | |
e694eb02 | 13378 | crtc_state->mode_changed = true; |
74c090b1 | 13379 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13380 | } |
13381 | ||
e694eb02 ML |
13382 | if (ret == -EDEADLK) { |
13383 | drm_atomic_state_clear(state); | |
13384 | drm_modeset_backoff(state->acquire_ctx); | |
13385 | goto retry; | |
4ed9fb37 | 13386 | } |
4be07317 | 13387 | |
2bfb4627 | 13388 | if (ret) |
e694eb02 | 13389 | out: |
2bfb4627 | 13390 | drm_atomic_state_free(state); |
c0c36b94 CW |
13391 | } |
13392 | ||
25c5b266 DV |
13393 | #undef for_each_intel_crtc_masked |
13394 | ||
f6e5b160 | 13395 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13396 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13397 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13398 | .destroy = intel_crtc_destroy, |
13399 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13400 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13401 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13402 | }; |
13403 | ||
5358901f DV |
13404 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13405 | struct intel_shared_dpll *pll, | |
13406 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13407 | { |
5358901f | 13408 | uint32_t val; |
ee7b9f93 | 13409 | |
f458ebbc | 13410 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13411 | return false; |
13412 | ||
5358901f | 13413 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13414 | hw_state->dpll = val; |
13415 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13416 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13417 | |
13418 | return val & DPLL_VCO_ENABLE; | |
13419 | } | |
13420 | ||
15bdd4cf DV |
13421 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13422 | struct intel_shared_dpll *pll) | |
13423 | { | |
3e369b76 ACO |
13424 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13425 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13426 | } |
13427 | ||
e7b903d2 DV |
13428 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13429 | struct intel_shared_dpll *pll) | |
13430 | { | |
e7b903d2 | 13431 | /* PCH refclock must be enabled first */ |
89eff4be | 13432 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13433 | |
3e369b76 | 13434 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13435 | |
13436 | /* Wait for the clocks to stabilize. */ | |
13437 | POSTING_READ(PCH_DPLL(pll->id)); | |
13438 | udelay(150); | |
13439 | ||
13440 | /* The pixel multiplier can only be updated once the | |
13441 | * DPLL is enabled and the clocks are stable. | |
13442 | * | |
13443 | * So write it again. | |
13444 | */ | |
3e369b76 | 13445 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13446 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13447 | udelay(200); |
13448 | } | |
13449 | ||
13450 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13451 | struct intel_shared_dpll *pll) | |
13452 | { | |
13453 | struct drm_device *dev = dev_priv->dev; | |
13454 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13455 | |
13456 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13457 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13458 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13459 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13460 | } |
13461 | ||
15bdd4cf DV |
13462 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13463 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13464 | udelay(200); |
13465 | } | |
13466 | ||
46edb027 DV |
13467 | static char *ibx_pch_dpll_names[] = { |
13468 | "PCH DPLL A", | |
13469 | "PCH DPLL B", | |
13470 | }; | |
13471 | ||
7c74ade1 | 13472 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13473 | { |
e7b903d2 | 13474 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13475 | int i; |
13476 | ||
7c74ade1 | 13477 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13478 | |
e72f9fbf | 13479 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13480 | dev_priv->shared_dplls[i].id = i; |
13481 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13482 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13483 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13484 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13485 | dev_priv->shared_dplls[i].get_hw_state = |
13486 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13487 | } |
13488 | } | |
13489 | ||
7c74ade1 DV |
13490 | static void intel_shared_dpll_init(struct drm_device *dev) |
13491 | { | |
e7b903d2 | 13492 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13493 | |
9cd86933 DV |
13494 | if (HAS_DDI(dev)) |
13495 | intel_ddi_pll_init(dev); | |
13496 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13497 | ibx_pch_dpll_init(dev); |
13498 | else | |
13499 | dev_priv->num_shared_dpll = 0; | |
13500 | ||
13501 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13502 | } |
13503 | ||
6beb8c23 MR |
13504 | /** |
13505 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13506 | * @plane: drm plane to prepare for | |
13507 | * @fb: framebuffer to prepare for presentation | |
13508 | * | |
13509 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13510 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13511 | * bits. Some older platforms need special physical address handling for | |
13512 | * cursor planes. | |
13513 | * | |
f935675f ML |
13514 | * Must be called with struct_mutex held. |
13515 | * | |
6beb8c23 MR |
13516 | * Returns 0 on success, negative error code on failure. |
13517 | */ | |
13518 | int | |
13519 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 13520 | const struct drm_plane_state *new_state) |
465c120c MR |
13521 | { |
13522 | struct drm_device *dev = plane->dev; | |
844f9111 | 13523 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 13524 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 | 13525 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 13526 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
6beb8c23 | 13527 | int ret = 0; |
465c120c | 13528 | |
1ee49399 | 13529 | if (!obj && !old_obj) |
465c120c MR |
13530 | return 0; |
13531 | ||
5008e874 ML |
13532 | if (old_obj) { |
13533 | struct drm_crtc_state *crtc_state = | |
13534 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13535 | ||
13536 | /* Big Hammer, we also need to ensure that any pending | |
13537 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13538 | * current scanout is retired before unpinning the old | |
13539 | * framebuffer. Note that we rely on userspace rendering | |
13540 | * into the buffer attached to the pipe they are waiting | |
13541 | * on. If not, userspace generates a GPU hang with IPEHR | |
13542 | * point to the MI_WAIT_FOR_EVENT. | |
13543 | * | |
13544 | * This should only fail upon a hung GPU, in which case we | |
13545 | * can safely continue. | |
13546 | */ | |
13547 | if (needs_modeset(crtc_state)) | |
13548 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13549 | ||
13550 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13551 | if (ret && ret != -EIO) | |
f935675f | 13552 | return ret; |
5008e874 ML |
13553 | } |
13554 | ||
1ee49399 ML |
13555 | if (!obj) { |
13556 | ret = 0; | |
13557 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
6beb8c23 MR |
13558 | INTEL_INFO(dev)->cursor_needs_physical) { |
13559 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13560 | ret = i915_gem_object_attach_phys(obj, align); | |
13561 | if (ret) | |
13562 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13563 | } else { | |
7580d774 | 13564 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state); |
6beb8c23 | 13565 | } |
465c120c | 13566 | |
7580d774 ML |
13567 | if (ret == 0) { |
13568 | if (obj) { | |
13569 | struct intel_plane_state *plane_state = | |
13570 | to_intel_plane_state(new_state); | |
13571 | ||
13572 | i915_gem_request_assign(&plane_state->wait_req, | |
13573 | obj->last_write_req); | |
13574 | } | |
13575 | ||
a9ff8714 | 13576 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
7580d774 | 13577 | } |
fdd508a6 | 13578 | |
6beb8c23 MR |
13579 | return ret; |
13580 | } | |
13581 | ||
38f3ce3a MR |
13582 | /** |
13583 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13584 | * @plane: drm plane to clean up for | |
13585 | * @fb: old framebuffer that was on plane | |
13586 | * | |
13587 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
13588 | * |
13589 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
13590 | */ |
13591 | void | |
13592 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 13593 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
13594 | { |
13595 | struct drm_device *dev = plane->dev; | |
1ee49399 | 13596 | struct intel_plane *intel_plane = to_intel_plane(plane); |
7580d774 | 13597 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
13598 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
13599 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 13600 | |
7580d774 ML |
13601 | old_intel_state = to_intel_plane_state(old_state); |
13602 | ||
1ee49399 | 13603 | if (!obj && !old_obj) |
38f3ce3a MR |
13604 | return; |
13605 | ||
1ee49399 ML |
13606 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
13607 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
844f9111 | 13608 | intel_unpin_fb_obj(old_state->fb, old_state); |
1ee49399 ML |
13609 | |
13610 | /* prepare_fb aborted? */ | |
13611 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
13612 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
13613 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
7580d774 ML |
13614 | |
13615 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
13616 | ||
465c120c MR |
13617 | } |
13618 | ||
6156a456 CK |
13619 | int |
13620 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13621 | { | |
13622 | int max_scale; | |
13623 | struct drm_device *dev; | |
13624 | struct drm_i915_private *dev_priv; | |
13625 | int crtc_clock, cdclk; | |
13626 | ||
13627 | if (!intel_crtc || !crtc_state) | |
13628 | return DRM_PLANE_HELPER_NO_SCALING; | |
13629 | ||
13630 | dev = intel_crtc->base.dev; | |
13631 | dev_priv = dev->dev_private; | |
13632 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 13633 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 13634 | |
54bf1ce6 | 13635 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
13636 | return DRM_PLANE_HELPER_NO_SCALING; |
13637 | ||
13638 | /* | |
13639 | * skl max scale is lower of: | |
13640 | * close to 3 but not 3, -1 is for that purpose | |
13641 | * or | |
13642 | * cdclk/crtc_clock | |
13643 | */ | |
13644 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13645 | ||
13646 | return max_scale; | |
13647 | } | |
13648 | ||
465c120c | 13649 | static int |
3c692a41 | 13650 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13651 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13652 | struct intel_plane_state *state) |
13653 | { | |
2b875c22 MR |
13654 | struct drm_crtc *crtc = state->base.crtc; |
13655 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13656 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13657 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13658 | bool can_position = false; | |
465c120c | 13659 | |
061e4b8d ML |
13660 | /* use scaler when colorkey is not required */ |
13661 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
818ed961 | 13662 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
061e4b8d ML |
13663 | min_scale = 1; |
13664 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13665 | can_position = true; |
6156a456 | 13666 | } |
d8106366 | 13667 | |
061e4b8d ML |
13668 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13669 | &state->dst, &state->clip, | |
da20eabd ML |
13670 | min_scale, max_scale, |
13671 | can_position, true, | |
13672 | &state->visible); | |
14af293f GP |
13673 | } |
13674 | ||
13675 | static void | |
13676 | intel_commit_primary_plane(struct drm_plane *plane, | |
13677 | struct intel_plane_state *state) | |
13678 | { | |
2b875c22 MR |
13679 | struct drm_crtc *crtc = state->base.crtc; |
13680 | struct drm_framebuffer *fb = state->base.fb; | |
13681 | struct drm_device *dev = plane->dev; | |
14af293f | 13682 | struct drm_i915_private *dev_priv = dev->dev_private; |
14af293f | 13683 | |
ea2c67bb | 13684 | crtc = crtc ? crtc : plane->crtc; |
ccc759dc | 13685 | |
d4b08630 ML |
13686 | dev_priv->display.update_primary_plane(crtc, fb, |
13687 | state->src.x1 >> 16, | |
13688 | state->src.y1 >> 16); | |
465c120c MR |
13689 | } |
13690 | ||
a8ad0d8e ML |
13691 | static void |
13692 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13693 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13694 | { |
13695 | struct drm_device *dev = plane->dev; | |
13696 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13697 | ||
a8ad0d8e ML |
13698 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13699 | } | |
13700 | ||
613d2b27 ML |
13701 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
13702 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 13703 | { |
32b7eeec | 13704 | struct drm_device *dev = crtc->dev; |
3c692a41 | 13705 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
bfd16b2a ML |
13706 | struct intel_crtc_state *old_intel_state = |
13707 | to_intel_crtc_state(old_crtc_state); | |
13708 | bool modeset = needs_modeset(crtc->state); | |
3c692a41 | 13709 | |
f015c551 | 13710 | if (intel_crtc->atomic.update_wm_pre) |
32b7eeec | 13711 | intel_update_watermarks(crtc); |
3c692a41 | 13712 | |
c34c9ee4 | 13713 | /* Perform vblank evasion around commit operation */ |
62852622 | 13714 | intel_pipe_update_start(intel_crtc); |
0583236e | 13715 | |
bfd16b2a ML |
13716 | if (modeset) |
13717 | return; | |
13718 | ||
13719 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
13720 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
13721 | else if (INTEL_INFO(dev)->gen >= 9) | |
0583236e | 13722 | skl_detach_scalers(intel_crtc); |
32b7eeec MR |
13723 | } |
13724 | ||
613d2b27 ML |
13725 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
13726 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 13727 | { |
32b7eeec | 13728 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 13729 | |
62852622 | 13730 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
13731 | } |
13732 | ||
cf4c7c12 | 13733 | /** |
4a3b8769 MR |
13734 | * intel_plane_destroy - destroy a plane |
13735 | * @plane: plane to destroy | |
cf4c7c12 | 13736 | * |
4a3b8769 MR |
13737 | * Common destruction function for all types of planes (primary, cursor, |
13738 | * sprite). | |
cf4c7c12 | 13739 | */ |
4a3b8769 | 13740 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13741 | { |
13742 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13743 | drm_plane_cleanup(plane); | |
13744 | kfree(intel_plane); | |
13745 | } | |
13746 | ||
65a3fea0 | 13747 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13748 | .update_plane = drm_atomic_helper_update_plane, |
13749 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13750 | .destroy = intel_plane_destroy, |
c196e1d6 | 13751 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13752 | .atomic_get_property = intel_plane_atomic_get_property, |
13753 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13754 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13755 | .atomic_destroy_state = intel_plane_destroy_state, | |
13756 | ||
465c120c MR |
13757 | }; |
13758 | ||
13759 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13760 | int pipe) | |
13761 | { | |
13762 | struct intel_plane *primary; | |
8e7d688b | 13763 | struct intel_plane_state *state; |
465c120c | 13764 | const uint32_t *intel_primary_formats; |
45e3743a | 13765 | unsigned int num_formats; |
465c120c MR |
13766 | |
13767 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13768 | if (primary == NULL) | |
13769 | return NULL; | |
13770 | ||
8e7d688b MR |
13771 | state = intel_create_plane_state(&primary->base); |
13772 | if (!state) { | |
ea2c67bb MR |
13773 | kfree(primary); |
13774 | return NULL; | |
13775 | } | |
8e7d688b | 13776 | primary->base.state = &state->base; |
ea2c67bb | 13777 | |
465c120c MR |
13778 | primary->can_scale = false; |
13779 | primary->max_downscale = 1; | |
6156a456 CK |
13780 | if (INTEL_INFO(dev)->gen >= 9) { |
13781 | primary->can_scale = true; | |
af99ceda | 13782 | state->scaler_id = -1; |
6156a456 | 13783 | } |
465c120c MR |
13784 | primary->pipe = pipe; |
13785 | primary->plane = pipe; | |
a9ff8714 | 13786 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 MR |
13787 | primary->check_plane = intel_check_primary_plane; |
13788 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13789 | primary->disable_plane = intel_disable_primary_plane; |
465c120c MR |
13790 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13791 | primary->plane = !pipe; | |
13792 | ||
6c0fd451 DL |
13793 | if (INTEL_INFO(dev)->gen >= 9) { |
13794 | intel_primary_formats = skl_primary_formats; | |
13795 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13796 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13797 | intel_primary_formats = i965_primary_formats; |
13798 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13799 | } else { |
13800 | intel_primary_formats = i8xx_primary_formats; | |
13801 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13802 | } |
13803 | ||
13804 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13805 | &intel_plane_funcs, |
465c120c MR |
13806 | intel_primary_formats, num_formats, |
13807 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13808 | |
3b7a5119 SJ |
13809 | if (INTEL_INFO(dev)->gen >= 4) |
13810 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13811 | |
ea2c67bb MR |
13812 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13813 | ||
465c120c MR |
13814 | return &primary->base; |
13815 | } | |
13816 | ||
3b7a5119 SJ |
13817 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13818 | { | |
13819 | if (!dev->mode_config.rotation_property) { | |
13820 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13821 | BIT(DRM_ROTATE_180); | |
13822 | ||
13823 | if (INTEL_INFO(dev)->gen >= 9) | |
13824 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13825 | ||
13826 | dev->mode_config.rotation_property = | |
13827 | drm_mode_create_rotation_property(dev, flags); | |
13828 | } | |
13829 | if (dev->mode_config.rotation_property) | |
13830 | drm_object_attach_property(&plane->base.base, | |
13831 | dev->mode_config.rotation_property, | |
13832 | plane->base.state->rotation); | |
13833 | } | |
13834 | ||
3d7d6510 | 13835 | static int |
852e787c | 13836 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 13837 | struct intel_crtc_state *crtc_state, |
852e787c | 13838 | struct intel_plane_state *state) |
3d7d6510 | 13839 | { |
061e4b8d | 13840 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 13841 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 13842 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
13843 | unsigned stride; |
13844 | int ret; | |
3d7d6510 | 13845 | |
061e4b8d ML |
13846 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13847 | &state->dst, &state->clip, | |
3d7d6510 MR |
13848 | DRM_PLANE_HELPER_NO_SCALING, |
13849 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13850 | true, true, &state->visible); |
757f9a3e GP |
13851 | if (ret) |
13852 | return ret; | |
13853 | ||
757f9a3e GP |
13854 | /* if we want to turn off the cursor ignore width and height */ |
13855 | if (!obj) | |
da20eabd | 13856 | return 0; |
757f9a3e | 13857 | |
757f9a3e | 13858 | /* Check for which cursor types we support */ |
061e4b8d | 13859 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
13860 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
13861 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13862 | return -EINVAL; |
13863 | } | |
13864 | ||
ea2c67bb MR |
13865 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13866 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13867 | DRM_DEBUG_KMS("buffer is too small\n"); |
13868 | return -ENOMEM; | |
13869 | } | |
13870 | ||
3a656b54 | 13871 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 13872 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 13873 | return -EINVAL; |
32b7eeec MR |
13874 | } |
13875 | ||
da20eabd | 13876 | return 0; |
852e787c | 13877 | } |
3d7d6510 | 13878 | |
a8ad0d8e ML |
13879 | static void |
13880 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 13881 | struct drm_crtc *crtc) |
a8ad0d8e | 13882 | { |
a8ad0d8e ML |
13883 | intel_crtc_update_cursor(crtc, false); |
13884 | } | |
13885 | ||
f4a2cf29 | 13886 | static void |
852e787c GP |
13887 | intel_commit_cursor_plane(struct drm_plane *plane, |
13888 | struct intel_plane_state *state) | |
13889 | { | |
2b875c22 | 13890 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
13891 | struct drm_device *dev = plane->dev; |
13892 | struct intel_crtc *intel_crtc; | |
2b875c22 | 13893 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 13894 | uint32_t addr; |
852e787c | 13895 | |
ea2c67bb MR |
13896 | crtc = crtc ? crtc : plane->crtc; |
13897 | intel_crtc = to_intel_crtc(crtc); | |
13898 | ||
a912f12f GP |
13899 | if (intel_crtc->cursor_bo == obj) |
13900 | goto update; | |
4ed91096 | 13901 | |
f4a2cf29 | 13902 | if (!obj) |
a912f12f | 13903 | addr = 0; |
f4a2cf29 | 13904 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 13905 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 13906 | else |
a912f12f | 13907 | addr = obj->phys_handle->busaddr; |
852e787c | 13908 | |
a912f12f GP |
13909 | intel_crtc->cursor_addr = addr; |
13910 | intel_crtc->cursor_bo = obj; | |
852e787c | 13911 | |
302d19ac | 13912 | update: |
62852622 | 13913 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
13914 | } |
13915 | ||
3d7d6510 MR |
13916 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
13917 | int pipe) | |
13918 | { | |
13919 | struct intel_plane *cursor; | |
8e7d688b | 13920 | struct intel_plane_state *state; |
3d7d6510 MR |
13921 | |
13922 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
13923 | if (cursor == NULL) | |
13924 | return NULL; | |
13925 | ||
8e7d688b MR |
13926 | state = intel_create_plane_state(&cursor->base); |
13927 | if (!state) { | |
ea2c67bb MR |
13928 | kfree(cursor); |
13929 | return NULL; | |
13930 | } | |
8e7d688b | 13931 | cursor->base.state = &state->base; |
ea2c67bb | 13932 | |
3d7d6510 MR |
13933 | cursor->can_scale = false; |
13934 | cursor->max_downscale = 1; | |
13935 | cursor->pipe = pipe; | |
13936 | cursor->plane = pipe; | |
a9ff8714 | 13937 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 MR |
13938 | cursor->check_plane = intel_check_cursor_plane; |
13939 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 13940 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
13941 | |
13942 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 13943 | &intel_plane_funcs, |
3d7d6510 MR |
13944 | intel_cursor_formats, |
13945 | ARRAY_SIZE(intel_cursor_formats), | |
13946 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
13947 | |
13948 | if (INTEL_INFO(dev)->gen >= 4) { | |
13949 | if (!dev->mode_config.rotation_property) | |
13950 | dev->mode_config.rotation_property = | |
13951 | drm_mode_create_rotation_property(dev, | |
13952 | BIT(DRM_ROTATE_0) | | |
13953 | BIT(DRM_ROTATE_180)); | |
13954 | if (dev->mode_config.rotation_property) | |
13955 | drm_object_attach_property(&cursor->base.base, | |
13956 | dev->mode_config.rotation_property, | |
8e7d688b | 13957 | state->base.rotation); |
4398ad45 VS |
13958 | } |
13959 | ||
af99ceda CK |
13960 | if (INTEL_INFO(dev)->gen >=9) |
13961 | state->scaler_id = -1; | |
13962 | ||
ea2c67bb MR |
13963 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
13964 | ||
3d7d6510 MR |
13965 | return &cursor->base; |
13966 | } | |
13967 | ||
549e2bfb CK |
13968 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
13969 | struct intel_crtc_state *crtc_state) | |
13970 | { | |
13971 | int i; | |
13972 | struct intel_scaler *intel_scaler; | |
13973 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
13974 | ||
13975 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
13976 | intel_scaler = &scaler_state->scalers[i]; | |
13977 | intel_scaler->in_use = 0; | |
549e2bfb CK |
13978 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
13979 | } | |
13980 | ||
13981 | scaler_state->scaler_id = -1; | |
13982 | } | |
13983 | ||
b358d0a6 | 13984 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 13985 | { |
fbee40df | 13986 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 13987 | struct intel_crtc *intel_crtc; |
f5de6e07 | 13988 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
13989 | struct drm_plane *primary = NULL; |
13990 | struct drm_plane *cursor = NULL; | |
465c120c | 13991 | int i, ret; |
79e53945 | 13992 | |
955382f3 | 13993 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
13994 | if (intel_crtc == NULL) |
13995 | return; | |
13996 | ||
f5de6e07 ACO |
13997 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
13998 | if (!crtc_state) | |
13999 | goto fail; | |
550acefd ACO |
14000 | intel_crtc->config = crtc_state; |
14001 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14002 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14003 | |
549e2bfb CK |
14004 | /* initialize shared scalers */ |
14005 | if (INTEL_INFO(dev)->gen >= 9) { | |
14006 | if (pipe == PIPE_C) | |
14007 | intel_crtc->num_scalers = 1; | |
14008 | else | |
14009 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14010 | ||
14011 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14012 | } | |
14013 | ||
465c120c | 14014 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14015 | if (!primary) |
14016 | goto fail; | |
14017 | ||
14018 | cursor = intel_cursor_plane_create(dev, pipe); | |
14019 | if (!cursor) | |
14020 | goto fail; | |
14021 | ||
465c120c | 14022 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14023 | cursor, &intel_crtc_funcs); |
14024 | if (ret) | |
14025 | goto fail; | |
79e53945 JB |
14026 | |
14027 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14028 | for (i = 0; i < 256; i++) { |
14029 | intel_crtc->lut_r[i] = i; | |
14030 | intel_crtc->lut_g[i] = i; | |
14031 | intel_crtc->lut_b[i] = i; | |
14032 | } | |
14033 | ||
1f1c2e24 VS |
14034 | /* |
14035 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14036 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14037 | */ |
80824003 JB |
14038 | intel_crtc->pipe = pipe; |
14039 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14040 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14041 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14042 | intel_crtc->plane = !pipe; |
80824003 JB |
14043 | } |
14044 | ||
4b0e333e CW |
14045 | intel_crtc->cursor_base = ~0; |
14046 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14047 | intel_crtc->cursor_size = ~0; |
8d7849db | 14048 | |
852eb00d VS |
14049 | intel_crtc->wm.cxsr_allowed = true; |
14050 | ||
22fd0fab JB |
14051 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14052 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14053 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14054 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14055 | ||
79e53945 | 14056 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14057 | |
14058 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14059 | return; |
14060 | ||
14061 | fail: | |
14062 | if (primary) | |
14063 | drm_plane_cleanup(primary); | |
14064 | if (cursor) | |
14065 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14066 | kfree(crtc_state); |
3d7d6510 | 14067 | kfree(intel_crtc); |
79e53945 JB |
14068 | } |
14069 | ||
752aa88a JB |
14070 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14071 | { | |
14072 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14073 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14074 | |
51fd371b | 14075 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14076 | |
d3babd3f | 14077 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14078 | return INVALID_PIPE; |
14079 | ||
14080 | return to_intel_crtc(encoder->crtc)->pipe; | |
14081 | } | |
14082 | ||
08d7b3d1 | 14083 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14084 | struct drm_file *file) |
08d7b3d1 | 14085 | { |
08d7b3d1 | 14086 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14087 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14088 | struct intel_crtc *crtc; |
08d7b3d1 | 14089 | |
7707e653 | 14090 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14091 | |
7707e653 | 14092 | if (!drmmode_crtc) { |
08d7b3d1 | 14093 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14094 | return -ENOENT; |
08d7b3d1 CW |
14095 | } |
14096 | ||
7707e653 | 14097 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14098 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14099 | |
c05422d5 | 14100 | return 0; |
08d7b3d1 CW |
14101 | } |
14102 | ||
66a9278e | 14103 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14104 | { |
66a9278e DV |
14105 | struct drm_device *dev = encoder->base.dev; |
14106 | struct intel_encoder *source_encoder; | |
79e53945 | 14107 | int index_mask = 0; |
79e53945 JB |
14108 | int entry = 0; |
14109 | ||
b2784e15 | 14110 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14111 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14112 | index_mask |= (1 << entry); |
14113 | ||
79e53945 JB |
14114 | entry++; |
14115 | } | |
4ef69c7a | 14116 | |
79e53945 JB |
14117 | return index_mask; |
14118 | } | |
14119 | ||
4d302442 CW |
14120 | static bool has_edp_a(struct drm_device *dev) |
14121 | { | |
14122 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14123 | ||
14124 | if (!IS_MOBILE(dev)) | |
14125 | return false; | |
14126 | ||
14127 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14128 | return false; | |
14129 | ||
e3589908 | 14130 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14131 | return false; |
14132 | ||
14133 | return true; | |
14134 | } | |
14135 | ||
84b4e042 JB |
14136 | static bool intel_crt_present(struct drm_device *dev) |
14137 | { | |
14138 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14139 | ||
884497ed DL |
14140 | if (INTEL_INFO(dev)->gen >= 9) |
14141 | return false; | |
14142 | ||
cf404ce4 | 14143 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14144 | return false; |
14145 | ||
14146 | if (IS_CHERRYVIEW(dev)) | |
14147 | return false; | |
14148 | ||
14149 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
14150 | return false; | |
14151 | ||
14152 | return true; | |
14153 | } | |
14154 | ||
79e53945 JB |
14155 | static void intel_setup_outputs(struct drm_device *dev) |
14156 | { | |
725e30ad | 14157 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14158 | struct intel_encoder *encoder; |
cb0953d7 | 14159 | bool dpd_is_edp = false; |
79e53945 | 14160 | |
c9093354 | 14161 | intel_lvds_init(dev); |
79e53945 | 14162 | |
84b4e042 | 14163 | if (intel_crt_present(dev)) |
79935fca | 14164 | intel_crt_init(dev); |
cb0953d7 | 14165 | |
c776eb2e VK |
14166 | if (IS_BROXTON(dev)) { |
14167 | /* | |
14168 | * FIXME: Broxton doesn't support port detection via the | |
14169 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14170 | * detect the ports. | |
14171 | */ | |
14172 | intel_ddi_init(dev, PORT_A); | |
14173 | intel_ddi_init(dev, PORT_B); | |
14174 | intel_ddi_init(dev, PORT_C); | |
14175 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14176 | int found; |
14177 | ||
de31facd JB |
14178 | /* |
14179 | * Haswell uses DDI functions to detect digital outputs. | |
14180 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14181 | * it's there. | |
14182 | */ | |
77179400 | 14183 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14184 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14185 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14186 | intel_ddi_init(dev, PORT_A); |
14187 | ||
14188 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14189 | * register */ | |
14190 | found = I915_READ(SFUSE_STRAP); | |
14191 | ||
14192 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14193 | intel_ddi_init(dev, PORT_B); | |
14194 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14195 | intel_ddi_init(dev, PORT_C); | |
14196 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14197 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14198 | /* |
14199 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14200 | */ | |
ef11bdb3 | 14201 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14202 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14203 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14204 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14205 | intel_ddi_init(dev, PORT_E); | |
14206 | ||
0e72a5b5 | 14207 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14208 | int found; |
5d8a7752 | 14209 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14210 | |
14211 | if (has_edp_a(dev)) | |
14212 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14213 | |
dc0fa718 | 14214 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14215 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 14216 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 14217 | if (!found) |
e2debe91 | 14218 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14219 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14220 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14221 | } |
14222 | ||
dc0fa718 | 14223 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14224 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14225 | |
dc0fa718 | 14226 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14227 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14228 | |
5eb08b69 | 14229 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14230 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14231 | |
270b3042 | 14232 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14233 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14234 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14235 | /* |
14236 | * The DP_DETECTED bit is the latched state of the DDC | |
14237 | * SDA pin at boot. However since eDP doesn't require DDC | |
14238 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14239 | * eDP ports may have been muxed to an alternate function. | |
14240 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14241 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14242 | * detect eDP ports. | |
14243 | */ | |
e66eb81d | 14244 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
d2182a66 | 14245 | !intel_dp_is_edp(dev, PORT_B)) |
e66eb81d VS |
14246 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
14247 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
e17ac6db | 14248 | intel_dp_is_edp(dev, PORT_B)) |
e66eb81d | 14249 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
585a94b8 | 14250 | |
e66eb81d | 14251 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
d2182a66 | 14252 | !intel_dp_is_edp(dev, PORT_C)) |
e66eb81d VS |
14253 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
14254 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
e17ac6db | 14255 | intel_dp_is_edp(dev, PORT_C)) |
e66eb81d | 14256 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
19c03924 | 14257 | |
9418c1f1 | 14258 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14259 | /* eDP not supported on port D, so don't check VBT */ |
e66eb81d VS |
14260 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
14261 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14262 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14263 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
9418c1f1 VS |
14264 | } |
14265 | ||
3cfca973 | 14266 | intel_dsi_init(dev); |
09da55dc | 14267 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14268 | bool found = false; |
7d57382e | 14269 | |
e2debe91 | 14270 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14271 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 14272 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
3fec3d2f | 14273 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14274 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14275 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14276 | } |
27185ae1 | 14277 | |
3fec3d2f | 14278 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14279 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14280 | } |
13520b05 KH |
14281 | |
14282 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14283 | |
e2debe91 | 14284 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14285 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 14286 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 14287 | } |
27185ae1 | 14288 | |
e2debe91 | 14289 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14290 | |
3fec3d2f | 14291 | if (IS_G4X(dev)) { |
b01f2c3a | 14292 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14293 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14294 | } |
3fec3d2f | 14295 | if (IS_G4X(dev)) |
ab9d7c30 | 14296 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14297 | } |
27185ae1 | 14298 | |
3fec3d2f | 14299 | if (IS_G4X(dev) && |
e7281eab | 14300 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14301 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14302 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14303 | intel_dvo_init(dev); |
14304 | ||
103a196f | 14305 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14306 | intel_tv_init(dev); |
14307 | ||
0bc12bcb | 14308 | intel_psr_init(dev); |
7c8f8a70 | 14309 | |
b2784e15 | 14310 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14311 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14312 | encoder->base.possible_clones = | |
66a9278e | 14313 | intel_encoder_clones(encoder); |
79e53945 | 14314 | } |
47356eb6 | 14315 | |
dde86e2d | 14316 | intel_init_pch_refclk(dev); |
270b3042 DV |
14317 | |
14318 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14319 | } |
14320 | ||
14321 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14322 | { | |
60a5ca01 | 14323 | struct drm_device *dev = fb->dev; |
79e53945 | 14324 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14325 | |
ef2d633e | 14326 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14327 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14328 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14329 | drm_gem_object_unreference(&intel_fb->obj->base); |
14330 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14331 | kfree(intel_fb); |
14332 | } | |
14333 | ||
14334 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14335 | struct drm_file *file, |
79e53945 JB |
14336 | unsigned int *handle) |
14337 | { | |
14338 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14339 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14340 | |
05394f39 | 14341 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14342 | } |
14343 | ||
86c98588 RV |
14344 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14345 | struct drm_file *file, | |
14346 | unsigned flags, unsigned color, | |
14347 | struct drm_clip_rect *clips, | |
14348 | unsigned num_clips) | |
14349 | { | |
14350 | struct drm_device *dev = fb->dev; | |
14351 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14352 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14353 | ||
14354 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14355 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14356 | mutex_unlock(&dev->struct_mutex); |
14357 | ||
14358 | return 0; | |
14359 | } | |
14360 | ||
79e53945 JB |
14361 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14362 | .destroy = intel_user_framebuffer_destroy, | |
14363 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14364 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14365 | }; |
14366 | ||
b321803d DL |
14367 | static |
14368 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14369 | uint32_t pixel_format) | |
14370 | { | |
14371 | u32 gen = INTEL_INFO(dev)->gen; | |
14372 | ||
14373 | if (gen >= 9) { | |
14374 | /* "The stride in bytes must not exceed the of the size of 8K | |
14375 | * pixels and 32K bytes." | |
14376 | */ | |
14377 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14378 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14379 | return 32*1024; | |
14380 | } else if (gen >= 4) { | |
14381 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14382 | return 16*1024; | |
14383 | else | |
14384 | return 32*1024; | |
14385 | } else if (gen >= 3) { | |
14386 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14387 | return 8*1024; | |
14388 | else | |
14389 | return 16*1024; | |
14390 | } else { | |
14391 | /* XXX DSPC is limited to 4k tiled */ | |
14392 | return 8*1024; | |
14393 | } | |
14394 | } | |
14395 | ||
b5ea642a DV |
14396 | static int intel_framebuffer_init(struct drm_device *dev, |
14397 | struct intel_framebuffer *intel_fb, | |
14398 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14399 | struct drm_i915_gem_object *obj) | |
79e53945 | 14400 | { |
6761dd31 | 14401 | unsigned int aligned_height; |
79e53945 | 14402 | int ret; |
b321803d | 14403 | u32 pitch_limit, stride_alignment; |
79e53945 | 14404 | |
dd4916c5 DV |
14405 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14406 | ||
2a80eada DV |
14407 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14408 | /* Enforce that fb modifier and tiling mode match, but only for | |
14409 | * X-tiled. This is needed for FBC. */ | |
14410 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14411 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14412 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14413 | return -EINVAL; | |
14414 | } | |
14415 | } else { | |
14416 | if (obj->tiling_mode == I915_TILING_X) | |
14417 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14418 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14419 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14420 | return -EINVAL; | |
14421 | } | |
14422 | } | |
14423 | ||
9a8f0a12 TU |
14424 | /* Passed in modifier sanity checking. */ |
14425 | switch (mode_cmd->modifier[0]) { | |
14426 | case I915_FORMAT_MOD_Y_TILED: | |
14427 | case I915_FORMAT_MOD_Yf_TILED: | |
14428 | if (INTEL_INFO(dev)->gen < 9) { | |
14429 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14430 | mode_cmd->modifier[0]); | |
14431 | return -EINVAL; | |
14432 | } | |
14433 | case DRM_FORMAT_MOD_NONE: | |
14434 | case I915_FORMAT_MOD_X_TILED: | |
14435 | break; | |
14436 | default: | |
c0f40428 JB |
14437 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14438 | mode_cmd->modifier[0]); | |
57cd6508 | 14439 | return -EINVAL; |
c16ed4be | 14440 | } |
57cd6508 | 14441 | |
b321803d DL |
14442 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14443 | mode_cmd->pixel_format); | |
14444 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14445 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14446 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14447 | return -EINVAL; |
c16ed4be | 14448 | } |
57cd6508 | 14449 | |
b321803d DL |
14450 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14451 | mode_cmd->pixel_format); | |
a35cdaa0 | 14452 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14453 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14454 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14455 | "tiled" : "linear", |
a35cdaa0 | 14456 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14457 | return -EINVAL; |
c16ed4be | 14458 | } |
5d7bd705 | 14459 | |
2a80eada | 14460 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14461 | mode_cmd->pitches[0] != obj->stride) { |
14462 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14463 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14464 | return -EINVAL; |
c16ed4be | 14465 | } |
5d7bd705 | 14466 | |
57779d06 | 14467 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14468 | switch (mode_cmd->pixel_format) { |
57779d06 | 14469 | case DRM_FORMAT_C8: |
04b3924d VS |
14470 | case DRM_FORMAT_RGB565: |
14471 | case DRM_FORMAT_XRGB8888: | |
14472 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14473 | break; |
14474 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14475 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14476 | DRM_DEBUG("unsupported pixel format: %s\n", |
14477 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14478 | return -EINVAL; |
c16ed4be | 14479 | } |
57779d06 | 14480 | break; |
57779d06 | 14481 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14482 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14483 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14484 | drm_get_format_name(mode_cmd->pixel_format)); | |
14485 | return -EINVAL; | |
14486 | } | |
14487 | break; | |
14488 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14489 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14490 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14491 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14492 | DRM_DEBUG("unsupported pixel format: %s\n", |
14493 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14494 | return -EINVAL; |
c16ed4be | 14495 | } |
b5626747 | 14496 | break; |
7531208b DL |
14497 | case DRM_FORMAT_ABGR2101010: |
14498 | if (!IS_VALLEYVIEW(dev)) { | |
14499 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14500 | drm_get_format_name(mode_cmd->pixel_format)); | |
14501 | return -EINVAL; | |
14502 | } | |
14503 | break; | |
04b3924d VS |
14504 | case DRM_FORMAT_YUYV: |
14505 | case DRM_FORMAT_UYVY: | |
14506 | case DRM_FORMAT_YVYU: | |
14507 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14508 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14509 | DRM_DEBUG("unsupported pixel format: %s\n", |
14510 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14511 | return -EINVAL; |
c16ed4be | 14512 | } |
57cd6508 CW |
14513 | break; |
14514 | default: | |
4ee62c76 VS |
14515 | DRM_DEBUG("unsupported pixel format: %s\n", |
14516 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14517 | return -EINVAL; |
14518 | } | |
14519 | ||
90f9a336 VS |
14520 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14521 | if (mode_cmd->offsets[0] != 0) | |
14522 | return -EINVAL; | |
14523 | ||
ec2c981e | 14524 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14525 | mode_cmd->pixel_format, |
14526 | mode_cmd->modifier[0]); | |
53155c0a DV |
14527 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14528 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14529 | return -EINVAL; | |
14530 | ||
c7d73f6a DV |
14531 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14532 | intel_fb->obj = obj; | |
80075d49 | 14533 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14534 | |
79e53945 JB |
14535 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14536 | if (ret) { | |
14537 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14538 | return ret; | |
14539 | } | |
14540 | ||
79e53945 JB |
14541 | return 0; |
14542 | } | |
14543 | ||
79e53945 JB |
14544 | static struct drm_framebuffer * |
14545 | intel_user_framebuffer_create(struct drm_device *dev, | |
14546 | struct drm_file *filp, | |
308e5bcb | 14547 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14548 | { |
dcb1394e | 14549 | struct drm_framebuffer *fb; |
05394f39 | 14550 | struct drm_i915_gem_object *obj; |
79e53945 | 14551 | |
308e5bcb JB |
14552 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14553 | mode_cmd->handles[0])); | |
c8725226 | 14554 | if (&obj->base == NULL) |
cce13ff7 | 14555 | return ERR_PTR(-ENOENT); |
79e53945 | 14556 | |
dcb1394e LW |
14557 | fb = intel_framebuffer_create(dev, mode_cmd, obj); |
14558 | if (IS_ERR(fb)) | |
14559 | drm_gem_object_unreference_unlocked(&obj->base); | |
14560 | ||
14561 | return fb; | |
79e53945 JB |
14562 | } |
14563 | ||
0695726e | 14564 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 14565 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14566 | { |
14567 | } | |
14568 | #endif | |
14569 | ||
79e53945 | 14570 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14571 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14572 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14573 | .atomic_check = intel_atomic_check, |
14574 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14575 | .atomic_state_alloc = intel_atomic_state_alloc, |
14576 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14577 | }; |
14578 | ||
e70236a8 JB |
14579 | /* Set up chip specific display functions */ |
14580 | static void intel_init_display(struct drm_device *dev) | |
14581 | { | |
14582 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14583 | ||
ee9300bb DV |
14584 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14585 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14586 | else if (IS_CHERRYVIEW(dev)) |
14587 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14588 | else if (IS_VALLEYVIEW(dev)) |
14589 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14590 | else if (IS_PINEVIEW(dev)) | |
14591 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14592 | else | |
14593 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14594 | ||
bc8d7dff DL |
14595 | if (INTEL_INFO(dev)->gen >= 9) { |
14596 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14597 | dev_priv->display.get_initial_plane_config = |
14598 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14599 | dev_priv->display.crtc_compute_clock = |
14600 | haswell_crtc_compute_clock; | |
14601 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14602 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14603 | dev_priv->display.update_primary_plane = |
14604 | skylake_update_primary_plane; | |
14605 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14606 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14607 | dev_priv->display.get_initial_plane_config = |
14608 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14609 | dev_priv->display.crtc_compute_clock = |
14610 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14611 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14612 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14613 | dev_priv->display.update_primary_plane = |
14614 | ironlake_update_primary_plane; | |
09b4ddf9 | 14615 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14616 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14617 | dev_priv->display.get_initial_plane_config = |
14618 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14619 | dev_priv->display.crtc_compute_clock = |
14620 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14621 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14622 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14623 | dev_priv->display.update_primary_plane = |
14624 | ironlake_update_primary_plane; | |
89b667f8 JB |
14625 | } else if (IS_VALLEYVIEW(dev)) { |
14626 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14627 | dev_priv->display.get_initial_plane_config = |
14628 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14629 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14630 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14631 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14632 | dev_priv->display.update_primary_plane = |
14633 | i9xx_update_primary_plane; | |
f564048e | 14634 | } else { |
0e8ffe1b | 14635 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14636 | dev_priv->display.get_initial_plane_config = |
14637 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14638 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14639 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14640 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14641 | dev_priv->display.update_primary_plane = |
14642 | i9xx_update_primary_plane; | |
f564048e | 14643 | } |
e70236a8 | 14644 | |
e70236a8 | 14645 | /* Returns the core display clock speed */ |
ef11bdb3 | 14646 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
1652d19e VS |
14647 | dev_priv->display.get_display_clock_speed = |
14648 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
14649 | else if (IS_BROXTON(dev)) |
14650 | dev_priv->display.get_display_clock_speed = | |
14651 | broxton_get_display_clock_speed; | |
1652d19e VS |
14652 | else if (IS_BROADWELL(dev)) |
14653 | dev_priv->display.get_display_clock_speed = | |
14654 | broadwell_get_display_clock_speed; | |
14655 | else if (IS_HASWELL(dev)) | |
14656 | dev_priv->display.get_display_clock_speed = | |
14657 | haswell_get_display_clock_speed; | |
14658 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14659 | dev_priv->display.get_display_clock_speed = |
14660 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14661 | else if (IS_GEN5(dev)) |
14662 | dev_priv->display.get_display_clock_speed = | |
14663 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14664 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14665 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14666 | dev_priv->display.get_display_clock_speed = |
14667 | i945_get_display_clock_speed; | |
34edce2f VS |
14668 | else if (IS_GM45(dev)) |
14669 | dev_priv->display.get_display_clock_speed = | |
14670 | gm45_get_display_clock_speed; | |
14671 | else if (IS_CRESTLINE(dev)) | |
14672 | dev_priv->display.get_display_clock_speed = | |
14673 | i965gm_get_display_clock_speed; | |
14674 | else if (IS_PINEVIEW(dev)) | |
14675 | dev_priv->display.get_display_clock_speed = | |
14676 | pnv_get_display_clock_speed; | |
14677 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14678 | dev_priv->display.get_display_clock_speed = | |
14679 | g33_get_display_clock_speed; | |
e70236a8 JB |
14680 | else if (IS_I915G(dev)) |
14681 | dev_priv->display.get_display_clock_speed = | |
14682 | i915_get_display_clock_speed; | |
257a7ffc | 14683 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14684 | dev_priv->display.get_display_clock_speed = |
14685 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14686 | else if (IS_PINEVIEW(dev)) |
14687 | dev_priv->display.get_display_clock_speed = | |
14688 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14689 | else if (IS_I915GM(dev)) |
14690 | dev_priv->display.get_display_clock_speed = | |
14691 | i915gm_get_display_clock_speed; | |
14692 | else if (IS_I865G(dev)) | |
14693 | dev_priv->display.get_display_clock_speed = | |
14694 | i865_get_display_clock_speed; | |
f0f8a9ce | 14695 | else if (IS_I85X(dev)) |
e70236a8 | 14696 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14697 | i85x_get_display_clock_speed; |
623e01e5 VS |
14698 | else { /* 830 */ |
14699 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14700 | dev_priv->display.get_display_clock_speed = |
14701 | i830_get_display_clock_speed; | |
623e01e5 | 14702 | } |
e70236a8 | 14703 | |
7c10a2b5 | 14704 | if (IS_GEN5(dev)) { |
3bb11b53 | 14705 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14706 | } else if (IS_GEN6(dev)) { |
14707 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14708 | } else if (IS_IVYBRIDGE(dev)) { |
14709 | /* FIXME: detect B0+ stepping and use auto training */ | |
14710 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14711 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14712 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
14713 | if (IS_BROADWELL(dev)) { |
14714 | dev_priv->display.modeset_commit_cdclk = | |
14715 | broadwell_modeset_commit_cdclk; | |
14716 | dev_priv->display.modeset_calc_cdclk = | |
14717 | broadwell_modeset_calc_cdclk; | |
14718 | } | |
30a970c6 | 14719 | } else if (IS_VALLEYVIEW(dev)) { |
27c329ed ML |
14720 | dev_priv->display.modeset_commit_cdclk = |
14721 | valleyview_modeset_commit_cdclk; | |
14722 | dev_priv->display.modeset_calc_cdclk = | |
14723 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 14724 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
14725 | dev_priv->display.modeset_commit_cdclk = |
14726 | broxton_modeset_commit_cdclk; | |
14727 | dev_priv->display.modeset_calc_cdclk = | |
14728 | broxton_modeset_calc_cdclk; | |
e70236a8 | 14729 | } |
8c9f3aaf | 14730 | |
8c9f3aaf JB |
14731 | switch (INTEL_INFO(dev)->gen) { |
14732 | case 2: | |
14733 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14734 | break; | |
14735 | ||
14736 | case 3: | |
14737 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14738 | break; | |
14739 | ||
14740 | case 4: | |
14741 | case 5: | |
14742 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14743 | break; | |
14744 | ||
14745 | case 6: | |
14746 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14747 | break; | |
7c9017e5 | 14748 | case 7: |
4e0bbc31 | 14749 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14750 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14751 | break; | |
830c81db | 14752 | case 9: |
ba343e02 TU |
14753 | /* Drop through - unsupported since execlist only. */ |
14754 | default: | |
14755 | /* Default just returns -ENODEV to indicate unsupported */ | |
14756 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14757 | } |
7bd688cd | 14758 | |
e39b999a | 14759 | mutex_init(&dev_priv->pps_mutex); |
e70236a8 JB |
14760 | } |
14761 | ||
b690e96c JB |
14762 | /* |
14763 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14764 | * resume, or other times. This quirk makes sure that's the case for | |
14765 | * affected systems. | |
14766 | */ | |
0206e353 | 14767 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14768 | { |
14769 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14770 | ||
14771 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14772 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14773 | } |
14774 | ||
b6b5d049 VS |
14775 | static void quirk_pipeb_force(struct drm_device *dev) |
14776 | { | |
14777 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14778 | ||
14779 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14780 | DRM_INFO("applying pipe b force quirk\n"); | |
14781 | } | |
14782 | ||
435793df KP |
14783 | /* |
14784 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14785 | */ | |
14786 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14787 | { | |
14788 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14789 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14790 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14791 | } |
14792 | ||
4dca20ef | 14793 | /* |
5a15ab5b CE |
14794 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14795 | * brightness value | |
4dca20ef CE |
14796 | */ |
14797 | static void quirk_invert_brightness(struct drm_device *dev) | |
14798 | { | |
14799 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14800 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14801 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14802 | } |
14803 | ||
9c72cc6f SD |
14804 | /* Some VBT's incorrectly indicate no backlight is present */ |
14805 | static void quirk_backlight_present(struct drm_device *dev) | |
14806 | { | |
14807 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14808 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14809 | DRM_INFO("applying backlight present quirk\n"); | |
14810 | } | |
14811 | ||
b690e96c JB |
14812 | struct intel_quirk { |
14813 | int device; | |
14814 | int subsystem_vendor; | |
14815 | int subsystem_device; | |
14816 | void (*hook)(struct drm_device *dev); | |
14817 | }; | |
14818 | ||
5f85f176 EE |
14819 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14820 | struct intel_dmi_quirk { | |
14821 | void (*hook)(struct drm_device *dev); | |
14822 | const struct dmi_system_id (*dmi_id_list)[]; | |
14823 | }; | |
14824 | ||
14825 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14826 | { | |
14827 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14828 | return 1; | |
14829 | } | |
14830 | ||
14831 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14832 | { | |
14833 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14834 | { | |
14835 | .callback = intel_dmi_reverse_brightness, | |
14836 | .ident = "NCR Corporation", | |
14837 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14838 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14839 | }, | |
14840 | }, | |
14841 | { } /* terminating entry */ | |
14842 | }, | |
14843 | .hook = quirk_invert_brightness, | |
14844 | }, | |
14845 | }; | |
14846 | ||
c43b5634 | 14847 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14848 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14849 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14850 | ||
b690e96c JB |
14851 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14852 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14853 | ||
5f080c0f VS |
14854 | /* 830 needs to leave pipe A & dpll A up */ |
14855 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14856 | ||
b6b5d049 VS |
14857 | /* 830 needs to leave pipe B & dpll B up */ |
14858 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14859 | ||
435793df KP |
14860 | /* Lenovo U160 cannot use SSC on LVDS */ |
14861 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14862 | |
14863 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14864 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14865 | |
be505f64 AH |
14866 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14867 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14868 | ||
14869 | /* Acer/eMachines G725 */ | |
14870 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14871 | ||
14872 | /* Acer/eMachines e725 */ | |
14873 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14874 | ||
14875 | /* Acer/Packard Bell NCL20 */ | |
14876 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14877 | ||
14878 | /* Acer Aspire 4736Z */ | |
14879 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14880 | |
14881 | /* Acer Aspire 5336 */ | |
14882 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14883 | |
14884 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14885 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14886 | |
dfb3d47b SD |
14887 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14888 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14889 | ||
b2a9601c | 14890 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14891 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14892 | ||
d4967d8c SD |
14893 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14894 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14895 | |
14896 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14897 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14898 | |
14899 | /* Dell Chromebook 11 */ | |
14900 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
14901 | }; |
14902 | ||
14903 | static void intel_init_quirks(struct drm_device *dev) | |
14904 | { | |
14905 | struct pci_dev *d = dev->pdev; | |
14906 | int i; | |
14907 | ||
14908 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14909 | struct intel_quirk *q = &intel_quirks[i]; | |
14910 | ||
14911 | if (d->device == q->device && | |
14912 | (d->subsystem_vendor == q->subsystem_vendor || | |
14913 | q->subsystem_vendor == PCI_ANY_ID) && | |
14914 | (d->subsystem_device == q->subsystem_device || | |
14915 | q->subsystem_device == PCI_ANY_ID)) | |
14916 | q->hook(dev); | |
14917 | } | |
5f85f176 EE |
14918 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14919 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14920 | intel_dmi_quirks[i].hook(dev); | |
14921 | } | |
b690e96c JB |
14922 | } |
14923 | ||
9cce37f4 JB |
14924 | /* Disable the VGA plane that we never use */ |
14925 | static void i915_disable_vga(struct drm_device *dev) | |
14926 | { | |
14927 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14928 | u8 sr1; | |
766aa1c4 | 14929 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 14930 | |
2b37c616 | 14931 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 14932 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 14933 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
14934 | sr1 = inb(VGA_SR_DATA); |
14935 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
14936 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
14937 | udelay(300); | |
14938 | ||
01f5a626 | 14939 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
14940 | POSTING_READ(vga_reg); |
14941 | } | |
14942 | ||
f817586c DV |
14943 | void intel_modeset_init_hw(struct drm_device *dev) |
14944 | { | |
b6283055 | 14945 | intel_update_cdclk(dev); |
a8f78b58 | 14946 | intel_prepare_ddi(dev); |
f817586c | 14947 | intel_init_clock_gating(dev); |
8090c6b9 | 14948 | intel_enable_gt_powersave(dev); |
f817586c DV |
14949 | } |
14950 | ||
79e53945 JB |
14951 | void intel_modeset_init(struct drm_device *dev) |
14952 | { | |
652c393a | 14953 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 14954 | int sprite, ret; |
8cc87b75 | 14955 | enum pipe pipe; |
46f297fb | 14956 | struct intel_crtc *crtc; |
79e53945 JB |
14957 | |
14958 | drm_mode_config_init(dev); | |
14959 | ||
14960 | dev->mode_config.min_width = 0; | |
14961 | dev->mode_config.min_height = 0; | |
14962 | ||
019d96cb DA |
14963 | dev->mode_config.preferred_depth = 24; |
14964 | dev->mode_config.prefer_shadow = 1; | |
14965 | ||
25bab385 TU |
14966 | dev->mode_config.allow_fb_modifiers = true; |
14967 | ||
e6ecefaa | 14968 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 14969 | |
b690e96c JB |
14970 | intel_init_quirks(dev); |
14971 | ||
1fa61106 ED |
14972 | intel_init_pm(dev); |
14973 | ||
e3c74757 BW |
14974 | if (INTEL_INFO(dev)->num_pipes == 0) |
14975 | return; | |
14976 | ||
69f92f67 LW |
14977 | /* |
14978 | * There may be no VBT; and if the BIOS enabled SSC we can | |
14979 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
14980 | * BIOS isn't using it, don't assume it will work even if the VBT | |
14981 | * indicates as much. | |
14982 | */ | |
14983 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
14984 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
14985 | DREF_SSC1_ENABLE); | |
14986 | ||
14987 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
14988 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
14989 | bios_lvds_use_ssc ? "en" : "dis", | |
14990 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
14991 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
14992 | } | |
14993 | } | |
14994 | ||
e70236a8 | 14995 | intel_init_display(dev); |
7c10a2b5 | 14996 | intel_init_audio(dev); |
e70236a8 | 14997 | |
a6c45cf0 CW |
14998 | if (IS_GEN2(dev)) { |
14999 | dev->mode_config.max_width = 2048; | |
15000 | dev->mode_config.max_height = 2048; | |
15001 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15002 | dev->mode_config.max_width = 4096; |
15003 | dev->mode_config.max_height = 4096; | |
79e53945 | 15004 | } else { |
a6c45cf0 CW |
15005 | dev->mode_config.max_width = 8192; |
15006 | dev->mode_config.max_height = 8192; | |
79e53945 | 15007 | } |
068be561 | 15008 | |
dc41c154 VS |
15009 | if (IS_845G(dev) || IS_I865G(dev)) { |
15010 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15011 | dev->mode_config.cursor_height = 1023; | |
15012 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15013 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15014 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15015 | } else { | |
15016 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15017 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15018 | } | |
15019 | ||
5d4545ae | 15020 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15021 | |
28c97730 | 15022 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15023 | INTEL_INFO(dev)->num_pipes, |
15024 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15025 | |
055e393f | 15026 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15027 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15028 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15029 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15030 | if (ret) |
06da8da2 | 15031 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15032 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15033 | } |
79e53945 JB |
15034 | } |
15035 | ||
bfa7df01 VS |
15036 | intel_update_czclk(dev_priv); |
15037 | intel_update_cdclk(dev); | |
15038 | ||
e72f9fbf | 15039 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15040 | |
9cce37f4 JB |
15041 | /* Just disable it once at startup */ |
15042 | i915_disable_vga(dev); | |
79e53945 | 15043 | intel_setup_outputs(dev); |
11be49eb | 15044 | |
6e9f798d | 15045 | drm_modeset_lock_all(dev); |
043e9bda | 15046 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15047 | drm_modeset_unlock_all(dev); |
46f297fb | 15048 | |
d3fcc808 | 15049 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15050 | struct intel_initial_plane_config plane_config = {}; |
15051 | ||
46f297fb JB |
15052 | if (!crtc->active) |
15053 | continue; | |
15054 | ||
46f297fb | 15055 | /* |
46f297fb JB |
15056 | * Note that reserving the BIOS fb up front prevents us |
15057 | * from stuffing other stolen allocations like the ring | |
15058 | * on top. This prevents some ugliness at boot time, and | |
15059 | * can even allow for smooth boot transitions if the BIOS | |
15060 | * fb is large enough for the active pipe configuration. | |
15061 | */ | |
eeebeac5 ML |
15062 | dev_priv->display.get_initial_plane_config(crtc, |
15063 | &plane_config); | |
15064 | ||
15065 | /* | |
15066 | * If the fb is shared between multiple heads, we'll | |
15067 | * just get the first one. | |
15068 | */ | |
15069 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15070 | } |
2c7111db CW |
15071 | } |
15072 | ||
7fad798e DV |
15073 | static void intel_enable_pipe_a(struct drm_device *dev) |
15074 | { | |
15075 | struct intel_connector *connector; | |
15076 | struct drm_connector *crt = NULL; | |
15077 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15078 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15079 | |
15080 | /* We can't just switch on the pipe A, we need to set things up with a | |
15081 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15082 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15083 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15084 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15085 | crt = &connector->base; | |
15086 | break; | |
15087 | } | |
15088 | } | |
15089 | ||
15090 | if (!crt) | |
15091 | return; | |
15092 | ||
208bf9fd | 15093 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15094 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15095 | } |
15096 | ||
fa555837 DV |
15097 | static bool |
15098 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15099 | { | |
7eb552ae BW |
15100 | struct drm_device *dev = crtc->base.dev; |
15101 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15102 | u32 val; |
fa555837 | 15103 | |
7eb552ae | 15104 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15105 | return true; |
15106 | ||
649636ef | 15107 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15108 | |
15109 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15110 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15111 | return false; | |
15112 | ||
15113 | return true; | |
15114 | } | |
15115 | ||
02e93c35 VS |
15116 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15117 | { | |
15118 | struct drm_device *dev = crtc->base.dev; | |
15119 | struct intel_encoder *encoder; | |
15120 | ||
15121 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15122 | return true; | |
15123 | ||
15124 | return false; | |
15125 | } | |
15126 | ||
24929352 DV |
15127 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15128 | { | |
15129 | struct drm_device *dev = crtc->base.dev; | |
15130 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 | 15131 | u32 reg; |
24929352 | 15132 | |
24929352 | 15133 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 15134 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
15135 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15136 | ||
d3eaf884 | 15137 | /* restore vblank interrupts to correct state */ |
9625604c | 15138 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15139 | if (crtc->active) { |
f9cd7b88 VS |
15140 | struct intel_plane *plane; |
15141 | ||
9625604c | 15142 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15143 | |
15144 | /* Disable everything but the primary plane */ | |
15145 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15146 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15147 | continue; | |
15148 | ||
15149 | plane->disable_plane(&plane->base, &crtc->base); | |
15150 | } | |
9625604c | 15151 | } |
d3eaf884 | 15152 | |
24929352 | 15153 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15154 | * disable the crtc (and hence change the state) if it is wrong. Note |
15155 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15156 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15157 | bool plane; |
15158 | ||
24929352 DV |
15159 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15160 | crtc->base.base.id); | |
15161 | ||
15162 | /* Pipe has the wrong plane attached and the plane is active. | |
15163 | * Temporarily change the plane mapping and disable everything | |
15164 | * ... */ | |
15165 | plane = crtc->plane; | |
b70709a6 | 15166 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15167 | crtc->plane = !plane; |
b17d48e2 | 15168 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15169 | crtc->plane = plane; |
24929352 | 15170 | } |
24929352 | 15171 | |
7fad798e DV |
15172 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15173 | crtc->pipe == PIPE_A && !crtc->active) { | |
15174 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15175 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15176 | * call below we restore the pipe to the right state, but leave | |
15177 | * the required bits on. */ | |
15178 | intel_enable_pipe_a(dev); | |
15179 | } | |
15180 | ||
24929352 DV |
15181 | /* Adjust the state of the output pipe according to whether we |
15182 | * have active connectors/encoders. */ | |
02e93c35 | 15183 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15184 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15185 | |
53d9f4e9 | 15186 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 15187 | struct intel_encoder *encoder; |
24929352 DV |
15188 | |
15189 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15190 | * functions or because of calls to intel_crtc_disable_noatomic, |
15191 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15192 | * pipe A quirk. */ |
15193 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15194 | crtc->base.base.id, | |
83d65738 | 15195 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15196 | crtc->active ? "enabled" : "disabled"); |
15197 | ||
4be40c98 | 15198 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 15199 | crtc->base.state->active = crtc->active; |
24929352 DV |
15200 | crtc->base.enabled = crtc->active; |
15201 | ||
15202 | /* Because we only establish the connector -> encoder -> | |
15203 | * crtc links if something is active, this means the | |
15204 | * crtc is now deactivated. Break the links. connector | |
15205 | * -> encoder links are only establish when things are | |
15206 | * actually up, hence no need to break them. */ | |
15207 | WARN_ON(crtc->active); | |
15208 | ||
2d406bb0 | 15209 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 15210 | encoder->base.crtc = NULL; |
24929352 | 15211 | } |
c5ab3bc0 | 15212 | |
a3ed6aad | 15213 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15214 | /* |
15215 | * We start out with underrun reporting disabled to avoid races. | |
15216 | * For correct bookkeeping mark this on active crtcs. | |
15217 | * | |
c5ab3bc0 DV |
15218 | * Also on gmch platforms we dont have any hardware bits to |
15219 | * disable the underrun reporting. Which means we need to start | |
15220 | * out with underrun reporting disabled also on inactive pipes, | |
15221 | * since otherwise we'll complain about the garbage we read when | |
15222 | * e.g. coming up after runtime pm. | |
15223 | * | |
4cc31489 DV |
15224 | * No protection against concurrent access is required - at |
15225 | * worst a fifo underrun happens which also sets this to false. | |
15226 | */ | |
15227 | crtc->cpu_fifo_underrun_disabled = true; | |
15228 | crtc->pch_fifo_underrun_disabled = true; | |
15229 | } | |
24929352 DV |
15230 | } |
15231 | ||
15232 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15233 | { | |
15234 | struct intel_connector *connector; | |
15235 | struct drm_device *dev = encoder->base.dev; | |
873ffe69 | 15236 | bool active = false; |
24929352 DV |
15237 | |
15238 | /* We need to check both for a crtc link (meaning that the | |
15239 | * encoder is active and trying to read from a pipe) and the | |
15240 | * pipe itself being active. */ | |
15241 | bool has_active_crtc = encoder->base.crtc && | |
15242 | to_intel_crtc(encoder->base.crtc)->active; | |
15243 | ||
873ffe69 ML |
15244 | for_each_intel_connector(dev, connector) { |
15245 | if (connector->base.encoder != &encoder->base) | |
15246 | continue; | |
15247 | ||
15248 | active = true; | |
15249 | break; | |
15250 | } | |
15251 | ||
15252 | if (active && !has_active_crtc) { | |
24929352 DV |
15253 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15254 | encoder->base.base.id, | |
8e329a03 | 15255 | encoder->base.name); |
24929352 DV |
15256 | |
15257 | /* Connector is active, but has no active pipe. This is | |
15258 | * fallout from our resume register restoring. Disable | |
15259 | * the encoder manually again. */ | |
15260 | if (encoder->base.crtc) { | |
15261 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15262 | encoder->base.base.id, | |
8e329a03 | 15263 | encoder->base.name); |
24929352 | 15264 | encoder->disable(encoder); |
a62d1497 VS |
15265 | if (encoder->post_disable) |
15266 | encoder->post_disable(encoder); | |
24929352 | 15267 | } |
7f1950fb | 15268 | encoder->base.crtc = NULL; |
24929352 DV |
15269 | |
15270 | /* Inconsistent output/port/pipe state happens presumably due to | |
15271 | * a bug in one of the get_hw_state functions. Or someplace else | |
15272 | * in our code, like the register restore mess on resume. Clamp | |
15273 | * things to off as a safer default. */ | |
3a3371ff | 15274 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15275 | if (connector->encoder != encoder) |
15276 | continue; | |
7f1950fb EE |
15277 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15278 | connector->base.encoder = NULL; | |
24929352 DV |
15279 | } |
15280 | } | |
15281 | /* Enabled encoders without active connectors will be fixed in | |
15282 | * the crtc fixup. */ | |
15283 | } | |
15284 | ||
04098753 | 15285 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15286 | { |
15287 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 15288 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15289 | |
04098753 ID |
15290 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15291 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15292 | i915_disable_vga(dev); | |
15293 | } | |
15294 | } | |
15295 | ||
15296 | void i915_redisable_vga(struct drm_device *dev) | |
15297 | { | |
15298 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15299 | ||
8dc8a27c PZ |
15300 | /* This function can be called both from intel_modeset_setup_hw_state or |
15301 | * at a very early point in our resume sequence, where the power well | |
15302 | * structures are not yet restored. Since this function is at a very | |
15303 | * paranoid "someone might have enabled VGA while we were not looking" | |
15304 | * level, just check if the power well is enabled instead of trying to | |
15305 | * follow the "don't touch the power well if we don't need it" policy | |
15306 | * the rest of the driver uses. */ | |
f458ebbc | 15307 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15308 | return; |
15309 | ||
04098753 | 15310 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15311 | } |
15312 | ||
f9cd7b88 | 15313 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15314 | { |
f9cd7b88 | 15315 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15316 | |
f9cd7b88 | 15317 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15318 | } |
15319 | ||
f9cd7b88 VS |
15320 | /* FIXME read out full plane state for all planes */ |
15321 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15322 | { |
b26d3ea3 | 15323 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15324 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15325 | to_intel_plane_state(primary->state); |
d032ffa0 | 15326 | |
19b8d387 | 15327 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
15328 | primary_get_hw_state(to_intel_plane(primary)); |
15329 | ||
15330 | if (plane_state->visible) | |
15331 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
15332 | } |
15333 | ||
30e984df | 15334 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15335 | { |
15336 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15337 | enum pipe pipe; | |
24929352 DV |
15338 | struct intel_crtc *crtc; |
15339 | struct intel_encoder *encoder; | |
15340 | struct intel_connector *connector; | |
5358901f | 15341 | int i; |
24929352 | 15342 | |
d3fcc808 | 15343 | for_each_intel_crtc(dev, crtc) { |
b06f8b0d | 15344 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
6e3c9717 | 15345 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15346 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15347 | |
0e8ffe1b | 15348 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15349 | crtc->config); |
24929352 | 15350 | |
49d6fa21 | 15351 | crtc->base.state->active = crtc->active; |
24929352 | 15352 | crtc->base.enabled = crtc->active; |
b70709a6 | 15353 | |
f9cd7b88 | 15354 | readout_plane_state(crtc); |
24929352 DV |
15355 | |
15356 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15357 | crtc->base.base.id, | |
15358 | crtc->active ? "enabled" : "disabled"); | |
15359 | } | |
15360 | ||
5358901f DV |
15361 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15362 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15363 | ||
3e369b76 ACO |
15364 | pll->on = pll->get_hw_state(dev_priv, pll, |
15365 | &pll->config.hw_state); | |
5358901f | 15366 | pll->active = 0; |
3e369b76 | 15367 | pll->config.crtc_mask = 0; |
d3fcc808 | 15368 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15369 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15370 | pll->active++; |
3e369b76 | 15371 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15372 | } |
5358901f | 15373 | } |
5358901f | 15374 | |
1e6f2ddc | 15375 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15376 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15377 | |
3e369b76 | 15378 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15379 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15380 | } |
15381 | ||
b2784e15 | 15382 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15383 | pipe = 0; |
15384 | ||
15385 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15386 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15387 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15388 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15389 | } else { |
15390 | encoder->base.crtc = NULL; | |
15391 | } | |
15392 | ||
6f2bcceb | 15393 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15394 | encoder->base.base.id, |
8e329a03 | 15395 | encoder->base.name, |
24929352 | 15396 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15397 | pipe_name(pipe)); |
24929352 DV |
15398 | } |
15399 | ||
3a3371ff | 15400 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15401 | if (connector->get_hw_state(connector)) { |
15402 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
24929352 DV |
15403 | connector->base.encoder = &connector->encoder->base; |
15404 | } else { | |
15405 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15406 | connector->base.encoder = NULL; | |
15407 | } | |
15408 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15409 | connector->base.base.id, | |
c23cc417 | 15410 | connector->base.name, |
24929352 DV |
15411 | connector->base.encoder ? "enabled" : "disabled"); |
15412 | } | |
7f4c6284 VS |
15413 | |
15414 | for_each_intel_crtc(dev, crtc) { | |
15415 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
15416 | ||
15417 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
15418 | if (crtc->base.state->active) { | |
15419 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
15420 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
15421 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
15422 | ||
15423 | /* | |
15424 | * The initial mode needs to be set in order to keep | |
15425 | * the atomic core happy. It wants a valid mode if the | |
15426 | * crtc's enabled, so we do the above call. | |
15427 | * | |
15428 | * At this point some state updated by the connectors | |
15429 | * in their ->detect() callback has not run yet, so | |
15430 | * no recalculation can be done yet. | |
15431 | * | |
15432 | * Even if we could do a recalculation and modeset | |
15433 | * right now it would cause a double modeset if | |
15434 | * fbdev or userspace chooses a different initial mode. | |
15435 | * | |
15436 | * If that happens, someone indicated they wanted a | |
15437 | * mode change, which means it's safe to do a full | |
15438 | * recalculation. | |
15439 | */ | |
15440 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
15441 | |
15442 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
15443 | update_scanline_offset(crtc); | |
7f4c6284 VS |
15444 | } |
15445 | } | |
30e984df DV |
15446 | } |
15447 | ||
043e9bda ML |
15448 | /* Scan out the current hw modeset state, |
15449 | * and sanitizes it to the current state | |
15450 | */ | |
15451 | static void | |
15452 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
15453 | { |
15454 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15455 | enum pipe pipe; | |
30e984df DV |
15456 | struct intel_crtc *crtc; |
15457 | struct intel_encoder *encoder; | |
35c95375 | 15458 | int i; |
30e984df DV |
15459 | |
15460 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
15461 | |
15462 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 15463 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15464 | intel_sanitize_encoder(encoder); |
15465 | } | |
15466 | ||
055e393f | 15467 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15468 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15469 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15470 | intel_dump_pipe_config(crtc, crtc->config, |
15471 | "[setup_hw_state]"); | |
24929352 | 15472 | } |
9a935856 | 15473 | |
d29b2f9d ACO |
15474 | intel_modeset_update_connector_atomic_state(dev); |
15475 | ||
35c95375 DV |
15476 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15477 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15478 | ||
15479 | if (!pll->on || pll->active) | |
15480 | continue; | |
15481 | ||
15482 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15483 | ||
15484 | pll->disable(dev_priv, pll); | |
15485 | pll->on = false; | |
15486 | } | |
15487 | ||
26e1fe4f | 15488 | if (IS_VALLEYVIEW(dev)) |
6eb1a681 VS |
15489 | vlv_wm_get_hw_state(dev); |
15490 | else if (IS_GEN9(dev)) | |
3078999f PB |
15491 | skl_wm_get_hw_state(dev); |
15492 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 15493 | ilk_wm_get_hw_state(dev); |
292b990e ML |
15494 | |
15495 | for_each_intel_crtc(dev, crtc) { | |
15496 | unsigned long put_domains; | |
15497 | ||
15498 | put_domains = modeset_get_crtc_power_domains(&crtc->base); | |
15499 | if (WARN_ON(put_domains)) | |
15500 | modeset_put_power_domains(dev_priv, put_domains); | |
15501 | } | |
15502 | intel_display_set_init_power(dev_priv, false); | |
043e9bda | 15503 | } |
7d0bc1ea | 15504 | |
043e9bda ML |
15505 | void intel_display_resume(struct drm_device *dev) |
15506 | { | |
15507 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); | |
15508 | struct intel_connector *conn; | |
15509 | struct intel_plane *plane; | |
15510 | struct drm_crtc *crtc; | |
15511 | int ret; | |
f30da187 | 15512 | |
043e9bda ML |
15513 | if (!state) |
15514 | return; | |
15515 | ||
15516 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
15517 | ||
15518 | /* preserve complete old state, including dpll */ | |
15519 | intel_atomic_get_shared_dpll_state(state); | |
15520 | ||
15521 | for_each_crtc(dev, crtc) { | |
15522 | struct drm_crtc_state *crtc_state = | |
15523 | drm_atomic_get_crtc_state(state, crtc); | |
15524 | ||
15525 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
15526 | if (ret) | |
15527 | goto err; | |
15528 | ||
15529 | /* force a restore */ | |
15530 | crtc_state->mode_changed = true; | |
45e2b5f6 | 15531 | } |
8af6cf88 | 15532 | |
043e9bda ML |
15533 | for_each_intel_plane(dev, plane) { |
15534 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); | |
15535 | if (ret) | |
15536 | goto err; | |
15537 | } | |
15538 | ||
15539 | for_each_intel_connector(dev, conn) { | |
15540 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); | |
15541 | if (ret) | |
15542 | goto err; | |
15543 | } | |
15544 | ||
15545 | intel_modeset_setup_hw_state(dev); | |
15546 | ||
15547 | i915_redisable_vga(dev); | |
74c090b1 | 15548 | ret = drm_atomic_commit(state); |
043e9bda ML |
15549 | if (!ret) |
15550 | return; | |
15551 | ||
15552 | err: | |
15553 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
15554 | drm_atomic_state_free(state); | |
2c7111db CW |
15555 | } |
15556 | ||
15557 | void intel_modeset_gem_init(struct drm_device *dev) | |
15558 | { | |
484b41dd | 15559 | struct drm_crtc *c; |
2ff8fde1 | 15560 | struct drm_i915_gem_object *obj; |
e0d6149b | 15561 | int ret; |
484b41dd | 15562 | |
ae48434c ID |
15563 | mutex_lock(&dev->struct_mutex); |
15564 | intel_init_gt_powersave(dev); | |
15565 | mutex_unlock(&dev->struct_mutex); | |
15566 | ||
1833b134 | 15567 | intel_modeset_init_hw(dev); |
02e792fb DV |
15568 | |
15569 | intel_setup_overlay(dev); | |
484b41dd JB |
15570 | |
15571 | /* | |
15572 | * Make sure any fbs we allocated at startup are properly | |
15573 | * pinned & fenced. When we do the allocation it's too early | |
15574 | * for this. | |
15575 | */ | |
70e1e0ec | 15576 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15577 | obj = intel_fb_obj(c->primary->fb); |
15578 | if (obj == NULL) | |
484b41dd JB |
15579 | continue; |
15580 | ||
e0d6149b TU |
15581 | mutex_lock(&dev->struct_mutex); |
15582 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15583 | c->primary->fb, | |
7580d774 | 15584 | c->primary->state); |
e0d6149b TU |
15585 | mutex_unlock(&dev->struct_mutex); |
15586 | if (ret) { | |
484b41dd JB |
15587 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15588 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15589 | drm_framebuffer_unreference(c->primary->fb); |
15590 | c->primary->fb = NULL; | |
36750f28 | 15591 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15592 | update_state_fb(c->primary); |
36750f28 | 15593 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15594 | } |
15595 | } | |
0962c3c9 VS |
15596 | |
15597 | intel_backlight_register(dev); | |
79e53945 JB |
15598 | } |
15599 | ||
4932e2c3 ID |
15600 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15601 | { | |
15602 | struct drm_connector *connector = &intel_connector->base; | |
15603 | ||
15604 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15605 | drm_connector_unregister(connector); |
4932e2c3 ID |
15606 | } |
15607 | ||
79e53945 JB |
15608 | void intel_modeset_cleanup(struct drm_device *dev) |
15609 | { | |
652c393a | 15610 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15611 | struct drm_connector *connector; |
652c393a | 15612 | |
2eb5252e ID |
15613 | intel_disable_gt_powersave(dev); |
15614 | ||
0962c3c9 VS |
15615 | intel_backlight_unregister(dev); |
15616 | ||
fd0c0642 DV |
15617 | /* |
15618 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15619 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15620 | * experience fancy races otherwise. |
15621 | */ | |
2aeb7d3a | 15622 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15623 | |
fd0c0642 DV |
15624 | /* |
15625 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15626 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15627 | */ | |
f87ea761 | 15628 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15629 | |
723bfd70 JB |
15630 | intel_unregister_dsm_handler(); |
15631 | ||
7733b49b | 15632 | intel_fbc_disable(dev_priv); |
69341a5e | 15633 | |
1630fe75 CW |
15634 | /* flush any delayed tasks or pending work */ |
15635 | flush_scheduled_work(); | |
15636 | ||
db31af1d JN |
15637 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15638 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15639 | struct intel_connector *intel_connector; |
15640 | ||
15641 | intel_connector = to_intel_connector(connector); | |
15642 | intel_connector->unregister(intel_connector); | |
db31af1d | 15643 | } |
d9255d57 | 15644 | |
79e53945 | 15645 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15646 | |
15647 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15648 | |
15649 | mutex_lock(&dev->struct_mutex); | |
15650 | intel_cleanup_gt_powersave(dev); | |
15651 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15652 | } |
15653 | ||
f1c79df3 ZW |
15654 | /* |
15655 | * Return which encoder is currently attached for connector. | |
15656 | */ | |
df0e9248 | 15657 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15658 | { |
df0e9248 CW |
15659 | return &intel_attached_encoder(connector)->base; |
15660 | } | |
f1c79df3 | 15661 | |
df0e9248 CW |
15662 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15663 | struct intel_encoder *encoder) | |
15664 | { | |
15665 | connector->encoder = encoder; | |
15666 | drm_mode_connector_attach_encoder(&connector->base, | |
15667 | &encoder->base); | |
79e53945 | 15668 | } |
28d52043 DA |
15669 | |
15670 | /* | |
15671 | * set vga decode state - true == enable VGA decode | |
15672 | */ | |
15673 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15674 | { | |
15675 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15676 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15677 | u16 gmch_ctrl; |
15678 | ||
75fa041d CW |
15679 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15680 | DRM_ERROR("failed to read control word\n"); | |
15681 | return -EIO; | |
15682 | } | |
15683 | ||
c0cc8a55 CW |
15684 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15685 | return 0; | |
15686 | ||
28d52043 DA |
15687 | if (state) |
15688 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15689 | else | |
15690 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15691 | |
15692 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15693 | DRM_ERROR("failed to write control word\n"); | |
15694 | return -EIO; | |
15695 | } | |
15696 | ||
28d52043 DA |
15697 | return 0; |
15698 | } | |
c4a1d9e4 | 15699 | |
c4a1d9e4 | 15700 | struct intel_display_error_state { |
ff57f1b0 PZ |
15701 | |
15702 | u32 power_well_driver; | |
15703 | ||
63b66e5b CW |
15704 | int num_transcoders; |
15705 | ||
c4a1d9e4 CW |
15706 | struct intel_cursor_error_state { |
15707 | u32 control; | |
15708 | u32 position; | |
15709 | u32 base; | |
15710 | u32 size; | |
52331309 | 15711 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15712 | |
15713 | struct intel_pipe_error_state { | |
ddf9c536 | 15714 | bool power_domain_on; |
c4a1d9e4 | 15715 | u32 source; |
f301b1e1 | 15716 | u32 stat; |
52331309 | 15717 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15718 | |
15719 | struct intel_plane_error_state { | |
15720 | u32 control; | |
15721 | u32 stride; | |
15722 | u32 size; | |
15723 | u32 pos; | |
15724 | u32 addr; | |
15725 | u32 surface; | |
15726 | u32 tile_offset; | |
52331309 | 15727 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15728 | |
15729 | struct intel_transcoder_error_state { | |
ddf9c536 | 15730 | bool power_domain_on; |
63b66e5b CW |
15731 | enum transcoder cpu_transcoder; |
15732 | ||
15733 | u32 conf; | |
15734 | ||
15735 | u32 htotal; | |
15736 | u32 hblank; | |
15737 | u32 hsync; | |
15738 | u32 vtotal; | |
15739 | u32 vblank; | |
15740 | u32 vsync; | |
15741 | } transcoder[4]; | |
c4a1d9e4 CW |
15742 | }; |
15743 | ||
15744 | struct intel_display_error_state * | |
15745 | intel_display_capture_error_state(struct drm_device *dev) | |
15746 | { | |
fbee40df | 15747 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15748 | struct intel_display_error_state *error; |
63b66e5b CW |
15749 | int transcoders[] = { |
15750 | TRANSCODER_A, | |
15751 | TRANSCODER_B, | |
15752 | TRANSCODER_C, | |
15753 | TRANSCODER_EDP, | |
15754 | }; | |
c4a1d9e4 CW |
15755 | int i; |
15756 | ||
63b66e5b CW |
15757 | if (INTEL_INFO(dev)->num_pipes == 0) |
15758 | return NULL; | |
15759 | ||
9d1cb914 | 15760 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15761 | if (error == NULL) |
15762 | return NULL; | |
15763 | ||
190be112 | 15764 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15765 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15766 | ||
055e393f | 15767 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15768 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15769 | __intel_display_power_is_enabled(dev_priv, |
15770 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15771 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15772 | continue; |
15773 | ||
5efb3e28 VS |
15774 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15775 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15776 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15777 | |
15778 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15779 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15780 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15781 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15782 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15783 | } | |
ca291363 PZ |
15784 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15785 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15786 | if (INTEL_INFO(dev)->gen >= 4) { |
15787 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15788 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15789 | } | |
15790 | ||
c4a1d9e4 | 15791 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15792 | |
3abfce77 | 15793 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15794 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15795 | } |
15796 | ||
15797 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15798 | if (HAS_DDI(dev_priv->dev)) | |
15799 | error->num_transcoders++; /* Account for eDP. */ | |
15800 | ||
15801 | for (i = 0; i < error->num_transcoders; i++) { | |
15802 | enum transcoder cpu_transcoder = transcoders[i]; | |
15803 | ||
ddf9c536 | 15804 | error->transcoder[i].power_domain_on = |
f458ebbc | 15805 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15806 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15807 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15808 | continue; |
15809 | ||
63b66e5b CW |
15810 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15811 | ||
15812 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15813 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15814 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15815 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15816 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15817 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15818 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15819 | } |
15820 | ||
15821 | return error; | |
15822 | } | |
15823 | ||
edc3d884 MK |
15824 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15825 | ||
c4a1d9e4 | 15826 | void |
edc3d884 | 15827 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15828 | struct drm_device *dev, |
15829 | struct intel_display_error_state *error) | |
15830 | { | |
055e393f | 15831 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15832 | int i; |
15833 | ||
63b66e5b CW |
15834 | if (!error) |
15835 | return; | |
15836 | ||
edc3d884 | 15837 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15838 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15839 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15840 | error->power_well_driver); |
055e393f | 15841 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15842 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15843 | err_printf(m, " Power: %s\n", |
15844 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15845 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15846 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15847 | |
15848 | err_printf(m, "Plane [%d]:\n", i); | |
15849 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15850 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15851 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15852 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15853 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15854 | } |
4b71a570 | 15855 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15856 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15857 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15858 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15859 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15860 | } |
15861 | ||
edc3d884 MK |
15862 | err_printf(m, "Cursor [%d]:\n", i); |
15863 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15864 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15865 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15866 | } |
63b66e5b CW |
15867 | |
15868 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15869 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15870 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15871 | err_printf(m, " Power: %s\n", |
15872 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15873 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15874 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15875 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15876 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15877 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15878 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15879 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15880 | } | |
c4a1d9e4 | 15881 | } |
e2fcdaa9 VS |
15882 | |
15883 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
15884 | { | |
15885 | struct intel_crtc *crtc; | |
15886 | ||
15887 | for_each_intel_crtc(dev, crtc) { | |
15888 | struct intel_unpin_work *work; | |
e2fcdaa9 | 15889 | |
5e2d7afc | 15890 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15891 | |
15892 | work = crtc->unpin_work; | |
15893 | ||
15894 | if (work && work->event && | |
15895 | work->event->base.file_priv == file) { | |
15896 | kfree(work->event); | |
15897 | work->event = NULL; | |
15898 | } | |
15899 | ||
5e2d7afc | 15900 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15901 | } |
15902 | } |