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)) |
409ee761 | 2133 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
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 | |
ff2a3117 | 3177 | if (dev_priv->fbc.disable_fbc) |
7733b49b | 3178 | dev_priv->fbc.disable_fbc(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)) { |
409ee761 | 4639 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
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; | |
7733b49b | 4795 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 ML |
4796 | |
4797 | if (atomic->wait_vblank) | |
4798 | intel_wait_for_vblank(dev, crtc->pipe); | |
4799 | ||
4800 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4801 | ||
852eb00d VS |
4802 | if (atomic->disable_cxsr) |
4803 | crtc->wm.cxsr_allowed = true; | |
4804 | ||
f015c551 VS |
4805 | if (crtc->atomic.update_wm_post) |
4806 | intel_update_watermarks(&crtc->base); | |
4807 | ||
c80ac854 | 4808 | if (atomic->update_fbc) |
7733b49b | 4809 | intel_fbc_update(dev_priv); |
ac21b225 ML |
4810 | |
4811 | if (atomic->post_enable_primary) | |
4812 | intel_post_enable_primary(&crtc->base); | |
4813 | ||
ac21b225 ML |
4814 | memset(atomic, 0, sizeof(*atomic)); |
4815 | } | |
4816 | ||
4817 | static void intel_pre_plane_update(struct intel_crtc *crtc) | |
4818 | { | |
4819 | struct drm_device *dev = crtc->base.dev; | |
eddfcbcd | 4820 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 | 4821 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
ac21b225 | 4822 | |
c80ac854 | 4823 | if (atomic->disable_fbc) |
25ad93fd | 4824 | intel_fbc_disable_crtc(crtc); |
ac21b225 | 4825 | |
066cf55b RV |
4826 | if (crtc->atomic.disable_ips) |
4827 | hsw_disable_ips(crtc); | |
4828 | ||
ac21b225 ML |
4829 | if (atomic->pre_disable_primary) |
4830 | intel_pre_disable_primary(&crtc->base); | |
852eb00d VS |
4831 | |
4832 | if (atomic->disable_cxsr) { | |
4833 | crtc->wm.cxsr_allowed = false; | |
4834 | intel_set_memory_cxsr(dev_priv, false); | |
4835 | } | |
ac21b225 ML |
4836 | } |
4837 | ||
d032ffa0 | 4838 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4839 | { |
4840 | struct drm_device *dev = crtc->dev; | |
4841 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4842 | struct drm_plane *p; |
87d4300a ML |
4843 | int pipe = intel_crtc->pipe; |
4844 | ||
7cac945f | 4845 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4846 | |
d032ffa0 ML |
4847 | drm_for_each_plane_mask(p, dev, plane_mask) |
4848 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4849 | |
f99d7069 DV |
4850 | /* |
4851 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4852 | * to compute the mask of flip planes precisely. For the time being | |
4853 | * consider this a flip to a NULL plane. | |
4854 | */ | |
4855 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4856 | } |
4857 | ||
f67a559d JB |
4858 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4859 | { | |
4860 | struct drm_device *dev = crtc->dev; | |
4861 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4862 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4863 | struct intel_encoder *encoder; |
f67a559d | 4864 | int pipe = intel_crtc->pipe; |
f67a559d | 4865 | |
53d9f4e9 | 4866 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4867 | return; |
4868 | ||
81b088ca VS |
4869 | if (intel_crtc->config->has_pch_encoder) |
4870 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
4871 | ||
6e3c9717 | 4872 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4873 | intel_prepare_shared_dpll(intel_crtc); |
4874 | ||
6e3c9717 | 4875 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4876 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4877 | |
4878 | intel_set_pipe_timings(intel_crtc); | |
4879 | ||
6e3c9717 | 4880 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4881 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4882 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4883 | } |
4884 | ||
4885 | ironlake_set_pipeconf(crtc); | |
4886 | ||
f67a559d | 4887 | intel_crtc->active = true; |
8664281b | 4888 | |
a72e4c9f | 4889 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
8664281b | 4890 | |
f6736a1a | 4891 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4892 | if (encoder->pre_enable) |
4893 | encoder->pre_enable(encoder); | |
f67a559d | 4894 | |
6e3c9717 | 4895 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4896 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4897 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4898 | * enabling. */ | |
88cefb6c | 4899 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4900 | } else { |
4901 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4902 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4903 | } | |
f67a559d | 4904 | |
b074cec8 | 4905 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4906 | |
9c54c0dd JB |
4907 | /* |
4908 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4909 | * clocks enabled | |
4910 | */ | |
4911 | intel_crtc_load_lut(crtc); | |
4912 | ||
f37fcc2a | 4913 | intel_update_watermarks(crtc); |
e1fdc473 | 4914 | intel_enable_pipe(intel_crtc); |
f67a559d | 4915 | |
6e3c9717 | 4916 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4917 | ironlake_pch_enable(crtc); |
c98e9dcf | 4918 | |
f9b61ff6 DV |
4919 | assert_vblank_disabled(crtc); |
4920 | drm_crtc_vblank_on(crtc); | |
4921 | ||
fa5c73b1 DV |
4922 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4923 | encoder->enable(encoder); | |
61b77ddd DV |
4924 | |
4925 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4926 | cpt_verify_modeset(dev, intel_crtc->pipe); |
37ca8d4c VS |
4927 | |
4928 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
4929 | if (intel_crtc->config->has_pch_encoder) | |
4930 | intel_wait_for_vblank(dev, pipe); | |
4931 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
6be4a607 JB |
4932 | } |
4933 | ||
42db64ef PZ |
4934 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4935 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4936 | { | |
f5adf94e | 4937 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4938 | } |
4939 | ||
4f771f10 PZ |
4940 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4941 | { | |
4942 | struct drm_device *dev = crtc->dev; | |
4943 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4944 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4945 | struct intel_encoder *encoder; | |
99d736a2 ML |
4946 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4947 | struct intel_crtc_state *pipe_config = | |
4948 | to_intel_crtc_state(crtc->state); | |
7d4aefd0 | 4949 | bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
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 | |
a72e4c9f | 4982 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
7d4aefd0 SS |
4983 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4984 | if (encoder->pre_pll_enable) | |
4985 | encoder->pre_pll_enable(encoder); | |
4f771f10 PZ |
4986 | if (encoder->pre_enable) |
4987 | encoder->pre_enable(encoder); | |
7d4aefd0 | 4988 | } |
4f771f10 | 4989 | |
d2d65408 | 4990 | if (intel_crtc->config->has_pch_encoder) |
4fe9467d | 4991 | dev_priv->display.fdi_link_train(crtc); |
4fe9467d | 4992 | |
7d4aefd0 SS |
4993 | if (!is_dsi) |
4994 | intel_ddi_enable_pipe_clock(intel_crtc); | |
4f771f10 | 4995 | |
1c132b44 | 4996 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 4997 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 4998 | else |
1c132b44 | 4999 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
5000 | |
5001 | /* | |
5002 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5003 | * clocks enabled | |
5004 | */ | |
5005 | intel_crtc_load_lut(crtc); | |
5006 | ||
1f544388 | 5007 | intel_ddi_set_pipe_settings(crtc); |
7d4aefd0 SS |
5008 | if (!is_dsi) |
5009 | intel_ddi_enable_transcoder_func(crtc); | |
4f771f10 | 5010 | |
f37fcc2a | 5011 | intel_update_watermarks(crtc); |
e1fdc473 | 5012 | intel_enable_pipe(intel_crtc); |
42db64ef | 5013 | |
6e3c9717 | 5014 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 5015 | lpt_pch_enable(crtc); |
4f771f10 | 5016 | |
7d4aefd0 | 5017 | if (intel_crtc->config->dp_encoder_is_mst && !is_dsi) |
0e32b39c DA |
5018 | intel_ddi_set_vc_payload_alloc(crtc, true); |
5019 | ||
f9b61ff6 DV |
5020 | assert_vblank_disabled(crtc); |
5021 | drm_crtc_vblank_on(crtc); | |
5022 | ||
8807e55b | 5023 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 5024 | encoder->enable(encoder); |
8807e55b JN |
5025 | intel_opregion_notify_encoder(encoder, true); |
5026 | } | |
4f771f10 | 5027 | |
d2d65408 VS |
5028 | if (intel_crtc->config->has_pch_encoder) |
5029 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5030 | true); | |
5031 | ||
e4916946 PZ |
5032 | /* If we change the relative order between pipe/planes enabling, we need |
5033 | * to change the workaround. */ | |
99d736a2 ML |
5034 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
5035 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
5036 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5037 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5038 | } | |
4f771f10 PZ |
5039 | } |
5040 | ||
bfd16b2a | 5041 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
5042 | { |
5043 | struct drm_device *dev = crtc->base.dev; | |
5044 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5045 | int pipe = crtc->pipe; | |
5046 | ||
5047 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5048 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 5049 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5050 | I915_WRITE(PF_CTL(pipe), 0); |
5051 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5052 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5053 | } | |
5054 | } | |
5055 | ||
6be4a607 JB |
5056 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
5057 | { | |
5058 | struct drm_device *dev = crtc->dev; | |
5059 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5060 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5061 | struct intel_encoder *encoder; |
6be4a607 | 5062 | int pipe = intel_crtc->pipe; |
b52eb4dc | 5063 | |
37ca8d4c VS |
5064 | if (intel_crtc->config->has_pch_encoder) |
5065 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
5066 | ||
ea9d758d DV |
5067 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5068 | encoder->disable(encoder); | |
5069 | ||
f9b61ff6 DV |
5070 | drm_crtc_vblank_off(crtc); |
5071 | assert_vblank_disabled(crtc); | |
5072 | ||
3860b2ec VS |
5073 | /* |
5074 | * Sometimes spurious CPU pipe underruns happen when the | |
5075 | * pipe is already disabled, but FDI RX/TX is still enabled. | |
5076 | * Happens at least with VGA+HDMI cloning. Suppress them. | |
5077 | */ | |
5078 | if (intel_crtc->config->has_pch_encoder) | |
5079 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
5080 | ||
575f7ab7 | 5081 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5082 | |
bfd16b2a | 5083 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 5084 | |
3860b2ec | 5085 | if (intel_crtc->config->has_pch_encoder) { |
5a74f70a | 5086 | ironlake_fdi_disable(crtc); |
3860b2ec VS |
5087 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
5088 | } | |
5a74f70a | 5089 | |
bf49ec8c DV |
5090 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5091 | if (encoder->post_disable) | |
5092 | encoder->post_disable(encoder); | |
2c07245f | 5093 | |
6e3c9717 | 5094 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5095 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5096 | |
d925c59a | 5097 | if (HAS_PCH_CPT(dev)) { |
f0f59a00 VS |
5098 | i915_reg_t reg; |
5099 | u32 temp; | |
5100 | ||
d925c59a DV |
5101 | /* disable TRANS_DP_CTL */ |
5102 | reg = TRANS_DP_CTL(pipe); | |
5103 | temp = I915_READ(reg); | |
5104 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5105 | TRANS_DP_PORT_SEL_MASK); | |
5106 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5107 | I915_WRITE(reg, temp); | |
5108 | ||
5109 | /* disable DPLL_SEL */ | |
5110 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5111 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5112 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5113 | } |
e3421a18 | 5114 | |
d925c59a DV |
5115 | ironlake_fdi_pll_disable(intel_crtc); |
5116 | } | |
81b088ca VS |
5117 | |
5118 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
6be4a607 | 5119 | } |
1b3c7a47 | 5120 | |
4f771f10 | 5121 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5122 | { |
4f771f10 PZ |
5123 | struct drm_device *dev = crtc->dev; |
5124 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5125 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5126 | struct intel_encoder *encoder; |
6e3c9717 | 5127 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7d4aefd0 | 5128 | bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
ee7b9f93 | 5129 | |
d2d65408 VS |
5130 | if (intel_crtc->config->has_pch_encoder) |
5131 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5132 | false); | |
5133 | ||
8807e55b JN |
5134 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5135 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5136 | encoder->disable(encoder); |
8807e55b | 5137 | } |
4f771f10 | 5138 | |
f9b61ff6 DV |
5139 | drm_crtc_vblank_off(crtc); |
5140 | assert_vblank_disabled(crtc); | |
5141 | ||
575f7ab7 | 5142 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5143 | |
6e3c9717 | 5144 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5145 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5146 | ||
7d4aefd0 SS |
5147 | if (!is_dsi) |
5148 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); | |
4f771f10 | 5149 | |
1c132b44 | 5150 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5151 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5152 | else |
bfd16b2a | 5153 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5154 | |
7d4aefd0 SS |
5155 | if (!is_dsi) |
5156 | intel_ddi_disable_pipe_clock(intel_crtc); | |
4f771f10 | 5157 | |
6e3c9717 | 5158 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5159 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5160 | intel_ddi_fdi_disable(crtc); |
83616634 | 5161 | } |
4f771f10 | 5162 | |
97b040aa ID |
5163 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5164 | if (encoder->post_disable) | |
5165 | encoder->post_disable(encoder); | |
81b088ca VS |
5166 | |
5167 | if (intel_crtc->config->has_pch_encoder) | |
5168 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5169 | true); | |
4f771f10 PZ |
5170 | } |
5171 | ||
2dd24552 JB |
5172 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5173 | { | |
5174 | struct drm_device *dev = crtc->base.dev; | |
5175 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5176 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5177 | |
681a8504 | 5178 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5179 | return; |
5180 | ||
2dd24552 | 5181 | /* |
c0b03411 DV |
5182 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5183 | * according to register description and PRM. | |
2dd24552 | 5184 | */ |
c0b03411 DV |
5185 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5186 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5187 | |
b074cec8 JB |
5188 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5189 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5190 | |
5191 | /* Border color in case we don't scale up to the full screen. Black by | |
5192 | * default, change to something else for debugging. */ | |
5193 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5194 | } |
5195 | ||
d05410f9 DA |
5196 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5197 | { | |
5198 | switch (port) { | |
5199 | case PORT_A: | |
6331a704 | 5200 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
d05410f9 | 5201 | case PORT_B: |
6331a704 | 5202 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
d05410f9 | 5203 | case PORT_C: |
6331a704 | 5204 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
d05410f9 | 5205 | case PORT_D: |
6331a704 | 5206 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
d8e19f99 | 5207 | case PORT_E: |
6331a704 | 5208 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
d05410f9 | 5209 | default: |
b9fec167 | 5210 | MISSING_CASE(port); |
d05410f9 DA |
5211 | return POWER_DOMAIN_PORT_OTHER; |
5212 | } | |
5213 | } | |
5214 | ||
25f78f58 VS |
5215 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
5216 | { | |
5217 | switch (port) { | |
5218 | case PORT_A: | |
5219 | return POWER_DOMAIN_AUX_A; | |
5220 | case PORT_B: | |
5221 | return POWER_DOMAIN_AUX_B; | |
5222 | case PORT_C: | |
5223 | return POWER_DOMAIN_AUX_C; | |
5224 | case PORT_D: | |
5225 | return POWER_DOMAIN_AUX_D; | |
5226 | case PORT_E: | |
5227 | /* FIXME: Check VBT for actual wiring of PORT E */ | |
5228 | return POWER_DOMAIN_AUX_D; | |
5229 | default: | |
b9fec167 | 5230 | MISSING_CASE(port); |
25f78f58 VS |
5231 | return POWER_DOMAIN_AUX_A; |
5232 | } | |
5233 | } | |
5234 | ||
77d22dca ID |
5235 | #define for_each_power_domain(domain, mask) \ |
5236 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5237 | if ((1 << (domain)) & (mask)) | |
5238 | ||
319be8ae ID |
5239 | enum intel_display_power_domain |
5240 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5241 | { | |
5242 | struct drm_device *dev = intel_encoder->base.dev; | |
5243 | struct intel_digital_port *intel_dig_port; | |
5244 | ||
5245 | switch (intel_encoder->type) { | |
5246 | case INTEL_OUTPUT_UNKNOWN: | |
5247 | /* Only DDI platforms should ever use this output type */ | |
5248 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5249 | case INTEL_OUTPUT_DISPLAYPORT: | |
5250 | case INTEL_OUTPUT_HDMI: | |
5251 | case INTEL_OUTPUT_EDP: | |
5252 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5253 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5254 | case INTEL_OUTPUT_DP_MST: |
5255 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5256 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5257 | case INTEL_OUTPUT_ANALOG: |
5258 | return POWER_DOMAIN_PORT_CRT; | |
5259 | case INTEL_OUTPUT_DSI: | |
5260 | return POWER_DOMAIN_PORT_DSI; | |
5261 | default: | |
5262 | return POWER_DOMAIN_PORT_OTHER; | |
5263 | } | |
5264 | } | |
5265 | ||
25f78f58 VS |
5266 | enum intel_display_power_domain |
5267 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) | |
5268 | { | |
5269 | struct drm_device *dev = intel_encoder->base.dev; | |
5270 | struct intel_digital_port *intel_dig_port; | |
5271 | ||
5272 | switch (intel_encoder->type) { | |
5273 | case INTEL_OUTPUT_UNKNOWN: | |
651174a4 ID |
5274 | case INTEL_OUTPUT_HDMI: |
5275 | /* | |
5276 | * Only DDI platforms should ever use these output types. | |
5277 | * We can get here after the HDMI detect code has already set | |
5278 | * the type of the shared encoder. Since we can't be sure | |
5279 | * what's the status of the given connectors, play safe and | |
5280 | * run the DP detection too. | |
5281 | */ | |
25f78f58 VS |
5282 | WARN_ON_ONCE(!HAS_DDI(dev)); |
5283 | case INTEL_OUTPUT_DISPLAYPORT: | |
5284 | case INTEL_OUTPUT_EDP: | |
5285 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
5286 | return port_to_aux_power_domain(intel_dig_port->port); | |
5287 | case INTEL_OUTPUT_DP_MST: | |
5288 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5289 | return port_to_aux_power_domain(intel_dig_port->port); | |
5290 | default: | |
b9fec167 | 5291 | MISSING_CASE(intel_encoder->type); |
25f78f58 VS |
5292 | return POWER_DOMAIN_AUX_A; |
5293 | } | |
5294 | } | |
5295 | ||
319be8ae | 5296 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5297 | { |
319be8ae ID |
5298 | struct drm_device *dev = crtc->dev; |
5299 | struct intel_encoder *intel_encoder; | |
5300 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5301 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca | 5302 | unsigned long mask; |
1a70a728 | 5303 | enum transcoder transcoder = intel_crtc->config->cpu_transcoder; |
77d22dca | 5304 | |
292b990e ML |
5305 | if (!crtc->state->active) |
5306 | return 0; | |
5307 | ||
77d22dca ID |
5308 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5309 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5310 | if (intel_crtc->config->pch_pfit.enabled || |
5311 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5312 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5313 | ||
319be8ae ID |
5314 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5315 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5316 | ||
77d22dca ID |
5317 | return mask; |
5318 | } | |
5319 | ||
292b990e | 5320 | static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5321 | { |
292b990e ML |
5322 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5323 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5324 | enum intel_display_power_domain domain; | |
5325 | unsigned long domains, new_domains, old_domains; | |
77d22dca | 5326 | |
292b990e ML |
5327 | old_domains = intel_crtc->enabled_power_domains; |
5328 | intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc); | |
77d22dca | 5329 | |
292b990e ML |
5330 | domains = new_domains & ~old_domains; |
5331 | ||
5332 | for_each_power_domain(domain, domains) | |
5333 | intel_display_power_get(dev_priv, domain); | |
5334 | ||
5335 | return old_domains & ~new_domains; | |
5336 | } | |
5337 | ||
5338 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5339 | unsigned long domains) | |
5340 | { | |
5341 | enum intel_display_power_domain domain; | |
5342 | ||
5343 | for_each_power_domain(domain, domains) | |
5344 | intel_display_power_put(dev_priv, domain); | |
5345 | } | |
77d22dca | 5346 | |
292b990e ML |
5347 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
5348 | { | |
5349 | struct drm_device *dev = state->dev; | |
5350 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5351 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
5352 | struct drm_crtc_state *crtc_state; | |
5353 | struct drm_crtc *crtc; | |
5354 | int i; | |
77d22dca | 5355 | |
292b990e ML |
5356 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5357 | if (needs_modeset(crtc->state)) | |
5358 | put_domains[to_intel_crtc(crtc)->pipe] = | |
5359 | modeset_get_crtc_power_domains(crtc); | |
77d22dca ID |
5360 | } |
5361 | ||
27c329ed ML |
5362 | if (dev_priv->display.modeset_commit_cdclk) { |
5363 | unsigned int cdclk = to_intel_atomic_state(state)->cdclk; | |
5364 | ||
5365 | if (cdclk != dev_priv->cdclk_freq && | |
5366 | !WARN_ON(!state->allow_modeset)) | |
5367 | dev_priv->display.modeset_commit_cdclk(state); | |
5368 | } | |
50f6e502 | 5369 | |
292b990e ML |
5370 | for (i = 0; i < I915_MAX_PIPES; i++) |
5371 | if (put_domains[i]) | |
5372 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
77d22dca ID |
5373 | } |
5374 | ||
adafdc6f MK |
5375 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5376 | { | |
5377 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5378 | ||
5379 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5380 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5381 | return max_cdclk_freq; | |
5382 | else if (IS_CHERRYVIEW(dev_priv)) | |
5383 | return max_cdclk_freq*95/100; | |
5384 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5385 | return 2*max_cdclk_freq*90/100; | |
5386 | else | |
5387 | return max_cdclk_freq*90/100; | |
5388 | } | |
5389 | ||
560a7ae4 DL |
5390 | static void intel_update_max_cdclk(struct drm_device *dev) |
5391 | { | |
5392 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5393 | ||
ef11bdb3 | 5394 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
560a7ae4 DL |
5395 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
5396 | ||
5397 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5398 | dev_priv->max_cdclk_freq = 675000; | |
5399 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5400 | dev_priv->max_cdclk_freq = 540000; | |
5401 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5402 | dev_priv->max_cdclk_freq = 450000; | |
5403 | else | |
5404 | dev_priv->max_cdclk_freq = 337500; | |
5405 | } else if (IS_BROADWELL(dev)) { | |
5406 | /* | |
5407 | * FIXME with extra cooling we can allow | |
5408 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5409 | * How can we know if extra cooling is | |
5410 | * available? PCI ID, VTB, something else? | |
5411 | */ | |
5412 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5413 | dev_priv->max_cdclk_freq = 450000; | |
5414 | else if (IS_BDW_ULX(dev)) | |
5415 | dev_priv->max_cdclk_freq = 450000; | |
5416 | else if (IS_BDW_ULT(dev)) | |
5417 | dev_priv->max_cdclk_freq = 540000; | |
5418 | else | |
5419 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5420 | } else if (IS_CHERRYVIEW(dev)) { |
5421 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5422 | } else if (IS_VALLEYVIEW(dev)) { |
5423 | dev_priv->max_cdclk_freq = 400000; | |
5424 | } else { | |
5425 | /* otherwise assume cdclk is fixed */ | |
5426 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5427 | } | |
5428 | ||
adafdc6f MK |
5429 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5430 | ||
560a7ae4 DL |
5431 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5432 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5433 | |
5434 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5435 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5436 | } |
5437 | ||
5438 | static void intel_update_cdclk(struct drm_device *dev) | |
5439 | { | |
5440 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5441 | ||
5442 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5443 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5444 | dev_priv->cdclk_freq); | |
5445 | ||
5446 | /* | |
5447 | * Program the gmbus_freq based on the cdclk frequency. | |
5448 | * BSpec erroneously claims we should aim for 4MHz, but | |
5449 | * in fact 1MHz is the correct frequency. | |
5450 | */ | |
5451 | if (IS_VALLEYVIEW(dev)) { | |
5452 | /* | |
5453 | * Program the gmbus_freq based on the cdclk frequency. | |
5454 | * BSpec erroneously claims we should aim for 4MHz, but | |
5455 | * in fact 1MHz is the correct frequency. | |
5456 | */ | |
5457 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5458 | } | |
5459 | ||
5460 | if (dev_priv->max_cdclk_freq == 0) | |
5461 | intel_update_max_cdclk(dev); | |
5462 | } | |
5463 | ||
70d0c574 | 5464 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5465 | { |
5466 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5467 | uint32_t divider; | |
5468 | uint32_t ratio; | |
5469 | uint32_t current_freq; | |
5470 | int ret; | |
5471 | ||
5472 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5473 | switch (frequency) { | |
5474 | case 144000: | |
5475 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5476 | ratio = BXT_DE_PLL_RATIO(60); | |
5477 | break; | |
5478 | case 288000: | |
5479 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5480 | ratio = BXT_DE_PLL_RATIO(60); | |
5481 | break; | |
5482 | case 384000: | |
5483 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5484 | ratio = BXT_DE_PLL_RATIO(60); | |
5485 | break; | |
5486 | case 576000: | |
5487 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5488 | ratio = BXT_DE_PLL_RATIO(60); | |
5489 | break; | |
5490 | case 624000: | |
5491 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5492 | ratio = BXT_DE_PLL_RATIO(65); | |
5493 | break; | |
5494 | case 19200: | |
5495 | /* | |
5496 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5497 | * to suppress GCC warning. | |
5498 | */ | |
5499 | ratio = 0; | |
5500 | divider = 0; | |
5501 | break; | |
5502 | default: | |
5503 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5504 | ||
5505 | return; | |
5506 | } | |
5507 | ||
5508 | mutex_lock(&dev_priv->rps.hw_lock); | |
5509 | /* Inform power controller of upcoming frequency change */ | |
5510 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5511 | 0x80000000); | |
5512 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5513 | ||
5514 | if (ret) { | |
5515 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5516 | ret, frequency); | |
5517 | return; | |
5518 | } | |
5519 | ||
5520 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5521 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5522 | current_freq = current_freq * 500 + 1000; | |
5523 | ||
5524 | /* | |
5525 | * DE PLL has to be disabled when | |
5526 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5527 | * - before setting to 624MHz (PLL needs toggling) | |
5528 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5529 | */ | |
5530 | if (frequency == 19200 || frequency == 624000 || | |
5531 | current_freq == 624000) { | |
5532 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5533 | /* Timeout 200us */ | |
5534 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5535 | 1)) | |
5536 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5537 | } | |
5538 | ||
5539 | if (frequency != 19200) { | |
5540 | uint32_t val; | |
5541 | ||
5542 | val = I915_READ(BXT_DE_PLL_CTL); | |
5543 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5544 | val |= ratio; | |
5545 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5546 | ||
5547 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5548 | /* Timeout 200us */ | |
5549 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5550 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5551 | ||
5552 | val = I915_READ(CDCLK_CTL); | |
5553 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5554 | val |= divider; | |
5555 | /* | |
5556 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5557 | * enable otherwise. | |
5558 | */ | |
5559 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5560 | if (frequency >= 500000) | |
5561 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5562 | ||
5563 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5564 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5565 | val |= (frequency - 1000) / 500; | |
5566 | I915_WRITE(CDCLK_CTL, val); | |
5567 | } | |
5568 | ||
5569 | mutex_lock(&dev_priv->rps.hw_lock); | |
5570 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5571 | DIV_ROUND_UP(frequency, 25000)); | |
5572 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5573 | ||
5574 | if (ret) { | |
5575 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5576 | ret, frequency); | |
5577 | return; | |
5578 | } | |
5579 | ||
a47871bd | 5580 | intel_update_cdclk(dev); |
f8437dd1 VK |
5581 | } |
5582 | ||
5583 | void broxton_init_cdclk(struct drm_device *dev) | |
5584 | { | |
5585 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5586 | uint32_t val; | |
5587 | ||
5588 | /* | |
5589 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5590 | * or else the reset will hang because there is no PCH to respond. | |
5591 | * Move the handshake programming to initialization sequence. | |
5592 | * Previously was left up to BIOS. | |
5593 | */ | |
5594 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5595 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5596 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5597 | ||
5598 | /* Enable PG1 for cdclk */ | |
5599 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5600 | ||
5601 | /* check if cd clock is enabled */ | |
5602 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5603 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5604 | return; | |
5605 | } | |
5606 | ||
5607 | /* | |
5608 | * FIXME: | |
5609 | * - The initial CDCLK needs to be read from VBT. | |
5610 | * Need to make this change after VBT has changes for BXT. | |
5611 | * - check if setting the max (or any) cdclk freq is really necessary | |
5612 | * here, it belongs to modeset time | |
5613 | */ | |
5614 | broxton_set_cdclk(dev, 624000); | |
5615 | ||
5616 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5617 | POSTING_READ(DBUF_CTL); |
5618 | ||
f8437dd1 VK |
5619 | udelay(10); |
5620 | ||
5621 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5622 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5623 | } | |
5624 | ||
5625 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5626 | { | |
5627 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5628 | ||
5629 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5630 | POSTING_READ(DBUF_CTL); |
5631 | ||
f8437dd1 VK |
5632 | udelay(10); |
5633 | ||
5634 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5635 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5636 | ||
5637 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5638 | broxton_set_cdclk(dev, 19200); | |
5639 | ||
5640 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5641 | } | |
5642 | ||
5d96d8af DL |
5643 | static const struct skl_cdclk_entry { |
5644 | unsigned int freq; | |
5645 | unsigned int vco; | |
5646 | } skl_cdclk_frequencies[] = { | |
5647 | { .freq = 308570, .vco = 8640 }, | |
5648 | { .freq = 337500, .vco = 8100 }, | |
5649 | { .freq = 432000, .vco = 8640 }, | |
5650 | { .freq = 450000, .vco = 8100 }, | |
5651 | { .freq = 540000, .vco = 8100 }, | |
5652 | { .freq = 617140, .vco = 8640 }, | |
5653 | { .freq = 675000, .vco = 8100 }, | |
5654 | }; | |
5655 | ||
5656 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5657 | { | |
5658 | return (freq - 1000) / 500; | |
5659 | } | |
5660 | ||
5661 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5662 | { | |
5663 | unsigned int i; | |
5664 | ||
5665 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5666 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5667 | ||
5668 | if (e->freq == freq) | |
5669 | return e->vco; | |
5670 | } | |
5671 | ||
5672 | return 8100; | |
5673 | } | |
5674 | ||
5675 | static void | |
5676 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5677 | { | |
5678 | unsigned int min_freq; | |
5679 | u32 val; | |
5680 | ||
5681 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5682 | val = I915_READ(CDCLK_CTL); | |
5683 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5684 | val |= CDCLK_FREQ_337_308; | |
5685 | ||
5686 | if (required_vco == 8640) | |
5687 | min_freq = 308570; | |
5688 | else | |
5689 | min_freq = 337500; | |
5690 | ||
5691 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5692 | ||
5693 | I915_WRITE(CDCLK_CTL, val); | |
5694 | POSTING_READ(CDCLK_CTL); | |
5695 | ||
5696 | /* | |
5697 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5698 | * taking into account the VCO required to operate the eDP panel at the | |
5699 | * desired frequency. The usual DP link rates operate with a VCO of | |
5700 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5701 | * The modeset code is responsible for the selection of the exact link | |
5702 | * rate later on, with the constraint of choosing a frequency that | |
5703 | * works with required_vco. | |
5704 | */ | |
5705 | val = I915_READ(DPLL_CTRL1); | |
5706 | ||
5707 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5708 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5709 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5710 | if (required_vco == 8640) | |
5711 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5712 | SKL_DPLL0); | |
5713 | else | |
5714 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5715 | SKL_DPLL0); | |
5716 | ||
5717 | I915_WRITE(DPLL_CTRL1, val); | |
5718 | POSTING_READ(DPLL_CTRL1); | |
5719 | ||
5720 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5721 | ||
5722 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5723 | DRM_ERROR("DPLL0 not locked\n"); | |
5724 | } | |
5725 | ||
5726 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5727 | { | |
5728 | int ret; | |
5729 | u32 val; | |
5730 | ||
5731 | /* inform PCU we want to change CDCLK */ | |
5732 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5733 | mutex_lock(&dev_priv->rps.hw_lock); | |
5734 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5735 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5736 | ||
5737 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5738 | } | |
5739 | ||
5740 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5741 | { | |
5742 | unsigned int i; | |
5743 | ||
5744 | for (i = 0; i < 15; i++) { | |
5745 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5746 | return true; | |
5747 | udelay(10); | |
5748 | } | |
5749 | ||
5750 | return false; | |
5751 | } | |
5752 | ||
5753 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5754 | { | |
560a7ae4 | 5755 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5756 | u32 freq_select, pcu_ack; |
5757 | ||
5758 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5759 | ||
5760 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5761 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5762 | return; | |
5763 | } | |
5764 | ||
5765 | /* set CDCLK_CTL */ | |
5766 | switch(freq) { | |
5767 | case 450000: | |
5768 | case 432000: | |
5769 | freq_select = CDCLK_FREQ_450_432; | |
5770 | pcu_ack = 1; | |
5771 | break; | |
5772 | case 540000: | |
5773 | freq_select = CDCLK_FREQ_540; | |
5774 | pcu_ack = 2; | |
5775 | break; | |
5776 | case 308570: | |
5777 | case 337500: | |
5778 | default: | |
5779 | freq_select = CDCLK_FREQ_337_308; | |
5780 | pcu_ack = 0; | |
5781 | break; | |
5782 | case 617140: | |
5783 | case 675000: | |
5784 | freq_select = CDCLK_FREQ_675_617; | |
5785 | pcu_ack = 3; | |
5786 | break; | |
5787 | } | |
5788 | ||
5789 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5790 | POSTING_READ(CDCLK_CTL); | |
5791 | ||
5792 | /* inform PCU of the change */ | |
5793 | mutex_lock(&dev_priv->rps.hw_lock); | |
5794 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5795 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5796 | |
5797 | intel_update_cdclk(dev); | |
5d96d8af DL |
5798 | } |
5799 | ||
5800 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5801 | { | |
5802 | /* disable DBUF power */ | |
5803 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5804 | POSTING_READ(DBUF_CTL); | |
5805 | ||
5806 | udelay(10); | |
5807 | ||
5808 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5809 | DRM_ERROR("DBuf power disable timeout\n"); | |
5810 | ||
ab96c1ee ID |
5811 | /* disable DPLL0 */ |
5812 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5813 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5814 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5d96d8af DL |
5815 | } |
5816 | ||
5817 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5818 | { | |
5d96d8af DL |
5819 | unsigned int required_vco; |
5820 | ||
39d9b85a GW |
5821 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5822 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5823 | /* enable DPLL0 */ | |
5824 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5825 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5826 | } |
5827 | ||
5d96d8af DL |
5828 | /* set CDCLK to the frequency the BIOS chose */ |
5829 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5830 | ||
5831 | /* enable DBUF power */ | |
5832 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5833 | POSTING_READ(DBUF_CTL); | |
5834 | ||
5835 | udelay(10); | |
5836 | ||
5837 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5838 | DRM_ERROR("DBuf power enable timeout\n"); | |
5839 | } | |
5840 | ||
c73666f3 SK |
5841 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
5842 | { | |
5843 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5844 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5845 | int freq = dev_priv->skl_boot_cdclk; | |
5846 | ||
f1b391a5 SK |
5847 | /* |
5848 | * check if the pre-os intialized the display | |
5849 | * There is SWF18 scratchpad register defined which is set by the | |
5850 | * pre-os which can be used by the OS drivers to check the status | |
5851 | */ | |
5852 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5853 | goto sanitize; | |
5854 | ||
c73666f3 SK |
5855 | /* Is PLL enabled and locked ? */ |
5856 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5857 | goto sanitize; | |
5858 | ||
5859 | /* DPLL okay; verify the cdclock | |
5860 | * | |
5861 | * Noticed in some instances that the freq selection is correct but | |
5862 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5863 | * enable display. Verify the same as well. | |
5864 | */ | |
5865 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5866 | /* All well; nothing to sanitize */ | |
5867 | return false; | |
5868 | sanitize: | |
5869 | /* | |
5870 | * As of now initialize with max cdclk till | |
5871 | * we get dynamic cdclk support | |
5872 | * */ | |
5873 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5874 | skl_init_cdclk(dev_priv); | |
5875 | ||
5876 | /* we did have to sanitize */ | |
5877 | return true; | |
5878 | } | |
5879 | ||
30a970c6 JB |
5880 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5881 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5882 | { | |
5883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5884 | u32 val, cmd; | |
5885 | ||
164dfd28 VK |
5886 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5887 | != dev_priv->cdclk_freq); | |
d60c4473 | 5888 | |
dfcab17e | 5889 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5890 | cmd = 2; |
dfcab17e | 5891 | else if (cdclk == 266667) |
30a970c6 JB |
5892 | cmd = 1; |
5893 | else | |
5894 | cmd = 0; | |
5895 | ||
5896 | mutex_lock(&dev_priv->rps.hw_lock); | |
5897 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5898 | val &= ~DSPFREQGUAR_MASK; | |
5899 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5900 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5901 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5902 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5903 | 50)) { | |
5904 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5905 | } | |
5906 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5907 | ||
54433e91 VS |
5908 | mutex_lock(&dev_priv->sb_lock); |
5909 | ||
dfcab17e | 5910 | if (cdclk == 400000) { |
6bcda4f0 | 5911 | u32 divider; |
30a970c6 | 5912 | |
6bcda4f0 | 5913 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5914 | |
30a970c6 JB |
5915 | /* adjust cdclk divider */ |
5916 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 5917 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
5918 | val |= divider; |
5919 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5920 | |
5921 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 5922 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
5923 | 50)) |
5924 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5925 | } |
5926 | ||
30a970c6 JB |
5927 | /* adjust self-refresh exit latency value */ |
5928 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5929 | val &= ~0x7f; | |
5930 | ||
5931 | /* | |
5932 | * For high bandwidth configs, we set a higher latency in the bunit | |
5933 | * so that the core display fetch happens in time to avoid underruns. | |
5934 | */ | |
dfcab17e | 5935 | if (cdclk == 400000) |
30a970c6 JB |
5936 | val |= 4500 / 250; /* 4.5 usec */ |
5937 | else | |
5938 | val |= 3000 / 250; /* 3.0 usec */ | |
5939 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5940 | |
a580516d | 5941 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5942 | |
b6283055 | 5943 | intel_update_cdclk(dev); |
30a970c6 JB |
5944 | } |
5945 | ||
383c5a6a VS |
5946 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5947 | { | |
5948 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5949 | u32 val, cmd; | |
5950 | ||
164dfd28 VK |
5951 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5952 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5953 | |
5954 | switch (cdclk) { | |
383c5a6a VS |
5955 | case 333333: |
5956 | case 320000: | |
383c5a6a | 5957 | case 266667: |
383c5a6a | 5958 | case 200000: |
383c5a6a VS |
5959 | break; |
5960 | default: | |
5f77eeb0 | 5961 | MISSING_CASE(cdclk); |
383c5a6a VS |
5962 | return; |
5963 | } | |
5964 | ||
9d0d3fda VS |
5965 | /* |
5966 | * Specs are full of misinformation, but testing on actual | |
5967 | * hardware has shown that we just need to write the desired | |
5968 | * CCK divider into the Punit register. | |
5969 | */ | |
5970 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5971 | ||
383c5a6a VS |
5972 | mutex_lock(&dev_priv->rps.hw_lock); |
5973 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5974 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5975 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5976 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5977 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5978 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5979 | 50)) { | |
5980 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5981 | } | |
5982 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5983 | ||
b6283055 | 5984 | intel_update_cdclk(dev); |
383c5a6a VS |
5985 | } |
5986 | ||
30a970c6 JB |
5987 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5988 | int max_pixclk) | |
5989 | { | |
6bcda4f0 | 5990 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5991 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5992 | |
30a970c6 JB |
5993 | /* |
5994 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5995 | * 200MHz | |
5996 | * 267MHz | |
29dc7ef3 | 5997 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5998 | * 400MHz (VLV only) |
5999 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
6000 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
6001 | * |
6002 | * We seem to get an unstable or solid color picture at 200MHz. | |
6003 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
6004 | * are off. | |
30a970c6 | 6005 | */ |
6cca3195 VS |
6006 | if (!IS_CHERRYVIEW(dev_priv) && |
6007 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 6008 | return 400000; |
6cca3195 | 6009 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 6010 | return freq_320; |
e37c67a1 | 6011 | else if (max_pixclk > 0) |
dfcab17e | 6012 | return 266667; |
e37c67a1 VS |
6013 | else |
6014 | return 200000; | |
30a970c6 JB |
6015 | } |
6016 | ||
f8437dd1 VK |
6017 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
6018 | int max_pixclk) | |
6019 | { | |
6020 | /* | |
6021 | * FIXME: | |
6022 | * - remove the guardband, it's not needed on BXT | |
6023 | * - set 19.2MHz bypass frequency if there are no active pipes | |
6024 | */ | |
6025 | if (max_pixclk > 576000*9/10) | |
6026 | return 624000; | |
6027 | else if (max_pixclk > 384000*9/10) | |
6028 | return 576000; | |
6029 | else if (max_pixclk > 288000*9/10) | |
6030 | return 384000; | |
6031 | else if (max_pixclk > 144000*9/10) | |
6032 | return 288000; | |
6033 | else | |
6034 | return 144000; | |
6035 | } | |
6036 | ||
a821fc46 ACO |
6037 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
6038 | * that's non-NULL, look at current state otherwise. */ | |
6039 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
6040 | struct drm_atomic_state *state) | |
30a970c6 | 6041 | { |
30a970c6 | 6042 | struct intel_crtc *intel_crtc; |
304603f4 | 6043 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
6044 | int max_pixclk = 0; |
6045 | ||
d3fcc808 | 6046 | for_each_intel_crtc(dev, intel_crtc) { |
27c329ed | 6047 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
304603f4 ACO |
6048 | if (IS_ERR(crtc_state)) |
6049 | return PTR_ERR(crtc_state); | |
6050 | ||
6051 | if (!crtc_state->base.enable) | |
6052 | continue; | |
6053 | ||
6054 | max_pixclk = max(max_pixclk, | |
6055 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
6056 | } |
6057 | ||
6058 | return max_pixclk; | |
6059 | } | |
6060 | ||
27c329ed | 6061 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 6062 | { |
27c329ed ML |
6063 | struct drm_device *dev = state->dev; |
6064 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6065 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
30a970c6 | 6066 | |
304603f4 ACO |
6067 | if (max_pixclk < 0) |
6068 | return max_pixclk; | |
30a970c6 | 6069 | |
27c329ed ML |
6070 | to_intel_atomic_state(state)->cdclk = |
6071 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
0a9ab303 | 6072 | |
27c329ed ML |
6073 | return 0; |
6074 | } | |
304603f4 | 6075 | |
27c329ed ML |
6076 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
6077 | { | |
6078 | struct drm_device *dev = state->dev; | |
6079 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6080 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
85a96e7a | 6081 | |
27c329ed ML |
6082 | if (max_pixclk < 0) |
6083 | return max_pixclk; | |
85a96e7a | 6084 | |
27c329ed ML |
6085 | to_intel_atomic_state(state)->cdclk = |
6086 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
85a96e7a | 6087 | |
27c329ed | 6088 | return 0; |
30a970c6 JB |
6089 | } |
6090 | ||
1e69cd74 VS |
6091 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
6092 | { | |
6093 | unsigned int credits, default_credits; | |
6094 | ||
6095 | if (IS_CHERRYVIEW(dev_priv)) | |
6096 | default_credits = PFI_CREDIT(12); | |
6097 | else | |
6098 | default_credits = PFI_CREDIT(8); | |
6099 | ||
bfa7df01 | 6100 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
6101 | /* CHV suggested value is 31 or 63 */ |
6102 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 6103 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
6104 | else |
6105 | credits = PFI_CREDIT(15); | |
6106 | } else { | |
6107 | credits = default_credits; | |
6108 | } | |
6109 | ||
6110 | /* | |
6111 | * WA - write default credits before re-programming | |
6112 | * FIXME: should we also set the resend bit here? | |
6113 | */ | |
6114 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6115 | default_credits); | |
6116 | ||
6117 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6118 | credits | PFI_CREDIT_RESEND); | |
6119 | ||
6120 | /* | |
6121 | * FIXME is this guaranteed to clear | |
6122 | * immediately or should we poll for it? | |
6123 | */ | |
6124 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6125 | } | |
6126 | ||
27c329ed | 6127 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6128 | { |
a821fc46 | 6129 | struct drm_device *dev = old_state->dev; |
27c329ed | 6130 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
30a970c6 | 6131 | struct drm_i915_private *dev_priv = dev->dev_private; |
30a970c6 | 6132 | |
27c329ed ML |
6133 | /* |
6134 | * FIXME: We can end up here with all power domains off, yet | |
6135 | * with a CDCLK frequency other than the minimum. To account | |
6136 | * for this take the PIPE-A power domain, which covers the HW | |
6137 | * blocks needed for the following programming. This can be | |
6138 | * removed once it's guaranteed that we get here either with | |
6139 | * the minimum CDCLK set, or the required power domains | |
6140 | * enabled. | |
6141 | */ | |
6142 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6143 | |
27c329ed ML |
6144 | if (IS_CHERRYVIEW(dev)) |
6145 | cherryview_set_cdclk(dev, req_cdclk); | |
6146 | else | |
6147 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6148 | |
27c329ed | 6149 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6150 | |
27c329ed | 6151 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6152 | } |
6153 | ||
89b667f8 JB |
6154 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6155 | { | |
6156 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6157 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6158 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6159 | struct intel_encoder *encoder; | |
6160 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6161 | bool is_dsi; |
89b667f8 | 6162 | |
53d9f4e9 | 6163 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6164 | return; |
6165 | ||
409ee761 | 6166 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6167 | |
6e3c9717 | 6168 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6169 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6170 | |
6171 | intel_set_pipe_timings(intel_crtc); | |
6172 | ||
c14b0485 VS |
6173 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6175 | ||
6176 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6177 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6178 | } | |
6179 | ||
5b18e57c DV |
6180 | i9xx_set_pipeconf(intel_crtc); |
6181 | ||
89b667f8 | 6182 | intel_crtc->active = true; |
89b667f8 | 6183 | |
a72e4c9f | 6184 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6185 | |
89b667f8 JB |
6186 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6187 | if (encoder->pre_pll_enable) | |
6188 | encoder->pre_pll_enable(encoder); | |
6189 | ||
9d556c99 | 6190 | if (!is_dsi) { |
c0b4c660 VS |
6191 | if (IS_CHERRYVIEW(dev)) { |
6192 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6193 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6194 | } else { |
6195 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6196 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6197 | } |
9d556c99 | 6198 | } |
89b667f8 JB |
6199 | |
6200 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6201 | if (encoder->pre_enable) | |
6202 | encoder->pre_enable(encoder); | |
6203 | ||
2dd24552 JB |
6204 | i9xx_pfit_enable(intel_crtc); |
6205 | ||
63cbb074 VS |
6206 | intel_crtc_load_lut(crtc); |
6207 | ||
e1fdc473 | 6208 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6209 | |
4b3a9526 VS |
6210 | assert_vblank_disabled(crtc); |
6211 | drm_crtc_vblank_on(crtc); | |
6212 | ||
f9b61ff6 DV |
6213 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6214 | encoder->enable(encoder); | |
89b667f8 JB |
6215 | } |
6216 | ||
f13c2ef3 DV |
6217 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6218 | { | |
6219 | struct drm_device *dev = crtc->base.dev; | |
6220 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6221 | ||
6e3c9717 ACO |
6222 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6223 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6224 | } |
6225 | ||
0b8765c6 | 6226 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6227 | { |
6228 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6229 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6230 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6231 | struct intel_encoder *encoder; |
79e53945 | 6232 | int pipe = intel_crtc->pipe; |
79e53945 | 6233 | |
53d9f4e9 | 6234 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6235 | return; |
6236 | ||
f13c2ef3 DV |
6237 | i9xx_set_pll_dividers(intel_crtc); |
6238 | ||
6e3c9717 | 6239 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6240 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6241 | |
6242 | intel_set_pipe_timings(intel_crtc); | |
6243 | ||
5b18e57c DV |
6244 | i9xx_set_pipeconf(intel_crtc); |
6245 | ||
f7abfe8b | 6246 | intel_crtc->active = true; |
6b383a7f | 6247 | |
4a3436e8 | 6248 | if (!IS_GEN2(dev)) |
a72e4c9f | 6249 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6250 | |
9d6d9f19 MK |
6251 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6252 | if (encoder->pre_enable) | |
6253 | encoder->pre_enable(encoder); | |
6254 | ||
f6736a1a DV |
6255 | i9xx_enable_pll(intel_crtc); |
6256 | ||
2dd24552 JB |
6257 | i9xx_pfit_enable(intel_crtc); |
6258 | ||
63cbb074 VS |
6259 | intel_crtc_load_lut(crtc); |
6260 | ||
f37fcc2a | 6261 | intel_update_watermarks(crtc); |
e1fdc473 | 6262 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6263 | |
4b3a9526 VS |
6264 | assert_vblank_disabled(crtc); |
6265 | drm_crtc_vblank_on(crtc); | |
6266 | ||
f9b61ff6 DV |
6267 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6268 | encoder->enable(encoder); | |
0b8765c6 | 6269 | } |
79e53945 | 6270 | |
87476d63 DV |
6271 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6272 | { | |
6273 | struct drm_device *dev = crtc->base.dev; | |
6274 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6275 | |
6e3c9717 | 6276 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6277 | return; |
87476d63 | 6278 | |
328d8e82 | 6279 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6280 | |
328d8e82 DV |
6281 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6282 | I915_READ(PFIT_CONTROL)); | |
6283 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6284 | } |
6285 | ||
0b8765c6 JB |
6286 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6287 | { | |
6288 | struct drm_device *dev = crtc->dev; | |
6289 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6290 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6291 | struct intel_encoder *encoder; |
0b8765c6 | 6292 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6293 | |
6304cd91 VS |
6294 | /* |
6295 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6296 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6297 | * We also need to wait on all gmch platforms because of the |
6298 | * self-refresh mode constraint explained above. | |
6304cd91 | 6299 | */ |
564ed191 | 6300 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6301 | |
4b3a9526 VS |
6302 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6303 | encoder->disable(encoder); | |
6304 | ||
f9b61ff6 DV |
6305 | drm_crtc_vblank_off(crtc); |
6306 | assert_vblank_disabled(crtc); | |
6307 | ||
575f7ab7 | 6308 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6309 | |
87476d63 | 6310 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6311 | |
89b667f8 JB |
6312 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6313 | if (encoder->post_disable) | |
6314 | encoder->post_disable(encoder); | |
6315 | ||
409ee761 | 6316 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6317 | if (IS_CHERRYVIEW(dev)) |
6318 | chv_disable_pll(dev_priv, pipe); | |
6319 | else if (IS_VALLEYVIEW(dev)) | |
6320 | vlv_disable_pll(dev_priv, pipe); | |
6321 | else | |
1c4e0274 | 6322 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6323 | } |
0b8765c6 | 6324 | |
d6db995f VS |
6325 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6326 | if (encoder->post_pll_disable) | |
6327 | encoder->post_pll_disable(encoder); | |
6328 | ||
4a3436e8 | 6329 | if (!IS_GEN2(dev)) |
a72e4c9f | 6330 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
0b8765c6 JB |
6331 | } |
6332 | ||
b17d48e2 ML |
6333 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6334 | { | |
6335 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6336 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6337 | enum intel_display_power_domain domain; | |
6338 | unsigned long domains; | |
6339 | ||
6340 | if (!intel_crtc->active) | |
6341 | return; | |
6342 | ||
a539205a | 6343 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
fc32b1fd ML |
6344 | WARN_ON(intel_crtc->unpin_work); |
6345 | ||
a539205a ML |
6346 | intel_pre_disable_primary(crtc); |
6347 | } | |
6348 | ||
d032ffa0 | 6349 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 | 6350 | dev_priv->display.crtc_disable(crtc); |
37d9078b MR |
6351 | intel_crtc->active = false; |
6352 | intel_update_watermarks(crtc); | |
1f7457b1 | 6353 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6354 | |
6355 | domains = intel_crtc->enabled_power_domains; | |
6356 | for_each_power_domain(domain, domains) | |
6357 | intel_display_power_put(dev_priv, domain); | |
6358 | intel_crtc->enabled_power_domains = 0; | |
6359 | } | |
6360 | ||
6b72d486 ML |
6361 | /* |
6362 | * turn all crtc's off, but do not adjust state | |
6363 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6364 | */ | |
70e0bd74 | 6365 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6366 | { |
70e0bd74 ML |
6367 | struct drm_mode_config *config = &dev->mode_config; |
6368 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
6369 | struct drm_atomic_state *state; | |
6b72d486 | 6370 | struct drm_crtc *crtc; |
70e0bd74 ML |
6371 | unsigned crtc_mask = 0; |
6372 | int ret = 0; | |
6373 | ||
6374 | if (WARN_ON(!ctx)) | |
6375 | return 0; | |
6376 | ||
6377 | lockdep_assert_held(&ctx->ww_ctx); | |
6378 | state = drm_atomic_state_alloc(dev); | |
6379 | if (WARN_ON(!state)) | |
6380 | return -ENOMEM; | |
6381 | ||
6382 | state->acquire_ctx = ctx; | |
6383 | state->allow_modeset = true; | |
6384 | ||
6385 | for_each_crtc(dev, crtc) { | |
6386 | struct drm_crtc_state *crtc_state = | |
6387 | drm_atomic_get_crtc_state(state, crtc); | |
6b72d486 | 6388 | |
70e0bd74 ML |
6389 | ret = PTR_ERR_OR_ZERO(crtc_state); |
6390 | if (ret) | |
6391 | goto free; | |
6392 | ||
6393 | if (!crtc_state->active) | |
6394 | continue; | |
6395 | ||
6396 | crtc_state->active = false; | |
6397 | crtc_mask |= 1 << drm_crtc_index(crtc); | |
6398 | } | |
6399 | ||
6400 | if (crtc_mask) { | |
74c090b1 | 6401 | ret = drm_atomic_commit(state); |
70e0bd74 ML |
6402 | |
6403 | if (!ret) { | |
6404 | for_each_crtc(dev, crtc) | |
6405 | if (crtc_mask & (1 << drm_crtc_index(crtc))) | |
6406 | crtc->state->active = true; | |
6407 | ||
6408 | return ret; | |
6409 | } | |
6410 | } | |
6411 | ||
6412 | free: | |
6413 | if (ret) | |
6414 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6415 | drm_atomic_state_free(state); | |
6416 | return ret; | |
ee7b9f93 JB |
6417 | } |
6418 | ||
ea5b213a | 6419 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6420 | { |
4ef69c7a | 6421 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6422 | |
ea5b213a CW |
6423 | drm_encoder_cleanup(encoder); |
6424 | kfree(intel_encoder); | |
7e7d76c3 JB |
6425 | } |
6426 | ||
0a91ca29 DV |
6427 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6428 | * internal consistency). */ | |
b980514c | 6429 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6430 | { |
35dd3c64 ML |
6431 | struct drm_crtc *crtc = connector->base.state->crtc; |
6432 | ||
6433 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6434 | connector->base.base.id, | |
6435 | connector->base.name); | |
6436 | ||
0a91ca29 | 6437 | if (connector->get_hw_state(connector)) { |
e85376cb | 6438 | struct intel_encoder *encoder = connector->encoder; |
35dd3c64 | 6439 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6440 | |
35dd3c64 ML |
6441 | I915_STATE_WARN(!crtc, |
6442 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6443 | |
35dd3c64 ML |
6444 | if (!crtc) |
6445 | return; | |
6446 | ||
6447 | I915_STATE_WARN(!crtc->state->active, | |
6448 | "connector is active, but attached crtc isn't\n"); | |
6449 | ||
e85376cb | 6450 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6451 | return; |
6452 | ||
e85376cb | 6453 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6454 | "atomic encoder doesn't match attached encoder\n"); |
6455 | ||
e85376cb | 6456 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6457 | "attached encoder crtc differs from connector crtc\n"); |
6458 | } else { | |
4d688a2a ML |
6459 | I915_STATE_WARN(crtc && crtc->state->active, |
6460 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6461 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6462 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6463 | } |
79e53945 JB |
6464 | } |
6465 | ||
08d9bc92 ACO |
6466 | int intel_connector_init(struct intel_connector *connector) |
6467 | { | |
6468 | struct drm_connector_state *connector_state; | |
6469 | ||
6470 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6471 | if (!connector_state) | |
6472 | return -ENOMEM; | |
6473 | ||
6474 | connector->base.state = connector_state; | |
6475 | return 0; | |
6476 | } | |
6477 | ||
6478 | struct intel_connector *intel_connector_alloc(void) | |
6479 | { | |
6480 | struct intel_connector *connector; | |
6481 | ||
6482 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6483 | if (!connector) | |
6484 | return NULL; | |
6485 | ||
6486 | if (intel_connector_init(connector) < 0) { | |
6487 | kfree(connector); | |
6488 | return NULL; | |
6489 | } | |
6490 | ||
6491 | return connector; | |
6492 | } | |
6493 | ||
f0947c37 DV |
6494 | /* Simple connector->get_hw_state implementation for encoders that support only |
6495 | * one connector and no cloning and hence the encoder state determines the state | |
6496 | * of the connector. */ | |
6497 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6498 | { |
24929352 | 6499 | enum pipe pipe = 0; |
f0947c37 | 6500 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6501 | |
f0947c37 | 6502 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6503 | } |
6504 | ||
6d293983 | 6505 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6506 | { |
6d293983 ACO |
6507 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6508 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6509 | |
6510 | return 0; | |
6511 | } | |
6512 | ||
6d293983 | 6513 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6514 | struct intel_crtc_state *pipe_config) |
1857e1da | 6515 | { |
6d293983 ACO |
6516 | struct drm_atomic_state *state = pipe_config->base.state; |
6517 | struct intel_crtc *other_crtc; | |
6518 | struct intel_crtc_state *other_crtc_state; | |
6519 | ||
1857e1da DV |
6520 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6521 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6522 | if (pipe_config->fdi_lanes > 4) { | |
6523 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6524 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6525 | return -EINVAL; |
1857e1da DV |
6526 | } |
6527 | ||
bafb6553 | 6528 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6529 | if (pipe_config->fdi_lanes > 2) { |
6530 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6531 | pipe_config->fdi_lanes); | |
6d293983 | 6532 | return -EINVAL; |
1857e1da | 6533 | } else { |
6d293983 | 6534 | return 0; |
1857e1da DV |
6535 | } |
6536 | } | |
6537 | ||
6538 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6539 | return 0; |
1857e1da DV |
6540 | |
6541 | /* Ivybridge 3 pipe is really complicated */ | |
6542 | switch (pipe) { | |
6543 | case PIPE_A: | |
6d293983 | 6544 | return 0; |
1857e1da | 6545 | case PIPE_B: |
6d293983 ACO |
6546 | if (pipe_config->fdi_lanes <= 2) |
6547 | return 0; | |
6548 | ||
6549 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6550 | other_crtc_state = | |
6551 | intel_atomic_get_crtc_state(state, other_crtc); | |
6552 | if (IS_ERR(other_crtc_state)) | |
6553 | return PTR_ERR(other_crtc_state); | |
6554 | ||
6555 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6556 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6557 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6558 | return -EINVAL; |
1857e1da | 6559 | } |
6d293983 | 6560 | return 0; |
1857e1da | 6561 | case PIPE_C: |
251cc67c VS |
6562 | if (pipe_config->fdi_lanes > 2) { |
6563 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6564 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6565 | return -EINVAL; |
251cc67c | 6566 | } |
6d293983 ACO |
6567 | |
6568 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6569 | other_crtc_state = | |
6570 | intel_atomic_get_crtc_state(state, other_crtc); | |
6571 | if (IS_ERR(other_crtc_state)) | |
6572 | return PTR_ERR(other_crtc_state); | |
6573 | ||
6574 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6575 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6576 | return -EINVAL; |
1857e1da | 6577 | } |
6d293983 | 6578 | return 0; |
1857e1da DV |
6579 | default: |
6580 | BUG(); | |
6581 | } | |
6582 | } | |
6583 | ||
e29c22c0 DV |
6584 | #define RETRY 1 |
6585 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6586 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6587 | { |
1857e1da | 6588 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6589 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6590 | int lane, link_bw, fdi_dotclock, ret; |
6591 | bool needs_recompute = false; | |
877d48d5 | 6592 | |
e29c22c0 | 6593 | retry: |
877d48d5 DV |
6594 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6595 | * each output octet as 10 bits. The actual frequency | |
6596 | * is stored as a divider into a 100MHz clock, and the | |
6597 | * mode pixel clock is stored in units of 1KHz. | |
6598 | * Hence the bw of each lane in terms of the mode signal | |
6599 | * is: | |
6600 | */ | |
6601 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6602 | ||
241bfc38 | 6603 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6604 | |
2bd89a07 | 6605 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6606 | pipe_config->pipe_bpp); |
6607 | ||
6608 | pipe_config->fdi_lanes = lane; | |
6609 | ||
2bd89a07 | 6610 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6611 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6612 | |
6d293983 ACO |
6613 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6614 | intel_crtc->pipe, pipe_config); | |
6615 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6616 | pipe_config->pipe_bpp -= 2*3; |
6617 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6618 | pipe_config->pipe_bpp); | |
6619 | needs_recompute = true; | |
6620 | pipe_config->bw_constrained = true; | |
6621 | ||
6622 | goto retry; | |
6623 | } | |
6624 | ||
6625 | if (needs_recompute) | |
6626 | return RETRY; | |
6627 | ||
6d293983 | 6628 | return ret; |
877d48d5 DV |
6629 | } |
6630 | ||
8cfb3407 VS |
6631 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6632 | struct intel_crtc_state *pipe_config) | |
6633 | { | |
6634 | if (pipe_config->pipe_bpp > 24) | |
6635 | return false; | |
6636 | ||
6637 | /* HSW can handle pixel rate up to cdclk? */ | |
6638 | if (IS_HASWELL(dev_priv->dev)) | |
6639 | return true; | |
6640 | ||
6641 | /* | |
b432e5cf VS |
6642 | * We compare against max which means we must take |
6643 | * the increased cdclk requirement into account when | |
6644 | * calculating the new cdclk. | |
6645 | * | |
6646 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6647 | */ |
6648 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6649 | dev_priv->max_cdclk_freq * 95 / 100; | |
6650 | } | |
6651 | ||
42db64ef | 6652 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6653 | struct intel_crtc_state *pipe_config) |
42db64ef | 6654 | { |
8cfb3407 VS |
6655 | struct drm_device *dev = crtc->base.dev; |
6656 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6657 | ||
d330a953 | 6658 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6659 | hsw_crtc_supports_ips(crtc) && |
6660 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6661 | } |
6662 | ||
39acb4aa VS |
6663 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6664 | { | |
6665 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6666 | ||
6667 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6668 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6669 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6670 | } | |
6671 | ||
a43f6e0f | 6672 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6673 | struct intel_crtc_state *pipe_config) |
79e53945 | 6674 | { |
a43f6e0f | 6675 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6676 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6677 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6678 | |
ad3a4479 | 6679 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6680 | if (INTEL_INFO(dev)->gen < 4) { |
39acb4aa | 6681 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6682 | |
6683 | /* | |
39acb4aa | 6684 | * Enable double wide mode when the dot clock |
cf532bb2 | 6685 | * is > 90% of the (display) core speed. |
cf532bb2 | 6686 | */ |
39acb4aa VS |
6687 | if (intel_crtc_supports_double_wide(crtc) && |
6688 | adjusted_mode->crtc_clock > clock_limit) { | |
ad3a4479 | 6689 | clock_limit *= 2; |
cf532bb2 | 6690 | pipe_config->double_wide = true; |
ad3a4479 VS |
6691 | } |
6692 | ||
39acb4aa VS |
6693 | if (adjusted_mode->crtc_clock > clock_limit) { |
6694 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6695 | adjusted_mode->crtc_clock, clock_limit, | |
6696 | yesno(pipe_config->double_wide)); | |
e29c22c0 | 6697 | return -EINVAL; |
39acb4aa | 6698 | } |
2c07245f | 6699 | } |
89749350 | 6700 | |
1d1d0e27 VS |
6701 | /* |
6702 | * Pipe horizontal size must be even in: | |
6703 | * - DVO ganged mode | |
6704 | * - LVDS dual channel mode | |
6705 | * - Double wide pipe | |
6706 | */ | |
a93e255f | 6707 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6708 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6709 | pipe_config->pipe_src_w &= ~1; | |
6710 | ||
8693a824 DL |
6711 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6712 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6713 | */ |
6714 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6715 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6716 | return -EINVAL; |
44f46b42 | 6717 | |
f5adf94e | 6718 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6719 | hsw_compute_ips_config(crtc, pipe_config); |
6720 | ||
877d48d5 | 6721 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6722 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6723 | |
cf5a15be | 6724 | return 0; |
79e53945 JB |
6725 | } |
6726 | ||
1652d19e VS |
6727 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6728 | { | |
6729 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6730 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6731 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6732 | uint32_t linkrate; | |
6733 | ||
414355a7 | 6734 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6735 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6736 | |
6737 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6738 | return 540000; | |
6739 | ||
6740 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6741 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6742 | |
71cd8423 DL |
6743 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6744 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6745 | /* vco 8640 */ |
6746 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6747 | case CDCLK_FREQ_450_432: | |
6748 | return 432000; | |
6749 | case CDCLK_FREQ_337_308: | |
6750 | return 308570; | |
6751 | case CDCLK_FREQ_675_617: | |
6752 | return 617140; | |
6753 | default: | |
6754 | WARN(1, "Unknown cd freq selection\n"); | |
6755 | } | |
6756 | } else { | |
6757 | /* vco 8100 */ | |
6758 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6759 | case CDCLK_FREQ_450_432: | |
6760 | return 450000; | |
6761 | case CDCLK_FREQ_337_308: | |
6762 | return 337500; | |
6763 | case CDCLK_FREQ_675_617: | |
6764 | return 675000; | |
6765 | default: | |
6766 | WARN(1, "Unknown cd freq selection\n"); | |
6767 | } | |
6768 | } | |
6769 | ||
6770 | /* error case, do as if DPLL0 isn't enabled */ | |
6771 | return 24000; | |
6772 | } | |
6773 | ||
acd3f3d3 BP |
6774 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6775 | { | |
6776 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6777 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6778 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6779 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6780 | int cdclk; | |
6781 | ||
6782 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6783 | return 19200; | |
6784 | ||
6785 | cdclk = 19200 * pll_ratio / 2; | |
6786 | ||
6787 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6788 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6789 | return cdclk; /* 576MHz or 624MHz */ | |
6790 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6791 | return cdclk * 2 / 3; /* 384MHz */ | |
6792 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6793 | return cdclk / 2; /* 288MHz */ | |
6794 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6795 | return cdclk / 4; /* 144MHz */ | |
6796 | } | |
6797 | ||
6798 | /* error case, do as if DE PLL isn't enabled */ | |
6799 | return 19200; | |
6800 | } | |
6801 | ||
1652d19e VS |
6802 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6803 | { | |
6804 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6805 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6806 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6807 | ||
6808 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6809 | return 800000; | |
6810 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6811 | return 450000; | |
6812 | else if (freq == LCPLL_CLK_FREQ_450) | |
6813 | return 450000; | |
6814 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6815 | return 540000; | |
6816 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6817 | return 337500; | |
6818 | else | |
6819 | return 675000; | |
6820 | } | |
6821 | ||
6822 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6823 | { | |
6824 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6825 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6826 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6827 | ||
6828 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6829 | return 800000; | |
6830 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6831 | return 450000; | |
6832 | else if (freq == LCPLL_CLK_FREQ_450) | |
6833 | return 450000; | |
6834 | else if (IS_HSW_ULT(dev)) | |
6835 | return 337500; | |
6836 | else | |
6837 | return 540000; | |
79e53945 JB |
6838 | } |
6839 | ||
25eb05fc JB |
6840 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6841 | { | |
bfa7df01 VS |
6842 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6843 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6844 | } |
6845 | ||
b37a6434 VS |
6846 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6847 | { | |
6848 | return 450000; | |
6849 | } | |
6850 | ||
e70236a8 JB |
6851 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6852 | { | |
6853 | return 400000; | |
6854 | } | |
79e53945 | 6855 | |
e70236a8 | 6856 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6857 | { |
e907f170 | 6858 | return 333333; |
e70236a8 | 6859 | } |
79e53945 | 6860 | |
e70236a8 JB |
6861 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6862 | { | |
6863 | return 200000; | |
6864 | } | |
79e53945 | 6865 | |
257a7ffc DV |
6866 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6867 | { | |
6868 | u16 gcfgc = 0; | |
6869 | ||
6870 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6871 | ||
6872 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6873 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6874 | return 266667; |
257a7ffc | 6875 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6876 | return 333333; |
257a7ffc | 6877 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6878 | return 444444; |
257a7ffc DV |
6879 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6880 | return 200000; | |
6881 | default: | |
6882 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6883 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6884 | return 133333; |
257a7ffc | 6885 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6886 | return 166667; |
257a7ffc DV |
6887 | } |
6888 | } | |
6889 | ||
e70236a8 JB |
6890 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6891 | { | |
6892 | u16 gcfgc = 0; | |
79e53945 | 6893 | |
e70236a8 JB |
6894 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6895 | ||
6896 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6897 | return 133333; |
e70236a8 JB |
6898 | else { |
6899 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6900 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6901 | return 333333; |
e70236a8 JB |
6902 | default: |
6903 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6904 | return 190000; | |
79e53945 | 6905 | } |
e70236a8 JB |
6906 | } |
6907 | } | |
6908 | ||
6909 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6910 | { | |
e907f170 | 6911 | return 266667; |
e70236a8 JB |
6912 | } |
6913 | ||
1b1d2716 | 6914 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6915 | { |
6916 | u16 hpllcc = 0; | |
1b1d2716 | 6917 | |
65cd2b3f VS |
6918 | /* |
6919 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6920 | * encoding is different :( | |
6921 | * FIXME is this the right way to detect 852GM/852GMV? | |
6922 | */ | |
6923 | if (dev->pdev->revision == 0x1) | |
6924 | return 133333; | |
6925 | ||
1b1d2716 VS |
6926 | pci_bus_read_config_word(dev->pdev->bus, |
6927 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6928 | ||
e70236a8 JB |
6929 | /* Assume that the hardware is in the high speed state. This |
6930 | * should be the default. | |
6931 | */ | |
6932 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6933 | case GC_CLOCK_133_200: | |
1b1d2716 | 6934 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6935 | case GC_CLOCK_100_200: |
6936 | return 200000; | |
6937 | case GC_CLOCK_166_250: | |
6938 | return 250000; | |
6939 | case GC_CLOCK_100_133: | |
e907f170 | 6940 | return 133333; |
1b1d2716 VS |
6941 | case GC_CLOCK_133_266: |
6942 | case GC_CLOCK_133_266_2: | |
6943 | case GC_CLOCK_166_266: | |
6944 | return 266667; | |
e70236a8 | 6945 | } |
79e53945 | 6946 | |
e70236a8 JB |
6947 | /* Shouldn't happen */ |
6948 | return 0; | |
6949 | } | |
79e53945 | 6950 | |
e70236a8 JB |
6951 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6952 | { | |
e907f170 | 6953 | return 133333; |
79e53945 JB |
6954 | } |
6955 | ||
34edce2f VS |
6956 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6957 | { | |
6958 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6959 | static const unsigned int blb_vco[8] = { | |
6960 | [0] = 3200000, | |
6961 | [1] = 4000000, | |
6962 | [2] = 5333333, | |
6963 | [3] = 4800000, | |
6964 | [4] = 6400000, | |
6965 | }; | |
6966 | static const unsigned int pnv_vco[8] = { | |
6967 | [0] = 3200000, | |
6968 | [1] = 4000000, | |
6969 | [2] = 5333333, | |
6970 | [3] = 4800000, | |
6971 | [4] = 2666667, | |
6972 | }; | |
6973 | static const unsigned int cl_vco[8] = { | |
6974 | [0] = 3200000, | |
6975 | [1] = 4000000, | |
6976 | [2] = 5333333, | |
6977 | [3] = 6400000, | |
6978 | [4] = 3333333, | |
6979 | [5] = 3566667, | |
6980 | [6] = 4266667, | |
6981 | }; | |
6982 | static const unsigned int elk_vco[8] = { | |
6983 | [0] = 3200000, | |
6984 | [1] = 4000000, | |
6985 | [2] = 5333333, | |
6986 | [3] = 4800000, | |
6987 | }; | |
6988 | static const unsigned int ctg_vco[8] = { | |
6989 | [0] = 3200000, | |
6990 | [1] = 4000000, | |
6991 | [2] = 5333333, | |
6992 | [3] = 6400000, | |
6993 | [4] = 2666667, | |
6994 | [5] = 4266667, | |
6995 | }; | |
6996 | const unsigned int *vco_table; | |
6997 | unsigned int vco; | |
6998 | uint8_t tmp = 0; | |
6999 | ||
7000 | /* FIXME other chipsets? */ | |
7001 | if (IS_GM45(dev)) | |
7002 | vco_table = ctg_vco; | |
7003 | else if (IS_G4X(dev)) | |
7004 | vco_table = elk_vco; | |
7005 | else if (IS_CRESTLINE(dev)) | |
7006 | vco_table = cl_vco; | |
7007 | else if (IS_PINEVIEW(dev)) | |
7008 | vco_table = pnv_vco; | |
7009 | else if (IS_G33(dev)) | |
7010 | vco_table = blb_vco; | |
7011 | else | |
7012 | return 0; | |
7013 | ||
7014 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
7015 | ||
7016 | vco = vco_table[tmp & 0x7]; | |
7017 | if (vco == 0) | |
7018 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
7019 | else | |
7020 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
7021 | ||
7022 | return vco; | |
7023 | } | |
7024 | ||
7025 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
7026 | { | |
7027 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7028 | uint16_t tmp = 0; | |
7029 | ||
7030 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7031 | ||
7032 | cdclk_sel = (tmp >> 12) & 0x1; | |
7033 | ||
7034 | switch (vco) { | |
7035 | case 2666667: | |
7036 | case 4000000: | |
7037 | case 5333333: | |
7038 | return cdclk_sel ? 333333 : 222222; | |
7039 | case 3200000: | |
7040 | return cdclk_sel ? 320000 : 228571; | |
7041 | default: | |
7042 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
7043 | return 222222; | |
7044 | } | |
7045 | } | |
7046 | ||
7047 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
7048 | { | |
7049 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
7050 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
7051 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
7052 | const uint8_t *div_table; | |
7053 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7054 | uint16_t tmp = 0; | |
7055 | ||
7056 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7057 | ||
7058 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
7059 | ||
7060 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7061 | goto fail; | |
7062 | ||
7063 | switch (vco) { | |
7064 | case 3200000: | |
7065 | div_table = div_3200; | |
7066 | break; | |
7067 | case 4000000: | |
7068 | div_table = div_4000; | |
7069 | break; | |
7070 | case 5333333: | |
7071 | div_table = div_5333; | |
7072 | break; | |
7073 | default: | |
7074 | goto fail; | |
7075 | } | |
7076 | ||
7077 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7078 | ||
caf4e252 | 7079 | fail: |
34edce2f VS |
7080 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
7081 | return 200000; | |
7082 | } | |
7083 | ||
7084 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
7085 | { | |
7086 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
7087 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
7088 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
7089 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
7090 | const uint8_t *div_table; | |
7091 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7092 | uint16_t tmp = 0; | |
7093 | ||
7094 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7095 | ||
7096 | cdclk_sel = (tmp >> 4) & 0x7; | |
7097 | ||
7098 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7099 | goto fail; | |
7100 | ||
7101 | switch (vco) { | |
7102 | case 3200000: | |
7103 | div_table = div_3200; | |
7104 | break; | |
7105 | case 4000000: | |
7106 | div_table = div_4000; | |
7107 | break; | |
7108 | case 4800000: | |
7109 | div_table = div_4800; | |
7110 | break; | |
7111 | case 5333333: | |
7112 | div_table = div_5333; | |
7113 | break; | |
7114 | default: | |
7115 | goto fail; | |
7116 | } | |
7117 | ||
7118 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7119 | ||
caf4e252 | 7120 | fail: |
34edce2f VS |
7121 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7122 | return 190476; | |
7123 | } | |
7124 | ||
2c07245f | 7125 | static void |
a65851af | 7126 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7127 | { |
a65851af VS |
7128 | while (*num > DATA_LINK_M_N_MASK || |
7129 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7130 | *num >>= 1; |
7131 | *den >>= 1; | |
7132 | } | |
7133 | } | |
7134 | ||
a65851af VS |
7135 | static void compute_m_n(unsigned int m, unsigned int n, |
7136 | uint32_t *ret_m, uint32_t *ret_n) | |
7137 | { | |
7138 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7139 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7140 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7141 | } | |
7142 | ||
e69d0bc1 DV |
7143 | void |
7144 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7145 | int pixel_clock, int link_clock, | |
7146 | struct intel_link_m_n *m_n) | |
2c07245f | 7147 | { |
e69d0bc1 | 7148 | m_n->tu = 64; |
a65851af VS |
7149 | |
7150 | compute_m_n(bits_per_pixel * pixel_clock, | |
7151 | link_clock * nlanes * 8, | |
7152 | &m_n->gmch_m, &m_n->gmch_n); | |
7153 | ||
7154 | compute_m_n(pixel_clock, link_clock, | |
7155 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7156 | } |
7157 | ||
a7615030 CW |
7158 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7159 | { | |
d330a953 JN |
7160 | if (i915.panel_use_ssc >= 0) |
7161 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7162 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7163 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7164 | } |
7165 | ||
a93e255f ACO |
7166 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7167 | int num_connectors) | |
c65d77d8 | 7168 | { |
a93e255f | 7169 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7170 | struct drm_i915_private *dev_priv = dev->dev_private; |
7171 | int refclk; | |
7172 | ||
a93e255f ACO |
7173 | WARN_ON(!crtc_state->base.state); |
7174 | ||
5ab7b0b7 | 7175 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7176 | refclk = 100000; |
a93e255f | 7177 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7178 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7179 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7180 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7181 | } else if (!IS_GEN2(dev)) { |
7182 | refclk = 96000; | |
7183 | } else { | |
7184 | refclk = 48000; | |
7185 | } | |
7186 | ||
7187 | return refclk; | |
7188 | } | |
7189 | ||
7429e9d4 | 7190 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7191 | { |
7df00d7a | 7192 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7193 | } |
f47709a9 | 7194 | |
7429e9d4 DV |
7195 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7196 | { | |
7197 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7198 | } |
7199 | ||
f47709a9 | 7200 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7201 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7202 | intel_clock_t *reduced_clock) |
7203 | { | |
f47709a9 | 7204 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7205 | u32 fp, fp2 = 0; |
7206 | ||
7207 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7208 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7209 | if (reduced_clock) |
7429e9d4 | 7210 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7211 | } else { |
190f68c5 | 7212 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7213 | if (reduced_clock) |
7429e9d4 | 7214 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7215 | } |
7216 | ||
190f68c5 | 7217 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7218 | |
f47709a9 | 7219 | crtc->lowfreq_avail = false; |
a93e255f | 7220 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7221 | reduced_clock) { |
190f68c5 | 7222 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7223 | crtc->lowfreq_avail = true; |
a7516a05 | 7224 | } else { |
190f68c5 | 7225 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7226 | } |
7227 | } | |
7228 | ||
5e69f97f CML |
7229 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7230 | pipe) | |
89b667f8 JB |
7231 | { |
7232 | u32 reg_val; | |
7233 | ||
7234 | /* | |
7235 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7236 | * and set it to a reasonable value instead. | |
7237 | */ | |
ab3c759a | 7238 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7239 | reg_val &= 0xffffff00; |
7240 | reg_val |= 0x00000030; | |
ab3c759a | 7241 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7242 | |
ab3c759a | 7243 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7244 | reg_val &= 0x8cffffff; |
7245 | reg_val = 0x8c000000; | |
ab3c759a | 7246 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7247 | |
ab3c759a | 7248 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7249 | reg_val &= 0xffffff00; |
ab3c759a | 7250 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7251 | |
ab3c759a | 7252 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7253 | reg_val &= 0x00ffffff; |
7254 | reg_val |= 0xb0000000; | |
ab3c759a | 7255 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7256 | } |
7257 | ||
b551842d DV |
7258 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7259 | struct intel_link_m_n *m_n) | |
7260 | { | |
7261 | struct drm_device *dev = crtc->base.dev; | |
7262 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7263 | int pipe = crtc->pipe; | |
7264 | ||
e3b95f1e DV |
7265 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7266 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7267 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7268 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7269 | } |
7270 | ||
7271 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7272 | struct intel_link_m_n *m_n, |
7273 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7274 | { |
7275 | struct drm_device *dev = crtc->base.dev; | |
7276 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7277 | int pipe = crtc->pipe; | |
6e3c9717 | 7278 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7279 | |
7280 | if (INTEL_INFO(dev)->gen >= 5) { | |
7281 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7282 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7283 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7284 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7285 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7286 | * for gen < 8) and if DRRS is supported (to make sure the | |
7287 | * registers are not unnecessarily accessed). | |
7288 | */ | |
44395bfe | 7289 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7290 | crtc->config->has_drrs) { |
f769cd24 VK |
7291 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7292 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7293 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7294 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7295 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7296 | } | |
b551842d | 7297 | } else { |
e3b95f1e DV |
7298 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7299 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7300 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7301 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7302 | } |
7303 | } | |
7304 | ||
fe3cd48d | 7305 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7306 | { |
fe3cd48d R |
7307 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7308 | ||
7309 | if (m_n == M1_N1) { | |
7310 | dp_m_n = &crtc->config->dp_m_n; | |
7311 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7312 | } else if (m_n == M2_N2) { | |
7313 | ||
7314 | /* | |
7315 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7316 | * needs to be programmed into M1_N1. | |
7317 | */ | |
7318 | dp_m_n = &crtc->config->dp_m2_n2; | |
7319 | } else { | |
7320 | DRM_ERROR("Unsupported divider value\n"); | |
7321 | return; | |
7322 | } | |
7323 | ||
6e3c9717 ACO |
7324 | if (crtc->config->has_pch_encoder) |
7325 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7326 | else |
fe3cd48d | 7327 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7328 | } |
7329 | ||
251ac862 DV |
7330 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7331 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7332 | { |
7333 | u32 dpll, dpll_md; | |
7334 | ||
7335 | /* | |
7336 | * Enable DPIO clock input. We should never disable the reference | |
7337 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7338 | * on it. | |
7339 | */ | |
60bfe44f VS |
7340 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7341 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7342 | /* We should never disable this, set it here for state tracking */ |
7343 | if (crtc->pipe == PIPE_B) | |
7344 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7345 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7346 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7347 | |
d288f65f | 7348 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7349 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7350 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7351 | } |
7352 | ||
d288f65f | 7353 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7354 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7355 | { |
f47709a9 | 7356 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7357 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7358 | int pipe = crtc->pipe; |
bdd4b6a6 | 7359 | u32 mdiv; |
a0c4da24 | 7360 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7361 | u32 coreclk, reg_val; |
a0c4da24 | 7362 | |
a580516d | 7363 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7364 | |
d288f65f VS |
7365 | bestn = pipe_config->dpll.n; |
7366 | bestm1 = pipe_config->dpll.m1; | |
7367 | bestm2 = pipe_config->dpll.m2; | |
7368 | bestp1 = pipe_config->dpll.p1; | |
7369 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7370 | |
89b667f8 JB |
7371 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7372 | ||
7373 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7374 | if (pipe == PIPE_B) |
5e69f97f | 7375 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7376 | |
7377 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7378 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7379 | |
7380 | /* Disable target IRef on PLL */ | |
ab3c759a | 7381 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7382 | reg_val &= 0x00ffffff; |
ab3c759a | 7383 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7384 | |
7385 | /* Disable fast lock */ | |
ab3c759a | 7386 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7387 | |
7388 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7389 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7390 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7391 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7392 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7393 | |
7394 | /* | |
7395 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7396 | * but we don't support that). | |
7397 | * Note: don't use the DAC post divider as it seems unstable. | |
7398 | */ | |
7399 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7400 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7401 | |
a0c4da24 | 7402 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7403 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7404 | |
89b667f8 | 7405 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7406 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7407 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7408 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7409 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7410 | 0x009f0003); |
89b667f8 | 7411 | else |
ab3c759a | 7412 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7413 | 0x00d0000f); |
7414 | ||
681a8504 | 7415 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7416 | /* Use SSC source */ |
bdd4b6a6 | 7417 | if (pipe == PIPE_A) |
ab3c759a | 7418 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7419 | 0x0df40000); |
7420 | else | |
ab3c759a | 7421 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7422 | 0x0df70000); |
7423 | } else { /* HDMI or VGA */ | |
7424 | /* Use bend source */ | |
bdd4b6a6 | 7425 | if (pipe == PIPE_A) |
ab3c759a | 7426 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7427 | 0x0df70000); |
7428 | else | |
ab3c759a | 7429 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7430 | 0x0df40000); |
7431 | } | |
a0c4da24 | 7432 | |
ab3c759a | 7433 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7434 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7435 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7436 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7437 | coreclk |= 0x01000000; |
ab3c759a | 7438 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7439 | |
ab3c759a | 7440 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7441 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7442 | } |
7443 | ||
251ac862 DV |
7444 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7445 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7446 | { |
60bfe44f VS |
7447 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7448 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7449 | DPLL_VCO_ENABLE; |
7450 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7451 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7452 | |
d288f65f VS |
7453 | pipe_config->dpll_hw_state.dpll_md = |
7454 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7455 | } |
7456 | ||
d288f65f | 7457 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7458 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7459 | { |
7460 | struct drm_device *dev = crtc->base.dev; | |
7461 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7462 | int pipe = crtc->pipe; | |
f0f59a00 | 7463 | i915_reg_t dpll_reg = DPLL(crtc->pipe); |
9d556c99 | 7464 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9cbe40c1 | 7465 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7466 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7467 | u32 dpio_val; |
9cbe40c1 | 7468 | int vco; |
9d556c99 | 7469 | |
d288f65f VS |
7470 | bestn = pipe_config->dpll.n; |
7471 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7472 | bestm1 = pipe_config->dpll.m1; | |
7473 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7474 | bestp1 = pipe_config->dpll.p1; | |
7475 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7476 | vco = pipe_config->dpll.vco; |
a945ce7e | 7477 | dpio_val = 0; |
9cbe40c1 | 7478 | loopfilter = 0; |
9d556c99 CML |
7479 | |
7480 | /* | |
7481 | * Enable Refclk and SSC | |
7482 | */ | |
a11b0703 | 7483 | I915_WRITE(dpll_reg, |
d288f65f | 7484 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7485 | |
a580516d | 7486 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7487 | |
9d556c99 CML |
7488 | /* p1 and p2 divider */ |
7489 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7490 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7491 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7492 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7493 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7494 | ||
7495 | /* Feedback post-divider - m2 */ | |
7496 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7497 | ||
7498 | /* Feedback refclk divider - n and m1 */ | |
7499 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7500 | DPIO_CHV_M1_DIV_BY_2 | | |
7501 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7502 | ||
7503 | /* M2 fraction division */ | |
25a25dfc | 7504 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7505 | |
7506 | /* M2 fraction division enable */ | |
a945ce7e VP |
7507 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7508 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7509 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7510 | if (bestm2_frac) | |
7511 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7512 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7513 | |
de3a0fde VP |
7514 | /* Program digital lock detect threshold */ |
7515 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7516 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7517 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7518 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7519 | if (!bestm2_frac) | |
7520 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7521 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7522 | ||
9d556c99 | 7523 | /* Loop filter */ |
9cbe40c1 VP |
7524 | if (vco == 5400000) { |
7525 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7526 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7527 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7528 | tribuf_calcntr = 0x9; | |
7529 | } else if (vco <= 6200000) { | |
7530 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7531 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7532 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7533 | tribuf_calcntr = 0x9; | |
7534 | } else if (vco <= 6480000) { | |
7535 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7536 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7537 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7538 | tribuf_calcntr = 0x8; | |
7539 | } else { | |
7540 | /* Not supported. Apply the same limits as in the max case */ | |
7541 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7542 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7543 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7544 | tribuf_calcntr = 0; | |
7545 | } | |
9d556c99 CML |
7546 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7547 | ||
968040b2 | 7548 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7549 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7550 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7551 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7552 | ||
9d556c99 CML |
7553 | /* AFC Recal */ |
7554 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7555 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7556 | DPIO_AFC_RECAL); | |
7557 | ||
a580516d | 7558 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7559 | } |
7560 | ||
d288f65f VS |
7561 | /** |
7562 | * vlv_force_pll_on - forcibly enable just the PLL | |
7563 | * @dev_priv: i915 private structure | |
7564 | * @pipe: pipe PLL to enable | |
7565 | * @dpll: PLL configuration | |
7566 | * | |
7567 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7568 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7569 | * be enabled. | |
7570 | */ | |
7571 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7572 | const struct dpll *dpll) | |
7573 | { | |
7574 | struct intel_crtc *crtc = | |
7575 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7576 | struct intel_crtc_state pipe_config = { |
a93e255f | 7577 | .base.crtc = &crtc->base, |
d288f65f VS |
7578 | .pixel_multiplier = 1, |
7579 | .dpll = *dpll, | |
7580 | }; | |
7581 | ||
7582 | if (IS_CHERRYVIEW(dev)) { | |
251ac862 | 7583 | chv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7584 | chv_prepare_pll(crtc, &pipe_config); |
7585 | chv_enable_pll(crtc, &pipe_config); | |
7586 | } else { | |
251ac862 | 7587 | vlv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7588 | vlv_prepare_pll(crtc, &pipe_config); |
7589 | vlv_enable_pll(crtc, &pipe_config); | |
7590 | } | |
7591 | } | |
7592 | ||
7593 | /** | |
7594 | * vlv_force_pll_off - forcibly disable just the PLL | |
7595 | * @dev_priv: i915 private structure | |
7596 | * @pipe: pipe PLL to disable | |
7597 | * | |
7598 | * Disable the PLL for @pipe. To be used in cases where we need | |
7599 | * the PLL enabled even when @pipe is not going to be enabled. | |
7600 | */ | |
7601 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7602 | { | |
7603 | if (IS_CHERRYVIEW(dev)) | |
7604 | chv_disable_pll(to_i915(dev), pipe); | |
7605 | else | |
7606 | vlv_disable_pll(to_i915(dev), pipe); | |
7607 | } | |
7608 | ||
251ac862 DV |
7609 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7610 | struct intel_crtc_state *crtc_state, | |
7611 | intel_clock_t *reduced_clock, | |
7612 | int num_connectors) | |
eb1cbe48 | 7613 | { |
f47709a9 | 7614 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7615 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7616 | u32 dpll; |
7617 | bool is_sdvo; | |
190f68c5 | 7618 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7619 | |
190f68c5 | 7620 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7621 | |
a93e255f ACO |
7622 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7623 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7624 | |
7625 | dpll = DPLL_VGA_MODE_DIS; | |
7626 | ||
a93e255f | 7627 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7628 | dpll |= DPLLB_MODE_LVDS; |
7629 | else | |
7630 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7631 | |
ef1b460d | 7632 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7633 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7634 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7635 | } |
198a037f DV |
7636 | |
7637 | if (is_sdvo) | |
4a33e48d | 7638 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7639 | |
190f68c5 | 7640 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7641 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7642 | |
7643 | /* compute bitmask from p1 value */ | |
7644 | if (IS_PINEVIEW(dev)) | |
7645 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7646 | else { | |
7647 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7648 | if (IS_G4X(dev) && reduced_clock) | |
7649 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7650 | } | |
7651 | switch (clock->p2) { | |
7652 | case 5: | |
7653 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7654 | break; | |
7655 | case 7: | |
7656 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7657 | break; | |
7658 | case 10: | |
7659 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7660 | break; | |
7661 | case 14: | |
7662 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7663 | break; | |
7664 | } | |
7665 | if (INTEL_INFO(dev)->gen >= 4) | |
7666 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7667 | ||
190f68c5 | 7668 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7669 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7670 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7671 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7672 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7673 | else | |
7674 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7675 | ||
7676 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7677 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7678 | |
eb1cbe48 | 7679 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7680 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7681 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7682 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7683 | } |
7684 | } | |
7685 | ||
251ac862 DV |
7686 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7687 | struct intel_crtc_state *crtc_state, | |
7688 | intel_clock_t *reduced_clock, | |
7689 | int num_connectors) | |
eb1cbe48 | 7690 | { |
f47709a9 | 7691 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7692 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7693 | u32 dpll; |
190f68c5 | 7694 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7695 | |
190f68c5 | 7696 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7697 | |
eb1cbe48 DV |
7698 | dpll = DPLL_VGA_MODE_DIS; |
7699 | ||
a93e255f | 7700 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7701 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7702 | } else { | |
7703 | if (clock->p1 == 2) | |
7704 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7705 | else | |
7706 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7707 | if (clock->p2 == 4) | |
7708 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7709 | } | |
7710 | ||
a93e255f | 7711 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7712 | dpll |= DPLL_DVO_2X_MODE; |
7713 | ||
a93e255f | 7714 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7715 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7716 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7717 | else | |
7718 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7719 | ||
7720 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7721 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7722 | } |
7723 | ||
8a654f3b | 7724 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7725 | { |
7726 | struct drm_device *dev = intel_crtc->base.dev; | |
7727 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7728 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7729 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7730 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7731 | uint32_t crtc_vtotal, crtc_vblank_end; |
7732 | int vsyncshift = 0; | |
4d8a62ea DV |
7733 | |
7734 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7735 | * the hw state checker will get angry at the mismatch. */ | |
7736 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7737 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7738 | |
609aeaca | 7739 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7740 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7741 | crtc_vtotal -= 1; |
7742 | crtc_vblank_end -= 1; | |
609aeaca | 7743 | |
409ee761 | 7744 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7745 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7746 | else | |
7747 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7748 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7749 | if (vsyncshift < 0) |
7750 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7751 | } |
7752 | ||
7753 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7754 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7755 | |
fe2b8f9d | 7756 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7757 | (adjusted_mode->crtc_hdisplay - 1) | |
7758 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7759 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7760 | (adjusted_mode->crtc_hblank_start - 1) | |
7761 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7762 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7763 | (adjusted_mode->crtc_hsync_start - 1) | |
7764 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7765 | ||
fe2b8f9d | 7766 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7767 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7768 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7769 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7770 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7771 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7772 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7773 | (adjusted_mode->crtc_vsync_start - 1) | |
7774 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7775 | ||
b5e508d4 PZ |
7776 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7777 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7778 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7779 | * bits. */ | |
7780 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7781 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7782 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7783 | ||
b0e77b9c PZ |
7784 | /* pipesrc controls the size that is scaled from, which should |
7785 | * always be the user's requested size. | |
7786 | */ | |
7787 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7788 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7789 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7790 | } |
7791 | ||
1bd1bd80 | 7792 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7793 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7794 | { |
7795 | struct drm_device *dev = crtc->base.dev; | |
7796 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7797 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7798 | uint32_t tmp; | |
7799 | ||
7800 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7801 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7802 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7803 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7804 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7805 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7806 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7807 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7808 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7809 | |
7810 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7811 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7812 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7813 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7814 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7815 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7816 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7817 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7818 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7819 | |
7820 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7821 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7822 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7823 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7824 | } |
7825 | ||
7826 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7827 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7828 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7829 | ||
2d112de7 ACO |
7830 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7831 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7832 | } |
7833 | ||
f6a83288 | 7834 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7835 | struct intel_crtc_state *pipe_config) |
babea61d | 7836 | { |
2d112de7 ACO |
7837 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7838 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7839 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7840 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7841 | |
2d112de7 ACO |
7842 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7843 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7844 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7845 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7846 | |
2d112de7 | 7847 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7848 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7849 | |
2d112de7 ACO |
7850 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7851 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7852 | |
7853 | mode->hsync = drm_mode_hsync(mode); | |
7854 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7855 | drm_mode_set_name(mode); | |
babea61d JB |
7856 | } |
7857 | ||
84b046f3 DV |
7858 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7859 | { | |
7860 | struct drm_device *dev = intel_crtc->base.dev; | |
7861 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7862 | uint32_t pipeconf; | |
7863 | ||
9f11a9e4 | 7864 | pipeconf = 0; |
84b046f3 | 7865 | |
b6b5d049 VS |
7866 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7867 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7868 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7869 | |
6e3c9717 | 7870 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7871 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7872 | |
ff9ce46e DV |
7873 | /* only g4x and later have fancy bpc/dither controls */ |
7874 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7875 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7876 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7877 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7878 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7879 | |
6e3c9717 | 7880 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7881 | case 18: |
7882 | pipeconf |= PIPECONF_6BPC; | |
7883 | break; | |
7884 | case 24: | |
7885 | pipeconf |= PIPECONF_8BPC; | |
7886 | break; | |
7887 | case 30: | |
7888 | pipeconf |= PIPECONF_10BPC; | |
7889 | break; | |
7890 | default: | |
7891 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7892 | BUG(); | |
84b046f3 DV |
7893 | } |
7894 | } | |
7895 | ||
7896 | if (HAS_PIPE_CXSR(dev)) { | |
7897 | if (intel_crtc->lowfreq_avail) { | |
7898 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7899 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7900 | } else { | |
7901 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7902 | } |
7903 | } | |
7904 | ||
6e3c9717 | 7905 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7906 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7907 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7908 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7909 | else | |
7910 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7911 | } else | |
84b046f3 DV |
7912 | pipeconf |= PIPECONF_PROGRESSIVE; |
7913 | ||
6e3c9717 | 7914 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7915 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7916 | |
84b046f3 DV |
7917 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7918 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7919 | } | |
7920 | ||
190f68c5 ACO |
7921 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7922 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7923 | { |
c7653199 | 7924 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7925 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7926 | int refclk, num_connectors = 0; |
c329a4ec DV |
7927 | intel_clock_t clock; |
7928 | bool ok; | |
7929 | bool is_dsi = false; | |
5eddb70b | 7930 | struct intel_encoder *encoder; |
d4906093 | 7931 | const intel_limit_t *limit; |
55bb9992 | 7932 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7933 | struct drm_connector *connector; |
55bb9992 ACO |
7934 | struct drm_connector_state *connector_state; |
7935 | int i; | |
79e53945 | 7936 | |
dd3cd74a ACO |
7937 | memset(&crtc_state->dpll_hw_state, 0, |
7938 | sizeof(crtc_state->dpll_hw_state)); | |
7939 | ||
da3ced29 | 7940 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7941 | if (connector_state->crtc != &crtc->base) |
7942 | continue; | |
7943 | ||
7944 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7945 | ||
5eddb70b | 7946 | switch (encoder->type) { |
e9fd1c02 JN |
7947 | case INTEL_OUTPUT_DSI: |
7948 | is_dsi = true; | |
7949 | break; | |
6847d71b PZ |
7950 | default: |
7951 | break; | |
79e53945 | 7952 | } |
43565a06 | 7953 | |
c751ce4f | 7954 | num_connectors++; |
79e53945 JB |
7955 | } |
7956 | ||
f2335330 | 7957 | if (is_dsi) |
5b18e57c | 7958 | return 0; |
f2335330 | 7959 | |
190f68c5 | 7960 | if (!crtc_state->clock_set) { |
a93e255f | 7961 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7962 | |
e9fd1c02 JN |
7963 | /* |
7964 | * Returns a set of divisors for the desired target clock with | |
7965 | * the given refclk, or FALSE. The returned values represent | |
7966 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7967 | * 2) / p1 / p2. | |
7968 | */ | |
a93e255f ACO |
7969 | limit = intel_limit(crtc_state, refclk); |
7970 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7971 | crtc_state->port_clock, |
e9fd1c02 | 7972 | refclk, NULL, &clock); |
f2335330 | 7973 | if (!ok) { |
e9fd1c02 JN |
7974 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7975 | return -EINVAL; | |
7976 | } | |
79e53945 | 7977 | |
f2335330 | 7978 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
7979 | crtc_state->dpll.n = clock.n; |
7980 | crtc_state->dpll.m1 = clock.m1; | |
7981 | crtc_state->dpll.m2 = clock.m2; | |
7982 | crtc_state->dpll.p1 = clock.p1; | |
7983 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7984 | } |
7026d4ac | 7985 | |
e9fd1c02 | 7986 | if (IS_GEN2(dev)) { |
c329a4ec | 7987 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7988 | num_connectors); |
9d556c99 | 7989 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 7990 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7991 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 7992 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7993 | } else { |
c329a4ec | 7994 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7995 | num_connectors); |
e9fd1c02 | 7996 | } |
79e53945 | 7997 | |
c8f7a0db | 7998 | return 0; |
f564048e EA |
7999 | } |
8000 | ||
2fa2fe9a | 8001 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8002 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
8003 | { |
8004 | struct drm_device *dev = crtc->base.dev; | |
8005 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8006 | uint32_t tmp; | |
8007 | ||
dc9e7dec VS |
8008 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
8009 | return; | |
8010 | ||
2fa2fe9a | 8011 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
8012 | if (!(tmp & PFIT_ENABLE)) |
8013 | return; | |
2fa2fe9a | 8014 | |
06922821 | 8015 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
8016 | if (INTEL_INFO(dev)->gen < 4) { |
8017 | if (crtc->pipe != PIPE_B) | |
8018 | return; | |
2fa2fe9a DV |
8019 | } else { |
8020 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
8021 | return; | |
8022 | } | |
8023 | ||
06922821 | 8024 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
8025 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
8026 | if (INTEL_INFO(dev)->gen < 5) | |
8027 | pipe_config->gmch_pfit.lvds_border_bits = | |
8028 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
8029 | } | |
8030 | ||
acbec814 | 8031 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8032 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
8033 | { |
8034 | struct drm_device *dev = crtc->base.dev; | |
8035 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8036 | int pipe = pipe_config->cpu_transcoder; | |
8037 | intel_clock_t clock; | |
8038 | u32 mdiv; | |
662c6ecb | 8039 | int refclk = 100000; |
acbec814 | 8040 | |
f573de5a SK |
8041 | /* In case of MIPI DPLL will not even be used */ |
8042 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
8043 | return; | |
8044 | ||
a580516d | 8045 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 8046 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 8047 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
8048 | |
8049 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
8050 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
8051 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
8052 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
8053 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
8054 | ||
dccbea3b | 8055 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
8056 | } |
8057 | ||
5724dbd1 DL |
8058 | static void |
8059 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
8060 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
8061 | { |
8062 | struct drm_device *dev = crtc->base.dev; | |
8063 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8064 | u32 val, base, offset; | |
8065 | int pipe = crtc->pipe, plane = crtc->plane; | |
8066 | int fourcc, pixel_format; | |
6761dd31 | 8067 | unsigned int aligned_height; |
b113d5ee | 8068 | struct drm_framebuffer *fb; |
1b842c89 | 8069 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 8070 | |
42a7b088 DL |
8071 | val = I915_READ(DSPCNTR(plane)); |
8072 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8073 | return; | |
8074 | ||
d9806c9f | 8075 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8076 | if (!intel_fb) { |
1ad292b5 JB |
8077 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8078 | return; | |
8079 | } | |
8080 | ||
1b842c89 DL |
8081 | fb = &intel_fb->base; |
8082 | ||
18c5247e DV |
8083 | if (INTEL_INFO(dev)->gen >= 4) { |
8084 | if (val & DISPPLANE_TILED) { | |
49af449b | 8085 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8086 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8087 | } | |
8088 | } | |
1ad292b5 JB |
8089 | |
8090 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8091 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8092 | fb->pixel_format = fourcc; |
8093 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
8094 | |
8095 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 8096 | if (plane_config->tiling) |
1ad292b5 JB |
8097 | offset = I915_READ(DSPTILEOFF(plane)); |
8098 | else | |
8099 | offset = I915_READ(DSPLINOFF(plane)); | |
8100 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8101 | } else { | |
8102 | base = I915_READ(DSPADDR(plane)); | |
8103 | } | |
8104 | plane_config->base = base; | |
8105 | ||
8106 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8107 | fb->width = ((val >> 16) & 0xfff) + 1; |
8108 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8109 | |
8110 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8111 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8112 | |
b113d5ee | 8113 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8114 | fb->pixel_format, |
8115 | fb->modifier[0]); | |
1ad292b5 | 8116 | |
f37b5c2b | 8117 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8118 | |
2844a921 DL |
8119 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8120 | pipe_name(pipe), plane, fb->width, fb->height, | |
8121 | fb->bits_per_pixel, base, fb->pitches[0], | |
8122 | plane_config->size); | |
1ad292b5 | 8123 | |
2d14030b | 8124 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8125 | } |
8126 | ||
70b23a98 | 8127 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8128 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8129 | { |
8130 | struct drm_device *dev = crtc->base.dev; | |
8131 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8132 | int pipe = pipe_config->cpu_transcoder; | |
8133 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8134 | intel_clock_t clock; | |
0d7b6b11 | 8135 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8136 | int refclk = 100000; |
8137 | ||
a580516d | 8138 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8139 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8140 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8141 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8142 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8143 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8144 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8145 | |
8146 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8147 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8148 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8149 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8150 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8151 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8152 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8153 | ||
dccbea3b | 8154 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8155 | } |
8156 | ||
0e8ffe1b | 8157 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8158 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8159 | { |
8160 | struct drm_device *dev = crtc->base.dev; | |
8161 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8162 | uint32_t tmp; | |
8163 | ||
f458ebbc DV |
8164 | if (!intel_display_power_is_enabled(dev_priv, |
8165 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8166 | return false; |
8167 | ||
e143a21c | 8168 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8169 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8170 | |
0e8ffe1b DV |
8171 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8172 | if (!(tmp & PIPECONF_ENABLE)) | |
8173 | return false; | |
8174 | ||
42571aef VS |
8175 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8176 | switch (tmp & PIPECONF_BPC_MASK) { | |
8177 | case PIPECONF_6BPC: | |
8178 | pipe_config->pipe_bpp = 18; | |
8179 | break; | |
8180 | case PIPECONF_8BPC: | |
8181 | pipe_config->pipe_bpp = 24; | |
8182 | break; | |
8183 | case PIPECONF_10BPC: | |
8184 | pipe_config->pipe_bpp = 30; | |
8185 | break; | |
8186 | default: | |
8187 | break; | |
8188 | } | |
8189 | } | |
8190 | ||
b5a9fa09 DV |
8191 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8192 | pipe_config->limited_color_range = true; | |
8193 | ||
282740f7 VS |
8194 | if (INTEL_INFO(dev)->gen < 4) |
8195 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8196 | ||
1bd1bd80 DV |
8197 | intel_get_pipe_timings(crtc, pipe_config); |
8198 | ||
2fa2fe9a DV |
8199 | i9xx_get_pfit_config(crtc, pipe_config); |
8200 | ||
6c49f241 DV |
8201 | if (INTEL_INFO(dev)->gen >= 4) { |
8202 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8203 | pipe_config->pixel_multiplier = | |
8204 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8205 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8206 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8207 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8208 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8209 | pipe_config->pixel_multiplier = | |
8210 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8211 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8212 | } else { | |
8213 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8214 | * port and will be fixed up in the encoder->get_config | |
8215 | * function. */ | |
8216 | pipe_config->pixel_multiplier = 1; | |
8217 | } | |
8bcc2795 DV |
8218 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8219 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8220 | /* |
8221 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8222 | * on 830. Filter it out here so that we don't | |
8223 | * report errors due to that. | |
8224 | */ | |
8225 | if (IS_I830(dev)) | |
8226 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8227 | ||
8bcc2795 DV |
8228 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8229 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8230 | } else { |
8231 | /* Mask out read-only status bits. */ | |
8232 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8233 | DPLL_PORTC_READY_MASK | | |
8234 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8235 | } |
6c49f241 | 8236 | |
70b23a98 VS |
8237 | if (IS_CHERRYVIEW(dev)) |
8238 | chv_crtc_clock_get(crtc, pipe_config); | |
8239 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8240 | vlv_crtc_clock_get(crtc, pipe_config); |
8241 | else | |
8242 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8243 | |
0f64614d VS |
8244 | /* |
8245 | * Normally the dotclock is filled in by the encoder .get_config() | |
8246 | * but in case the pipe is enabled w/o any ports we need a sane | |
8247 | * default. | |
8248 | */ | |
8249 | pipe_config->base.adjusted_mode.crtc_clock = | |
8250 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8251 | ||
0e8ffe1b DV |
8252 | return true; |
8253 | } | |
8254 | ||
dde86e2d | 8255 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8256 | { |
8257 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8258 | struct intel_encoder *encoder; |
74cfd7ac | 8259 | u32 val, final; |
13d83a67 | 8260 | bool has_lvds = false; |
199e5d79 | 8261 | bool has_cpu_edp = false; |
199e5d79 | 8262 | bool has_panel = false; |
99eb6a01 KP |
8263 | bool has_ck505 = false; |
8264 | bool can_ssc = false; | |
13d83a67 JB |
8265 | |
8266 | /* We need to take the global config into account */ | |
b2784e15 | 8267 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8268 | switch (encoder->type) { |
8269 | case INTEL_OUTPUT_LVDS: | |
8270 | has_panel = true; | |
8271 | has_lvds = true; | |
8272 | break; | |
8273 | case INTEL_OUTPUT_EDP: | |
8274 | has_panel = true; | |
2de6905f | 8275 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8276 | has_cpu_edp = true; |
8277 | break; | |
6847d71b PZ |
8278 | default: |
8279 | break; | |
13d83a67 JB |
8280 | } |
8281 | } | |
8282 | ||
99eb6a01 | 8283 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8284 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8285 | can_ssc = has_ck505; |
8286 | } else { | |
8287 | has_ck505 = false; | |
8288 | can_ssc = true; | |
8289 | } | |
8290 | ||
2de6905f ID |
8291 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8292 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8293 | |
8294 | /* Ironlake: try to setup display ref clock before DPLL | |
8295 | * enabling. This is only under driver's control after | |
8296 | * PCH B stepping, previous chipset stepping should be | |
8297 | * ignoring this setting. | |
8298 | */ | |
74cfd7ac CW |
8299 | val = I915_READ(PCH_DREF_CONTROL); |
8300 | ||
8301 | /* As we must carefully and slowly disable/enable each source in turn, | |
8302 | * compute the final state we want first and check if we need to | |
8303 | * make any changes at all. | |
8304 | */ | |
8305 | final = val; | |
8306 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8307 | if (has_ck505) | |
8308 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8309 | else | |
8310 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8311 | ||
8312 | final &= ~DREF_SSC_SOURCE_MASK; | |
8313 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8314 | final &= ~DREF_SSC1_ENABLE; | |
8315 | ||
8316 | if (has_panel) { | |
8317 | final |= DREF_SSC_SOURCE_ENABLE; | |
8318 | ||
8319 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8320 | final |= DREF_SSC1_ENABLE; | |
8321 | ||
8322 | if (has_cpu_edp) { | |
8323 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8324 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8325 | else | |
8326 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8327 | } else | |
8328 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8329 | } else { | |
8330 | final |= DREF_SSC_SOURCE_DISABLE; | |
8331 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8332 | } | |
8333 | ||
8334 | if (final == val) | |
8335 | return; | |
8336 | ||
13d83a67 | 8337 | /* Always enable nonspread source */ |
74cfd7ac | 8338 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8339 | |
99eb6a01 | 8340 | if (has_ck505) |
74cfd7ac | 8341 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8342 | else |
74cfd7ac | 8343 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8344 | |
199e5d79 | 8345 | if (has_panel) { |
74cfd7ac CW |
8346 | val &= ~DREF_SSC_SOURCE_MASK; |
8347 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8348 | |
199e5d79 | 8349 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8350 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8351 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8352 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8353 | } else |
74cfd7ac | 8354 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8355 | |
8356 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8357 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8358 | POSTING_READ(PCH_DREF_CONTROL); |
8359 | udelay(200); | |
8360 | ||
74cfd7ac | 8361 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8362 | |
8363 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8364 | if (has_cpu_edp) { |
99eb6a01 | 8365 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8366 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8367 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8368 | } else |
74cfd7ac | 8369 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8370 | } else |
74cfd7ac | 8371 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8372 | |
74cfd7ac | 8373 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8374 | POSTING_READ(PCH_DREF_CONTROL); |
8375 | udelay(200); | |
8376 | } else { | |
8377 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8378 | ||
74cfd7ac | 8379 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8380 | |
8381 | /* Turn off CPU output */ | |
74cfd7ac | 8382 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8383 | |
74cfd7ac | 8384 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8385 | POSTING_READ(PCH_DREF_CONTROL); |
8386 | udelay(200); | |
8387 | ||
8388 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8389 | val &= ~DREF_SSC_SOURCE_MASK; |
8390 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8391 | |
8392 | /* Turn off SSC1 */ | |
74cfd7ac | 8393 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8394 | |
74cfd7ac | 8395 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8396 | POSTING_READ(PCH_DREF_CONTROL); |
8397 | udelay(200); | |
8398 | } | |
74cfd7ac CW |
8399 | |
8400 | BUG_ON(val != final); | |
13d83a67 JB |
8401 | } |
8402 | ||
f31f2d55 | 8403 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8404 | { |
f31f2d55 | 8405 | uint32_t tmp; |
dde86e2d | 8406 | |
0ff066a9 PZ |
8407 | tmp = I915_READ(SOUTH_CHICKEN2); |
8408 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8409 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8410 | |
0ff066a9 PZ |
8411 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8412 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8413 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8414 | |
0ff066a9 PZ |
8415 | tmp = I915_READ(SOUTH_CHICKEN2); |
8416 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8417 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8418 | |
0ff066a9 PZ |
8419 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8420 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8421 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8422 | } |
8423 | ||
8424 | /* WaMPhyProgramming:hsw */ | |
8425 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8426 | { | |
8427 | uint32_t tmp; | |
dde86e2d PZ |
8428 | |
8429 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8430 | tmp &= ~(0xFF << 24); | |
8431 | tmp |= (0x12 << 24); | |
8432 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8433 | ||
dde86e2d PZ |
8434 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8435 | tmp |= (1 << 11); | |
8436 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8437 | ||
8438 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8439 | tmp |= (1 << 11); | |
8440 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8441 | ||
dde86e2d PZ |
8442 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8443 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8444 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8445 | ||
8446 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8447 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8448 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8449 | ||
0ff066a9 PZ |
8450 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8451 | tmp &= ~(7 << 13); | |
8452 | tmp |= (5 << 13); | |
8453 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8454 | |
0ff066a9 PZ |
8455 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8456 | tmp &= ~(7 << 13); | |
8457 | tmp |= (5 << 13); | |
8458 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8459 | |
8460 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8461 | tmp &= ~0xFF; | |
8462 | tmp |= 0x1C; | |
8463 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8464 | ||
8465 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8466 | tmp &= ~0xFF; | |
8467 | tmp |= 0x1C; | |
8468 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8469 | ||
8470 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8471 | tmp &= ~(0xFF << 16); | |
8472 | tmp |= (0x1C << 16); | |
8473 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8474 | ||
8475 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8476 | tmp &= ~(0xFF << 16); | |
8477 | tmp |= (0x1C << 16); | |
8478 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8479 | ||
0ff066a9 PZ |
8480 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8481 | tmp |= (1 << 27); | |
8482 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8483 | |
0ff066a9 PZ |
8484 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8485 | tmp |= (1 << 27); | |
8486 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8487 | |
0ff066a9 PZ |
8488 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8489 | tmp &= ~(0xF << 28); | |
8490 | tmp |= (4 << 28); | |
8491 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8492 | |
0ff066a9 PZ |
8493 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8494 | tmp &= ~(0xF << 28); | |
8495 | tmp |= (4 << 28); | |
8496 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8497 | } |
8498 | ||
2fa86a1f PZ |
8499 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8500 | * Programming" based on the parameters passed: | |
8501 | * - Sequence to enable CLKOUT_DP | |
8502 | * - Sequence to enable CLKOUT_DP without spread | |
8503 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8504 | */ | |
8505 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8506 | bool with_fdi) | |
f31f2d55 PZ |
8507 | { |
8508 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8509 | uint32_t reg, tmp; |
8510 | ||
8511 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8512 | with_spread = true; | |
c2699524 | 8513 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8514 | with_fdi = false; |
f31f2d55 | 8515 | |
a580516d | 8516 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8517 | |
8518 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8519 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8520 | tmp |= SBI_SSCCTL_PATHALT; | |
8521 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8522 | ||
8523 | udelay(24); | |
8524 | ||
2fa86a1f PZ |
8525 | if (with_spread) { |
8526 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8527 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8528 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8529 | |
2fa86a1f PZ |
8530 | if (with_fdi) { |
8531 | lpt_reset_fdi_mphy(dev_priv); | |
8532 | lpt_program_fdi_mphy(dev_priv); | |
8533 | } | |
8534 | } | |
dde86e2d | 8535 | |
c2699524 | 8536 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8537 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8538 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8539 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8540 | |
a580516d | 8541 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8542 | } |
8543 | ||
47701c3b PZ |
8544 | /* Sequence to disable CLKOUT_DP */ |
8545 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8546 | { | |
8547 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8548 | uint32_t reg, tmp; | |
8549 | ||
a580516d | 8550 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8551 | |
c2699524 | 8552 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8553 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8554 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8555 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8556 | ||
8557 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8558 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8559 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8560 | tmp |= SBI_SSCCTL_PATHALT; | |
8561 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8562 | udelay(32); | |
8563 | } | |
8564 | tmp |= SBI_SSCCTL_DISABLE; | |
8565 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8566 | } | |
8567 | ||
a580516d | 8568 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8569 | } |
8570 | ||
bf8fa3d3 PZ |
8571 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8572 | { | |
bf8fa3d3 PZ |
8573 | struct intel_encoder *encoder; |
8574 | bool has_vga = false; | |
8575 | ||
b2784e15 | 8576 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8577 | switch (encoder->type) { |
8578 | case INTEL_OUTPUT_ANALOG: | |
8579 | has_vga = true; | |
8580 | break; | |
6847d71b PZ |
8581 | default: |
8582 | break; | |
bf8fa3d3 PZ |
8583 | } |
8584 | } | |
8585 | ||
47701c3b PZ |
8586 | if (has_vga) |
8587 | lpt_enable_clkout_dp(dev, true, true); | |
8588 | else | |
8589 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8590 | } |
8591 | ||
dde86e2d PZ |
8592 | /* |
8593 | * Initialize reference clocks when the driver loads | |
8594 | */ | |
8595 | void intel_init_pch_refclk(struct drm_device *dev) | |
8596 | { | |
8597 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8598 | ironlake_init_pch_refclk(dev); | |
8599 | else if (HAS_PCH_LPT(dev)) | |
8600 | lpt_init_pch_refclk(dev); | |
8601 | } | |
8602 | ||
55bb9992 | 8603 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8604 | { |
55bb9992 | 8605 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8606 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8607 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8608 | struct drm_connector *connector; |
55bb9992 | 8609 | struct drm_connector_state *connector_state; |
d9d444cb | 8610 | struct intel_encoder *encoder; |
55bb9992 | 8611 | int num_connectors = 0, i; |
d9d444cb JB |
8612 | bool is_lvds = false; |
8613 | ||
da3ced29 | 8614 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8615 | if (connector_state->crtc != crtc_state->base.crtc) |
8616 | continue; | |
8617 | ||
8618 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8619 | ||
d9d444cb JB |
8620 | switch (encoder->type) { |
8621 | case INTEL_OUTPUT_LVDS: | |
8622 | is_lvds = true; | |
8623 | break; | |
6847d71b PZ |
8624 | default: |
8625 | break; | |
d9d444cb JB |
8626 | } |
8627 | num_connectors++; | |
8628 | } | |
8629 | ||
8630 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8631 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8632 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8633 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8634 | } |
8635 | ||
8636 | return 120000; | |
8637 | } | |
8638 | ||
6ff93609 | 8639 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8640 | { |
c8203565 | 8641 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8642 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8643 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8644 | uint32_t val; |
8645 | ||
78114071 | 8646 | val = 0; |
c8203565 | 8647 | |
6e3c9717 | 8648 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8649 | case 18: |
dfd07d72 | 8650 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8651 | break; |
8652 | case 24: | |
dfd07d72 | 8653 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8654 | break; |
8655 | case 30: | |
dfd07d72 | 8656 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8657 | break; |
8658 | case 36: | |
dfd07d72 | 8659 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8660 | break; |
8661 | default: | |
cc769b62 PZ |
8662 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8663 | BUG(); | |
c8203565 PZ |
8664 | } |
8665 | ||
6e3c9717 | 8666 | if (intel_crtc->config->dither) |
c8203565 PZ |
8667 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8668 | ||
6e3c9717 | 8669 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8670 | val |= PIPECONF_INTERLACED_ILK; |
8671 | else | |
8672 | val |= PIPECONF_PROGRESSIVE; | |
8673 | ||
6e3c9717 | 8674 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8675 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8676 | |
c8203565 PZ |
8677 | I915_WRITE(PIPECONF(pipe), val); |
8678 | POSTING_READ(PIPECONF(pipe)); | |
8679 | } | |
8680 | ||
86d3efce VS |
8681 | /* |
8682 | * Set up the pipe CSC unit. | |
8683 | * | |
8684 | * Currently only full range RGB to limited range RGB conversion | |
8685 | * is supported, but eventually this should handle various | |
8686 | * RGB<->YCbCr scenarios as well. | |
8687 | */ | |
50f3b016 | 8688 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8689 | { |
8690 | struct drm_device *dev = crtc->dev; | |
8691 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8692 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8693 | int pipe = intel_crtc->pipe; | |
8694 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8695 | ||
8696 | /* | |
8697 | * TODO: Check what kind of values actually come out of the pipe | |
8698 | * with these coeff/postoff values and adjust to get the best | |
8699 | * accuracy. Perhaps we even need to take the bpc value into | |
8700 | * consideration. | |
8701 | */ | |
8702 | ||
6e3c9717 | 8703 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8704 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8705 | ||
8706 | /* | |
8707 | * GY/GU and RY/RU should be the other way around according | |
8708 | * to BSpec, but reality doesn't agree. Just set them up in | |
8709 | * a way that results in the correct picture. | |
8710 | */ | |
8711 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8712 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8713 | ||
8714 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8715 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8716 | ||
8717 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8718 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8719 | ||
8720 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8721 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8722 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8723 | ||
8724 | if (INTEL_INFO(dev)->gen > 6) { | |
8725 | uint16_t postoff = 0; | |
8726 | ||
6e3c9717 | 8727 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8728 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8729 | |
8730 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8731 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8732 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8733 | ||
8734 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8735 | } else { | |
8736 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8737 | ||
6e3c9717 | 8738 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8739 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8740 | ||
8741 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8742 | } | |
8743 | } | |
8744 | ||
6ff93609 | 8745 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8746 | { |
756f85cf PZ |
8747 | struct drm_device *dev = crtc->dev; |
8748 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8749 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8750 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8751 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8752 | uint32_t val; |
8753 | ||
3eff4faa | 8754 | val = 0; |
ee2b0b38 | 8755 | |
6e3c9717 | 8756 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8757 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8758 | ||
6e3c9717 | 8759 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8760 | val |= PIPECONF_INTERLACED_ILK; |
8761 | else | |
8762 | val |= PIPECONF_PROGRESSIVE; | |
8763 | ||
702e7a56 PZ |
8764 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8765 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8766 | |
8767 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8768 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8769 | |
3cdf122c | 8770 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8771 | val = 0; |
8772 | ||
6e3c9717 | 8773 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8774 | case 18: |
8775 | val |= PIPEMISC_DITHER_6_BPC; | |
8776 | break; | |
8777 | case 24: | |
8778 | val |= PIPEMISC_DITHER_8_BPC; | |
8779 | break; | |
8780 | case 30: | |
8781 | val |= PIPEMISC_DITHER_10_BPC; | |
8782 | break; | |
8783 | case 36: | |
8784 | val |= PIPEMISC_DITHER_12_BPC; | |
8785 | break; | |
8786 | default: | |
8787 | /* Case prevented by pipe_config_set_bpp. */ | |
8788 | BUG(); | |
8789 | } | |
8790 | ||
6e3c9717 | 8791 | if (intel_crtc->config->dither) |
756f85cf PZ |
8792 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8793 | ||
8794 | I915_WRITE(PIPEMISC(pipe), val); | |
8795 | } | |
ee2b0b38 PZ |
8796 | } |
8797 | ||
6591c6e4 | 8798 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8799 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8800 | intel_clock_t *clock, |
8801 | bool *has_reduced_clock, | |
8802 | intel_clock_t *reduced_clock) | |
8803 | { | |
8804 | struct drm_device *dev = crtc->dev; | |
8805 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8806 | int refclk; |
d4906093 | 8807 | const intel_limit_t *limit; |
c329a4ec | 8808 | bool ret; |
79e53945 | 8809 | |
55bb9992 | 8810 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8811 | |
d4906093 ML |
8812 | /* |
8813 | * Returns a set of divisors for the desired target clock with the given | |
8814 | * refclk, or FALSE. The returned values represent the clock equation: | |
8815 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8816 | */ | |
a93e255f ACO |
8817 | limit = intel_limit(crtc_state, refclk); |
8818 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8819 | crtc_state->port_clock, |
ee9300bb | 8820 | refclk, NULL, clock); |
6591c6e4 PZ |
8821 | if (!ret) |
8822 | return false; | |
cda4b7d3 | 8823 | |
6591c6e4 PZ |
8824 | return true; |
8825 | } | |
8826 | ||
d4b1931c PZ |
8827 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8828 | { | |
8829 | /* | |
8830 | * Account for spread spectrum to avoid | |
8831 | * oversubscribing the link. Max center spread | |
8832 | * is 2.5%; use 5% for safety's sake. | |
8833 | */ | |
8834 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8835 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8836 | } |
8837 | ||
7429e9d4 | 8838 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8839 | { |
7429e9d4 | 8840 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8841 | } |
8842 | ||
de13a2e3 | 8843 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8844 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8845 | u32 *fp, |
9a7c7890 | 8846 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8847 | { |
de13a2e3 | 8848 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8849 | struct drm_device *dev = crtc->dev; |
8850 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8851 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8852 | struct drm_connector *connector; |
55bb9992 ACO |
8853 | struct drm_connector_state *connector_state; |
8854 | struct intel_encoder *encoder; | |
de13a2e3 | 8855 | uint32_t dpll; |
55bb9992 | 8856 | int factor, num_connectors = 0, i; |
09ede541 | 8857 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8858 | |
da3ced29 | 8859 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8860 | if (connector_state->crtc != crtc_state->base.crtc) |
8861 | continue; | |
8862 | ||
8863 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8864 | ||
8865 | switch (encoder->type) { | |
79e53945 JB |
8866 | case INTEL_OUTPUT_LVDS: |
8867 | is_lvds = true; | |
8868 | break; | |
8869 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8870 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8871 | is_sdvo = true; |
79e53945 | 8872 | break; |
6847d71b PZ |
8873 | default: |
8874 | break; | |
79e53945 | 8875 | } |
43565a06 | 8876 | |
c751ce4f | 8877 | num_connectors++; |
79e53945 | 8878 | } |
79e53945 | 8879 | |
c1858123 | 8880 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8881 | factor = 21; |
8882 | if (is_lvds) { | |
8883 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8884 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8885 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8886 | factor = 25; |
190f68c5 | 8887 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8888 | factor = 20; |
c1858123 | 8889 | |
190f68c5 | 8890 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8891 | *fp |= FP_CB_TUNE; |
2c07245f | 8892 | |
9a7c7890 DV |
8893 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8894 | *fp2 |= FP_CB_TUNE; | |
8895 | ||
5eddb70b | 8896 | dpll = 0; |
2c07245f | 8897 | |
a07d6787 EA |
8898 | if (is_lvds) |
8899 | dpll |= DPLLB_MODE_LVDS; | |
8900 | else | |
8901 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8902 | |
190f68c5 | 8903 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8904 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8905 | |
8906 | if (is_sdvo) | |
4a33e48d | 8907 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8908 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8909 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8910 | |
a07d6787 | 8911 | /* compute bitmask from p1 value */ |
190f68c5 | 8912 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8913 | /* also FPA1 */ |
190f68c5 | 8914 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8915 | |
190f68c5 | 8916 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8917 | case 5: |
8918 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8919 | break; | |
8920 | case 7: | |
8921 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8922 | break; | |
8923 | case 10: | |
8924 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8925 | break; | |
8926 | case 14: | |
8927 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8928 | break; | |
79e53945 JB |
8929 | } |
8930 | ||
b4c09f3b | 8931 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8932 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8933 | else |
8934 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8935 | ||
959e16d6 | 8936 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8937 | } |
8938 | ||
190f68c5 ACO |
8939 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8940 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8941 | { |
c7653199 | 8942 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8943 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8944 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8945 | bool ok, has_reduced_clock = false; |
8b47047b | 8946 | bool is_lvds = false; |
e2b78267 | 8947 | struct intel_shared_dpll *pll; |
de13a2e3 | 8948 | |
dd3cd74a ACO |
8949 | memset(&crtc_state->dpll_hw_state, 0, |
8950 | sizeof(crtc_state->dpll_hw_state)); | |
8951 | ||
409ee761 | 8952 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8953 | |
5dc5298b PZ |
8954 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8955 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8956 | |
190f68c5 | 8957 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8958 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8959 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8960 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8961 | return -EINVAL; | |
79e53945 | 8962 | } |
f47709a9 | 8963 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8964 | if (!crtc_state->clock_set) { |
8965 | crtc_state->dpll.n = clock.n; | |
8966 | crtc_state->dpll.m1 = clock.m1; | |
8967 | crtc_state->dpll.m2 = clock.m2; | |
8968 | crtc_state->dpll.p1 = clock.p1; | |
8969 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8970 | } |
79e53945 | 8971 | |
5dc5298b | 8972 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8973 | if (crtc_state->has_pch_encoder) { |
8974 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8975 | if (has_reduced_clock) |
7429e9d4 | 8976 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8977 | |
190f68c5 | 8978 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8979 | &fp, &reduced_clock, |
8980 | has_reduced_clock ? &fp2 : NULL); | |
8981 | ||
190f68c5 ACO |
8982 | crtc_state->dpll_hw_state.dpll = dpll; |
8983 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8984 | if (has_reduced_clock) |
190f68c5 | 8985 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8986 | else |
190f68c5 | 8987 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8988 | |
190f68c5 | 8989 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8990 | if (pll == NULL) { |
84f44ce7 | 8991 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8992 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8993 | return -EINVAL; |
8994 | } | |
3fb37703 | 8995 | } |
79e53945 | 8996 | |
ab585dea | 8997 | if (is_lvds && has_reduced_clock) |
c7653199 | 8998 | crtc->lowfreq_avail = true; |
bcd644e0 | 8999 | else |
c7653199 | 9000 | crtc->lowfreq_avail = false; |
e2b78267 | 9001 | |
c8f7a0db | 9002 | return 0; |
79e53945 JB |
9003 | } |
9004 | ||
eb14cb74 VS |
9005 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
9006 | struct intel_link_m_n *m_n) | |
9007 | { | |
9008 | struct drm_device *dev = crtc->base.dev; | |
9009 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9010 | enum pipe pipe = crtc->pipe; | |
9011 | ||
9012 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
9013 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
9014 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9015 | & ~TU_SIZE_MASK; | |
9016 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
9017 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9018 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9019 | } | |
9020 | ||
9021 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
9022 | enum transcoder transcoder, | |
b95af8be VK |
9023 | struct intel_link_m_n *m_n, |
9024 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
9025 | { |
9026 | struct drm_device *dev = crtc->base.dev; | |
9027 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 9028 | enum pipe pipe = crtc->pipe; |
72419203 | 9029 | |
eb14cb74 VS |
9030 | if (INTEL_INFO(dev)->gen >= 5) { |
9031 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
9032 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
9033 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
9034 | & ~TU_SIZE_MASK; | |
9035 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
9036 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
9037 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
9038 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
9039 | * gen < 8) and if DRRS is supported (to make sure the | |
9040 | * registers are not unnecessarily read). | |
9041 | */ | |
9042 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 9043 | crtc->config->has_drrs) { |
b95af8be VK |
9044 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
9045 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
9046 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
9047 | & ~TU_SIZE_MASK; | |
9048 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
9049 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
9050 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9051 | } | |
eb14cb74 VS |
9052 | } else { |
9053 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
9054 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
9055 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9056 | & ~TU_SIZE_MASK; | |
9057 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
9058 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9059 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9060 | } | |
9061 | } | |
9062 | ||
9063 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 9064 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 9065 | { |
681a8504 | 9066 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
9067 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
9068 | else | |
9069 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
9070 | &pipe_config->dp_m_n, |
9071 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 9072 | } |
72419203 | 9073 | |
eb14cb74 | 9074 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 9075 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
9076 | { |
9077 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 9078 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
9079 | } |
9080 | ||
bd2e244f | 9081 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9082 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
9083 | { |
9084 | struct drm_device *dev = crtc->base.dev; | |
9085 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
9086 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
9087 | uint32_t ps_ctrl = 0; | |
9088 | int id = -1; | |
9089 | int i; | |
bd2e244f | 9090 | |
a1b2278e CK |
9091 | /* find scaler attached to this pipe */ |
9092 | for (i = 0; i < crtc->num_scalers; i++) { | |
9093 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9094 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9095 | id = i; | |
9096 | pipe_config->pch_pfit.enabled = true; | |
9097 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9098 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9099 | break; | |
9100 | } | |
9101 | } | |
bd2e244f | 9102 | |
a1b2278e CK |
9103 | scaler_state->scaler_id = id; |
9104 | if (id >= 0) { | |
9105 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9106 | } else { | |
9107 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9108 | } |
9109 | } | |
9110 | ||
5724dbd1 DL |
9111 | static void |
9112 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9113 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9114 | { |
9115 | struct drm_device *dev = crtc->base.dev; | |
9116 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9117 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9118 | int pipe = crtc->pipe; |
9119 | int fourcc, pixel_format; | |
6761dd31 | 9120 | unsigned int aligned_height; |
bc8d7dff | 9121 | struct drm_framebuffer *fb; |
1b842c89 | 9122 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9123 | |
d9806c9f | 9124 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9125 | if (!intel_fb) { |
bc8d7dff DL |
9126 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9127 | return; | |
9128 | } | |
9129 | ||
1b842c89 DL |
9130 | fb = &intel_fb->base; |
9131 | ||
bc8d7dff | 9132 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9133 | if (!(val & PLANE_CTL_ENABLE)) |
9134 | goto error; | |
9135 | ||
bc8d7dff DL |
9136 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9137 | fourcc = skl_format_to_fourcc(pixel_format, | |
9138 | val & PLANE_CTL_ORDER_RGBX, | |
9139 | val & PLANE_CTL_ALPHA_MASK); | |
9140 | fb->pixel_format = fourcc; | |
9141 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9142 | ||
40f46283 DL |
9143 | tiling = val & PLANE_CTL_TILED_MASK; |
9144 | switch (tiling) { | |
9145 | case PLANE_CTL_TILED_LINEAR: | |
9146 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9147 | break; | |
9148 | case PLANE_CTL_TILED_X: | |
9149 | plane_config->tiling = I915_TILING_X; | |
9150 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9151 | break; | |
9152 | case PLANE_CTL_TILED_Y: | |
9153 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9154 | break; | |
9155 | case PLANE_CTL_TILED_YF: | |
9156 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9157 | break; | |
9158 | default: | |
9159 | MISSING_CASE(tiling); | |
9160 | goto error; | |
9161 | } | |
9162 | ||
bc8d7dff DL |
9163 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9164 | plane_config->base = base; | |
9165 | ||
9166 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9167 | ||
9168 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9169 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9170 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9171 | ||
9172 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9173 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9174 | fb->pixel_format); | |
bc8d7dff DL |
9175 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9176 | ||
9177 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9178 | fb->pixel_format, |
9179 | fb->modifier[0]); | |
bc8d7dff | 9180 | |
f37b5c2b | 9181 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9182 | |
9183 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9184 | pipe_name(pipe), fb->width, fb->height, | |
9185 | fb->bits_per_pixel, base, fb->pitches[0], | |
9186 | plane_config->size); | |
9187 | ||
2d14030b | 9188 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9189 | return; |
9190 | ||
9191 | error: | |
9192 | kfree(fb); | |
9193 | } | |
9194 | ||
2fa2fe9a | 9195 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9196 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9197 | { |
9198 | struct drm_device *dev = crtc->base.dev; | |
9199 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9200 | uint32_t tmp; | |
9201 | ||
9202 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9203 | ||
9204 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9205 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9206 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9207 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9208 | |
9209 | /* We currently do not free assignements of panel fitters on | |
9210 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9211 | * differentiates them) so just WARN about this case for now. */ | |
9212 | if (IS_GEN7(dev)) { | |
9213 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9214 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9215 | } | |
2fa2fe9a | 9216 | } |
79e53945 JB |
9217 | } |
9218 | ||
5724dbd1 DL |
9219 | static void |
9220 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9221 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9222 | { |
9223 | struct drm_device *dev = crtc->base.dev; | |
9224 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9225 | u32 val, base, offset; | |
aeee5a49 | 9226 | int pipe = crtc->pipe; |
4c6baa59 | 9227 | int fourcc, pixel_format; |
6761dd31 | 9228 | unsigned int aligned_height; |
b113d5ee | 9229 | struct drm_framebuffer *fb; |
1b842c89 | 9230 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9231 | |
42a7b088 DL |
9232 | val = I915_READ(DSPCNTR(pipe)); |
9233 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9234 | return; | |
9235 | ||
d9806c9f | 9236 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9237 | if (!intel_fb) { |
4c6baa59 JB |
9238 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9239 | return; | |
9240 | } | |
9241 | ||
1b842c89 DL |
9242 | fb = &intel_fb->base; |
9243 | ||
18c5247e DV |
9244 | if (INTEL_INFO(dev)->gen >= 4) { |
9245 | if (val & DISPPLANE_TILED) { | |
49af449b | 9246 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9247 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9248 | } | |
9249 | } | |
4c6baa59 JB |
9250 | |
9251 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9252 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9253 | fb->pixel_format = fourcc; |
9254 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9255 | |
aeee5a49 | 9256 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9257 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9258 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9259 | } else { |
49af449b | 9260 | if (plane_config->tiling) |
aeee5a49 | 9261 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9262 | else |
aeee5a49 | 9263 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9264 | } |
9265 | plane_config->base = base; | |
9266 | ||
9267 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9268 | fb->width = ((val >> 16) & 0xfff) + 1; |
9269 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9270 | |
9271 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9272 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9273 | |
b113d5ee | 9274 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9275 | fb->pixel_format, |
9276 | fb->modifier[0]); | |
4c6baa59 | 9277 | |
f37b5c2b | 9278 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9279 | |
2844a921 DL |
9280 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9281 | pipe_name(pipe), fb->width, fb->height, | |
9282 | fb->bits_per_pixel, base, fb->pitches[0], | |
9283 | plane_config->size); | |
b113d5ee | 9284 | |
2d14030b | 9285 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9286 | } |
9287 | ||
0e8ffe1b | 9288 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9289 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9290 | { |
9291 | struct drm_device *dev = crtc->base.dev; | |
9292 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9293 | uint32_t tmp; | |
9294 | ||
f458ebbc DV |
9295 | if (!intel_display_power_is_enabled(dev_priv, |
9296 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9297 | return false; |
9298 | ||
e143a21c | 9299 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9300 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9301 | |
0e8ffe1b DV |
9302 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9303 | if (!(tmp & PIPECONF_ENABLE)) | |
9304 | return false; | |
9305 | ||
42571aef VS |
9306 | switch (tmp & PIPECONF_BPC_MASK) { |
9307 | case PIPECONF_6BPC: | |
9308 | pipe_config->pipe_bpp = 18; | |
9309 | break; | |
9310 | case PIPECONF_8BPC: | |
9311 | pipe_config->pipe_bpp = 24; | |
9312 | break; | |
9313 | case PIPECONF_10BPC: | |
9314 | pipe_config->pipe_bpp = 30; | |
9315 | break; | |
9316 | case PIPECONF_12BPC: | |
9317 | pipe_config->pipe_bpp = 36; | |
9318 | break; | |
9319 | default: | |
9320 | break; | |
9321 | } | |
9322 | ||
b5a9fa09 DV |
9323 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9324 | pipe_config->limited_color_range = true; | |
9325 | ||
ab9412ba | 9326 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9327 | struct intel_shared_dpll *pll; |
9328 | ||
88adfff1 DV |
9329 | pipe_config->has_pch_encoder = true; |
9330 | ||
627eb5a3 DV |
9331 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9332 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9333 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9334 | |
9335 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9336 | |
c0d43d62 | 9337 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9338 | pipe_config->shared_dpll = |
9339 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9340 | } else { |
9341 | tmp = I915_READ(PCH_DPLL_SEL); | |
9342 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9343 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9344 | else | |
9345 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9346 | } | |
66e985c0 DV |
9347 | |
9348 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9349 | ||
9350 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9351 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9352 | |
9353 | tmp = pipe_config->dpll_hw_state.dpll; | |
9354 | pipe_config->pixel_multiplier = | |
9355 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9356 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9357 | |
9358 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9359 | } else { |
9360 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9361 | } |
9362 | ||
1bd1bd80 DV |
9363 | intel_get_pipe_timings(crtc, pipe_config); |
9364 | ||
2fa2fe9a DV |
9365 | ironlake_get_pfit_config(crtc, pipe_config); |
9366 | ||
0e8ffe1b DV |
9367 | return true; |
9368 | } | |
9369 | ||
be256dc7 PZ |
9370 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9371 | { | |
9372 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9373 | struct intel_crtc *crtc; |
be256dc7 | 9374 | |
d3fcc808 | 9375 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9376 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9377 | pipe_name(crtc->pipe)); |
9378 | ||
e2c719b7 RC |
9379 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9380 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9381 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9382 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9383 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9384 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9385 | "CPU PWM1 enabled\n"); |
c5107b87 | 9386 | if (IS_HASWELL(dev)) |
e2c719b7 | 9387 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9388 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9389 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9390 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9391 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9392 | "Utility pin enabled\n"); |
e2c719b7 | 9393 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9394 | |
9926ada1 PZ |
9395 | /* |
9396 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9397 | * interrupts remain enabled. We used to check for that, but since it's | |
9398 | * gen-specific and since we only disable LCPLL after we fully disable | |
9399 | * the interrupts, the check below should be enough. | |
9400 | */ | |
e2c719b7 | 9401 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9402 | } |
9403 | ||
9ccd5aeb PZ |
9404 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9405 | { | |
9406 | struct drm_device *dev = dev_priv->dev; | |
9407 | ||
9408 | if (IS_HASWELL(dev)) | |
9409 | return I915_READ(D_COMP_HSW); | |
9410 | else | |
9411 | return I915_READ(D_COMP_BDW); | |
9412 | } | |
9413 | ||
3c4c9b81 PZ |
9414 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9415 | { | |
9416 | struct drm_device *dev = dev_priv->dev; | |
9417 | ||
9418 | if (IS_HASWELL(dev)) { | |
9419 | mutex_lock(&dev_priv->rps.hw_lock); | |
9420 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9421 | val)) | |
f475dadf | 9422 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9423 | mutex_unlock(&dev_priv->rps.hw_lock); |
9424 | } else { | |
9ccd5aeb PZ |
9425 | I915_WRITE(D_COMP_BDW, val); |
9426 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9427 | } |
be256dc7 PZ |
9428 | } |
9429 | ||
9430 | /* | |
9431 | * This function implements pieces of two sequences from BSpec: | |
9432 | * - Sequence for display software to disable LCPLL | |
9433 | * - Sequence for display software to allow package C8+ | |
9434 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9435 | * register. Callers should take care of disabling all the display engine | |
9436 | * functions, doing the mode unset, fixing interrupts, etc. | |
9437 | */ | |
6ff58d53 PZ |
9438 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9439 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9440 | { |
9441 | uint32_t val; | |
9442 | ||
9443 | assert_can_disable_lcpll(dev_priv); | |
9444 | ||
9445 | val = I915_READ(LCPLL_CTL); | |
9446 | ||
9447 | if (switch_to_fclk) { | |
9448 | val |= LCPLL_CD_SOURCE_FCLK; | |
9449 | I915_WRITE(LCPLL_CTL, val); | |
9450 | ||
9451 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9452 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9453 | DRM_ERROR("Switching to FCLK failed\n"); | |
9454 | ||
9455 | val = I915_READ(LCPLL_CTL); | |
9456 | } | |
9457 | ||
9458 | val |= LCPLL_PLL_DISABLE; | |
9459 | I915_WRITE(LCPLL_CTL, val); | |
9460 | POSTING_READ(LCPLL_CTL); | |
9461 | ||
9462 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9463 | DRM_ERROR("LCPLL still locked\n"); | |
9464 | ||
9ccd5aeb | 9465 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9466 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9467 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9468 | ndelay(100); |
9469 | ||
9ccd5aeb PZ |
9470 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9471 | 1)) | |
be256dc7 PZ |
9472 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9473 | ||
9474 | if (allow_power_down) { | |
9475 | val = I915_READ(LCPLL_CTL); | |
9476 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9477 | I915_WRITE(LCPLL_CTL, val); | |
9478 | POSTING_READ(LCPLL_CTL); | |
9479 | } | |
9480 | } | |
9481 | ||
9482 | /* | |
9483 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9484 | * source. | |
9485 | */ | |
6ff58d53 | 9486 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9487 | { |
9488 | uint32_t val; | |
9489 | ||
9490 | val = I915_READ(LCPLL_CTL); | |
9491 | ||
9492 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9493 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9494 | return; | |
9495 | ||
a8a8bd54 PZ |
9496 | /* |
9497 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9498 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9499 | */ |
59bad947 | 9500 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9501 | |
be256dc7 PZ |
9502 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9503 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9504 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9505 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9506 | } |
9507 | ||
9ccd5aeb | 9508 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9509 | val |= D_COMP_COMP_FORCE; |
9510 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9511 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9512 | |
9513 | val = I915_READ(LCPLL_CTL); | |
9514 | val &= ~LCPLL_PLL_DISABLE; | |
9515 | I915_WRITE(LCPLL_CTL, val); | |
9516 | ||
9517 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9518 | DRM_ERROR("LCPLL not locked yet\n"); | |
9519 | ||
9520 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9521 | val = I915_READ(LCPLL_CTL); | |
9522 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9523 | I915_WRITE(LCPLL_CTL, val); | |
9524 | ||
9525 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9526 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9527 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9528 | } | |
215733fa | 9529 | |
59bad947 | 9530 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9531 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9532 | } |
9533 | ||
765dab67 PZ |
9534 | /* |
9535 | * Package states C8 and deeper are really deep PC states that can only be | |
9536 | * reached when all the devices on the system allow it, so even if the graphics | |
9537 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9538 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9539 | * | |
9540 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9541 | * well is disabled and most interrupts are disabled, and these are also | |
9542 | * requirements for runtime PM. When these conditions are met, we manually do | |
9543 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9544 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9545 | * hang the machine. | |
9546 | * | |
9547 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9548 | * the state of some registers, so when we come back from PC8+ we need to | |
9549 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9550 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9551 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9552 | * because of the runtime PM support). | |
9553 | * | |
9554 | * For more, read "Display Sequences for Package C8" on the hardware | |
9555 | * documentation. | |
9556 | */ | |
a14cb6fc | 9557 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9558 | { |
c67a470b PZ |
9559 | struct drm_device *dev = dev_priv->dev; |
9560 | uint32_t val; | |
9561 | ||
c67a470b PZ |
9562 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9563 | ||
c2699524 | 9564 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9565 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9566 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9567 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9568 | } | |
9569 | ||
9570 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9571 | hsw_disable_lcpll(dev_priv, true, true); |
9572 | } | |
9573 | ||
a14cb6fc | 9574 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9575 | { |
9576 | struct drm_device *dev = dev_priv->dev; | |
9577 | uint32_t val; | |
9578 | ||
c67a470b PZ |
9579 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9580 | ||
9581 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9582 | lpt_init_pch_refclk(dev); |
9583 | ||
c2699524 | 9584 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9585 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9586 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9587 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9588 | } | |
9589 | ||
9590 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9591 | } |
9592 | ||
27c329ed | 9593 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9594 | { |
a821fc46 | 9595 | struct drm_device *dev = old_state->dev; |
27c329ed | 9596 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
f8437dd1 | 9597 | |
27c329ed | 9598 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9599 | } |
9600 | ||
b432e5cf | 9601 | /* compute the max rate for new configuration */ |
27c329ed | 9602 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9603 | { |
b432e5cf | 9604 | struct intel_crtc *intel_crtc; |
27c329ed | 9605 | struct intel_crtc_state *crtc_state; |
b432e5cf | 9606 | int max_pixel_rate = 0; |
b432e5cf | 9607 | |
27c329ed ML |
9608 | for_each_intel_crtc(state->dev, intel_crtc) { |
9609 | int pixel_rate; | |
9610 | ||
9611 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
9612 | if (IS_ERR(crtc_state)) | |
9613 | return PTR_ERR(crtc_state); | |
9614 | ||
9615 | if (!crtc_state->base.enable) | |
b432e5cf VS |
9616 | continue; |
9617 | ||
27c329ed | 9618 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9619 | |
9620 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
27c329ed | 9621 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
b432e5cf VS |
9622 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9623 | ||
9624 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9625 | } | |
9626 | ||
9627 | return max_pixel_rate; | |
9628 | } | |
9629 | ||
9630 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9631 | { | |
9632 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9633 | uint32_t val, data; | |
9634 | int ret; | |
9635 | ||
9636 | if (WARN((I915_READ(LCPLL_CTL) & | |
9637 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9638 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9639 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9640 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9641 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9642 | return; | |
9643 | ||
9644 | mutex_lock(&dev_priv->rps.hw_lock); | |
9645 | ret = sandybridge_pcode_write(dev_priv, | |
9646 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9647 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9648 | if (ret) { | |
9649 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9650 | return; | |
9651 | } | |
9652 | ||
9653 | val = I915_READ(LCPLL_CTL); | |
9654 | val |= LCPLL_CD_SOURCE_FCLK; | |
9655 | I915_WRITE(LCPLL_CTL, val); | |
9656 | ||
9657 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9658 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9659 | DRM_ERROR("Switching to FCLK failed\n"); | |
9660 | ||
9661 | val = I915_READ(LCPLL_CTL); | |
9662 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9663 | ||
9664 | switch (cdclk) { | |
9665 | case 450000: | |
9666 | val |= LCPLL_CLK_FREQ_450; | |
9667 | data = 0; | |
9668 | break; | |
9669 | case 540000: | |
9670 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9671 | data = 1; | |
9672 | break; | |
9673 | case 337500: | |
9674 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9675 | data = 2; | |
9676 | break; | |
9677 | case 675000: | |
9678 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9679 | data = 3; | |
9680 | break; | |
9681 | default: | |
9682 | WARN(1, "invalid cdclk frequency\n"); | |
9683 | return; | |
9684 | } | |
9685 | ||
9686 | I915_WRITE(LCPLL_CTL, val); | |
9687 | ||
9688 | val = I915_READ(LCPLL_CTL); | |
9689 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9690 | I915_WRITE(LCPLL_CTL, val); | |
9691 | ||
9692 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9693 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9694 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9695 | ||
9696 | mutex_lock(&dev_priv->rps.hw_lock); | |
9697 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9698 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9699 | ||
9700 | intel_update_cdclk(dev); | |
9701 | ||
9702 | WARN(cdclk != dev_priv->cdclk_freq, | |
9703 | "cdclk requested %d kHz but got %d kHz\n", | |
9704 | cdclk, dev_priv->cdclk_freq); | |
9705 | } | |
9706 | ||
27c329ed | 9707 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9708 | { |
27c329ed ML |
9709 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
9710 | int max_pixclk = ilk_max_pixel_rate(state); | |
b432e5cf VS |
9711 | int cdclk; |
9712 | ||
9713 | /* | |
9714 | * FIXME should also account for plane ratio | |
9715 | * once 64bpp pixel formats are supported. | |
9716 | */ | |
27c329ed | 9717 | if (max_pixclk > 540000) |
b432e5cf | 9718 | cdclk = 675000; |
27c329ed | 9719 | else if (max_pixclk > 450000) |
b432e5cf | 9720 | cdclk = 540000; |
27c329ed | 9721 | else if (max_pixclk > 337500) |
b432e5cf VS |
9722 | cdclk = 450000; |
9723 | else | |
9724 | cdclk = 337500; | |
9725 | ||
9726 | /* | |
9727 | * FIXME move the cdclk caclulation to | |
9728 | * compute_config() so we can fail gracegully. | |
9729 | */ | |
9730 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9731 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9732 | cdclk, dev_priv->max_cdclk_freq); | |
9733 | cdclk = dev_priv->max_cdclk_freq; | |
9734 | } | |
9735 | ||
27c329ed | 9736 | to_intel_atomic_state(state)->cdclk = cdclk; |
b432e5cf VS |
9737 | |
9738 | return 0; | |
9739 | } | |
9740 | ||
27c329ed | 9741 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9742 | { |
27c329ed ML |
9743 | struct drm_device *dev = old_state->dev; |
9744 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; | |
b432e5cf | 9745 | |
27c329ed | 9746 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9747 | } |
9748 | ||
190f68c5 ACO |
9749 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9750 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9751 | { |
190f68c5 | 9752 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9753 | return -EINVAL; |
716c2e55 | 9754 | |
c7653199 | 9755 | crtc->lowfreq_avail = false; |
644cef34 | 9756 | |
c8f7a0db | 9757 | return 0; |
79e53945 JB |
9758 | } |
9759 | ||
3760b59c S |
9760 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9761 | enum port port, | |
9762 | struct intel_crtc_state *pipe_config) | |
9763 | { | |
9764 | switch (port) { | |
9765 | case PORT_A: | |
9766 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9767 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9768 | break; | |
9769 | case PORT_B: | |
9770 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9771 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9772 | break; | |
9773 | case PORT_C: | |
9774 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9775 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9776 | break; | |
9777 | default: | |
9778 | DRM_ERROR("Incorrect port type\n"); | |
9779 | } | |
9780 | } | |
9781 | ||
96b7dfb7 S |
9782 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9783 | enum port port, | |
5cec258b | 9784 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9785 | { |
3148ade7 | 9786 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9787 | |
9788 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9789 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9790 | ||
9791 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9792 | case SKL_DPLL0: |
9793 | /* | |
9794 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9795 | * of the shared DPLL framework and thus needs to be read out | |
9796 | * separately | |
9797 | */ | |
9798 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9799 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9800 | break; | |
96b7dfb7 S |
9801 | case SKL_DPLL1: |
9802 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9803 | break; | |
9804 | case SKL_DPLL2: | |
9805 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9806 | break; | |
9807 | case SKL_DPLL3: | |
9808 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9809 | break; | |
96b7dfb7 S |
9810 | } |
9811 | } | |
9812 | ||
7d2c8175 DL |
9813 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9814 | enum port port, | |
5cec258b | 9815 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9816 | { |
9817 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9818 | ||
9819 | switch (pipe_config->ddi_pll_sel) { | |
9820 | case PORT_CLK_SEL_WRPLL1: | |
9821 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9822 | break; | |
9823 | case PORT_CLK_SEL_WRPLL2: | |
9824 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9825 | break; | |
00490c22 ML |
9826 | case PORT_CLK_SEL_SPLL: |
9827 | pipe_config->shared_dpll = DPLL_ID_SPLL; | |
7d2c8175 DL |
9828 | } |
9829 | } | |
9830 | ||
26804afd | 9831 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9832 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9833 | { |
9834 | struct drm_device *dev = crtc->base.dev; | |
9835 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9836 | struct intel_shared_dpll *pll; |
26804afd DV |
9837 | enum port port; |
9838 | uint32_t tmp; | |
9839 | ||
9840 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9841 | ||
9842 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9843 | ||
ef11bdb3 | 9844 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 9845 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
9846 | else if (IS_BROXTON(dev)) |
9847 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9848 | else |
9849 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9850 | |
d452c5b6 DV |
9851 | if (pipe_config->shared_dpll >= 0) { |
9852 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9853 | ||
9854 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9855 | &pipe_config->dpll_hw_state)); | |
9856 | } | |
9857 | ||
26804afd DV |
9858 | /* |
9859 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9860 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9861 | * the PCH transcoder is on. | |
9862 | */ | |
ca370455 DL |
9863 | if (INTEL_INFO(dev)->gen < 9 && |
9864 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9865 | pipe_config->has_pch_encoder = true; |
9866 | ||
9867 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9868 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9869 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9870 | ||
9871 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9872 | } | |
9873 | } | |
9874 | ||
0e8ffe1b | 9875 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9876 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9877 | { |
9878 | struct drm_device *dev = crtc->base.dev; | |
9879 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9880 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9881 | uint32_t tmp; |
9882 | ||
f458ebbc | 9883 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9884 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9885 | return false; | |
9886 | ||
e143a21c | 9887 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9888 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9889 | ||
eccb140b DV |
9890 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9891 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9892 | enum pipe trans_edp_pipe; | |
9893 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9894 | default: | |
9895 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9896 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9897 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9898 | trans_edp_pipe = PIPE_A; | |
9899 | break; | |
9900 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9901 | trans_edp_pipe = PIPE_B; | |
9902 | break; | |
9903 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9904 | trans_edp_pipe = PIPE_C; | |
9905 | break; | |
9906 | } | |
9907 | ||
9908 | if (trans_edp_pipe == crtc->pipe) | |
9909 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9910 | } | |
9911 | ||
f458ebbc | 9912 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9913 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9914 | return false; |
9915 | ||
eccb140b | 9916 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9917 | if (!(tmp & PIPECONF_ENABLE)) |
9918 | return false; | |
9919 | ||
26804afd | 9920 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9921 | |
1bd1bd80 DV |
9922 | intel_get_pipe_timings(crtc, pipe_config); |
9923 | ||
a1b2278e CK |
9924 | if (INTEL_INFO(dev)->gen >= 9) { |
9925 | skl_init_scalers(dev, crtc, pipe_config); | |
9926 | } | |
9927 | ||
2fa2fe9a | 9928 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9929 | |
9930 | if (INTEL_INFO(dev)->gen >= 9) { | |
9931 | pipe_config->scaler_state.scaler_id = -1; | |
9932 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9933 | } | |
9934 | ||
bd2e244f | 9935 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
1c132b44 | 9936 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 9937 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9938 | else |
1c132b44 | 9939 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 9940 | } |
88adfff1 | 9941 | |
e59150dc JB |
9942 | if (IS_HASWELL(dev)) |
9943 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9944 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9945 | |
ebb69c95 CT |
9946 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9947 | pipe_config->pixel_multiplier = | |
9948 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9949 | } else { | |
9950 | pipe_config->pixel_multiplier = 1; | |
9951 | } | |
6c49f241 | 9952 | |
0e8ffe1b DV |
9953 | return true; |
9954 | } | |
9955 | ||
560b85bb CW |
9956 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9957 | { | |
9958 | struct drm_device *dev = crtc->dev; | |
9959 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9960 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9961 | uint32_t cntl = 0, size = 0; |
560b85bb | 9962 | |
dc41c154 | 9963 | if (base) { |
3dd512fb MR |
9964 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9965 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9966 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9967 | ||
9968 | switch (stride) { | |
9969 | default: | |
9970 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9971 | width, stride); | |
9972 | stride = 256; | |
9973 | /* fallthrough */ | |
9974 | case 256: | |
9975 | case 512: | |
9976 | case 1024: | |
9977 | case 2048: | |
9978 | break; | |
4b0e333e CW |
9979 | } |
9980 | ||
dc41c154 VS |
9981 | cntl |= CURSOR_ENABLE | |
9982 | CURSOR_GAMMA_ENABLE | | |
9983 | CURSOR_FORMAT_ARGB | | |
9984 | CURSOR_STRIDE(stride); | |
9985 | ||
9986 | size = (height << 12) | width; | |
4b0e333e | 9987 | } |
560b85bb | 9988 | |
dc41c154 VS |
9989 | if (intel_crtc->cursor_cntl != 0 && |
9990 | (intel_crtc->cursor_base != base || | |
9991 | intel_crtc->cursor_size != size || | |
9992 | intel_crtc->cursor_cntl != cntl)) { | |
9993 | /* On these chipsets we can only modify the base/size/stride | |
9994 | * whilst the cursor is disabled. | |
9995 | */ | |
0b87c24e VS |
9996 | I915_WRITE(CURCNTR(PIPE_A), 0); |
9997 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 9998 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9999 | } |
560b85bb | 10000 | |
99d1f387 | 10001 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 10002 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
10003 | intel_crtc->cursor_base = base; |
10004 | } | |
4726e0b0 | 10005 | |
dc41c154 VS |
10006 | if (intel_crtc->cursor_size != size) { |
10007 | I915_WRITE(CURSIZE, size); | |
10008 | intel_crtc->cursor_size = size; | |
4b0e333e | 10009 | } |
560b85bb | 10010 | |
4b0e333e | 10011 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
10012 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
10013 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 10014 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 10015 | } |
560b85bb CW |
10016 | } |
10017 | ||
560b85bb | 10018 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
10019 | { |
10020 | struct drm_device *dev = crtc->dev; | |
10021 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10022 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10023 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
10024 | uint32_t cntl; |
10025 | ||
10026 | cntl = 0; | |
10027 | if (base) { | |
10028 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 10029 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
10030 | case 64: |
10031 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
10032 | break; | |
10033 | case 128: | |
10034 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
10035 | break; | |
10036 | case 256: | |
10037 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10038 | break; | |
10039 | default: | |
3dd512fb | 10040 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 10041 | return; |
65a21cd6 | 10042 | } |
4b0e333e | 10043 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 10044 | |
fc6f93bc | 10045 | if (HAS_DDI(dev)) |
47bf17a7 | 10046 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
4b0e333e | 10047 | } |
65a21cd6 | 10048 | |
8e7d688b | 10049 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
10050 | cntl |= CURSOR_ROTATE_180; |
10051 | ||
4b0e333e CW |
10052 | if (intel_crtc->cursor_cntl != cntl) { |
10053 | I915_WRITE(CURCNTR(pipe), cntl); | |
10054 | POSTING_READ(CURCNTR(pipe)); | |
10055 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 10056 | } |
4b0e333e | 10057 | |
65a21cd6 | 10058 | /* and commit changes on next vblank */ |
5efb3e28 VS |
10059 | I915_WRITE(CURBASE(pipe), base); |
10060 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
10061 | |
10062 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
10063 | } |
10064 | ||
cda4b7d3 | 10065 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
10066 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
10067 | bool on) | |
cda4b7d3 CW |
10068 | { |
10069 | struct drm_device *dev = crtc->dev; | |
10070 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10071 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10072 | int pipe = intel_crtc->pipe; | |
9b4101be ML |
10073 | struct drm_plane_state *cursor_state = crtc->cursor->state; |
10074 | int x = cursor_state->crtc_x; | |
10075 | int y = cursor_state->crtc_y; | |
d6e4db15 | 10076 | u32 base = 0, pos = 0; |
cda4b7d3 | 10077 | |
d6e4db15 | 10078 | if (on) |
cda4b7d3 | 10079 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 10080 | |
6e3c9717 | 10081 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
10082 | base = 0; |
10083 | ||
6e3c9717 | 10084 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
10085 | base = 0; |
10086 | ||
10087 | if (x < 0) { | |
9b4101be | 10088 | if (x + cursor_state->crtc_w <= 0) |
cda4b7d3 CW |
10089 | base = 0; |
10090 | ||
10091 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10092 | x = -x; | |
10093 | } | |
10094 | pos |= x << CURSOR_X_SHIFT; | |
10095 | ||
10096 | if (y < 0) { | |
9b4101be | 10097 | if (y + cursor_state->crtc_h <= 0) |
cda4b7d3 CW |
10098 | base = 0; |
10099 | ||
10100 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10101 | y = -y; | |
10102 | } | |
10103 | pos |= y << CURSOR_Y_SHIFT; | |
10104 | ||
4b0e333e | 10105 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
10106 | return; |
10107 | ||
5efb3e28 VS |
10108 | I915_WRITE(CURPOS(pipe), pos); |
10109 | ||
4398ad45 VS |
10110 | /* ILK+ do this automagically */ |
10111 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 10112 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
9b4101be ML |
10113 | base += (cursor_state->crtc_h * |
10114 | cursor_state->crtc_w - 1) * 4; | |
4398ad45 VS |
10115 | } |
10116 | ||
8ac54669 | 10117 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10118 | i845_update_cursor(crtc, base); |
10119 | else | |
10120 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10121 | } |
10122 | ||
dc41c154 VS |
10123 | static bool cursor_size_ok(struct drm_device *dev, |
10124 | uint32_t width, uint32_t height) | |
10125 | { | |
10126 | if (width == 0 || height == 0) | |
10127 | return false; | |
10128 | ||
10129 | /* | |
10130 | * 845g/865g are special in that they are only limited by | |
10131 | * the width of their cursors, the height is arbitrary up to | |
10132 | * the precision of the register. Everything else requires | |
10133 | * square cursors, limited to a few power-of-two sizes. | |
10134 | */ | |
10135 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10136 | if ((width & 63) != 0) | |
10137 | return false; | |
10138 | ||
10139 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10140 | return false; | |
10141 | ||
10142 | if (height > 1023) | |
10143 | return false; | |
10144 | } else { | |
10145 | switch (width | height) { | |
10146 | case 256: | |
10147 | case 128: | |
10148 | if (IS_GEN2(dev)) | |
10149 | return false; | |
10150 | case 64: | |
10151 | break; | |
10152 | default: | |
10153 | return false; | |
10154 | } | |
10155 | } | |
10156 | ||
10157 | return true; | |
10158 | } | |
10159 | ||
79e53945 | 10160 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10161 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10162 | { |
7203425a | 10163 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10164 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10165 | |
7203425a | 10166 | for (i = start; i < end; i++) { |
79e53945 JB |
10167 | intel_crtc->lut_r[i] = red[i] >> 8; |
10168 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10169 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10170 | } | |
10171 | ||
10172 | intel_crtc_load_lut(crtc); | |
10173 | } | |
10174 | ||
79e53945 JB |
10175 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10176 | static struct drm_display_mode load_detect_mode = { | |
10177 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10178 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10179 | }; | |
10180 | ||
a8bb6818 DV |
10181 | struct drm_framebuffer * |
10182 | __intel_framebuffer_create(struct drm_device *dev, | |
10183 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10184 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10185 | { |
10186 | struct intel_framebuffer *intel_fb; | |
10187 | int ret; | |
10188 | ||
10189 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10190 | if (!intel_fb) |
d2dff872 | 10191 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10192 | |
10193 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10194 | if (ret) |
10195 | goto err; | |
d2dff872 CW |
10196 | |
10197 | return &intel_fb->base; | |
dcb1394e | 10198 | |
dd4916c5 | 10199 | err: |
dd4916c5 | 10200 | kfree(intel_fb); |
dd4916c5 | 10201 | return ERR_PTR(ret); |
d2dff872 CW |
10202 | } |
10203 | ||
b5ea642a | 10204 | static struct drm_framebuffer * |
a8bb6818 DV |
10205 | intel_framebuffer_create(struct drm_device *dev, |
10206 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10207 | struct drm_i915_gem_object *obj) | |
10208 | { | |
10209 | struct drm_framebuffer *fb; | |
10210 | int ret; | |
10211 | ||
10212 | ret = i915_mutex_lock_interruptible(dev); | |
10213 | if (ret) | |
10214 | return ERR_PTR(ret); | |
10215 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10216 | mutex_unlock(&dev->struct_mutex); | |
10217 | ||
10218 | return fb; | |
10219 | } | |
10220 | ||
d2dff872 CW |
10221 | static u32 |
10222 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10223 | { | |
10224 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10225 | return ALIGN(pitch, 64); | |
10226 | } | |
10227 | ||
10228 | static u32 | |
10229 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10230 | { | |
10231 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10232 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10233 | } |
10234 | ||
10235 | static struct drm_framebuffer * | |
10236 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10237 | struct drm_display_mode *mode, | |
10238 | int depth, int bpp) | |
10239 | { | |
dcb1394e | 10240 | struct drm_framebuffer *fb; |
d2dff872 | 10241 | struct drm_i915_gem_object *obj; |
0fed39bd | 10242 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10243 | |
10244 | obj = i915_gem_alloc_object(dev, | |
10245 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10246 | if (obj == NULL) | |
10247 | return ERR_PTR(-ENOMEM); | |
10248 | ||
10249 | mode_cmd.width = mode->hdisplay; | |
10250 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10251 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10252 | bpp); | |
5ca0c34a | 10253 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10254 | |
dcb1394e LW |
10255 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10256 | if (IS_ERR(fb)) | |
10257 | drm_gem_object_unreference_unlocked(&obj->base); | |
10258 | ||
10259 | return fb; | |
d2dff872 CW |
10260 | } |
10261 | ||
10262 | static struct drm_framebuffer * | |
10263 | mode_fits_in_fbdev(struct drm_device *dev, | |
10264 | struct drm_display_mode *mode) | |
10265 | { | |
0695726e | 10266 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10267 | struct drm_i915_private *dev_priv = dev->dev_private; |
10268 | struct drm_i915_gem_object *obj; | |
10269 | struct drm_framebuffer *fb; | |
10270 | ||
4c0e5528 | 10271 | if (!dev_priv->fbdev) |
d2dff872 CW |
10272 | return NULL; |
10273 | ||
4c0e5528 | 10274 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10275 | return NULL; |
10276 | ||
4c0e5528 DV |
10277 | obj = dev_priv->fbdev->fb->obj; |
10278 | BUG_ON(!obj); | |
10279 | ||
8bcd4553 | 10280 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10281 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10282 | fb->bits_per_pixel)) | |
d2dff872 CW |
10283 | return NULL; |
10284 | ||
01f2c773 | 10285 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10286 | return NULL; |
10287 | ||
10288 | return fb; | |
4520f53a DV |
10289 | #else |
10290 | return NULL; | |
10291 | #endif | |
d2dff872 CW |
10292 | } |
10293 | ||
d3a40d1b ACO |
10294 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10295 | struct drm_crtc *crtc, | |
10296 | struct drm_display_mode *mode, | |
10297 | struct drm_framebuffer *fb, | |
10298 | int x, int y) | |
10299 | { | |
10300 | struct drm_plane_state *plane_state; | |
10301 | int hdisplay, vdisplay; | |
10302 | int ret; | |
10303 | ||
10304 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10305 | if (IS_ERR(plane_state)) | |
10306 | return PTR_ERR(plane_state); | |
10307 | ||
10308 | if (mode) | |
10309 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10310 | else | |
10311 | hdisplay = vdisplay = 0; | |
10312 | ||
10313 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10314 | if (ret) | |
10315 | return ret; | |
10316 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10317 | plane_state->crtc_x = 0; | |
10318 | plane_state->crtc_y = 0; | |
10319 | plane_state->crtc_w = hdisplay; | |
10320 | plane_state->crtc_h = vdisplay; | |
10321 | plane_state->src_x = x << 16; | |
10322 | plane_state->src_y = y << 16; | |
10323 | plane_state->src_w = hdisplay << 16; | |
10324 | plane_state->src_h = vdisplay << 16; | |
10325 | ||
10326 | return 0; | |
10327 | } | |
10328 | ||
d2434ab7 | 10329 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10330 | struct drm_display_mode *mode, |
51fd371b RC |
10331 | struct intel_load_detect_pipe *old, |
10332 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10333 | { |
10334 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10335 | struct intel_encoder *intel_encoder = |
10336 | intel_attached_encoder(connector); | |
79e53945 | 10337 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10338 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10339 | struct drm_crtc *crtc = NULL; |
10340 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10341 | struct drm_framebuffer *fb; |
51fd371b | 10342 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10343 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10344 | struct drm_connector_state *connector_state; |
4be07317 | 10345 | struct intel_crtc_state *crtc_state; |
51fd371b | 10346 | int ret, i = -1; |
79e53945 | 10347 | |
d2dff872 | 10348 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10349 | connector->base.id, connector->name, |
8e329a03 | 10350 | encoder->base.id, encoder->name); |
d2dff872 | 10351 | |
51fd371b RC |
10352 | retry: |
10353 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10354 | if (ret) | |
ad3c558f | 10355 | goto fail; |
6e9f798d | 10356 | |
79e53945 JB |
10357 | /* |
10358 | * Algorithm gets a little messy: | |
7a5e4805 | 10359 | * |
79e53945 JB |
10360 | * - if the connector already has an assigned crtc, use it (but make |
10361 | * sure it's on first) | |
7a5e4805 | 10362 | * |
79e53945 JB |
10363 | * - try to find the first unused crtc that can drive this connector, |
10364 | * and use that if we find one | |
79e53945 JB |
10365 | */ |
10366 | ||
10367 | /* See if we already have a CRTC for this connector */ | |
10368 | if (encoder->crtc) { | |
10369 | crtc = encoder->crtc; | |
8261b191 | 10370 | |
51fd371b | 10371 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10372 | if (ret) |
ad3c558f | 10373 | goto fail; |
4d02e2de | 10374 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
51fd371b | 10375 | if (ret) |
ad3c558f | 10376 | goto fail; |
7b24056b | 10377 | |
24218aac | 10378 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10379 | old->load_detect_temp = false; |
10380 | ||
10381 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10382 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10383 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10384 | |
7173188d | 10385 | return true; |
79e53945 JB |
10386 | } |
10387 | ||
10388 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10389 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10390 | i++; |
10391 | if (!(encoder->possible_crtcs & (1 << i))) | |
10392 | continue; | |
83d65738 | 10393 | if (possible_crtc->state->enable) |
a459249c | 10394 | continue; |
a459249c VS |
10395 | |
10396 | crtc = possible_crtc; | |
10397 | break; | |
79e53945 JB |
10398 | } |
10399 | ||
10400 | /* | |
10401 | * If we didn't find an unused CRTC, don't use any. | |
10402 | */ | |
10403 | if (!crtc) { | |
7173188d | 10404 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10405 | goto fail; |
79e53945 JB |
10406 | } |
10407 | ||
51fd371b RC |
10408 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10409 | if (ret) | |
ad3c558f | 10410 | goto fail; |
4d02e2de DV |
10411 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10412 | if (ret) | |
ad3c558f | 10413 | goto fail; |
79e53945 JB |
10414 | |
10415 | intel_crtc = to_intel_crtc(crtc); | |
24218aac | 10416 | old->dpms_mode = connector->dpms; |
8261b191 | 10417 | old->load_detect_temp = true; |
d2dff872 | 10418 | old->release_fb = NULL; |
79e53945 | 10419 | |
83a57153 ACO |
10420 | state = drm_atomic_state_alloc(dev); |
10421 | if (!state) | |
10422 | return false; | |
10423 | ||
10424 | state->acquire_ctx = ctx; | |
10425 | ||
944b0c76 ACO |
10426 | connector_state = drm_atomic_get_connector_state(state, connector); |
10427 | if (IS_ERR(connector_state)) { | |
10428 | ret = PTR_ERR(connector_state); | |
10429 | goto fail; | |
10430 | } | |
10431 | ||
10432 | connector_state->crtc = crtc; | |
10433 | connector_state->best_encoder = &intel_encoder->base; | |
10434 | ||
4be07317 ACO |
10435 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10436 | if (IS_ERR(crtc_state)) { | |
10437 | ret = PTR_ERR(crtc_state); | |
10438 | goto fail; | |
10439 | } | |
10440 | ||
49d6fa21 | 10441 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10442 | |
6492711d CW |
10443 | if (!mode) |
10444 | mode = &load_detect_mode; | |
79e53945 | 10445 | |
d2dff872 CW |
10446 | /* We need a framebuffer large enough to accommodate all accesses |
10447 | * that the plane may generate whilst we perform load detection. | |
10448 | * We can not rely on the fbcon either being present (we get called | |
10449 | * during its initialisation to detect all boot displays, or it may | |
10450 | * not even exist) or that it is large enough to satisfy the | |
10451 | * requested mode. | |
10452 | */ | |
94352cf9 DV |
10453 | fb = mode_fits_in_fbdev(dev, mode); |
10454 | if (fb == NULL) { | |
d2dff872 | 10455 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10456 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10457 | old->release_fb = fb; | |
d2dff872 CW |
10458 | } else |
10459 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10460 | if (IS_ERR(fb)) { |
d2dff872 | 10461 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10462 | goto fail; |
79e53945 | 10463 | } |
79e53945 | 10464 | |
d3a40d1b ACO |
10465 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10466 | if (ret) | |
10467 | goto fail; | |
10468 | ||
8c7b5ccb ACO |
10469 | drm_mode_copy(&crtc_state->base.mode, mode); |
10470 | ||
74c090b1 | 10471 | if (drm_atomic_commit(state)) { |
6492711d | 10472 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10473 | if (old->release_fb) |
10474 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10475 | goto fail; |
79e53945 | 10476 | } |
9128b040 | 10477 | crtc->primary->crtc = crtc; |
7173188d | 10478 | |
79e53945 | 10479 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10480 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10481 | return true; |
412b61d8 | 10482 | |
ad3c558f | 10483 | fail: |
e5d958ef ACO |
10484 | drm_atomic_state_free(state); |
10485 | state = NULL; | |
83a57153 | 10486 | |
51fd371b RC |
10487 | if (ret == -EDEADLK) { |
10488 | drm_modeset_backoff(ctx); | |
10489 | goto retry; | |
10490 | } | |
10491 | ||
412b61d8 | 10492 | return false; |
79e53945 JB |
10493 | } |
10494 | ||
d2434ab7 | 10495 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10496 | struct intel_load_detect_pipe *old, |
10497 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10498 | { |
83a57153 | 10499 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10500 | struct intel_encoder *intel_encoder = |
10501 | intel_attached_encoder(connector); | |
4ef69c7a | 10502 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10503 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10504 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10505 | struct drm_atomic_state *state; |
944b0c76 | 10506 | struct drm_connector_state *connector_state; |
4be07317 | 10507 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10508 | int ret; |
79e53945 | 10509 | |
d2dff872 | 10510 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10511 | connector->base.id, connector->name, |
8e329a03 | 10512 | encoder->base.id, encoder->name); |
d2dff872 | 10513 | |
8261b191 | 10514 | if (old->load_detect_temp) { |
83a57153 | 10515 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10516 | if (!state) |
10517 | goto fail; | |
83a57153 ACO |
10518 | |
10519 | state->acquire_ctx = ctx; | |
10520 | ||
944b0c76 ACO |
10521 | connector_state = drm_atomic_get_connector_state(state, connector); |
10522 | if (IS_ERR(connector_state)) | |
10523 | goto fail; | |
10524 | ||
4be07317 ACO |
10525 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10526 | if (IS_ERR(crtc_state)) | |
10527 | goto fail; | |
10528 | ||
944b0c76 ACO |
10529 | connector_state->best_encoder = NULL; |
10530 | connector_state->crtc = NULL; | |
10531 | ||
49d6fa21 | 10532 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10533 | |
d3a40d1b ACO |
10534 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10535 | 0, 0); | |
10536 | if (ret) | |
10537 | goto fail; | |
10538 | ||
74c090b1 | 10539 | ret = drm_atomic_commit(state); |
2bfb4627 ACO |
10540 | if (ret) |
10541 | goto fail; | |
d2dff872 | 10542 | |
36206361 DV |
10543 | if (old->release_fb) { |
10544 | drm_framebuffer_unregister_private(old->release_fb); | |
10545 | drm_framebuffer_unreference(old->release_fb); | |
10546 | } | |
d2dff872 | 10547 | |
0622a53c | 10548 | return; |
79e53945 JB |
10549 | } |
10550 | ||
c751ce4f | 10551 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10552 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10553 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10554 | |
10555 | return; | |
10556 | fail: | |
10557 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10558 | drm_atomic_state_free(state); | |
79e53945 JB |
10559 | } |
10560 | ||
da4a1efa | 10561 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10562 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10563 | { |
10564 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10565 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10566 | ||
10567 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10568 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10569 | else if (HAS_PCH_SPLIT(dev)) |
10570 | return 120000; | |
10571 | else if (!IS_GEN2(dev)) | |
10572 | return 96000; | |
10573 | else | |
10574 | return 48000; | |
10575 | } | |
10576 | ||
79e53945 | 10577 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10578 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10579 | struct intel_crtc_state *pipe_config) |
79e53945 | 10580 | { |
f1f644dc | 10581 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10582 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10583 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10584 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10585 | u32 fp; |
10586 | intel_clock_t clock; | |
dccbea3b | 10587 | int port_clock; |
da4a1efa | 10588 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10589 | |
10590 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10591 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10592 | else |
293623f7 | 10593 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10594 | |
10595 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10596 | if (IS_PINEVIEW(dev)) { |
10597 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10598 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10599 | } else { |
10600 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10601 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10602 | } | |
10603 | ||
a6c45cf0 | 10604 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10605 | if (IS_PINEVIEW(dev)) |
10606 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10607 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10608 | else |
10609 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10610 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10611 | ||
10612 | switch (dpll & DPLL_MODE_MASK) { | |
10613 | case DPLLB_MODE_DAC_SERIAL: | |
10614 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10615 | 5 : 10; | |
10616 | break; | |
10617 | case DPLLB_MODE_LVDS: | |
10618 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10619 | 7 : 14; | |
10620 | break; | |
10621 | default: | |
28c97730 | 10622 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10623 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10624 | return; |
79e53945 JB |
10625 | } |
10626 | ||
ac58c3f0 | 10627 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10628 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10629 | else |
dccbea3b | 10630 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10631 | } else { |
0fb58223 | 10632 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10633 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10634 | |
10635 | if (is_lvds) { | |
10636 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10637 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10638 | |
10639 | if (lvds & LVDS_CLKB_POWER_UP) | |
10640 | clock.p2 = 7; | |
10641 | else | |
10642 | clock.p2 = 14; | |
79e53945 JB |
10643 | } else { |
10644 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10645 | clock.p1 = 2; | |
10646 | else { | |
10647 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10648 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10649 | } | |
10650 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10651 | clock.p2 = 4; | |
10652 | else | |
10653 | clock.p2 = 2; | |
79e53945 | 10654 | } |
da4a1efa | 10655 | |
dccbea3b | 10656 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10657 | } |
10658 | ||
18442d08 VS |
10659 | /* |
10660 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10661 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10662 | * encoder's get_config() function. |
10663 | */ | |
dccbea3b | 10664 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10665 | } |
10666 | ||
6878da05 VS |
10667 | int intel_dotclock_calculate(int link_freq, |
10668 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10669 | { |
f1f644dc JB |
10670 | /* |
10671 | * The calculation for the data clock is: | |
1041a02f | 10672 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10673 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10674 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10675 | * |
10676 | * and the link clock is simpler: | |
1041a02f | 10677 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10678 | */ |
10679 | ||
6878da05 VS |
10680 | if (!m_n->link_n) |
10681 | return 0; | |
f1f644dc | 10682 | |
6878da05 VS |
10683 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10684 | } | |
f1f644dc | 10685 | |
18442d08 | 10686 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10687 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10688 | { |
10689 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10690 | |
18442d08 VS |
10691 | /* read out port_clock from the DPLL */ |
10692 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10693 | |
f1f644dc | 10694 | /* |
18442d08 | 10695 | * This value does not include pixel_multiplier. |
241bfc38 | 10696 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10697 | * agree once we know their relationship in the encoder's |
10698 | * get_config() function. | |
79e53945 | 10699 | */ |
2d112de7 | 10700 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10701 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10702 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10703 | } |
10704 | ||
10705 | /** Returns the currently programmed mode of the given pipe. */ | |
10706 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10707 | struct drm_crtc *crtc) | |
10708 | { | |
548f245b | 10709 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10710 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10711 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10712 | struct drm_display_mode *mode; |
5cec258b | 10713 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10714 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10715 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10716 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10717 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10718 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10719 | |
10720 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10721 | if (!mode) | |
10722 | return NULL; | |
10723 | ||
f1f644dc JB |
10724 | /* |
10725 | * Construct a pipe_config sufficient for getting the clock info | |
10726 | * back out of crtc_clock_get. | |
10727 | * | |
10728 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10729 | * to use a real value here instead. | |
10730 | */ | |
293623f7 | 10731 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10732 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10733 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10734 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10735 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10736 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10737 | ||
773ae034 | 10738 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10739 | mode->hdisplay = (htot & 0xffff) + 1; |
10740 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10741 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10742 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10743 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10744 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10745 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10746 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10747 | ||
10748 | drm_mode_set_name(mode); | |
79e53945 JB |
10749 | |
10750 | return mode; | |
10751 | } | |
10752 | ||
f047e395 CW |
10753 | void intel_mark_busy(struct drm_device *dev) |
10754 | { | |
c67a470b PZ |
10755 | struct drm_i915_private *dev_priv = dev->dev_private; |
10756 | ||
f62a0076 CW |
10757 | if (dev_priv->mm.busy) |
10758 | return; | |
10759 | ||
43694d69 | 10760 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10761 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10762 | if (INTEL_INFO(dev)->gen >= 6) |
10763 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10764 | dev_priv->mm.busy = true; |
f047e395 CW |
10765 | } |
10766 | ||
10767 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10768 | { |
c67a470b | 10769 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10770 | |
f62a0076 CW |
10771 | if (!dev_priv->mm.busy) |
10772 | return; | |
10773 | ||
10774 | dev_priv->mm.busy = false; | |
10775 | ||
3d13ef2e | 10776 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10777 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10778 | |
43694d69 | 10779 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10780 | } |
10781 | ||
79e53945 JB |
10782 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10783 | { | |
10784 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10785 | struct drm_device *dev = crtc->dev; |
10786 | struct intel_unpin_work *work; | |
67e77c5a | 10787 | |
5e2d7afc | 10788 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10789 | work = intel_crtc->unpin_work; |
10790 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10791 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10792 | |
10793 | if (work) { | |
10794 | cancel_work_sync(&work->work); | |
10795 | kfree(work); | |
10796 | } | |
79e53945 JB |
10797 | |
10798 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10799 | |
79e53945 JB |
10800 | kfree(intel_crtc); |
10801 | } | |
10802 | ||
6b95a207 KH |
10803 | static void intel_unpin_work_fn(struct work_struct *__work) |
10804 | { | |
10805 | struct intel_unpin_work *work = | |
10806 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10807 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10808 | struct drm_device *dev = crtc->base.dev; | |
10809 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10810 | |
b4a98e57 | 10811 | mutex_lock(&dev->struct_mutex); |
a9ff8714 | 10812 | intel_unpin_fb_obj(work->old_fb, primary->state); |
05394f39 | 10813 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10814 | |
f06cc1b9 | 10815 | if (work->flip_queued_req) |
146d84f0 | 10816 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10817 | mutex_unlock(&dev->struct_mutex); |
10818 | ||
a9ff8714 | 10819 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
89ed88ba | 10820 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10821 | |
a9ff8714 VS |
10822 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10823 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10824 | |
6b95a207 KH |
10825 | kfree(work); |
10826 | } | |
10827 | ||
1afe3e9d | 10828 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10829 | struct drm_crtc *crtc) |
6b95a207 | 10830 | { |
6b95a207 KH |
10831 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10832 | struct intel_unpin_work *work; | |
6b95a207 KH |
10833 | unsigned long flags; |
10834 | ||
10835 | /* Ignore early vblank irqs */ | |
10836 | if (intel_crtc == NULL) | |
10837 | return; | |
10838 | ||
f326038a DV |
10839 | /* |
10840 | * This is called both by irq handlers and the reset code (to complete | |
10841 | * lost pageflips) so needs the full irqsave spinlocks. | |
10842 | */ | |
6b95a207 KH |
10843 | spin_lock_irqsave(&dev->event_lock, flags); |
10844 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10845 | |
10846 | /* Ensure we don't miss a work->pending update ... */ | |
10847 | smp_rmb(); | |
10848 | ||
10849 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10850 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10851 | return; | |
10852 | } | |
10853 | ||
d6bbafa1 | 10854 | page_flip_completed(intel_crtc); |
0af7e4df | 10855 | |
6b95a207 | 10856 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10857 | } |
10858 | ||
1afe3e9d JB |
10859 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10860 | { | |
fbee40df | 10861 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10862 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10863 | ||
49b14a5c | 10864 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10865 | } |
10866 | ||
10867 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10868 | { | |
fbee40df | 10869 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10870 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10871 | ||
49b14a5c | 10872 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10873 | } |
10874 | ||
75f7f3ec VS |
10875 | /* Is 'a' after or equal to 'b'? */ |
10876 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10877 | { | |
10878 | return !((a - b) & 0x80000000); | |
10879 | } | |
10880 | ||
10881 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10882 | { | |
10883 | struct drm_device *dev = crtc->base.dev; | |
10884 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10885 | ||
bdfa7542 VS |
10886 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10887 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10888 | return true; | |
10889 | ||
75f7f3ec VS |
10890 | /* |
10891 | * The relevant registers doen't exist on pre-ctg. | |
10892 | * As the flip done interrupt doesn't trigger for mmio | |
10893 | * flips on gmch platforms, a flip count check isn't | |
10894 | * really needed there. But since ctg has the registers, | |
10895 | * include it in the check anyway. | |
10896 | */ | |
10897 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10898 | return true; | |
10899 | ||
10900 | /* | |
10901 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10902 | * used the same base address. In that case the mmio flip might | |
10903 | * have completed, but the CS hasn't even executed the flip yet. | |
10904 | * | |
10905 | * A flip count check isn't enough as the CS might have updated | |
10906 | * the base address just after start of vblank, but before we | |
10907 | * managed to process the interrupt. This means we'd complete the | |
10908 | * CS flip too soon. | |
10909 | * | |
10910 | * Combining both checks should get us a good enough result. It may | |
10911 | * still happen that the CS flip has been executed, but has not | |
10912 | * yet actually completed. But in case the base address is the same | |
10913 | * anyway, we don't really care. | |
10914 | */ | |
10915 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10916 | crtc->unpin_work->gtt_offset && | |
fd8f507c | 10917 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
75f7f3ec VS |
10918 | crtc->unpin_work->flip_count); |
10919 | } | |
10920 | ||
6b95a207 KH |
10921 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10922 | { | |
fbee40df | 10923 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10924 | struct intel_crtc *intel_crtc = |
10925 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10926 | unsigned long flags; | |
10927 | ||
f326038a DV |
10928 | |
10929 | /* | |
10930 | * This is called both by irq handlers and the reset code (to complete | |
10931 | * lost pageflips) so needs the full irqsave spinlocks. | |
10932 | * | |
10933 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10934 | * generate a page-flip completion irq, i.e. every modeset |
10935 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10936 | */ | |
6b95a207 | 10937 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10938 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10939 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10940 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10941 | } | |
10942 | ||
6042639c | 10943 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
e7d841ca CW |
10944 | { |
10945 | /* Ensure that the work item is consistent when activating it ... */ | |
10946 | smp_wmb(); | |
6042639c | 10947 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
e7d841ca CW |
10948 | /* and that it is marked active as soon as the irq could fire. */ |
10949 | smp_wmb(); | |
10950 | } | |
10951 | ||
8c9f3aaf JB |
10952 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10953 | struct drm_crtc *crtc, | |
10954 | struct drm_framebuffer *fb, | |
ed8d1975 | 10955 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10956 | struct drm_i915_gem_request *req, |
ed8d1975 | 10957 | uint32_t flags) |
8c9f3aaf | 10958 | { |
6258fbe2 | 10959 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10960 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10961 | u32 flip_mask; |
10962 | int ret; | |
10963 | ||
5fb9de1a | 10964 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10965 | if (ret) |
4fa62c89 | 10966 | return ret; |
8c9f3aaf JB |
10967 | |
10968 | /* Can't queue multiple flips, so wait for the previous | |
10969 | * one to finish before executing the next. | |
10970 | */ | |
10971 | if (intel_crtc->plane) | |
10972 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10973 | else | |
10974 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10975 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10976 | intel_ring_emit(ring, MI_NOOP); | |
10977 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10978 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10979 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10980 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10981 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca | 10982 | |
6042639c | 10983 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 10984 | return 0; |
8c9f3aaf JB |
10985 | } |
10986 | ||
10987 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10988 | struct drm_crtc *crtc, | |
10989 | struct drm_framebuffer *fb, | |
ed8d1975 | 10990 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10991 | struct drm_i915_gem_request *req, |
ed8d1975 | 10992 | uint32_t flags) |
8c9f3aaf | 10993 | { |
6258fbe2 | 10994 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10995 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10996 | u32 flip_mask; |
10997 | int ret; | |
10998 | ||
5fb9de1a | 10999 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 11000 | if (ret) |
4fa62c89 | 11001 | return ret; |
8c9f3aaf JB |
11002 | |
11003 | if (intel_crtc->plane) | |
11004 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11005 | else | |
11006 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11007 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11008 | intel_ring_emit(ring, MI_NOOP); | |
11009 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
11010 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11011 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11012 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
11013 | intel_ring_emit(ring, MI_NOOP); |
11014 | ||
6042639c | 11015 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11016 | return 0; |
8c9f3aaf JB |
11017 | } |
11018 | ||
11019 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
11020 | struct drm_crtc *crtc, | |
11021 | struct drm_framebuffer *fb, | |
ed8d1975 | 11022 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11023 | struct drm_i915_gem_request *req, |
ed8d1975 | 11024 | uint32_t flags) |
8c9f3aaf | 11025 | { |
6258fbe2 | 11026 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
11027 | struct drm_i915_private *dev_priv = dev->dev_private; |
11028 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11029 | uint32_t pf, pipesrc; | |
11030 | int ret; | |
11031 | ||
5fb9de1a | 11032 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 11033 | if (ret) |
4fa62c89 | 11034 | return ret; |
8c9f3aaf JB |
11035 | |
11036 | /* i965+ uses the linear or tiled offsets from the | |
11037 | * Display Registers (which do not change across a page-flip) | |
11038 | * so we need only reprogram the base address. | |
11039 | */ | |
6d90c952 DV |
11040 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11041 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11042 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11043 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 11044 | obj->tiling_mode); |
8c9f3aaf JB |
11045 | |
11046 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11047 | * untested on non-native modes, so ignore it for now. | |
11048 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11049 | */ | |
11050 | pf = 0; | |
11051 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 11052 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 11053 | |
6042639c | 11054 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11055 | return 0; |
8c9f3aaf JB |
11056 | } |
11057 | ||
11058 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
11059 | struct drm_crtc *crtc, | |
11060 | struct drm_framebuffer *fb, | |
ed8d1975 | 11061 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11062 | struct drm_i915_gem_request *req, |
ed8d1975 | 11063 | uint32_t flags) |
8c9f3aaf | 11064 | { |
6258fbe2 | 11065 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
11066 | struct drm_i915_private *dev_priv = dev->dev_private; |
11067 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11068 | uint32_t pf, pipesrc; | |
11069 | int ret; | |
11070 | ||
5fb9de1a | 11071 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 11072 | if (ret) |
4fa62c89 | 11073 | return ret; |
8c9f3aaf | 11074 | |
6d90c952 DV |
11075 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11076 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11077 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 11078 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 11079 | |
dc257cf1 DV |
11080 | /* Contrary to the suggestions in the documentation, |
11081 | * "Enable Panel Fitter" does not seem to be required when page | |
11082 | * flipping with a non-native mode, and worse causes a normal | |
11083 | * modeset to fail. | |
11084 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11085 | */ | |
11086 | pf = 0; | |
8c9f3aaf | 11087 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 11088 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 11089 | |
6042639c | 11090 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11091 | return 0; |
8c9f3aaf JB |
11092 | } |
11093 | ||
7c9017e5 JB |
11094 | static int intel_gen7_queue_flip(struct drm_device *dev, |
11095 | struct drm_crtc *crtc, | |
11096 | struct drm_framebuffer *fb, | |
ed8d1975 | 11097 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11098 | struct drm_i915_gem_request *req, |
ed8d1975 | 11099 | uint32_t flags) |
7c9017e5 | 11100 | { |
6258fbe2 | 11101 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 11102 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 11103 | uint32_t plane_bit = 0; |
ffe74d75 CW |
11104 | int len, ret; |
11105 | ||
eba905b2 | 11106 | switch (intel_crtc->plane) { |
cb05d8de DV |
11107 | case PLANE_A: |
11108 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11109 | break; | |
11110 | case PLANE_B: | |
11111 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11112 | break; | |
11113 | case PLANE_C: | |
11114 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11115 | break; | |
11116 | default: | |
11117 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11118 | return -ENODEV; |
cb05d8de DV |
11119 | } |
11120 | ||
ffe74d75 | 11121 | len = 4; |
f476828a | 11122 | if (ring->id == RCS) { |
ffe74d75 | 11123 | len += 6; |
f476828a DL |
11124 | /* |
11125 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11126 | * 48bits addresses, and we need a NOOP for the batch size to | |
11127 | * stay even. | |
11128 | */ | |
11129 | if (IS_GEN8(dev)) | |
11130 | len += 2; | |
11131 | } | |
ffe74d75 | 11132 | |
f66fab8e VS |
11133 | /* |
11134 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11135 | * "The full packet must be contained within the same cache line." | |
11136 | * | |
11137 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11138 | * cacheline, if we ever start emitting more commands before | |
11139 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11140 | * then do the cacheline alignment, and finally emit the | |
11141 | * MI_DISPLAY_FLIP. | |
11142 | */ | |
bba09b12 | 11143 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 11144 | if (ret) |
4fa62c89 | 11145 | return ret; |
f66fab8e | 11146 | |
5fb9de1a | 11147 | ret = intel_ring_begin(req, len); |
7c9017e5 | 11148 | if (ret) |
4fa62c89 | 11149 | return ret; |
7c9017e5 | 11150 | |
ffe74d75 CW |
11151 | /* Unmask the flip-done completion message. Note that the bspec says that |
11152 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11153 | * more than one flip event at any time (or ensure that one flip message | |
11154 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11155 | * Experimentation says that BCS works despite DERRMR masking all | |
11156 | * flip-done completion events and that unmasking all planes at once | |
11157 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11158 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11159 | */ | |
11160 | if (ring->id == RCS) { | |
11161 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
f92a9162 | 11162 | intel_ring_emit_reg(ring, DERRMR); |
ffe74d75 CW |
11163 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
11164 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11165 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11166 | if (IS_GEN8(dev)) |
f1afe24f | 11167 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11168 | MI_SRM_LRM_GLOBAL_GTT); |
11169 | else | |
f1afe24f | 11170 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11171 | MI_SRM_LRM_GLOBAL_GTT); |
f92a9162 | 11172 | intel_ring_emit_reg(ring, DERRMR); |
ffe74d75 | 11173 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
f476828a DL |
11174 | if (IS_GEN8(dev)) { |
11175 | intel_ring_emit(ring, 0); | |
11176 | intel_ring_emit(ring, MI_NOOP); | |
11177 | } | |
ffe74d75 CW |
11178 | } |
11179 | ||
cb05d8de | 11180 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11181 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11182 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11183 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca | 11184 | |
6042639c | 11185 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11186 | return 0; |
7c9017e5 JB |
11187 | } |
11188 | ||
84c33a64 SG |
11189 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11190 | struct drm_i915_gem_object *obj) | |
11191 | { | |
11192 | /* | |
11193 | * This is not being used for older platforms, because | |
11194 | * non-availability of flip done interrupt forces us to use | |
11195 | * CS flips. Older platforms derive flip done using some clever | |
11196 | * tricks involving the flip_pending status bits and vblank irqs. | |
11197 | * So using MMIO flips there would disrupt this mechanism. | |
11198 | */ | |
11199 | ||
8e09bf83 CW |
11200 | if (ring == NULL) |
11201 | return true; | |
11202 | ||
84c33a64 SG |
11203 | if (INTEL_INFO(ring->dev)->gen < 5) |
11204 | return false; | |
11205 | ||
11206 | if (i915.use_mmio_flip < 0) | |
11207 | return false; | |
11208 | else if (i915.use_mmio_flip > 0) | |
11209 | return true; | |
14bf993e OM |
11210 | else if (i915.enable_execlists) |
11211 | return true; | |
84c33a64 | 11212 | else |
b4716185 | 11213 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11214 | } |
11215 | ||
6042639c | 11216 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
86efe24a | 11217 | unsigned int rotation, |
6042639c | 11218 | struct intel_unpin_work *work) |
ff944564 DL |
11219 | { |
11220 | struct drm_device *dev = intel_crtc->base.dev; | |
11221 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11222 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 | 11223 | const enum pipe pipe = intel_crtc->pipe; |
86efe24a | 11224 | u32 ctl, stride, tile_height; |
ff944564 DL |
11225 | |
11226 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11227 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11228 | switch (fb->modifier[0]) { |
11229 | case DRM_FORMAT_MOD_NONE: | |
11230 | break; | |
11231 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11232 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11233 | break; |
11234 | case I915_FORMAT_MOD_Y_TILED: | |
11235 | ctl |= PLANE_CTL_TILED_Y; | |
11236 | break; | |
11237 | case I915_FORMAT_MOD_Yf_TILED: | |
11238 | ctl |= PLANE_CTL_TILED_YF; | |
11239 | break; | |
11240 | default: | |
11241 | MISSING_CASE(fb->modifier[0]); | |
11242 | } | |
ff944564 DL |
11243 | |
11244 | /* | |
11245 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11246 | * linear buffers or in number of tiles for tiled buffers. | |
11247 | */ | |
86efe24a TU |
11248 | if (intel_rotation_90_or_270(rotation)) { |
11249 | /* stride = Surface height in tiles */ | |
11250 | tile_height = intel_tile_height(dev, fb->pixel_format, | |
11251 | fb->modifier[0], 0); | |
11252 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11253 | } else { | |
11254 | stride = fb->pitches[0] / | |
11255 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11256 | fb->pixel_format); | |
11257 | } | |
ff944564 DL |
11258 | |
11259 | /* | |
11260 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11261 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11262 | */ | |
11263 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11264 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11265 | ||
6042639c | 11266 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
ff944564 DL |
11267 | POSTING_READ(PLANE_SURF(pipe, 0)); |
11268 | } | |
11269 | ||
6042639c CW |
11270 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
11271 | struct intel_unpin_work *work) | |
84c33a64 SG |
11272 | { |
11273 | struct drm_device *dev = intel_crtc->base.dev; | |
11274 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11275 | struct intel_framebuffer *intel_fb = | |
11276 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11277 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
f0f59a00 | 11278 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
84c33a64 | 11279 | u32 dspcntr; |
84c33a64 | 11280 | |
84c33a64 SG |
11281 | dspcntr = I915_READ(reg); |
11282 | ||
c5d97472 DL |
11283 | if (obj->tiling_mode != I915_TILING_NONE) |
11284 | dspcntr |= DISPPLANE_TILED; | |
11285 | else | |
11286 | dspcntr &= ~DISPPLANE_TILED; | |
11287 | ||
84c33a64 SG |
11288 | I915_WRITE(reg, dspcntr); |
11289 | ||
6042639c | 11290 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
84c33a64 | 11291 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
ff944564 DL |
11292 | } |
11293 | ||
11294 | /* | |
11295 | * XXX: This is the temporary way to update the plane registers until we get | |
11296 | * around to using the usual plane update functions for MMIO flips | |
11297 | */ | |
6042639c | 11298 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
ff944564 | 11299 | { |
6042639c CW |
11300 | struct intel_crtc *crtc = mmio_flip->crtc; |
11301 | struct intel_unpin_work *work; | |
11302 | ||
11303 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11304 | work = crtc->unpin_work; | |
11305 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11306 | if (work == NULL) | |
11307 | return; | |
ff944564 | 11308 | |
6042639c | 11309 | intel_mark_page_flip_active(work); |
ff944564 | 11310 | |
6042639c | 11311 | intel_pipe_update_start(crtc); |
ff944564 | 11312 | |
6042639c | 11313 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
86efe24a | 11314 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
ff944564 DL |
11315 | else |
11316 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
6042639c | 11317 | ilk_do_mmio_flip(crtc, work); |
ff944564 | 11318 | |
6042639c | 11319 | intel_pipe_update_end(crtc); |
84c33a64 SG |
11320 | } |
11321 | ||
9362c7c5 | 11322 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11323 | { |
b2cfe0ab CW |
11324 | struct intel_mmio_flip *mmio_flip = |
11325 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11326 | |
6042639c | 11327 | if (mmio_flip->req) { |
eed29a5b | 11328 | WARN_ON(__i915_wait_request(mmio_flip->req, |
b2cfe0ab | 11329 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11330 | false, NULL, |
11331 | &mmio_flip->i915->rps.mmioflips)); | |
6042639c CW |
11332 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
11333 | } | |
84c33a64 | 11334 | |
6042639c | 11335 | intel_do_mmio_flip(mmio_flip); |
b2cfe0ab | 11336 | kfree(mmio_flip); |
84c33a64 SG |
11337 | } |
11338 | ||
11339 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11340 | struct drm_crtc *crtc, | |
86efe24a | 11341 | struct drm_i915_gem_object *obj) |
84c33a64 | 11342 | { |
b2cfe0ab CW |
11343 | struct intel_mmio_flip *mmio_flip; |
11344 | ||
11345 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11346 | if (mmio_flip == NULL) | |
11347 | return -ENOMEM; | |
84c33a64 | 11348 | |
bcafc4e3 | 11349 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11350 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11351 | mmio_flip->crtc = to_intel_crtc(crtc); |
86efe24a | 11352 | mmio_flip->rotation = crtc->primary->state->rotation; |
536f5b5e | 11353 | |
b2cfe0ab CW |
11354 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11355 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11356 | |
84c33a64 SG |
11357 | return 0; |
11358 | } | |
11359 | ||
8c9f3aaf JB |
11360 | static int intel_default_queue_flip(struct drm_device *dev, |
11361 | struct drm_crtc *crtc, | |
11362 | struct drm_framebuffer *fb, | |
ed8d1975 | 11363 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11364 | struct drm_i915_gem_request *req, |
ed8d1975 | 11365 | uint32_t flags) |
8c9f3aaf JB |
11366 | { |
11367 | return -ENODEV; | |
11368 | } | |
11369 | ||
d6bbafa1 CW |
11370 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11371 | struct drm_crtc *crtc) | |
11372 | { | |
11373 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11374 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11375 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11376 | u32 addr; | |
11377 | ||
11378 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11379 | return true; | |
11380 | ||
908565c2 CW |
11381 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11382 | return false; | |
11383 | ||
d6bbafa1 CW |
11384 | if (!work->enable_stall_check) |
11385 | return false; | |
11386 | ||
11387 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11388 | if (work->flip_queued_req && |
11389 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11390 | return false; |
11391 | ||
1e3feefd | 11392 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11393 | } |
11394 | ||
1e3feefd | 11395 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11396 | return false; |
11397 | ||
11398 | /* Potential stall - if we see that the flip has happened, | |
11399 | * assume a missed interrupt. */ | |
11400 | if (INTEL_INFO(dev)->gen >= 4) | |
11401 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11402 | else | |
11403 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11404 | ||
11405 | /* There is a potential issue here with a false positive after a flip | |
11406 | * to the same address. We could address this by checking for a | |
11407 | * non-incrementing frame counter. | |
11408 | */ | |
11409 | return addr == work->gtt_offset; | |
11410 | } | |
11411 | ||
11412 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11413 | { | |
11414 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11415 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11416 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11417 | struct intel_unpin_work *work; |
f326038a | 11418 | |
6c51d46f | 11419 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11420 | |
11421 | if (crtc == NULL) | |
11422 | return; | |
11423 | ||
f326038a | 11424 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11425 | work = intel_crtc->unpin_work; |
11426 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11427 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11428 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11429 | page_flip_completed(intel_crtc); |
6ad790c0 | 11430 | work = NULL; |
d6bbafa1 | 11431 | } |
6ad790c0 CW |
11432 | if (work != NULL && |
11433 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11434 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11435 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11436 | } |
11437 | ||
6b95a207 KH |
11438 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11439 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11440 | struct drm_pending_vblank_event *event, |
11441 | uint32_t page_flip_flags) | |
6b95a207 KH |
11442 | { |
11443 | struct drm_device *dev = crtc->dev; | |
11444 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11445 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11446 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11447 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11448 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11449 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11450 | struct intel_unpin_work *work; |
a4872ba6 | 11451 | struct intel_engine_cs *ring; |
cf5d8a46 | 11452 | bool mmio_flip; |
91af127f | 11453 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11454 | int ret; |
6b95a207 | 11455 | |
2ff8fde1 MR |
11456 | /* |
11457 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11458 | * check to be safe. In the future we may enable pageflipping from | |
11459 | * a disabled primary plane. | |
11460 | */ | |
11461 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11462 | return -EBUSY; | |
11463 | ||
e6a595d2 | 11464 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11465 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11466 | return -EINVAL; |
11467 | ||
11468 | /* | |
11469 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11470 | * Note that pitch changes could also affect these register. | |
11471 | */ | |
11472 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11473 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11474 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11475 | return -EINVAL; |
11476 | ||
f900db47 CW |
11477 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11478 | goto out_hang; | |
11479 | ||
b14c5679 | 11480 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11481 | if (work == NULL) |
11482 | return -ENOMEM; | |
11483 | ||
6b95a207 | 11484 | work->event = event; |
b4a98e57 | 11485 | work->crtc = crtc; |
ab8d6675 | 11486 | work->old_fb = old_fb; |
6b95a207 KH |
11487 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11488 | ||
87b6b101 | 11489 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11490 | if (ret) |
11491 | goto free_work; | |
11492 | ||
6b95a207 | 11493 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11494 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11495 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11496 | /* Before declaring the flip queue wedged, check if |
11497 | * the hardware completed the operation behind our backs. | |
11498 | */ | |
11499 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11500 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11501 | page_flip_completed(intel_crtc); | |
11502 | } else { | |
11503 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11504 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11505 | |
d6bbafa1 CW |
11506 | drm_crtc_vblank_put(crtc); |
11507 | kfree(work); | |
11508 | return -EBUSY; | |
11509 | } | |
6b95a207 KH |
11510 | } |
11511 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11512 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11513 | |
b4a98e57 CW |
11514 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11515 | flush_workqueue(dev_priv->wq); | |
11516 | ||
75dfca80 | 11517 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11518 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11519 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11520 | |
f4510a27 | 11521 | crtc->primary->fb = fb; |
afd65eb4 | 11522 | update_state_fb(crtc->primary); |
1ed1f968 | 11523 | |
e1f99ce6 | 11524 | work->pending_flip_obj = obj; |
e1f99ce6 | 11525 | |
89ed88ba CW |
11526 | ret = i915_mutex_lock_interruptible(dev); |
11527 | if (ret) | |
11528 | goto cleanup; | |
11529 | ||
b4a98e57 | 11530 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11531 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11532 | |
75f7f3ec | 11533 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
fd8f507c | 11534 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
75f7f3ec | 11535 | |
4fa62c89 VS |
11536 | if (IS_VALLEYVIEW(dev)) { |
11537 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11538 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11539 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11540 | ring = NULL; | |
48bf5b2d | 11541 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11542 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11543 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11544 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11545 | if (ring == NULL || ring->id != RCS) |
11546 | ring = &dev_priv->ring[BCS]; | |
11547 | } else { | |
11548 | ring = &dev_priv->ring[RCS]; | |
11549 | } | |
11550 | ||
cf5d8a46 CW |
11551 | mmio_flip = use_mmio_flip(ring, obj); |
11552 | ||
11553 | /* When using CS flips, we want to emit semaphores between rings. | |
11554 | * However, when using mmio flips we will create a task to do the | |
11555 | * synchronisation, so all we want here is to pin the framebuffer | |
11556 | * into the display plane and skip any waits. | |
11557 | */ | |
7580d774 ML |
11558 | if (!mmio_flip) { |
11559 | ret = i915_gem_object_sync(obj, ring, &request); | |
11560 | if (ret) | |
11561 | goto cleanup_pending; | |
11562 | } | |
11563 | ||
82bc3b2d | 11564 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
7580d774 | 11565 | crtc->primary->state); |
8c9f3aaf JB |
11566 | if (ret) |
11567 | goto cleanup_pending; | |
6b95a207 | 11568 | |
dedf278c TU |
11569 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
11570 | obj, 0); | |
11571 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
4fa62c89 | 11572 | |
cf5d8a46 | 11573 | if (mmio_flip) { |
86efe24a | 11574 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
d6bbafa1 CW |
11575 | if (ret) |
11576 | goto cleanup_unpin; | |
11577 | ||
f06cc1b9 JH |
11578 | i915_gem_request_assign(&work->flip_queued_req, |
11579 | obj->last_write_req); | |
d6bbafa1 | 11580 | } else { |
6258fbe2 JH |
11581 | if (!request) { |
11582 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); | |
11583 | if (ret) | |
11584 | goto cleanup_unpin; | |
11585 | } | |
11586 | ||
11587 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11588 | page_flip_flags); |
11589 | if (ret) | |
11590 | goto cleanup_unpin; | |
11591 | ||
6258fbe2 | 11592 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11593 | } |
11594 | ||
91af127f | 11595 | if (request) |
75289874 | 11596 | i915_add_request_no_flush(request); |
91af127f | 11597 | |
1e3feefd | 11598 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11599 | work->enable_stall_check = true; |
4fa62c89 | 11600 | |
ab8d6675 | 11601 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11602 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11603 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11604 | |
4e1e26f1 | 11605 | intel_fbc_disable_crtc(intel_crtc); |
a9ff8714 VS |
11606 | intel_frontbuffer_flip_prepare(dev, |
11607 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11608 | |
e5510fac JB |
11609 | trace_i915_flip_request(intel_crtc->plane, obj); |
11610 | ||
6b95a207 | 11611 | return 0; |
96b099fd | 11612 | |
4fa62c89 | 11613 | cleanup_unpin: |
82bc3b2d | 11614 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11615 | cleanup_pending: |
91af127f JH |
11616 | if (request) |
11617 | i915_gem_request_cancel(request); | |
b4a98e57 | 11618 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11619 | mutex_unlock(&dev->struct_mutex); |
11620 | cleanup: | |
f4510a27 | 11621 | crtc->primary->fb = old_fb; |
afd65eb4 | 11622 | update_state_fb(crtc->primary); |
89ed88ba CW |
11623 | |
11624 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11625 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11626 | |
5e2d7afc | 11627 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11628 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11629 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11630 | |
87b6b101 | 11631 | drm_crtc_vblank_put(crtc); |
7317c75e | 11632 | free_work: |
96b099fd CW |
11633 | kfree(work); |
11634 | ||
f900db47 | 11635 | if (ret == -EIO) { |
02e0efb5 ML |
11636 | struct drm_atomic_state *state; |
11637 | struct drm_plane_state *plane_state; | |
11638 | ||
f900db47 | 11639 | out_hang: |
02e0efb5 ML |
11640 | state = drm_atomic_state_alloc(dev); |
11641 | if (!state) | |
11642 | return -ENOMEM; | |
11643 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11644 | ||
11645 | retry: | |
11646 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11647 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11648 | if (!ret) { | |
11649 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11650 | ||
11651 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11652 | if (!ret) | |
11653 | ret = drm_atomic_commit(state); | |
11654 | } | |
11655 | ||
11656 | if (ret == -EDEADLK) { | |
11657 | drm_modeset_backoff(state->acquire_ctx); | |
11658 | drm_atomic_state_clear(state); | |
11659 | goto retry; | |
11660 | } | |
11661 | ||
11662 | if (ret) | |
11663 | drm_atomic_state_free(state); | |
11664 | ||
f0d3dad3 | 11665 | if (ret == 0 && event) { |
5e2d7afc | 11666 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11667 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11668 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11669 | } |
f900db47 | 11670 | } |
96b099fd | 11671 | return ret; |
6b95a207 KH |
11672 | } |
11673 | ||
da20eabd ML |
11674 | |
11675 | /** | |
11676 | * intel_wm_need_update - Check whether watermarks need updating | |
11677 | * @plane: drm plane | |
11678 | * @state: new plane state | |
11679 | * | |
11680 | * Check current plane state versus the new one to determine whether | |
11681 | * watermarks need to be recalculated. | |
11682 | * | |
11683 | * Returns true or false. | |
11684 | */ | |
11685 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11686 | struct drm_plane_state *state) | |
11687 | { | |
d21fbe87 MR |
11688 | struct intel_plane_state *new = to_intel_plane_state(state); |
11689 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11690 | ||
11691 | /* Update watermarks on tiling or size changes. */ | |
da20eabd ML |
11692 | if (!plane->state->fb || !state->fb || |
11693 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
d21fbe87 MR |
11694 | plane->state->rotation != state->rotation || |
11695 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11696 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11697 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11698 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
2791a16c | 11699 | return true; |
7809e5ae | 11700 | |
2791a16c | 11701 | return false; |
7809e5ae MR |
11702 | } |
11703 | ||
d21fbe87 MR |
11704 | static bool needs_scaling(struct intel_plane_state *state) |
11705 | { | |
11706 | int src_w = drm_rect_width(&state->src) >> 16; | |
11707 | int src_h = drm_rect_height(&state->src) >> 16; | |
11708 | int dst_w = drm_rect_width(&state->dst); | |
11709 | int dst_h = drm_rect_height(&state->dst); | |
11710 | ||
11711 | return (src_w != dst_w || src_h != dst_h); | |
11712 | } | |
11713 | ||
da20eabd ML |
11714 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11715 | struct drm_plane_state *plane_state) | |
11716 | { | |
11717 | struct drm_crtc *crtc = crtc_state->crtc; | |
11718 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11719 | struct drm_plane *plane = plane_state->plane; | |
11720 | struct drm_device *dev = crtc->dev; | |
11721 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11722 | struct intel_plane_state *old_plane_state = | |
11723 | to_intel_plane_state(plane->state); | |
11724 | int idx = intel_crtc->base.base.id, ret; | |
11725 | int i = drm_plane_index(plane); | |
11726 | bool mode_changed = needs_modeset(crtc_state); | |
11727 | bool was_crtc_enabled = crtc->state->active; | |
11728 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11729 | bool turn_off, turn_on, visible, was_visible; |
11730 | struct drm_framebuffer *fb = plane_state->fb; | |
11731 | ||
11732 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11733 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11734 | ret = skl_update_scaler_plane( | |
11735 | to_intel_crtc_state(crtc_state), | |
11736 | to_intel_plane_state(plane_state)); | |
11737 | if (ret) | |
11738 | return ret; | |
11739 | } | |
11740 | ||
da20eabd ML |
11741 | was_visible = old_plane_state->visible; |
11742 | visible = to_intel_plane_state(plane_state)->visible; | |
11743 | ||
11744 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11745 | was_visible = false; | |
11746 | ||
11747 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11748 | visible = false; | |
11749 | ||
11750 | if (!was_visible && !visible) | |
11751 | return 0; | |
11752 | ||
11753 | turn_off = was_visible && (!visible || mode_changed); | |
11754 | turn_on = visible && (!was_visible || mode_changed); | |
11755 | ||
11756 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11757 | plane->base.id, fb ? fb->base.id : -1); | |
11758 | ||
11759 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11760 | plane->base.id, was_visible, visible, | |
11761 | turn_off, turn_on, mode_changed); | |
11762 | ||
852eb00d | 11763 | if (turn_on) { |
f015c551 | 11764 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d VS |
11765 | /* must disable cxsr around plane enable/disable */ |
11766 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11767 | intel_crtc->atomic.disable_cxsr = true; | |
11768 | /* to potentially re-enable cxsr */ | |
11769 | intel_crtc->atomic.wait_vblank = true; | |
11770 | intel_crtc->atomic.update_wm_post = true; | |
11771 | } | |
11772 | } else if (turn_off) { | |
f015c551 | 11773 | intel_crtc->atomic.update_wm_post = true; |
852eb00d VS |
11774 | /* must disable cxsr around plane enable/disable */ |
11775 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11776 | if (is_crtc_enabled) | |
11777 | intel_crtc->atomic.wait_vblank = true; | |
11778 | intel_crtc->atomic.disable_cxsr = true; | |
11779 | } | |
11780 | } else if (intel_wm_need_update(plane, plane_state)) { | |
f015c551 | 11781 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d | 11782 | } |
da20eabd | 11783 | |
8be6ca85 | 11784 | if (visible || was_visible) |
a9ff8714 VS |
11785 | intel_crtc->atomic.fb_bits |= |
11786 | to_intel_plane(plane)->frontbuffer_bit; | |
11787 | ||
da20eabd ML |
11788 | switch (plane->type) { |
11789 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd ML |
11790 | intel_crtc->atomic.pre_disable_primary = turn_off; |
11791 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11792 | ||
066cf55b RV |
11793 | if (turn_off) { |
11794 | /* | |
11795 | * FIXME: Actually if we will still have any other | |
11796 | * plane enabled on the pipe we could let IPS enabled | |
11797 | * still, but for now lets consider that when we make | |
11798 | * primary invisible by setting DSPCNTR to 0 on | |
11799 | * update_primary_plane function IPS needs to be | |
11800 | * disable. | |
11801 | */ | |
11802 | intel_crtc->atomic.disable_ips = true; | |
11803 | ||
da20eabd | 11804 | intel_crtc->atomic.disable_fbc = true; |
066cf55b | 11805 | } |
da20eabd ML |
11806 | |
11807 | /* | |
11808 | * FBC does not work on some platforms for rotated | |
11809 | * planes, so disable it when rotation is not 0 and | |
11810 | * update it when rotation is set back to 0. | |
11811 | * | |
11812 | * FIXME: This is redundant with the fbc update done in | |
11813 | * the primary plane enable function except that that | |
11814 | * one is done too late. We eventually need to unify | |
11815 | * this. | |
11816 | */ | |
11817 | ||
11818 | if (visible && | |
11819 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11820 | dev_priv->fbc.crtc == intel_crtc && | |
11821 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11822 | intel_crtc->atomic.disable_fbc = true; | |
11823 | ||
11824 | /* | |
11825 | * BDW signals flip done immediately if the plane | |
11826 | * is disabled, even if the plane enable is already | |
11827 | * armed to occur at the next vblank :( | |
11828 | */ | |
11829 | if (turn_on && IS_BROADWELL(dev)) | |
11830 | intel_crtc->atomic.wait_vblank = true; | |
11831 | ||
11832 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11833 | break; | |
11834 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11835 | break; |
11836 | case DRM_PLANE_TYPE_OVERLAY: | |
d21fbe87 MR |
11837 | /* |
11838 | * WaCxSRDisabledForSpriteScaling:ivb | |
11839 | * | |
11840 | * cstate->update_wm was already set above, so this flag will | |
11841 | * take effect when we commit and program watermarks. | |
11842 | */ | |
11843 | if (IS_IVYBRIDGE(dev) && | |
11844 | needs_scaling(to_intel_plane_state(plane_state)) && | |
11845 | !needs_scaling(old_plane_state)) { | |
11846 | to_intel_crtc_state(crtc_state)->disable_lp_wm = true; | |
11847 | } else if (turn_off && !mode_changed) { | |
da20eabd ML |
11848 | intel_crtc->atomic.wait_vblank = true; |
11849 | intel_crtc->atomic.update_sprite_watermarks |= | |
11850 | 1 << i; | |
11851 | } | |
d21fbe87 MR |
11852 | |
11853 | break; | |
da20eabd ML |
11854 | } |
11855 | return 0; | |
11856 | } | |
11857 | ||
6d3a1ce7 ML |
11858 | static bool encoders_cloneable(const struct intel_encoder *a, |
11859 | const struct intel_encoder *b) | |
11860 | { | |
11861 | /* masks could be asymmetric, so check both ways */ | |
11862 | return a == b || (a->cloneable & (1 << b->type) && | |
11863 | b->cloneable & (1 << a->type)); | |
11864 | } | |
11865 | ||
11866 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11867 | struct intel_crtc *crtc, | |
11868 | struct intel_encoder *encoder) | |
11869 | { | |
11870 | struct intel_encoder *source_encoder; | |
11871 | struct drm_connector *connector; | |
11872 | struct drm_connector_state *connector_state; | |
11873 | int i; | |
11874 | ||
11875 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11876 | if (connector_state->crtc != &crtc->base) | |
11877 | continue; | |
11878 | ||
11879 | source_encoder = | |
11880 | to_intel_encoder(connector_state->best_encoder); | |
11881 | if (!encoders_cloneable(encoder, source_encoder)) | |
11882 | return false; | |
11883 | } | |
11884 | ||
11885 | return true; | |
11886 | } | |
11887 | ||
11888 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11889 | struct intel_crtc *crtc) | |
11890 | { | |
11891 | struct intel_encoder *encoder; | |
11892 | struct drm_connector *connector; | |
11893 | struct drm_connector_state *connector_state; | |
11894 | int i; | |
11895 | ||
11896 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11897 | if (connector_state->crtc != &crtc->base) | |
11898 | continue; | |
11899 | ||
11900 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11901 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11902 | return false; | |
11903 | } | |
11904 | ||
11905 | return true; | |
11906 | } | |
11907 | ||
11908 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11909 | struct drm_crtc_state *crtc_state) | |
11910 | { | |
cf5a15be | 11911 | struct drm_device *dev = crtc->dev; |
ad421372 | 11912 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11913 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11914 | struct intel_crtc_state *pipe_config = |
11915 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11916 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 11917 | int ret; |
6d3a1ce7 ML |
11918 | bool mode_changed = needs_modeset(crtc_state); |
11919 | ||
11920 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11921 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11922 | return -EINVAL; | |
11923 | } | |
11924 | ||
852eb00d VS |
11925 | if (mode_changed && !crtc_state->active) |
11926 | intel_crtc->atomic.update_wm_post = true; | |
eddfcbcd | 11927 | |
ad421372 ML |
11928 | if (mode_changed && crtc_state->enable && |
11929 | dev_priv->display.crtc_compute_clock && | |
11930 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11931 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11932 | pipe_config); | |
11933 | if (ret) | |
11934 | return ret; | |
11935 | } | |
11936 | ||
e435d6e5 | 11937 | ret = 0; |
86c8bbbe MR |
11938 | if (dev_priv->display.compute_pipe_wm) { |
11939 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
11940 | if (ret) | |
11941 | return ret; | |
11942 | } | |
11943 | ||
e435d6e5 ML |
11944 | if (INTEL_INFO(dev)->gen >= 9) { |
11945 | if (mode_changed) | |
11946 | ret = skl_update_scaler_crtc(pipe_config); | |
11947 | ||
11948 | if (!ret) | |
11949 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
11950 | pipe_config); | |
11951 | } | |
11952 | ||
11953 | return ret; | |
6d3a1ce7 ML |
11954 | } |
11955 | ||
65b38e0d | 11956 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11957 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11958 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11959 | .atomic_begin = intel_begin_crtc_commit, |
11960 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11961 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11962 | }; |
11963 | ||
d29b2f9d ACO |
11964 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
11965 | { | |
11966 | struct intel_connector *connector; | |
11967 | ||
11968 | for_each_intel_connector(dev, connector) { | |
11969 | if (connector->base.encoder) { | |
11970 | connector->base.state->best_encoder = | |
11971 | connector->base.encoder; | |
11972 | connector->base.state->crtc = | |
11973 | connector->base.encoder->crtc; | |
11974 | } else { | |
11975 | connector->base.state->best_encoder = NULL; | |
11976 | connector->base.state->crtc = NULL; | |
11977 | } | |
11978 | } | |
11979 | } | |
11980 | ||
050f7aeb | 11981 | static void |
eba905b2 | 11982 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11983 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11984 | { |
11985 | int bpp = pipe_config->pipe_bpp; | |
11986 | ||
11987 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11988 | connector->base.base.id, | |
c23cc417 | 11989 | connector->base.name); |
050f7aeb DV |
11990 | |
11991 | /* Don't use an invalid EDID bpc value */ | |
11992 | if (connector->base.display_info.bpc && | |
11993 | connector->base.display_info.bpc * 3 < bpp) { | |
11994 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11995 | bpp, connector->base.display_info.bpc*3); | |
11996 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11997 | } | |
11998 | ||
11999 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
12000 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
12001 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
12002 | bpp); | |
12003 | pipe_config->pipe_bpp = 24; | |
12004 | } | |
12005 | } | |
12006 | ||
4e53c2e0 | 12007 | static int |
050f7aeb | 12008 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 12009 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 12010 | { |
050f7aeb | 12011 | struct drm_device *dev = crtc->base.dev; |
1486017f | 12012 | struct drm_atomic_state *state; |
da3ced29 ACO |
12013 | struct drm_connector *connector; |
12014 | struct drm_connector_state *connector_state; | |
1486017f | 12015 | int bpp, i; |
4e53c2e0 | 12016 | |
d328c9d7 | 12017 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 12018 | bpp = 10*3; |
d328c9d7 DV |
12019 | else if (INTEL_INFO(dev)->gen >= 5) |
12020 | bpp = 12*3; | |
12021 | else | |
12022 | bpp = 8*3; | |
12023 | ||
4e53c2e0 | 12024 | |
4e53c2e0 DV |
12025 | pipe_config->pipe_bpp = bpp; |
12026 | ||
1486017f ACO |
12027 | state = pipe_config->base.state; |
12028 | ||
4e53c2e0 | 12029 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
12030 | for_each_connector_in_state(state, connector, connector_state, i) { |
12031 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
12032 | continue; |
12033 | ||
da3ced29 ACO |
12034 | connected_sink_compute_bpp(to_intel_connector(connector), |
12035 | pipe_config); | |
4e53c2e0 DV |
12036 | } |
12037 | ||
12038 | return bpp; | |
12039 | } | |
12040 | ||
644db711 DV |
12041 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
12042 | { | |
12043 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
12044 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 12045 | mode->crtc_clock, |
644db711 DV |
12046 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
12047 | mode->crtc_hsync_end, mode->crtc_htotal, | |
12048 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
12049 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
12050 | } | |
12051 | ||
c0b03411 | 12052 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 12053 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
12054 | const char *context) |
12055 | { | |
6a60cd87 CK |
12056 | struct drm_device *dev = crtc->base.dev; |
12057 | struct drm_plane *plane; | |
12058 | struct intel_plane *intel_plane; | |
12059 | struct intel_plane_state *state; | |
12060 | struct drm_framebuffer *fb; | |
12061 | ||
12062 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
12063 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
12064 | |
12065 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
12066 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
12067 | pipe_config->pipe_bpp, pipe_config->dither); | |
12068 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12069 | pipe_config->has_pch_encoder, | |
12070 | pipe_config->fdi_lanes, | |
12071 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
12072 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
12073 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 12074 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 12075 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12076 | pipe_config->lane_count, |
eb14cb74 VS |
12077 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
12078 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
12079 | pipe_config->dp_m_n.tu); | |
b95af8be | 12080 | |
90a6b7b0 | 12081 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 12082 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12083 | pipe_config->lane_count, |
b95af8be VK |
12084 | pipe_config->dp_m2_n2.gmch_m, |
12085 | pipe_config->dp_m2_n2.gmch_n, | |
12086 | pipe_config->dp_m2_n2.link_m, | |
12087 | pipe_config->dp_m2_n2.link_n, | |
12088 | pipe_config->dp_m2_n2.tu); | |
12089 | ||
55072d19 DV |
12090 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
12091 | pipe_config->has_audio, | |
12092 | pipe_config->has_infoframe); | |
12093 | ||
c0b03411 | 12094 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 12095 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 12096 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
12097 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
12098 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 12099 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
12100 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
12101 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
12102 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
12103 | crtc->num_scalers, | |
12104 | pipe_config->scaler_state.scaler_users, | |
12105 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
12106 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12107 | pipe_config->gmch_pfit.control, | |
12108 | pipe_config->gmch_pfit.pgm_ratios, | |
12109 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12110 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12111 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12112 | pipe_config->pch_pfit.size, |
12113 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12114 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12115 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12116 | |
415ff0f6 | 12117 | if (IS_BROXTON(dev)) { |
05712c15 | 12118 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12119 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12120 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12121 | pipe_config->ddi_pll_sel, |
12122 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12123 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12124 | pipe_config->dpll_hw_state.pll0, |
12125 | pipe_config->dpll_hw_state.pll1, | |
12126 | pipe_config->dpll_hw_state.pll2, | |
12127 | pipe_config->dpll_hw_state.pll3, | |
12128 | pipe_config->dpll_hw_state.pll6, | |
12129 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12130 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12131 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12132 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12133 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12134 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12135 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12136 | pipe_config->ddi_pll_sel, | |
12137 | pipe_config->dpll_hw_state.ctrl1, | |
12138 | pipe_config->dpll_hw_state.cfgcr1, | |
12139 | pipe_config->dpll_hw_state.cfgcr2); | |
12140 | } else if (HAS_DDI(dev)) { | |
00490c22 | 12141 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", |
415ff0f6 | 12142 | pipe_config->ddi_pll_sel, |
00490c22 ML |
12143 | pipe_config->dpll_hw_state.wrpll, |
12144 | pipe_config->dpll_hw_state.spll); | |
415ff0f6 TU |
12145 | } else { |
12146 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12147 | "fp0: 0x%x, fp1: 0x%x\n", | |
12148 | pipe_config->dpll_hw_state.dpll, | |
12149 | pipe_config->dpll_hw_state.dpll_md, | |
12150 | pipe_config->dpll_hw_state.fp0, | |
12151 | pipe_config->dpll_hw_state.fp1); | |
12152 | } | |
12153 | ||
6a60cd87 CK |
12154 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12155 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12156 | intel_plane = to_intel_plane(plane); | |
12157 | if (intel_plane->pipe != crtc->pipe) | |
12158 | continue; | |
12159 | ||
12160 | state = to_intel_plane_state(plane->state); | |
12161 | fb = state->base.fb; | |
12162 | if (!fb) { | |
12163 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12164 | "disabled, scaler_id = %d\n", | |
12165 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12166 | plane->base.id, intel_plane->pipe, | |
12167 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12168 | drm_plane_index(plane), state->scaler_id); | |
12169 | continue; | |
12170 | } | |
12171 | ||
12172 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12173 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12174 | plane->base.id, intel_plane->pipe, | |
12175 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12176 | drm_plane_index(plane)); | |
12177 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12178 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12179 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12180 | state->scaler_id, | |
12181 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12182 | drm_rect_width(&state->src) >> 16, | |
12183 | drm_rect_height(&state->src) >> 16, | |
12184 | state->dst.x1, state->dst.y1, | |
12185 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12186 | } | |
c0b03411 DV |
12187 | } |
12188 | ||
5448a00d | 12189 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12190 | { |
5448a00d ACO |
12191 | struct drm_device *dev = state->dev; |
12192 | struct intel_encoder *encoder; | |
da3ced29 | 12193 | struct drm_connector *connector; |
5448a00d | 12194 | struct drm_connector_state *connector_state; |
00f0b378 | 12195 | unsigned int used_ports = 0; |
5448a00d | 12196 | int i; |
00f0b378 VS |
12197 | |
12198 | /* | |
12199 | * Walk the connector list instead of the encoder | |
12200 | * list to detect the problem on ddi platforms | |
12201 | * where there's just one encoder per digital port. | |
12202 | */ | |
da3ced29 | 12203 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12204 | if (!connector_state->best_encoder) |
00f0b378 VS |
12205 | continue; |
12206 | ||
5448a00d ACO |
12207 | encoder = to_intel_encoder(connector_state->best_encoder); |
12208 | ||
12209 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12210 | |
12211 | switch (encoder->type) { | |
12212 | unsigned int port_mask; | |
12213 | case INTEL_OUTPUT_UNKNOWN: | |
12214 | if (WARN_ON(!HAS_DDI(dev))) | |
12215 | break; | |
12216 | case INTEL_OUTPUT_DISPLAYPORT: | |
12217 | case INTEL_OUTPUT_HDMI: | |
12218 | case INTEL_OUTPUT_EDP: | |
12219 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12220 | ||
12221 | /* the same port mustn't appear more than once */ | |
12222 | if (used_ports & port_mask) | |
12223 | return false; | |
12224 | ||
12225 | used_ports |= port_mask; | |
12226 | default: | |
12227 | break; | |
12228 | } | |
12229 | } | |
12230 | ||
12231 | return true; | |
12232 | } | |
12233 | ||
83a57153 ACO |
12234 | static void |
12235 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12236 | { | |
12237 | struct drm_crtc_state tmp_state; | |
663a3640 | 12238 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12239 | struct intel_dpll_hw_state dpll_hw_state; |
12240 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12241 | uint32_t ddi_pll_sel; |
c4e2d043 | 12242 | bool force_thru; |
83a57153 | 12243 | |
7546a384 ACO |
12244 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12245 | * kzalloc'd. Code that depends on any field being zero should be | |
12246 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12247 | * only fields that are know to not cause problems are preserved. */ | |
12248 | ||
83a57153 | 12249 | tmp_state = crtc_state->base; |
663a3640 | 12250 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12251 | shared_dpll = crtc_state->shared_dpll; |
12252 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12253 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12254 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12255 | |
83a57153 | 12256 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12257 | |
83a57153 | 12258 | crtc_state->base = tmp_state; |
663a3640 | 12259 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12260 | crtc_state->shared_dpll = shared_dpll; |
12261 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12262 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12263 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12264 | } |
12265 | ||
548ee15b | 12266 | static int |
b8cecdf5 | 12267 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12268 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12269 | { |
b359283a | 12270 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12271 | struct intel_encoder *encoder; |
da3ced29 | 12272 | struct drm_connector *connector; |
0b901879 | 12273 | struct drm_connector_state *connector_state; |
d328c9d7 | 12274 | int base_bpp, ret = -EINVAL; |
0b901879 | 12275 | int i; |
e29c22c0 | 12276 | bool retry = true; |
ee7b9f93 | 12277 | |
83a57153 | 12278 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12279 | |
e143a21c DV |
12280 | pipe_config->cpu_transcoder = |
12281 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12282 | |
2960bc9c ID |
12283 | /* |
12284 | * Sanitize sync polarity flags based on requested ones. If neither | |
12285 | * positive or negative polarity is requested, treat this as meaning | |
12286 | * negative polarity. | |
12287 | */ | |
2d112de7 | 12288 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12289 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12290 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12291 | |
2d112de7 | 12292 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12293 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12294 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12295 | |
d328c9d7 DV |
12296 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12297 | pipe_config); | |
12298 | if (base_bpp < 0) | |
4e53c2e0 DV |
12299 | goto fail; |
12300 | ||
e41a56be VS |
12301 | /* |
12302 | * Determine the real pipe dimensions. Note that stereo modes can | |
12303 | * increase the actual pipe size due to the frame doubling and | |
12304 | * insertion of additional space for blanks between the frame. This | |
12305 | * is stored in the crtc timings. We use the requested mode to do this | |
12306 | * computation to clearly distinguish it from the adjusted mode, which | |
12307 | * can be changed by the connectors in the below retry loop. | |
12308 | */ | |
2d112de7 | 12309 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12310 | &pipe_config->pipe_src_w, |
12311 | &pipe_config->pipe_src_h); | |
e41a56be | 12312 | |
e29c22c0 | 12313 | encoder_retry: |
ef1b460d | 12314 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12315 | pipe_config->port_clock = 0; |
ef1b460d | 12316 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12317 | |
135c81b8 | 12318 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12319 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12320 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12321 | |
7758a113 DV |
12322 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12323 | * adjust it according to limitations or connector properties, and also | |
12324 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12325 | */ |
da3ced29 | 12326 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12327 | if (connector_state->crtc != crtc) |
7758a113 | 12328 | continue; |
7ae89233 | 12329 | |
0b901879 ACO |
12330 | encoder = to_intel_encoder(connector_state->best_encoder); |
12331 | ||
efea6e8e DV |
12332 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12333 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12334 | goto fail; |
12335 | } | |
ee7b9f93 | 12336 | } |
47f1c6c9 | 12337 | |
ff9a6750 DV |
12338 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12339 | * done afterwards in case the encoder adjusts the mode. */ | |
12340 | if (!pipe_config->port_clock) | |
2d112de7 | 12341 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12342 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12343 | |
a43f6e0f | 12344 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12345 | if (ret < 0) { |
7758a113 DV |
12346 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12347 | goto fail; | |
ee7b9f93 | 12348 | } |
e29c22c0 DV |
12349 | |
12350 | if (ret == RETRY) { | |
12351 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12352 | ret = -EINVAL; | |
12353 | goto fail; | |
12354 | } | |
12355 | ||
12356 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12357 | retry = false; | |
12358 | goto encoder_retry; | |
12359 | } | |
12360 | ||
e8fa4270 DV |
12361 | /* Dithering seems to not pass-through bits correctly when it should, so |
12362 | * only enable it on 6bpc panels. */ | |
12363 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12364 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12365 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12366 | |
7758a113 | 12367 | fail: |
548ee15b | 12368 | return ret; |
ee7b9f93 | 12369 | } |
47f1c6c9 | 12370 | |
ea9d758d | 12371 | static void |
4740b0f2 | 12372 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12373 | { |
0a9ab303 ACO |
12374 | struct drm_crtc *crtc; |
12375 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12376 | int i; |
ea9d758d | 12377 | |
7668851f | 12378 | /* Double check state. */ |
8a75d157 | 12379 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12380 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12381 | |
12382 | /* Update hwmode for vblank functions */ | |
12383 | if (crtc->state->active) | |
12384 | crtc->hwmode = crtc->state->adjusted_mode; | |
12385 | else | |
12386 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12387 | |
12388 | /* | |
12389 | * Update legacy state to satisfy fbc code. This can | |
12390 | * be removed when fbc uses the atomic state. | |
12391 | */ | |
12392 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12393 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12394 | ||
12395 | crtc->primary->fb = plane_state->fb; | |
12396 | crtc->x = plane_state->src_x >> 16; | |
12397 | crtc->y = plane_state->src_y >> 16; | |
12398 | } | |
ea9d758d | 12399 | } |
ea9d758d DV |
12400 | } |
12401 | ||
3bd26263 | 12402 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12403 | { |
3bd26263 | 12404 | int diff; |
f1f644dc JB |
12405 | |
12406 | if (clock1 == clock2) | |
12407 | return true; | |
12408 | ||
12409 | if (!clock1 || !clock2) | |
12410 | return false; | |
12411 | ||
12412 | diff = abs(clock1 - clock2); | |
12413 | ||
12414 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12415 | return true; | |
12416 | ||
12417 | return false; | |
12418 | } | |
12419 | ||
25c5b266 DV |
12420 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12421 | list_for_each_entry((intel_crtc), \ | |
12422 | &(dev)->mode_config.crtc_list, \ | |
12423 | base.head) \ | |
0973f18f | 12424 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12425 | |
cfb23ed6 ML |
12426 | static bool |
12427 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12428 | unsigned int m2, unsigned int n2, | |
12429 | bool exact) | |
12430 | { | |
12431 | if (m == m2 && n == n2) | |
12432 | return true; | |
12433 | ||
12434 | if (exact || !m || !n || !m2 || !n2) | |
12435 | return false; | |
12436 | ||
12437 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12438 | ||
12439 | if (m > m2) { | |
12440 | while (m > m2) { | |
12441 | m2 <<= 1; | |
12442 | n2 <<= 1; | |
12443 | } | |
12444 | } else if (m < m2) { | |
12445 | while (m < m2) { | |
12446 | m <<= 1; | |
12447 | n <<= 1; | |
12448 | } | |
12449 | } | |
12450 | ||
12451 | return m == m2 && n == n2; | |
12452 | } | |
12453 | ||
12454 | static bool | |
12455 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12456 | struct intel_link_m_n *m2_n2, | |
12457 | bool adjust) | |
12458 | { | |
12459 | if (m_n->tu == m2_n2->tu && | |
12460 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12461 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12462 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12463 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12464 | if (adjust) | |
12465 | *m2_n2 = *m_n; | |
12466 | ||
12467 | return true; | |
12468 | } | |
12469 | ||
12470 | return false; | |
12471 | } | |
12472 | ||
0e8ffe1b | 12473 | static bool |
2fa2fe9a | 12474 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12475 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12476 | struct intel_crtc_state *pipe_config, |
12477 | bool adjust) | |
0e8ffe1b | 12478 | { |
cfb23ed6 ML |
12479 | bool ret = true; |
12480 | ||
12481 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12482 | do { \ | |
12483 | if (!adjust) \ | |
12484 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12485 | else \ | |
12486 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12487 | } while (0) | |
12488 | ||
66e985c0 DV |
12489 | #define PIPE_CONF_CHECK_X(name) \ |
12490 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12491 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12492 | "(expected 0x%08x, found 0x%08x)\n", \ |
12493 | current_config->name, \ | |
12494 | pipe_config->name); \ | |
cfb23ed6 | 12495 | ret = false; \ |
66e985c0 DV |
12496 | } |
12497 | ||
08a24034 DV |
12498 | #define PIPE_CONF_CHECK_I(name) \ |
12499 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12500 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12501 | "(expected %i, found %i)\n", \ |
12502 | current_config->name, \ | |
12503 | pipe_config->name); \ | |
cfb23ed6 ML |
12504 | ret = false; \ |
12505 | } | |
12506 | ||
12507 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12508 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12509 | &pipe_config->name,\ | |
12510 | adjust)) { \ | |
12511 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12512 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12513 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12514 | current_config->name.tu, \ | |
12515 | current_config->name.gmch_m, \ | |
12516 | current_config->name.gmch_n, \ | |
12517 | current_config->name.link_m, \ | |
12518 | current_config->name.link_n, \ | |
12519 | pipe_config->name.tu, \ | |
12520 | pipe_config->name.gmch_m, \ | |
12521 | pipe_config->name.gmch_n, \ | |
12522 | pipe_config->name.link_m, \ | |
12523 | pipe_config->name.link_n); \ | |
12524 | ret = false; \ | |
12525 | } | |
12526 | ||
12527 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12528 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12529 | &pipe_config->name, adjust) && \ | |
12530 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12531 | &pipe_config->name, adjust)) { \ | |
12532 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12533 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12534 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12535 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12536 | current_config->name.tu, \ | |
12537 | current_config->name.gmch_m, \ | |
12538 | current_config->name.gmch_n, \ | |
12539 | current_config->name.link_m, \ | |
12540 | current_config->name.link_n, \ | |
12541 | current_config->alt_name.tu, \ | |
12542 | current_config->alt_name.gmch_m, \ | |
12543 | current_config->alt_name.gmch_n, \ | |
12544 | current_config->alt_name.link_m, \ | |
12545 | current_config->alt_name.link_n, \ | |
12546 | pipe_config->name.tu, \ | |
12547 | pipe_config->name.gmch_m, \ | |
12548 | pipe_config->name.gmch_n, \ | |
12549 | pipe_config->name.link_m, \ | |
12550 | pipe_config->name.link_n); \ | |
12551 | ret = false; \ | |
88adfff1 DV |
12552 | } |
12553 | ||
b95af8be VK |
12554 | /* This is required for BDW+ where there is only one set of registers for |
12555 | * switching between high and low RR. | |
12556 | * This macro can be used whenever a comparison has to be made between one | |
12557 | * hw state and multiple sw state variables. | |
12558 | */ | |
12559 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12560 | if ((current_config->name != pipe_config->name) && \ | |
12561 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12562 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12563 | "(expected %i or %i, found %i)\n", \ |
12564 | current_config->name, \ | |
12565 | current_config->alt_name, \ | |
12566 | pipe_config->name); \ | |
cfb23ed6 | 12567 | ret = false; \ |
b95af8be VK |
12568 | } |
12569 | ||
1bd1bd80 DV |
12570 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12571 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12572 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12573 | "(expected %i, found %i)\n", \ |
12574 | current_config->name & (mask), \ | |
12575 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12576 | ret = false; \ |
1bd1bd80 DV |
12577 | } |
12578 | ||
5e550656 VS |
12579 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12580 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12581 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12582 | "(expected %i, found %i)\n", \ |
12583 | current_config->name, \ | |
12584 | pipe_config->name); \ | |
cfb23ed6 | 12585 | ret = false; \ |
5e550656 VS |
12586 | } |
12587 | ||
bb760063 DV |
12588 | #define PIPE_CONF_QUIRK(quirk) \ |
12589 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12590 | ||
eccb140b DV |
12591 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12592 | ||
08a24034 DV |
12593 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12594 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12595 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12596 | |
eb14cb74 | 12597 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12598 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12599 | |
12600 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12601 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12602 | ||
12603 | PIPE_CONF_CHECK_I(has_drrs); | |
12604 | if (current_config->has_drrs) | |
12605 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12606 | } else | |
12607 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12608 | |
2d112de7 ACO |
12609 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12610 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12611 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12612 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12613 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12614 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12615 | |
2d112de7 ACO |
12616 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12617 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12618 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12619 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12620 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12621 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12622 | |
c93f54cf | 12623 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12624 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12625 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12626 | IS_VALLEYVIEW(dev)) | |
12627 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12628 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12629 | |
9ed109a7 DV |
12630 | PIPE_CONF_CHECK_I(has_audio); |
12631 | ||
2d112de7 | 12632 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12633 | DRM_MODE_FLAG_INTERLACE); |
12634 | ||
bb760063 | 12635 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12636 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12637 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12638 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12639 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12640 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12641 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12642 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12643 | DRM_MODE_FLAG_NVSYNC); |
12644 | } | |
045ac3b5 | 12645 | |
333b8ca8 | 12646 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12647 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12648 | if (INTEL_INFO(dev)->gen < 4) | |
12649 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
333b8ca8 | 12650 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12651 | |
bfd16b2a ML |
12652 | if (!adjust) { |
12653 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12654 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12655 | ||
12656 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12657 | if (current_config->pch_pfit.enabled) { | |
12658 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12659 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12660 | } | |
2fa2fe9a | 12661 | |
7aefe2b5 ML |
12662 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12663 | } | |
a1b2278e | 12664 | |
e59150dc JB |
12665 | /* BDW+ don't expose a synchronous way to read the state */ |
12666 | if (IS_HASWELL(dev)) | |
12667 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12668 | |
282740f7 VS |
12669 | PIPE_CONF_CHECK_I(double_wide); |
12670 | ||
26804afd DV |
12671 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12672 | ||
c0d43d62 | 12673 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12674 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12675 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12676 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12677 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12678 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
00490c22 | 12679 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
3f4cd19f DL |
12680 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12681 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12682 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12683 | |
42571aef VS |
12684 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12685 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12686 | ||
2d112de7 | 12687 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12688 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12689 | |
66e985c0 | 12690 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12691 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12692 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12693 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12694 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12695 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12696 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12697 | |
cfb23ed6 | 12698 | return ret; |
0e8ffe1b DV |
12699 | } |
12700 | ||
08db6652 DL |
12701 | static void check_wm_state(struct drm_device *dev) |
12702 | { | |
12703 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12704 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12705 | struct intel_crtc *intel_crtc; | |
12706 | int plane; | |
12707 | ||
12708 | if (INTEL_INFO(dev)->gen < 9) | |
12709 | return; | |
12710 | ||
12711 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12712 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12713 | ||
12714 | for_each_intel_crtc(dev, intel_crtc) { | |
12715 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12716 | const enum pipe pipe = intel_crtc->pipe; | |
12717 | ||
12718 | if (!intel_crtc->active) | |
12719 | continue; | |
12720 | ||
12721 | /* planes */ | |
dd740780 | 12722 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12723 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12724 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12725 | ||
12726 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12727 | continue; | |
12728 | ||
12729 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12730 | "(expected (%u,%u), found (%u,%u))\n", | |
12731 | pipe_name(pipe), plane + 1, | |
12732 | sw_entry->start, sw_entry->end, | |
12733 | hw_entry->start, hw_entry->end); | |
12734 | } | |
12735 | ||
12736 | /* cursor */ | |
4969d33e MR |
12737 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
12738 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 DL |
12739 | |
12740 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12741 | continue; | |
12742 | ||
12743 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12744 | "(expected (%u,%u), found (%u,%u))\n", | |
12745 | pipe_name(pipe), | |
12746 | sw_entry->start, sw_entry->end, | |
12747 | hw_entry->start, hw_entry->end); | |
12748 | } | |
12749 | } | |
12750 | ||
91d1b4bd | 12751 | static void |
35dd3c64 ML |
12752 | check_connector_state(struct drm_device *dev, |
12753 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12754 | { |
35dd3c64 ML |
12755 | struct drm_connector_state *old_conn_state; |
12756 | struct drm_connector *connector; | |
12757 | int i; | |
8af6cf88 | 12758 | |
35dd3c64 ML |
12759 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12760 | struct drm_encoder *encoder = connector->encoder; | |
12761 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12762 | |
8af6cf88 DV |
12763 | /* This also checks the encoder/connector hw state with the |
12764 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12765 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12766 | |
ad3c558f | 12767 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12768 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12769 | } |
91d1b4bd DV |
12770 | } |
12771 | ||
12772 | static void | |
12773 | check_encoder_state(struct drm_device *dev) | |
12774 | { | |
12775 | struct intel_encoder *encoder; | |
12776 | struct intel_connector *connector; | |
8af6cf88 | 12777 | |
b2784e15 | 12778 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12779 | bool enabled = false; |
4d20cd86 | 12780 | enum pipe pipe; |
8af6cf88 DV |
12781 | |
12782 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12783 | encoder->base.base.id, | |
8e329a03 | 12784 | encoder->base.name); |
8af6cf88 | 12785 | |
3a3371ff | 12786 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12787 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12788 | continue; |
12789 | enabled = true; | |
ad3c558f ML |
12790 | |
12791 | I915_STATE_WARN(connector->base.state->crtc != | |
12792 | encoder->base.crtc, | |
12793 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12794 | } |
0e32b39c | 12795 | |
e2c719b7 | 12796 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12797 | "encoder's enabled state mismatch " |
12798 | "(expected %i, found %i)\n", | |
12799 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12800 | |
12801 | if (!encoder->base.crtc) { | |
4d20cd86 | 12802 | bool active; |
7c60d198 | 12803 | |
4d20cd86 ML |
12804 | active = encoder->get_hw_state(encoder, &pipe); |
12805 | I915_STATE_WARN(active, | |
12806 | "encoder detached but still enabled on pipe %c.\n", | |
12807 | pipe_name(pipe)); | |
7c60d198 | 12808 | } |
8af6cf88 | 12809 | } |
91d1b4bd DV |
12810 | } |
12811 | ||
12812 | static void | |
4d20cd86 | 12813 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12814 | { |
fbee40df | 12815 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12816 | struct intel_encoder *encoder; |
4d20cd86 ML |
12817 | struct drm_crtc_state *old_crtc_state; |
12818 | struct drm_crtc *crtc; | |
12819 | int i; | |
8af6cf88 | 12820 | |
4d20cd86 ML |
12821 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12823 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12824 | bool active; |
8af6cf88 | 12825 | |
bfd16b2a ML |
12826 | if (!needs_modeset(crtc->state) && |
12827 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
4d20cd86 | 12828 | continue; |
045ac3b5 | 12829 | |
4d20cd86 ML |
12830 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
12831 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
12832 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
12833 | pipe_config->base.crtc = crtc; | |
12834 | pipe_config->base.state = old_state; | |
8af6cf88 | 12835 | |
4d20cd86 ML |
12836 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12837 | crtc->base.id); | |
8af6cf88 | 12838 | |
4d20cd86 ML |
12839 | active = dev_priv->display.get_pipe_config(intel_crtc, |
12840 | pipe_config); | |
d62cf62a | 12841 | |
b6b5d049 | 12842 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
12843 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
12844 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
12845 | active = crtc->state->active; | |
6c49f241 | 12846 | |
4d20cd86 | 12847 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 12848 | "crtc active state doesn't match with hw state " |
4d20cd86 | 12849 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 12850 | |
4d20cd86 | 12851 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 12852 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
12853 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
12854 | ||
12855 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
12856 | enum pipe pipe; | |
12857 | ||
12858 | active = encoder->get_hw_state(encoder, &pipe); | |
12859 | I915_STATE_WARN(active != crtc->state->active, | |
12860 | "[ENCODER:%i] active %i with crtc active %i\n", | |
12861 | encoder->base.base.id, active, crtc->state->active); | |
12862 | ||
12863 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
12864 | "Encoder connected to wrong pipe %c\n", | |
12865 | pipe_name(pipe)); | |
12866 | ||
12867 | if (active) | |
12868 | encoder->get_config(encoder, pipe_config); | |
12869 | } | |
53d9f4e9 | 12870 | |
4d20cd86 | 12871 | if (!crtc->state->active) |
cfb23ed6 ML |
12872 | continue; |
12873 | ||
4d20cd86 ML |
12874 | sw_config = to_intel_crtc_state(crtc->state); |
12875 | if (!intel_pipe_config_compare(dev, sw_config, | |
12876 | pipe_config, false)) { | |
e2c719b7 | 12877 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 12878 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 12879 | "[hw state]"); |
4d20cd86 | 12880 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
12881 | "[sw state]"); |
12882 | } | |
8af6cf88 DV |
12883 | } |
12884 | } | |
12885 | ||
91d1b4bd DV |
12886 | static void |
12887 | check_shared_dpll_state(struct drm_device *dev) | |
12888 | { | |
fbee40df | 12889 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12890 | struct intel_crtc *crtc; |
12891 | struct intel_dpll_hw_state dpll_hw_state; | |
12892 | int i; | |
5358901f DV |
12893 | |
12894 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12895 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12896 | int enabled_crtcs = 0, active_crtcs = 0; | |
12897 | bool active; | |
12898 | ||
12899 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12900 | ||
12901 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12902 | ||
12903 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12904 | ||
e2c719b7 | 12905 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12906 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12907 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12908 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12909 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12910 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12911 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12912 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12913 | "pll on state mismatch (expected %i, found %i)\n", |
12914 | pll->on, active); | |
12915 | ||
d3fcc808 | 12916 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12917 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12918 | enabled_crtcs++; |
12919 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12920 | active_crtcs++; | |
12921 | } | |
e2c719b7 | 12922 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12923 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12924 | pll->active, active_crtcs); | |
e2c719b7 | 12925 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12926 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12927 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12928 | |
e2c719b7 | 12929 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12930 | sizeof(dpll_hw_state)), |
12931 | "pll hw state mismatch\n"); | |
5358901f | 12932 | } |
8af6cf88 DV |
12933 | } |
12934 | ||
ee165b1a ML |
12935 | static void |
12936 | intel_modeset_check_state(struct drm_device *dev, | |
12937 | struct drm_atomic_state *old_state) | |
91d1b4bd | 12938 | { |
08db6652 | 12939 | check_wm_state(dev); |
35dd3c64 | 12940 | check_connector_state(dev, old_state); |
91d1b4bd | 12941 | check_encoder_state(dev); |
4d20cd86 | 12942 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
12943 | check_shared_dpll_state(dev); |
12944 | } | |
12945 | ||
5cec258b | 12946 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12947 | int dotclock) |
12948 | { | |
12949 | /* | |
12950 | * FDI already provided one idea for the dotclock. | |
12951 | * Yell if the encoder disagrees. | |
12952 | */ | |
2d112de7 | 12953 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12954 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12955 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12956 | } |
12957 | ||
80715b2f VS |
12958 | static void update_scanline_offset(struct intel_crtc *crtc) |
12959 | { | |
12960 | struct drm_device *dev = crtc->base.dev; | |
12961 | ||
12962 | /* | |
12963 | * The scanline counter increments at the leading edge of hsync. | |
12964 | * | |
12965 | * On most platforms it starts counting from vtotal-1 on the | |
12966 | * first active line. That means the scanline counter value is | |
12967 | * always one less than what we would expect. Ie. just after | |
12968 | * start of vblank, which also occurs at start of hsync (on the | |
12969 | * last active line), the scanline counter will read vblank_start-1. | |
12970 | * | |
12971 | * On gen2 the scanline counter starts counting from 1 instead | |
12972 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12973 | * to keep the value positive), instead of adding one. | |
12974 | * | |
12975 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12976 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12977 | * there's an extra 1 line difference. So we need to add two instead of | |
12978 | * one to the value. | |
12979 | */ | |
12980 | if (IS_GEN2(dev)) { | |
124abe07 | 12981 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12982 | int vtotal; |
12983 | ||
124abe07 VS |
12984 | vtotal = adjusted_mode->crtc_vtotal; |
12985 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
12986 | vtotal /= 2; |
12987 | ||
12988 | crtc->scanline_offset = vtotal - 1; | |
12989 | } else if (HAS_DDI(dev) && | |
409ee761 | 12990 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12991 | crtc->scanline_offset = 2; |
12992 | } else | |
12993 | crtc->scanline_offset = 1; | |
12994 | } | |
12995 | ||
ad421372 | 12996 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 12997 | { |
225da59b | 12998 | struct drm_device *dev = state->dev; |
ed6739ef | 12999 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 13000 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 13001 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
13002 | struct intel_crtc_state *intel_crtc_state; |
13003 | struct drm_crtc *crtc; | |
13004 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 13005 | int i; |
ed6739ef ACO |
13006 | |
13007 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 13008 | return; |
ed6739ef | 13009 | |
0a9ab303 | 13010 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
13011 | int dpll; |
13012 | ||
0a9ab303 | 13013 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 13014 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 13015 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 13016 | |
ad421372 | 13017 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
13018 | continue; |
13019 | ||
ad421372 | 13020 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 13021 | |
ad421372 ML |
13022 | if (!shared_dpll) |
13023 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 13024 | |
ad421372 ML |
13025 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
13026 | } | |
ed6739ef ACO |
13027 | } |
13028 | ||
99d736a2 ML |
13029 | /* |
13030 | * This implements the workaround described in the "notes" section of the mode | |
13031 | * set sequence documentation. When going from no pipes or single pipe to | |
13032 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
13033 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
13034 | */ | |
13035 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
13036 | { | |
13037 | struct drm_crtc_state *crtc_state; | |
13038 | struct intel_crtc *intel_crtc; | |
13039 | struct drm_crtc *crtc; | |
13040 | struct intel_crtc_state *first_crtc_state = NULL; | |
13041 | struct intel_crtc_state *other_crtc_state = NULL; | |
13042 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
13043 | int i; | |
13044 | ||
13045 | /* look at all crtc's that are going to be enabled in during modeset */ | |
13046 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13047 | intel_crtc = to_intel_crtc(crtc); | |
13048 | ||
13049 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
13050 | continue; | |
13051 | ||
13052 | if (first_crtc_state) { | |
13053 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
13054 | break; | |
13055 | } else { | |
13056 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
13057 | first_pipe = intel_crtc->pipe; | |
13058 | } | |
13059 | } | |
13060 | ||
13061 | /* No workaround needed? */ | |
13062 | if (!first_crtc_state) | |
13063 | return 0; | |
13064 | ||
13065 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
13066 | for_each_intel_crtc(state->dev, intel_crtc) { | |
13067 | struct intel_crtc_state *pipe_config; | |
13068 | ||
13069 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
13070 | if (IS_ERR(pipe_config)) | |
13071 | return PTR_ERR(pipe_config); | |
13072 | ||
13073 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
13074 | ||
13075 | if (!pipe_config->base.active || | |
13076 | needs_modeset(&pipe_config->base)) | |
13077 | continue; | |
13078 | ||
13079 | /* 2 or more enabled crtcs means no need for w/a */ | |
13080 | if (enabled_pipe != INVALID_PIPE) | |
13081 | return 0; | |
13082 | ||
13083 | enabled_pipe = intel_crtc->pipe; | |
13084 | } | |
13085 | ||
13086 | if (enabled_pipe != INVALID_PIPE) | |
13087 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
13088 | else if (other_crtc_state) | |
13089 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
13090 | ||
13091 | return 0; | |
13092 | } | |
13093 | ||
27c329ed ML |
13094 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
13095 | { | |
13096 | struct drm_crtc *crtc; | |
13097 | struct drm_crtc_state *crtc_state; | |
13098 | int ret = 0; | |
13099 | ||
13100 | /* add all active pipes to the state */ | |
13101 | for_each_crtc(state->dev, crtc) { | |
13102 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13103 | if (IS_ERR(crtc_state)) | |
13104 | return PTR_ERR(crtc_state); | |
13105 | ||
13106 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
13107 | continue; | |
13108 | ||
13109 | crtc_state->mode_changed = true; | |
13110 | ||
13111 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13112 | if (ret) | |
13113 | break; | |
13114 | ||
13115 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13116 | if (ret) | |
13117 | break; | |
13118 | } | |
13119 | ||
13120 | return ret; | |
13121 | } | |
13122 | ||
c347a676 | 13123 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
13124 | { |
13125 | struct drm_device *dev = state->dev; | |
27c329ed | 13126 | struct drm_i915_private *dev_priv = dev->dev_private; |
054518dd ACO |
13127 | int ret; |
13128 | ||
b359283a ML |
13129 | if (!check_digital_port_conflicts(state)) { |
13130 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13131 | return -EINVAL; | |
13132 | } | |
13133 | ||
054518dd ACO |
13134 | /* |
13135 | * See if the config requires any additional preparation, e.g. | |
13136 | * to adjust global state with pipes off. We need to do this | |
13137 | * here so we can get the modeset_pipe updated config for the new | |
13138 | * mode set on this crtc. For other crtcs we need to use the | |
13139 | * adjusted_mode bits in the crtc directly. | |
13140 | */ | |
27c329ed ML |
13141 | if (dev_priv->display.modeset_calc_cdclk) { |
13142 | unsigned int cdclk; | |
b432e5cf | 13143 | |
27c329ed ML |
13144 | ret = dev_priv->display.modeset_calc_cdclk(state); |
13145 | ||
13146 | cdclk = to_intel_atomic_state(state)->cdclk; | |
13147 | if (!ret && cdclk != dev_priv->cdclk_freq) | |
13148 | ret = intel_modeset_all_pipes(state); | |
13149 | ||
13150 | if (ret < 0) | |
054518dd | 13151 | return ret; |
27c329ed ML |
13152 | } else |
13153 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; | |
054518dd | 13154 | |
ad421372 | 13155 | intel_modeset_clear_plls(state); |
054518dd | 13156 | |
99d736a2 | 13157 | if (IS_HASWELL(dev)) |
ad421372 | 13158 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13159 | |
ad421372 | 13160 | return 0; |
c347a676 ACO |
13161 | } |
13162 | ||
aa363136 MR |
13163 | /* |
13164 | * Handle calculation of various watermark data at the end of the atomic check | |
13165 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13166 | * handlers to ensure that all derived state has been updated. | |
13167 | */ | |
13168 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13169 | { | |
13170 | struct drm_device *dev = state->dev; | |
13171 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13172 | struct drm_crtc *crtc; | |
13173 | struct drm_crtc_state *cstate; | |
13174 | struct drm_plane *plane; | |
13175 | struct drm_plane_state *pstate; | |
13176 | ||
13177 | /* | |
13178 | * Calculate watermark configuration details now that derived | |
13179 | * plane/crtc state is all properly updated. | |
13180 | */ | |
13181 | drm_for_each_crtc(crtc, dev) { | |
13182 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13183 | crtc->state; | |
13184 | ||
13185 | if (cstate->active) | |
13186 | intel_state->wm_config.num_pipes_active++; | |
13187 | } | |
13188 | drm_for_each_legacy_plane(plane, dev) { | |
13189 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13190 | plane->state; | |
13191 | ||
13192 | if (!to_intel_plane_state(pstate)->visible) | |
13193 | continue; | |
13194 | ||
13195 | intel_state->wm_config.sprites_enabled = true; | |
13196 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13197 | pstate->crtc_h != pstate->src_h >> 16) | |
13198 | intel_state->wm_config.sprites_scaled = true; | |
13199 | } | |
13200 | } | |
13201 | ||
74c090b1 ML |
13202 | /** |
13203 | * intel_atomic_check - validate state object | |
13204 | * @dev: drm device | |
13205 | * @state: state to validate | |
13206 | */ | |
13207 | static int intel_atomic_check(struct drm_device *dev, | |
13208 | struct drm_atomic_state *state) | |
c347a676 | 13209 | { |
aa363136 | 13210 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13211 | struct drm_crtc *crtc; |
13212 | struct drm_crtc_state *crtc_state; | |
13213 | int ret, i; | |
61333b60 | 13214 | bool any_ms = false; |
c347a676 | 13215 | |
74c090b1 | 13216 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13217 | if (ret) |
13218 | return ret; | |
13219 | ||
c347a676 | 13220 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13221 | struct intel_crtc_state *pipe_config = |
13222 | to_intel_crtc_state(crtc_state); | |
1ed51de9 | 13223 | |
ba8af3e5 ML |
13224 | memset(&to_intel_crtc(crtc)->atomic, 0, |
13225 | sizeof(struct intel_crtc_atomic_commit)); | |
13226 | ||
1ed51de9 DV |
13227 | /* Catch I915_MODE_FLAG_INHERITED */ |
13228 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13229 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13230 | |
61333b60 ML |
13231 | if (!crtc_state->enable) { |
13232 | if (needs_modeset(crtc_state)) | |
13233 | any_ms = true; | |
c347a676 | 13234 | continue; |
61333b60 | 13235 | } |
c347a676 | 13236 | |
26495481 | 13237 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
13238 | continue; |
13239 | ||
26495481 DV |
13240 | /* FIXME: For only active_changed we shouldn't need to do any |
13241 | * state recomputation at all. */ | |
13242 | ||
1ed51de9 DV |
13243 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13244 | if (ret) | |
13245 | return ret; | |
b359283a | 13246 | |
cfb23ed6 | 13247 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13248 | if (ret) |
13249 | return ret; | |
13250 | ||
73831236 JN |
13251 | if (i915.fastboot && |
13252 | intel_pipe_config_compare(state->dev, | |
cfb23ed6 | 13253 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13254 | pipe_config, true)) { |
26495481 | 13255 | crtc_state->mode_changed = false; |
bfd16b2a | 13256 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13257 | } |
13258 | ||
13259 | if (needs_modeset(crtc_state)) { | |
13260 | any_ms = true; | |
cfb23ed6 ML |
13261 | |
13262 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13263 | if (ret) | |
13264 | return ret; | |
13265 | } | |
61333b60 | 13266 | |
26495481 DV |
13267 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13268 | needs_modeset(crtc_state) ? | |
13269 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13270 | } |
13271 | ||
61333b60 ML |
13272 | if (any_ms) { |
13273 | ret = intel_modeset_checks(state); | |
13274 | ||
13275 | if (ret) | |
13276 | return ret; | |
27c329ed | 13277 | } else |
aa363136 | 13278 | intel_state->cdclk = to_i915(state->dev)->cdclk_freq; |
76305b1a | 13279 | |
aa363136 MR |
13280 | ret = drm_atomic_helper_check_planes(state->dev, state); |
13281 | if (ret) | |
13282 | return ret; | |
13283 | ||
13284 | calc_watermark_data(state); | |
13285 | ||
13286 | return 0; | |
054518dd ACO |
13287 | } |
13288 | ||
5008e874 ML |
13289 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13290 | struct drm_atomic_state *state, | |
13291 | bool async) | |
13292 | { | |
7580d774 ML |
13293 | struct drm_i915_private *dev_priv = dev->dev_private; |
13294 | struct drm_plane_state *plane_state; | |
5008e874 | 13295 | struct drm_crtc_state *crtc_state; |
7580d774 | 13296 | struct drm_plane *plane; |
5008e874 ML |
13297 | struct drm_crtc *crtc; |
13298 | int i, ret; | |
13299 | ||
13300 | if (async) { | |
13301 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13302 | return -EINVAL; | |
13303 | } | |
13304 | ||
13305 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13306 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13307 | if (ret) | |
13308 | return ret; | |
7580d774 ML |
13309 | |
13310 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13311 | flush_workqueue(dev_priv->wq); | |
5008e874 ML |
13312 | } |
13313 | ||
f935675f ML |
13314 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13315 | if (ret) | |
13316 | return ret; | |
13317 | ||
5008e874 | 13318 | ret = drm_atomic_helper_prepare_planes(dev, state); |
7580d774 ML |
13319 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
13320 | u32 reset_counter; | |
13321 | ||
13322 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13323 | mutex_unlock(&dev->struct_mutex); | |
13324 | ||
13325 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13326 | struct intel_plane_state *intel_plane_state = | |
13327 | to_intel_plane_state(plane_state); | |
13328 | ||
13329 | if (!intel_plane_state->wait_req) | |
13330 | continue; | |
13331 | ||
13332 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13333 | reset_counter, true, | |
13334 | NULL, NULL); | |
13335 | ||
13336 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13337 | if (ret == -EIO) | |
13338 | ret = 0; | |
13339 | ||
13340 | if (ret) | |
13341 | break; | |
13342 | } | |
13343 | ||
13344 | if (!ret) | |
13345 | return 0; | |
13346 | ||
13347 | mutex_lock(&dev->struct_mutex); | |
13348 | drm_atomic_helper_cleanup_planes(dev, state); | |
13349 | } | |
5008e874 | 13350 | |
f935675f | 13351 | mutex_unlock(&dev->struct_mutex); |
5008e874 ML |
13352 | return ret; |
13353 | } | |
13354 | ||
74c090b1 ML |
13355 | /** |
13356 | * intel_atomic_commit - commit validated state object | |
13357 | * @dev: DRM device | |
13358 | * @state: the top-level driver state object | |
13359 | * @async: asynchronous commit | |
13360 | * | |
13361 | * This function commits a top-level state object that has been validated | |
13362 | * with drm_atomic_helper_check(). | |
13363 | * | |
13364 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13365 | * we can only handle plane-related operations and do not yet support | |
13366 | * asynchronous commit. | |
13367 | * | |
13368 | * RETURNS | |
13369 | * Zero for success or -errno. | |
13370 | */ | |
13371 | static int intel_atomic_commit(struct drm_device *dev, | |
13372 | struct drm_atomic_state *state, | |
13373 | bool async) | |
a6778b3c | 13374 | { |
fbee40df | 13375 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 | 13376 | struct drm_crtc_state *crtc_state; |
7580d774 | 13377 | struct drm_crtc *crtc; |
c0c36b94 | 13378 | int ret = 0; |
0a9ab303 | 13379 | int i; |
61333b60 | 13380 | bool any_ms = false; |
a6778b3c | 13381 | |
5008e874 | 13382 | ret = intel_atomic_prepare_commit(dev, state, async); |
7580d774 ML |
13383 | if (ret) { |
13384 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
d4afb8cc | 13385 | return ret; |
7580d774 | 13386 | } |
d4afb8cc | 13387 | |
1c5e19f8 | 13388 | drm_atomic_helper_swap_state(dev, state); |
aa363136 | 13389 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; |
1c5e19f8 | 13390 | |
0a9ab303 | 13391 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13392 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13393 | ||
61333b60 ML |
13394 | if (!needs_modeset(crtc->state)) |
13395 | continue; | |
13396 | ||
13397 | any_ms = true; | |
a539205a | 13398 | intel_pre_plane_update(intel_crtc); |
460da916 | 13399 | |
a539205a ML |
13400 | if (crtc_state->active) { |
13401 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13402 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd ML |
13403 | intel_crtc->active = false; |
13404 | intel_disable_shared_dpll(intel_crtc); | |
a539205a | 13405 | } |
b8cecdf5 | 13406 | } |
7758a113 | 13407 | |
ea9d758d DV |
13408 | /* Only after disabling all output pipelines that will be changed can we |
13409 | * update the the output configuration. */ | |
4740b0f2 | 13410 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13411 | |
4740b0f2 ML |
13412 | if (any_ms) { |
13413 | intel_shared_dpll_commit(state); | |
13414 | ||
13415 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
61333b60 | 13416 | modeset_update_crtc_power_domains(state); |
4740b0f2 | 13417 | } |
47fab737 | 13418 | |
a6778b3c | 13419 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13420 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13422 | bool modeset = needs_modeset(crtc->state); | |
bfd16b2a ML |
13423 | bool update_pipe = !modeset && |
13424 | to_intel_crtc_state(crtc->state)->update_pipe; | |
13425 | unsigned long put_domains = 0; | |
f6ac4b2a | 13426 | |
9f836f90 PJ |
13427 | if (modeset) |
13428 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); | |
13429 | ||
f6ac4b2a | 13430 | if (modeset && crtc->state->active) { |
a539205a ML |
13431 | update_scanline_offset(to_intel_crtc(crtc)); |
13432 | dev_priv->display.crtc_enable(crtc); | |
13433 | } | |
80715b2f | 13434 | |
bfd16b2a ML |
13435 | if (update_pipe) { |
13436 | put_domains = modeset_get_crtc_power_domains(crtc); | |
13437 | ||
13438 | /* make sure intel_modeset_check_state runs */ | |
13439 | any_ms = true; | |
13440 | } | |
13441 | ||
f6ac4b2a ML |
13442 | if (!modeset) |
13443 | intel_pre_plane_update(intel_crtc); | |
13444 | ||
6173ee28 ML |
13445 | if (crtc->state->active && |
13446 | (crtc->state->planes_changed || update_pipe)) | |
62852622 | 13447 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
bfd16b2a ML |
13448 | |
13449 | if (put_domains) | |
13450 | modeset_put_power_domains(dev_priv, put_domains); | |
13451 | ||
f6ac4b2a | 13452 | intel_post_plane_update(intel_crtc); |
9f836f90 PJ |
13453 | |
13454 | if (modeset) | |
13455 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); | |
80715b2f | 13456 | } |
a6778b3c | 13457 | |
a6778b3c | 13458 | /* FIXME: add subpixel order */ |
83a57153 | 13459 | |
74c090b1 | 13460 | drm_atomic_helper_wait_for_vblanks(dev, state); |
f935675f ML |
13461 | |
13462 | mutex_lock(&dev->struct_mutex); | |
d4afb8cc | 13463 | drm_atomic_helper_cleanup_planes(dev, state); |
f935675f | 13464 | mutex_unlock(&dev->struct_mutex); |
2bfb4627 | 13465 | |
74c090b1 | 13466 | if (any_ms) |
ee165b1a ML |
13467 | intel_modeset_check_state(dev, state); |
13468 | ||
13469 | drm_atomic_state_free(state); | |
f30da187 | 13470 | |
74c090b1 | 13471 | return 0; |
7f27126e JB |
13472 | } |
13473 | ||
c0c36b94 CW |
13474 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13475 | { | |
83a57153 ACO |
13476 | struct drm_device *dev = crtc->dev; |
13477 | struct drm_atomic_state *state; | |
e694eb02 | 13478 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13479 | int ret; |
83a57153 ACO |
13480 | |
13481 | state = drm_atomic_state_alloc(dev); | |
13482 | if (!state) { | |
e694eb02 | 13483 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13484 | crtc->base.id); |
13485 | return; | |
13486 | } | |
13487 | ||
e694eb02 | 13488 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13489 | |
e694eb02 ML |
13490 | retry: |
13491 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13492 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13493 | if (!ret) { | |
13494 | if (!crtc_state->active) | |
13495 | goto out; | |
83a57153 | 13496 | |
e694eb02 | 13497 | crtc_state->mode_changed = true; |
74c090b1 | 13498 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13499 | } |
13500 | ||
e694eb02 ML |
13501 | if (ret == -EDEADLK) { |
13502 | drm_atomic_state_clear(state); | |
13503 | drm_modeset_backoff(state->acquire_ctx); | |
13504 | goto retry; | |
4ed9fb37 | 13505 | } |
4be07317 | 13506 | |
2bfb4627 | 13507 | if (ret) |
e694eb02 | 13508 | out: |
2bfb4627 | 13509 | drm_atomic_state_free(state); |
c0c36b94 CW |
13510 | } |
13511 | ||
25c5b266 DV |
13512 | #undef for_each_intel_crtc_masked |
13513 | ||
f6e5b160 | 13514 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13515 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13516 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13517 | .destroy = intel_crtc_destroy, |
13518 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13519 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13520 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13521 | }; |
13522 | ||
5358901f DV |
13523 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13524 | struct intel_shared_dpll *pll, | |
13525 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13526 | { |
5358901f | 13527 | uint32_t val; |
ee7b9f93 | 13528 | |
f458ebbc | 13529 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13530 | return false; |
13531 | ||
5358901f | 13532 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13533 | hw_state->dpll = val; |
13534 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13535 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13536 | |
13537 | return val & DPLL_VCO_ENABLE; | |
13538 | } | |
13539 | ||
15bdd4cf DV |
13540 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13541 | struct intel_shared_dpll *pll) | |
13542 | { | |
3e369b76 ACO |
13543 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13544 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13545 | } |
13546 | ||
e7b903d2 DV |
13547 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13548 | struct intel_shared_dpll *pll) | |
13549 | { | |
e7b903d2 | 13550 | /* PCH refclock must be enabled first */ |
89eff4be | 13551 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13552 | |
3e369b76 | 13553 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13554 | |
13555 | /* Wait for the clocks to stabilize. */ | |
13556 | POSTING_READ(PCH_DPLL(pll->id)); | |
13557 | udelay(150); | |
13558 | ||
13559 | /* The pixel multiplier can only be updated once the | |
13560 | * DPLL is enabled and the clocks are stable. | |
13561 | * | |
13562 | * So write it again. | |
13563 | */ | |
3e369b76 | 13564 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13565 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13566 | udelay(200); |
13567 | } | |
13568 | ||
13569 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13570 | struct intel_shared_dpll *pll) | |
13571 | { | |
13572 | struct drm_device *dev = dev_priv->dev; | |
13573 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13574 | |
13575 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13576 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13577 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13578 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13579 | } |
13580 | ||
15bdd4cf DV |
13581 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13582 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13583 | udelay(200); |
13584 | } | |
13585 | ||
46edb027 DV |
13586 | static char *ibx_pch_dpll_names[] = { |
13587 | "PCH DPLL A", | |
13588 | "PCH DPLL B", | |
13589 | }; | |
13590 | ||
7c74ade1 | 13591 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13592 | { |
e7b903d2 | 13593 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13594 | int i; |
13595 | ||
7c74ade1 | 13596 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13597 | |
e72f9fbf | 13598 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13599 | dev_priv->shared_dplls[i].id = i; |
13600 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13601 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13602 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13603 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13604 | dev_priv->shared_dplls[i].get_hw_state = |
13605 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13606 | } |
13607 | } | |
13608 | ||
7c74ade1 DV |
13609 | static void intel_shared_dpll_init(struct drm_device *dev) |
13610 | { | |
e7b903d2 | 13611 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13612 | |
9cd86933 DV |
13613 | if (HAS_DDI(dev)) |
13614 | intel_ddi_pll_init(dev); | |
13615 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13616 | ibx_pch_dpll_init(dev); |
13617 | else | |
13618 | dev_priv->num_shared_dpll = 0; | |
13619 | ||
13620 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13621 | } |
13622 | ||
6beb8c23 MR |
13623 | /** |
13624 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13625 | * @plane: drm plane to prepare for | |
13626 | * @fb: framebuffer to prepare for presentation | |
13627 | * | |
13628 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13629 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13630 | * bits. Some older platforms need special physical address handling for | |
13631 | * cursor planes. | |
13632 | * | |
f935675f ML |
13633 | * Must be called with struct_mutex held. |
13634 | * | |
6beb8c23 MR |
13635 | * Returns 0 on success, negative error code on failure. |
13636 | */ | |
13637 | int | |
13638 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 13639 | const struct drm_plane_state *new_state) |
465c120c MR |
13640 | { |
13641 | struct drm_device *dev = plane->dev; | |
844f9111 | 13642 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 13643 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 | 13644 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 13645 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
6beb8c23 | 13646 | int ret = 0; |
465c120c | 13647 | |
1ee49399 | 13648 | if (!obj && !old_obj) |
465c120c MR |
13649 | return 0; |
13650 | ||
5008e874 ML |
13651 | if (old_obj) { |
13652 | struct drm_crtc_state *crtc_state = | |
13653 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13654 | ||
13655 | /* Big Hammer, we also need to ensure that any pending | |
13656 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13657 | * current scanout is retired before unpinning the old | |
13658 | * framebuffer. Note that we rely on userspace rendering | |
13659 | * into the buffer attached to the pipe they are waiting | |
13660 | * on. If not, userspace generates a GPU hang with IPEHR | |
13661 | * point to the MI_WAIT_FOR_EVENT. | |
13662 | * | |
13663 | * This should only fail upon a hung GPU, in which case we | |
13664 | * can safely continue. | |
13665 | */ | |
13666 | if (needs_modeset(crtc_state)) | |
13667 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13668 | ||
13669 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13670 | if (ret && ret != -EIO) | |
f935675f | 13671 | return ret; |
5008e874 ML |
13672 | } |
13673 | ||
1ee49399 ML |
13674 | if (!obj) { |
13675 | ret = 0; | |
13676 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
6beb8c23 MR |
13677 | INTEL_INFO(dev)->cursor_needs_physical) { |
13678 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13679 | ret = i915_gem_object_attach_phys(obj, align); | |
13680 | if (ret) | |
13681 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13682 | } else { | |
7580d774 | 13683 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state); |
6beb8c23 | 13684 | } |
465c120c | 13685 | |
7580d774 ML |
13686 | if (ret == 0) { |
13687 | if (obj) { | |
13688 | struct intel_plane_state *plane_state = | |
13689 | to_intel_plane_state(new_state); | |
13690 | ||
13691 | i915_gem_request_assign(&plane_state->wait_req, | |
13692 | obj->last_write_req); | |
13693 | } | |
13694 | ||
a9ff8714 | 13695 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
7580d774 | 13696 | } |
fdd508a6 | 13697 | |
6beb8c23 MR |
13698 | return ret; |
13699 | } | |
13700 | ||
38f3ce3a MR |
13701 | /** |
13702 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13703 | * @plane: drm plane to clean up for | |
13704 | * @fb: old framebuffer that was on plane | |
13705 | * | |
13706 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
13707 | * |
13708 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
13709 | */ |
13710 | void | |
13711 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 13712 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
13713 | { |
13714 | struct drm_device *dev = plane->dev; | |
1ee49399 | 13715 | struct intel_plane *intel_plane = to_intel_plane(plane); |
7580d774 | 13716 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
13717 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
13718 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 13719 | |
7580d774 ML |
13720 | old_intel_state = to_intel_plane_state(old_state); |
13721 | ||
1ee49399 | 13722 | if (!obj && !old_obj) |
38f3ce3a MR |
13723 | return; |
13724 | ||
1ee49399 ML |
13725 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
13726 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
844f9111 | 13727 | intel_unpin_fb_obj(old_state->fb, old_state); |
1ee49399 ML |
13728 | |
13729 | /* prepare_fb aborted? */ | |
13730 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
13731 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
13732 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
7580d774 ML |
13733 | |
13734 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
13735 | ||
465c120c MR |
13736 | } |
13737 | ||
6156a456 CK |
13738 | int |
13739 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13740 | { | |
13741 | int max_scale; | |
13742 | struct drm_device *dev; | |
13743 | struct drm_i915_private *dev_priv; | |
13744 | int crtc_clock, cdclk; | |
13745 | ||
13746 | if (!intel_crtc || !crtc_state) | |
13747 | return DRM_PLANE_HELPER_NO_SCALING; | |
13748 | ||
13749 | dev = intel_crtc->base.dev; | |
13750 | dev_priv = dev->dev_private; | |
13751 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 13752 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 13753 | |
54bf1ce6 | 13754 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
13755 | return DRM_PLANE_HELPER_NO_SCALING; |
13756 | ||
13757 | /* | |
13758 | * skl max scale is lower of: | |
13759 | * close to 3 but not 3, -1 is for that purpose | |
13760 | * or | |
13761 | * cdclk/crtc_clock | |
13762 | */ | |
13763 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13764 | ||
13765 | return max_scale; | |
13766 | } | |
13767 | ||
465c120c | 13768 | static int |
3c692a41 | 13769 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13770 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13771 | struct intel_plane_state *state) |
13772 | { | |
2b875c22 MR |
13773 | struct drm_crtc *crtc = state->base.crtc; |
13774 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13775 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13776 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13777 | bool can_position = false; | |
465c120c | 13778 | |
061e4b8d ML |
13779 | /* use scaler when colorkey is not required */ |
13780 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
818ed961 | 13781 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
061e4b8d ML |
13782 | min_scale = 1; |
13783 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13784 | can_position = true; |
6156a456 | 13785 | } |
d8106366 | 13786 | |
061e4b8d ML |
13787 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13788 | &state->dst, &state->clip, | |
da20eabd ML |
13789 | min_scale, max_scale, |
13790 | can_position, true, | |
13791 | &state->visible); | |
14af293f GP |
13792 | } |
13793 | ||
13794 | static void | |
13795 | intel_commit_primary_plane(struct drm_plane *plane, | |
13796 | struct intel_plane_state *state) | |
13797 | { | |
2b875c22 MR |
13798 | struct drm_crtc *crtc = state->base.crtc; |
13799 | struct drm_framebuffer *fb = state->base.fb; | |
13800 | struct drm_device *dev = plane->dev; | |
14af293f | 13801 | struct drm_i915_private *dev_priv = dev->dev_private; |
14af293f | 13802 | |
ea2c67bb | 13803 | crtc = crtc ? crtc : plane->crtc; |
ccc759dc | 13804 | |
d4b08630 ML |
13805 | dev_priv->display.update_primary_plane(crtc, fb, |
13806 | state->src.x1 >> 16, | |
13807 | state->src.y1 >> 16); | |
465c120c MR |
13808 | } |
13809 | ||
a8ad0d8e ML |
13810 | static void |
13811 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13812 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13813 | { |
13814 | struct drm_device *dev = plane->dev; | |
13815 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13816 | ||
a8ad0d8e ML |
13817 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13818 | } | |
13819 | ||
613d2b27 ML |
13820 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
13821 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 13822 | { |
32b7eeec | 13823 | struct drm_device *dev = crtc->dev; |
3c692a41 | 13824 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
bfd16b2a ML |
13825 | struct intel_crtc_state *old_intel_state = |
13826 | to_intel_crtc_state(old_crtc_state); | |
13827 | bool modeset = needs_modeset(crtc->state); | |
3c692a41 | 13828 | |
f015c551 | 13829 | if (intel_crtc->atomic.update_wm_pre) |
32b7eeec | 13830 | intel_update_watermarks(crtc); |
3c692a41 | 13831 | |
c34c9ee4 | 13832 | /* Perform vblank evasion around commit operation */ |
62852622 | 13833 | intel_pipe_update_start(intel_crtc); |
0583236e | 13834 | |
bfd16b2a ML |
13835 | if (modeset) |
13836 | return; | |
13837 | ||
13838 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
13839 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
13840 | else if (INTEL_INFO(dev)->gen >= 9) | |
0583236e | 13841 | skl_detach_scalers(intel_crtc); |
32b7eeec MR |
13842 | } |
13843 | ||
613d2b27 ML |
13844 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
13845 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 13846 | { |
32b7eeec | 13847 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 13848 | |
62852622 | 13849 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
13850 | } |
13851 | ||
cf4c7c12 | 13852 | /** |
4a3b8769 MR |
13853 | * intel_plane_destroy - destroy a plane |
13854 | * @plane: plane to destroy | |
cf4c7c12 | 13855 | * |
4a3b8769 MR |
13856 | * Common destruction function for all types of planes (primary, cursor, |
13857 | * sprite). | |
cf4c7c12 | 13858 | */ |
4a3b8769 | 13859 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13860 | { |
13861 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13862 | drm_plane_cleanup(plane); | |
13863 | kfree(intel_plane); | |
13864 | } | |
13865 | ||
65a3fea0 | 13866 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13867 | .update_plane = drm_atomic_helper_update_plane, |
13868 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13869 | .destroy = intel_plane_destroy, |
c196e1d6 | 13870 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13871 | .atomic_get_property = intel_plane_atomic_get_property, |
13872 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13873 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13874 | .atomic_destroy_state = intel_plane_destroy_state, | |
13875 | ||
465c120c MR |
13876 | }; |
13877 | ||
13878 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13879 | int pipe) | |
13880 | { | |
13881 | struct intel_plane *primary; | |
8e7d688b | 13882 | struct intel_plane_state *state; |
465c120c | 13883 | const uint32_t *intel_primary_formats; |
45e3743a | 13884 | unsigned int num_formats; |
465c120c MR |
13885 | |
13886 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13887 | if (primary == NULL) | |
13888 | return NULL; | |
13889 | ||
8e7d688b MR |
13890 | state = intel_create_plane_state(&primary->base); |
13891 | if (!state) { | |
ea2c67bb MR |
13892 | kfree(primary); |
13893 | return NULL; | |
13894 | } | |
8e7d688b | 13895 | primary->base.state = &state->base; |
ea2c67bb | 13896 | |
465c120c MR |
13897 | primary->can_scale = false; |
13898 | primary->max_downscale = 1; | |
6156a456 CK |
13899 | if (INTEL_INFO(dev)->gen >= 9) { |
13900 | primary->can_scale = true; | |
af99ceda | 13901 | state->scaler_id = -1; |
6156a456 | 13902 | } |
465c120c MR |
13903 | primary->pipe = pipe; |
13904 | primary->plane = pipe; | |
a9ff8714 | 13905 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 MR |
13906 | primary->check_plane = intel_check_primary_plane; |
13907 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13908 | primary->disable_plane = intel_disable_primary_plane; |
465c120c MR |
13909 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13910 | primary->plane = !pipe; | |
13911 | ||
6c0fd451 DL |
13912 | if (INTEL_INFO(dev)->gen >= 9) { |
13913 | intel_primary_formats = skl_primary_formats; | |
13914 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13915 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13916 | intel_primary_formats = i965_primary_formats; |
13917 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13918 | } else { |
13919 | intel_primary_formats = i8xx_primary_formats; | |
13920 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13921 | } |
13922 | ||
13923 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13924 | &intel_plane_funcs, |
465c120c MR |
13925 | intel_primary_formats, num_formats, |
13926 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13927 | |
3b7a5119 SJ |
13928 | if (INTEL_INFO(dev)->gen >= 4) |
13929 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13930 | |
ea2c67bb MR |
13931 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13932 | ||
465c120c MR |
13933 | return &primary->base; |
13934 | } | |
13935 | ||
3b7a5119 SJ |
13936 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13937 | { | |
13938 | if (!dev->mode_config.rotation_property) { | |
13939 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13940 | BIT(DRM_ROTATE_180); | |
13941 | ||
13942 | if (INTEL_INFO(dev)->gen >= 9) | |
13943 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13944 | ||
13945 | dev->mode_config.rotation_property = | |
13946 | drm_mode_create_rotation_property(dev, flags); | |
13947 | } | |
13948 | if (dev->mode_config.rotation_property) | |
13949 | drm_object_attach_property(&plane->base.base, | |
13950 | dev->mode_config.rotation_property, | |
13951 | plane->base.state->rotation); | |
13952 | } | |
13953 | ||
3d7d6510 | 13954 | static int |
852e787c | 13955 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 13956 | struct intel_crtc_state *crtc_state, |
852e787c | 13957 | struct intel_plane_state *state) |
3d7d6510 | 13958 | { |
061e4b8d | 13959 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 13960 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 13961 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
13962 | unsigned stride; |
13963 | int ret; | |
3d7d6510 | 13964 | |
061e4b8d ML |
13965 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13966 | &state->dst, &state->clip, | |
3d7d6510 MR |
13967 | DRM_PLANE_HELPER_NO_SCALING, |
13968 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13969 | true, true, &state->visible); |
757f9a3e GP |
13970 | if (ret) |
13971 | return ret; | |
13972 | ||
757f9a3e GP |
13973 | /* if we want to turn off the cursor ignore width and height */ |
13974 | if (!obj) | |
da20eabd | 13975 | return 0; |
757f9a3e | 13976 | |
757f9a3e | 13977 | /* Check for which cursor types we support */ |
061e4b8d | 13978 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
13979 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
13980 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13981 | return -EINVAL; |
13982 | } | |
13983 | ||
ea2c67bb MR |
13984 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13985 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13986 | DRM_DEBUG_KMS("buffer is too small\n"); |
13987 | return -ENOMEM; | |
13988 | } | |
13989 | ||
3a656b54 | 13990 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 13991 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 13992 | return -EINVAL; |
32b7eeec MR |
13993 | } |
13994 | ||
da20eabd | 13995 | return 0; |
852e787c | 13996 | } |
3d7d6510 | 13997 | |
a8ad0d8e ML |
13998 | static void |
13999 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 14000 | struct drm_crtc *crtc) |
a8ad0d8e | 14001 | { |
a8ad0d8e ML |
14002 | intel_crtc_update_cursor(crtc, false); |
14003 | } | |
14004 | ||
f4a2cf29 | 14005 | static void |
852e787c GP |
14006 | intel_commit_cursor_plane(struct drm_plane *plane, |
14007 | struct intel_plane_state *state) | |
14008 | { | |
2b875c22 | 14009 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
14010 | struct drm_device *dev = plane->dev; |
14011 | struct intel_crtc *intel_crtc; | |
2b875c22 | 14012 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 14013 | uint32_t addr; |
852e787c | 14014 | |
ea2c67bb MR |
14015 | crtc = crtc ? crtc : plane->crtc; |
14016 | intel_crtc = to_intel_crtc(crtc); | |
14017 | ||
a912f12f GP |
14018 | if (intel_crtc->cursor_bo == obj) |
14019 | goto update; | |
4ed91096 | 14020 | |
f4a2cf29 | 14021 | if (!obj) |
a912f12f | 14022 | addr = 0; |
f4a2cf29 | 14023 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 14024 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 14025 | else |
a912f12f | 14026 | addr = obj->phys_handle->busaddr; |
852e787c | 14027 | |
a912f12f GP |
14028 | intel_crtc->cursor_addr = addr; |
14029 | intel_crtc->cursor_bo = obj; | |
852e787c | 14030 | |
302d19ac | 14031 | update: |
62852622 | 14032 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
14033 | } |
14034 | ||
3d7d6510 MR |
14035 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
14036 | int pipe) | |
14037 | { | |
14038 | struct intel_plane *cursor; | |
8e7d688b | 14039 | struct intel_plane_state *state; |
3d7d6510 MR |
14040 | |
14041 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
14042 | if (cursor == NULL) | |
14043 | return NULL; | |
14044 | ||
8e7d688b MR |
14045 | state = intel_create_plane_state(&cursor->base); |
14046 | if (!state) { | |
ea2c67bb MR |
14047 | kfree(cursor); |
14048 | return NULL; | |
14049 | } | |
8e7d688b | 14050 | cursor->base.state = &state->base; |
ea2c67bb | 14051 | |
3d7d6510 MR |
14052 | cursor->can_scale = false; |
14053 | cursor->max_downscale = 1; | |
14054 | cursor->pipe = pipe; | |
14055 | cursor->plane = pipe; | |
a9ff8714 | 14056 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 MR |
14057 | cursor->check_plane = intel_check_cursor_plane; |
14058 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 14059 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
14060 | |
14061 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 14062 | &intel_plane_funcs, |
3d7d6510 MR |
14063 | intel_cursor_formats, |
14064 | ARRAY_SIZE(intel_cursor_formats), | |
14065 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
14066 | |
14067 | if (INTEL_INFO(dev)->gen >= 4) { | |
14068 | if (!dev->mode_config.rotation_property) | |
14069 | dev->mode_config.rotation_property = | |
14070 | drm_mode_create_rotation_property(dev, | |
14071 | BIT(DRM_ROTATE_0) | | |
14072 | BIT(DRM_ROTATE_180)); | |
14073 | if (dev->mode_config.rotation_property) | |
14074 | drm_object_attach_property(&cursor->base.base, | |
14075 | dev->mode_config.rotation_property, | |
8e7d688b | 14076 | state->base.rotation); |
4398ad45 VS |
14077 | } |
14078 | ||
af99ceda CK |
14079 | if (INTEL_INFO(dev)->gen >=9) |
14080 | state->scaler_id = -1; | |
14081 | ||
ea2c67bb MR |
14082 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
14083 | ||
3d7d6510 MR |
14084 | return &cursor->base; |
14085 | } | |
14086 | ||
549e2bfb CK |
14087 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
14088 | struct intel_crtc_state *crtc_state) | |
14089 | { | |
14090 | int i; | |
14091 | struct intel_scaler *intel_scaler; | |
14092 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14093 | ||
14094 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14095 | intel_scaler = &scaler_state->scalers[i]; | |
14096 | intel_scaler->in_use = 0; | |
549e2bfb CK |
14097 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
14098 | } | |
14099 | ||
14100 | scaler_state->scaler_id = -1; | |
14101 | } | |
14102 | ||
b358d0a6 | 14103 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 14104 | { |
fbee40df | 14105 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 14106 | struct intel_crtc *intel_crtc; |
f5de6e07 | 14107 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
14108 | struct drm_plane *primary = NULL; |
14109 | struct drm_plane *cursor = NULL; | |
465c120c | 14110 | int i, ret; |
79e53945 | 14111 | |
955382f3 | 14112 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14113 | if (intel_crtc == NULL) |
14114 | return; | |
14115 | ||
f5de6e07 ACO |
14116 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14117 | if (!crtc_state) | |
14118 | goto fail; | |
550acefd ACO |
14119 | intel_crtc->config = crtc_state; |
14120 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14121 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14122 | |
549e2bfb CK |
14123 | /* initialize shared scalers */ |
14124 | if (INTEL_INFO(dev)->gen >= 9) { | |
14125 | if (pipe == PIPE_C) | |
14126 | intel_crtc->num_scalers = 1; | |
14127 | else | |
14128 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14129 | ||
14130 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14131 | } | |
14132 | ||
465c120c | 14133 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14134 | if (!primary) |
14135 | goto fail; | |
14136 | ||
14137 | cursor = intel_cursor_plane_create(dev, pipe); | |
14138 | if (!cursor) | |
14139 | goto fail; | |
14140 | ||
465c120c | 14141 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14142 | cursor, &intel_crtc_funcs); |
14143 | if (ret) | |
14144 | goto fail; | |
79e53945 JB |
14145 | |
14146 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14147 | for (i = 0; i < 256; i++) { |
14148 | intel_crtc->lut_r[i] = i; | |
14149 | intel_crtc->lut_g[i] = i; | |
14150 | intel_crtc->lut_b[i] = i; | |
14151 | } | |
14152 | ||
1f1c2e24 VS |
14153 | /* |
14154 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14155 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14156 | */ |
80824003 JB |
14157 | intel_crtc->pipe = pipe; |
14158 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14159 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14160 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14161 | intel_crtc->plane = !pipe; |
80824003 JB |
14162 | } |
14163 | ||
4b0e333e CW |
14164 | intel_crtc->cursor_base = ~0; |
14165 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14166 | intel_crtc->cursor_size = ~0; |
8d7849db | 14167 | |
852eb00d VS |
14168 | intel_crtc->wm.cxsr_allowed = true; |
14169 | ||
22fd0fab JB |
14170 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14171 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14172 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14173 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14174 | ||
79e53945 | 14175 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14176 | |
14177 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14178 | return; |
14179 | ||
14180 | fail: | |
14181 | if (primary) | |
14182 | drm_plane_cleanup(primary); | |
14183 | if (cursor) | |
14184 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14185 | kfree(crtc_state); |
3d7d6510 | 14186 | kfree(intel_crtc); |
79e53945 JB |
14187 | } |
14188 | ||
752aa88a JB |
14189 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14190 | { | |
14191 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14192 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14193 | |
51fd371b | 14194 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14195 | |
d3babd3f | 14196 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14197 | return INVALID_PIPE; |
14198 | ||
14199 | return to_intel_crtc(encoder->crtc)->pipe; | |
14200 | } | |
14201 | ||
08d7b3d1 | 14202 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14203 | struct drm_file *file) |
08d7b3d1 | 14204 | { |
08d7b3d1 | 14205 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14206 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14207 | struct intel_crtc *crtc; |
08d7b3d1 | 14208 | |
7707e653 | 14209 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14210 | |
7707e653 | 14211 | if (!drmmode_crtc) { |
08d7b3d1 | 14212 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14213 | return -ENOENT; |
08d7b3d1 CW |
14214 | } |
14215 | ||
7707e653 | 14216 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14217 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14218 | |
c05422d5 | 14219 | return 0; |
08d7b3d1 CW |
14220 | } |
14221 | ||
66a9278e | 14222 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14223 | { |
66a9278e DV |
14224 | struct drm_device *dev = encoder->base.dev; |
14225 | struct intel_encoder *source_encoder; | |
79e53945 | 14226 | int index_mask = 0; |
79e53945 JB |
14227 | int entry = 0; |
14228 | ||
b2784e15 | 14229 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14230 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14231 | index_mask |= (1 << entry); |
14232 | ||
79e53945 JB |
14233 | entry++; |
14234 | } | |
4ef69c7a | 14235 | |
79e53945 JB |
14236 | return index_mask; |
14237 | } | |
14238 | ||
4d302442 CW |
14239 | static bool has_edp_a(struct drm_device *dev) |
14240 | { | |
14241 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14242 | ||
14243 | if (!IS_MOBILE(dev)) | |
14244 | return false; | |
14245 | ||
14246 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14247 | return false; | |
14248 | ||
e3589908 | 14249 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14250 | return false; |
14251 | ||
14252 | return true; | |
14253 | } | |
14254 | ||
84b4e042 JB |
14255 | static bool intel_crt_present(struct drm_device *dev) |
14256 | { | |
14257 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14258 | ||
884497ed DL |
14259 | if (INTEL_INFO(dev)->gen >= 9) |
14260 | return false; | |
14261 | ||
cf404ce4 | 14262 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14263 | return false; |
14264 | ||
14265 | if (IS_CHERRYVIEW(dev)) | |
14266 | return false; | |
14267 | ||
14268 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
14269 | return false; | |
14270 | ||
14271 | return true; | |
14272 | } | |
14273 | ||
79e53945 JB |
14274 | static void intel_setup_outputs(struct drm_device *dev) |
14275 | { | |
725e30ad | 14276 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14277 | struct intel_encoder *encoder; |
cb0953d7 | 14278 | bool dpd_is_edp = false; |
79e53945 | 14279 | |
c9093354 | 14280 | intel_lvds_init(dev); |
79e53945 | 14281 | |
84b4e042 | 14282 | if (intel_crt_present(dev)) |
79935fca | 14283 | intel_crt_init(dev); |
cb0953d7 | 14284 | |
c776eb2e VK |
14285 | if (IS_BROXTON(dev)) { |
14286 | /* | |
14287 | * FIXME: Broxton doesn't support port detection via the | |
14288 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14289 | * detect the ports. | |
14290 | */ | |
14291 | intel_ddi_init(dev, PORT_A); | |
14292 | intel_ddi_init(dev, PORT_B); | |
14293 | intel_ddi_init(dev, PORT_C); | |
14294 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14295 | int found; |
14296 | ||
de31facd JB |
14297 | /* |
14298 | * Haswell uses DDI functions to detect digital outputs. | |
14299 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14300 | * it's there. | |
14301 | */ | |
77179400 | 14302 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14303 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14304 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14305 | intel_ddi_init(dev, PORT_A); |
14306 | ||
14307 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14308 | * register */ | |
14309 | found = I915_READ(SFUSE_STRAP); | |
14310 | ||
14311 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14312 | intel_ddi_init(dev, PORT_B); | |
14313 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14314 | intel_ddi_init(dev, PORT_C); | |
14315 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14316 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14317 | /* |
14318 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14319 | */ | |
ef11bdb3 | 14320 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14321 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14322 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14323 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14324 | intel_ddi_init(dev, PORT_E); | |
14325 | ||
0e72a5b5 | 14326 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14327 | int found; |
5d8a7752 | 14328 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14329 | |
14330 | if (has_edp_a(dev)) | |
14331 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14332 | |
dc0fa718 | 14333 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14334 | /* PCH SDVOB multiplex with HDMIB */ |
2a5c0832 | 14335 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
30ad48b7 | 14336 | if (!found) |
e2debe91 | 14337 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14338 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14339 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14340 | } |
14341 | ||
dc0fa718 | 14342 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14343 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14344 | |
dc0fa718 | 14345 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14346 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14347 | |
5eb08b69 | 14348 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14349 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14350 | |
270b3042 | 14351 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14352 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14353 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14354 | /* |
14355 | * The DP_DETECTED bit is the latched state of the DDC | |
14356 | * SDA pin at boot. However since eDP doesn't require DDC | |
14357 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14358 | * eDP ports may have been muxed to an alternate function. | |
14359 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14360 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14361 | * detect eDP ports. | |
14362 | */ | |
e66eb81d | 14363 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
d2182a66 | 14364 | !intel_dp_is_edp(dev, PORT_B)) |
e66eb81d VS |
14365 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
14366 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
e17ac6db | 14367 | intel_dp_is_edp(dev, PORT_B)) |
e66eb81d | 14368 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
585a94b8 | 14369 | |
e66eb81d | 14370 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
d2182a66 | 14371 | !intel_dp_is_edp(dev, PORT_C)) |
e66eb81d VS |
14372 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
14373 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
e17ac6db | 14374 | intel_dp_is_edp(dev, PORT_C)) |
e66eb81d | 14375 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
19c03924 | 14376 | |
9418c1f1 | 14377 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14378 | /* eDP not supported on port D, so don't check VBT */ |
e66eb81d VS |
14379 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
14380 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14381 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14382 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
9418c1f1 VS |
14383 | } |
14384 | ||
3cfca973 | 14385 | intel_dsi_init(dev); |
09da55dc | 14386 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14387 | bool found = false; |
7d57382e | 14388 | |
e2debe91 | 14389 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14390 | DRM_DEBUG_KMS("probing SDVOB\n"); |
2a5c0832 | 14391 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
3fec3d2f | 14392 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14393 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14394 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14395 | } |
27185ae1 | 14396 | |
3fec3d2f | 14397 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14398 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14399 | } |
13520b05 KH |
14400 | |
14401 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14402 | |
e2debe91 | 14403 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14404 | DRM_DEBUG_KMS("probing SDVOC\n"); |
2a5c0832 | 14405 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
b01f2c3a | 14406 | } |
27185ae1 | 14407 | |
e2debe91 | 14408 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14409 | |
3fec3d2f | 14410 | if (IS_G4X(dev)) { |
b01f2c3a | 14411 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14412 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14413 | } |
3fec3d2f | 14414 | if (IS_G4X(dev)) |
ab9d7c30 | 14415 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14416 | } |
27185ae1 | 14417 | |
3fec3d2f | 14418 | if (IS_G4X(dev) && |
e7281eab | 14419 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14420 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14421 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14422 | intel_dvo_init(dev); |
14423 | ||
103a196f | 14424 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14425 | intel_tv_init(dev); |
14426 | ||
0bc12bcb | 14427 | intel_psr_init(dev); |
7c8f8a70 | 14428 | |
b2784e15 | 14429 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14430 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14431 | encoder->base.possible_clones = | |
66a9278e | 14432 | intel_encoder_clones(encoder); |
79e53945 | 14433 | } |
47356eb6 | 14434 | |
dde86e2d | 14435 | intel_init_pch_refclk(dev); |
270b3042 DV |
14436 | |
14437 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14438 | } |
14439 | ||
14440 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14441 | { | |
60a5ca01 | 14442 | struct drm_device *dev = fb->dev; |
79e53945 | 14443 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14444 | |
ef2d633e | 14445 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14446 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14447 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14448 | drm_gem_object_unreference(&intel_fb->obj->base); |
14449 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14450 | kfree(intel_fb); |
14451 | } | |
14452 | ||
14453 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14454 | struct drm_file *file, |
79e53945 JB |
14455 | unsigned int *handle) |
14456 | { | |
14457 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14458 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14459 | |
cc917ab4 CW |
14460 | if (obj->userptr.mm) { |
14461 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); | |
14462 | return -EINVAL; | |
14463 | } | |
14464 | ||
05394f39 | 14465 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14466 | } |
14467 | ||
86c98588 RV |
14468 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14469 | struct drm_file *file, | |
14470 | unsigned flags, unsigned color, | |
14471 | struct drm_clip_rect *clips, | |
14472 | unsigned num_clips) | |
14473 | { | |
14474 | struct drm_device *dev = fb->dev; | |
14475 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14476 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14477 | ||
14478 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14479 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14480 | mutex_unlock(&dev->struct_mutex); |
14481 | ||
14482 | return 0; | |
14483 | } | |
14484 | ||
79e53945 JB |
14485 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14486 | .destroy = intel_user_framebuffer_destroy, | |
14487 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14488 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14489 | }; |
14490 | ||
b321803d DL |
14491 | static |
14492 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14493 | uint32_t pixel_format) | |
14494 | { | |
14495 | u32 gen = INTEL_INFO(dev)->gen; | |
14496 | ||
14497 | if (gen >= 9) { | |
14498 | /* "The stride in bytes must not exceed the of the size of 8K | |
14499 | * pixels and 32K bytes." | |
14500 | */ | |
14501 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14502 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14503 | return 32*1024; | |
14504 | } else if (gen >= 4) { | |
14505 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14506 | return 16*1024; | |
14507 | else | |
14508 | return 32*1024; | |
14509 | } else if (gen >= 3) { | |
14510 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14511 | return 8*1024; | |
14512 | else | |
14513 | return 16*1024; | |
14514 | } else { | |
14515 | /* XXX DSPC is limited to 4k tiled */ | |
14516 | return 8*1024; | |
14517 | } | |
14518 | } | |
14519 | ||
b5ea642a DV |
14520 | static int intel_framebuffer_init(struct drm_device *dev, |
14521 | struct intel_framebuffer *intel_fb, | |
14522 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14523 | struct drm_i915_gem_object *obj) | |
79e53945 | 14524 | { |
6761dd31 | 14525 | unsigned int aligned_height; |
79e53945 | 14526 | int ret; |
b321803d | 14527 | u32 pitch_limit, stride_alignment; |
79e53945 | 14528 | |
dd4916c5 DV |
14529 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14530 | ||
2a80eada DV |
14531 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14532 | /* Enforce that fb modifier and tiling mode match, but only for | |
14533 | * X-tiled. This is needed for FBC. */ | |
14534 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14535 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14536 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14537 | return -EINVAL; | |
14538 | } | |
14539 | } else { | |
14540 | if (obj->tiling_mode == I915_TILING_X) | |
14541 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14542 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14543 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14544 | return -EINVAL; | |
14545 | } | |
14546 | } | |
14547 | ||
9a8f0a12 TU |
14548 | /* Passed in modifier sanity checking. */ |
14549 | switch (mode_cmd->modifier[0]) { | |
14550 | case I915_FORMAT_MOD_Y_TILED: | |
14551 | case I915_FORMAT_MOD_Yf_TILED: | |
14552 | if (INTEL_INFO(dev)->gen < 9) { | |
14553 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14554 | mode_cmd->modifier[0]); | |
14555 | return -EINVAL; | |
14556 | } | |
14557 | case DRM_FORMAT_MOD_NONE: | |
14558 | case I915_FORMAT_MOD_X_TILED: | |
14559 | break; | |
14560 | default: | |
c0f40428 JB |
14561 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14562 | mode_cmd->modifier[0]); | |
57cd6508 | 14563 | return -EINVAL; |
c16ed4be | 14564 | } |
57cd6508 | 14565 | |
b321803d DL |
14566 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14567 | mode_cmd->pixel_format); | |
14568 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14569 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14570 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14571 | return -EINVAL; |
c16ed4be | 14572 | } |
57cd6508 | 14573 | |
b321803d DL |
14574 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14575 | mode_cmd->pixel_format); | |
a35cdaa0 | 14576 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14577 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14578 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14579 | "tiled" : "linear", |
a35cdaa0 | 14580 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14581 | return -EINVAL; |
c16ed4be | 14582 | } |
5d7bd705 | 14583 | |
2a80eada | 14584 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14585 | mode_cmd->pitches[0] != obj->stride) { |
14586 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14587 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14588 | return -EINVAL; |
c16ed4be | 14589 | } |
5d7bd705 | 14590 | |
57779d06 | 14591 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14592 | switch (mode_cmd->pixel_format) { |
57779d06 | 14593 | case DRM_FORMAT_C8: |
04b3924d VS |
14594 | case DRM_FORMAT_RGB565: |
14595 | case DRM_FORMAT_XRGB8888: | |
14596 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14597 | break; |
14598 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14599 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14600 | DRM_DEBUG("unsupported pixel format: %s\n", |
14601 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14602 | return -EINVAL; |
c16ed4be | 14603 | } |
57779d06 | 14604 | break; |
57779d06 | 14605 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14606 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14607 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14608 | drm_get_format_name(mode_cmd->pixel_format)); | |
14609 | return -EINVAL; | |
14610 | } | |
14611 | break; | |
14612 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14613 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14614 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14615 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14616 | DRM_DEBUG("unsupported pixel format: %s\n", |
14617 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14618 | return -EINVAL; |
c16ed4be | 14619 | } |
b5626747 | 14620 | break; |
7531208b DL |
14621 | case DRM_FORMAT_ABGR2101010: |
14622 | if (!IS_VALLEYVIEW(dev)) { | |
14623 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14624 | drm_get_format_name(mode_cmd->pixel_format)); | |
14625 | return -EINVAL; | |
14626 | } | |
14627 | break; | |
04b3924d VS |
14628 | case DRM_FORMAT_YUYV: |
14629 | case DRM_FORMAT_UYVY: | |
14630 | case DRM_FORMAT_YVYU: | |
14631 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14632 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14633 | DRM_DEBUG("unsupported pixel format: %s\n", |
14634 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14635 | return -EINVAL; |
c16ed4be | 14636 | } |
57cd6508 CW |
14637 | break; |
14638 | default: | |
4ee62c76 VS |
14639 | DRM_DEBUG("unsupported pixel format: %s\n", |
14640 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14641 | return -EINVAL; |
14642 | } | |
14643 | ||
90f9a336 VS |
14644 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14645 | if (mode_cmd->offsets[0] != 0) | |
14646 | return -EINVAL; | |
14647 | ||
ec2c981e | 14648 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14649 | mode_cmd->pixel_format, |
14650 | mode_cmd->modifier[0]); | |
53155c0a DV |
14651 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14652 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14653 | return -EINVAL; | |
14654 | ||
c7d73f6a DV |
14655 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14656 | intel_fb->obj = obj; | |
80075d49 | 14657 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14658 | |
79e53945 JB |
14659 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14660 | if (ret) { | |
14661 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14662 | return ret; | |
14663 | } | |
14664 | ||
79e53945 JB |
14665 | return 0; |
14666 | } | |
14667 | ||
79e53945 JB |
14668 | static struct drm_framebuffer * |
14669 | intel_user_framebuffer_create(struct drm_device *dev, | |
14670 | struct drm_file *filp, | |
76dc3769 | 14671 | struct drm_mode_fb_cmd2 *user_mode_cmd) |
79e53945 | 14672 | { |
dcb1394e | 14673 | struct drm_framebuffer *fb; |
05394f39 | 14674 | struct drm_i915_gem_object *obj; |
76dc3769 | 14675 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
79e53945 | 14676 | |
308e5bcb | 14677 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
76dc3769 | 14678 | mode_cmd.handles[0])); |
c8725226 | 14679 | if (&obj->base == NULL) |
cce13ff7 | 14680 | return ERR_PTR(-ENOENT); |
79e53945 | 14681 | |
92907cbb | 14682 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
dcb1394e LW |
14683 | if (IS_ERR(fb)) |
14684 | drm_gem_object_unreference_unlocked(&obj->base); | |
14685 | ||
14686 | return fb; | |
79e53945 JB |
14687 | } |
14688 | ||
0695726e | 14689 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 14690 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14691 | { |
14692 | } | |
14693 | #endif | |
14694 | ||
79e53945 | 14695 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14696 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14697 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14698 | .atomic_check = intel_atomic_check, |
14699 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14700 | .atomic_state_alloc = intel_atomic_state_alloc, |
14701 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14702 | }; |
14703 | ||
e70236a8 JB |
14704 | /* Set up chip specific display functions */ |
14705 | static void intel_init_display(struct drm_device *dev) | |
14706 | { | |
14707 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14708 | ||
ee9300bb DV |
14709 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14710 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14711 | else if (IS_CHERRYVIEW(dev)) |
14712 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14713 | else if (IS_VALLEYVIEW(dev)) |
14714 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14715 | else if (IS_PINEVIEW(dev)) | |
14716 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14717 | else | |
14718 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14719 | ||
bc8d7dff DL |
14720 | if (INTEL_INFO(dev)->gen >= 9) { |
14721 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14722 | dev_priv->display.get_initial_plane_config = |
14723 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14724 | dev_priv->display.crtc_compute_clock = |
14725 | haswell_crtc_compute_clock; | |
14726 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14727 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14728 | dev_priv->display.update_primary_plane = |
14729 | skylake_update_primary_plane; | |
14730 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14731 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14732 | dev_priv->display.get_initial_plane_config = |
14733 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14734 | dev_priv->display.crtc_compute_clock = |
14735 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14736 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14737 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14738 | dev_priv->display.update_primary_plane = |
14739 | ironlake_update_primary_plane; | |
09b4ddf9 | 14740 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14741 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14742 | dev_priv->display.get_initial_plane_config = |
14743 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14744 | dev_priv->display.crtc_compute_clock = |
14745 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14746 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14747 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14748 | dev_priv->display.update_primary_plane = |
14749 | ironlake_update_primary_plane; | |
89b667f8 JB |
14750 | } else if (IS_VALLEYVIEW(dev)) { |
14751 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14752 | dev_priv->display.get_initial_plane_config = |
14753 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14754 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14755 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14756 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14757 | dev_priv->display.update_primary_plane = |
14758 | i9xx_update_primary_plane; | |
f564048e | 14759 | } else { |
0e8ffe1b | 14760 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14761 | dev_priv->display.get_initial_plane_config = |
14762 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14763 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14764 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14765 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14766 | dev_priv->display.update_primary_plane = |
14767 | i9xx_update_primary_plane; | |
f564048e | 14768 | } |
e70236a8 | 14769 | |
e70236a8 | 14770 | /* Returns the core display clock speed */ |
ef11bdb3 | 14771 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
1652d19e VS |
14772 | dev_priv->display.get_display_clock_speed = |
14773 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
14774 | else if (IS_BROXTON(dev)) |
14775 | dev_priv->display.get_display_clock_speed = | |
14776 | broxton_get_display_clock_speed; | |
1652d19e VS |
14777 | else if (IS_BROADWELL(dev)) |
14778 | dev_priv->display.get_display_clock_speed = | |
14779 | broadwell_get_display_clock_speed; | |
14780 | else if (IS_HASWELL(dev)) | |
14781 | dev_priv->display.get_display_clock_speed = | |
14782 | haswell_get_display_clock_speed; | |
14783 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14784 | dev_priv->display.get_display_clock_speed = |
14785 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14786 | else if (IS_GEN5(dev)) |
14787 | dev_priv->display.get_display_clock_speed = | |
14788 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14789 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14790 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14791 | dev_priv->display.get_display_clock_speed = |
14792 | i945_get_display_clock_speed; | |
34edce2f VS |
14793 | else if (IS_GM45(dev)) |
14794 | dev_priv->display.get_display_clock_speed = | |
14795 | gm45_get_display_clock_speed; | |
14796 | else if (IS_CRESTLINE(dev)) | |
14797 | dev_priv->display.get_display_clock_speed = | |
14798 | i965gm_get_display_clock_speed; | |
14799 | else if (IS_PINEVIEW(dev)) | |
14800 | dev_priv->display.get_display_clock_speed = | |
14801 | pnv_get_display_clock_speed; | |
14802 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14803 | dev_priv->display.get_display_clock_speed = | |
14804 | g33_get_display_clock_speed; | |
e70236a8 JB |
14805 | else if (IS_I915G(dev)) |
14806 | dev_priv->display.get_display_clock_speed = | |
14807 | i915_get_display_clock_speed; | |
257a7ffc | 14808 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14809 | dev_priv->display.get_display_clock_speed = |
14810 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14811 | else if (IS_PINEVIEW(dev)) |
14812 | dev_priv->display.get_display_clock_speed = | |
14813 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14814 | else if (IS_I915GM(dev)) |
14815 | dev_priv->display.get_display_clock_speed = | |
14816 | i915gm_get_display_clock_speed; | |
14817 | else if (IS_I865G(dev)) | |
14818 | dev_priv->display.get_display_clock_speed = | |
14819 | i865_get_display_clock_speed; | |
f0f8a9ce | 14820 | else if (IS_I85X(dev)) |
e70236a8 | 14821 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14822 | i85x_get_display_clock_speed; |
623e01e5 VS |
14823 | else { /* 830 */ |
14824 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14825 | dev_priv->display.get_display_clock_speed = |
14826 | i830_get_display_clock_speed; | |
623e01e5 | 14827 | } |
e70236a8 | 14828 | |
7c10a2b5 | 14829 | if (IS_GEN5(dev)) { |
3bb11b53 | 14830 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14831 | } else if (IS_GEN6(dev)) { |
14832 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14833 | } else if (IS_IVYBRIDGE(dev)) { |
14834 | /* FIXME: detect B0+ stepping and use auto training */ | |
14835 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14836 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14837 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
14838 | if (IS_BROADWELL(dev)) { |
14839 | dev_priv->display.modeset_commit_cdclk = | |
14840 | broadwell_modeset_commit_cdclk; | |
14841 | dev_priv->display.modeset_calc_cdclk = | |
14842 | broadwell_modeset_calc_cdclk; | |
14843 | } | |
30a970c6 | 14844 | } else if (IS_VALLEYVIEW(dev)) { |
27c329ed ML |
14845 | dev_priv->display.modeset_commit_cdclk = |
14846 | valleyview_modeset_commit_cdclk; | |
14847 | dev_priv->display.modeset_calc_cdclk = | |
14848 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 14849 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
14850 | dev_priv->display.modeset_commit_cdclk = |
14851 | broxton_modeset_commit_cdclk; | |
14852 | dev_priv->display.modeset_calc_cdclk = | |
14853 | broxton_modeset_calc_cdclk; | |
e70236a8 | 14854 | } |
8c9f3aaf | 14855 | |
8c9f3aaf JB |
14856 | switch (INTEL_INFO(dev)->gen) { |
14857 | case 2: | |
14858 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14859 | break; | |
14860 | ||
14861 | case 3: | |
14862 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14863 | break; | |
14864 | ||
14865 | case 4: | |
14866 | case 5: | |
14867 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14868 | break; | |
14869 | ||
14870 | case 6: | |
14871 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14872 | break; | |
7c9017e5 | 14873 | case 7: |
4e0bbc31 | 14874 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14875 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14876 | break; | |
830c81db | 14877 | case 9: |
ba343e02 TU |
14878 | /* Drop through - unsupported since execlist only. */ |
14879 | default: | |
14880 | /* Default just returns -ENODEV to indicate unsupported */ | |
14881 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14882 | } |
7bd688cd | 14883 | |
e39b999a | 14884 | mutex_init(&dev_priv->pps_mutex); |
e70236a8 JB |
14885 | } |
14886 | ||
b690e96c JB |
14887 | /* |
14888 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14889 | * resume, or other times. This quirk makes sure that's the case for | |
14890 | * affected systems. | |
14891 | */ | |
0206e353 | 14892 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14893 | { |
14894 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14895 | ||
14896 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14897 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14898 | } |
14899 | ||
b6b5d049 VS |
14900 | static void quirk_pipeb_force(struct drm_device *dev) |
14901 | { | |
14902 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14903 | ||
14904 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14905 | DRM_INFO("applying pipe b force quirk\n"); | |
14906 | } | |
14907 | ||
435793df KP |
14908 | /* |
14909 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14910 | */ | |
14911 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14912 | { | |
14913 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14914 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14915 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14916 | } |
14917 | ||
4dca20ef | 14918 | /* |
5a15ab5b CE |
14919 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14920 | * brightness value | |
4dca20ef CE |
14921 | */ |
14922 | static void quirk_invert_brightness(struct drm_device *dev) | |
14923 | { | |
14924 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14925 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14926 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14927 | } |
14928 | ||
9c72cc6f SD |
14929 | /* Some VBT's incorrectly indicate no backlight is present */ |
14930 | static void quirk_backlight_present(struct drm_device *dev) | |
14931 | { | |
14932 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14933 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14934 | DRM_INFO("applying backlight present quirk\n"); | |
14935 | } | |
14936 | ||
b690e96c JB |
14937 | struct intel_quirk { |
14938 | int device; | |
14939 | int subsystem_vendor; | |
14940 | int subsystem_device; | |
14941 | void (*hook)(struct drm_device *dev); | |
14942 | }; | |
14943 | ||
5f85f176 EE |
14944 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14945 | struct intel_dmi_quirk { | |
14946 | void (*hook)(struct drm_device *dev); | |
14947 | const struct dmi_system_id (*dmi_id_list)[]; | |
14948 | }; | |
14949 | ||
14950 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14951 | { | |
14952 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14953 | return 1; | |
14954 | } | |
14955 | ||
14956 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14957 | { | |
14958 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14959 | { | |
14960 | .callback = intel_dmi_reverse_brightness, | |
14961 | .ident = "NCR Corporation", | |
14962 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14963 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14964 | }, | |
14965 | }, | |
14966 | { } /* terminating entry */ | |
14967 | }, | |
14968 | .hook = quirk_invert_brightness, | |
14969 | }, | |
14970 | }; | |
14971 | ||
c43b5634 | 14972 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14973 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14974 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14975 | ||
b690e96c JB |
14976 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14977 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14978 | ||
5f080c0f VS |
14979 | /* 830 needs to leave pipe A & dpll A up */ |
14980 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14981 | ||
b6b5d049 VS |
14982 | /* 830 needs to leave pipe B & dpll B up */ |
14983 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14984 | ||
435793df KP |
14985 | /* Lenovo U160 cannot use SSC on LVDS */ |
14986 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14987 | |
14988 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14989 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14990 | |
be505f64 AH |
14991 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14992 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14993 | ||
14994 | /* Acer/eMachines G725 */ | |
14995 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14996 | ||
14997 | /* Acer/eMachines e725 */ | |
14998 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14999 | ||
15000 | /* Acer/Packard Bell NCL20 */ | |
15001 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
15002 | ||
15003 | /* Acer Aspire 4736Z */ | |
15004 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
15005 | |
15006 | /* Acer Aspire 5336 */ | |
15007 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
15008 | |
15009 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
15010 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 15011 | |
dfb3d47b SD |
15012 | /* Acer C720 Chromebook (Core i3 4005U) */ |
15013 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
15014 | ||
b2a9601c | 15015 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
15016 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
15017 | ||
1b9448b0 JN |
15018 | /* Apple Macbook 4,1 */ |
15019 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, | |
15020 | ||
d4967d8c SD |
15021 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
15022 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
15023 | |
15024 | /* HP Chromebook 14 (Celeron 2955U) */ | |
15025 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
15026 | |
15027 | /* Dell Chromebook 11 */ | |
15028 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
9be64eee JN |
15029 | |
15030 | /* Dell Chromebook 11 (2015 version) */ | |
15031 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
15032 | }; |
15033 | ||
15034 | static void intel_init_quirks(struct drm_device *dev) | |
15035 | { | |
15036 | struct pci_dev *d = dev->pdev; | |
15037 | int i; | |
15038 | ||
15039 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
15040 | struct intel_quirk *q = &intel_quirks[i]; | |
15041 | ||
15042 | if (d->device == q->device && | |
15043 | (d->subsystem_vendor == q->subsystem_vendor || | |
15044 | q->subsystem_vendor == PCI_ANY_ID) && | |
15045 | (d->subsystem_device == q->subsystem_device || | |
15046 | q->subsystem_device == PCI_ANY_ID)) | |
15047 | q->hook(dev); | |
15048 | } | |
5f85f176 EE |
15049 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
15050 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
15051 | intel_dmi_quirks[i].hook(dev); | |
15052 | } | |
b690e96c JB |
15053 | } |
15054 | ||
9cce37f4 JB |
15055 | /* Disable the VGA plane that we never use */ |
15056 | static void i915_disable_vga(struct drm_device *dev) | |
15057 | { | |
15058 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15059 | u8 sr1; | |
f0f59a00 | 15060 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 15061 | |
2b37c616 | 15062 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 15063 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 15064 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
15065 | sr1 = inb(VGA_SR_DATA); |
15066 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15067 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15068 | udelay(300); | |
15069 | ||
01f5a626 | 15070 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
15071 | POSTING_READ(vga_reg); |
15072 | } | |
15073 | ||
f817586c DV |
15074 | void intel_modeset_init_hw(struct drm_device *dev) |
15075 | { | |
b6283055 | 15076 | intel_update_cdclk(dev); |
a8f78b58 | 15077 | intel_prepare_ddi(dev); |
f817586c | 15078 | intel_init_clock_gating(dev); |
8090c6b9 | 15079 | intel_enable_gt_powersave(dev); |
f817586c DV |
15080 | } |
15081 | ||
79e53945 JB |
15082 | void intel_modeset_init(struct drm_device *dev) |
15083 | { | |
652c393a | 15084 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 15085 | int sprite, ret; |
8cc87b75 | 15086 | enum pipe pipe; |
46f297fb | 15087 | struct intel_crtc *crtc; |
79e53945 JB |
15088 | |
15089 | drm_mode_config_init(dev); | |
15090 | ||
15091 | dev->mode_config.min_width = 0; | |
15092 | dev->mode_config.min_height = 0; | |
15093 | ||
019d96cb DA |
15094 | dev->mode_config.preferred_depth = 24; |
15095 | dev->mode_config.prefer_shadow = 1; | |
15096 | ||
25bab385 TU |
15097 | dev->mode_config.allow_fb_modifiers = true; |
15098 | ||
e6ecefaa | 15099 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 15100 | |
b690e96c JB |
15101 | intel_init_quirks(dev); |
15102 | ||
1fa61106 ED |
15103 | intel_init_pm(dev); |
15104 | ||
e3c74757 BW |
15105 | if (INTEL_INFO(dev)->num_pipes == 0) |
15106 | return; | |
15107 | ||
69f92f67 LW |
15108 | /* |
15109 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15110 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15111 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15112 | * indicates as much. | |
15113 | */ | |
15114 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
15115 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15116 | DREF_SSC1_ENABLE); | |
15117 | ||
15118 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
15119 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
15120 | bios_lvds_use_ssc ? "en" : "dis", | |
15121 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
15122 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
15123 | } | |
15124 | } | |
15125 | ||
e70236a8 | 15126 | intel_init_display(dev); |
7c10a2b5 | 15127 | intel_init_audio(dev); |
e70236a8 | 15128 | |
a6c45cf0 CW |
15129 | if (IS_GEN2(dev)) { |
15130 | dev->mode_config.max_width = 2048; | |
15131 | dev->mode_config.max_height = 2048; | |
15132 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15133 | dev->mode_config.max_width = 4096; |
15134 | dev->mode_config.max_height = 4096; | |
79e53945 | 15135 | } else { |
a6c45cf0 CW |
15136 | dev->mode_config.max_width = 8192; |
15137 | dev->mode_config.max_height = 8192; | |
79e53945 | 15138 | } |
068be561 | 15139 | |
dc41c154 VS |
15140 | if (IS_845G(dev) || IS_I865G(dev)) { |
15141 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15142 | dev->mode_config.cursor_height = 1023; | |
15143 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15144 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15145 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15146 | } else { | |
15147 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15148 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15149 | } | |
15150 | ||
5d4545ae | 15151 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15152 | |
28c97730 | 15153 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15154 | INTEL_INFO(dev)->num_pipes, |
15155 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15156 | |
055e393f | 15157 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15158 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15159 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15160 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15161 | if (ret) |
06da8da2 | 15162 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15163 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15164 | } |
79e53945 JB |
15165 | } |
15166 | ||
bfa7df01 VS |
15167 | intel_update_czclk(dev_priv); |
15168 | intel_update_cdclk(dev); | |
15169 | ||
e72f9fbf | 15170 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15171 | |
9cce37f4 JB |
15172 | /* Just disable it once at startup */ |
15173 | i915_disable_vga(dev); | |
79e53945 | 15174 | intel_setup_outputs(dev); |
11be49eb | 15175 | |
6e9f798d | 15176 | drm_modeset_lock_all(dev); |
043e9bda | 15177 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15178 | drm_modeset_unlock_all(dev); |
46f297fb | 15179 | |
d3fcc808 | 15180 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15181 | struct intel_initial_plane_config plane_config = {}; |
15182 | ||
46f297fb JB |
15183 | if (!crtc->active) |
15184 | continue; | |
15185 | ||
46f297fb | 15186 | /* |
46f297fb JB |
15187 | * Note that reserving the BIOS fb up front prevents us |
15188 | * from stuffing other stolen allocations like the ring | |
15189 | * on top. This prevents some ugliness at boot time, and | |
15190 | * can even allow for smooth boot transitions if the BIOS | |
15191 | * fb is large enough for the active pipe configuration. | |
15192 | */ | |
eeebeac5 ML |
15193 | dev_priv->display.get_initial_plane_config(crtc, |
15194 | &plane_config); | |
15195 | ||
15196 | /* | |
15197 | * If the fb is shared between multiple heads, we'll | |
15198 | * just get the first one. | |
15199 | */ | |
15200 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15201 | } |
2c7111db CW |
15202 | } |
15203 | ||
7fad798e DV |
15204 | static void intel_enable_pipe_a(struct drm_device *dev) |
15205 | { | |
15206 | struct intel_connector *connector; | |
15207 | struct drm_connector *crt = NULL; | |
15208 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15209 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15210 | |
15211 | /* We can't just switch on the pipe A, we need to set things up with a | |
15212 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15213 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15214 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15215 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15216 | crt = &connector->base; | |
15217 | break; | |
15218 | } | |
15219 | } | |
15220 | ||
15221 | if (!crt) | |
15222 | return; | |
15223 | ||
208bf9fd | 15224 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15225 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15226 | } |
15227 | ||
fa555837 DV |
15228 | static bool |
15229 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15230 | { | |
7eb552ae BW |
15231 | struct drm_device *dev = crtc->base.dev; |
15232 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15233 | u32 val; |
fa555837 | 15234 | |
7eb552ae | 15235 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15236 | return true; |
15237 | ||
649636ef | 15238 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15239 | |
15240 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15241 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15242 | return false; | |
15243 | ||
15244 | return true; | |
15245 | } | |
15246 | ||
02e93c35 VS |
15247 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15248 | { | |
15249 | struct drm_device *dev = crtc->base.dev; | |
15250 | struct intel_encoder *encoder; | |
15251 | ||
15252 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15253 | return true; | |
15254 | ||
15255 | return false; | |
15256 | } | |
15257 | ||
24929352 DV |
15258 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15259 | { | |
15260 | struct drm_device *dev = crtc->base.dev; | |
15261 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15262 | i915_reg_t reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 | 15263 | |
24929352 | 15264 | /* Clear any frame start delays used for debugging left by the BIOS */ |
24929352 DV |
15265 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15266 | ||
d3eaf884 | 15267 | /* restore vblank interrupts to correct state */ |
9625604c | 15268 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15269 | if (crtc->active) { |
f9cd7b88 VS |
15270 | struct intel_plane *plane; |
15271 | ||
9625604c | 15272 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15273 | |
15274 | /* Disable everything but the primary plane */ | |
15275 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15276 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15277 | continue; | |
15278 | ||
15279 | plane->disable_plane(&plane->base, &crtc->base); | |
15280 | } | |
9625604c | 15281 | } |
d3eaf884 | 15282 | |
24929352 | 15283 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15284 | * disable the crtc (and hence change the state) if it is wrong. Note |
15285 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15286 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15287 | bool plane; |
15288 | ||
24929352 DV |
15289 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15290 | crtc->base.base.id); | |
15291 | ||
15292 | /* Pipe has the wrong plane attached and the plane is active. | |
15293 | * Temporarily change the plane mapping and disable everything | |
15294 | * ... */ | |
15295 | plane = crtc->plane; | |
b70709a6 | 15296 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15297 | crtc->plane = !plane; |
b17d48e2 | 15298 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15299 | crtc->plane = plane; |
24929352 | 15300 | } |
24929352 | 15301 | |
7fad798e DV |
15302 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15303 | crtc->pipe == PIPE_A && !crtc->active) { | |
15304 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15305 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15306 | * call below we restore the pipe to the right state, but leave | |
15307 | * the required bits on. */ | |
15308 | intel_enable_pipe_a(dev); | |
15309 | } | |
15310 | ||
24929352 DV |
15311 | /* Adjust the state of the output pipe according to whether we |
15312 | * have active connectors/encoders. */ | |
02e93c35 | 15313 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15314 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15315 | |
53d9f4e9 | 15316 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 15317 | struct intel_encoder *encoder; |
24929352 DV |
15318 | |
15319 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15320 | * functions or because of calls to intel_crtc_disable_noatomic, |
15321 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15322 | * pipe A quirk. */ |
15323 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15324 | crtc->base.base.id, | |
83d65738 | 15325 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15326 | crtc->active ? "enabled" : "disabled"); |
15327 | ||
4be40c98 | 15328 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 15329 | crtc->base.state->active = crtc->active; |
24929352 DV |
15330 | crtc->base.enabled = crtc->active; |
15331 | ||
15332 | /* Because we only establish the connector -> encoder -> | |
15333 | * crtc links if something is active, this means the | |
15334 | * crtc is now deactivated. Break the links. connector | |
15335 | * -> encoder links are only establish when things are | |
15336 | * actually up, hence no need to break them. */ | |
15337 | WARN_ON(crtc->active); | |
15338 | ||
2d406bb0 | 15339 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 15340 | encoder->base.crtc = NULL; |
24929352 | 15341 | } |
c5ab3bc0 | 15342 | |
a3ed6aad | 15343 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15344 | /* |
15345 | * We start out with underrun reporting disabled to avoid races. | |
15346 | * For correct bookkeeping mark this on active crtcs. | |
15347 | * | |
c5ab3bc0 DV |
15348 | * Also on gmch platforms we dont have any hardware bits to |
15349 | * disable the underrun reporting. Which means we need to start | |
15350 | * out with underrun reporting disabled also on inactive pipes, | |
15351 | * since otherwise we'll complain about the garbage we read when | |
15352 | * e.g. coming up after runtime pm. | |
15353 | * | |
4cc31489 DV |
15354 | * No protection against concurrent access is required - at |
15355 | * worst a fifo underrun happens which also sets this to false. | |
15356 | */ | |
15357 | crtc->cpu_fifo_underrun_disabled = true; | |
15358 | crtc->pch_fifo_underrun_disabled = true; | |
15359 | } | |
24929352 DV |
15360 | } |
15361 | ||
15362 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15363 | { | |
15364 | struct intel_connector *connector; | |
15365 | struct drm_device *dev = encoder->base.dev; | |
873ffe69 | 15366 | bool active = false; |
24929352 DV |
15367 | |
15368 | /* We need to check both for a crtc link (meaning that the | |
15369 | * encoder is active and trying to read from a pipe) and the | |
15370 | * pipe itself being active. */ | |
15371 | bool has_active_crtc = encoder->base.crtc && | |
15372 | to_intel_crtc(encoder->base.crtc)->active; | |
15373 | ||
873ffe69 ML |
15374 | for_each_intel_connector(dev, connector) { |
15375 | if (connector->base.encoder != &encoder->base) | |
15376 | continue; | |
15377 | ||
15378 | active = true; | |
15379 | break; | |
15380 | } | |
15381 | ||
15382 | if (active && !has_active_crtc) { | |
24929352 DV |
15383 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15384 | encoder->base.base.id, | |
8e329a03 | 15385 | encoder->base.name); |
24929352 DV |
15386 | |
15387 | /* Connector is active, but has no active pipe. This is | |
15388 | * fallout from our resume register restoring. Disable | |
15389 | * the encoder manually again. */ | |
15390 | if (encoder->base.crtc) { | |
15391 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15392 | encoder->base.base.id, | |
8e329a03 | 15393 | encoder->base.name); |
24929352 | 15394 | encoder->disable(encoder); |
a62d1497 VS |
15395 | if (encoder->post_disable) |
15396 | encoder->post_disable(encoder); | |
24929352 | 15397 | } |
7f1950fb | 15398 | encoder->base.crtc = NULL; |
24929352 DV |
15399 | |
15400 | /* Inconsistent output/port/pipe state happens presumably due to | |
15401 | * a bug in one of the get_hw_state functions. Or someplace else | |
15402 | * in our code, like the register restore mess on resume. Clamp | |
15403 | * things to off as a safer default. */ | |
3a3371ff | 15404 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15405 | if (connector->encoder != encoder) |
15406 | continue; | |
7f1950fb EE |
15407 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15408 | connector->base.encoder = NULL; | |
24929352 DV |
15409 | } |
15410 | } | |
15411 | /* Enabled encoders without active connectors will be fixed in | |
15412 | * the crtc fixup. */ | |
15413 | } | |
15414 | ||
04098753 | 15415 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15416 | { |
15417 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15418 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15419 | |
04098753 ID |
15420 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15421 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15422 | i915_disable_vga(dev); | |
15423 | } | |
15424 | } | |
15425 | ||
15426 | void i915_redisable_vga(struct drm_device *dev) | |
15427 | { | |
15428 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15429 | ||
8dc8a27c PZ |
15430 | /* This function can be called both from intel_modeset_setup_hw_state or |
15431 | * at a very early point in our resume sequence, where the power well | |
15432 | * structures are not yet restored. Since this function is at a very | |
15433 | * paranoid "someone might have enabled VGA while we were not looking" | |
15434 | * level, just check if the power well is enabled instead of trying to | |
15435 | * follow the "don't touch the power well if we don't need it" policy | |
15436 | * the rest of the driver uses. */ | |
f458ebbc | 15437 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15438 | return; |
15439 | ||
04098753 | 15440 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15441 | } |
15442 | ||
f9cd7b88 | 15443 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15444 | { |
f9cd7b88 | 15445 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15446 | |
f9cd7b88 | 15447 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15448 | } |
15449 | ||
f9cd7b88 VS |
15450 | /* FIXME read out full plane state for all planes */ |
15451 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15452 | { |
b26d3ea3 | 15453 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15454 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15455 | to_intel_plane_state(primary->state); |
d032ffa0 | 15456 | |
19b8d387 | 15457 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
15458 | primary_get_hw_state(to_intel_plane(primary)); |
15459 | ||
15460 | if (plane_state->visible) | |
15461 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
15462 | } |
15463 | ||
30e984df | 15464 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15465 | { |
15466 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15467 | enum pipe pipe; | |
24929352 DV |
15468 | struct intel_crtc *crtc; |
15469 | struct intel_encoder *encoder; | |
15470 | struct intel_connector *connector; | |
5358901f | 15471 | int i; |
24929352 | 15472 | |
d3fcc808 | 15473 | for_each_intel_crtc(dev, crtc) { |
b06f8b0d | 15474 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
6e3c9717 | 15475 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15476 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15477 | |
0e8ffe1b | 15478 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15479 | crtc->config); |
24929352 | 15480 | |
49d6fa21 | 15481 | crtc->base.state->active = crtc->active; |
24929352 | 15482 | crtc->base.enabled = crtc->active; |
b70709a6 | 15483 | |
f9cd7b88 | 15484 | readout_plane_state(crtc); |
24929352 DV |
15485 | |
15486 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15487 | crtc->base.base.id, | |
15488 | crtc->active ? "enabled" : "disabled"); | |
15489 | } | |
15490 | ||
5358901f DV |
15491 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15492 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15493 | ||
3e369b76 ACO |
15494 | pll->on = pll->get_hw_state(dev_priv, pll, |
15495 | &pll->config.hw_state); | |
5358901f | 15496 | pll->active = 0; |
3e369b76 | 15497 | pll->config.crtc_mask = 0; |
d3fcc808 | 15498 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15499 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15500 | pll->active++; |
3e369b76 | 15501 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15502 | } |
5358901f | 15503 | } |
5358901f | 15504 | |
1e6f2ddc | 15505 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15506 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15507 | |
3e369b76 | 15508 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15509 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15510 | } |
15511 | ||
b2784e15 | 15512 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15513 | pipe = 0; |
15514 | ||
15515 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15516 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15517 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15518 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15519 | } else { |
15520 | encoder->base.crtc = NULL; | |
15521 | } | |
15522 | ||
6f2bcceb | 15523 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15524 | encoder->base.base.id, |
8e329a03 | 15525 | encoder->base.name, |
24929352 | 15526 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15527 | pipe_name(pipe)); |
24929352 DV |
15528 | } |
15529 | ||
3a3371ff | 15530 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15531 | if (connector->get_hw_state(connector)) { |
15532 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
24929352 DV |
15533 | connector->base.encoder = &connector->encoder->base; |
15534 | } else { | |
15535 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15536 | connector->base.encoder = NULL; | |
15537 | } | |
15538 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15539 | connector->base.base.id, | |
c23cc417 | 15540 | connector->base.name, |
24929352 DV |
15541 | connector->base.encoder ? "enabled" : "disabled"); |
15542 | } | |
7f4c6284 VS |
15543 | |
15544 | for_each_intel_crtc(dev, crtc) { | |
15545 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
15546 | ||
15547 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
15548 | if (crtc->base.state->active) { | |
15549 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
15550 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
15551 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
15552 | ||
15553 | /* | |
15554 | * The initial mode needs to be set in order to keep | |
15555 | * the atomic core happy. It wants a valid mode if the | |
15556 | * crtc's enabled, so we do the above call. | |
15557 | * | |
15558 | * At this point some state updated by the connectors | |
15559 | * in their ->detect() callback has not run yet, so | |
15560 | * no recalculation can be done yet. | |
15561 | * | |
15562 | * Even if we could do a recalculation and modeset | |
15563 | * right now it would cause a double modeset if | |
15564 | * fbdev or userspace chooses a different initial mode. | |
15565 | * | |
15566 | * If that happens, someone indicated they wanted a | |
15567 | * mode change, which means it's safe to do a full | |
15568 | * recalculation. | |
15569 | */ | |
15570 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
15571 | |
15572 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
15573 | update_scanline_offset(crtc); | |
7f4c6284 VS |
15574 | } |
15575 | } | |
30e984df DV |
15576 | } |
15577 | ||
043e9bda ML |
15578 | /* Scan out the current hw modeset state, |
15579 | * and sanitizes it to the current state | |
15580 | */ | |
15581 | static void | |
15582 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
15583 | { |
15584 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15585 | enum pipe pipe; | |
30e984df DV |
15586 | struct intel_crtc *crtc; |
15587 | struct intel_encoder *encoder; | |
35c95375 | 15588 | int i; |
30e984df DV |
15589 | |
15590 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
15591 | |
15592 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 15593 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15594 | intel_sanitize_encoder(encoder); |
15595 | } | |
15596 | ||
055e393f | 15597 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15598 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15599 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15600 | intel_dump_pipe_config(crtc, crtc->config, |
15601 | "[setup_hw_state]"); | |
24929352 | 15602 | } |
9a935856 | 15603 | |
d29b2f9d ACO |
15604 | intel_modeset_update_connector_atomic_state(dev); |
15605 | ||
35c95375 DV |
15606 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15607 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15608 | ||
15609 | if (!pll->on || pll->active) | |
15610 | continue; | |
15611 | ||
15612 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15613 | ||
15614 | pll->disable(dev_priv, pll); | |
15615 | pll->on = false; | |
15616 | } | |
15617 | ||
26e1fe4f | 15618 | if (IS_VALLEYVIEW(dev)) |
6eb1a681 VS |
15619 | vlv_wm_get_hw_state(dev); |
15620 | else if (IS_GEN9(dev)) | |
3078999f PB |
15621 | skl_wm_get_hw_state(dev); |
15622 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 15623 | ilk_wm_get_hw_state(dev); |
292b990e ML |
15624 | |
15625 | for_each_intel_crtc(dev, crtc) { | |
15626 | unsigned long put_domains; | |
15627 | ||
15628 | put_domains = modeset_get_crtc_power_domains(&crtc->base); | |
15629 | if (WARN_ON(put_domains)) | |
15630 | modeset_put_power_domains(dev_priv, put_domains); | |
15631 | } | |
15632 | intel_display_set_init_power(dev_priv, false); | |
043e9bda | 15633 | } |
7d0bc1ea | 15634 | |
043e9bda ML |
15635 | void intel_display_resume(struct drm_device *dev) |
15636 | { | |
15637 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); | |
15638 | struct intel_connector *conn; | |
15639 | struct intel_plane *plane; | |
15640 | struct drm_crtc *crtc; | |
15641 | int ret; | |
f30da187 | 15642 | |
043e9bda ML |
15643 | if (!state) |
15644 | return; | |
15645 | ||
15646 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
15647 | ||
15648 | /* preserve complete old state, including dpll */ | |
15649 | intel_atomic_get_shared_dpll_state(state); | |
15650 | ||
15651 | for_each_crtc(dev, crtc) { | |
15652 | struct drm_crtc_state *crtc_state = | |
15653 | drm_atomic_get_crtc_state(state, crtc); | |
15654 | ||
15655 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
15656 | if (ret) | |
15657 | goto err; | |
15658 | ||
15659 | /* force a restore */ | |
15660 | crtc_state->mode_changed = true; | |
45e2b5f6 | 15661 | } |
8af6cf88 | 15662 | |
043e9bda ML |
15663 | for_each_intel_plane(dev, plane) { |
15664 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); | |
15665 | if (ret) | |
15666 | goto err; | |
15667 | } | |
15668 | ||
15669 | for_each_intel_connector(dev, conn) { | |
15670 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); | |
15671 | if (ret) | |
15672 | goto err; | |
15673 | } | |
15674 | ||
15675 | intel_modeset_setup_hw_state(dev); | |
15676 | ||
15677 | i915_redisable_vga(dev); | |
74c090b1 | 15678 | ret = drm_atomic_commit(state); |
043e9bda ML |
15679 | if (!ret) |
15680 | return; | |
15681 | ||
15682 | err: | |
15683 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
15684 | drm_atomic_state_free(state); | |
2c7111db CW |
15685 | } |
15686 | ||
15687 | void intel_modeset_gem_init(struct drm_device *dev) | |
15688 | { | |
484b41dd | 15689 | struct drm_crtc *c; |
2ff8fde1 | 15690 | struct drm_i915_gem_object *obj; |
e0d6149b | 15691 | int ret; |
484b41dd | 15692 | |
ae48434c ID |
15693 | mutex_lock(&dev->struct_mutex); |
15694 | intel_init_gt_powersave(dev); | |
15695 | mutex_unlock(&dev->struct_mutex); | |
15696 | ||
1833b134 | 15697 | intel_modeset_init_hw(dev); |
02e792fb DV |
15698 | |
15699 | intel_setup_overlay(dev); | |
484b41dd JB |
15700 | |
15701 | /* | |
15702 | * Make sure any fbs we allocated at startup are properly | |
15703 | * pinned & fenced. When we do the allocation it's too early | |
15704 | * for this. | |
15705 | */ | |
70e1e0ec | 15706 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15707 | obj = intel_fb_obj(c->primary->fb); |
15708 | if (obj == NULL) | |
484b41dd JB |
15709 | continue; |
15710 | ||
e0d6149b TU |
15711 | mutex_lock(&dev->struct_mutex); |
15712 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15713 | c->primary->fb, | |
7580d774 | 15714 | c->primary->state); |
e0d6149b TU |
15715 | mutex_unlock(&dev->struct_mutex); |
15716 | if (ret) { | |
484b41dd JB |
15717 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15718 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15719 | drm_framebuffer_unreference(c->primary->fb); |
15720 | c->primary->fb = NULL; | |
36750f28 | 15721 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15722 | update_state_fb(c->primary); |
36750f28 | 15723 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15724 | } |
15725 | } | |
0962c3c9 VS |
15726 | |
15727 | intel_backlight_register(dev); | |
79e53945 JB |
15728 | } |
15729 | ||
4932e2c3 ID |
15730 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15731 | { | |
15732 | struct drm_connector *connector = &intel_connector->base; | |
15733 | ||
15734 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15735 | drm_connector_unregister(connector); |
4932e2c3 ID |
15736 | } |
15737 | ||
79e53945 JB |
15738 | void intel_modeset_cleanup(struct drm_device *dev) |
15739 | { | |
652c393a | 15740 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15741 | struct drm_connector *connector; |
652c393a | 15742 | |
2eb5252e ID |
15743 | intel_disable_gt_powersave(dev); |
15744 | ||
0962c3c9 VS |
15745 | intel_backlight_unregister(dev); |
15746 | ||
fd0c0642 DV |
15747 | /* |
15748 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15749 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15750 | * experience fancy races otherwise. |
15751 | */ | |
2aeb7d3a | 15752 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15753 | |
fd0c0642 DV |
15754 | /* |
15755 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15756 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15757 | */ | |
f87ea761 | 15758 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15759 | |
723bfd70 JB |
15760 | intel_unregister_dsm_handler(); |
15761 | ||
7733b49b | 15762 | intel_fbc_disable(dev_priv); |
69341a5e | 15763 | |
1630fe75 CW |
15764 | /* flush any delayed tasks or pending work */ |
15765 | flush_scheduled_work(); | |
15766 | ||
db31af1d JN |
15767 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15768 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15769 | struct intel_connector *intel_connector; |
15770 | ||
15771 | intel_connector = to_intel_connector(connector); | |
15772 | intel_connector->unregister(intel_connector); | |
db31af1d | 15773 | } |
d9255d57 | 15774 | |
79e53945 | 15775 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15776 | |
15777 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15778 | |
15779 | mutex_lock(&dev->struct_mutex); | |
15780 | intel_cleanup_gt_powersave(dev); | |
15781 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15782 | } |
15783 | ||
f1c79df3 ZW |
15784 | /* |
15785 | * Return which encoder is currently attached for connector. | |
15786 | */ | |
df0e9248 | 15787 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15788 | { |
df0e9248 CW |
15789 | return &intel_attached_encoder(connector)->base; |
15790 | } | |
f1c79df3 | 15791 | |
df0e9248 CW |
15792 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15793 | struct intel_encoder *encoder) | |
15794 | { | |
15795 | connector->encoder = encoder; | |
15796 | drm_mode_connector_attach_encoder(&connector->base, | |
15797 | &encoder->base); | |
79e53945 | 15798 | } |
28d52043 DA |
15799 | |
15800 | /* | |
15801 | * set vga decode state - true == enable VGA decode | |
15802 | */ | |
15803 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15804 | { | |
15805 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15806 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15807 | u16 gmch_ctrl; |
15808 | ||
75fa041d CW |
15809 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15810 | DRM_ERROR("failed to read control word\n"); | |
15811 | return -EIO; | |
15812 | } | |
15813 | ||
c0cc8a55 CW |
15814 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15815 | return 0; | |
15816 | ||
28d52043 DA |
15817 | if (state) |
15818 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15819 | else | |
15820 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15821 | |
15822 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15823 | DRM_ERROR("failed to write control word\n"); | |
15824 | return -EIO; | |
15825 | } | |
15826 | ||
28d52043 DA |
15827 | return 0; |
15828 | } | |
c4a1d9e4 | 15829 | |
c4a1d9e4 | 15830 | struct intel_display_error_state { |
ff57f1b0 PZ |
15831 | |
15832 | u32 power_well_driver; | |
15833 | ||
63b66e5b CW |
15834 | int num_transcoders; |
15835 | ||
c4a1d9e4 CW |
15836 | struct intel_cursor_error_state { |
15837 | u32 control; | |
15838 | u32 position; | |
15839 | u32 base; | |
15840 | u32 size; | |
52331309 | 15841 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15842 | |
15843 | struct intel_pipe_error_state { | |
ddf9c536 | 15844 | bool power_domain_on; |
c4a1d9e4 | 15845 | u32 source; |
f301b1e1 | 15846 | u32 stat; |
52331309 | 15847 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15848 | |
15849 | struct intel_plane_error_state { | |
15850 | u32 control; | |
15851 | u32 stride; | |
15852 | u32 size; | |
15853 | u32 pos; | |
15854 | u32 addr; | |
15855 | u32 surface; | |
15856 | u32 tile_offset; | |
52331309 | 15857 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15858 | |
15859 | struct intel_transcoder_error_state { | |
ddf9c536 | 15860 | bool power_domain_on; |
63b66e5b CW |
15861 | enum transcoder cpu_transcoder; |
15862 | ||
15863 | u32 conf; | |
15864 | ||
15865 | u32 htotal; | |
15866 | u32 hblank; | |
15867 | u32 hsync; | |
15868 | u32 vtotal; | |
15869 | u32 vblank; | |
15870 | u32 vsync; | |
15871 | } transcoder[4]; | |
c4a1d9e4 CW |
15872 | }; |
15873 | ||
15874 | struct intel_display_error_state * | |
15875 | intel_display_capture_error_state(struct drm_device *dev) | |
15876 | { | |
fbee40df | 15877 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15878 | struct intel_display_error_state *error; |
63b66e5b CW |
15879 | int transcoders[] = { |
15880 | TRANSCODER_A, | |
15881 | TRANSCODER_B, | |
15882 | TRANSCODER_C, | |
15883 | TRANSCODER_EDP, | |
15884 | }; | |
c4a1d9e4 CW |
15885 | int i; |
15886 | ||
63b66e5b CW |
15887 | if (INTEL_INFO(dev)->num_pipes == 0) |
15888 | return NULL; | |
15889 | ||
9d1cb914 | 15890 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15891 | if (error == NULL) |
15892 | return NULL; | |
15893 | ||
190be112 | 15894 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15895 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15896 | ||
055e393f | 15897 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15898 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15899 | __intel_display_power_is_enabled(dev_priv, |
15900 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15901 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15902 | continue; |
15903 | ||
5efb3e28 VS |
15904 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15905 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15906 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15907 | |
15908 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15909 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15910 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15911 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15912 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15913 | } | |
ca291363 PZ |
15914 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15915 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15916 | if (INTEL_INFO(dev)->gen >= 4) { |
15917 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15918 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15919 | } | |
15920 | ||
c4a1d9e4 | 15921 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15922 | |
3abfce77 | 15923 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15924 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15925 | } |
15926 | ||
15927 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15928 | if (HAS_DDI(dev_priv->dev)) | |
15929 | error->num_transcoders++; /* Account for eDP. */ | |
15930 | ||
15931 | for (i = 0; i < error->num_transcoders; i++) { | |
15932 | enum transcoder cpu_transcoder = transcoders[i]; | |
15933 | ||
ddf9c536 | 15934 | error->transcoder[i].power_domain_on = |
f458ebbc | 15935 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15936 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15937 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15938 | continue; |
15939 | ||
63b66e5b CW |
15940 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15941 | ||
15942 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15943 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15944 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15945 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15946 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15947 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15948 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15949 | } |
15950 | ||
15951 | return error; | |
15952 | } | |
15953 | ||
edc3d884 MK |
15954 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15955 | ||
c4a1d9e4 | 15956 | void |
edc3d884 | 15957 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15958 | struct drm_device *dev, |
15959 | struct intel_display_error_state *error) | |
15960 | { | |
055e393f | 15961 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15962 | int i; |
15963 | ||
63b66e5b CW |
15964 | if (!error) |
15965 | return; | |
15966 | ||
edc3d884 | 15967 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15968 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15969 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15970 | error->power_well_driver); |
055e393f | 15971 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15972 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15973 | err_printf(m, " Power: %s\n", |
15974 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15975 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15976 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15977 | |
15978 | err_printf(m, "Plane [%d]:\n", i); | |
15979 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15980 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15981 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15982 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15983 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15984 | } |
4b71a570 | 15985 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15986 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15987 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15988 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15989 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15990 | } |
15991 | ||
edc3d884 MK |
15992 | err_printf(m, "Cursor [%d]:\n", i); |
15993 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15994 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15995 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15996 | } |
63b66e5b CW |
15997 | |
15998 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15999 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 16000 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
16001 | err_printf(m, " Power: %s\n", |
16002 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
16003 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
16004 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
16005 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
16006 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
16007 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
16008 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
16009 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
16010 | } | |
c4a1d9e4 | 16011 | } |
e2fcdaa9 VS |
16012 | |
16013 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
16014 | { | |
16015 | struct intel_crtc *crtc; | |
16016 | ||
16017 | for_each_intel_crtc(dev, crtc) { | |
16018 | struct intel_unpin_work *work; | |
e2fcdaa9 | 16019 | |
5e2d7afc | 16020 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
16021 | |
16022 | work = crtc->unpin_work; | |
16023 | ||
16024 | if (work && work->event && | |
16025 | work->event->base.file_priv == file) { | |
16026 | kfree(work->event); | |
16027 | work->event = NULL; | |
16028 | } | |
16029 | ||
5e2d7afc | 16030 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
16031 | } |
16032 | } |