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; | |
f0f59a00 | 1098 | i915_reg_t reg = PIPEDSL(pipe); |
fbf49ea2 VS |
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) { | |
f0f59a00 | 1138 | i915_reg_t 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 | 1287 | struct drm_device *dev = dev_priv->dev; |
f0f59a00 | 1288 | i915_reg_t 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)) { | |
f0f59a00 | 1483 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
f0575e92 KP |
1484 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
1485 | return false; | |
44f37d1f CML |
1486 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1487 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1488 | return false; | |
f0575e92 KP |
1489 | } else { |
1490 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1491 | return false; | |
1492 | } | |
1493 | return true; | |
1494 | } | |
1495 | ||
1519b995 KP |
1496 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1497 | enum pipe pipe, u32 val) | |
1498 | { | |
dc0fa718 | 1499 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1500 | return false; |
1501 | ||
1502 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1503 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1504 | return false; |
44f37d1f CML |
1505 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1506 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1507 | return false; | |
1519b995 | 1508 | } else { |
dc0fa718 | 1509 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1510 | return false; |
1511 | } | |
1512 | return true; | |
1513 | } | |
1514 | ||
1515 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1516 | enum pipe pipe, u32 val) | |
1517 | { | |
1518 | if ((val & LVDS_PORT_EN) == 0) | |
1519 | return false; | |
1520 | ||
1521 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1522 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1523 | return false; | |
1524 | } else { | |
1525 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1526 | return false; | |
1527 | } | |
1528 | return true; | |
1529 | } | |
1530 | ||
1531 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1532 | enum pipe pipe, u32 val) | |
1533 | { | |
1534 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1535 | return false; | |
1536 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1537 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1538 | return false; | |
1539 | } else { | |
1540 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1541 | return false; | |
1542 | } | |
1543 | return true; | |
1544 | } | |
1545 | ||
291906f1 | 1546 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0f59a00 VS |
1547 | enum pipe pipe, i915_reg_t reg, |
1548 | 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", |
f0f59a00 | 1553 | i915_mmio_reg_offset(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, | |
f0f59a00 | 1561 | enum pipe pipe, i915_reg_t reg) |
291906f1 | 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", |
f0f59a00 | 1566 | i915_mmio_reg_offset(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; | |
f0f59a00 | 1602 | i915_reg_t 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; | |
f0f59a00 | 1691 | i915_reg_t 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 | 1715 | |
c2b63374 VS |
1716 | /* |
1717 | * Apparently we need to have VGA mode enabled prior to changing | |
1718 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old | |
1719 | * dividers, even though the register value does change. | |
1720 | */ | |
1721 | I915_WRITE(reg, 0); | |
1722 | ||
8e7a65aa VS |
1723 | I915_WRITE(reg, dpll); |
1724 | ||
66e3d5c0 DV |
1725 | /* Wait for the clocks to stabilize. */ |
1726 | POSTING_READ(reg); | |
1727 | udelay(150); | |
1728 | ||
1729 | if (INTEL_INFO(dev)->gen >= 4) { | |
1730 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1731 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1732 | } else { |
1733 | /* The pixel multiplier can only be updated once the | |
1734 | * DPLL is enabled and the clocks are stable. | |
1735 | * | |
1736 | * So write it again. | |
1737 | */ | |
1738 | I915_WRITE(reg, dpll); | |
1739 | } | |
63d7bbe9 JB |
1740 | |
1741 | /* We do this three times for luck */ | |
66e3d5c0 | 1742 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1743 | POSTING_READ(reg); |
1744 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1745 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1746 | POSTING_READ(reg); |
1747 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1748 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1749 | POSTING_READ(reg); |
1750 | udelay(150); /* wait for warmup */ | |
1751 | } | |
1752 | ||
1753 | /** | |
50b44a44 | 1754 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1755 | * @dev_priv: i915 private structure |
1756 | * @pipe: pipe PLL to disable | |
1757 | * | |
1758 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1759 | * | |
1760 | * Note! This is for pre-ILK only. | |
1761 | */ | |
1c4e0274 | 1762 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1763 | { |
1c4e0274 VS |
1764 | struct drm_device *dev = crtc->base.dev; |
1765 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1766 | enum pipe pipe = crtc->pipe; | |
1767 | ||
1768 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1769 | if (IS_I830(dev) && | |
409ee761 | 1770 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1771 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1772 | I915_WRITE(DPLL(PIPE_B), |
1773 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1774 | I915_WRITE(DPLL(PIPE_A), | |
1775 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1776 | } | |
1777 | ||
b6b5d049 VS |
1778 | /* Don't disable pipe or pipe PLLs if needed */ |
1779 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1780 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1781 | return; |
1782 | ||
1783 | /* Make sure the pipe isn't still relying on us */ | |
1784 | assert_pipe_disabled(dev_priv, pipe); | |
1785 | ||
b8afb911 | 1786 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1787 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1788 | } |
1789 | ||
f6071166 JB |
1790 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1791 | { | |
b8afb911 | 1792 | u32 val; |
f6071166 JB |
1793 | |
1794 | /* Make sure the pipe isn't still relying on us */ | |
1795 | assert_pipe_disabled(dev_priv, pipe); | |
1796 | ||
e5cbfbfb ID |
1797 | /* |
1798 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1799 | * The latter is needed for VGA hotplug / manual detection. | |
1800 | */ | |
b8afb911 | 1801 | val = DPLL_VGA_MODE_DIS; |
f6071166 | 1802 | if (pipe == PIPE_B) |
60bfe44f | 1803 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
f6071166 JB |
1804 | I915_WRITE(DPLL(pipe), val); |
1805 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1806 | |
1807 | } | |
1808 | ||
1809 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1810 | { | |
d752048d | 1811 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1812 | u32 val; |
1813 | ||
a11b0703 VS |
1814 | /* Make sure the pipe isn't still relying on us */ |
1815 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1816 | |
a11b0703 | 1817 | /* Set PLL en = 0 */ |
60bfe44f VS |
1818 | val = DPLL_SSC_REF_CLK_CHV | |
1819 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1820 | if (pipe != PIPE_A) |
1821 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1822 | I915_WRITE(DPLL(pipe), val); | |
1823 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1824 | |
a580516d | 1825 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1826 | |
1827 | /* Disable 10bit clock to display controller */ | |
1828 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1829 | val &= ~DPIO_DCLKP_EN; | |
1830 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1831 | ||
a580516d | 1832 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1833 | } |
1834 | ||
e4607fcf | 1835 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1836 | struct intel_digital_port *dport, |
1837 | unsigned int expected_mask) | |
89b667f8 JB |
1838 | { |
1839 | u32 port_mask; | |
f0f59a00 | 1840 | i915_reg_t dpll_reg; |
89b667f8 | 1841 | |
e4607fcf CML |
1842 | switch (dport->port) { |
1843 | case PORT_B: | |
89b667f8 | 1844 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1845 | dpll_reg = DPLL(0); |
e4607fcf CML |
1846 | break; |
1847 | case PORT_C: | |
89b667f8 | 1848 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1849 | dpll_reg = DPLL(0); |
9b6de0a1 | 1850 | expected_mask <<= 4; |
00fc31b7 CML |
1851 | break; |
1852 | case PORT_D: | |
1853 | port_mask = DPLL_PORTD_READY_MASK; | |
1854 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1855 | break; |
1856 | default: | |
1857 | BUG(); | |
1858 | } | |
89b667f8 | 1859 | |
9b6de0a1 VS |
1860 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1861 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1862 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1863 | } |
1864 | ||
b14b1055 DV |
1865 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1866 | { | |
1867 | struct drm_device *dev = crtc->base.dev; | |
1868 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1869 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1870 | ||
be19f0ff CW |
1871 | if (WARN_ON(pll == NULL)) |
1872 | return; | |
1873 | ||
3e369b76 | 1874 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1875 | if (pll->active == 0) { |
1876 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1877 | WARN_ON(pll->on); | |
1878 | assert_shared_dpll_disabled(dev_priv, pll); | |
1879 | ||
1880 | pll->mode_set(dev_priv, pll); | |
1881 | } | |
1882 | } | |
1883 | ||
92f2584a | 1884 | /** |
85b3894f | 1885 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1886 | * @dev_priv: i915 private structure |
1887 | * @pipe: pipe PLL to enable | |
1888 | * | |
1889 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1890 | * drives the transcoder clock. | |
1891 | */ | |
85b3894f | 1892 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1893 | { |
3d13ef2e DL |
1894 | struct drm_device *dev = crtc->base.dev; |
1895 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1896 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1897 | |
87a875bb | 1898 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1899 | return; |
1900 | ||
3e369b76 | 1901 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1902 | return; |
ee7b9f93 | 1903 | |
74dd6928 | 1904 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1905 | pll->name, pll->active, pll->on, |
e2b78267 | 1906 | crtc->base.base.id); |
92f2584a | 1907 | |
cdbd2316 DV |
1908 | if (pll->active++) { |
1909 | WARN_ON(!pll->on); | |
e9d6944e | 1910 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1911 | return; |
1912 | } | |
f4a091c7 | 1913 | WARN_ON(pll->on); |
ee7b9f93 | 1914 | |
bd2bb1b9 PZ |
1915 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1916 | ||
46edb027 | 1917 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1918 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1919 | pll->on = true; |
92f2584a JB |
1920 | } |
1921 | ||
f6daaec2 | 1922 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1923 | { |
3d13ef2e DL |
1924 | struct drm_device *dev = crtc->base.dev; |
1925 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1926 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1927 | |
92f2584a | 1928 | /* PCH only available on ILK+ */ |
80aa9312 JB |
1929 | if (INTEL_INFO(dev)->gen < 5) |
1930 | return; | |
1931 | ||
eddfcbcd ML |
1932 | if (pll == NULL) |
1933 | return; | |
92f2584a | 1934 | |
eddfcbcd | 1935 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) |
48da64a8 | 1936 | return; |
7a419866 | 1937 | |
46edb027 DV |
1938 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1939 | pll->name, pll->active, pll->on, | |
e2b78267 | 1940 | crtc->base.base.id); |
7a419866 | 1941 | |
48da64a8 | 1942 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1943 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1944 | return; |
1945 | } | |
1946 | ||
e9d6944e | 1947 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1948 | WARN_ON(!pll->on); |
cdbd2316 | 1949 | if (--pll->active) |
7a419866 | 1950 | return; |
ee7b9f93 | 1951 | |
46edb027 | 1952 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1953 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1954 | pll->on = false; |
bd2bb1b9 PZ |
1955 | |
1956 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1957 | } |
1958 | ||
b8a4f404 PZ |
1959 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1960 | enum pipe pipe) | |
040484af | 1961 | { |
23670b32 | 1962 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1963 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1964 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
f0f59a00 VS |
1965 | i915_reg_t reg; |
1966 | uint32_t val, pipeconf_val; | |
040484af JB |
1967 | |
1968 | /* PCH only available on ILK+ */ | |
55522f37 | 1969 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1970 | |
1971 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1972 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1973 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1974 | |
1975 | /* FDI must be feeding us bits for PCH ports */ | |
1976 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1977 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1978 | ||
23670b32 DV |
1979 | if (HAS_PCH_CPT(dev)) { |
1980 | /* Workaround: Set the timing override bit before enabling the | |
1981 | * pch transcoder. */ | |
1982 | reg = TRANS_CHICKEN2(pipe); | |
1983 | val = I915_READ(reg); | |
1984 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1985 | I915_WRITE(reg, val); | |
59c859d6 | 1986 | } |
23670b32 | 1987 | |
ab9412ba | 1988 | reg = PCH_TRANSCONF(pipe); |
040484af | 1989 | val = I915_READ(reg); |
5f7f726d | 1990 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
1991 | |
1992 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
1993 | /* | |
c5de7c6f VS |
1994 | * Make the BPC in transcoder be consistent with |
1995 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1996 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1997 | */ |
dfd07d72 | 1998 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
1999 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
2000 | val |= PIPECONF_8BPC; | |
2001 | else | |
2002 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 2003 | } |
5f7f726d PZ |
2004 | |
2005 | val &= ~TRANS_INTERLACE_MASK; | |
2006 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 2007 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 2008 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
2009 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2010 | else | |
2011 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2012 | else |
2013 | val |= TRANS_PROGRESSIVE; | |
2014 | ||
040484af JB |
2015 | I915_WRITE(reg, val | TRANS_ENABLE); |
2016 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2017 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2018 | } |
2019 | ||
8fb033d7 | 2020 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2021 | enum transcoder cpu_transcoder) |
040484af | 2022 | { |
8fb033d7 | 2023 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2024 | |
2025 | /* PCH only available on ILK+ */ | |
55522f37 | 2026 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2027 | |
8fb033d7 | 2028 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2029 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2030 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2031 | |
223a6fdf | 2032 | /* Workaround: set timing override bit. */ |
36c0d0cf | 2033 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2034 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2035 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
223a6fdf | 2036 | |
25f3ef11 | 2037 | val = TRANS_ENABLE; |
937bb610 | 2038 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2039 | |
9a76b1c6 PZ |
2040 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2041 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2042 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2043 | else |
2044 | val |= TRANS_PROGRESSIVE; | |
2045 | ||
ab9412ba DV |
2046 | I915_WRITE(LPT_TRANSCONF, val); |
2047 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2048 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2049 | } |
2050 | ||
b8a4f404 PZ |
2051 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2052 | enum pipe pipe) | |
040484af | 2053 | { |
23670b32 | 2054 | struct drm_device *dev = dev_priv->dev; |
f0f59a00 VS |
2055 | i915_reg_t reg; |
2056 | uint32_t val; | |
040484af JB |
2057 | |
2058 | /* FDI relies on the transcoder */ | |
2059 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2060 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2061 | ||
291906f1 JB |
2062 | /* Ports must be off as well */ |
2063 | assert_pch_ports_disabled(dev_priv, pipe); | |
2064 | ||
ab9412ba | 2065 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2066 | val = I915_READ(reg); |
2067 | val &= ~TRANS_ENABLE; | |
2068 | I915_WRITE(reg, val); | |
2069 | /* wait for PCH transcoder off, transcoder state */ | |
2070 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2071 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 | 2072 | |
c465613b | 2073 | if (HAS_PCH_CPT(dev)) { |
23670b32 DV |
2074 | /* Workaround: Clear the timing override chicken bit again. */ |
2075 | reg = TRANS_CHICKEN2(pipe); | |
2076 | val = I915_READ(reg); | |
2077 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2078 | I915_WRITE(reg, val); | |
2079 | } | |
040484af JB |
2080 | } |
2081 | ||
ab4d966c | 2082 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2083 | { |
8fb033d7 PZ |
2084 | u32 val; |
2085 | ||
ab9412ba | 2086 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2087 | val &= ~TRANS_ENABLE; |
ab9412ba | 2088 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2089 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2090 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2091 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2092 | |
2093 | /* Workaround: clear timing override bit. */ | |
36c0d0cf | 2094 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2095 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2096 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
040484af JB |
2097 | } |
2098 | ||
b24e7179 | 2099 | /** |
309cfea8 | 2100 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2101 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2102 | * |
0372264a | 2103 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2104 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2105 | */ |
e1fdc473 | 2106 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2107 | { |
0372264a PZ |
2108 | struct drm_device *dev = crtc->base.dev; |
2109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2110 | enum pipe pipe = crtc->pipe; | |
1a70a728 | 2111 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
1a240d4d | 2112 | enum pipe pch_transcoder; |
f0f59a00 | 2113 | i915_reg_t reg; |
b24e7179 JB |
2114 | u32 val; |
2115 | ||
9e2ee2dd VS |
2116 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
2117 | ||
58c6eaa2 | 2118 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2119 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2120 | assert_sprites_disabled(dev_priv, pipe); |
2121 | ||
681e5811 | 2122 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2123 | pch_transcoder = TRANSCODER_A; |
2124 | else | |
2125 | pch_transcoder = pipe; | |
2126 | ||
b24e7179 JB |
2127 | /* |
2128 | * A pipe without a PLL won't actually be able to drive bits from | |
2129 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2130 | * need the check. | |
2131 | */ | |
50360403 | 2132 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
a65347ba | 2133 | if (crtc->config->has_dsi_encoder) |
23538ef1 JN |
2134 | assert_dsi_pll_enabled(dev_priv); |
2135 | else | |
2136 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2137 | else { |
6e3c9717 | 2138 | if (crtc->config->has_pch_encoder) { |
040484af | 2139 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2140 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2141 | assert_fdi_tx_pll_enabled(dev_priv, |
2142 | (enum pipe) cpu_transcoder); | |
040484af JB |
2143 | } |
2144 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2145 | } | |
b24e7179 | 2146 | |
702e7a56 | 2147 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2148 | val = I915_READ(reg); |
7ad25d48 | 2149 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2150 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2151 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2152 | return; |
7ad25d48 | 2153 | } |
00d70b15 CW |
2154 | |
2155 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2156 | POSTING_READ(reg); |
b24e7179 JB |
2157 | } |
2158 | ||
2159 | /** | |
309cfea8 | 2160 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2161 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2162 | * |
575f7ab7 VS |
2163 | * Disable the pipe of @crtc, making sure that various hardware |
2164 | * specific requirements are met, if applicable, e.g. plane | |
2165 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2166 | * |
2167 | * Will wait until the pipe has shut down before returning. | |
2168 | */ | |
575f7ab7 | 2169 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2170 | { |
575f7ab7 | 2171 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2172 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2173 | enum pipe pipe = crtc->pipe; |
f0f59a00 | 2174 | i915_reg_t reg; |
b24e7179 JB |
2175 | u32 val; |
2176 | ||
9e2ee2dd VS |
2177 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
2178 | ||
b24e7179 JB |
2179 | /* |
2180 | * Make sure planes won't keep trying to pump pixels to us, | |
2181 | * or we might hang the display. | |
2182 | */ | |
2183 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2184 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2185 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2186 | |
702e7a56 | 2187 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2188 | val = I915_READ(reg); |
00d70b15 CW |
2189 | if ((val & PIPECONF_ENABLE) == 0) |
2190 | return; | |
2191 | ||
67adc644 VS |
2192 | /* |
2193 | * Double wide has implications for planes | |
2194 | * so best keep it disabled when not needed. | |
2195 | */ | |
6e3c9717 | 2196 | if (crtc->config->double_wide) |
67adc644 VS |
2197 | val &= ~PIPECONF_DOUBLE_WIDE; |
2198 | ||
2199 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2200 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2201 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2202 | val &= ~PIPECONF_ENABLE; |
2203 | ||
2204 | I915_WRITE(reg, val); | |
2205 | if ((val & PIPECONF_ENABLE) == 0) | |
2206 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2207 | } |
2208 | ||
693db184 CW |
2209 | static bool need_vtd_wa(struct drm_device *dev) |
2210 | { | |
2211 | #ifdef CONFIG_INTEL_IOMMU | |
2212 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2213 | return true; | |
2214 | #endif | |
2215 | return false; | |
2216 | } | |
2217 | ||
50470bb0 | 2218 | unsigned int |
6761dd31 | 2219 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
fe47ea0c | 2220 | uint64_t fb_format_modifier, unsigned int plane) |
a57ce0b2 | 2221 | { |
6761dd31 TU |
2222 | unsigned int tile_height; |
2223 | uint32_t pixel_bytes; | |
a57ce0b2 | 2224 | |
b5d0e9bf DL |
2225 | switch (fb_format_modifier) { |
2226 | case DRM_FORMAT_MOD_NONE: | |
2227 | tile_height = 1; | |
2228 | break; | |
2229 | case I915_FORMAT_MOD_X_TILED: | |
2230 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2231 | break; | |
2232 | case I915_FORMAT_MOD_Y_TILED: | |
2233 | tile_height = 32; | |
2234 | break; | |
2235 | case I915_FORMAT_MOD_Yf_TILED: | |
fe47ea0c | 2236 | pixel_bytes = drm_format_plane_cpp(pixel_format, plane); |
6761dd31 | 2237 | switch (pixel_bytes) { |
b5d0e9bf | 2238 | default: |
6761dd31 | 2239 | case 1: |
b5d0e9bf DL |
2240 | tile_height = 64; |
2241 | break; | |
6761dd31 TU |
2242 | case 2: |
2243 | case 4: | |
b5d0e9bf DL |
2244 | tile_height = 32; |
2245 | break; | |
6761dd31 | 2246 | case 8: |
b5d0e9bf DL |
2247 | tile_height = 16; |
2248 | break; | |
6761dd31 | 2249 | case 16: |
b5d0e9bf DL |
2250 | WARN_ONCE(1, |
2251 | "128-bit pixels are not supported for display!"); | |
2252 | tile_height = 16; | |
2253 | break; | |
2254 | } | |
2255 | break; | |
2256 | default: | |
2257 | MISSING_CASE(fb_format_modifier); | |
2258 | tile_height = 1; | |
2259 | break; | |
2260 | } | |
091df6cb | 2261 | |
6761dd31 TU |
2262 | return tile_height; |
2263 | } | |
2264 | ||
2265 | unsigned int | |
2266 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2267 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2268 | { | |
2269 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
fe47ea0c | 2270 | fb_format_modifier, 0)); |
a57ce0b2 JB |
2271 | } |
2272 | ||
75c82a53 | 2273 | static void |
f64b98cd TU |
2274 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, |
2275 | const struct drm_plane_state *plane_state) | |
2276 | { | |
a6d09186 | 2277 | struct intel_rotation_info *info = &view->params.rotation_info; |
84fe03f7 | 2278 | unsigned int tile_height, tile_pitch; |
50470bb0 | 2279 | |
f64b98cd TU |
2280 | *view = i915_ggtt_view_normal; |
2281 | ||
50470bb0 | 2282 | if (!plane_state) |
75c82a53 | 2283 | return; |
50470bb0 | 2284 | |
121920fa | 2285 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
75c82a53 | 2286 | return; |
50470bb0 | 2287 | |
9abc4648 | 2288 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2289 | |
2290 | info->height = fb->height; | |
2291 | info->pixel_format = fb->pixel_format; | |
2292 | info->pitch = fb->pitches[0]; | |
89e3e142 | 2293 | info->uv_offset = fb->offsets[1]; |
50470bb0 TU |
2294 | info->fb_modifier = fb->modifier[0]; |
2295 | ||
84fe03f7 | 2296 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, |
fe47ea0c | 2297 | fb->modifier[0], 0); |
84fe03f7 TU |
2298 | tile_pitch = PAGE_SIZE / tile_height; |
2299 | info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2300 | info->height_pages = DIV_ROUND_UP(fb->height, tile_height); | |
2301 | info->size = info->width_pages * info->height_pages * PAGE_SIZE; | |
2302 | ||
89e3e142 TU |
2303 | if (info->pixel_format == DRM_FORMAT_NV12) { |
2304 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, | |
2305 | fb->modifier[0], 1); | |
2306 | tile_pitch = PAGE_SIZE / tile_height; | |
2307 | info->width_pages_uv = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2308 | info->height_pages_uv = DIV_ROUND_UP(fb->height / 2, | |
2309 | tile_height); | |
2310 | info->size_uv = info->width_pages_uv * info->height_pages_uv * | |
2311 | PAGE_SIZE; | |
2312 | } | |
f64b98cd TU |
2313 | } |
2314 | ||
4e9a86b6 VS |
2315 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
2316 | { | |
2317 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2318 | return 256 * 1024; | |
985b8bb4 VS |
2319 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
2320 | IS_VALLEYVIEW(dev_priv)) | |
4e9a86b6 VS |
2321 | return 128 * 1024; |
2322 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2323 | return 4 * 1024; | |
2324 | else | |
44c5905e | 2325 | return 0; |
4e9a86b6 VS |
2326 | } |
2327 | ||
127bd2ac | 2328 | int |
850c4cdc TU |
2329 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2330 | struct drm_framebuffer *fb, | |
7580d774 | 2331 | const struct drm_plane_state *plane_state) |
6b95a207 | 2332 | { |
850c4cdc | 2333 | struct drm_device *dev = fb->dev; |
ce453d81 | 2334 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2335 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2336 | struct i915_ggtt_view view; |
6b95a207 KH |
2337 | u32 alignment; |
2338 | int ret; | |
2339 | ||
ebcdd39e MR |
2340 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2341 | ||
7b911adc TU |
2342 | switch (fb->modifier[0]) { |
2343 | case DRM_FORMAT_MOD_NONE: | |
4e9a86b6 | 2344 | alignment = intel_linear_alignment(dev_priv); |
6b95a207 | 2345 | break; |
7b911adc | 2346 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2347 | if (INTEL_INFO(dev)->gen >= 9) |
2348 | alignment = 256 * 1024; | |
2349 | else { | |
2350 | /* pin() will align the object as required by fence */ | |
2351 | alignment = 0; | |
2352 | } | |
6b95a207 | 2353 | break; |
7b911adc | 2354 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2355 | case I915_FORMAT_MOD_Yf_TILED: |
2356 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2357 | "Y tiling bo slipped through, driver bug!\n")) | |
2358 | return -EINVAL; | |
2359 | alignment = 1 * 1024 * 1024; | |
2360 | break; | |
6b95a207 | 2361 | default: |
7b911adc TU |
2362 | MISSING_CASE(fb->modifier[0]); |
2363 | return -EINVAL; | |
6b95a207 KH |
2364 | } |
2365 | ||
75c82a53 | 2366 | intel_fill_fb_ggtt_view(&view, fb, plane_state); |
f64b98cd | 2367 | |
693db184 CW |
2368 | /* Note that the w/a also requires 64 PTE of padding following the |
2369 | * bo. We currently fill all unused PTE with the shadow page and so | |
2370 | * we should always have valid PTE following the scanout preventing | |
2371 | * the VT-d warning. | |
2372 | */ | |
2373 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2374 | alignment = 256 * 1024; | |
2375 | ||
d6dd6843 PZ |
2376 | /* |
2377 | * Global gtt pte registers are special registers which actually forward | |
2378 | * writes to a chunk of system memory. Which means that there is no risk | |
2379 | * that the register values disappear as soon as we call | |
2380 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2381 | * pin/unpin/fence and not more. | |
2382 | */ | |
2383 | intel_runtime_pm_get(dev_priv); | |
2384 | ||
7580d774 ML |
2385 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
2386 | &view); | |
48b956c5 | 2387 | if (ret) |
b26a6b35 | 2388 | goto err_pm; |
6b95a207 KH |
2389 | |
2390 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2391 | * fence, whereas 965+ only requires a fence if using | |
2392 | * framebuffer compression. For simplicity, we always install | |
2393 | * a fence as the cost is not that onerous. | |
2394 | */ | |
9807216f VK |
2395 | if (view.type == I915_GGTT_VIEW_NORMAL) { |
2396 | ret = i915_gem_object_get_fence(obj); | |
2397 | if (ret == -EDEADLK) { | |
2398 | /* | |
2399 | * -EDEADLK means there are no free fences | |
2400 | * no pending flips. | |
2401 | * | |
2402 | * This is propagated to atomic, but it uses | |
2403 | * -EDEADLK to force a locking recovery, so | |
2404 | * change the returned error to -EBUSY. | |
2405 | */ | |
2406 | ret = -EBUSY; | |
2407 | goto err_unpin; | |
2408 | } else if (ret) | |
2409 | goto err_unpin; | |
1690e1eb | 2410 | |
9807216f VK |
2411 | i915_gem_object_pin_fence(obj); |
2412 | } | |
6b95a207 | 2413 | |
d6dd6843 | 2414 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2415 | return 0; |
48b956c5 CW |
2416 | |
2417 | err_unpin: | |
f64b98cd | 2418 | i915_gem_object_unpin_from_display_plane(obj, &view); |
b26a6b35 | 2419 | err_pm: |
d6dd6843 | 2420 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2421 | return ret; |
6b95a207 KH |
2422 | } |
2423 | ||
82bc3b2d TU |
2424 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2425 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2426 | { |
82bc3b2d | 2427 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2428 | struct i915_ggtt_view view; |
82bc3b2d | 2429 | |
ebcdd39e MR |
2430 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2431 | ||
75c82a53 | 2432 | intel_fill_fb_ggtt_view(&view, fb, plane_state); |
f64b98cd | 2433 | |
9807216f VK |
2434 | if (view.type == I915_GGTT_VIEW_NORMAL) |
2435 | i915_gem_object_unpin_fence(obj); | |
2436 | ||
f64b98cd | 2437 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2438 | } |
2439 | ||
c2c75131 DV |
2440 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2441 | * is assumed to be a power-of-two. */ | |
4e9a86b6 VS |
2442 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
2443 | int *x, int *y, | |
bc752862 CW |
2444 | unsigned int tiling_mode, |
2445 | unsigned int cpp, | |
2446 | unsigned int pitch) | |
c2c75131 | 2447 | { |
bc752862 CW |
2448 | if (tiling_mode != I915_TILING_NONE) { |
2449 | unsigned int tile_rows, tiles; | |
c2c75131 | 2450 | |
bc752862 CW |
2451 | tile_rows = *y / 8; |
2452 | *y %= 8; | |
c2c75131 | 2453 | |
bc752862 CW |
2454 | tiles = *x / (512/cpp); |
2455 | *x %= 512/cpp; | |
2456 | ||
2457 | return tile_rows * pitch * 8 + tiles * 4096; | |
2458 | } else { | |
4e9a86b6 | 2459 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
bc752862 CW |
2460 | unsigned int offset; |
2461 | ||
2462 | offset = *y * pitch + *x * cpp; | |
4e9a86b6 VS |
2463 | *y = (offset & alignment) / pitch; |
2464 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2465 | return offset & ~alignment; | |
bc752862 | 2466 | } |
c2c75131 DV |
2467 | } |
2468 | ||
b35d63fa | 2469 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2470 | { |
2471 | switch (format) { | |
2472 | case DISPPLANE_8BPP: | |
2473 | return DRM_FORMAT_C8; | |
2474 | case DISPPLANE_BGRX555: | |
2475 | return DRM_FORMAT_XRGB1555; | |
2476 | case DISPPLANE_BGRX565: | |
2477 | return DRM_FORMAT_RGB565; | |
2478 | default: | |
2479 | case DISPPLANE_BGRX888: | |
2480 | return DRM_FORMAT_XRGB8888; | |
2481 | case DISPPLANE_RGBX888: | |
2482 | return DRM_FORMAT_XBGR8888; | |
2483 | case DISPPLANE_BGRX101010: | |
2484 | return DRM_FORMAT_XRGB2101010; | |
2485 | case DISPPLANE_RGBX101010: | |
2486 | return DRM_FORMAT_XBGR2101010; | |
2487 | } | |
2488 | } | |
2489 | ||
bc8d7dff DL |
2490 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2491 | { | |
2492 | switch (format) { | |
2493 | case PLANE_CTL_FORMAT_RGB_565: | |
2494 | return DRM_FORMAT_RGB565; | |
2495 | default: | |
2496 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2497 | if (rgb_order) { | |
2498 | if (alpha) | |
2499 | return DRM_FORMAT_ABGR8888; | |
2500 | else | |
2501 | return DRM_FORMAT_XBGR8888; | |
2502 | } else { | |
2503 | if (alpha) | |
2504 | return DRM_FORMAT_ARGB8888; | |
2505 | else | |
2506 | return DRM_FORMAT_XRGB8888; | |
2507 | } | |
2508 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2509 | if (rgb_order) | |
2510 | return DRM_FORMAT_XBGR2101010; | |
2511 | else | |
2512 | return DRM_FORMAT_XRGB2101010; | |
2513 | } | |
2514 | } | |
2515 | ||
5724dbd1 | 2516 | static bool |
f6936e29 DV |
2517 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2518 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2519 | { |
2520 | struct drm_device *dev = crtc->base.dev; | |
3badb49f | 2521 | struct drm_i915_private *dev_priv = to_i915(dev); |
46f297fb JB |
2522 | struct drm_i915_gem_object *obj = NULL; |
2523 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2524 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2525 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2526 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2527 | PAGE_SIZE); | |
2528 | ||
2529 | size_aligned -= base_aligned; | |
46f297fb | 2530 | |
ff2652ea CW |
2531 | if (plane_config->size == 0) |
2532 | return false; | |
2533 | ||
3badb49f PZ |
2534 | /* If the FB is too big, just don't use it since fbdev is not very |
2535 | * important and we should probably use that space with FBC or other | |
2536 | * features. */ | |
2537 | if (size_aligned * 2 > dev_priv->gtt.stolen_usable_size) | |
2538 | return false; | |
2539 | ||
f37b5c2b DV |
2540 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2541 | base_aligned, | |
2542 | base_aligned, | |
2543 | size_aligned); | |
46f297fb | 2544 | if (!obj) |
484b41dd | 2545 | return false; |
46f297fb | 2546 | |
49af449b DL |
2547 | obj->tiling_mode = plane_config->tiling; |
2548 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2549 | obj->stride = fb->pitches[0]; |
46f297fb | 2550 | |
6bf129df DL |
2551 | mode_cmd.pixel_format = fb->pixel_format; |
2552 | mode_cmd.width = fb->width; | |
2553 | mode_cmd.height = fb->height; | |
2554 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2555 | mode_cmd.modifier[0] = fb->modifier[0]; |
2556 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2557 | |
2558 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2559 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2560 | &mode_cmd, obj)) { |
46f297fb JB |
2561 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2562 | goto out_unref_obj; | |
2563 | } | |
46f297fb | 2564 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2565 | |
f6936e29 | 2566 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2567 | return true; |
46f297fb JB |
2568 | |
2569 | out_unref_obj: | |
2570 | drm_gem_object_unreference(&obj->base); | |
2571 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2572 | return false; |
2573 | } | |
2574 | ||
afd65eb4 MR |
2575 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2576 | static void | |
2577 | update_state_fb(struct drm_plane *plane) | |
2578 | { | |
2579 | if (plane->fb == plane->state->fb) | |
2580 | return; | |
2581 | ||
2582 | if (plane->state->fb) | |
2583 | drm_framebuffer_unreference(plane->state->fb); | |
2584 | plane->state->fb = plane->fb; | |
2585 | if (plane->state->fb) | |
2586 | drm_framebuffer_reference(plane->state->fb); | |
2587 | } | |
2588 | ||
5724dbd1 | 2589 | static void |
f6936e29 DV |
2590 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2591 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2592 | { |
2593 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2594 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2595 | struct drm_crtc *c; |
2596 | struct intel_crtc *i; | |
2ff8fde1 | 2597 | struct drm_i915_gem_object *obj; |
88595ac9 | 2598 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2599 | struct drm_plane_state *plane_state = primary->state; |
88595ac9 | 2600 | struct drm_framebuffer *fb; |
484b41dd | 2601 | |
2d14030b | 2602 | if (!plane_config->fb) |
484b41dd JB |
2603 | return; |
2604 | ||
f6936e29 | 2605 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2606 | fb = &plane_config->fb->base; |
2607 | goto valid_fb; | |
f55548b5 | 2608 | } |
484b41dd | 2609 | |
2d14030b | 2610 | kfree(plane_config->fb); |
484b41dd JB |
2611 | |
2612 | /* | |
2613 | * Failed to alloc the obj, check to see if we should share | |
2614 | * an fb with another CRTC instead | |
2615 | */ | |
70e1e0ec | 2616 | for_each_crtc(dev, c) { |
484b41dd JB |
2617 | i = to_intel_crtc(c); |
2618 | ||
2619 | if (c == &intel_crtc->base) | |
2620 | continue; | |
2621 | ||
2ff8fde1 MR |
2622 | if (!i->active) |
2623 | continue; | |
2624 | ||
88595ac9 DV |
2625 | fb = c->primary->fb; |
2626 | if (!fb) | |
484b41dd JB |
2627 | continue; |
2628 | ||
88595ac9 | 2629 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2630 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2631 | drm_framebuffer_reference(fb); |
2632 | goto valid_fb; | |
484b41dd JB |
2633 | } |
2634 | } | |
88595ac9 DV |
2635 | |
2636 | return; | |
2637 | ||
2638 | valid_fb: | |
f44e2659 VS |
2639 | plane_state->src_x = 0; |
2640 | plane_state->src_y = 0; | |
be5651f2 ML |
2641 | plane_state->src_w = fb->width << 16; |
2642 | plane_state->src_h = fb->height << 16; | |
2643 | ||
f44e2659 VS |
2644 | plane_state->crtc_x = 0; |
2645 | plane_state->crtc_y = 0; | |
be5651f2 ML |
2646 | plane_state->crtc_w = fb->width; |
2647 | plane_state->crtc_h = fb->height; | |
2648 | ||
88595ac9 DV |
2649 | obj = intel_fb_obj(fb); |
2650 | if (obj->tiling_mode != I915_TILING_NONE) | |
2651 | dev_priv->preserve_bios_swizzle = true; | |
2652 | ||
be5651f2 ML |
2653 | drm_framebuffer_reference(fb); |
2654 | primary->fb = primary->state->fb = fb; | |
36750f28 | 2655 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
36750f28 | 2656 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
a9ff8714 | 2657 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
46f297fb JB |
2658 | } |
2659 | ||
29b9bde6 DV |
2660 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2661 | struct drm_framebuffer *fb, | |
2662 | int x, int y) | |
81255565 JB |
2663 | { |
2664 | struct drm_device *dev = crtc->dev; | |
2665 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2666 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2667 | struct drm_plane *primary = crtc->primary; |
2668 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2669 | struct drm_i915_gem_object *obj; |
81255565 | 2670 | int plane = intel_crtc->plane; |
e506a0c6 | 2671 | unsigned long linear_offset; |
81255565 | 2672 | u32 dspcntr; |
f0f59a00 | 2673 | i915_reg_t reg = DSPCNTR(plane); |
48404c1e | 2674 | int pixel_size; |
f45651ba | 2675 | |
b70709a6 | 2676 | if (!visible || !fb) { |
fdd508a6 VS |
2677 | I915_WRITE(reg, 0); |
2678 | if (INTEL_INFO(dev)->gen >= 4) | |
2679 | I915_WRITE(DSPSURF(plane), 0); | |
2680 | else | |
2681 | I915_WRITE(DSPADDR(plane), 0); | |
2682 | POSTING_READ(reg); | |
2683 | return; | |
2684 | } | |
2685 | ||
c9ba6fad VS |
2686 | obj = intel_fb_obj(fb); |
2687 | if (WARN_ON(obj == NULL)) | |
2688 | return; | |
2689 | ||
2690 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2691 | ||
f45651ba VS |
2692 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2693 | ||
fdd508a6 | 2694 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2695 | |
2696 | if (INTEL_INFO(dev)->gen < 4) { | |
2697 | if (intel_crtc->pipe == PIPE_B) | |
2698 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2699 | ||
2700 | /* pipesrc and dspsize control the size that is scaled from, | |
2701 | * which should always be the user's requested size. | |
2702 | */ | |
2703 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2704 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2705 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2706 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2707 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2708 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2709 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2710 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2711 | I915_WRITE(PRIMPOS(plane), 0); |
2712 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2713 | } |
81255565 | 2714 | |
57779d06 VS |
2715 | switch (fb->pixel_format) { |
2716 | case DRM_FORMAT_C8: | |
81255565 JB |
2717 | dspcntr |= DISPPLANE_8BPP; |
2718 | break; | |
57779d06 | 2719 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2720 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2721 | break; |
57779d06 VS |
2722 | case DRM_FORMAT_RGB565: |
2723 | dspcntr |= DISPPLANE_BGRX565; | |
2724 | break; | |
2725 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2726 | dspcntr |= DISPPLANE_BGRX888; |
2727 | break; | |
2728 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2729 | dspcntr |= DISPPLANE_RGBX888; |
2730 | break; | |
2731 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2732 | dspcntr |= DISPPLANE_BGRX101010; |
2733 | break; | |
2734 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2735 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2736 | break; |
2737 | default: | |
baba133a | 2738 | BUG(); |
81255565 | 2739 | } |
57779d06 | 2740 | |
f45651ba VS |
2741 | if (INTEL_INFO(dev)->gen >= 4 && |
2742 | obj->tiling_mode != I915_TILING_NONE) | |
2743 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2744 | |
de1aa629 VS |
2745 | if (IS_G4X(dev)) |
2746 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2747 | ||
b9897127 | 2748 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2749 | |
c2c75131 DV |
2750 | if (INTEL_INFO(dev)->gen >= 4) { |
2751 | intel_crtc->dspaddr_offset = | |
4e9a86b6 VS |
2752 | intel_gen4_compute_page_offset(dev_priv, |
2753 | &x, &y, obj->tiling_mode, | |
b9897127 | 2754 | pixel_size, |
bc752862 | 2755 | fb->pitches[0]); |
c2c75131 DV |
2756 | linear_offset -= intel_crtc->dspaddr_offset; |
2757 | } else { | |
e506a0c6 | 2758 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2759 | } |
e506a0c6 | 2760 | |
8e7d688b | 2761 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2762 | dspcntr |= DISPPLANE_ROTATE_180; |
2763 | ||
6e3c9717 ACO |
2764 | x += (intel_crtc->config->pipe_src_w - 1); |
2765 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2766 | |
2767 | /* Finding the last pixel of the last line of the display | |
2768 | data and adding to linear_offset*/ | |
2769 | linear_offset += | |
6e3c9717 ACO |
2770 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2771 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2772 | } |
2773 | ||
2db3366b PZ |
2774 | intel_crtc->adjusted_x = x; |
2775 | intel_crtc->adjusted_y = y; | |
2776 | ||
48404c1e SJ |
2777 | I915_WRITE(reg, dspcntr); |
2778 | ||
01f2c773 | 2779 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2780 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2781 | I915_WRITE(DSPSURF(plane), |
2782 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2783 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2784 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2785 | } else |
f343c5f6 | 2786 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2787 | POSTING_READ(reg); |
17638cd6 JB |
2788 | } |
2789 | ||
29b9bde6 DV |
2790 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2791 | struct drm_framebuffer *fb, | |
2792 | int x, int y) | |
17638cd6 JB |
2793 | { |
2794 | struct drm_device *dev = crtc->dev; | |
2795 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2796 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2797 | struct drm_plane *primary = crtc->primary; |
2798 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2799 | struct drm_i915_gem_object *obj; |
17638cd6 | 2800 | int plane = intel_crtc->plane; |
e506a0c6 | 2801 | unsigned long linear_offset; |
17638cd6 | 2802 | u32 dspcntr; |
f0f59a00 | 2803 | i915_reg_t reg = DSPCNTR(plane); |
48404c1e | 2804 | int pixel_size; |
f45651ba | 2805 | |
b70709a6 | 2806 | if (!visible || !fb) { |
fdd508a6 VS |
2807 | I915_WRITE(reg, 0); |
2808 | I915_WRITE(DSPSURF(plane), 0); | |
2809 | POSTING_READ(reg); | |
2810 | return; | |
2811 | } | |
2812 | ||
c9ba6fad VS |
2813 | obj = intel_fb_obj(fb); |
2814 | if (WARN_ON(obj == NULL)) | |
2815 | return; | |
2816 | ||
2817 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2818 | ||
f45651ba VS |
2819 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2820 | ||
fdd508a6 | 2821 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2822 | |
2823 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2824 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2825 | |
57779d06 VS |
2826 | switch (fb->pixel_format) { |
2827 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2828 | dspcntr |= DISPPLANE_8BPP; |
2829 | break; | |
57779d06 VS |
2830 | case DRM_FORMAT_RGB565: |
2831 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2832 | break; |
57779d06 | 2833 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2834 | dspcntr |= DISPPLANE_BGRX888; |
2835 | break; | |
2836 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2837 | dspcntr |= DISPPLANE_RGBX888; |
2838 | break; | |
2839 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2840 | dspcntr |= DISPPLANE_BGRX101010; |
2841 | break; | |
2842 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2843 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2844 | break; |
2845 | default: | |
baba133a | 2846 | BUG(); |
17638cd6 JB |
2847 | } |
2848 | ||
2849 | if (obj->tiling_mode != I915_TILING_NONE) | |
2850 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2851 | |
f45651ba | 2852 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2853 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2854 | |
b9897127 | 2855 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2856 | intel_crtc->dspaddr_offset = |
4e9a86b6 VS |
2857 | intel_gen4_compute_page_offset(dev_priv, |
2858 | &x, &y, obj->tiling_mode, | |
b9897127 | 2859 | pixel_size, |
bc752862 | 2860 | fb->pitches[0]); |
c2c75131 | 2861 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2862 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2863 | dspcntr |= DISPPLANE_ROTATE_180; |
2864 | ||
2865 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2866 | x += (intel_crtc->config->pipe_src_w - 1); |
2867 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2868 | |
2869 | /* Finding the last pixel of the last line of the display | |
2870 | data and adding to linear_offset*/ | |
2871 | linear_offset += | |
6e3c9717 ACO |
2872 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2873 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2874 | } |
2875 | } | |
2876 | ||
2db3366b PZ |
2877 | intel_crtc->adjusted_x = x; |
2878 | intel_crtc->adjusted_y = y; | |
2879 | ||
48404c1e | 2880 | I915_WRITE(reg, dspcntr); |
17638cd6 | 2881 | |
01f2c773 | 2882 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2883 | I915_WRITE(DSPSURF(plane), |
2884 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2885 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2886 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2887 | } else { | |
2888 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2889 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2890 | } | |
17638cd6 | 2891 | POSTING_READ(reg); |
17638cd6 JB |
2892 | } |
2893 | ||
b321803d DL |
2894 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2895 | uint32_t pixel_format) | |
2896 | { | |
2897 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2898 | ||
2899 | /* | |
2900 | * The stride is either expressed as a multiple of 64 bytes | |
2901 | * chunks for linear buffers or in number of tiles for tiled | |
2902 | * buffers. | |
2903 | */ | |
2904 | switch (fb_modifier) { | |
2905 | case DRM_FORMAT_MOD_NONE: | |
2906 | return 64; | |
2907 | case I915_FORMAT_MOD_X_TILED: | |
2908 | if (INTEL_INFO(dev)->gen == 2) | |
2909 | return 128; | |
2910 | return 512; | |
2911 | case I915_FORMAT_MOD_Y_TILED: | |
2912 | /* No need to check for old gens and Y tiling since this is | |
2913 | * about the display engine and those will be blocked before | |
2914 | * we get here. | |
2915 | */ | |
2916 | return 128; | |
2917 | case I915_FORMAT_MOD_Yf_TILED: | |
2918 | if (bits_per_pixel == 8) | |
2919 | return 64; | |
2920 | else | |
2921 | return 128; | |
2922 | default: | |
2923 | MISSING_CASE(fb_modifier); | |
2924 | return 64; | |
2925 | } | |
2926 | } | |
2927 | ||
44eb0cb9 MK |
2928 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
2929 | struct drm_i915_gem_object *obj, | |
2930 | unsigned int plane) | |
121920fa | 2931 | { |
ce7f1728 | 2932 | struct i915_ggtt_view view; |
dedf278c | 2933 | struct i915_vma *vma; |
44eb0cb9 | 2934 | u64 offset; |
121920fa | 2935 | |
ce7f1728 DV |
2936 | intel_fill_fb_ggtt_view(&view, intel_plane->base.fb, |
2937 | intel_plane->base.state); | |
121920fa | 2938 | |
ce7f1728 | 2939 | vma = i915_gem_obj_to_ggtt_view(obj, &view); |
dedf278c | 2940 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", |
ce7f1728 | 2941 | view.type)) |
dedf278c TU |
2942 | return -1; |
2943 | ||
44eb0cb9 | 2944 | offset = vma->node.start; |
dedf278c TU |
2945 | |
2946 | if (plane == 1) { | |
a6d09186 | 2947 | offset += vma->ggtt_view.params.rotation_info.uv_start_page * |
dedf278c TU |
2948 | PAGE_SIZE; |
2949 | } | |
2950 | ||
44eb0cb9 MK |
2951 | WARN_ON(upper_32_bits(offset)); |
2952 | ||
2953 | return lower_32_bits(offset); | |
121920fa TU |
2954 | } |
2955 | ||
e435d6e5 ML |
2956 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
2957 | { | |
2958 | struct drm_device *dev = intel_crtc->base.dev; | |
2959 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2960 | ||
2961 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
2962 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
2963 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
2964 | } |
2965 | ||
a1b2278e CK |
2966 | /* |
2967 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2968 | */ | |
0583236e | 2969 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 2970 | { |
a1b2278e CK |
2971 | struct intel_crtc_scaler_state *scaler_state; |
2972 | int i; | |
2973 | ||
a1b2278e CK |
2974 | scaler_state = &intel_crtc->config->scaler_state; |
2975 | ||
2976 | /* loop through and disable scalers that aren't in use */ | |
2977 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
2978 | if (!scaler_state->scalers[i].in_use) |
2979 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
2980 | } |
2981 | } | |
2982 | ||
6156a456 | 2983 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2984 | { |
6156a456 | 2985 | switch (pixel_format) { |
d161cf7a | 2986 | case DRM_FORMAT_C8: |
c34ce3d1 | 2987 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2988 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2989 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2990 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2991 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2992 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2993 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2994 | /* |
2995 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2996 | * to be already pre-multiplied. We need to add a knob (or a different | |
2997 | * DRM_FORMAT) for user-space to configure that. | |
2998 | */ | |
f75fb42a | 2999 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 3000 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 3001 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 3002 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 3003 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 3004 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 3005 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 3006 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 3007 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 3008 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 3009 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 3010 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 3011 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 3012 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 3013 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 3014 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 3015 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 3016 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 3017 | default: |
4249eeef | 3018 | MISSING_CASE(pixel_format); |
70d21f0e | 3019 | } |
8cfcba41 | 3020 | |
c34ce3d1 | 3021 | return 0; |
6156a456 | 3022 | } |
70d21f0e | 3023 | |
6156a456 CK |
3024 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
3025 | { | |
6156a456 | 3026 | switch (fb_modifier) { |
30af77c4 | 3027 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 3028 | break; |
30af77c4 | 3029 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 3030 | return PLANE_CTL_TILED_X; |
b321803d | 3031 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 3032 | return PLANE_CTL_TILED_Y; |
b321803d | 3033 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3034 | return PLANE_CTL_TILED_YF; |
70d21f0e | 3035 | default: |
6156a456 | 3036 | MISSING_CASE(fb_modifier); |
70d21f0e | 3037 | } |
8cfcba41 | 3038 | |
c34ce3d1 | 3039 | return 0; |
6156a456 | 3040 | } |
70d21f0e | 3041 | |
6156a456 CK |
3042 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
3043 | { | |
3b7a5119 | 3044 | switch (rotation) { |
6156a456 CK |
3045 | case BIT(DRM_ROTATE_0): |
3046 | break; | |
1e8df167 SJ |
3047 | /* |
3048 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3049 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3050 | */ | |
3b7a5119 | 3051 | case BIT(DRM_ROTATE_90): |
1e8df167 | 3052 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 3053 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3054 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3055 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3056 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3057 | default: |
3058 | MISSING_CASE(rotation); | |
3059 | } | |
3060 | ||
c34ce3d1 | 3061 | return 0; |
6156a456 CK |
3062 | } |
3063 | ||
3064 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
3065 | struct drm_framebuffer *fb, | |
3066 | int x, int y) | |
3067 | { | |
3068 | struct drm_device *dev = crtc->dev; | |
3069 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3070 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3071 | struct drm_plane *plane = crtc->primary; |
3072 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3073 | struct drm_i915_gem_object *obj; |
3074 | int pipe = intel_crtc->pipe; | |
3075 | u32 plane_ctl, stride_div, stride; | |
3076 | u32 tile_height, plane_offset, plane_size; | |
3077 | unsigned int rotation; | |
3078 | int x_offset, y_offset; | |
44eb0cb9 | 3079 | u32 surf_addr; |
6156a456 CK |
3080 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3081 | struct intel_plane_state *plane_state; | |
3082 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3083 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3084 | int scaler_id = -1; | |
3085 | ||
6156a456 CK |
3086 | plane_state = to_intel_plane_state(plane->state); |
3087 | ||
b70709a6 | 3088 | if (!visible || !fb) { |
6156a456 CK |
3089 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3090 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3091 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3092 | return; | |
3b7a5119 | 3093 | } |
70d21f0e | 3094 | |
6156a456 CK |
3095 | plane_ctl = PLANE_CTL_ENABLE | |
3096 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3097 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3098 | ||
3099 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3100 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3101 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3102 | ||
3103 | rotation = plane->state->rotation; | |
3104 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3105 | ||
b321803d DL |
3106 | obj = intel_fb_obj(fb); |
3107 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3108 | fb->pixel_format); | |
dedf278c | 3109 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
3b7a5119 | 3110 | |
a42e5a23 PZ |
3111 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
3112 | ||
3113 | scaler_id = plane_state->scaler_id; | |
3114 | src_x = plane_state->src.x1 >> 16; | |
3115 | src_y = plane_state->src.y1 >> 16; | |
3116 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3117 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3118 | dst_x = plane_state->dst.x1; | |
3119 | dst_y = plane_state->dst.y1; | |
3120 | dst_w = drm_rect_width(&plane_state->dst); | |
3121 | dst_h = drm_rect_height(&plane_state->dst); | |
3122 | ||
3123 | WARN_ON(x != src_x || y != src_y); | |
6156a456 | 3124 | |
3b7a5119 SJ |
3125 | if (intel_rotation_90_or_270(rotation)) { |
3126 | /* stride = Surface height in tiles */ | |
2614f17d | 3127 | tile_height = intel_tile_height(dev, fb->pixel_format, |
fe47ea0c | 3128 | fb->modifier[0], 0); |
3b7a5119 | 3129 | stride = DIV_ROUND_UP(fb->height, tile_height); |
6156a456 | 3130 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3131 | y_offset = x; |
6156a456 | 3132 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3133 | } else { |
3134 | stride = fb->pitches[0] / stride_div; | |
3135 | x_offset = x; | |
3136 | y_offset = y; | |
6156a456 | 3137 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3138 | } |
3139 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3140 | |
2db3366b PZ |
3141 | intel_crtc->adjusted_x = x_offset; |
3142 | intel_crtc->adjusted_y = y_offset; | |
3143 | ||
70d21f0e | 3144 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3145 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3146 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3147 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3148 | |
3149 | if (scaler_id >= 0) { | |
3150 | uint32_t ps_ctrl = 0; | |
3151 | ||
3152 | WARN_ON(!dst_w || !dst_h); | |
3153 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3154 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3155 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3156 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3157 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3158 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3159 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3160 | } else { | |
3161 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3162 | } | |
3163 | ||
121920fa | 3164 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3165 | |
3166 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3167 | } | |
3168 | ||
17638cd6 JB |
3169 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3170 | static int | |
3171 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3172 | int x, int y, enum mode_set_atomic state) | |
3173 | { | |
3174 | struct drm_device *dev = crtc->dev; | |
3175 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3176 | |
0e631adc PZ |
3177 | if (dev_priv->fbc.deactivate) |
3178 | dev_priv->fbc.deactivate(dev_priv); | |
81255565 | 3179 | |
29b9bde6 DV |
3180 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3181 | ||
3182 | return 0; | |
81255565 JB |
3183 | } |
3184 | ||
7514747d | 3185 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3186 | { |
96a02917 VS |
3187 | struct drm_crtc *crtc; |
3188 | ||
70e1e0ec | 3189 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3190 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3191 | enum plane plane = intel_crtc->plane; | |
3192 | ||
3193 | intel_prepare_page_flip(dev, plane); | |
3194 | intel_finish_page_flip_plane(dev, plane); | |
3195 | } | |
7514747d VS |
3196 | } |
3197 | ||
3198 | static void intel_update_primary_planes(struct drm_device *dev) | |
3199 | { | |
7514747d | 3200 | struct drm_crtc *crtc; |
96a02917 | 3201 | |
70e1e0ec | 3202 | for_each_crtc(dev, crtc) { |
11c22da6 ML |
3203 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
3204 | struct intel_plane_state *plane_state; | |
96a02917 | 3205 | |
11c22da6 | 3206 | drm_modeset_lock_crtc(crtc, &plane->base); |
11c22da6 ML |
3207 | plane_state = to_intel_plane_state(plane->base.state); |
3208 | ||
f029ee82 | 3209 | if (crtc->state->active && plane_state->base.fb) |
11c22da6 ML |
3210 | plane->commit_plane(&plane->base, plane_state); |
3211 | ||
3212 | drm_modeset_unlock_crtc(crtc); | |
96a02917 VS |
3213 | } |
3214 | } | |
3215 | ||
7514747d VS |
3216 | void intel_prepare_reset(struct drm_device *dev) |
3217 | { | |
3218 | /* no reset support for gen2 */ | |
3219 | if (IS_GEN2(dev)) | |
3220 | return; | |
3221 | ||
3222 | /* reset doesn't touch the display */ | |
3223 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3224 | return; | |
3225 | ||
3226 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3227 | /* |
3228 | * Disabling the crtcs gracefully seems nicer. Also the | |
3229 | * g33 docs say we should at least disable all the planes. | |
3230 | */ | |
6b72d486 | 3231 | intel_display_suspend(dev); |
7514747d VS |
3232 | } |
3233 | ||
3234 | void intel_finish_reset(struct drm_device *dev) | |
3235 | { | |
3236 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3237 | ||
3238 | /* | |
3239 | * Flips in the rings will be nuked by the reset, | |
3240 | * so complete all pending flips so that user space | |
3241 | * will get its events and not get stuck. | |
3242 | */ | |
3243 | intel_complete_page_flips(dev); | |
3244 | ||
3245 | /* no reset support for gen2 */ | |
3246 | if (IS_GEN2(dev)) | |
3247 | return; | |
3248 | ||
3249 | /* reset doesn't touch the display */ | |
3250 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3251 | /* | |
3252 | * Flips in the rings have been nuked by the reset, | |
3253 | * so update the base address of all primary | |
3254 | * planes to the the last fb to make sure we're | |
3255 | * showing the correct fb after a reset. | |
11c22da6 ML |
3256 | * |
3257 | * FIXME: Atomic will make this obsolete since we won't schedule | |
3258 | * CS-based flips (which might get lost in gpu resets) any more. | |
7514747d VS |
3259 | */ |
3260 | intel_update_primary_planes(dev); | |
3261 | return; | |
3262 | } | |
3263 | ||
3264 | /* | |
3265 | * The display has been reset as well, | |
3266 | * so need a full re-initialization. | |
3267 | */ | |
3268 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3269 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3270 | ||
3271 | intel_modeset_init_hw(dev); | |
3272 | ||
3273 | spin_lock_irq(&dev_priv->irq_lock); | |
3274 | if (dev_priv->display.hpd_irq_setup) | |
3275 | dev_priv->display.hpd_irq_setup(dev); | |
3276 | spin_unlock_irq(&dev_priv->irq_lock); | |
3277 | ||
043e9bda | 3278 | intel_display_resume(dev); |
7514747d VS |
3279 | |
3280 | intel_hpd_init(dev_priv); | |
3281 | ||
3282 | drm_modeset_unlock_all(dev); | |
3283 | } | |
3284 | ||
7d5e3799 CW |
3285 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3286 | { | |
3287 | struct drm_device *dev = crtc->dev; | |
3288 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3289 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3290 | bool pending; |
3291 | ||
3292 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3293 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3294 | return false; | |
3295 | ||
5e2d7afc | 3296 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3297 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3298 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3299 | |
3300 | return pending; | |
3301 | } | |
3302 | ||
bfd16b2a ML |
3303 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
3304 | struct intel_crtc_state *old_crtc_state) | |
e30e8f75 GP |
3305 | { |
3306 | struct drm_device *dev = crtc->base.dev; | |
3307 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bfd16b2a ML |
3308 | struct intel_crtc_state *pipe_config = |
3309 | to_intel_crtc_state(crtc->base.state); | |
e30e8f75 | 3310 | |
bfd16b2a ML |
3311 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
3312 | crtc->base.mode = crtc->base.state->mode; | |
3313 | ||
3314 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", | |
3315 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, | |
3316 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
e30e8f75 | 3317 | |
44522d85 ML |
3318 | if (HAS_DDI(dev)) |
3319 | intel_set_pipe_csc(&crtc->base); | |
3320 | ||
e30e8f75 GP |
3321 | /* |
3322 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3323 | * that in compute_mode_changes we check the native mode (not the pfit | |
3324 | * mode) to see if we can flip rather than do a full mode set. In the | |
3325 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3326 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3327 | * sized surface. | |
e30e8f75 GP |
3328 | */ |
3329 | ||
e30e8f75 | 3330 | I915_WRITE(PIPESRC(crtc->pipe), |
bfd16b2a ML |
3331 | ((pipe_config->pipe_src_w - 1) << 16) | |
3332 | (pipe_config->pipe_src_h - 1)); | |
3333 | ||
3334 | /* on skylake this is done by detaching scalers */ | |
3335 | if (INTEL_INFO(dev)->gen >= 9) { | |
3336 | skl_detach_scalers(crtc); | |
3337 | ||
3338 | if (pipe_config->pch_pfit.enabled) | |
3339 | skylake_pfit_enable(crtc); | |
3340 | } else if (HAS_PCH_SPLIT(dev)) { | |
3341 | if (pipe_config->pch_pfit.enabled) | |
3342 | ironlake_pfit_enable(crtc); | |
3343 | else if (old_crtc_state->pch_pfit.enabled) | |
3344 | ironlake_pfit_disable(crtc, true); | |
e30e8f75 | 3345 | } |
e30e8f75 GP |
3346 | } |
3347 | ||
5e84e1a4 ZW |
3348 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3349 | { | |
3350 | struct drm_device *dev = crtc->dev; | |
3351 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3352 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3353 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3354 | i915_reg_t reg; |
3355 | u32 temp; | |
5e84e1a4 ZW |
3356 | |
3357 | /* enable normal train */ | |
3358 | reg = FDI_TX_CTL(pipe); | |
3359 | temp = I915_READ(reg); | |
61e499bf | 3360 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3361 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3362 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3363 | } else { |
3364 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3365 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3366 | } |
5e84e1a4 ZW |
3367 | I915_WRITE(reg, temp); |
3368 | ||
3369 | reg = FDI_RX_CTL(pipe); | |
3370 | temp = I915_READ(reg); | |
3371 | if (HAS_PCH_CPT(dev)) { | |
3372 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3373 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3374 | } else { | |
3375 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3376 | temp |= FDI_LINK_TRAIN_NONE; | |
3377 | } | |
3378 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3379 | ||
3380 | /* wait one idle pattern time */ | |
3381 | POSTING_READ(reg); | |
3382 | udelay(1000); | |
357555c0 JB |
3383 | |
3384 | /* IVB wants error correction enabled */ | |
3385 | if (IS_IVYBRIDGE(dev)) | |
3386 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3387 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3388 | } |
3389 | ||
8db9d77b ZW |
3390 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3391 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3392 | { | |
3393 | struct drm_device *dev = crtc->dev; | |
3394 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3395 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3396 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3397 | i915_reg_t reg; |
3398 | u32 temp, tries; | |
8db9d77b | 3399 | |
1c8562f6 | 3400 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3401 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3402 | |
e1a44743 AJ |
3403 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3404 | for train result */ | |
5eddb70b CW |
3405 | reg = FDI_RX_IMR(pipe); |
3406 | temp = I915_READ(reg); | |
e1a44743 AJ |
3407 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3408 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3409 | I915_WRITE(reg, temp); |
3410 | I915_READ(reg); | |
e1a44743 AJ |
3411 | udelay(150); |
3412 | ||
8db9d77b | 3413 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3414 | reg = FDI_TX_CTL(pipe); |
3415 | temp = I915_READ(reg); | |
627eb5a3 | 3416 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3417 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3418 | temp &= ~FDI_LINK_TRAIN_NONE; |
3419 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3420 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3421 | |
5eddb70b CW |
3422 | reg = FDI_RX_CTL(pipe); |
3423 | temp = I915_READ(reg); | |
8db9d77b ZW |
3424 | temp &= ~FDI_LINK_TRAIN_NONE; |
3425 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3426 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3427 | ||
3428 | POSTING_READ(reg); | |
8db9d77b ZW |
3429 | udelay(150); |
3430 | ||
5b2adf89 | 3431 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3432 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3433 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3434 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3435 | |
5eddb70b | 3436 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3437 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3438 | temp = I915_READ(reg); |
8db9d77b ZW |
3439 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3440 | ||
3441 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3442 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3443 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3444 | break; |
3445 | } | |
8db9d77b | 3446 | } |
e1a44743 | 3447 | if (tries == 5) |
5eddb70b | 3448 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3449 | |
3450 | /* Train 2 */ | |
5eddb70b CW |
3451 | reg = FDI_TX_CTL(pipe); |
3452 | temp = I915_READ(reg); | |
8db9d77b ZW |
3453 | temp &= ~FDI_LINK_TRAIN_NONE; |
3454 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3455 | I915_WRITE(reg, temp); |
8db9d77b | 3456 | |
5eddb70b CW |
3457 | reg = FDI_RX_CTL(pipe); |
3458 | temp = I915_READ(reg); | |
8db9d77b ZW |
3459 | temp &= ~FDI_LINK_TRAIN_NONE; |
3460 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3461 | I915_WRITE(reg, temp); |
8db9d77b | 3462 | |
5eddb70b CW |
3463 | POSTING_READ(reg); |
3464 | udelay(150); | |
8db9d77b | 3465 | |
5eddb70b | 3466 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3467 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3468 | temp = I915_READ(reg); |
8db9d77b ZW |
3469 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3470 | ||
3471 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3472 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3473 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3474 | break; | |
3475 | } | |
8db9d77b | 3476 | } |
e1a44743 | 3477 | if (tries == 5) |
5eddb70b | 3478 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3479 | |
3480 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3481 | |
8db9d77b ZW |
3482 | } |
3483 | ||
0206e353 | 3484 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3485 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3486 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3487 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3488 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3489 | }; | |
3490 | ||
3491 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3492 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3493 | { | |
3494 | struct drm_device *dev = crtc->dev; | |
3495 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3496 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3497 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3498 | i915_reg_t reg; |
3499 | u32 temp, i, retry; | |
8db9d77b | 3500 | |
e1a44743 AJ |
3501 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3502 | for train result */ | |
5eddb70b CW |
3503 | reg = FDI_RX_IMR(pipe); |
3504 | temp = I915_READ(reg); | |
e1a44743 AJ |
3505 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3506 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3507 | I915_WRITE(reg, temp); |
3508 | ||
3509 | POSTING_READ(reg); | |
e1a44743 AJ |
3510 | udelay(150); |
3511 | ||
8db9d77b | 3512 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3513 | reg = FDI_TX_CTL(pipe); |
3514 | temp = I915_READ(reg); | |
627eb5a3 | 3515 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3516 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3517 | temp &= ~FDI_LINK_TRAIN_NONE; |
3518 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3519 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3520 | /* SNB-B */ | |
3521 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3522 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3523 | |
d74cf324 DV |
3524 | I915_WRITE(FDI_RX_MISC(pipe), |
3525 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3526 | ||
5eddb70b CW |
3527 | reg = FDI_RX_CTL(pipe); |
3528 | temp = I915_READ(reg); | |
8db9d77b ZW |
3529 | if (HAS_PCH_CPT(dev)) { |
3530 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3531 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3532 | } else { | |
3533 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3534 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3535 | } | |
5eddb70b CW |
3536 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3537 | ||
3538 | POSTING_READ(reg); | |
8db9d77b ZW |
3539 | udelay(150); |
3540 | ||
0206e353 | 3541 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3542 | reg = FDI_TX_CTL(pipe); |
3543 | temp = I915_READ(reg); | |
8db9d77b ZW |
3544 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3545 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3546 | I915_WRITE(reg, temp); |
3547 | ||
3548 | POSTING_READ(reg); | |
8db9d77b ZW |
3549 | udelay(500); |
3550 | ||
fa37d39e SP |
3551 | for (retry = 0; retry < 5; retry++) { |
3552 | reg = FDI_RX_IIR(pipe); | |
3553 | temp = I915_READ(reg); | |
3554 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3555 | if (temp & FDI_RX_BIT_LOCK) { | |
3556 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3557 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3558 | break; | |
3559 | } | |
3560 | udelay(50); | |
8db9d77b | 3561 | } |
fa37d39e SP |
3562 | if (retry < 5) |
3563 | break; | |
8db9d77b ZW |
3564 | } |
3565 | if (i == 4) | |
5eddb70b | 3566 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3567 | |
3568 | /* Train 2 */ | |
5eddb70b CW |
3569 | reg = FDI_TX_CTL(pipe); |
3570 | temp = I915_READ(reg); | |
8db9d77b ZW |
3571 | temp &= ~FDI_LINK_TRAIN_NONE; |
3572 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3573 | if (IS_GEN6(dev)) { | |
3574 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3575 | /* SNB-B */ | |
3576 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3577 | } | |
5eddb70b | 3578 | I915_WRITE(reg, temp); |
8db9d77b | 3579 | |
5eddb70b CW |
3580 | reg = FDI_RX_CTL(pipe); |
3581 | temp = I915_READ(reg); | |
8db9d77b ZW |
3582 | if (HAS_PCH_CPT(dev)) { |
3583 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3584 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3585 | } else { | |
3586 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3587 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3588 | } | |
5eddb70b CW |
3589 | I915_WRITE(reg, temp); |
3590 | ||
3591 | POSTING_READ(reg); | |
8db9d77b ZW |
3592 | udelay(150); |
3593 | ||
0206e353 | 3594 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3595 | reg = FDI_TX_CTL(pipe); |
3596 | temp = I915_READ(reg); | |
8db9d77b ZW |
3597 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3598 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3599 | I915_WRITE(reg, temp); |
3600 | ||
3601 | POSTING_READ(reg); | |
8db9d77b ZW |
3602 | udelay(500); |
3603 | ||
fa37d39e SP |
3604 | for (retry = 0; retry < 5; retry++) { |
3605 | reg = FDI_RX_IIR(pipe); | |
3606 | temp = I915_READ(reg); | |
3607 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3608 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3609 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3610 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3611 | break; | |
3612 | } | |
3613 | udelay(50); | |
8db9d77b | 3614 | } |
fa37d39e SP |
3615 | if (retry < 5) |
3616 | break; | |
8db9d77b ZW |
3617 | } |
3618 | if (i == 4) | |
5eddb70b | 3619 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3620 | |
3621 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3622 | } | |
3623 | ||
357555c0 JB |
3624 | /* Manual link training for Ivy Bridge A0 parts */ |
3625 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3626 | { | |
3627 | struct drm_device *dev = crtc->dev; | |
3628 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3629 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3630 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3631 | i915_reg_t reg; |
3632 | u32 temp, i, j; | |
357555c0 JB |
3633 | |
3634 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3635 | for train result */ | |
3636 | reg = FDI_RX_IMR(pipe); | |
3637 | temp = I915_READ(reg); | |
3638 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3639 | temp &= ~FDI_RX_BIT_LOCK; | |
3640 | I915_WRITE(reg, temp); | |
3641 | ||
3642 | POSTING_READ(reg); | |
3643 | udelay(150); | |
3644 | ||
01a415fd DV |
3645 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3646 | I915_READ(FDI_RX_IIR(pipe))); | |
3647 | ||
139ccd3f JB |
3648 | /* Try each vswing and preemphasis setting twice before moving on */ |
3649 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3650 | /* disable first in case we need to retry */ | |
3651 | reg = FDI_TX_CTL(pipe); | |
3652 | temp = I915_READ(reg); | |
3653 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3654 | temp &= ~FDI_TX_ENABLE; | |
3655 | I915_WRITE(reg, temp); | |
357555c0 | 3656 | |
139ccd3f JB |
3657 | reg = FDI_RX_CTL(pipe); |
3658 | temp = I915_READ(reg); | |
3659 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3660 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3661 | temp &= ~FDI_RX_ENABLE; | |
3662 | I915_WRITE(reg, temp); | |
357555c0 | 3663 | |
139ccd3f | 3664 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3665 | reg = FDI_TX_CTL(pipe); |
3666 | temp = I915_READ(reg); | |
139ccd3f | 3667 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3668 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3669 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3670 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3671 | temp |= snb_b_fdi_train_param[j/2]; |
3672 | temp |= FDI_COMPOSITE_SYNC; | |
3673 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3674 | |
139ccd3f JB |
3675 | I915_WRITE(FDI_RX_MISC(pipe), |
3676 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3677 | |
139ccd3f | 3678 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3679 | temp = I915_READ(reg); |
139ccd3f JB |
3680 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3681 | temp |= FDI_COMPOSITE_SYNC; | |
3682 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3683 | |
139ccd3f JB |
3684 | POSTING_READ(reg); |
3685 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3686 | |
139ccd3f JB |
3687 | for (i = 0; i < 4; i++) { |
3688 | reg = FDI_RX_IIR(pipe); | |
3689 | temp = I915_READ(reg); | |
3690 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3691 | |
139ccd3f JB |
3692 | if (temp & FDI_RX_BIT_LOCK || |
3693 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3694 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3695 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3696 | i); | |
3697 | break; | |
3698 | } | |
3699 | udelay(1); /* should be 0.5us */ | |
3700 | } | |
3701 | if (i == 4) { | |
3702 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3703 | continue; | |
3704 | } | |
357555c0 | 3705 | |
139ccd3f | 3706 | /* Train 2 */ |
357555c0 JB |
3707 | reg = FDI_TX_CTL(pipe); |
3708 | temp = I915_READ(reg); | |
139ccd3f JB |
3709 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3710 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3711 | I915_WRITE(reg, temp); | |
3712 | ||
3713 | reg = FDI_RX_CTL(pipe); | |
3714 | temp = I915_READ(reg); | |
3715 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3716 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3717 | I915_WRITE(reg, temp); |
3718 | ||
3719 | POSTING_READ(reg); | |
139ccd3f | 3720 | udelay(2); /* should be 1.5us */ |
357555c0 | 3721 | |
139ccd3f JB |
3722 | for (i = 0; i < 4; i++) { |
3723 | reg = FDI_RX_IIR(pipe); | |
3724 | temp = I915_READ(reg); | |
3725 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3726 | |
139ccd3f JB |
3727 | if (temp & FDI_RX_SYMBOL_LOCK || |
3728 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3729 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3730 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3731 | i); | |
3732 | goto train_done; | |
3733 | } | |
3734 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3735 | } |
139ccd3f JB |
3736 | if (i == 4) |
3737 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3738 | } |
357555c0 | 3739 | |
139ccd3f | 3740 | train_done: |
357555c0 JB |
3741 | DRM_DEBUG_KMS("FDI train done.\n"); |
3742 | } | |
3743 | ||
88cefb6c | 3744 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3745 | { |
88cefb6c | 3746 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3747 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3748 | int pipe = intel_crtc->pipe; |
f0f59a00 VS |
3749 | i915_reg_t reg; |
3750 | u32 temp; | |
c64e311e | 3751 | |
c98e9dcf | 3752 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3753 | reg = FDI_RX_CTL(pipe); |
3754 | temp = I915_READ(reg); | |
627eb5a3 | 3755 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3756 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3757 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3758 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3759 | ||
3760 | POSTING_READ(reg); | |
c98e9dcf JB |
3761 | udelay(200); |
3762 | ||
3763 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3764 | temp = I915_READ(reg); |
3765 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3766 | ||
3767 | POSTING_READ(reg); | |
c98e9dcf JB |
3768 | udelay(200); |
3769 | ||
20749730 PZ |
3770 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3771 | reg = FDI_TX_CTL(pipe); | |
3772 | temp = I915_READ(reg); | |
3773 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3774 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3775 | |
20749730 PZ |
3776 | POSTING_READ(reg); |
3777 | udelay(100); | |
6be4a607 | 3778 | } |
0e23b99d JB |
3779 | } |
3780 | ||
88cefb6c DV |
3781 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3782 | { | |
3783 | struct drm_device *dev = intel_crtc->base.dev; | |
3784 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3785 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3786 | i915_reg_t reg; |
3787 | u32 temp; | |
88cefb6c DV |
3788 | |
3789 | /* Switch from PCDclk to Rawclk */ | |
3790 | reg = FDI_RX_CTL(pipe); | |
3791 | temp = I915_READ(reg); | |
3792 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3793 | ||
3794 | /* Disable CPU FDI TX PLL */ | |
3795 | reg = FDI_TX_CTL(pipe); | |
3796 | temp = I915_READ(reg); | |
3797 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3798 | ||
3799 | POSTING_READ(reg); | |
3800 | udelay(100); | |
3801 | ||
3802 | reg = FDI_RX_CTL(pipe); | |
3803 | temp = I915_READ(reg); | |
3804 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3805 | ||
3806 | /* Wait for the clocks to turn off. */ | |
3807 | POSTING_READ(reg); | |
3808 | udelay(100); | |
3809 | } | |
3810 | ||
0fc932b8 JB |
3811 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3812 | { | |
3813 | struct drm_device *dev = crtc->dev; | |
3814 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3815 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3816 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3817 | i915_reg_t reg; |
3818 | u32 temp; | |
0fc932b8 JB |
3819 | |
3820 | /* disable CPU FDI tx and PCH FDI rx */ | |
3821 | reg = FDI_TX_CTL(pipe); | |
3822 | temp = I915_READ(reg); | |
3823 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3824 | POSTING_READ(reg); | |
3825 | ||
3826 | reg = FDI_RX_CTL(pipe); | |
3827 | temp = I915_READ(reg); | |
3828 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3829 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3830 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3831 | ||
3832 | POSTING_READ(reg); | |
3833 | udelay(100); | |
3834 | ||
3835 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3836 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3837 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3838 | |
3839 | /* still set train pattern 1 */ | |
3840 | reg = FDI_TX_CTL(pipe); | |
3841 | temp = I915_READ(reg); | |
3842 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3843 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3844 | I915_WRITE(reg, temp); | |
3845 | ||
3846 | reg = FDI_RX_CTL(pipe); | |
3847 | temp = I915_READ(reg); | |
3848 | if (HAS_PCH_CPT(dev)) { | |
3849 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3850 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3851 | } else { | |
3852 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3853 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3854 | } | |
3855 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3856 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3857 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3858 | I915_WRITE(reg, temp); |
3859 | ||
3860 | POSTING_READ(reg); | |
3861 | udelay(100); | |
3862 | } | |
3863 | ||
5dce5b93 CW |
3864 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3865 | { | |
3866 | struct intel_crtc *crtc; | |
3867 | ||
3868 | /* Note that we don't need to be called with mode_config.lock here | |
3869 | * as our list of CRTC objects is static for the lifetime of the | |
3870 | * device and so cannot disappear as we iterate. Similarly, we can | |
3871 | * happily treat the predicates as racy, atomic checks as userspace | |
3872 | * cannot claim and pin a new fb without at least acquring the | |
3873 | * struct_mutex and so serialising with us. | |
3874 | */ | |
d3fcc808 | 3875 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3876 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3877 | continue; | |
3878 | ||
3879 | if (crtc->unpin_work) | |
3880 | intel_wait_for_vblank(dev, crtc->pipe); | |
3881 | ||
3882 | return true; | |
3883 | } | |
3884 | ||
3885 | return false; | |
3886 | } | |
3887 | ||
d6bbafa1 CW |
3888 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3889 | { | |
3890 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3891 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3892 | ||
3893 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3894 | smp_rmb(); | |
3895 | intel_crtc->unpin_work = NULL; | |
3896 | ||
3897 | if (work->event) | |
3898 | drm_send_vblank_event(intel_crtc->base.dev, | |
3899 | intel_crtc->pipe, | |
3900 | work->event); | |
3901 | ||
3902 | drm_crtc_vblank_put(&intel_crtc->base); | |
3903 | ||
3904 | wake_up_all(&dev_priv->pending_flip_queue); | |
3905 | queue_work(dev_priv->wq, &work->work); | |
3906 | ||
3907 | trace_i915_flip_complete(intel_crtc->plane, | |
3908 | work->pending_flip_obj); | |
3909 | } | |
3910 | ||
5008e874 | 3911 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3912 | { |
0f91128d | 3913 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3914 | struct drm_i915_private *dev_priv = dev->dev_private; |
5008e874 | 3915 | long ret; |
e6c3a2a6 | 3916 | |
2c10d571 | 3917 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
5008e874 ML |
3918 | |
3919 | ret = wait_event_interruptible_timeout( | |
3920 | dev_priv->pending_flip_queue, | |
3921 | !intel_crtc_has_pending_flip(crtc), | |
3922 | 60*HZ); | |
3923 | ||
3924 | if (ret < 0) | |
3925 | return ret; | |
3926 | ||
3927 | if (ret == 0) { | |
9c787942 | 3928 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
2c10d571 | 3929 | |
5e2d7afc | 3930 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3931 | if (intel_crtc->unpin_work) { |
3932 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3933 | page_flip_completed(intel_crtc); | |
3934 | } | |
5e2d7afc | 3935 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3936 | } |
5bb61643 | 3937 | |
5008e874 | 3938 | return 0; |
e6c3a2a6 CW |
3939 | } |
3940 | ||
e615efe4 ED |
3941 | /* Program iCLKIP clock to the desired frequency */ |
3942 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3943 | { | |
3944 | struct drm_device *dev = crtc->dev; | |
3945 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3946 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3947 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3948 | u32 temp; | |
3949 | ||
a580516d | 3950 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 3951 | |
e615efe4 ED |
3952 | /* It is necessary to ungate the pixclk gate prior to programming |
3953 | * the divisors, and gate it back when it is done. | |
3954 | */ | |
3955 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3956 | ||
3957 | /* Disable SSCCTL */ | |
3958 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3959 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3960 | SBI_SSCCTL_DISABLE, | |
3961 | SBI_ICLK); | |
e615efe4 ED |
3962 | |
3963 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3964 | if (clock == 20000) { |
e615efe4 ED |
3965 | auxdiv = 1; |
3966 | divsel = 0x41; | |
3967 | phaseinc = 0x20; | |
3968 | } else { | |
3969 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3970 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3971 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3972 | * convert the virtual clock precision to KHz here for higher |
3973 | * precision. | |
3974 | */ | |
3975 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3976 | u32 iclk_pi_range = 64; | |
3977 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3978 | ||
12d7ceed | 3979 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3980 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3981 | pi_value = desired_divisor % iclk_pi_range; | |
3982 | ||
3983 | auxdiv = 0; | |
3984 | divsel = msb_divisor_value - 2; | |
3985 | phaseinc = pi_value; | |
3986 | } | |
3987 | ||
3988 | /* This should not happen with any sane values */ | |
3989 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3990 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3991 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3992 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3993 | ||
3994 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3995 | clock, |
e615efe4 ED |
3996 | auxdiv, |
3997 | divsel, | |
3998 | phasedir, | |
3999 | phaseinc); | |
4000 | ||
4001 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 4002 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
4003 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
4004 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
4005 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
4006 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
4007 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
4008 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 4009 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
4010 | |
4011 | /* Program SSCAUXDIV */ | |
988d6ee8 | 4012 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
4013 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
4014 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 4015 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
4016 | |
4017 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4018 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4019 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4020 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
4021 | |
4022 | /* Wait for initialization time */ | |
4023 | udelay(24); | |
4024 | ||
4025 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 | 4026 | |
a580516d | 4027 | mutex_unlock(&dev_priv->sb_lock); |
e615efe4 ED |
4028 | } |
4029 | ||
275f01b2 DV |
4030 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4031 | enum pipe pch_transcoder) | |
4032 | { | |
4033 | struct drm_device *dev = crtc->base.dev; | |
4034 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4035 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4036 | |
4037 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4038 | I915_READ(HTOTAL(cpu_transcoder))); | |
4039 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4040 | I915_READ(HBLANK(cpu_transcoder))); | |
4041 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4042 | I915_READ(HSYNC(cpu_transcoder))); | |
4043 | ||
4044 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4045 | I915_READ(VTOTAL(cpu_transcoder))); | |
4046 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4047 | I915_READ(VBLANK(cpu_transcoder))); | |
4048 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4049 | I915_READ(VSYNC(cpu_transcoder))); | |
4050 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4051 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4052 | } | |
4053 | ||
003632d9 | 4054 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4055 | { |
4056 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4057 | uint32_t temp; | |
4058 | ||
4059 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4060 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4061 | return; |
4062 | ||
4063 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4064 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4065 | ||
003632d9 ACO |
4066 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4067 | if (enable) | |
4068 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4069 | ||
4070 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4071 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4072 | POSTING_READ(SOUTH_CHICKEN1); | |
4073 | } | |
4074 | ||
4075 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4076 | { | |
4077 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4078 | |
4079 | switch (intel_crtc->pipe) { | |
4080 | case PIPE_A: | |
4081 | break; | |
4082 | case PIPE_B: | |
6e3c9717 | 4083 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4084 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4085 | else |
003632d9 | 4086 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4087 | |
4088 | break; | |
4089 | case PIPE_C: | |
003632d9 | 4090 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4091 | |
4092 | break; | |
4093 | default: | |
4094 | BUG(); | |
4095 | } | |
4096 | } | |
4097 | ||
c48b5305 VS |
4098 | /* Return which DP Port should be selected for Transcoder DP control */ |
4099 | static enum port | |
4100 | intel_trans_dp_port_sel(struct drm_crtc *crtc) | |
4101 | { | |
4102 | struct drm_device *dev = crtc->dev; | |
4103 | struct intel_encoder *encoder; | |
4104 | ||
4105 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
4106 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || | |
4107 | encoder->type == INTEL_OUTPUT_EDP) | |
4108 | return enc_to_dig_port(&encoder->base)->port; | |
4109 | } | |
4110 | ||
4111 | return -1; | |
4112 | } | |
4113 | ||
f67a559d JB |
4114 | /* |
4115 | * Enable PCH resources required for PCH ports: | |
4116 | * - PCH PLLs | |
4117 | * - FDI training & RX/TX | |
4118 | * - update transcoder timings | |
4119 | * - DP transcoding bits | |
4120 | * - transcoder | |
4121 | */ | |
4122 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4123 | { |
4124 | struct drm_device *dev = crtc->dev; | |
4125 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4126 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4127 | int pipe = intel_crtc->pipe; | |
f0f59a00 | 4128 | u32 temp; |
2c07245f | 4129 | |
ab9412ba | 4130 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4131 | |
1fbc0d78 DV |
4132 | if (IS_IVYBRIDGE(dev)) |
4133 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4134 | ||
cd986abb DV |
4135 | /* Write the TU size bits before fdi link training, so that error |
4136 | * detection works. */ | |
4137 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4138 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4139 | ||
3860b2ec VS |
4140 | /* |
4141 | * Sometimes spurious CPU pipe underruns happen during FDI | |
4142 | * training, at least with VGA+HDMI cloning. Suppress them. | |
4143 | */ | |
4144 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
4145 | ||
c98e9dcf | 4146 | /* For PCH output, training FDI link */ |
674cf967 | 4147 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4148 | |
3ad8a208 DV |
4149 | /* We need to program the right clock selection before writing the pixel |
4150 | * mutliplier into the DPLL. */ | |
303b81e0 | 4151 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4152 | u32 sel; |
4b645f14 | 4153 | |
c98e9dcf | 4154 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4155 | temp |= TRANS_DPLL_ENABLE(pipe); |
4156 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4157 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4158 | temp |= sel; |
4159 | else | |
4160 | temp &= ~sel; | |
c98e9dcf | 4161 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4162 | } |
5eddb70b | 4163 | |
3ad8a208 DV |
4164 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4165 | * transcoder, and we actually should do this to not upset any PCH | |
4166 | * transcoder that already use the clock when we share it. | |
4167 | * | |
4168 | * Note that enable_shared_dpll tries to do the right thing, but | |
4169 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4170 | * the right LVDS enable sequence. */ | |
85b3894f | 4171 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4172 | |
d9b6cb56 JB |
4173 | /* set transcoder timing, panel must allow it */ |
4174 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4175 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4176 | |
303b81e0 | 4177 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4178 | |
3860b2ec VS |
4179 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4180 | ||
c98e9dcf | 4181 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4182 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
9c4edaee VS |
4183 | const struct drm_display_mode *adjusted_mode = |
4184 | &intel_crtc->config->base.adjusted_mode; | |
dfd07d72 | 4185 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
f0f59a00 | 4186 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
5eddb70b CW |
4187 | temp = I915_READ(reg); |
4188 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4189 | TRANS_DP_SYNC_MASK | |
4190 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4191 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4192 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf | 4193 | |
9c4edaee | 4194 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
5eddb70b | 4195 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
9c4edaee | 4196 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4197 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4198 | |
4199 | switch (intel_trans_dp_port_sel(crtc)) { | |
c48b5305 | 4200 | case PORT_B: |
5eddb70b | 4201 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf | 4202 | break; |
c48b5305 | 4203 | case PORT_C: |
5eddb70b | 4204 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf | 4205 | break; |
c48b5305 | 4206 | case PORT_D: |
5eddb70b | 4207 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4208 | break; |
4209 | default: | |
e95d41e1 | 4210 | BUG(); |
32f9d658 | 4211 | } |
2c07245f | 4212 | |
5eddb70b | 4213 | I915_WRITE(reg, temp); |
6be4a607 | 4214 | } |
b52eb4dc | 4215 | |
b8a4f404 | 4216 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4217 | } |
4218 | ||
1507e5bd PZ |
4219 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4220 | { | |
4221 | struct drm_device *dev = crtc->dev; | |
4222 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4223 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4224 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4225 | |
ab9412ba | 4226 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4227 | |
8c52b5e8 | 4228 | lpt_program_iclkip(crtc); |
1507e5bd | 4229 | |
0540e488 | 4230 | /* Set transcoder timing. */ |
275f01b2 | 4231 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4232 | |
937bb610 | 4233 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4234 | } |
4235 | ||
190f68c5 ACO |
4236 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4237 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4238 | { |
e2b78267 | 4239 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4240 | struct intel_shared_dpll *pll; |
de419ab6 | 4241 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4242 | enum intel_dpll_id i; |
00490c22 | 4243 | int max = dev_priv->num_shared_dpll; |
ee7b9f93 | 4244 | |
de419ab6 ML |
4245 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4246 | ||
98b6bd99 DV |
4247 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4248 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4249 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4250 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4251 | |
46edb027 DV |
4252 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4253 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4254 | |
de419ab6 | 4255 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4256 | |
98b6bd99 DV |
4257 | goto found; |
4258 | } | |
4259 | ||
bcddf610 S |
4260 | if (IS_BROXTON(dev_priv->dev)) { |
4261 | /* PLL is attached to port in bxt */ | |
4262 | struct intel_encoder *encoder; | |
4263 | struct intel_digital_port *intel_dig_port; | |
4264 | ||
4265 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4266 | if (WARN_ON(!encoder)) | |
4267 | return NULL; | |
4268 | ||
4269 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4270 | /* 1:1 mapping between ports and PLLs */ | |
4271 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4272 | pll = &dev_priv->shared_dplls[i]; | |
4273 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4274 | crtc->base.base.id, pll->name); | |
de419ab6 | 4275 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4276 | |
4277 | goto found; | |
00490c22 ML |
4278 | } else if (INTEL_INFO(dev_priv)->gen < 9 && HAS_DDI(dev_priv)) |
4279 | /* Do not consider SPLL */ | |
4280 | max = 2; | |
bcddf610 | 4281 | |
00490c22 | 4282 | for (i = 0; i < max; i++) { |
e72f9fbf | 4283 | pll = &dev_priv->shared_dplls[i]; |
ee7b9f93 JB |
4284 | |
4285 | /* Only want to check enabled timings first */ | |
de419ab6 | 4286 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4287 | continue; |
4288 | ||
190f68c5 | 4289 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4290 | &shared_dpll[i].hw_state, |
4291 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4292 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4293 | crtc->base.base.id, pll->name, |
de419ab6 | 4294 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4295 | pll->active); |
ee7b9f93 JB |
4296 | goto found; |
4297 | } | |
4298 | } | |
4299 | ||
4300 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4301 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4302 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4303 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4304 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4305 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4306 | goto found; |
4307 | } | |
4308 | } | |
4309 | ||
4310 | return NULL; | |
4311 | ||
4312 | found: | |
de419ab6 ML |
4313 | if (shared_dpll[i].crtc_mask == 0) |
4314 | shared_dpll[i].hw_state = | |
4315 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4316 | |
190f68c5 | 4317 | crtc_state->shared_dpll = i; |
46edb027 DV |
4318 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4319 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4320 | |
de419ab6 | 4321 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4322 | |
ee7b9f93 JB |
4323 | return pll; |
4324 | } | |
4325 | ||
de419ab6 | 4326 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4327 | { |
de419ab6 ML |
4328 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4329 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4330 | struct intel_shared_dpll *pll; |
4331 | enum intel_dpll_id i; | |
4332 | ||
de419ab6 ML |
4333 | if (!to_intel_atomic_state(state)->dpll_set) |
4334 | return; | |
8bd31e67 | 4335 | |
de419ab6 | 4336 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4337 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4338 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4339 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4340 | } |
4341 | } | |
4342 | ||
a1520318 | 4343 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4344 | { |
4345 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 4346 | i915_reg_t dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4347 | u32 temp; |
4348 | ||
4349 | temp = I915_READ(dslreg); | |
4350 | udelay(500); | |
4351 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4352 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4353 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4354 | } |
4355 | } | |
4356 | ||
86adf9d7 ML |
4357 | static int |
4358 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4359 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4360 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4361 | { |
86adf9d7 ML |
4362 | struct intel_crtc_scaler_state *scaler_state = |
4363 | &crtc_state->scaler_state; | |
4364 | struct intel_crtc *intel_crtc = | |
4365 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4366 | int need_scaling; |
6156a456 CK |
4367 | |
4368 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4369 | (src_h != dst_w || src_w != dst_h): | |
4370 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4371 | |
4372 | /* | |
4373 | * if plane is being disabled or scaler is no more required or force detach | |
4374 | * - free scaler binded to this plane/crtc | |
4375 | * - in order to do this, update crtc->scaler_usage | |
4376 | * | |
4377 | * Here scaler state in crtc_state is set free so that | |
4378 | * scaler can be assigned to other user. Actual register | |
4379 | * update to free the scaler is done in plane/panel-fit programming. | |
4380 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4381 | */ | |
86adf9d7 | 4382 | if (force_detach || !need_scaling) { |
a1b2278e | 4383 | if (*scaler_id >= 0) { |
86adf9d7 | 4384 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4385 | scaler_state->scalers[*scaler_id].in_use = 0; |
4386 | ||
86adf9d7 ML |
4387 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4388 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4389 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4390 | scaler_state->scaler_users); |
4391 | *scaler_id = -1; | |
4392 | } | |
4393 | return 0; | |
4394 | } | |
4395 | ||
4396 | /* range checks */ | |
4397 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4398 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4399 | ||
4400 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4401 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4402 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4403 | "size is out of scaler range\n", |
86adf9d7 | 4404 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4405 | return -EINVAL; |
4406 | } | |
4407 | ||
86adf9d7 ML |
4408 | /* mark this plane as a scaler user in crtc_state */ |
4409 | scaler_state->scaler_users |= (1 << scaler_user); | |
4410 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4411 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4412 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4413 | scaler_state->scaler_users); | |
4414 | ||
4415 | return 0; | |
4416 | } | |
4417 | ||
4418 | /** | |
4419 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4420 | * | |
4421 | * @state: crtc's scaler state | |
86adf9d7 ML |
4422 | * |
4423 | * Return | |
4424 | * 0 - scaler_usage updated successfully | |
4425 | * error - requested scaling cannot be supported or other error condition | |
4426 | */ | |
e435d6e5 | 4427 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 ML |
4428 | { |
4429 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
7c5f93b0 | 4430 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
86adf9d7 ML |
4431 | |
4432 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4433 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4434 | ||
e435d6e5 | 4435 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
86adf9d7 ML |
4436 | &state->scaler_state.scaler_id, DRM_ROTATE_0, |
4437 | state->pipe_src_w, state->pipe_src_h, | |
aad941d5 | 4438 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
86adf9d7 ML |
4439 | } |
4440 | ||
4441 | /** | |
4442 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4443 | * | |
4444 | * @state: crtc's scaler state | |
86adf9d7 ML |
4445 | * @plane_state: atomic plane state to update |
4446 | * | |
4447 | * Return | |
4448 | * 0 - scaler_usage updated successfully | |
4449 | * error - requested scaling cannot be supported or other error condition | |
4450 | */ | |
da20eabd ML |
4451 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4452 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4453 | { |
4454 | ||
4455 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4456 | struct intel_plane *intel_plane = |
4457 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4458 | struct drm_framebuffer *fb = plane_state->base.fb; |
4459 | int ret; | |
4460 | ||
4461 | bool force_detach = !fb || !plane_state->visible; | |
4462 | ||
4463 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4464 | intel_plane->base.base.id, intel_crtc->pipe, | |
4465 | drm_plane_index(&intel_plane->base)); | |
4466 | ||
4467 | ret = skl_update_scaler(crtc_state, force_detach, | |
4468 | drm_plane_index(&intel_plane->base), | |
4469 | &plane_state->scaler_id, | |
4470 | plane_state->base.rotation, | |
4471 | drm_rect_width(&plane_state->src) >> 16, | |
4472 | drm_rect_height(&plane_state->src) >> 16, | |
4473 | drm_rect_width(&plane_state->dst), | |
4474 | drm_rect_height(&plane_state->dst)); | |
4475 | ||
4476 | if (ret || plane_state->scaler_id < 0) | |
4477 | return ret; | |
4478 | ||
a1b2278e | 4479 | /* check colorkey */ |
818ed961 | 4480 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
86adf9d7 | 4481 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
818ed961 | 4482 | intel_plane->base.base.id); |
a1b2278e CK |
4483 | return -EINVAL; |
4484 | } | |
4485 | ||
4486 | /* Check src format */ | |
86adf9d7 ML |
4487 | switch (fb->pixel_format) { |
4488 | case DRM_FORMAT_RGB565: | |
4489 | case DRM_FORMAT_XBGR8888: | |
4490 | case DRM_FORMAT_XRGB8888: | |
4491 | case DRM_FORMAT_ABGR8888: | |
4492 | case DRM_FORMAT_ARGB8888: | |
4493 | case DRM_FORMAT_XRGB2101010: | |
4494 | case DRM_FORMAT_XBGR2101010: | |
4495 | case DRM_FORMAT_YUYV: | |
4496 | case DRM_FORMAT_YVYU: | |
4497 | case DRM_FORMAT_UYVY: | |
4498 | case DRM_FORMAT_VYUY: | |
4499 | break; | |
4500 | default: | |
4501 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4502 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4503 | return -EINVAL; | |
a1b2278e CK |
4504 | } |
4505 | ||
a1b2278e CK |
4506 | return 0; |
4507 | } | |
4508 | ||
e435d6e5 ML |
4509 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4510 | { | |
4511 | int i; | |
4512 | ||
4513 | for (i = 0; i < crtc->num_scalers; i++) | |
4514 | skl_detach_scaler(crtc, i); | |
4515 | } | |
4516 | ||
4517 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4518 | { |
4519 | struct drm_device *dev = crtc->base.dev; | |
4520 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4521 | int pipe = crtc->pipe; | |
a1b2278e CK |
4522 | struct intel_crtc_scaler_state *scaler_state = |
4523 | &crtc->config->scaler_state; | |
4524 | ||
4525 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4526 | ||
6e3c9717 | 4527 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4528 | int id; |
4529 | ||
4530 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4531 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4532 | return; | |
4533 | } | |
4534 | ||
4535 | id = scaler_state->scaler_id; | |
4536 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4537 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4538 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4539 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4540 | ||
4541 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4542 | } |
4543 | } | |
4544 | ||
b074cec8 JB |
4545 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4546 | { | |
4547 | struct drm_device *dev = crtc->base.dev; | |
4548 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4549 | int pipe = crtc->pipe; | |
4550 | ||
6e3c9717 | 4551 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4552 | /* Force use of hard-coded filter coefficients |
4553 | * as some pre-programmed values are broken, | |
4554 | * e.g. x201. | |
4555 | */ | |
4556 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4557 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4558 | PF_PIPE_SEL_IVB(pipe)); | |
4559 | else | |
4560 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4561 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4562 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4563 | } |
4564 | } | |
4565 | ||
20bc8673 | 4566 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4567 | { |
cea165c3 VS |
4568 | struct drm_device *dev = crtc->base.dev; |
4569 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4570 | |
6e3c9717 | 4571 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4572 | return; |
4573 | ||
cea165c3 VS |
4574 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4575 | intel_wait_for_vblank(dev, crtc->pipe); | |
4576 | ||
d77e4531 | 4577 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4578 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4579 | mutex_lock(&dev_priv->rps.hw_lock); |
4580 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4581 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4582 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4583 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4584 | * mailbox." Moreover, the mailbox may return a bogus state, |
4585 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4586 | */ |
4587 | } else { | |
4588 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4589 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4590 | * is essentially intel_wait_for_vblank. If we don't have this | |
4591 | * and don't wait for vblanks until the end of crtc_enable, then | |
4592 | * the HW state readout code will complain that the expected | |
4593 | * IPS_CTL value is not the one we read. */ | |
4594 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4595 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4596 | } | |
d77e4531 PZ |
4597 | } |
4598 | ||
20bc8673 | 4599 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4600 | { |
4601 | struct drm_device *dev = crtc->base.dev; | |
4602 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4603 | ||
6e3c9717 | 4604 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4605 | return; |
4606 | ||
4607 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4608 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4609 | mutex_lock(&dev_priv->rps.hw_lock); |
4610 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4611 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4612 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4613 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4614 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4615 | } else { |
2a114cc1 | 4616 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4617 | POSTING_READ(IPS_CTL); |
4618 | } | |
d77e4531 PZ |
4619 | |
4620 | /* We need to wait for a vblank before we can disable the plane. */ | |
4621 | intel_wait_for_vblank(dev, crtc->pipe); | |
4622 | } | |
4623 | ||
4624 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4625 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4626 | { | |
4627 | struct drm_device *dev = crtc->dev; | |
4628 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4629 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4630 | enum pipe pipe = intel_crtc->pipe; | |
d77e4531 PZ |
4631 | int i; |
4632 | bool reenable_ips = false; | |
4633 | ||
4634 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4635 | if (!crtc->state->active) |
d77e4531 PZ |
4636 | return; |
4637 | ||
50360403 | 4638 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
a65347ba | 4639 | if (intel_crtc->config->has_dsi_encoder) |
d77e4531 PZ |
4640 | assert_dsi_pll_enabled(dev_priv); |
4641 | else | |
4642 | assert_pll_enabled(dev_priv, pipe); | |
4643 | } | |
4644 | ||
d77e4531 PZ |
4645 | /* Workaround : Do not read or write the pipe palette/gamma data while |
4646 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4647 | */ | |
6e3c9717 | 4648 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4649 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4650 | GAMMA_MODE_MODE_SPLIT)) { | |
4651 | hsw_disable_ips(intel_crtc); | |
4652 | reenable_ips = true; | |
4653 | } | |
4654 | ||
4655 | for (i = 0; i < 256; i++) { | |
f0f59a00 | 4656 | i915_reg_t palreg; |
f65a9c5b VS |
4657 | |
4658 | if (HAS_GMCH_DISPLAY(dev)) | |
4659 | palreg = PALETTE(pipe, i); | |
4660 | else | |
4661 | palreg = LGC_PALETTE(pipe, i); | |
4662 | ||
4663 | I915_WRITE(palreg, | |
d77e4531 PZ |
4664 | (intel_crtc->lut_r[i] << 16) | |
4665 | (intel_crtc->lut_g[i] << 8) | | |
4666 | intel_crtc->lut_b[i]); | |
4667 | } | |
4668 | ||
4669 | if (reenable_ips) | |
4670 | hsw_enable_ips(intel_crtc); | |
4671 | } | |
4672 | ||
7cac945f | 4673 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4674 | { |
7cac945f | 4675 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4676 | struct drm_device *dev = intel_crtc->base.dev; |
4677 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4678 | ||
4679 | mutex_lock(&dev->struct_mutex); | |
4680 | dev_priv->mm.interruptible = false; | |
4681 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4682 | dev_priv->mm.interruptible = true; | |
4683 | mutex_unlock(&dev->struct_mutex); | |
4684 | } | |
4685 | ||
4686 | /* Let userspace switch the overlay on again. In most cases userspace | |
4687 | * has to recompute where to put it anyway. | |
4688 | */ | |
4689 | } | |
4690 | ||
87d4300a ML |
4691 | /** |
4692 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4693 | * @crtc: the CRTC whose primary plane was just enabled | |
4694 | * | |
4695 | * Performs potentially sleeping operations that must be done after the primary | |
4696 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4697 | * called due to an explicit primary plane update, or due to an implicit | |
4698 | * re-enable that is caused when a sprite plane is updated to no longer | |
4699 | * completely hide the primary plane. | |
4700 | */ | |
4701 | static void | |
4702 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4703 | { |
4704 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4705 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4706 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4707 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4708 | |
87d4300a ML |
4709 | /* |
4710 | * BDW signals flip done immediately if the plane | |
4711 | * is disabled, even if the plane enable is already | |
4712 | * armed to occur at the next vblank :( | |
4713 | */ | |
4714 | if (IS_BROADWELL(dev)) | |
4715 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4716 | |
87d4300a ML |
4717 | /* |
4718 | * FIXME IPS should be fine as long as one plane is | |
4719 | * enabled, but in practice it seems to have problems | |
4720 | * when going from primary only to sprite only and vice | |
4721 | * versa. | |
4722 | */ | |
a5c4d7bc VS |
4723 | hsw_enable_ips(intel_crtc); |
4724 | ||
f99d7069 | 4725 | /* |
87d4300a ML |
4726 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4727 | * So don't enable underrun reporting before at least some planes | |
4728 | * are enabled. | |
4729 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4730 | * but leave the pipe running. | |
f99d7069 | 4731 | */ |
87d4300a ML |
4732 | if (IS_GEN2(dev)) |
4733 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4734 | ||
aca7b684 VS |
4735 | /* Underruns don't always raise interrupts, so check manually. */ |
4736 | intel_check_cpu_fifo_underruns(dev_priv); | |
4737 | intel_check_pch_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4738 | } |
4739 | ||
87d4300a ML |
4740 | /** |
4741 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4742 | * @crtc: the CRTC whose primary plane is to be disabled | |
4743 | * | |
4744 | * Performs potentially sleeping operations that must be done before the | |
4745 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4746 | * be called due to an explicit primary plane update, or due to an implicit | |
4747 | * disable that is caused when a sprite plane completely hides the primary | |
4748 | * plane. | |
4749 | */ | |
4750 | static void | |
4751 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4752 | { |
4753 | struct drm_device *dev = crtc->dev; | |
4754 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4755 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4756 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4757 | |
87d4300a ML |
4758 | /* |
4759 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4760 | * So diasble underrun reporting before all the planes get disabled. | |
4761 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4762 | * but leave the pipe running. | |
4763 | */ | |
4764 | if (IS_GEN2(dev)) | |
4765 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4766 | |
87d4300a ML |
4767 | /* |
4768 | * Vblank time updates from the shadow to live plane control register | |
4769 | * are blocked if the memory self-refresh mode is active at that | |
4770 | * moment. So to make sure the plane gets truly disabled, disable | |
4771 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4772 | * will be checked/applied by the HW only at the next frame start | |
4773 | * event which is after the vblank start event, so we need to have a | |
4774 | * wait-for-vblank between disabling the plane and the pipe. | |
4775 | */ | |
262cd2e1 | 4776 | if (HAS_GMCH_DISPLAY(dev)) { |
87d4300a | 4777 | intel_set_memory_cxsr(dev_priv, false); |
262cd2e1 VS |
4778 | dev_priv->wm.vlv.cxsr = false; |
4779 | intel_wait_for_vblank(dev, pipe); | |
4780 | } | |
87d4300a | 4781 | |
87d4300a ML |
4782 | /* |
4783 | * FIXME IPS should be fine as long as one plane is | |
4784 | * enabled, but in practice it seems to have problems | |
4785 | * when going from primary only to sprite only and vice | |
4786 | * versa. | |
4787 | */ | |
a5c4d7bc | 4788 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4789 | } |
4790 | ||
ac21b225 ML |
4791 | static void intel_post_plane_update(struct intel_crtc *crtc) |
4792 | { | |
4793 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4794 | struct drm_device *dev = crtc->base.dev; | |
ac21b225 ML |
4795 | |
4796 | if (atomic->wait_vblank) | |
4797 | intel_wait_for_vblank(dev, crtc->pipe); | |
4798 | ||
4799 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4800 | ||
852eb00d VS |
4801 | if (atomic->disable_cxsr) |
4802 | crtc->wm.cxsr_allowed = true; | |
4803 | ||
f015c551 VS |
4804 | if (crtc->atomic.update_wm_post) |
4805 | intel_update_watermarks(&crtc->base); | |
4806 | ||
c80ac854 | 4807 | if (atomic->update_fbc) |
754d1133 | 4808 | intel_fbc_update(crtc); |
ac21b225 ML |
4809 | |
4810 | if (atomic->post_enable_primary) | |
4811 | intel_post_enable_primary(&crtc->base); | |
4812 | ||
ac21b225 ML |
4813 | memset(atomic, 0, sizeof(*atomic)); |
4814 | } | |
4815 | ||
4816 | static void intel_pre_plane_update(struct intel_crtc *crtc) | |
4817 | { | |
4818 | struct drm_device *dev = crtc->base.dev; | |
eddfcbcd | 4819 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 | 4820 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
ac21b225 | 4821 | |
c80ac854 | 4822 | if (atomic->disable_fbc) |
d029bcad | 4823 | intel_fbc_deactivate(crtc); |
ac21b225 | 4824 | |
066cf55b RV |
4825 | if (crtc->atomic.disable_ips) |
4826 | hsw_disable_ips(crtc); | |
4827 | ||
ac21b225 ML |
4828 | if (atomic->pre_disable_primary) |
4829 | intel_pre_disable_primary(&crtc->base); | |
852eb00d VS |
4830 | |
4831 | if (atomic->disable_cxsr) { | |
4832 | crtc->wm.cxsr_allowed = false; | |
4833 | intel_set_memory_cxsr(dev_priv, false); | |
4834 | } | |
ac21b225 ML |
4835 | } |
4836 | ||
d032ffa0 | 4837 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4838 | { |
4839 | struct drm_device *dev = crtc->dev; | |
4840 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4841 | struct drm_plane *p; |
87d4300a ML |
4842 | int pipe = intel_crtc->pipe; |
4843 | ||
7cac945f | 4844 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4845 | |
d032ffa0 ML |
4846 | drm_for_each_plane_mask(p, dev, plane_mask) |
4847 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4848 | |
f99d7069 DV |
4849 | /* |
4850 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4851 | * to compute the mask of flip planes precisely. For the time being | |
4852 | * consider this a flip to a NULL plane. | |
4853 | */ | |
4854 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4855 | } |
4856 | ||
f67a559d JB |
4857 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4858 | { | |
4859 | struct drm_device *dev = crtc->dev; | |
4860 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4861 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4862 | struct intel_encoder *encoder; |
f67a559d | 4863 | int pipe = intel_crtc->pipe; |
f67a559d | 4864 | |
53d9f4e9 | 4865 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4866 | return; |
4867 | ||
81b088ca VS |
4868 | if (intel_crtc->config->has_pch_encoder) |
4869 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
4870 | ||
6e3c9717 | 4871 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4872 | intel_prepare_shared_dpll(intel_crtc); |
4873 | ||
6e3c9717 | 4874 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4875 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4876 | |
4877 | intel_set_pipe_timings(intel_crtc); | |
4878 | ||
6e3c9717 | 4879 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4880 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4881 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4882 | } |
4883 | ||
4884 | ironlake_set_pipeconf(crtc); | |
4885 | ||
f67a559d | 4886 | intel_crtc->active = true; |
8664281b | 4887 | |
a72e4c9f | 4888 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
8664281b | 4889 | |
f6736a1a | 4890 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4891 | if (encoder->pre_enable) |
4892 | encoder->pre_enable(encoder); | |
f67a559d | 4893 | |
6e3c9717 | 4894 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4895 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4896 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4897 | * enabling. */ | |
88cefb6c | 4898 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4899 | } else { |
4900 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4901 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4902 | } | |
f67a559d | 4903 | |
b074cec8 | 4904 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4905 | |
9c54c0dd JB |
4906 | /* |
4907 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4908 | * clocks enabled | |
4909 | */ | |
4910 | intel_crtc_load_lut(crtc); | |
4911 | ||
f37fcc2a | 4912 | intel_update_watermarks(crtc); |
e1fdc473 | 4913 | intel_enable_pipe(intel_crtc); |
f67a559d | 4914 | |
6e3c9717 | 4915 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4916 | ironlake_pch_enable(crtc); |
c98e9dcf | 4917 | |
f9b61ff6 DV |
4918 | assert_vblank_disabled(crtc); |
4919 | drm_crtc_vblank_on(crtc); | |
4920 | ||
fa5c73b1 DV |
4921 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4922 | encoder->enable(encoder); | |
61b77ddd DV |
4923 | |
4924 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4925 | cpt_verify_modeset(dev, intel_crtc->pipe); |
37ca8d4c VS |
4926 | |
4927 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
4928 | if (intel_crtc->config->has_pch_encoder) | |
4929 | intel_wait_for_vblank(dev, pipe); | |
4930 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
d029bcad PZ |
4931 | |
4932 | intel_fbc_enable(intel_crtc); | |
6be4a607 JB |
4933 | } |
4934 | ||
42db64ef PZ |
4935 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4936 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4937 | { | |
f5adf94e | 4938 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4939 | } |
4940 | ||
4f771f10 PZ |
4941 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4942 | { | |
4943 | struct drm_device *dev = crtc->dev; | |
4944 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4945 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4946 | struct intel_encoder *encoder; | |
99d736a2 ML |
4947 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4948 | struct intel_crtc_state *pipe_config = | |
4949 | to_intel_crtc_state(crtc->state); | |
4f771f10 | 4950 | |
53d9f4e9 | 4951 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4952 | return; |
4953 | ||
81b088ca VS |
4954 | if (intel_crtc->config->has_pch_encoder) |
4955 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
4956 | false); | |
4957 | ||
df8ad70c DV |
4958 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4959 | intel_enable_shared_dpll(intel_crtc); | |
4960 | ||
6e3c9717 | 4961 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4962 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
4963 | |
4964 | intel_set_pipe_timings(intel_crtc); | |
4965 | ||
6e3c9717 ACO |
4966 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
4967 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
4968 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
4969 | } |
4970 | ||
6e3c9717 | 4971 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4972 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4973 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4974 | } |
4975 | ||
4976 | haswell_set_pipeconf(crtc); | |
4977 | ||
4978 | intel_set_pipe_csc(crtc); | |
4979 | ||
4f771f10 | 4980 | intel_crtc->active = true; |
8664281b | 4981 | |
6b698516 DV |
4982 | if (intel_crtc->config->has_pch_encoder) |
4983 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
4984 | else | |
4985 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4986 | ||
7d4aefd0 | 4987 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 PZ |
4988 | if (encoder->pre_enable) |
4989 | encoder->pre_enable(encoder); | |
7d4aefd0 | 4990 | } |
4f771f10 | 4991 | |
d2d65408 | 4992 | if (intel_crtc->config->has_pch_encoder) |
4fe9467d | 4993 | dev_priv->display.fdi_link_train(crtc); |
4fe9467d | 4994 | |
a65347ba | 4995 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 4996 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 4997 | |
1c132b44 | 4998 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 4999 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 5000 | else |
1c132b44 | 5001 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
5002 | |
5003 | /* | |
5004 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5005 | * clocks enabled | |
5006 | */ | |
5007 | intel_crtc_load_lut(crtc); | |
5008 | ||
1f544388 | 5009 | intel_ddi_set_pipe_settings(crtc); |
a65347ba | 5010 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5011 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 5012 | |
f37fcc2a | 5013 | intel_update_watermarks(crtc); |
e1fdc473 | 5014 | intel_enable_pipe(intel_crtc); |
42db64ef | 5015 | |
6e3c9717 | 5016 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 5017 | lpt_pch_enable(crtc); |
4f771f10 | 5018 | |
a65347ba | 5019 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
5020 | intel_ddi_set_vc_payload_alloc(crtc, true); |
5021 | ||
f9b61ff6 DV |
5022 | assert_vblank_disabled(crtc); |
5023 | drm_crtc_vblank_on(crtc); | |
5024 | ||
8807e55b | 5025 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 5026 | encoder->enable(encoder); |
8807e55b JN |
5027 | intel_opregion_notify_encoder(encoder, true); |
5028 | } | |
4f771f10 | 5029 | |
6b698516 DV |
5030 | if (intel_crtc->config->has_pch_encoder) { |
5031 | intel_wait_for_vblank(dev, pipe); | |
5032 | intel_wait_for_vblank(dev, pipe); | |
5033 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
d2d65408 VS |
5034 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5035 | true); | |
6b698516 | 5036 | } |
d2d65408 | 5037 | |
e4916946 PZ |
5038 | /* If we change the relative order between pipe/planes enabling, we need |
5039 | * to change the workaround. */ | |
99d736a2 ML |
5040 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
5041 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
5042 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5043 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5044 | } | |
d029bcad PZ |
5045 | |
5046 | intel_fbc_enable(intel_crtc); | |
4f771f10 PZ |
5047 | } |
5048 | ||
bfd16b2a | 5049 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
5050 | { |
5051 | struct drm_device *dev = crtc->base.dev; | |
5052 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5053 | int pipe = crtc->pipe; | |
5054 | ||
5055 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5056 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 5057 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5058 | I915_WRITE(PF_CTL(pipe), 0); |
5059 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5060 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5061 | } | |
5062 | } | |
5063 | ||
6be4a607 JB |
5064 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
5065 | { | |
5066 | struct drm_device *dev = crtc->dev; | |
5067 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5068 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5069 | struct intel_encoder *encoder; |
6be4a607 | 5070 | int pipe = intel_crtc->pipe; |
b52eb4dc | 5071 | |
37ca8d4c VS |
5072 | if (intel_crtc->config->has_pch_encoder) |
5073 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
5074 | ||
ea9d758d DV |
5075 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5076 | encoder->disable(encoder); | |
5077 | ||
f9b61ff6 DV |
5078 | drm_crtc_vblank_off(crtc); |
5079 | assert_vblank_disabled(crtc); | |
5080 | ||
3860b2ec VS |
5081 | /* |
5082 | * Sometimes spurious CPU pipe underruns happen when the | |
5083 | * pipe is already disabled, but FDI RX/TX is still enabled. | |
5084 | * Happens at least with VGA+HDMI cloning. Suppress them. | |
5085 | */ | |
5086 | if (intel_crtc->config->has_pch_encoder) | |
5087 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
5088 | ||
575f7ab7 | 5089 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5090 | |
bfd16b2a | 5091 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 5092 | |
3860b2ec | 5093 | if (intel_crtc->config->has_pch_encoder) { |
5a74f70a | 5094 | ironlake_fdi_disable(crtc); |
3860b2ec VS |
5095 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
5096 | } | |
5a74f70a | 5097 | |
bf49ec8c DV |
5098 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5099 | if (encoder->post_disable) | |
5100 | encoder->post_disable(encoder); | |
2c07245f | 5101 | |
6e3c9717 | 5102 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5103 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5104 | |
d925c59a | 5105 | if (HAS_PCH_CPT(dev)) { |
f0f59a00 VS |
5106 | i915_reg_t reg; |
5107 | u32 temp; | |
5108 | ||
d925c59a DV |
5109 | /* disable TRANS_DP_CTL */ |
5110 | reg = TRANS_DP_CTL(pipe); | |
5111 | temp = I915_READ(reg); | |
5112 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5113 | TRANS_DP_PORT_SEL_MASK); | |
5114 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5115 | I915_WRITE(reg, temp); | |
5116 | ||
5117 | /* disable DPLL_SEL */ | |
5118 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5119 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5120 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5121 | } |
e3421a18 | 5122 | |
d925c59a DV |
5123 | ironlake_fdi_pll_disable(intel_crtc); |
5124 | } | |
81b088ca VS |
5125 | |
5126 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
d029bcad PZ |
5127 | |
5128 | intel_fbc_disable_crtc(intel_crtc); | |
6be4a607 | 5129 | } |
1b3c7a47 | 5130 | |
4f771f10 | 5131 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5132 | { |
4f771f10 PZ |
5133 | struct drm_device *dev = crtc->dev; |
5134 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5135 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5136 | struct intel_encoder *encoder; |
6e3c9717 | 5137 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5138 | |
d2d65408 VS |
5139 | if (intel_crtc->config->has_pch_encoder) |
5140 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5141 | false); | |
5142 | ||
8807e55b JN |
5143 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5144 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5145 | encoder->disable(encoder); |
8807e55b | 5146 | } |
4f771f10 | 5147 | |
f9b61ff6 DV |
5148 | drm_crtc_vblank_off(crtc); |
5149 | assert_vblank_disabled(crtc); | |
5150 | ||
575f7ab7 | 5151 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5152 | |
6e3c9717 | 5153 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5154 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5155 | ||
a65347ba | 5156 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5157 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5158 | |
1c132b44 | 5159 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5160 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5161 | else |
bfd16b2a | 5162 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5163 | |
a65347ba | 5164 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5165 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5166 | |
6e3c9717 | 5167 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5168 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5169 | intel_ddi_fdi_disable(crtc); |
83616634 | 5170 | } |
4f771f10 | 5171 | |
97b040aa ID |
5172 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5173 | if (encoder->post_disable) | |
5174 | encoder->post_disable(encoder); | |
81b088ca VS |
5175 | |
5176 | if (intel_crtc->config->has_pch_encoder) | |
5177 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5178 | true); | |
d029bcad PZ |
5179 | |
5180 | intel_fbc_disable_crtc(intel_crtc); | |
4f771f10 PZ |
5181 | } |
5182 | ||
2dd24552 JB |
5183 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5184 | { | |
5185 | struct drm_device *dev = crtc->base.dev; | |
5186 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5187 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5188 | |
681a8504 | 5189 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5190 | return; |
5191 | ||
2dd24552 | 5192 | /* |
c0b03411 DV |
5193 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5194 | * according to register description and PRM. | |
2dd24552 | 5195 | */ |
c0b03411 DV |
5196 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5197 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5198 | |
b074cec8 JB |
5199 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5200 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5201 | |
5202 | /* Border color in case we don't scale up to the full screen. Black by | |
5203 | * default, change to something else for debugging. */ | |
5204 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5205 | } |
5206 | ||
d05410f9 DA |
5207 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5208 | { | |
5209 | switch (port) { | |
5210 | case PORT_A: | |
6331a704 | 5211 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
d05410f9 | 5212 | case PORT_B: |
6331a704 | 5213 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
d05410f9 | 5214 | case PORT_C: |
6331a704 | 5215 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
d05410f9 | 5216 | case PORT_D: |
6331a704 | 5217 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
d8e19f99 | 5218 | case PORT_E: |
6331a704 | 5219 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
d05410f9 | 5220 | default: |
b9fec167 | 5221 | MISSING_CASE(port); |
d05410f9 DA |
5222 | return POWER_DOMAIN_PORT_OTHER; |
5223 | } | |
5224 | } | |
5225 | ||
25f78f58 VS |
5226 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
5227 | { | |
5228 | switch (port) { | |
5229 | case PORT_A: | |
5230 | return POWER_DOMAIN_AUX_A; | |
5231 | case PORT_B: | |
5232 | return POWER_DOMAIN_AUX_B; | |
5233 | case PORT_C: | |
5234 | return POWER_DOMAIN_AUX_C; | |
5235 | case PORT_D: | |
5236 | return POWER_DOMAIN_AUX_D; | |
5237 | case PORT_E: | |
5238 | /* FIXME: Check VBT for actual wiring of PORT E */ | |
5239 | return POWER_DOMAIN_AUX_D; | |
5240 | default: | |
b9fec167 | 5241 | MISSING_CASE(port); |
25f78f58 VS |
5242 | return POWER_DOMAIN_AUX_A; |
5243 | } | |
5244 | } | |
5245 | ||
319be8ae ID |
5246 | enum intel_display_power_domain |
5247 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5248 | { | |
5249 | struct drm_device *dev = intel_encoder->base.dev; | |
5250 | struct intel_digital_port *intel_dig_port; | |
5251 | ||
5252 | switch (intel_encoder->type) { | |
5253 | case INTEL_OUTPUT_UNKNOWN: | |
5254 | /* Only DDI platforms should ever use this output type */ | |
5255 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5256 | case INTEL_OUTPUT_DISPLAYPORT: | |
5257 | case INTEL_OUTPUT_HDMI: | |
5258 | case INTEL_OUTPUT_EDP: | |
5259 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5260 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5261 | case INTEL_OUTPUT_DP_MST: |
5262 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5263 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5264 | case INTEL_OUTPUT_ANALOG: |
5265 | return POWER_DOMAIN_PORT_CRT; | |
5266 | case INTEL_OUTPUT_DSI: | |
5267 | return POWER_DOMAIN_PORT_DSI; | |
5268 | default: | |
5269 | return POWER_DOMAIN_PORT_OTHER; | |
5270 | } | |
5271 | } | |
5272 | ||
25f78f58 VS |
5273 | enum intel_display_power_domain |
5274 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) | |
5275 | { | |
5276 | struct drm_device *dev = intel_encoder->base.dev; | |
5277 | struct intel_digital_port *intel_dig_port; | |
5278 | ||
5279 | switch (intel_encoder->type) { | |
5280 | case INTEL_OUTPUT_UNKNOWN: | |
651174a4 ID |
5281 | case INTEL_OUTPUT_HDMI: |
5282 | /* | |
5283 | * Only DDI platforms should ever use these output types. | |
5284 | * We can get here after the HDMI detect code has already set | |
5285 | * the type of the shared encoder. Since we can't be sure | |
5286 | * what's the status of the given connectors, play safe and | |
5287 | * run the DP detection too. | |
5288 | */ | |
25f78f58 VS |
5289 | WARN_ON_ONCE(!HAS_DDI(dev)); |
5290 | case INTEL_OUTPUT_DISPLAYPORT: | |
5291 | case INTEL_OUTPUT_EDP: | |
5292 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
5293 | return port_to_aux_power_domain(intel_dig_port->port); | |
5294 | case INTEL_OUTPUT_DP_MST: | |
5295 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5296 | return port_to_aux_power_domain(intel_dig_port->port); | |
5297 | default: | |
b9fec167 | 5298 | MISSING_CASE(intel_encoder->type); |
25f78f58 VS |
5299 | return POWER_DOMAIN_AUX_A; |
5300 | } | |
5301 | } | |
5302 | ||
319be8ae | 5303 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5304 | { |
319be8ae ID |
5305 | struct drm_device *dev = crtc->dev; |
5306 | struct intel_encoder *intel_encoder; | |
5307 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5308 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca | 5309 | unsigned long mask; |
1a70a728 | 5310 | enum transcoder transcoder = intel_crtc->config->cpu_transcoder; |
77d22dca | 5311 | |
292b990e ML |
5312 | if (!crtc->state->active) |
5313 | return 0; | |
5314 | ||
77d22dca ID |
5315 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5316 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5317 | if (intel_crtc->config->pch_pfit.enabled || |
5318 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5319 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5320 | ||
319be8ae ID |
5321 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5322 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5323 | ||
77d22dca ID |
5324 | return mask; |
5325 | } | |
5326 | ||
292b990e | 5327 | static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5328 | { |
292b990e ML |
5329 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5330 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5331 | enum intel_display_power_domain domain; | |
5332 | unsigned long domains, new_domains, old_domains; | |
77d22dca | 5333 | |
292b990e ML |
5334 | old_domains = intel_crtc->enabled_power_domains; |
5335 | intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc); | |
77d22dca | 5336 | |
292b990e ML |
5337 | domains = new_domains & ~old_domains; |
5338 | ||
5339 | for_each_power_domain(domain, domains) | |
5340 | intel_display_power_get(dev_priv, domain); | |
5341 | ||
5342 | return old_domains & ~new_domains; | |
5343 | } | |
5344 | ||
5345 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5346 | unsigned long domains) | |
5347 | { | |
5348 | enum intel_display_power_domain domain; | |
5349 | ||
5350 | for_each_power_domain(domain, domains) | |
5351 | intel_display_power_put(dev_priv, domain); | |
5352 | } | |
77d22dca | 5353 | |
292b990e ML |
5354 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
5355 | { | |
5356 | struct drm_device *dev = state->dev; | |
5357 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5358 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
5359 | struct drm_crtc_state *crtc_state; | |
5360 | struct drm_crtc *crtc; | |
5361 | int i; | |
77d22dca | 5362 | |
292b990e ML |
5363 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5364 | if (needs_modeset(crtc->state)) | |
5365 | put_domains[to_intel_crtc(crtc)->pipe] = | |
5366 | modeset_get_crtc_power_domains(crtc); | |
77d22dca ID |
5367 | } |
5368 | ||
27c329ed ML |
5369 | if (dev_priv->display.modeset_commit_cdclk) { |
5370 | unsigned int cdclk = to_intel_atomic_state(state)->cdclk; | |
5371 | ||
5372 | if (cdclk != dev_priv->cdclk_freq && | |
5373 | !WARN_ON(!state->allow_modeset)) | |
5374 | dev_priv->display.modeset_commit_cdclk(state); | |
5375 | } | |
50f6e502 | 5376 | |
292b990e ML |
5377 | for (i = 0; i < I915_MAX_PIPES; i++) |
5378 | if (put_domains[i]) | |
5379 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
77d22dca ID |
5380 | } |
5381 | ||
adafdc6f MK |
5382 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5383 | { | |
5384 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5385 | ||
5386 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5387 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5388 | return max_cdclk_freq; | |
5389 | else if (IS_CHERRYVIEW(dev_priv)) | |
5390 | return max_cdclk_freq*95/100; | |
5391 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5392 | return 2*max_cdclk_freq*90/100; | |
5393 | else | |
5394 | return max_cdclk_freq*90/100; | |
5395 | } | |
5396 | ||
560a7ae4 DL |
5397 | static void intel_update_max_cdclk(struct drm_device *dev) |
5398 | { | |
5399 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5400 | ||
ef11bdb3 | 5401 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
560a7ae4 DL |
5402 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
5403 | ||
5404 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5405 | dev_priv->max_cdclk_freq = 675000; | |
5406 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5407 | dev_priv->max_cdclk_freq = 540000; | |
5408 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5409 | dev_priv->max_cdclk_freq = 450000; | |
5410 | else | |
5411 | dev_priv->max_cdclk_freq = 337500; | |
5412 | } else if (IS_BROADWELL(dev)) { | |
5413 | /* | |
5414 | * FIXME with extra cooling we can allow | |
5415 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5416 | * How can we know if extra cooling is | |
5417 | * available? PCI ID, VTB, something else? | |
5418 | */ | |
5419 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5420 | dev_priv->max_cdclk_freq = 450000; | |
5421 | else if (IS_BDW_ULX(dev)) | |
5422 | dev_priv->max_cdclk_freq = 450000; | |
5423 | else if (IS_BDW_ULT(dev)) | |
5424 | dev_priv->max_cdclk_freq = 540000; | |
5425 | else | |
5426 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5427 | } else if (IS_CHERRYVIEW(dev)) { |
5428 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5429 | } else if (IS_VALLEYVIEW(dev)) { |
5430 | dev_priv->max_cdclk_freq = 400000; | |
5431 | } else { | |
5432 | /* otherwise assume cdclk is fixed */ | |
5433 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5434 | } | |
5435 | ||
adafdc6f MK |
5436 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5437 | ||
560a7ae4 DL |
5438 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5439 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5440 | |
5441 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5442 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5443 | } |
5444 | ||
5445 | static void intel_update_cdclk(struct drm_device *dev) | |
5446 | { | |
5447 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5448 | ||
5449 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5450 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5451 | dev_priv->cdclk_freq); | |
5452 | ||
5453 | /* | |
5454 | * Program the gmbus_freq based on the cdclk frequency. | |
5455 | * BSpec erroneously claims we should aim for 4MHz, but | |
5456 | * in fact 1MHz is the correct frequency. | |
5457 | */ | |
5458 | if (IS_VALLEYVIEW(dev)) { | |
5459 | /* | |
5460 | * Program the gmbus_freq based on the cdclk frequency. | |
5461 | * BSpec erroneously claims we should aim for 4MHz, but | |
5462 | * in fact 1MHz is the correct frequency. | |
5463 | */ | |
5464 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5465 | } | |
5466 | ||
5467 | if (dev_priv->max_cdclk_freq == 0) | |
5468 | intel_update_max_cdclk(dev); | |
5469 | } | |
5470 | ||
70d0c574 | 5471 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5472 | { |
5473 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5474 | uint32_t divider; | |
5475 | uint32_t ratio; | |
5476 | uint32_t current_freq; | |
5477 | int ret; | |
5478 | ||
5479 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5480 | switch (frequency) { | |
5481 | case 144000: | |
5482 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5483 | ratio = BXT_DE_PLL_RATIO(60); | |
5484 | break; | |
5485 | case 288000: | |
5486 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5487 | ratio = BXT_DE_PLL_RATIO(60); | |
5488 | break; | |
5489 | case 384000: | |
5490 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5491 | ratio = BXT_DE_PLL_RATIO(60); | |
5492 | break; | |
5493 | case 576000: | |
5494 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5495 | ratio = BXT_DE_PLL_RATIO(60); | |
5496 | break; | |
5497 | case 624000: | |
5498 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5499 | ratio = BXT_DE_PLL_RATIO(65); | |
5500 | break; | |
5501 | case 19200: | |
5502 | /* | |
5503 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5504 | * to suppress GCC warning. | |
5505 | */ | |
5506 | ratio = 0; | |
5507 | divider = 0; | |
5508 | break; | |
5509 | default: | |
5510 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5511 | ||
5512 | return; | |
5513 | } | |
5514 | ||
5515 | mutex_lock(&dev_priv->rps.hw_lock); | |
5516 | /* Inform power controller of upcoming frequency change */ | |
5517 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5518 | 0x80000000); | |
5519 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5520 | ||
5521 | if (ret) { | |
5522 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5523 | ret, frequency); | |
5524 | return; | |
5525 | } | |
5526 | ||
5527 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5528 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5529 | current_freq = current_freq * 500 + 1000; | |
5530 | ||
5531 | /* | |
5532 | * DE PLL has to be disabled when | |
5533 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5534 | * - before setting to 624MHz (PLL needs toggling) | |
5535 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5536 | */ | |
5537 | if (frequency == 19200 || frequency == 624000 || | |
5538 | current_freq == 624000) { | |
5539 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5540 | /* Timeout 200us */ | |
5541 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5542 | 1)) | |
5543 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5544 | } | |
5545 | ||
5546 | if (frequency != 19200) { | |
5547 | uint32_t val; | |
5548 | ||
5549 | val = I915_READ(BXT_DE_PLL_CTL); | |
5550 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5551 | val |= ratio; | |
5552 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5553 | ||
5554 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5555 | /* Timeout 200us */ | |
5556 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5557 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5558 | ||
5559 | val = I915_READ(CDCLK_CTL); | |
5560 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5561 | val |= divider; | |
5562 | /* | |
5563 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5564 | * enable otherwise. | |
5565 | */ | |
5566 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5567 | if (frequency >= 500000) | |
5568 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5569 | ||
5570 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5571 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5572 | val |= (frequency - 1000) / 500; | |
5573 | I915_WRITE(CDCLK_CTL, val); | |
5574 | } | |
5575 | ||
5576 | mutex_lock(&dev_priv->rps.hw_lock); | |
5577 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5578 | DIV_ROUND_UP(frequency, 25000)); | |
5579 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5580 | ||
5581 | if (ret) { | |
5582 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5583 | ret, frequency); | |
5584 | return; | |
5585 | } | |
5586 | ||
a47871bd | 5587 | intel_update_cdclk(dev); |
f8437dd1 VK |
5588 | } |
5589 | ||
5590 | void broxton_init_cdclk(struct drm_device *dev) | |
5591 | { | |
5592 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5593 | uint32_t val; | |
5594 | ||
5595 | /* | |
5596 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5597 | * or else the reset will hang because there is no PCH to respond. | |
5598 | * Move the handshake programming to initialization sequence. | |
5599 | * Previously was left up to BIOS. | |
5600 | */ | |
5601 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5602 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5603 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5604 | ||
5605 | /* Enable PG1 for cdclk */ | |
5606 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5607 | ||
5608 | /* check if cd clock is enabled */ | |
5609 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5610 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5611 | return; | |
5612 | } | |
5613 | ||
5614 | /* | |
5615 | * FIXME: | |
5616 | * - The initial CDCLK needs to be read from VBT. | |
5617 | * Need to make this change after VBT has changes for BXT. | |
5618 | * - check if setting the max (or any) cdclk freq is really necessary | |
5619 | * here, it belongs to modeset time | |
5620 | */ | |
5621 | broxton_set_cdclk(dev, 624000); | |
5622 | ||
5623 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5624 | POSTING_READ(DBUF_CTL); |
5625 | ||
f8437dd1 VK |
5626 | udelay(10); |
5627 | ||
5628 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5629 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5630 | } | |
5631 | ||
5632 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5633 | { | |
5634 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5635 | ||
5636 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5637 | POSTING_READ(DBUF_CTL); |
5638 | ||
f8437dd1 VK |
5639 | udelay(10); |
5640 | ||
5641 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5642 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5643 | ||
5644 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5645 | broxton_set_cdclk(dev, 19200); | |
5646 | ||
5647 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5648 | } | |
5649 | ||
5d96d8af DL |
5650 | static const struct skl_cdclk_entry { |
5651 | unsigned int freq; | |
5652 | unsigned int vco; | |
5653 | } skl_cdclk_frequencies[] = { | |
5654 | { .freq = 308570, .vco = 8640 }, | |
5655 | { .freq = 337500, .vco = 8100 }, | |
5656 | { .freq = 432000, .vco = 8640 }, | |
5657 | { .freq = 450000, .vco = 8100 }, | |
5658 | { .freq = 540000, .vco = 8100 }, | |
5659 | { .freq = 617140, .vco = 8640 }, | |
5660 | { .freq = 675000, .vco = 8100 }, | |
5661 | }; | |
5662 | ||
5663 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5664 | { | |
5665 | return (freq - 1000) / 500; | |
5666 | } | |
5667 | ||
5668 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5669 | { | |
5670 | unsigned int i; | |
5671 | ||
5672 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5673 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5674 | ||
5675 | if (e->freq == freq) | |
5676 | return e->vco; | |
5677 | } | |
5678 | ||
5679 | return 8100; | |
5680 | } | |
5681 | ||
5682 | static void | |
5683 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5684 | { | |
5685 | unsigned int min_freq; | |
5686 | u32 val; | |
5687 | ||
5688 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5689 | val = I915_READ(CDCLK_CTL); | |
5690 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5691 | val |= CDCLK_FREQ_337_308; | |
5692 | ||
5693 | if (required_vco == 8640) | |
5694 | min_freq = 308570; | |
5695 | else | |
5696 | min_freq = 337500; | |
5697 | ||
5698 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5699 | ||
5700 | I915_WRITE(CDCLK_CTL, val); | |
5701 | POSTING_READ(CDCLK_CTL); | |
5702 | ||
5703 | /* | |
5704 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5705 | * taking into account the VCO required to operate the eDP panel at the | |
5706 | * desired frequency. The usual DP link rates operate with a VCO of | |
5707 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5708 | * The modeset code is responsible for the selection of the exact link | |
5709 | * rate later on, with the constraint of choosing a frequency that | |
5710 | * works with required_vco. | |
5711 | */ | |
5712 | val = I915_READ(DPLL_CTRL1); | |
5713 | ||
5714 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5715 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5716 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5717 | if (required_vco == 8640) | |
5718 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5719 | SKL_DPLL0); | |
5720 | else | |
5721 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5722 | SKL_DPLL0); | |
5723 | ||
5724 | I915_WRITE(DPLL_CTRL1, val); | |
5725 | POSTING_READ(DPLL_CTRL1); | |
5726 | ||
5727 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5728 | ||
5729 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5730 | DRM_ERROR("DPLL0 not locked\n"); | |
5731 | } | |
5732 | ||
5733 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5734 | { | |
5735 | int ret; | |
5736 | u32 val; | |
5737 | ||
5738 | /* inform PCU we want to change CDCLK */ | |
5739 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5740 | mutex_lock(&dev_priv->rps.hw_lock); | |
5741 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5742 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5743 | ||
5744 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5745 | } | |
5746 | ||
5747 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5748 | { | |
5749 | unsigned int i; | |
5750 | ||
5751 | for (i = 0; i < 15; i++) { | |
5752 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5753 | return true; | |
5754 | udelay(10); | |
5755 | } | |
5756 | ||
5757 | return false; | |
5758 | } | |
5759 | ||
5760 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5761 | { | |
560a7ae4 | 5762 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5763 | u32 freq_select, pcu_ack; |
5764 | ||
5765 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5766 | ||
5767 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5768 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5769 | return; | |
5770 | } | |
5771 | ||
5772 | /* set CDCLK_CTL */ | |
5773 | switch(freq) { | |
5774 | case 450000: | |
5775 | case 432000: | |
5776 | freq_select = CDCLK_FREQ_450_432; | |
5777 | pcu_ack = 1; | |
5778 | break; | |
5779 | case 540000: | |
5780 | freq_select = CDCLK_FREQ_540; | |
5781 | pcu_ack = 2; | |
5782 | break; | |
5783 | case 308570: | |
5784 | case 337500: | |
5785 | default: | |
5786 | freq_select = CDCLK_FREQ_337_308; | |
5787 | pcu_ack = 0; | |
5788 | break; | |
5789 | case 617140: | |
5790 | case 675000: | |
5791 | freq_select = CDCLK_FREQ_675_617; | |
5792 | pcu_ack = 3; | |
5793 | break; | |
5794 | } | |
5795 | ||
5796 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5797 | POSTING_READ(CDCLK_CTL); | |
5798 | ||
5799 | /* inform PCU of the change */ | |
5800 | mutex_lock(&dev_priv->rps.hw_lock); | |
5801 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5802 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5803 | |
5804 | intel_update_cdclk(dev); | |
5d96d8af DL |
5805 | } |
5806 | ||
5807 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5808 | { | |
5809 | /* disable DBUF power */ | |
5810 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5811 | POSTING_READ(DBUF_CTL); | |
5812 | ||
5813 | udelay(10); | |
5814 | ||
5815 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5816 | DRM_ERROR("DBuf power disable timeout\n"); | |
5817 | ||
ab96c1ee ID |
5818 | /* disable DPLL0 */ |
5819 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5820 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5821 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5d96d8af DL |
5822 | } |
5823 | ||
5824 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5825 | { | |
5d96d8af DL |
5826 | unsigned int required_vco; |
5827 | ||
39d9b85a GW |
5828 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5829 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5830 | /* enable DPLL0 */ | |
5831 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5832 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5833 | } |
5834 | ||
5d96d8af DL |
5835 | /* set CDCLK to the frequency the BIOS chose */ |
5836 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5837 | ||
5838 | /* enable DBUF power */ | |
5839 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5840 | POSTING_READ(DBUF_CTL); | |
5841 | ||
5842 | udelay(10); | |
5843 | ||
5844 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5845 | DRM_ERROR("DBuf power enable timeout\n"); | |
5846 | } | |
5847 | ||
c73666f3 SK |
5848 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
5849 | { | |
5850 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5851 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5852 | int freq = dev_priv->skl_boot_cdclk; | |
5853 | ||
f1b391a5 SK |
5854 | /* |
5855 | * check if the pre-os intialized the display | |
5856 | * There is SWF18 scratchpad register defined which is set by the | |
5857 | * pre-os which can be used by the OS drivers to check the status | |
5858 | */ | |
5859 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5860 | goto sanitize; | |
5861 | ||
c73666f3 SK |
5862 | /* Is PLL enabled and locked ? */ |
5863 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5864 | goto sanitize; | |
5865 | ||
5866 | /* DPLL okay; verify the cdclock | |
5867 | * | |
5868 | * Noticed in some instances that the freq selection is correct but | |
5869 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5870 | * enable display. Verify the same as well. | |
5871 | */ | |
5872 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5873 | /* All well; nothing to sanitize */ | |
5874 | return false; | |
5875 | sanitize: | |
5876 | /* | |
5877 | * As of now initialize with max cdclk till | |
5878 | * we get dynamic cdclk support | |
5879 | * */ | |
5880 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5881 | skl_init_cdclk(dev_priv); | |
5882 | ||
5883 | /* we did have to sanitize */ | |
5884 | return true; | |
5885 | } | |
5886 | ||
30a970c6 JB |
5887 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5888 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5889 | { | |
5890 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5891 | u32 val, cmd; | |
5892 | ||
164dfd28 VK |
5893 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5894 | != dev_priv->cdclk_freq); | |
d60c4473 | 5895 | |
dfcab17e | 5896 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5897 | cmd = 2; |
dfcab17e | 5898 | else if (cdclk == 266667) |
30a970c6 JB |
5899 | cmd = 1; |
5900 | else | |
5901 | cmd = 0; | |
5902 | ||
5903 | mutex_lock(&dev_priv->rps.hw_lock); | |
5904 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5905 | val &= ~DSPFREQGUAR_MASK; | |
5906 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5907 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5908 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5909 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5910 | 50)) { | |
5911 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5912 | } | |
5913 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5914 | ||
54433e91 VS |
5915 | mutex_lock(&dev_priv->sb_lock); |
5916 | ||
dfcab17e | 5917 | if (cdclk == 400000) { |
6bcda4f0 | 5918 | u32 divider; |
30a970c6 | 5919 | |
6bcda4f0 | 5920 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5921 | |
30a970c6 JB |
5922 | /* adjust cdclk divider */ |
5923 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 5924 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
5925 | val |= divider; |
5926 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5927 | |
5928 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 5929 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
5930 | 50)) |
5931 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5932 | } |
5933 | ||
30a970c6 JB |
5934 | /* adjust self-refresh exit latency value */ |
5935 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5936 | val &= ~0x7f; | |
5937 | ||
5938 | /* | |
5939 | * For high bandwidth configs, we set a higher latency in the bunit | |
5940 | * so that the core display fetch happens in time to avoid underruns. | |
5941 | */ | |
dfcab17e | 5942 | if (cdclk == 400000) |
30a970c6 JB |
5943 | val |= 4500 / 250; /* 4.5 usec */ |
5944 | else | |
5945 | val |= 3000 / 250; /* 3.0 usec */ | |
5946 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5947 | |
a580516d | 5948 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5949 | |
b6283055 | 5950 | intel_update_cdclk(dev); |
30a970c6 JB |
5951 | } |
5952 | ||
383c5a6a VS |
5953 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5954 | { | |
5955 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5956 | u32 val, cmd; | |
5957 | ||
164dfd28 VK |
5958 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5959 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5960 | |
5961 | switch (cdclk) { | |
383c5a6a VS |
5962 | case 333333: |
5963 | case 320000: | |
383c5a6a | 5964 | case 266667: |
383c5a6a | 5965 | case 200000: |
383c5a6a VS |
5966 | break; |
5967 | default: | |
5f77eeb0 | 5968 | MISSING_CASE(cdclk); |
383c5a6a VS |
5969 | return; |
5970 | } | |
5971 | ||
9d0d3fda VS |
5972 | /* |
5973 | * Specs are full of misinformation, but testing on actual | |
5974 | * hardware has shown that we just need to write the desired | |
5975 | * CCK divider into the Punit register. | |
5976 | */ | |
5977 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5978 | ||
383c5a6a VS |
5979 | mutex_lock(&dev_priv->rps.hw_lock); |
5980 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5981 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5982 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5983 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5984 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5985 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5986 | 50)) { | |
5987 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5988 | } | |
5989 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5990 | ||
b6283055 | 5991 | intel_update_cdclk(dev); |
383c5a6a VS |
5992 | } |
5993 | ||
30a970c6 JB |
5994 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5995 | int max_pixclk) | |
5996 | { | |
6bcda4f0 | 5997 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5998 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5999 | |
30a970c6 JB |
6000 | /* |
6001 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
6002 | * 200MHz | |
6003 | * 267MHz | |
29dc7ef3 | 6004 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
6005 | * 400MHz (VLV only) |
6006 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
6007 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
6008 | * |
6009 | * We seem to get an unstable or solid color picture at 200MHz. | |
6010 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
6011 | * are off. | |
30a970c6 | 6012 | */ |
6cca3195 VS |
6013 | if (!IS_CHERRYVIEW(dev_priv) && |
6014 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 6015 | return 400000; |
6cca3195 | 6016 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 6017 | return freq_320; |
e37c67a1 | 6018 | else if (max_pixclk > 0) |
dfcab17e | 6019 | return 266667; |
e37c67a1 VS |
6020 | else |
6021 | return 200000; | |
30a970c6 JB |
6022 | } |
6023 | ||
f8437dd1 VK |
6024 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
6025 | int max_pixclk) | |
6026 | { | |
6027 | /* | |
6028 | * FIXME: | |
6029 | * - remove the guardband, it's not needed on BXT | |
6030 | * - set 19.2MHz bypass frequency if there are no active pipes | |
6031 | */ | |
6032 | if (max_pixclk > 576000*9/10) | |
6033 | return 624000; | |
6034 | else if (max_pixclk > 384000*9/10) | |
6035 | return 576000; | |
6036 | else if (max_pixclk > 288000*9/10) | |
6037 | return 384000; | |
6038 | else if (max_pixclk > 144000*9/10) | |
6039 | return 288000; | |
6040 | else | |
6041 | return 144000; | |
6042 | } | |
6043 | ||
a821fc46 ACO |
6044 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
6045 | * that's non-NULL, look at current state otherwise. */ | |
6046 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
6047 | struct drm_atomic_state *state) | |
30a970c6 | 6048 | { |
30a970c6 | 6049 | struct intel_crtc *intel_crtc; |
304603f4 | 6050 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
6051 | int max_pixclk = 0; |
6052 | ||
d3fcc808 | 6053 | for_each_intel_crtc(dev, intel_crtc) { |
27c329ed | 6054 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
304603f4 ACO |
6055 | if (IS_ERR(crtc_state)) |
6056 | return PTR_ERR(crtc_state); | |
6057 | ||
6058 | if (!crtc_state->base.enable) | |
6059 | continue; | |
6060 | ||
6061 | max_pixclk = max(max_pixclk, | |
6062 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
6063 | } |
6064 | ||
6065 | return max_pixclk; | |
6066 | } | |
6067 | ||
27c329ed | 6068 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 6069 | { |
27c329ed ML |
6070 | struct drm_device *dev = state->dev; |
6071 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6072 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
30a970c6 | 6073 | |
304603f4 ACO |
6074 | if (max_pixclk < 0) |
6075 | return max_pixclk; | |
30a970c6 | 6076 | |
27c329ed ML |
6077 | to_intel_atomic_state(state)->cdclk = |
6078 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
0a9ab303 | 6079 | |
27c329ed ML |
6080 | return 0; |
6081 | } | |
304603f4 | 6082 | |
27c329ed ML |
6083 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
6084 | { | |
6085 | struct drm_device *dev = state->dev; | |
6086 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6087 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
85a96e7a | 6088 | |
27c329ed ML |
6089 | if (max_pixclk < 0) |
6090 | return max_pixclk; | |
85a96e7a | 6091 | |
27c329ed ML |
6092 | to_intel_atomic_state(state)->cdclk = |
6093 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
85a96e7a | 6094 | |
27c329ed | 6095 | return 0; |
30a970c6 JB |
6096 | } |
6097 | ||
1e69cd74 VS |
6098 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
6099 | { | |
6100 | unsigned int credits, default_credits; | |
6101 | ||
6102 | if (IS_CHERRYVIEW(dev_priv)) | |
6103 | default_credits = PFI_CREDIT(12); | |
6104 | else | |
6105 | default_credits = PFI_CREDIT(8); | |
6106 | ||
bfa7df01 | 6107 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
6108 | /* CHV suggested value is 31 or 63 */ |
6109 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 6110 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
6111 | else |
6112 | credits = PFI_CREDIT(15); | |
6113 | } else { | |
6114 | credits = default_credits; | |
6115 | } | |
6116 | ||
6117 | /* | |
6118 | * WA - write default credits before re-programming | |
6119 | * FIXME: should we also set the resend bit here? | |
6120 | */ | |
6121 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6122 | default_credits); | |
6123 | ||
6124 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6125 | credits | PFI_CREDIT_RESEND); | |
6126 | ||
6127 | /* | |
6128 | * FIXME is this guaranteed to clear | |
6129 | * immediately or should we poll for it? | |
6130 | */ | |
6131 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6132 | } | |
6133 | ||
27c329ed | 6134 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6135 | { |
a821fc46 | 6136 | struct drm_device *dev = old_state->dev; |
27c329ed | 6137 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
30a970c6 | 6138 | struct drm_i915_private *dev_priv = dev->dev_private; |
30a970c6 | 6139 | |
27c329ed ML |
6140 | /* |
6141 | * FIXME: We can end up here with all power domains off, yet | |
6142 | * with a CDCLK frequency other than the minimum. To account | |
6143 | * for this take the PIPE-A power domain, which covers the HW | |
6144 | * blocks needed for the following programming. This can be | |
6145 | * removed once it's guaranteed that we get here either with | |
6146 | * the minimum CDCLK set, or the required power domains | |
6147 | * enabled. | |
6148 | */ | |
6149 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6150 | |
27c329ed ML |
6151 | if (IS_CHERRYVIEW(dev)) |
6152 | cherryview_set_cdclk(dev, req_cdclk); | |
6153 | else | |
6154 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6155 | |
27c329ed | 6156 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6157 | |
27c329ed | 6158 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6159 | } |
6160 | ||
89b667f8 JB |
6161 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6162 | { | |
6163 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6164 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6165 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6166 | struct intel_encoder *encoder; | |
6167 | int pipe = intel_crtc->pipe; | |
89b667f8 | 6168 | |
53d9f4e9 | 6169 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6170 | return; |
6171 | ||
6e3c9717 | 6172 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6173 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6174 | |
6175 | intel_set_pipe_timings(intel_crtc); | |
6176 | ||
c14b0485 VS |
6177 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6178 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6179 | ||
6180 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6181 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6182 | } | |
6183 | ||
5b18e57c DV |
6184 | i9xx_set_pipeconf(intel_crtc); |
6185 | ||
89b667f8 | 6186 | intel_crtc->active = true; |
89b667f8 | 6187 | |
a72e4c9f | 6188 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6189 | |
89b667f8 JB |
6190 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6191 | if (encoder->pre_pll_enable) | |
6192 | encoder->pre_pll_enable(encoder); | |
6193 | ||
a65347ba | 6194 | if (!intel_crtc->config->has_dsi_encoder) { |
c0b4c660 VS |
6195 | if (IS_CHERRYVIEW(dev)) { |
6196 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6197 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6198 | } else { |
6199 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6200 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6201 | } |
9d556c99 | 6202 | } |
89b667f8 JB |
6203 | |
6204 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6205 | if (encoder->pre_enable) | |
6206 | encoder->pre_enable(encoder); | |
6207 | ||
2dd24552 JB |
6208 | i9xx_pfit_enable(intel_crtc); |
6209 | ||
63cbb074 VS |
6210 | intel_crtc_load_lut(crtc); |
6211 | ||
e1fdc473 | 6212 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6213 | |
4b3a9526 VS |
6214 | assert_vblank_disabled(crtc); |
6215 | drm_crtc_vblank_on(crtc); | |
6216 | ||
f9b61ff6 DV |
6217 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6218 | encoder->enable(encoder); | |
89b667f8 JB |
6219 | } |
6220 | ||
f13c2ef3 DV |
6221 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6222 | { | |
6223 | struct drm_device *dev = crtc->base.dev; | |
6224 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6225 | ||
6e3c9717 ACO |
6226 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6227 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6228 | } |
6229 | ||
0b8765c6 | 6230 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6231 | { |
6232 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6233 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6234 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6235 | struct intel_encoder *encoder; |
79e53945 | 6236 | int pipe = intel_crtc->pipe; |
79e53945 | 6237 | |
53d9f4e9 | 6238 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6239 | return; |
6240 | ||
f13c2ef3 DV |
6241 | i9xx_set_pll_dividers(intel_crtc); |
6242 | ||
6e3c9717 | 6243 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6244 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6245 | |
6246 | intel_set_pipe_timings(intel_crtc); | |
6247 | ||
5b18e57c DV |
6248 | i9xx_set_pipeconf(intel_crtc); |
6249 | ||
f7abfe8b | 6250 | intel_crtc->active = true; |
6b383a7f | 6251 | |
4a3436e8 | 6252 | if (!IS_GEN2(dev)) |
a72e4c9f | 6253 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6254 | |
9d6d9f19 MK |
6255 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6256 | if (encoder->pre_enable) | |
6257 | encoder->pre_enable(encoder); | |
6258 | ||
f6736a1a DV |
6259 | i9xx_enable_pll(intel_crtc); |
6260 | ||
2dd24552 JB |
6261 | i9xx_pfit_enable(intel_crtc); |
6262 | ||
63cbb074 VS |
6263 | intel_crtc_load_lut(crtc); |
6264 | ||
f37fcc2a | 6265 | intel_update_watermarks(crtc); |
e1fdc473 | 6266 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6267 | |
4b3a9526 VS |
6268 | assert_vblank_disabled(crtc); |
6269 | drm_crtc_vblank_on(crtc); | |
6270 | ||
f9b61ff6 DV |
6271 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6272 | encoder->enable(encoder); | |
d029bcad PZ |
6273 | |
6274 | intel_fbc_enable(intel_crtc); | |
0b8765c6 | 6275 | } |
79e53945 | 6276 | |
87476d63 DV |
6277 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6278 | { | |
6279 | struct drm_device *dev = crtc->base.dev; | |
6280 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6281 | |
6e3c9717 | 6282 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6283 | return; |
87476d63 | 6284 | |
328d8e82 | 6285 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6286 | |
328d8e82 DV |
6287 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6288 | I915_READ(PFIT_CONTROL)); | |
6289 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6290 | } |
6291 | ||
0b8765c6 JB |
6292 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6293 | { | |
6294 | struct drm_device *dev = crtc->dev; | |
6295 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6296 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6297 | struct intel_encoder *encoder; |
0b8765c6 | 6298 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6299 | |
6304cd91 VS |
6300 | /* |
6301 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6302 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6303 | * We also need to wait on all gmch platforms because of the |
6304 | * self-refresh mode constraint explained above. | |
6304cd91 | 6305 | */ |
564ed191 | 6306 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6307 | |
4b3a9526 VS |
6308 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6309 | encoder->disable(encoder); | |
6310 | ||
f9b61ff6 DV |
6311 | drm_crtc_vblank_off(crtc); |
6312 | assert_vblank_disabled(crtc); | |
6313 | ||
575f7ab7 | 6314 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6315 | |
87476d63 | 6316 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6317 | |
89b667f8 JB |
6318 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6319 | if (encoder->post_disable) | |
6320 | encoder->post_disable(encoder); | |
6321 | ||
a65347ba | 6322 | if (!intel_crtc->config->has_dsi_encoder) { |
076ed3b2 CML |
6323 | if (IS_CHERRYVIEW(dev)) |
6324 | chv_disable_pll(dev_priv, pipe); | |
6325 | else if (IS_VALLEYVIEW(dev)) | |
6326 | vlv_disable_pll(dev_priv, pipe); | |
6327 | else | |
1c4e0274 | 6328 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6329 | } |
0b8765c6 | 6330 | |
d6db995f VS |
6331 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6332 | if (encoder->post_pll_disable) | |
6333 | encoder->post_pll_disable(encoder); | |
6334 | ||
4a3436e8 | 6335 | if (!IS_GEN2(dev)) |
a72e4c9f | 6336 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
d029bcad PZ |
6337 | |
6338 | intel_fbc_disable_crtc(intel_crtc); | |
0b8765c6 JB |
6339 | } |
6340 | ||
b17d48e2 ML |
6341 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6342 | { | |
6343 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6344 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6345 | enum intel_display_power_domain domain; | |
6346 | unsigned long domains; | |
6347 | ||
6348 | if (!intel_crtc->active) | |
6349 | return; | |
6350 | ||
a539205a | 6351 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
fc32b1fd ML |
6352 | WARN_ON(intel_crtc->unpin_work); |
6353 | ||
a539205a ML |
6354 | intel_pre_disable_primary(crtc); |
6355 | } | |
6356 | ||
d032ffa0 | 6357 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 | 6358 | dev_priv->display.crtc_disable(crtc); |
37d9078b MR |
6359 | intel_crtc->active = false; |
6360 | intel_update_watermarks(crtc); | |
1f7457b1 | 6361 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6362 | |
6363 | domains = intel_crtc->enabled_power_domains; | |
6364 | for_each_power_domain(domain, domains) | |
6365 | intel_display_power_put(dev_priv, domain); | |
6366 | intel_crtc->enabled_power_domains = 0; | |
6367 | } | |
6368 | ||
6b72d486 ML |
6369 | /* |
6370 | * turn all crtc's off, but do not adjust state | |
6371 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6372 | */ | |
70e0bd74 | 6373 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6374 | { |
70e0bd74 ML |
6375 | struct drm_mode_config *config = &dev->mode_config; |
6376 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
6377 | struct drm_atomic_state *state; | |
6b72d486 | 6378 | struct drm_crtc *crtc; |
70e0bd74 ML |
6379 | unsigned crtc_mask = 0; |
6380 | int ret = 0; | |
6381 | ||
6382 | if (WARN_ON(!ctx)) | |
6383 | return 0; | |
6384 | ||
6385 | lockdep_assert_held(&ctx->ww_ctx); | |
6386 | state = drm_atomic_state_alloc(dev); | |
6387 | if (WARN_ON(!state)) | |
6388 | return -ENOMEM; | |
6389 | ||
6390 | state->acquire_ctx = ctx; | |
6391 | state->allow_modeset = true; | |
6392 | ||
6393 | for_each_crtc(dev, crtc) { | |
6394 | struct drm_crtc_state *crtc_state = | |
6395 | drm_atomic_get_crtc_state(state, crtc); | |
6b72d486 | 6396 | |
70e0bd74 ML |
6397 | ret = PTR_ERR_OR_ZERO(crtc_state); |
6398 | if (ret) | |
6399 | goto free; | |
6400 | ||
6401 | if (!crtc_state->active) | |
6402 | continue; | |
6403 | ||
6404 | crtc_state->active = false; | |
6405 | crtc_mask |= 1 << drm_crtc_index(crtc); | |
6406 | } | |
6407 | ||
6408 | if (crtc_mask) { | |
74c090b1 | 6409 | ret = drm_atomic_commit(state); |
70e0bd74 ML |
6410 | |
6411 | if (!ret) { | |
6412 | for_each_crtc(dev, crtc) | |
6413 | if (crtc_mask & (1 << drm_crtc_index(crtc))) | |
6414 | crtc->state->active = true; | |
6415 | ||
6416 | return ret; | |
6417 | } | |
6418 | } | |
6419 | ||
6420 | free: | |
6421 | if (ret) | |
6422 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6423 | drm_atomic_state_free(state); | |
6424 | return ret; | |
ee7b9f93 JB |
6425 | } |
6426 | ||
ea5b213a | 6427 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6428 | { |
4ef69c7a | 6429 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6430 | |
ea5b213a CW |
6431 | drm_encoder_cleanup(encoder); |
6432 | kfree(intel_encoder); | |
7e7d76c3 JB |
6433 | } |
6434 | ||
0a91ca29 DV |
6435 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6436 | * internal consistency). */ | |
b980514c | 6437 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6438 | { |
35dd3c64 ML |
6439 | struct drm_crtc *crtc = connector->base.state->crtc; |
6440 | ||
6441 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6442 | connector->base.base.id, | |
6443 | connector->base.name); | |
6444 | ||
0a91ca29 | 6445 | if (connector->get_hw_state(connector)) { |
e85376cb | 6446 | struct intel_encoder *encoder = connector->encoder; |
35dd3c64 | 6447 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6448 | |
35dd3c64 ML |
6449 | I915_STATE_WARN(!crtc, |
6450 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6451 | |
35dd3c64 ML |
6452 | if (!crtc) |
6453 | return; | |
6454 | ||
6455 | I915_STATE_WARN(!crtc->state->active, | |
6456 | "connector is active, but attached crtc isn't\n"); | |
6457 | ||
e85376cb | 6458 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6459 | return; |
6460 | ||
e85376cb | 6461 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6462 | "atomic encoder doesn't match attached encoder\n"); |
6463 | ||
e85376cb | 6464 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6465 | "attached encoder crtc differs from connector crtc\n"); |
6466 | } else { | |
4d688a2a ML |
6467 | I915_STATE_WARN(crtc && crtc->state->active, |
6468 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6469 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6470 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6471 | } |
79e53945 JB |
6472 | } |
6473 | ||
08d9bc92 ACO |
6474 | int intel_connector_init(struct intel_connector *connector) |
6475 | { | |
6476 | struct drm_connector_state *connector_state; | |
6477 | ||
6478 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6479 | if (!connector_state) | |
6480 | return -ENOMEM; | |
6481 | ||
6482 | connector->base.state = connector_state; | |
6483 | return 0; | |
6484 | } | |
6485 | ||
6486 | struct intel_connector *intel_connector_alloc(void) | |
6487 | { | |
6488 | struct intel_connector *connector; | |
6489 | ||
6490 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6491 | if (!connector) | |
6492 | return NULL; | |
6493 | ||
6494 | if (intel_connector_init(connector) < 0) { | |
6495 | kfree(connector); | |
6496 | return NULL; | |
6497 | } | |
6498 | ||
6499 | return connector; | |
6500 | } | |
6501 | ||
f0947c37 DV |
6502 | /* Simple connector->get_hw_state implementation for encoders that support only |
6503 | * one connector and no cloning and hence the encoder state determines the state | |
6504 | * of the connector. */ | |
6505 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6506 | { |
24929352 | 6507 | enum pipe pipe = 0; |
f0947c37 | 6508 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6509 | |
f0947c37 | 6510 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6511 | } |
6512 | ||
6d293983 | 6513 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6514 | { |
6d293983 ACO |
6515 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6516 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6517 | |
6518 | return 0; | |
6519 | } | |
6520 | ||
6d293983 | 6521 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6522 | struct intel_crtc_state *pipe_config) |
1857e1da | 6523 | { |
6d293983 ACO |
6524 | struct drm_atomic_state *state = pipe_config->base.state; |
6525 | struct intel_crtc *other_crtc; | |
6526 | struct intel_crtc_state *other_crtc_state; | |
6527 | ||
1857e1da DV |
6528 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6529 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6530 | if (pipe_config->fdi_lanes > 4) { | |
6531 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6532 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6533 | return -EINVAL; |
1857e1da DV |
6534 | } |
6535 | ||
bafb6553 | 6536 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6537 | if (pipe_config->fdi_lanes > 2) { |
6538 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6539 | pipe_config->fdi_lanes); | |
6d293983 | 6540 | return -EINVAL; |
1857e1da | 6541 | } else { |
6d293983 | 6542 | return 0; |
1857e1da DV |
6543 | } |
6544 | } | |
6545 | ||
6546 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6547 | return 0; |
1857e1da DV |
6548 | |
6549 | /* Ivybridge 3 pipe is really complicated */ | |
6550 | switch (pipe) { | |
6551 | case PIPE_A: | |
6d293983 | 6552 | return 0; |
1857e1da | 6553 | case PIPE_B: |
6d293983 ACO |
6554 | if (pipe_config->fdi_lanes <= 2) |
6555 | return 0; | |
6556 | ||
6557 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6558 | other_crtc_state = | |
6559 | intel_atomic_get_crtc_state(state, other_crtc); | |
6560 | if (IS_ERR(other_crtc_state)) | |
6561 | return PTR_ERR(other_crtc_state); | |
6562 | ||
6563 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6564 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6565 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6566 | return -EINVAL; |
1857e1da | 6567 | } |
6d293983 | 6568 | return 0; |
1857e1da | 6569 | case PIPE_C: |
251cc67c VS |
6570 | if (pipe_config->fdi_lanes > 2) { |
6571 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6572 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6573 | return -EINVAL; |
251cc67c | 6574 | } |
6d293983 ACO |
6575 | |
6576 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6577 | other_crtc_state = | |
6578 | intel_atomic_get_crtc_state(state, other_crtc); | |
6579 | if (IS_ERR(other_crtc_state)) | |
6580 | return PTR_ERR(other_crtc_state); | |
6581 | ||
6582 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6583 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6584 | return -EINVAL; |
1857e1da | 6585 | } |
6d293983 | 6586 | return 0; |
1857e1da DV |
6587 | default: |
6588 | BUG(); | |
6589 | } | |
6590 | } | |
6591 | ||
e29c22c0 DV |
6592 | #define RETRY 1 |
6593 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6594 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6595 | { |
1857e1da | 6596 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6597 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6598 | int lane, link_bw, fdi_dotclock, ret; |
6599 | bool needs_recompute = false; | |
877d48d5 | 6600 | |
e29c22c0 | 6601 | retry: |
877d48d5 DV |
6602 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6603 | * each output octet as 10 bits. The actual frequency | |
6604 | * is stored as a divider into a 100MHz clock, and the | |
6605 | * mode pixel clock is stored in units of 1KHz. | |
6606 | * Hence the bw of each lane in terms of the mode signal | |
6607 | * is: | |
6608 | */ | |
6609 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6610 | ||
241bfc38 | 6611 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6612 | |
2bd89a07 | 6613 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6614 | pipe_config->pipe_bpp); |
6615 | ||
6616 | pipe_config->fdi_lanes = lane; | |
6617 | ||
2bd89a07 | 6618 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6619 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6620 | |
6d293983 ACO |
6621 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6622 | intel_crtc->pipe, pipe_config); | |
6623 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6624 | pipe_config->pipe_bpp -= 2*3; |
6625 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6626 | pipe_config->pipe_bpp); | |
6627 | needs_recompute = true; | |
6628 | pipe_config->bw_constrained = true; | |
6629 | ||
6630 | goto retry; | |
6631 | } | |
6632 | ||
6633 | if (needs_recompute) | |
6634 | return RETRY; | |
6635 | ||
6d293983 | 6636 | return ret; |
877d48d5 DV |
6637 | } |
6638 | ||
8cfb3407 VS |
6639 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6640 | struct intel_crtc_state *pipe_config) | |
6641 | { | |
6642 | if (pipe_config->pipe_bpp > 24) | |
6643 | return false; | |
6644 | ||
6645 | /* HSW can handle pixel rate up to cdclk? */ | |
6646 | if (IS_HASWELL(dev_priv->dev)) | |
6647 | return true; | |
6648 | ||
6649 | /* | |
b432e5cf VS |
6650 | * We compare against max which means we must take |
6651 | * the increased cdclk requirement into account when | |
6652 | * calculating the new cdclk. | |
6653 | * | |
6654 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6655 | */ |
6656 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6657 | dev_priv->max_cdclk_freq * 95 / 100; | |
6658 | } | |
6659 | ||
42db64ef | 6660 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6661 | struct intel_crtc_state *pipe_config) |
42db64ef | 6662 | { |
8cfb3407 VS |
6663 | struct drm_device *dev = crtc->base.dev; |
6664 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6665 | ||
d330a953 | 6666 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6667 | hsw_crtc_supports_ips(crtc) && |
6668 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6669 | } |
6670 | ||
39acb4aa VS |
6671 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6672 | { | |
6673 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6674 | ||
6675 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6676 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6677 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6678 | } | |
6679 | ||
a43f6e0f | 6680 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6681 | struct intel_crtc_state *pipe_config) |
79e53945 | 6682 | { |
a43f6e0f | 6683 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6684 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6685 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6686 | |
ad3a4479 | 6687 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6688 | if (INTEL_INFO(dev)->gen < 4) { |
39acb4aa | 6689 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6690 | |
6691 | /* | |
39acb4aa | 6692 | * Enable double wide mode when the dot clock |
cf532bb2 | 6693 | * is > 90% of the (display) core speed. |
cf532bb2 | 6694 | */ |
39acb4aa VS |
6695 | if (intel_crtc_supports_double_wide(crtc) && |
6696 | adjusted_mode->crtc_clock > clock_limit) { | |
ad3a4479 | 6697 | clock_limit *= 2; |
cf532bb2 | 6698 | pipe_config->double_wide = true; |
ad3a4479 VS |
6699 | } |
6700 | ||
39acb4aa VS |
6701 | if (adjusted_mode->crtc_clock > clock_limit) { |
6702 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6703 | adjusted_mode->crtc_clock, clock_limit, | |
6704 | yesno(pipe_config->double_wide)); | |
e29c22c0 | 6705 | return -EINVAL; |
39acb4aa | 6706 | } |
2c07245f | 6707 | } |
89749350 | 6708 | |
1d1d0e27 VS |
6709 | /* |
6710 | * Pipe horizontal size must be even in: | |
6711 | * - DVO ganged mode | |
6712 | * - LVDS dual channel mode | |
6713 | * - Double wide pipe | |
6714 | */ | |
a93e255f | 6715 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6716 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6717 | pipe_config->pipe_src_w &= ~1; | |
6718 | ||
8693a824 DL |
6719 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6720 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6721 | */ |
6722 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6723 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6724 | return -EINVAL; |
44f46b42 | 6725 | |
f5adf94e | 6726 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6727 | hsw_compute_ips_config(crtc, pipe_config); |
6728 | ||
877d48d5 | 6729 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6730 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6731 | |
cf5a15be | 6732 | return 0; |
79e53945 JB |
6733 | } |
6734 | ||
1652d19e VS |
6735 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6736 | { | |
6737 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6738 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6739 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6740 | uint32_t linkrate; | |
6741 | ||
414355a7 | 6742 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6743 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6744 | |
6745 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6746 | return 540000; | |
6747 | ||
6748 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6749 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6750 | |
71cd8423 DL |
6751 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6752 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6753 | /* vco 8640 */ |
6754 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6755 | case CDCLK_FREQ_450_432: | |
6756 | return 432000; | |
6757 | case CDCLK_FREQ_337_308: | |
6758 | return 308570; | |
6759 | case CDCLK_FREQ_675_617: | |
6760 | return 617140; | |
6761 | default: | |
6762 | WARN(1, "Unknown cd freq selection\n"); | |
6763 | } | |
6764 | } else { | |
6765 | /* vco 8100 */ | |
6766 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6767 | case CDCLK_FREQ_450_432: | |
6768 | return 450000; | |
6769 | case CDCLK_FREQ_337_308: | |
6770 | return 337500; | |
6771 | case CDCLK_FREQ_675_617: | |
6772 | return 675000; | |
6773 | default: | |
6774 | WARN(1, "Unknown cd freq selection\n"); | |
6775 | } | |
6776 | } | |
6777 | ||
6778 | /* error case, do as if DPLL0 isn't enabled */ | |
6779 | return 24000; | |
6780 | } | |
6781 | ||
acd3f3d3 BP |
6782 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6783 | { | |
6784 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6785 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6786 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6787 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6788 | int cdclk; | |
6789 | ||
6790 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6791 | return 19200; | |
6792 | ||
6793 | cdclk = 19200 * pll_ratio / 2; | |
6794 | ||
6795 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6796 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6797 | return cdclk; /* 576MHz or 624MHz */ | |
6798 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6799 | return cdclk * 2 / 3; /* 384MHz */ | |
6800 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6801 | return cdclk / 2; /* 288MHz */ | |
6802 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6803 | return cdclk / 4; /* 144MHz */ | |
6804 | } | |
6805 | ||
6806 | /* error case, do as if DE PLL isn't enabled */ | |
6807 | return 19200; | |
6808 | } | |
6809 | ||
1652d19e VS |
6810 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6811 | { | |
6812 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6813 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6814 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6815 | ||
6816 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6817 | return 800000; | |
6818 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6819 | return 450000; | |
6820 | else if (freq == LCPLL_CLK_FREQ_450) | |
6821 | return 450000; | |
6822 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6823 | return 540000; | |
6824 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6825 | return 337500; | |
6826 | else | |
6827 | return 675000; | |
6828 | } | |
6829 | ||
6830 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6831 | { | |
6832 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6833 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6834 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6835 | ||
6836 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6837 | return 800000; | |
6838 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6839 | return 450000; | |
6840 | else if (freq == LCPLL_CLK_FREQ_450) | |
6841 | return 450000; | |
6842 | else if (IS_HSW_ULT(dev)) | |
6843 | return 337500; | |
6844 | else | |
6845 | return 540000; | |
79e53945 JB |
6846 | } |
6847 | ||
25eb05fc JB |
6848 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6849 | { | |
bfa7df01 VS |
6850 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6851 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6852 | } |
6853 | ||
b37a6434 VS |
6854 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6855 | { | |
6856 | return 450000; | |
6857 | } | |
6858 | ||
e70236a8 JB |
6859 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6860 | { | |
6861 | return 400000; | |
6862 | } | |
79e53945 | 6863 | |
e70236a8 | 6864 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6865 | { |
e907f170 | 6866 | return 333333; |
e70236a8 | 6867 | } |
79e53945 | 6868 | |
e70236a8 JB |
6869 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6870 | { | |
6871 | return 200000; | |
6872 | } | |
79e53945 | 6873 | |
257a7ffc DV |
6874 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6875 | { | |
6876 | u16 gcfgc = 0; | |
6877 | ||
6878 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6879 | ||
6880 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6881 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6882 | return 266667; |
257a7ffc | 6883 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6884 | return 333333; |
257a7ffc | 6885 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6886 | return 444444; |
257a7ffc DV |
6887 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6888 | return 200000; | |
6889 | default: | |
6890 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6891 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6892 | return 133333; |
257a7ffc | 6893 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6894 | return 166667; |
257a7ffc DV |
6895 | } |
6896 | } | |
6897 | ||
e70236a8 JB |
6898 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6899 | { | |
6900 | u16 gcfgc = 0; | |
79e53945 | 6901 | |
e70236a8 JB |
6902 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6903 | ||
6904 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6905 | return 133333; |
e70236a8 JB |
6906 | else { |
6907 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6908 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6909 | return 333333; |
e70236a8 JB |
6910 | default: |
6911 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6912 | return 190000; | |
79e53945 | 6913 | } |
e70236a8 JB |
6914 | } |
6915 | } | |
6916 | ||
6917 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6918 | { | |
e907f170 | 6919 | return 266667; |
e70236a8 JB |
6920 | } |
6921 | ||
1b1d2716 | 6922 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6923 | { |
6924 | u16 hpllcc = 0; | |
1b1d2716 | 6925 | |
65cd2b3f VS |
6926 | /* |
6927 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6928 | * encoding is different :( | |
6929 | * FIXME is this the right way to detect 852GM/852GMV? | |
6930 | */ | |
6931 | if (dev->pdev->revision == 0x1) | |
6932 | return 133333; | |
6933 | ||
1b1d2716 VS |
6934 | pci_bus_read_config_word(dev->pdev->bus, |
6935 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6936 | ||
e70236a8 JB |
6937 | /* Assume that the hardware is in the high speed state. This |
6938 | * should be the default. | |
6939 | */ | |
6940 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6941 | case GC_CLOCK_133_200: | |
1b1d2716 | 6942 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6943 | case GC_CLOCK_100_200: |
6944 | return 200000; | |
6945 | case GC_CLOCK_166_250: | |
6946 | return 250000; | |
6947 | case GC_CLOCK_100_133: | |
e907f170 | 6948 | return 133333; |
1b1d2716 VS |
6949 | case GC_CLOCK_133_266: |
6950 | case GC_CLOCK_133_266_2: | |
6951 | case GC_CLOCK_166_266: | |
6952 | return 266667; | |
e70236a8 | 6953 | } |
79e53945 | 6954 | |
e70236a8 JB |
6955 | /* Shouldn't happen */ |
6956 | return 0; | |
6957 | } | |
79e53945 | 6958 | |
e70236a8 JB |
6959 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6960 | { | |
e907f170 | 6961 | return 133333; |
79e53945 JB |
6962 | } |
6963 | ||
34edce2f VS |
6964 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6965 | { | |
6966 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6967 | static const unsigned int blb_vco[8] = { | |
6968 | [0] = 3200000, | |
6969 | [1] = 4000000, | |
6970 | [2] = 5333333, | |
6971 | [3] = 4800000, | |
6972 | [4] = 6400000, | |
6973 | }; | |
6974 | static const unsigned int pnv_vco[8] = { | |
6975 | [0] = 3200000, | |
6976 | [1] = 4000000, | |
6977 | [2] = 5333333, | |
6978 | [3] = 4800000, | |
6979 | [4] = 2666667, | |
6980 | }; | |
6981 | static const unsigned int cl_vco[8] = { | |
6982 | [0] = 3200000, | |
6983 | [1] = 4000000, | |
6984 | [2] = 5333333, | |
6985 | [3] = 6400000, | |
6986 | [4] = 3333333, | |
6987 | [5] = 3566667, | |
6988 | [6] = 4266667, | |
6989 | }; | |
6990 | static const unsigned int elk_vco[8] = { | |
6991 | [0] = 3200000, | |
6992 | [1] = 4000000, | |
6993 | [2] = 5333333, | |
6994 | [3] = 4800000, | |
6995 | }; | |
6996 | static const unsigned int ctg_vco[8] = { | |
6997 | [0] = 3200000, | |
6998 | [1] = 4000000, | |
6999 | [2] = 5333333, | |
7000 | [3] = 6400000, | |
7001 | [4] = 2666667, | |
7002 | [5] = 4266667, | |
7003 | }; | |
7004 | const unsigned int *vco_table; | |
7005 | unsigned int vco; | |
7006 | uint8_t tmp = 0; | |
7007 | ||
7008 | /* FIXME other chipsets? */ | |
7009 | if (IS_GM45(dev)) | |
7010 | vco_table = ctg_vco; | |
7011 | else if (IS_G4X(dev)) | |
7012 | vco_table = elk_vco; | |
7013 | else if (IS_CRESTLINE(dev)) | |
7014 | vco_table = cl_vco; | |
7015 | else if (IS_PINEVIEW(dev)) | |
7016 | vco_table = pnv_vco; | |
7017 | else if (IS_G33(dev)) | |
7018 | vco_table = blb_vco; | |
7019 | else | |
7020 | return 0; | |
7021 | ||
7022 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
7023 | ||
7024 | vco = vco_table[tmp & 0x7]; | |
7025 | if (vco == 0) | |
7026 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
7027 | else | |
7028 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
7029 | ||
7030 | return vco; | |
7031 | } | |
7032 | ||
7033 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
7034 | { | |
7035 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7036 | uint16_t tmp = 0; | |
7037 | ||
7038 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7039 | ||
7040 | cdclk_sel = (tmp >> 12) & 0x1; | |
7041 | ||
7042 | switch (vco) { | |
7043 | case 2666667: | |
7044 | case 4000000: | |
7045 | case 5333333: | |
7046 | return cdclk_sel ? 333333 : 222222; | |
7047 | case 3200000: | |
7048 | return cdclk_sel ? 320000 : 228571; | |
7049 | default: | |
7050 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
7051 | return 222222; | |
7052 | } | |
7053 | } | |
7054 | ||
7055 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
7056 | { | |
7057 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
7058 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
7059 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
7060 | const uint8_t *div_table; | |
7061 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7062 | uint16_t tmp = 0; | |
7063 | ||
7064 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7065 | ||
7066 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
7067 | ||
7068 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7069 | goto fail; | |
7070 | ||
7071 | switch (vco) { | |
7072 | case 3200000: | |
7073 | div_table = div_3200; | |
7074 | break; | |
7075 | case 4000000: | |
7076 | div_table = div_4000; | |
7077 | break; | |
7078 | case 5333333: | |
7079 | div_table = div_5333; | |
7080 | break; | |
7081 | default: | |
7082 | goto fail; | |
7083 | } | |
7084 | ||
7085 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7086 | ||
caf4e252 | 7087 | fail: |
34edce2f VS |
7088 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
7089 | return 200000; | |
7090 | } | |
7091 | ||
7092 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
7093 | { | |
7094 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
7095 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
7096 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
7097 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
7098 | const uint8_t *div_table; | |
7099 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7100 | uint16_t tmp = 0; | |
7101 | ||
7102 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7103 | ||
7104 | cdclk_sel = (tmp >> 4) & 0x7; | |
7105 | ||
7106 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7107 | goto fail; | |
7108 | ||
7109 | switch (vco) { | |
7110 | case 3200000: | |
7111 | div_table = div_3200; | |
7112 | break; | |
7113 | case 4000000: | |
7114 | div_table = div_4000; | |
7115 | break; | |
7116 | case 4800000: | |
7117 | div_table = div_4800; | |
7118 | break; | |
7119 | case 5333333: | |
7120 | div_table = div_5333; | |
7121 | break; | |
7122 | default: | |
7123 | goto fail; | |
7124 | } | |
7125 | ||
7126 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7127 | ||
caf4e252 | 7128 | fail: |
34edce2f VS |
7129 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7130 | return 190476; | |
7131 | } | |
7132 | ||
2c07245f | 7133 | static void |
a65851af | 7134 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7135 | { |
a65851af VS |
7136 | while (*num > DATA_LINK_M_N_MASK || |
7137 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7138 | *num >>= 1; |
7139 | *den >>= 1; | |
7140 | } | |
7141 | } | |
7142 | ||
a65851af VS |
7143 | static void compute_m_n(unsigned int m, unsigned int n, |
7144 | uint32_t *ret_m, uint32_t *ret_n) | |
7145 | { | |
7146 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7147 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7148 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7149 | } | |
7150 | ||
e69d0bc1 DV |
7151 | void |
7152 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7153 | int pixel_clock, int link_clock, | |
7154 | struct intel_link_m_n *m_n) | |
2c07245f | 7155 | { |
e69d0bc1 | 7156 | m_n->tu = 64; |
a65851af VS |
7157 | |
7158 | compute_m_n(bits_per_pixel * pixel_clock, | |
7159 | link_clock * nlanes * 8, | |
7160 | &m_n->gmch_m, &m_n->gmch_n); | |
7161 | ||
7162 | compute_m_n(pixel_clock, link_clock, | |
7163 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7164 | } |
7165 | ||
a7615030 CW |
7166 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7167 | { | |
d330a953 JN |
7168 | if (i915.panel_use_ssc >= 0) |
7169 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7170 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7171 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7172 | } |
7173 | ||
a93e255f ACO |
7174 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7175 | int num_connectors) | |
c65d77d8 | 7176 | { |
a93e255f | 7177 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7178 | struct drm_i915_private *dev_priv = dev->dev_private; |
7179 | int refclk; | |
7180 | ||
a93e255f ACO |
7181 | WARN_ON(!crtc_state->base.state); |
7182 | ||
5ab7b0b7 | 7183 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7184 | refclk = 100000; |
a93e255f | 7185 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7186 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7187 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7188 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7189 | } else if (!IS_GEN2(dev)) { |
7190 | refclk = 96000; | |
7191 | } else { | |
7192 | refclk = 48000; | |
7193 | } | |
7194 | ||
7195 | return refclk; | |
7196 | } | |
7197 | ||
7429e9d4 | 7198 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7199 | { |
7df00d7a | 7200 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7201 | } |
f47709a9 | 7202 | |
7429e9d4 DV |
7203 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7204 | { | |
7205 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7206 | } |
7207 | ||
f47709a9 | 7208 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7209 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7210 | intel_clock_t *reduced_clock) |
7211 | { | |
f47709a9 | 7212 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7213 | u32 fp, fp2 = 0; |
7214 | ||
7215 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7216 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7217 | if (reduced_clock) |
7429e9d4 | 7218 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7219 | } else { |
190f68c5 | 7220 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7221 | if (reduced_clock) |
7429e9d4 | 7222 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7223 | } |
7224 | ||
190f68c5 | 7225 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7226 | |
f47709a9 | 7227 | crtc->lowfreq_avail = false; |
a93e255f | 7228 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7229 | reduced_clock) { |
190f68c5 | 7230 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7231 | crtc->lowfreq_avail = true; |
a7516a05 | 7232 | } else { |
190f68c5 | 7233 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7234 | } |
7235 | } | |
7236 | ||
5e69f97f CML |
7237 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7238 | pipe) | |
89b667f8 JB |
7239 | { |
7240 | u32 reg_val; | |
7241 | ||
7242 | /* | |
7243 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7244 | * and set it to a reasonable value instead. | |
7245 | */ | |
ab3c759a | 7246 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7247 | reg_val &= 0xffffff00; |
7248 | reg_val |= 0x00000030; | |
ab3c759a | 7249 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7250 | |
ab3c759a | 7251 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7252 | reg_val &= 0x8cffffff; |
7253 | reg_val = 0x8c000000; | |
ab3c759a | 7254 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7255 | |
ab3c759a | 7256 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7257 | reg_val &= 0xffffff00; |
ab3c759a | 7258 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7259 | |
ab3c759a | 7260 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7261 | reg_val &= 0x00ffffff; |
7262 | reg_val |= 0xb0000000; | |
ab3c759a | 7263 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7264 | } |
7265 | ||
b551842d DV |
7266 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7267 | struct intel_link_m_n *m_n) | |
7268 | { | |
7269 | struct drm_device *dev = crtc->base.dev; | |
7270 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7271 | int pipe = crtc->pipe; | |
7272 | ||
e3b95f1e DV |
7273 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7274 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7275 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7276 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7277 | } |
7278 | ||
7279 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7280 | struct intel_link_m_n *m_n, |
7281 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7282 | { |
7283 | struct drm_device *dev = crtc->base.dev; | |
7284 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7285 | int pipe = crtc->pipe; | |
6e3c9717 | 7286 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7287 | |
7288 | if (INTEL_INFO(dev)->gen >= 5) { | |
7289 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7290 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7291 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7292 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7293 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7294 | * for gen < 8) and if DRRS is supported (to make sure the | |
7295 | * registers are not unnecessarily accessed). | |
7296 | */ | |
44395bfe | 7297 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7298 | crtc->config->has_drrs) { |
f769cd24 VK |
7299 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7300 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7301 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7302 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7303 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7304 | } | |
b551842d | 7305 | } else { |
e3b95f1e DV |
7306 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7307 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7308 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7309 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7310 | } |
7311 | } | |
7312 | ||
fe3cd48d | 7313 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7314 | { |
fe3cd48d R |
7315 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7316 | ||
7317 | if (m_n == M1_N1) { | |
7318 | dp_m_n = &crtc->config->dp_m_n; | |
7319 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7320 | } else if (m_n == M2_N2) { | |
7321 | ||
7322 | /* | |
7323 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7324 | * needs to be programmed into M1_N1. | |
7325 | */ | |
7326 | dp_m_n = &crtc->config->dp_m2_n2; | |
7327 | } else { | |
7328 | DRM_ERROR("Unsupported divider value\n"); | |
7329 | return; | |
7330 | } | |
7331 | ||
6e3c9717 ACO |
7332 | if (crtc->config->has_pch_encoder) |
7333 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7334 | else |
fe3cd48d | 7335 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7336 | } |
7337 | ||
251ac862 DV |
7338 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7339 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7340 | { |
7341 | u32 dpll, dpll_md; | |
7342 | ||
7343 | /* | |
7344 | * Enable DPIO clock input. We should never disable the reference | |
7345 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7346 | * on it. | |
7347 | */ | |
60bfe44f VS |
7348 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7349 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7350 | /* We should never disable this, set it here for state tracking */ |
7351 | if (crtc->pipe == PIPE_B) | |
7352 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7353 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7354 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7355 | |
d288f65f | 7356 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7357 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7358 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7359 | } |
7360 | ||
d288f65f | 7361 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7362 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7363 | { |
f47709a9 | 7364 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7365 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7366 | int pipe = crtc->pipe; |
bdd4b6a6 | 7367 | u32 mdiv; |
a0c4da24 | 7368 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7369 | u32 coreclk, reg_val; |
a0c4da24 | 7370 | |
a580516d | 7371 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7372 | |
d288f65f VS |
7373 | bestn = pipe_config->dpll.n; |
7374 | bestm1 = pipe_config->dpll.m1; | |
7375 | bestm2 = pipe_config->dpll.m2; | |
7376 | bestp1 = pipe_config->dpll.p1; | |
7377 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7378 | |
89b667f8 JB |
7379 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7380 | ||
7381 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7382 | if (pipe == PIPE_B) |
5e69f97f | 7383 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7384 | |
7385 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7386 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7387 | |
7388 | /* Disable target IRef on PLL */ | |
ab3c759a | 7389 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7390 | reg_val &= 0x00ffffff; |
ab3c759a | 7391 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7392 | |
7393 | /* Disable fast lock */ | |
ab3c759a | 7394 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7395 | |
7396 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7397 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7398 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7399 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7400 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7401 | |
7402 | /* | |
7403 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7404 | * but we don't support that). | |
7405 | * Note: don't use the DAC post divider as it seems unstable. | |
7406 | */ | |
7407 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7408 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7409 | |
a0c4da24 | 7410 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7411 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7412 | |
89b667f8 | 7413 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7414 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7415 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7416 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7417 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7418 | 0x009f0003); |
89b667f8 | 7419 | else |
ab3c759a | 7420 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7421 | 0x00d0000f); |
7422 | ||
681a8504 | 7423 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7424 | /* Use SSC source */ |
bdd4b6a6 | 7425 | if (pipe == PIPE_A) |
ab3c759a | 7426 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7427 | 0x0df40000); |
7428 | else | |
ab3c759a | 7429 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7430 | 0x0df70000); |
7431 | } else { /* HDMI or VGA */ | |
7432 | /* Use bend source */ | |
bdd4b6a6 | 7433 | if (pipe == PIPE_A) |
ab3c759a | 7434 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7435 | 0x0df70000); |
7436 | else | |
ab3c759a | 7437 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7438 | 0x0df40000); |
7439 | } | |
a0c4da24 | 7440 | |
ab3c759a | 7441 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7442 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7443 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7444 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7445 | coreclk |= 0x01000000; |
ab3c759a | 7446 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7447 | |
ab3c759a | 7448 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7449 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7450 | } |
7451 | ||
251ac862 DV |
7452 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7453 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7454 | { |
60bfe44f VS |
7455 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7456 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7457 | DPLL_VCO_ENABLE; |
7458 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7459 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7460 | |
d288f65f VS |
7461 | pipe_config->dpll_hw_state.dpll_md = |
7462 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7463 | } |
7464 | ||
d288f65f | 7465 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7466 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7467 | { |
7468 | struct drm_device *dev = crtc->base.dev; | |
7469 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7470 | int pipe = crtc->pipe; | |
f0f59a00 | 7471 | i915_reg_t dpll_reg = DPLL(crtc->pipe); |
9d556c99 | 7472 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9cbe40c1 | 7473 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7474 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7475 | u32 dpio_val; |
9cbe40c1 | 7476 | int vco; |
9d556c99 | 7477 | |
d288f65f VS |
7478 | bestn = pipe_config->dpll.n; |
7479 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7480 | bestm1 = pipe_config->dpll.m1; | |
7481 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7482 | bestp1 = pipe_config->dpll.p1; | |
7483 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7484 | vco = pipe_config->dpll.vco; |
a945ce7e | 7485 | dpio_val = 0; |
9cbe40c1 | 7486 | loopfilter = 0; |
9d556c99 CML |
7487 | |
7488 | /* | |
7489 | * Enable Refclk and SSC | |
7490 | */ | |
a11b0703 | 7491 | I915_WRITE(dpll_reg, |
d288f65f | 7492 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7493 | |
a580516d | 7494 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7495 | |
9d556c99 CML |
7496 | /* p1 and p2 divider */ |
7497 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7498 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7499 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7500 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7501 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7502 | ||
7503 | /* Feedback post-divider - m2 */ | |
7504 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7505 | ||
7506 | /* Feedback refclk divider - n and m1 */ | |
7507 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7508 | DPIO_CHV_M1_DIV_BY_2 | | |
7509 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7510 | ||
7511 | /* M2 fraction division */ | |
25a25dfc | 7512 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7513 | |
7514 | /* M2 fraction division enable */ | |
a945ce7e VP |
7515 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7516 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7517 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7518 | if (bestm2_frac) | |
7519 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7520 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7521 | |
de3a0fde VP |
7522 | /* Program digital lock detect threshold */ |
7523 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7524 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7525 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7526 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7527 | if (!bestm2_frac) | |
7528 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7529 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7530 | ||
9d556c99 | 7531 | /* Loop filter */ |
9cbe40c1 VP |
7532 | if (vco == 5400000) { |
7533 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7534 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7535 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7536 | tribuf_calcntr = 0x9; | |
7537 | } else if (vco <= 6200000) { | |
7538 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7539 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7540 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7541 | tribuf_calcntr = 0x9; | |
7542 | } else if (vco <= 6480000) { | |
7543 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7544 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7545 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7546 | tribuf_calcntr = 0x8; | |
7547 | } else { | |
7548 | /* Not supported. Apply the same limits as in the max case */ | |
7549 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7550 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7551 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7552 | tribuf_calcntr = 0; | |
7553 | } | |
9d556c99 CML |
7554 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7555 | ||
968040b2 | 7556 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7557 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7558 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7559 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7560 | ||
9d556c99 CML |
7561 | /* AFC Recal */ |
7562 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7563 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7564 | DPIO_AFC_RECAL); | |
7565 | ||
a580516d | 7566 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7567 | } |
7568 | ||
d288f65f VS |
7569 | /** |
7570 | * vlv_force_pll_on - forcibly enable just the PLL | |
7571 | * @dev_priv: i915 private structure | |
7572 | * @pipe: pipe PLL to enable | |
7573 | * @dpll: PLL configuration | |
7574 | * | |
7575 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7576 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7577 | * be enabled. | |
7578 | */ | |
7579 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7580 | const struct dpll *dpll) | |
7581 | { | |
7582 | struct intel_crtc *crtc = | |
7583 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7584 | struct intel_crtc_state pipe_config = { |
a93e255f | 7585 | .base.crtc = &crtc->base, |
d288f65f VS |
7586 | .pixel_multiplier = 1, |
7587 | .dpll = *dpll, | |
7588 | }; | |
7589 | ||
7590 | if (IS_CHERRYVIEW(dev)) { | |
251ac862 | 7591 | chv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7592 | chv_prepare_pll(crtc, &pipe_config); |
7593 | chv_enable_pll(crtc, &pipe_config); | |
7594 | } else { | |
251ac862 | 7595 | vlv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7596 | vlv_prepare_pll(crtc, &pipe_config); |
7597 | vlv_enable_pll(crtc, &pipe_config); | |
7598 | } | |
7599 | } | |
7600 | ||
7601 | /** | |
7602 | * vlv_force_pll_off - forcibly disable just the PLL | |
7603 | * @dev_priv: i915 private structure | |
7604 | * @pipe: pipe PLL to disable | |
7605 | * | |
7606 | * Disable the PLL for @pipe. To be used in cases where we need | |
7607 | * the PLL enabled even when @pipe is not going to be enabled. | |
7608 | */ | |
7609 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7610 | { | |
7611 | if (IS_CHERRYVIEW(dev)) | |
7612 | chv_disable_pll(to_i915(dev), pipe); | |
7613 | else | |
7614 | vlv_disable_pll(to_i915(dev), pipe); | |
7615 | } | |
7616 | ||
251ac862 DV |
7617 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7618 | struct intel_crtc_state *crtc_state, | |
7619 | intel_clock_t *reduced_clock, | |
7620 | int num_connectors) | |
eb1cbe48 | 7621 | { |
f47709a9 | 7622 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7623 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7624 | u32 dpll; |
7625 | bool is_sdvo; | |
190f68c5 | 7626 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7627 | |
190f68c5 | 7628 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7629 | |
a93e255f ACO |
7630 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7631 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7632 | |
7633 | dpll = DPLL_VGA_MODE_DIS; | |
7634 | ||
a93e255f | 7635 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7636 | dpll |= DPLLB_MODE_LVDS; |
7637 | else | |
7638 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7639 | |
ef1b460d | 7640 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7641 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7642 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7643 | } |
198a037f DV |
7644 | |
7645 | if (is_sdvo) | |
4a33e48d | 7646 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7647 | |
190f68c5 | 7648 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7649 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7650 | |
7651 | /* compute bitmask from p1 value */ | |
7652 | if (IS_PINEVIEW(dev)) | |
7653 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7654 | else { | |
7655 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7656 | if (IS_G4X(dev) && reduced_clock) | |
7657 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7658 | } | |
7659 | switch (clock->p2) { | |
7660 | case 5: | |
7661 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7662 | break; | |
7663 | case 7: | |
7664 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7665 | break; | |
7666 | case 10: | |
7667 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7668 | break; | |
7669 | case 14: | |
7670 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7671 | break; | |
7672 | } | |
7673 | if (INTEL_INFO(dev)->gen >= 4) | |
7674 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7675 | ||
190f68c5 | 7676 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7677 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7678 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7679 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7680 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7681 | else | |
7682 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7683 | ||
7684 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7685 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7686 | |
eb1cbe48 | 7687 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7688 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7689 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7690 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7691 | } |
7692 | } | |
7693 | ||
251ac862 DV |
7694 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7695 | struct intel_crtc_state *crtc_state, | |
7696 | intel_clock_t *reduced_clock, | |
7697 | int num_connectors) | |
eb1cbe48 | 7698 | { |
f47709a9 | 7699 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7700 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7701 | u32 dpll; |
190f68c5 | 7702 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7703 | |
190f68c5 | 7704 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7705 | |
eb1cbe48 DV |
7706 | dpll = DPLL_VGA_MODE_DIS; |
7707 | ||
a93e255f | 7708 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7709 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7710 | } else { | |
7711 | if (clock->p1 == 2) | |
7712 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7713 | else | |
7714 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7715 | if (clock->p2 == 4) | |
7716 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7717 | } | |
7718 | ||
a93e255f | 7719 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7720 | dpll |= DPLL_DVO_2X_MODE; |
7721 | ||
a93e255f | 7722 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7723 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7724 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7725 | else | |
7726 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7727 | ||
7728 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7729 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7730 | } |
7731 | ||
8a654f3b | 7732 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7733 | { |
7734 | struct drm_device *dev = intel_crtc->base.dev; | |
7735 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7736 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7737 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7738 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7739 | uint32_t crtc_vtotal, crtc_vblank_end; |
7740 | int vsyncshift = 0; | |
4d8a62ea DV |
7741 | |
7742 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7743 | * the hw state checker will get angry at the mismatch. */ | |
7744 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7745 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7746 | |
609aeaca | 7747 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7748 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7749 | crtc_vtotal -= 1; |
7750 | crtc_vblank_end -= 1; | |
609aeaca | 7751 | |
409ee761 | 7752 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7753 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7754 | else | |
7755 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7756 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7757 | if (vsyncshift < 0) |
7758 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7759 | } |
7760 | ||
7761 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7762 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7763 | |
fe2b8f9d | 7764 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7765 | (adjusted_mode->crtc_hdisplay - 1) | |
7766 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7767 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7768 | (adjusted_mode->crtc_hblank_start - 1) | |
7769 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7770 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7771 | (adjusted_mode->crtc_hsync_start - 1) | |
7772 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7773 | ||
fe2b8f9d | 7774 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7775 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7776 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7777 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7778 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7779 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7780 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7781 | (adjusted_mode->crtc_vsync_start - 1) | |
7782 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7783 | ||
b5e508d4 PZ |
7784 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7785 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7786 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7787 | * bits. */ | |
7788 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7789 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7790 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7791 | ||
b0e77b9c PZ |
7792 | /* pipesrc controls the size that is scaled from, which should |
7793 | * always be the user's requested size. | |
7794 | */ | |
7795 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7796 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7797 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7798 | } |
7799 | ||
1bd1bd80 | 7800 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7801 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7802 | { |
7803 | struct drm_device *dev = crtc->base.dev; | |
7804 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7805 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7806 | uint32_t tmp; | |
7807 | ||
7808 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7809 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7810 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7811 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7812 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7813 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7814 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7815 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7816 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7817 | |
7818 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7819 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7820 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7821 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7822 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7823 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7824 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7825 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7826 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7827 | |
7828 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7829 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7830 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7831 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7832 | } |
7833 | ||
7834 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7835 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7836 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7837 | ||
2d112de7 ACO |
7838 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7839 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7840 | } |
7841 | ||
f6a83288 | 7842 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7843 | struct intel_crtc_state *pipe_config) |
babea61d | 7844 | { |
2d112de7 ACO |
7845 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7846 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7847 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7848 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7849 | |
2d112de7 ACO |
7850 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7851 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7852 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7853 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7854 | |
2d112de7 | 7855 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7856 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7857 | |
2d112de7 ACO |
7858 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7859 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7860 | |
7861 | mode->hsync = drm_mode_hsync(mode); | |
7862 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7863 | drm_mode_set_name(mode); | |
babea61d JB |
7864 | } |
7865 | ||
84b046f3 DV |
7866 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7867 | { | |
7868 | struct drm_device *dev = intel_crtc->base.dev; | |
7869 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7870 | uint32_t pipeconf; | |
7871 | ||
9f11a9e4 | 7872 | pipeconf = 0; |
84b046f3 | 7873 | |
b6b5d049 VS |
7874 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7875 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7876 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7877 | |
6e3c9717 | 7878 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7879 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7880 | |
ff9ce46e DV |
7881 | /* only g4x and later have fancy bpc/dither controls */ |
7882 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7883 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7884 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7885 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7886 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7887 | |
6e3c9717 | 7888 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7889 | case 18: |
7890 | pipeconf |= PIPECONF_6BPC; | |
7891 | break; | |
7892 | case 24: | |
7893 | pipeconf |= PIPECONF_8BPC; | |
7894 | break; | |
7895 | case 30: | |
7896 | pipeconf |= PIPECONF_10BPC; | |
7897 | break; | |
7898 | default: | |
7899 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7900 | BUG(); | |
84b046f3 DV |
7901 | } |
7902 | } | |
7903 | ||
7904 | if (HAS_PIPE_CXSR(dev)) { | |
7905 | if (intel_crtc->lowfreq_avail) { | |
7906 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7907 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7908 | } else { | |
7909 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7910 | } |
7911 | } | |
7912 | ||
6e3c9717 | 7913 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7914 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7915 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7916 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7917 | else | |
7918 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7919 | } else | |
84b046f3 DV |
7920 | pipeconf |= PIPECONF_PROGRESSIVE; |
7921 | ||
6e3c9717 | 7922 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7923 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7924 | |
84b046f3 DV |
7925 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7926 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7927 | } | |
7928 | ||
190f68c5 ACO |
7929 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7930 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7931 | { |
c7653199 | 7932 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7933 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7934 | int refclk, num_connectors = 0; |
c329a4ec DV |
7935 | intel_clock_t clock; |
7936 | bool ok; | |
d4906093 | 7937 | const intel_limit_t *limit; |
55bb9992 | 7938 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7939 | struct drm_connector *connector; |
55bb9992 ACO |
7940 | struct drm_connector_state *connector_state; |
7941 | int i; | |
79e53945 | 7942 | |
dd3cd74a ACO |
7943 | memset(&crtc_state->dpll_hw_state, 0, |
7944 | sizeof(crtc_state->dpll_hw_state)); | |
7945 | ||
a65347ba JN |
7946 | if (crtc_state->has_dsi_encoder) |
7947 | return 0; | |
43565a06 | 7948 | |
a65347ba JN |
7949 | for_each_connector_in_state(state, connector, connector_state, i) { |
7950 | if (connector_state->crtc == &crtc->base) | |
7951 | num_connectors++; | |
79e53945 JB |
7952 | } |
7953 | ||
190f68c5 | 7954 | if (!crtc_state->clock_set) { |
a93e255f | 7955 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7956 | |
e9fd1c02 JN |
7957 | /* |
7958 | * Returns a set of divisors for the desired target clock with | |
7959 | * the given refclk, or FALSE. The returned values represent | |
7960 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7961 | * 2) / p1 / p2. | |
7962 | */ | |
a93e255f ACO |
7963 | limit = intel_limit(crtc_state, refclk); |
7964 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7965 | crtc_state->port_clock, |
e9fd1c02 | 7966 | refclk, NULL, &clock); |
f2335330 | 7967 | if (!ok) { |
e9fd1c02 JN |
7968 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7969 | return -EINVAL; | |
7970 | } | |
79e53945 | 7971 | |
f2335330 | 7972 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
7973 | crtc_state->dpll.n = clock.n; |
7974 | crtc_state->dpll.m1 = clock.m1; | |
7975 | crtc_state->dpll.m2 = clock.m2; | |
7976 | crtc_state->dpll.p1 = clock.p1; | |
7977 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7978 | } |
7026d4ac | 7979 | |
e9fd1c02 | 7980 | if (IS_GEN2(dev)) { |
c329a4ec | 7981 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7982 | num_connectors); |
9d556c99 | 7983 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 7984 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7985 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 7986 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7987 | } else { |
c329a4ec | 7988 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7989 | num_connectors); |
e9fd1c02 | 7990 | } |
79e53945 | 7991 | |
c8f7a0db | 7992 | return 0; |
f564048e EA |
7993 | } |
7994 | ||
2fa2fe9a | 7995 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7996 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7997 | { |
7998 | struct drm_device *dev = crtc->base.dev; | |
7999 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8000 | uint32_t tmp; | |
8001 | ||
dc9e7dec VS |
8002 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
8003 | return; | |
8004 | ||
2fa2fe9a | 8005 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
8006 | if (!(tmp & PFIT_ENABLE)) |
8007 | return; | |
2fa2fe9a | 8008 | |
06922821 | 8009 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
8010 | if (INTEL_INFO(dev)->gen < 4) { |
8011 | if (crtc->pipe != PIPE_B) | |
8012 | return; | |
2fa2fe9a DV |
8013 | } else { |
8014 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
8015 | return; | |
8016 | } | |
8017 | ||
06922821 | 8018 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
8019 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
8020 | if (INTEL_INFO(dev)->gen < 5) | |
8021 | pipe_config->gmch_pfit.lvds_border_bits = | |
8022 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
8023 | } | |
8024 | ||
acbec814 | 8025 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8026 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
8027 | { |
8028 | struct drm_device *dev = crtc->base.dev; | |
8029 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8030 | int pipe = pipe_config->cpu_transcoder; | |
8031 | intel_clock_t clock; | |
8032 | u32 mdiv; | |
662c6ecb | 8033 | int refclk = 100000; |
acbec814 | 8034 | |
f573de5a SK |
8035 | /* In case of MIPI DPLL will not even be used */ |
8036 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
8037 | return; | |
8038 | ||
a580516d | 8039 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 8040 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 8041 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
8042 | |
8043 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
8044 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
8045 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
8046 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
8047 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
8048 | ||
dccbea3b | 8049 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
8050 | } |
8051 | ||
5724dbd1 DL |
8052 | static void |
8053 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
8054 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
8055 | { |
8056 | struct drm_device *dev = crtc->base.dev; | |
8057 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8058 | u32 val, base, offset; | |
8059 | int pipe = crtc->pipe, plane = crtc->plane; | |
8060 | int fourcc, pixel_format; | |
6761dd31 | 8061 | unsigned int aligned_height; |
b113d5ee | 8062 | struct drm_framebuffer *fb; |
1b842c89 | 8063 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 8064 | |
42a7b088 DL |
8065 | val = I915_READ(DSPCNTR(plane)); |
8066 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8067 | return; | |
8068 | ||
d9806c9f | 8069 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8070 | if (!intel_fb) { |
1ad292b5 JB |
8071 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8072 | return; | |
8073 | } | |
8074 | ||
1b842c89 DL |
8075 | fb = &intel_fb->base; |
8076 | ||
18c5247e DV |
8077 | if (INTEL_INFO(dev)->gen >= 4) { |
8078 | if (val & DISPPLANE_TILED) { | |
49af449b | 8079 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8080 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8081 | } | |
8082 | } | |
1ad292b5 JB |
8083 | |
8084 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8085 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8086 | fb->pixel_format = fourcc; |
8087 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
8088 | |
8089 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 8090 | if (plane_config->tiling) |
1ad292b5 JB |
8091 | offset = I915_READ(DSPTILEOFF(plane)); |
8092 | else | |
8093 | offset = I915_READ(DSPLINOFF(plane)); | |
8094 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8095 | } else { | |
8096 | base = I915_READ(DSPADDR(plane)); | |
8097 | } | |
8098 | plane_config->base = base; | |
8099 | ||
8100 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8101 | fb->width = ((val >> 16) & 0xfff) + 1; |
8102 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8103 | |
8104 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8105 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8106 | |
b113d5ee | 8107 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8108 | fb->pixel_format, |
8109 | fb->modifier[0]); | |
1ad292b5 | 8110 | |
f37b5c2b | 8111 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8112 | |
2844a921 DL |
8113 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8114 | pipe_name(pipe), plane, fb->width, fb->height, | |
8115 | fb->bits_per_pixel, base, fb->pitches[0], | |
8116 | plane_config->size); | |
1ad292b5 | 8117 | |
2d14030b | 8118 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8119 | } |
8120 | ||
70b23a98 | 8121 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8122 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8123 | { |
8124 | struct drm_device *dev = crtc->base.dev; | |
8125 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8126 | int pipe = pipe_config->cpu_transcoder; | |
8127 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8128 | intel_clock_t clock; | |
0d7b6b11 | 8129 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8130 | int refclk = 100000; |
8131 | ||
a580516d | 8132 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8133 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8134 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8135 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8136 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8137 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8138 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8139 | |
8140 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8141 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8142 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8143 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8144 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8145 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8146 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8147 | ||
dccbea3b | 8148 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8149 | } |
8150 | ||
0e8ffe1b | 8151 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8152 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8153 | { |
8154 | struct drm_device *dev = crtc->base.dev; | |
8155 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8156 | uint32_t tmp; | |
8157 | ||
f458ebbc DV |
8158 | if (!intel_display_power_is_enabled(dev_priv, |
8159 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8160 | return false; |
8161 | ||
e143a21c | 8162 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8163 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8164 | |
0e8ffe1b DV |
8165 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8166 | if (!(tmp & PIPECONF_ENABLE)) | |
8167 | return false; | |
8168 | ||
42571aef VS |
8169 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8170 | switch (tmp & PIPECONF_BPC_MASK) { | |
8171 | case PIPECONF_6BPC: | |
8172 | pipe_config->pipe_bpp = 18; | |
8173 | break; | |
8174 | case PIPECONF_8BPC: | |
8175 | pipe_config->pipe_bpp = 24; | |
8176 | break; | |
8177 | case PIPECONF_10BPC: | |
8178 | pipe_config->pipe_bpp = 30; | |
8179 | break; | |
8180 | default: | |
8181 | break; | |
8182 | } | |
8183 | } | |
8184 | ||
b5a9fa09 DV |
8185 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8186 | pipe_config->limited_color_range = true; | |
8187 | ||
282740f7 VS |
8188 | if (INTEL_INFO(dev)->gen < 4) |
8189 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8190 | ||
1bd1bd80 DV |
8191 | intel_get_pipe_timings(crtc, pipe_config); |
8192 | ||
2fa2fe9a DV |
8193 | i9xx_get_pfit_config(crtc, pipe_config); |
8194 | ||
6c49f241 DV |
8195 | if (INTEL_INFO(dev)->gen >= 4) { |
8196 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8197 | pipe_config->pixel_multiplier = | |
8198 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8199 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8200 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8201 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8202 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8203 | pipe_config->pixel_multiplier = | |
8204 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8205 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8206 | } else { | |
8207 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8208 | * port and will be fixed up in the encoder->get_config | |
8209 | * function. */ | |
8210 | pipe_config->pixel_multiplier = 1; | |
8211 | } | |
8bcc2795 DV |
8212 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8213 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8214 | /* |
8215 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8216 | * on 830. Filter it out here so that we don't | |
8217 | * report errors due to that. | |
8218 | */ | |
8219 | if (IS_I830(dev)) | |
8220 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8221 | ||
8bcc2795 DV |
8222 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8223 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8224 | } else { |
8225 | /* Mask out read-only status bits. */ | |
8226 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8227 | DPLL_PORTC_READY_MASK | | |
8228 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8229 | } |
6c49f241 | 8230 | |
70b23a98 VS |
8231 | if (IS_CHERRYVIEW(dev)) |
8232 | chv_crtc_clock_get(crtc, pipe_config); | |
8233 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8234 | vlv_crtc_clock_get(crtc, pipe_config); |
8235 | else | |
8236 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8237 | |
0f64614d VS |
8238 | /* |
8239 | * Normally the dotclock is filled in by the encoder .get_config() | |
8240 | * but in case the pipe is enabled w/o any ports we need a sane | |
8241 | * default. | |
8242 | */ | |
8243 | pipe_config->base.adjusted_mode.crtc_clock = | |
8244 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8245 | ||
0e8ffe1b DV |
8246 | return true; |
8247 | } | |
8248 | ||
dde86e2d | 8249 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8250 | { |
8251 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8252 | struct intel_encoder *encoder; |
74cfd7ac | 8253 | u32 val, final; |
13d83a67 | 8254 | bool has_lvds = false; |
199e5d79 | 8255 | bool has_cpu_edp = false; |
199e5d79 | 8256 | bool has_panel = false; |
99eb6a01 KP |
8257 | bool has_ck505 = false; |
8258 | bool can_ssc = false; | |
13d83a67 JB |
8259 | |
8260 | /* We need to take the global config into account */ | |
b2784e15 | 8261 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8262 | switch (encoder->type) { |
8263 | case INTEL_OUTPUT_LVDS: | |
8264 | has_panel = true; | |
8265 | has_lvds = true; | |
8266 | break; | |
8267 | case INTEL_OUTPUT_EDP: | |
8268 | has_panel = true; | |
2de6905f | 8269 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8270 | has_cpu_edp = true; |
8271 | break; | |
6847d71b PZ |
8272 | default: |
8273 | break; | |
13d83a67 JB |
8274 | } |
8275 | } | |
8276 | ||
99eb6a01 | 8277 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8278 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8279 | can_ssc = has_ck505; |
8280 | } else { | |
8281 | has_ck505 = false; | |
8282 | can_ssc = true; | |
8283 | } | |
8284 | ||
2de6905f ID |
8285 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8286 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8287 | |
8288 | /* Ironlake: try to setup display ref clock before DPLL | |
8289 | * enabling. This is only under driver's control after | |
8290 | * PCH B stepping, previous chipset stepping should be | |
8291 | * ignoring this setting. | |
8292 | */ | |
74cfd7ac CW |
8293 | val = I915_READ(PCH_DREF_CONTROL); |
8294 | ||
8295 | /* As we must carefully and slowly disable/enable each source in turn, | |
8296 | * compute the final state we want first and check if we need to | |
8297 | * make any changes at all. | |
8298 | */ | |
8299 | final = val; | |
8300 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8301 | if (has_ck505) | |
8302 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8303 | else | |
8304 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8305 | ||
8306 | final &= ~DREF_SSC_SOURCE_MASK; | |
8307 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8308 | final &= ~DREF_SSC1_ENABLE; | |
8309 | ||
8310 | if (has_panel) { | |
8311 | final |= DREF_SSC_SOURCE_ENABLE; | |
8312 | ||
8313 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8314 | final |= DREF_SSC1_ENABLE; | |
8315 | ||
8316 | if (has_cpu_edp) { | |
8317 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8318 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8319 | else | |
8320 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8321 | } else | |
8322 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8323 | } else { | |
8324 | final |= DREF_SSC_SOURCE_DISABLE; | |
8325 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8326 | } | |
8327 | ||
8328 | if (final == val) | |
8329 | return; | |
8330 | ||
13d83a67 | 8331 | /* Always enable nonspread source */ |
74cfd7ac | 8332 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8333 | |
99eb6a01 | 8334 | if (has_ck505) |
74cfd7ac | 8335 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8336 | else |
74cfd7ac | 8337 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8338 | |
199e5d79 | 8339 | if (has_panel) { |
74cfd7ac CW |
8340 | val &= ~DREF_SSC_SOURCE_MASK; |
8341 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8342 | |
199e5d79 | 8343 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8344 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8345 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8346 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8347 | } else |
74cfd7ac | 8348 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8349 | |
8350 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8351 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8352 | POSTING_READ(PCH_DREF_CONTROL); |
8353 | udelay(200); | |
8354 | ||
74cfd7ac | 8355 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8356 | |
8357 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8358 | if (has_cpu_edp) { |
99eb6a01 | 8359 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8360 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8361 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8362 | } else |
74cfd7ac | 8363 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8364 | } else |
74cfd7ac | 8365 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8366 | |
74cfd7ac | 8367 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8368 | POSTING_READ(PCH_DREF_CONTROL); |
8369 | udelay(200); | |
8370 | } else { | |
8371 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8372 | ||
74cfd7ac | 8373 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8374 | |
8375 | /* Turn off CPU output */ | |
74cfd7ac | 8376 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8377 | |
74cfd7ac | 8378 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8379 | POSTING_READ(PCH_DREF_CONTROL); |
8380 | udelay(200); | |
8381 | ||
8382 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8383 | val &= ~DREF_SSC_SOURCE_MASK; |
8384 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8385 | |
8386 | /* Turn off SSC1 */ | |
74cfd7ac | 8387 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8388 | |
74cfd7ac | 8389 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8390 | POSTING_READ(PCH_DREF_CONTROL); |
8391 | udelay(200); | |
8392 | } | |
74cfd7ac CW |
8393 | |
8394 | BUG_ON(val != final); | |
13d83a67 JB |
8395 | } |
8396 | ||
f31f2d55 | 8397 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8398 | { |
f31f2d55 | 8399 | uint32_t tmp; |
dde86e2d | 8400 | |
0ff066a9 PZ |
8401 | tmp = I915_READ(SOUTH_CHICKEN2); |
8402 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8403 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8404 | |
0ff066a9 PZ |
8405 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8406 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8407 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8408 | |
0ff066a9 PZ |
8409 | tmp = I915_READ(SOUTH_CHICKEN2); |
8410 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8411 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8412 | |
0ff066a9 PZ |
8413 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8414 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8415 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8416 | } |
8417 | ||
8418 | /* WaMPhyProgramming:hsw */ | |
8419 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8420 | { | |
8421 | uint32_t tmp; | |
dde86e2d PZ |
8422 | |
8423 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8424 | tmp &= ~(0xFF << 24); | |
8425 | tmp |= (0x12 << 24); | |
8426 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8427 | ||
dde86e2d PZ |
8428 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8429 | tmp |= (1 << 11); | |
8430 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8431 | ||
8432 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8433 | tmp |= (1 << 11); | |
8434 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8435 | ||
dde86e2d PZ |
8436 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8437 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8438 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8439 | ||
8440 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8441 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8442 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8443 | ||
0ff066a9 PZ |
8444 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8445 | tmp &= ~(7 << 13); | |
8446 | tmp |= (5 << 13); | |
8447 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8448 | |
0ff066a9 PZ |
8449 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8450 | tmp &= ~(7 << 13); | |
8451 | tmp |= (5 << 13); | |
8452 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8453 | |
8454 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8455 | tmp &= ~0xFF; | |
8456 | tmp |= 0x1C; | |
8457 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8458 | ||
8459 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8460 | tmp &= ~0xFF; | |
8461 | tmp |= 0x1C; | |
8462 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8463 | ||
8464 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8465 | tmp &= ~(0xFF << 16); | |
8466 | tmp |= (0x1C << 16); | |
8467 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8468 | ||
8469 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8470 | tmp &= ~(0xFF << 16); | |
8471 | tmp |= (0x1C << 16); | |
8472 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8473 | ||
0ff066a9 PZ |
8474 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8475 | tmp |= (1 << 27); | |
8476 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8477 | |
0ff066a9 PZ |
8478 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8479 | tmp |= (1 << 27); | |
8480 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8481 | |
0ff066a9 PZ |
8482 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8483 | tmp &= ~(0xF << 28); | |
8484 | tmp |= (4 << 28); | |
8485 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8486 | |
0ff066a9 PZ |
8487 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8488 | tmp &= ~(0xF << 28); | |
8489 | tmp |= (4 << 28); | |
8490 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8491 | } |
8492 | ||
2fa86a1f PZ |
8493 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8494 | * Programming" based on the parameters passed: | |
8495 | * - Sequence to enable CLKOUT_DP | |
8496 | * - Sequence to enable CLKOUT_DP without spread | |
8497 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8498 | */ | |
8499 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8500 | bool with_fdi) | |
f31f2d55 PZ |
8501 | { |
8502 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8503 | uint32_t reg, tmp; |
8504 | ||
8505 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8506 | with_spread = true; | |
c2699524 | 8507 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8508 | with_fdi = false; |
f31f2d55 | 8509 | |
a580516d | 8510 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8511 | |
8512 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8513 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8514 | tmp |= SBI_SSCCTL_PATHALT; | |
8515 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8516 | ||
8517 | udelay(24); | |
8518 | ||
2fa86a1f PZ |
8519 | if (with_spread) { |
8520 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8521 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8522 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8523 | |
2fa86a1f PZ |
8524 | if (with_fdi) { |
8525 | lpt_reset_fdi_mphy(dev_priv); | |
8526 | lpt_program_fdi_mphy(dev_priv); | |
8527 | } | |
8528 | } | |
dde86e2d | 8529 | |
c2699524 | 8530 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8531 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8532 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8533 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8534 | |
a580516d | 8535 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8536 | } |
8537 | ||
47701c3b PZ |
8538 | /* Sequence to disable CLKOUT_DP */ |
8539 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8540 | { | |
8541 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8542 | uint32_t reg, tmp; | |
8543 | ||
a580516d | 8544 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8545 | |
c2699524 | 8546 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8547 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8548 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8549 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8550 | ||
8551 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8552 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8553 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8554 | tmp |= SBI_SSCCTL_PATHALT; | |
8555 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8556 | udelay(32); | |
8557 | } | |
8558 | tmp |= SBI_SSCCTL_DISABLE; | |
8559 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8560 | } | |
8561 | ||
a580516d | 8562 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8563 | } |
8564 | ||
bf8fa3d3 PZ |
8565 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8566 | { | |
bf8fa3d3 PZ |
8567 | struct intel_encoder *encoder; |
8568 | bool has_vga = false; | |
8569 | ||
b2784e15 | 8570 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8571 | switch (encoder->type) { |
8572 | case INTEL_OUTPUT_ANALOG: | |
8573 | has_vga = true; | |
8574 | break; | |
6847d71b PZ |
8575 | default: |
8576 | break; | |
bf8fa3d3 PZ |
8577 | } |
8578 | } | |
8579 | ||
47701c3b PZ |
8580 | if (has_vga) |
8581 | lpt_enable_clkout_dp(dev, true, true); | |
8582 | else | |
8583 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8584 | } |
8585 | ||
dde86e2d PZ |
8586 | /* |
8587 | * Initialize reference clocks when the driver loads | |
8588 | */ | |
8589 | void intel_init_pch_refclk(struct drm_device *dev) | |
8590 | { | |
8591 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8592 | ironlake_init_pch_refclk(dev); | |
8593 | else if (HAS_PCH_LPT(dev)) | |
8594 | lpt_init_pch_refclk(dev); | |
8595 | } | |
8596 | ||
55bb9992 | 8597 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8598 | { |
55bb9992 | 8599 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8600 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8601 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8602 | struct drm_connector *connector; |
55bb9992 | 8603 | struct drm_connector_state *connector_state; |
d9d444cb | 8604 | struct intel_encoder *encoder; |
55bb9992 | 8605 | int num_connectors = 0, i; |
d9d444cb JB |
8606 | bool is_lvds = false; |
8607 | ||
da3ced29 | 8608 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8609 | if (connector_state->crtc != crtc_state->base.crtc) |
8610 | continue; | |
8611 | ||
8612 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8613 | ||
d9d444cb JB |
8614 | switch (encoder->type) { |
8615 | case INTEL_OUTPUT_LVDS: | |
8616 | is_lvds = true; | |
8617 | break; | |
6847d71b PZ |
8618 | default: |
8619 | break; | |
d9d444cb JB |
8620 | } |
8621 | num_connectors++; | |
8622 | } | |
8623 | ||
8624 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8625 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8626 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8627 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8628 | } |
8629 | ||
8630 | return 120000; | |
8631 | } | |
8632 | ||
6ff93609 | 8633 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8634 | { |
c8203565 | 8635 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8636 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8637 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8638 | uint32_t val; |
8639 | ||
78114071 | 8640 | val = 0; |
c8203565 | 8641 | |
6e3c9717 | 8642 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8643 | case 18: |
dfd07d72 | 8644 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8645 | break; |
8646 | case 24: | |
dfd07d72 | 8647 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8648 | break; |
8649 | case 30: | |
dfd07d72 | 8650 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8651 | break; |
8652 | case 36: | |
dfd07d72 | 8653 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8654 | break; |
8655 | default: | |
cc769b62 PZ |
8656 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8657 | BUG(); | |
c8203565 PZ |
8658 | } |
8659 | ||
6e3c9717 | 8660 | if (intel_crtc->config->dither) |
c8203565 PZ |
8661 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8662 | ||
6e3c9717 | 8663 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8664 | val |= PIPECONF_INTERLACED_ILK; |
8665 | else | |
8666 | val |= PIPECONF_PROGRESSIVE; | |
8667 | ||
6e3c9717 | 8668 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8669 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8670 | |
c8203565 PZ |
8671 | I915_WRITE(PIPECONF(pipe), val); |
8672 | POSTING_READ(PIPECONF(pipe)); | |
8673 | } | |
8674 | ||
86d3efce VS |
8675 | /* |
8676 | * Set up the pipe CSC unit. | |
8677 | * | |
8678 | * Currently only full range RGB to limited range RGB conversion | |
8679 | * is supported, but eventually this should handle various | |
8680 | * RGB<->YCbCr scenarios as well. | |
8681 | */ | |
50f3b016 | 8682 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8683 | { |
8684 | struct drm_device *dev = crtc->dev; | |
8685 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8686 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8687 | int pipe = intel_crtc->pipe; | |
8688 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8689 | ||
8690 | /* | |
8691 | * TODO: Check what kind of values actually come out of the pipe | |
8692 | * with these coeff/postoff values and adjust to get the best | |
8693 | * accuracy. Perhaps we even need to take the bpc value into | |
8694 | * consideration. | |
8695 | */ | |
8696 | ||
6e3c9717 | 8697 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8698 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8699 | ||
8700 | /* | |
8701 | * GY/GU and RY/RU should be the other way around according | |
8702 | * to BSpec, but reality doesn't agree. Just set them up in | |
8703 | * a way that results in the correct picture. | |
8704 | */ | |
8705 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8706 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8707 | ||
8708 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8709 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8710 | ||
8711 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8712 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8713 | ||
8714 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8715 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8716 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8717 | ||
8718 | if (INTEL_INFO(dev)->gen > 6) { | |
8719 | uint16_t postoff = 0; | |
8720 | ||
6e3c9717 | 8721 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8722 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8723 | |
8724 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8725 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8726 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8727 | ||
8728 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8729 | } else { | |
8730 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8731 | ||
6e3c9717 | 8732 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8733 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8734 | ||
8735 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8736 | } | |
8737 | } | |
8738 | ||
6ff93609 | 8739 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8740 | { |
756f85cf PZ |
8741 | struct drm_device *dev = crtc->dev; |
8742 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8743 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8744 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8745 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8746 | uint32_t val; |
8747 | ||
3eff4faa | 8748 | val = 0; |
ee2b0b38 | 8749 | |
6e3c9717 | 8750 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8751 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8752 | ||
6e3c9717 | 8753 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8754 | val |= PIPECONF_INTERLACED_ILK; |
8755 | else | |
8756 | val |= PIPECONF_PROGRESSIVE; | |
8757 | ||
702e7a56 PZ |
8758 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8759 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8760 | |
8761 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8762 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8763 | |
3cdf122c | 8764 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8765 | val = 0; |
8766 | ||
6e3c9717 | 8767 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8768 | case 18: |
8769 | val |= PIPEMISC_DITHER_6_BPC; | |
8770 | break; | |
8771 | case 24: | |
8772 | val |= PIPEMISC_DITHER_8_BPC; | |
8773 | break; | |
8774 | case 30: | |
8775 | val |= PIPEMISC_DITHER_10_BPC; | |
8776 | break; | |
8777 | case 36: | |
8778 | val |= PIPEMISC_DITHER_12_BPC; | |
8779 | break; | |
8780 | default: | |
8781 | /* Case prevented by pipe_config_set_bpp. */ | |
8782 | BUG(); | |
8783 | } | |
8784 | ||
6e3c9717 | 8785 | if (intel_crtc->config->dither) |
756f85cf PZ |
8786 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8787 | ||
8788 | I915_WRITE(PIPEMISC(pipe), val); | |
8789 | } | |
ee2b0b38 PZ |
8790 | } |
8791 | ||
6591c6e4 | 8792 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8793 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8794 | intel_clock_t *clock, |
8795 | bool *has_reduced_clock, | |
8796 | intel_clock_t *reduced_clock) | |
8797 | { | |
8798 | struct drm_device *dev = crtc->dev; | |
8799 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8800 | int refclk; |
d4906093 | 8801 | const intel_limit_t *limit; |
c329a4ec | 8802 | bool ret; |
79e53945 | 8803 | |
55bb9992 | 8804 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8805 | |
d4906093 ML |
8806 | /* |
8807 | * Returns a set of divisors for the desired target clock with the given | |
8808 | * refclk, or FALSE. The returned values represent the clock equation: | |
8809 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8810 | */ | |
a93e255f ACO |
8811 | limit = intel_limit(crtc_state, refclk); |
8812 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8813 | crtc_state->port_clock, |
ee9300bb | 8814 | refclk, NULL, clock); |
6591c6e4 PZ |
8815 | if (!ret) |
8816 | return false; | |
cda4b7d3 | 8817 | |
6591c6e4 PZ |
8818 | return true; |
8819 | } | |
8820 | ||
d4b1931c PZ |
8821 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8822 | { | |
8823 | /* | |
8824 | * Account for spread spectrum to avoid | |
8825 | * oversubscribing the link. Max center spread | |
8826 | * is 2.5%; use 5% for safety's sake. | |
8827 | */ | |
8828 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8829 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8830 | } |
8831 | ||
7429e9d4 | 8832 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8833 | { |
7429e9d4 | 8834 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8835 | } |
8836 | ||
de13a2e3 | 8837 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8838 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8839 | u32 *fp, |
9a7c7890 | 8840 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8841 | { |
de13a2e3 | 8842 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8843 | struct drm_device *dev = crtc->dev; |
8844 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8845 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8846 | struct drm_connector *connector; |
55bb9992 ACO |
8847 | struct drm_connector_state *connector_state; |
8848 | struct intel_encoder *encoder; | |
de13a2e3 | 8849 | uint32_t dpll; |
55bb9992 | 8850 | int factor, num_connectors = 0, i; |
09ede541 | 8851 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8852 | |
da3ced29 | 8853 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8854 | if (connector_state->crtc != crtc_state->base.crtc) |
8855 | continue; | |
8856 | ||
8857 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8858 | ||
8859 | switch (encoder->type) { | |
79e53945 JB |
8860 | case INTEL_OUTPUT_LVDS: |
8861 | is_lvds = true; | |
8862 | break; | |
8863 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8864 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8865 | is_sdvo = true; |
79e53945 | 8866 | break; |
6847d71b PZ |
8867 | default: |
8868 | break; | |
79e53945 | 8869 | } |
43565a06 | 8870 | |
c751ce4f | 8871 | num_connectors++; |
79e53945 | 8872 | } |
79e53945 | 8873 | |
c1858123 | 8874 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8875 | factor = 21; |
8876 | if (is_lvds) { | |
8877 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8878 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8879 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8880 | factor = 25; |
190f68c5 | 8881 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8882 | factor = 20; |
c1858123 | 8883 | |
190f68c5 | 8884 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8885 | *fp |= FP_CB_TUNE; |
2c07245f | 8886 | |
9a7c7890 DV |
8887 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8888 | *fp2 |= FP_CB_TUNE; | |
8889 | ||
5eddb70b | 8890 | dpll = 0; |
2c07245f | 8891 | |
a07d6787 EA |
8892 | if (is_lvds) |
8893 | dpll |= DPLLB_MODE_LVDS; | |
8894 | else | |
8895 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8896 | |
190f68c5 | 8897 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8898 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8899 | |
8900 | if (is_sdvo) | |
4a33e48d | 8901 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8902 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8903 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8904 | |
a07d6787 | 8905 | /* compute bitmask from p1 value */ |
190f68c5 | 8906 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8907 | /* also FPA1 */ |
190f68c5 | 8908 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8909 | |
190f68c5 | 8910 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8911 | case 5: |
8912 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8913 | break; | |
8914 | case 7: | |
8915 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8916 | break; | |
8917 | case 10: | |
8918 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8919 | break; | |
8920 | case 14: | |
8921 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8922 | break; | |
79e53945 JB |
8923 | } |
8924 | ||
b4c09f3b | 8925 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8926 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8927 | else |
8928 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8929 | ||
959e16d6 | 8930 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8931 | } |
8932 | ||
190f68c5 ACO |
8933 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8934 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8935 | { |
c7653199 | 8936 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8937 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8938 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8939 | bool ok, has_reduced_clock = false; |
8b47047b | 8940 | bool is_lvds = false; |
e2b78267 | 8941 | struct intel_shared_dpll *pll; |
de13a2e3 | 8942 | |
dd3cd74a ACO |
8943 | memset(&crtc_state->dpll_hw_state, 0, |
8944 | sizeof(crtc_state->dpll_hw_state)); | |
8945 | ||
7905df29 | 8946 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
79e53945 | 8947 | |
5dc5298b PZ |
8948 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8949 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8950 | |
190f68c5 | 8951 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8952 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8953 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8954 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8955 | return -EINVAL; | |
79e53945 | 8956 | } |
f47709a9 | 8957 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8958 | if (!crtc_state->clock_set) { |
8959 | crtc_state->dpll.n = clock.n; | |
8960 | crtc_state->dpll.m1 = clock.m1; | |
8961 | crtc_state->dpll.m2 = clock.m2; | |
8962 | crtc_state->dpll.p1 = clock.p1; | |
8963 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8964 | } |
79e53945 | 8965 | |
5dc5298b | 8966 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8967 | if (crtc_state->has_pch_encoder) { |
8968 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8969 | if (has_reduced_clock) |
7429e9d4 | 8970 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8971 | |
190f68c5 | 8972 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8973 | &fp, &reduced_clock, |
8974 | has_reduced_clock ? &fp2 : NULL); | |
8975 | ||
190f68c5 ACO |
8976 | crtc_state->dpll_hw_state.dpll = dpll; |
8977 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8978 | if (has_reduced_clock) |
190f68c5 | 8979 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8980 | else |
190f68c5 | 8981 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8982 | |
190f68c5 | 8983 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8984 | if (pll == NULL) { |
84f44ce7 | 8985 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8986 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8987 | return -EINVAL; |
8988 | } | |
3fb37703 | 8989 | } |
79e53945 | 8990 | |
ab585dea | 8991 | if (is_lvds && has_reduced_clock) |
c7653199 | 8992 | crtc->lowfreq_avail = true; |
bcd644e0 | 8993 | else |
c7653199 | 8994 | crtc->lowfreq_avail = false; |
e2b78267 | 8995 | |
c8f7a0db | 8996 | return 0; |
79e53945 JB |
8997 | } |
8998 | ||
eb14cb74 VS |
8999 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
9000 | struct intel_link_m_n *m_n) | |
9001 | { | |
9002 | struct drm_device *dev = crtc->base.dev; | |
9003 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9004 | enum pipe pipe = crtc->pipe; | |
9005 | ||
9006 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
9007 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
9008 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9009 | & ~TU_SIZE_MASK; | |
9010 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
9011 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9012 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9013 | } | |
9014 | ||
9015 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
9016 | enum transcoder transcoder, | |
b95af8be VK |
9017 | struct intel_link_m_n *m_n, |
9018 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
9019 | { |
9020 | struct drm_device *dev = crtc->base.dev; | |
9021 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 9022 | enum pipe pipe = crtc->pipe; |
72419203 | 9023 | |
eb14cb74 VS |
9024 | if (INTEL_INFO(dev)->gen >= 5) { |
9025 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
9026 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
9027 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
9028 | & ~TU_SIZE_MASK; | |
9029 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
9030 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
9031 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
9032 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
9033 | * gen < 8) and if DRRS is supported (to make sure the | |
9034 | * registers are not unnecessarily read). | |
9035 | */ | |
9036 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 9037 | crtc->config->has_drrs) { |
b95af8be VK |
9038 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
9039 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
9040 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
9041 | & ~TU_SIZE_MASK; | |
9042 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
9043 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
9044 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9045 | } | |
eb14cb74 VS |
9046 | } else { |
9047 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
9048 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
9049 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9050 | & ~TU_SIZE_MASK; | |
9051 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
9052 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9053 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9054 | } | |
9055 | } | |
9056 | ||
9057 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 9058 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 9059 | { |
681a8504 | 9060 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
9061 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
9062 | else | |
9063 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
9064 | &pipe_config->dp_m_n, |
9065 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 9066 | } |
72419203 | 9067 | |
eb14cb74 | 9068 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 9069 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
9070 | { |
9071 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 9072 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
9073 | } |
9074 | ||
bd2e244f | 9075 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9076 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
9077 | { |
9078 | struct drm_device *dev = crtc->base.dev; | |
9079 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
9080 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
9081 | uint32_t ps_ctrl = 0; | |
9082 | int id = -1; | |
9083 | int i; | |
bd2e244f | 9084 | |
a1b2278e CK |
9085 | /* find scaler attached to this pipe */ |
9086 | for (i = 0; i < crtc->num_scalers; i++) { | |
9087 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9088 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9089 | id = i; | |
9090 | pipe_config->pch_pfit.enabled = true; | |
9091 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9092 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9093 | break; | |
9094 | } | |
9095 | } | |
bd2e244f | 9096 | |
a1b2278e CK |
9097 | scaler_state->scaler_id = id; |
9098 | if (id >= 0) { | |
9099 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9100 | } else { | |
9101 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9102 | } |
9103 | } | |
9104 | ||
5724dbd1 DL |
9105 | static void |
9106 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9107 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9108 | { |
9109 | struct drm_device *dev = crtc->base.dev; | |
9110 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9111 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9112 | int pipe = crtc->pipe; |
9113 | int fourcc, pixel_format; | |
6761dd31 | 9114 | unsigned int aligned_height; |
bc8d7dff | 9115 | struct drm_framebuffer *fb; |
1b842c89 | 9116 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9117 | |
d9806c9f | 9118 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9119 | if (!intel_fb) { |
bc8d7dff DL |
9120 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9121 | return; | |
9122 | } | |
9123 | ||
1b842c89 DL |
9124 | fb = &intel_fb->base; |
9125 | ||
bc8d7dff | 9126 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9127 | if (!(val & PLANE_CTL_ENABLE)) |
9128 | goto error; | |
9129 | ||
bc8d7dff DL |
9130 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9131 | fourcc = skl_format_to_fourcc(pixel_format, | |
9132 | val & PLANE_CTL_ORDER_RGBX, | |
9133 | val & PLANE_CTL_ALPHA_MASK); | |
9134 | fb->pixel_format = fourcc; | |
9135 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9136 | ||
40f46283 DL |
9137 | tiling = val & PLANE_CTL_TILED_MASK; |
9138 | switch (tiling) { | |
9139 | case PLANE_CTL_TILED_LINEAR: | |
9140 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9141 | break; | |
9142 | case PLANE_CTL_TILED_X: | |
9143 | plane_config->tiling = I915_TILING_X; | |
9144 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9145 | break; | |
9146 | case PLANE_CTL_TILED_Y: | |
9147 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9148 | break; | |
9149 | case PLANE_CTL_TILED_YF: | |
9150 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9151 | break; | |
9152 | default: | |
9153 | MISSING_CASE(tiling); | |
9154 | goto error; | |
9155 | } | |
9156 | ||
bc8d7dff DL |
9157 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9158 | plane_config->base = base; | |
9159 | ||
9160 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9161 | ||
9162 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9163 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9164 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9165 | ||
9166 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9167 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9168 | fb->pixel_format); | |
bc8d7dff DL |
9169 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9170 | ||
9171 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9172 | fb->pixel_format, |
9173 | fb->modifier[0]); | |
bc8d7dff | 9174 | |
f37b5c2b | 9175 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9176 | |
9177 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9178 | pipe_name(pipe), fb->width, fb->height, | |
9179 | fb->bits_per_pixel, base, fb->pitches[0], | |
9180 | plane_config->size); | |
9181 | ||
2d14030b | 9182 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9183 | return; |
9184 | ||
9185 | error: | |
9186 | kfree(fb); | |
9187 | } | |
9188 | ||
2fa2fe9a | 9189 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9190 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9191 | { |
9192 | struct drm_device *dev = crtc->base.dev; | |
9193 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9194 | uint32_t tmp; | |
9195 | ||
9196 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9197 | ||
9198 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9199 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9200 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9201 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9202 | |
9203 | /* We currently do not free assignements of panel fitters on | |
9204 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9205 | * differentiates them) so just WARN about this case for now. */ | |
9206 | if (IS_GEN7(dev)) { | |
9207 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9208 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9209 | } | |
2fa2fe9a | 9210 | } |
79e53945 JB |
9211 | } |
9212 | ||
5724dbd1 DL |
9213 | static void |
9214 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9215 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9216 | { |
9217 | struct drm_device *dev = crtc->base.dev; | |
9218 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9219 | u32 val, base, offset; | |
aeee5a49 | 9220 | int pipe = crtc->pipe; |
4c6baa59 | 9221 | int fourcc, pixel_format; |
6761dd31 | 9222 | unsigned int aligned_height; |
b113d5ee | 9223 | struct drm_framebuffer *fb; |
1b842c89 | 9224 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9225 | |
42a7b088 DL |
9226 | val = I915_READ(DSPCNTR(pipe)); |
9227 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9228 | return; | |
9229 | ||
d9806c9f | 9230 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9231 | if (!intel_fb) { |
4c6baa59 JB |
9232 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9233 | return; | |
9234 | } | |
9235 | ||
1b842c89 DL |
9236 | fb = &intel_fb->base; |
9237 | ||
18c5247e DV |
9238 | if (INTEL_INFO(dev)->gen >= 4) { |
9239 | if (val & DISPPLANE_TILED) { | |
49af449b | 9240 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9241 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9242 | } | |
9243 | } | |
4c6baa59 JB |
9244 | |
9245 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9246 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9247 | fb->pixel_format = fourcc; |
9248 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9249 | |
aeee5a49 | 9250 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9251 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9252 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9253 | } else { |
49af449b | 9254 | if (plane_config->tiling) |
aeee5a49 | 9255 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9256 | else |
aeee5a49 | 9257 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9258 | } |
9259 | plane_config->base = base; | |
9260 | ||
9261 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9262 | fb->width = ((val >> 16) & 0xfff) + 1; |
9263 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9264 | |
9265 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9266 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9267 | |
b113d5ee | 9268 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9269 | fb->pixel_format, |
9270 | fb->modifier[0]); | |
4c6baa59 | 9271 | |
f37b5c2b | 9272 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9273 | |
2844a921 DL |
9274 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9275 | pipe_name(pipe), fb->width, fb->height, | |
9276 | fb->bits_per_pixel, base, fb->pitches[0], | |
9277 | plane_config->size); | |
b113d5ee | 9278 | |
2d14030b | 9279 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9280 | } |
9281 | ||
0e8ffe1b | 9282 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9283 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9284 | { |
9285 | struct drm_device *dev = crtc->base.dev; | |
9286 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9287 | uint32_t tmp; | |
9288 | ||
f458ebbc DV |
9289 | if (!intel_display_power_is_enabled(dev_priv, |
9290 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9291 | return false; |
9292 | ||
e143a21c | 9293 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9294 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9295 | |
0e8ffe1b DV |
9296 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9297 | if (!(tmp & PIPECONF_ENABLE)) | |
9298 | return false; | |
9299 | ||
42571aef VS |
9300 | switch (tmp & PIPECONF_BPC_MASK) { |
9301 | case PIPECONF_6BPC: | |
9302 | pipe_config->pipe_bpp = 18; | |
9303 | break; | |
9304 | case PIPECONF_8BPC: | |
9305 | pipe_config->pipe_bpp = 24; | |
9306 | break; | |
9307 | case PIPECONF_10BPC: | |
9308 | pipe_config->pipe_bpp = 30; | |
9309 | break; | |
9310 | case PIPECONF_12BPC: | |
9311 | pipe_config->pipe_bpp = 36; | |
9312 | break; | |
9313 | default: | |
9314 | break; | |
9315 | } | |
9316 | ||
b5a9fa09 DV |
9317 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9318 | pipe_config->limited_color_range = true; | |
9319 | ||
ab9412ba | 9320 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9321 | struct intel_shared_dpll *pll; |
9322 | ||
88adfff1 DV |
9323 | pipe_config->has_pch_encoder = true; |
9324 | ||
627eb5a3 DV |
9325 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9326 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9327 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9328 | |
9329 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9330 | |
c0d43d62 | 9331 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9332 | pipe_config->shared_dpll = |
9333 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9334 | } else { |
9335 | tmp = I915_READ(PCH_DPLL_SEL); | |
9336 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9337 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9338 | else | |
9339 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9340 | } | |
66e985c0 DV |
9341 | |
9342 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9343 | ||
9344 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9345 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9346 | |
9347 | tmp = pipe_config->dpll_hw_state.dpll; | |
9348 | pipe_config->pixel_multiplier = | |
9349 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9350 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9351 | |
9352 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9353 | } else { |
9354 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9355 | } |
9356 | ||
1bd1bd80 DV |
9357 | intel_get_pipe_timings(crtc, pipe_config); |
9358 | ||
2fa2fe9a DV |
9359 | ironlake_get_pfit_config(crtc, pipe_config); |
9360 | ||
0e8ffe1b DV |
9361 | return true; |
9362 | } | |
9363 | ||
be256dc7 PZ |
9364 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9365 | { | |
9366 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9367 | struct intel_crtc *crtc; |
be256dc7 | 9368 | |
d3fcc808 | 9369 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9370 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9371 | pipe_name(crtc->pipe)); |
9372 | ||
e2c719b7 RC |
9373 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9374 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9375 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9376 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9377 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9378 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9379 | "CPU PWM1 enabled\n"); |
c5107b87 | 9380 | if (IS_HASWELL(dev)) |
e2c719b7 | 9381 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9382 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9383 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9384 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9385 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9386 | "Utility pin enabled\n"); |
e2c719b7 | 9387 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9388 | |
9926ada1 PZ |
9389 | /* |
9390 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9391 | * interrupts remain enabled. We used to check for that, but since it's | |
9392 | * gen-specific and since we only disable LCPLL after we fully disable | |
9393 | * the interrupts, the check below should be enough. | |
9394 | */ | |
e2c719b7 | 9395 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9396 | } |
9397 | ||
9ccd5aeb PZ |
9398 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9399 | { | |
9400 | struct drm_device *dev = dev_priv->dev; | |
9401 | ||
9402 | if (IS_HASWELL(dev)) | |
9403 | return I915_READ(D_COMP_HSW); | |
9404 | else | |
9405 | return I915_READ(D_COMP_BDW); | |
9406 | } | |
9407 | ||
3c4c9b81 PZ |
9408 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9409 | { | |
9410 | struct drm_device *dev = dev_priv->dev; | |
9411 | ||
9412 | if (IS_HASWELL(dev)) { | |
9413 | mutex_lock(&dev_priv->rps.hw_lock); | |
9414 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9415 | val)) | |
f475dadf | 9416 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9417 | mutex_unlock(&dev_priv->rps.hw_lock); |
9418 | } else { | |
9ccd5aeb PZ |
9419 | I915_WRITE(D_COMP_BDW, val); |
9420 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9421 | } |
be256dc7 PZ |
9422 | } |
9423 | ||
9424 | /* | |
9425 | * This function implements pieces of two sequences from BSpec: | |
9426 | * - Sequence for display software to disable LCPLL | |
9427 | * - Sequence for display software to allow package C8+ | |
9428 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9429 | * register. Callers should take care of disabling all the display engine | |
9430 | * functions, doing the mode unset, fixing interrupts, etc. | |
9431 | */ | |
6ff58d53 PZ |
9432 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9433 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9434 | { |
9435 | uint32_t val; | |
9436 | ||
9437 | assert_can_disable_lcpll(dev_priv); | |
9438 | ||
9439 | val = I915_READ(LCPLL_CTL); | |
9440 | ||
9441 | if (switch_to_fclk) { | |
9442 | val |= LCPLL_CD_SOURCE_FCLK; | |
9443 | I915_WRITE(LCPLL_CTL, val); | |
9444 | ||
9445 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9446 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9447 | DRM_ERROR("Switching to FCLK failed\n"); | |
9448 | ||
9449 | val = I915_READ(LCPLL_CTL); | |
9450 | } | |
9451 | ||
9452 | val |= LCPLL_PLL_DISABLE; | |
9453 | I915_WRITE(LCPLL_CTL, val); | |
9454 | POSTING_READ(LCPLL_CTL); | |
9455 | ||
9456 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9457 | DRM_ERROR("LCPLL still locked\n"); | |
9458 | ||
9ccd5aeb | 9459 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9460 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9461 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9462 | ndelay(100); |
9463 | ||
9ccd5aeb PZ |
9464 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9465 | 1)) | |
be256dc7 PZ |
9466 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9467 | ||
9468 | if (allow_power_down) { | |
9469 | val = I915_READ(LCPLL_CTL); | |
9470 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9471 | I915_WRITE(LCPLL_CTL, val); | |
9472 | POSTING_READ(LCPLL_CTL); | |
9473 | } | |
9474 | } | |
9475 | ||
9476 | /* | |
9477 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9478 | * source. | |
9479 | */ | |
6ff58d53 | 9480 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9481 | { |
9482 | uint32_t val; | |
9483 | ||
9484 | val = I915_READ(LCPLL_CTL); | |
9485 | ||
9486 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9487 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9488 | return; | |
9489 | ||
a8a8bd54 PZ |
9490 | /* |
9491 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9492 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9493 | */ |
59bad947 | 9494 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9495 | |
be256dc7 PZ |
9496 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9497 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9498 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9499 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9500 | } |
9501 | ||
9ccd5aeb | 9502 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9503 | val |= D_COMP_COMP_FORCE; |
9504 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9505 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9506 | |
9507 | val = I915_READ(LCPLL_CTL); | |
9508 | val &= ~LCPLL_PLL_DISABLE; | |
9509 | I915_WRITE(LCPLL_CTL, val); | |
9510 | ||
9511 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9512 | DRM_ERROR("LCPLL not locked yet\n"); | |
9513 | ||
9514 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9515 | val = I915_READ(LCPLL_CTL); | |
9516 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9517 | I915_WRITE(LCPLL_CTL, val); | |
9518 | ||
9519 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9520 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9521 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9522 | } | |
215733fa | 9523 | |
59bad947 | 9524 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9525 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9526 | } |
9527 | ||
765dab67 PZ |
9528 | /* |
9529 | * Package states C8 and deeper are really deep PC states that can only be | |
9530 | * reached when all the devices on the system allow it, so even if the graphics | |
9531 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9532 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9533 | * | |
9534 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9535 | * well is disabled and most interrupts are disabled, and these are also | |
9536 | * requirements for runtime PM. When these conditions are met, we manually do | |
9537 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9538 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9539 | * hang the machine. | |
9540 | * | |
9541 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9542 | * the state of some registers, so when we come back from PC8+ we need to | |
9543 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9544 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9545 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9546 | * because of the runtime PM support). | |
9547 | * | |
9548 | * For more, read "Display Sequences for Package C8" on the hardware | |
9549 | * documentation. | |
9550 | */ | |
a14cb6fc | 9551 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9552 | { |
c67a470b PZ |
9553 | struct drm_device *dev = dev_priv->dev; |
9554 | uint32_t val; | |
9555 | ||
c67a470b PZ |
9556 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9557 | ||
c2699524 | 9558 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9559 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9560 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9561 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9562 | } | |
9563 | ||
9564 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9565 | hsw_disable_lcpll(dev_priv, true, true); |
9566 | } | |
9567 | ||
a14cb6fc | 9568 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9569 | { |
9570 | struct drm_device *dev = dev_priv->dev; | |
9571 | uint32_t val; | |
9572 | ||
c67a470b PZ |
9573 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9574 | ||
9575 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9576 | lpt_init_pch_refclk(dev); |
9577 | ||
c2699524 | 9578 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9579 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9580 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9581 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9582 | } | |
9583 | ||
9584 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9585 | } |
9586 | ||
27c329ed | 9587 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9588 | { |
a821fc46 | 9589 | struct drm_device *dev = old_state->dev; |
27c329ed | 9590 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
f8437dd1 | 9591 | |
27c329ed | 9592 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9593 | } |
9594 | ||
b432e5cf | 9595 | /* compute the max rate for new configuration */ |
27c329ed | 9596 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9597 | { |
b432e5cf | 9598 | struct intel_crtc *intel_crtc; |
27c329ed | 9599 | struct intel_crtc_state *crtc_state; |
b432e5cf | 9600 | int max_pixel_rate = 0; |
b432e5cf | 9601 | |
27c329ed ML |
9602 | for_each_intel_crtc(state->dev, intel_crtc) { |
9603 | int pixel_rate; | |
9604 | ||
9605 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
9606 | if (IS_ERR(crtc_state)) | |
9607 | return PTR_ERR(crtc_state); | |
9608 | ||
9609 | if (!crtc_state->base.enable) | |
b432e5cf VS |
9610 | continue; |
9611 | ||
27c329ed | 9612 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9613 | |
9614 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
27c329ed | 9615 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
b432e5cf VS |
9616 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9617 | ||
9618 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9619 | } | |
9620 | ||
9621 | return max_pixel_rate; | |
9622 | } | |
9623 | ||
9624 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9625 | { | |
9626 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9627 | uint32_t val, data; | |
9628 | int ret; | |
9629 | ||
9630 | if (WARN((I915_READ(LCPLL_CTL) & | |
9631 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9632 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9633 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9634 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9635 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9636 | return; | |
9637 | ||
9638 | mutex_lock(&dev_priv->rps.hw_lock); | |
9639 | ret = sandybridge_pcode_write(dev_priv, | |
9640 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9641 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9642 | if (ret) { | |
9643 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9644 | return; | |
9645 | } | |
9646 | ||
9647 | val = I915_READ(LCPLL_CTL); | |
9648 | val |= LCPLL_CD_SOURCE_FCLK; | |
9649 | I915_WRITE(LCPLL_CTL, val); | |
9650 | ||
9651 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9652 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9653 | DRM_ERROR("Switching to FCLK failed\n"); | |
9654 | ||
9655 | val = I915_READ(LCPLL_CTL); | |
9656 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9657 | ||
9658 | switch (cdclk) { | |
9659 | case 450000: | |
9660 | val |= LCPLL_CLK_FREQ_450; | |
9661 | data = 0; | |
9662 | break; | |
9663 | case 540000: | |
9664 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9665 | data = 1; | |
9666 | break; | |
9667 | case 337500: | |
9668 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9669 | data = 2; | |
9670 | break; | |
9671 | case 675000: | |
9672 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9673 | data = 3; | |
9674 | break; | |
9675 | default: | |
9676 | WARN(1, "invalid cdclk frequency\n"); | |
9677 | return; | |
9678 | } | |
9679 | ||
9680 | I915_WRITE(LCPLL_CTL, val); | |
9681 | ||
9682 | val = I915_READ(LCPLL_CTL); | |
9683 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9684 | I915_WRITE(LCPLL_CTL, val); | |
9685 | ||
9686 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9687 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9688 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9689 | ||
9690 | mutex_lock(&dev_priv->rps.hw_lock); | |
9691 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9692 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9693 | ||
9694 | intel_update_cdclk(dev); | |
9695 | ||
9696 | WARN(cdclk != dev_priv->cdclk_freq, | |
9697 | "cdclk requested %d kHz but got %d kHz\n", | |
9698 | cdclk, dev_priv->cdclk_freq); | |
9699 | } | |
9700 | ||
27c329ed | 9701 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9702 | { |
27c329ed ML |
9703 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
9704 | int max_pixclk = ilk_max_pixel_rate(state); | |
b432e5cf VS |
9705 | int cdclk; |
9706 | ||
9707 | /* | |
9708 | * FIXME should also account for plane ratio | |
9709 | * once 64bpp pixel formats are supported. | |
9710 | */ | |
27c329ed | 9711 | if (max_pixclk > 540000) |
b432e5cf | 9712 | cdclk = 675000; |
27c329ed | 9713 | else if (max_pixclk > 450000) |
b432e5cf | 9714 | cdclk = 540000; |
27c329ed | 9715 | else if (max_pixclk > 337500) |
b432e5cf VS |
9716 | cdclk = 450000; |
9717 | else | |
9718 | cdclk = 337500; | |
9719 | ||
9720 | /* | |
9721 | * FIXME move the cdclk caclulation to | |
9722 | * compute_config() so we can fail gracegully. | |
9723 | */ | |
9724 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9725 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9726 | cdclk, dev_priv->max_cdclk_freq); | |
9727 | cdclk = dev_priv->max_cdclk_freq; | |
9728 | } | |
9729 | ||
27c329ed | 9730 | to_intel_atomic_state(state)->cdclk = cdclk; |
b432e5cf VS |
9731 | |
9732 | return 0; | |
9733 | } | |
9734 | ||
27c329ed | 9735 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9736 | { |
27c329ed ML |
9737 | struct drm_device *dev = old_state->dev; |
9738 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; | |
b432e5cf | 9739 | |
27c329ed | 9740 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9741 | } |
9742 | ||
190f68c5 ACO |
9743 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9744 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9745 | { |
190f68c5 | 9746 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9747 | return -EINVAL; |
716c2e55 | 9748 | |
c7653199 | 9749 | crtc->lowfreq_avail = false; |
644cef34 | 9750 | |
c8f7a0db | 9751 | return 0; |
79e53945 JB |
9752 | } |
9753 | ||
3760b59c S |
9754 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9755 | enum port port, | |
9756 | struct intel_crtc_state *pipe_config) | |
9757 | { | |
9758 | switch (port) { | |
9759 | case PORT_A: | |
9760 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9761 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9762 | break; | |
9763 | case PORT_B: | |
9764 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9765 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9766 | break; | |
9767 | case PORT_C: | |
9768 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9769 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9770 | break; | |
9771 | default: | |
9772 | DRM_ERROR("Incorrect port type\n"); | |
9773 | } | |
9774 | } | |
9775 | ||
96b7dfb7 S |
9776 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9777 | enum port port, | |
5cec258b | 9778 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9779 | { |
3148ade7 | 9780 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9781 | |
9782 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9783 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9784 | ||
9785 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9786 | case SKL_DPLL0: |
9787 | /* | |
9788 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9789 | * of the shared DPLL framework and thus needs to be read out | |
9790 | * separately | |
9791 | */ | |
9792 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9793 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9794 | break; | |
96b7dfb7 S |
9795 | case SKL_DPLL1: |
9796 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9797 | break; | |
9798 | case SKL_DPLL2: | |
9799 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9800 | break; | |
9801 | case SKL_DPLL3: | |
9802 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9803 | break; | |
96b7dfb7 S |
9804 | } |
9805 | } | |
9806 | ||
7d2c8175 DL |
9807 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9808 | enum port port, | |
5cec258b | 9809 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9810 | { |
9811 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9812 | ||
9813 | switch (pipe_config->ddi_pll_sel) { | |
9814 | case PORT_CLK_SEL_WRPLL1: | |
9815 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9816 | break; | |
9817 | case PORT_CLK_SEL_WRPLL2: | |
9818 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9819 | break; | |
00490c22 ML |
9820 | case PORT_CLK_SEL_SPLL: |
9821 | pipe_config->shared_dpll = DPLL_ID_SPLL; | |
79bd23da | 9822 | break; |
7d2c8175 DL |
9823 | } |
9824 | } | |
9825 | ||
26804afd | 9826 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9827 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9828 | { |
9829 | struct drm_device *dev = crtc->base.dev; | |
9830 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9831 | struct intel_shared_dpll *pll; |
26804afd DV |
9832 | enum port port; |
9833 | uint32_t tmp; | |
9834 | ||
9835 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9836 | ||
9837 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9838 | ||
ef11bdb3 | 9839 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 9840 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
9841 | else if (IS_BROXTON(dev)) |
9842 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9843 | else |
9844 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9845 | |
d452c5b6 DV |
9846 | if (pipe_config->shared_dpll >= 0) { |
9847 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9848 | ||
9849 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9850 | &pipe_config->dpll_hw_state)); | |
9851 | } | |
9852 | ||
26804afd DV |
9853 | /* |
9854 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9855 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9856 | * the PCH transcoder is on. | |
9857 | */ | |
ca370455 DL |
9858 | if (INTEL_INFO(dev)->gen < 9 && |
9859 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9860 | pipe_config->has_pch_encoder = true; |
9861 | ||
9862 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9863 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9864 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9865 | ||
9866 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9867 | } | |
9868 | } | |
9869 | ||
0e8ffe1b | 9870 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9871 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9872 | { |
9873 | struct drm_device *dev = crtc->base.dev; | |
9874 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9875 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9876 | uint32_t tmp; |
9877 | ||
f458ebbc | 9878 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9879 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9880 | return false; | |
9881 | ||
e143a21c | 9882 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9883 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9884 | ||
eccb140b DV |
9885 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9886 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9887 | enum pipe trans_edp_pipe; | |
9888 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9889 | default: | |
9890 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9891 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9892 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9893 | trans_edp_pipe = PIPE_A; | |
9894 | break; | |
9895 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9896 | trans_edp_pipe = PIPE_B; | |
9897 | break; | |
9898 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9899 | trans_edp_pipe = PIPE_C; | |
9900 | break; | |
9901 | } | |
9902 | ||
9903 | if (trans_edp_pipe == crtc->pipe) | |
9904 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9905 | } | |
9906 | ||
f458ebbc | 9907 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9908 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9909 | return false; |
9910 | ||
eccb140b | 9911 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9912 | if (!(tmp & PIPECONF_ENABLE)) |
9913 | return false; | |
9914 | ||
26804afd | 9915 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9916 | |
1bd1bd80 DV |
9917 | intel_get_pipe_timings(crtc, pipe_config); |
9918 | ||
a1b2278e CK |
9919 | if (INTEL_INFO(dev)->gen >= 9) { |
9920 | skl_init_scalers(dev, crtc, pipe_config); | |
9921 | } | |
9922 | ||
2fa2fe9a | 9923 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9924 | |
9925 | if (INTEL_INFO(dev)->gen >= 9) { | |
9926 | pipe_config->scaler_state.scaler_id = -1; | |
9927 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9928 | } | |
9929 | ||
bd2e244f | 9930 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
1c132b44 | 9931 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 9932 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9933 | else |
1c132b44 | 9934 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 9935 | } |
88adfff1 | 9936 | |
e59150dc JB |
9937 | if (IS_HASWELL(dev)) |
9938 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9939 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9940 | |
ebb69c95 CT |
9941 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9942 | pipe_config->pixel_multiplier = | |
9943 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9944 | } else { | |
9945 | pipe_config->pixel_multiplier = 1; | |
9946 | } | |
6c49f241 | 9947 | |
0e8ffe1b DV |
9948 | return true; |
9949 | } | |
9950 | ||
560b85bb CW |
9951 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9952 | { | |
9953 | struct drm_device *dev = crtc->dev; | |
9954 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9955 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9956 | uint32_t cntl = 0, size = 0; |
560b85bb | 9957 | |
dc41c154 | 9958 | if (base) { |
3dd512fb MR |
9959 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9960 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9961 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9962 | ||
9963 | switch (stride) { | |
9964 | default: | |
9965 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9966 | width, stride); | |
9967 | stride = 256; | |
9968 | /* fallthrough */ | |
9969 | case 256: | |
9970 | case 512: | |
9971 | case 1024: | |
9972 | case 2048: | |
9973 | break; | |
4b0e333e CW |
9974 | } |
9975 | ||
dc41c154 VS |
9976 | cntl |= CURSOR_ENABLE | |
9977 | CURSOR_GAMMA_ENABLE | | |
9978 | CURSOR_FORMAT_ARGB | | |
9979 | CURSOR_STRIDE(stride); | |
9980 | ||
9981 | size = (height << 12) | width; | |
4b0e333e | 9982 | } |
560b85bb | 9983 | |
dc41c154 VS |
9984 | if (intel_crtc->cursor_cntl != 0 && |
9985 | (intel_crtc->cursor_base != base || | |
9986 | intel_crtc->cursor_size != size || | |
9987 | intel_crtc->cursor_cntl != cntl)) { | |
9988 | /* On these chipsets we can only modify the base/size/stride | |
9989 | * whilst the cursor is disabled. | |
9990 | */ | |
0b87c24e VS |
9991 | I915_WRITE(CURCNTR(PIPE_A), 0); |
9992 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 9993 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9994 | } |
560b85bb | 9995 | |
99d1f387 | 9996 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 9997 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
9998 | intel_crtc->cursor_base = base; |
9999 | } | |
4726e0b0 | 10000 | |
dc41c154 VS |
10001 | if (intel_crtc->cursor_size != size) { |
10002 | I915_WRITE(CURSIZE, size); | |
10003 | intel_crtc->cursor_size = size; | |
4b0e333e | 10004 | } |
560b85bb | 10005 | |
4b0e333e | 10006 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
10007 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
10008 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 10009 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 10010 | } |
560b85bb CW |
10011 | } |
10012 | ||
560b85bb | 10013 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
10014 | { |
10015 | struct drm_device *dev = crtc->dev; | |
10016 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10017 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10018 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
10019 | uint32_t cntl; |
10020 | ||
10021 | cntl = 0; | |
10022 | if (base) { | |
10023 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 10024 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
10025 | case 64: |
10026 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
10027 | break; | |
10028 | case 128: | |
10029 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
10030 | break; | |
10031 | case 256: | |
10032 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10033 | break; | |
10034 | default: | |
3dd512fb | 10035 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 10036 | return; |
65a21cd6 | 10037 | } |
4b0e333e | 10038 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 10039 | |
fc6f93bc | 10040 | if (HAS_DDI(dev)) |
47bf17a7 | 10041 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
4b0e333e | 10042 | } |
65a21cd6 | 10043 | |
8e7d688b | 10044 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
10045 | cntl |= CURSOR_ROTATE_180; |
10046 | ||
4b0e333e CW |
10047 | if (intel_crtc->cursor_cntl != cntl) { |
10048 | I915_WRITE(CURCNTR(pipe), cntl); | |
10049 | POSTING_READ(CURCNTR(pipe)); | |
10050 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 10051 | } |
4b0e333e | 10052 | |
65a21cd6 | 10053 | /* and commit changes on next vblank */ |
5efb3e28 VS |
10054 | I915_WRITE(CURBASE(pipe), base); |
10055 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
10056 | |
10057 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
10058 | } |
10059 | ||
cda4b7d3 | 10060 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
10061 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
10062 | bool on) | |
cda4b7d3 CW |
10063 | { |
10064 | struct drm_device *dev = crtc->dev; | |
10065 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10066 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10067 | int pipe = intel_crtc->pipe; | |
9b4101be ML |
10068 | struct drm_plane_state *cursor_state = crtc->cursor->state; |
10069 | int x = cursor_state->crtc_x; | |
10070 | int y = cursor_state->crtc_y; | |
d6e4db15 | 10071 | u32 base = 0, pos = 0; |
cda4b7d3 | 10072 | |
d6e4db15 | 10073 | if (on) |
cda4b7d3 | 10074 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 10075 | |
6e3c9717 | 10076 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
10077 | base = 0; |
10078 | ||
6e3c9717 | 10079 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
10080 | base = 0; |
10081 | ||
10082 | if (x < 0) { | |
9b4101be | 10083 | if (x + cursor_state->crtc_w <= 0) |
cda4b7d3 CW |
10084 | base = 0; |
10085 | ||
10086 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10087 | x = -x; | |
10088 | } | |
10089 | pos |= x << CURSOR_X_SHIFT; | |
10090 | ||
10091 | if (y < 0) { | |
9b4101be | 10092 | if (y + cursor_state->crtc_h <= 0) |
cda4b7d3 CW |
10093 | base = 0; |
10094 | ||
10095 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10096 | y = -y; | |
10097 | } | |
10098 | pos |= y << CURSOR_Y_SHIFT; | |
10099 | ||
4b0e333e | 10100 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
10101 | return; |
10102 | ||
5efb3e28 VS |
10103 | I915_WRITE(CURPOS(pipe), pos); |
10104 | ||
4398ad45 VS |
10105 | /* ILK+ do this automagically */ |
10106 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 10107 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
9b4101be ML |
10108 | base += (cursor_state->crtc_h * |
10109 | cursor_state->crtc_w - 1) * 4; | |
4398ad45 VS |
10110 | } |
10111 | ||
8ac54669 | 10112 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10113 | i845_update_cursor(crtc, base); |
10114 | else | |
10115 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10116 | } |
10117 | ||
dc41c154 VS |
10118 | static bool cursor_size_ok(struct drm_device *dev, |
10119 | uint32_t width, uint32_t height) | |
10120 | { | |
10121 | if (width == 0 || height == 0) | |
10122 | return false; | |
10123 | ||
10124 | /* | |
10125 | * 845g/865g are special in that they are only limited by | |
10126 | * the width of their cursors, the height is arbitrary up to | |
10127 | * the precision of the register. Everything else requires | |
10128 | * square cursors, limited to a few power-of-two sizes. | |
10129 | */ | |
10130 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10131 | if ((width & 63) != 0) | |
10132 | return false; | |
10133 | ||
10134 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10135 | return false; | |
10136 | ||
10137 | if (height > 1023) | |
10138 | return false; | |
10139 | } else { | |
10140 | switch (width | height) { | |
10141 | case 256: | |
10142 | case 128: | |
10143 | if (IS_GEN2(dev)) | |
10144 | return false; | |
10145 | case 64: | |
10146 | break; | |
10147 | default: | |
10148 | return false; | |
10149 | } | |
10150 | } | |
10151 | ||
10152 | return true; | |
10153 | } | |
10154 | ||
79e53945 | 10155 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10156 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10157 | { |
7203425a | 10158 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10159 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10160 | |
7203425a | 10161 | for (i = start; i < end; i++) { |
79e53945 JB |
10162 | intel_crtc->lut_r[i] = red[i] >> 8; |
10163 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10164 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10165 | } | |
10166 | ||
10167 | intel_crtc_load_lut(crtc); | |
10168 | } | |
10169 | ||
79e53945 JB |
10170 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10171 | static struct drm_display_mode load_detect_mode = { | |
10172 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10173 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10174 | }; | |
10175 | ||
a8bb6818 DV |
10176 | struct drm_framebuffer * |
10177 | __intel_framebuffer_create(struct drm_device *dev, | |
10178 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10179 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10180 | { |
10181 | struct intel_framebuffer *intel_fb; | |
10182 | int ret; | |
10183 | ||
10184 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10185 | if (!intel_fb) |
d2dff872 | 10186 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10187 | |
10188 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10189 | if (ret) |
10190 | goto err; | |
d2dff872 CW |
10191 | |
10192 | return &intel_fb->base; | |
dcb1394e | 10193 | |
dd4916c5 | 10194 | err: |
dd4916c5 | 10195 | kfree(intel_fb); |
dd4916c5 | 10196 | return ERR_PTR(ret); |
d2dff872 CW |
10197 | } |
10198 | ||
b5ea642a | 10199 | static struct drm_framebuffer * |
a8bb6818 DV |
10200 | intel_framebuffer_create(struct drm_device *dev, |
10201 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10202 | struct drm_i915_gem_object *obj) | |
10203 | { | |
10204 | struct drm_framebuffer *fb; | |
10205 | int ret; | |
10206 | ||
10207 | ret = i915_mutex_lock_interruptible(dev); | |
10208 | if (ret) | |
10209 | return ERR_PTR(ret); | |
10210 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10211 | mutex_unlock(&dev->struct_mutex); | |
10212 | ||
10213 | return fb; | |
10214 | } | |
10215 | ||
d2dff872 CW |
10216 | static u32 |
10217 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10218 | { | |
10219 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10220 | return ALIGN(pitch, 64); | |
10221 | } | |
10222 | ||
10223 | static u32 | |
10224 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10225 | { | |
10226 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10227 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10228 | } |
10229 | ||
10230 | static struct drm_framebuffer * | |
10231 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10232 | struct drm_display_mode *mode, | |
10233 | int depth, int bpp) | |
10234 | { | |
dcb1394e | 10235 | struct drm_framebuffer *fb; |
d2dff872 | 10236 | struct drm_i915_gem_object *obj; |
0fed39bd | 10237 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10238 | |
10239 | obj = i915_gem_alloc_object(dev, | |
10240 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10241 | if (obj == NULL) | |
10242 | return ERR_PTR(-ENOMEM); | |
10243 | ||
10244 | mode_cmd.width = mode->hdisplay; | |
10245 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10246 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10247 | bpp); | |
5ca0c34a | 10248 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10249 | |
dcb1394e LW |
10250 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10251 | if (IS_ERR(fb)) | |
10252 | drm_gem_object_unreference_unlocked(&obj->base); | |
10253 | ||
10254 | return fb; | |
d2dff872 CW |
10255 | } |
10256 | ||
10257 | static struct drm_framebuffer * | |
10258 | mode_fits_in_fbdev(struct drm_device *dev, | |
10259 | struct drm_display_mode *mode) | |
10260 | { | |
0695726e | 10261 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10262 | struct drm_i915_private *dev_priv = dev->dev_private; |
10263 | struct drm_i915_gem_object *obj; | |
10264 | struct drm_framebuffer *fb; | |
10265 | ||
4c0e5528 | 10266 | if (!dev_priv->fbdev) |
d2dff872 CW |
10267 | return NULL; |
10268 | ||
4c0e5528 | 10269 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10270 | return NULL; |
10271 | ||
4c0e5528 DV |
10272 | obj = dev_priv->fbdev->fb->obj; |
10273 | BUG_ON(!obj); | |
10274 | ||
8bcd4553 | 10275 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10276 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10277 | fb->bits_per_pixel)) | |
d2dff872 CW |
10278 | return NULL; |
10279 | ||
01f2c773 | 10280 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10281 | return NULL; |
10282 | ||
10283 | return fb; | |
4520f53a DV |
10284 | #else |
10285 | return NULL; | |
10286 | #endif | |
d2dff872 CW |
10287 | } |
10288 | ||
d3a40d1b ACO |
10289 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10290 | struct drm_crtc *crtc, | |
10291 | struct drm_display_mode *mode, | |
10292 | struct drm_framebuffer *fb, | |
10293 | int x, int y) | |
10294 | { | |
10295 | struct drm_plane_state *plane_state; | |
10296 | int hdisplay, vdisplay; | |
10297 | int ret; | |
10298 | ||
10299 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10300 | if (IS_ERR(plane_state)) | |
10301 | return PTR_ERR(plane_state); | |
10302 | ||
10303 | if (mode) | |
10304 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10305 | else | |
10306 | hdisplay = vdisplay = 0; | |
10307 | ||
10308 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10309 | if (ret) | |
10310 | return ret; | |
10311 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10312 | plane_state->crtc_x = 0; | |
10313 | plane_state->crtc_y = 0; | |
10314 | plane_state->crtc_w = hdisplay; | |
10315 | plane_state->crtc_h = vdisplay; | |
10316 | plane_state->src_x = x << 16; | |
10317 | plane_state->src_y = y << 16; | |
10318 | plane_state->src_w = hdisplay << 16; | |
10319 | plane_state->src_h = vdisplay << 16; | |
10320 | ||
10321 | return 0; | |
10322 | } | |
10323 | ||
d2434ab7 | 10324 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10325 | struct drm_display_mode *mode, |
51fd371b RC |
10326 | struct intel_load_detect_pipe *old, |
10327 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10328 | { |
10329 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10330 | struct intel_encoder *intel_encoder = |
10331 | intel_attached_encoder(connector); | |
79e53945 | 10332 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10333 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10334 | struct drm_crtc *crtc = NULL; |
10335 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10336 | struct drm_framebuffer *fb; |
51fd371b | 10337 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10338 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10339 | struct drm_connector_state *connector_state; |
4be07317 | 10340 | struct intel_crtc_state *crtc_state; |
51fd371b | 10341 | int ret, i = -1; |
79e53945 | 10342 | |
d2dff872 | 10343 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10344 | connector->base.id, connector->name, |
8e329a03 | 10345 | encoder->base.id, encoder->name); |
d2dff872 | 10346 | |
51fd371b RC |
10347 | retry: |
10348 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10349 | if (ret) | |
ad3c558f | 10350 | goto fail; |
6e9f798d | 10351 | |
79e53945 JB |
10352 | /* |
10353 | * Algorithm gets a little messy: | |
7a5e4805 | 10354 | * |
79e53945 JB |
10355 | * - if the connector already has an assigned crtc, use it (but make |
10356 | * sure it's on first) | |
7a5e4805 | 10357 | * |
79e53945 JB |
10358 | * - try to find the first unused crtc that can drive this connector, |
10359 | * and use that if we find one | |
79e53945 JB |
10360 | */ |
10361 | ||
10362 | /* See if we already have a CRTC for this connector */ | |
10363 | if (encoder->crtc) { | |
10364 | crtc = encoder->crtc; | |
8261b191 | 10365 | |
51fd371b | 10366 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10367 | if (ret) |
ad3c558f | 10368 | goto fail; |
4d02e2de | 10369 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
51fd371b | 10370 | if (ret) |
ad3c558f | 10371 | goto fail; |
7b24056b | 10372 | |
24218aac | 10373 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10374 | old->load_detect_temp = false; |
10375 | ||
10376 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10377 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10378 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10379 | |
7173188d | 10380 | return true; |
79e53945 JB |
10381 | } |
10382 | ||
10383 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10384 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10385 | i++; |
10386 | if (!(encoder->possible_crtcs & (1 << i))) | |
10387 | continue; | |
83d65738 | 10388 | if (possible_crtc->state->enable) |
a459249c | 10389 | continue; |
a459249c VS |
10390 | |
10391 | crtc = possible_crtc; | |
10392 | break; | |
79e53945 JB |
10393 | } |
10394 | ||
10395 | /* | |
10396 | * If we didn't find an unused CRTC, don't use any. | |
10397 | */ | |
10398 | if (!crtc) { | |
7173188d | 10399 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10400 | goto fail; |
79e53945 JB |
10401 | } |
10402 | ||
51fd371b RC |
10403 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10404 | if (ret) | |
ad3c558f | 10405 | goto fail; |
4d02e2de DV |
10406 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10407 | if (ret) | |
ad3c558f | 10408 | goto fail; |
79e53945 JB |
10409 | |
10410 | intel_crtc = to_intel_crtc(crtc); | |
24218aac | 10411 | old->dpms_mode = connector->dpms; |
8261b191 | 10412 | old->load_detect_temp = true; |
d2dff872 | 10413 | old->release_fb = NULL; |
79e53945 | 10414 | |
83a57153 ACO |
10415 | state = drm_atomic_state_alloc(dev); |
10416 | if (!state) | |
10417 | return false; | |
10418 | ||
10419 | state->acquire_ctx = ctx; | |
10420 | ||
944b0c76 ACO |
10421 | connector_state = drm_atomic_get_connector_state(state, connector); |
10422 | if (IS_ERR(connector_state)) { | |
10423 | ret = PTR_ERR(connector_state); | |
10424 | goto fail; | |
10425 | } | |
10426 | ||
10427 | connector_state->crtc = crtc; | |
10428 | connector_state->best_encoder = &intel_encoder->base; | |
10429 | ||
4be07317 ACO |
10430 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10431 | if (IS_ERR(crtc_state)) { | |
10432 | ret = PTR_ERR(crtc_state); | |
10433 | goto fail; | |
10434 | } | |
10435 | ||
49d6fa21 | 10436 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10437 | |
6492711d CW |
10438 | if (!mode) |
10439 | mode = &load_detect_mode; | |
79e53945 | 10440 | |
d2dff872 CW |
10441 | /* We need a framebuffer large enough to accommodate all accesses |
10442 | * that the plane may generate whilst we perform load detection. | |
10443 | * We can not rely on the fbcon either being present (we get called | |
10444 | * during its initialisation to detect all boot displays, or it may | |
10445 | * not even exist) or that it is large enough to satisfy the | |
10446 | * requested mode. | |
10447 | */ | |
94352cf9 DV |
10448 | fb = mode_fits_in_fbdev(dev, mode); |
10449 | if (fb == NULL) { | |
d2dff872 | 10450 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10451 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10452 | old->release_fb = fb; | |
d2dff872 CW |
10453 | } else |
10454 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10455 | if (IS_ERR(fb)) { |
d2dff872 | 10456 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10457 | goto fail; |
79e53945 | 10458 | } |
79e53945 | 10459 | |
d3a40d1b ACO |
10460 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10461 | if (ret) | |
10462 | goto fail; | |
10463 | ||
8c7b5ccb ACO |
10464 | drm_mode_copy(&crtc_state->base.mode, mode); |
10465 | ||
74c090b1 | 10466 | if (drm_atomic_commit(state)) { |
6492711d | 10467 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10468 | if (old->release_fb) |
10469 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10470 | goto fail; |
79e53945 | 10471 | } |
9128b040 | 10472 | crtc->primary->crtc = crtc; |
7173188d | 10473 | |
79e53945 | 10474 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10475 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10476 | return true; |
412b61d8 | 10477 | |
ad3c558f | 10478 | fail: |
e5d958ef ACO |
10479 | drm_atomic_state_free(state); |
10480 | state = NULL; | |
83a57153 | 10481 | |
51fd371b RC |
10482 | if (ret == -EDEADLK) { |
10483 | drm_modeset_backoff(ctx); | |
10484 | goto retry; | |
10485 | } | |
10486 | ||
412b61d8 | 10487 | return false; |
79e53945 JB |
10488 | } |
10489 | ||
d2434ab7 | 10490 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10491 | struct intel_load_detect_pipe *old, |
10492 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10493 | { |
83a57153 | 10494 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10495 | struct intel_encoder *intel_encoder = |
10496 | intel_attached_encoder(connector); | |
4ef69c7a | 10497 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10498 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10499 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10500 | struct drm_atomic_state *state; |
944b0c76 | 10501 | struct drm_connector_state *connector_state; |
4be07317 | 10502 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10503 | int ret; |
79e53945 | 10504 | |
d2dff872 | 10505 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10506 | connector->base.id, connector->name, |
8e329a03 | 10507 | encoder->base.id, encoder->name); |
d2dff872 | 10508 | |
8261b191 | 10509 | if (old->load_detect_temp) { |
83a57153 | 10510 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10511 | if (!state) |
10512 | goto fail; | |
83a57153 ACO |
10513 | |
10514 | state->acquire_ctx = ctx; | |
10515 | ||
944b0c76 ACO |
10516 | connector_state = drm_atomic_get_connector_state(state, connector); |
10517 | if (IS_ERR(connector_state)) | |
10518 | goto fail; | |
10519 | ||
4be07317 ACO |
10520 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10521 | if (IS_ERR(crtc_state)) | |
10522 | goto fail; | |
10523 | ||
944b0c76 ACO |
10524 | connector_state->best_encoder = NULL; |
10525 | connector_state->crtc = NULL; | |
10526 | ||
49d6fa21 | 10527 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10528 | |
d3a40d1b ACO |
10529 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10530 | 0, 0); | |
10531 | if (ret) | |
10532 | goto fail; | |
10533 | ||
74c090b1 | 10534 | ret = drm_atomic_commit(state); |
2bfb4627 ACO |
10535 | if (ret) |
10536 | goto fail; | |
d2dff872 | 10537 | |
36206361 DV |
10538 | if (old->release_fb) { |
10539 | drm_framebuffer_unregister_private(old->release_fb); | |
10540 | drm_framebuffer_unreference(old->release_fb); | |
10541 | } | |
d2dff872 | 10542 | |
0622a53c | 10543 | return; |
79e53945 JB |
10544 | } |
10545 | ||
c751ce4f | 10546 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10547 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10548 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10549 | |
10550 | return; | |
10551 | fail: | |
10552 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10553 | drm_atomic_state_free(state); | |
79e53945 JB |
10554 | } |
10555 | ||
da4a1efa | 10556 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10557 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10558 | { |
10559 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10560 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10561 | ||
10562 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10563 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10564 | else if (HAS_PCH_SPLIT(dev)) |
10565 | return 120000; | |
10566 | else if (!IS_GEN2(dev)) | |
10567 | return 96000; | |
10568 | else | |
10569 | return 48000; | |
10570 | } | |
10571 | ||
79e53945 | 10572 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10573 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10574 | struct intel_crtc_state *pipe_config) |
79e53945 | 10575 | { |
f1f644dc | 10576 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10577 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10578 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10579 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10580 | u32 fp; |
10581 | intel_clock_t clock; | |
dccbea3b | 10582 | int port_clock; |
da4a1efa | 10583 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10584 | |
10585 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10586 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10587 | else |
293623f7 | 10588 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10589 | |
10590 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10591 | if (IS_PINEVIEW(dev)) { |
10592 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10593 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10594 | } else { |
10595 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10596 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10597 | } | |
10598 | ||
a6c45cf0 | 10599 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10600 | if (IS_PINEVIEW(dev)) |
10601 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10602 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10603 | else |
10604 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10605 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10606 | ||
10607 | switch (dpll & DPLL_MODE_MASK) { | |
10608 | case DPLLB_MODE_DAC_SERIAL: | |
10609 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10610 | 5 : 10; | |
10611 | break; | |
10612 | case DPLLB_MODE_LVDS: | |
10613 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10614 | 7 : 14; | |
10615 | break; | |
10616 | default: | |
28c97730 | 10617 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10618 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10619 | return; |
79e53945 JB |
10620 | } |
10621 | ||
ac58c3f0 | 10622 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10623 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10624 | else |
dccbea3b | 10625 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10626 | } else { |
0fb58223 | 10627 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10628 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10629 | |
10630 | if (is_lvds) { | |
10631 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10632 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10633 | |
10634 | if (lvds & LVDS_CLKB_POWER_UP) | |
10635 | clock.p2 = 7; | |
10636 | else | |
10637 | clock.p2 = 14; | |
79e53945 JB |
10638 | } else { |
10639 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10640 | clock.p1 = 2; | |
10641 | else { | |
10642 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10643 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10644 | } | |
10645 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10646 | clock.p2 = 4; | |
10647 | else | |
10648 | clock.p2 = 2; | |
79e53945 | 10649 | } |
da4a1efa | 10650 | |
dccbea3b | 10651 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10652 | } |
10653 | ||
18442d08 VS |
10654 | /* |
10655 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10656 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10657 | * encoder's get_config() function. |
10658 | */ | |
dccbea3b | 10659 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10660 | } |
10661 | ||
6878da05 VS |
10662 | int intel_dotclock_calculate(int link_freq, |
10663 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10664 | { |
f1f644dc JB |
10665 | /* |
10666 | * The calculation for the data clock is: | |
1041a02f | 10667 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10668 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10669 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10670 | * |
10671 | * and the link clock is simpler: | |
1041a02f | 10672 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10673 | */ |
10674 | ||
6878da05 VS |
10675 | if (!m_n->link_n) |
10676 | return 0; | |
f1f644dc | 10677 | |
6878da05 VS |
10678 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10679 | } | |
f1f644dc | 10680 | |
18442d08 | 10681 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10682 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10683 | { |
10684 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10685 | |
18442d08 VS |
10686 | /* read out port_clock from the DPLL */ |
10687 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10688 | |
f1f644dc | 10689 | /* |
18442d08 | 10690 | * This value does not include pixel_multiplier. |
241bfc38 | 10691 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10692 | * agree once we know their relationship in the encoder's |
10693 | * get_config() function. | |
79e53945 | 10694 | */ |
2d112de7 | 10695 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10696 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10697 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10698 | } |
10699 | ||
10700 | /** Returns the currently programmed mode of the given pipe. */ | |
10701 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10702 | struct drm_crtc *crtc) | |
10703 | { | |
548f245b | 10704 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10705 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10706 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10707 | struct drm_display_mode *mode; |
5cec258b | 10708 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10709 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10710 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10711 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10712 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10713 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10714 | |
10715 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10716 | if (!mode) | |
10717 | return NULL; | |
10718 | ||
f1f644dc JB |
10719 | /* |
10720 | * Construct a pipe_config sufficient for getting the clock info | |
10721 | * back out of crtc_clock_get. | |
10722 | * | |
10723 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10724 | * to use a real value here instead. | |
10725 | */ | |
293623f7 | 10726 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10727 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10728 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10729 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10730 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10731 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10732 | ||
773ae034 | 10733 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10734 | mode->hdisplay = (htot & 0xffff) + 1; |
10735 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10736 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10737 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10738 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10739 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10740 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10741 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10742 | ||
10743 | drm_mode_set_name(mode); | |
79e53945 JB |
10744 | |
10745 | return mode; | |
10746 | } | |
10747 | ||
f047e395 CW |
10748 | void intel_mark_busy(struct drm_device *dev) |
10749 | { | |
c67a470b PZ |
10750 | struct drm_i915_private *dev_priv = dev->dev_private; |
10751 | ||
f62a0076 CW |
10752 | if (dev_priv->mm.busy) |
10753 | return; | |
10754 | ||
43694d69 | 10755 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10756 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10757 | if (INTEL_INFO(dev)->gen >= 6) |
10758 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10759 | dev_priv->mm.busy = true; |
f047e395 CW |
10760 | } |
10761 | ||
10762 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10763 | { |
c67a470b | 10764 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10765 | |
f62a0076 CW |
10766 | if (!dev_priv->mm.busy) |
10767 | return; | |
10768 | ||
10769 | dev_priv->mm.busy = false; | |
10770 | ||
3d13ef2e | 10771 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10772 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10773 | |
43694d69 | 10774 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10775 | } |
10776 | ||
79e53945 JB |
10777 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10778 | { | |
10779 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10780 | struct drm_device *dev = crtc->dev; |
10781 | struct intel_unpin_work *work; | |
67e77c5a | 10782 | |
5e2d7afc | 10783 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10784 | work = intel_crtc->unpin_work; |
10785 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10786 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10787 | |
10788 | if (work) { | |
10789 | cancel_work_sync(&work->work); | |
10790 | kfree(work); | |
10791 | } | |
79e53945 JB |
10792 | |
10793 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10794 | |
79e53945 JB |
10795 | kfree(intel_crtc); |
10796 | } | |
10797 | ||
6b95a207 KH |
10798 | static void intel_unpin_work_fn(struct work_struct *__work) |
10799 | { | |
10800 | struct intel_unpin_work *work = | |
10801 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10802 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10803 | struct drm_device *dev = crtc->base.dev; | |
10804 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10805 | |
b4a98e57 | 10806 | mutex_lock(&dev->struct_mutex); |
a9ff8714 | 10807 | intel_unpin_fb_obj(work->old_fb, primary->state); |
05394f39 | 10808 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10809 | |
f06cc1b9 | 10810 | if (work->flip_queued_req) |
146d84f0 | 10811 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10812 | mutex_unlock(&dev->struct_mutex); |
10813 | ||
a9ff8714 | 10814 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
89ed88ba | 10815 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10816 | |
a9ff8714 VS |
10817 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10818 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10819 | |
6b95a207 KH |
10820 | kfree(work); |
10821 | } | |
10822 | ||
1afe3e9d | 10823 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10824 | struct drm_crtc *crtc) |
6b95a207 | 10825 | { |
6b95a207 KH |
10826 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10827 | struct intel_unpin_work *work; | |
6b95a207 KH |
10828 | unsigned long flags; |
10829 | ||
10830 | /* Ignore early vblank irqs */ | |
10831 | if (intel_crtc == NULL) | |
10832 | return; | |
10833 | ||
f326038a DV |
10834 | /* |
10835 | * This is called both by irq handlers and the reset code (to complete | |
10836 | * lost pageflips) so needs the full irqsave spinlocks. | |
10837 | */ | |
6b95a207 KH |
10838 | spin_lock_irqsave(&dev->event_lock, flags); |
10839 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10840 | |
10841 | /* Ensure we don't miss a work->pending update ... */ | |
10842 | smp_rmb(); | |
10843 | ||
10844 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10845 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10846 | return; | |
10847 | } | |
10848 | ||
d6bbafa1 | 10849 | page_flip_completed(intel_crtc); |
0af7e4df | 10850 | |
6b95a207 | 10851 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10852 | } |
10853 | ||
1afe3e9d JB |
10854 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10855 | { | |
fbee40df | 10856 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10857 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10858 | ||
49b14a5c | 10859 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10860 | } |
10861 | ||
10862 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10863 | { | |
fbee40df | 10864 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10865 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10866 | ||
49b14a5c | 10867 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10868 | } |
10869 | ||
75f7f3ec VS |
10870 | /* Is 'a' after or equal to 'b'? */ |
10871 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10872 | { | |
10873 | return !((a - b) & 0x80000000); | |
10874 | } | |
10875 | ||
10876 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10877 | { | |
10878 | struct drm_device *dev = crtc->base.dev; | |
10879 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10880 | ||
bdfa7542 VS |
10881 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10882 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10883 | return true; | |
10884 | ||
75f7f3ec VS |
10885 | /* |
10886 | * The relevant registers doen't exist on pre-ctg. | |
10887 | * As the flip done interrupt doesn't trigger for mmio | |
10888 | * flips on gmch platforms, a flip count check isn't | |
10889 | * really needed there. But since ctg has the registers, | |
10890 | * include it in the check anyway. | |
10891 | */ | |
10892 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10893 | return true; | |
10894 | ||
10895 | /* | |
10896 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10897 | * used the same base address. In that case the mmio flip might | |
10898 | * have completed, but the CS hasn't even executed the flip yet. | |
10899 | * | |
10900 | * A flip count check isn't enough as the CS might have updated | |
10901 | * the base address just after start of vblank, but before we | |
10902 | * managed to process the interrupt. This means we'd complete the | |
10903 | * CS flip too soon. | |
10904 | * | |
10905 | * Combining both checks should get us a good enough result. It may | |
10906 | * still happen that the CS flip has been executed, but has not | |
10907 | * yet actually completed. But in case the base address is the same | |
10908 | * anyway, we don't really care. | |
10909 | */ | |
10910 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10911 | crtc->unpin_work->gtt_offset && | |
fd8f507c | 10912 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
75f7f3ec VS |
10913 | crtc->unpin_work->flip_count); |
10914 | } | |
10915 | ||
6b95a207 KH |
10916 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10917 | { | |
fbee40df | 10918 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10919 | struct intel_crtc *intel_crtc = |
10920 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10921 | unsigned long flags; | |
10922 | ||
f326038a DV |
10923 | |
10924 | /* | |
10925 | * This is called both by irq handlers and the reset code (to complete | |
10926 | * lost pageflips) so needs the full irqsave spinlocks. | |
10927 | * | |
10928 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10929 | * generate a page-flip completion irq, i.e. every modeset |
10930 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10931 | */ | |
6b95a207 | 10932 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10933 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10934 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10935 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10936 | } | |
10937 | ||
6042639c | 10938 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
e7d841ca CW |
10939 | { |
10940 | /* Ensure that the work item is consistent when activating it ... */ | |
10941 | smp_wmb(); | |
6042639c | 10942 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
e7d841ca CW |
10943 | /* and that it is marked active as soon as the irq could fire. */ |
10944 | smp_wmb(); | |
10945 | } | |
10946 | ||
8c9f3aaf JB |
10947 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10948 | struct drm_crtc *crtc, | |
10949 | struct drm_framebuffer *fb, | |
ed8d1975 | 10950 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10951 | struct drm_i915_gem_request *req, |
ed8d1975 | 10952 | uint32_t flags) |
8c9f3aaf | 10953 | { |
6258fbe2 | 10954 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10955 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10956 | u32 flip_mask; |
10957 | int ret; | |
10958 | ||
5fb9de1a | 10959 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10960 | if (ret) |
4fa62c89 | 10961 | return ret; |
8c9f3aaf JB |
10962 | |
10963 | /* Can't queue multiple flips, so wait for the previous | |
10964 | * one to finish before executing the next. | |
10965 | */ | |
10966 | if (intel_crtc->plane) | |
10967 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10968 | else | |
10969 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10970 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10971 | intel_ring_emit(ring, MI_NOOP); | |
10972 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10973 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10974 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10975 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10976 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca | 10977 | |
6042639c | 10978 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10979 | return 0; |
8c9f3aaf JB |
10980 | } |
10981 | ||
10982 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10983 | struct drm_crtc *crtc, | |
10984 | struct drm_framebuffer *fb, | |
ed8d1975 | 10985 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10986 | struct drm_i915_gem_request *req, |
ed8d1975 | 10987 | uint32_t flags) |
8c9f3aaf | 10988 | { |
6258fbe2 | 10989 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10990 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10991 | u32 flip_mask; |
10992 | int ret; | |
10993 | ||
5fb9de1a | 10994 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10995 | if (ret) |
4fa62c89 | 10996 | return ret; |
8c9f3aaf JB |
10997 | |
10998 | if (intel_crtc->plane) | |
10999 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11000 | else | |
11001 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11002 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11003 | intel_ring_emit(ring, MI_NOOP); | |
11004 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
11005 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11006 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11007 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
11008 | intel_ring_emit(ring, MI_NOOP); |
11009 | ||
6042639c | 11010 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11011 | return 0; |
8c9f3aaf JB |
11012 | } |
11013 | ||
11014 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
11015 | struct drm_crtc *crtc, | |
11016 | struct drm_framebuffer *fb, | |
ed8d1975 | 11017 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11018 | struct drm_i915_gem_request *req, |
ed8d1975 | 11019 | uint32_t flags) |
8c9f3aaf | 11020 | { |
6258fbe2 | 11021 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
11022 | struct drm_i915_private *dev_priv = dev->dev_private; |
11023 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11024 | uint32_t pf, pipesrc; | |
11025 | int ret; | |
11026 | ||
5fb9de1a | 11027 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 11028 | if (ret) |
4fa62c89 | 11029 | return ret; |
8c9f3aaf JB |
11030 | |
11031 | /* i965+ uses the linear or tiled offsets from the | |
11032 | * Display Registers (which do not change across a page-flip) | |
11033 | * so we need only reprogram the base address. | |
11034 | */ | |
6d90c952 DV |
11035 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11036 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11037 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11038 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 11039 | obj->tiling_mode); |
8c9f3aaf JB |
11040 | |
11041 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11042 | * untested on non-native modes, so ignore it for now. | |
11043 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11044 | */ | |
11045 | pf = 0; | |
11046 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 11047 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 11048 | |
6042639c | 11049 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11050 | return 0; |
8c9f3aaf JB |
11051 | } |
11052 | ||
11053 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
11054 | struct drm_crtc *crtc, | |
11055 | struct drm_framebuffer *fb, | |
ed8d1975 | 11056 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11057 | struct drm_i915_gem_request *req, |
ed8d1975 | 11058 | uint32_t flags) |
8c9f3aaf | 11059 | { |
6258fbe2 | 11060 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
11061 | struct drm_i915_private *dev_priv = dev->dev_private; |
11062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11063 | uint32_t pf, pipesrc; | |
11064 | int ret; | |
11065 | ||
5fb9de1a | 11066 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 11067 | if (ret) |
4fa62c89 | 11068 | return ret; |
8c9f3aaf | 11069 | |
6d90c952 DV |
11070 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11071 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11072 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 11073 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 11074 | |
dc257cf1 DV |
11075 | /* Contrary to the suggestions in the documentation, |
11076 | * "Enable Panel Fitter" does not seem to be required when page | |
11077 | * flipping with a non-native mode, and worse causes a normal | |
11078 | * modeset to fail. | |
11079 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11080 | */ | |
11081 | pf = 0; | |
8c9f3aaf | 11082 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 11083 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 11084 | |
6042639c | 11085 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11086 | return 0; |
8c9f3aaf JB |
11087 | } |
11088 | ||
7c9017e5 JB |
11089 | static int intel_gen7_queue_flip(struct drm_device *dev, |
11090 | struct drm_crtc *crtc, | |
11091 | struct drm_framebuffer *fb, | |
ed8d1975 | 11092 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11093 | struct drm_i915_gem_request *req, |
ed8d1975 | 11094 | uint32_t flags) |
7c9017e5 | 11095 | { |
6258fbe2 | 11096 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 11097 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 11098 | uint32_t plane_bit = 0; |
ffe74d75 CW |
11099 | int len, ret; |
11100 | ||
eba905b2 | 11101 | switch (intel_crtc->plane) { |
cb05d8de DV |
11102 | case PLANE_A: |
11103 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11104 | break; | |
11105 | case PLANE_B: | |
11106 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11107 | break; | |
11108 | case PLANE_C: | |
11109 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11110 | break; | |
11111 | default: | |
11112 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11113 | return -ENODEV; |
cb05d8de DV |
11114 | } |
11115 | ||
ffe74d75 | 11116 | len = 4; |
f476828a | 11117 | if (ring->id == RCS) { |
ffe74d75 | 11118 | len += 6; |
f476828a DL |
11119 | /* |
11120 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11121 | * 48bits addresses, and we need a NOOP for the batch size to | |
11122 | * stay even. | |
11123 | */ | |
11124 | if (IS_GEN8(dev)) | |
11125 | len += 2; | |
11126 | } | |
ffe74d75 | 11127 | |
f66fab8e VS |
11128 | /* |
11129 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11130 | * "The full packet must be contained within the same cache line." | |
11131 | * | |
11132 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11133 | * cacheline, if we ever start emitting more commands before | |
11134 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11135 | * then do the cacheline alignment, and finally emit the | |
11136 | * MI_DISPLAY_FLIP. | |
11137 | */ | |
bba09b12 | 11138 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 11139 | if (ret) |
4fa62c89 | 11140 | return ret; |
f66fab8e | 11141 | |
5fb9de1a | 11142 | ret = intel_ring_begin(req, len); |
7c9017e5 | 11143 | if (ret) |
4fa62c89 | 11144 | return ret; |
7c9017e5 | 11145 | |
ffe74d75 CW |
11146 | /* Unmask the flip-done completion message. Note that the bspec says that |
11147 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11148 | * more than one flip event at any time (or ensure that one flip message | |
11149 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11150 | * Experimentation says that BCS works despite DERRMR masking all | |
11151 | * flip-done completion events and that unmasking all planes at once | |
11152 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11153 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11154 | */ | |
11155 | if (ring->id == RCS) { | |
11156 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
f92a9162 | 11157 | intel_ring_emit_reg(ring, DERRMR); |
ffe74d75 CW |
11158 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
11159 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11160 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11161 | if (IS_GEN8(dev)) |
f1afe24f | 11162 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11163 | MI_SRM_LRM_GLOBAL_GTT); |
11164 | else | |
f1afe24f | 11165 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11166 | MI_SRM_LRM_GLOBAL_GTT); |
f92a9162 | 11167 | intel_ring_emit_reg(ring, DERRMR); |
ffe74d75 | 11168 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
f476828a DL |
11169 | if (IS_GEN8(dev)) { |
11170 | intel_ring_emit(ring, 0); | |
11171 | intel_ring_emit(ring, MI_NOOP); | |
11172 | } | |
ffe74d75 CW |
11173 | } |
11174 | ||
cb05d8de | 11175 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11176 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11177 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11178 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca | 11179 | |
6042639c | 11180 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11181 | return 0; |
7c9017e5 JB |
11182 | } |
11183 | ||
84c33a64 SG |
11184 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11185 | struct drm_i915_gem_object *obj) | |
11186 | { | |
11187 | /* | |
11188 | * This is not being used for older platforms, because | |
11189 | * non-availability of flip done interrupt forces us to use | |
11190 | * CS flips. Older platforms derive flip done using some clever | |
11191 | * tricks involving the flip_pending status bits and vblank irqs. | |
11192 | * So using MMIO flips there would disrupt this mechanism. | |
11193 | */ | |
11194 | ||
8e09bf83 CW |
11195 | if (ring == NULL) |
11196 | return true; | |
11197 | ||
84c33a64 SG |
11198 | if (INTEL_INFO(ring->dev)->gen < 5) |
11199 | return false; | |
11200 | ||
11201 | if (i915.use_mmio_flip < 0) | |
11202 | return false; | |
11203 | else if (i915.use_mmio_flip > 0) | |
11204 | return true; | |
14bf993e OM |
11205 | else if (i915.enable_execlists) |
11206 | return true; | |
84c33a64 | 11207 | else |
b4716185 | 11208 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11209 | } |
11210 | ||
6042639c | 11211 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
86efe24a | 11212 | unsigned int rotation, |
6042639c | 11213 | struct intel_unpin_work *work) |
ff944564 DL |
11214 | { |
11215 | struct drm_device *dev = intel_crtc->base.dev; | |
11216 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11217 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 | 11218 | const enum pipe pipe = intel_crtc->pipe; |
86efe24a | 11219 | u32 ctl, stride, tile_height; |
ff944564 DL |
11220 | |
11221 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11222 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11223 | switch (fb->modifier[0]) { |
11224 | case DRM_FORMAT_MOD_NONE: | |
11225 | break; | |
11226 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11227 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11228 | break; |
11229 | case I915_FORMAT_MOD_Y_TILED: | |
11230 | ctl |= PLANE_CTL_TILED_Y; | |
11231 | break; | |
11232 | case I915_FORMAT_MOD_Yf_TILED: | |
11233 | ctl |= PLANE_CTL_TILED_YF; | |
11234 | break; | |
11235 | default: | |
11236 | MISSING_CASE(fb->modifier[0]); | |
11237 | } | |
ff944564 DL |
11238 | |
11239 | /* | |
11240 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11241 | * linear buffers or in number of tiles for tiled buffers. | |
11242 | */ | |
86efe24a TU |
11243 | if (intel_rotation_90_or_270(rotation)) { |
11244 | /* stride = Surface height in tiles */ | |
11245 | tile_height = intel_tile_height(dev, fb->pixel_format, | |
11246 | fb->modifier[0], 0); | |
11247 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11248 | } else { | |
11249 | stride = fb->pitches[0] / | |
11250 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11251 | fb->pixel_format); | |
11252 | } | |
ff944564 DL |
11253 | |
11254 | /* | |
11255 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11256 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11257 | */ | |
11258 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11259 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11260 | ||
6042639c | 11261 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
ff944564 DL |
11262 | POSTING_READ(PLANE_SURF(pipe, 0)); |
11263 | } | |
11264 | ||
6042639c CW |
11265 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
11266 | struct intel_unpin_work *work) | |
84c33a64 SG |
11267 | { |
11268 | struct drm_device *dev = intel_crtc->base.dev; | |
11269 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11270 | struct intel_framebuffer *intel_fb = | |
11271 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11272 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
f0f59a00 | 11273 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
84c33a64 | 11274 | u32 dspcntr; |
84c33a64 | 11275 | |
84c33a64 SG |
11276 | dspcntr = I915_READ(reg); |
11277 | ||
c5d97472 DL |
11278 | if (obj->tiling_mode != I915_TILING_NONE) |
11279 | dspcntr |= DISPPLANE_TILED; | |
11280 | else | |
11281 | dspcntr &= ~DISPPLANE_TILED; | |
11282 | ||
84c33a64 SG |
11283 | I915_WRITE(reg, dspcntr); |
11284 | ||
6042639c | 11285 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
84c33a64 | 11286 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
ff944564 DL |
11287 | } |
11288 | ||
11289 | /* | |
11290 | * XXX: This is the temporary way to update the plane registers until we get | |
11291 | * around to using the usual plane update functions for MMIO flips | |
11292 | */ | |
6042639c | 11293 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
ff944564 | 11294 | { |
6042639c CW |
11295 | struct intel_crtc *crtc = mmio_flip->crtc; |
11296 | struct intel_unpin_work *work; | |
11297 | ||
11298 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11299 | work = crtc->unpin_work; | |
11300 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11301 | if (work == NULL) | |
11302 | return; | |
ff944564 | 11303 | |
6042639c | 11304 | intel_mark_page_flip_active(work); |
ff944564 | 11305 | |
6042639c | 11306 | intel_pipe_update_start(crtc); |
ff944564 | 11307 | |
6042639c | 11308 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
86efe24a | 11309 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
ff944564 DL |
11310 | else |
11311 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
6042639c | 11312 | ilk_do_mmio_flip(crtc, work); |
ff944564 | 11313 | |
6042639c | 11314 | intel_pipe_update_end(crtc); |
84c33a64 SG |
11315 | } |
11316 | ||
9362c7c5 | 11317 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11318 | { |
b2cfe0ab CW |
11319 | struct intel_mmio_flip *mmio_flip = |
11320 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11321 | |
6042639c | 11322 | if (mmio_flip->req) { |
eed29a5b | 11323 | WARN_ON(__i915_wait_request(mmio_flip->req, |
b2cfe0ab | 11324 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11325 | false, NULL, |
11326 | &mmio_flip->i915->rps.mmioflips)); | |
6042639c CW |
11327 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
11328 | } | |
84c33a64 | 11329 | |
6042639c | 11330 | intel_do_mmio_flip(mmio_flip); |
b2cfe0ab | 11331 | kfree(mmio_flip); |
84c33a64 SG |
11332 | } |
11333 | ||
11334 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11335 | struct drm_crtc *crtc, | |
86efe24a | 11336 | struct drm_i915_gem_object *obj) |
84c33a64 | 11337 | { |
b2cfe0ab CW |
11338 | struct intel_mmio_flip *mmio_flip; |
11339 | ||
11340 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11341 | if (mmio_flip == NULL) | |
11342 | return -ENOMEM; | |
84c33a64 | 11343 | |
bcafc4e3 | 11344 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11345 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11346 | mmio_flip->crtc = to_intel_crtc(crtc); |
86efe24a | 11347 | mmio_flip->rotation = crtc->primary->state->rotation; |
536f5b5e | 11348 | |
b2cfe0ab CW |
11349 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11350 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11351 | |
84c33a64 SG |
11352 | return 0; |
11353 | } | |
11354 | ||
8c9f3aaf JB |
11355 | static int intel_default_queue_flip(struct drm_device *dev, |
11356 | struct drm_crtc *crtc, | |
11357 | struct drm_framebuffer *fb, | |
ed8d1975 | 11358 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11359 | struct drm_i915_gem_request *req, |
ed8d1975 | 11360 | uint32_t flags) |
8c9f3aaf JB |
11361 | { |
11362 | return -ENODEV; | |
11363 | } | |
11364 | ||
d6bbafa1 CW |
11365 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11366 | struct drm_crtc *crtc) | |
11367 | { | |
11368 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11369 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11370 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11371 | u32 addr; | |
11372 | ||
11373 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11374 | return true; | |
11375 | ||
908565c2 CW |
11376 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11377 | return false; | |
11378 | ||
d6bbafa1 CW |
11379 | if (!work->enable_stall_check) |
11380 | return false; | |
11381 | ||
11382 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11383 | if (work->flip_queued_req && |
11384 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11385 | return false; |
11386 | ||
1e3feefd | 11387 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11388 | } |
11389 | ||
1e3feefd | 11390 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11391 | return false; |
11392 | ||
11393 | /* Potential stall - if we see that the flip has happened, | |
11394 | * assume a missed interrupt. */ | |
11395 | if (INTEL_INFO(dev)->gen >= 4) | |
11396 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11397 | else | |
11398 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11399 | ||
11400 | /* There is a potential issue here with a false positive after a flip | |
11401 | * to the same address. We could address this by checking for a | |
11402 | * non-incrementing frame counter. | |
11403 | */ | |
11404 | return addr == work->gtt_offset; | |
11405 | } | |
11406 | ||
11407 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11408 | { | |
11409 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11410 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11411 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11412 | struct intel_unpin_work *work; |
f326038a | 11413 | |
6c51d46f | 11414 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11415 | |
11416 | if (crtc == NULL) | |
11417 | return; | |
11418 | ||
f326038a | 11419 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11420 | work = intel_crtc->unpin_work; |
11421 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11422 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11423 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11424 | page_flip_completed(intel_crtc); |
6ad790c0 | 11425 | work = NULL; |
d6bbafa1 | 11426 | } |
6ad790c0 CW |
11427 | if (work != NULL && |
11428 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11429 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11430 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11431 | } |
11432 | ||
6b95a207 KH |
11433 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11434 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11435 | struct drm_pending_vblank_event *event, |
11436 | uint32_t page_flip_flags) | |
6b95a207 KH |
11437 | { |
11438 | struct drm_device *dev = crtc->dev; | |
11439 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11440 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11441 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11442 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11443 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11444 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11445 | struct intel_unpin_work *work; |
a4872ba6 | 11446 | struct intel_engine_cs *ring; |
cf5d8a46 | 11447 | bool mmio_flip; |
91af127f | 11448 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11449 | int ret; |
6b95a207 | 11450 | |
2ff8fde1 MR |
11451 | /* |
11452 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11453 | * check to be safe. In the future we may enable pageflipping from | |
11454 | * a disabled primary plane. | |
11455 | */ | |
11456 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11457 | return -EBUSY; | |
11458 | ||
e6a595d2 | 11459 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11460 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11461 | return -EINVAL; |
11462 | ||
11463 | /* | |
11464 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11465 | * Note that pitch changes could also affect these register. | |
11466 | */ | |
11467 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11468 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11469 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11470 | return -EINVAL; |
11471 | ||
f900db47 CW |
11472 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11473 | goto out_hang; | |
11474 | ||
b14c5679 | 11475 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11476 | if (work == NULL) |
11477 | return -ENOMEM; | |
11478 | ||
6b95a207 | 11479 | work->event = event; |
b4a98e57 | 11480 | work->crtc = crtc; |
ab8d6675 | 11481 | work->old_fb = old_fb; |
6b95a207 KH |
11482 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11483 | ||
87b6b101 | 11484 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11485 | if (ret) |
11486 | goto free_work; | |
11487 | ||
6b95a207 | 11488 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11489 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11490 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11491 | /* Before declaring the flip queue wedged, check if |
11492 | * the hardware completed the operation behind our backs. | |
11493 | */ | |
11494 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11495 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11496 | page_flip_completed(intel_crtc); | |
11497 | } else { | |
11498 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11499 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11500 | |
d6bbafa1 CW |
11501 | drm_crtc_vblank_put(crtc); |
11502 | kfree(work); | |
11503 | return -EBUSY; | |
11504 | } | |
6b95a207 KH |
11505 | } |
11506 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11507 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11508 | |
b4a98e57 CW |
11509 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11510 | flush_workqueue(dev_priv->wq); | |
11511 | ||
75dfca80 | 11512 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11513 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11514 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11515 | |
f4510a27 | 11516 | crtc->primary->fb = fb; |
afd65eb4 | 11517 | update_state_fb(crtc->primary); |
1ed1f968 | 11518 | |
e1f99ce6 | 11519 | work->pending_flip_obj = obj; |
e1f99ce6 | 11520 | |
89ed88ba CW |
11521 | ret = i915_mutex_lock_interruptible(dev); |
11522 | if (ret) | |
11523 | goto cleanup; | |
11524 | ||
b4a98e57 | 11525 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11526 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11527 | |
75f7f3ec | 11528 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
fd8f507c | 11529 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
75f7f3ec | 11530 | |
4fa62c89 VS |
11531 | if (IS_VALLEYVIEW(dev)) { |
11532 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11533 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11534 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11535 | ring = NULL; | |
48bf5b2d | 11536 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11537 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11538 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11539 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11540 | if (ring == NULL || ring->id != RCS) |
11541 | ring = &dev_priv->ring[BCS]; | |
11542 | } else { | |
11543 | ring = &dev_priv->ring[RCS]; | |
11544 | } | |
11545 | ||
cf5d8a46 CW |
11546 | mmio_flip = use_mmio_flip(ring, obj); |
11547 | ||
11548 | /* When using CS flips, we want to emit semaphores between rings. | |
11549 | * However, when using mmio flips we will create a task to do the | |
11550 | * synchronisation, so all we want here is to pin the framebuffer | |
11551 | * into the display plane and skip any waits. | |
11552 | */ | |
7580d774 ML |
11553 | if (!mmio_flip) { |
11554 | ret = i915_gem_object_sync(obj, ring, &request); | |
11555 | if (ret) | |
11556 | goto cleanup_pending; | |
11557 | } | |
11558 | ||
82bc3b2d | 11559 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
7580d774 | 11560 | crtc->primary->state); |
8c9f3aaf JB |
11561 | if (ret) |
11562 | goto cleanup_pending; | |
6b95a207 | 11563 | |
dedf278c TU |
11564 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
11565 | obj, 0); | |
11566 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
4fa62c89 | 11567 | |
cf5d8a46 | 11568 | if (mmio_flip) { |
86efe24a | 11569 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
d6bbafa1 CW |
11570 | if (ret) |
11571 | goto cleanup_unpin; | |
11572 | ||
f06cc1b9 JH |
11573 | i915_gem_request_assign(&work->flip_queued_req, |
11574 | obj->last_write_req); | |
d6bbafa1 | 11575 | } else { |
6258fbe2 JH |
11576 | if (!request) { |
11577 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); | |
11578 | if (ret) | |
11579 | goto cleanup_unpin; | |
11580 | } | |
11581 | ||
11582 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11583 | page_flip_flags); |
11584 | if (ret) | |
11585 | goto cleanup_unpin; | |
11586 | ||
6258fbe2 | 11587 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11588 | } |
11589 | ||
91af127f | 11590 | if (request) |
75289874 | 11591 | i915_add_request_no_flush(request); |
91af127f | 11592 | |
1e3feefd | 11593 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11594 | work->enable_stall_check = true; |
4fa62c89 | 11595 | |
ab8d6675 | 11596 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11597 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11598 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11599 | |
d029bcad | 11600 | intel_fbc_deactivate(intel_crtc); |
a9ff8714 VS |
11601 | intel_frontbuffer_flip_prepare(dev, |
11602 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11603 | |
e5510fac JB |
11604 | trace_i915_flip_request(intel_crtc->plane, obj); |
11605 | ||
6b95a207 | 11606 | return 0; |
96b099fd | 11607 | |
4fa62c89 | 11608 | cleanup_unpin: |
82bc3b2d | 11609 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11610 | cleanup_pending: |
91af127f JH |
11611 | if (request) |
11612 | i915_gem_request_cancel(request); | |
b4a98e57 | 11613 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11614 | mutex_unlock(&dev->struct_mutex); |
11615 | cleanup: | |
f4510a27 | 11616 | crtc->primary->fb = old_fb; |
afd65eb4 | 11617 | update_state_fb(crtc->primary); |
89ed88ba CW |
11618 | |
11619 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11620 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11621 | |
5e2d7afc | 11622 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11623 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11624 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11625 | |
87b6b101 | 11626 | drm_crtc_vblank_put(crtc); |
7317c75e | 11627 | free_work: |
96b099fd CW |
11628 | kfree(work); |
11629 | ||
f900db47 | 11630 | if (ret == -EIO) { |
02e0efb5 ML |
11631 | struct drm_atomic_state *state; |
11632 | struct drm_plane_state *plane_state; | |
11633 | ||
f900db47 | 11634 | out_hang: |
02e0efb5 ML |
11635 | state = drm_atomic_state_alloc(dev); |
11636 | if (!state) | |
11637 | return -ENOMEM; | |
11638 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11639 | ||
11640 | retry: | |
11641 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11642 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11643 | if (!ret) { | |
11644 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11645 | ||
11646 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11647 | if (!ret) | |
11648 | ret = drm_atomic_commit(state); | |
11649 | } | |
11650 | ||
11651 | if (ret == -EDEADLK) { | |
11652 | drm_modeset_backoff(state->acquire_ctx); | |
11653 | drm_atomic_state_clear(state); | |
11654 | goto retry; | |
11655 | } | |
11656 | ||
11657 | if (ret) | |
11658 | drm_atomic_state_free(state); | |
11659 | ||
f0d3dad3 | 11660 | if (ret == 0 && event) { |
5e2d7afc | 11661 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11662 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11663 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11664 | } |
f900db47 | 11665 | } |
96b099fd | 11666 | return ret; |
6b95a207 KH |
11667 | } |
11668 | ||
da20eabd ML |
11669 | |
11670 | /** | |
11671 | * intel_wm_need_update - Check whether watermarks need updating | |
11672 | * @plane: drm plane | |
11673 | * @state: new plane state | |
11674 | * | |
11675 | * Check current plane state versus the new one to determine whether | |
11676 | * watermarks need to be recalculated. | |
11677 | * | |
11678 | * Returns true or false. | |
11679 | */ | |
11680 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11681 | struct drm_plane_state *state) | |
11682 | { | |
d21fbe87 MR |
11683 | struct intel_plane_state *new = to_intel_plane_state(state); |
11684 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11685 | ||
11686 | /* Update watermarks on tiling or size changes. */ | |
da20eabd ML |
11687 | if (!plane->state->fb || !state->fb || |
11688 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
d21fbe87 MR |
11689 | plane->state->rotation != state->rotation || |
11690 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11691 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11692 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11693 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
2791a16c | 11694 | return true; |
7809e5ae | 11695 | |
2791a16c | 11696 | return false; |
7809e5ae MR |
11697 | } |
11698 | ||
d21fbe87 MR |
11699 | static bool needs_scaling(struct intel_plane_state *state) |
11700 | { | |
11701 | int src_w = drm_rect_width(&state->src) >> 16; | |
11702 | int src_h = drm_rect_height(&state->src) >> 16; | |
11703 | int dst_w = drm_rect_width(&state->dst); | |
11704 | int dst_h = drm_rect_height(&state->dst); | |
11705 | ||
11706 | return (src_w != dst_w || src_h != dst_h); | |
11707 | } | |
11708 | ||
da20eabd ML |
11709 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11710 | struct drm_plane_state *plane_state) | |
11711 | { | |
11712 | struct drm_crtc *crtc = crtc_state->crtc; | |
11713 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11714 | struct drm_plane *plane = plane_state->plane; | |
11715 | struct drm_device *dev = crtc->dev; | |
11716 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11717 | struct intel_plane_state *old_plane_state = | |
11718 | to_intel_plane_state(plane->state); | |
11719 | int idx = intel_crtc->base.base.id, ret; | |
11720 | int i = drm_plane_index(plane); | |
11721 | bool mode_changed = needs_modeset(crtc_state); | |
11722 | bool was_crtc_enabled = crtc->state->active; | |
11723 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11724 | bool turn_off, turn_on, visible, was_visible; |
11725 | struct drm_framebuffer *fb = plane_state->fb; | |
11726 | ||
11727 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11728 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11729 | ret = skl_update_scaler_plane( | |
11730 | to_intel_crtc_state(crtc_state), | |
11731 | to_intel_plane_state(plane_state)); | |
11732 | if (ret) | |
11733 | return ret; | |
11734 | } | |
11735 | ||
da20eabd ML |
11736 | was_visible = old_plane_state->visible; |
11737 | visible = to_intel_plane_state(plane_state)->visible; | |
11738 | ||
11739 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11740 | was_visible = false; | |
11741 | ||
11742 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11743 | visible = false; | |
11744 | ||
11745 | if (!was_visible && !visible) | |
11746 | return 0; | |
11747 | ||
11748 | turn_off = was_visible && (!visible || mode_changed); | |
11749 | turn_on = visible && (!was_visible || mode_changed); | |
11750 | ||
11751 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11752 | plane->base.id, fb ? fb->base.id : -1); | |
11753 | ||
11754 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11755 | plane->base.id, was_visible, visible, | |
11756 | turn_off, turn_on, mode_changed); | |
11757 | ||
852eb00d | 11758 | if (turn_on) { |
f015c551 | 11759 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d VS |
11760 | /* must disable cxsr around plane enable/disable */ |
11761 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11762 | intel_crtc->atomic.disable_cxsr = true; | |
11763 | /* to potentially re-enable cxsr */ | |
11764 | intel_crtc->atomic.wait_vblank = true; | |
11765 | intel_crtc->atomic.update_wm_post = true; | |
11766 | } | |
11767 | } else if (turn_off) { | |
f015c551 | 11768 | intel_crtc->atomic.update_wm_post = true; |
852eb00d VS |
11769 | /* must disable cxsr around plane enable/disable */ |
11770 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11771 | if (is_crtc_enabled) | |
11772 | intel_crtc->atomic.wait_vblank = true; | |
11773 | intel_crtc->atomic.disable_cxsr = true; | |
11774 | } | |
11775 | } else if (intel_wm_need_update(plane, plane_state)) { | |
f015c551 | 11776 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d | 11777 | } |
da20eabd | 11778 | |
8be6ca85 | 11779 | if (visible || was_visible) |
a9ff8714 VS |
11780 | intel_crtc->atomic.fb_bits |= |
11781 | to_intel_plane(plane)->frontbuffer_bit; | |
11782 | ||
da20eabd ML |
11783 | switch (plane->type) { |
11784 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd ML |
11785 | intel_crtc->atomic.pre_disable_primary = turn_off; |
11786 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11787 | ||
066cf55b RV |
11788 | if (turn_off) { |
11789 | /* | |
11790 | * FIXME: Actually if we will still have any other | |
11791 | * plane enabled on the pipe we could let IPS enabled | |
11792 | * still, but for now lets consider that when we make | |
11793 | * primary invisible by setting DSPCNTR to 0 on | |
11794 | * update_primary_plane function IPS needs to be | |
11795 | * disable. | |
11796 | */ | |
11797 | intel_crtc->atomic.disable_ips = true; | |
11798 | ||
da20eabd | 11799 | intel_crtc->atomic.disable_fbc = true; |
066cf55b | 11800 | } |
da20eabd ML |
11801 | |
11802 | /* | |
11803 | * FBC does not work on some platforms for rotated | |
11804 | * planes, so disable it when rotation is not 0 and | |
11805 | * update it when rotation is set back to 0. | |
11806 | * | |
11807 | * FIXME: This is redundant with the fbc update done in | |
11808 | * the primary plane enable function except that that | |
11809 | * one is done too late. We eventually need to unify | |
11810 | * this. | |
11811 | */ | |
11812 | ||
11813 | if (visible && | |
11814 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11815 | dev_priv->fbc.crtc == intel_crtc && | |
11816 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11817 | intel_crtc->atomic.disable_fbc = true; | |
11818 | ||
11819 | /* | |
11820 | * BDW signals flip done immediately if the plane | |
11821 | * is disabled, even if the plane enable is already | |
11822 | * armed to occur at the next vblank :( | |
11823 | */ | |
11824 | if (turn_on && IS_BROADWELL(dev)) | |
11825 | intel_crtc->atomic.wait_vblank = true; | |
11826 | ||
11827 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11828 | break; | |
11829 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11830 | break; |
11831 | case DRM_PLANE_TYPE_OVERLAY: | |
d21fbe87 MR |
11832 | /* |
11833 | * WaCxSRDisabledForSpriteScaling:ivb | |
11834 | * | |
11835 | * cstate->update_wm was already set above, so this flag will | |
11836 | * take effect when we commit and program watermarks. | |
11837 | */ | |
11838 | if (IS_IVYBRIDGE(dev) && | |
11839 | needs_scaling(to_intel_plane_state(plane_state)) && | |
11840 | !needs_scaling(old_plane_state)) { | |
11841 | to_intel_crtc_state(crtc_state)->disable_lp_wm = true; | |
11842 | } else if (turn_off && !mode_changed) { | |
da20eabd ML |
11843 | intel_crtc->atomic.wait_vblank = true; |
11844 | intel_crtc->atomic.update_sprite_watermarks |= | |
11845 | 1 << i; | |
11846 | } | |
d21fbe87 MR |
11847 | |
11848 | break; | |
da20eabd ML |
11849 | } |
11850 | return 0; | |
11851 | } | |
11852 | ||
6d3a1ce7 ML |
11853 | static bool encoders_cloneable(const struct intel_encoder *a, |
11854 | const struct intel_encoder *b) | |
11855 | { | |
11856 | /* masks could be asymmetric, so check both ways */ | |
11857 | return a == b || (a->cloneable & (1 << b->type) && | |
11858 | b->cloneable & (1 << a->type)); | |
11859 | } | |
11860 | ||
11861 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11862 | struct intel_crtc *crtc, | |
11863 | struct intel_encoder *encoder) | |
11864 | { | |
11865 | struct intel_encoder *source_encoder; | |
11866 | struct drm_connector *connector; | |
11867 | struct drm_connector_state *connector_state; | |
11868 | int i; | |
11869 | ||
11870 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11871 | if (connector_state->crtc != &crtc->base) | |
11872 | continue; | |
11873 | ||
11874 | source_encoder = | |
11875 | to_intel_encoder(connector_state->best_encoder); | |
11876 | if (!encoders_cloneable(encoder, source_encoder)) | |
11877 | return false; | |
11878 | } | |
11879 | ||
11880 | return true; | |
11881 | } | |
11882 | ||
11883 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11884 | struct intel_crtc *crtc) | |
11885 | { | |
11886 | struct intel_encoder *encoder; | |
11887 | struct drm_connector *connector; | |
11888 | struct drm_connector_state *connector_state; | |
11889 | int i; | |
11890 | ||
11891 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11892 | if (connector_state->crtc != &crtc->base) | |
11893 | continue; | |
11894 | ||
11895 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11896 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11897 | return false; | |
11898 | } | |
11899 | ||
11900 | return true; | |
11901 | } | |
11902 | ||
11903 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11904 | struct drm_crtc_state *crtc_state) | |
11905 | { | |
cf5a15be | 11906 | struct drm_device *dev = crtc->dev; |
ad421372 | 11907 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11908 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11909 | struct intel_crtc_state *pipe_config = |
11910 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11911 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 11912 | int ret; |
6d3a1ce7 ML |
11913 | bool mode_changed = needs_modeset(crtc_state); |
11914 | ||
11915 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11916 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11917 | return -EINVAL; | |
11918 | } | |
11919 | ||
852eb00d VS |
11920 | if (mode_changed && !crtc_state->active) |
11921 | intel_crtc->atomic.update_wm_post = true; | |
eddfcbcd | 11922 | |
ad421372 ML |
11923 | if (mode_changed && crtc_state->enable && |
11924 | dev_priv->display.crtc_compute_clock && | |
11925 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11926 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11927 | pipe_config); | |
11928 | if (ret) | |
11929 | return ret; | |
11930 | } | |
11931 | ||
e435d6e5 | 11932 | ret = 0; |
86c8bbbe MR |
11933 | if (dev_priv->display.compute_pipe_wm) { |
11934 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
11935 | if (ret) | |
11936 | return ret; | |
11937 | } | |
11938 | ||
e435d6e5 ML |
11939 | if (INTEL_INFO(dev)->gen >= 9) { |
11940 | if (mode_changed) | |
11941 | ret = skl_update_scaler_crtc(pipe_config); | |
11942 | ||
11943 | if (!ret) | |
11944 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
11945 | pipe_config); | |
11946 | } | |
11947 | ||
11948 | return ret; | |
6d3a1ce7 ML |
11949 | } |
11950 | ||
65b38e0d | 11951 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11952 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11953 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11954 | .atomic_begin = intel_begin_crtc_commit, |
11955 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11956 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11957 | }; |
11958 | ||
d29b2f9d ACO |
11959 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
11960 | { | |
11961 | struct intel_connector *connector; | |
11962 | ||
11963 | for_each_intel_connector(dev, connector) { | |
11964 | if (connector->base.encoder) { | |
11965 | connector->base.state->best_encoder = | |
11966 | connector->base.encoder; | |
11967 | connector->base.state->crtc = | |
11968 | connector->base.encoder->crtc; | |
11969 | } else { | |
11970 | connector->base.state->best_encoder = NULL; | |
11971 | connector->base.state->crtc = NULL; | |
11972 | } | |
11973 | } | |
11974 | } | |
11975 | ||
050f7aeb | 11976 | static void |
eba905b2 | 11977 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11978 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11979 | { |
11980 | int bpp = pipe_config->pipe_bpp; | |
11981 | ||
11982 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11983 | connector->base.base.id, | |
c23cc417 | 11984 | connector->base.name); |
050f7aeb DV |
11985 | |
11986 | /* Don't use an invalid EDID bpc value */ | |
11987 | if (connector->base.display_info.bpc && | |
11988 | connector->base.display_info.bpc * 3 < bpp) { | |
11989 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11990 | bpp, connector->base.display_info.bpc*3); | |
11991 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11992 | } | |
11993 | ||
11994 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11995 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11996 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11997 | bpp); | |
11998 | pipe_config->pipe_bpp = 24; | |
11999 | } | |
12000 | } | |
12001 | ||
4e53c2e0 | 12002 | static int |
050f7aeb | 12003 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 12004 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 12005 | { |
050f7aeb | 12006 | struct drm_device *dev = crtc->base.dev; |
1486017f | 12007 | struct drm_atomic_state *state; |
da3ced29 ACO |
12008 | struct drm_connector *connector; |
12009 | struct drm_connector_state *connector_state; | |
1486017f | 12010 | int bpp, i; |
4e53c2e0 | 12011 | |
d328c9d7 | 12012 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 12013 | bpp = 10*3; |
d328c9d7 DV |
12014 | else if (INTEL_INFO(dev)->gen >= 5) |
12015 | bpp = 12*3; | |
12016 | else | |
12017 | bpp = 8*3; | |
12018 | ||
4e53c2e0 | 12019 | |
4e53c2e0 DV |
12020 | pipe_config->pipe_bpp = bpp; |
12021 | ||
1486017f ACO |
12022 | state = pipe_config->base.state; |
12023 | ||
4e53c2e0 | 12024 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
12025 | for_each_connector_in_state(state, connector, connector_state, i) { |
12026 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
12027 | continue; |
12028 | ||
da3ced29 ACO |
12029 | connected_sink_compute_bpp(to_intel_connector(connector), |
12030 | pipe_config); | |
4e53c2e0 DV |
12031 | } |
12032 | ||
12033 | return bpp; | |
12034 | } | |
12035 | ||
644db711 DV |
12036 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
12037 | { | |
12038 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
12039 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 12040 | mode->crtc_clock, |
644db711 DV |
12041 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
12042 | mode->crtc_hsync_end, mode->crtc_htotal, | |
12043 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
12044 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
12045 | } | |
12046 | ||
c0b03411 | 12047 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 12048 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
12049 | const char *context) |
12050 | { | |
6a60cd87 CK |
12051 | struct drm_device *dev = crtc->base.dev; |
12052 | struct drm_plane *plane; | |
12053 | struct intel_plane *intel_plane; | |
12054 | struct intel_plane_state *state; | |
12055 | struct drm_framebuffer *fb; | |
12056 | ||
12057 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
12058 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
12059 | |
12060 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
12061 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
12062 | pipe_config->pipe_bpp, pipe_config->dither); | |
12063 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12064 | pipe_config->has_pch_encoder, | |
12065 | pipe_config->fdi_lanes, | |
12066 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
12067 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
12068 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 12069 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 12070 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12071 | pipe_config->lane_count, |
eb14cb74 VS |
12072 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
12073 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
12074 | pipe_config->dp_m_n.tu); | |
b95af8be | 12075 | |
90a6b7b0 | 12076 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 12077 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12078 | pipe_config->lane_count, |
b95af8be VK |
12079 | pipe_config->dp_m2_n2.gmch_m, |
12080 | pipe_config->dp_m2_n2.gmch_n, | |
12081 | pipe_config->dp_m2_n2.link_m, | |
12082 | pipe_config->dp_m2_n2.link_n, | |
12083 | pipe_config->dp_m2_n2.tu); | |
12084 | ||
55072d19 DV |
12085 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
12086 | pipe_config->has_audio, | |
12087 | pipe_config->has_infoframe); | |
12088 | ||
c0b03411 | 12089 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 12090 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 12091 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
12092 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
12093 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 12094 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
12095 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
12096 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
12097 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
12098 | crtc->num_scalers, | |
12099 | pipe_config->scaler_state.scaler_users, | |
12100 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
12101 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12102 | pipe_config->gmch_pfit.control, | |
12103 | pipe_config->gmch_pfit.pgm_ratios, | |
12104 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12105 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12106 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12107 | pipe_config->pch_pfit.size, |
12108 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12109 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12110 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12111 | |
415ff0f6 | 12112 | if (IS_BROXTON(dev)) { |
05712c15 | 12113 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12114 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12115 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12116 | pipe_config->ddi_pll_sel, |
12117 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12118 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12119 | pipe_config->dpll_hw_state.pll0, |
12120 | pipe_config->dpll_hw_state.pll1, | |
12121 | pipe_config->dpll_hw_state.pll2, | |
12122 | pipe_config->dpll_hw_state.pll3, | |
12123 | pipe_config->dpll_hw_state.pll6, | |
12124 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12125 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12126 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12127 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12128 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12129 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12130 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12131 | pipe_config->ddi_pll_sel, | |
12132 | pipe_config->dpll_hw_state.ctrl1, | |
12133 | pipe_config->dpll_hw_state.cfgcr1, | |
12134 | pipe_config->dpll_hw_state.cfgcr2); | |
12135 | } else if (HAS_DDI(dev)) { | |
00490c22 | 12136 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", |
415ff0f6 | 12137 | pipe_config->ddi_pll_sel, |
00490c22 ML |
12138 | pipe_config->dpll_hw_state.wrpll, |
12139 | pipe_config->dpll_hw_state.spll); | |
415ff0f6 TU |
12140 | } else { |
12141 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12142 | "fp0: 0x%x, fp1: 0x%x\n", | |
12143 | pipe_config->dpll_hw_state.dpll, | |
12144 | pipe_config->dpll_hw_state.dpll_md, | |
12145 | pipe_config->dpll_hw_state.fp0, | |
12146 | pipe_config->dpll_hw_state.fp1); | |
12147 | } | |
12148 | ||
6a60cd87 CK |
12149 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12150 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12151 | intel_plane = to_intel_plane(plane); | |
12152 | if (intel_plane->pipe != crtc->pipe) | |
12153 | continue; | |
12154 | ||
12155 | state = to_intel_plane_state(plane->state); | |
12156 | fb = state->base.fb; | |
12157 | if (!fb) { | |
12158 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12159 | "disabled, scaler_id = %d\n", | |
12160 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12161 | plane->base.id, intel_plane->pipe, | |
12162 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12163 | drm_plane_index(plane), state->scaler_id); | |
12164 | continue; | |
12165 | } | |
12166 | ||
12167 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12168 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12169 | plane->base.id, intel_plane->pipe, | |
12170 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12171 | drm_plane_index(plane)); | |
12172 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12173 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12174 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12175 | state->scaler_id, | |
12176 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12177 | drm_rect_width(&state->src) >> 16, | |
12178 | drm_rect_height(&state->src) >> 16, | |
12179 | state->dst.x1, state->dst.y1, | |
12180 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12181 | } | |
c0b03411 DV |
12182 | } |
12183 | ||
5448a00d | 12184 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12185 | { |
5448a00d ACO |
12186 | struct drm_device *dev = state->dev; |
12187 | struct intel_encoder *encoder; | |
da3ced29 | 12188 | struct drm_connector *connector; |
5448a00d | 12189 | struct drm_connector_state *connector_state; |
00f0b378 | 12190 | unsigned int used_ports = 0; |
5448a00d | 12191 | int i; |
00f0b378 VS |
12192 | |
12193 | /* | |
12194 | * Walk the connector list instead of the encoder | |
12195 | * list to detect the problem on ddi platforms | |
12196 | * where there's just one encoder per digital port. | |
12197 | */ | |
da3ced29 | 12198 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12199 | if (!connector_state->best_encoder) |
00f0b378 VS |
12200 | continue; |
12201 | ||
5448a00d ACO |
12202 | encoder = to_intel_encoder(connector_state->best_encoder); |
12203 | ||
12204 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12205 | |
12206 | switch (encoder->type) { | |
12207 | unsigned int port_mask; | |
12208 | case INTEL_OUTPUT_UNKNOWN: | |
12209 | if (WARN_ON(!HAS_DDI(dev))) | |
12210 | break; | |
12211 | case INTEL_OUTPUT_DISPLAYPORT: | |
12212 | case INTEL_OUTPUT_HDMI: | |
12213 | case INTEL_OUTPUT_EDP: | |
12214 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12215 | ||
12216 | /* the same port mustn't appear more than once */ | |
12217 | if (used_ports & port_mask) | |
12218 | return false; | |
12219 | ||
12220 | used_ports |= port_mask; | |
12221 | default: | |
12222 | break; | |
12223 | } | |
12224 | } | |
12225 | ||
12226 | return true; | |
12227 | } | |
12228 | ||
83a57153 ACO |
12229 | static void |
12230 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12231 | { | |
12232 | struct drm_crtc_state tmp_state; | |
663a3640 | 12233 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12234 | struct intel_dpll_hw_state dpll_hw_state; |
12235 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12236 | uint32_t ddi_pll_sel; |
c4e2d043 | 12237 | bool force_thru; |
83a57153 | 12238 | |
7546a384 ACO |
12239 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12240 | * kzalloc'd. Code that depends on any field being zero should be | |
12241 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12242 | * only fields that are know to not cause problems are preserved. */ | |
12243 | ||
83a57153 | 12244 | tmp_state = crtc_state->base; |
663a3640 | 12245 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12246 | shared_dpll = crtc_state->shared_dpll; |
12247 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12248 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12249 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12250 | |
83a57153 | 12251 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12252 | |
83a57153 | 12253 | crtc_state->base = tmp_state; |
663a3640 | 12254 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12255 | crtc_state->shared_dpll = shared_dpll; |
12256 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12257 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12258 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12259 | } |
12260 | ||
548ee15b | 12261 | static int |
b8cecdf5 | 12262 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12263 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12264 | { |
b359283a | 12265 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12266 | struct intel_encoder *encoder; |
da3ced29 | 12267 | struct drm_connector *connector; |
0b901879 | 12268 | struct drm_connector_state *connector_state; |
d328c9d7 | 12269 | int base_bpp, ret = -EINVAL; |
0b901879 | 12270 | int i; |
e29c22c0 | 12271 | bool retry = true; |
ee7b9f93 | 12272 | |
83a57153 | 12273 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12274 | |
e143a21c DV |
12275 | pipe_config->cpu_transcoder = |
12276 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12277 | |
2960bc9c ID |
12278 | /* |
12279 | * Sanitize sync polarity flags based on requested ones. If neither | |
12280 | * positive or negative polarity is requested, treat this as meaning | |
12281 | * negative polarity. | |
12282 | */ | |
2d112de7 | 12283 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12284 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12285 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12286 | |
2d112de7 | 12287 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12288 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12289 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12290 | |
d328c9d7 DV |
12291 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12292 | pipe_config); | |
12293 | if (base_bpp < 0) | |
4e53c2e0 DV |
12294 | goto fail; |
12295 | ||
e41a56be VS |
12296 | /* |
12297 | * Determine the real pipe dimensions. Note that stereo modes can | |
12298 | * increase the actual pipe size due to the frame doubling and | |
12299 | * insertion of additional space for blanks between the frame. This | |
12300 | * is stored in the crtc timings. We use the requested mode to do this | |
12301 | * computation to clearly distinguish it from the adjusted mode, which | |
12302 | * can be changed by the connectors in the below retry loop. | |
12303 | */ | |
2d112de7 | 12304 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12305 | &pipe_config->pipe_src_w, |
12306 | &pipe_config->pipe_src_h); | |
e41a56be | 12307 | |
e29c22c0 | 12308 | encoder_retry: |
ef1b460d | 12309 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12310 | pipe_config->port_clock = 0; |
ef1b460d | 12311 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12312 | |
135c81b8 | 12313 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12314 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12315 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12316 | |
7758a113 DV |
12317 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12318 | * adjust it according to limitations or connector properties, and also | |
12319 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12320 | */ |
da3ced29 | 12321 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12322 | if (connector_state->crtc != crtc) |
7758a113 | 12323 | continue; |
7ae89233 | 12324 | |
0b901879 ACO |
12325 | encoder = to_intel_encoder(connector_state->best_encoder); |
12326 | ||
efea6e8e DV |
12327 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12328 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12329 | goto fail; |
12330 | } | |
ee7b9f93 | 12331 | } |
47f1c6c9 | 12332 | |
ff9a6750 DV |
12333 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12334 | * done afterwards in case the encoder adjusts the mode. */ | |
12335 | if (!pipe_config->port_clock) | |
2d112de7 | 12336 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12337 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12338 | |
a43f6e0f | 12339 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12340 | if (ret < 0) { |
7758a113 DV |
12341 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12342 | goto fail; | |
ee7b9f93 | 12343 | } |
e29c22c0 DV |
12344 | |
12345 | if (ret == RETRY) { | |
12346 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12347 | ret = -EINVAL; | |
12348 | goto fail; | |
12349 | } | |
12350 | ||
12351 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12352 | retry = false; | |
12353 | goto encoder_retry; | |
12354 | } | |
12355 | ||
e8fa4270 DV |
12356 | /* Dithering seems to not pass-through bits correctly when it should, so |
12357 | * only enable it on 6bpc panels. */ | |
12358 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12359 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12360 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12361 | |
7758a113 | 12362 | fail: |
548ee15b | 12363 | return ret; |
ee7b9f93 | 12364 | } |
47f1c6c9 | 12365 | |
ea9d758d | 12366 | static void |
4740b0f2 | 12367 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12368 | { |
0a9ab303 ACO |
12369 | struct drm_crtc *crtc; |
12370 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12371 | int i; |
ea9d758d | 12372 | |
7668851f | 12373 | /* Double check state. */ |
8a75d157 | 12374 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12375 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12376 | |
12377 | /* Update hwmode for vblank functions */ | |
12378 | if (crtc->state->active) | |
12379 | crtc->hwmode = crtc->state->adjusted_mode; | |
12380 | else | |
12381 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12382 | |
12383 | /* | |
12384 | * Update legacy state to satisfy fbc code. This can | |
12385 | * be removed when fbc uses the atomic state. | |
12386 | */ | |
12387 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12388 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12389 | ||
12390 | crtc->primary->fb = plane_state->fb; | |
12391 | crtc->x = plane_state->src_x >> 16; | |
12392 | crtc->y = plane_state->src_y >> 16; | |
12393 | } | |
ea9d758d | 12394 | } |
ea9d758d DV |
12395 | } |
12396 | ||
3bd26263 | 12397 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12398 | { |
3bd26263 | 12399 | int diff; |
f1f644dc JB |
12400 | |
12401 | if (clock1 == clock2) | |
12402 | return true; | |
12403 | ||
12404 | if (!clock1 || !clock2) | |
12405 | return false; | |
12406 | ||
12407 | diff = abs(clock1 - clock2); | |
12408 | ||
12409 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12410 | return true; | |
12411 | ||
12412 | return false; | |
12413 | } | |
12414 | ||
25c5b266 DV |
12415 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12416 | list_for_each_entry((intel_crtc), \ | |
12417 | &(dev)->mode_config.crtc_list, \ | |
12418 | base.head) \ | |
0973f18f | 12419 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12420 | |
cfb23ed6 ML |
12421 | static bool |
12422 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12423 | unsigned int m2, unsigned int n2, | |
12424 | bool exact) | |
12425 | { | |
12426 | if (m == m2 && n == n2) | |
12427 | return true; | |
12428 | ||
12429 | if (exact || !m || !n || !m2 || !n2) | |
12430 | return false; | |
12431 | ||
12432 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12433 | ||
12434 | if (m > m2) { | |
12435 | while (m > m2) { | |
12436 | m2 <<= 1; | |
12437 | n2 <<= 1; | |
12438 | } | |
12439 | } else if (m < m2) { | |
12440 | while (m < m2) { | |
12441 | m <<= 1; | |
12442 | n <<= 1; | |
12443 | } | |
12444 | } | |
12445 | ||
12446 | return m == m2 && n == n2; | |
12447 | } | |
12448 | ||
12449 | static bool | |
12450 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12451 | struct intel_link_m_n *m2_n2, | |
12452 | bool adjust) | |
12453 | { | |
12454 | if (m_n->tu == m2_n2->tu && | |
12455 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12456 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12457 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12458 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12459 | if (adjust) | |
12460 | *m2_n2 = *m_n; | |
12461 | ||
12462 | return true; | |
12463 | } | |
12464 | ||
12465 | return false; | |
12466 | } | |
12467 | ||
0e8ffe1b | 12468 | static bool |
2fa2fe9a | 12469 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12470 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12471 | struct intel_crtc_state *pipe_config, |
12472 | bool adjust) | |
0e8ffe1b | 12473 | { |
cfb23ed6 ML |
12474 | bool ret = true; |
12475 | ||
12476 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12477 | do { \ | |
12478 | if (!adjust) \ | |
12479 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12480 | else \ | |
12481 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12482 | } while (0) | |
12483 | ||
66e985c0 DV |
12484 | #define PIPE_CONF_CHECK_X(name) \ |
12485 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12486 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12487 | "(expected 0x%08x, found 0x%08x)\n", \ |
12488 | current_config->name, \ | |
12489 | pipe_config->name); \ | |
cfb23ed6 | 12490 | ret = false; \ |
66e985c0 DV |
12491 | } |
12492 | ||
08a24034 DV |
12493 | #define PIPE_CONF_CHECK_I(name) \ |
12494 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12495 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12496 | "(expected %i, found %i)\n", \ |
12497 | current_config->name, \ | |
12498 | pipe_config->name); \ | |
cfb23ed6 ML |
12499 | ret = false; \ |
12500 | } | |
12501 | ||
12502 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12503 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12504 | &pipe_config->name,\ | |
12505 | adjust)) { \ | |
12506 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12507 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12508 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12509 | current_config->name.tu, \ | |
12510 | current_config->name.gmch_m, \ | |
12511 | current_config->name.gmch_n, \ | |
12512 | current_config->name.link_m, \ | |
12513 | current_config->name.link_n, \ | |
12514 | pipe_config->name.tu, \ | |
12515 | pipe_config->name.gmch_m, \ | |
12516 | pipe_config->name.gmch_n, \ | |
12517 | pipe_config->name.link_m, \ | |
12518 | pipe_config->name.link_n); \ | |
12519 | ret = false; \ | |
12520 | } | |
12521 | ||
12522 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12523 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12524 | &pipe_config->name, adjust) && \ | |
12525 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12526 | &pipe_config->name, adjust)) { \ | |
12527 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12528 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12529 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12530 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12531 | current_config->name.tu, \ | |
12532 | current_config->name.gmch_m, \ | |
12533 | current_config->name.gmch_n, \ | |
12534 | current_config->name.link_m, \ | |
12535 | current_config->name.link_n, \ | |
12536 | current_config->alt_name.tu, \ | |
12537 | current_config->alt_name.gmch_m, \ | |
12538 | current_config->alt_name.gmch_n, \ | |
12539 | current_config->alt_name.link_m, \ | |
12540 | current_config->alt_name.link_n, \ | |
12541 | pipe_config->name.tu, \ | |
12542 | pipe_config->name.gmch_m, \ | |
12543 | pipe_config->name.gmch_n, \ | |
12544 | pipe_config->name.link_m, \ | |
12545 | pipe_config->name.link_n); \ | |
12546 | ret = false; \ | |
88adfff1 DV |
12547 | } |
12548 | ||
b95af8be VK |
12549 | /* This is required for BDW+ where there is only one set of registers for |
12550 | * switching between high and low RR. | |
12551 | * This macro can be used whenever a comparison has to be made between one | |
12552 | * hw state and multiple sw state variables. | |
12553 | */ | |
12554 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12555 | if ((current_config->name != pipe_config->name) && \ | |
12556 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12557 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12558 | "(expected %i or %i, found %i)\n", \ |
12559 | current_config->name, \ | |
12560 | current_config->alt_name, \ | |
12561 | pipe_config->name); \ | |
cfb23ed6 | 12562 | ret = false; \ |
b95af8be VK |
12563 | } |
12564 | ||
1bd1bd80 DV |
12565 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12566 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12567 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12568 | "(expected %i, found %i)\n", \ |
12569 | current_config->name & (mask), \ | |
12570 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12571 | ret = false; \ |
1bd1bd80 DV |
12572 | } |
12573 | ||
5e550656 VS |
12574 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12575 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12576 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12577 | "(expected %i, found %i)\n", \ |
12578 | current_config->name, \ | |
12579 | pipe_config->name); \ | |
cfb23ed6 | 12580 | ret = false; \ |
5e550656 VS |
12581 | } |
12582 | ||
bb760063 DV |
12583 | #define PIPE_CONF_QUIRK(quirk) \ |
12584 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12585 | ||
eccb140b DV |
12586 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12587 | ||
08a24034 DV |
12588 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12589 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12590 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12591 | |
eb14cb74 | 12592 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12593 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12594 | |
12595 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12596 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12597 | ||
12598 | PIPE_CONF_CHECK_I(has_drrs); | |
12599 | if (current_config->has_drrs) | |
12600 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12601 | } else | |
12602 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12603 | |
a65347ba JN |
12604 | PIPE_CONF_CHECK_I(has_dsi_encoder); |
12605 | ||
2d112de7 ACO |
12606 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12607 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12608 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12609 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12610 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12611 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12612 | |
2d112de7 ACO |
12613 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12614 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12615 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12616 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12617 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12618 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12619 | |
c93f54cf | 12620 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12621 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12622 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12623 | IS_VALLEYVIEW(dev)) | |
12624 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12625 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12626 | |
9ed109a7 DV |
12627 | PIPE_CONF_CHECK_I(has_audio); |
12628 | ||
2d112de7 | 12629 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12630 | DRM_MODE_FLAG_INTERLACE); |
12631 | ||
bb760063 | 12632 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12633 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12634 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12635 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12636 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12637 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12638 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12639 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12640 | DRM_MODE_FLAG_NVSYNC); |
12641 | } | |
045ac3b5 | 12642 | |
333b8ca8 | 12643 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12644 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12645 | if (INTEL_INFO(dev)->gen < 4) | |
12646 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
333b8ca8 | 12647 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12648 | |
bfd16b2a ML |
12649 | if (!adjust) { |
12650 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12651 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12652 | ||
12653 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12654 | if (current_config->pch_pfit.enabled) { | |
12655 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12656 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12657 | } | |
2fa2fe9a | 12658 | |
7aefe2b5 ML |
12659 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12660 | } | |
a1b2278e | 12661 | |
e59150dc JB |
12662 | /* BDW+ don't expose a synchronous way to read the state */ |
12663 | if (IS_HASWELL(dev)) | |
12664 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12665 | |
282740f7 VS |
12666 | PIPE_CONF_CHECK_I(double_wide); |
12667 | ||
26804afd DV |
12668 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12669 | ||
c0d43d62 | 12670 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12671 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12672 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12673 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12674 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12675 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
00490c22 | 12676 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
3f4cd19f DL |
12677 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12678 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12679 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12680 | |
42571aef VS |
12681 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12682 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12683 | ||
2d112de7 | 12684 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12685 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12686 | |
66e985c0 | 12687 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12688 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12689 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12690 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12691 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12692 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12693 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12694 | |
cfb23ed6 | 12695 | return ret; |
0e8ffe1b DV |
12696 | } |
12697 | ||
08db6652 DL |
12698 | static void check_wm_state(struct drm_device *dev) |
12699 | { | |
12700 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12701 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12702 | struct intel_crtc *intel_crtc; | |
12703 | int plane; | |
12704 | ||
12705 | if (INTEL_INFO(dev)->gen < 9) | |
12706 | return; | |
12707 | ||
12708 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12709 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12710 | ||
12711 | for_each_intel_crtc(dev, intel_crtc) { | |
12712 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12713 | const enum pipe pipe = intel_crtc->pipe; | |
12714 | ||
12715 | if (!intel_crtc->active) | |
12716 | continue; | |
12717 | ||
12718 | /* planes */ | |
dd740780 | 12719 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12720 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12721 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12722 | ||
12723 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12724 | continue; | |
12725 | ||
12726 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12727 | "(expected (%u,%u), found (%u,%u))\n", | |
12728 | pipe_name(pipe), plane + 1, | |
12729 | sw_entry->start, sw_entry->end, | |
12730 | hw_entry->start, hw_entry->end); | |
12731 | } | |
12732 | ||
12733 | /* cursor */ | |
4969d33e MR |
12734 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
12735 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 DL |
12736 | |
12737 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12738 | continue; | |
12739 | ||
12740 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12741 | "(expected (%u,%u), found (%u,%u))\n", | |
12742 | pipe_name(pipe), | |
12743 | sw_entry->start, sw_entry->end, | |
12744 | hw_entry->start, hw_entry->end); | |
12745 | } | |
12746 | } | |
12747 | ||
91d1b4bd | 12748 | static void |
35dd3c64 ML |
12749 | check_connector_state(struct drm_device *dev, |
12750 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12751 | { |
35dd3c64 ML |
12752 | struct drm_connector_state *old_conn_state; |
12753 | struct drm_connector *connector; | |
12754 | int i; | |
8af6cf88 | 12755 | |
35dd3c64 ML |
12756 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12757 | struct drm_encoder *encoder = connector->encoder; | |
12758 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12759 | |
8af6cf88 DV |
12760 | /* This also checks the encoder/connector hw state with the |
12761 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12762 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12763 | |
ad3c558f | 12764 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12765 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12766 | } |
91d1b4bd DV |
12767 | } |
12768 | ||
12769 | static void | |
12770 | check_encoder_state(struct drm_device *dev) | |
12771 | { | |
12772 | struct intel_encoder *encoder; | |
12773 | struct intel_connector *connector; | |
8af6cf88 | 12774 | |
b2784e15 | 12775 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12776 | bool enabled = false; |
4d20cd86 | 12777 | enum pipe pipe; |
8af6cf88 DV |
12778 | |
12779 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12780 | encoder->base.base.id, | |
8e329a03 | 12781 | encoder->base.name); |
8af6cf88 | 12782 | |
3a3371ff | 12783 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12784 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12785 | continue; |
12786 | enabled = true; | |
ad3c558f ML |
12787 | |
12788 | I915_STATE_WARN(connector->base.state->crtc != | |
12789 | encoder->base.crtc, | |
12790 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12791 | } |
0e32b39c | 12792 | |
e2c719b7 | 12793 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12794 | "encoder's enabled state mismatch " |
12795 | "(expected %i, found %i)\n", | |
12796 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12797 | |
12798 | if (!encoder->base.crtc) { | |
4d20cd86 | 12799 | bool active; |
7c60d198 | 12800 | |
4d20cd86 ML |
12801 | active = encoder->get_hw_state(encoder, &pipe); |
12802 | I915_STATE_WARN(active, | |
12803 | "encoder detached but still enabled on pipe %c.\n", | |
12804 | pipe_name(pipe)); | |
7c60d198 | 12805 | } |
8af6cf88 | 12806 | } |
91d1b4bd DV |
12807 | } |
12808 | ||
12809 | static void | |
4d20cd86 | 12810 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12811 | { |
fbee40df | 12812 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12813 | struct intel_encoder *encoder; |
4d20cd86 ML |
12814 | struct drm_crtc_state *old_crtc_state; |
12815 | struct drm_crtc *crtc; | |
12816 | int i; | |
8af6cf88 | 12817 | |
4d20cd86 ML |
12818 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12819 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12820 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12821 | bool active; |
8af6cf88 | 12822 | |
bfd16b2a ML |
12823 | if (!needs_modeset(crtc->state) && |
12824 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
4d20cd86 | 12825 | continue; |
045ac3b5 | 12826 | |
4d20cd86 ML |
12827 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
12828 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
12829 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
12830 | pipe_config->base.crtc = crtc; | |
12831 | pipe_config->base.state = old_state; | |
8af6cf88 | 12832 | |
4d20cd86 ML |
12833 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12834 | crtc->base.id); | |
8af6cf88 | 12835 | |
4d20cd86 ML |
12836 | active = dev_priv->display.get_pipe_config(intel_crtc, |
12837 | pipe_config); | |
d62cf62a | 12838 | |
b6b5d049 | 12839 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
12840 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
12841 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
12842 | active = crtc->state->active; | |
6c49f241 | 12843 | |
4d20cd86 | 12844 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 12845 | "crtc active state doesn't match with hw state " |
4d20cd86 | 12846 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 12847 | |
4d20cd86 | 12848 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 12849 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
12850 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
12851 | ||
12852 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
12853 | enum pipe pipe; | |
12854 | ||
12855 | active = encoder->get_hw_state(encoder, &pipe); | |
12856 | I915_STATE_WARN(active != crtc->state->active, | |
12857 | "[ENCODER:%i] active %i with crtc active %i\n", | |
12858 | encoder->base.base.id, active, crtc->state->active); | |
12859 | ||
12860 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
12861 | "Encoder connected to wrong pipe %c\n", | |
12862 | pipe_name(pipe)); | |
12863 | ||
12864 | if (active) | |
12865 | encoder->get_config(encoder, pipe_config); | |
12866 | } | |
53d9f4e9 | 12867 | |
4d20cd86 | 12868 | if (!crtc->state->active) |
cfb23ed6 ML |
12869 | continue; |
12870 | ||
4d20cd86 ML |
12871 | sw_config = to_intel_crtc_state(crtc->state); |
12872 | if (!intel_pipe_config_compare(dev, sw_config, | |
12873 | pipe_config, false)) { | |
e2c719b7 | 12874 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 12875 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 12876 | "[hw state]"); |
4d20cd86 | 12877 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
12878 | "[sw state]"); |
12879 | } | |
8af6cf88 DV |
12880 | } |
12881 | } | |
12882 | ||
91d1b4bd DV |
12883 | static void |
12884 | check_shared_dpll_state(struct drm_device *dev) | |
12885 | { | |
fbee40df | 12886 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12887 | struct intel_crtc *crtc; |
12888 | struct intel_dpll_hw_state dpll_hw_state; | |
12889 | int i; | |
5358901f DV |
12890 | |
12891 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12892 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12893 | int enabled_crtcs = 0, active_crtcs = 0; | |
12894 | bool active; | |
12895 | ||
12896 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12897 | ||
12898 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12899 | ||
12900 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12901 | ||
e2c719b7 | 12902 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12903 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12904 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12905 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12906 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12907 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12908 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12909 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12910 | "pll on state mismatch (expected %i, found %i)\n", |
12911 | pll->on, active); | |
12912 | ||
d3fcc808 | 12913 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12914 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12915 | enabled_crtcs++; |
12916 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12917 | active_crtcs++; | |
12918 | } | |
e2c719b7 | 12919 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12920 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12921 | pll->active, active_crtcs); | |
e2c719b7 | 12922 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12923 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12924 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12925 | |
e2c719b7 | 12926 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12927 | sizeof(dpll_hw_state)), |
12928 | "pll hw state mismatch\n"); | |
5358901f | 12929 | } |
8af6cf88 DV |
12930 | } |
12931 | ||
ee165b1a ML |
12932 | static void |
12933 | intel_modeset_check_state(struct drm_device *dev, | |
12934 | struct drm_atomic_state *old_state) | |
91d1b4bd | 12935 | { |
08db6652 | 12936 | check_wm_state(dev); |
35dd3c64 | 12937 | check_connector_state(dev, old_state); |
91d1b4bd | 12938 | check_encoder_state(dev); |
4d20cd86 | 12939 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
12940 | check_shared_dpll_state(dev); |
12941 | } | |
12942 | ||
5cec258b | 12943 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12944 | int dotclock) |
12945 | { | |
12946 | /* | |
12947 | * FDI already provided one idea for the dotclock. | |
12948 | * Yell if the encoder disagrees. | |
12949 | */ | |
2d112de7 | 12950 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12951 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12952 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12953 | } |
12954 | ||
80715b2f VS |
12955 | static void update_scanline_offset(struct intel_crtc *crtc) |
12956 | { | |
12957 | struct drm_device *dev = crtc->base.dev; | |
12958 | ||
12959 | /* | |
12960 | * The scanline counter increments at the leading edge of hsync. | |
12961 | * | |
12962 | * On most platforms it starts counting from vtotal-1 on the | |
12963 | * first active line. That means the scanline counter value is | |
12964 | * always one less than what we would expect. Ie. just after | |
12965 | * start of vblank, which also occurs at start of hsync (on the | |
12966 | * last active line), the scanline counter will read vblank_start-1. | |
12967 | * | |
12968 | * On gen2 the scanline counter starts counting from 1 instead | |
12969 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12970 | * to keep the value positive), instead of adding one. | |
12971 | * | |
12972 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12973 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12974 | * there's an extra 1 line difference. So we need to add two instead of | |
12975 | * one to the value. | |
12976 | */ | |
12977 | if (IS_GEN2(dev)) { | |
124abe07 | 12978 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12979 | int vtotal; |
12980 | ||
124abe07 VS |
12981 | vtotal = adjusted_mode->crtc_vtotal; |
12982 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
12983 | vtotal /= 2; |
12984 | ||
12985 | crtc->scanline_offset = vtotal - 1; | |
12986 | } else if (HAS_DDI(dev) && | |
409ee761 | 12987 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12988 | crtc->scanline_offset = 2; |
12989 | } else | |
12990 | crtc->scanline_offset = 1; | |
12991 | } | |
12992 | ||
ad421372 | 12993 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 12994 | { |
225da59b | 12995 | struct drm_device *dev = state->dev; |
ed6739ef | 12996 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 12997 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 12998 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12999 | struct intel_crtc_state *intel_crtc_state; |
13000 | struct drm_crtc *crtc; | |
13001 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 13002 | int i; |
ed6739ef ACO |
13003 | |
13004 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 13005 | return; |
ed6739ef | 13006 | |
0a9ab303 | 13007 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
13008 | int dpll; |
13009 | ||
0a9ab303 | 13010 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 13011 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 13012 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 13013 | |
ad421372 | 13014 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
13015 | continue; |
13016 | ||
ad421372 | 13017 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 13018 | |
ad421372 ML |
13019 | if (!shared_dpll) |
13020 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 13021 | |
ad421372 ML |
13022 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
13023 | } | |
ed6739ef ACO |
13024 | } |
13025 | ||
99d736a2 ML |
13026 | /* |
13027 | * This implements the workaround described in the "notes" section of the mode | |
13028 | * set sequence documentation. When going from no pipes or single pipe to | |
13029 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
13030 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
13031 | */ | |
13032 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
13033 | { | |
13034 | struct drm_crtc_state *crtc_state; | |
13035 | struct intel_crtc *intel_crtc; | |
13036 | struct drm_crtc *crtc; | |
13037 | struct intel_crtc_state *first_crtc_state = NULL; | |
13038 | struct intel_crtc_state *other_crtc_state = NULL; | |
13039 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
13040 | int i; | |
13041 | ||
13042 | /* look at all crtc's that are going to be enabled in during modeset */ | |
13043 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13044 | intel_crtc = to_intel_crtc(crtc); | |
13045 | ||
13046 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
13047 | continue; | |
13048 | ||
13049 | if (first_crtc_state) { | |
13050 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
13051 | break; | |
13052 | } else { | |
13053 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
13054 | first_pipe = intel_crtc->pipe; | |
13055 | } | |
13056 | } | |
13057 | ||
13058 | /* No workaround needed? */ | |
13059 | if (!first_crtc_state) | |
13060 | return 0; | |
13061 | ||
13062 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
13063 | for_each_intel_crtc(state->dev, intel_crtc) { | |
13064 | struct intel_crtc_state *pipe_config; | |
13065 | ||
13066 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
13067 | if (IS_ERR(pipe_config)) | |
13068 | return PTR_ERR(pipe_config); | |
13069 | ||
13070 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
13071 | ||
13072 | if (!pipe_config->base.active || | |
13073 | needs_modeset(&pipe_config->base)) | |
13074 | continue; | |
13075 | ||
13076 | /* 2 or more enabled crtcs means no need for w/a */ | |
13077 | if (enabled_pipe != INVALID_PIPE) | |
13078 | return 0; | |
13079 | ||
13080 | enabled_pipe = intel_crtc->pipe; | |
13081 | } | |
13082 | ||
13083 | if (enabled_pipe != INVALID_PIPE) | |
13084 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
13085 | else if (other_crtc_state) | |
13086 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
13087 | ||
13088 | return 0; | |
13089 | } | |
13090 | ||
27c329ed ML |
13091 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
13092 | { | |
13093 | struct drm_crtc *crtc; | |
13094 | struct drm_crtc_state *crtc_state; | |
13095 | int ret = 0; | |
13096 | ||
13097 | /* add all active pipes to the state */ | |
13098 | for_each_crtc(state->dev, crtc) { | |
13099 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13100 | if (IS_ERR(crtc_state)) | |
13101 | return PTR_ERR(crtc_state); | |
13102 | ||
13103 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
13104 | continue; | |
13105 | ||
13106 | crtc_state->mode_changed = true; | |
13107 | ||
13108 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13109 | if (ret) | |
13110 | break; | |
13111 | ||
13112 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13113 | if (ret) | |
13114 | break; | |
13115 | } | |
13116 | ||
13117 | return ret; | |
13118 | } | |
13119 | ||
c347a676 | 13120 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
13121 | { |
13122 | struct drm_device *dev = state->dev; | |
27c329ed | 13123 | struct drm_i915_private *dev_priv = dev->dev_private; |
054518dd ACO |
13124 | int ret; |
13125 | ||
b359283a ML |
13126 | if (!check_digital_port_conflicts(state)) { |
13127 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13128 | return -EINVAL; | |
13129 | } | |
13130 | ||
054518dd ACO |
13131 | /* |
13132 | * See if the config requires any additional preparation, e.g. | |
13133 | * to adjust global state with pipes off. We need to do this | |
13134 | * here so we can get the modeset_pipe updated config for the new | |
13135 | * mode set on this crtc. For other crtcs we need to use the | |
13136 | * adjusted_mode bits in the crtc directly. | |
13137 | */ | |
27c329ed ML |
13138 | if (dev_priv->display.modeset_calc_cdclk) { |
13139 | unsigned int cdclk; | |
b432e5cf | 13140 | |
27c329ed ML |
13141 | ret = dev_priv->display.modeset_calc_cdclk(state); |
13142 | ||
13143 | cdclk = to_intel_atomic_state(state)->cdclk; | |
13144 | if (!ret && cdclk != dev_priv->cdclk_freq) | |
13145 | ret = intel_modeset_all_pipes(state); | |
13146 | ||
13147 | if (ret < 0) | |
054518dd | 13148 | return ret; |
27c329ed ML |
13149 | } else |
13150 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; | |
054518dd | 13151 | |
ad421372 | 13152 | intel_modeset_clear_plls(state); |
054518dd | 13153 | |
99d736a2 | 13154 | if (IS_HASWELL(dev)) |
ad421372 | 13155 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13156 | |
ad421372 | 13157 | return 0; |
c347a676 ACO |
13158 | } |
13159 | ||
aa363136 MR |
13160 | /* |
13161 | * Handle calculation of various watermark data at the end of the atomic check | |
13162 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13163 | * handlers to ensure that all derived state has been updated. | |
13164 | */ | |
13165 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13166 | { | |
13167 | struct drm_device *dev = state->dev; | |
13168 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13169 | struct drm_crtc *crtc; | |
13170 | struct drm_crtc_state *cstate; | |
13171 | struct drm_plane *plane; | |
13172 | struct drm_plane_state *pstate; | |
13173 | ||
13174 | /* | |
13175 | * Calculate watermark configuration details now that derived | |
13176 | * plane/crtc state is all properly updated. | |
13177 | */ | |
13178 | drm_for_each_crtc(crtc, dev) { | |
13179 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13180 | crtc->state; | |
13181 | ||
13182 | if (cstate->active) | |
13183 | intel_state->wm_config.num_pipes_active++; | |
13184 | } | |
13185 | drm_for_each_legacy_plane(plane, dev) { | |
13186 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13187 | plane->state; | |
13188 | ||
13189 | if (!to_intel_plane_state(pstate)->visible) | |
13190 | continue; | |
13191 | ||
13192 | intel_state->wm_config.sprites_enabled = true; | |
13193 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13194 | pstate->crtc_h != pstate->src_h >> 16) | |
13195 | intel_state->wm_config.sprites_scaled = true; | |
13196 | } | |
13197 | } | |
13198 | ||
74c090b1 ML |
13199 | /** |
13200 | * intel_atomic_check - validate state object | |
13201 | * @dev: drm device | |
13202 | * @state: state to validate | |
13203 | */ | |
13204 | static int intel_atomic_check(struct drm_device *dev, | |
13205 | struct drm_atomic_state *state) | |
c347a676 | 13206 | { |
aa363136 | 13207 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13208 | struct drm_crtc *crtc; |
13209 | struct drm_crtc_state *crtc_state; | |
13210 | int ret, i; | |
61333b60 | 13211 | bool any_ms = false; |
c347a676 | 13212 | |
74c090b1 | 13213 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13214 | if (ret) |
13215 | return ret; | |
13216 | ||
c347a676 | 13217 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13218 | struct intel_crtc_state *pipe_config = |
13219 | to_intel_crtc_state(crtc_state); | |
1ed51de9 | 13220 | |
ba8af3e5 ML |
13221 | memset(&to_intel_crtc(crtc)->atomic, 0, |
13222 | sizeof(struct intel_crtc_atomic_commit)); | |
13223 | ||
1ed51de9 DV |
13224 | /* Catch I915_MODE_FLAG_INHERITED */ |
13225 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13226 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13227 | |
61333b60 ML |
13228 | if (!crtc_state->enable) { |
13229 | if (needs_modeset(crtc_state)) | |
13230 | any_ms = true; | |
c347a676 | 13231 | continue; |
61333b60 | 13232 | } |
c347a676 | 13233 | |
26495481 | 13234 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
13235 | continue; |
13236 | ||
26495481 DV |
13237 | /* FIXME: For only active_changed we shouldn't need to do any |
13238 | * state recomputation at all. */ | |
13239 | ||
1ed51de9 DV |
13240 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13241 | if (ret) | |
13242 | return ret; | |
b359283a | 13243 | |
cfb23ed6 | 13244 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13245 | if (ret) |
13246 | return ret; | |
13247 | ||
73831236 JN |
13248 | if (i915.fastboot && |
13249 | intel_pipe_config_compare(state->dev, | |
cfb23ed6 | 13250 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13251 | pipe_config, true)) { |
26495481 | 13252 | crtc_state->mode_changed = false; |
bfd16b2a | 13253 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13254 | } |
13255 | ||
13256 | if (needs_modeset(crtc_state)) { | |
13257 | any_ms = true; | |
cfb23ed6 ML |
13258 | |
13259 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13260 | if (ret) | |
13261 | return ret; | |
13262 | } | |
61333b60 | 13263 | |
26495481 DV |
13264 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13265 | needs_modeset(crtc_state) ? | |
13266 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13267 | } |
13268 | ||
61333b60 ML |
13269 | if (any_ms) { |
13270 | ret = intel_modeset_checks(state); | |
13271 | ||
13272 | if (ret) | |
13273 | return ret; | |
27c329ed | 13274 | } else |
aa363136 | 13275 | intel_state->cdclk = to_i915(state->dev)->cdclk_freq; |
76305b1a | 13276 | |
aa363136 MR |
13277 | ret = drm_atomic_helper_check_planes(state->dev, state); |
13278 | if (ret) | |
13279 | return ret; | |
13280 | ||
13281 | calc_watermark_data(state); | |
13282 | ||
13283 | return 0; | |
054518dd ACO |
13284 | } |
13285 | ||
5008e874 ML |
13286 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13287 | struct drm_atomic_state *state, | |
13288 | bool async) | |
13289 | { | |
7580d774 ML |
13290 | struct drm_i915_private *dev_priv = dev->dev_private; |
13291 | struct drm_plane_state *plane_state; | |
5008e874 | 13292 | struct drm_crtc_state *crtc_state; |
7580d774 | 13293 | struct drm_plane *plane; |
5008e874 ML |
13294 | struct drm_crtc *crtc; |
13295 | int i, ret; | |
13296 | ||
13297 | if (async) { | |
13298 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13299 | return -EINVAL; | |
13300 | } | |
13301 | ||
13302 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13303 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13304 | if (ret) | |
13305 | return ret; | |
7580d774 ML |
13306 | |
13307 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13308 | flush_workqueue(dev_priv->wq); | |
5008e874 ML |
13309 | } |
13310 | ||
f935675f ML |
13311 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13312 | if (ret) | |
13313 | return ret; | |
13314 | ||
5008e874 | 13315 | ret = drm_atomic_helper_prepare_planes(dev, state); |
7580d774 ML |
13316 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
13317 | u32 reset_counter; | |
13318 | ||
13319 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13320 | mutex_unlock(&dev->struct_mutex); | |
13321 | ||
13322 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13323 | struct intel_plane_state *intel_plane_state = | |
13324 | to_intel_plane_state(plane_state); | |
13325 | ||
13326 | if (!intel_plane_state->wait_req) | |
13327 | continue; | |
13328 | ||
13329 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13330 | reset_counter, true, | |
13331 | NULL, NULL); | |
13332 | ||
13333 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13334 | if (ret == -EIO) | |
13335 | ret = 0; | |
13336 | ||
13337 | if (ret) | |
13338 | break; | |
13339 | } | |
13340 | ||
13341 | if (!ret) | |
13342 | return 0; | |
13343 | ||
13344 | mutex_lock(&dev->struct_mutex); | |
13345 | drm_atomic_helper_cleanup_planes(dev, state); | |
13346 | } | |
5008e874 | 13347 | |
f935675f | 13348 | mutex_unlock(&dev->struct_mutex); |
5008e874 ML |
13349 | return ret; |
13350 | } | |
13351 | ||
74c090b1 ML |
13352 | /** |
13353 | * intel_atomic_commit - commit validated state object | |
13354 | * @dev: DRM device | |
13355 | * @state: the top-level driver state object | |
13356 | * @async: asynchronous commit | |
13357 | * | |
13358 | * This function commits a top-level state object that has been validated | |
13359 | * with drm_atomic_helper_check(). | |
13360 | * | |
13361 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13362 | * we can only handle plane-related operations and do not yet support | |
13363 | * asynchronous commit. | |
13364 | * | |
13365 | * RETURNS | |
13366 | * Zero for success or -errno. | |
13367 | */ | |
13368 | static int intel_atomic_commit(struct drm_device *dev, | |
13369 | struct drm_atomic_state *state, | |
13370 | bool async) | |
a6778b3c | 13371 | { |
fbee40df | 13372 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 | 13373 | struct drm_crtc_state *crtc_state; |
7580d774 | 13374 | struct drm_crtc *crtc; |
c0c36b94 | 13375 | int ret = 0; |
0a9ab303 | 13376 | int i; |
61333b60 | 13377 | bool any_ms = false; |
a6778b3c | 13378 | |
5008e874 | 13379 | ret = intel_atomic_prepare_commit(dev, state, async); |
7580d774 ML |
13380 | if (ret) { |
13381 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
d4afb8cc | 13382 | return ret; |
7580d774 | 13383 | } |
d4afb8cc | 13384 | |
1c5e19f8 | 13385 | drm_atomic_helper_swap_state(dev, state); |
aa363136 | 13386 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; |
1c5e19f8 | 13387 | |
0a9ab303 | 13388 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13389 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13390 | ||
61333b60 ML |
13391 | if (!needs_modeset(crtc->state)) |
13392 | continue; | |
13393 | ||
13394 | any_ms = true; | |
a539205a | 13395 | intel_pre_plane_update(intel_crtc); |
460da916 | 13396 | |
a539205a ML |
13397 | if (crtc_state->active) { |
13398 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13399 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd ML |
13400 | intel_crtc->active = false; |
13401 | intel_disable_shared_dpll(intel_crtc); | |
9bbc8258 VS |
13402 | |
13403 | /* | |
13404 | * Underruns don't always raise | |
13405 | * interrupts, so check manually. | |
13406 | */ | |
13407 | intel_check_cpu_fifo_underruns(dev_priv); | |
13408 | intel_check_pch_fifo_underruns(dev_priv); | |
a539205a | 13409 | } |
b8cecdf5 | 13410 | } |
7758a113 | 13411 | |
ea9d758d DV |
13412 | /* Only after disabling all output pipelines that will be changed can we |
13413 | * update the the output configuration. */ | |
4740b0f2 | 13414 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13415 | |
4740b0f2 ML |
13416 | if (any_ms) { |
13417 | intel_shared_dpll_commit(state); | |
13418 | ||
13419 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
61333b60 | 13420 | modeset_update_crtc_power_domains(state); |
4740b0f2 | 13421 | } |
47fab737 | 13422 | |
a6778b3c | 13423 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13424 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13425 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13426 | bool modeset = needs_modeset(crtc->state); | |
bfd16b2a ML |
13427 | bool update_pipe = !modeset && |
13428 | to_intel_crtc_state(crtc->state)->update_pipe; | |
13429 | unsigned long put_domains = 0; | |
f6ac4b2a | 13430 | |
9f836f90 PJ |
13431 | if (modeset) |
13432 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); | |
13433 | ||
f6ac4b2a | 13434 | if (modeset && crtc->state->active) { |
a539205a ML |
13435 | update_scanline_offset(to_intel_crtc(crtc)); |
13436 | dev_priv->display.crtc_enable(crtc); | |
13437 | } | |
80715b2f | 13438 | |
bfd16b2a ML |
13439 | if (update_pipe) { |
13440 | put_domains = modeset_get_crtc_power_domains(crtc); | |
13441 | ||
13442 | /* make sure intel_modeset_check_state runs */ | |
13443 | any_ms = true; | |
13444 | } | |
13445 | ||
f6ac4b2a ML |
13446 | if (!modeset) |
13447 | intel_pre_plane_update(intel_crtc); | |
13448 | ||
6173ee28 ML |
13449 | if (crtc->state->active && |
13450 | (crtc->state->planes_changed || update_pipe)) | |
62852622 | 13451 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
bfd16b2a ML |
13452 | |
13453 | if (put_domains) | |
13454 | modeset_put_power_domains(dev_priv, put_domains); | |
13455 | ||
f6ac4b2a | 13456 | intel_post_plane_update(intel_crtc); |
9f836f90 PJ |
13457 | |
13458 | if (modeset) | |
13459 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); | |
80715b2f | 13460 | } |
a6778b3c | 13461 | |
a6778b3c | 13462 | /* FIXME: add subpixel order */ |
83a57153 | 13463 | |
74c090b1 | 13464 | drm_atomic_helper_wait_for_vblanks(dev, state); |
f935675f ML |
13465 | |
13466 | mutex_lock(&dev->struct_mutex); | |
d4afb8cc | 13467 | drm_atomic_helper_cleanup_planes(dev, state); |
f935675f | 13468 | mutex_unlock(&dev->struct_mutex); |
2bfb4627 | 13469 | |
74c090b1 | 13470 | if (any_ms) |
ee165b1a ML |
13471 | intel_modeset_check_state(dev, state); |
13472 | ||
13473 | drm_atomic_state_free(state); | |
f30da187 | 13474 | |
74c090b1 | 13475 | return 0; |
7f27126e JB |
13476 | } |
13477 | ||
c0c36b94 CW |
13478 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13479 | { | |
83a57153 ACO |
13480 | struct drm_device *dev = crtc->dev; |
13481 | struct drm_atomic_state *state; | |
e694eb02 | 13482 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13483 | int ret; |
83a57153 ACO |
13484 | |
13485 | state = drm_atomic_state_alloc(dev); | |
13486 | if (!state) { | |
e694eb02 | 13487 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13488 | crtc->base.id); |
13489 | return; | |
13490 | } | |
13491 | ||
e694eb02 | 13492 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13493 | |
e694eb02 ML |
13494 | retry: |
13495 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13496 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13497 | if (!ret) { | |
13498 | if (!crtc_state->active) | |
13499 | goto out; | |
83a57153 | 13500 | |
e694eb02 | 13501 | crtc_state->mode_changed = true; |
74c090b1 | 13502 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13503 | } |
13504 | ||
e694eb02 ML |
13505 | if (ret == -EDEADLK) { |
13506 | drm_atomic_state_clear(state); | |
13507 | drm_modeset_backoff(state->acquire_ctx); | |
13508 | goto retry; | |
4ed9fb37 | 13509 | } |
4be07317 | 13510 | |
2bfb4627 | 13511 | if (ret) |
e694eb02 | 13512 | out: |
2bfb4627 | 13513 | drm_atomic_state_free(state); |
c0c36b94 CW |
13514 | } |
13515 | ||
25c5b266 DV |
13516 | #undef for_each_intel_crtc_masked |
13517 | ||
f6e5b160 | 13518 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13519 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13520 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13521 | .destroy = intel_crtc_destroy, |
13522 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13523 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13524 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13525 | }; |
13526 | ||
5358901f DV |
13527 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13528 | struct intel_shared_dpll *pll, | |
13529 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13530 | { |
5358901f | 13531 | uint32_t val; |
ee7b9f93 | 13532 | |
f458ebbc | 13533 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13534 | return false; |
13535 | ||
5358901f | 13536 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13537 | hw_state->dpll = val; |
13538 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13539 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13540 | |
13541 | return val & DPLL_VCO_ENABLE; | |
13542 | } | |
13543 | ||
15bdd4cf DV |
13544 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13545 | struct intel_shared_dpll *pll) | |
13546 | { | |
3e369b76 ACO |
13547 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13548 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13549 | } |
13550 | ||
e7b903d2 DV |
13551 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13552 | struct intel_shared_dpll *pll) | |
13553 | { | |
e7b903d2 | 13554 | /* PCH refclock must be enabled first */ |
89eff4be | 13555 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13556 | |
3e369b76 | 13557 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13558 | |
13559 | /* Wait for the clocks to stabilize. */ | |
13560 | POSTING_READ(PCH_DPLL(pll->id)); | |
13561 | udelay(150); | |
13562 | ||
13563 | /* The pixel multiplier can only be updated once the | |
13564 | * DPLL is enabled and the clocks are stable. | |
13565 | * | |
13566 | * So write it again. | |
13567 | */ | |
3e369b76 | 13568 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13569 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13570 | udelay(200); |
13571 | } | |
13572 | ||
13573 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13574 | struct intel_shared_dpll *pll) | |
13575 | { | |
13576 | struct drm_device *dev = dev_priv->dev; | |
13577 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13578 | |
13579 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13580 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13581 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13582 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13583 | } |
13584 | ||
15bdd4cf DV |
13585 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13586 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13587 | udelay(200); |
13588 | } | |
13589 | ||
46edb027 DV |
13590 | static char *ibx_pch_dpll_names[] = { |
13591 | "PCH DPLL A", | |
13592 | "PCH DPLL B", | |
13593 | }; | |
13594 | ||
7c74ade1 | 13595 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13596 | { |
e7b903d2 | 13597 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13598 | int i; |
13599 | ||
7c74ade1 | 13600 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13601 | |
e72f9fbf | 13602 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13603 | dev_priv->shared_dplls[i].id = i; |
13604 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13605 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13606 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13607 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13608 | dev_priv->shared_dplls[i].get_hw_state = |
13609 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13610 | } |
13611 | } | |
13612 | ||
7c74ade1 DV |
13613 | static void intel_shared_dpll_init(struct drm_device *dev) |
13614 | { | |
e7b903d2 | 13615 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13616 | |
9cd86933 DV |
13617 | if (HAS_DDI(dev)) |
13618 | intel_ddi_pll_init(dev); | |
13619 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13620 | ibx_pch_dpll_init(dev); |
13621 | else | |
13622 | dev_priv->num_shared_dpll = 0; | |
13623 | ||
13624 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13625 | } |
13626 | ||
6beb8c23 MR |
13627 | /** |
13628 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13629 | * @plane: drm plane to prepare for | |
13630 | * @fb: framebuffer to prepare for presentation | |
13631 | * | |
13632 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13633 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13634 | * bits. Some older platforms need special physical address handling for | |
13635 | * cursor planes. | |
13636 | * | |
f935675f ML |
13637 | * Must be called with struct_mutex held. |
13638 | * | |
6beb8c23 MR |
13639 | * Returns 0 on success, negative error code on failure. |
13640 | */ | |
13641 | int | |
13642 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 13643 | const struct drm_plane_state *new_state) |
465c120c MR |
13644 | { |
13645 | struct drm_device *dev = plane->dev; | |
844f9111 | 13646 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 13647 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 | 13648 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 13649 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
6beb8c23 | 13650 | int ret = 0; |
465c120c | 13651 | |
1ee49399 | 13652 | if (!obj && !old_obj) |
465c120c MR |
13653 | return 0; |
13654 | ||
5008e874 ML |
13655 | if (old_obj) { |
13656 | struct drm_crtc_state *crtc_state = | |
13657 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13658 | ||
13659 | /* Big Hammer, we also need to ensure that any pending | |
13660 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13661 | * current scanout is retired before unpinning the old | |
13662 | * framebuffer. Note that we rely on userspace rendering | |
13663 | * into the buffer attached to the pipe they are waiting | |
13664 | * on. If not, userspace generates a GPU hang with IPEHR | |
13665 | * point to the MI_WAIT_FOR_EVENT. | |
13666 | * | |
13667 | * This should only fail upon a hung GPU, in which case we | |
13668 | * can safely continue. | |
13669 | */ | |
13670 | if (needs_modeset(crtc_state)) | |
13671 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13672 | ||
13673 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13674 | if (ret && ret != -EIO) | |
f935675f | 13675 | return ret; |
5008e874 ML |
13676 | } |
13677 | ||
1ee49399 ML |
13678 | if (!obj) { |
13679 | ret = 0; | |
13680 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
6beb8c23 MR |
13681 | INTEL_INFO(dev)->cursor_needs_physical) { |
13682 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13683 | ret = i915_gem_object_attach_phys(obj, align); | |
13684 | if (ret) | |
13685 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13686 | } else { | |
7580d774 | 13687 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state); |
6beb8c23 | 13688 | } |
465c120c | 13689 | |
7580d774 ML |
13690 | if (ret == 0) { |
13691 | if (obj) { | |
13692 | struct intel_plane_state *plane_state = | |
13693 | to_intel_plane_state(new_state); | |
13694 | ||
13695 | i915_gem_request_assign(&plane_state->wait_req, | |
13696 | obj->last_write_req); | |
13697 | } | |
13698 | ||
a9ff8714 | 13699 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
7580d774 | 13700 | } |
fdd508a6 | 13701 | |
6beb8c23 MR |
13702 | return ret; |
13703 | } | |
13704 | ||
38f3ce3a MR |
13705 | /** |
13706 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13707 | * @plane: drm plane to clean up for | |
13708 | * @fb: old framebuffer that was on plane | |
13709 | * | |
13710 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
13711 | * |
13712 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
13713 | */ |
13714 | void | |
13715 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 13716 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
13717 | { |
13718 | struct drm_device *dev = plane->dev; | |
1ee49399 | 13719 | struct intel_plane *intel_plane = to_intel_plane(plane); |
7580d774 | 13720 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
13721 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
13722 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 13723 | |
7580d774 ML |
13724 | old_intel_state = to_intel_plane_state(old_state); |
13725 | ||
1ee49399 | 13726 | if (!obj && !old_obj) |
38f3ce3a MR |
13727 | return; |
13728 | ||
1ee49399 ML |
13729 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
13730 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
844f9111 | 13731 | intel_unpin_fb_obj(old_state->fb, old_state); |
1ee49399 ML |
13732 | |
13733 | /* prepare_fb aborted? */ | |
13734 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
13735 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
13736 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
7580d774 ML |
13737 | |
13738 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
13739 | ||
465c120c MR |
13740 | } |
13741 | ||
6156a456 CK |
13742 | int |
13743 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13744 | { | |
13745 | int max_scale; | |
13746 | struct drm_device *dev; | |
13747 | struct drm_i915_private *dev_priv; | |
13748 | int crtc_clock, cdclk; | |
13749 | ||
13750 | if (!intel_crtc || !crtc_state) | |
13751 | return DRM_PLANE_HELPER_NO_SCALING; | |
13752 | ||
13753 | dev = intel_crtc->base.dev; | |
13754 | dev_priv = dev->dev_private; | |
13755 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 13756 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 13757 | |
54bf1ce6 | 13758 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
13759 | return DRM_PLANE_HELPER_NO_SCALING; |
13760 | ||
13761 | /* | |
13762 | * skl max scale is lower of: | |
13763 | * close to 3 but not 3, -1 is for that purpose | |
13764 | * or | |
13765 | * cdclk/crtc_clock | |
13766 | */ | |
13767 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13768 | ||
13769 | return max_scale; | |
13770 | } | |
13771 | ||
465c120c | 13772 | static int |
3c692a41 | 13773 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13774 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13775 | struct intel_plane_state *state) |
13776 | { | |
2b875c22 MR |
13777 | struct drm_crtc *crtc = state->base.crtc; |
13778 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13779 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13780 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13781 | bool can_position = false; | |
465c120c | 13782 | |
061e4b8d ML |
13783 | /* use scaler when colorkey is not required */ |
13784 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
818ed961 | 13785 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
061e4b8d ML |
13786 | min_scale = 1; |
13787 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13788 | can_position = true; |
6156a456 | 13789 | } |
d8106366 | 13790 | |
061e4b8d ML |
13791 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13792 | &state->dst, &state->clip, | |
da20eabd ML |
13793 | min_scale, max_scale, |
13794 | can_position, true, | |
13795 | &state->visible); | |
14af293f GP |
13796 | } |
13797 | ||
13798 | static void | |
13799 | intel_commit_primary_plane(struct drm_plane *plane, | |
13800 | struct intel_plane_state *state) | |
13801 | { | |
2b875c22 MR |
13802 | struct drm_crtc *crtc = state->base.crtc; |
13803 | struct drm_framebuffer *fb = state->base.fb; | |
13804 | struct drm_device *dev = plane->dev; | |
14af293f | 13805 | struct drm_i915_private *dev_priv = dev->dev_private; |
14af293f | 13806 | |
ea2c67bb | 13807 | crtc = crtc ? crtc : plane->crtc; |
ccc759dc | 13808 | |
d4b08630 ML |
13809 | dev_priv->display.update_primary_plane(crtc, fb, |
13810 | state->src.x1 >> 16, | |
13811 | state->src.y1 >> 16); | |
465c120c MR |
13812 | } |
13813 | ||
a8ad0d8e ML |
13814 | static void |
13815 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13816 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13817 | { |
13818 | struct drm_device *dev = plane->dev; | |
13819 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13820 | ||
a8ad0d8e ML |
13821 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13822 | } | |
13823 | ||
613d2b27 ML |
13824 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
13825 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 13826 | { |
32b7eeec | 13827 | struct drm_device *dev = crtc->dev; |
3c692a41 | 13828 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
bfd16b2a ML |
13829 | struct intel_crtc_state *old_intel_state = |
13830 | to_intel_crtc_state(old_crtc_state); | |
13831 | bool modeset = needs_modeset(crtc->state); | |
3c692a41 | 13832 | |
f015c551 | 13833 | if (intel_crtc->atomic.update_wm_pre) |
32b7eeec | 13834 | intel_update_watermarks(crtc); |
3c692a41 | 13835 | |
c34c9ee4 | 13836 | /* Perform vblank evasion around commit operation */ |
62852622 | 13837 | intel_pipe_update_start(intel_crtc); |
0583236e | 13838 | |
bfd16b2a ML |
13839 | if (modeset) |
13840 | return; | |
13841 | ||
13842 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
13843 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
13844 | else if (INTEL_INFO(dev)->gen >= 9) | |
0583236e | 13845 | skl_detach_scalers(intel_crtc); |
32b7eeec MR |
13846 | } |
13847 | ||
613d2b27 ML |
13848 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
13849 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 13850 | { |
32b7eeec | 13851 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 13852 | |
62852622 | 13853 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
13854 | } |
13855 | ||
cf4c7c12 | 13856 | /** |
4a3b8769 MR |
13857 | * intel_plane_destroy - destroy a plane |
13858 | * @plane: plane to destroy | |
cf4c7c12 | 13859 | * |
4a3b8769 MR |
13860 | * Common destruction function for all types of planes (primary, cursor, |
13861 | * sprite). | |
cf4c7c12 | 13862 | */ |
4a3b8769 | 13863 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13864 | { |
13865 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13866 | drm_plane_cleanup(plane); | |
13867 | kfree(intel_plane); | |
13868 | } | |
13869 | ||
65a3fea0 | 13870 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13871 | .update_plane = drm_atomic_helper_update_plane, |
13872 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13873 | .destroy = intel_plane_destroy, |
c196e1d6 | 13874 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13875 | .atomic_get_property = intel_plane_atomic_get_property, |
13876 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13877 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13878 | .atomic_destroy_state = intel_plane_destroy_state, | |
13879 | ||
465c120c MR |
13880 | }; |
13881 | ||
13882 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13883 | int pipe) | |
13884 | { | |
13885 | struct intel_plane *primary; | |
8e7d688b | 13886 | struct intel_plane_state *state; |
465c120c | 13887 | const uint32_t *intel_primary_formats; |
45e3743a | 13888 | unsigned int num_formats; |
465c120c MR |
13889 | |
13890 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13891 | if (primary == NULL) | |
13892 | return NULL; | |
13893 | ||
8e7d688b MR |
13894 | state = intel_create_plane_state(&primary->base); |
13895 | if (!state) { | |
ea2c67bb MR |
13896 | kfree(primary); |
13897 | return NULL; | |
13898 | } | |
8e7d688b | 13899 | primary->base.state = &state->base; |
ea2c67bb | 13900 | |
465c120c MR |
13901 | primary->can_scale = false; |
13902 | primary->max_downscale = 1; | |
6156a456 CK |
13903 | if (INTEL_INFO(dev)->gen >= 9) { |
13904 | primary->can_scale = true; | |
af99ceda | 13905 | state->scaler_id = -1; |
6156a456 | 13906 | } |
465c120c MR |
13907 | primary->pipe = pipe; |
13908 | primary->plane = pipe; | |
a9ff8714 | 13909 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 MR |
13910 | primary->check_plane = intel_check_primary_plane; |
13911 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13912 | primary->disable_plane = intel_disable_primary_plane; |
465c120c MR |
13913 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13914 | primary->plane = !pipe; | |
13915 | ||
6c0fd451 DL |
13916 | if (INTEL_INFO(dev)->gen >= 9) { |
13917 | intel_primary_formats = skl_primary_formats; | |
13918 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13919 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13920 | intel_primary_formats = i965_primary_formats; |
13921 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13922 | } else { |
13923 | intel_primary_formats = i8xx_primary_formats; | |
13924 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13925 | } |
13926 | ||
13927 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13928 | &intel_plane_funcs, |
465c120c MR |
13929 | intel_primary_formats, num_formats, |
13930 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13931 | |
3b7a5119 SJ |
13932 | if (INTEL_INFO(dev)->gen >= 4) |
13933 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13934 | |
ea2c67bb MR |
13935 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13936 | ||
465c120c MR |
13937 | return &primary->base; |
13938 | } | |
13939 | ||
3b7a5119 SJ |
13940 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13941 | { | |
13942 | if (!dev->mode_config.rotation_property) { | |
13943 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13944 | BIT(DRM_ROTATE_180); | |
13945 | ||
13946 | if (INTEL_INFO(dev)->gen >= 9) | |
13947 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13948 | ||
13949 | dev->mode_config.rotation_property = | |
13950 | drm_mode_create_rotation_property(dev, flags); | |
13951 | } | |
13952 | if (dev->mode_config.rotation_property) | |
13953 | drm_object_attach_property(&plane->base.base, | |
13954 | dev->mode_config.rotation_property, | |
13955 | plane->base.state->rotation); | |
13956 | } | |
13957 | ||
3d7d6510 | 13958 | static int |
852e787c | 13959 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 13960 | struct intel_crtc_state *crtc_state, |
852e787c | 13961 | struct intel_plane_state *state) |
3d7d6510 | 13962 | { |
061e4b8d | 13963 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 13964 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 13965 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
13966 | unsigned stride; |
13967 | int ret; | |
3d7d6510 | 13968 | |
061e4b8d ML |
13969 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13970 | &state->dst, &state->clip, | |
3d7d6510 MR |
13971 | DRM_PLANE_HELPER_NO_SCALING, |
13972 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13973 | true, true, &state->visible); |
757f9a3e GP |
13974 | if (ret) |
13975 | return ret; | |
13976 | ||
757f9a3e GP |
13977 | /* if we want to turn off the cursor ignore width and height */ |
13978 | if (!obj) | |
da20eabd | 13979 | return 0; |
757f9a3e | 13980 | |
757f9a3e | 13981 | /* Check for which cursor types we support */ |
061e4b8d | 13982 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
13983 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
13984 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13985 | return -EINVAL; |
13986 | } | |
13987 | ||
ea2c67bb MR |
13988 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13989 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13990 | DRM_DEBUG_KMS("buffer is too small\n"); |
13991 | return -ENOMEM; | |
13992 | } | |
13993 | ||
3a656b54 | 13994 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 13995 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 13996 | return -EINVAL; |
32b7eeec MR |
13997 | } |
13998 | ||
da20eabd | 13999 | return 0; |
852e787c | 14000 | } |
3d7d6510 | 14001 | |
a8ad0d8e ML |
14002 | static void |
14003 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 14004 | struct drm_crtc *crtc) |
a8ad0d8e | 14005 | { |
a8ad0d8e ML |
14006 | intel_crtc_update_cursor(crtc, false); |
14007 | } | |
14008 | ||
f4a2cf29 | 14009 | static void |
852e787c GP |
14010 | intel_commit_cursor_plane(struct drm_plane *plane, |
14011 | struct intel_plane_state *state) | |
14012 | { | |
2b875c22 | 14013 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
14014 | struct drm_device *dev = plane->dev; |
14015 | struct intel_crtc *intel_crtc; | |
2b875c22 | 14016 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 14017 | uint32_t addr; |
852e787c | 14018 | |
ea2c67bb MR |
14019 | crtc = crtc ? crtc : plane->crtc; |
14020 | intel_crtc = to_intel_crtc(crtc); | |
14021 | ||
a912f12f GP |
14022 | if (intel_crtc->cursor_bo == obj) |
14023 | goto update; | |
4ed91096 | 14024 | |
f4a2cf29 | 14025 | if (!obj) |
a912f12f | 14026 | addr = 0; |
f4a2cf29 | 14027 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 14028 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 14029 | else |
a912f12f | 14030 | addr = obj->phys_handle->busaddr; |
852e787c | 14031 | |
a912f12f GP |
14032 | intel_crtc->cursor_addr = addr; |
14033 | intel_crtc->cursor_bo = obj; | |
852e787c | 14034 | |
302d19ac | 14035 | update: |
62852622 | 14036 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
14037 | } |
14038 | ||
3d7d6510 MR |
14039 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
14040 | int pipe) | |
14041 | { | |
14042 | struct intel_plane *cursor; | |
8e7d688b | 14043 | struct intel_plane_state *state; |
3d7d6510 MR |
14044 | |
14045 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
14046 | if (cursor == NULL) | |
14047 | return NULL; | |
14048 | ||
8e7d688b MR |
14049 | state = intel_create_plane_state(&cursor->base); |
14050 | if (!state) { | |
ea2c67bb MR |
14051 | kfree(cursor); |
14052 | return NULL; | |
14053 | } | |
8e7d688b | 14054 | cursor->base.state = &state->base; |
ea2c67bb | 14055 | |
3d7d6510 MR |
14056 | cursor->can_scale = false; |
14057 | cursor->max_downscale = 1; | |
14058 | cursor->pipe = pipe; | |
14059 | cursor->plane = pipe; | |
a9ff8714 | 14060 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 MR |
14061 | cursor->check_plane = intel_check_cursor_plane; |
14062 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 14063 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
14064 | |
14065 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 14066 | &intel_plane_funcs, |
3d7d6510 MR |
14067 | intel_cursor_formats, |
14068 | ARRAY_SIZE(intel_cursor_formats), | |
14069 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
14070 | |
14071 | if (INTEL_INFO(dev)->gen >= 4) { | |
14072 | if (!dev->mode_config.rotation_property) | |
14073 | dev->mode_config.rotation_property = | |
14074 | drm_mode_create_rotation_property(dev, | |
14075 | BIT(DRM_ROTATE_0) | | |
14076 | BIT(DRM_ROTATE_180)); | |
14077 | if (dev->mode_config.rotation_property) | |
14078 | drm_object_attach_property(&cursor->base.base, | |
14079 | dev->mode_config.rotation_property, | |
8e7d688b | 14080 | state->base.rotation); |
4398ad45 VS |
14081 | } |
14082 | ||
af99ceda CK |
14083 | if (INTEL_INFO(dev)->gen >=9) |
14084 | state->scaler_id = -1; | |
14085 | ||
ea2c67bb MR |
14086 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
14087 | ||
3d7d6510 MR |
14088 | return &cursor->base; |
14089 | } | |
14090 | ||
549e2bfb CK |
14091 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
14092 | struct intel_crtc_state *crtc_state) | |
14093 | { | |
14094 | int i; | |
14095 | struct intel_scaler *intel_scaler; | |
14096 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14097 | ||
14098 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14099 | intel_scaler = &scaler_state->scalers[i]; | |
14100 | intel_scaler->in_use = 0; | |
549e2bfb CK |
14101 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
14102 | } | |
14103 | ||
14104 | scaler_state->scaler_id = -1; | |
14105 | } | |
14106 | ||
b358d0a6 | 14107 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 14108 | { |
fbee40df | 14109 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 14110 | struct intel_crtc *intel_crtc; |
f5de6e07 | 14111 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
14112 | struct drm_plane *primary = NULL; |
14113 | struct drm_plane *cursor = NULL; | |
465c120c | 14114 | int i, ret; |
79e53945 | 14115 | |
955382f3 | 14116 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14117 | if (intel_crtc == NULL) |
14118 | return; | |
14119 | ||
f5de6e07 ACO |
14120 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14121 | if (!crtc_state) | |
14122 | goto fail; | |
550acefd ACO |
14123 | intel_crtc->config = crtc_state; |
14124 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14125 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14126 | |
549e2bfb CK |
14127 | /* initialize shared scalers */ |
14128 | if (INTEL_INFO(dev)->gen >= 9) { | |
14129 | if (pipe == PIPE_C) | |
14130 | intel_crtc->num_scalers = 1; | |
14131 | else | |
14132 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14133 | ||
14134 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14135 | } | |
14136 | ||
465c120c | 14137 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14138 | if (!primary) |
14139 | goto fail; | |
14140 | ||
14141 | cursor = intel_cursor_plane_create(dev, pipe); | |
14142 | if (!cursor) | |
14143 | goto fail; | |
14144 | ||
465c120c | 14145 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14146 | cursor, &intel_crtc_funcs); |
14147 | if (ret) | |
14148 | goto fail; | |
79e53945 JB |
14149 | |
14150 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14151 | for (i = 0; i < 256; i++) { |
14152 | intel_crtc->lut_r[i] = i; | |
14153 | intel_crtc->lut_g[i] = i; | |
14154 | intel_crtc->lut_b[i] = i; | |
14155 | } | |
14156 | ||
1f1c2e24 VS |
14157 | /* |
14158 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14159 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14160 | */ |
80824003 JB |
14161 | intel_crtc->pipe = pipe; |
14162 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14163 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14164 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14165 | intel_crtc->plane = !pipe; |
80824003 JB |
14166 | } |
14167 | ||
4b0e333e CW |
14168 | intel_crtc->cursor_base = ~0; |
14169 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14170 | intel_crtc->cursor_size = ~0; |
8d7849db | 14171 | |
852eb00d VS |
14172 | intel_crtc->wm.cxsr_allowed = true; |
14173 | ||
22fd0fab JB |
14174 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14175 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14176 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14177 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14178 | ||
79e53945 | 14179 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14180 | |
14181 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14182 | return; |
14183 | ||
14184 | fail: | |
14185 | if (primary) | |
14186 | drm_plane_cleanup(primary); | |
14187 | if (cursor) | |
14188 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14189 | kfree(crtc_state); |
3d7d6510 | 14190 | kfree(intel_crtc); |
79e53945 JB |
14191 | } |
14192 | ||
752aa88a JB |
14193 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14194 | { | |
14195 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14196 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14197 | |
51fd371b | 14198 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14199 | |
d3babd3f | 14200 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14201 | return INVALID_PIPE; |
14202 | ||
14203 | return to_intel_crtc(encoder->crtc)->pipe; | |
14204 | } | |
14205 | ||
08d7b3d1 | 14206 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14207 | struct drm_file *file) |
08d7b3d1 | 14208 | { |
08d7b3d1 | 14209 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14210 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14211 | struct intel_crtc *crtc; |
08d7b3d1 | 14212 | |
7707e653 | 14213 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14214 | |
7707e653 | 14215 | if (!drmmode_crtc) { |
08d7b3d1 | 14216 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14217 | return -ENOENT; |
08d7b3d1 CW |
14218 | } |
14219 | ||
7707e653 | 14220 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14221 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14222 | |
c05422d5 | 14223 | return 0; |
08d7b3d1 CW |
14224 | } |
14225 | ||
66a9278e | 14226 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14227 | { |
66a9278e DV |
14228 | struct drm_device *dev = encoder->base.dev; |
14229 | struct intel_encoder *source_encoder; | |
79e53945 | 14230 | int index_mask = 0; |
79e53945 JB |
14231 | int entry = 0; |
14232 | ||
b2784e15 | 14233 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14234 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14235 | index_mask |= (1 << entry); |
14236 | ||
79e53945 JB |
14237 | entry++; |
14238 | } | |
4ef69c7a | 14239 | |
79e53945 JB |
14240 | return index_mask; |
14241 | } | |
14242 | ||
4d302442 CW |
14243 | static bool has_edp_a(struct drm_device *dev) |
14244 | { | |
14245 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14246 | ||
14247 | if (!IS_MOBILE(dev)) | |
14248 | return false; | |
14249 | ||
14250 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14251 | return false; | |
14252 | ||
e3589908 | 14253 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14254 | return false; |
14255 | ||
14256 | return true; | |
14257 | } | |
14258 | ||
84b4e042 JB |
14259 | static bool intel_crt_present(struct drm_device *dev) |
14260 | { | |
14261 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14262 | ||
884497ed DL |
14263 | if (INTEL_INFO(dev)->gen >= 9) |
14264 | return false; | |
14265 | ||
cf404ce4 | 14266 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14267 | return false; |
14268 | ||
14269 | if (IS_CHERRYVIEW(dev)) | |
14270 | return false; | |
14271 | ||
65e472e4 VS |
14272 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
14273 | return false; | |
14274 | ||
70ac54d0 VS |
14275 | /* DDI E can't be used if DDI A requires 4 lanes */ |
14276 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) | |
14277 | return false; | |
14278 | ||
e4abb733 | 14279 | if (!dev_priv->vbt.int_crt_support) |
84b4e042 JB |
14280 | return false; |
14281 | ||
14282 | return true; | |
14283 | } | |
14284 | ||
79e53945 JB |
14285 | static void intel_setup_outputs(struct drm_device *dev) |
14286 | { | |
725e30ad | 14287 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14288 | struct intel_encoder *encoder; |
cb0953d7 | 14289 | bool dpd_is_edp = false; |
79e53945 | 14290 | |
c9093354 | 14291 | intel_lvds_init(dev); |
79e53945 | 14292 | |
84b4e042 | 14293 | if (intel_crt_present(dev)) |
79935fca | 14294 | intel_crt_init(dev); |
cb0953d7 | 14295 | |
c776eb2e VK |
14296 | if (IS_BROXTON(dev)) { |
14297 | /* | |
14298 | * FIXME: Broxton doesn't support port detection via the | |
14299 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14300 | * detect the ports. | |
14301 | */ | |
14302 | intel_ddi_init(dev, PORT_A); | |
14303 | intel_ddi_init(dev, PORT_B); | |
14304 | intel_ddi_init(dev, PORT_C); | |
14305 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14306 | int found; |
14307 | ||
de31facd JB |
14308 | /* |
14309 | * Haswell uses DDI functions to detect digital outputs. | |
14310 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14311 | * it's there. | |
14312 | */ | |
77179400 | 14313 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14314 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14315 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14316 | intel_ddi_init(dev, PORT_A); |
14317 | ||
14318 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14319 | * register */ | |
14320 | found = I915_READ(SFUSE_STRAP); | |
14321 | ||
14322 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14323 | intel_ddi_init(dev, PORT_B); | |
14324 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14325 | intel_ddi_init(dev, PORT_C); | |
14326 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14327 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14328 | /* |
14329 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14330 | */ | |
ef11bdb3 | 14331 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14332 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14333 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14334 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14335 | intel_ddi_init(dev, PORT_E); | |
14336 | ||
0e72a5b5 | 14337 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14338 | int found; |
5d8a7752 | 14339 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14340 | |
14341 | if (has_edp_a(dev)) | |
14342 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14343 | |
dc0fa718 | 14344 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14345 | /* PCH SDVOB multiplex with HDMIB */ |
2a5c0832 | 14346 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
30ad48b7 | 14347 | if (!found) |
e2debe91 | 14348 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14349 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14350 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14351 | } |
14352 | ||
dc0fa718 | 14353 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14354 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14355 | |
dc0fa718 | 14356 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14357 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14358 | |
5eb08b69 | 14359 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14360 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14361 | |
270b3042 | 14362 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14363 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14364 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14365 | /* |
14366 | * The DP_DETECTED bit is the latched state of the DDC | |
14367 | * SDA pin at boot. However since eDP doesn't require DDC | |
14368 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14369 | * eDP ports may have been muxed to an alternate function. | |
14370 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14371 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14372 | * detect eDP ports. | |
14373 | */ | |
e66eb81d | 14374 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
d2182a66 | 14375 | !intel_dp_is_edp(dev, PORT_B)) |
e66eb81d VS |
14376 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
14377 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
e17ac6db | 14378 | intel_dp_is_edp(dev, PORT_B)) |
e66eb81d | 14379 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
585a94b8 | 14380 | |
e66eb81d | 14381 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
d2182a66 | 14382 | !intel_dp_is_edp(dev, PORT_C)) |
e66eb81d VS |
14383 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
14384 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
e17ac6db | 14385 | intel_dp_is_edp(dev, PORT_C)) |
e66eb81d | 14386 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
19c03924 | 14387 | |
9418c1f1 | 14388 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14389 | /* eDP not supported on port D, so don't check VBT */ |
e66eb81d VS |
14390 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
14391 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14392 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14393 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
9418c1f1 VS |
14394 | } |
14395 | ||
3cfca973 | 14396 | intel_dsi_init(dev); |
09da55dc | 14397 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14398 | bool found = false; |
7d57382e | 14399 | |
e2debe91 | 14400 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14401 | DRM_DEBUG_KMS("probing SDVOB\n"); |
2a5c0832 | 14402 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
3fec3d2f | 14403 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14404 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14405 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14406 | } |
27185ae1 | 14407 | |
3fec3d2f | 14408 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14409 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14410 | } |
13520b05 KH |
14411 | |
14412 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14413 | |
e2debe91 | 14414 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14415 | DRM_DEBUG_KMS("probing SDVOC\n"); |
2a5c0832 | 14416 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
b01f2c3a | 14417 | } |
27185ae1 | 14418 | |
e2debe91 | 14419 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14420 | |
3fec3d2f | 14421 | if (IS_G4X(dev)) { |
b01f2c3a | 14422 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14423 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14424 | } |
3fec3d2f | 14425 | if (IS_G4X(dev)) |
ab9d7c30 | 14426 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14427 | } |
27185ae1 | 14428 | |
3fec3d2f | 14429 | if (IS_G4X(dev) && |
e7281eab | 14430 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14431 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14432 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14433 | intel_dvo_init(dev); |
14434 | ||
103a196f | 14435 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14436 | intel_tv_init(dev); |
14437 | ||
0bc12bcb | 14438 | intel_psr_init(dev); |
7c8f8a70 | 14439 | |
b2784e15 | 14440 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14441 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14442 | encoder->base.possible_clones = | |
66a9278e | 14443 | intel_encoder_clones(encoder); |
79e53945 | 14444 | } |
47356eb6 | 14445 | |
dde86e2d | 14446 | intel_init_pch_refclk(dev); |
270b3042 DV |
14447 | |
14448 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14449 | } |
14450 | ||
14451 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14452 | { | |
60a5ca01 | 14453 | struct drm_device *dev = fb->dev; |
79e53945 | 14454 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14455 | |
ef2d633e | 14456 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14457 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14458 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14459 | drm_gem_object_unreference(&intel_fb->obj->base); |
14460 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14461 | kfree(intel_fb); |
14462 | } | |
14463 | ||
14464 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14465 | struct drm_file *file, |
79e53945 JB |
14466 | unsigned int *handle) |
14467 | { | |
14468 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14469 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14470 | |
cc917ab4 CW |
14471 | if (obj->userptr.mm) { |
14472 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); | |
14473 | return -EINVAL; | |
14474 | } | |
14475 | ||
05394f39 | 14476 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14477 | } |
14478 | ||
86c98588 RV |
14479 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14480 | struct drm_file *file, | |
14481 | unsigned flags, unsigned color, | |
14482 | struct drm_clip_rect *clips, | |
14483 | unsigned num_clips) | |
14484 | { | |
14485 | struct drm_device *dev = fb->dev; | |
14486 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14487 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14488 | ||
14489 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14490 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14491 | mutex_unlock(&dev->struct_mutex); |
14492 | ||
14493 | return 0; | |
14494 | } | |
14495 | ||
79e53945 JB |
14496 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14497 | .destroy = intel_user_framebuffer_destroy, | |
14498 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14499 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14500 | }; |
14501 | ||
b321803d DL |
14502 | static |
14503 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14504 | uint32_t pixel_format) | |
14505 | { | |
14506 | u32 gen = INTEL_INFO(dev)->gen; | |
14507 | ||
14508 | if (gen >= 9) { | |
14509 | /* "The stride in bytes must not exceed the of the size of 8K | |
14510 | * pixels and 32K bytes." | |
14511 | */ | |
14512 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14513 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14514 | return 32*1024; | |
14515 | } else if (gen >= 4) { | |
14516 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14517 | return 16*1024; | |
14518 | else | |
14519 | return 32*1024; | |
14520 | } else if (gen >= 3) { | |
14521 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14522 | return 8*1024; | |
14523 | else | |
14524 | return 16*1024; | |
14525 | } else { | |
14526 | /* XXX DSPC is limited to 4k tiled */ | |
14527 | return 8*1024; | |
14528 | } | |
14529 | } | |
14530 | ||
b5ea642a DV |
14531 | static int intel_framebuffer_init(struct drm_device *dev, |
14532 | struct intel_framebuffer *intel_fb, | |
14533 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14534 | struct drm_i915_gem_object *obj) | |
79e53945 | 14535 | { |
6761dd31 | 14536 | unsigned int aligned_height; |
79e53945 | 14537 | int ret; |
b321803d | 14538 | u32 pitch_limit, stride_alignment; |
79e53945 | 14539 | |
dd4916c5 DV |
14540 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14541 | ||
2a80eada DV |
14542 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14543 | /* Enforce that fb modifier and tiling mode match, but only for | |
14544 | * X-tiled. This is needed for FBC. */ | |
14545 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14546 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14547 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14548 | return -EINVAL; | |
14549 | } | |
14550 | } else { | |
14551 | if (obj->tiling_mode == I915_TILING_X) | |
14552 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14553 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14554 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14555 | return -EINVAL; | |
14556 | } | |
14557 | } | |
14558 | ||
9a8f0a12 TU |
14559 | /* Passed in modifier sanity checking. */ |
14560 | switch (mode_cmd->modifier[0]) { | |
14561 | case I915_FORMAT_MOD_Y_TILED: | |
14562 | case I915_FORMAT_MOD_Yf_TILED: | |
14563 | if (INTEL_INFO(dev)->gen < 9) { | |
14564 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14565 | mode_cmd->modifier[0]); | |
14566 | return -EINVAL; | |
14567 | } | |
14568 | case DRM_FORMAT_MOD_NONE: | |
14569 | case I915_FORMAT_MOD_X_TILED: | |
14570 | break; | |
14571 | default: | |
c0f40428 JB |
14572 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14573 | mode_cmd->modifier[0]); | |
57cd6508 | 14574 | return -EINVAL; |
c16ed4be | 14575 | } |
57cd6508 | 14576 | |
b321803d DL |
14577 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14578 | mode_cmd->pixel_format); | |
14579 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14580 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14581 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14582 | return -EINVAL; |
c16ed4be | 14583 | } |
57cd6508 | 14584 | |
b321803d DL |
14585 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14586 | mode_cmd->pixel_format); | |
a35cdaa0 | 14587 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14588 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14589 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14590 | "tiled" : "linear", |
a35cdaa0 | 14591 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14592 | return -EINVAL; |
c16ed4be | 14593 | } |
5d7bd705 | 14594 | |
2a80eada | 14595 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14596 | mode_cmd->pitches[0] != obj->stride) { |
14597 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14598 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14599 | return -EINVAL; |
c16ed4be | 14600 | } |
5d7bd705 | 14601 | |
57779d06 | 14602 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14603 | switch (mode_cmd->pixel_format) { |
57779d06 | 14604 | case DRM_FORMAT_C8: |
04b3924d VS |
14605 | case DRM_FORMAT_RGB565: |
14606 | case DRM_FORMAT_XRGB8888: | |
14607 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14608 | break; |
14609 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14610 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14611 | DRM_DEBUG("unsupported pixel format: %s\n", |
14612 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14613 | return -EINVAL; |
c16ed4be | 14614 | } |
57779d06 | 14615 | break; |
57779d06 | 14616 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14617 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14618 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14619 | drm_get_format_name(mode_cmd->pixel_format)); | |
14620 | return -EINVAL; | |
14621 | } | |
14622 | break; | |
14623 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14624 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14625 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14626 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14627 | DRM_DEBUG("unsupported pixel format: %s\n", |
14628 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14629 | return -EINVAL; |
c16ed4be | 14630 | } |
b5626747 | 14631 | break; |
7531208b DL |
14632 | case DRM_FORMAT_ABGR2101010: |
14633 | if (!IS_VALLEYVIEW(dev)) { | |
14634 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14635 | drm_get_format_name(mode_cmd->pixel_format)); | |
14636 | return -EINVAL; | |
14637 | } | |
14638 | break; | |
04b3924d VS |
14639 | case DRM_FORMAT_YUYV: |
14640 | case DRM_FORMAT_UYVY: | |
14641 | case DRM_FORMAT_YVYU: | |
14642 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14643 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14644 | DRM_DEBUG("unsupported pixel format: %s\n", |
14645 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14646 | return -EINVAL; |
c16ed4be | 14647 | } |
57cd6508 CW |
14648 | break; |
14649 | default: | |
4ee62c76 VS |
14650 | DRM_DEBUG("unsupported pixel format: %s\n", |
14651 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14652 | return -EINVAL; |
14653 | } | |
14654 | ||
90f9a336 VS |
14655 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14656 | if (mode_cmd->offsets[0] != 0) | |
14657 | return -EINVAL; | |
14658 | ||
ec2c981e | 14659 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14660 | mode_cmd->pixel_format, |
14661 | mode_cmd->modifier[0]); | |
53155c0a DV |
14662 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14663 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14664 | return -EINVAL; | |
14665 | ||
c7d73f6a DV |
14666 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14667 | intel_fb->obj = obj; | |
80075d49 | 14668 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14669 | |
79e53945 JB |
14670 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14671 | if (ret) { | |
14672 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14673 | return ret; | |
14674 | } | |
14675 | ||
79e53945 JB |
14676 | return 0; |
14677 | } | |
14678 | ||
79e53945 JB |
14679 | static struct drm_framebuffer * |
14680 | intel_user_framebuffer_create(struct drm_device *dev, | |
14681 | struct drm_file *filp, | |
76dc3769 | 14682 | struct drm_mode_fb_cmd2 *user_mode_cmd) |
79e53945 | 14683 | { |
dcb1394e | 14684 | struct drm_framebuffer *fb; |
05394f39 | 14685 | struct drm_i915_gem_object *obj; |
76dc3769 | 14686 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
79e53945 | 14687 | |
308e5bcb | 14688 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
76dc3769 | 14689 | mode_cmd.handles[0])); |
c8725226 | 14690 | if (&obj->base == NULL) |
cce13ff7 | 14691 | return ERR_PTR(-ENOENT); |
79e53945 | 14692 | |
92907cbb | 14693 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
dcb1394e LW |
14694 | if (IS_ERR(fb)) |
14695 | drm_gem_object_unreference_unlocked(&obj->base); | |
14696 | ||
14697 | return fb; | |
79e53945 JB |
14698 | } |
14699 | ||
0695726e | 14700 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 14701 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14702 | { |
14703 | } | |
14704 | #endif | |
14705 | ||
79e53945 | 14706 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14707 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14708 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14709 | .atomic_check = intel_atomic_check, |
14710 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14711 | .atomic_state_alloc = intel_atomic_state_alloc, |
14712 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14713 | }; |
14714 | ||
e70236a8 JB |
14715 | /* Set up chip specific display functions */ |
14716 | static void intel_init_display(struct drm_device *dev) | |
14717 | { | |
14718 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14719 | ||
ee9300bb DV |
14720 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14721 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14722 | else if (IS_CHERRYVIEW(dev)) |
14723 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14724 | else if (IS_VALLEYVIEW(dev)) |
14725 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14726 | else if (IS_PINEVIEW(dev)) | |
14727 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14728 | else | |
14729 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14730 | ||
bc8d7dff DL |
14731 | if (INTEL_INFO(dev)->gen >= 9) { |
14732 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14733 | dev_priv->display.get_initial_plane_config = |
14734 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14735 | dev_priv->display.crtc_compute_clock = |
14736 | haswell_crtc_compute_clock; | |
14737 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14738 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14739 | dev_priv->display.update_primary_plane = |
14740 | skylake_update_primary_plane; | |
14741 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14742 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14743 | dev_priv->display.get_initial_plane_config = |
14744 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14745 | dev_priv->display.crtc_compute_clock = |
14746 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14747 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14748 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14749 | dev_priv->display.update_primary_plane = |
14750 | ironlake_update_primary_plane; | |
09b4ddf9 | 14751 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14752 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14753 | dev_priv->display.get_initial_plane_config = |
14754 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14755 | dev_priv->display.crtc_compute_clock = |
14756 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14757 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14758 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14759 | dev_priv->display.update_primary_plane = |
14760 | ironlake_update_primary_plane; | |
89b667f8 JB |
14761 | } else if (IS_VALLEYVIEW(dev)) { |
14762 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14763 | dev_priv->display.get_initial_plane_config = |
14764 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14765 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14766 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14767 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14768 | dev_priv->display.update_primary_plane = |
14769 | i9xx_update_primary_plane; | |
f564048e | 14770 | } else { |
0e8ffe1b | 14771 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14772 | dev_priv->display.get_initial_plane_config = |
14773 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14774 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14775 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14776 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14777 | dev_priv->display.update_primary_plane = |
14778 | i9xx_update_primary_plane; | |
f564048e | 14779 | } |
e70236a8 | 14780 | |
e70236a8 | 14781 | /* Returns the core display clock speed */ |
ef11bdb3 | 14782 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
1652d19e VS |
14783 | dev_priv->display.get_display_clock_speed = |
14784 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
14785 | else if (IS_BROXTON(dev)) |
14786 | dev_priv->display.get_display_clock_speed = | |
14787 | broxton_get_display_clock_speed; | |
1652d19e VS |
14788 | else if (IS_BROADWELL(dev)) |
14789 | dev_priv->display.get_display_clock_speed = | |
14790 | broadwell_get_display_clock_speed; | |
14791 | else if (IS_HASWELL(dev)) | |
14792 | dev_priv->display.get_display_clock_speed = | |
14793 | haswell_get_display_clock_speed; | |
14794 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14795 | dev_priv->display.get_display_clock_speed = |
14796 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14797 | else if (IS_GEN5(dev)) |
14798 | dev_priv->display.get_display_clock_speed = | |
14799 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14800 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14801 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14802 | dev_priv->display.get_display_clock_speed = |
14803 | i945_get_display_clock_speed; | |
34edce2f VS |
14804 | else if (IS_GM45(dev)) |
14805 | dev_priv->display.get_display_clock_speed = | |
14806 | gm45_get_display_clock_speed; | |
14807 | else if (IS_CRESTLINE(dev)) | |
14808 | dev_priv->display.get_display_clock_speed = | |
14809 | i965gm_get_display_clock_speed; | |
14810 | else if (IS_PINEVIEW(dev)) | |
14811 | dev_priv->display.get_display_clock_speed = | |
14812 | pnv_get_display_clock_speed; | |
14813 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14814 | dev_priv->display.get_display_clock_speed = | |
14815 | g33_get_display_clock_speed; | |
e70236a8 JB |
14816 | else if (IS_I915G(dev)) |
14817 | dev_priv->display.get_display_clock_speed = | |
14818 | i915_get_display_clock_speed; | |
257a7ffc | 14819 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14820 | dev_priv->display.get_display_clock_speed = |
14821 | i9xx_misc_get_display_clock_speed; | |
14822 | else if (IS_I915GM(dev)) | |
14823 | dev_priv->display.get_display_clock_speed = | |
14824 | i915gm_get_display_clock_speed; | |
14825 | else if (IS_I865G(dev)) | |
14826 | dev_priv->display.get_display_clock_speed = | |
14827 | i865_get_display_clock_speed; | |
f0f8a9ce | 14828 | else if (IS_I85X(dev)) |
e70236a8 | 14829 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14830 | i85x_get_display_clock_speed; |
623e01e5 VS |
14831 | else { /* 830 */ |
14832 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14833 | dev_priv->display.get_display_clock_speed = |
14834 | i830_get_display_clock_speed; | |
623e01e5 | 14835 | } |
e70236a8 | 14836 | |
7c10a2b5 | 14837 | if (IS_GEN5(dev)) { |
3bb11b53 | 14838 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14839 | } else if (IS_GEN6(dev)) { |
14840 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14841 | } else if (IS_IVYBRIDGE(dev)) { |
14842 | /* FIXME: detect B0+ stepping and use auto training */ | |
14843 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14844 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14845 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
14846 | if (IS_BROADWELL(dev)) { |
14847 | dev_priv->display.modeset_commit_cdclk = | |
14848 | broadwell_modeset_commit_cdclk; | |
14849 | dev_priv->display.modeset_calc_cdclk = | |
14850 | broadwell_modeset_calc_cdclk; | |
14851 | } | |
30a970c6 | 14852 | } else if (IS_VALLEYVIEW(dev)) { |
27c329ed ML |
14853 | dev_priv->display.modeset_commit_cdclk = |
14854 | valleyview_modeset_commit_cdclk; | |
14855 | dev_priv->display.modeset_calc_cdclk = | |
14856 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 14857 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
14858 | dev_priv->display.modeset_commit_cdclk = |
14859 | broxton_modeset_commit_cdclk; | |
14860 | dev_priv->display.modeset_calc_cdclk = | |
14861 | broxton_modeset_calc_cdclk; | |
e70236a8 | 14862 | } |
8c9f3aaf | 14863 | |
8c9f3aaf JB |
14864 | switch (INTEL_INFO(dev)->gen) { |
14865 | case 2: | |
14866 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14867 | break; | |
14868 | ||
14869 | case 3: | |
14870 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14871 | break; | |
14872 | ||
14873 | case 4: | |
14874 | case 5: | |
14875 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14876 | break; | |
14877 | ||
14878 | case 6: | |
14879 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14880 | break; | |
7c9017e5 | 14881 | case 7: |
4e0bbc31 | 14882 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14883 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14884 | break; | |
830c81db | 14885 | case 9: |
ba343e02 TU |
14886 | /* Drop through - unsupported since execlist only. */ |
14887 | default: | |
14888 | /* Default just returns -ENODEV to indicate unsupported */ | |
14889 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14890 | } |
7bd688cd | 14891 | |
e39b999a | 14892 | mutex_init(&dev_priv->pps_mutex); |
e70236a8 JB |
14893 | } |
14894 | ||
b690e96c JB |
14895 | /* |
14896 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14897 | * resume, or other times. This quirk makes sure that's the case for | |
14898 | * affected systems. | |
14899 | */ | |
0206e353 | 14900 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14901 | { |
14902 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14903 | ||
14904 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14905 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14906 | } |
14907 | ||
b6b5d049 VS |
14908 | static void quirk_pipeb_force(struct drm_device *dev) |
14909 | { | |
14910 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14911 | ||
14912 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14913 | DRM_INFO("applying pipe b force quirk\n"); | |
14914 | } | |
14915 | ||
435793df KP |
14916 | /* |
14917 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14918 | */ | |
14919 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14920 | { | |
14921 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14922 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14923 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14924 | } |
14925 | ||
4dca20ef | 14926 | /* |
5a15ab5b CE |
14927 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14928 | * brightness value | |
4dca20ef CE |
14929 | */ |
14930 | static void quirk_invert_brightness(struct drm_device *dev) | |
14931 | { | |
14932 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14933 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14934 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14935 | } |
14936 | ||
9c72cc6f SD |
14937 | /* Some VBT's incorrectly indicate no backlight is present */ |
14938 | static void quirk_backlight_present(struct drm_device *dev) | |
14939 | { | |
14940 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14941 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14942 | DRM_INFO("applying backlight present quirk\n"); | |
14943 | } | |
14944 | ||
b690e96c JB |
14945 | struct intel_quirk { |
14946 | int device; | |
14947 | int subsystem_vendor; | |
14948 | int subsystem_device; | |
14949 | void (*hook)(struct drm_device *dev); | |
14950 | }; | |
14951 | ||
5f85f176 EE |
14952 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14953 | struct intel_dmi_quirk { | |
14954 | void (*hook)(struct drm_device *dev); | |
14955 | const struct dmi_system_id (*dmi_id_list)[]; | |
14956 | }; | |
14957 | ||
14958 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14959 | { | |
14960 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14961 | return 1; | |
14962 | } | |
14963 | ||
14964 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14965 | { | |
14966 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14967 | { | |
14968 | .callback = intel_dmi_reverse_brightness, | |
14969 | .ident = "NCR Corporation", | |
14970 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14971 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14972 | }, | |
14973 | }, | |
14974 | { } /* terminating entry */ | |
14975 | }, | |
14976 | .hook = quirk_invert_brightness, | |
14977 | }, | |
14978 | }; | |
14979 | ||
c43b5634 | 14980 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14981 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14982 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14983 | ||
b690e96c JB |
14984 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14985 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14986 | ||
5f080c0f VS |
14987 | /* 830 needs to leave pipe A & dpll A up */ |
14988 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14989 | ||
b6b5d049 VS |
14990 | /* 830 needs to leave pipe B & dpll B up */ |
14991 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14992 | ||
435793df KP |
14993 | /* Lenovo U160 cannot use SSC on LVDS */ |
14994 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14995 | |
14996 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14997 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14998 | |
be505f64 AH |
14999 | /* Acer Aspire 5734Z must invert backlight brightness */ |
15000 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
15001 | ||
15002 | /* Acer/eMachines G725 */ | |
15003 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
15004 | ||
15005 | /* Acer/eMachines e725 */ | |
15006 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
15007 | ||
15008 | /* Acer/Packard Bell NCL20 */ | |
15009 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
15010 | ||
15011 | /* Acer Aspire 4736Z */ | |
15012 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
15013 | |
15014 | /* Acer Aspire 5336 */ | |
15015 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
15016 | |
15017 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
15018 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 15019 | |
dfb3d47b SD |
15020 | /* Acer C720 Chromebook (Core i3 4005U) */ |
15021 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
15022 | ||
b2a9601c | 15023 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
15024 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
15025 | ||
1b9448b0 JN |
15026 | /* Apple Macbook 4,1 */ |
15027 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, | |
15028 | ||
d4967d8c SD |
15029 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
15030 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
15031 | |
15032 | /* HP Chromebook 14 (Celeron 2955U) */ | |
15033 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
15034 | |
15035 | /* Dell Chromebook 11 */ | |
15036 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
9be64eee JN |
15037 | |
15038 | /* Dell Chromebook 11 (2015 version) */ | |
15039 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
15040 | }; |
15041 | ||
15042 | static void intel_init_quirks(struct drm_device *dev) | |
15043 | { | |
15044 | struct pci_dev *d = dev->pdev; | |
15045 | int i; | |
15046 | ||
15047 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
15048 | struct intel_quirk *q = &intel_quirks[i]; | |
15049 | ||
15050 | if (d->device == q->device && | |
15051 | (d->subsystem_vendor == q->subsystem_vendor || | |
15052 | q->subsystem_vendor == PCI_ANY_ID) && | |
15053 | (d->subsystem_device == q->subsystem_device || | |
15054 | q->subsystem_device == PCI_ANY_ID)) | |
15055 | q->hook(dev); | |
15056 | } | |
5f85f176 EE |
15057 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
15058 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
15059 | intel_dmi_quirks[i].hook(dev); | |
15060 | } | |
b690e96c JB |
15061 | } |
15062 | ||
9cce37f4 JB |
15063 | /* Disable the VGA plane that we never use */ |
15064 | static void i915_disable_vga(struct drm_device *dev) | |
15065 | { | |
15066 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15067 | u8 sr1; | |
f0f59a00 | 15068 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 15069 | |
2b37c616 | 15070 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 15071 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 15072 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
15073 | sr1 = inb(VGA_SR_DATA); |
15074 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15075 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15076 | udelay(300); | |
15077 | ||
01f5a626 | 15078 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
15079 | POSTING_READ(vga_reg); |
15080 | } | |
15081 | ||
f817586c DV |
15082 | void intel_modeset_init_hw(struct drm_device *dev) |
15083 | { | |
b6283055 | 15084 | intel_update_cdclk(dev); |
a8f78b58 | 15085 | intel_prepare_ddi(dev); |
f817586c | 15086 | intel_init_clock_gating(dev); |
8090c6b9 | 15087 | intel_enable_gt_powersave(dev); |
f817586c DV |
15088 | } |
15089 | ||
79e53945 JB |
15090 | void intel_modeset_init(struct drm_device *dev) |
15091 | { | |
652c393a | 15092 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 15093 | int sprite, ret; |
8cc87b75 | 15094 | enum pipe pipe; |
46f297fb | 15095 | struct intel_crtc *crtc; |
79e53945 JB |
15096 | |
15097 | drm_mode_config_init(dev); | |
15098 | ||
15099 | dev->mode_config.min_width = 0; | |
15100 | dev->mode_config.min_height = 0; | |
15101 | ||
019d96cb DA |
15102 | dev->mode_config.preferred_depth = 24; |
15103 | dev->mode_config.prefer_shadow = 1; | |
15104 | ||
25bab385 TU |
15105 | dev->mode_config.allow_fb_modifiers = true; |
15106 | ||
e6ecefaa | 15107 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 15108 | |
b690e96c JB |
15109 | intel_init_quirks(dev); |
15110 | ||
1fa61106 ED |
15111 | intel_init_pm(dev); |
15112 | ||
e3c74757 BW |
15113 | if (INTEL_INFO(dev)->num_pipes == 0) |
15114 | return; | |
15115 | ||
69f92f67 LW |
15116 | /* |
15117 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15118 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15119 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15120 | * indicates as much. | |
15121 | */ | |
15122 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
15123 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15124 | DREF_SSC1_ENABLE); | |
15125 | ||
15126 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
15127 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
15128 | bios_lvds_use_ssc ? "en" : "dis", | |
15129 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
15130 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
15131 | } | |
15132 | } | |
15133 | ||
e70236a8 | 15134 | intel_init_display(dev); |
7c10a2b5 | 15135 | intel_init_audio(dev); |
e70236a8 | 15136 | |
a6c45cf0 CW |
15137 | if (IS_GEN2(dev)) { |
15138 | dev->mode_config.max_width = 2048; | |
15139 | dev->mode_config.max_height = 2048; | |
15140 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15141 | dev->mode_config.max_width = 4096; |
15142 | dev->mode_config.max_height = 4096; | |
79e53945 | 15143 | } else { |
a6c45cf0 CW |
15144 | dev->mode_config.max_width = 8192; |
15145 | dev->mode_config.max_height = 8192; | |
79e53945 | 15146 | } |
068be561 | 15147 | |
dc41c154 VS |
15148 | if (IS_845G(dev) || IS_I865G(dev)) { |
15149 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15150 | dev->mode_config.cursor_height = 1023; | |
15151 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15152 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15153 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15154 | } else { | |
15155 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15156 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15157 | } | |
15158 | ||
5d4545ae | 15159 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15160 | |
28c97730 | 15161 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15162 | INTEL_INFO(dev)->num_pipes, |
15163 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15164 | |
055e393f | 15165 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15166 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15167 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15168 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15169 | if (ret) |
06da8da2 | 15170 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15171 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15172 | } |
79e53945 JB |
15173 | } |
15174 | ||
bfa7df01 VS |
15175 | intel_update_czclk(dev_priv); |
15176 | intel_update_cdclk(dev); | |
15177 | ||
e72f9fbf | 15178 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15179 | |
9cce37f4 JB |
15180 | /* Just disable it once at startup */ |
15181 | i915_disable_vga(dev); | |
79e53945 | 15182 | intel_setup_outputs(dev); |
11be49eb | 15183 | |
6e9f798d | 15184 | drm_modeset_lock_all(dev); |
043e9bda | 15185 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15186 | drm_modeset_unlock_all(dev); |
46f297fb | 15187 | |
d3fcc808 | 15188 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15189 | struct intel_initial_plane_config plane_config = {}; |
15190 | ||
46f297fb JB |
15191 | if (!crtc->active) |
15192 | continue; | |
15193 | ||
46f297fb | 15194 | /* |
46f297fb JB |
15195 | * Note that reserving the BIOS fb up front prevents us |
15196 | * from stuffing other stolen allocations like the ring | |
15197 | * on top. This prevents some ugliness at boot time, and | |
15198 | * can even allow for smooth boot transitions if the BIOS | |
15199 | * fb is large enough for the active pipe configuration. | |
15200 | */ | |
eeebeac5 ML |
15201 | dev_priv->display.get_initial_plane_config(crtc, |
15202 | &plane_config); | |
15203 | ||
15204 | /* | |
15205 | * If the fb is shared between multiple heads, we'll | |
15206 | * just get the first one. | |
15207 | */ | |
15208 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15209 | } |
2c7111db CW |
15210 | } |
15211 | ||
7fad798e DV |
15212 | static void intel_enable_pipe_a(struct drm_device *dev) |
15213 | { | |
15214 | struct intel_connector *connector; | |
15215 | struct drm_connector *crt = NULL; | |
15216 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15217 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15218 | |
15219 | /* We can't just switch on the pipe A, we need to set things up with a | |
15220 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15221 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15222 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15223 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15224 | crt = &connector->base; | |
15225 | break; | |
15226 | } | |
15227 | } | |
15228 | ||
15229 | if (!crt) | |
15230 | return; | |
15231 | ||
208bf9fd | 15232 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15233 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15234 | } |
15235 | ||
fa555837 DV |
15236 | static bool |
15237 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15238 | { | |
7eb552ae BW |
15239 | struct drm_device *dev = crtc->base.dev; |
15240 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15241 | u32 val; |
fa555837 | 15242 | |
7eb552ae | 15243 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15244 | return true; |
15245 | ||
649636ef | 15246 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15247 | |
15248 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15249 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15250 | return false; | |
15251 | ||
15252 | return true; | |
15253 | } | |
15254 | ||
02e93c35 VS |
15255 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15256 | { | |
15257 | struct drm_device *dev = crtc->base.dev; | |
15258 | struct intel_encoder *encoder; | |
15259 | ||
15260 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15261 | return true; | |
15262 | ||
15263 | return false; | |
15264 | } | |
15265 | ||
24929352 DV |
15266 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15267 | { | |
15268 | struct drm_device *dev = crtc->base.dev; | |
15269 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15270 | i915_reg_t reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 | 15271 | |
24929352 | 15272 | /* Clear any frame start delays used for debugging left by the BIOS */ |
24929352 DV |
15273 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15274 | ||
d3eaf884 | 15275 | /* restore vblank interrupts to correct state */ |
9625604c | 15276 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15277 | if (crtc->active) { |
f9cd7b88 VS |
15278 | struct intel_plane *plane; |
15279 | ||
9625604c | 15280 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15281 | |
15282 | /* Disable everything but the primary plane */ | |
15283 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15284 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15285 | continue; | |
15286 | ||
15287 | plane->disable_plane(&plane->base, &crtc->base); | |
15288 | } | |
9625604c | 15289 | } |
d3eaf884 | 15290 | |
24929352 | 15291 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15292 | * disable the crtc (and hence change the state) if it is wrong. Note |
15293 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15294 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15295 | bool plane; |
15296 | ||
24929352 DV |
15297 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15298 | crtc->base.base.id); | |
15299 | ||
15300 | /* Pipe has the wrong plane attached and the plane is active. | |
15301 | * Temporarily change the plane mapping and disable everything | |
15302 | * ... */ | |
15303 | plane = crtc->plane; | |
b70709a6 | 15304 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15305 | crtc->plane = !plane; |
b17d48e2 | 15306 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15307 | crtc->plane = plane; |
24929352 | 15308 | } |
24929352 | 15309 | |
7fad798e DV |
15310 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15311 | crtc->pipe == PIPE_A && !crtc->active) { | |
15312 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15313 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15314 | * call below we restore the pipe to the right state, but leave | |
15315 | * the required bits on. */ | |
15316 | intel_enable_pipe_a(dev); | |
15317 | } | |
15318 | ||
24929352 DV |
15319 | /* Adjust the state of the output pipe according to whether we |
15320 | * have active connectors/encoders. */ | |
02e93c35 | 15321 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15322 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15323 | |
53d9f4e9 | 15324 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 15325 | struct intel_encoder *encoder; |
24929352 DV |
15326 | |
15327 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15328 | * functions or because of calls to intel_crtc_disable_noatomic, |
15329 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15330 | * pipe A quirk. */ |
15331 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15332 | crtc->base.base.id, | |
83d65738 | 15333 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15334 | crtc->active ? "enabled" : "disabled"); |
15335 | ||
4be40c98 | 15336 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 15337 | crtc->base.state->active = crtc->active; |
24929352 DV |
15338 | crtc->base.enabled = crtc->active; |
15339 | ||
15340 | /* Because we only establish the connector -> encoder -> | |
15341 | * crtc links if something is active, this means the | |
15342 | * crtc is now deactivated. Break the links. connector | |
15343 | * -> encoder links are only establish when things are | |
15344 | * actually up, hence no need to break them. */ | |
15345 | WARN_ON(crtc->active); | |
15346 | ||
2d406bb0 | 15347 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 15348 | encoder->base.crtc = NULL; |
24929352 | 15349 | } |
c5ab3bc0 | 15350 | |
a3ed6aad | 15351 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15352 | /* |
15353 | * We start out with underrun reporting disabled to avoid races. | |
15354 | * For correct bookkeeping mark this on active crtcs. | |
15355 | * | |
c5ab3bc0 DV |
15356 | * Also on gmch platforms we dont have any hardware bits to |
15357 | * disable the underrun reporting. Which means we need to start | |
15358 | * out with underrun reporting disabled also on inactive pipes, | |
15359 | * since otherwise we'll complain about the garbage we read when | |
15360 | * e.g. coming up after runtime pm. | |
15361 | * | |
4cc31489 DV |
15362 | * No protection against concurrent access is required - at |
15363 | * worst a fifo underrun happens which also sets this to false. | |
15364 | */ | |
15365 | crtc->cpu_fifo_underrun_disabled = true; | |
15366 | crtc->pch_fifo_underrun_disabled = true; | |
15367 | } | |
24929352 DV |
15368 | } |
15369 | ||
15370 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15371 | { | |
15372 | struct intel_connector *connector; | |
15373 | struct drm_device *dev = encoder->base.dev; | |
873ffe69 | 15374 | bool active = false; |
24929352 DV |
15375 | |
15376 | /* We need to check both for a crtc link (meaning that the | |
15377 | * encoder is active and trying to read from a pipe) and the | |
15378 | * pipe itself being active. */ | |
15379 | bool has_active_crtc = encoder->base.crtc && | |
15380 | to_intel_crtc(encoder->base.crtc)->active; | |
15381 | ||
873ffe69 ML |
15382 | for_each_intel_connector(dev, connector) { |
15383 | if (connector->base.encoder != &encoder->base) | |
15384 | continue; | |
15385 | ||
15386 | active = true; | |
15387 | break; | |
15388 | } | |
15389 | ||
15390 | if (active && !has_active_crtc) { | |
24929352 DV |
15391 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15392 | encoder->base.base.id, | |
8e329a03 | 15393 | encoder->base.name); |
24929352 DV |
15394 | |
15395 | /* Connector is active, but has no active pipe. This is | |
15396 | * fallout from our resume register restoring. Disable | |
15397 | * the encoder manually again. */ | |
15398 | if (encoder->base.crtc) { | |
15399 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15400 | encoder->base.base.id, | |
8e329a03 | 15401 | encoder->base.name); |
24929352 | 15402 | encoder->disable(encoder); |
a62d1497 VS |
15403 | if (encoder->post_disable) |
15404 | encoder->post_disable(encoder); | |
24929352 | 15405 | } |
7f1950fb | 15406 | encoder->base.crtc = NULL; |
24929352 DV |
15407 | |
15408 | /* Inconsistent output/port/pipe state happens presumably due to | |
15409 | * a bug in one of the get_hw_state functions. Or someplace else | |
15410 | * in our code, like the register restore mess on resume. Clamp | |
15411 | * things to off as a safer default. */ | |
3a3371ff | 15412 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15413 | if (connector->encoder != encoder) |
15414 | continue; | |
7f1950fb EE |
15415 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15416 | connector->base.encoder = NULL; | |
24929352 DV |
15417 | } |
15418 | } | |
15419 | /* Enabled encoders without active connectors will be fixed in | |
15420 | * the crtc fixup. */ | |
15421 | } | |
15422 | ||
04098753 | 15423 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15424 | { |
15425 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15426 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15427 | |
04098753 ID |
15428 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15429 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15430 | i915_disable_vga(dev); | |
15431 | } | |
15432 | } | |
15433 | ||
15434 | void i915_redisable_vga(struct drm_device *dev) | |
15435 | { | |
15436 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15437 | ||
8dc8a27c PZ |
15438 | /* This function can be called both from intel_modeset_setup_hw_state or |
15439 | * at a very early point in our resume sequence, where the power well | |
15440 | * structures are not yet restored. Since this function is at a very | |
15441 | * paranoid "someone might have enabled VGA while we were not looking" | |
15442 | * level, just check if the power well is enabled instead of trying to | |
15443 | * follow the "don't touch the power well if we don't need it" policy | |
15444 | * the rest of the driver uses. */ | |
f458ebbc | 15445 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15446 | return; |
15447 | ||
04098753 | 15448 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15449 | } |
15450 | ||
f9cd7b88 | 15451 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15452 | { |
f9cd7b88 | 15453 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15454 | |
f9cd7b88 | 15455 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15456 | } |
15457 | ||
f9cd7b88 VS |
15458 | /* FIXME read out full plane state for all planes */ |
15459 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15460 | { |
b26d3ea3 | 15461 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15462 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15463 | to_intel_plane_state(primary->state); |
d032ffa0 | 15464 | |
19b8d387 | 15465 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
15466 | primary_get_hw_state(to_intel_plane(primary)); |
15467 | ||
15468 | if (plane_state->visible) | |
15469 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
15470 | } |
15471 | ||
30e984df | 15472 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15473 | { |
15474 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15475 | enum pipe pipe; | |
24929352 DV |
15476 | struct intel_crtc *crtc; |
15477 | struct intel_encoder *encoder; | |
15478 | struct intel_connector *connector; | |
5358901f | 15479 | int i; |
24929352 | 15480 | |
d3fcc808 | 15481 | for_each_intel_crtc(dev, crtc) { |
b06f8b0d | 15482 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
6e3c9717 | 15483 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15484 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15485 | |
0e8ffe1b | 15486 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15487 | crtc->config); |
24929352 | 15488 | |
49d6fa21 | 15489 | crtc->base.state->active = crtc->active; |
24929352 | 15490 | crtc->base.enabled = crtc->active; |
b70709a6 | 15491 | |
f9cd7b88 | 15492 | readout_plane_state(crtc); |
24929352 DV |
15493 | |
15494 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15495 | crtc->base.base.id, | |
15496 | crtc->active ? "enabled" : "disabled"); | |
15497 | } | |
15498 | ||
5358901f DV |
15499 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15500 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15501 | ||
3e369b76 ACO |
15502 | pll->on = pll->get_hw_state(dev_priv, pll, |
15503 | &pll->config.hw_state); | |
5358901f | 15504 | pll->active = 0; |
3e369b76 | 15505 | pll->config.crtc_mask = 0; |
d3fcc808 | 15506 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15507 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15508 | pll->active++; |
3e369b76 | 15509 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15510 | } |
5358901f | 15511 | } |
5358901f | 15512 | |
1e6f2ddc | 15513 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15514 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15515 | |
3e369b76 | 15516 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15517 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15518 | } |
15519 | ||
b2784e15 | 15520 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15521 | pipe = 0; |
15522 | ||
15523 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15524 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15525 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15526 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15527 | } else { |
15528 | encoder->base.crtc = NULL; | |
15529 | } | |
15530 | ||
6f2bcceb | 15531 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15532 | encoder->base.base.id, |
8e329a03 | 15533 | encoder->base.name, |
24929352 | 15534 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15535 | pipe_name(pipe)); |
24929352 DV |
15536 | } |
15537 | ||
3a3371ff | 15538 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15539 | if (connector->get_hw_state(connector)) { |
15540 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
24929352 DV |
15541 | connector->base.encoder = &connector->encoder->base; |
15542 | } else { | |
15543 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15544 | connector->base.encoder = NULL; | |
15545 | } | |
15546 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15547 | connector->base.base.id, | |
c23cc417 | 15548 | connector->base.name, |
24929352 DV |
15549 | connector->base.encoder ? "enabled" : "disabled"); |
15550 | } | |
7f4c6284 VS |
15551 | |
15552 | for_each_intel_crtc(dev, crtc) { | |
15553 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
15554 | ||
15555 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
15556 | if (crtc->base.state->active) { | |
15557 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
15558 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
15559 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
15560 | ||
15561 | /* | |
15562 | * The initial mode needs to be set in order to keep | |
15563 | * the atomic core happy. It wants a valid mode if the | |
15564 | * crtc's enabled, so we do the above call. | |
15565 | * | |
15566 | * At this point some state updated by the connectors | |
15567 | * in their ->detect() callback has not run yet, so | |
15568 | * no recalculation can be done yet. | |
15569 | * | |
15570 | * Even if we could do a recalculation and modeset | |
15571 | * right now it would cause a double modeset if | |
15572 | * fbdev or userspace chooses a different initial mode. | |
15573 | * | |
15574 | * If that happens, someone indicated they wanted a | |
15575 | * mode change, which means it's safe to do a full | |
15576 | * recalculation. | |
15577 | */ | |
15578 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
15579 | |
15580 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
15581 | update_scanline_offset(crtc); | |
7f4c6284 VS |
15582 | } |
15583 | } | |
30e984df DV |
15584 | } |
15585 | ||
043e9bda ML |
15586 | /* Scan out the current hw modeset state, |
15587 | * and sanitizes it to the current state | |
15588 | */ | |
15589 | static void | |
15590 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
15591 | { |
15592 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15593 | enum pipe pipe; | |
30e984df DV |
15594 | struct intel_crtc *crtc; |
15595 | struct intel_encoder *encoder; | |
35c95375 | 15596 | int i; |
30e984df DV |
15597 | |
15598 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
15599 | |
15600 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 15601 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15602 | intel_sanitize_encoder(encoder); |
15603 | } | |
15604 | ||
055e393f | 15605 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15606 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15607 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15608 | intel_dump_pipe_config(crtc, crtc->config, |
15609 | "[setup_hw_state]"); | |
24929352 | 15610 | } |
9a935856 | 15611 | |
d29b2f9d ACO |
15612 | intel_modeset_update_connector_atomic_state(dev); |
15613 | ||
35c95375 DV |
15614 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15615 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15616 | ||
15617 | if (!pll->on || pll->active) | |
15618 | continue; | |
15619 | ||
15620 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15621 | ||
15622 | pll->disable(dev_priv, pll); | |
15623 | pll->on = false; | |
15624 | } | |
15625 | ||
26e1fe4f | 15626 | if (IS_VALLEYVIEW(dev)) |
6eb1a681 VS |
15627 | vlv_wm_get_hw_state(dev); |
15628 | else if (IS_GEN9(dev)) | |
3078999f PB |
15629 | skl_wm_get_hw_state(dev); |
15630 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 15631 | ilk_wm_get_hw_state(dev); |
292b990e ML |
15632 | |
15633 | for_each_intel_crtc(dev, crtc) { | |
15634 | unsigned long put_domains; | |
15635 | ||
15636 | put_domains = modeset_get_crtc_power_domains(&crtc->base); | |
15637 | if (WARN_ON(put_domains)) | |
15638 | modeset_put_power_domains(dev_priv, put_domains); | |
15639 | } | |
15640 | intel_display_set_init_power(dev_priv, false); | |
043e9bda | 15641 | } |
7d0bc1ea | 15642 | |
043e9bda ML |
15643 | void intel_display_resume(struct drm_device *dev) |
15644 | { | |
15645 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); | |
15646 | struct intel_connector *conn; | |
15647 | struct intel_plane *plane; | |
15648 | struct drm_crtc *crtc; | |
15649 | int ret; | |
f30da187 | 15650 | |
043e9bda ML |
15651 | if (!state) |
15652 | return; | |
15653 | ||
15654 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
15655 | ||
15656 | /* preserve complete old state, including dpll */ | |
15657 | intel_atomic_get_shared_dpll_state(state); | |
15658 | ||
15659 | for_each_crtc(dev, crtc) { | |
15660 | struct drm_crtc_state *crtc_state = | |
15661 | drm_atomic_get_crtc_state(state, crtc); | |
15662 | ||
15663 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
15664 | if (ret) | |
15665 | goto err; | |
15666 | ||
15667 | /* force a restore */ | |
15668 | crtc_state->mode_changed = true; | |
45e2b5f6 | 15669 | } |
8af6cf88 | 15670 | |
043e9bda ML |
15671 | for_each_intel_plane(dev, plane) { |
15672 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); | |
15673 | if (ret) | |
15674 | goto err; | |
15675 | } | |
15676 | ||
15677 | for_each_intel_connector(dev, conn) { | |
15678 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); | |
15679 | if (ret) | |
15680 | goto err; | |
15681 | } | |
15682 | ||
15683 | intel_modeset_setup_hw_state(dev); | |
15684 | ||
15685 | i915_redisable_vga(dev); | |
74c090b1 | 15686 | ret = drm_atomic_commit(state); |
043e9bda ML |
15687 | if (!ret) |
15688 | return; | |
15689 | ||
15690 | err: | |
15691 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
15692 | drm_atomic_state_free(state); | |
2c7111db CW |
15693 | } |
15694 | ||
15695 | void intel_modeset_gem_init(struct drm_device *dev) | |
15696 | { | |
484b41dd | 15697 | struct drm_crtc *c; |
2ff8fde1 | 15698 | struct drm_i915_gem_object *obj; |
e0d6149b | 15699 | int ret; |
484b41dd | 15700 | |
ae48434c ID |
15701 | mutex_lock(&dev->struct_mutex); |
15702 | intel_init_gt_powersave(dev); | |
15703 | mutex_unlock(&dev->struct_mutex); | |
15704 | ||
1833b134 | 15705 | intel_modeset_init_hw(dev); |
02e792fb DV |
15706 | |
15707 | intel_setup_overlay(dev); | |
484b41dd JB |
15708 | |
15709 | /* | |
15710 | * Make sure any fbs we allocated at startup are properly | |
15711 | * pinned & fenced. When we do the allocation it's too early | |
15712 | * for this. | |
15713 | */ | |
70e1e0ec | 15714 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15715 | obj = intel_fb_obj(c->primary->fb); |
15716 | if (obj == NULL) | |
484b41dd JB |
15717 | continue; |
15718 | ||
e0d6149b TU |
15719 | mutex_lock(&dev->struct_mutex); |
15720 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15721 | c->primary->fb, | |
7580d774 | 15722 | c->primary->state); |
e0d6149b TU |
15723 | mutex_unlock(&dev->struct_mutex); |
15724 | if (ret) { | |
484b41dd JB |
15725 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15726 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15727 | drm_framebuffer_unreference(c->primary->fb); |
15728 | c->primary->fb = NULL; | |
36750f28 | 15729 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15730 | update_state_fb(c->primary); |
36750f28 | 15731 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15732 | } |
15733 | } | |
0962c3c9 VS |
15734 | |
15735 | intel_backlight_register(dev); | |
79e53945 JB |
15736 | } |
15737 | ||
4932e2c3 ID |
15738 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15739 | { | |
15740 | struct drm_connector *connector = &intel_connector->base; | |
15741 | ||
15742 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15743 | drm_connector_unregister(connector); |
4932e2c3 ID |
15744 | } |
15745 | ||
79e53945 JB |
15746 | void intel_modeset_cleanup(struct drm_device *dev) |
15747 | { | |
652c393a | 15748 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15749 | struct drm_connector *connector; |
652c393a | 15750 | |
2eb5252e ID |
15751 | intel_disable_gt_powersave(dev); |
15752 | ||
0962c3c9 VS |
15753 | intel_backlight_unregister(dev); |
15754 | ||
fd0c0642 DV |
15755 | /* |
15756 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15757 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15758 | * experience fancy races otherwise. |
15759 | */ | |
2aeb7d3a | 15760 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15761 | |
fd0c0642 DV |
15762 | /* |
15763 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15764 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15765 | */ | |
f87ea761 | 15766 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15767 | |
723bfd70 JB |
15768 | intel_unregister_dsm_handler(); |
15769 | ||
7733b49b | 15770 | intel_fbc_disable(dev_priv); |
69341a5e | 15771 | |
1630fe75 CW |
15772 | /* flush any delayed tasks or pending work */ |
15773 | flush_scheduled_work(); | |
15774 | ||
db31af1d JN |
15775 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15776 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15777 | struct intel_connector *intel_connector; |
15778 | ||
15779 | intel_connector = to_intel_connector(connector); | |
15780 | intel_connector->unregister(intel_connector); | |
db31af1d | 15781 | } |
d9255d57 | 15782 | |
79e53945 | 15783 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15784 | |
15785 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15786 | |
15787 | mutex_lock(&dev->struct_mutex); | |
15788 | intel_cleanup_gt_powersave(dev); | |
15789 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15790 | } |
15791 | ||
f1c79df3 ZW |
15792 | /* |
15793 | * Return which encoder is currently attached for connector. | |
15794 | */ | |
df0e9248 | 15795 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15796 | { |
df0e9248 CW |
15797 | return &intel_attached_encoder(connector)->base; |
15798 | } | |
f1c79df3 | 15799 | |
df0e9248 CW |
15800 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15801 | struct intel_encoder *encoder) | |
15802 | { | |
15803 | connector->encoder = encoder; | |
15804 | drm_mode_connector_attach_encoder(&connector->base, | |
15805 | &encoder->base); | |
79e53945 | 15806 | } |
28d52043 DA |
15807 | |
15808 | /* | |
15809 | * set vga decode state - true == enable VGA decode | |
15810 | */ | |
15811 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15812 | { | |
15813 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15814 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15815 | u16 gmch_ctrl; |
15816 | ||
75fa041d CW |
15817 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15818 | DRM_ERROR("failed to read control word\n"); | |
15819 | return -EIO; | |
15820 | } | |
15821 | ||
c0cc8a55 CW |
15822 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15823 | return 0; | |
15824 | ||
28d52043 DA |
15825 | if (state) |
15826 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15827 | else | |
15828 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15829 | |
15830 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15831 | DRM_ERROR("failed to write control word\n"); | |
15832 | return -EIO; | |
15833 | } | |
15834 | ||
28d52043 DA |
15835 | return 0; |
15836 | } | |
c4a1d9e4 | 15837 | |
c4a1d9e4 | 15838 | struct intel_display_error_state { |
ff57f1b0 PZ |
15839 | |
15840 | u32 power_well_driver; | |
15841 | ||
63b66e5b CW |
15842 | int num_transcoders; |
15843 | ||
c4a1d9e4 CW |
15844 | struct intel_cursor_error_state { |
15845 | u32 control; | |
15846 | u32 position; | |
15847 | u32 base; | |
15848 | u32 size; | |
52331309 | 15849 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15850 | |
15851 | struct intel_pipe_error_state { | |
ddf9c536 | 15852 | bool power_domain_on; |
c4a1d9e4 | 15853 | u32 source; |
f301b1e1 | 15854 | u32 stat; |
52331309 | 15855 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15856 | |
15857 | struct intel_plane_error_state { | |
15858 | u32 control; | |
15859 | u32 stride; | |
15860 | u32 size; | |
15861 | u32 pos; | |
15862 | u32 addr; | |
15863 | u32 surface; | |
15864 | u32 tile_offset; | |
52331309 | 15865 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15866 | |
15867 | struct intel_transcoder_error_state { | |
ddf9c536 | 15868 | bool power_domain_on; |
63b66e5b CW |
15869 | enum transcoder cpu_transcoder; |
15870 | ||
15871 | u32 conf; | |
15872 | ||
15873 | u32 htotal; | |
15874 | u32 hblank; | |
15875 | u32 hsync; | |
15876 | u32 vtotal; | |
15877 | u32 vblank; | |
15878 | u32 vsync; | |
15879 | } transcoder[4]; | |
c4a1d9e4 CW |
15880 | }; |
15881 | ||
15882 | struct intel_display_error_state * | |
15883 | intel_display_capture_error_state(struct drm_device *dev) | |
15884 | { | |
fbee40df | 15885 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15886 | struct intel_display_error_state *error; |
63b66e5b CW |
15887 | int transcoders[] = { |
15888 | TRANSCODER_A, | |
15889 | TRANSCODER_B, | |
15890 | TRANSCODER_C, | |
15891 | TRANSCODER_EDP, | |
15892 | }; | |
c4a1d9e4 CW |
15893 | int i; |
15894 | ||
63b66e5b CW |
15895 | if (INTEL_INFO(dev)->num_pipes == 0) |
15896 | return NULL; | |
15897 | ||
9d1cb914 | 15898 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15899 | if (error == NULL) |
15900 | return NULL; | |
15901 | ||
190be112 | 15902 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15903 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15904 | ||
055e393f | 15905 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15906 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15907 | __intel_display_power_is_enabled(dev_priv, |
15908 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15909 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15910 | continue; |
15911 | ||
5efb3e28 VS |
15912 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15913 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15914 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15915 | |
15916 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15917 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15918 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15919 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15920 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15921 | } | |
ca291363 PZ |
15922 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15923 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15924 | if (INTEL_INFO(dev)->gen >= 4) { |
15925 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15926 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15927 | } | |
15928 | ||
c4a1d9e4 | 15929 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15930 | |
3abfce77 | 15931 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15932 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15933 | } |
15934 | ||
15935 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15936 | if (HAS_DDI(dev_priv->dev)) | |
15937 | error->num_transcoders++; /* Account for eDP. */ | |
15938 | ||
15939 | for (i = 0; i < error->num_transcoders; i++) { | |
15940 | enum transcoder cpu_transcoder = transcoders[i]; | |
15941 | ||
ddf9c536 | 15942 | error->transcoder[i].power_domain_on = |
f458ebbc | 15943 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15944 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15945 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15946 | continue; |
15947 | ||
63b66e5b CW |
15948 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15949 | ||
15950 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15951 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15952 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15953 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15954 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15955 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15956 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15957 | } |
15958 | ||
15959 | return error; | |
15960 | } | |
15961 | ||
edc3d884 MK |
15962 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15963 | ||
c4a1d9e4 | 15964 | void |
edc3d884 | 15965 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15966 | struct drm_device *dev, |
15967 | struct intel_display_error_state *error) | |
15968 | { | |
055e393f | 15969 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15970 | int i; |
15971 | ||
63b66e5b CW |
15972 | if (!error) |
15973 | return; | |
15974 | ||
edc3d884 | 15975 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15976 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15977 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15978 | error->power_well_driver); |
055e393f | 15979 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15980 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15981 | err_printf(m, " Power: %s\n", |
15982 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15983 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15984 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15985 | |
15986 | err_printf(m, "Plane [%d]:\n", i); | |
15987 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15988 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15989 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15990 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15991 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15992 | } |
4b71a570 | 15993 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15994 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15995 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15996 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15997 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15998 | } |
15999 | ||
edc3d884 MK |
16000 | err_printf(m, "Cursor [%d]:\n", i); |
16001 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
16002 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
16003 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 16004 | } |
63b66e5b CW |
16005 | |
16006 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 16007 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 16008 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
16009 | err_printf(m, " Power: %s\n", |
16010 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
16011 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
16012 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
16013 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
16014 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
16015 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
16016 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
16017 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
16018 | } | |
c4a1d9e4 | 16019 | } |
e2fcdaa9 VS |
16020 | |
16021 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
16022 | { | |
16023 | struct intel_crtc *crtc; | |
16024 | ||
16025 | for_each_intel_crtc(dev, crtc) { | |
16026 | struct intel_unpin_work *work; | |
e2fcdaa9 | 16027 | |
5e2d7afc | 16028 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
16029 | |
16030 | work = crtc->unpin_work; | |
16031 | ||
16032 | if (work && work->event && | |
16033 | work->event->base.file_priv == file) { | |
16034 | kfree(work->event); | |
16035 | work->event = NULL; | |
16036 | } | |
16037 | ||
5e2d7afc | 16038 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
16039 | } |
16040 | } |