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 | ||
4e961e42 AM |
5705 | /* |
5706 | * DMC assumes ownership of LCPLL and will get confused if we touch it. | |
5707 | */ | |
5708 | if (dev_priv->csr.dmc_payload) { | |
5709 | /* disable DPLL0 */ | |
5710 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & | |
5711 | ~LCPLL_PLL_ENABLE); | |
5712 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5713 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5714 | } | |
5d96d8af DL |
5715 | } |
5716 | ||
5717 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5718 | { | |
5d96d8af DL |
5719 | unsigned int required_vco; |
5720 | ||
39d9b85a GW |
5721 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5722 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5723 | /* enable DPLL0 */ | |
5724 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5725 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5726 | } |
5727 | ||
5d96d8af DL |
5728 | /* set CDCLK to the frequency the BIOS chose */ |
5729 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5730 | ||
5731 | /* enable DBUF power */ | |
5732 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5733 | POSTING_READ(DBUF_CTL); | |
5734 | ||
5735 | udelay(10); | |
5736 | ||
5737 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5738 | DRM_ERROR("DBuf power enable timeout\n"); | |
5739 | } | |
5740 | ||
c73666f3 SK |
5741 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
5742 | { | |
5743 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5744 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5745 | int freq = dev_priv->skl_boot_cdclk; | |
5746 | ||
f1b391a5 SK |
5747 | /* |
5748 | * check if the pre-os intialized the display | |
5749 | * There is SWF18 scratchpad register defined which is set by the | |
5750 | * pre-os which can be used by the OS drivers to check the status | |
5751 | */ | |
5752 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5753 | goto sanitize; | |
5754 | ||
c73666f3 SK |
5755 | /* Is PLL enabled and locked ? */ |
5756 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5757 | goto sanitize; | |
5758 | ||
5759 | /* DPLL okay; verify the cdclock | |
5760 | * | |
5761 | * Noticed in some instances that the freq selection is correct but | |
5762 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5763 | * enable display. Verify the same as well. | |
5764 | */ | |
5765 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5766 | /* All well; nothing to sanitize */ | |
5767 | return false; | |
5768 | sanitize: | |
5769 | /* | |
5770 | * As of now initialize with max cdclk till | |
5771 | * we get dynamic cdclk support | |
5772 | * */ | |
5773 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5774 | skl_init_cdclk(dev_priv); | |
5775 | ||
5776 | /* we did have to sanitize */ | |
5777 | return true; | |
5778 | } | |
5779 | ||
30a970c6 JB |
5780 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5781 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5782 | { | |
5783 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5784 | u32 val, cmd; | |
5785 | ||
164dfd28 VK |
5786 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5787 | != dev_priv->cdclk_freq); | |
d60c4473 | 5788 | |
dfcab17e | 5789 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5790 | cmd = 2; |
dfcab17e | 5791 | else if (cdclk == 266667) |
30a970c6 JB |
5792 | cmd = 1; |
5793 | else | |
5794 | cmd = 0; | |
5795 | ||
5796 | mutex_lock(&dev_priv->rps.hw_lock); | |
5797 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5798 | val &= ~DSPFREQGUAR_MASK; | |
5799 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5800 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5801 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5802 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5803 | 50)) { | |
5804 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5805 | } | |
5806 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5807 | ||
54433e91 VS |
5808 | mutex_lock(&dev_priv->sb_lock); |
5809 | ||
dfcab17e | 5810 | if (cdclk == 400000) { |
6bcda4f0 | 5811 | u32 divider; |
30a970c6 | 5812 | |
6bcda4f0 | 5813 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5814 | |
30a970c6 JB |
5815 | /* adjust cdclk divider */ |
5816 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 5817 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
5818 | val |= divider; |
5819 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5820 | |
5821 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 5822 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
5823 | 50)) |
5824 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5825 | } |
5826 | ||
30a970c6 JB |
5827 | /* adjust self-refresh exit latency value */ |
5828 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5829 | val &= ~0x7f; | |
5830 | ||
5831 | /* | |
5832 | * For high bandwidth configs, we set a higher latency in the bunit | |
5833 | * so that the core display fetch happens in time to avoid underruns. | |
5834 | */ | |
dfcab17e | 5835 | if (cdclk == 400000) |
30a970c6 JB |
5836 | val |= 4500 / 250; /* 4.5 usec */ |
5837 | else | |
5838 | val |= 3000 / 250; /* 3.0 usec */ | |
5839 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5840 | |
a580516d | 5841 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5842 | |
b6283055 | 5843 | intel_update_cdclk(dev); |
30a970c6 JB |
5844 | } |
5845 | ||
383c5a6a VS |
5846 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5847 | { | |
5848 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5849 | u32 val, cmd; | |
5850 | ||
164dfd28 VK |
5851 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5852 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5853 | |
5854 | switch (cdclk) { | |
383c5a6a VS |
5855 | case 333333: |
5856 | case 320000: | |
383c5a6a | 5857 | case 266667: |
383c5a6a | 5858 | case 200000: |
383c5a6a VS |
5859 | break; |
5860 | default: | |
5f77eeb0 | 5861 | MISSING_CASE(cdclk); |
383c5a6a VS |
5862 | return; |
5863 | } | |
5864 | ||
9d0d3fda VS |
5865 | /* |
5866 | * Specs are full of misinformation, but testing on actual | |
5867 | * hardware has shown that we just need to write the desired | |
5868 | * CCK divider into the Punit register. | |
5869 | */ | |
5870 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5871 | ||
383c5a6a VS |
5872 | mutex_lock(&dev_priv->rps.hw_lock); |
5873 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5874 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5875 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5876 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5877 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5878 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5879 | 50)) { | |
5880 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5881 | } | |
5882 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5883 | ||
b6283055 | 5884 | intel_update_cdclk(dev); |
383c5a6a VS |
5885 | } |
5886 | ||
30a970c6 JB |
5887 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5888 | int max_pixclk) | |
5889 | { | |
6bcda4f0 | 5890 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5891 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5892 | |
30a970c6 JB |
5893 | /* |
5894 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5895 | * 200MHz | |
5896 | * 267MHz | |
29dc7ef3 | 5897 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5898 | * 400MHz (VLV only) |
5899 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5900 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5901 | * |
5902 | * We seem to get an unstable or solid color picture at 200MHz. | |
5903 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5904 | * are off. | |
30a970c6 | 5905 | */ |
6cca3195 VS |
5906 | if (!IS_CHERRYVIEW(dev_priv) && |
5907 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5908 | return 400000; |
6cca3195 | 5909 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5910 | return freq_320; |
e37c67a1 | 5911 | else if (max_pixclk > 0) |
dfcab17e | 5912 | return 266667; |
e37c67a1 VS |
5913 | else |
5914 | return 200000; | |
30a970c6 JB |
5915 | } |
5916 | ||
f8437dd1 VK |
5917 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5918 | int max_pixclk) | |
5919 | { | |
5920 | /* | |
5921 | * FIXME: | |
5922 | * - remove the guardband, it's not needed on BXT | |
5923 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5924 | */ | |
5925 | if (max_pixclk > 576000*9/10) | |
5926 | return 624000; | |
5927 | else if (max_pixclk > 384000*9/10) | |
5928 | return 576000; | |
5929 | else if (max_pixclk > 288000*9/10) | |
5930 | return 384000; | |
5931 | else if (max_pixclk > 144000*9/10) | |
5932 | return 288000; | |
5933 | else | |
5934 | return 144000; | |
5935 | } | |
5936 | ||
a821fc46 ACO |
5937 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5938 | * that's non-NULL, look at current state otherwise. */ | |
5939 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5940 | struct drm_atomic_state *state) | |
30a970c6 | 5941 | { |
30a970c6 | 5942 | struct intel_crtc *intel_crtc; |
304603f4 | 5943 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5944 | int max_pixclk = 0; |
5945 | ||
d3fcc808 | 5946 | for_each_intel_crtc(dev, intel_crtc) { |
27c329ed | 5947 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
304603f4 ACO |
5948 | if (IS_ERR(crtc_state)) |
5949 | return PTR_ERR(crtc_state); | |
5950 | ||
5951 | if (!crtc_state->base.enable) | |
5952 | continue; | |
5953 | ||
5954 | max_pixclk = max(max_pixclk, | |
5955 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5956 | } |
5957 | ||
5958 | return max_pixclk; | |
5959 | } | |
5960 | ||
27c329ed | 5961 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 5962 | { |
27c329ed ML |
5963 | struct drm_device *dev = state->dev; |
5964 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5965 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
30a970c6 | 5966 | |
304603f4 ACO |
5967 | if (max_pixclk < 0) |
5968 | return max_pixclk; | |
30a970c6 | 5969 | |
27c329ed ML |
5970 | to_intel_atomic_state(state)->cdclk = |
5971 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
0a9ab303 | 5972 | |
27c329ed ML |
5973 | return 0; |
5974 | } | |
304603f4 | 5975 | |
27c329ed ML |
5976 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
5977 | { | |
5978 | struct drm_device *dev = state->dev; | |
5979 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5980 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
85a96e7a | 5981 | |
27c329ed ML |
5982 | if (max_pixclk < 0) |
5983 | return max_pixclk; | |
85a96e7a | 5984 | |
27c329ed ML |
5985 | to_intel_atomic_state(state)->cdclk = |
5986 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
85a96e7a | 5987 | |
27c329ed | 5988 | return 0; |
30a970c6 JB |
5989 | } |
5990 | ||
1e69cd74 VS |
5991 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
5992 | { | |
5993 | unsigned int credits, default_credits; | |
5994 | ||
5995 | if (IS_CHERRYVIEW(dev_priv)) | |
5996 | default_credits = PFI_CREDIT(12); | |
5997 | else | |
5998 | default_credits = PFI_CREDIT(8); | |
5999 | ||
bfa7df01 | 6000 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
6001 | /* CHV suggested value is 31 or 63 */ |
6002 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 6003 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
6004 | else |
6005 | credits = PFI_CREDIT(15); | |
6006 | } else { | |
6007 | credits = default_credits; | |
6008 | } | |
6009 | ||
6010 | /* | |
6011 | * WA - write default credits before re-programming | |
6012 | * FIXME: should we also set the resend bit here? | |
6013 | */ | |
6014 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6015 | default_credits); | |
6016 | ||
6017 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6018 | credits | PFI_CREDIT_RESEND); | |
6019 | ||
6020 | /* | |
6021 | * FIXME is this guaranteed to clear | |
6022 | * immediately or should we poll for it? | |
6023 | */ | |
6024 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6025 | } | |
6026 | ||
27c329ed | 6027 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6028 | { |
a821fc46 | 6029 | struct drm_device *dev = old_state->dev; |
27c329ed | 6030 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
30a970c6 | 6031 | struct drm_i915_private *dev_priv = dev->dev_private; |
30a970c6 | 6032 | |
27c329ed ML |
6033 | /* |
6034 | * FIXME: We can end up here with all power domains off, yet | |
6035 | * with a CDCLK frequency other than the minimum. To account | |
6036 | * for this take the PIPE-A power domain, which covers the HW | |
6037 | * blocks needed for the following programming. This can be | |
6038 | * removed once it's guaranteed that we get here either with | |
6039 | * the minimum CDCLK set, or the required power domains | |
6040 | * enabled. | |
6041 | */ | |
6042 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6043 | |
27c329ed ML |
6044 | if (IS_CHERRYVIEW(dev)) |
6045 | cherryview_set_cdclk(dev, req_cdclk); | |
6046 | else | |
6047 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6048 | |
27c329ed | 6049 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6050 | |
27c329ed | 6051 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6052 | } |
6053 | ||
89b667f8 JB |
6054 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6055 | { | |
6056 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6057 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6058 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6059 | struct intel_encoder *encoder; | |
6060 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6061 | bool is_dsi; |
89b667f8 | 6062 | |
53d9f4e9 | 6063 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6064 | return; |
6065 | ||
409ee761 | 6066 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6067 | |
6e3c9717 | 6068 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6069 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6070 | |
6071 | intel_set_pipe_timings(intel_crtc); | |
6072 | ||
c14b0485 VS |
6073 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6074 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6075 | ||
6076 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6077 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6078 | } | |
6079 | ||
5b18e57c DV |
6080 | i9xx_set_pipeconf(intel_crtc); |
6081 | ||
89b667f8 | 6082 | intel_crtc->active = true; |
89b667f8 | 6083 | |
a72e4c9f | 6084 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6085 | |
89b667f8 JB |
6086 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6087 | if (encoder->pre_pll_enable) | |
6088 | encoder->pre_pll_enable(encoder); | |
6089 | ||
9d556c99 | 6090 | if (!is_dsi) { |
c0b4c660 VS |
6091 | if (IS_CHERRYVIEW(dev)) { |
6092 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6093 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6094 | } else { |
6095 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6096 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6097 | } |
9d556c99 | 6098 | } |
89b667f8 JB |
6099 | |
6100 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6101 | if (encoder->pre_enable) | |
6102 | encoder->pre_enable(encoder); | |
6103 | ||
2dd24552 JB |
6104 | i9xx_pfit_enable(intel_crtc); |
6105 | ||
63cbb074 VS |
6106 | intel_crtc_load_lut(crtc); |
6107 | ||
e1fdc473 | 6108 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6109 | |
4b3a9526 VS |
6110 | assert_vblank_disabled(crtc); |
6111 | drm_crtc_vblank_on(crtc); | |
6112 | ||
f9b61ff6 DV |
6113 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6114 | encoder->enable(encoder); | |
89b667f8 JB |
6115 | } |
6116 | ||
f13c2ef3 DV |
6117 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6118 | { | |
6119 | struct drm_device *dev = crtc->base.dev; | |
6120 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6121 | ||
6e3c9717 ACO |
6122 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6123 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6124 | } |
6125 | ||
0b8765c6 | 6126 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6127 | { |
6128 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6129 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6130 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6131 | struct intel_encoder *encoder; |
79e53945 | 6132 | int pipe = intel_crtc->pipe; |
79e53945 | 6133 | |
53d9f4e9 | 6134 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6135 | return; |
6136 | ||
f13c2ef3 DV |
6137 | i9xx_set_pll_dividers(intel_crtc); |
6138 | ||
6e3c9717 | 6139 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6140 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6141 | |
6142 | intel_set_pipe_timings(intel_crtc); | |
6143 | ||
5b18e57c DV |
6144 | i9xx_set_pipeconf(intel_crtc); |
6145 | ||
f7abfe8b | 6146 | intel_crtc->active = true; |
6b383a7f | 6147 | |
4a3436e8 | 6148 | if (!IS_GEN2(dev)) |
a72e4c9f | 6149 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6150 | |
9d6d9f19 MK |
6151 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6152 | if (encoder->pre_enable) | |
6153 | encoder->pre_enable(encoder); | |
6154 | ||
f6736a1a DV |
6155 | i9xx_enable_pll(intel_crtc); |
6156 | ||
2dd24552 JB |
6157 | i9xx_pfit_enable(intel_crtc); |
6158 | ||
63cbb074 VS |
6159 | intel_crtc_load_lut(crtc); |
6160 | ||
f37fcc2a | 6161 | intel_update_watermarks(crtc); |
e1fdc473 | 6162 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6163 | |
4b3a9526 VS |
6164 | assert_vblank_disabled(crtc); |
6165 | drm_crtc_vblank_on(crtc); | |
6166 | ||
f9b61ff6 DV |
6167 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6168 | encoder->enable(encoder); | |
0b8765c6 | 6169 | } |
79e53945 | 6170 | |
87476d63 DV |
6171 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6172 | { | |
6173 | struct drm_device *dev = crtc->base.dev; | |
6174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6175 | |
6e3c9717 | 6176 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6177 | return; |
87476d63 | 6178 | |
328d8e82 | 6179 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6180 | |
328d8e82 DV |
6181 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6182 | I915_READ(PFIT_CONTROL)); | |
6183 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6184 | } |
6185 | ||
0b8765c6 JB |
6186 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6187 | { | |
6188 | struct drm_device *dev = crtc->dev; | |
6189 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6190 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6191 | struct intel_encoder *encoder; |
0b8765c6 | 6192 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6193 | |
6304cd91 VS |
6194 | /* |
6195 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6196 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6197 | * We also need to wait on all gmch platforms because of the |
6198 | * self-refresh mode constraint explained above. | |
6304cd91 | 6199 | */ |
564ed191 | 6200 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6201 | |
4b3a9526 VS |
6202 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6203 | encoder->disable(encoder); | |
6204 | ||
f9b61ff6 DV |
6205 | drm_crtc_vblank_off(crtc); |
6206 | assert_vblank_disabled(crtc); | |
6207 | ||
575f7ab7 | 6208 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6209 | |
87476d63 | 6210 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6211 | |
89b667f8 JB |
6212 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6213 | if (encoder->post_disable) | |
6214 | encoder->post_disable(encoder); | |
6215 | ||
409ee761 | 6216 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6217 | if (IS_CHERRYVIEW(dev)) |
6218 | chv_disable_pll(dev_priv, pipe); | |
6219 | else if (IS_VALLEYVIEW(dev)) | |
6220 | vlv_disable_pll(dev_priv, pipe); | |
6221 | else | |
1c4e0274 | 6222 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6223 | } |
0b8765c6 | 6224 | |
d6db995f VS |
6225 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6226 | if (encoder->post_pll_disable) | |
6227 | encoder->post_pll_disable(encoder); | |
6228 | ||
4a3436e8 | 6229 | if (!IS_GEN2(dev)) |
a72e4c9f | 6230 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
0b8765c6 JB |
6231 | } |
6232 | ||
b17d48e2 ML |
6233 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6234 | { | |
6235 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6236 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6237 | enum intel_display_power_domain domain; | |
6238 | unsigned long domains; | |
6239 | ||
6240 | if (!intel_crtc->active) | |
6241 | return; | |
6242 | ||
a539205a | 6243 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
fc32b1fd ML |
6244 | WARN_ON(intel_crtc->unpin_work); |
6245 | ||
a539205a ML |
6246 | intel_pre_disable_primary(crtc); |
6247 | } | |
6248 | ||
d032ffa0 | 6249 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 | 6250 | dev_priv->display.crtc_disable(crtc); |
37d9078b MR |
6251 | intel_crtc->active = false; |
6252 | intel_update_watermarks(crtc); | |
1f7457b1 | 6253 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6254 | |
6255 | domains = intel_crtc->enabled_power_domains; | |
6256 | for_each_power_domain(domain, domains) | |
6257 | intel_display_power_put(dev_priv, domain); | |
6258 | intel_crtc->enabled_power_domains = 0; | |
6259 | } | |
6260 | ||
6b72d486 ML |
6261 | /* |
6262 | * turn all crtc's off, but do not adjust state | |
6263 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6264 | */ | |
70e0bd74 | 6265 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6266 | { |
70e0bd74 ML |
6267 | struct drm_mode_config *config = &dev->mode_config; |
6268 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
6269 | struct drm_atomic_state *state; | |
6b72d486 | 6270 | struct drm_crtc *crtc; |
70e0bd74 ML |
6271 | unsigned crtc_mask = 0; |
6272 | int ret = 0; | |
6273 | ||
6274 | if (WARN_ON(!ctx)) | |
6275 | return 0; | |
6276 | ||
6277 | lockdep_assert_held(&ctx->ww_ctx); | |
6278 | state = drm_atomic_state_alloc(dev); | |
6279 | if (WARN_ON(!state)) | |
6280 | return -ENOMEM; | |
6281 | ||
6282 | state->acquire_ctx = ctx; | |
6283 | state->allow_modeset = true; | |
6284 | ||
6285 | for_each_crtc(dev, crtc) { | |
6286 | struct drm_crtc_state *crtc_state = | |
6287 | drm_atomic_get_crtc_state(state, crtc); | |
6b72d486 | 6288 | |
70e0bd74 ML |
6289 | ret = PTR_ERR_OR_ZERO(crtc_state); |
6290 | if (ret) | |
6291 | goto free; | |
6292 | ||
6293 | if (!crtc_state->active) | |
6294 | continue; | |
6295 | ||
6296 | crtc_state->active = false; | |
6297 | crtc_mask |= 1 << drm_crtc_index(crtc); | |
6298 | } | |
6299 | ||
6300 | if (crtc_mask) { | |
74c090b1 | 6301 | ret = drm_atomic_commit(state); |
70e0bd74 ML |
6302 | |
6303 | if (!ret) { | |
6304 | for_each_crtc(dev, crtc) | |
6305 | if (crtc_mask & (1 << drm_crtc_index(crtc))) | |
6306 | crtc->state->active = true; | |
6307 | ||
6308 | return ret; | |
6309 | } | |
6310 | } | |
6311 | ||
6312 | free: | |
6313 | if (ret) | |
6314 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6315 | drm_atomic_state_free(state); | |
6316 | return ret; | |
ee7b9f93 JB |
6317 | } |
6318 | ||
ea5b213a | 6319 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6320 | { |
4ef69c7a | 6321 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6322 | |
ea5b213a CW |
6323 | drm_encoder_cleanup(encoder); |
6324 | kfree(intel_encoder); | |
7e7d76c3 JB |
6325 | } |
6326 | ||
0a91ca29 DV |
6327 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6328 | * internal consistency). */ | |
b980514c | 6329 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6330 | { |
35dd3c64 ML |
6331 | struct drm_crtc *crtc = connector->base.state->crtc; |
6332 | ||
6333 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6334 | connector->base.base.id, | |
6335 | connector->base.name); | |
6336 | ||
0a91ca29 | 6337 | if (connector->get_hw_state(connector)) { |
e85376cb | 6338 | struct intel_encoder *encoder = connector->encoder; |
35dd3c64 | 6339 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6340 | |
35dd3c64 ML |
6341 | I915_STATE_WARN(!crtc, |
6342 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6343 | |
35dd3c64 ML |
6344 | if (!crtc) |
6345 | return; | |
6346 | ||
6347 | I915_STATE_WARN(!crtc->state->active, | |
6348 | "connector is active, but attached crtc isn't\n"); | |
6349 | ||
e85376cb | 6350 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6351 | return; |
6352 | ||
e85376cb | 6353 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6354 | "atomic encoder doesn't match attached encoder\n"); |
6355 | ||
e85376cb | 6356 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6357 | "attached encoder crtc differs from connector crtc\n"); |
6358 | } else { | |
4d688a2a ML |
6359 | I915_STATE_WARN(crtc && crtc->state->active, |
6360 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6361 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6362 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6363 | } |
79e53945 JB |
6364 | } |
6365 | ||
08d9bc92 ACO |
6366 | int intel_connector_init(struct intel_connector *connector) |
6367 | { | |
6368 | struct drm_connector_state *connector_state; | |
6369 | ||
6370 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6371 | if (!connector_state) | |
6372 | return -ENOMEM; | |
6373 | ||
6374 | connector->base.state = connector_state; | |
6375 | return 0; | |
6376 | } | |
6377 | ||
6378 | struct intel_connector *intel_connector_alloc(void) | |
6379 | { | |
6380 | struct intel_connector *connector; | |
6381 | ||
6382 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6383 | if (!connector) | |
6384 | return NULL; | |
6385 | ||
6386 | if (intel_connector_init(connector) < 0) { | |
6387 | kfree(connector); | |
6388 | return NULL; | |
6389 | } | |
6390 | ||
6391 | return connector; | |
6392 | } | |
6393 | ||
f0947c37 DV |
6394 | /* Simple connector->get_hw_state implementation for encoders that support only |
6395 | * one connector and no cloning and hence the encoder state determines the state | |
6396 | * of the connector. */ | |
6397 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6398 | { |
24929352 | 6399 | enum pipe pipe = 0; |
f0947c37 | 6400 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6401 | |
f0947c37 | 6402 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6403 | } |
6404 | ||
6d293983 | 6405 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6406 | { |
6d293983 ACO |
6407 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6408 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6409 | |
6410 | return 0; | |
6411 | } | |
6412 | ||
6d293983 | 6413 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6414 | struct intel_crtc_state *pipe_config) |
1857e1da | 6415 | { |
6d293983 ACO |
6416 | struct drm_atomic_state *state = pipe_config->base.state; |
6417 | struct intel_crtc *other_crtc; | |
6418 | struct intel_crtc_state *other_crtc_state; | |
6419 | ||
1857e1da DV |
6420 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6421 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6422 | if (pipe_config->fdi_lanes > 4) { | |
6423 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6424 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6425 | return -EINVAL; |
1857e1da DV |
6426 | } |
6427 | ||
bafb6553 | 6428 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6429 | if (pipe_config->fdi_lanes > 2) { |
6430 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6431 | pipe_config->fdi_lanes); | |
6d293983 | 6432 | return -EINVAL; |
1857e1da | 6433 | } else { |
6d293983 | 6434 | return 0; |
1857e1da DV |
6435 | } |
6436 | } | |
6437 | ||
6438 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6439 | return 0; |
1857e1da DV |
6440 | |
6441 | /* Ivybridge 3 pipe is really complicated */ | |
6442 | switch (pipe) { | |
6443 | case PIPE_A: | |
6d293983 | 6444 | return 0; |
1857e1da | 6445 | case PIPE_B: |
6d293983 ACO |
6446 | if (pipe_config->fdi_lanes <= 2) |
6447 | return 0; | |
6448 | ||
6449 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6450 | other_crtc_state = | |
6451 | intel_atomic_get_crtc_state(state, other_crtc); | |
6452 | if (IS_ERR(other_crtc_state)) | |
6453 | return PTR_ERR(other_crtc_state); | |
6454 | ||
6455 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6456 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6457 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6458 | return -EINVAL; |
1857e1da | 6459 | } |
6d293983 | 6460 | return 0; |
1857e1da | 6461 | case PIPE_C: |
251cc67c VS |
6462 | if (pipe_config->fdi_lanes > 2) { |
6463 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6464 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6465 | return -EINVAL; |
251cc67c | 6466 | } |
6d293983 ACO |
6467 | |
6468 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6469 | other_crtc_state = | |
6470 | intel_atomic_get_crtc_state(state, other_crtc); | |
6471 | if (IS_ERR(other_crtc_state)) | |
6472 | return PTR_ERR(other_crtc_state); | |
6473 | ||
6474 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6475 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6476 | return -EINVAL; |
1857e1da | 6477 | } |
6d293983 | 6478 | return 0; |
1857e1da DV |
6479 | default: |
6480 | BUG(); | |
6481 | } | |
6482 | } | |
6483 | ||
e29c22c0 DV |
6484 | #define RETRY 1 |
6485 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6486 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6487 | { |
1857e1da | 6488 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6489 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6490 | int lane, link_bw, fdi_dotclock, ret; |
6491 | bool needs_recompute = false; | |
877d48d5 | 6492 | |
e29c22c0 | 6493 | retry: |
877d48d5 DV |
6494 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6495 | * each output octet as 10 bits. The actual frequency | |
6496 | * is stored as a divider into a 100MHz clock, and the | |
6497 | * mode pixel clock is stored in units of 1KHz. | |
6498 | * Hence the bw of each lane in terms of the mode signal | |
6499 | * is: | |
6500 | */ | |
6501 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6502 | ||
241bfc38 | 6503 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6504 | |
2bd89a07 | 6505 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6506 | pipe_config->pipe_bpp); |
6507 | ||
6508 | pipe_config->fdi_lanes = lane; | |
6509 | ||
2bd89a07 | 6510 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6511 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6512 | |
6d293983 ACO |
6513 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6514 | intel_crtc->pipe, pipe_config); | |
6515 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6516 | pipe_config->pipe_bpp -= 2*3; |
6517 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6518 | pipe_config->pipe_bpp); | |
6519 | needs_recompute = true; | |
6520 | pipe_config->bw_constrained = true; | |
6521 | ||
6522 | goto retry; | |
6523 | } | |
6524 | ||
6525 | if (needs_recompute) | |
6526 | return RETRY; | |
6527 | ||
6d293983 | 6528 | return ret; |
877d48d5 DV |
6529 | } |
6530 | ||
8cfb3407 VS |
6531 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6532 | struct intel_crtc_state *pipe_config) | |
6533 | { | |
6534 | if (pipe_config->pipe_bpp > 24) | |
6535 | return false; | |
6536 | ||
6537 | /* HSW can handle pixel rate up to cdclk? */ | |
6538 | if (IS_HASWELL(dev_priv->dev)) | |
6539 | return true; | |
6540 | ||
6541 | /* | |
b432e5cf VS |
6542 | * We compare against max which means we must take |
6543 | * the increased cdclk requirement into account when | |
6544 | * calculating the new cdclk. | |
6545 | * | |
6546 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6547 | */ |
6548 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6549 | dev_priv->max_cdclk_freq * 95 / 100; | |
6550 | } | |
6551 | ||
42db64ef | 6552 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6553 | struct intel_crtc_state *pipe_config) |
42db64ef | 6554 | { |
8cfb3407 VS |
6555 | struct drm_device *dev = crtc->base.dev; |
6556 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6557 | ||
d330a953 | 6558 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6559 | hsw_crtc_supports_ips(crtc) && |
6560 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6561 | } |
6562 | ||
39acb4aa VS |
6563 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6564 | { | |
6565 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6566 | ||
6567 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6568 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6569 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6570 | } | |
6571 | ||
a43f6e0f | 6572 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6573 | struct intel_crtc_state *pipe_config) |
79e53945 | 6574 | { |
a43f6e0f | 6575 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6576 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6577 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6578 | |
ad3a4479 | 6579 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6580 | if (INTEL_INFO(dev)->gen < 4) { |
39acb4aa | 6581 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6582 | |
6583 | /* | |
39acb4aa | 6584 | * Enable double wide mode when the dot clock |
cf532bb2 | 6585 | * is > 90% of the (display) core speed. |
cf532bb2 | 6586 | */ |
39acb4aa VS |
6587 | if (intel_crtc_supports_double_wide(crtc) && |
6588 | adjusted_mode->crtc_clock > clock_limit) { | |
ad3a4479 | 6589 | clock_limit *= 2; |
cf532bb2 | 6590 | pipe_config->double_wide = true; |
ad3a4479 VS |
6591 | } |
6592 | ||
39acb4aa VS |
6593 | if (adjusted_mode->crtc_clock > clock_limit) { |
6594 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6595 | adjusted_mode->crtc_clock, clock_limit, | |
6596 | yesno(pipe_config->double_wide)); | |
e29c22c0 | 6597 | return -EINVAL; |
39acb4aa | 6598 | } |
2c07245f | 6599 | } |
89749350 | 6600 | |
1d1d0e27 VS |
6601 | /* |
6602 | * Pipe horizontal size must be even in: | |
6603 | * - DVO ganged mode | |
6604 | * - LVDS dual channel mode | |
6605 | * - Double wide pipe | |
6606 | */ | |
a93e255f | 6607 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6608 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6609 | pipe_config->pipe_src_w &= ~1; | |
6610 | ||
8693a824 DL |
6611 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6612 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6613 | */ |
6614 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6615 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6616 | return -EINVAL; |
44f46b42 | 6617 | |
f5adf94e | 6618 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6619 | hsw_compute_ips_config(crtc, pipe_config); |
6620 | ||
877d48d5 | 6621 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6622 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6623 | |
cf5a15be | 6624 | return 0; |
79e53945 JB |
6625 | } |
6626 | ||
1652d19e VS |
6627 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6628 | { | |
6629 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6630 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6631 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6632 | uint32_t linkrate; | |
6633 | ||
414355a7 | 6634 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6635 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6636 | |
6637 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6638 | return 540000; | |
6639 | ||
6640 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6641 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6642 | |
71cd8423 DL |
6643 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6644 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6645 | /* vco 8640 */ |
6646 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6647 | case CDCLK_FREQ_450_432: | |
6648 | return 432000; | |
6649 | case CDCLK_FREQ_337_308: | |
6650 | return 308570; | |
6651 | case CDCLK_FREQ_675_617: | |
6652 | return 617140; | |
6653 | default: | |
6654 | WARN(1, "Unknown cd freq selection\n"); | |
6655 | } | |
6656 | } else { | |
6657 | /* vco 8100 */ | |
6658 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6659 | case CDCLK_FREQ_450_432: | |
6660 | return 450000; | |
6661 | case CDCLK_FREQ_337_308: | |
6662 | return 337500; | |
6663 | case CDCLK_FREQ_675_617: | |
6664 | return 675000; | |
6665 | default: | |
6666 | WARN(1, "Unknown cd freq selection\n"); | |
6667 | } | |
6668 | } | |
6669 | ||
6670 | /* error case, do as if DPLL0 isn't enabled */ | |
6671 | return 24000; | |
6672 | } | |
6673 | ||
acd3f3d3 BP |
6674 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6675 | { | |
6676 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6677 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6678 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6679 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6680 | int cdclk; | |
6681 | ||
6682 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6683 | return 19200; | |
6684 | ||
6685 | cdclk = 19200 * pll_ratio / 2; | |
6686 | ||
6687 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6688 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6689 | return cdclk; /* 576MHz or 624MHz */ | |
6690 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6691 | return cdclk * 2 / 3; /* 384MHz */ | |
6692 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6693 | return cdclk / 2; /* 288MHz */ | |
6694 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6695 | return cdclk / 4; /* 144MHz */ | |
6696 | } | |
6697 | ||
6698 | /* error case, do as if DE PLL isn't enabled */ | |
6699 | return 19200; | |
6700 | } | |
6701 | ||
1652d19e VS |
6702 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6703 | { | |
6704 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6705 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6706 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6707 | ||
6708 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6709 | return 800000; | |
6710 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6711 | return 450000; | |
6712 | else if (freq == LCPLL_CLK_FREQ_450) | |
6713 | return 450000; | |
6714 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6715 | return 540000; | |
6716 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6717 | return 337500; | |
6718 | else | |
6719 | return 675000; | |
6720 | } | |
6721 | ||
6722 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6723 | { | |
6724 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6725 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6726 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6727 | ||
6728 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6729 | return 800000; | |
6730 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6731 | return 450000; | |
6732 | else if (freq == LCPLL_CLK_FREQ_450) | |
6733 | return 450000; | |
6734 | else if (IS_HSW_ULT(dev)) | |
6735 | return 337500; | |
6736 | else | |
6737 | return 540000; | |
79e53945 JB |
6738 | } |
6739 | ||
25eb05fc JB |
6740 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6741 | { | |
bfa7df01 VS |
6742 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6743 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6744 | } |
6745 | ||
b37a6434 VS |
6746 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6747 | { | |
6748 | return 450000; | |
6749 | } | |
6750 | ||
e70236a8 JB |
6751 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6752 | { | |
6753 | return 400000; | |
6754 | } | |
79e53945 | 6755 | |
e70236a8 | 6756 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6757 | { |
e907f170 | 6758 | return 333333; |
e70236a8 | 6759 | } |
79e53945 | 6760 | |
e70236a8 JB |
6761 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6762 | { | |
6763 | return 200000; | |
6764 | } | |
79e53945 | 6765 | |
257a7ffc DV |
6766 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6767 | { | |
6768 | u16 gcfgc = 0; | |
6769 | ||
6770 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6771 | ||
6772 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6773 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6774 | return 266667; |
257a7ffc | 6775 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6776 | return 333333; |
257a7ffc | 6777 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6778 | return 444444; |
257a7ffc DV |
6779 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6780 | return 200000; | |
6781 | default: | |
6782 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6783 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6784 | return 133333; |
257a7ffc | 6785 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6786 | return 166667; |
257a7ffc DV |
6787 | } |
6788 | } | |
6789 | ||
e70236a8 JB |
6790 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6791 | { | |
6792 | u16 gcfgc = 0; | |
79e53945 | 6793 | |
e70236a8 JB |
6794 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6795 | ||
6796 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6797 | return 133333; |
e70236a8 JB |
6798 | else { |
6799 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6800 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6801 | return 333333; |
e70236a8 JB |
6802 | default: |
6803 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6804 | return 190000; | |
79e53945 | 6805 | } |
e70236a8 JB |
6806 | } |
6807 | } | |
6808 | ||
6809 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6810 | { | |
e907f170 | 6811 | return 266667; |
e70236a8 JB |
6812 | } |
6813 | ||
1b1d2716 | 6814 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6815 | { |
6816 | u16 hpllcc = 0; | |
1b1d2716 | 6817 | |
65cd2b3f VS |
6818 | /* |
6819 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6820 | * encoding is different :( | |
6821 | * FIXME is this the right way to detect 852GM/852GMV? | |
6822 | */ | |
6823 | if (dev->pdev->revision == 0x1) | |
6824 | return 133333; | |
6825 | ||
1b1d2716 VS |
6826 | pci_bus_read_config_word(dev->pdev->bus, |
6827 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6828 | ||
e70236a8 JB |
6829 | /* Assume that the hardware is in the high speed state. This |
6830 | * should be the default. | |
6831 | */ | |
6832 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6833 | case GC_CLOCK_133_200: | |
1b1d2716 | 6834 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6835 | case GC_CLOCK_100_200: |
6836 | return 200000; | |
6837 | case GC_CLOCK_166_250: | |
6838 | return 250000; | |
6839 | case GC_CLOCK_100_133: | |
e907f170 | 6840 | return 133333; |
1b1d2716 VS |
6841 | case GC_CLOCK_133_266: |
6842 | case GC_CLOCK_133_266_2: | |
6843 | case GC_CLOCK_166_266: | |
6844 | return 266667; | |
e70236a8 | 6845 | } |
79e53945 | 6846 | |
e70236a8 JB |
6847 | /* Shouldn't happen */ |
6848 | return 0; | |
6849 | } | |
79e53945 | 6850 | |
e70236a8 JB |
6851 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6852 | { | |
e907f170 | 6853 | return 133333; |
79e53945 JB |
6854 | } |
6855 | ||
34edce2f VS |
6856 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6857 | { | |
6858 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6859 | static const unsigned int blb_vco[8] = { | |
6860 | [0] = 3200000, | |
6861 | [1] = 4000000, | |
6862 | [2] = 5333333, | |
6863 | [3] = 4800000, | |
6864 | [4] = 6400000, | |
6865 | }; | |
6866 | static const unsigned int pnv_vco[8] = { | |
6867 | [0] = 3200000, | |
6868 | [1] = 4000000, | |
6869 | [2] = 5333333, | |
6870 | [3] = 4800000, | |
6871 | [4] = 2666667, | |
6872 | }; | |
6873 | static const unsigned int cl_vco[8] = { | |
6874 | [0] = 3200000, | |
6875 | [1] = 4000000, | |
6876 | [2] = 5333333, | |
6877 | [3] = 6400000, | |
6878 | [4] = 3333333, | |
6879 | [5] = 3566667, | |
6880 | [6] = 4266667, | |
6881 | }; | |
6882 | static const unsigned int elk_vco[8] = { | |
6883 | [0] = 3200000, | |
6884 | [1] = 4000000, | |
6885 | [2] = 5333333, | |
6886 | [3] = 4800000, | |
6887 | }; | |
6888 | static const unsigned int ctg_vco[8] = { | |
6889 | [0] = 3200000, | |
6890 | [1] = 4000000, | |
6891 | [2] = 5333333, | |
6892 | [3] = 6400000, | |
6893 | [4] = 2666667, | |
6894 | [5] = 4266667, | |
6895 | }; | |
6896 | const unsigned int *vco_table; | |
6897 | unsigned int vco; | |
6898 | uint8_t tmp = 0; | |
6899 | ||
6900 | /* FIXME other chipsets? */ | |
6901 | if (IS_GM45(dev)) | |
6902 | vco_table = ctg_vco; | |
6903 | else if (IS_G4X(dev)) | |
6904 | vco_table = elk_vco; | |
6905 | else if (IS_CRESTLINE(dev)) | |
6906 | vco_table = cl_vco; | |
6907 | else if (IS_PINEVIEW(dev)) | |
6908 | vco_table = pnv_vco; | |
6909 | else if (IS_G33(dev)) | |
6910 | vco_table = blb_vco; | |
6911 | else | |
6912 | return 0; | |
6913 | ||
6914 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6915 | ||
6916 | vco = vco_table[tmp & 0x7]; | |
6917 | if (vco == 0) | |
6918 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6919 | else | |
6920 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6921 | ||
6922 | return vco; | |
6923 | } | |
6924 | ||
6925 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
6926 | { | |
6927 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6928 | uint16_t tmp = 0; | |
6929 | ||
6930 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6931 | ||
6932 | cdclk_sel = (tmp >> 12) & 0x1; | |
6933 | ||
6934 | switch (vco) { | |
6935 | case 2666667: | |
6936 | case 4000000: | |
6937 | case 5333333: | |
6938 | return cdclk_sel ? 333333 : 222222; | |
6939 | case 3200000: | |
6940 | return cdclk_sel ? 320000 : 228571; | |
6941 | default: | |
6942 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
6943 | return 222222; | |
6944 | } | |
6945 | } | |
6946 | ||
6947 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
6948 | { | |
6949 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
6950 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
6951 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
6952 | const uint8_t *div_table; | |
6953 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6954 | uint16_t tmp = 0; | |
6955 | ||
6956 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6957 | ||
6958 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
6959 | ||
6960 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6961 | goto fail; | |
6962 | ||
6963 | switch (vco) { | |
6964 | case 3200000: | |
6965 | div_table = div_3200; | |
6966 | break; | |
6967 | case 4000000: | |
6968 | div_table = div_4000; | |
6969 | break; | |
6970 | case 5333333: | |
6971 | div_table = div_5333; | |
6972 | break; | |
6973 | default: | |
6974 | goto fail; | |
6975 | } | |
6976 | ||
6977 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
6978 | ||
caf4e252 | 6979 | fail: |
34edce2f VS |
6980 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
6981 | return 200000; | |
6982 | } | |
6983 | ||
6984 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
6985 | { | |
6986 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
6987 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
6988 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
6989 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
6990 | const uint8_t *div_table; | |
6991 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6992 | uint16_t tmp = 0; | |
6993 | ||
6994 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6995 | ||
6996 | cdclk_sel = (tmp >> 4) & 0x7; | |
6997 | ||
6998 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6999 | goto fail; | |
7000 | ||
7001 | switch (vco) { | |
7002 | case 3200000: | |
7003 | div_table = div_3200; | |
7004 | break; | |
7005 | case 4000000: | |
7006 | div_table = div_4000; | |
7007 | break; | |
7008 | case 4800000: | |
7009 | div_table = div_4800; | |
7010 | break; | |
7011 | case 5333333: | |
7012 | div_table = div_5333; | |
7013 | break; | |
7014 | default: | |
7015 | goto fail; | |
7016 | } | |
7017 | ||
7018 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7019 | ||
caf4e252 | 7020 | fail: |
34edce2f VS |
7021 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7022 | return 190476; | |
7023 | } | |
7024 | ||
2c07245f | 7025 | static void |
a65851af | 7026 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7027 | { |
a65851af VS |
7028 | while (*num > DATA_LINK_M_N_MASK || |
7029 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7030 | *num >>= 1; |
7031 | *den >>= 1; | |
7032 | } | |
7033 | } | |
7034 | ||
a65851af VS |
7035 | static void compute_m_n(unsigned int m, unsigned int n, |
7036 | uint32_t *ret_m, uint32_t *ret_n) | |
7037 | { | |
7038 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7039 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7040 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7041 | } | |
7042 | ||
e69d0bc1 DV |
7043 | void |
7044 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7045 | int pixel_clock, int link_clock, | |
7046 | struct intel_link_m_n *m_n) | |
2c07245f | 7047 | { |
e69d0bc1 | 7048 | m_n->tu = 64; |
a65851af VS |
7049 | |
7050 | compute_m_n(bits_per_pixel * pixel_clock, | |
7051 | link_clock * nlanes * 8, | |
7052 | &m_n->gmch_m, &m_n->gmch_n); | |
7053 | ||
7054 | compute_m_n(pixel_clock, link_clock, | |
7055 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7056 | } |
7057 | ||
a7615030 CW |
7058 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7059 | { | |
d330a953 JN |
7060 | if (i915.panel_use_ssc >= 0) |
7061 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7062 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7063 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7064 | } |
7065 | ||
a93e255f ACO |
7066 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7067 | int num_connectors) | |
c65d77d8 | 7068 | { |
a93e255f | 7069 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7070 | struct drm_i915_private *dev_priv = dev->dev_private; |
7071 | int refclk; | |
7072 | ||
a93e255f ACO |
7073 | WARN_ON(!crtc_state->base.state); |
7074 | ||
5ab7b0b7 | 7075 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7076 | refclk = 100000; |
a93e255f | 7077 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7078 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7079 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7080 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7081 | } else if (!IS_GEN2(dev)) { |
7082 | refclk = 96000; | |
7083 | } else { | |
7084 | refclk = 48000; | |
7085 | } | |
7086 | ||
7087 | return refclk; | |
7088 | } | |
7089 | ||
7429e9d4 | 7090 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7091 | { |
7df00d7a | 7092 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7093 | } |
f47709a9 | 7094 | |
7429e9d4 DV |
7095 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7096 | { | |
7097 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7098 | } |
7099 | ||
f47709a9 | 7100 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7101 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7102 | intel_clock_t *reduced_clock) |
7103 | { | |
f47709a9 | 7104 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7105 | u32 fp, fp2 = 0; |
7106 | ||
7107 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7108 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7109 | if (reduced_clock) |
7429e9d4 | 7110 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7111 | } else { |
190f68c5 | 7112 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7113 | if (reduced_clock) |
7429e9d4 | 7114 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7115 | } |
7116 | ||
190f68c5 | 7117 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7118 | |
f47709a9 | 7119 | crtc->lowfreq_avail = false; |
a93e255f | 7120 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7121 | reduced_clock) { |
190f68c5 | 7122 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7123 | crtc->lowfreq_avail = true; |
a7516a05 | 7124 | } else { |
190f68c5 | 7125 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7126 | } |
7127 | } | |
7128 | ||
5e69f97f CML |
7129 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7130 | pipe) | |
89b667f8 JB |
7131 | { |
7132 | u32 reg_val; | |
7133 | ||
7134 | /* | |
7135 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7136 | * and set it to a reasonable value instead. | |
7137 | */ | |
ab3c759a | 7138 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7139 | reg_val &= 0xffffff00; |
7140 | reg_val |= 0x00000030; | |
ab3c759a | 7141 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7142 | |
ab3c759a | 7143 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7144 | reg_val &= 0x8cffffff; |
7145 | reg_val = 0x8c000000; | |
ab3c759a | 7146 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7147 | |
ab3c759a | 7148 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7149 | reg_val &= 0xffffff00; |
ab3c759a | 7150 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7151 | |
ab3c759a | 7152 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7153 | reg_val &= 0x00ffffff; |
7154 | reg_val |= 0xb0000000; | |
ab3c759a | 7155 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7156 | } |
7157 | ||
b551842d DV |
7158 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7159 | struct intel_link_m_n *m_n) | |
7160 | { | |
7161 | struct drm_device *dev = crtc->base.dev; | |
7162 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7163 | int pipe = crtc->pipe; | |
7164 | ||
e3b95f1e DV |
7165 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7166 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7167 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7168 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7169 | } |
7170 | ||
7171 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7172 | struct intel_link_m_n *m_n, |
7173 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7174 | { |
7175 | struct drm_device *dev = crtc->base.dev; | |
7176 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7177 | int pipe = crtc->pipe; | |
6e3c9717 | 7178 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7179 | |
7180 | if (INTEL_INFO(dev)->gen >= 5) { | |
7181 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7182 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7183 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7184 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7185 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7186 | * for gen < 8) and if DRRS is supported (to make sure the | |
7187 | * registers are not unnecessarily accessed). | |
7188 | */ | |
44395bfe | 7189 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7190 | crtc->config->has_drrs) { |
f769cd24 VK |
7191 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7192 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7193 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7194 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7195 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7196 | } | |
b551842d | 7197 | } else { |
e3b95f1e DV |
7198 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7199 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7200 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7201 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7202 | } |
7203 | } | |
7204 | ||
fe3cd48d | 7205 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7206 | { |
fe3cd48d R |
7207 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7208 | ||
7209 | if (m_n == M1_N1) { | |
7210 | dp_m_n = &crtc->config->dp_m_n; | |
7211 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7212 | } else if (m_n == M2_N2) { | |
7213 | ||
7214 | /* | |
7215 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7216 | * needs to be programmed into M1_N1. | |
7217 | */ | |
7218 | dp_m_n = &crtc->config->dp_m2_n2; | |
7219 | } else { | |
7220 | DRM_ERROR("Unsupported divider value\n"); | |
7221 | return; | |
7222 | } | |
7223 | ||
6e3c9717 ACO |
7224 | if (crtc->config->has_pch_encoder) |
7225 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7226 | else |
fe3cd48d | 7227 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7228 | } |
7229 | ||
251ac862 DV |
7230 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7231 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7232 | { |
7233 | u32 dpll, dpll_md; | |
7234 | ||
7235 | /* | |
7236 | * Enable DPIO clock input. We should never disable the reference | |
7237 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7238 | * on it. | |
7239 | */ | |
60bfe44f VS |
7240 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7241 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7242 | /* We should never disable this, set it here for state tracking */ |
7243 | if (crtc->pipe == PIPE_B) | |
7244 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7245 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7246 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7247 | |
d288f65f | 7248 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7249 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7250 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7251 | } |
7252 | ||
d288f65f | 7253 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7254 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7255 | { |
f47709a9 | 7256 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7257 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7258 | int pipe = crtc->pipe; |
bdd4b6a6 | 7259 | u32 mdiv; |
a0c4da24 | 7260 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7261 | u32 coreclk, reg_val; |
a0c4da24 | 7262 | |
a580516d | 7263 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7264 | |
d288f65f VS |
7265 | bestn = pipe_config->dpll.n; |
7266 | bestm1 = pipe_config->dpll.m1; | |
7267 | bestm2 = pipe_config->dpll.m2; | |
7268 | bestp1 = pipe_config->dpll.p1; | |
7269 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7270 | |
89b667f8 JB |
7271 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7272 | ||
7273 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7274 | if (pipe == PIPE_B) |
5e69f97f | 7275 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7276 | |
7277 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7278 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7279 | |
7280 | /* Disable target IRef on PLL */ | |
ab3c759a | 7281 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7282 | reg_val &= 0x00ffffff; |
ab3c759a | 7283 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7284 | |
7285 | /* Disable fast lock */ | |
ab3c759a | 7286 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7287 | |
7288 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7289 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7290 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7291 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7292 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7293 | |
7294 | /* | |
7295 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7296 | * but we don't support that). | |
7297 | * Note: don't use the DAC post divider as it seems unstable. | |
7298 | */ | |
7299 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7300 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7301 | |
a0c4da24 | 7302 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7303 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7304 | |
89b667f8 | 7305 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7306 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7307 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7308 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7309 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7310 | 0x009f0003); |
89b667f8 | 7311 | else |
ab3c759a | 7312 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7313 | 0x00d0000f); |
7314 | ||
681a8504 | 7315 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7316 | /* Use SSC source */ |
bdd4b6a6 | 7317 | if (pipe == PIPE_A) |
ab3c759a | 7318 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7319 | 0x0df40000); |
7320 | else | |
ab3c759a | 7321 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7322 | 0x0df70000); |
7323 | } else { /* HDMI or VGA */ | |
7324 | /* Use bend source */ | |
bdd4b6a6 | 7325 | if (pipe == PIPE_A) |
ab3c759a | 7326 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7327 | 0x0df70000); |
7328 | else | |
ab3c759a | 7329 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7330 | 0x0df40000); |
7331 | } | |
a0c4da24 | 7332 | |
ab3c759a | 7333 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7334 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7335 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7336 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7337 | coreclk |= 0x01000000; |
ab3c759a | 7338 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7339 | |
ab3c759a | 7340 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7341 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7342 | } |
7343 | ||
251ac862 DV |
7344 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7345 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7346 | { |
60bfe44f VS |
7347 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7348 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7349 | DPLL_VCO_ENABLE; |
7350 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7351 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7352 | |
d288f65f VS |
7353 | pipe_config->dpll_hw_state.dpll_md = |
7354 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7355 | } |
7356 | ||
d288f65f | 7357 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7358 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7359 | { |
7360 | struct drm_device *dev = crtc->base.dev; | |
7361 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7362 | int pipe = crtc->pipe; | |
7363 | int dpll_reg = DPLL(crtc->pipe); | |
7364 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 7365 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7366 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7367 | u32 dpio_val; |
9cbe40c1 | 7368 | int vco; |
9d556c99 | 7369 | |
d288f65f VS |
7370 | bestn = pipe_config->dpll.n; |
7371 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7372 | bestm1 = pipe_config->dpll.m1; | |
7373 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7374 | bestp1 = pipe_config->dpll.p1; | |
7375 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7376 | vco = pipe_config->dpll.vco; |
a945ce7e | 7377 | dpio_val = 0; |
9cbe40c1 | 7378 | loopfilter = 0; |
9d556c99 CML |
7379 | |
7380 | /* | |
7381 | * Enable Refclk and SSC | |
7382 | */ | |
a11b0703 | 7383 | I915_WRITE(dpll_reg, |
d288f65f | 7384 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7385 | |
a580516d | 7386 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7387 | |
9d556c99 CML |
7388 | /* p1 and p2 divider */ |
7389 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7390 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7391 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7392 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7393 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7394 | ||
7395 | /* Feedback post-divider - m2 */ | |
7396 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7397 | ||
7398 | /* Feedback refclk divider - n and m1 */ | |
7399 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7400 | DPIO_CHV_M1_DIV_BY_2 | | |
7401 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7402 | ||
7403 | /* M2 fraction division */ | |
25a25dfc | 7404 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7405 | |
7406 | /* M2 fraction division enable */ | |
a945ce7e VP |
7407 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7408 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7409 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7410 | if (bestm2_frac) | |
7411 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7412 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7413 | |
de3a0fde VP |
7414 | /* Program digital lock detect threshold */ |
7415 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7416 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7417 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7418 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7419 | if (!bestm2_frac) | |
7420 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7421 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7422 | ||
9d556c99 | 7423 | /* Loop filter */ |
9cbe40c1 VP |
7424 | if (vco == 5400000) { |
7425 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7426 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7427 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7428 | tribuf_calcntr = 0x9; | |
7429 | } else if (vco <= 6200000) { | |
7430 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7431 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7432 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7433 | tribuf_calcntr = 0x9; | |
7434 | } else if (vco <= 6480000) { | |
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 = 0x8; | |
7439 | } else { | |
7440 | /* Not supported. Apply the same limits as in the max case */ | |
7441 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7442 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7443 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7444 | tribuf_calcntr = 0; | |
7445 | } | |
9d556c99 CML |
7446 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7447 | ||
968040b2 | 7448 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7449 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7450 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7451 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7452 | ||
9d556c99 CML |
7453 | /* AFC Recal */ |
7454 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7455 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7456 | DPIO_AFC_RECAL); | |
7457 | ||
a580516d | 7458 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7459 | } |
7460 | ||
d288f65f VS |
7461 | /** |
7462 | * vlv_force_pll_on - forcibly enable just the PLL | |
7463 | * @dev_priv: i915 private structure | |
7464 | * @pipe: pipe PLL to enable | |
7465 | * @dpll: PLL configuration | |
7466 | * | |
7467 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7468 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7469 | * be enabled. | |
7470 | */ | |
7471 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7472 | const struct dpll *dpll) | |
7473 | { | |
7474 | struct intel_crtc *crtc = | |
7475 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7476 | struct intel_crtc_state pipe_config = { |
a93e255f | 7477 | .base.crtc = &crtc->base, |
d288f65f VS |
7478 | .pixel_multiplier = 1, |
7479 | .dpll = *dpll, | |
7480 | }; | |
7481 | ||
7482 | if (IS_CHERRYVIEW(dev)) { | |
251ac862 | 7483 | chv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7484 | chv_prepare_pll(crtc, &pipe_config); |
7485 | chv_enable_pll(crtc, &pipe_config); | |
7486 | } else { | |
251ac862 | 7487 | vlv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7488 | vlv_prepare_pll(crtc, &pipe_config); |
7489 | vlv_enable_pll(crtc, &pipe_config); | |
7490 | } | |
7491 | } | |
7492 | ||
7493 | /** | |
7494 | * vlv_force_pll_off - forcibly disable just the PLL | |
7495 | * @dev_priv: i915 private structure | |
7496 | * @pipe: pipe PLL to disable | |
7497 | * | |
7498 | * Disable the PLL for @pipe. To be used in cases where we need | |
7499 | * the PLL enabled even when @pipe is not going to be enabled. | |
7500 | */ | |
7501 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7502 | { | |
7503 | if (IS_CHERRYVIEW(dev)) | |
7504 | chv_disable_pll(to_i915(dev), pipe); | |
7505 | else | |
7506 | vlv_disable_pll(to_i915(dev), pipe); | |
7507 | } | |
7508 | ||
251ac862 DV |
7509 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7510 | struct intel_crtc_state *crtc_state, | |
7511 | intel_clock_t *reduced_clock, | |
7512 | int num_connectors) | |
eb1cbe48 | 7513 | { |
f47709a9 | 7514 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7515 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7516 | u32 dpll; |
7517 | bool is_sdvo; | |
190f68c5 | 7518 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7519 | |
190f68c5 | 7520 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7521 | |
a93e255f ACO |
7522 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7523 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7524 | |
7525 | dpll = DPLL_VGA_MODE_DIS; | |
7526 | ||
a93e255f | 7527 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7528 | dpll |= DPLLB_MODE_LVDS; |
7529 | else | |
7530 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7531 | |
ef1b460d | 7532 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7533 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7534 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7535 | } |
198a037f DV |
7536 | |
7537 | if (is_sdvo) | |
4a33e48d | 7538 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7539 | |
190f68c5 | 7540 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7541 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7542 | |
7543 | /* compute bitmask from p1 value */ | |
7544 | if (IS_PINEVIEW(dev)) | |
7545 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7546 | else { | |
7547 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7548 | if (IS_G4X(dev) && reduced_clock) | |
7549 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7550 | } | |
7551 | switch (clock->p2) { | |
7552 | case 5: | |
7553 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7554 | break; | |
7555 | case 7: | |
7556 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7557 | break; | |
7558 | case 10: | |
7559 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7560 | break; | |
7561 | case 14: | |
7562 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7563 | break; | |
7564 | } | |
7565 | if (INTEL_INFO(dev)->gen >= 4) | |
7566 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7567 | ||
190f68c5 | 7568 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7569 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7570 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7571 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7572 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7573 | else | |
7574 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7575 | ||
7576 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7577 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7578 | |
eb1cbe48 | 7579 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7580 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7581 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7582 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7583 | } |
7584 | } | |
7585 | ||
251ac862 DV |
7586 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7587 | struct intel_crtc_state *crtc_state, | |
7588 | intel_clock_t *reduced_clock, | |
7589 | int num_connectors) | |
eb1cbe48 | 7590 | { |
f47709a9 | 7591 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7592 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7593 | u32 dpll; |
190f68c5 | 7594 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7595 | |
190f68c5 | 7596 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7597 | |
eb1cbe48 DV |
7598 | dpll = DPLL_VGA_MODE_DIS; |
7599 | ||
a93e255f | 7600 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7601 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7602 | } else { | |
7603 | if (clock->p1 == 2) | |
7604 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7605 | else | |
7606 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7607 | if (clock->p2 == 4) | |
7608 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7609 | } | |
7610 | ||
a93e255f | 7611 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7612 | dpll |= DPLL_DVO_2X_MODE; |
7613 | ||
a93e255f | 7614 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7615 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7616 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7617 | else | |
7618 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7619 | ||
7620 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7621 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7622 | } |
7623 | ||
8a654f3b | 7624 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7625 | { |
7626 | struct drm_device *dev = intel_crtc->base.dev; | |
7627 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7628 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7629 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7630 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7631 | uint32_t crtc_vtotal, crtc_vblank_end; |
7632 | int vsyncshift = 0; | |
4d8a62ea DV |
7633 | |
7634 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7635 | * the hw state checker will get angry at the mismatch. */ | |
7636 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7637 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7638 | |
609aeaca | 7639 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7640 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7641 | crtc_vtotal -= 1; |
7642 | crtc_vblank_end -= 1; | |
609aeaca | 7643 | |
409ee761 | 7644 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7645 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7646 | else | |
7647 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7648 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7649 | if (vsyncshift < 0) |
7650 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7651 | } |
7652 | ||
7653 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7654 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7655 | |
fe2b8f9d | 7656 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7657 | (adjusted_mode->crtc_hdisplay - 1) | |
7658 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7659 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7660 | (adjusted_mode->crtc_hblank_start - 1) | |
7661 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7662 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7663 | (adjusted_mode->crtc_hsync_start - 1) | |
7664 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7665 | ||
fe2b8f9d | 7666 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7667 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7668 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7669 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7670 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7671 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7672 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7673 | (adjusted_mode->crtc_vsync_start - 1) | |
7674 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7675 | ||
b5e508d4 PZ |
7676 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7677 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7678 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7679 | * bits. */ | |
7680 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7681 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7682 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7683 | ||
b0e77b9c PZ |
7684 | /* pipesrc controls the size that is scaled from, which should |
7685 | * always be the user's requested size. | |
7686 | */ | |
7687 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7688 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7689 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7690 | } |
7691 | ||
1bd1bd80 | 7692 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7693 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7694 | { |
7695 | struct drm_device *dev = crtc->base.dev; | |
7696 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7697 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7698 | uint32_t tmp; | |
7699 | ||
7700 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7701 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7702 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7703 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7704 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7705 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7706 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7707 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7708 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7709 | |
7710 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7711 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7712 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7713 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7714 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7715 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7716 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7717 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7718 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7719 | |
7720 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7721 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7722 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7723 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7724 | } |
7725 | ||
7726 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7727 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7728 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7729 | ||
2d112de7 ACO |
7730 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7731 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7732 | } |
7733 | ||
f6a83288 | 7734 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7735 | struct intel_crtc_state *pipe_config) |
babea61d | 7736 | { |
2d112de7 ACO |
7737 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7738 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7739 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7740 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7741 | |
2d112de7 ACO |
7742 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7743 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7744 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7745 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7746 | |
2d112de7 | 7747 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7748 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7749 | |
2d112de7 ACO |
7750 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7751 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7752 | |
7753 | mode->hsync = drm_mode_hsync(mode); | |
7754 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7755 | drm_mode_set_name(mode); | |
babea61d JB |
7756 | } |
7757 | ||
84b046f3 DV |
7758 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7759 | { | |
7760 | struct drm_device *dev = intel_crtc->base.dev; | |
7761 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7762 | uint32_t pipeconf; | |
7763 | ||
9f11a9e4 | 7764 | pipeconf = 0; |
84b046f3 | 7765 | |
b6b5d049 VS |
7766 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7767 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7768 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7769 | |
6e3c9717 | 7770 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7771 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7772 | |
ff9ce46e DV |
7773 | /* only g4x and later have fancy bpc/dither controls */ |
7774 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7775 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7776 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7777 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7778 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7779 | |
6e3c9717 | 7780 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7781 | case 18: |
7782 | pipeconf |= PIPECONF_6BPC; | |
7783 | break; | |
7784 | case 24: | |
7785 | pipeconf |= PIPECONF_8BPC; | |
7786 | break; | |
7787 | case 30: | |
7788 | pipeconf |= PIPECONF_10BPC; | |
7789 | break; | |
7790 | default: | |
7791 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7792 | BUG(); | |
84b046f3 DV |
7793 | } |
7794 | } | |
7795 | ||
7796 | if (HAS_PIPE_CXSR(dev)) { | |
7797 | if (intel_crtc->lowfreq_avail) { | |
7798 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7799 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7800 | } else { | |
7801 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7802 | } |
7803 | } | |
7804 | ||
6e3c9717 | 7805 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7806 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7807 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7808 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7809 | else | |
7810 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7811 | } else | |
84b046f3 DV |
7812 | pipeconf |= PIPECONF_PROGRESSIVE; |
7813 | ||
6e3c9717 | 7814 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7815 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7816 | |
84b046f3 DV |
7817 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7818 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7819 | } | |
7820 | ||
190f68c5 ACO |
7821 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7822 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7823 | { |
c7653199 | 7824 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7825 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7826 | int refclk, num_connectors = 0; |
c329a4ec DV |
7827 | intel_clock_t clock; |
7828 | bool ok; | |
7829 | bool is_dsi = false; | |
5eddb70b | 7830 | struct intel_encoder *encoder; |
d4906093 | 7831 | const intel_limit_t *limit; |
55bb9992 | 7832 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7833 | struct drm_connector *connector; |
55bb9992 ACO |
7834 | struct drm_connector_state *connector_state; |
7835 | int i; | |
79e53945 | 7836 | |
dd3cd74a ACO |
7837 | memset(&crtc_state->dpll_hw_state, 0, |
7838 | sizeof(crtc_state->dpll_hw_state)); | |
7839 | ||
da3ced29 | 7840 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7841 | if (connector_state->crtc != &crtc->base) |
7842 | continue; | |
7843 | ||
7844 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7845 | ||
5eddb70b | 7846 | switch (encoder->type) { |
e9fd1c02 JN |
7847 | case INTEL_OUTPUT_DSI: |
7848 | is_dsi = true; | |
7849 | break; | |
6847d71b PZ |
7850 | default: |
7851 | break; | |
79e53945 | 7852 | } |
43565a06 | 7853 | |
c751ce4f | 7854 | num_connectors++; |
79e53945 JB |
7855 | } |
7856 | ||
f2335330 | 7857 | if (is_dsi) |
5b18e57c | 7858 | return 0; |
f2335330 | 7859 | |
190f68c5 | 7860 | if (!crtc_state->clock_set) { |
a93e255f | 7861 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7862 | |
e9fd1c02 JN |
7863 | /* |
7864 | * Returns a set of divisors for the desired target clock with | |
7865 | * the given refclk, or FALSE. The returned values represent | |
7866 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7867 | * 2) / p1 / p2. | |
7868 | */ | |
a93e255f ACO |
7869 | limit = intel_limit(crtc_state, refclk); |
7870 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7871 | crtc_state->port_clock, |
e9fd1c02 | 7872 | refclk, NULL, &clock); |
f2335330 | 7873 | if (!ok) { |
e9fd1c02 JN |
7874 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7875 | return -EINVAL; | |
7876 | } | |
79e53945 | 7877 | |
f2335330 | 7878 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
7879 | crtc_state->dpll.n = clock.n; |
7880 | crtc_state->dpll.m1 = clock.m1; | |
7881 | crtc_state->dpll.m2 = clock.m2; | |
7882 | crtc_state->dpll.p1 = clock.p1; | |
7883 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7884 | } |
7026d4ac | 7885 | |
e9fd1c02 | 7886 | if (IS_GEN2(dev)) { |
c329a4ec | 7887 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7888 | num_connectors); |
9d556c99 | 7889 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 7890 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7891 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 7892 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7893 | } else { |
c329a4ec | 7894 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7895 | num_connectors); |
e9fd1c02 | 7896 | } |
79e53945 | 7897 | |
c8f7a0db | 7898 | return 0; |
f564048e EA |
7899 | } |
7900 | ||
2fa2fe9a | 7901 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7902 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7903 | { |
7904 | struct drm_device *dev = crtc->base.dev; | |
7905 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7906 | uint32_t tmp; | |
7907 | ||
dc9e7dec VS |
7908 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7909 | return; | |
7910 | ||
2fa2fe9a | 7911 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7912 | if (!(tmp & PFIT_ENABLE)) |
7913 | return; | |
2fa2fe9a | 7914 | |
06922821 | 7915 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7916 | if (INTEL_INFO(dev)->gen < 4) { |
7917 | if (crtc->pipe != PIPE_B) | |
7918 | return; | |
2fa2fe9a DV |
7919 | } else { |
7920 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7921 | return; | |
7922 | } | |
7923 | ||
06922821 | 7924 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
7925 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
7926 | if (INTEL_INFO(dev)->gen < 5) | |
7927 | pipe_config->gmch_pfit.lvds_border_bits = | |
7928 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
7929 | } | |
7930 | ||
acbec814 | 7931 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7932 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7933 | { |
7934 | struct drm_device *dev = crtc->base.dev; | |
7935 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7936 | int pipe = pipe_config->cpu_transcoder; | |
7937 | intel_clock_t clock; | |
7938 | u32 mdiv; | |
662c6ecb | 7939 | int refclk = 100000; |
acbec814 | 7940 | |
f573de5a SK |
7941 | /* In case of MIPI DPLL will not even be used */ |
7942 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
7943 | return; | |
7944 | ||
a580516d | 7945 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 7946 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 7947 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
7948 | |
7949 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7950 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7951 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7952 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7953 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7954 | ||
dccbea3b | 7955 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
7956 | } |
7957 | ||
5724dbd1 DL |
7958 | static void |
7959 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7960 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7961 | { |
7962 | struct drm_device *dev = crtc->base.dev; | |
7963 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7964 | u32 val, base, offset; | |
7965 | int pipe = crtc->pipe, plane = crtc->plane; | |
7966 | int fourcc, pixel_format; | |
6761dd31 | 7967 | unsigned int aligned_height; |
b113d5ee | 7968 | struct drm_framebuffer *fb; |
1b842c89 | 7969 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7970 | |
42a7b088 DL |
7971 | val = I915_READ(DSPCNTR(plane)); |
7972 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7973 | return; | |
7974 | ||
d9806c9f | 7975 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7976 | if (!intel_fb) { |
1ad292b5 JB |
7977 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7978 | return; | |
7979 | } | |
7980 | ||
1b842c89 DL |
7981 | fb = &intel_fb->base; |
7982 | ||
18c5247e DV |
7983 | if (INTEL_INFO(dev)->gen >= 4) { |
7984 | if (val & DISPPLANE_TILED) { | |
49af449b | 7985 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
7986 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
7987 | } | |
7988 | } | |
1ad292b5 JB |
7989 | |
7990 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 7991 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
7992 | fb->pixel_format = fourcc; |
7993 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
7994 | |
7995 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 7996 | if (plane_config->tiling) |
1ad292b5 JB |
7997 | offset = I915_READ(DSPTILEOFF(plane)); |
7998 | else | |
7999 | offset = I915_READ(DSPLINOFF(plane)); | |
8000 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8001 | } else { | |
8002 | base = I915_READ(DSPADDR(plane)); | |
8003 | } | |
8004 | plane_config->base = base; | |
8005 | ||
8006 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8007 | fb->width = ((val >> 16) & 0xfff) + 1; |
8008 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8009 | |
8010 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8011 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8012 | |
b113d5ee | 8013 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8014 | fb->pixel_format, |
8015 | fb->modifier[0]); | |
1ad292b5 | 8016 | |
f37b5c2b | 8017 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8018 | |
2844a921 DL |
8019 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8020 | pipe_name(pipe), plane, fb->width, fb->height, | |
8021 | fb->bits_per_pixel, base, fb->pitches[0], | |
8022 | plane_config->size); | |
1ad292b5 | 8023 | |
2d14030b | 8024 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8025 | } |
8026 | ||
70b23a98 | 8027 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8028 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8029 | { |
8030 | struct drm_device *dev = crtc->base.dev; | |
8031 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8032 | int pipe = pipe_config->cpu_transcoder; | |
8033 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8034 | intel_clock_t clock; | |
0d7b6b11 | 8035 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8036 | int refclk = 100000; |
8037 | ||
a580516d | 8038 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8039 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8040 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8041 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8042 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8043 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8044 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8045 | |
8046 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8047 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8048 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8049 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8050 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8051 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8052 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8053 | ||
dccbea3b | 8054 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8055 | } |
8056 | ||
0e8ffe1b | 8057 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8058 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8059 | { |
8060 | struct drm_device *dev = crtc->base.dev; | |
8061 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8062 | uint32_t tmp; | |
8063 | ||
f458ebbc DV |
8064 | if (!intel_display_power_is_enabled(dev_priv, |
8065 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8066 | return false; |
8067 | ||
e143a21c | 8068 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8069 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8070 | |
0e8ffe1b DV |
8071 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8072 | if (!(tmp & PIPECONF_ENABLE)) | |
8073 | return false; | |
8074 | ||
42571aef VS |
8075 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8076 | switch (tmp & PIPECONF_BPC_MASK) { | |
8077 | case PIPECONF_6BPC: | |
8078 | pipe_config->pipe_bpp = 18; | |
8079 | break; | |
8080 | case PIPECONF_8BPC: | |
8081 | pipe_config->pipe_bpp = 24; | |
8082 | break; | |
8083 | case PIPECONF_10BPC: | |
8084 | pipe_config->pipe_bpp = 30; | |
8085 | break; | |
8086 | default: | |
8087 | break; | |
8088 | } | |
8089 | } | |
8090 | ||
b5a9fa09 DV |
8091 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8092 | pipe_config->limited_color_range = true; | |
8093 | ||
282740f7 VS |
8094 | if (INTEL_INFO(dev)->gen < 4) |
8095 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8096 | ||
1bd1bd80 DV |
8097 | intel_get_pipe_timings(crtc, pipe_config); |
8098 | ||
2fa2fe9a DV |
8099 | i9xx_get_pfit_config(crtc, pipe_config); |
8100 | ||
6c49f241 DV |
8101 | if (INTEL_INFO(dev)->gen >= 4) { |
8102 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8103 | pipe_config->pixel_multiplier = | |
8104 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8105 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8106 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8107 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8108 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8109 | pipe_config->pixel_multiplier = | |
8110 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8111 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8112 | } else { | |
8113 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8114 | * port and will be fixed up in the encoder->get_config | |
8115 | * function. */ | |
8116 | pipe_config->pixel_multiplier = 1; | |
8117 | } | |
8bcc2795 DV |
8118 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8119 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8120 | /* |
8121 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8122 | * on 830. Filter it out here so that we don't | |
8123 | * report errors due to that. | |
8124 | */ | |
8125 | if (IS_I830(dev)) | |
8126 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8127 | ||
8bcc2795 DV |
8128 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8129 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8130 | } else { |
8131 | /* Mask out read-only status bits. */ | |
8132 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8133 | DPLL_PORTC_READY_MASK | | |
8134 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8135 | } |
6c49f241 | 8136 | |
70b23a98 VS |
8137 | if (IS_CHERRYVIEW(dev)) |
8138 | chv_crtc_clock_get(crtc, pipe_config); | |
8139 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8140 | vlv_crtc_clock_get(crtc, pipe_config); |
8141 | else | |
8142 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8143 | |
0f64614d VS |
8144 | /* |
8145 | * Normally the dotclock is filled in by the encoder .get_config() | |
8146 | * but in case the pipe is enabled w/o any ports we need a sane | |
8147 | * default. | |
8148 | */ | |
8149 | pipe_config->base.adjusted_mode.crtc_clock = | |
8150 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8151 | ||
0e8ffe1b DV |
8152 | return true; |
8153 | } | |
8154 | ||
dde86e2d | 8155 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8156 | { |
8157 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8158 | struct intel_encoder *encoder; |
74cfd7ac | 8159 | u32 val, final; |
13d83a67 | 8160 | bool has_lvds = false; |
199e5d79 | 8161 | bool has_cpu_edp = false; |
199e5d79 | 8162 | bool has_panel = false; |
99eb6a01 KP |
8163 | bool has_ck505 = false; |
8164 | bool can_ssc = false; | |
13d83a67 JB |
8165 | |
8166 | /* We need to take the global config into account */ | |
b2784e15 | 8167 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8168 | switch (encoder->type) { |
8169 | case INTEL_OUTPUT_LVDS: | |
8170 | has_panel = true; | |
8171 | has_lvds = true; | |
8172 | break; | |
8173 | case INTEL_OUTPUT_EDP: | |
8174 | has_panel = true; | |
2de6905f | 8175 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8176 | has_cpu_edp = true; |
8177 | break; | |
6847d71b PZ |
8178 | default: |
8179 | break; | |
13d83a67 JB |
8180 | } |
8181 | } | |
8182 | ||
99eb6a01 | 8183 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8184 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8185 | can_ssc = has_ck505; |
8186 | } else { | |
8187 | has_ck505 = false; | |
8188 | can_ssc = true; | |
8189 | } | |
8190 | ||
2de6905f ID |
8191 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8192 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8193 | |
8194 | /* Ironlake: try to setup display ref clock before DPLL | |
8195 | * enabling. This is only under driver's control after | |
8196 | * PCH B stepping, previous chipset stepping should be | |
8197 | * ignoring this setting. | |
8198 | */ | |
74cfd7ac CW |
8199 | val = I915_READ(PCH_DREF_CONTROL); |
8200 | ||
8201 | /* As we must carefully and slowly disable/enable each source in turn, | |
8202 | * compute the final state we want first and check if we need to | |
8203 | * make any changes at all. | |
8204 | */ | |
8205 | final = val; | |
8206 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8207 | if (has_ck505) | |
8208 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8209 | else | |
8210 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8211 | ||
8212 | final &= ~DREF_SSC_SOURCE_MASK; | |
8213 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8214 | final &= ~DREF_SSC1_ENABLE; | |
8215 | ||
8216 | if (has_panel) { | |
8217 | final |= DREF_SSC_SOURCE_ENABLE; | |
8218 | ||
8219 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8220 | final |= DREF_SSC1_ENABLE; | |
8221 | ||
8222 | if (has_cpu_edp) { | |
8223 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8224 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8225 | else | |
8226 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8227 | } else | |
8228 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8229 | } else { | |
8230 | final |= DREF_SSC_SOURCE_DISABLE; | |
8231 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8232 | } | |
8233 | ||
8234 | if (final == val) | |
8235 | return; | |
8236 | ||
13d83a67 | 8237 | /* Always enable nonspread source */ |
74cfd7ac | 8238 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8239 | |
99eb6a01 | 8240 | if (has_ck505) |
74cfd7ac | 8241 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8242 | else |
74cfd7ac | 8243 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8244 | |
199e5d79 | 8245 | if (has_panel) { |
74cfd7ac CW |
8246 | val &= ~DREF_SSC_SOURCE_MASK; |
8247 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8248 | |
199e5d79 | 8249 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8250 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8251 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8252 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8253 | } else |
74cfd7ac | 8254 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8255 | |
8256 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8257 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8258 | POSTING_READ(PCH_DREF_CONTROL); |
8259 | udelay(200); | |
8260 | ||
74cfd7ac | 8261 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8262 | |
8263 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8264 | if (has_cpu_edp) { |
99eb6a01 | 8265 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8266 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8267 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8268 | } else |
74cfd7ac | 8269 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8270 | } else |
74cfd7ac | 8271 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8272 | |
74cfd7ac | 8273 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8274 | POSTING_READ(PCH_DREF_CONTROL); |
8275 | udelay(200); | |
8276 | } else { | |
8277 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8278 | ||
74cfd7ac | 8279 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8280 | |
8281 | /* Turn off CPU output */ | |
74cfd7ac | 8282 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8283 | |
74cfd7ac | 8284 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8285 | POSTING_READ(PCH_DREF_CONTROL); |
8286 | udelay(200); | |
8287 | ||
8288 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8289 | val &= ~DREF_SSC_SOURCE_MASK; |
8290 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8291 | |
8292 | /* Turn off SSC1 */ | |
74cfd7ac | 8293 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8294 | |
74cfd7ac | 8295 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8296 | POSTING_READ(PCH_DREF_CONTROL); |
8297 | udelay(200); | |
8298 | } | |
74cfd7ac CW |
8299 | |
8300 | BUG_ON(val != final); | |
13d83a67 JB |
8301 | } |
8302 | ||
f31f2d55 | 8303 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8304 | { |
f31f2d55 | 8305 | uint32_t tmp; |
dde86e2d | 8306 | |
0ff066a9 PZ |
8307 | tmp = I915_READ(SOUTH_CHICKEN2); |
8308 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8309 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8310 | |
0ff066a9 PZ |
8311 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8312 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8313 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8314 | |
0ff066a9 PZ |
8315 | tmp = I915_READ(SOUTH_CHICKEN2); |
8316 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8317 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8318 | |
0ff066a9 PZ |
8319 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8320 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8321 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8322 | } |
8323 | ||
8324 | /* WaMPhyProgramming:hsw */ | |
8325 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8326 | { | |
8327 | uint32_t tmp; | |
dde86e2d PZ |
8328 | |
8329 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8330 | tmp &= ~(0xFF << 24); | |
8331 | tmp |= (0x12 << 24); | |
8332 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8333 | ||
dde86e2d PZ |
8334 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8335 | tmp |= (1 << 11); | |
8336 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8337 | ||
8338 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8339 | tmp |= (1 << 11); | |
8340 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8341 | ||
dde86e2d PZ |
8342 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8343 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8344 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8345 | ||
8346 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8347 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8348 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8349 | ||
0ff066a9 PZ |
8350 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8351 | tmp &= ~(7 << 13); | |
8352 | tmp |= (5 << 13); | |
8353 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8354 | |
0ff066a9 PZ |
8355 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8356 | tmp &= ~(7 << 13); | |
8357 | tmp |= (5 << 13); | |
8358 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8359 | |
8360 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8361 | tmp &= ~0xFF; | |
8362 | tmp |= 0x1C; | |
8363 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8364 | ||
8365 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8366 | tmp &= ~0xFF; | |
8367 | tmp |= 0x1C; | |
8368 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8369 | ||
8370 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8371 | tmp &= ~(0xFF << 16); | |
8372 | tmp |= (0x1C << 16); | |
8373 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8374 | ||
8375 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8376 | tmp &= ~(0xFF << 16); | |
8377 | tmp |= (0x1C << 16); | |
8378 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8379 | ||
0ff066a9 PZ |
8380 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8381 | tmp |= (1 << 27); | |
8382 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8383 | |
0ff066a9 PZ |
8384 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8385 | tmp |= (1 << 27); | |
8386 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8387 | |
0ff066a9 PZ |
8388 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8389 | tmp &= ~(0xF << 28); | |
8390 | tmp |= (4 << 28); | |
8391 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8392 | |
0ff066a9 PZ |
8393 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8394 | tmp &= ~(0xF << 28); | |
8395 | tmp |= (4 << 28); | |
8396 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8397 | } |
8398 | ||
2fa86a1f PZ |
8399 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8400 | * Programming" based on the parameters passed: | |
8401 | * - Sequence to enable CLKOUT_DP | |
8402 | * - Sequence to enable CLKOUT_DP without spread | |
8403 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8404 | */ | |
8405 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8406 | bool with_fdi) | |
f31f2d55 PZ |
8407 | { |
8408 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8409 | uint32_t reg, tmp; |
8410 | ||
8411 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8412 | with_spread = true; | |
c2699524 | 8413 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8414 | with_fdi = false; |
f31f2d55 | 8415 | |
a580516d | 8416 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8417 | |
8418 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8419 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8420 | tmp |= SBI_SSCCTL_PATHALT; | |
8421 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8422 | ||
8423 | udelay(24); | |
8424 | ||
2fa86a1f PZ |
8425 | if (with_spread) { |
8426 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8427 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8428 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8429 | |
2fa86a1f PZ |
8430 | if (with_fdi) { |
8431 | lpt_reset_fdi_mphy(dev_priv); | |
8432 | lpt_program_fdi_mphy(dev_priv); | |
8433 | } | |
8434 | } | |
dde86e2d | 8435 | |
c2699524 | 8436 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8437 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8438 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8439 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8440 | |
a580516d | 8441 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8442 | } |
8443 | ||
47701c3b PZ |
8444 | /* Sequence to disable CLKOUT_DP */ |
8445 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8446 | { | |
8447 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8448 | uint32_t reg, tmp; | |
8449 | ||
a580516d | 8450 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8451 | |
c2699524 | 8452 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8453 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8454 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8455 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8456 | ||
8457 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8458 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8459 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8460 | tmp |= SBI_SSCCTL_PATHALT; | |
8461 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8462 | udelay(32); | |
8463 | } | |
8464 | tmp |= SBI_SSCCTL_DISABLE; | |
8465 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8466 | } | |
8467 | ||
a580516d | 8468 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8469 | } |
8470 | ||
bf8fa3d3 PZ |
8471 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8472 | { | |
bf8fa3d3 PZ |
8473 | struct intel_encoder *encoder; |
8474 | bool has_vga = false; | |
8475 | ||
b2784e15 | 8476 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8477 | switch (encoder->type) { |
8478 | case INTEL_OUTPUT_ANALOG: | |
8479 | has_vga = true; | |
8480 | break; | |
6847d71b PZ |
8481 | default: |
8482 | break; | |
bf8fa3d3 PZ |
8483 | } |
8484 | } | |
8485 | ||
47701c3b PZ |
8486 | if (has_vga) |
8487 | lpt_enable_clkout_dp(dev, true, true); | |
8488 | else | |
8489 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8490 | } |
8491 | ||
dde86e2d PZ |
8492 | /* |
8493 | * Initialize reference clocks when the driver loads | |
8494 | */ | |
8495 | void intel_init_pch_refclk(struct drm_device *dev) | |
8496 | { | |
8497 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8498 | ironlake_init_pch_refclk(dev); | |
8499 | else if (HAS_PCH_LPT(dev)) | |
8500 | lpt_init_pch_refclk(dev); | |
8501 | } | |
8502 | ||
55bb9992 | 8503 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8504 | { |
55bb9992 | 8505 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8506 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8507 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8508 | struct drm_connector *connector; |
55bb9992 | 8509 | struct drm_connector_state *connector_state; |
d9d444cb | 8510 | struct intel_encoder *encoder; |
55bb9992 | 8511 | int num_connectors = 0, i; |
d9d444cb JB |
8512 | bool is_lvds = false; |
8513 | ||
da3ced29 | 8514 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8515 | if (connector_state->crtc != crtc_state->base.crtc) |
8516 | continue; | |
8517 | ||
8518 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8519 | ||
d9d444cb JB |
8520 | switch (encoder->type) { |
8521 | case INTEL_OUTPUT_LVDS: | |
8522 | is_lvds = true; | |
8523 | break; | |
6847d71b PZ |
8524 | default: |
8525 | break; | |
d9d444cb JB |
8526 | } |
8527 | num_connectors++; | |
8528 | } | |
8529 | ||
8530 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8531 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8532 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8533 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8534 | } |
8535 | ||
8536 | return 120000; | |
8537 | } | |
8538 | ||
6ff93609 | 8539 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8540 | { |
c8203565 | 8541 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8542 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8543 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8544 | uint32_t val; |
8545 | ||
78114071 | 8546 | val = 0; |
c8203565 | 8547 | |
6e3c9717 | 8548 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8549 | case 18: |
dfd07d72 | 8550 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8551 | break; |
8552 | case 24: | |
dfd07d72 | 8553 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8554 | break; |
8555 | case 30: | |
dfd07d72 | 8556 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8557 | break; |
8558 | case 36: | |
dfd07d72 | 8559 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8560 | break; |
8561 | default: | |
cc769b62 PZ |
8562 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8563 | BUG(); | |
c8203565 PZ |
8564 | } |
8565 | ||
6e3c9717 | 8566 | if (intel_crtc->config->dither) |
c8203565 PZ |
8567 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8568 | ||
6e3c9717 | 8569 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8570 | val |= PIPECONF_INTERLACED_ILK; |
8571 | else | |
8572 | val |= PIPECONF_PROGRESSIVE; | |
8573 | ||
6e3c9717 | 8574 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8575 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8576 | |
c8203565 PZ |
8577 | I915_WRITE(PIPECONF(pipe), val); |
8578 | POSTING_READ(PIPECONF(pipe)); | |
8579 | } | |
8580 | ||
86d3efce VS |
8581 | /* |
8582 | * Set up the pipe CSC unit. | |
8583 | * | |
8584 | * Currently only full range RGB to limited range RGB conversion | |
8585 | * is supported, but eventually this should handle various | |
8586 | * RGB<->YCbCr scenarios as well. | |
8587 | */ | |
50f3b016 | 8588 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8589 | { |
8590 | struct drm_device *dev = crtc->dev; | |
8591 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8592 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8593 | int pipe = intel_crtc->pipe; | |
8594 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8595 | ||
8596 | /* | |
8597 | * TODO: Check what kind of values actually come out of the pipe | |
8598 | * with these coeff/postoff values and adjust to get the best | |
8599 | * accuracy. Perhaps we even need to take the bpc value into | |
8600 | * consideration. | |
8601 | */ | |
8602 | ||
6e3c9717 | 8603 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8604 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8605 | ||
8606 | /* | |
8607 | * GY/GU and RY/RU should be the other way around according | |
8608 | * to BSpec, but reality doesn't agree. Just set them up in | |
8609 | * a way that results in the correct picture. | |
8610 | */ | |
8611 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8612 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8613 | ||
8614 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8615 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8616 | ||
8617 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8618 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8619 | ||
8620 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8621 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8622 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8623 | ||
8624 | if (INTEL_INFO(dev)->gen > 6) { | |
8625 | uint16_t postoff = 0; | |
8626 | ||
6e3c9717 | 8627 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8628 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8629 | |
8630 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8631 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8632 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8633 | ||
8634 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8635 | } else { | |
8636 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8637 | ||
6e3c9717 | 8638 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8639 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8640 | ||
8641 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8642 | } | |
8643 | } | |
8644 | ||
6ff93609 | 8645 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8646 | { |
756f85cf PZ |
8647 | struct drm_device *dev = crtc->dev; |
8648 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8649 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8650 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8651 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8652 | uint32_t val; |
8653 | ||
3eff4faa | 8654 | val = 0; |
ee2b0b38 | 8655 | |
6e3c9717 | 8656 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8657 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8658 | ||
6e3c9717 | 8659 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8660 | val |= PIPECONF_INTERLACED_ILK; |
8661 | else | |
8662 | val |= PIPECONF_PROGRESSIVE; | |
8663 | ||
702e7a56 PZ |
8664 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8665 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8666 | |
8667 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8668 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8669 | |
3cdf122c | 8670 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8671 | val = 0; |
8672 | ||
6e3c9717 | 8673 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8674 | case 18: |
8675 | val |= PIPEMISC_DITHER_6_BPC; | |
8676 | break; | |
8677 | case 24: | |
8678 | val |= PIPEMISC_DITHER_8_BPC; | |
8679 | break; | |
8680 | case 30: | |
8681 | val |= PIPEMISC_DITHER_10_BPC; | |
8682 | break; | |
8683 | case 36: | |
8684 | val |= PIPEMISC_DITHER_12_BPC; | |
8685 | break; | |
8686 | default: | |
8687 | /* Case prevented by pipe_config_set_bpp. */ | |
8688 | BUG(); | |
8689 | } | |
8690 | ||
6e3c9717 | 8691 | if (intel_crtc->config->dither) |
756f85cf PZ |
8692 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8693 | ||
8694 | I915_WRITE(PIPEMISC(pipe), val); | |
8695 | } | |
ee2b0b38 PZ |
8696 | } |
8697 | ||
6591c6e4 | 8698 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8699 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8700 | intel_clock_t *clock, |
8701 | bool *has_reduced_clock, | |
8702 | intel_clock_t *reduced_clock) | |
8703 | { | |
8704 | struct drm_device *dev = crtc->dev; | |
8705 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8706 | int refclk; |
d4906093 | 8707 | const intel_limit_t *limit; |
c329a4ec | 8708 | bool ret; |
79e53945 | 8709 | |
55bb9992 | 8710 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8711 | |
d4906093 ML |
8712 | /* |
8713 | * Returns a set of divisors for the desired target clock with the given | |
8714 | * refclk, or FALSE. The returned values represent the clock equation: | |
8715 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8716 | */ | |
a93e255f ACO |
8717 | limit = intel_limit(crtc_state, refclk); |
8718 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8719 | crtc_state->port_clock, |
ee9300bb | 8720 | refclk, NULL, clock); |
6591c6e4 PZ |
8721 | if (!ret) |
8722 | return false; | |
cda4b7d3 | 8723 | |
6591c6e4 PZ |
8724 | return true; |
8725 | } | |
8726 | ||
d4b1931c PZ |
8727 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8728 | { | |
8729 | /* | |
8730 | * Account for spread spectrum to avoid | |
8731 | * oversubscribing the link. Max center spread | |
8732 | * is 2.5%; use 5% for safety's sake. | |
8733 | */ | |
8734 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8735 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8736 | } |
8737 | ||
7429e9d4 | 8738 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8739 | { |
7429e9d4 | 8740 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8741 | } |
8742 | ||
de13a2e3 | 8743 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8744 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8745 | u32 *fp, |
9a7c7890 | 8746 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8747 | { |
de13a2e3 | 8748 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8749 | struct drm_device *dev = crtc->dev; |
8750 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8751 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8752 | struct drm_connector *connector; |
55bb9992 ACO |
8753 | struct drm_connector_state *connector_state; |
8754 | struct intel_encoder *encoder; | |
de13a2e3 | 8755 | uint32_t dpll; |
55bb9992 | 8756 | int factor, num_connectors = 0, i; |
09ede541 | 8757 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8758 | |
da3ced29 | 8759 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8760 | if (connector_state->crtc != crtc_state->base.crtc) |
8761 | continue; | |
8762 | ||
8763 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8764 | ||
8765 | switch (encoder->type) { | |
79e53945 JB |
8766 | case INTEL_OUTPUT_LVDS: |
8767 | is_lvds = true; | |
8768 | break; | |
8769 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8770 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8771 | is_sdvo = true; |
79e53945 | 8772 | break; |
6847d71b PZ |
8773 | default: |
8774 | break; | |
79e53945 | 8775 | } |
43565a06 | 8776 | |
c751ce4f | 8777 | num_connectors++; |
79e53945 | 8778 | } |
79e53945 | 8779 | |
c1858123 | 8780 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8781 | factor = 21; |
8782 | if (is_lvds) { | |
8783 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8784 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8785 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8786 | factor = 25; |
190f68c5 | 8787 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8788 | factor = 20; |
c1858123 | 8789 | |
190f68c5 | 8790 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8791 | *fp |= FP_CB_TUNE; |
2c07245f | 8792 | |
9a7c7890 DV |
8793 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8794 | *fp2 |= FP_CB_TUNE; | |
8795 | ||
5eddb70b | 8796 | dpll = 0; |
2c07245f | 8797 | |
a07d6787 EA |
8798 | if (is_lvds) |
8799 | dpll |= DPLLB_MODE_LVDS; | |
8800 | else | |
8801 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8802 | |
190f68c5 | 8803 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8804 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8805 | |
8806 | if (is_sdvo) | |
4a33e48d | 8807 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8808 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8809 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8810 | |
a07d6787 | 8811 | /* compute bitmask from p1 value */ |
190f68c5 | 8812 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8813 | /* also FPA1 */ |
190f68c5 | 8814 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8815 | |
190f68c5 | 8816 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8817 | case 5: |
8818 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8819 | break; | |
8820 | case 7: | |
8821 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8822 | break; | |
8823 | case 10: | |
8824 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8825 | break; | |
8826 | case 14: | |
8827 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8828 | break; | |
79e53945 JB |
8829 | } |
8830 | ||
b4c09f3b | 8831 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8832 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8833 | else |
8834 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8835 | ||
959e16d6 | 8836 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8837 | } |
8838 | ||
190f68c5 ACO |
8839 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8840 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8841 | { |
c7653199 | 8842 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8843 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8844 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8845 | bool ok, has_reduced_clock = false; |
8b47047b | 8846 | bool is_lvds = false; |
e2b78267 | 8847 | struct intel_shared_dpll *pll; |
de13a2e3 | 8848 | |
dd3cd74a ACO |
8849 | memset(&crtc_state->dpll_hw_state, 0, |
8850 | sizeof(crtc_state->dpll_hw_state)); | |
8851 | ||
409ee761 | 8852 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8853 | |
5dc5298b PZ |
8854 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8855 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8856 | |
190f68c5 | 8857 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8858 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8859 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8860 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8861 | return -EINVAL; | |
79e53945 | 8862 | } |
f47709a9 | 8863 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8864 | if (!crtc_state->clock_set) { |
8865 | crtc_state->dpll.n = clock.n; | |
8866 | crtc_state->dpll.m1 = clock.m1; | |
8867 | crtc_state->dpll.m2 = clock.m2; | |
8868 | crtc_state->dpll.p1 = clock.p1; | |
8869 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8870 | } |
79e53945 | 8871 | |
5dc5298b | 8872 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8873 | if (crtc_state->has_pch_encoder) { |
8874 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8875 | if (has_reduced_clock) |
7429e9d4 | 8876 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8877 | |
190f68c5 | 8878 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8879 | &fp, &reduced_clock, |
8880 | has_reduced_clock ? &fp2 : NULL); | |
8881 | ||
190f68c5 ACO |
8882 | crtc_state->dpll_hw_state.dpll = dpll; |
8883 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8884 | if (has_reduced_clock) |
190f68c5 | 8885 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8886 | else |
190f68c5 | 8887 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8888 | |
190f68c5 | 8889 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8890 | if (pll == NULL) { |
84f44ce7 | 8891 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8892 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8893 | return -EINVAL; |
8894 | } | |
3fb37703 | 8895 | } |
79e53945 | 8896 | |
ab585dea | 8897 | if (is_lvds && has_reduced_clock) |
c7653199 | 8898 | crtc->lowfreq_avail = true; |
bcd644e0 | 8899 | else |
c7653199 | 8900 | crtc->lowfreq_avail = false; |
e2b78267 | 8901 | |
c8f7a0db | 8902 | return 0; |
79e53945 JB |
8903 | } |
8904 | ||
eb14cb74 VS |
8905 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8906 | struct intel_link_m_n *m_n) | |
8907 | { | |
8908 | struct drm_device *dev = crtc->base.dev; | |
8909 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8910 | enum pipe pipe = crtc->pipe; | |
8911 | ||
8912 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8913 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8914 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8915 | & ~TU_SIZE_MASK; | |
8916 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8917 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8918 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8919 | } | |
8920 | ||
8921 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8922 | enum transcoder transcoder, | |
b95af8be VK |
8923 | struct intel_link_m_n *m_n, |
8924 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
8925 | { |
8926 | struct drm_device *dev = crtc->base.dev; | |
8927 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 8928 | enum pipe pipe = crtc->pipe; |
72419203 | 8929 | |
eb14cb74 VS |
8930 | if (INTEL_INFO(dev)->gen >= 5) { |
8931 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
8932 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8933 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8934 | & ~TU_SIZE_MASK; | |
8935 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8936 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8937 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8938 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8939 | * gen < 8) and if DRRS is supported (to make sure the | |
8940 | * registers are not unnecessarily read). | |
8941 | */ | |
8942 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 8943 | crtc->config->has_drrs) { |
b95af8be VK |
8944 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8945 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8946 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8947 | & ~TU_SIZE_MASK; | |
8948 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8949 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8950 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8951 | } | |
eb14cb74 VS |
8952 | } else { |
8953 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8954 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8955 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8956 | & ~TU_SIZE_MASK; | |
8957 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8958 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8959 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8960 | } | |
8961 | } | |
8962 | ||
8963 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8964 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8965 | { |
681a8504 | 8966 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8967 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8968 | else | |
8969 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8970 | &pipe_config->dp_m_n, |
8971 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8972 | } |
72419203 | 8973 | |
eb14cb74 | 8974 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 8975 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
8976 | { |
8977 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 8978 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
8979 | } |
8980 | ||
bd2e244f | 8981 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8982 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
8983 | { |
8984 | struct drm_device *dev = crtc->base.dev; | |
8985 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
8986 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
8987 | uint32_t ps_ctrl = 0; | |
8988 | int id = -1; | |
8989 | int i; | |
bd2e244f | 8990 | |
a1b2278e CK |
8991 | /* find scaler attached to this pipe */ |
8992 | for (i = 0; i < crtc->num_scalers; i++) { | |
8993 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
8994 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
8995 | id = i; | |
8996 | pipe_config->pch_pfit.enabled = true; | |
8997 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
8998 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
8999 | break; | |
9000 | } | |
9001 | } | |
bd2e244f | 9002 | |
a1b2278e CK |
9003 | scaler_state->scaler_id = id; |
9004 | if (id >= 0) { | |
9005 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9006 | } else { | |
9007 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9008 | } |
9009 | } | |
9010 | ||
5724dbd1 DL |
9011 | static void |
9012 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9013 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9014 | { |
9015 | struct drm_device *dev = crtc->base.dev; | |
9016 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9017 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9018 | int pipe = crtc->pipe; |
9019 | int fourcc, pixel_format; | |
6761dd31 | 9020 | unsigned int aligned_height; |
bc8d7dff | 9021 | struct drm_framebuffer *fb; |
1b842c89 | 9022 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9023 | |
d9806c9f | 9024 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9025 | if (!intel_fb) { |
bc8d7dff DL |
9026 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9027 | return; | |
9028 | } | |
9029 | ||
1b842c89 DL |
9030 | fb = &intel_fb->base; |
9031 | ||
bc8d7dff | 9032 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9033 | if (!(val & PLANE_CTL_ENABLE)) |
9034 | goto error; | |
9035 | ||
bc8d7dff DL |
9036 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9037 | fourcc = skl_format_to_fourcc(pixel_format, | |
9038 | val & PLANE_CTL_ORDER_RGBX, | |
9039 | val & PLANE_CTL_ALPHA_MASK); | |
9040 | fb->pixel_format = fourcc; | |
9041 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9042 | ||
40f46283 DL |
9043 | tiling = val & PLANE_CTL_TILED_MASK; |
9044 | switch (tiling) { | |
9045 | case PLANE_CTL_TILED_LINEAR: | |
9046 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9047 | break; | |
9048 | case PLANE_CTL_TILED_X: | |
9049 | plane_config->tiling = I915_TILING_X; | |
9050 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9051 | break; | |
9052 | case PLANE_CTL_TILED_Y: | |
9053 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9054 | break; | |
9055 | case PLANE_CTL_TILED_YF: | |
9056 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9057 | break; | |
9058 | default: | |
9059 | MISSING_CASE(tiling); | |
9060 | goto error; | |
9061 | } | |
9062 | ||
bc8d7dff DL |
9063 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9064 | plane_config->base = base; | |
9065 | ||
9066 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9067 | ||
9068 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9069 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9070 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9071 | ||
9072 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9073 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9074 | fb->pixel_format); | |
bc8d7dff DL |
9075 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9076 | ||
9077 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9078 | fb->pixel_format, |
9079 | fb->modifier[0]); | |
bc8d7dff | 9080 | |
f37b5c2b | 9081 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9082 | |
9083 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9084 | pipe_name(pipe), fb->width, fb->height, | |
9085 | fb->bits_per_pixel, base, fb->pitches[0], | |
9086 | plane_config->size); | |
9087 | ||
2d14030b | 9088 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9089 | return; |
9090 | ||
9091 | error: | |
9092 | kfree(fb); | |
9093 | } | |
9094 | ||
2fa2fe9a | 9095 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9096 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9097 | { |
9098 | struct drm_device *dev = crtc->base.dev; | |
9099 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9100 | uint32_t tmp; | |
9101 | ||
9102 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9103 | ||
9104 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9105 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9106 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9107 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9108 | |
9109 | /* We currently do not free assignements of panel fitters on | |
9110 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9111 | * differentiates them) so just WARN about this case for now. */ | |
9112 | if (IS_GEN7(dev)) { | |
9113 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9114 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9115 | } | |
2fa2fe9a | 9116 | } |
79e53945 JB |
9117 | } |
9118 | ||
5724dbd1 DL |
9119 | static void |
9120 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9121 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9122 | { |
9123 | struct drm_device *dev = crtc->base.dev; | |
9124 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9125 | u32 val, base, offset; | |
aeee5a49 | 9126 | int pipe = crtc->pipe; |
4c6baa59 | 9127 | int fourcc, pixel_format; |
6761dd31 | 9128 | unsigned int aligned_height; |
b113d5ee | 9129 | struct drm_framebuffer *fb; |
1b842c89 | 9130 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9131 | |
42a7b088 DL |
9132 | val = I915_READ(DSPCNTR(pipe)); |
9133 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9134 | return; | |
9135 | ||
d9806c9f | 9136 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9137 | if (!intel_fb) { |
4c6baa59 JB |
9138 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9139 | return; | |
9140 | } | |
9141 | ||
1b842c89 DL |
9142 | fb = &intel_fb->base; |
9143 | ||
18c5247e DV |
9144 | if (INTEL_INFO(dev)->gen >= 4) { |
9145 | if (val & DISPPLANE_TILED) { | |
49af449b | 9146 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9147 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9148 | } | |
9149 | } | |
4c6baa59 JB |
9150 | |
9151 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9152 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9153 | fb->pixel_format = fourcc; |
9154 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9155 | |
aeee5a49 | 9156 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9157 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9158 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9159 | } else { |
49af449b | 9160 | if (plane_config->tiling) |
aeee5a49 | 9161 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9162 | else |
aeee5a49 | 9163 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9164 | } |
9165 | plane_config->base = base; | |
9166 | ||
9167 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9168 | fb->width = ((val >> 16) & 0xfff) + 1; |
9169 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9170 | |
9171 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9172 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9173 | |
b113d5ee | 9174 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9175 | fb->pixel_format, |
9176 | fb->modifier[0]); | |
4c6baa59 | 9177 | |
f37b5c2b | 9178 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9179 | |
2844a921 DL |
9180 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9181 | pipe_name(pipe), fb->width, fb->height, | |
9182 | fb->bits_per_pixel, base, fb->pitches[0], | |
9183 | plane_config->size); | |
b113d5ee | 9184 | |
2d14030b | 9185 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9186 | } |
9187 | ||
0e8ffe1b | 9188 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9189 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9190 | { |
9191 | struct drm_device *dev = crtc->base.dev; | |
9192 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9193 | uint32_t tmp; | |
9194 | ||
f458ebbc DV |
9195 | if (!intel_display_power_is_enabled(dev_priv, |
9196 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9197 | return false; |
9198 | ||
e143a21c | 9199 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9200 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9201 | |
0e8ffe1b DV |
9202 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9203 | if (!(tmp & PIPECONF_ENABLE)) | |
9204 | return false; | |
9205 | ||
42571aef VS |
9206 | switch (tmp & PIPECONF_BPC_MASK) { |
9207 | case PIPECONF_6BPC: | |
9208 | pipe_config->pipe_bpp = 18; | |
9209 | break; | |
9210 | case PIPECONF_8BPC: | |
9211 | pipe_config->pipe_bpp = 24; | |
9212 | break; | |
9213 | case PIPECONF_10BPC: | |
9214 | pipe_config->pipe_bpp = 30; | |
9215 | break; | |
9216 | case PIPECONF_12BPC: | |
9217 | pipe_config->pipe_bpp = 36; | |
9218 | break; | |
9219 | default: | |
9220 | break; | |
9221 | } | |
9222 | ||
b5a9fa09 DV |
9223 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9224 | pipe_config->limited_color_range = true; | |
9225 | ||
ab9412ba | 9226 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9227 | struct intel_shared_dpll *pll; |
9228 | ||
88adfff1 DV |
9229 | pipe_config->has_pch_encoder = true; |
9230 | ||
627eb5a3 DV |
9231 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9232 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9233 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9234 | |
9235 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9236 | |
c0d43d62 | 9237 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9238 | pipe_config->shared_dpll = |
9239 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9240 | } else { |
9241 | tmp = I915_READ(PCH_DPLL_SEL); | |
9242 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9243 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9244 | else | |
9245 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9246 | } | |
66e985c0 DV |
9247 | |
9248 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9249 | ||
9250 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9251 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9252 | |
9253 | tmp = pipe_config->dpll_hw_state.dpll; | |
9254 | pipe_config->pixel_multiplier = | |
9255 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9256 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9257 | |
9258 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9259 | } else { |
9260 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9261 | } |
9262 | ||
1bd1bd80 DV |
9263 | intel_get_pipe_timings(crtc, pipe_config); |
9264 | ||
2fa2fe9a DV |
9265 | ironlake_get_pfit_config(crtc, pipe_config); |
9266 | ||
0e8ffe1b DV |
9267 | return true; |
9268 | } | |
9269 | ||
be256dc7 PZ |
9270 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9271 | { | |
9272 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9273 | struct intel_crtc *crtc; |
be256dc7 | 9274 | |
d3fcc808 | 9275 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9276 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9277 | pipe_name(crtc->pipe)); |
9278 | ||
e2c719b7 RC |
9279 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9280 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9281 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9282 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9283 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9284 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9285 | "CPU PWM1 enabled\n"); |
c5107b87 | 9286 | if (IS_HASWELL(dev)) |
e2c719b7 | 9287 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9288 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9289 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9290 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9291 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9292 | "Utility pin enabled\n"); |
e2c719b7 | 9293 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9294 | |
9926ada1 PZ |
9295 | /* |
9296 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9297 | * interrupts remain enabled. We used to check for that, but since it's | |
9298 | * gen-specific and since we only disable LCPLL after we fully disable | |
9299 | * the interrupts, the check below should be enough. | |
9300 | */ | |
e2c719b7 | 9301 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9302 | } |
9303 | ||
9ccd5aeb PZ |
9304 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9305 | { | |
9306 | struct drm_device *dev = dev_priv->dev; | |
9307 | ||
9308 | if (IS_HASWELL(dev)) | |
9309 | return I915_READ(D_COMP_HSW); | |
9310 | else | |
9311 | return I915_READ(D_COMP_BDW); | |
9312 | } | |
9313 | ||
3c4c9b81 PZ |
9314 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9315 | { | |
9316 | struct drm_device *dev = dev_priv->dev; | |
9317 | ||
9318 | if (IS_HASWELL(dev)) { | |
9319 | mutex_lock(&dev_priv->rps.hw_lock); | |
9320 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9321 | val)) | |
f475dadf | 9322 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9323 | mutex_unlock(&dev_priv->rps.hw_lock); |
9324 | } else { | |
9ccd5aeb PZ |
9325 | I915_WRITE(D_COMP_BDW, val); |
9326 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9327 | } |
be256dc7 PZ |
9328 | } |
9329 | ||
9330 | /* | |
9331 | * This function implements pieces of two sequences from BSpec: | |
9332 | * - Sequence for display software to disable LCPLL | |
9333 | * - Sequence for display software to allow package C8+ | |
9334 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9335 | * register. Callers should take care of disabling all the display engine | |
9336 | * functions, doing the mode unset, fixing interrupts, etc. | |
9337 | */ | |
6ff58d53 PZ |
9338 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9339 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9340 | { |
9341 | uint32_t val; | |
9342 | ||
9343 | assert_can_disable_lcpll(dev_priv); | |
9344 | ||
9345 | val = I915_READ(LCPLL_CTL); | |
9346 | ||
9347 | if (switch_to_fclk) { | |
9348 | val |= LCPLL_CD_SOURCE_FCLK; | |
9349 | I915_WRITE(LCPLL_CTL, val); | |
9350 | ||
9351 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9352 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9353 | DRM_ERROR("Switching to FCLK failed\n"); | |
9354 | ||
9355 | val = I915_READ(LCPLL_CTL); | |
9356 | } | |
9357 | ||
9358 | val |= LCPLL_PLL_DISABLE; | |
9359 | I915_WRITE(LCPLL_CTL, val); | |
9360 | POSTING_READ(LCPLL_CTL); | |
9361 | ||
9362 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9363 | DRM_ERROR("LCPLL still locked\n"); | |
9364 | ||
9ccd5aeb | 9365 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9366 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9367 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9368 | ndelay(100); |
9369 | ||
9ccd5aeb PZ |
9370 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9371 | 1)) | |
be256dc7 PZ |
9372 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9373 | ||
9374 | if (allow_power_down) { | |
9375 | val = I915_READ(LCPLL_CTL); | |
9376 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9377 | I915_WRITE(LCPLL_CTL, val); | |
9378 | POSTING_READ(LCPLL_CTL); | |
9379 | } | |
9380 | } | |
9381 | ||
9382 | /* | |
9383 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9384 | * source. | |
9385 | */ | |
6ff58d53 | 9386 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9387 | { |
9388 | uint32_t val; | |
9389 | ||
9390 | val = I915_READ(LCPLL_CTL); | |
9391 | ||
9392 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9393 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9394 | return; | |
9395 | ||
a8a8bd54 PZ |
9396 | /* |
9397 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9398 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9399 | */ |
59bad947 | 9400 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9401 | |
be256dc7 PZ |
9402 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9403 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9404 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9405 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9406 | } |
9407 | ||
9ccd5aeb | 9408 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9409 | val |= D_COMP_COMP_FORCE; |
9410 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9411 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9412 | |
9413 | val = I915_READ(LCPLL_CTL); | |
9414 | val &= ~LCPLL_PLL_DISABLE; | |
9415 | I915_WRITE(LCPLL_CTL, val); | |
9416 | ||
9417 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9418 | DRM_ERROR("LCPLL not locked yet\n"); | |
9419 | ||
9420 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9421 | val = I915_READ(LCPLL_CTL); | |
9422 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9423 | I915_WRITE(LCPLL_CTL, val); | |
9424 | ||
9425 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9426 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9427 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9428 | } | |
215733fa | 9429 | |
59bad947 | 9430 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9431 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9432 | } |
9433 | ||
765dab67 PZ |
9434 | /* |
9435 | * Package states C8 and deeper are really deep PC states that can only be | |
9436 | * reached when all the devices on the system allow it, so even if the graphics | |
9437 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9438 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9439 | * | |
9440 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9441 | * well is disabled and most interrupts are disabled, and these are also | |
9442 | * requirements for runtime PM. When these conditions are met, we manually do | |
9443 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9444 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9445 | * hang the machine. | |
9446 | * | |
9447 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9448 | * the state of some registers, so when we come back from PC8+ we need to | |
9449 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9450 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9451 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9452 | * because of the runtime PM support). | |
9453 | * | |
9454 | * For more, read "Display Sequences for Package C8" on the hardware | |
9455 | * documentation. | |
9456 | */ | |
a14cb6fc | 9457 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9458 | { |
c67a470b PZ |
9459 | struct drm_device *dev = dev_priv->dev; |
9460 | uint32_t val; | |
9461 | ||
c67a470b PZ |
9462 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9463 | ||
c2699524 | 9464 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9465 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9466 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9467 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9468 | } | |
9469 | ||
9470 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9471 | hsw_disable_lcpll(dev_priv, true, true); |
9472 | } | |
9473 | ||
a14cb6fc | 9474 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9475 | { |
9476 | struct drm_device *dev = dev_priv->dev; | |
9477 | uint32_t val; | |
9478 | ||
c67a470b PZ |
9479 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9480 | ||
9481 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9482 | lpt_init_pch_refclk(dev); |
9483 | ||
c2699524 | 9484 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9485 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9486 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9487 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9488 | } | |
9489 | ||
9490 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9491 | } |
9492 | ||
27c329ed | 9493 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9494 | { |
a821fc46 | 9495 | struct drm_device *dev = old_state->dev; |
27c329ed | 9496 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
f8437dd1 | 9497 | |
27c329ed | 9498 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9499 | } |
9500 | ||
b432e5cf | 9501 | /* compute the max rate for new configuration */ |
27c329ed | 9502 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9503 | { |
b432e5cf | 9504 | struct intel_crtc *intel_crtc; |
27c329ed | 9505 | struct intel_crtc_state *crtc_state; |
b432e5cf | 9506 | int max_pixel_rate = 0; |
b432e5cf | 9507 | |
27c329ed ML |
9508 | for_each_intel_crtc(state->dev, intel_crtc) { |
9509 | int pixel_rate; | |
9510 | ||
9511 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
9512 | if (IS_ERR(crtc_state)) | |
9513 | return PTR_ERR(crtc_state); | |
9514 | ||
9515 | if (!crtc_state->base.enable) | |
b432e5cf VS |
9516 | continue; |
9517 | ||
27c329ed | 9518 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9519 | |
9520 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
27c329ed | 9521 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
b432e5cf VS |
9522 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9523 | ||
9524 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9525 | } | |
9526 | ||
9527 | return max_pixel_rate; | |
9528 | } | |
9529 | ||
9530 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9531 | { | |
9532 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9533 | uint32_t val, data; | |
9534 | int ret; | |
9535 | ||
9536 | if (WARN((I915_READ(LCPLL_CTL) & | |
9537 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9538 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9539 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9540 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9541 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9542 | return; | |
9543 | ||
9544 | mutex_lock(&dev_priv->rps.hw_lock); | |
9545 | ret = sandybridge_pcode_write(dev_priv, | |
9546 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9547 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9548 | if (ret) { | |
9549 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9550 | return; | |
9551 | } | |
9552 | ||
9553 | val = I915_READ(LCPLL_CTL); | |
9554 | val |= LCPLL_CD_SOURCE_FCLK; | |
9555 | I915_WRITE(LCPLL_CTL, val); | |
9556 | ||
9557 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9558 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9559 | DRM_ERROR("Switching to FCLK failed\n"); | |
9560 | ||
9561 | val = I915_READ(LCPLL_CTL); | |
9562 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9563 | ||
9564 | switch (cdclk) { | |
9565 | case 450000: | |
9566 | val |= LCPLL_CLK_FREQ_450; | |
9567 | data = 0; | |
9568 | break; | |
9569 | case 540000: | |
9570 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9571 | data = 1; | |
9572 | break; | |
9573 | case 337500: | |
9574 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9575 | data = 2; | |
9576 | break; | |
9577 | case 675000: | |
9578 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9579 | data = 3; | |
9580 | break; | |
9581 | default: | |
9582 | WARN(1, "invalid cdclk frequency\n"); | |
9583 | return; | |
9584 | } | |
9585 | ||
9586 | I915_WRITE(LCPLL_CTL, val); | |
9587 | ||
9588 | val = I915_READ(LCPLL_CTL); | |
9589 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9590 | I915_WRITE(LCPLL_CTL, val); | |
9591 | ||
9592 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9593 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9594 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9595 | ||
9596 | mutex_lock(&dev_priv->rps.hw_lock); | |
9597 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9598 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9599 | ||
9600 | intel_update_cdclk(dev); | |
9601 | ||
9602 | WARN(cdclk != dev_priv->cdclk_freq, | |
9603 | "cdclk requested %d kHz but got %d kHz\n", | |
9604 | cdclk, dev_priv->cdclk_freq); | |
9605 | } | |
9606 | ||
27c329ed | 9607 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9608 | { |
27c329ed ML |
9609 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
9610 | int max_pixclk = ilk_max_pixel_rate(state); | |
b432e5cf VS |
9611 | int cdclk; |
9612 | ||
9613 | /* | |
9614 | * FIXME should also account for plane ratio | |
9615 | * once 64bpp pixel formats are supported. | |
9616 | */ | |
27c329ed | 9617 | if (max_pixclk > 540000) |
b432e5cf | 9618 | cdclk = 675000; |
27c329ed | 9619 | else if (max_pixclk > 450000) |
b432e5cf | 9620 | cdclk = 540000; |
27c329ed | 9621 | else if (max_pixclk > 337500) |
b432e5cf VS |
9622 | cdclk = 450000; |
9623 | else | |
9624 | cdclk = 337500; | |
9625 | ||
9626 | /* | |
9627 | * FIXME move the cdclk caclulation to | |
9628 | * compute_config() so we can fail gracegully. | |
9629 | */ | |
9630 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9631 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9632 | cdclk, dev_priv->max_cdclk_freq); | |
9633 | cdclk = dev_priv->max_cdclk_freq; | |
9634 | } | |
9635 | ||
27c329ed | 9636 | to_intel_atomic_state(state)->cdclk = cdclk; |
b432e5cf VS |
9637 | |
9638 | return 0; | |
9639 | } | |
9640 | ||
27c329ed | 9641 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9642 | { |
27c329ed ML |
9643 | struct drm_device *dev = old_state->dev; |
9644 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; | |
b432e5cf | 9645 | |
27c329ed | 9646 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9647 | } |
9648 | ||
190f68c5 ACO |
9649 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9650 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9651 | { |
190f68c5 | 9652 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9653 | return -EINVAL; |
716c2e55 | 9654 | |
c7653199 | 9655 | crtc->lowfreq_avail = false; |
644cef34 | 9656 | |
c8f7a0db | 9657 | return 0; |
79e53945 JB |
9658 | } |
9659 | ||
3760b59c S |
9660 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9661 | enum port port, | |
9662 | struct intel_crtc_state *pipe_config) | |
9663 | { | |
9664 | switch (port) { | |
9665 | case PORT_A: | |
9666 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9667 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9668 | break; | |
9669 | case PORT_B: | |
9670 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9671 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9672 | break; | |
9673 | case PORT_C: | |
9674 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9675 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9676 | break; | |
9677 | default: | |
9678 | DRM_ERROR("Incorrect port type\n"); | |
9679 | } | |
9680 | } | |
9681 | ||
96b7dfb7 S |
9682 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9683 | enum port port, | |
5cec258b | 9684 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9685 | { |
3148ade7 | 9686 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9687 | |
9688 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9689 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9690 | ||
9691 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9692 | case SKL_DPLL0: |
9693 | /* | |
9694 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9695 | * of the shared DPLL framework and thus needs to be read out | |
9696 | * separately | |
9697 | */ | |
9698 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9699 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9700 | break; | |
96b7dfb7 S |
9701 | case SKL_DPLL1: |
9702 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9703 | break; | |
9704 | case SKL_DPLL2: | |
9705 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9706 | break; | |
9707 | case SKL_DPLL3: | |
9708 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9709 | break; | |
96b7dfb7 S |
9710 | } |
9711 | } | |
9712 | ||
7d2c8175 DL |
9713 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9714 | enum port port, | |
5cec258b | 9715 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9716 | { |
9717 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9718 | ||
9719 | switch (pipe_config->ddi_pll_sel) { | |
9720 | case PORT_CLK_SEL_WRPLL1: | |
9721 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9722 | break; | |
9723 | case PORT_CLK_SEL_WRPLL2: | |
9724 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9725 | break; | |
9726 | } | |
9727 | } | |
9728 | ||
26804afd | 9729 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9730 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9731 | { |
9732 | struct drm_device *dev = crtc->base.dev; | |
9733 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9734 | struct intel_shared_dpll *pll; |
26804afd DV |
9735 | enum port port; |
9736 | uint32_t tmp; | |
9737 | ||
9738 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9739 | ||
9740 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9741 | ||
ef11bdb3 | 9742 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 9743 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
9744 | else if (IS_BROXTON(dev)) |
9745 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9746 | else |
9747 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9748 | |
d452c5b6 DV |
9749 | if (pipe_config->shared_dpll >= 0) { |
9750 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9751 | ||
9752 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9753 | &pipe_config->dpll_hw_state)); | |
9754 | } | |
9755 | ||
26804afd DV |
9756 | /* |
9757 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9758 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9759 | * the PCH transcoder is on. | |
9760 | */ | |
ca370455 DL |
9761 | if (INTEL_INFO(dev)->gen < 9 && |
9762 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9763 | pipe_config->has_pch_encoder = true; |
9764 | ||
9765 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9766 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9767 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9768 | ||
9769 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9770 | } | |
9771 | } | |
9772 | ||
0e8ffe1b | 9773 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9774 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9775 | { |
9776 | struct drm_device *dev = crtc->base.dev; | |
9777 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9778 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9779 | uint32_t tmp; |
9780 | ||
f458ebbc | 9781 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9782 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9783 | return false; | |
9784 | ||
e143a21c | 9785 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9786 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9787 | ||
eccb140b DV |
9788 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9789 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9790 | enum pipe trans_edp_pipe; | |
9791 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9792 | default: | |
9793 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9794 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9795 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9796 | trans_edp_pipe = PIPE_A; | |
9797 | break; | |
9798 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9799 | trans_edp_pipe = PIPE_B; | |
9800 | break; | |
9801 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9802 | trans_edp_pipe = PIPE_C; | |
9803 | break; | |
9804 | } | |
9805 | ||
9806 | if (trans_edp_pipe == crtc->pipe) | |
9807 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9808 | } | |
9809 | ||
f458ebbc | 9810 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9811 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9812 | return false; |
9813 | ||
eccb140b | 9814 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9815 | if (!(tmp & PIPECONF_ENABLE)) |
9816 | return false; | |
9817 | ||
26804afd | 9818 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9819 | |
1bd1bd80 DV |
9820 | intel_get_pipe_timings(crtc, pipe_config); |
9821 | ||
a1b2278e CK |
9822 | if (INTEL_INFO(dev)->gen >= 9) { |
9823 | skl_init_scalers(dev, crtc, pipe_config); | |
9824 | } | |
9825 | ||
2fa2fe9a | 9826 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9827 | |
9828 | if (INTEL_INFO(dev)->gen >= 9) { | |
9829 | pipe_config->scaler_state.scaler_id = -1; | |
9830 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9831 | } | |
9832 | ||
bd2e244f | 9833 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
1c132b44 | 9834 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 9835 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9836 | else |
1c132b44 | 9837 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 9838 | } |
88adfff1 | 9839 | |
e59150dc JB |
9840 | if (IS_HASWELL(dev)) |
9841 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9842 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9843 | |
ebb69c95 CT |
9844 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9845 | pipe_config->pixel_multiplier = | |
9846 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9847 | } else { | |
9848 | pipe_config->pixel_multiplier = 1; | |
9849 | } | |
6c49f241 | 9850 | |
0e8ffe1b DV |
9851 | return true; |
9852 | } | |
9853 | ||
560b85bb CW |
9854 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9855 | { | |
9856 | struct drm_device *dev = crtc->dev; | |
9857 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9858 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9859 | uint32_t cntl = 0, size = 0; |
560b85bb | 9860 | |
dc41c154 | 9861 | if (base) { |
3dd512fb MR |
9862 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9863 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9864 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9865 | ||
9866 | switch (stride) { | |
9867 | default: | |
9868 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9869 | width, stride); | |
9870 | stride = 256; | |
9871 | /* fallthrough */ | |
9872 | case 256: | |
9873 | case 512: | |
9874 | case 1024: | |
9875 | case 2048: | |
9876 | break; | |
4b0e333e CW |
9877 | } |
9878 | ||
dc41c154 VS |
9879 | cntl |= CURSOR_ENABLE | |
9880 | CURSOR_GAMMA_ENABLE | | |
9881 | CURSOR_FORMAT_ARGB | | |
9882 | CURSOR_STRIDE(stride); | |
9883 | ||
9884 | size = (height << 12) | width; | |
4b0e333e | 9885 | } |
560b85bb | 9886 | |
dc41c154 VS |
9887 | if (intel_crtc->cursor_cntl != 0 && |
9888 | (intel_crtc->cursor_base != base || | |
9889 | intel_crtc->cursor_size != size || | |
9890 | intel_crtc->cursor_cntl != cntl)) { | |
9891 | /* On these chipsets we can only modify the base/size/stride | |
9892 | * whilst the cursor is disabled. | |
9893 | */ | |
0b87c24e VS |
9894 | I915_WRITE(CURCNTR(PIPE_A), 0); |
9895 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 9896 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9897 | } |
560b85bb | 9898 | |
99d1f387 | 9899 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 9900 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
9901 | intel_crtc->cursor_base = base; |
9902 | } | |
4726e0b0 | 9903 | |
dc41c154 VS |
9904 | if (intel_crtc->cursor_size != size) { |
9905 | I915_WRITE(CURSIZE, size); | |
9906 | intel_crtc->cursor_size = size; | |
4b0e333e | 9907 | } |
560b85bb | 9908 | |
4b0e333e | 9909 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
9910 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
9911 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 9912 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 9913 | } |
560b85bb CW |
9914 | } |
9915 | ||
560b85bb | 9916 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
9917 | { |
9918 | struct drm_device *dev = crtc->dev; | |
9919 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9920 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9921 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
9922 | uint32_t cntl; |
9923 | ||
9924 | cntl = 0; | |
9925 | if (base) { | |
9926 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 9927 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
9928 | case 64: |
9929 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9930 | break; | |
9931 | case 128: | |
9932 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9933 | break; | |
9934 | case 256: | |
9935 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
9936 | break; | |
9937 | default: | |
3dd512fb | 9938 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 9939 | return; |
65a21cd6 | 9940 | } |
4b0e333e | 9941 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 9942 | |
fc6f93bc | 9943 | if (HAS_DDI(dev)) |
47bf17a7 | 9944 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
4b0e333e | 9945 | } |
65a21cd6 | 9946 | |
8e7d688b | 9947 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
9948 | cntl |= CURSOR_ROTATE_180; |
9949 | ||
4b0e333e CW |
9950 | if (intel_crtc->cursor_cntl != cntl) { |
9951 | I915_WRITE(CURCNTR(pipe), cntl); | |
9952 | POSTING_READ(CURCNTR(pipe)); | |
9953 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 9954 | } |
4b0e333e | 9955 | |
65a21cd6 | 9956 | /* and commit changes on next vblank */ |
5efb3e28 VS |
9957 | I915_WRITE(CURBASE(pipe), base); |
9958 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
9959 | |
9960 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
9961 | } |
9962 | ||
cda4b7d3 | 9963 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
9964 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
9965 | bool on) | |
cda4b7d3 CW |
9966 | { |
9967 | struct drm_device *dev = crtc->dev; | |
9968 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9969 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9970 | int pipe = intel_crtc->pipe; | |
9b4101be ML |
9971 | struct drm_plane_state *cursor_state = crtc->cursor->state; |
9972 | int x = cursor_state->crtc_x; | |
9973 | int y = cursor_state->crtc_y; | |
d6e4db15 | 9974 | u32 base = 0, pos = 0; |
cda4b7d3 | 9975 | |
d6e4db15 | 9976 | if (on) |
cda4b7d3 | 9977 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 9978 | |
6e3c9717 | 9979 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
9980 | base = 0; |
9981 | ||
6e3c9717 | 9982 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
9983 | base = 0; |
9984 | ||
9985 | if (x < 0) { | |
9b4101be | 9986 | if (x + cursor_state->crtc_w <= 0) |
cda4b7d3 CW |
9987 | base = 0; |
9988 | ||
9989 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
9990 | x = -x; | |
9991 | } | |
9992 | pos |= x << CURSOR_X_SHIFT; | |
9993 | ||
9994 | if (y < 0) { | |
9b4101be | 9995 | if (y + cursor_state->crtc_h <= 0) |
cda4b7d3 CW |
9996 | base = 0; |
9997 | ||
9998 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
9999 | y = -y; | |
10000 | } | |
10001 | pos |= y << CURSOR_Y_SHIFT; | |
10002 | ||
4b0e333e | 10003 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
10004 | return; |
10005 | ||
5efb3e28 VS |
10006 | I915_WRITE(CURPOS(pipe), pos); |
10007 | ||
4398ad45 VS |
10008 | /* ILK+ do this automagically */ |
10009 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 10010 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
9b4101be ML |
10011 | base += (cursor_state->crtc_h * |
10012 | cursor_state->crtc_w - 1) * 4; | |
4398ad45 VS |
10013 | } |
10014 | ||
8ac54669 | 10015 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10016 | i845_update_cursor(crtc, base); |
10017 | else | |
10018 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10019 | } |
10020 | ||
dc41c154 VS |
10021 | static bool cursor_size_ok(struct drm_device *dev, |
10022 | uint32_t width, uint32_t height) | |
10023 | { | |
10024 | if (width == 0 || height == 0) | |
10025 | return false; | |
10026 | ||
10027 | /* | |
10028 | * 845g/865g are special in that they are only limited by | |
10029 | * the width of their cursors, the height is arbitrary up to | |
10030 | * the precision of the register. Everything else requires | |
10031 | * square cursors, limited to a few power-of-two sizes. | |
10032 | */ | |
10033 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10034 | if ((width & 63) != 0) | |
10035 | return false; | |
10036 | ||
10037 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10038 | return false; | |
10039 | ||
10040 | if (height > 1023) | |
10041 | return false; | |
10042 | } else { | |
10043 | switch (width | height) { | |
10044 | case 256: | |
10045 | case 128: | |
10046 | if (IS_GEN2(dev)) | |
10047 | return false; | |
10048 | case 64: | |
10049 | break; | |
10050 | default: | |
10051 | return false; | |
10052 | } | |
10053 | } | |
10054 | ||
10055 | return true; | |
10056 | } | |
10057 | ||
79e53945 | 10058 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10059 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10060 | { |
7203425a | 10061 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10063 | |
7203425a | 10064 | for (i = start; i < end; i++) { |
79e53945 JB |
10065 | intel_crtc->lut_r[i] = red[i] >> 8; |
10066 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10067 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10068 | } | |
10069 | ||
10070 | intel_crtc_load_lut(crtc); | |
10071 | } | |
10072 | ||
79e53945 JB |
10073 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10074 | static struct drm_display_mode load_detect_mode = { | |
10075 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10076 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10077 | }; | |
10078 | ||
a8bb6818 DV |
10079 | struct drm_framebuffer * |
10080 | __intel_framebuffer_create(struct drm_device *dev, | |
10081 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10082 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10083 | { |
10084 | struct intel_framebuffer *intel_fb; | |
10085 | int ret; | |
10086 | ||
10087 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10088 | if (!intel_fb) |
d2dff872 | 10089 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10090 | |
10091 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10092 | if (ret) |
10093 | goto err; | |
d2dff872 CW |
10094 | |
10095 | return &intel_fb->base; | |
dcb1394e | 10096 | |
dd4916c5 | 10097 | err: |
dd4916c5 | 10098 | kfree(intel_fb); |
dd4916c5 | 10099 | return ERR_PTR(ret); |
d2dff872 CW |
10100 | } |
10101 | ||
b5ea642a | 10102 | static struct drm_framebuffer * |
a8bb6818 DV |
10103 | intel_framebuffer_create(struct drm_device *dev, |
10104 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10105 | struct drm_i915_gem_object *obj) | |
10106 | { | |
10107 | struct drm_framebuffer *fb; | |
10108 | int ret; | |
10109 | ||
10110 | ret = i915_mutex_lock_interruptible(dev); | |
10111 | if (ret) | |
10112 | return ERR_PTR(ret); | |
10113 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10114 | mutex_unlock(&dev->struct_mutex); | |
10115 | ||
10116 | return fb; | |
10117 | } | |
10118 | ||
d2dff872 CW |
10119 | static u32 |
10120 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10121 | { | |
10122 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10123 | return ALIGN(pitch, 64); | |
10124 | } | |
10125 | ||
10126 | static u32 | |
10127 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10128 | { | |
10129 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10130 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10131 | } |
10132 | ||
10133 | static struct drm_framebuffer * | |
10134 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10135 | struct drm_display_mode *mode, | |
10136 | int depth, int bpp) | |
10137 | { | |
dcb1394e | 10138 | struct drm_framebuffer *fb; |
d2dff872 | 10139 | struct drm_i915_gem_object *obj; |
0fed39bd | 10140 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10141 | |
10142 | obj = i915_gem_alloc_object(dev, | |
10143 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10144 | if (obj == NULL) | |
10145 | return ERR_PTR(-ENOMEM); | |
10146 | ||
10147 | mode_cmd.width = mode->hdisplay; | |
10148 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10149 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10150 | bpp); | |
5ca0c34a | 10151 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10152 | |
dcb1394e LW |
10153 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10154 | if (IS_ERR(fb)) | |
10155 | drm_gem_object_unreference_unlocked(&obj->base); | |
10156 | ||
10157 | return fb; | |
d2dff872 CW |
10158 | } |
10159 | ||
10160 | static struct drm_framebuffer * | |
10161 | mode_fits_in_fbdev(struct drm_device *dev, | |
10162 | struct drm_display_mode *mode) | |
10163 | { | |
0695726e | 10164 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10165 | struct drm_i915_private *dev_priv = dev->dev_private; |
10166 | struct drm_i915_gem_object *obj; | |
10167 | struct drm_framebuffer *fb; | |
10168 | ||
4c0e5528 | 10169 | if (!dev_priv->fbdev) |
d2dff872 CW |
10170 | return NULL; |
10171 | ||
4c0e5528 | 10172 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10173 | return NULL; |
10174 | ||
4c0e5528 DV |
10175 | obj = dev_priv->fbdev->fb->obj; |
10176 | BUG_ON(!obj); | |
10177 | ||
8bcd4553 | 10178 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10179 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10180 | fb->bits_per_pixel)) | |
d2dff872 CW |
10181 | return NULL; |
10182 | ||
01f2c773 | 10183 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10184 | return NULL; |
10185 | ||
10186 | return fb; | |
4520f53a DV |
10187 | #else |
10188 | return NULL; | |
10189 | #endif | |
d2dff872 CW |
10190 | } |
10191 | ||
d3a40d1b ACO |
10192 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10193 | struct drm_crtc *crtc, | |
10194 | struct drm_display_mode *mode, | |
10195 | struct drm_framebuffer *fb, | |
10196 | int x, int y) | |
10197 | { | |
10198 | struct drm_plane_state *plane_state; | |
10199 | int hdisplay, vdisplay; | |
10200 | int ret; | |
10201 | ||
10202 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10203 | if (IS_ERR(plane_state)) | |
10204 | return PTR_ERR(plane_state); | |
10205 | ||
10206 | if (mode) | |
10207 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10208 | else | |
10209 | hdisplay = vdisplay = 0; | |
10210 | ||
10211 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10212 | if (ret) | |
10213 | return ret; | |
10214 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10215 | plane_state->crtc_x = 0; | |
10216 | plane_state->crtc_y = 0; | |
10217 | plane_state->crtc_w = hdisplay; | |
10218 | plane_state->crtc_h = vdisplay; | |
10219 | plane_state->src_x = x << 16; | |
10220 | plane_state->src_y = y << 16; | |
10221 | plane_state->src_w = hdisplay << 16; | |
10222 | plane_state->src_h = vdisplay << 16; | |
10223 | ||
10224 | return 0; | |
10225 | } | |
10226 | ||
d2434ab7 | 10227 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10228 | struct drm_display_mode *mode, |
51fd371b RC |
10229 | struct intel_load_detect_pipe *old, |
10230 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10231 | { |
10232 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10233 | struct intel_encoder *intel_encoder = |
10234 | intel_attached_encoder(connector); | |
79e53945 | 10235 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10236 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10237 | struct drm_crtc *crtc = NULL; |
10238 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10239 | struct drm_framebuffer *fb; |
51fd371b | 10240 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10241 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10242 | struct drm_connector_state *connector_state; |
4be07317 | 10243 | struct intel_crtc_state *crtc_state; |
51fd371b | 10244 | int ret, i = -1; |
79e53945 | 10245 | |
d2dff872 | 10246 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10247 | connector->base.id, connector->name, |
8e329a03 | 10248 | encoder->base.id, encoder->name); |
d2dff872 | 10249 | |
51fd371b RC |
10250 | retry: |
10251 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10252 | if (ret) | |
ad3c558f | 10253 | goto fail; |
6e9f798d | 10254 | |
79e53945 JB |
10255 | /* |
10256 | * Algorithm gets a little messy: | |
7a5e4805 | 10257 | * |
79e53945 JB |
10258 | * - if the connector already has an assigned crtc, use it (but make |
10259 | * sure it's on first) | |
7a5e4805 | 10260 | * |
79e53945 JB |
10261 | * - try to find the first unused crtc that can drive this connector, |
10262 | * and use that if we find one | |
79e53945 JB |
10263 | */ |
10264 | ||
10265 | /* See if we already have a CRTC for this connector */ | |
10266 | if (encoder->crtc) { | |
10267 | crtc = encoder->crtc; | |
8261b191 | 10268 | |
51fd371b | 10269 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10270 | if (ret) |
ad3c558f | 10271 | goto fail; |
4d02e2de | 10272 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
51fd371b | 10273 | if (ret) |
ad3c558f | 10274 | goto fail; |
7b24056b | 10275 | |
24218aac | 10276 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10277 | old->load_detect_temp = false; |
10278 | ||
10279 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10280 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10281 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10282 | |
7173188d | 10283 | return true; |
79e53945 JB |
10284 | } |
10285 | ||
10286 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10287 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10288 | i++; |
10289 | if (!(encoder->possible_crtcs & (1 << i))) | |
10290 | continue; | |
83d65738 | 10291 | if (possible_crtc->state->enable) |
a459249c | 10292 | continue; |
a459249c VS |
10293 | |
10294 | crtc = possible_crtc; | |
10295 | break; | |
79e53945 JB |
10296 | } |
10297 | ||
10298 | /* | |
10299 | * If we didn't find an unused CRTC, don't use any. | |
10300 | */ | |
10301 | if (!crtc) { | |
7173188d | 10302 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10303 | goto fail; |
79e53945 JB |
10304 | } |
10305 | ||
51fd371b RC |
10306 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10307 | if (ret) | |
ad3c558f | 10308 | goto fail; |
4d02e2de DV |
10309 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10310 | if (ret) | |
ad3c558f | 10311 | goto fail; |
79e53945 JB |
10312 | |
10313 | intel_crtc = to_intel_crtc(crtc); | |
24218aac | 10314 | old->dpms_mode = connector->dpms; |
8261b191 | 10315 | old->load_detect_temp = true; |
d2dff872 | 10316 | old->release_fb = NULL; |
79e53945 | 10317 | |
83a57153 ACO |
10318 | state = drm_atomic_state_alloc(dev); |
10319 | if (!state) | |
10320 | return false; | |
10321 | ||
10322 | state->acquire_ctx = ctx; | |
10323 | ||
944b0c76 ACO |
10324 | connector_state = drm_atomic_get_connector_state(state, connector); |
10325 | if (IS_ERR(connector_state)) { | |
10326 | ret = PTR_ERR(connector_state); | |
10327 | goto fail; | |
10328 | } | |
10329 | ||
10330 | connector_state->crtc = crtc; | |
10331 | connector_state->best_encoder = &intel_encoder->base; | |
10332 | ||
4be07317 ACO |
10333 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10334 | if (IS_ERR(crtc_state)) { | |
10335 | ret = PTR_ERR(crtc_state); | |
10336 | goto fail; | |
10337 | } | |
10338 | ||
49d6fa21 | 10339 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10340 | |
6492711d CW |
10341 | if (!mode) |
10342 | mode = &load_detect_mode; | |
79e53945 | 10343 | |
d2dff872 CW |
10344 | /* We need a framebuffer large enough to accommodate all accesses |
10345 | * that the plane may generate whilst we perform load detection. | |
10346 | * We can not rely on the fbcon either being present (we get called | |
10347 | * during its initialisation to detect all boot displays, or it may | |
10348 | * not even exist) or that it is large enough to satisfy the | |
10349 | * requested mode. | |
10350 | */ | |
94352cf9 DV |
10351 | fb = mode_fits_in_fbdev(dev, mode); |
10352 | if (fb == NULL) { | |
d2dff872 | 10353 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10354 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10355 | old->release_fb = fb; | |
d2dff872 CW |
10356 | } else |
10357 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10358 | if (IS_ERR(fb)) { |
d2dff872 | 10359 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10360 | goto fail; |
79e53945 | 10361 | } |
79e53945 | 10362 | |
d3a40d1b ACO |
10363 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10364 | if (ret) | |
10365 | goto fail; | |
10366 | ||
8c7b5ccb ACO |
10367 | drm_mode_copy(&crtc_state->base.mode, mode); |
10368 | ||
74c090b1 | 10369 | if (drm_atomic_commit(state)) { |
6492711d | 10370 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10371 | if (old->release_fb) |
10372 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10373 | goto fail; |
79e53945 | 10374 | } |
9128b040 | 10375 | crtc->primary->crtc = crtc; |
7173188d | 10376 | |
79e53945 | 10377 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10378 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10379 | return true; |
412b61d8 | 10380 | |
ad3c558f | 10381 | fail: |
e5d958ef ACO |
10382 | drm_atomic_state_free(state); |
10383 | state = NULL; | |
83a57153 | 10384 | |
51fd371b RC |
10385 | if (ret == -EDEADLK) { |
10386 | drm_modeset_backoff(ctx); | |
10387 | goto retry; | |
10388 | } | |
10389 | ||
412b61d8 | 10390 | return false; |
79e53945 JB |
10391 | } |
10392 | ||
d2434ab7 | 10393 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10394 | struct intel_load_detect_pipe *old, |
10395 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10396 | { |
83a57153 | 10397 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10398 | struct intel_encoder *intel_encoder = |
10399 | intel_attached_encoder(connector); | |
4ef69c7a | 10400 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10401 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10402 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10403 | struct drm_atomic_state *state; |
944b0c76 | 10404 | struct drm_connector_state *connector_state; |
4be07317 | 10405 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10406 | int ret; |
79e53945 | 10407 | |
d2dff872 | 10408 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10409 | connector->base.id, connector->name, |
8e329a03 | 10410 | encoder->base.id, encoder->name); |
d2dff872 | 10411 | |
8261b191 | 10412 | if (old->load_detect_temp) { |
83a57153 | 10413 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10414 | if (!state) |
10415 | goto fail; | |
83a57153 ACO |
10416 | |
10417 | state->acquire_ctx = ctx; | |
10418 | ||
944b0c76 ACO |
10419 | connector_state = drm_atomic_get_connector_state(state, connector); |
10420 | if (IS_ERR(connector_state)) | |
10421 | goto fail; | |
10422 | ||
4be07317 ACO |
10423 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10424 | if (IS_ERR(crtc_state)) | |
10425 | goto fail; | |
10426 | ||
944b0c76 ACO |
10427 | connector_state->best_encoder = NULL; |
10428 | connector_state->crtc = NULL; | |
10429 | ||
49d6fa21 | 10430 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10431 | |
d3a40d1b ACO |
10432 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10433 | 0, 0); | |
10434 | if (ret) | |
10435 | goto fail; | |
10436 | ||
74c090b1 | 10437 | ret = drm_atomic_commit(state); |
2bfb4627 ACO |
10438 | if (ret) |
10439 | goto fail; | |
d2dff872 | 10440 | |
36206361 DV |
10441 | if (old->release_fb) { |
10442 | drm_framebuffer_unregister_private(old->release_fb); | |
10443 | drm_framebuffer_unreference(old->release_fb); | |
10444 | } | |
d2dff872 | 10445 | |
0622a53c | 10446 | return; |
79e53945 JB |
10447 | } |
10448 | ||
c751ce4f | 10449 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10450 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10451 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10452 | |
10453 | return; | |
10454 | fail: | |
10455 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10456 | drm_atomic_state_free(state); | |
79e53945 JB |
10457 | } |
10458 | ||
da4a1efa | 10459 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10460 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10461 | { |
10462 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10463 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10464 | ||
10465 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10466 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10467 | else if (HAS_PCH_SPLIT(dev)) |
10468 | return 120000; | |
10469 | else if (!IS_GEN2(dev)) | |
10470 | return 96000; | |
10471 | else | |
10472 | return 48000; | |
10473 | } | |
10474 | ||
79e53945 | 10475 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10476 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10477 | struct intel_crtc_state *pipe_config) |
79e53945 | 10478 | { |
f1f644dc | 10479 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10480 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10481 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10482 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10483 | u32 fp; |
10484 | intel_clock_t clock; | |
dccbea3b | 10485 | int port_clock; |
da4a1efa | 10486 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10487 | |
10488 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10489 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10490 | else |
293623f7 | 10491 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10492 | |
10493 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10494 | if (IS_PINEVIEW(dev)) { |
10495 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10496 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10497 | } else { |
10498 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10499 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10500 | } | |
10501 | ||
a6c45cf0 | 10502 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10503 | if (IS_PINEVIEW(dev)) |
10504 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10505 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10506 | else |
10507 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10508 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10509 | ||
10510 | switch (dpll & DPLL_MODE_MASK) { | |
10511 | case DPLLB_MODE_DAC_SERIAL: | |
10512 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10513 | 5 : 10; | |
10514 | break; | |
10515 | case DPLLB_MODE_LVDS: | |
10516 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10517 | 7 : 14; | |
10518 | break; | |
10519 | default: | |
28c97730 | 10520 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10521 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10522 | return; |
79e53945 JB |
10523 | } |
10524 | ||
ac58c3f0 | 10525 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10526 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10527 | else |
dccbea3b | 10528 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10529 | } else { |
0fb58223 | 10530 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10531 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10532 | |
10533 | if (is_lvds) { | |
10534 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10535 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10536 | |
10537 | if (lvds & LVDS_CLKB_POWER_UP) | |
10538 | clock.p2 = 7; | |
10539 | else | |
10540 | clock.p2 = 14; | |
79e53945 JB |
10541 | } else { |
10542 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10543 | clock.p1 = 2; | |
10544 | else { | |
10545 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10546 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10547 | } | |
10548 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10549 | clock.p2 = 4; | |
10550 | else | |
10551 | clock.p2 = 2; | |
79e53945 | 10552 | } |
da4a1efa | 10553 | |
dccbea3b | 10554 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10555 | } |
10556 | ||
18442d08 VS |
10557 | /* |
10558 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10559 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10560 | * encoder's get_config() function. |
10561 | */ | |
dccbea3b | 10562 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10563 | } |
10564 | ||
6878da05 VS |
10565 | int intel_dotclock_calculate(int link_freq, |
10566 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10567 | { |
f1f644dc JB |
10568 | /* |
10569 | * The calculation for the data clock is: | |
1041a02f | 10570 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10571 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10572 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10573 | * |
10574 | * and the link clock is simpler: | |
1041a02f | 10575 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10576 | */ |
10577 | ||
6878da05 VS |
10578 | if (!m_n->link_n) |
10579 | return 0; | |
f1f644dc | 10580 | |
6878da05 VS |
10581 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10582 | } | |
f1f644dc | 10583 | |
18442d08 | 10584 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10585 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10586 | { |
10587 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10588 | |
18442d08 VS |
10589 | /* read out port_clock from the DPLL */ |
10590 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10591 | |
f1f644dc | 10592 | /* |
18442d08 | 10593 | * This value does not include pixel_multiplier. |
241bfc38 | 10594 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10595 | * agree once we know their relationship in the encoder's |
10596 | * get_config() function. | |
79e53945 | 10597 | */ |
2d112de7 | 10598 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10599 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10600 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10601 | } |
10602 | ||
10603 | /** Returns the currently programmed mode of the given pipe. */ | |
10604 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10605 | struct drm_crtc *crtc) | |
10606 | { | |
548f245b | 10607 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10608 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10609 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10610 | struct drm_display_mode *mode; |
5cec258b | 10611 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10612 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10613 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10614 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10615 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10616 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10617 | |
10618 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10619 | if (!mode) | |
10620 | return NULL; | |
10621 | ||
f1f644dc JB |
10622 | /* |
10623 | * Construct a pipe_config sufficient for getting the clock info | |
10624 | * back out of crtc_clock_get. | |
10625 | * | |
10626 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10627 | * to use a real value here instead. | |
10628 | */ | |
293623f7 | 10629 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10630 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10631 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10632 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10633 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10634 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10635 | ||
773ae034 | 10636 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10637 | mode->hdisplay = (htot & 0xffff) + 1; |
10638 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10639 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10640 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10641 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10642 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10643 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10644 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10645 | ||
10646 | drm_mode_set_name(mode); | |
79e53945 JB |
10647 | |
10648 | return mode; | |
10649 | } | |
10650 | ||
f047e395 CW |
10651 | void intel_mark_busy(struct drm_device *dev) |
10652 | { | |
c67a470b PZ |
10653 | struct drm_i915_private *dev_priv = dev->dev_private; |
10654 | ||
f62a0076 CW |
10655 | if (dev_priv->mm.busy) |
10656 | return; | |
10657 | ||
43694d69 | 10658 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10659 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10660 | if (INTEL_INFO(dev)->gen >= 6) |
10661 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10662 | dev_priv->mm.busy = true; |
f047e395 CW |
10663 | } |
10664 | ||
10665 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10666 | { |
c67a470b | 10667 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10668 | |
f62a0076 CW |
10669 | if (!dev_priv->mm.busy) |
10670 | return; | |
10671 | ||
10672 | dev_priv->mm.busy = false; | |
10673 | ||
3d13ef2e | 10674 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10675 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10676 | |
43694d69 | 10677 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10678 | } |
10679 | ||
79e53945 JB |
10680 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10681 | { | |
10682 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10683 | struct drm_device *dev = crtc->dev; |
10684 | struct intel_unpin_work *work; | |
67e77c5a | 10685 | |
5e2d7afc | 10686 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10687 | work = intel_crtc->unpin_work; |
10688 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10689 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10690 | |
10691 | if (work) { | |
10692 | cancel_work_sync(&work->work); | |
10693 | kfree(work); | |
10694 | } | |
79e53945 JB |
10695 | |
10696 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10697 | |
79e53945 JB |
10698 | kfree(intel_crtc); |
10699 | } | |
10700 | ||
6b95a207 KH |
10701 | static void intel_unpin_work_fn(struct work_struct *__work) |
10702 | { | |
10703 | struct intel_unpin_work *work = | |
10704 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10705 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10706 | struct drm_device *dev = crtc->base.dev; | |
10707 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10708 | |
b4a98e57 | 10709 | mutex_lock(&dev->struct_mutex); |
a9ff8714 | 10710 | intel_unpin_fb_obj(work->old_fb, primary->state); |
05394f39 | 10711 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10712 | |
f06cc1b9 | 10713 | if (work->flip_queued_req) |
146d84f0 | 10714 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10715 | mutex_unlock(&dev->struct_mutex); |
10716 | ||
a9ff8714 | 10717 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
89ed88ba | 10718 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10719 | |
a9ff8714 VS |
10720 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10721 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10722 | |
6b95a207 KH |
10723 | kfree(work); |
10724 | } | |
10725 | ||
1afe3e9d | 10726 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10727 | struct drm_crtc *crtc) |
6b95a207 | 10728 | { |
6b95a207 KH |
10729 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10730 | struct intel_unpin_work *work; | |
6b95a207 KH |
10731 | unsigned long flags; |
10732 | ||
10733 | /* Ignore early vblank irqs */ | |
10734 | if (intel_crtc == NULL) | |
10735 | return; | |
10736 | ||
f326038a DV |
10737 | /* |
10738 | * This is called both by irq handlers and the reset code (to complete | |
10739 | * lost pageflips) so needs the full irqsave spinlocks. | |
10740 | */ | |
6b95a207 KH |
10741 | spin_lock_irqsave(&dev->event_lock, flags); |
10742 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10743 | |
10744 | /* Ensure we don't miss a work->pending update ... */ | |
10745 | smp_rmb(); | |
10746 | ||
10747 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10748 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10749 | return; | |
10750 | } | |
10751 | ||
d6bbafa1 | 10752 | page_flip_completed(intel_crtc); |
0af7e4df | 10753 | |
6b95a207 | 10754 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10755 | } |
10756 | ||
1afe3e9d JB |
10757 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10758 | { | |
fbee40df | 10759 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10760 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10761 | ||
49b14a5c | 10762 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10763 | } |
10764 | ||
10765 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10766 | { | |
fbee40df | 10767 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10768 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10769 | ||
49b14a5c | 10770 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10771 | } |
10772 | ||
75f7f3ec VS |
10773 | /* Is 'a' after or equal to 'b'? */ |
10774 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10775 | { | |
10776 | return !((a - b) & 0x80000000); | |
10777 | } | |
10778 | ||
10779 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10780 | { | |
10781 | struct drm_device *dev = crtc->base.dev; | |
10782 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10783 | ||
bdfa7542 VS |
10784 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10785 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10786 | return true; | |
10787 | ||
75f7f3ec VS |
10788 | /* |
10789 | * The relevant registers doen't exist on pre-ctg. | |
10790 | * As the flip done interrupt doesn't trigger for mmio | |
10791 | * flips on gmch platforms, a flip count check isn't | |
10792 | * really needed there. But since ctg has the registers, | |
10793 | * include it in the check anyway. | |
10794 | */ | |
10795 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10796 | return true; | |
10797 | ||
10798 | /* | |
10799 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10800 | * used the same base address. In that case the mmio flip might | |
10801 | * have completed, but the CS hasn't even executed the flip yet. | |
10802 | * | |
10803 | * A flip count check isn't enough as the CS might have updated | |
10804 | * the base address just after start of vblank, but before we | |
10805 | * managed to process the interrupt. This means we'd complete the | |
10806 | * CS flip too soon. | |
10807 | * | |
10808 | * Combining both checks should get us a good enough result. It may | |
10809 | * still happen that the CS flip has been executed, but has not | |
10810 | * yet actually completed. But in case the base address is the same | |
10811 | * anyway, we don't really care. | |
10812 | */ | |
10813 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10814 | crtc->unpin_work->gtt_offset && | |
fd8f507c | 10815 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
75f7f3ec VS |
10816 | crtc->unpin_work->flip_count); |
10817 | } | |
10818 | ||
6b95a207 KH |
10819 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10820 | { | |
fbee40df | 10821 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10822 | struct intel_crtc *intel_crtc = |
10823 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10824 | unsigned long flags; | |
10825 | ||
f326038a DV |
10826 | |
10827 | /* | |
10828 | * This is called both by irq handlers and the reset code (to complete | |
10829 | * lost pageflips) so needs the full irqsave spinlocks. | |
10830 | * | |
10831 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10832 | * generate a page-flip completion irq, i.e. every modeset |
10833 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10834 | */ | |
6b95a207 | 10835 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10836 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10837 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10838 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10839 | } | |
10840 | ||
6042639c | 10841 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
e7d841ca CW |
10842 | { |
10843 | /* Ensure that the work item is consistent when activating it ... */ | |
10844 | smp_wmb(); | |
6042639c | 10845 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
e7d841ca CW |
10846 | /* and that it is marked active as soon as the irq could fire. */ |
10847 | smp_wmb(); | |
10848 | } | |
10849 | ||
8c9f3aaf JB |
10850 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10851 | struct drm_crtc *crtc, | |
10852 | struct drm_framebuffer *fb, | |
ed8d1975 | 10853 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10854 | struct drm_i915_gem_request *req, |
ed8d1975 | 10855 | uint32_t flags) |
8c9f3aaf | 10856 | { |
6258fbe2 | 10857 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10858 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10859 | u32 flip_mask; |
10860 | int ret; | |
10861 | ||
5fb9de1a | 10862 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10863 | if (ret) |
4fa62c89 | 10864 | return ret; |
8c9f3aaf JB |
10865 | |
10866 | /* Can't queue multiple flips, so wait for the previous | |
10867 | * one to finish before executing the next. | |
10868 | */ | |
10869 | if (intel_crtc->plane) | |
10870 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10871 | else | |
10872 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10873 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10874 | intel_ring_emit(ring, MI_NOOP); | |
10875 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10876 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10877 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10878 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10879 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca | 10880 | |
6042639c | 10881 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10882 | return 0; |
8c9f3aaf JB |
10883 | } |
10884 | ||
10885 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10886 | struct drm_crtc *crtc, | |
10887 | struct drm_framebuffer *fb, | |
ed8d1975 | 10888 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10889 | struct drm_i915_gem_request *req, |
ed8d1975 | 10890 | uint32_t flags) |
8c9f3aaf | 10891 | { |
6258fbe2 | 10892 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10893 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10894 | u32 flip_mask; |
10895 | int ret; | |
10896 | ||
5fb9de1a | 10897 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10898 | if (ret) |
4fa62c89 | 10899 | return ret; |
8c9f3aaf JB |
10900 | |
10901 | if (intel_crtc->plane) | |
10902 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10903 | else | |
10904 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10905 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10906 | intel_ring_emit(ring, MI_NOOP); | |
10907 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
10908 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10909 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10910 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
10911 | intel_ring_emit(ring, MI_NOOP); |
10912 | ||
6042639c | 10913 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10914 | return 0; |
8c9f3aaf JB |
10915 | } |
10916 | ||
10917 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
10918 | struct drm_crtc *crtc, | |
10919 | struct drm_framebuffer *fb, | |
ed8d1975 | 10920 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10921 | struct drm_i915_gem_request *req, |
ed8d1975 | 10922 | uint32_t flags) |
8c9f3aaf | 10923 | { |
6258fbe2 | 10924 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10925 | struct drm_i915_private *dev_priv = dev->dev_private; |
10926 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10927 | uint32_t pf, pipesrc; | |
10928 | int ret; | |
10929 | ||
5fb9de1a | 10930 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10931 | if (ret) |
4fa62c89 | 10932 | return ret; |
8c9f3aaf JB |
10933 | |
10934 | /* i965+ uses the linear or tiled offsets from the | |
10935 | * Display Registers (which do not change across a page-flip) | |
10936 | * so we need only reprogram the base address. | |
10937 | */ | |
6d90c952 DV |
10938 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10939 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10940 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10941 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 10942 | obj->tiling_mode); |
8c9f3aaf JB |
10943 | |
10944 | /* XXX Enabling the panel-fitter across page-flip is so far | |
10945 | * untested on non-native modes, so ignore it for now. | |
10946 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
10947 | */ | |
10948 | pf = 0; | |
10949 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 10950 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 10951 | |
6042639c | 10952 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10953 | return 0; |
8c9f3aaf JB |
10954 | } |
10955 | ||
10956 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
10957 | struct drm_crtc *crtc, | |
10958 | struct drm_framebuffer *fb, | |
ed8d1975 | 10959 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10960 | struct drm_i915_gem_request *req, |
ed8d1975 | 10961 | uint32_t flags) |
8c9f3aaf | 10962 | { |
6258fbe2 | 10963 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10964 | struct drm_i915_private *dev_priv = dev->dev_private; |
10965 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10966 | uint32_t pf, pipesrc; | |
10967 | int ret; | |
10968 | ||
5fb9de1a | 10969 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10970 | if (ret) |
4fa62c89 | 10971 | return ret; |
8c9f3aaf | 10972 | |
6d90c952 DV |
10973 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10974 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10975 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 10976 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 10977 | |
dc257cf1 DV |
10978 | /* Contrary to the suggestions in the documentation, |
10979 | * "Enable Panel Fitter" does not seem to be required when page | |
10980 | * flipping with a non-native mode, and worse causes a normal | |
10981 | * modeset to fail. | |
10982 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
10983 | */ | |
10984 | pf = 0; | |
8c9f3aaf | 10985 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 10986 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 10987 | |
6042639c | 10988 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10989 | return 0; |
8c9f3aaf JB |
10990 | } |
10991 | ||
7c9017e5 JB |
10992 | static int intel_gen7_queue_flip(struct drm_device *dev, |
10993 | struct drm_crtc *crtc, | |
10994 | struct drm_framebuffer *fb, | |
ed8d1975 | 10995 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10996 | struct drm_i915_gem_request *req, |
ed8d1975 | 10997 | uint32_t flags) |
7c9017e5 | 10998 | { |
6258fbe2 | 10999 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 11000 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 11001 | uint32_t plane_bit = 0; |
ffe74d75 CW |
11002 | int len, ret; |
11003 | ||
eba905b2 | 11004 | switch (intel_crtc->plane) { |
cb05d8de DV |
11005 | case PLANE_A: |
11006 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11007 | break; | |
11008 | case PLANE_B: | |
11009 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11010 | break; | |
11011 | case PLANE_C: | |
11012 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11013 | break; | |
11014 | default: | |
11015 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11016 | return -ENODEV; |
cb05d8de DV |
11017 | } |
11018 | ||
ffe74d75 | 11019 | len = 4; |
f476828a | 11020 | if (ring->id == RCS) { |
ffe74d75 | 11021 | len += 6; |
f476828a DL |
11022 | /* |
11023 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11024 | * 48bits addresses, and we need a NOOP for the batch size to | |
11025 | * stay even. | |
11026 | */ | |
11027 | if (IS_GEN8(dev)) | |
11028 | len += 2; | |
11029 | } | |
ffe74d75 | 11030 | |
f66fab8e VS |
11031 | /* |
11032 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11033 | * "The full packet must be contained within the same cache line." | |
11034 | * | |
11035 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11036 | * cacheline, if we ever start emitting more commands before | |
11037 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11038 | * then do the cacheline alignment, and finally emit the | |
11039 | * MI_DISPLAY_FLIP. | |
11040 | */ | |
bba09b12 | 11041 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 11042 | if (ret) |
4fa62c89 | 11043 | return ret; |
f66fab8e | 11044 | |
5fb9de1a | 11045 | ret = intel_ring_begin(req, len); |
7c9017e5 | 11046 | if (ret) |
4fa62c89 | 11047 | return ret; |
7c9017e5 | 11048 | |
ffe74d75 CW |
11049 | /* Unmask the flip-done completion message. Note that the bspec says that |
11050 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11051 | * more than one flip event at any time (or ensure that one flip message | |
11052 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11053 | * Experimentation says that BCS works despite DERRMR masking all | |
11054 | * flip-done completion events and that unmasking all planes at once | |
11055 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11056 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11057 | */ | |
11058 | if (ring->id == RCS) { | |
11059 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11060 | intel_ring_emit(ring, DERRMR); | |
11061 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11062 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11063 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11064 | if (IS_GEN8(dev)) |
f1afe24f | 11065 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11066 | MI_SRM_LRM_GLOBAL_GTT); |
11067 | else | |
f1afe24f | 11068 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11069 | MI_SRM_LRM_GLOBAL_GTT); |
ffe74d75 CW |
11070 | intel_ring_emit(ring, DERRMR); |
11071 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
11072 | if (IS_GEN8(dev)) { |
11073 | intel_ring_emit(ring, 0); | |
11074 | intel_ring_emit(ring, MI_NOOP); | |
11075 | } | |
ffe74d75 CW |
11076 | } |
11077 | ||
cb05d8de | 11078 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11079 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11080 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11081 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca | 11082 | |
6042639c | 11083 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11084 | return 0; |
7c9017e5 JB |
11085 | } |
11086 | ||
84c33a64 SG |
11087 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11088 | struct drm_i915_gem_object *obj) | |
11089 | { | |
11090 | /* | |
11091 | * This is not being used for older platforms, because | |
11092 | * non-availability of flip done interrupt forces us to use | |
11093 | * CS flips. Older platforms derive flip done using some clever | |
11094 | * tricks involving the flip_pending status bits and vblank irqs. | |
11095 | * So using MMIO flips there would disrupt this mechanism. | |
11096 | */ | |
11097 | ||
8e09bf83 CW |
11098 | if (ring == NULL) |
11099 | return true; | |
11100 | ||
84c33a64 SG |
11101 | if (INTEL_INFO(ring->dev)->gen < 5) |
11102 | return false; | |
11103 | ||
11104 | if (i915.use_mmio_flip < 0) | |
11105 | return false; | |
11106 | else if (i915.use_mmio_flip > 0) | |
11107 | return true; | |
14bf993e OM |
11108 | else if (i915.enable_execlists) |
11109 | return true; | |
84c33a64 | 11110 | else |
b4716185 | 11111 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11112 | } |
11113 | ||
6042639c | 11114 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
86efe24a | 11115 | unsigned int rotation, |
6042639c | 11116 | struct intel_unpin_work *work) |
ff944564 DL |
11117 | { |
11118 | struct drm_device *dev = intel_crtc->base.dev; | |
11119 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11120 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 | 11121 | const enum pipe pipe = intel_crtc->pipe; |
86efe24a | 11122 | u32 ctl, stride, tile_height; |
ff944564 DL |
11123 | |
11124 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11125 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11126 | switch (fb->modifier[0]) { |
11127 | case DRM_FORMAT_MOD_NONE: | |
11128 | break; | |
11129 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11130 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11131 | break; |
11132 | case I915_FORMAT_MOD_Y_TILED: | |
11133 | ctl |= PLANE_CTL_TILED_Y; | |
11134 | break; | |
11135 | case I915_FORMAT_MOD_Yf_TILED: | |
11136 | ctl |= PLANE_CTL_TILED_YF; | |
11137 | break; | |
11138 | default: | |
11139 | MISSING_CASE(fb->modifier[0]); | |
11140 | } | |
ff944564 DL |
11141 | |
11142 | /* | |
11143 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11144 | * linear buffers or in number of tiles for tiled buffers. | |
11145 | */ | |
86efe24a TU |
11146 | if (intel_rotation_90_or_270(rotation)) { |
11147 | /* stride = Surface height in tiles */ | |
11148 | tile_height = intel_tile_height(dev, fb->pixel_format, | |
11149 | fb->modifier[0], 0); | |
11150 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11151 | } else { | |
11152 | stride = fb->pitches[0] / | |
11153 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11154 | fb->pixel_format); | |
11155 | } | |
ff944564 DL |
11156 | |
11157 | /* | |
11158 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11159 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11160 | */ | |
11161 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11162 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11163 | ||
6042639c | 11164 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
ff944564 DL |
11165 | POSTING_READ(PLANE_SURF(pipe, 0)); |
11166 | } | |
11167 | ||
6042639c CW |
11168 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
11169 | struct intel_unpin_work *work) | |
84c33a64 SG |
11170 | { |
11171 | struct drm_device *dev = intel_crtc->base.dev; | |
11172 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11173 | struct intel_framebuffer *intel_fb = | |
11174 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11175 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11176 | u32 dspcntr; | |
11177 | u32 reg; | |
11178 | ||
84c33a64 SG |
11179 | reg = DSPCNTR(intel_crtc->plane); |
11180 | dspcntr = I915_READ(reg); | |
11181 | ||
c5d97472 DL |
11182 | if (obj->tiling_mode != I915_TILING_NONE) |
11183 | dspcntr |= DISPPLANE_TILED; | |
11184 | else | |
11185 | dspcntr &= ~DISPPLANE_TILED; | |
11186 | ||
84c33a64 SG |
11187 | I915_WRITE(reg, dspcntr); |
11188 | ||
6042639c | 11189 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
84c33a64 | 11190 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
ff944564 DL |
11191 | } |
11192 | ||
11193 | /* | |
11194 | * XXX: This is the temporary way to update the plane registers until we get | |
11195 | * around to using the usual plane update functions for MMIO flips | |
11196 | */ | |
6042639c | 11197 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
ff944564 | 11198 | { |
6042639c CW |
11199 | struct intel_crtc *crtc = mmio_flip->crtc; |
11200 | struct intel_unpin_work *work; | |
11201 | ||
11202 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11203 | work = crtc->unpin_work; | |
11204 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11205 | if (work == NULL) | |
11206 | return; | |
ff944564 | 11207 | |
6042639c | 11208 | intel_mark_page_flip_active(work); |
ff944564 | 11209 | |
6042639c | 11210 | intel_pipe_update_start(crtc); |
ff944564 | 11211 | |
6042639c | 11212 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
86efe24a | 11213 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
ff944564 DL |
11214 | else |
11215 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
6042639c | 11216 | ilk_do_mmio_flip(crtc, work); |
ff944564 | 11217 | |
6042639c | 11218 | intel_pipe_update_end(crtc); |
84c33a64 SG |
11219 | } |
11220 | ||
9362c7c5 | 11221 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11222 | { |
b2cfe0ab CW |
11223 | struct intel_mmio_flip *mmio_flip = |
11224 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11225 | |
6042639c | 11226 | if (mmio_flip->req) { |
eed29a5b | 11227 | WARN_ON(__i915_wait_request(mmio_flip->req, |
b2cfe0ab | 11228 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11229 | false, NULL, |
11230 | &mmio_flip->i915->rps.mmioflips)); | |
6042639c CW |
11231 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
11232 | } | |
84c33a64 | 11233 | |
6042639c | 11234 | intel_do_mmio_flip(mmio_flip); |
b2cfe0ab | 11235 | kfree(mmio_flip); |
84c33a64 SG |
11236 | } |
11237 | ||
11238 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11239 | struct drm_crtc *crtc, | |
86efe24a | 11240 | struct drm_i915_gem_object *obj) |
84c33a64 | 11241 | { |
b2cfe0ab CW |
11242 | struct intel_mmio_flip *mmio_flip; |
11243 | ||
11244 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11245 | if (mmio_flip == NULL) | |
11246 | return -ENOMEM; | |
84c33a64 | 11247 | |
bcafc4e3 | 11248 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11249 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11250 | mmio_flip->crtc = to_intel_crtc(crtc); |
86efe24a | 11251 | mmio_flip->rotation = crtc->primary->state->rotation; |
536f5b5e | 11252 | |
b2cfe0ab CW |
11253 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11254 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11255 | |
84c33a64 SG |
11256 | return 0; |
11257 | } | |
11258 | ||
8c9f3aaf JB |
11259 | static int intel_default_queue_flip(struct drm_device *dev, |
11260 | struct drm_crtc *crtc, | |
11261 | struct drm_framebuffer *fb, | |
ed8d1975 | 11262 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11263 | struct drm_i915_gem_request *req, |
ed8d1975 | 11264 | uint32_t flags) |
8c9f3aaf JB |
11265 | { |
11266 | return -ENODEV; | |
11267 | } | |
11268 | ||
d6bbafa1 CW |
11269 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11270 | struct drm_crtc *crtc) | |
11271 | { | |
11272 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11273 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11274 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11275 | u32 addr; | |
11276 | ||
11277 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11278 | return true; | |
11279 | ||
908565c2 CW |
11280 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11281 | return false; | |
11282 | ||
d6bbafa1 CW |
11283 | if (!work->enable_stall_check) |
11284 | return false; | |
11285 | ||
11286 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11287 | if (work->flip_queued_req && |
11288 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11289 | return false; |
11290 | ||
1e3feefd | 11291 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11292 | } |
11293 | ||
1e3feefd | 11294 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11295 | return false; |
11296 | ||
11297 | /* Potential stall - if we see that the flip has happened, | |
11298 | * assume a missed interrupt. */ | |
11299 | if (INTEL_INFO(dev)->gen >= 4) | |
11300 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11301 | else | |
11302 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11303 | ||
11304 | /* There is a potential issue here with a false positive after a flip | |
11305 | * to the same address. We could address this by checking for a | |
11306 | * non-incrementing frame counter. | |
11307 | */ | |
11308 | return addr == work->gtt_offset; | |
11309 | } | |
11310 | ||
11311 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11312 | { | |
11313 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11314 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11315 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11316 | struct intel_unpin_work *work; |
f326038a | 11317 | |
6c51d46f | 11318 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11319 | |
11320 | if (crtc == NULL) | |
11321 | return; | |
11322 | ||
f326038a | 11323 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11324 | work = intel_crtc->unpin_work; |
11325 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11326 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11327 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11328 | page_flip_completed(intel_crtc); |
6ad790c0 | 11329 | work = NULL; |
d6bbafa1 | 11330 | } |
6ad790c0 CW |
11331 | if (work != NULL && |
11332 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11333 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11334 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11335 | } |
11336 | ||
6b95a207 KH |
11337 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11338 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11339 | struct drm_pending_vblank_event *event, |
11340 | uint32_t page_flip_flags) | |
6b95a207 KH |
11341 | { |
11342 | struct drm_device *dev = crtc->dev; | |
11343 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11344 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11345 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11346 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11347 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11348 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11349 | struct intel_unpin_work *work; |
a4872ba6 | 11350 | struct intel_engine_cs *ring; |
cf5d8a46 | 11351 | bool mmio_flip; |
91af127f | 11352 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11353 | int ret; |
6b95a207 | 11354 | |
2ff8fde1 MR |
11355 | /* |
11356 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11357 | * check to be safe. In the future we may enable pageflipping from | |
11358 | * a disabled primary plane. | |
11359 | */ | |
11360 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11361 | return -EBUSY; | |
11362 | ||
e6a595d2 | 11363 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11364 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11365 | return -EINVAL; |
11366 | ||
11367 | /* | |
11368 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11369 | * Note that pitch changes could also affect these register. | |
11370 | */ | |
11371 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11372 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11373 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11374 | return -EINVAL; |
11375 | ||
f900db47 CW |
11376 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11377 | goto out_hang; | |
11378 | ||
b14c5679 | 11379 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11380 | if (work == NULL) |
11381 | return -ENOMEM; | |
11382 | ||
6b95a207 | 11383 | work->event = event; |
b4a98e57 | 11384 | work->crtc = crtc; |
ab8d6675 | 11385 | work->old_fb = old_fb; |
6b95a207 KH |
11386 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11387 | ||
87b6b101 | 11388 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11389 | if (ret) |
11390 | goto free_work; | |
11391 | ||
6b95a207 | 11392 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11393 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11394 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11395 | /* Before declaring the flip queue wedged, check if |
11396 | * the hardware completed the operation behind our backs. | |
11397 | */ | |
11398 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11399 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11400 | page_flip_completed(intel_crtc); | |
11401 | } else { | |
11402 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11403 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11404 | |
d6bbafa1 CW |
11405 | drm_crtc_vblank_put(crtc); |
11406 | kfree(work); | |
11407 | return -EBUSY; | |
11408 | } | |
6b95a207 KH |
11409 | } |
11410 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11411 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11412 | |
b4a98e57 CW |
11413 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11414 | flush_workqueue(dev_priv->wq); | |
11415 | ||
75dfca80 | 11416 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11417 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11418 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11419 | |
f4510a27 | 11420 | crtc->primary->fb = fb; |
afd65eb4 | 11421 | update_state_fb(crtc->primary); |
1ed1f968 | 11422 | |
e1f99ce6 | 11423 | work->pending_flip_obj = obj; |
e1f99ce6 | 11424 | |
89ed88ba CW |
11425 | ret = i915_mutex_lock_interruptible(dev); |
11426 | if (ret) | |
11427 | goto cleanup; | |
11428 | ||
b4a98e57 | 11429 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11430 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11431 | |
75f7f3ec | 11432 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
fd8f507c | 11433 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
75f7f3ec | 11434 | |
4fa62c89 VS |
11435 | if (IS_VALLEYVIEW(dev)) { |
11436 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11437 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11438 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11439 | ring = NULL; | |
48bf5b2d | 11440 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11441 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11442 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11443 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11444 | if (ring == NULL || ring->id != RCS) |
11445 | ring = &dev_priv->ring[BCS]; | |
11446 | } else { | |
11447 | ring = &dev_priv->ring[RCS]; | |
11448 | } | |
11449 | ||
cf5d8a46 CW |
11450 | mmio_flip = use_mmio_flip(ring, obj); |
11451 | ||
11452 | /* When using CS flips, we want to emit semaphores between rings. | |
11453 | * However, when using mmio flips we will create a task to do the | |
11454 | * synchronisation, so all we want here is to pin the framebuffer | |
11455 | * into the display plane and skip any waits. | |
11456 | */ | |
7580d774 ML |
11457 | if (!mmio_flip) { |
11458 | ret = i915_gem_object_sync(obj, ring, &request); | |
11459 | if (ret) | |
11460 | goto cleanup_pending; | |
11461 | } | |
11462 | ||
82bc3b2d | 11463 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
7580d774 | 11464 | crtc->primary->state); |
8c9f3aaf JB |
11465 | if (ret) |
11466 | goto cleanup_pending; | |
6b95a207 | 11467 | |
dedf278c TU |
11468 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
11469 | obj, 0); | |
11470 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
4fa62c89 | 11471 | |
cf5d8a46 | 11472 | if (mmio_flip) { |
86efe24a | 11473 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
d6bbafa1 CW |
11474 | if (ret) |
11475 | goto cleanup_unpin; | |
11476 | ||
f06cc1b9 JH |
11477 | i915_gem_request_assign(&work->flip_queued_req, |
11478 | obj->last_write_req); | |
d6bbafa1 | 11479 | } else { |
6258fbe2 JH |
11480 | if (!request) { |
11481 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); | |
11482 | if (ret) | |
11483 | goto cleanup_unpin; | |
11484 | } | |
11485 | ||
11486 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11487 | page_flip_flags); |
11488 | if (ret) | |
11489 | goto cleanup_unpin; | |
11490 | ||
6258fbe2 | 11491 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11492 | } |
11493 | ||
91af127f | 11494 | if (request) |
75289874 | 11495 | i915_add_request_no_flush(request); |
91af127f | 11496 | |
1e3feefd | 11497 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11498 | work->enable_stall_check = true; |
4fa62c89 | 11499 | |
ab8d6675 | 11500 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11501 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11502 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11503 | |
4e1e26f1 | 11504 | intel_fbc_disable_crtc(intel_crtc); |
a9ff8714 VS |
11505 | intel_frontbuffer_flip_prepare(dev, |
11506 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11507 | |
e5510fac JB |
11508 | trace_i915_flip_request(intel_crtc->plane, obj); |
11509 | ||
6b95a207 | 11510 | return 0; |
96b099fd | 11511 | |
4fa62c89 | 11512 | cleanup_unpin: |
82bc3b2d | 11513 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11514 | cleanup_pending: |
91af127f JH |
11515 | if (request) |
11516 | i915_gem_request_cancel(request); | |
b4a98e57 | 11517 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11518 | mutex_unlock(&dev->struct_mutex); |
11519 | cleanup: | |
f4510a27 | 11520 | crtc->primary->fb = old_fb; |
afd65eb4 | 11521 | update_state_fb(crtc->primary); |
89ed88ba CW |
11522 | |
11523 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11524 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11525 | |
5e2d7afc | 11526 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11527 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11528 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11529 | |
87b6b101 | 11530 | drm_crtc_vblank_put(crtc); |
7317c75e | 11531 | free_work: |
96b099fd CW |
11532 | kfree(work); |
11533 | ||
f900db47 | 11534 | if (ret == -EIO) { |
02e0efb5 ML |
11535 | struct drm_atomic_state *state; |
11536 | struct drm_plane_state *plane_state; | |
11537 | ||
f900db47 | 11538 | out_hang: |
02e0efb5 ML |
11539 | state = drm_atomic_state_alloc(dev); |
11540 | if (!state) | |
11541 | return -ENOMEM; | |
11542 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11543 | ||
11544 | retry: | |
11545 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11546 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11547 | if (!ret) { | |
11548 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11549 | ||
11550 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11551 | if (!ret) | |
11552 | ret = drm_atomic_commit(state); | |
11553 | } | |
11554 | ||
11555 | if (ret == -EDEADLK) { | |
11556 | drm_modeset_backoff(state->acquire_ctx); | |
11557 | drm_atomic_state_clear(state); | |
11558 | goto retry; | |
11559 | } | |
11560 | ||
11561 | if (ret) | |
11562 | drm_atomic_state_free(state); | |
11563 | ||
f0d3dad3 | 11564 | if (ret == 0 && event) { |
5e2d7afc | 11565 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11566 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11567 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11568 | } |
f900db47 | 11569 | } |
96b099fd | 11570 | return ret; |
6b95a207 KH |
11571 | } |
11572 | ||
da20eabd ML |
11573 | |
11574 | /** | |
11575 | * intel_wm_need_update - Check whether watermarks need updating | |
11576 | * @plane: drm plane | |
11577 | * @state: new plane state | |
11578 | * | |
11579 | * Check current plane state versus the new one to determine whether | |
11580 | * watermarks need to be recalculated. | |
11581 | * | |
11582 | * Returns true or false. | |
11583 | */ | |
11584 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11585 | struct drm_plane_state *state) | |
11586 | { | |
d21fbe87 MR |
11587 | struct intel_plane_state *new = to_intel_plane_state(state); |
11588 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11589 | ||
11590 | /* Update watermarks on tiling or size changes. */ | |
da20eabd ML |
11591 | if (!plane->state->fb || !state->fb || |
11592 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
d21fbe87 MR |
11593 | plane->state->rotation != state->rotation || |
11594 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11595 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11596 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11597 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
2791a16c | 11598 | return true; |
7809e5ae | 11599 | |
2791a16c | 11600 | return false; |
7809e5ae MR |
11601 | } |
11602 | ||
d21fbe87 MR |
11603 | static bool needs_scaling(struct intel_plane_state *state) |
11604 | { | |
11605 | int src_w = drm_rect_width(&state->src) >> 16; | |
11606 | int src_h = drm_rect_height(&state->src) >> 16; | |
11607 | int dst_w = drm_rect_width(&state->dst); | |
11608 | int dst_h = drm_rect_height(&state->dst); | |
11609 | ||
11610 | return (src_w != dst_w || src_h != dst_h); | |
11611 | } | |
11612 | ||
da20eabd ML |
11613 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11614 | struct drm_plane_state *plane_state) | |
11615 | { | |
11616 | struct drm_crtc *crtc = crtc_state->crtc; | |
11617 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11618 | struct drm_plane *plane = plane_state->plane; | |
11619 | struct drm_device *dev = crtc->dev; | |
11620 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11621 | struct intel_plane_state *old_plane_state = | |
11622 | to_intel_plane_state(plane->state); | |
11623 | int idx = intel_crtc->base.base.id, ret; | |
11624 | int i = drm_plane_index(plane); | |
11625 | bool mode_changed = needs_modeset(crtc_state); | |
11626 | bool was_crtc_enabled = crtc->state->active; | |
11627 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11628 | bool turn_off, turn_on, visible, was_visible; |
11629 | struct drm_framebuffer *fb = plane_state->fb; | |
11630 | ||
11631 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11632 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11633 | ret = skl_update_scaler_plane( | |
11634 | to_intel_crtc_state(crtc_state), | |
11635 | to_intel_plane_state(plane_state)); | |
11636 | if (ret) | |
11637 | return ret; | |
11638 | } | |
11639 | ||
da20eabd ML |
11640 | was_visible = old_plane_state->visible; |
11641 | visible = to_intel_plane_state(plane_state)->visible; | |
11642 | ||
11643 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11644 | was_visible = false; | |
11645 | ||
11646 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11647 | visible = false; | |
11648 | ||
11649 | if (!was_visible && !visible) | |
11650 | return 0; | |
11651 | ||
11652 | turn_off = was_visible && (!visible || mode_changed); | |
11653 | turn_on = visible && (!was_visible || mode_changed); | |
11654 | ||
11655 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11656 | plane->base.id, fb ? fb->base.id : -1); | |
11657 | ||
11658 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11659 | plane->base.id, was_visible, visible, | |
11660 | turn_off, turn_on, mode_changed); | |
11661 | ||
852eb00d | 11662 | if (turn_on) { |
f015c551 | 11663 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d VS |
11664 | /* must disable cxsr around plane enable/disable */ |
11665 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11666 | intel_crtc->atomic.disable_cxsr = true; | |
11667 | /* to potentially re-enable cxsr */ | |
11668 | intel_crtc->atomic.wait_vblank = true; | |
11669 | intel_crtc->atomic.update_wm_post = true; | |
11670 | } | |
11671 | } else if (turn_off) { | |
f015c551 | 11672 | intel_crtc->atomic.update_wm_post = true; |
852eb00d VS |
11673 | /* must disable cxsr around plane enable/disable */ |
11674 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11675 | if (is_crtc_enabled) | |
11676 | intel_crtc->atomic.wait_vblank = true; | |
11677 | intel_crtc->atomic.disable_cxsr = true; | |
11678 | } | |
11679 | } else if (intel_wm_need_update(plane, plane_state)) { | |
f015c551 | 11680 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d | 11681 | } |
da20eabd | 11682 | |
8be6ca85 | 11683 | if (visible || was_visible) |
a9ff8714 VS |
11684 | intel_crtc->atomic.fb_bits |= |
11685 | to_intel_plane(plane)->frontbuffer_bit; | |
11686 | ||
da20eabd ML |
11687 | switch (plane->type) { |
11688 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd ML |
11689 | intel_crtc->atomic.pre_disable_primary = turn_off; |
11690 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11691 | ||
066cf55b RV |
11692 | if (turn_off) { |
11693 | /* | |
11694 | * FIXME: Actually if we will still have any other | |
11695 | * plane enabled on the pipe we could let IPS enabled | |
11696 | * still, but for now lets consider that when we make | |
11697 | * primary invisible by setting DSPCNTR to 0 on | |
11698 | * update_primary_plane function IPS needs to be | |
11699 | * disable. | |
11700 | */ | |
11701 | intel_crtc->atomic.disable_ips = true; | |
11702 | ||
da20eabd | 11703 | intel_crtc->atomic.disable_fbc = true; |
066cf55b | 11704 | } |
da20eabd ML |
11705 | |
11706 | /* | |
11707 | * FBC does not work on some platforms for rotated | |
11708 | * planes, so disable it when rotation is not 0 and | |
11709 | * update it when rotation is set back to 0. | |
11710 | * | |
11711 | * FIXME: This is redundant with the fbc update done in | |
11712 | * the primary plane enable function except that that | |
11713 | * one is done too late. We eventually need to unify | |
11714 | * this. | |
11715 | */ | |
11716 | ||
11717 | if (visible && | |
11718 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11719 | dev_priv->fbc.crtc == intel_crtc && | |
11720 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11721 | intel_crtc->atomic.disable_fbc = true; | |
11722 | ||
11723 | /* | |
11724 | * BDW signals flip done immediately if the plane | |
11725 | * is disabled, even if the plane enable is already | |
11726 | * armed to occur at the next vblank :( | |
11727 | */ | |
11728 | if (turn_on && IS_BROADWELL(dev)) | |
11729 | intel_crtc->atomic.wait_vblank = true; | |
11730 | ||
11731 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11732 | break; | |
11733 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11734 | break; |
11735 | case DRM_PLANE_TYPE_OVERLAY: | |
d21fbe87 MR |
11736 | /* |
11737 | * WaCxSRDisabledForSpriteScaling:ivb | |
11738 | * | |
11739 | * cstate->update_wm was already set above, so this flag will | |
11740 | * take effect when we commit and program watermarks. | |
11741 | */ | |
11742 | if (IS_IVYBRIDGE(dev) && | |
11743 | needs_scaling(to_intel_plane_state(plane_state)) && | |
11744 | !needs_scaling(old_plane_state)) { | |
11745 | to_intel_crtc_state(crtc_state)->disable_lp_wm = true; | |
11746 | } else if (turn_off && !mode_changed) { | |
da20eabd ML |
11747 | intel_crtc->atomic.wait_vblank = true; |
11748 | intel_crtc->atomic.update_sprite_watermarks |= | |
11749 | 1 << i; | |
11750 | } | |
d21fbe87 MR |
11751 | |
11752 | break; | |
da20eabd ML |
11753 | } |
11754 | return 0; | |
11755 | } | |
11756 | ||
6d3a1ce7 ML |
11757 | static bool encoders_cloneable(const struct intel_encoder *a, |
11758 | const struct intel_encoder *b) | |
11759 | { | |
11760 | /* masks could be asymmetric, so check both ways */ | |
11761 | return a == b || (a->cloneable & (1 << b->type) && | |
11762 | b->cloneable & (1 << a->type)); | |
11763 | } | |
11764 | ||
11765 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11766 | struct intel_crtc *crtc, | |
11767 | struct intel_encoder *encoder) | |
11768 | { | |
11769 | struct intel_encoder *source_encoder; | |
11770 | struct drm_connector *connector; | |
11771 | struct drm_connector_state *connector_state; | |
11772 | int i; | |
11773 | ||
11774 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11775 | if (connector_state->crtc != &crtc->base) | |
11776 | continue; | |
11777 | ||
11778 | source_encoder = | |
11779 | to_intel_encoder(connector_state->best_encoder); | |
11780 | if (!encoders_cloneable(encoder, source_encoder)) | |
11781 | return false; | |
11782 | } | |
11783 | ||
11784 | return true; | |
11785 | } | |
11786 | ||
11787 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11788 | struct intel_crtc *crtc) | |
11789 | { | |
11790 | struct intel_encoder *encoder; | |
11791 | struct drm_connector *connector; | |
11792 | struct drm_connector_state *connector_state; | |
11793 | int i; | |
11794 | ||
11795 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11796 | if (connector_state->crtc != &crtc->base) | |
11797 | continue; | |
11798 | ||
11799 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11800 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11801 | return false; | |
11802 | } | |
11803 | ||
11804 | return true; | |
11805 | } | |
11806 | ||
11807 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11808 | struct drm_crtc_state *crtc_state) | |
11809 | { | |
cf5a15be | 11810 | struct drm_device *dev = crtc->dev; |
ad421372 | 11811 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11812 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11813 | struct intel_crtc_state *pipe_config = |
11814 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11815 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 11816 | int ret; |
6d3a1ce7 ML |
11817 | bool mode_changed = needs_modeset(crtc_state); |
11818 | ||
11819 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11820 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11821 | return -EINVAL; | |
11822 | } | |
11823 | ||
852eb00d VS |
11824 | if (mode_changed && !crtc_state->active) |
11825 | intel_crtc->atomic.update_wm_post = true; | |
eddfcbcd | 11826 | |
ad421372 ML |
11827 | if (mode_changed && crtc_state->enable && |
11828 | dev_priv->display.crtc_compute_clock && | |
11829 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11830 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11831 | pipe_config); | |
11832 | if (ret) | |
11833 | return ret; | |
11834 | } | |
11835 | ||
e435d6e5 | 11836 | ret = 0; |
86c8bbbe MR |
11837 | if (dev_priv->display.compute_pipe_wm) { |
11838 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
11839 | if (ret) | |
11840 | return ret; | |
11841 | } | |
11842 | ||
e435d6e5 ML |
11843 | if (INTEL_INFO(dev)->gen >= 9) { |
11844 | if (mode_changed) | |
11845 | ret = skl_update_scaler_crtc(pipe_config); | |
11846 | ||
11847 | if (!ret) | |
11848 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
11849 | pipe_config); | |
11850 | } | |
11851 | ||
11852 | return ret; | |
6d3a1ce7 ML |
11853 | } |
11854 | ||
65b38e0d | 11855 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11856 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11857 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11858 | .atomic_begin = intel_begin_crtc_commit, |
11859 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11860 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11861 | }; |
11862 | ||
d29b2f9d ACO |
11863 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
11864 | { | |
11865 | struct intel_connector *connector; | |
11866 | ||
11867 | for_each_intel_connector(dev, connector) { | |
11868 | if (connector->base.encoder) { | |
11869 | connector->base.state->best_encoder = | |
11870 | connector->base.encoder; | |
11871 | connector->base.state->crtc = | |
11872 | connector->base.encoder->crtc; | |
11873 | } else { | |
11874 | connector->base.state->best_encoder = NULL; | |
11875 | connector->base.state->crtc = NULL; | |
11876 | } | |
11877 | } | |
11878 | } | |
11879 | ||
050f7aeb | 11880 | static void |
eba905b2 | 11881 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11882 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11883 | { |
11884 | int bpp = pipe_config->pipe_bpp; | |
11885 | ||
11886 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11887 | connector->base.base.id, | |
c23cc417 | 11888 | connector->base.name); |
050f7aeb DV |
11889 | |
11890 | /* Don't use an invalid EDID bpc value */ | |
11891 | if (connector->base.display_info.bpc && | |
11892 | connector->base.display_info.bpc * 3 < bpp) { | |
11893 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11894 | bpp, connector->base.display_info.bpc*3); | |
11895 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11896 | } | |
11897 | ||
11898 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11899 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11900 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11901 | bpp); | |
11902 | pipe_config->pipe_bpp = 24; | |
11903 | } | |
11904 | } | |
11905 | ||
4e53c2e0 | 11906 | static int |
050f7aeb | 11907 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 11908 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 11909 | { |
050f7aeb | 11910 | struct drm_device *dev = crtc->base.dev; |
1486017f | 11911 | struct drm_atomic_state *state; |
da3ced29 ACO |
11912 | struct drm_connector *connector; |
11913 | struct drm_connector_state *connector_state; | |
1486017f | 11914 | int bpp, i; |
4e53c2e0 | 11915 | |
d328c9d7 | 11916 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 11917 | bpp = 10*3; |
d328c9d7 DV |
11918 | else if (INTEL_INFO(dev)->gen >= 5) |
11919 | bpp = 12*3; | |
11920 | else | |
11921 | bpp = 8*3; | |
11922 | ||
4e53c2e0 | 11923 | |
4e53c2e0 DV |
11924 | pipe_config->pipe_bpp = bpp; |
11925 | ||
1486017f ACO |
11926 | state = pipe_config->base.state; |
11927 | ||
4e53c2e0 | 11928 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
11929 | for_each_connector_in_state(state, connector, connector_state, i) { |
11930 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
11931 | continue; |
11932 | ||
da3ced29 ACO |
11933 | connected_sink_compute_bpp(to_intel_connector(connector), |
11934 | pipe_config); | |
4e53c2e0 DV |
11935 | } |
11936 | ||
11937 | return bpp; | |
11938 | } | |
11939 | ||
644db711 DV |
11940 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
11941 | { | |
11942 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
11943 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 11944 | mode->crtc_clock, |
644db711 DV |
11945 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
11946 | mode->crtc_hsync_end, mode->crtc_htotal, | |
11947 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
11948 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
11949 | } | |
11950 | ||
c0b03411 | 11951 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 11952 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
11953 | const char *context) |
11954 | { | |
6a60cd87 CK |
11955 | struct drm_device *dev = crtc->base.dev; |
11956 | struct drm_plane *plane; | |
11957 | struct intel_plane *intel_plane; | |
11958 | struct intel_plane_state *state; | |
11959 | struct drm_framebuffer *fb; | |
11960 | ||
11961 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
11962 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
11963 | |
11964 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
11965 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
11966 | pipe_config->pipe_bpp, pipe_config->dither); | |
11967 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
11968 | pipe_config->has_pch_encoder, | |
11969 | pipe_config->fdi_lanes, | |
11970 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
11971 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
11972 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 11973 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 11974 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11975 | pipe_config->lane_count, |
eb14cb74 VS |
11976 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
11977 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
11978 | pipe_config->dp_m_n.tu); | |
b95af8be | 11979 | |
90a6b7b0 | 11980 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 11981 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11982 | pipe_config->lane_count, |
b95af8be VK |
11983 | pipe_config->dp_m2_n2.gmch_m, |
11984 | pipe_config->dp_m2_n2.gmch_n, | |
11985 | pipe_config->dp_m2_n2.link_m, | |
11986 | pipe_config->dp_m2_n2.link_n, | |
11987 | pipe_config->dp_m2_n2.tu); | |
11988 | ||
55072d19 DV |
11989 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
11990 | pipe_config->has_audio, | |
11991 | pipe_config->has_infoframe); | |
11992 | ||
c0b03411 | 11993 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 11994 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 11995 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
11996 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
11997 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 11998 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
11999 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
12000 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
12001 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
12002 | crtc->num_scalers, | |
12003 | pipe_config->scaler_state.scaler_users, | |
12004 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
12005 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12006 | pipe_config->gmch_pfit.control, | |
12007 | pipe_config->gmch_pfit.pgm_ratios, | |
12008 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12009 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12010 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12011 | pipe_config->pch_pfit.size, |
12012 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12013 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12014 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12015 | |
415ff0f6 | 12016 | if (IS_BROXTON(dev)) { |
05712c15 | 12017 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12018 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12019 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12020 | pipe_config->ddi_pll_sel, |
12021 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12022 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12023 | pipe_config->dpll_hw_state.pll0, |
12024 | pipe_config->dpll_hw_state.pll1, | |
12025 | pipe_config->dpll_hw_state.pll2, | |
12026 | pipe_config->dpll_hw_state.pll3, | |
12027 | pipe_config->dpll_hw_state.pll6, | |
12028 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12029 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12030 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12031 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12032 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12033 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12034 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12035 | pipe_config->ddi_pll_sel, | |
12036 | pipe_config->dpll_hw_state.ctrl1, | |
12037 | pipe_config->dpll_hw_state.cfgcr1, | |
12038 | pipe_config->dpll_hw_state.cfgcr2); | |
12039 | } else if (HAS_DDI(dev)) { | |
12040 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
12041 | pipe_config->ddi_pll_sel, | |
12042 | pipe_config->dpll_hw_state.wrpll); | |
12043 | } else { | |
12044 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12045 | "fp0: 0x%x, fp1: 0x%x\n", | |
12046 | pipe_config->dpll_hw_state.dpll, | |
12047 | pipe_config->dpll_hw_state.dpll_md, | |
12048 | pipe_config->dpll_hw_state.fp0, | |
12049 | pipe_config->dpll_hw_state.fp1); | |
12050 | } | |
12051 | ||
6a60cd87 CK |
12052 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12053 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12054 | intel_plane = to_intel_plane(plane); | |
12055 | if (intel_plane->pipe != crtc->pipe) | |
12056 | continue; | |
12057 | ||
12058 | state = to_intel_plane_state(plane->state); | |
12059 | fb = state->base.fb; | |
12060 | if (!fb) { | |
12061 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12062 | "disabled, scaler_id = %d\n", | |
12063 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12064 | plane->base.id, intel_plane->pipe, | |
12065 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12066 | drm_plane_index(plane), state->scaler_id); | |
12067 | continue; | |
12068 | } | |
12069 | ||
12070 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12071 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12072 | plane->base.id, intel_plane->pipe, | |
12073 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12074 | drm_plane_index(plane)); | |
12075 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12076 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12077 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12078 | state->scaler_id, | |
12079 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12080 | drm_rect_width(&state->src) >> 16, | |
12081 | drm_rect_height(&state->src) >> 16, | |
12082 | state->dst.x1, state->dst.y1, | |
12083 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12084 | } | |
c0b03411 DV |
12085 | } |
12086 | ||
5448a00d | 12087 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12088 | { |
5448a00d ACO |
12089 | struct drm_device *dev = state->dev; |
12090 | struct intel_encoder *encoder; | |
da3ced29 | 12091 | struct drm_connector *connector; |
5448a00d | 12092 | struct drm_connector_state *connector_state; |
00f0b378 | 12093 | unsigned int used_ports = 0; |
5448a00d | 12094 | int i; |
00f0b378 VS |
12095 | |
12096 | /* | |
12097 | * Walk the connector list instead of the encoder | |
12098 | * list to detect the problem on ddi platforms | |
12099 | * where there's just one encoder per digital port. | |
12100 | */ | |
da3ced29 | 12101 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12102 | if (!connector_state->best_encoder) |
00f0b378 VS |
12103 | continue; |
12104 | ||
5448a00d ACO |
12105 | encoder = to_intel_encoder(connector_state->best_encoder); |
12106 | ||
12107 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12108 | |
12109 | switch (encoder->type) { | |
12110 | unsigned int port_mask; | |
12111 | case INTEL_OUTPUT_UNKNOWN: | |
12112 | if (WARN_ON(!HAS_DDI(dev))) | |
12113 | break; | |
12114 | case INTEL_OUTPUT_DISPLAYPORT: | |
12115 | case INTEL_OUTPUT_HDMI: | |
12116 | case INTEL_OUTPUT_EDP: | |
12117 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12118 | ||
12119 | /* the same port mustn't appear more than once */ | |
12120 | if (used_ports & port_mask) | |
12121 | return false; | |
12122 | ||
12123 | used_ports |= port_mask; | |
12124 | default: | |
12125 | break; | |
12126 | } | |
12127 | } | |
12128 | ||
12129 | return true; | |
12130 | } | |
12131 | ||
83a57153 ACO |
12132 | static void |
12133 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12134 | { | |
12135 | struct drm_crtc_state tmp_state; | |
663a3640 | 12136 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12137 | struct intel_dpll_hw_state dpll_hw_state; |
12138 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12139 | uint32_t ddi_pll_sel; |
c4e2d043 | 12140 | bool force_thru; |
83a57153 | 12141 | |
7546a384 ACO |
12142 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12143 | * kzalloc'd. Code that depends on any field being zero should be | |
12144 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12145 | * only fields that are know to not cause problems are preserved. */ | |
12146 | ||
83a57153 | 12147 | tmp_state = crtc_state->base; |
663a3640 | 12148 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12149 | shared_dpll = crtc_state->shared_dpll; |
12150 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12151 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12152 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12153 | |
83a57153 | 12154 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12155 | |
83a57153 | 12156 | crtc_state->base = tmp_state; |
663a3640 | 12157 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12158 | crtc_state->shared_dpll = shared_dpll; |
12159 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12160 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12161 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12162 | } |
12163 | ||
548ee15b | 12164 | static int |
b8cecdf5 | 12165 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12166 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12167 | { |
b359283a | 12168 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12169 | struct intel_encoder *encoder; |
da3ced29 | 12170 | struct drm_connector *connector; |
0b901879 | 12171 | struct drm_connector_state *connector_state; |
d328c9d7 | 12172 | int base_bpp, ret = -EINVAL; |
0b901879 | 12173 | int i; |
e29c22c0 | 12174 | bool retry = true; |
ee7b9f93 | 12175 | |
83a57153 | 12176 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12177 | |
e143a21c DV |
12178 | pipe_config->cpu_transcoder = |
12179 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12180 | |
2960bc9c ID |
12181 | /* |
12182 | * Sanitize sync polarity flags based on requested ones. If neither | |
12183 | * positive or negative polarity is requested, treat this as meaning | |
12184 | * negative polarity. | |
12185 | */ | |
2d112de7 | 12186 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12187 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12188 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12189 | |
2d112de7 | 12190 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12191 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12192 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12193 | |
d328c9d7 DV |
12194 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12195 | pipe_config); | |
12196 | if (base_bpp < 0) | |
4e53c2e0 DV |
12197 | goto fail; |
12198 | ||
e41a56be VS |
12199 | /* |
12200 | * Determine the real pipe dimensions. Note that stereo modes can | |
12201 | * increase the actual pipe size due to the frame doubling and | |
12202 | * insertion of additional space for blanks between the frame. This | |
12203 | * is stored in the crtc timings. We use the requested mode to do this | |
12204 | * computation to clearly distinguish it from the adjusted mode, which | |
12205 | * can be changed by the connectors in the below retry loop. | |
12206 | */ | |
2d112de7 | 12207 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12208 | &pipe_config->pipe_src_w, |
12209 | &pipe_config->pipe_src_h); | |
e41a56be | 12210 | |
e29c22c0 | 12211 | encoder_retry: |
ef1b460d | 12212 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12213 | pipe_config->port_clock = 0; |
ef1b460d | 12214 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12215 | |
135c81b8 | 12216 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12217 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12218 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12219 | |
7758a113 DV |
12220 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12221 | * adjust it according to limitations or connector properties, and also | |
12222 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12223 | */ |
da3ced29 | 12224 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12225 | if (connector_state->crtc != crtc) |
7758a113 | 12226 | continue; |
7ae89233 | 12227 | |
0b901879 ACO |
12228 | encoder = to_intel_encoder(connector_state->best_encoder); |
12229 | ||
efea6e8e DV |
12230 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12231 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12232 | goto fail; |
12233 | } | |
ee7b9f93 | 12234 | } |
47f1c6c9 | 12235 | |
ff9a6750 DV |
12236 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12237 | * done afterwards in case the encoder adjusts the mode. */ | |
12238 | if (!pipe_config->port_clock) | |
2d112de7 | 12239 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12240 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12241 | |
a43f6e0f | 12242 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12243 | if (ret < 0) { |
7758a113 DV |
12244 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12245 | goto fail; | |
ee7b9f93 | 12246 | } |
e29c22c0 DV |
12247 | |
12248 | if (ret == RETRY) { | |
12249 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12250 | ret = -EINVAL; | |
12251 | goto fail; | |
12252 | } | |
12253 | ||
12254 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12255 | retry = false; | |
12256 | goto encoder_retry; | |
12257 | } | |
12258 | ||
e8fa4270 DV |
12259 | /* Dithering seems to not pass-through bits correctly when it should, so |
12260 | * only enable it on 6bpc panels. */ | |
12261 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12262 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12263 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12264 | |
7758a113 | 12265 | fail: |
548ee15b | 12266 | return ret; |
ee7b9f93 | 12267 | } |
47f1c6c9 | 12268 | |
ea9d758d | 12269 | static void |
4740b0f2 | 12270 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12271 | { |
0a9ab303 ACO |
12272 | struct drm_crtc *crtc; |
12273 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12274 | int i; |
ea9d758d | 12275 | |
7668851f | 12276 | /* Double check state. */ |
8a75d157 | 12277 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12278 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12279 | |
12280 | /* Update hwmode for vblank functions */ | |
12281 | if (crtc->state->active) | |
12282 | crtc->hwmode = crtc->state->adjusted_mode; | |
12283 | else | |
12284 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12285 | |
12286 | /* | |
12287 | * Update legacy state to satisfy fbc code. This can | |
12288 | * be removed when fbc uses the atomic state. | |
12289 | */ | |
12290 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12291 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12292 | ||
12293 | crtc->primary->fb = plane_state->fb; | |
12294 | crtc->x = plane_state->src_x >> 16; | |
12295 | crtc->y = plane_state->src_y >> 16; | |
12296 | } | |
ea9d758d | 12297 | } |
ea9d758d DV |
12298 | } |
12299 | ||
3bd26263 | 12300 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12301 | { |
3bd26263 | 12302 | int diff; |
f1f644dc JB |
12303 | |
12304 | if (clock1 == clock2) | |
12305 | return true; | |
12306 | ||
12307 | if (!clock1 || !clock2) | |
12308 | return false; | |
12309 | ||
12310 | diff = abs(clock1 - clock2); | |
12311 | ||
12312 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12313 | return true; | |
12314 | ||
12315 | return false; | |
12316 | } | |
12317 | ||
25c5b266 DV |
12318 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12319 | list_for_each_entry((intel_crtc), \ | |
12320 | &(dev)->mode_config.crtc_list, \ | |
12321 | base.head) \ | |
0973f18f | 12322 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12323 | |
cfb23ed6 ML |
12324 | static bool |
12325 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12326 | unsigned int m2, unsigned int n2, | |
12327 | bool exact) | |
12328 | { | |
12329 | if (m == m2 && n == n2) | |
12330 | return true; | |
12331 | ||
12332 | if (exact || !m || !n || !m2 || !n2) | |
12333 | return false; | |
12334 | ||
12335 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12336 | ||
12337 | if (m > m2) { | |
12338 | while (m > m2) { | |
12339 | m2 <<= 1; | |
12340 | n2 <<= 1; | |
12341 | } | |
12342 | } else if (m < m2) { | |
12343 | while (m < m2) { | |
12344 | m <<= 1; | |
12345 | n <<= 1; | |
12346 | } | |
12347 | } | |
12348 | ||
12349 | return m == m2 && n == n2; | |
12350 | } | |
12351 | ||
12352 | static bool | |
12353 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12354 | struct intel_link_m_n *m2_n2, | |
12355 | bool adjust) | |
12356 | { | |
12357 | if (m_n->tu == m2_n2->tu && | |
12358 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12359 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12360 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12361 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12362 | if (adjust) | |
12363 | *m2_n2 = *m_n; | |
12364 | ||
12365 | return true; | |
12366 | } | |
12367 | ||
12368 | return false; | |
12369 | } | |
12370 | ||
0e8ffe1b | 12371 | static bool |
2fa2fe9a | 12372 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12373 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12374 | struct intel_crtc_state *pipe_config, |
12375 | bool adjust) | |
0e8ffe1b | 12376 | { |
cfb23ed6 ML |
12377 | bool ret = true; |
12378 | ||
12379 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12380 | do { \ | |
12381 | if (!adjust) \ | |
12382 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12383 | else \ | |
12384 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12385 | } while (0) | |
12386 | ||
66e985c0 DV |
12387 | #define PIPE_CONF_CHECK_X(name) \ |
12388 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12389 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12390 | "(expected 0x%08x, found 0x%08x)\n", \ |
12391 | current_config->name, \ | |
12392 | pipe_config->name); \ | |
cfb23ed6 | 12393 | ret = false; \ |
66e985c0 DV |
12394 | } |
12395 | ||
08a24034 DV |
12396 | #define PIPE_CONF_CHECK_I(name) \ |
12397 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12398 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12399 | "(expected %i, found %i)\n", \ |
12400 | current_config->name, \ | |
12401 | pipe_config->name); \ | |
cfb23ed6 ML |
12402 | ret = false; \ |
12403 | } | |
12404 | ||
12405 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12406 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12407 | &pipe_config->name,\ | |
12408 | adjust)) { \ | |
12409 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12410 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12411 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12412 | current_config->name.tu, \ | |
12413 | current_config->name.gmch_m, \ | |
12414 | current_config->name.gmch_n, \ | |
12415 | current_config->name.link_m, \ | |
12416 | current_config->name.link_n, \ | |
12417 | pipe_config->name.tu, \ | |
12418 | pipe_config->name.gmch_m, \ | |
12419 | pipe_config->name.gmch_n, \ | |
12420 | pipe_config->name.link_m, \ | |
12421 | pipe_config->name.link_n); \ | |
12422 | ret = false; \ | |
12423 | } | |
12424 | ||
12425 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12426 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12427 | &pipe_config->name, adjust) && \ | |
12428 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12429 | &pipe_config->name, adjust)) { \ | |
12430 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12431 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12432 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12433 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12434 | current_config->name.tu, \ | |
12435 | current_config->name.gmch_m, \ | |
12436 | current_config->name.gmch_n, \ | |
12437 | current_config->name.link_m, \ | |
12438 | current_config->name.link_n, \ | |
12439 | current_config->alt_name.tu, \ | |
12440 | current_config->alt_name.gmch_m, \ | |
12441 | current_config->alt_name.gmch_n, \ | |
12442 | current_config->alt_name.link_m, \ | |
12443 | current_config->alt_name.link_n, \ | |
12444 | pipe_config->name.tu, \ | |
12445 | pipe_config->name.gmch_m, \ | |
12446 | pipe_config->name.gmch_n, \ | |
12447 | pipe_config->name.link_m, \ | |
12448 | pipe_config->name.link_n); \ | |
12449 | ret = false; \ | |
88adfff1 DV |
12450 | } |
12451 | ||
b95af8be VK |
12452 | /* This is required for BDW+ where there is only one set of registers for |
12453 | * switching between high and low RR. | |
12454 | * This macro can be used whenever a comparison has to be made between one | |
12455 | * hw state and multiple sw state variables. | |
12456 | */ | |
12457 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12458 | if ((current_config->name != pipe_config->name) && \ | |
12459 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12460 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12461 | "(expected %i or %i, found %i)\n", \ |
12462 | current_config->name, \ | |
12463 | current_config->alt_name, \ | |
12464 | pipe_config->name); \ | |
cfb23ed6 | 12465 | ret = false; \ |
b95af8be VK |
12466 | } |
12467 | ||
1bd1bd80 DV |
12468 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12469 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12470 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12471 | "(expected %i, found %i)\n", \ |
12472 | current_config->name & (mask), \ | |
12473 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12474 | ret = false; \ |
1bd1bd80 DV |
12475 | } |
12476 | ||
5e550656 VS |
12477 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12478 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12479 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12480 | "(expected %i, found %i)\n", \ |
12481 | current_config->name, \ | |
12482 | pipe_config->name); \ | |
cfb23ed6 | 12483 | ret = false; \ |
5e550656 VS |
12484 | } |
12485 | ||
bb760063 DV |
12486 | #define PIPE_CONF_QUIRK(quirk) \ |
12487 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12488 | ||
eccb140b DV |
12489 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12490 | ||
08a24034 DV |
12491 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12492 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12493 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12494 | |
eb14cb74 | 12495 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12496 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12497 | |
12498 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12499 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12500 | ||
12501 | PIPE_CONF_CHECK_I(has_drrs); | |
12502 | if (current_config->has_drrs) | |
12503 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12504 | } else | |
12505 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12506 | |
2d112de7 ACO |
12507 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12508 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12509 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12510 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12511 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12512 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12513 | |
2d112de7 ACO |
12514 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12515 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12516 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12517 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12518 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12519 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12520 | |
c93f54cf | 12521 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12522 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12523 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12524 | IS_VALLEYVIEW(dev)) | |
12525 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12526 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12527 | |
9ed109a7 DV |
12528 | PIPE_CONF_CHECK_I(has_audio); |
12529 | ||
2d112de7 | 12530 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12531 | DRM_MODE_FLAG_INTERLACE); |
12532 | ||
bb760063 | 12533 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12534 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12535 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12536 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12537 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12538 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12539 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12540 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12541 | DRM_MODE_FLAG_NVSYNC); |
12542 | } | |
045ac3b5 | 12543 | |
333b8ca8 | 12544 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12545 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12546 | if (INTEL_INFO(dev)->gen < 4) | |
12547 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
333b8ca8 | 12548 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12549 | |
bfd16b2a ML |
12550 | if (!adjust) { |
12551 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12552 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12553 | ||
12554 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12555 | if (current_config->pch_pfit.enabled) { | |
12556 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12557 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12558 | } | |
2fa2fe9a | 12559 | |
7aefe2b5 ML |
12560 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12561 | } | |
a1b2278e | 12562 | |
e59150dc JB |
12563 | /* BDW+ don't expose a synchronous way to read the state */ |
12564 | if (IS_HASWELL(dev)) | |
12565 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12566 | |
282740f7 VS |
12567 | PIPE_CONF_CHECK_I(double_wide); |
12568 | ||
26804afd DV |
12569 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12570 | ||
c0d43d62 | 12571 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12572 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12573 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12574 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12575 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12576 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
12577 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12578 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12579 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12580 | |
42571aef VS |
12581 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12582 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12583 | ||
2d112de7 | 12584 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12585 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12586 | |
66e985c0 | 12587 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12588 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12589 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12590 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12591 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12592 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12593 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12594 | |
cfb23ed6 | 12595 | return ret; |
0e8ffe1b DV |
12596 | } |
12597 | ||
08db6652 DL |
12598 | static void check_wm_state(struct drm_device *dev) |
12599 | { | |
12600 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12601 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12602 | struct intel_crtc *intel_crtc; | |
12603 | int plane; | |
12604 | ||
12605 | if (INTEL_INFO(dev)->gen < 9) | |
12606 | return; | |
12607 | ||
12608 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12609 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12610 | ||
12611 | for_each_intel_crtc(dev, intel_crtc) { | |
12612 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12613 | const enum pipe pipe = intel_crtc->pipe; | |
12614 | ||
12615 | if (!intel_crtc->active) | |
12616 | continue; | |
12617 | ||
12618 | /* planes */ | |
dd740780 | 12619 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12620 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12621 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12622 | ||
12623 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12624 | continue; | |
12625 | ||
12626 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12627 | "(expected (%u,%u), found (%u,%u))\n", | |
12628 | pipe_name(pipe), plane + 1, | |
12629 | sw_entry->start, sw_entry->end, | |
12630 | hw_entry->start, hw_entry->end); | |
12631 | } | |
12632 | ||
12633 | /* cursor */ | |
4969d33e MR |
12634 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
12635 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 DL |
12636 | |
12637 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12638 | continue; | |
12639 | ||
12640 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12641 | "(expected (%u,%u), found (%u,%u))\n", | |
12642 | pipe_name(pipe), | |
12643 | sw_entry->start, sw_entry->end, | |
12644 | hw_entry->start, hw_entry->end); | |
12645 | } | |
12646 | } | |
12647 | ||
91d1b4bd | 12648 | static void |
35dd3c64 ML |
12649 | check_connector_state(struct drm_device *dev, |
12650 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12651 | { |
35dd3c64 ML |
12652 | struct drm_connector_state *old_conn_state; |
12653 | struct drm_connector *connector; | |
12654 | int i; | |
8af6cf88 | 12655 | |
35dd3c64 ML |
12656 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12657 | struct drm_encoder *encoder = connector->encoder; | |
12658 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12659 | |
8af6cf88 DV |
12660 | /* This also checks the encoder/connector hw state with the |
12661 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12662 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12663 | |
ad3c558f | 12664 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12665 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12666 | } |
91d1b4bd DV |
12667 | } |
12668 | ||
12669 | static void | |
12670 | check_encoder_state(struct drm_device *dev) | |
12671 | { | |
12672 | struct intel_encoder *encoder; | |
12673 | struct intel_connector *connector; | |
8af6cf88 | 12674 | |
b2784e15 | 12675 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12676 | bool enabled = false; |
4d20cd86 | 12677 | enum pipe pipe; |
8af6cf88 DV |
12678 | |
12679 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12680 | encoder->base.base.id, | |
8e329a03 | 12681 | encoder->base.name); |
8af6cf88 | 12682 | |
3a3371ff | 12683 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12684 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12685 | continue; |
12686 | enabled = true; | |
ad3c558f ML |
12687 | |
12688 | I915_STATE_WARN(connector->base.state->crtc != | |
12689 | encoder->base.crtc, | |
12690 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12691 | } |
0e32b39c | 12692 | |
e2c719b7 | 12693 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12694 | "encoder's enabled state mismatch " |
12695 | "(expected %i, found %i)\n", | |
12696 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12697 | |
12698 | if (!encoder->base.crtc) { | |
4d20cd86 | 12699 | bool active; |
7c60d198 | 12700 | |
4d20cd86 ML |
12701 | active = encoder->get_hw_state(encoder, &pipe); |
12702 | I915_STATE_WARN(active, | |
12703 | "encoder detached but still enabled on pipe %c.\n", | |
12704 | pipe_name(pipe)); | |
7c60d198 | 12705 | } |
8af6cf88 | 12706 | } |
91d1b4bd DV |
12707 | } |
12708 | ||
12709 | static void | |
4d20cd86 | 12710 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12711 | { |
fbee40df | 12712 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12713 | struct intel_encoder *encoder; |
4d20cd86 ML |
12714 | struct drm_crtc_state *old_crtc_state; |
12715 | struct drm_crtc *crtc; | |
12716 | int i; | |
8af6cf88 | 12717 | |
4d20cd86 ML |
12718 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12719 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12720 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12721 | bool active; |
8af6cf88 | 12722 | |
bfd16b2a ML |
12723 | if (!needs_modeset(crtc->state) && |
12724 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
4d20cd86 | 12725 | continue; |
045ac3b5 | 12726 | |
4d20cd86 ML |
12727 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
12728 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
12729 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
12730 | pipe_config->base.crtc = crtc; | |
12731 | pipe_config->base.state = old_state; | |
8af6cf88 | 12732 | |
4d20cd86 ML |
12733 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12734 | crtc->base.id); | |
8af6cf88 | 12735 | |
4d20cd86 ML |
12736 | active = dev_priv->display.get_pipe_config(intel_crtc, |
12737 | pipe_config); | |
d62cf62a | 12738 | |
b6b5d049 | 12739 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
12740 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
12741 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
12742 | active = crtc->state->active; | |
6c49f241 | 12743 | |
4d20cd86 | 12744 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 12745 | "crtc active state doesn't match with hw state " |
4d20cd86 | 12746 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 12747 | |
4d20cd86 | 12748 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 12749 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
12750 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
12751 | ||
12752 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
12753 | enum pipe pipe; | |
12754 | ||
12755 | active = encoder->get_hw_state(encoder, &pipe); | |
12756 | I915_STATE_WARN(active != crtc->state->active, | |
12757 | "[ENCODER:%i] active %i with crtc active %i\n", | |
12758 | encoder->base.base.id, active, crtc->state->active); | |
12759 | ||
12760 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
12761 | "Encoder connected to wrong pipe %c\n", | |
12762 | pipe_name(pipe)); | |
12763 | ||
12764 | if (active) | |
12765 | encoder->get_config(encoder, pipe_config); | |
12766 | } | |
53d9f4e9 | 12767 | |
4d20cd86 | 12768 | if (!crtc->state->active) |
cfb23ed6 ML |
12769 | continue; |
12770 | ||
4d20cd86 ML |
12771 | sw_config = to_intel_crtc_state(crtc->state); |
12772 | if (!intel_pipe_config_compare(dev, sw_config, | |
12773 | pipe_config, false)) { | |
e2c719b7 | 12774 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 12775 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 12776 | "[hw state]"); |
4d20cd86 | 12777 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
12778 | "[sw state]"); |
12779 | } | |
8af6cf88 DV |
12780 | } |
12781 | } | |
12782 | ||
91d1b4bd DV |
12783 | static void |
12784 | check_shared_dpll_state(struct drm_device *dev) | |
12785 | { | |
fbee40df | 12786 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12787 | struct intel_crtc *crtc; |
12788 | struct intel_dpll_hw_state dpll_hw_state; | |
12789 | int i; | |
5358901f DV |
12790 | |
12791 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12792 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12793 | int enabled_crtcs = 0, active_crtcs = 0; | |
12794 | bool active; | |
12795 | ||
12796 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12797 | ||
12798 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12799 | ||
12800 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12801 | ||
e2c719b7 | 12802 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12803 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12804 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12805 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12806 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12807 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12808 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12809 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12810 | "pll on state mismatch (expected %i, found %i)\n", |
12811 | pll->on, active); | |
12812 | ||
d3fcc808 | 12813 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12814 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12815 | enabled_crtcs++; |
12816 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12817 | active_crtcs++; | |
12818 | } | |
e2c719b7 | 12819 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12820 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12821 | pll->active, active_crtcs); | |
e2c719b7 | 12822 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12823 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12824 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12825 | |
e2c719b7 | 12826 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12827 | sizeof(dpll_hw_state)), |
12828 | "pll hw state mismatch\n"); | |
5358901f | 12829 | } |
8af6cf88 DV |
12830 | } |
12831 | ||
ee165b1a ML |
12832 | static void |
12833 | intel_modeset_check_state(struct drm_device *dev, | |
12834 | struct drm_atomic_state *old_state) | |
91d1b4bd | 12835 | { |
08db6652 | 12836 | check_wm_state(dev); |
35dd3c64 | 12837 | check_connector_state(dev, old_state); |
91d1b4bd | 12838 | check_encoder_state(dev); |
4d20cd86 | 12839 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
12840 | check_shared_dpll_state(dev); |
12841 | } | |
12842 | ||
5cec258b | 12843 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12844 | int dotclock) |
12845 | { | |
12846 | /* | |
12847 | * FDI already provided one idea for the dotclock. | |
12848 | * Yell if the encoder disagrees. | |
12849 | */ | |
2d112de7 | 12850 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12851 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12852 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12853 | } |
12854 | ||
80715b2f VS |
12855 | static void update_scanline_offset(struct intel_crtc *crtc) |
12856 | { | |
12857 | struct drm_device *dev = crtc->base.dev; | |
12858 | ||
12859 | /* | |
12860 | * The scanline counter increments at the leading edge of hsync. | |
12861 | * | |
12862 | * On most platforms it starts counting from vtotal-1 on the | |
12863 | * first active line. That means the scanline counter value is | |
12864 | * always one less than what we would expect. Ie. just after | |
12865 | * start of vblank, which also occurs at start of hsync (on the | |
12866 | * last active line), the scanline counter will read vblank_start-1. | |
12867 | * | |
12868 | * On gen2 the scanline counter starts counting from 1 instead | |
12869 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12870 | * to keep the value positive), instead of adding one. | |
12871 | * | |
12872 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12873 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12874 | * there's an extra 1 line difference. So we need to add two instead of | |
12875 | * one to the value. | |
12876 | */ | |
12877 | if (IS_GEN2(dev)) { | |
124abe07 | 12878 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12879 | int vtotal; |
12880 | ||
124abe07 VS |
12881 | vtotal = adjusted_mode->crtc_vtotal; |
12882 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
12883 | vtotal /= 2; |
12884 | ||
12885 | crtc->scanline_offset = vtotal - 1; | |
12886 | } else if (HAS_DDI(dev) && | |
409ee761 | 12887 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12888 | crtc->scanline_offset = 2; |
12889 | } else | |
12890 | crtc->scanline_offset = 1; | |
12891 | } | |
12892 | ||
ad421372 | 12893 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 12894 | { |
225da59b | 12895 | struct drm_device *dev = state->dev; |
ed6739ef | 12896 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 12897 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 12898 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12899 | struct intel_crtc_state *intel_crtc_state; |
12900 | struct drm_crtc *crtc; | |
12901 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 12902 | int i; |
ed6739ef ACO |
12903 | |
12904 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 12905 | return; |
ed6739ef | 12906 | |
0a9ab303 | 12907 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
12908 | int dpll; |
12909 | ||
0a9ab303 | 12910 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 12911 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 12912 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 12913 | |
ad421372 | 12914 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
12915 | continue; |
12916 | ||
ad421372 | 12917 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 12918 | |
ad421372 ML |
12919 | if (!shared_dpll) |
12920 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 12921 | |
ad421372 ML |
12922 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
12923 | } | |
ed6739ef ACO |
12924 | } |
12925 | ||
99d736a2 ML |
12926 | /* |
12927 | * This implements the workaround described in the "notes" section of the mode | |
12928 | * set sequence documentation. When going from no pipes or single pipe to | |
12929 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
12930 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
12931 | */ | |
12932 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
12933 | { | |
12934 | struct drm_crtc_state *crtc_state; | |
12935 | struct intel_crtc *intel_crtc; | |
12936 | struct drm_crtc *crtc; | |
12937 | struct intel_crtc_state *first_crtc_state = NULL; | |
12938 | struct intel_crtc_state *other_crtc_state = NULL; | |
12939 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
12940 | int i; | |
12941 | ||
12942 | /* look at all crtc's that are going to be enabled in during modeset */ | |
12943 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
12944 | intel_crtc = to_intel_crtc(crtc); | |
12945 | ||
12946 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
12947 | continue; | |
12948 | ||
12949 | if (first_crtc_state) { | |
12950 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
12951 | break; | |
12952 | } else { | |
12953 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
12954 | first_pipe = intel_crtc->pipe; | |
12955 | } | |
12956 | } | |
12957 | ||
12958 | /* No workaround needed? */ | |
12959 | if (!first_crtc_state) | |
12960 | return 0; | |
12961 | ||
12962 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
12963 | for_each_intel_crtc(state->dev, intel_crtc) { | |
12964 | struct intel_crtc_state *pipe_config; | |
12965 | ||
12966 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
12967 | if (IS_ERR(pipe_config)) | |
12968 | return PTR_ERR(pipe_config); | |
12969 | ||
12970 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
12971 | ||
12972 | if (!pipe_config->base.active || | |
12973 | needs_modeset(&pipe_config->base)) | |
12974 | continue; | |
12975 | ||
12976 | /* 2 or more enabled crtcs means no need for w/a */ | |
12977 | if (enabled_pipe != INVALID_PIPE) | |
12978 | return 0; | |
12979 | ||
12980 | enabled_pipe = intel_crtc->pipe; | |
12981 | } | |
12982 | ||
12983 | if (enabled_pipe != INVALID_PIPE) | |
12984 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
12985 | else if (other_crtc_state) | |
12986 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
12987 | ||
12988 | return 0; | |
12989 | } | |
12990 | ||
27c329ed ML |
12991 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
12992 | { | |
12993 | struct drm_crtc *crtc; | |
12994 | struct drm_crtc_state *crtc_state; | |
12995 | int ret = 0; | |
12996 | ||
12997 | /* add all active pipes to the state */ | |
12998 | for_each_crtc(state->dev, crtc) { | |
12999 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13000 | if (IS_ERR(crtc_state)) | |
13001 | return PTR_ERR(crtc_state); | |
13002 | ||
13003 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
13004 | continue; | |
13005 | ||
13006 | crtc_state->mode_changed = true; | |
13007 | ||
13008 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13009 | if (ret) | |
13010 | break; | |
13011 | ||
13012 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13013 | if (ret) | |
13014 | break; | |
13015 | } | |
13016 | ||
13017 | return ret; | |
13018 | } | |
13019 | ||
c347a676 | 13020 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
13021 | { |
13022 | struct drm_device *dev = state->dev; | |
27c329ed | 13023 | struct drm_i915_private *dev_priv = dev->dev_private; |
054518dd ACO |
13024 | int ret; |
13025 | ||
b359283a ML |
13026 | if (!check_digital_port_conflicts(state)) { |
13027 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13028 | return -EINVAL; | |
13029 | } | |
13030 | ||
054518dd ACO |
13031 | /* |
13032 | * See if the config requires any additional preparation, e.g. | |
13033 | * to adjust global state with pipes off. We need to do this | |
13034 | * here so we can get the modeset_pipe updated config for the new | |
13035 | * mode set on this crtc. For other crtcs we need to use the | |
13036 | * adjusted_mode bits in the crtc directly. | |
13037 | */ | |
27c329ed ML |
13038 | if (dev_priv->display.modeset_calc_cdclk) { |
13039 | unsigned int cdclk; | |
b432e5cf | 13040 | |
27c329ed ML |
13041 | ret = dev_priv->display.modeset_calc_cdclk(state); |
13042 | ||
13043 | cdclk = to_intel_atomic_state(state)->cdclk; | |
13044 | if (!ret && cdclk != dev_priv->cdclk_freq) | |
13045 | ret = intel_modeset_all_pipes(state); | |
13046 | ||
13047 | if (ret < 0) | |
054518dd | 13048 | return ret; |
27c329ed ML |
13049 | } else |
13050 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; | |
054518dd | 13051 | |
ad421372 | 13052 | intel_modeset_clear_plls(state); |
054518dd | 13053 | |
99d736a2 | 13054 | if (IS_HASWELL(dev)) |
ad421372 | 13055 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13056 | |
ad421372 | 13057 | return 0; |
c347a676 ACO |
13058 | } |
13059 | ||
aa363136 MR |
13060 | /* |
13061 | * Handle calculation of various watermark data at the end of the atomic check | |
13062 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13063 | * handlers to ensure that all derived state has been updated. | |
13064 | */ | |
13065 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13066 | { | |
13067 | struct drm_device *dev = state->dev; | |
13068 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13069 | struct drm_crtc *crtc; | |
13070 | struct drm_crtc_state *cstate; | |
13071 | struct drm_plane *plane; | |
13072 | struct drm_plane_state *pstate; | |
13073 | ||
13074 | /* | |
13075 | * Calculate watermark configuration details now that derived | |
13076 | * plane/crtc state is all properly updated. | |
13077 | */ | |
13078 | drm_for_each_crtc(crtc, dev) { | |
13079 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13080 | crtc->state; | |
13081 | ||
13082 | if (cstate->active) | |
13083 | intel_state->wm_config.num_pipes_active++; | |
13084 | } | |
13085 | drm_for_each_legacy_plane(plane, dev) { | |
13086 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13087 | plane->state; | |
13088 | ||
13089 | if (!to_intel_plane_state(pstate)->visible) | |
13090 | continue; | |
13091 | ||
13092 | intel_state->wm_config.sprites_enabled = true; | |
13093 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13094 | pstate->crtc_h != pstate->src_h >> 16) | |
13095 | intel_state->wm_config.sprites_scaled = true; | |
13096 | } | |
13097 | } | |
13098 | ||
74c090b1 ML |
13099 | /** |
13100 | * intel_atomic_check - validate state object | |
13101 | * @dev: drm device | |
13102 | * @state: state to validate | |
13103 | */ | |
13104 | static int intel_atomic_check(struct drm_device *dev, | |
13105 | struct drm_atomic_state *state) | |
c347a676 | 13106 | { |
aa363136 | 13107 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13108 | struct drm_crtc *crtc; |
13109 | struct drm_crtc_state *crtc_state; | |
13110 | int ret, i; | |
61333b60 | 13111 | bool any_ms = false; |
c347a676 | 13112 | |
74c090b1 | 13113 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13114 | if (ret) |
13115 | return ret; | |
13116 | ||
c347a676 | 13117 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13118 | struct intel_crtc_state *pipe_config = |
13119 | to_intel_crtc_state(crtc_state); | |
1ed51de9 DV |
13120 | |
13121 | /* Catch I915_MODE_FLAG_INHERITED */ | |
13122 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13123 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13124 | |
61333b60 ML |
13125 | if (!crtc_state->enable) { |
13126 | if (needs_modeset(crtc_state)) | |
13127 | any_ms = true; | |
c347a676 | 13128 | continue; |
61333b60 | 13129 | } |
c347a676 | 13130 | |
26495481 | 13131 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
13132 | continue; |
13133 | ||
26495481 DV |
13134 | /* FIXME: For only active_changed we shouldn't need to do any |
13135 | * state recomputation at all. */ | |
13136 | ||
1ed51de9 DV |
13137 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13138 | if (ret) | |
13139 | return ret; | |
b359283a | 13140 | |
cfb23ed6 | 13141 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13142 | if (ret) |
13143 | return ret; | |
13144 | ||
6764e9f8 | 13145 | if (intel_pipe_config_compare(state->dev, |
cfb23ed6 | 13146 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13147 | pipe_config, true)) { |
26495481 | 13148 | crtc_state->mode_changed = false; |
bfd16b2a | 13149 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13150 | } |
13151 | ||
13152 | if (needs_modeset(crtc_state)) { | |
13153 | any_ms = true; | |
cfb23ed6 ML |
13154 | |
13155 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13156 | if (ret) | |
13157 | return ret; | |
13158 | } | |
61333b60 | 13159 | |
26495481 DV |
13160 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13161 | needs_modeset(crtc_state) ? | |
13162 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13163 | } |
13164 | ||
61333b60 ML |
13165 | if (any_ms) { |
13166 | ret = intel_modeset_checks(state); | |
13167 | ||
13168 | if (ret) | |
13169 | return ret; | |
27c329ed | 13170 | } else |
aa363136 | 13171 | intel_state->cdclk = to_i915(state->dev)->cdclk_freq; |
76305b1a | 13172 | |
aa363136 MR |
13173 | ret = drm_atomic_helper_check_planes(state->dev, state); |
13174 | if (ret) | |
13175 | return ret; | |
13176 | ||
13177 | calc_watermark_data(state); | |
13178 | ||
13179 | return 0; | |
054518dd ACO |
13180 | } |
13181 | ||
5008e874 ML |
13182 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13183 | struct drm_atomic_state *state, | |
13184 | bool async) | |
13185 | { | |
7580d774 ML |
13186 | struct drm_i915_private *dev_priv = dev->dev_private; |
13187 | struct drm_plane_state *plane_state; | |
5008e874 | 13188 | struct drm_crtc_state *crtc_state; |
7580d774 | 13189 | struct drm_plane *plane; |
5008e874 ML |
13190 | struct drm_crtc *crtc; |
13191 | int i, ret; | |
13192 | ||
13193 | if (async) { | |
13194 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13195 | return -EINVAL; | |
13196 | } | |
13197 | ||
13198 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13199 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13200 | if (ret) | |
13201 | return ret; | |
7580d774 ML |
13202 | |
13203 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13204 | flush_workqueue(dev_priv->wq); | |
5008e874 ML |
13205 | } |
13206 | ||
f935675f ML |
13207 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13208 | if (ret) | |
13209 | return ret; | |
13210 | ||
5008e874 | 13211 | ret = drm_atomic_helper_prepare_planes(dev, state); |
7580d774 ML |
13212 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
13213 | u32 reset_counter; | |
13214 | ||
13215 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13216 | mutex_unlock(&dev->struct_mutex); | |
13217 | ||
13218 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13219 | struct intel_plane_state *intel_plane_state = | |
13220 | to_intel_plane_state(plane_state); | |
13221 | ||
13222 | if (!intel_plane_state->wait_req) | |
13223 | continue; | |
13224 | ||
13225 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13226 | reset_counter, true, | |
13227 | NULL, NULL); | |
13228 | ||
13229 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13230 | if (ret == -EIO) | |
13231 | ret = 0; | |
13232 | ||
13233 | if (ret) | |
13234 | break; | |
13235 | } | |
13236 | ||
13237 | if (!ret) | |
13238 | return 0; | |
13239 | ||
13240 | mutex_lock(&dev->struct_mutex); | |
13241 | drm_atomic_helper_cleanup_planes(dev, state); | |
13242 | } | |
5008e874 | 13243 | |
f935675f | 13244 | mutex_unlock(&dev->struct_mutex); |
5008e874 ML |
13245 | return ret; |
13246 | } | |
13247 | ||
74c090b1 ML |
13248 | /** |
13249 | * intel_atomic_commit - commit validated state object | |
13250 | * @dev: DRM device | |
13251 | * @state: the top-level driver state object | |
13252 | * @async: asynchronous commit | |
13253 | * | |
13254 | * This function commits a top-level state object that has been validated | |
13255 | * with drm_atomic_helper_check(). | |
13256 | * | |
13257 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13258 | * we can only handle plane-related operations and do not yet support | |
13259 | * asynchronous commit. | |
13260 | * | |
13261 | * RETURNS | |
13262 | * Zero for success or -errno. | |
13263 | */ | |
13264 | static int intel_atomic_commit(struct drm_device *dev, | |
13265 | struct drm_atomic_state *state, | |
13266 | bool async) | |
a6778b3c | 13267 | { |
fbee40df | 13268 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 | 13269 | struct drm_crtc_state *crtc_state; |
7580d774 | 13270 | struct drm_crtc *crtc; |
c0c36b94 | 13271 | int ret = 0; |
0a9ab303 | 13272 | int i; |
61333b60 | 13273 | bool any_ms = false; |
a6778b3c | 13274 | |
5008e874 | 13275 | ret = intel_atomic_prepare_commit(dev, state, async); |
7580d774 ML |
13276 | if (ret) { |
13277 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
d4afb8cc | 13278 | return ret; |
7580d774 | 13279 | } |
d4afb8cc | 13280 | |
1c5e19f8 | 13281 | drm_atomic_helper_swap_state(dev, state); |
aa363136 | 13282 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; |
1c5e19f8 | 13283 | |
0a9ab303 | 13284 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13285 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13286 | ||
61333b60 ML |
13287 | if (!needs_modeset(crtc->state)) |
13288 | continue; | |
13289 | ||
13290 | any_ms = true; | |
a539205a | 13291 | intel_pre_plane_update(intel_crtc); |
460da916 | 13292 | |
a539205a ML |
13293 | if (crtc_state->active) { |
13294 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13295 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd ML |
13296 | intel_crtc->active = false; |
13297 | intel_disable_shared_dpll(intel_crtc); | |
a539205a | 13298 | } |
b8cecdf5 | 13299 | } |
7758a113 | 13300 | |
ea9d758d DV |
13301 | /* Only after disabling all output pipelines that will be changed can we |
13302 | * update the the output configuration. */ | |
4740b0f2 | 13303 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13304 | |
4740b0f2 ML |
13305 | if (any_ms) { |
13306 | intel_shared_dpll_commit(state); | |
13307 | ||
13308 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
61333b60 | 13309 | modeset_update_crtc_power_domains(state); |
4740b0f2 | 13310 | } |
47fab737 | 13311 | |
a6778b3c | 13312 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13313 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13314 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13315 | bool modeset = needs_modeset(crtc->state); | |
bfd16b2a ML |
13316 | bool update_pipe = !modeset && |
13317 | to_intel_crtc_state(crtc->state)->update_pipe; | |
13318 | unsigned long put_domains = 0; | |
f6ac4b2a ML |
13319 | |
13320 | if (modeset && crtc->state->active) { | |
a539205a ML |
13321 | update_scanline_offset(to_intel_crtc(crtc)); |
13322 | dev_priv->display.crtc_enable(crtc); | |
13323 | } | |
80715b2f | 13324 | |
bfd16b2a ML |
13325 | if (update_pipe) { |
13326 | put_domains = modeset_get_crtc_power_domains(crtc); | |
13327 | ||
13328 | /* make sure intel_modeset_check_state runs */ | |
13329 | any_ms = true; | |
13330 | } | |
13331 | ||
f6ac4b2a ML |
13332 | if (!modeset) |
13333 | intel_pre_plane_update(intel_crtc); | |
13334 | ||
6173ee28 ML |
13335 | if (crtc->state->active && |
13336 | (crtc->state->planes_changed || update_pipe)) | |
62852622 | 13337 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
bfd16b2a ML |
13338 | |
13339 | if (put_domains) | |
13340 | modeset_put_power_domains(dev_priv, put_domains); | |
13341 | ||
f6ac4b2a | 13342 | intel_post_plane_update(intel_crtc); |
80715b2f | 13343 | } |
a6778b3c | 13344 | |
a6778b3c | 13345 | /* FIXME: add subpixel order */ |
83a57153 | 13346 | |
74c090b1 | 13347 | drm_atomic_helper_wait_for_vblanks(dev, state); |
f935675f ML |
13348 | |
13349 | mutex_lock(&dev->struct_mutex); | |
d4afb8cc | 13350 | drm_atomic_helper_cleanup_planes(dev, state); |
f935675f | 13351 | mutex_unlock(&dev->struct_mutex); |
2bfb4627 | 13352 | |
74c090b1 | 13353 | if (any_ms) |
ee165b1a ML |
13354 | intel_modeset_check_state(dev, state); |
13355 | ||
13356 | drm_atomic_state_free(state); | |
f30da187 | 13357 | |
74c090b1 | 13358 | return 0; |
7f27126e JB |
13359 | } |
13360 | ||
c0c36b94 CW |
13361 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13362 | { | |
83a57153 ACO |
13363 | struct drm_device *dev = crtc->dev; |
13364 | struct drm_atomic_state *state; | |
e694eb02 | 13365 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13366 | int ret; |
83a57153 ACO |
13367 | |
13368 | state = drm_atomic_state_alloc(dev); | |
13369 | if (!state) { | |
e694eb02 | 13370 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13371 | crtc->base.id); |
13372 | return; | |
13373 | } | |
13374 | ||
e694eb02 | 13375 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13376 | |
e694eb02 ML |
13377 | retry: |
13378 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13379 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13380 | if (!ret) { | |
13381 | if (!crtc_state->active) | |
13382 | goto out; | |
83a57153 | 13383 | |
e694eb02 | 13384 | crtc_state->mode_changed = true; |
74c090b1 | 13385 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13386 | } |
13387 | ||
e694eb02 ML |
13388 | if (ret == -EDEADLK) { |
13389 | drm_atomic_state_clear(state); | |
13390 | drm_modeset_backoff(state->acquire_ctx); | |
13391 | goto retry; | |
4ed9fb37 | 13392 | } |
4be07317 | 13393 | |
2bfb4627 | 13394 | if (ret) |
e694eb02 | 13395 | out: |
2bfb4627 | 13396 | drm_atomic_state_free(state); |
c0c36b94 CW |
13397 | } |
13398 | ||
25c5b266 DV |
13399 | #undef for_each_intel_crtc_masked |
13400 | ||
f6e5b160 | 13401 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13402 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13403 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13404 | .destroy = intel_crtc_destroy, |
13405 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13406 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13407 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13408 | }; |
13409 | ||
5358901f DV |
13410 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13411 | struct intel_shared_dpll *pll, | |
13412 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13413 | { |
5358901f | 13414 | uint32_t val; |
ee7b9f93 | 13415 | |
f458ebbc | 13416 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13417 | return false; |
13418 | ||
5358901f | 13419 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13420 | hw_state->dpll = val; |
13421 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13422 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13423 | |
13424 | return val & DPLL_VCO_ENABLE; | |
13425 | } | |
13426 | ||
15bdd4cf DV |
13427 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13428 | struct intel_shared_dpll *pll) | |
13429 | { | |
3e369b76 ACO |
13430 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13431 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13432 | } |
13433 | ||
e7b903d2 DV |
13434 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13435 | struct intel_shared_dpll *pll) | |
13436 | { | |
e7b903d2 | 13437 | /* PCH refclock must be enabled first */ |
89eff4be | 13438 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13439 | |
3e369b76 | 13440 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13441 | |
13442 | /* Wait for the clocks to stabilize. */ | |
13443 | POSTING_READ(PCH_DPLL(pll->id)); | |
13444 | udelay(150); | |
13445 | ||
13446 | /* The pixel multiplier can only be updated once the | |
13447 | * DPLL is enabled and the clocks are stable. | |
13448 | * | |
13449 | * So write it again. | |
13450 | */ | |
3e369b76 | 13451 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13452 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13453 | udelay(200); |
13454 | } | |
13455 | ||
13456 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13457 | struct intel_shared_dpll *pll) | |
13458 | { | |
13459 | struct drm_device *dev = dev_priv->dev; | |
13460 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13461 | |
13462 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13463 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13464 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13465 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13466 | } |
13467 | ||
15bdd4cf DV |
13468 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13469 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13470 | udelay(200); |
13471 | } | |
13472 | ||
46edb027 DV |
13473 | static char *ibx_pch_dpll_names[] = { |
13474 | "PCH DPLL A", | |
13475 | "PCH DPLL B", | |
13476 | }; | |
13477 | ||
7c74ade1 | 13478 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13479 | { |
e7b903d2 | 13480 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13481 | int i; |
13482 | ||
7c74ade1 | 13483 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13484 | |
e72f9fbf | 13485 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13486 | dev_priv->shared_dplls[i].id = i; |
13487 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13488 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13489 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13490 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13491 | dev_priv->shared_dplls[i].get_hw_state = |
13492 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13493 | } |
13494 | } | |
13495 | ||
7c74ade1 DV |
13496 | static void intel_shared_dpll_init(struct drm_device *dev) |
13497 | { | |
e7b903d2 | 13498 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13499 | |
9cd86933 DV |
13500 | if (HAS_DDI(dev)) |
13501 | intel_ddi_pll_init(dev); | |
13502 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13503 | ibx_pch_dpll_init(dev); |
13504 | else | |
13505 | dev_priv->num_shared_dpll = 0; | |
13506 | ||
13507 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13508 | } |
13509 | ||
6beb8c23 MR |
13510 | /** |
13511 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13512 | * @plane: drm plane to prepare for | |
13513 | * @fb: framebuffer to prepare for presentation | |
13514 | * | |
13515 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13516 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13517 | * bits. Some older platforms need special physical address handling for | |
13518 | * cursor planes. | |
13519 | * | |
f935675f ML |
13520 | * Must be called with struct_mutex held. |
13521 | * | |
6beb8c23 MR |
13522 | * Returns 0 on success, negative error code on failure. |
13523 | */ | |
13524 | int | |
13525 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 13526 | const struct drm_plane_state *new_state) |
465c120c MR |
13527 | { |
13528 | struct drm_device *dev = plane->dev; | |
844f9111 | 13529 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 13530 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 | 13531 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 13532 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
6beb8c23 | 13533 | int ret = 0; |
465c120c | 13534 | |
1ee49399 | 13535 | if (!obj && !old_obj) |
465c120c MR |
13536 | return 0; |
13537 | ||
5008e874 ML |
13538 | if (old_obj) { |
13539 | struct drm_crtc_state *crtc_state = | |
13540 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13541 | ||
13542 | /* Big Hammer, we also need to ensure that any pending | |
13543 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13544 | * current scanout is retired before unpinning the old | |
13545 | * framebuffer. Note that we rely on userspace rendering | |
13546 | * into the buffer attached to the pipe they are waiting | |
13547 | * on. If not, userspace generates a GPU hang with IPEHR | |
13548 | * point to the MI_WAIT_FOR_EVENT. | |
13549 | * | |
13550 | * This should only fail upon a hung GPU, in which case we | |
13551 | * can safely continue. | |
13552 | */ | |
13553 | if (needs_modeset(crtc_state)) | |
13554 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13555 | ||
13556 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13557 | if (ret && ret != -EIO) | |
f935675f | 13558 | return ret; |
5008e874 ML |
13559 | } |
13560 | ||
1ee49399 ML |
13561 | if (!obj) { |
13562 | ret = 0; | |
13563 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
6beb8c23 MR |
13564 | INTEL_INFO(dev)->cursor_needs_physical) { |
13565 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13566 | ret = i915_gem_object_attach_phys(obj, align); | |
13567 | if (ret) | |
13568 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13569 | } else { | |
7580d774 | 13570 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state); |
6beb8c23 | 13571 | } |
465c120c | 13572 | |
7580d774 ML |
13573 | if (ret == 0) { |
13574 | if (obj) { | |
13575 | struct intel_plane_state *plane_state = | |
13576 | to_intel_plane_state(new_state); | |
13577 | ||
13578 | i915_gem_request_assign(&plane_state->wait_req, | |
13579 | obj->last_write_req); | |
13580 | } | |
13581 | ||
a9ff8714 | 13582 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
7580d774 | 13583 | } |
fdd508a6 | 13584 | |
6beb8c23 MR |
13585 | return ret; |
13586 | } | |
13587 | ||
38f3ce3a MR |
13588 | /** |
13589 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13590 | * @plane: drm plane to clean up for | |
13591 | * @fb: old framebuffer that was on plane | |
13592 | * | |
13593 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
13594 | * |
13595 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
13596 | */ |
13597 | void | |
13598 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 13599 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
13600 | { |
13601 | struct drm_device *dev = plane->dev; | |
1ee49399 | 13602 | struct intel_plane *intel_plane = to_intel_plane(plane); |
7580d774 | 13603 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
13604 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
13605 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 13606 | |
7580d774 ML |
13607 | old_intel_state = to_intel_plane_state(old_state); |
13608 | ||
1ee49399 | 13609 | if (!obj && !old_obj) |
38f3ce3a MR |
13610 | return; |
13611 | ||
1ee49399 ML |
13612 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
13613 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
844f9111 | 13614 | intel_unpin_fb_obj(old_state->fb, old_state); |
1ee49399 ML |
13615 | |
13616 | /* prepare_fb aborted? */ | |
13617 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
13618 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
13619 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
7580d774 ML |
13620 | |
13621 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
13622 | ||
465c120c MR |
13623 | } |
13624 | ||
6156a456 CK |
13625 | int |
13626 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13627 | { | |
13628 | int max_scale; | |
13629 | struct drm_device *dev; | |
13630 | struct drm_i915_private *dev_priv; | |
13631 | int crtc_clock, cdclk; | |
13632 | ||
13633 | if (!intel_crtc || !crtc_state) | |
13634 | return DRM_PLANE_HELPER_NO_SCALING; | |
13635 | ||
13636 | dev = intel_crtc->base.dev; | |
13637 | dev_priv = dev->dev_private; | |
13638 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 13639 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 13640 | |
54bf1ce6 | 13641 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
13642 | return DRM_PLANE_HELPER_NO_SCALING; |
13643 | ||
13644 | /* | |
13645 | * skl max scale is lower of: | |
13646 | * close to 3 but not 3, -1 is for that purpose | |
13647 | * or | |
13648 | * cdclk/crtc_clock | |
13649 | */ | |
13650 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13651 | ||
13652 | return max_scale; | |
13653 | } | |
13654 | ||
465c120c | 13655 | static int |
3c692a41 | 13656 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13657 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13658 | struct intel_plane_state *state) |
13659 | { | |
2b875c22 MR |
13660 | struct drm_crtc *crtc = state->base.crtc; |
13661 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13662 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13663 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13664 | bool can_position = false; | |
465c120c | 13665 | |
061e4b8d ML |
13666 | /* use scaler when colorkey is not required */ |
13667 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
818ed961 | 13668 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
061e4b8d ML |
13669 | min_scale = 1; |
13670 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13671 | can_position = true; |
6156a456 | 13672 | } |
d8106366 | 13673 | |
061e4b8d ML |
13674 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13675 | &state->dst, &state->clip, | |
da20eabd ML |
13676 | min_scale, max_scale, |
13677 | can_position, true, | |
13678 | &state->visible); | |
14af293f GP |
13679 | } |
13680 | ||
13681 | static void | |
13682 | intel_commit_primary_plane(struct drm_plane *plane, | |
13683 | struct intel_plane_state *state) | |
13684 | { | |
2b875c22 MR |
13685 | struct drm_crtc *crtc = state->base.crtc; |
13686 | struct drm_framebuffer *fb = state->base.fb; | |
13687 | struct drm_device *dev = plane->dev; | |
14af293f | 13688 | struct drm_i915_private *dev_priv = dev->dev_private; |
14af293f | 13689 | |
ea2c67bb | 13690 | crtc = crtc ? crtc : plane->crtc; |
ccc759dc | 13691 | |
d4b08630 ML |
13692 | dev_priv->display.update_primary_plane(crtc, fb, |
13693 | state->src.x1 >> 16, | |
13694 | state->src.y1 >> 16); | |
465c120c MR |
13695 | } |
13696 | ||
a8ad0d8e ML |
13697 | static void |
13698 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13699 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13700 | { |
13701 | struct drm_device *dev = plane->dev; | |
13702 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13703 | ||
a8ad0d8e ML |
13704 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13705 | } | |
13706 | ||
613d2b27 ML |
13707 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
13708 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 13709 | { |
32b7eeec | 13710 | struct drm_device *dev = crtc->dev; |
3c692a41 | 13711 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
bfd16b2a ML |
13712 | struct intel_crtc_state *old_intel_state = |
13713 | to_intel_crtc_state(old_crtc_state); | |
13714 | bool modeset = needs_modeset(crtc->state); | |
3c692a41 | 13715 | |
f015c551 | 13716 | if (intel_crtc->atomic.update_wm_pre) |
32b7eeec | 13717 | intel_update_watermarks(crtc); |
3c692a41 | 13718 | |
c34c9ee4 | 13719 | /* Perform vblank evasion around commit operation */ |
62852622 | 13720 | intel_pipe_update_start(intel_crtc); |
0583236e | 13721 | |
bfd16b2a ML |
13722 | if (modeset) |
13723 | return; | |
13724 | ||
13725 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
13726 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
13727 | else if (INTEL_INFO(dev)->gen >= 9) | |
0583236e | 13728 | skl_detach_scalers(intel_crtc); |
32b7eeec MR |
13729 | } |
13730 | ||
613d2b27 ML |
13731 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
13732 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 13733 | { |
32b7eeec | 13734 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 13735 | |
62852622 | 13736 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
13737 | } |
13738 | ||
cf4c7c12 | 13739 | /** |
4a3b8769 MR |
13740 | * intel_plane_destroy - destroy a plane |
13741 | * @plane: plane to destroy | |
cf4c7c12 | 13742 | * |
4a3b8769 MR |
13743 | * Common destruction function for all types of planes (primary, cursor, |
13744 | * sprite). | |
cf4c7c12 | 13745 | */ |
4a3b8769 | 13746 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13747 | { |
13748 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13749 | drm_plane_cleanup(plane); | |
13750 | kfree(intel_plane); | |
13751 | } | |
13752 | ||
65a3fea0 | 13753 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13754 | .update_plane = drm_atomic_helper_update_plane, |
13755 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13756 | .destroy = intel_plane_destroy, |
c196e1d6 | 13757 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13758 | .atomic_get_property = intel_plane_atomic_get_property, |
13759 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13760 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13761 | .atomic_destroy_state = intel_plane_destroy_state, | |
13762 | ||
465c120c MR |
13763 | }; |
13764 | ||
13765 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13766 | int pipe) | |
13767 | { | |
13768 | struct intel_plane *primary; | |
8e7d688b | 13769 | struct intel_plane_state *state; |
465c120c | 13770 | const uint32_t *intel_primary_formats; |
45e3743a | 13771 | unsigned int num_formats; |
465c120c MR |
13772 | |
13773 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13774 | if (primary == NULL) | |
13775 | return NULL; | |
13776 | ||
8e7d688b MR |
13777 | state = intel_create_plane_state(&primary->base); |
13778 | if (!state) { | |
ea2c67bb MR |
13779 | kfree(primary); |
13780 | return NULL; | |
13781 | } | |
8e7d688b | 13782 | primary->base.state = &state->base; |
ea2c67bb | 13783 | |
465c120c MR |
13784 | primary->can_scale = false; |
13785 | primary->max_downscale = 1; | |
6156a456 CK |
13786 | if (INTEL_INFO(dev)->gen >= 9) { |
13787 | primary->can_scale = true; | |
af99ceda | 13788 | state->scaler_id = -1; |
6156a456 | 13789 | } |
465c120c MR |
13790 | primary->pipe = pipe; |
13791 | primary->plane = pipe; | |
a9ff8714 | 13792 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 MR |
13793 | primary->check_plane = intel_check_primary_plane; |
13794 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13795 | primary->disable_plane = intel_disable_primary_plane; |
465c120c MR |
13796 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13797 | primary->plane = !pipe; | |
13798 | ||
6c0fd451 DL |
13799 | if (INTEL_INFO(dev)->gen >= 9) { |
13800 | intel_primary_formats = skl_primary_formats; | |
13801 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13802 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13803 | intel_primary_formats = i965_primary_formats; |
13804 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13805 | } else { |
13806 | intel_primary_formats = i8xx_primary_formats; | |
13807 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13808 | } |
13809 | ||
13810 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13811 | &intel_plane_funcs, |
465c120c MR |
13812 | intel_primary_formats, num_formats, |
13813 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13814 | |
3b7a5119 SJ |
13815 | if (INTEL_INFO(dev)->gen >= 4) |
13816 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13817 | |
ea2c67bb MR |
13818 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13819 | ||
465c120c MR |
13820 | return &primary->base; |
13821 | } | |
13822 | ||
3b7a5119 SJ |
13823 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13824 | { | |
13825 | if (!dev->mode_config.rotation_property) { | |
13826 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13827 | BIT(DRM_ROTATE_180); | |
13828 | ||
13829 | if (INTEL_INFO(dev)->gen >= 9) | |
13830 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13831 | ||
13832 | dev->mode_config.rotation_property = | |
13833 | drm_mode_create_rotation_property(dev, flags); | |
13834 | } | |
13835 | if (dev->mode_config.rotation_property) | |
13836 | drm_object_attach_property(&plane->base.base, | |
13837 | dev->mode_config.rotation_property, | |
13838 | plane->base.state->rotation); | |
13839 | } | |
13840 | ||
3d7d6510 | 13841 | static int |
852e787c | 13842 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 13843 | struct intel_crtc_state *crtc_state, |
852e787c | 13844 | struct intel_plane_state *state) |
3d7d6510 | 13845 | { |
061e4b8d | 13846 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 13847 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 13848 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
13849 | unsigned stride; |
13850 | int ret; | |
3d7d6510 | 13851 | |
061e4b8d ML |
13852 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13853 | &state->dst, &state->clip, | |
3d7d6510 MR |
13854 | DRM_PLANE_HELPER_NO_SCALING, |
13855 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13856 | true, true, &state->visible); |
757f9a3e GP |
13857 | if (ret) |
13858 | return ret; | |
13859 | ||
757f9a3e GP |
13860 | /* if we want to turn off the cursor ignore width and height */ |
13861 | if (!obj) | |
da20eabd | 13862 | return 0; |
757f9a3e | 13863 | |
757f9a3e | 13864 | /* Check for which cursor types we support */ |
061e4b8d | 13865 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
13866 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
13867 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13868 | return -EINVAL; |
13869 | } | |
13870 | ||
ea2c67bb MR |
13871 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13872 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13873 | DRM_DEBUG_KMS("buffer is too small\n"); |
13874 | return -ENOMEM; | |
13875 | } | |
13876 | ||
3a656b54 | 13877 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 13878 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 13879 | return -EINVAL; |
32b7eeec MR |
13880 | } |
13881 | ||
da20eabd | 13882 | return 0; |
852e787c | 13883 | } |
3d7d6510 | 13884 | |
a8ad0d8e ML |
13885 | static void |
13886 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 13887 | struct drm_crtc *crtc) |
a8ad0d8e | 13888 | { |
a8ad0d8e ML |
13889 | intel_crtc_update_cursor(crtc, false); |
13890 | } | |
13891 | ||
f4a2cf29 | 13892 | static void |
852e787c GP |
13893 | intel_commit_cursor_plane(struct drm_plane *plane, |
13894 | struct intel_plane_state *state) | |
13895 | { | |
2b875c22 | 13896 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
13897 | struct drm_device *dev = plane->dev; |
13898 | struct intel_crtc *intel_crtc; | |
2b875c22 | 13899 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 13900 | uint32_t addr; |
852e787c | 13901 | |
ea2c67bb MR |
13902 | crtc = crtc ? crtc : plane->crtc; |
13903 | intel_crtc = to_intel_crtc(crtc); | |
13904 | ||
a912f12f GP |
13905 | if (intel_crtc->cursor_bo == obj) |
13906 | goto update; | |
4ed91096 | 13907 | |
f4a2cf29 | 13908 | if (!obj) |
a912f12f | 13909 | addr = 0; |
f4a2cf29 | 13910 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 13911 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 13912 | else |
a912f12f | 13913 | addr = obj->phys_handle->busaddr; |
852e787c | 13914 | |
a912f12f GP |
13915 | intel_crtc->cursor_addr = addr; |
13916 | intel_crtc->cursor_bo = obj; | |
852e787c | 13917 | |
302d19ac | 13918 | update: |
62852622 | 13919 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
13920 | } |
13921 | ||
3d7d6510 MR |
13922 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
13923 | int pipe) | |
13924 | { | |
13925 | struct intel_plane *cursor; | |
8e7d688b | 13926 | struct intel_plane_state *state; |
3d7d6510 MR |
13927 | |
13928 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
13929 | if (cursor == NULL) | |
13930 | return NULL; | |
13931 | ||
8e7d688b MR |
13932 | state = intel_create_plane_state(&cursor->base); |
13933 | if (!state) { | |
ea2c67bb MR |
13934 | kfree(cursor); |
13935 | return NULL; | |
13936 | } | |
8e7d688b | 13937 | cursor->base.state = &state->base; |
ea2c67bb | 13938 | |
3d7d6510 MR |
13939 | cursor->can_scale = false; |
13940 | cursor->max_downscale = 1; | |
13941 | cursor->pipe = pipe; | |
13942 | cursor->plane = pipe; | |
a9ff8714 | 13943 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 MR |
13944 | cursor->check_plane = intel_check_cursor_plane; |
13945 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 13946 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
13947 | |
13948 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 13949 | &intel_plane_funcs, |
3d7d6510 MR |
13950 | intel_cursor_formats, |
13951 | ARRAY_SIZE(intel_cursor_formats), | |
13952 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
13953 | |
13954 | if (INTEL_INFO(dev)->gen >= 4) { | |
13955 | if (!dev->mode_config.rotation_property) | |
13956 | dev->mode_config.rotation_property = | |
13957 | drm_mode_create_rotation_property(dev, | |
13958 | BIT(DRM_ROTATE_0) | | |
13959 | BIT(DRM_ROTATE_180)); | |
13960 | if (dev->mode_config.rotation_property) | |
13961 | drm_object_attach_property(&cursor->base.base, | |
13962 | dev->mode_config.rotation_property, | |
8e7d688b | 13963 | state->base.rotation); |
4398ad45 VS |
13964 | } |
13965 | ||
af99ceda CK |
13966 | if (INTEL_INFO(dev)->gen >=9) |
13967 | state->scaler_id = -1; | |
13968 | ||
ea2c67bb MR |
13969 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
13970 | ||
3d7d6510 MR |
13971 | return &cursor->base; |
13972 | } | |
13973 | ||
549e2bfb CK |
13974 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
13975 | struct intel_crtc_state *crtc_state) | |
13976 | { | |
13977 | int i; | |
13978 | struct intel_scaler *intel_scaler; | |
13979 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
13980 | ||
13981 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
13982 | intel_scaler = &scaler_state->scalers[i]; | |
13983 | intel_scaler->in_use = 0; | |
549e2bfb CK |
13984 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
13985 | } | |
13986 | ||
13987 | scaler_state->scaler_id = -1; | |
13988 | } | |
13989 | ||
b358d0a6 | 13990 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 13991 | { |
fbee40df | 13992 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 13993 | struct intel_crtc *intel_crtc; |
f5de6e07 | 13994 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
13995 | struct drm_plane *primary = NULL; |
13996 | struct drm_plane *cursor = NULL; | |
465c120c | 13997 | int i, ret; |
79e53945 | 13998 | |
955382f3 | 13999 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14000 | if (intel_crtc == NULL) |
14001 | return; | |
14002 | ||
f5de6e07 ACO |
14003 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14004 | if (!crtc_state) | |
14005 | goto fail; | |
550acefd ACO |
14006 | intel_crtc->config = crtc_state; |
14007 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14008 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14009 | |
549e2bfb CK |
14010 | /* initialize shared scalers */ |
14011 | if (INTEL_INFO(dev)->gen >= 9) { | |
14012 | if (pipe == PIPE_C) | |
14013 | intel_crtc->num_scalers = 1; | |
14014 | else | |
14015 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14016 | ||
14017 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14018 | } | |
14019 | ||
465c120c | 14020 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14021 | if (!primary) |
14022 | goto fail; | |
14023 | ||
14024 | cursor = intel_cursor_plane_create(dev, pipe); | |
14025 | if (!cursor) | |
14026 | goto fail; | |
14027 | ||
465c120c | 14028 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14029 | cursor, &intel_crtc_funcs); |
14030 | if (ret) | |
14031 | goto fail; | |
79e53945 JB |
14032 | |
14033 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14034 | for (i = 0; i < 256; i++) { |
14035 | intel_crtc->lut_r[i] = i; | |
14036 | intel_crtc->lut_g[i] = i; | |
14037 | intel_crtc->lut_b[i] = i; | |
14038 | } | |
14039 | ||
1f1c2e24 VS |
14040 | /* |
14041 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14042 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14043 | */ |
80824003 JB |
14044 | intel_crtc->pipe = pipe; |
14045 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14046 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14047 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14048 | intel_crtc->plane = !pipe; |
80824003 JB |
14049 | } |
14050 | ||
4b0e333e CW |
14051 | intel_crtc->cursor_base = ~0; |
14052 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14053 | intel_crtc->cursor_size = ~0; |
8d7849db | 14054 | |
852eb00d VS |
14055 | intel_crtc->wm.cxsr_allowed = true; |
14056 | ||
22fd0fab JB |
14057 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14058 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14059 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14060 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14061 | ||
79e53945 | 14062 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14063 | |
14064 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14065 | return; |
14066 | ||
14067 | fail: | |
14068 | if (primary) | |
14069 | drm_plane_cleanup(primary); | |
14070 | if (cursor) | |
14071 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14072 | kfree(crtc_state); |
3d7d6510 | 14073 | kfree(intel_crtc); |
79e53945 JB |
14074 | } |
14075 | ||
752aa88a JB |
14076 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14077 | { | |
14078 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14079 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14080 | |
51fd371b | 14081 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14082 | |
d3babd3f | 14083 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14084 | return INVALID_PIPE; |
14085 | ||
14086 | return to_intel_crtc(encoder->crtc)->pipe; | |
14087 | } | |
14088 | ||
08d7b3d1 | 14089 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14090 | struct drm_file *file) |
08d7b3d1 | 14091 | { |
08d7b3d1 | 14092 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14093 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14094 | struct intel_crtc *crtc; |
08d7b3d1 | 14095 | |
7707e653 | 14096 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14097 | |
7707e653 | 14098 | if (!drmmode_crtc) { |
08d7b3d1 | 14099 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14100 | return -ENOENT; |
08d7b3d1 CW |
14101 | } |
14102 | ||
7707e653 | 14103 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14104 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14105 | |
c05422d5 | 14106 | return 0; |
08d7b3d1 CW |
14107 | } |
14108 | ||
66a9278e | 14109 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14110 | { |
66a9278e DV |
14111 | struct drm_device *dev = encoder->base.dev; |
14112 | struct intel_encoder *source_encoder; | |
79e53945 | 14113 | int index_mask = 0; |
79e53945 JB |
14114 | int entry = 0; |
14115 | ||
b2784e15 | 14116 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14117 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14118 | index_mask |= (1 << entry); |
14119 | ||
79e53945 JB |
14120 | entry++; |
14121 | } | |
4ef69c7a | 14122 | |
79e53945 JB |
14123 | return index_mask; |
14124 | } | |
14125 | ||
4d302442 CW |
14126 | static bool has_edp_a(struct drm_device *dev) |
14127 | { | |
14128 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14129 | ||
14130 | if (!IS_MOBILE(dev)) | |
14131 | return false; | |
14132 | ||
14133 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14134 | return false; | |
14135 | ||
e3589908 | 14136 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14137 | return false; |
14138 | ||
14139 | return true; | |
14140 | } | |
14141 | ||
84b4e042 JB |
14142 | static bool intel_crt_present(struct drm_device *dev) |
14143 | { | |
14144 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14145 | ||
884497ed DL |
14146 | if (INTEL_INFO(dev)->gen >= 9) |
14147 | return false; | |
14148 | ||
cf404ce4 | 14149 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14150 | return false; |
14151 | ||
14152 | if (IS_CHERRYVIEW(dev)) | |
14153 | return false; | |
14154 | ||
14155 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
14156 | return false; | |
14157 | ||
14158 | return true; | |
14159 | } | |
14160 | ||
79e53945 JB |
14161 | static void intel_setup_outputs(struct drm_device *dev) |
14162 | { | |
725e30ad | 14163 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14164 | struct intel_encoder *encoder; |
cb0953d7 | 14165 | bool dpd_is_edp = false; |
79e53945 | 14166 | |
c9093354 | 14167 | intel_lvds_init(dev); |
79e53945 | 14168 | |
84b4e042 | 14169 | if (intel_crt_present(dev)) |
79935fca | 14170 | intel_crt_init(dev); |
cb0953d7 | 14171 | |
c776eb2e VK |
14172 | if (IS_BROXTON(dev)) { |
14173 | /* | |
14174 | * FIXME: Broxton doesn't support port detection via the | |
14175 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14176 | * detect the ports. | |
14177 | */ | |
14178 | intel_ddi_init(dev, PORT_A); | |
14179 | intel_ddi_init(dev, PORT_B); | |
14180 | intel_ddi_init(dev, PORT_C); | |
14181 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14182 | int found; |
14183 | ||
de31facd JB |
14184 | /* |
14185 | * Haswell uses DDI functions to detect digital outputs. | |
14186 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14187 | * it's there. | |
14188 | */ | |
77179400 | 14189 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14190 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14191 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14192 | intel_ddi_init(dev, PORT_A); |
14193 | ||
14194 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14195 | * register */ | |
14196 | found = I915_READ(SFUSE_STRAP); | |
14197 | ||
14198 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14199 | intel_ddi_init(dev, PORT_B); | |
14200 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14201 | intel_ddi_init(dev, PORT_C); | |
14202 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14203 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14204 | /* |
14205 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14206 | */ | |
ef11bdb3 | 14207 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14208 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14209 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14210 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14211 | intel_ddi_init(dev, PORT_E); | |
14212 | ||
0e72a5b5 | 14213 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14214 | int found; |
5d8a7752 | 14215 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14216 | |
14217 | if (has_edp_a(dev)) | |
14218 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14219 | |
dc0fa718 | 14220 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14221 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 14222 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 14223 | if (!found) |
e2debe91 | 14224 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14225 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14226 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14227 | } |
14228 | ||
dc0fa718 | 14229 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14230 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14231 | |
dc0fa718 | 14232 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14233 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14234 | |
5eb08b69 | 14235 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14236 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14237 | |
270b3042 | 14238 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14239 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14240 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14241 | /* |
14242 | * The DP_DETECTED bit is the latched state of the DDC | |
14243 | * SDA pin at boot. However since eDP doesn't require DDC | |
14244 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14245 | * eDP ports may have been muxed to an alternate function. | |
14246 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14247 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14248 | * detect eDP ports. | |
14249 | */ | |
e66eb81d | 14250 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
d2182a66 | 14251 | !intel_dp_is_edp(dev, PORT_B)) |
e66eb81d VS |
14252 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
14253 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
e17ac6db | 14254 | intel_dp_is_edp(dev, PORT_B)) |
e66eb81d | 14255 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
585a94b8 | 14256 | |
e66eb81d | 14257 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
d2182a66 | 14258 | !intel_dp_is_edp(dev, PORT_C)) |
e66eb81d VS |
14259 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
14260 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
e17ac6db | 14261 | intel_dp_is_edp(dev, PORT_C)) |
e66eb81d | 14262 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
19c03924 | 14263 | |
9418c1f1 | 14264 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14265 | /* eDP not supported on port D, so don't check VBT */ |
e66eb81d VS |
14266 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
14267 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14268 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14269 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
9418c1f1 VS |
14270 | } |
14271 | ||
3cfca973 | 14272 | intel_dsi_init(dev); |
09da55dc | 14273 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14274 | bool found = false; |
7d57382e | 14275 | |
e2debe91 | 14276 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14277 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 14278 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
3fec3d2f | 14279 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14280 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14281 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14282 | } |
27185ae1 | 14283 | |
3fec3d2f | 14284 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14285 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14286 | } |
13520b05 KH |
14287 | |
14288 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14289 | |
e2debe91 | 14290 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14291 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 14292 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 14293 | } |
27185ae1 | 14294 | |
e2debe91 | 14295 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14296 | |
3fec3d2f | 14297 | if (IS_G4X(dev)) { |
b01f2c3a | 14298 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14299 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14300 | } |
3fec3d2f | 14301 | if (IS_G4X(dev)) |
ab9d7c30 | 14302 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14303 | } |
27185ae1 | 14304 | |
3fec3d2f | 14305 | if (IS_G4X(dev) && |
e7281eab | 14306 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14307 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14308 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14309 | intel_dvo_init(dev); |
14310 | ||
103a196f | 14311 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14312 | intel_tv_init(dev); |
14313 | ||
0bc12bcb | 14314 | intel_psr_init(dev); |
7c8f8a70 | 14315 | |
b2784e15 | 14316 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14317 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14318 | encoder->base.possible_clones = | |
66a9278e | 14319 | intel_encoder_clones(encoder); |
79e53945 | 14320 | } |
47356eb6 | 14321 | |
dde86e2d | 14322 | intel_init_pch_refclk(dev); |
270b3042 DV |
14323 | |
14324 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14325 | } |
14326 | ||
14327 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14328 | { | |
60a5ca01 | 14329 | struct drm_device *dev = fb->dev; |
79e53945 | 14330 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14331 | |
ef2d633e | 14332 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14333 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14334 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14335 | drm_gem_object_unreference(&intel_fb->obj->base); |
14336 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14337 | kfree(intel_fb); |
14338 | } | |
14339 | ||
14340 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14341 | struct drm_file *file, |
79e53945 JB |
14342 | unsigned int *handle) |
14343 | { | |
14344 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14345 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14346 | |
05394f39 | 14347 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14348 | } |
14349 | ||
86c98588 RV |
14350 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14351 | struct drm_file *file, | |
14352 | unsigned flags, unsigned color, | |
14353 | struct drm_clip_rect *clips, | |
14354 | unsigned num_clips) | |
14355 | { | |
14356 | struct drm_device *dev = fb->dev; | |
14357 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14358 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14359 | ||
14360 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14361 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14362 | mutex_unlock(&dev->struct_mutex); |
14363 | ||
14364 | return 0; | |
14365 | } | |
14366 | ||
79e53945 JB |
14367 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14368 | .destroy = intel_user_framebuffer_destroy, | |
14369 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14370 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14371 | }; |
14372 | ||
b321803d DL |
14373 | static |
14374 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14375 | uint32_t pixel_format) | |
14376 | { | |
14377 | u32 gen = INTEL_INFO(dev)->gen; | |
14378 | ||
14379 | if (gen >= 9) { | |
14380 | /* "The stride in bytes must not exceed the of the size of 8K | |
14381 | * pixels and 32K bytes." | |
14382 | */ | |
14383 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14384 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14385 | return 32*1024; | |
14386 | } else if (gen >= 4) { | |
14387 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14388 | return 16*1024; | |
14389 | else | |
14390 | return 32*1024; | |
14391 | } else if (gen >= 3) { | |
14392 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14393 | return 8*1024; | |
14394 | else | |
14395 | return 16*1024; | |
14396 | } else { | |
14397 | /* XXX DSPC is limited to 4k tiled */ | |
14398 | return 8*1024; | |
14399 | } | |
14400 | } | |
14401 | ||
b5ea642a DV |
14402 | static int intel_framebuffer_init(struct drm_device *dev, |
14403 | struct intel_framebuffer *intel_fb, | |
14404 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14405 | struct drm_i915_gem_object *obj) | |
79e53945 | 14406 | { |
6761dd31 | 14407 | unsigned int aligned_height; |
79e53945 | 14408 | int ret; |
b321803d | 14409 | u32 pitch_limit, stride_alignment; |
79e53945 | 14410 | |
dd4916c5 DV |
14411 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14412 | ||
2a80eada DV |
14413 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14414 | /* Enforce that fb modifier and tiling mode match, but only for | |
14415 | * X-tiled. This is needed for FBC. */ | |
14416 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14417 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14418 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14419 | return -EINVAL; | |
14420 | } | |
14421 | } else { | |
14422 | if (obj->tiling_mode == I915_TILING_X) | |
14423 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14424 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14425 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14426 | return -EINVAL; | |
14427 | } | |
14428 | } | |
14429 | ||
9a8f0a12 TU |
14430 | /* Passed in modifier sanity checking. */ |
14431 | switch (mode_cmd->modifier[0]) { | |
14432 | case I915_FORMAT_MOD_Y_TILED: | |
14433 | case I915_FORMAT_MOD_Yf_TILED: | |
14434 | if (INTEL_INFO(dev)->gen < 9) { | |
14435 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14436 | mode_cmd->modifier[0]); | |
14437 | return -EINVAL; | |
14438 | } | |
14439 | case DRM_FORMAT_MOD_NONE: | |
14440 | case I915_FORMAT_MOD_X_TILED: | |
14441 | break; | |
14442 | default: | |
c0f40428 JB |
14443 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14444 | mode_cmd->modifier[0]); | |
57cd6508 | 14445 | return -EINVAL; |
c16ed4be | 14446 | } |
57cd6508 | 14447 | |
b321803d DL |
14448 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14449 | mode_cmd->pixel_format); | |
14450 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14451 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14452 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14453 | return -EINVAL; |
c16ed4be | 14454 | } |
57cd6508 | 14455 | |
b321803d DL |
14456 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14457 | mode_cmd->pixel_format); | |
a35cdaa0 | 14458 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14459 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14460 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14461 | "tiled" : "linear", |
a35cdaa0 | 14462 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14463 | return -EINVAL; |
c16ed4be | 14464 | } |
5d7bd705 | 14465 | |
2a80eada | 14466 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14467 | mode_cmd->pitches[0] != obj->stride) { |
14468 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14469 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14470 | return -EINVAL; |
c16ed4be | 14471 | } |
5d7bd705 | 14472 | |
57779d06 | 14473 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14474 | switch (mode_cmd->pixel_format) { |
57779d06 | 14475 | case DRM_FORMAT_C8: |
04b3924d VS |
14476 | case DRM_FORMAT_RGB565: |
14477 | case DRM_FORMAT_XRGB8888: | |
14478 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14479 | break; |
14480 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14481 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14482 | DRM_DEBUG("unsupported pixel format: %s\n", |
14483 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14484 | return -EINVAL; |
c16ed4be | 14485 | } |
57779d06 | 14486 | break; |
57779d06 | 14487 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14488 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14489 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14490 | drm_get_format_name(mode_cmd->pixel_format)); | |
14491 | return -EINVAL; | |
14492 | } | |
14493 | break; | |
14494 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14495 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14496 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14497 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14498 | DRM_DEBUG("unsupported pixel format: %s\n", |
14499 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14500 | return -EINVAL; |
c16ed4be | 14501 | } |
b5626747 | 14502 | break; |
7531208b DL |
14503 | case DRM_FORMAT_ABGR2101010: |
14504 | if (!IS_VALLEYVIEW(dev)) { | |
14505 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14506 | drm_get_format_name(mode_cmd->pixel_format)); | |
14507 | return -EINVAL; | |
14508 | } | |
14509 | break; | |
04b3924d VS |
14510 | case DRM_FORMAT_YUYV: |
14511 | case DRM_FORMAT_UYVY: | |
14512 | case DRM_FORMAT_YVYU: | |
14513 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14514 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14515 | DRM_DEBUG("unsupported pixel format: %s\n", |
14516 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14517 | return -EINVAL; |
c16ed4be | 14518 | } |
57cd6508 CW |
14519 | break; |
14520 | default: | |
4ee62c76 VS |
14521 | DRM_DEBUG("unsupported pixel format: %s\n", |
14522 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14523 | return -EINVAL; |
14524 | } | |
14525 | ||
90f9a336 VS |
14526 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14527 | if (mode_cmd->offsets[0] != 0) | |
14528 | return -EINVAL; | |
14529 | ||
ec2c981e | 14530 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14531 | mode_cmd->pixel_format, |
14532 | mode_cmd->modifier[0]); | |
53155c0a DV |
14533 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14534 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14535 | return -EINVAL; | |
14536 | ||
c7d73f6a DV |
14537 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14538 | intel_fb->obj = obj; | |
80075d49 | 14539 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14540 | |
79e53945 JB |
14541 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14542 | if (ret) { | |
14543 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14544 | return ret; | |
14545 | } | |
14546 | ||
79e53945 JB |
14547 | return 0; |
14548 | } | |
14549 | ||
79e53945 JB |
14550 | static struct drm_framebuffer * |
14551 | intel_user_framebuffer_create(struct drm_device *dev, | |
14552 | struct drm_file *filp, | |
308e5bcb | 14553 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14554 | { |
dcb1394e | 14555 | struct drm_framebuffer *fb; |
05394f39 | 14556 | struct drm_i915_gem_object *obj; |
79e53945 | 14557 | |
308e5bcb JB |
14558 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14559 | mode_cmd->handles[0])); | |
c8725226 | 14560 | if (&obj->base == NULL) |
cce13ff7 | 14561 | return ERR_PTR(-ENOENT); |
79e53945 | 14562 | |
dcb1394e LW |
14563 | fb = intel_framebuffer_create(dev, mode_cmd, obj); |
14564 | if (IS_ERR(fb)) | |
14565 | drm_gem_object_unreference_unlocked(&obj->base); | |
14566 | ||
14567 | return fb; | |
79e53945 JB |
14568 | } |
14569 | ||
0695726e | 14570 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 14571 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14572 | { |
14573 | } | |
14574 | #endif | |
14575 | ||
79e53945 | 14576 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14577 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14578 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14579 | .atomic_check = intel_atomic_check, |
14580 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14581 | .atomic_state_alloc = intel_atomic_state_alloc, |
14582 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14583 | }; |
14584 | ||
e70236a8 JB |
14585 | /* Set up chip specific display functions */ |
14586 | static void intel_init_display(struct drm_device *dev) | |
14587 | { | |
14588 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14589 | ||
ee9300bb DV |
14590 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14591 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14592 | else if (IS_CHERRYVIEW(dev)) |
14593 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14594 | else if (IS_VALLEYVIEW(dev)) |
14595 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14596 | else if (IS_PINEVIEW(dev)) | |
14597 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14598 | else | |
14599 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14600 | ||
bc8d7dff DL |
14601 | if (INTEL_INFO(dev)->gen >= 9) { |
14602 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14603 | dev_priv->display.get_initial_plane_config = |
14604 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14605 | dev_priv->display.crtc_compute_clock = |
14606 | haswell_crtc_compute_clock; | |
14607 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14608 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14609 | dev_priv->display.update_primary_plane = |
14610 | skylake_update_primary_plane; | |
14611 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14612 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14613 | dev_priv->display.get_initial_plane_config = |
14614 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14615 | dev_priv->display.crtc_compute_clock = |
14616 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14617 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14618 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14619 | dev_priv->display.update_primary_plane = |
14620 | ironlake_update_primary_plane; | |
09b4ddf9 | 14621 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14622 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14623 | dev_priv->display.get_initial_plane_config = |
14624 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14625 | dev_priv->display.crtc_compute_clock = |
14626 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14627 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14628 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14629 | dev_priv->display.update_primary_plane = |
14630 | ironlake_update_primary_plane; | |
89b667f8 JB |
14631 | } else if (IS_VALLEYVIEW(dev)) { |
14632 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14633 | dev_priv->display.get_initial_plane_config = |
14634 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14635 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14636 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14637 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14638 | dev_priv->display.update_primary_plane = |
14639 | i9xx_update_primary_plane; | |
f564048e | 14640 | } else { |
0e8ffe1b | 14641 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14642 | dev_priv->display.get_initial_plane_config = |
14643 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14644 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14645 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14646 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14647 | dev_priv->display.update_primary_plane = |
14648 | i9xx_update_primary_plane; | |
f564048e | 14649 | } |
e70236a8 | 14650 | |
e70236a8 | 14651 | /* Returns the core display clock speed */ |
ef11bdb3 | 14652 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
1652d19e VS |
14653 | dev_priv->display.get_display_clock_speed = |
14654 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
14655 | else if (IS_BROXTON(dev)) |
14656 | dev_priv->display.get_display_clock_speed = | |
14657 | broxton_get_display_clock_speed; | |
1652d19e VS |
14658 | else if (IS_BROADWELL(dev)) |
14659 | dev_priv->display.get_display_clock_speed = | |
14660 | broadwell_get_display_clock_speed; | |
14661 | else if (IS_HASWELL(dev)) | |
14662 | dev_priv->display.get_display_clock_speed = | |
14663 | haswell_get_display_clock_speed; | |
14664 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14665 | dev_priv->display.get_display_clock_speed = |
14666 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14667 | else if (IS_GEN5(dev)) |
14668 | dev_priv->display.get_display_clock_speed = | |
14669 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14670 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14671 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14672 | dev_priv->display.get_display_clock_speed = |
14673 | i945_get_display_clock_speed; | |
34edce2f VS |
14674 | else if (IS_GM45(dev)) |
14675 | dev_priv->display.get_display_clock_speed = | |
14676 | gm45_get_display_clock_speed; | |
14677 | else if (IS_CRESTLINE(dev)) | |
14678 | dev_priv->display.get_display_clock_speed = | |
14679 | i965gm_get_display_clock_speed; | |
14680 | else if (IS_PINEVIEW(dev)) | |
14681 | dev_priv->display.get_display_clock_speed = | |
14682 | pnv_get_display_clock_speed; | |
14683 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14684 | dev_priv->display.get_display_clock_speed = | |
14685 | g33_get_display_clock_speed; | |
e70236a8 JB |
14686 | else if (IS_I915G(dev)) |
14687 | dev_priv->display.get_display_clock_speed = | |
14688 | i915_get_display_clock_speed; | |
257a7ffc | 14689 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14690 | dev_priv->display.get_display_clock_speed = |
14691 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14692 | else if (IS_PINEVIEW(dev)) |
14693 | dev_priv->display.get_display_clock_speed = | |
14694 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14695 | else if (IS_I915GM(dev)) |
14696 | dev_priv->display.get_display_clock_speed = | |
14697 | i915gm_get_display_clock_speed; | |
14698 | else if (IS_I865G(dev)) | |
14699 | dev_priv->display.get_display_clock_speed = | |
14700 | i865_get_display_clock_speed; | |
f0f8a9ce | 14701 | else if (IS_I85X(dev)) |
e70236a8 | 14702 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14703 | i85x_get_display_clock_speed; |
623e01e5 VS |
14704 | else { /* 830 */ |
14705 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14706 | dev_priv->display.get_display_clock_speed = |
14707 | i830_get_display_clock_speed; | |
623e01e5 | 14708 | } |
e70236a8 | 14709 | |
7c10a2b5 | 14710 | if (IS_GEN5(dev)) { |
3bb11b53 | 14711 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14712 | } else if (IS_GEN6(dev)) { |
14713 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14714 | } else if (IS_IVYBRIDGE(dev)) { |
14715 | /* FIXME: detect B0+ stepping and use auto training */ | |
14716 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14717 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14718 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
14719 | if (IS_BROADWELL(dev)) { |
14720 | dev_priv->display.modeset_commit_cdclk = | |
14721 | broadwell_modeset_commit_cdclk; | |
14722 | dev_priv->display.modeset_calc_cdclk = | |
14723 | broadwell_modeset_calc_cdclk; | |
14724 | } | |
30a970c6 | 14725 | } else if (IS_VALLEYVIEW(dev)) { |
27c329ed ML |
14726 | dev_priv->display.modeset_commit_cdclk = |
14727 | valleyview_modeset_commit_cdclk; | |
14728 | dev_priv->display.modeset_calc_cdclk = | |
14729 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 14730 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
14731 | dev_priv->display.modeset_commit_cdclk = |
14732 | broxton_modeset_commit_cdclk; | |
14733 | dev_priv->display.modeset_calc_cdclk = | |
14734 | broxton_modeset_calc_cdclk; | |
e70236a8 | 14735 | } |
8c9f3aaf | 14736 | |
8c9f3aaf JB |
14737 | switch (INTEL_INFO(dev)->gen) { |
14738 | case 2: | |
14739 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14740 | break; | |
14741 | ||
14742 | case 3: | |
14743 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14744 | break; | |
14745 | ||
14746 | case 4: | |
14747 | case 5: | |
14748 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14749 | break; | |
14750 | ||
14751 | case 6: | |
14752 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14753 | break; | |
7c9017e5 | 14754 | case 7: |
4e0bbc31 | 14755 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14756 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14757 | break; | |
830c81db | 14758 | case 9: |
ba343e02 TU |
14759 | /* Drop through - unsupported since execlist only. */ |
14760 | default: | |
14761 | /* Default just returns -ENODEV to indicate unsupported */ | |
14762 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14763 | } |
7bd688cd | 14764 | |
e39b999a | 14765 | mutex_init(&dev_priv->pps_mutex); |
e70236a8 JB |
14766 | } |
14767 | ||
b690e96c JB |
14768 | /* |
14769 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14770 | * resume, or other times. This quirk makes sure that's the case for | |
14771 | * affected systems. | |
14772 | */ | |
0206e353 | 14773 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14774 | { |
14775 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14776 | ||
14777 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14778 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14779 | } |
14780 | ||
b6b5d049 VS |
14781 | static void quirk_pipeb_force(struct drm_device *dev) |
14782 | { | |
14783 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14784 | ||
14785 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14786 | DRM_INFO("applying pipe b force quirk\n"); | |
14787 | } | |
14788 | ||
435793df KP |
14789 | /* |
14790 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14791 | */ | |
14792 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14793 | { | |
14794 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14795 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14796 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14797 | } |
14798 | ||
4dca20ef | 14799 | /* |
5a15ab5b CE |
14800 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14801 | * brightness value | |
4dca20ef CE |
14802 | */ |
14803 | static void quirk_invert_brightness(struct drm_device *dev) | |
14804 | { | |
14805 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14806 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14807 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14808 | } |
14809 | ||
9c72cc6f SD |
14810 | /* Some VBT's incorrectly indicate no backlight is present */ |
14811 | static void quirk_backlight_present(struct drm_device *dev) | |
14812 | { | |
14813 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14814 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14815 | DRM_INFO("applying backlight present quirk\n"); | |
14816 | } | |
14817 | ||
b690e96c JB |
14818 | struct intel_quirk { |
14819 | int device; | |
14820 | int subsystem_vendor; | |
14821 | int subsystem_device; | |
14822 | void (*hook)(struct drm_device *dev); | |
14823 | }; | |
14824 | ||
5f85f176 EE |
14825 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14826 | struct intel_dmi_quirk { | |
14827 | void (*hook)(struct drm_device *dev); | |
14828 | const struct dmi_system_id (*dmi_id_list)[]; | |
14829 | }; | |
14830 | ||
14831 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14832 | { | |
14833 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14834 | return 1; | |
14835 | } | |
14836 | ||
14837 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14838 | { | |
14839 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14840 | { | |
14841 | .callback = intel_dmi_reverse_brightness, | |
14842 | .ident = "NCR Corporation", | |
14843 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14844 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14845 | }, | |
14846 | }, | |
14847 | { } /* terminating entry */ | |
14848 | }, | |
14849 | .hook = quirk_invert_brightness, | |
14850 | }, | |
14851 | }; | |
14852 | ||
c43b5634 | 14853 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14854 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14855 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14856 | ||
b690e96c JB |
14857 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14858 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14859 | ||
5f080c0f VS |
14860 | /* 830 needs to leave pipe A & dpll A up */ |
14861 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14862 | ||
b6b5d049 VS |
14863 | /* 830 needs to leave pipe B & dpll B up */ |
14864 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14865 | ||
435793df KP |
14866 | /* Lenovo U160 cannot use SSC on LVDS */ |
14867 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14868 | |
14869 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14870 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14871 | |
be505f64 AH |
14872 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14873 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14874 | ||
14875 | /* Acer/eMachines G725 */ | |
14876 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14877 | ||
14878 | /* Acer/eMachines e725 */ | |
14879 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14880 | ||
14881 | /* Acer/Packard Bell NCL20 */ | |
14882 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14883 | ||
14884 | /* Acer Aspire 4736Z */ | |
14885 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14886 | |
14887 | /* Acer Aspire 5336 */ | |
14888 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14889 | |
14890 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14891 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14892 | |
dfb3d47b SD |
14893 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14894 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14895 | ||
b2a9601c | 14896 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14897 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14898 | ||
d4967d8c SD |
14899 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14900 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14901 | |
14902 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14903 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14904 | |
14905 | /* Dell Chromebook 11 */ | |
14906 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
14907 | }; |
14908 | ||
14909 | static void intel_init_quirks(struct drm_device *dev) | |
14910 | { | |
14911 | struct pci_dev *d = dev->pdev; | |
14912 | int i; | |
14913 | ||
14914 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14915 | struct intel_quirk *q = &intel_quirks[i]; | |
14916 | ||
14917 | if (d->device == q->device && | |
14918 | (d->subsystem_vendor == q->subsystem_vendor || | |
14919 | q->subsystem_vendor == PCI_ANY_ID) && | |
14920 | (d->subsystem_device == q->subsystem_device || | |
14921 | q->subsystem_device == PCI_ANY_ID)) | |
14922 | q->hook(dev); | |
14923 | } | |
5f85f176 EE |
14924 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14925 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14926 | intel_dmi_quirks[i].hook(dev); | |
14927 | } | |
b690e96c JB |
14928 | } |
14929 | ||
9cce37f4 JB |
14930 | /* Disable the VGA plane that we never use */ |
14931 | static void i915_disable_vga(struct drm_device *dev) | |
14932 | { | |
14933 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14934 | u8 sr1; | |
766aa1c4 | 14935 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 14936 | |
2b37c616 | 14937 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 14938 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 14939 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
14940 | sr1 = inb(VGA_SR_DATA); |
14941 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
14942 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
14943 | udelay(300); | |
14944 | ||
01f5a626 | 14945 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
14946 | POSTING_READ(vga_reg); |
14947 | } | |
14948 | ||
f817586c DV |
14949 | void intel_modeset_init_hw(struct drm_device *dev) |
14950 | { | |
b6283055 | 14951 | intel_update_cdclk(dev); |
a8f78b58 | 14952 | intel_prepare_ddi(dev); |
f817586c | 14953 | intel_init_clock_gating(dev); |
8090c6b9 | 14954 | intel_enable_gt_powersave(dev); |
f817586c DV |
14955 | } |
14956 | ||
79e53945 JB |
14957 | void intel_modeset_init(struct drm_device *dev) |
14958 | { | |
652c393a | 14959 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 14960 | int sprite, ret; |
8cc87b75 | 14961 | enum pipe pipe; |
46f297fb | 14962 | struct intel_crtc *crtc; |
79e53945 JB |
14963 | |
14964 | drm_mode_config_init(dev); | |
14965 | ||
14966 | dev->mode_config.min_width = 0; | |
14967 | dev->mode_config.min_height = 0; | |
14968 | ||
019d96cb DA |
14969 | dev->mode_config.preferred_depth = 24; |
14970 | dev->mode_config.prefer_shadow = 1; | |
14971 | ||
25bab385 TU |
14972 | dev->mode_config.allow_fb_modifiers = true; |
14973 | ||
e6ecefaa | 14974 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 14975 | |
b690e96c JB |
14976 | intel_init_quirks(dev); |
14977 | ||
1fa61106 ED |
14978 | intel_init_pm(dev); |
14979 | ||
e3c74757 BW |
14980 | if (INTEL_INFO(dev)->num_pipes == 0) |
14981 | return; | |
14982 | ||
69f92f67 LW |
14983 | /* |
14984 | * There may be no VBT; and if the BIOS enabled SSC we can | |
14985 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
14986 | * BIOS isn't using it, don't assume it will work even if the VBT | |
14987 | * indicates as much. | |
14988 | */ | |
14989 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
14990 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
14991 | DREF_SSC1_ENABLE); | |
14992 | ||
14993 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
14994 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
14995 | bios_lvds_use_ssc ? "en" : "dis", | |
14996 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
14997 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
14998 | } | |
14999 | } | |
15000 | ||
e70236a8 | 15001 | intel_init_display(dev); |
7c10a2b5 | 15002 | intel_init_audio(dev); |
e70236a8 | 15003 | |
a6c45cf0 CW |
15004 | if (IS_GEN2(dev)) { |
15005 | dev->mode_config.max_width = 2048; | |
15006 | dev->mode_config.max_height = 2048; | |
15007 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15008 | dev->mode_config.max_width = 4096; |
15009 | dev->mode_config.max_height = 4096; | |
79e53945 | 15010 | } else { |
a6c45cf0 CW |
15011 | dev->mode_config.max_width = 8192; |
15012 | dev->mode_config.max_height = 8192; | |
79e53945 | 15013 | } |
068be561 | 15014 | |
dc41c154 VS |
15015 | if (IS_845G(dev) || IS_I865G(dev)) { |
15016 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15017 | dev->mode_config.cursor_height = 1023; | |
15018 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15019 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15020 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15021 | } else { | |
15022 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15023 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15024 | } | |
15025 | ||
5d4545ae | 15026 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15027 | |
28c97730 | 15028 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15029 | INTEL_INFO(dev)->num_pipes, |
15030 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15031 | |
055e393f | 15032 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15033 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15034 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15035 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15036 | if (ret) |
06da8da2 | 15037 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15038 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15039 | } |
79e53945 JB |
15040 | } |
15041 | ||
bfa7df01 VS |
15042 | intel_update_czclk(dev_priv); |
15043 | intel_update_cdclk(dev); | |
15044 | ||
e72f9fbf | 15045 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15046 | |
9cce37f4 JB |
15047 | /* Just disable it once at startup */ |
15048 | i915_disable_vga(dev); | |
79e53945 | 15049 | intel_setup_outputs(dev); |
11be49eb | 15050 | |
6e9f798d | 15051 | drm_modeset_lock_all(dev); |
043e9bda | 15052 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15053 | drm_modeset_unlock_all(dev); |
46f297fb | 15054 | |
d3fcc808 | 15055 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15056 | struct intel_initial_plane_config plane_config = {}; |
15057 | ||
46f297fb JB |
15058 | if (!crtc->active) |
15059 | continue; | |
15060 | ||
46f297fb | 15061 | /* |
46f297fb JB |
15062 | * Note that reserving the BIOS fb up front prevents us |
15063 | * from stuffing other stolen allocations like the ring | |
15064 | * on top. This prevents some ugliness at boot time, and | |
15065 | * can even allow for smooth boot transitions if the BIOS | |
15066 | * fb is large enough for the active pipe configuration. | |
15067 | */ | |
eeebeac5 ML |
15068 | dev_priv->display.get_initial_plane_config(crtc, |
15069 | &plane_config); | |
15070 | ||
15071 | /* | |
15072 | * If the fb is shared between multiple heads, we'll | |
15073 | * just get the first one. | |
15074 | */ | |
15075 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15076 | } |
2c7111db CW |
15077 | } |
15078 | ||
7fad798e DV |
15079 | static void intel_enable_pipe_a(struct drm_device *dev) |
15080 | { | |
15081 | struct intel_connector *connector; | |
15082 | struct drm_connector *crt = NULL; | |
15083 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15084 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15085 | |
15086 | /* We can't just switch on the pipe A, we need to set things up with a | |
15087 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15088 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15089 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15090 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15091 | crt = &connector->base; | |
15092 | break; | |
15093 | } | |
15094 | } | |
15095 | ||
15096 | if (!crt) | |
15097 | return; | |
15098 | ||
208bf9fd | 15099 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15100 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15101 | } |
15102 | ||
fa555837 DV |
15103 | static bool |
15104 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15105 | { | |
7eb552ae BW |
15106 | struct drm_device *dev = crtc->base.dev; |
15107 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15108 | u32 val; |
fa555837 | 15109 | |
7eb552ae | 15110 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15111 | return true; |
15112 | ||
649636ef | 15113 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15114 | |
15115 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15116 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15117 | return false; | |
15118 | ||
15119 | return true; | |
15120 | } | |
15121 | ||
02e93c35 VS |
15122 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15123 | { | |
15124 | struct drm_device *dev = crtc->base.dev; | |
15125 | struct intel_encoder *encoder; | |
15126 | ||
15127 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15128 | return true; | |
15129 | ||
15130 | return false; | |
15131 | } | |
15132 | ||
24929352 DV |
15133 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15134 | { | |
15135 | struct drm_device *dev = crtc->base.dev; | |
15136 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 | 15137 | u32 reg; |
24929352 | 15138 | |
24929352 | 15139 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 15140 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
15141 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15142 | ||
d3eaf884 | 15143 | /* restore vblank interrupts to correct state */ |
9625604c | 15144 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15145 | if (crtc->active) { |
f9cd7b88 VS |
15146 | struct intel_plane *plane; |
15147 | ||
9625604c | 15148 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15149 | |
15150 | /* Disable everything but the primary plane */ | |
15151 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15152 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15153 | continue; | |
15154 | ||
15155 | plane->disable_plane(&plane->base, &crtc->base); | |
15156 | } | |
9625604c | 15157 | } |
d3eaf884 | 15158 | |
24929352 | 15159 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15160 | * disable the crtc (and hence change the state) if it is wrong. Note |
15161 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15162 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15163 | bool plane; |
15164 | ||
24929352 DV |
15165 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15166 | crtc->base.base.id); | |
15167 | ||
15168 | /* Pipe has the wrong plane attached and the plane is active. | |
15169 | * Temporarily change the plane mapping and disable everything | |
15170 | * ... */ | |
15171 | plane = crtc->plane; | |
b70709a6 | 15172 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15173 | crtc->plane = !plane; |
b17d48e2 | 15174 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15175 | crtc->plane = plane; |
24929352 | 15176 | } |
24929352 | 15177 | |
7fad798e DV |
15178 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15179 | crtc->pipe == PIPE_A && !crtc->active) { | |
15180 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15181 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15182 | * call below we restore the pipe to the right state, but leave | |
15183 | * the required bits on. */ | |
15184 | intel_enable_pipe_a(dev); | |
15185 | } | |
15186 | ||
24929352 DV |
15187 | /* Adjust the state of the output pipe according to whether we |
15188 | * have active connectors/encoders. */ | |
02e93c35 | 15189 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15190 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15191 | |
53d9f4e9 | 15192 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 15193 | struct intel_encoder *encoder; |
24929352 DV |
15194 | |
15195 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15196 | * functions or because of calls to intel_crtc_disable_noatomic, |
15197 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15198 | * pipe A quirk. */ |
15199 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15200 | crtc->base.base.id, | |
83d65738 | 15201 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15202 | crtc->active ? "enabled" : "disabled"); |
15203 | ||
4be40c98 | 15204 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 15205 | crtc->base.state->active = crtc->active; |
24929352 DV |
15206 | crtc->base.enabled = crtc->active; |
15207 | ||
15208 | /* Because we only establish the connector -> encoder -> | |
15209 | * crtc links if something is active, this means the | |
15210 | * crtc is now deactivated. Break the links. connector | |
15211 | * -> encoder links are only establish when things are | |
15212 | * actually up, hence no need to break them. */ | |
15213 | WARN_ON(crtc->active); | |
15214 | ||
2d406bb0 | 15215 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 15216 | encoder->base.crtc = NULL; |
24929352 | 15217 | } |
c5ab3bc0 | 15218 | |
a3ed6aad | 15219 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15220 | /* |
15221 | * We start out with underrun reporting disabled to avoid races. | |
15222 | * For correct bookkeeping mark this on active crtcs. | |
15223 | * | |
c5ab3bc0 DV |
15224 | * Also on gmch platforms we dont have any hardware bits to |
15225 | * disable the underrun reporting. Which means we need to start | |
15226 | * out with underrun reporting disabled also on inactive pipes, | |
15227 | * since otherwise we'll complain about the garbage we read when | |
15228 | * e.g. coming up after runtime pm. | |
15229 | * | |
4cc31489 DV |
15230 | * No protection against concurrent access is required - at |
15231 | * worst a fifo underrun happens which also sets this to false. | |
15232 | */ | |
15233 | crtc->cpu_fifo_underrun_disabled = true; | |
15234 | crtc->pch_fifo_underrun_disabled = true; | |
15235 | } | |
24929352 DV |
15236 | } |
15237 | ||
15238 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15239 | { | |
15240 | struct intel_connector *connector; | |
15241 | struct drm_device *dev = encoder->base.dev; | |
873ffe69 | 15242 | bool active = false; |
24929352 DV |
15243 | |
15244 | /* We need to check both for a crtc link (meaning that the | |
15245 | * encoder is active and trying to read from a pipe) and the | |
15246 | * pipe itself being active. */ | |
15247 | bool has_active_crtc = encoder->base.crtc && | |
15248 | to_intel_crtc(encoder->base.crtc)->active; | |
15249 | ||
873ffe69 ML |
15250 | for_each_intel_connector(dev, connector) { |
15251 | if (connector->base.encoder != &encoder->base) | |
15252 | continue; | |
15253 | ||
15254 | active = true; | |
15255 | break; | |
15256 | } | |
15257 | ||
15258 | if (active && !has_active_crtc) { | |
24929352 DV |
15259 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15260 | encoder->base.base.id, | |
8e329a03 | 15261 | encoder->base.name); |
24929352 DV |
15262 | |
15263 | /* Connector is active, but has no active pipe. This is | |
15264 | * fallout from our resume register restoring. Disable | |
15265 | * the encoder manually again. */ | |
15266 | if (encoder->base.crtc) { | |
15267 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15268 | encoder->base.base.id, | |
8e329a03 | 15269 | encoder->base.name); |
24929352 | 15270 | encoder->disable(encoder); |
a62d1497 VS |
15271 | if (encoder->post_disable) |
15272 | encoder->post_disable(encoder); | |
24929352 | 15273 | } |
7f1950fb | 15274 | encoder->base.crtc = NULL; |
24929352 DV |
15275 | |
15276 | /* Inconsistent output/port/pipe state happens presumably due to | |
15277 | * a bug in one of the get_hw_state functions. Or someplace else | |
15278 | * in our code, like the register restore mess on resume. Clamp | |
15279 | * things to off as a safer default. */ | |
3a3371ff | 15280 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15281 | if (connector->encoder != encoder) |
15282 | continue; | |
7f1950fb EE |
15283 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15284 | connector->base.encoder = NULL; | |
24929352 DV |
15285 | } |
15286 | } | |
15287 | /* Enabled encoders without active connectors will be fixed in | |
15288 | * the crtc fixup. */ | |
15289 | } | |
15290 | ||
04098753 | 15291 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15292 | { |
15293 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 15294 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15295 | |
04098753 ID |
15296 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15297 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15298 | i915_disable_vga(dev); | |
15299 | } | |
15300 | } | |
15301 | ||
15302 | void i915_redisable_vga(struct drm_device *dev) | |
15303 | { | |
15304 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15305 | ||
8dc8a27c PZ |
15306 | /* This function can be called both from intel_modeset_setup_hw_state or |
15307 | * at a very early point in our resume sequence, where the power well | |
15308 | * structures are not yet restored. Since this function is at a very | |
15309 | * paranoid "someone might have enabled VGA while we were not looking" | |
15310 | * level, just check if the power well is enabled instead of trying to | |
15311 | * follow the "don't touch the power well if we don't need it" policy | |
15312 | * the rest of the driver uses. */ | |
f458ebbc | 15313 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15314 | return; |
15315 | ||
04098753 | 15316 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15317 | } |
15318 | ||
f9cd7b88 | 15319 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15320 | { |
f9cd7b88 | 15321 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15322 | |
f9cd7b88 | 15323 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15324 | } |
15325 | ||
f9cd7b88 VS |
15326 | /* FIXME read out full plane state for all planes */ |
15327 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15328 | { |
b26d3ea3 | 15329 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15330 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15331 | to_intel_plane_state(primary->state); |
d032ffa0 | 15332 | |
19b8d387 | 15333 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
15334 | primary_get_hw_state(to_intel_plane(primary)); |
15335 | ||
15336 | if (plane_state->visible) | |
15337 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
15338 | } |
15339 | ||
30e984df | 15340 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15341 | { |
15342 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15343 | enum pipe pipe; | |
24929352 DV |
15344 | struct intel_crtc *crtc; |
15345 | struct intel_encoder *encoder; | |
15346 | struct intel_connector *connector; | |
5358901f | 15347 | int i; |
24929352 | 15348 | |
d3fcc808 | 15349 | for_each_intel_crtc(dev, crtc) { |
b06f8b0d | 15350 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
6e3c9717 | 15351 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15352 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15353 | |
0e8ffe1b | 15354 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15355 | crtc->config); |
24929352 | 15356 | |
49d6fa21 | 15357 | crtc->base.state->active = crtc->active; |
24929352 | 15358 | crtc->base.enabled = crtc->active; |
b70709a6 | 15359 | |
f9cd7b88 | 15360 | readout_plane_state(crtc); |
24929352 DV |
15361 | |
15362 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15363 | crtc->base.base.id, | |
15364 | crtc->active ? "enabled" : "disabled"); | |
15365 | } | |
15366 | ||
5358901f DV |
15367 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15368 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15369 | ||
3e369b76 ACO |
15370 | pll->on = pll->get_hw_state(dev_priv, pll, |
15371 | &pll->config.hw_state); | |
5358901f | 15372 | pll->active = 0; |
3e369b76 | 15373 | pll->config.crtc_mask = 0; |
d3fcc808 | 15374 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15375 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15376 | pll->active++; |
3e369b76 | 15377 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15378 | } |
5358901f | 15379 | } |
5358901f | 15380 | |
1e6f2ddc | 15381 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15382 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15383 | |
3e369b76 | 15384 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15385 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15386 | } |
15387 | ||
b2784e15 | 15388 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15389 | pipe = 0; |
15390 | ||
15391 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15392 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15393 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15394 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15395 | } else { |
15396 | encoder->base.crtc = NULL; | |
15397 | } | |
15398 | ||
6f2bcceb | 15399 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15400 | encoder->base.base.id, |
8e329a03 | 15401 | encoder->base.name, |
24929352 | 15402 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15403 | pipe_name(pipe)); |
24929352 DV |
15404 | } |
15405 | ||
3a3371ff | 15406 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15407 | if (connector->get_hw_state(connector)) { |
15408 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
24929352 DV |
15409 | connector->base.encoder = &connector->encoder->base; |
15410 | } else { | |
15411 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15412 | connector->base.encoder = NULL; | |
15413 | } | |
15414 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15415 | connector->base.base.id, | |
c23cc417 | 15416 | connector->base.name, |
24929352 DV |
15417 | connector->base.encoder ? "enabled" : "disabled"); |
15418 | } | |
7f4c6284 VS |
15419 | |
15420 | for_each_intel_crtc(dev, crtc) { | |
15421 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
15422 | ||
15423 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
15424 | if (crtc->base.state->active) { | |
15425 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
15426 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
15427 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
15428 | ||
15429 | /* | |
15430 | * The initial mode needs to be set in order to keep | |
15431 | * the atomic core happy. It wants a valid mode if the | |
15432 | * crtc's enabled, so we do the above call. | |
15433 | * | |
15434 | * At this point some state updated by the connectors | |
15435 | * in their ->detect() callback has not run yet, so | |
15436 | * no recalculation can be done yet. | |
15437 | * | |
15438 | * Even if we could do a recalculation and modeset | |
15439 | * right now it would cause a double modeset if | |
15440 | * fbdev or userspace chooses a different initial mode. | |
15441 | * | |
15442 | * If that happens, someone indicated they wanted a | |
15443 | * mode change, which means it's safe to do a full | |
15444 | * recalculation. | |
15445 | */ | |
15446 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
15447 | |
15448 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
15449 | update_scanline_offset(crtc); | |
7f4c6284 VS |
15450 | } |
15451 | } | |
30e984df DV |
15452 | } |
15453 | ||
043e9bda ML |
15454 | /* Scan out the current hw modeset state, |
15455 | * and sanitizes it to the current state | |
15456 | */ | |
15457 | static void | |
15458 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
15459 | { |
15460 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15461 | enum pipe pipe; | |
30e984df DV |
15462 | struct intel_crtc *crtc; |
15463 | struct intel_encoder *encoder; | |
35c95375 | 15464 | int i; |
30e984df DV |
15465 | |
15466 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
15467 | |
15468 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 15469 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15470 | intel_sanitize_encoder(encoder); |
15471 | } | |
15472 | ||
055e393f | 15473 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15474 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15475 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15476 | intel_dump_pipe_config(crtc, crtc->config, |
15477 | "[setup_hw_state]"); | |
24929352 | 15478 | } |
9a935856 | 15479 | |
d29b2f9d ACO |
15480 | intel_modeset_update_connector_atomic_state(dev); |
15481 | ||
35c95375 DV |
15482 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15483 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15484 | ||
15485 | if (!pll->on || pll->active) | |
15486 | continue; | |
15487 | ||
15488 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15489 | ||
15490 | pll->disable(dev_priv, pll); | |
15491 | pll->on = false; | |
15492 | } | |
15493 | ||
26e1fe4f | 15494 | if (IS_VALLEYVIEW(dev)) |
6eb1a681 VS |
15495 | vlv_wm_get_hw_state(dev); |
15496 | else if (IS_GEN9(dev)) | |
3078999f PB |
15497 | skl_wm_get_hw_state(dev); |
15498 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 15499 | ilk_wm_get_hw_state(dev); |
292b990e ML |
15500 | |
15501 | for_each_intel_crtc(dev, crtc) { | |
15502 | unsigned long put_domains; | |
15503 | ||
15504 | put_domains = modeset_get_crtc_power_domains(&crtc->base); | |
15505 | if (WARN_ON(put_domains)) | |
15506 | modeset_put_power_domains(dev_priv, put_domains); | |
15507 | } | |
15508 | intel_display_set_init_power(dev_priv, false); | |
043e9bda | 15509 | } |
7d0bc1ea | 15510 | |
043e9bda ML |
15511 | void intel_display_resume(struct drm_device *dev) |
15512 | { | |
15513 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); | |
15514 | struct intel_connector *conn; | |
15515 | struct intel_plane *plane; | |
15516 | struct drm_crtc *crtc; | |
15517 | int ret; | |
f30da187 | 15518 | |
043e9bda ML |
15519 | if (!state) |
15520 | return; | |
15521 | ||
15522 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
15523 | ||
15524 | /* preserve complete old state, including dpll */ | |
15525 | intel_atomic_get_shared_dpll_state(state); | |
15526 | ||
15527 | for_each_crtc(dev, crtc) { | |
15528 | struct drm_crtc_state *crtc_state = | |
15529 | drm_atomic_get_crtc_state(state, crtc); | |
15530 | ||
15531 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
15532 | if (ret) | |
15533 | goto err; | |
15534 | ||
15535 | /* force a restore */ | |
15536 | crtc_state->mode_changed = true; | |
45e2b5f6 | 15537 | } |
8af6cf88 | 15538 | |
043e9bda ML |
15539 | for_each_intel_plane(dev, plane) { |
15540 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); | |
15541 | if (ret) | |
15542 | goto err; | |
15543 | } | |
15544 | ||
15545 | for_each_intel_connector(dev, conn) { | |
15546 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); | |
15547 | if (ret) | |
15548 | goto err; | |
15549 | } | |
15550 | ||
15551 | intel_modeset_setup_hw_state(dev); | |
15552 | ||
15553 | i915_redisable_vga(dev); | |
74c090b1 | 15554 | ret = drm_atomic_commit(state); |
043e9bda ML |
15555 | if (!ret) |
15556 | return; | |
15557 | ||
15558 | err: | |
15559 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
15560 | drm_atomic_state_free(state); | |
2c7111db CW |
15561 | } |
15562 | ||
15563 | void intel_modeset_gem_init(struct drm_device *dev) | |
15564 | { | |
484b41dd | 15565 | struct drm_crtc *c; |
2ff8fde1 | 15566 | struct drm_i915_gem_object *obj; |
e0d6149b | 15567 | int ret; |
484b41dd | 15568 | |
ae48434c ID |
15569 | mutex_lock(&dev->struct_mutex); |
15570 | intel_init_gt_powersave(dev); | |
15571 | mutex_unlock(&dev->struct_mutex); | |
15572 | ||
1833b134 | 15573 | intel_modeset_init_hw(dev); |
02e792fb DV |
15574 | |
15575 | intel_setup_overlay(dev); | |
484b41dd JB |
15576 | |
15577 | /* | |
15578 | * Make sure any fbs we allocated at startup are properly | |
15579 | * pinned & fenced. When we do the allocation it's too early | |
15580 | * for this. | |
15581 | */ | |
70e1e0ec | 15582 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15583 | obj = intel_fb_obj(c->primary->fb); |
15584 | if (obj == NULL) | |
484b41dd JB |
15585 | continue; |
15586 | ||
e0d6149b TU |
15587 | mutex_lock(&dev->struct_mutex); |
15588 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15589 | c->primary->fb, | |
7580d774 | 15590 | c->primary->state); |
e0d6149b TU |
15591 | mutex_unlock(&dev->struct_mutex); |
15592 | if (ret) { | |
484b41dd JB |
15593 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15594 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15595 | drm_framebuffer_unreference(c->primary->fb); |
15596 | c->primary->fb = NULL; | |
36750f28 | 15597 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15598 | update_state_fb(c->primary); |
36750f28 | 15599 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15600 | } |
15601 | } | |
0962c3c9 VS |
15602 | |
15603 | intel_backlight_register(dev); | |
79e53945 JB |
15604 | } |
15605 | ||
4932e2c3 ID |
15606 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15607 | { | |
15608 | struct drm_connector *connector = &intel_connector->base; | |
15609 | ||
15610 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15611 | drm_connector_unregister(connector); |
4932e2c3 ID |
15612 | } |
15613 | ||
79e53945 JB |
15614 | void intel_modeset_cleanup(struct drm_device *dev) |
15615 | { | |
652c393a | 15616 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15617 | struct drm_connector *connector; |
652c393a | 15618 | |
2eb5252e ID |
15619 | intel_disable_gt_powersave(dev); |
15620 | ||
0962c3c9 VS |
15621 | intel_backlight_unregister(dev); |
15622 | ||
fd0c0642 DV |
15623 | /* |
15624 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15625 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15626 | * experience fancy races otherwise. |
15627 | */ | |
2aeb7d3a | 15628 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15629 | |
fd0c0642 DV |
15630 | /* |
15631 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15632 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15633 | */ | |
f87ea761 | 15634 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15635 | |
723bfd70 JB |
15636 | intel_unregister_dsm_handler(); |
15637 | ||
7733b49b | 15638 | intel_fbc_disable(dev_priv); |
69341a5e | 15639 | |
1630fe75 CW |
15640 | /* flush any delayed tasks or pending work */ |
15641 | flush_scheduled_work(); | |
15642 | ||
db31af1d JN |
15643 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15644 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15645 | struct intel_connector *intel_connector; |
15646 | ||
15647 | intel_connector = to_intel_connector(connector); | |
15648 | intel_connector->unregister(intel_connector); | |
db31af1d | 15649 | } |
d9255d57 | 15650 | |
79e53945 | 15651 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15652 | |
15653 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15654 | |
15655 | mutex_lock(&dev->struct_mutex); | |
15656 | intel_cleanup_gt_powersave(dev); | |
15657 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15658 | } |
15659 | ||
f1c79df3 ZW |
15660 | /* |
15661 | * Return which encoder is currently attached for connector. | |
15662 | */ | |
df0e9248 | 15663 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15664 | { |
df0e9248 CW |
15665 | return &intel_attached_encoder(connector)->base; |
15666 | } | |
f1c79df3 | 15667 | |
df0e9248 CW |
15668 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15669 | struct intel_encoder *encoder) | |
15670 | { | |
15671 | connector->encoder = encoder; | |
15672 | drm_mode_connector_attach_encoder(&connector->base, | |
15673 | &encoder->base); | |
79e53945 | 15674 | } |
28d52043 DA |
15675 | |
15676 | /* | |
15677 | * set vga decode state - true == enable VGA decode | |
15678 | */ | |
15679 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15680 | { | |
15681 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15682 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15683 | u16 gmch_ctrl; |
15684 | ||
75fa041d CW |
15685 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15686 | DRM_ERROR("failed to read control word\n"); | |
15687 | return -EIO; | |
15688 | } | |
15689 | ||
c0cc8a55 CW |
15690 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15691 | return 0; | |
15692 | ||
28d52043 DA |
15693 | if (state) |
15694 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15695 | else | |
15696 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15697 | |
15698 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15699 | DRM_ERROR("failed to write control word\n"); | |
15700 | return -EIO; | |
15701 | } | |
15702 | ||
28d52043 DA |
15703 | return 0; |
15704 | } | |
c4a1d9e4 | 15705 | |
c4a1d9e4 | 15706 | struct intel_display_error_state { |
ff57f1b0 PZ |
15707 | |
15708 | u32 power_well_driver; | |
15709 | ||
63b66e5b CW |
15710 | int num_transcoders; |
15711 | ||
c4a1d9e4 CW |
15712 | struct intel_cursor_error_state { |
15713 | u32 control; | |
15714 | u32 position; | |
15715 | u32 base; | |
15716 | u32 size; | |
52331309 | 15717 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15718 | |
15719 | struct intel_pipe_error_state { | |
ddf9c536 | 15720 | bool power_domain_on; |
c4a1d9e4 | 15721 | u32 source; |
f301b1e1 | 15722 | u32 stat; |
52331309 | 15723 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15724 | |
15725 | struct intel_plane_error_state { | |
15726 | u32 control; | |
15727 | u32 stride; | |
15728 | u32 size; | |
15729 | u32 pos; | |
15730 | u32 addr; | |
15731 | u32 surface; | |
15732 | u32 tile_offset; | |
52331309 | 15733 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15734 | |
15735 | struct intel_transcoder_error_state { | |
ddf9c536 | 15736 | bool power_domain_on; |
63b66e5b CW |
15737 | enum transcoder cpu_transcoder; |
15738 | ||
15739 | u32 conf; | |
15740 | ||
15741 | u32 htotal; | |
15742 | u32 hblank; | |
15743 | u32 hsync; | |
15744 | u32 vtotal; | |
15745 | u32 vblank; | |
15746 | u32 vsync; | |
15747 | } transcoder[4]; | |
c4a1d9e4 CW |
15748 | }; |
15749 | ||
15750 | struct intel_display_error_state * | |
15751 | intel_display_capture_error_state(struct drm_device *dev) | |
15752 | { | |
fbee40df | 15753 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15754 | struct intel_display_error_state *error; |
63b66e5b CW |
15755 | int transcoders[] = { |
15756 | TRANSCODER_A, | |
15757 | TRANSCODER_B, | |
15758 | TRANSCODER_C, | |
15759 | TRANSCODER_EDP, | |
15760 | }; | |
c4a1d9e4 CW |
15761 | int i; |
15762 | ||
63b66e5b CW |
15763 | if (INTEL_INFO(dev)->num_pipes == 0) |
15764 | return NULL; | |
15765 | ||
9d1cb914 | 15766 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15767 | if (error == NULL) |
15768 | return NULL; | |
15769 | ||
190be112 | 15770 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15771 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15772 | ||
055e393f | 15773 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15774 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15775 | __intel_display_power_is_enabled(dev_priv, |
15776 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15777 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15778 | continue; |
15779 | ||
5efb3e28 VS |
15780 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15781 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15782 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15783 | |
15784 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15785 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15786 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15787 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15788 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15789 | } | |
ca291363 PZ |
15790 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15791 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15792 | if (INTEL_INFO(dev)->gen >= 4) { |
15793 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15794 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15795 | } | |
15796 | ||
c4a1d9e4 | 15797 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15798 | |
3abfce77 | 15799 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15800 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15801 | } |
15802 | ||
15803 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15804 | if (HAS_DDI(dev_priv->dev)) | |
15805 | error->num_transcoders++; /* Account for eDP. */ | |
15806 | ||
15807 | for (i = 0; i < error->num_transcoders; i++) { | |
15808 | enum transcoder cpu_transcoder = transcoders[i]; | |
15809 | ||
ddf9c536 | 15810 | error->transcoder[i].power_domain_on = |
f458ebbc | 15811 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15812 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15813 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15814 | continue; |
15815 | ||
63b66e5b CW |
15816 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15817 | ||
15818 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15819 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15820 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15821 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15822 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15823 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15824 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15825 | } |
15826 | ||
15827 | return error; | |
15828 | } | |
15829 | ||
edc3d884 MK |
15830 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15831 | ||
c4a1d9e4 | 15832 | void |
edc3d884 | 15833 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15834 | struct drm_device *dev, |
15835 | struct intel_display_error_state *error) | |
15836 | { | |
055e393f | 15837 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15838 | int i; |
15839 | ||
63b66e5b CW |
15840 | if (!error) |
15841 | return; | |
15842 | ||
edc3d884 | 15843 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15844 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15845 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15846 | error->power_well_driver); |
055e393f | 15847 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15848 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15849 | err_printf(m, " Power: %s\n", |
15850 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15851 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15852 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15853 | |
15854 | err_printf(m, "Plane [%d]:\n", i); | |
15855 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15856 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15857 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15858 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15859 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15860 | } |
4b71a570 | 15861 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15862 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15863 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15864 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15865 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15866 | } |
15867 | ||
edc3d884 MK |
15868 | err_printf(m, "Cursor [%d]:\n", i); |
15869 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15870 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15871 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15872 | } |
63b66e5b CW |
15873 | |
15874 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15875 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15876 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15877 | err_printf(m, " Power: %s\n", |
15878 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15879 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15880 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15881 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15882 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15883 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15884 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15885 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15886 | } | |
c4a1d9e4 | 15887 | } |
e2fcdaa9 VS |
15888 | |
15889 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
15890 | { | |
15891 | struct intel_crtc *crtc; | |
15892 | ||
15893 | for_each_intel_crtc(dev, crtc) { | |
15894 | struct intel_unpin_work *work; | |
e2fcdaa9 | 15895 | |
5e2d7afc | 15896 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15897 | |
15898 | work = crtc->unpin_work; | |
15899 | ||
15900 | if (work && work->event && | |
15901 | work->event->base.file_priv == file) { | |
15902 | kfree(work->event); | |
15903 | work->event = NULL; | |
15904 | } | |
15905 | ||
5e2d7afc | 15906 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15907 | } |
15908 | } |