]>
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); | |
043e9bda | 115 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
e7457a9a | 116 | |
79e53945 | 117 | typedef struct { |
0206e353 | 118 | int min, max; |
79e53945 JB |
119 | } intel_range_t; |
120 | ||
121 | typedef struct { | |
0206e353 AJ |
122 | int dot_limit; |
123 | int p2_slow, p2_fast; | |
79e53945 JB |
124 | } intel_p2_t; |
125 | ||
d4906093 ML |
126 | typedef struct intel_limit intel_limit_t; |
127 | struct intel_limit { | |
0206e353 AJ |
128 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
129 | intel_p2_t p2; | |
d4906093 | 130 | }; |
79e53945 | 131 | |
d2acd215 DV |
132 | int |
133 | intel_pch_rawclk(struct drm_device *dev) | |
134 | { | |
135 | struct drm_i915_private *dev_priv = dev->dev_private; | |
136 | ||
137 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
138 | ||
139 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
140 | } | |
141 | ||
79e50a4f JN |
142 | /* hrawclock is 1/4 the FSB frequency */ |
143 | int intel_hrawclk(struct drm_device *dev) | |
144 | { | |
145 | struct drm_i915_private *dev_priv = dev->dev_private; | |
146 | uint32_t clkcfg; | |
147 | ||
148 | /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */ | |
149 | if (IS_VALLEYVIEW(dev)) | |
150 | return 200; | |
151 | ||
152 | clkcfg = I915_READ(CLKCFG); | |
153 | switch (clkcfg & CLKCFG_FSB_MASK) { | |
154 | case CLKCFG_FSB_400: | |
155 | return 100; | |
156 | case CLKCFG_FSB_533: | |
157 | return 133; | |
158 | case CLKCFG_FSB_667: | |
159 | return 166; | |
160 | case CLKCFG_FSB_800: | |
161 | return 200; | |
162 | case CLKCFG_FSB_1067: | |
163 | return 266; | |
164 | case CLKCFG_FSB_1333: | |
165 | return 333; | |
166 | /* these two are just a guess; one of them might be right */ | |
167 | case CLKCFG_FSB_1600: | |
168 | case CLKCFG_FSB_1600_ALT: | |
169 | return 400; | |
170 | default: | |
171 | return 133; | |
172 | } | |
173 | } | |
174 | ||
021357ac CW |
175 | static inline u32 /* units of 100MHz */ |
176 | intel_fdi_link_freq(struct drm_device *dev) | |
177 | { | |
8b99e68c CW |
178 | if (IS_GEN5(dev)) { |
179 | struct drm_i915_private *dev_priv = dev->dev_private; | |
180 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
181 | } else | |
182 | return 27; | |
021357ac CW |
183 | } |
184 | ||
5d536e28 | 185 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 186 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 187 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 188 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
189 | .m = { .min = 96, .max = 140 }, |
190 | .m1 = { .min = 18, .max = 26 }, | |
191 | .m2 = { .min = 6, .max = 16 }, | |
192 | .p = { .min = 4, .max = 128 }, | |
193 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
194 | .p2 = { .dot_limit = 165000, |
195 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
196 | }; |
197 | ||
5d536e28 DV |
198 | static const intel_limit_t intel_limits_i8xx_dvo = { |
199 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 200 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 201 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
202 | .m = { .min = 96, .max = 140 }, |
203 | .m1 = { .min = 18, .max = 26 }, | |
204 | .m2 = { .min = 6, .max = 16 }, | |
205 | .p = { .min = 4, .max = 128 }, | |
206 | .p1 = { .min = 2, .max = 33 }, | |
207 | .p2 = { .dot_limit = 165000, | |
208 | .p2_slow = 4, .p2_fast = 4 }, | |
209 | }; | |
210 | ||
e4b36699 | 211 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 212 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 213 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 214 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
215 | .m = { .min = 96, .max = 140 }, |
216 | .m1 = { .min = 18, .max = 26 }, | |
217 | .m2 = { .min = 6, .max = 16 }, | |
218 | .p = { .min = 4, .max = 128 }, | |
219 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
220 | .p2 = { .dot_limit = 165000, |
221 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 222 | }; |
273e27ca | 223 | |
e4b36699 | 224 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
225 | .dot = { .min = 20000, .max = 400000 }, |
226 | .vco = { .min = 1400000, .max = 2800000 }, | |
227 | .n = { .min = 1, .max = 6 }, | |
228 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
229 | .m1 = { .min = 8, .max = 18 }, |
230 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
231 | .p = { .min = 5, .max = 80 }, |
232 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
233 | .p2 = { .dot_limit = 200000, |
234 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
235 | }; |
236 | ||
237 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
238 | .dot = { .min = 20000, .max = 400000 }, |
239 | .vco = { .min = 1400000, .max = 2800000 }, | |
240 | .n = { .min = 1, .max = 6 }, | |
241 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
242 | .m1 = { .min = 8, .max = 18 }, |
243 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
244 | .p = { .min = 7, .max = 98 }, |
245 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
246 | .p2 = { .dot_limit = 112000, |
247 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
248 | }; |
249 | ||
273e27ca | 250 | |
e4b36699 | 251 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
252 | .dot = { .min = 25000, .max = 270000 }, |
253 | .vco = { .min = 1750000, .max = 3500000}, | |
254 | .n = { .min = 1, .max = 4 }, | |
255 | .m = { .min = 104, .max = 138 }, | |
256 | .m1 = { .min = 17, .max = 23 }, | |
257 | .m2 = { .min = 5, .max = 11 }, | |
258 | .p = { .min = 10, .max = 30 }, | |
259 | .p1 = { .min = 1, .max = 3}, | |
260 | .p2 = { .dot_limit = 270000, | |
261 | .p2_slow = 10, | |
262 | .p2_fast = 10 | |
044c7c41 | 263 | }, |
e4b36699 KP |
264 | }; |
265 | ||
266 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
267 | .dot = { .min = 22000, .max = 400000 }, |
268 | .vco = { .min = 1750000, .max = 3500000}, | |
269 | .n = { .min = 1, .max = 4 }, | |
270 | .m = { .min = 104, .max = 138 }, | |
271 | .m1 = { .min = 16, .max = 23 }, | |
272 | .m2 = { .min = 5, .max = 11 }, | |
273 | .p = { .min = 5, .max = 80 }, | |
274 | .p1 = { .min = 1, .max = 8}, | |
275 | .p2 = { .dot_limit = 165000, | |
276 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
277 | }; |
278 | ||
279 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
280 | .dot = { .min = 20000, .max = 115000 }, |
281 | .vco = { .min = 1750000, .max = 3500000 }, | |
282 | .n = { .min = 1, .max = 3 }, | |
283 | .m = { .min = 104, .max = 138 }, | |
284 | .m1 = { .min = 17, .max = 23 }, | |
285 | .m2 = { .min = 5, .max = 11 }, | |
286 | .p = { .min = 28, .max = 112 }, | |
287 | .p1 = { .min = 2, .max = 8 }, | |
288 | .p2 = { .dot_limit = 0, | |
289 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 290 | }, |
e4b36699 KP |
291 | }; |
292 | ||
293 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
294 | .dot = { .min = 80000, .max = 224000 }, |
295 | .vco = { .min = 1750000, .max = 3500000 }, | |
296 | .n = { .min = 1, .max = 3 }, | |
297 | .m = { .min = 104, .max = 138 }, | |
298 | .m1 = { .min = 17, .max = 23 }, | |
299 | .m2 = { .min = 5, .max = 11 }, | |
300 | .p = { .min = 14, .max = 42 }, | |
301 | .p1 = { .min = 2, .max = 6 }, | |
302 | .p2 = { .dot_limit = 0, | |
303 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 304 | }, |
e4b36699 KP |
305 | }; |
306 | ||
f2b115e6 | 307 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
308 | .dot = { .min = 20000, .max = 400000}, |
309 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 310 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
311 | .n = { .min = 3, .max = 6 }, |
312 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 313 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
314 | .m1 = { .min = 0, .max = 0 }, |
315 | .m2 = { .min = 0, .max = 254 }, | |
316 | .p = { .min = 5, .max = 80 }, | |
317 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
318 | .p2 = { .dot_limit = 200000, |
319 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
320 | }; |
321 | ||
f2b115e6 | 322 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
323 | .dot = { .min = 20000, .max = 400000 }, |
324 | .vco = { .min = 1700000, .max = 3500000 }, | |
325 | .n = { .min = 3, .max = 6 }, | |
326 | .m = { .min = 2, .max = 256 }, | |
327 | .m1 = { .min = 0, .max = 0 }, | |
328 | .m2 = { .min = 0, .max = 254 }, | |
329 | .p = { .min = 7, .max = 112 }, | |
330 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
331 | .p2 = { .dot_limit = 112000, |
332 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
333 | }; |
334 | ||
273e27ca EA |
335 | /* Ironlake / Sandybridge |
336 | * | |
337 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
338 | * the range value for them is (actual_value - 2). | |
339 | */ | |
b91ad0ec | 340 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
341 | .dot = { .min = 25000, .max = 350000 }, |
342 | .vco = { .min = 1760000, .max = 3510000 }, | |
343 | .n = { .min = 1, .max = 5 }, | |
344 | .m = { .min = 79, .max = 127 }, | |
345 | .m1 = { .min = 12, .max = 22 }, | |
346 | .m2 = { .min = 5, .max = 9 }, | |
347 | .p = { .min = 5, .max = 80 }, | |
348 | .p1 = { .min = 1, .max = 8 }, | |
349 | .p2 = { .dot_limit = 225000, | |
350 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
351 | }; |
352 | ||
b91ad0ec | 353 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
354 | .dot = { .min = 25000, .max = 350000 }, |
355 | .vco = { .min = 1760000, .max = 3510000 }, | |
356 | .n = { .min = 1, .max = 3 }, | |
357 | .m = { .min = 79, .max = 118 }, | |
358 | .m1 = { .min = 12, .max = 22 }, | |
359 | .m2 = { .min = 5, .max = 9 }, | |
360 | .p = { .min = 28, .max = 112 }, | |
361 | .p1 = { .min = 2, .max = 8 }, | |
362 | .p2 = { .dot_limit = 225000, | |
363 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
364 | }; |
365 | ||
366 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
367 | .dot = { .min = 25000, .max = 350000 }, |
368 | .vco = { .min = 1760000, .max = 3510000 }, | |
369 | .n = { .min = 1, .max = 3 }, | |
370 | .m = { .min = 79, .max = 127 }, | |
371 | .m1 = { .min = 12, .max = 22 }, | |
372 | .m2 = { .min = 5, .max = 9 }, | |
373 | .p = { .min = 14, .max = 56 }, | |
374 | .p1 = { .min = 2, .max = 8 }, | |
375 | .p2 = { .dot_limit = 225000, | |
376 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
377 | }; |
378 | ||
273e27ca | 379 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 380 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
381 | .dot = { .min = 25000, .max = 350000 }, |
382 | .vco = { .min = 1760000, .max = 3510000 }, | |
383 | .n = { .min = 1, .max = 2 }, | |
384 | .m = { .min = 79, .max = 126 }, | |
385 | .m1 = { .min = 12, .max = 22 }, | |
386 | .m2 = { .min = 5, .max = 9 }, | |
387 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 388 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
389 | .p2 = { .dot_limit = 225000, |
390 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
391 | }; |
392 | ||
393 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
394 | .dot = { .min = 25000, .max = 350000 }, |
395 | .vco = { .min = 1760000, .max = 3510000 }, | |
396 | .n = { .min = 1, .max = 3 }, | |
397 | .m = { .min = 79, .max = 126 }, | |
398 | .m1 = { .min = 12, .max = 22 }, | |
399 | .m2 = { .min = 5, .max = 9 }, | |
400 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 401 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
402 | .p2 = { .dot_limit = 225000, |
403 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
404 | }; |
405 | ||
dc730512 | 406 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
407 | /* |
408 | * These are the data rate limits (measured in fast clocks) | |
409 | * since those are the strictest limits we have. The fast | |
410 | * clock and actual rate limits are more relaxed, so checking | |
411 | * them would make no difference. | |
412 | */ | |
413 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 414 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 415 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
416 | .m1 = { .min = 2, .max = 3 }, |
417 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 418 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 419 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
420 | }; |
421 | ||
ef9348c8 CML |
422 | static const intel_limit_t intel_limits_chv = { |
423 | /* | |
424 | * These are the data rate limits (measured in fast clocks) | |
425 | * since those are the strictest limits we have. The fast | |
426 | * clock and actual rate limits are more relaxed, so checking | |
427 | * them would make no difference. | |
428 | */ | |
429 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 430 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
431 | .n = { .min = 1, .max = 1 }, |
432 | .m1 = { .min = 2, .max = 2 }, | |
433 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
434 | .p1 = { .min = 2, .max = 4 }, | |
435 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
436 | }; | |
437 | ||
5ab7b0b7 ID |
438 | static const intel_limit_t intel_limits_bxt = { |
439 | /* FIXME: find real dot limits */ | |
440 | .dot = { .min = 0, .max = INT_MAX }, | |
e6292556 | 441 | .vco = { .min = 4800000, .max = 6700000 }, |
5ab7b0b7 ID |
442 | .n = { .min = 1, .max = 1 }, |
443 | .m1 = { .min = 2, .max = 2 }, | |
444 | /* FIXME: find real m2 limits */ | |
445 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
446 | .p1 = { .min = 2, .max = 4 }, | |
447 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
448 | }; | |
449 | ||
cdba954e ACO |
450 | static bool |
451 | needs_modeset(struct drm_crtc_state *state) | |
452 | { | |
fc596660 | 453 | return drm_atomic_crtc_needs_modeset(state); |
cdba954e ACO |
454 | } |
455 | ||
e0638cdf PZ |
456 | /** |
457 | * Returns whether any output on the specified pipe is of the specified type | |
458 | */ | |
4093561b | 459 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 460 | { |
409ee761 | 461 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
462 | struct intel_encoder *encoder; |
463 | ||
409ee761 | 464 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
465 | if (encoder->type == type) |
466 | return true; | |
467 | ||
468 | return false; | |
469 | } | |
470 | ||
d0737e1d ACO |
471 | /** |
472 | * Returns whether any output on the specified pipe will have the specified | |
473 | * type after a staged modeset is complete, i.e., the same as | |
474 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
475 | * encoder->crtc. | |
476 | */ | |
a93e255f ACO |
477 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
478 | int type) | |
d0737e1d | 479 | { |
a93e255f | 480 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 481 | struct drm_connector *connector; |
a93e255f | 482 | struct drm_connector_state *connector_state; |
d0737e1d | 483 | struct intel_encoder *encoder; |
a93e255f ACO |
484 | int i, num_connectors = 0; |
485 | ||
da3ced29 | 486 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
487 | if (connector_state->crtc != crtc_state->base.crtc) |
488 | continue; | |
489 | ||
490 | num_connectors++; | |
d0737e1d | 491 | |
a93e255f ACO |
492 | encoder = to_intel_encoder(connector_state->best_encoder); |
493 | if (encoder->type == type) | |
d0737e1d | 494 | return true; |
a93e255f ACO |
495 | } |
496 | ||
497 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
498 | |
499 | return false; | |
500 | } | |
501 | ||
a93e255f ACO |
502 | static const intel_limit_t * |
503 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 504 | { |
a93e255f | 505 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 506 | const intel_limit_t *limit; |
b91ad0ec | 507 | |
a93e255f | 508 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 509 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 510 | if (refclk == 100000) |
b91ad0ec ZW |
511 | limit = &intel_limits_ironlake_dual_lvds_100m; |
512 | else | |
513 | limit = &intel_limits_ironlake_dual_lvds; | |
514 | } else { | |
1b894b59 | 515 | if (refclk == 100000) |
b91ad0ec ZW |
516 | limit = &intel_limits_ironlake_single_lvds_100m; |
517 | else | |
518 | limit = &intel_limits_ironlake_single_lvds; | |
519 | } | |
c6bb3538 | 520 | } else |
b91ad0ec | 521 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
522 | |
523 | return limit; | |
524 | } | |
525 | ||
a93e255f ACO |
526 | static const intel_limit_t * |
527 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 528 | { |
a93e255f | 529 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
530 | const intel_limit_t *limit; |
531 | ||
a93e255f | 532 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 533 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 534 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 535 | else |
e4b36699 | 536 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
537 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
538 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 539 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 540 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 541 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 542 | } else /* The option is for other outputs */ |
e4b36699 | 543 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
544 | |
545 | return limit; | |
546 | } | |
547 | ||
a93e255f ACO |
548 | static const intel_limit_t * |
549 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 550 | { |
a93e255f | 551 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
552 | const intel_limit_t *limit; |
553 | ||
5ab7b0b7 ID |
554 | if (IS_BROXTON(dev)) |
555 | limit = &intel_limits_bxt; | |
556 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 557 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 558 | else if (IS_G4X(dev)) { |
a93e255f | 559 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 560 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 561 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 562 | limit = &intel_limits_pineview_lvds; |
2177832f | 563 | else |
f2b115e6 | 564 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
565 | } else if (IS_CHERRYVIEW(dev)) { |
566 | limit = &intel_limits_chv; | |
a0c4da24 | 567 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 568 | limit = &intel_limits_vlv; |
a6c45cf0 | 569 | } else if (!IS_GEN2(dev)) { |
a93e255f | 570 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
571 | limit = &intel_limits_i9xx_lvds; |
572 | else | |
573 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 574 | } else { |
a93e255f | 575 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 576 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 577 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 578 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
579 | else |
580 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
581 | } |
582 | return limit; | |
583 | } | |
584 | ||
dccbea3b ID |
585 | /* |
586 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
587 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
588 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
589 | * The helpers' return value is the rate of the clock that is fed to the | |
590 | * display engine's pipe which can be the above fast dot clock rate or a | |
591 | * divided-down version of it. | |
592 | */ | |
f2b115e6 | 593 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
dccbea3b | 594 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
79e53945 | 595 | { |
2177832f SL |
596 | clock->m = clock->m2 + 2; |
597 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e | 598 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
dccbea3b | 599 | return 0; |
fb03ac01 VS |
600 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
601 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
602 | |
603 | return clock->dot; | |
2177832f SL |
604 | } |
605 | ||
7429e9d4 DV |
606 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
607 | { | |
608 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
609 | } | |
610 | ||
dccbea3b | 611 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
2177832f | 612 | { |
7429e9d4 | 613 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 614 | clock->p = clock->p1 * clock->p2; |
ed5ca77e | 615 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
dccbea3b | 616 | return 0; |
fb03ac01 VS |
617 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
618 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
619 | |
620 | return clock->dot; | |
79e53945 JB |
621 | } |
622 | ||
dccbea3b | 623 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
589eca67 ID |
624 | { |
625 | clock->m = clock->m1 * clock->m2; | |
626 | clock->p = clock->p1 * clock->p2; | |
627 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 628 | return 0; |
589eca67 ID |
629 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
630 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
631 | |
632 | return clock->dot / 5; | |
589eca67 ID |
633 | } |
634 | ||
dccbea3b | 635 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
ef9348c8 CML |
636 | { |
637 | clock->m = clock->m1 * clock->m2; | |
638 | clock->p = clock->p1 * clock->p2; | |
639 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 640 | return 0; |
ef9348c8 CML |
641 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
642 | clock->n << 22); | |
643 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
644 | |
645 | return clock->dot / 5; | |
ef9348c8 CML |
646 | } |
647 | ||
7c04d1d9 | 648 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
649 | /** |
650 | * Returns whether the given set of divisors are valid for a given refclk with | |
651 | * the given connectors. | |
652 | */ | |
653 | ||
1b894b59 CW |
654 | static bool intel_PLL_is_valid(struct drm_device *dev, |
655 | const intel_limit_t *limit, | |
656 | const intel_clock_t *clock) | |
79e53945 | 657 | { |
f01b7962 VS |
658 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
659 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 660 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 661 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 662 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 663 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 664 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 665 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 666 | |
5ab7b0b7 | 667 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
f01b7962 VS |
668 | if (clock->m1 <= clock->m2) |
669 | INTELPllInvalid("m1 <= m2\n"); | |
670 | ||
5ab7b0b7 | 671 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
672 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
673 | INTELPllInvalid("p out of range\n"); | |
674 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
675 | INTELPllInvalid("m out of range\n"); | |
676 | } | |
677 | ||
79e53945 | 678 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 679 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
680 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
681 | * connector, etc., rather than just a single range. | |
682 | */ | |
683 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 684 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
685 | |
686 | return true; | |
687 | } | |
688 | ||
3b1429d9 VS |
689 | static int |
690 | i9xx_select_p2_div(const intel_limit_t *limit, | |
691 | const struct intel_crtc_state *crtc_state, | |
692 | int target) | |
79e53945 | 693 | { |
3b1429d9 | 694 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 695 | |
a93e255f | 696 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 697 | /* |
a210b028 DV |
698 | * For LVDS just rely on its current settings for dual-channel. |
699 | * We haven't figured out how to reliably set up different | |
700 | * single/dual channel state, if we even can. | |
79e53945 | 701 | */ |
1974cad0 | 702 | if (intel_is_dual_link_lvds(dev)) |
3b1429d9 | 703 | return limit->p2.p2_fast; |
79e53945 | 704 | else |
3b1429d9 | 705 | return limit->p2.p2_slow; |
79e53945 JB |
706 | } else { |
707 | if (target < limit->p2.dot_limit) | |
3b1429d9 | 708 | return limit->p2.p2_slow; |
79e53945 | 709 | else |
3b1429d9 | 710 | return limit->p2.p2_fast; |
79e53945 | 711 | } |
3b1429d9 VS |
712 | } |
713 | ||
714 | static bool | |
715 | i9xx_find_best_dpll(const intel_limit_t *limit, | |
716 | struct intel_crtc_state *crtc_state, | |
717 | int target, int refclk, intel_clock_t *match_clock, | |
718 | intel_clock_t *best_clock) | |
719 | { | |
720 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
721 | intel_clock_t clock; | |
722 | int err = target; | |
79e53945 | 723 | |
0206e353 | 724 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 725 | |
3b1429d9 VS |
726 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
727 | ||
42158660 ZY |
728 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
729 | clock.m1++) { | |
730 | for (clock.m2 = limit->m2.min; | |
731 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 732 | if (clock.m2 >= clock.m1) |
42158660 ZY |
733 | break; |
734 | for (clock.n = limit->n.min; | |
735 | clock.n <= limit->n.max; clock.n++) { | |
736 | for (clock.p1 = limit->p1.min; | |
737 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
738 | int this_err; |
739 | ||
dccbea3b | 740 | i9xx_calc_dpll_params(refclk, &clock); |
ac58c3f0 DV |
741 | if (!intel_PLL_is_valid(dev, limit, |
742 | &clock)) | |
743 | continue; | |
744 | if (match_clock && | |
745 | clock.p != match_clock->p) | |
746 | continue; | |
747 | ||
748 | this_err = abs(clock.dot - target); | |
749 | if (this_err < err) { | |
750 | *best_clock = clock; | |
751 | err = this_err; | |
752 | } | |
753 | } | |
754 | } | |
755 | } | |
756 | } | |
757 | ||
758 | return (err != target); | |
759 | } | |
760 | ||
761 | static bool | |
a93e255f ACO |
762 | pnv_find_best_dpll(const intel_limit_t *limit, |
763 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
764 | int target, int refclk, intel_clock_t *match_clock, |
765 | intel_clock_t *best_clock) | |
79e53945 | 766 | { |
3b1429d9 | 767 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 768 | intel_clock_t clock; |
79e53945 JB |
769 | int err = target; |
770 | ||
0206e353 | 771 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 772 | |
3b1429d9 VS |
773 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
774 | ||
42158660 ZY |
775 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
776 | clock.m1++) { | |
777 | for (clock.m2 = limit->m2.min; | |
778 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
779 | for (clock.n = limit->n.min; |
780 | clock.n <= limit->n.max; clock.n++) { | |
781 | for (clock.p1 = limit->p1.min; | |
782 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
783 | int this_err; |
784 | ||
dccbea3b | 785 | pnv_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
786 | if (!intel_PLL_is_valid(dev, limit, |
787 | &clock)) | |
79e53945 | 788 | continue; |
cec2f356 SP |
789 | if (match_clock && |
790 | clock.p != match_clock->p) | |
791 | continue; | |
79e53945 JB |
792 | |
793 | this_err = abs(clock.dot - target); | |
794 | if (this_err < err) { | |
795 | *best_clock = clock; | |
796 | err = this_err; | |
797 | } | |
798 | } | |
799 | } | |
800 | } | |
801 | } | |
802 | ||
803 | return (err != target); | |
804 | } | |
805 | ||
d4906093 | 806 | static bool |
a93e255f ACO |
807 | g4x_find_best_dpll(const intel_limit_t *limit, |
808 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
809 | int target, int refclk, intel_clock_t *match_clock, |
810 | intel_clock_t *best_clock) | |
d4906093 | 811 | { |
3b1429d9 | 812 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d4906093 ML |
813 | intel_clock_t clock; |
814 | int max_n; | |
3b1429d9 | 815 | bool found = false; |
6ba770dc AJ |
816 | /* approximately equals target * 0.00585 */ |
817 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
818 | |
819 | memset(best_clock, 0, sizeof(*best_clock)); | |
3b1429d9 VS |
820 | |
821 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
822 | ||
d4906093 | 823 | max_n = limit->n.max; |
f77f13e2 | 824 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 825 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 826 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
827 | for (clock.m1 = limit->m1.max; |
828 | clock.m1 >= limit->m1.min; clock.m1--) { | |
829 | for (clock.m2 = limit->m2.max; | |
830 | clock.m2 >= limit->m2.min; clock.m2--) { | |
831 | for (clock.p1 = limit->p1.max; | |
832 | clock.p1 >= limit->p1.min; clock.p1--) { | |
833 | int this_err; | |
834 | ||
dccbea3b | 835 | i9xx_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
836 | if (!intel_PLL_is_valid(dev, limit, |
837 | &clock)) | |
d4906093 | 838 | continue; |
1b894b59 CW |
839 | |
840 | this_err = abs(clock.dot - target); | |
d4906093 ML |
841 | if (this_err < err_most) { |
842 | *best_clock = clock; | |
843 | err_most = this_err; | |
844 | max_n = clock.n; | |
845 | found = true; | |
846 | } | |
847 | } | |
848 | } | |
849 | } | |
850 | } | |
2c07245f ZW |
851 | return found; |
852 | } | |
853 | ||
d5dd62bd ID |
854 | /* |
855 | * Check if the calculated PLL configuration is more optimal compared to the | |
856 | * best configuration and error found so far. Return the calculated error. | |
857 | */ | |
858 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
859 | const intel_clock_t *calculated_clock, | |
860 | const intel_clock_t *best_clock, | |
861 | unsigned int best_error_ppm, | |
862 | unsigned int *error_ppm) | |
863 | { | |
9ca3ba01 ID |
864 | /* |
865 | * For CHV ignore the error and consider only the P value. | |
866 | * Prefer a bigger P value based on HW requirements. | |
867 | */ | |
868 | if (IS_CHERRYVIEW(dev)) { | |
869 | *error_ppm = 0; | |
870 | ||
871 | return calculated_clock->p > best_clock->p; | |
872 | } | |
873 | ||
24be4e46 ID |
874 | if (WARN_ON_ONCE(!target_freq)) |
875 | return false; | |
876 | ||
d5dd62bd ID |
877 | *error_ppm = div_u64(1000000ULL * |
878 | abs(target_freq - calculated_clock->dot), | |
879 | target_freq); | |
880 | /* | |
881 | * Prefer a better P value over a better (smaller) error if the error | |
882 | * is small. Ensure this preference for future configurations too by | |
883 | * setting the error to 0. | |
884 | */ | |
885 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
886 | *error_ppm = 0; | |
887 | ||
888 | return true; | |
889 | } | |
890 | ||
891 | return *error_ppm + 10 < best_error_ppm; | |
892 | } | |
893 | ||
a0c4da24 | 894 | static bool |
a93e255f ACO |
895 | vlv_find_best_dpll(const intel_limit_t *limit, |
896 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
897 | int target, int refclk, intel_clock_t *match_clock, |
898 | intel_clock_t *best_clock) | |
a0c4da24 | 899 | { |
a93e255f | 900 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 901 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 902 | intel_clock_t clock; |
69e4f900 | 903 | unsigned int bestppm = 1000000; |
27e639bf VS |
904 | /* min update 19.2 MHz */ |
905 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 906 | bool found = false; |
a0c4da24 | 907 | |
6b4bf1c4 VS |
908 | target *= 5; /* fast clock */ |
909 | ||
910 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
911 | |
912 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 913 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 914 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 915 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 916 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 917 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 918 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 919 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 920 | unsigned int ppm; |
69e4f900 | 921 | |
6b4bf1c4 VS |
922 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
923 | refclk * clock.m1); | |
924 | ||
dccbea3b | 925 | vlv_calc_dpll_params(refclk, &clock); |
43b0ac53 | 926 | |
f01b7962 VS |
927 | if (!intel_PLL_is_valid(dev, limit, |
928 | &clock)) | |
43b0ac53 VS |
929 | continue; |
930 | ||
d5dd62bd ID |
931 | if (!vlv_PLL_is_optimal(dev, target, |
932 | &clock, | |
933 | best_clock, | |
934 | bestppm, &ppm)) | |
935 | continue; | |
6b4bf1c4 | 936 | |
d5dd62bd ID |
937 | *best_clock = clock; |
938 | bestppm = ppm; | |
939 | found = true; | |
a0c4da24 JB |
940 | } |
941 | } | |
942 | } | |
943 | } | |
a0c4da24 | 944 | |
49e497ef | 945 | return found; |
a0c4da24 | 946 | } |
a4fc5ed6 | 947 | |
ef9348c8 | 948 | static bool |
a93e255f ACO |
949 | chv_find_best_dpll(const intel_limit_t *limit, |
950 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
951 | int target, int refclk, intel_clock_t *match_clock, |
952 | intel_clock_t *best_clock) | |
953 | { | |
a93e255f | 954 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 955 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 956 | unsigned int best_error_ppm; |
ef9348c8 CML |
957 | intel_clock_t clock; |
958 | uint64_t m2; | |
959 | int found = false; | |
960 | ||
961 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 962 | best_error_ppm = 1000000; |
ef9348c8 CML |
963 | |
964 | /* | |
965 | * Based on hardware doc, the n always set to 1, and m1 always | |
966 | * set to 2. If requires to support 200Mhz refclk, we need to | |
967 | * revisit this because n may not 1 anymore. | |
968 | */ | |
969 | clock.n = 1, clock.m1 = 2; | |
970 | target *= 5; /* fast clock */ | |
971 | ||
972 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
973 | for (clock.p2 = limit->p2.p2_fast; | |
974 | clock.p2 >= limit->p2.p2_slow; | |
975 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 976 | unsigned int error_ppm; |
ef9348c8 CML |
977 | |
978 | clock.p = clock.p1 * clock.p2; | |
979 | ||
980 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
981 | clock.n) << 22, refclk * clock.m1); | |
982 | ||
983 | if (m2 > INT_MAX/clock.m1) | |
984 | continue; | |
985 | ||
986 | clock.m2 = m2; | |
987 | ||
dccbea3b | 988 | chv_calc_dpll_params(refclk, &clock); |
ef9348c8 CML |
989 | |
990 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
991 | continue; | |
992 | ||
9ca3ba01 ID |
993 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
994 | best_error_ppm, &error_ppm)) | |
995 | continue; | |
996 | ||
997 | *best_clock = clock; | |
998 | best_error_ppm = error_ppm; | |
999 | found = true; | |
ef9348c8 CML |
1000 | } |
1001 | } | |
1002 | ||
1003 | return found; | |
1004 | } | |
1005 | ||
5ab7b0b7 ID |
1006 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
1007 | intel_clock_t *best_clock) | |
1008 | { | |
1009 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
1010 | ||
1011 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
1012 | target_clock, refclk, NULL, best_clock); | |
1013 | } | |
1014 | ||
20ddf665 VS |
1015 | bool intel_crtc_active(struct drm_crtc *crtc) |
1016 | { | |
1017 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1018 | ||
1019 | /* Be paranoid as we can arrive here with only partial | |
1020 | * state retrieved from the hardware during setup. | |
1021 | * | |
241bfc38 | 1022 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
1023 | * as Haswell has gained clock readout/fastboot support. |
1024 | * | |
66e514c1 | 1025 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 1026 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1027 | * |
1028 | * FIXME: The intel_crtc->active here should be switched to | |
1029 | * crtc->state->active once we have proper CRTC states wired up | |
1030 | * for atomic. | |
20ddf665 | 1031 | */ |
c3d1f436 | 1032 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1033 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1034 | } |
1035 | ||
a5c961d1 PZ |
1036 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1037 | enum pipe pipe) | |
1038 | { | |
1039 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1040 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1041 | ||
6e3c9717 | 1042 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1043 | } |
1044 | ||
fbf49ea2 VS |
1045 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1046 | { | |
1047 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1048 | u32 reg = PIPEDSL(pipe); | |
1049 | u32 line1, line2; | |
1050 | u32 line_mask; | |
1051 | ||
1052 | if (IS_GEN2(dev)) | |
1053 | line_mask = DSL_LINEMASK_GEN2; | |
1054 | else | |
1055 | line_mask = DSL_LINEMASK_GEN3; | |
1056 | ||
1057 | line1 = I915_READ(reg) & line_mask; | |
6adfb1ef | 1058 | msleep(5); |
fbf49ea2 VS |
1059 | line2 = I915_READ(reg) & line_mask; |
1060 | ||
1061 | return line1 == line2; | |
1062 | } | |
1063 | ||
ab7ad7f6 KP |
1064 | /* |
1065 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1066 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1067 | * |
1068 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1069 | * spinning on the vblank interrupt status bit, since we won't actually | |
1070 | * see an interrupt when the pipe is disabled. | |
1071 | * | |
ab7ad7f6 KP |
1072 | * On Gen4 and above: |
1073 | * wait for the pipe register state bit to turn off | |
1074 | * | |
1075 | * Otherwise: | |
1076 | * wait for the display line value to settle (it usually | |
1077 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1078 | * |
9d0498a2 | 1079 | */ |
575f7ab7 | 1080 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1081 | { |
575f7ab7 | 1082 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1083 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1084 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1085 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1086 | |
1087 | if (INTEL_INFO(dev)->gen >= 4) { | |
702e7a56 | 1088 | int reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1089 | |
1090 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1091 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1092 | 100)) | |
284637d9 | 1093 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1094 | } else { |
ab7ad7f6 | 1095 | /* Wait for the display line to settle */ |
fbf49ea2 | 1096 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1097 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1098 | } |
79e53945 JB |
1099 | } |
1100 | ||
b24e7179 JB |
1101 | static const char *state_string(bool enabled) |
1102 | { | |
1103 | return enabled ? "on" : "off"; | |
1104 | } | |
1105 | ||
1106 | /* Only for pre-ILK configs */ | |
55607e8a DV |
1107 | void assert_pll(struct drm_i915_private *dev_priv, |
1108 | enum pipe pipe, bool state) | |
b24e7179 JB |
1109 | { |
1110 | int reg; | |
1111 | u32 val; | |
1112 | bool cur_state; | |
1113 | ||
1114 | reg = DPLL(pipe); | |
1115 | val = I915_READ(reg); | |
1116 | cur_state = !!(val & DPLL_VCO_ENABLE); | |
e2c719b7 | 1117 | I915_STATE_WARN(cur_state != state, |
b24e7179 JB |
1118 | "PLL state assertion failure (expected %s, current %s)\n", |
1119 | state_string(state), state_string(cur_state)); | |
1120 | } | |
b24e7179 | 1121 | |
23538ef1 JN |
1122 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1123 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1124 | { | |
1125 | u32 val; | |
1126 | bool cur_state; | |
1127 | ||
a580516d | 1128 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1129 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1130 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1131 | |
1132 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1133 | I915_STATE_WARN(cur_state != state, |
23538ef1 JN |
1134 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
1135 | state_string(state), state_string(cur_state)); | |
1136 | } | |
1137 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1138 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1139 | ||
55607e8a | 1140 | struct intel_shared_dpll * |
e2b78267 DV |
1141 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1142 | { | |
1143 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1144 | ||
6e3c9717 | 1145 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1146 | return NULL; |
1147 | ||
6e3c9717 | 1148 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1149 | } |
1150 | ||
040484af | 1151 | /* For ILK+ */ |
55607e8a DV |
1152 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1153 | struct intel_shared_dpll *pll, | |
1154 | bool state) | |
040484af | 1155 | { |
040484af | 1156 | bool cur_state; |
5358901f | 1157 | struct intel_dpll_hw_state hw_state; |
040484af | 1158 | |
92b27b08 | 1159 | if (WARN (!pll, |
46edb027 | 1160 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
ee7b9f93 | 1161 | return; |
ee7b9f93 | 1162 | |
5358901f | 1163 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1164 | I915_STATE_WARN(cur_state != state, |
5358901f DV |
1165 | "%s assertion failure (expected %s, current %s)\n", |
1166 | pll->name, state_string(state), state_string(cur_state)); | |
040484af | 1167 | } |
040484af JB |
1168 | |
1169 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1170 | enum pipe pipe, bool state) | |
1171 | { | |
1172 | int reg; | |
1173 | u32 val; | |
1174 | bool cur_state; | |
ad80a810 PZ |
1175 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1176 | pipe); | |
040484af | 1177 | |
affa9354 PZ |
1178 | if (HAS_DDI(dev_priv->dev)) { |
1179 | /* DDI does not have a specific FDI_TX register */ | |
ad80a810 | 1180 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
bf507ef7 | 1181 | val = I915_READ(reg); |
ad80a810 | 1182 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 ED |
1183 | } else { |
1184 | reg = FDI_TX_CTL(pipe); | |
1185 | val = I915_READ(reg); | |
1186 | cur_state = !!(val & FDI_TX_ENABLE); | |
1187 | } | |
e2c719b7 | 1188 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1189 | "FDI TX state assertion failure (expected %s, current %s)\n", |
1190 | state_string(state), state_string(cur_state)); | |
1191 | } | |
1192 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1193 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1194 | ||
1195 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1196 | enum pipe pipe, bool state) | |
1197 | { | |
1198 | int reg; | |
1199 | u32 val; | |
1200 | bool cur_state; | |
1201 | ||
d63fa0dc PZ |
1202 | reg = FDI_RX_CTL(pipe); |
1203 | val = I915_READ(reg); | |
1204 | cur_state = !!(val & FDI_RX_ENABLE); | |
e2c719b7 | 1205 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1206 | "FDI RX state assertion failure (expected %s, current %s)\n", |
1207 | state_string(state), state_string(cur_state)); | |
1208 | } | |
1209 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1210 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1211 | ||
1212 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1213 | enum pipe pipe) | |
1214 | { | |
1215 | int reg; | |
1216 | u32 val; | |
1217 | ||
1218 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1219 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1220 | return; |
1221 | ||
bf507ef7 | 1222 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1223 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1224 | return; |
1225 | ||
040484af JB |
1226 | reg = FDI_TX_CTL(pipe); |
1227 | val = I915_READ(reg); | |
e2c719b7 | 1228 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1229 | } |
1230 | ||
55607e8a DV |
1231 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1232 | enum pipe pipe, bool state) | |
040484af JB |
1233 | { |
1234 | int reg; | |
1235 | u32 val; | |
55607e8a | 1236 | bool cur_state; |
040484af JB |
1237 | |
1238 | reg = FDI_RX_CTL(pipe); | |
1239 | val = I915_READ(reg); | |
55607e8a | 1240 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1241 | I915_STATE_WARN(cur_state != state, |
55607e8a DV |
1242 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
1243 | state_string(state), state_string(cur_state)); | |
040484af JB |
1244 | } |
1245 | ||
b680c37a DV |
1246 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1247 | enum pipe pipe) | |
ea0760cf | 1248 | { |
bedd4dba JN |
1249 | struct drm_device *dev = dev_priv->dev; |
1250 | int pp_reg; | |
ea0760cf JB |
1251 | u32 val; |
1252 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1253 | bool locked = true; |
ea0760cf | 1254 | |
bedd4dba JN |
1255 | if (WARN_ON(HAS_DDI(dev))) |
1256 | return; | |
1257 | ||
1258 | if (HAS_PCH_SPLIT(dev)) { | |
1259 | u32 port_sel; | |
1260 | ||
ea0760cf | 1261 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1262 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1263 | ||
1264 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1265 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1266 | panel_pipe = PIPE_B; | |
1267 | /* XXX: else fix for eDP */ | |
1268 | } else if (IS_VALLEYVIEW(dev)) { | |
1269 | /* presumably write lock depends on pipe, not port select */ | |
1270 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1271 | panel_pipe = pipe; | |
ea0760cf JB |
1272 | } else { |
1273 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1274 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1275 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1276 | } |
1277 | ||
1278 | val = I915_READ(pp_reg); | |
1279 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1280 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1281 | locked = false; |
1282 | ||
e2c719b7 | 1283 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1284 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1285 | pipe_name(pipe)); |
ea0760cf JB |
1286 | } |
1287 | ||
93ce0ba6 JN |
1288 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1289 | enum pipe pipe, bool state) | |
1290 | { | |
1291 | struct drm_device *dev = dev_priv->dev; | |
1292 | bool cur_state; | |
1293 | ||
d9d82081 | 1294 | if (IS_845G(dev) || IS_I865G(dev)) |
93ce0ba6 | 1295 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
d9d82081 | 1296 | else |
5efb3e28 | 1297 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1298 | |
e2c719b7 | 1299 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 JN |
1300 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
1301 | pipe_name(pipe), state_string(state), state_string(cur_state)); | |
1302 | } | |
1303 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1304 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1305 | ||
b840d907 JB |
1306 | void assert_pipe(struct drm_i915_private *dev_priv, |
1307 | enum pipe pipe, bool state) | |
b24e7179 JB |
1308 | { |
1309 | int reg; | |
1310 | u32 val; | |
63d7bbe9 | 1311 | bool cur_state; |
702e7a56 PZ |
1312 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1313 | pipe); | |
b24e7179 | 1314 | |
b6b5d049 VS |
1315 | /* if we need the pipe quirk it must be always on */ |
1316 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1317 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1318 | state = true; |
1319 | ||
f458ebbc | 1320 | if (!intel_display_power_is_enabled(dev_priv, |
b97186f0 | 1321 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
69310161 PZ |
1322 | cur_state = false; |
1323 | } else { | |
1324 | reg = PIPECONF(cpu_transcoder); | |
1325 | val = I915_READ(reg); | |
1326 | cur_state = !!(val & PIPECONF_ENABLE); | |
1327 | } | |
1328 | ||
e2c719b7 | 1329 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1330 | "pipe %c assertion failure (expected %s, current %s)\n", |
9db4a9c7 | 1331 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
b24e7179 JB |
1332 | } |
1333 | ||
931872fc CW |
1334 | static void assert_plane(struct drm_i915_private *dev_priv, |
1335 | enum plane plane, bool state) | |
b24e7179 JB |
1336 | { |
1337 | int reg; | |
1338 | u32 val; | |
931872fc | 1339 | bool cur_state; |
b24e7179 JB |
1340 | |
1341 | reg = DSPCNTR(plane); | |
1342 | val = I915_READ(reg); | |
931872fc | 1343 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1344 | I915_STATE_WARN(cur_state != state, |
931872fc CW |
1345 | "plane %c assertion failure (expected %s, current %s)\n", |
1346 | plane_name(plane), state_string(state), state_string(cur_state)); | |
b24e7179 JB |
1347 | } |
1348 | ||
931872fc CW |
1349 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1350 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1351 | ||
b24e7179 JB |
1352 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1353 | enum pipe pipe) | |
1354 | { | |
653e1026 | 1355 | struct drm_device *dev = dev_priv->dev; |
b24e7179 JB |
1356 | int reg, i; |
1357 | u32 val; | |
1358 | int cur_pipe; | |
1359 | ||
653e1026 VS |
1360 | /* Primary planes are fixed to pipes on gen4+ */ |
1361 | if (INTEL_INFO(dev)->gen >= 4) { | |
28c05794 AJ |
1362 | reg = DSPCNTR(pipe); |
1363 | val = I915_READ(reg); | |
e2c719b7 | 1364 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1365 | "plane %c assertion failure, should be disabled but not\n", |
1366 | plane_name(pipe)); | |
19ec1358 | 1367 | return; |
28c05794 | 1368 | } |
19ec1358 | 1369 | |
b24e7179 | 1370 | /* Need to check both planes against the pipe */ |
055e393f | 1371 | for_each_pipe(dev_priv, i) { |
b24e7179 JB |
1372 | reg = DSPCNTR(i); |
1373 | val = I915_READ(reg); | |
1374 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
1375 | DISPPLANE_SEL_PIPE_SHIFT; | |
e2c719b7 | 1376 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1377 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1378 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1379 | } |
1380 | } | |
1381 | ||
19332d7a JB |
1382 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1383 | enum pipe pipe) | |
1384 | { | |
20674eef | 1385 | struct drm_device *dev = dev_priv->dev; |
1fe47785 | 1386 | int reg, sprite; |
19332d7a JB |
1387 | u32 val; |
1388 | ||
7feb8b88 | 1389 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1390 | for_each_sprite(dev_priv, pipe, sprite) { |
7feb8b88 | 1391 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1392 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1393 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1394 | sprite, pipe_name(pipe)); | |
1395 | } | |
1396 | } else if (IS_VALLEYVIEW(dev)) { | |
3bdcfc0c | 1397 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 1398 | reg = SPCNTR(pipe, sprite); |
20674eef | 1399 | val = I915_READ(reg); |
e2c719b7 | 1400 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1401 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1402 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1403 | } |
1404 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
1405 | reg = SPRCTL(pipe); | |
19332d7a | 1406 | val = I915_READ(reg); |
e2c719b7 | 1407 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1408 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1409 | plane_name(pipe), pipe_name(pipe)); |
1410 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
1411 | reg = DVSCNTR(pipe); | |
19332d7a | 1412 | val = I915_READ(reg); |
e2c719b7 | 1413 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1414 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1415 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1416 | } |
1417 | } | |
1418 | ||
08c71e5e VS |
1419 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1420 | { | |
e2c719b7 | 1421 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1422 | drm_crtc_vblank_put(crtc); |
1423 | } | |
1424 | ||
89eff4be | 1425 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1426 | { |
1427 | u32 val; | |
1428 | bool enabled; | |
1429 | ||
e2c719b7 | 1430 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1431 | |
92f2584a JB |
1432 | val = I915_READ(PCH_DREF_CONTROL); |
1433 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1434 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1435 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1436 | } |
1437 | ||
ab9412ba DV |
1438 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1439 | enum pipe pipe) | |
92f2584a JB |
1440 | { |
1441 | int reg; | |
1442 | u32 val; | |
1443 | bool enabled; | |
1444 | ||
ab9412ba | 1445 | reg = PCH_TRANSCONF(pipe); |
92f2584a JB |
1446 | val = I915_READ(reg); |
1447 | enabled = !!(val & TRANS_ENABLE); | |
e2c719b7 | 1448 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1449 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1450 | pipe_name(pipe)); | |
92f2584a JB |
1451 | } |
1452 | ||
4e634389 KP |
1453 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1454 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1455 | { |
1456 | if ((val & DP_PORT_EN) == 0) | |
1457 | return false; | |
1458 | ||
1459 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1460 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); | |
1461 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); | |
1462 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1463 | return false; | |
44f37d1f CML |
1464 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1465 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1466 | return false; | |
f0575e92 KP |
1467 | } else { |
1468 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1469 | return false; | |
1470 | } | |
1471 | return true; | |
1472 | } | |
1473 | ||
1519b995 KP |
1474 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1475 | enum pipe pipe, u32 val) | |
1476 | { | |
dc0fa718 | 1477 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1478 | return false; |
1479 | ||
1480 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1481 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1482 | return false; |
44f37d1f CML |
1483 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1484 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1485 | return false; | |
1519b995 | 1486 | } else { |
dc0fa718 | 1487 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1488 | return false; |
1489 | } | |
1490 | return true; | |
1491 | } | |
1492 | ||
1493 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1494 | enum pipe pipe, u32 val) | |
1495 | { | |
1496 | if ((val & LVDS_PORT_EN) == 0) | |
1497 | return false; | |
1498 | ||
1499 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1500 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1501 | return false; | |
1502 | } else { | |
1503 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1504 | return false; | |
1505 | } | |
1506 | return true; | |
1507 | } | |
1508 | ||
1509 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1510 | enum pipe pipe, u32 val) | |
1511 | { | |
1512 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1513 | return false; | |
1514 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1515 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1516 | return false; | |
1517 | } else { | |
1518 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1519 | return false; | |
1520 | } | |
1521 | return true; | |
1522 | } | |
1523 | ||
291906f1 | 1524 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0575e92 | 1525 | enum pipe pipe, int reg, u32 port_sel) |
291906f1 | 1526 | { |
47a05eca | 1527 | u32 val = I915_READ(reg); |
e2c719b7 | 1528 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1529 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1530 | reg, pipe_name(pipe)); |
de9a35ab | 1531 | |
e2c719b7 | 1532 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1533 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1534 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1535 | } |
1536 | ||
1537 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1538 | enum pipe pipe, int reg) | |
1539 | { | |
47a05eca | 1540 | u32 val = I915_READ(reg); |
e2c719b7 | 1541 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1542 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1543 | reg, pipe_name(pipe)); |
de9a35ab | 1544 | |
e2c719b7 | 1545 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1546 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1547 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1548 | } |
1549 | ||
1550 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1551 | enum pipe pipe) | |
1552 | { | |
1553 | int reg; | |
1554 | u32 val; | |
291906f1 | 1555 | |
f0575e92 KP |
1556 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1557 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1558 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 JB |
1559 | |
1560 | reg = PCH_ADPA; | |
1561 | val = I915_READ(reg); | |
e2c719b7 | 1562 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1563 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1564 | pipe_name(pipe)); |
291906f1 JB |
1565 | |
1566 | reg = PCH_LVDS; | |
1567 | val = I915_READ(reg); | |
e2c719b7 | 1568 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1569 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1570 | pipe_name(pipe)); |
291906f1 | 1571 | |
e2debe91 PZ |
1572 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1573 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1574 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1575 | } |
1576 | ||
d288f65f | 1577 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1578 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1579 | { |
426115cf DV |
1580 | struct drm_device *dev = crtc->base.dev; |
1581 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1582 | int reg = DPLL(crtc->pipe); | |
d288f65f | 1583 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1584 | |
426115cf | 1585 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 DV |
1586 | |
1587 | /* No really, not for ILK+ */ | |
1588 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); | |
1589 | ||
1590 | /* PLL is protected by panel, make sure we can write it */ | |
6a9e7363 | 1591 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1592 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1593 | |
426115cf DV |
1594 | I915_WRITE(reg, dpll); |
1595 | POSTING_READ(reg); | |
1596 | udelay(150); | |
1597 | ||
1598 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1599 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1600 | ||
d288f65f | 1601 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1602 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1603 | |
1604 | /* We do this three times for luck */ | |
426115cf | 1605 | I915_WRITE(reg, dpll); |
87442f73 DV |
1606 | POSTING_READ(reg); |
1607 | udelay(150); /* wait for warmup */ | |
426115cf | 1608 | I915_WRITE(reg, dpll); |
87442f73 DV |
1609 | POSTING_READ(reg); |
1610 | udelay(150); /* wait for warmup */ | |
426115cf | 1611 | I915_WRITE(reg, dpll); |
87442f73 DV |
1612 | POSTING_READ(reg); |
1613 | udelay(150); /* wait for warmup */ | |
1614 | } | |
1615 | ||
d288f65f | 1616 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1617 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1618 | { |
1619 | struct drm_device *dev = crtc->base.dev; | |
1620 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1621 | int pipe = crtc->pipe; | |
1622 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1623 | u32 tmp; |
1624 | ||
1625 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1626 | ||
1627 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); | |
1628 | ||
a580516d | 1629 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1630 | |
1631 | /* Enable back the 10bit clock to display controller */ | |
1632 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1633 | tmp |= DPIO_DCLKP_EN; | |
1634 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1635 | ||
54433e91 VS |
1636 | mutex_unlock(&dev_priv->sb_lock); |
1637 | ||
9d556c99 CML |
1638 | /* |
1639 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1640 | */ | |
1641 | udelay(1); | |
1642 | ||
1643 | /* Enable PLL */ | |
d288f65f | 1644 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1645 | |
1646 | /* Check PLL is locked */ | |
a11b0703 | 1647 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1648 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1649 | ||
a11b0703 | 1650 | /* not sure when this should be written */ |
d288f65f | 1651 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 | 1652 | POSTING_READ(DPLL_MD(pipe)); |
9d556c99 CML |
1653 | } |
1654 | ||
1c4e0274 VS |
1655 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1656 | { | |
1657 | struct intel_crtc *crtc; | |
1658 | int count = 0; | |
1659 | ||
1660 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1661 | count += crtc->base.state->active && |
409ee761 | 1662 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1663 | |
1664 | return count; | |
1665 | } | |
1666 | ||
66e3d5c0 | 1667 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1668 | { |
66e3d5c0 DV |
1669 | struct drm_device *dev = crtc->base.dev; |
1670 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1671 | int reg = DPLL(crtc->pipe); | |
6e3c9717 | 1672 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1673 | |
66e3d5c0 | 1674 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1675 | |
63d7bbe9 | 1676 | /* No really, not for ILK+ */ |
3d13ef2e | 1677 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1678 | |
1679 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1680 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1681 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1682 | |
1c4e0274 VS |
1683 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1684 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1685 | /* | |
1686 | * It appears to be important that we don't enable this | |
1687 | * for the current pipe before otherwise configuring the | |
1688 | * PLL. No idea how this should be handled if multiple | |
1689 | * DVO outputs are enabled simultaneosly. | |
1690 | */ | |
1691 | dpll |= DPLL_DVO_2X_MODE; | |
1692 | I915_WRITE(DPLL(!crtc->pipe), | |
1693 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1694 | } | |
66e3d5c0 DV |
1695 | |
1696 | /* Wait for the clocks to stabilize. */ | |
1697 | POSTING_READ(reg); | |
1698 | udelay(150); | |
1699 | ||
1700 | if (INTEL_INFO(dev)->gen >= 4) { | |
1701 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1702 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1703 | } else { |
1704 | /* The pixel multiplier can only be updated once the | |
1705 | * DPLL is enabled and the clocks are stable. | |
1706 | * | |
1707 | * So write it again. | |
1708 | */ | |
1709 | I915_WRITE(reg, dpll); | |
1710 | } | |
63d7bbe9 JB |
1711 | |
1712 | /* We do this three times for luck */ | |
66e3d5c0 | 1713 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1714 | POSTING_READ(reg); |
1715 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1716 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1717 | POSTING_READ(reg); |
1718 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1719 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1720 | POSTING_READ(reg); |
1721 | udelay(150); /* wait for warmup */ | |
1722 | } | |
1723 | ||
1724 | /** | |
50b44a44 | 1725 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1726 | * @dev_priv: i915 private structure |
1727 | * @pipe: pipe PLL to disable | |
1728 | * | |
1729 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1730 | * | |
1731 | * Note! This is for pre-ILK only. | |
1732 | */ | |
1c4e0274 | 1733 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1734 | { |
1c4e0274 VS |
1735 | struct drm_device *dev = crtc->base.dev; |
1736 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1737 | enum pipe pipe = crtc->pipe; | |
1738 | ||
1739 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1740 | if (IS_I830(dev) && | |
409ee761 | 1741 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1742 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1743 | I915_WRITE(DPLL(PIPE_B), |
1744 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1745 | I915_WRITE(DPLL(PIPE_A), | |
1746 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1747 | } | |
1748 | ||
b6b5d049 VS |
1749 | /* Don't disable pipe or pipe PLLs if needed */ |
1750 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1751 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1752 | return; |
1753 | ||
1754 | /* Make sure the pipe isn't still relying on us */ | |
1755 | assert_pipe_disabled(dev_priv, pipe); | |
1756 | ||
b8afb911 | 1757 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1758 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1759 | } |
1760 | ||
f6071166 JB |
1761 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1762 | { | |
b8afb911 | 1763 | u32 val; |
f6071166 JB |
1764 | |
1765 | /* Make sure the pipe isn't still relying on us */ | |
1766 | assert_pipe_disabled(dev_priv, pipe); | |
1767 | ||
e5cbfbfb ID |
1768 | /* |
1769 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1770 | * The latter is needed for VGA hotplug / manual detection. | |
1771 | */ | |
b8afb911 | 1772 | val = DPLL_VGA_MODE_DIS; |
f6071166 | 1773 | if (pipe == PIPE_B) |
60bfe44f | 1774 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
f6071166 JB |
1775 | I915_WRITE(DPLL(pipe), val); |
1776 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1777 | |
1778 | } | |
1779 | ||
1780 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1781 | { | |
d752048d | 1782 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1783 | u32 val; |
1784 | ||
a11b0703 VS |
1785 | /* Make sure the pipe isn't still relying on us */ |
1786 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1787 | |
a11b0703 | 1788 | /* Set PLL en = 0 */ |
60bfe44f VS |
1789 | val = DPLL_SSC_REF_CLK_CHV | |
1790 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1791 | if (pipe != PIPE_A) |
1792 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1793 | I915_WRITE(DPLL(pipe), val); | |
1794 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1795 | |
a580516d | 1796 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1797 | |
1798 | /* Disable 10bit clock to display controller */ | |
1799 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1800 | val &= ~DPIO_DCLKP_EN; | |
1801 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1802 | ||
a580516d | 1803 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1804 | } |
1805 | ||
e4607fcf | 1806 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1807 | struct intel_digital_port *dport, |
1808 | unsigned int expected_mask) | |
89b667f8 JB |
1809 | { |
1810 | u32 port_mask; | |
00fc31b7 | 1811 | int dpll_reg; |
89b667f8 | 1812 | |
e4607fcf CML |
1813 | switch (dport->port) { |
1814 | case PORT_B: | |
89b667f8 | 1815 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1816 | dpll_reg = DPLL(0); |
e4607fcf CML |
1817 | break; |
1818 | case PORT_C: | |
89b667f8 | 1819 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1820 | dpll_reg = DPLL(0); |
9b6de0a1 | 1821 | expected_mask <<= 4; |
00fc31b7 CML |
1822 | break; |
1823 | case PORT_D: | |
1824 | port_mask = DPLL_PORTD_READY_MASK; | |
1825 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1826 | break; |
1827 | default: | |
1828 | BUG(); | |
1829 | } | |
89b667f8 | 1830 | |
9b6de0a1 VS |
1831 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1832 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1833 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1834 | } |
1835 | ||
b14b1055 DV |
1836 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1837 | { | |
1838 | struct drm_device *dev = crtc->base.dev; | |
1839 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1840 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1841 | ||
be19f0ff CW |
1842 | if (WARN_ON(pll == NULL)) |
1843 | return; | |
1844 | ||
3e369b76 | 1845 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1846 | if (pll->active == 0) { |
1847 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1848 | WARN_ON(pll->on); | |
1849 | assert_shared_dpll_disabled(dev_priv, pll); | |
1850 | ||
1851 | pll->mode_set(dev_priv, pll); | |
1852 | } | |
1853 | } | |
1854 | ||
92f2584a | 1855 | /** |
85b3894f | 1856 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1857 | * @dev_priv: i915 private structure |
1858 | * @pipe: pipe PLL to enable | |
1859 | * | |
1860 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1861 | * drives the transcoder clock. | |
1862 | */ | |
85b3894f | 1863 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1864 | { |
3d13ef2e DL |
1865 | struct drm_device *dev = crtc->base.dev; |
1866 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1867 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1868 | |
87a875bb | 1869 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1870 | return; |
1871 | ||
3e369b76 | 1872 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1873 | return; |
ee7b9f93 | 1874 | |
74dd6928 | 1875 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1876 | pll->name, pll->active, pll->on, |
e2b78267 | 1877 | crtc->base.base.id); |
92f2584a | 1878 | |
cdbd2316 DV |
1879 | if (pll->active++) { |
1880 | WARN_ON(!pll->on); | |
e9d6944e | 1881 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1882 | return; |
1883 | } | |
f4a091c7 | 1884 | WARN_ON(pll->on); |
ee7b9f93 | 1885 | |
bd2bb1b9 PZ |
1886 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1887 | ||
46edb027 | 1888 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1889 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1890 | pll->on = true; |
92f2584a JB |
1891 | } |
1892 | ||
f6daaec2 | 1893 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1894 | { |
3d13ef2e DL |
1895 | struct drm_device *dev = crtc->base.dev; |
1896 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1897 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1898 | |
92f2584a | 1899 | /* PCH only available on ILK+ */ |
80aa9312 JB |
1900 | if (INTEL_INFO(dev)->gen < 5) |
1901 | return; | |
1902 | ||
eddfcbcd ML |
1903 | if (pll == NULL) |
1904 | return; | |
92f2584a | 1905 | |
eddfcbcd | 1906 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) |
48da64a8 | 1907 | return; |
7a419866 | 1908 | |
46edb027 DV |
1909 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1910 | pll->name, pll->active, pll->on, | |
e2b78267 | 1911 | crtc->base.base.id); |
7a419866 | 1912 | |
48da64a8 | 1913 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1914 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1915 | return; |
1916 | } | |
1917 | ||
e9d6944e | 1918 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1919 | WARN_ON(!pll->on); |
cdbd2316 | 1920 | if (--pll->active) |
7a419866 | 1921 | return; |
ee7b9f93 | 1922 | |
46edb027 | 1923 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1924 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1925 | pll->on = false; |
bd2bb1b9 PZ |
1926 | |
1927 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1928 | } |
1929 | ||
b8a4f404 PZ |
1930 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1931 | enum pipe pipe) | |
040484af | 1932 | { |
23670b32 | 1933 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1934 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1935 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
23670b32 | 1936 | uint32_t reg, val, pipeconf_val; |
040484af JB |
1937 | |
1938 | /* PCH only available on ILK+ */ | |
55522f37 | 1939 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1940 | |
1941 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1942 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1943 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1944 | |
1945 | /* FDI must be feeding us bits for PCH ports */ | |
1946 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1947 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1948 | ||
23670b32 DV |
1949 | if (HAS_PCH_CPT(dev)) { |
1950 | /* Workaround: Set the timing override bit before enabling the | |
1951 | * pch transcoder. */ | |
1952 | reg = TRANS_CHICKEN2(pipe); | |
1953 | val = I915_READ(reg); | |
1954 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1955 | I915_WRITE(reg, val); | |
59c859d6 | 1956 | } |
23670b32 | 1957 | |
ab9412ba | 1958 | reg = PCH_TRANSCONF(pipe); |
040484af | 1959 | val = I915_READ(reg); |
5f7f726d | 1960 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
1961 | |
1962 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
1963 | /* | |
c5de7c6f VS |
1964 | * Make the BPC in transcoder be consistent with |
1965 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1966 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1967 | */ |
dfd07d72 | 1968 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
1969 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
1970 | val |= PIPECONF_8BPC; | |
1971 | else | |
1972 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 1973 | } |
5f7f726d PZ |
1974 | |
1975 | val &= ~TRANS_INTERLACE_MASK; | |
1976 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 1977 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 1978 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
1979 | val |= TRANS_LEGACY_INTERLACED_ILK; |
1980 | else | |
1981 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
1982 | else |
1983 | val |= TRANS_PROGRESSIVE; | |
1984 | ||
040484af JB |
1985 | I915_WRITE(reg, val | TRANS_ENABLE); |
1986 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 1987 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
1988 | } |
1989 | ||
8fb033d7 | 1990 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 1991 | enum transcoder cpu_transcoder) |
040484af | 1992 | { |
8fb033d7 | 1993 | u32 val, pipeconf_val; |
8fb033d7 PZ |
1994 | |
1995 | /* PCH only available on ILK+ */ | |
55522f37 | 1996 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 1997 | |
8fb033d7 | 1998 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 1999 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2000 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2001 | |
223a6fdf PZ |
2002 | /* Workaround: set timing override bit. */ |
2003 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2004 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf PZ |
2005 | I915_WRITE(_TRANSA_CHICKEN2, val); |
2006 | ||
25f3ef11 | 2007 | val = TRANS_ENABLE; |
937bb610 | 2008 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2009 | |
9a76b1c6 PZ |
2010 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2011 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2012 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2013 | else |
2014 | val |= TRANS_PROGRESSIVE; | |
2015 | ||
ab9412ba DV |
2016 | I915_WRITE(LPT_TRANSCONF, val); |
2017 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2018 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2019 | } |
2020 | ||
b8a4f404 PZ |
2021 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2022 | enum pipe pipe) | |
040484af | 2023 | { |
23670b32 DV |
2024 | struct drm_device *dev = dev_priv->dev; |
2025 | uint32_t reg, val; | |
040484af JB |
2026 | |
2027 | /* FDI relies on the transcoder */ | |
2028 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2029 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2030 | ||
291906f1 JB |
2031 | /* Ports must be off as well */ |
2032 | assert_pch_ports_disabled(dev_priv, pipe); | |
2033 | ||
ab9412ba | 2034 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2035 | val = I915_READ(reg); |
2036 | val &= ~TRANS_ENABLE; | |
2037 | I915_WRITE(reg, val); | |
2038 | /* wait for PCH transcoder off, transcoder state */ | |
2039 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2040 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 DV |
2041 | |
2042 | if (!HAS_PCH_IBX(dev)) { | |
2043 | /* Workaround: Clear the timing override chicken bit again. */ | |
2044 | reg = TRANS_CHICKEN2(pipe); | |
2045 | val = I915_READ(reg); | |
2046 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2047 | I915_WRITE(reg, val); | |
2048 | } | |
040484af JB |
2049 | } |
2050 | ||
ab4d966c | 2051 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2052 | { |
8fb033d7 PZ |
2053 | u32 val; |
2054 | ||
ab9412ba | 2055 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2056 | val &= ~TRANS_ENABLE; |
ab9412ba | 2057 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2058 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2059 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2060 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2061 | |
2062 | /* Workaround: clear timing override bit. */ | |
2063 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2064 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf | 2065 | I915_WRITE(_TRANSA_CHICKEN2, val); |
040484af JB |
2066 | } |
2067 | ||
b24e7179 | 2068 | /** |
309cfea8 | 2069 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2070 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2071 | * |
0372264a | 2072 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2073 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2074 | */ |
e1fdc473 | 2075 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2076 | { |
0372264a PZ |
2077 | struct drm_device *dev = crtc->base.dev; |
2078 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2079 | enum pipe pipe = crtc->pipe; | |
702e7a56 PZ |
2080 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
2081 | pipe); | |
1a240d4d | 2082 | enum pipe pch_transcoder; |
b24e7179 JB |
2083 | int reg; |
2084 | u32 val; | |
2085 | ||
9e2ee2dd VS |
2086 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
2087 | ||
58c6eaa2 | 2088 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2089 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2090 | assert_sprites_disabled(dev_priv, pipe); |
2091 | ||
681e5811 | 2092 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2093 | pch_transcoder = TRANSCODER_A; |
2094 | else | |
2095 | pch_transcoder = pipe; | |
2096 | ||
b24e7179 JB |
2097 | /* |
2098 | * A pipe without a PLL won't actually be able to drive bits from | |
2099 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2100 | * need the check. | |
2101 | */ | |
50360403 | 2102 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
409ee761 | 2103 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
2104 | assert_dsi_pll_enabled(dev_priv); |
2105 | else | |
2106 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2107 | else { |
6e3c9717 | 2108 | if (crtc->config->has_pch_encoder) { |
040484af | 2109 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2110 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2111 | assert_fdi_tx_pll_enabled(dev_priv, |
2112 | (enum pipe) cpu_transcoder); | |
040484af JB |
2113 | } |
2114 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2115 | } | |
b24e7179 | 2116 | |
702e7a56 | 2117 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2118 | val = I915_READ(reg); |
7ad25d48 | 2119 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2120 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2121 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2122 | return; |
7ad25d48 | 2123 | } |
00d70b15 CW |
2124 | |
2125 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2126 | POSTING_READ(reg); |
b24e7179 JB |
2127 | } |
2128 | ||
2129 | /** | |
309cfea8 | 2130 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2131 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2132 | * |
575f7ab7 VS |
2133 | * Disable the pipe of @crtc, making sure that various hardware |
2134 | * specific requirements are met, if applicable, e.g. plane | |
2135 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2136 | * |
2137 | * Will wait until the pipe has shut down before returning. | |
2138 | */ | |
575f7ab7 | 2139 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2140 | { |
575f7ab7 | 2141 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2142 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2143 | enum pipe pipe = crtc->pipe; |
b24e7179 JB |
2144 | int reg; |
2145 | u32 val; | |
2146 | ||
9e2ee2dd VS |
2147 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
2148 | ||
b24e7179 JB |
2149 | /* |
2150 | * Make sure planes won't keep trying to pump pixels to us, | |
2151 | * or we might hang the display. | |
2152 | */ | |
2153 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2154 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2155 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2156 | |
702e7a56 | 2157 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2158 | val = I915_READ(reg); |
00d70b15 CW |
2159 | if ((val & PIPECONF_ENABLE) == 0) |
2160 | return; | |
2161 | ||
67adc644 VS |
2162 | /* |
2163 | * Double wide has implications for planes | |
2164 | * so best keep it disabled when not needed. | |
2165 | */ | |
6e3c9717 | 2166 | if (crtc->config->double_wide) |
67adc644 VS |
2167 | val &= ~PIPECONF_DOUBLE_WIDE; |
2168 | ||
2169 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2170 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2171 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2172 | val &= ~PIPECONF_ENABLE; |
2173 | ||
2174 | I915_WRITE(reg, val); | |
2175 | if ((val & PIPECONF_ENABLE) == 0) | |
2176 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2177 | } |
2178 | ||
693db184 CW |
2179 | static bool need_vtd_wa(struct drm_device *dev) |
2180 | { | |
2181 | #ifdef CONFIG_INTEL_IOMMU | |
2182 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2183 | return true; | |
2184 | #endif | |
2185 | return false; | |
2186 | } | |
2187 | ||
50470bb0 | 2188 | unsigned int |
6761dd31 TU |
2189 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
2190 | uint64_t fb_format_modifier) | |
a57ce0b2 | 2191 | { |
6761dd31 TU |
2192 | unsigned int tile_height; |
2193 | uint32_t pixel_bytes; | |
a57ce0b2 | 2194 | |
b5d0e9bf DL |
2195 | switch (fb_format_modifier) { |
2196 | case DRM_FORMAT_MOD_NONE: | |
2197 | tile_height = 1; | |
2198 | break; | |
2199 | case I915_FORMAT_MOD_X_TILED: | |
2200 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2201 | break; | |
2202 | case I915_FORMAT_MOD_Y_TILED: | |
2203 | tile_height = 32; | |
2204 | break; | |
2205 | case I915_FORMAT_MOD_Yf_TILED: | |
6761dd31 TU |
2206 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
2207 | switch (pixel_bytes) { | |
b5d0e9bf | 2208 | default: |
6761dd31 | 2209 | case 1: |
b5d0e9bf DL |
2210 | tile_height = 64; |
2211 | break; | |
6761dd31 TU |
2212 | case 2: |
2213 | case 4: | |
b5d0e9bf DL |
2214 | tile_height = 32; |
2215 | break; | |
6761dd31 | 2216 | case 8: |
b5d0e9bf DL |
2217 | tile_height = 16; |
2218 | break; | |
6761dd31 | 2219 | case 16: |
b5d0e9bf DL |
2220 | WARN_ONCE(1, |
2221 | "128-bit pixels are not supported for display!"); | |
2222 | tile_height = 16; | |
2223 | break; | |
2224 | } | |
2225 | break; | |
2226 | default: | |
2227 | MISSING_CASE(fb_format_modifier); | |
2228 | tile_height = 1; | |
2229 | break; | |
2230 | } | |
091df6cb | 2231 | |
6761dd31 TU |
2232 | return tile_height; |
2233 | } | |
2234 | ||
2235 | unsigned int | |
2236 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2237 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2238 | { | |
2239 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
2240 | fb_format_modifier)); | |
a57ce0b2 JB |
2241 | } |
2242 | ||
f64b98cd TU |
2243 | static int |
2244 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, | |
2245 | const struct drm_plane_state *plane_state) | |
2246 | { | |
50470bb0 | 2247 | struct intel_rotation_info *info = &view->rotation_info; |
84fe03f7 | 2248 | unsigned int tile_height, tile_pitch; |
50470bb0 | 2249 | |
f64b98cd TU |
2250 | *view = i915_ggtt_view_normal; |
2251 | ||
50470bb0 TU |
2252 | if (!plane_state) |
2253 | return 0; | |
2254 | ||
121920fa | 2255 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
50470bb0 TU |
2256 | return 0; |
2257 | ||
9abc4648 | 2258 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2259 | |
2260 | info->height = fb->height; | |
2261 | info->pixel_format = fb->pixel_format; | |
2262 | info->pitch = fb->pitches[0]; | |
2263 | info->fb_modifier = fb->modifier[0]; | |
2264 | ||
84fe03f7 TU |
2265 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, |
2266 | fb->modifier[0]); | |
2267 | tile_pitch = PAGE_SIZE / tile_height; | |
2268 | info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch); | |
2269 | info->height_pages = DIV_ROUND_UP(fb->height, tile_height); | |
2270 | info->size = info->width_pages * info->height_pages * PAGE_SIZE; | |
2271 | ||
f64b98cd TU |
2272 | return 0; |
2273 | } | |
2274 | ||
4e9a86b6 VS |
2275 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
2276 | { | |
2277 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2278 | return 256 * 1024; | |
985b8bb4 VS |
2279 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
2280 | IS_VALLEYVIEW(dev_priv)) | |
4e9a86b6 VS |
2281 | return 128 * 1024; |
2282 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2283 | return 4 * 1024; | |
2284 | else | |
44c5905e | 2285 | return 0; |
4e9a86b6 VS |
2286 | } |
2287 | ||
127bd2ac | 2288 | int |
850c4cdc TU |
2289 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2290 | struct drm_framebuffer *fb, | |
82bc3b2d | 2291 | const struct drm_plane_state *plane_state, |
91af127f JH |
2292 | struct intel_engine_cs *pipelined, |
2293 | struct drm_i915_gem_request **pipelined_request) | |
6b95a207 | 2294 | { |
850c4cdc | 2295 | struct drm_device *dev = fb->dev; |
ce453d81 | 2296 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2297 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2298 | struct i915_ggtt_view view; |
6b95a207 KH |
2299 | u32 alignment; |
2300 | int ret; | |
2301 | ||
ebcdd39e MR |
2302 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2303 | ||
7b911adc TU |
2304 | switch (fb->modifier[0]) { |
2305 | case DRM_FORMAT_MOD_NONE: | |
4e9a86b6 | 2306 | alignment = intel_linear_alignment(dev_priv); |
6b95a207 | 2307 | break; |
7b911adc | 2308 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2309 | if (INTEL_INFO(dev)->gen >= 9) |
2310 | alignment = 256 * 1024; | |
2311 | else { | |
2312 | /* pin() will align the object as required by fence */ | |
2313 | alignment = 0; | |
2314 | } | |
6b95a207 | 2315 | break; |
7b911adc | 2316 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2317 | case I915_FORMAT_MOD_Yf_TILED: |
2318 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2319 | "Y tiling bo slipped through, driver bug!\n")) | |
2320 | return -EINVAL; | |
2321 | alignment = 1 * 1024 * 1024; | |
2322 | break; | |
6b95a207 | 2323 | default: |
7b911adc TU |
2324 | MISSING_CASE(fb->modifier[0]); |
2325 | return -EINVAL; | |
6b95a207 KH |
2326 | } |
2327 | ||
f64b98cd TU |
2328 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2329 | if (ret) | |
2330 | return ret; | |
2331 | ||
693db184 CW |
2332 | /* Note that the w/a also requires 64 PTE of padding following the |
2333 | * bo. We currently fill all unused PTE with the shadow page and so | |
2334 | * we should always have valid PTE following the scanout preventing | |
2335 | * the VT-d warning. | |
2336 | */ | |
2337 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2338 | alignment = 256 * 1024; | |
2339 | ||
d6dd6843 PZ |
2340 | /* |
2341 | * Global gtt pte registers are special registers which actually forward | |
2342 | * writes to a chunk of system memory. Which means that there is no risk | |
2343 | * that the register values disappear as soon as we call | |
2344 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2345 | * pin/unpin/fence and not more. | |
2346 | */ | |
2347 | intel_runtime_pm_get(dev_priv); | |
2348 | ||
ce453d81 | 2349 | dev_priv->mm.interruptible = false; |
e6617330 | 2350 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
91af127f | 2351 | pipelined_request, &view); |
48b956c5 | 2352 | if (ret) |
ce453d81 | 2353 | goto err_interruptible; |
6b95a207 KH |
2354 | |
2355 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2356 | * fence, whereas 965+ only requires a fence if using | |
2357 | * framebuffer compression. For simplicity, we always install | |
2358 | * a fence as the cost is not that onerous. | |
2359 | */ | |
06d98131 | 2360 | ret = i915_gem_object_get_fence(obj); |
842315ee ML |
2361 | if (ret == -EDEADLK) { |
2362 | /* | |
2363 | * -EDEADLK means there are no free fences | |
2364 | * no pending flips. | |
2365 | * | |
2366 | * This is propagated to atomic, but it uses | |
2367 | * -EDEADLK to force a locking recovery, so | |
2368 | * change the returned error to -EBUSY. | |
2369 | */ | |
2370 | ret = -EBUSY; | |
2371 | goto err_unpin; | |
2372 | } else if (ret) | |
9a5a53b3 | 2373 | goto err_unpin; |
1690e1eb | 2374 | |
9a5a53b3 | 2375 | i915_gem_object_pin_fence(obj); |
6b95a207 | 2376 | |
ce453d81 | 2377 | dev_priv->mm.interruptible = true; |
d6dd6843 | 2378 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2379 | return 0; |
48b956c5 CW |
2380 | |
2381 | err_unpin: | |
f64b98cd | 2382 | i915_gem_object_unpin_from_display_plane(obj, &view); |
ce453d81 CW |
2383 | err_interruptible: |
2384 | dev_priv->mm.interruptible = true; | |
d6dd6843 | 2385 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2386 | return ret; |
6b95a207 KH |
2387 | } |
2388 | ||
82bc3b2d TU |
2389 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2390 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2391 | { |
82bc3b2d | 2392 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd TU |
2393 | struct i915_ggtt_view view; |
2394 | int ret; | |
82bc3b2d | 2395 | |
ebcdd39e MR |
2396 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2397 | ||
f64b98cd TU |
2398 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2399 | WARN_ONCE(ret, "Couldn't get view from plane state!"); | |
2400 | ||
1690e1eb | 2401 | i915_gem_object_unpin_fence(obj); |
f64b98cd | 2402 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2403 | } |
2404 | ||
c2c75131 DV |
2405 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2406 | * is assumed to be a power-of-two. */ | |
4e9a86b6 VS |
2407 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
2408 | int *x, int *y, | |
bc752862 CW |
2409 | unsigned int tiling_mode, |
2410 | unsigned int cpp, | |
2411 | unsigned int pitch) | |
c2c75131 | 2412 | { |
bc752862 CW |
2413 | if (tiling_mode != I915_TILING_NONE) { |
2414 | unsigned int tile_rows, tiles; | |
c2c75131 | 2415 | |
bc752862 CW |
2416 | tile_rows = *y / 8; |
2417 | *y %= 8; | |
c2c75131 | 2418 | |
bc752862 CW |
2419 | tiles = *x / (512/cpp); |
2420 | *x %= 512/cpp; | |
2421 | ||
2422 | return tile_rows * pitch * 8 + tiles * 4096; | |
2423 | } else { | |
4e9a86b6 | 2424 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
bc752862 CW |
2425 | unsigned int offset; |
2426 | ||
2427 | offset = *y * pitch + *x * cpp; | |
4e9a86b6 VS |
2428 | *y = (offset & alignment) / pitch; |
2429 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2430 | return offset & ~alignment; | |
bc752862 | 2431 | } |
c2c75131 DV |
2432 | } |
2433 | ||
b35d63fa | 2434 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2435 | { |
2436 | switch (format) { | |
2437 | case DISPPLANE_8BPP: | |
2438 | return DRM_FORMAT_C8; | |
2439 | case DISPPLANE_BGRX555: | |
2440 | return DRM_FORMAT_XRGB1555; | |
2441 | case DISPPLANE_BGRX565: | |
2442 | return DRM_FORMAT_RGB565; | |
2443 | default: | |
2444 | case DISPPLANE_BGRX888: | |
2445 | return DRM_FORMAT_XRGB8888; | |
2446 | case DISPPLANE_RGBX888: | |
2447 | return DRM_FORMAT_XBGR8888; | |
2448 | case DISPPLANE_BGRX101010: | |
2449 | return DRM_FORMAT_XRGB2101010; | |
2450 | case DISPPLANE_RGBX101010: | |
2451 | return DRM_FORMAT_XBGR2101010; | |
2452 | } | |
2453 | } | |
2454 | ||
bc8d7dff DL |
2455 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2456 | { | |
2457 | switch (format) { | |
2458 | case PLANE_CTL_FORMAT_RGB_565: | |
2459 | return DRM_FORMAT_RGB565; | |
2460 | default: | |
2461 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2462 | if (rgb_order) { | |
2463 | if (alpha) | |
2464 | return DRM_FORMAT_ABGR8888; | |
2465 | else | |
2466 | return DRM_FORMAT_XBGR8888; | |
2467 | } else { | |
2468 | if (alpha) | |
2469 | return DRM_FORMAT_ARGB8888; | |
2470 | else | |
2471 | return DRM_FORMAT_XRGB8888; | |
2472 | } | |
2473 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2474 | if (rgb_order) | |
2475 | return DRM_FORMAT_XBGR2101010; | |
2476 | else | |
2477 | return DRM_FORMAT_XRGB2101010; | |
2478 | } | |
2479 | } | |
2480 | ||
5724dbd1 | 2481 | static bool |
f6936e29 DV |
2482 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2483 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2484 | { |
2485 | struct drm_device *dev = crtc->base.dev; | |
2486 | struct drm_i915_gem_object *obj = NULL; | |
2487 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2488 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2489 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2490 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2491 | PAGE_SIZE); | |
2492 | ||
2493 | size_aligned -= base_aligned; | |
46f297fb | 2494 | |
ff2652ea CW |
2495 | if (plane_config->size == 0) |
2496 | return false; | |
2497 | ||
f37b5c2b DV |
2498 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2499 | base_aligned, | |
2500 | base_aligned, | |
2501 | size_aligned); | |
46f297fb | 2502 | if (!obj) |
484b41dd | 2503 | return false; |
46f297fb | 2504 | |
49af449b DL |
2505 | obj->tiling_mode = plane_config->tiling; |
2506 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2507 | obj->stride = fb->pitches[0]; |
46f297fb | 2508 | |
6bf129df DL |
2509 | mode_cmd.pixel_format = fb->pixel_format; |
2510 | mode_cmd.width = fb->width; | |
2511 | mode_cmd.height = fb->height; | |
2512 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2513 | mode_cmd.modifier[0] = fb->modifier[0]; |
2514 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2515 | |
2516 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2517 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2518 | &mode_cmd, obj)) { |
46f297fb JB |
2519 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2520 | goto out_unref_obj; | |
2521 | } | |
46f297fb | 2522 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2523 | |
f6936e29 | 2524 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2525 | return true; |
46f297fb JB |
2526 | |
2527 | out_unref_obj: | |
2528 | drm_gem_object_unreference(&obj->base); | |
2529 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2530 | return false; |
2531 | } | |
2532 | ||
afd65eb4 MR |
2533 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2534 | static void | |
2535 | update_state_fb(struct drm_plane *plane) | |
2536 | { | |
2537 | if (plane->fb == plane->state->fb) | |
2538 | return; | |
2539 | ||
2540 | if (plane->state->fb) | |
2541 | drm_framebuffer_unreference(plane->state->fb); | |
2542 | plane->state->fb = plane->fb; | |
2543 | if (plane->state->fb) | |
2544 | drm_framebuffer_reference(plane->state->fb); | |
2545 | } | |
2546 | ||
5724dbd1 | 2547 | static void |
f6936e29 DV |
2548 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2549 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2550 | { |
2551 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2552 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2553 | struct drm_crtc *c; |
2554 | struct intel_crtc *i; | |
2ff8fde1 | 2555 | struct drm_i915_gem_object *obj; |
88595ac9 | 2556 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2557 | struct drm_plane_state *plane_state = primary->state; |
88595ac9 | 2558 | struct drm_framebuffer *fb; |
484b41dd | 2559 | |
2d14030b | 2560 | if (!plane_config->fb) |
484b41dd JB |
2561 | return; |
2562 | ||
f6936e29 | 2563 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2564 | fb = &plane_config->fb->base; |
2565 | goto valid_fb; | |
f55548b5 | 2566 | } |
484b41dd | 2567 | |
2d14030b | 2568 | kfree(plane_config->fb); |
484b41dd JB |
2569 | |
2570 | /* | |
2571 | * Failed to alloc the obj, check to see if we should share | |
2572 | * an fb with another CRTC instead | |
2573 | */ | |
70e1e0ec | 2574 | for_each_crtc(dev, c) { |
484b41dd JB |
2575 | i = to_intel_crtc(c); |
2576 | ||
2577 | if (c == &intel_crtc->base) | |
2578 | continue; | |
2579 | ||
2ff8fde1 MR |
2580 | if (!i->active) |
2581 | continue; | |
2582 | ||
88595ac9 DV |
2583 | fb = c->primary->fb; |
2584 | if (!fb) | |
484b41dd JB |
2585 | continue; |
2586 | ||
88595ac9 | 2587 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2588 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2589 | drm_framebuffer_reference(fb); |
2590 | goto valid_fb; | |
484b41dd JB |
2591 | } |
2592 | } | |
88595ac9 DV |
2593 | |
2594 | return; | |
2595 | ||
2596 | valid_fb: | |
be5651f2 ML |
2597 | plane_state->src_x = plane_state->src_y = 0; |
2598 | plane_state->src_w = fb->width << 16; | |
2599 | plane_state->src_h = fb->height << 16; | |
2600 | ||
2601 | plane_state->crtc_x = plane_state->src_y = 0; | |
2602 | plane_state->crtc_w = fb->width; | |
2603 | plane_state->crtc_h = fb->height; | |
2604 | ||
88595ac9 DV |
2605 | obj = intel_fb_obj(fb); |
2606 | if (obj->tiling_mode != I915_TILING_NONE) | |
2607 | dev_priv->preserve_bios_swizzle = true; | |
2608 | ||
be5651f2 ML |
2609 | drm_framebuffer_reference(fb); |
2610 | primary->fb = primary->state->fb = fb; | |
36750f28 | 2611 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
36750f28 | 2612 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
a9ff8714 | 2613 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
46f297fb JB |
2614 | } |
2615 | ||
29b9bde6 DV |
2616 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2617 | struct drm_framebuffer *fb, | |
2618 | int x, int y) | |
81255565 JB |
2619 | { |
2620 | struct drm_device *dev = crtc->dev; | |
2621 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2622 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2623 | struct drm_plane *primary = crtc->primary; |
2624 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2625 | struct drm_i915_gem_object *obj; |
81255565 | 2626 | int plane = intel_crtc->plane; |
e506a0c6 | 2627 | unsigned long linear_offset; |
81255565 | 2628 | u32 dspcntr; |
f45651ba | 2629 | u32 reg = DSPCNTR(plane); |
48404c1e | 2630 | int pixel_size; |
f45651ba | 2631 | |
b70709a6 | 2632 | if (!visible || !fb) { |
fdd508a6 VS |
2633 | I915_WRITE(reg, 0); |
2634 | if (INTEL_INFO(dev)->gen >= 4) | |
2635 | I915_WRITE(DSPSURF(plane), 0); | |
2636 | else | |
2637 | I915_WRITE(DSPADDR(plane), 0); | |
2638 | POSTING_READ(reg); | |
2639 | return; | |
2640 | } | |
2641 | ||
c9ba6fad VS |
2642 | obj = intel_fb_obj(fb); |
2643 | if (WARN_ON(obj == NULL)) | |
2644 | return; | |
2645 | ||
2646 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2647 | ||
f45651ba VS |
2648 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2649 | ||
fdd508a6 | 2650 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2651 | |
2652 | if (INTEL_INFO(dev)->gen < 4) { | |
2653 | if (intel_crtc->pipe == PIPE_B) | |
2654 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2655 | ||
2656 | /* pipesrc and dspsize control the size that is scaled from, | |
2657 | * which should always be the user's requested size. | |
2658 | */ | |
2659 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2660 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2661 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2662 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2663 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2664 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2665 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2666 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2667 | I915_WRITE(PRIMPOS(plane), 0); |
2668 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2669 | } |
81255565 | 2670 | |
57779d06 VS |
2671 | switch (fb->pixel_format) { |
2672 | case DRM_FORMAT_C8: | |
81255565 JB |
2673 | dspcntr |= DISPPLANE_8BPP; |
2674 | break; | |
57779d06 | 2675 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2676 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2677 | break; |
57779d06 VS |
2678 | case DRM_FORMAT_RGB565: |
2679 | dspcntr |= DISPPLANE_BGRX565; | |
2680 | break; | |
2681 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2682 | dspcntr |= DISPPLANE_BGRX888; |
2683 | break; | |
2684 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2685 | dspcntr |= DISPPLANE_RGBX888; |
2686 | break; | |
2687 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2688 | dspcntr |= DISPPLANE_BGRX101010; |
2689 | break; | |
2690 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2691 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2692 | break; |
2693 | default: | |
baba133a | 2694 | BUG(); |
81255565 | 2695 | } |
57779d06 | 2696 | |
f45651ba VS |
2697 | if (INTEL_INFO(dev)->gen >= 4 && |
2698 | obj->tiling_mode != I915_TILING_NONE) | |
2699 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2700 | |
de1aa629 VS |
2701 | if (IS_G4X(dev)) |
2702 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2703 | ||
b9897127 | 2704 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2705 | |
c2c75131 DV |
2706 | if (INTEL_INFO(dev)->gen >= 4) { |
2707 | intel_crtc->dspaddr_offset = | |
4e9a86b6 VS |
2708 | intel_gen4_compute_page_offset(dev_priv, |
2709 | &x, &y, obj->tiling_mode, | |
b9897127 | 2710 | pixel_size, |
bc752862 | 2711 | fb->pitches[0]); |
c2c75131 DV |
2712 | linear_offset -= intel_crtc->dspaddr_offset; |
2713 | } else { | |
e506a0c6 | 2714 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2715 | } |
e506a0c6 | 2716 | |
8e7d688b | 2717 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2718 | dspcntr |= DISPPLANE_ROTATE_180; |
2719 | ||
6e3c9717 ACO |
2720 | x += (intel_crtc->config->pipe_src_w - 1); |
2721 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2722 | |
2723 | /* Finding the last pixel of the last line of the display | |
2724 | data and adding to linear_offset*/ | |
2725 | linear_offset += | |
6e3c9717 ACO |
2726 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2727 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2728 | } |
2729 | ||
2730 | I915_WRITE(reg, dspcntr); | |
2731 | ||
01f2c773 | 2732 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2733 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2734 | I915_WRITE(DSPSURF(plane), |
2735 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2736 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2737 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2738 | } else |
f343c5f6 | 2739 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2740 | POSTING_READ(reg); |
17638cd6 JB |
2741 | } |
2742 | ||
29b9bde6 DV |
2743 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2744 | struct drm_framebuffer *fb, | |
2745 | int x, int y) | |
17638cd6 JB |
2746 | { |
2747 | struct drm_device *dev = crtc->dev; | |
2748 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2749 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2750 | struct drm_plane *primary = crtc->primary; |
2751 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2752 | struct drm_i915_gem_object *obj; |
17638cd6 | 2753 | int plane = intel_crtc->plane; |
e506a0c6 | 2754 | unsigned long linear_offset; |
17638cd6 | 2755 | u32 dspcntr; |
f45651ba | 2756 | u32 reg = DSPCNTR(plane); |
48404c1e | 2757 | int pixel_size; |
f45651ba | 2758 | |
b70709a6 | 2759 | if (!visible || !fb) { |
fdd508a6 VS |
2760 | I915_WRITE(reg, 0); |
2761 | I915_WRITE(DSPSURF(plane), 0); | |
2762 | POSTING_READ(reg); | |
2763 | return; | |
2764 | } | |
2765 | ||
c9ba6fad VS |
2766 | obj = intel_fb_obj(fb); |
2767 | if (WARN_ON(obj == NULL)) | |
2768 | return; | |
2769 | ||
2770 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2771 | ||
f45651ba VS |
2772 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2773 | ||
fdd508a6 | 2774 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2775 | |
2776 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2777 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2778 | |
57779d06 VS |
2779 | switch (fb->pixel_format) { |
2780 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2781 | dspcntr |= DISPPLANE_8BPP; |
2782 | break; | |
57779d06 VS |
2783 | case DRM_FORMAT_RGB565: |
2784 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2785 | break; |
57779d06 | 2786 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2787 | dspcntr |= DISPPLANE_BGRX888; |
2788 | break; | |
2789 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2790 | dspcntr |= DISPPLANE_RGBX888; |
2791 | break; | |
2792 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2793 | dspcntr |= DISPPLANE_BGRX101010; |
2794 | break; | |
2795 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2796 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2797 | break; |
2798 | default: | |
baba133a | 2799 | BUG(); |
17638cd6 JB |
2800 | } |
2801 | ||
2802 | if (obj->tiling_mode != I915_TILING_NONE) | |
2803 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2804 | |
f45651ba | 2805 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2806 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2807 | |
b9897127 | 2808 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2809 | intel_crtc->dspaddr_offset = |
4e9a86b6 VS |
2810 | intel_gen4_compute_page_offset(dev_priv, |
2811 | &x, &y, obj->tiling_mode, | |
b9897127 | 2812 | pixel_size, |
bc752862 | 2813 | fb->pitches[0]); |
c2c75131 | 2814 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2815 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2816 | dspcntr |= DISPPLANE_ROTATE_180; |
2817 | ||
2818 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2819 | x += (intel_crtc->config->pipe_src_w - 1); |
2820 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2821 | |
2822 | /* Finding the last pixel of the last line of the display | |
2823 | data and adding to linear_offset*/ | |
2824 | linear_offset += | |
6e3c9717 ACO |
2825 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2826 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2827 | } |
2828 | } | |
2829 | ||
2830 | I915_WRITE(reg, dspcntr); | |
17638cd6 | 2831 | |
01f2c773 | 2832 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2833 | I915_WRITE(DSPSURF(plane), |
2834 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2835 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2836 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2837 | } else { | |
2838 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2839 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2840 | } | |
17638cd6 | 2841 | POSTING_READ(reg); |
17638cd6 JB |
2842 | } |
2843 | ||
b321803d DL |
2844 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2845 | uint32_t pixel_format) | |
2846 | { | |
2847 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2848 | ||
2849 | /* | |
2850 | * The stride is either expressed as a multiple of 64 bytes | |
2851 | * chunks for linear buffers or in number of tiles for tiled | |
2852 | * buffers. | |
2853 | */ | |
2854 | switch (fb_modifier) { | |
2855 | case DRM_FORMAT_MOD_NONE: | |
2856 | return 64; | |
2857 | case I915_FORMAT_MOD_X_TILED: | |
2858 | if (INTEL_INFO(dev)->gen == 2) | |
2859 | return 128; | |
2860 | return 512; | |
2861 | case I915_FORMAT_MOD_Y_TILED: | |
2862 | /* No need to check for old gens and Y tiling since this is | |
2863 | * about the display engine and those will be blocked before | |
2864 | * we get here. | |
2865 | */ | |
2866 | return 128; | |
2867 | case I915_FORMAT_MOD_Yf_TILED: | |
2868 | if (bits_per_pixel == 8) | |
2869 | return 64; | |
2870 | else | |
2871 | return 128; | |
2872 | default: | |
2873 | MISSING_CASE(fb_modifier); | |
2874 | return 64; | |
2875 | } | |
2876 | } | |
2877 | ||
121920fa TU |
2878 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
2879 | struct drm_i915_gem_object *obj) | |
2880 | { | |
9abc4648 | 2881 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
121920fa TU |
2882 | |
2883 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) | |
9abc4648 | 2884 | view = &i915_ggtt_view_rotated; |
121920fa TU |
2885 | |
2886 | return i915_gem_obj_ggtt_offset_view(obj, view); | |
2887 | } | |
2888 | ||
e435d6e5 ML |
2889 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
2890 | { | |
2891 | struct drm_device *dev = intel_crtc->base.dev; | |
2892 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2893 | ||
2894 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
2895 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
2896 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
2897 | } |
2898 | ||
a1b2278e CK |
2899 | /* |
2900 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2901 | */ | |
0583236e | 2902 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 2903 | { |
a1b2278e CK |
2904 | struct intel_crtc_scaler_state *scaler_state; |
2905 | int i; | |
2906 | ||
a1b2278e CK |
2907 | scaler_state = &intel_crtc->config->scaler_state; |
2908 | ||
2909 | /* loop through and disable scalers that aren't in use */ | |
2910 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
2911 | if (!scaler_state->scalers[i].in_use) |
2912 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
2913 | } |
2914 | } | |
2915 | ||
6156a456 | 2916 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2917 | { |
6156a456 | 2918 | switch (pixel_format) { |
d161cf7a | 2919 | case DRM_FORMAT_C8: |
c34ce3d1 | 2920 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2921 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2922 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2923 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2924 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2925 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2926 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2927 | /* |
2928 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2929 | * to be already pre-multiplied. We need to add a knob (or a different | |
2930 | * DRM_FORMAT) for user-space to configure that. | |
2931 | */ | |
f75fb42a | 2932 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 2933 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 2934 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 2935 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 2936 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 2937 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 2938 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 2939 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 2940 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 2941 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 2942 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 2943 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 2944 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 2945 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 2946 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 2947 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 2948 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 2949 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 2950 | default: |
4249eeef | 2951 | MISSING_CASE(pixel_format); |
70d21f0e | 2952 | } |
8cfcba41 | 2953 | |
c34ce3d1 | 2954 | return 0; |
6156a456 | 2955 | } |
70d21f0e | 2956 | |
6156a456 CK |
2957 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
2958 | { | |
6156a456 | 2959 | switch (fb_modifier) { |
30af77c4 | 2960 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 2961 | break; |
30af77c4 | 2962 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 2963 | return PLANE_CTL_TILED_X; |
b321803d | 2964 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 2965 | return PLANE_CTL_TILED_Y; |
b321803d | 2966 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 2967 | return PLANE_CTL_TILED_YF; |
70d21f0e | 2968 | default: |
6156a456 | 2969 | MISSING_CASE(fb_modifier); |
70d21f0e | 2970 | } |
8cfcba41 | 2971 | |
c34ce3d1 | 2972 | return 0; |
6156a456 | 2973 | } |
70d21f0e | 2974 | |
6156a456 CK |
2975 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
2976 | { | |
3b7a5119 | 2977 | switch (rotation) { |
6156a456 CK |
2978 | case BIT(DRM_ROTATE_0): |
2979 | break; | |
1e8df167 SJ |
2980 | /* |
2981 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
2982 | * while i915 HW rotation is clockwise, thats why this swapping. | |
2983 | */ | |
3b7a5119 | 2984 | case BIT(DRM_ROTATE_90): |
1e8df167 | 2985 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 2986 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 2987 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 2988 | case BIT(DRM_ROTATE_270): |
1e8df167 | 2989 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
2990 | default: |
2991 | MISSING_CASE(rotation); | |
2992 | } | |
2993 | ||
c34ce3d1 | 2994 | return 0; |
6156a456 CK |
2995 | } |
2996 | ||
2997 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
2998 | struct drm_framebuffer *fb, | |
2999 | int x, int y) | |
3000 | { | |
3001 | struct drm_device *dev = crtc->dev; | |
3002 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3003 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3004 | struct drm_plane *plane = crtc->primary; |
3005 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3006 | struct drm_i915_gem_object *obj; |
3007 | int pipe = intel_crtc->pipe; | |
3008 | u32 plane_ctl, stride_div, stride; | |
3009 | u32 tile_height, plane_offset, plane_size; | |
3010 | unsigned int rotation; | |
3011 | int x_offset, y_offset; | |
3012 | unsigned long surf_addr; | |
6156a456 CK |
3013 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3014 | struct intel_plane_state *plane_state; | |
3015 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3016 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3017 | int scaler_id = -1; | |
3018 | ||
6156a456 CK |
3019 | plane_state = to_intel_plane_state(plane->state); |
3020 | ||
b70709a6 | 3021 | if (!visible || !fb) { |
6156a456 CK |
3022 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3023 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3024 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3025 | return; | |
3b7a5119 | 3026 | } |
70d21f0e | 3027 | |
6156a456 CK |
3028 | plane_ctl = PLANE_CTL_ENABLE | |
3029 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3030 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3031 | ||
3032 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3033 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3034 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3035 | ||
3036 | rotation = plane->state->rotation; | |
3037 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3038 | ||
b321803d DL |
3039 | obj = intel_fb_obj(fb); |
3040 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3041 | fb->pixel_format); | |
3b7a5119 SJ |
3042 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
3043 | ||
6156a456 CK |
3044 | /* |
3045 | * FIXME: intel_plane_state->src, dst aren't set when transitional | |
3046 | * update_plane helpers are called from legacy paths. | |
3047 | * Once full atomic crtc is available, below check can be avoided. | |
3048 | */ | |
3049 | if (drm_rect_width(&plane_state->src)) { | |
3050 | scaler_id = plane_state->scaler_id; | |
3051 | src_x = plane_state->src.x1 >> 16; | |
3052 | src_y = plane_state->src.y1 >> 16; | |
3053 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3054 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3055 | dst_x = plane_state->dst.x1; | |
3056 | dst_y = plane_state->dst.y1; | |
3057 | dst_w = drm_rect_width(&plane_state->dst); | |
3058 | dst_h = drm_rect_height(&plane_state->dst); | |
3059 | ||
3060 | WARN_ON(x != src_x || y != src_y); | |
3061 | } else { | |
3062 | src_w = intel_crtc->config->pipe_src_w; | |
3063 | src_h = intel_crtc->config->pipe_src_h; | |
3064 | } | |
3065 | ||
3b7a5119 SJ |
3066 | if (intel_rotation_90_or_270(rotation)) { |
3067 | /* stride = Surface height in tiles */ | |
2614f17d | 3068 | tile_height = intel_tile_height(dev, fb->pixel_format, |
3b7a5119 SJ |
3069 | fb->modifier[0]); |
3070 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
6156a456 | 3071 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3072 | y_offset = x; |
6156a456 | 3073 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3074 | } else { |
3075 | stride = fb->pitches[0] / stride_div; | |
3076 | x_offset = x; | |
3077 | y_offset = y; | |
6156a456 | 3078 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3079 | } |
3080 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3081 | |
70d21f0e | 3082 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3083 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3084 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3085 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3086 | |
3087 | if (scaler_id >= 0) { | |
3088 | uint32_t ps_ctrl = 0; | |
3089 | ||
3090 | WARN_ON(!dst_w || !dst_h); | |
3091 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3092 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3093 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3094 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3095 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3096 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3097 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3098 | } else { | |
3099 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3100 | } | |
3101 | ||
121920fa | 3102 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3103 | |
3104 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3105 | } | |
3106 | ||
17638cd6 JB |
3107 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3108 | static int | |
3109 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3110 | int x, int y, enum mode_set_atomic state) | |
3111 | { | |
3112 | struct drm_device *dev = crtc->dev; | |
3113 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3114 | |
ff2a3117 | 3115 | if (dev_priv->fbc.disable_fbc) |
7733b49b | 3116 | dev_priv->fbc.disable_fbc(dev_priv); |
81255565 | 3117 | |
29b9bde6 DV |
3118 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3119 | ||
3120 | return 0; | |
81255565 JB |
3121 | } |
3122 | ||
7514747d | 3123 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3124 | { |
96a02917 VS |
3125 | struct drm_crtc *crtc; |
3126 | ||
70e1e0ec | 3127 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3128 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3129 | enum plane plane = intel_crtc->plane; | |
3130 | ||
3131 | intel_prepare_page_flip(dev, plane); | |
3132 | intel_finish_page_flip_plane(dev, plane); | |
3133 | } | |
7514747d VS |
3134 | } |
3135 | ||
3136 | static void intel_update_primary_planes(struct drm_device *dev) | |
3137 | { | |
3138 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3139 | struct drm_crtc *crtc; | |
96a02917 | 3140 | |
70e1e0ec | 3141 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3142 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3143 | ||
51fd371b | 3144 | drm_modeset_lock(&crtc->mutex, NULL); |
947fdaad CW |
3145 | /* |
3146 | * FIXME: Once we have proper support for primary planes (and | |
3147 | * disabling them without disabling the entire crtc) allow again | |
66e514c1 | 3148 | * a NULL crtc->primary->fb. |
947fdaad | 3149 | */ |
f4510a27 | 3150 | if (intel_crtc->active && crtc->primary->fb) |
262ca2b0 | 3151 | dev_priv->display.update_primary_plane(crtc, |
66e514c1 | 3152 | crtc->primary->fb, |
262ca2b0 MR |
3153 | crtc->x, |
3154 | crtc->y); | |
51fd371b | 3155 | drm_modeset_unlock(&crtc->mutex); |
96a02917 VS |
3156 | } |
3157 | } | |
3158 | ||
7514747d VS |
3159 | void intel_prepare_reset(struct drm_device *dev) |
3160 | { | |
3161 | /* no reset support for gen2 */ | |
3162 | if (IS_GEN2(dev)) | |
3163 | return; | |
3164 | ||
3165 | /* reset doesn't touch the display */ | |
3166 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3167 | return; | |
3168 | ||
3169 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3170 | /* |
3171 | * Disabling the crtcs gracefully seems nicer. Also the | |
3172 | * g33 docs say we should at least disable all the planes. | |
3173 | */ | |
6b72d486 | 3174 | intel_display_suspend(dev); |
7514747d VS |
3175 | } |
3176 | ||
3177 | void intel_finish_reset(struct drm_device *dev) | |
3178 | { | |
3179 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3180 | ||
3181 | /* | |
3182 | * Flips in the rings will be nuked by the reset, | |
3183 | * so complete all pending flips so that user space | |
3184 | * will get its events and not get stuck. | |
3185 | */ | |
3186 | intel_complete_page_flips(dev); | |
3187 | ||
3188 | /* no reset support for gen2 */ | |
3189 | if (IS_GEN2(dev)) | |
3190 | return; | |
3191 | ||
3192 | /* reset doesn't touch the display */ | |
3193 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3194 | /* | |
3195 | * Flips in the rings have been nuked by the reset, | |
3196 | * so update the base address of all primary | |
3197 | * planes to the the last fb to make sure we're | |
3198 | * showing the correct fb after a reset. | |
3199 | */ | |
3200 | intel_update_primary_planes(dev); | |
3201 | return; | |
3202 | } | |
3203 | ||
3204 | /* | |
3205 | * The display has been reset as well, | |
3206 | * so need a full re-initialization. | |
3207 | */ | |
3208 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3209 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3210 | ||
3211 | intel_modeset_init_hw(dev); | |
3212 | ||
3213 | spin_lock_irq(&dev_priv->irq_lock); | |
3214 | if (dev_priv->display.hpd_irq_setup) | |
3215 | dev_priv->display.hpd_irq_setup(dev); | |
3216 | spin_unlock_irq(&dev_priv->irq_lock); | |
3217 | ||
043e9bda | 3218 | intel_display_resume(dev); |
7514747d VS |
3219 | |
3220 | intel_hpd_init(dev_priv); | |
3221 | ||
3222 | drm_modeset_unlock_all(dev); | |
3223 | } | |
3224 | ||
2e2f351d | 3225 | static void |
14667a4b CW |
3226 | intel_finish_fb(struct drm_framebuffer *old_fb) |
3227 | { | |
2ff8fde1 | 3228 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
2e2f351d | 3229 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
14667a4b CW |
3230 | bool was_interruptible = dev_priv->mm.interruptible; |
3231 | int ret; | |
3232 | ||
14667a4b CW |
3233 | /* Big Hammer, we also need to ensure that any pending |
3234 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
3235 | * current scanout is retired before unpinning the old | |
2e2f351d CW |
3236 | * framebuffer. Note that we rely on userspace rendering |
3237 | * into the buffer attached to the pipe they are waiting | |
3238 | * on. If not, userspace generates a GPU hang with IPEHR | |
3239 | * point to the MI_WAIT_FOR_EVENT. | |
14667a4b CW |
3240 | * |
3241 | * This should only fail upon a hung GPU, in which case we | |
3242 | * can safely continue. | |
3243 | */ | |
3244 | dev_priv->mm.interruptible = false; | |
2e2f351d | 3245 | ret = i915_gem_object_wait_rendering(obj, true); |
14667a4b CW |
3246 | dev_priv->mm.interruptible = was_interruptible; |
3247 | ||
2e2f351d | 3248 | WARN_ON(ret); |
14667a4b CW |
3249 | } |
3250 | ||
7d5e3799 CW |
3251 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3252 | { | |
3253 | struct drm_device *dev = crtc->dev; | |
3254 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3255 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3256 | bool pending; |
3257 | ||
3258 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3259 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3260 | return false; | |
3261 | ||
5e2d7afc | 3262 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3263 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3264 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3265 | |
3266 | return pending; | |
3267 | } | |
3268 | ||
e30e8f75 GP |
3269 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
3270 | { | |
3271 | struct drm_device *dev = crtc->base.dev; | |
3272 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3273 | const struct drm_display_mode *adjusted_mode; | |
3274 | ||
3275 | if (!i915.fastboot) | |
3276 | return; | |
3277 | ||
3278 | /* | |
3279 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3280 | * that in compute_mode_changes we check the native mode (not the pfit | |
3281 | * mode) to see if we can flip rather than do a full mode set. In the | |
3282 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3283 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3284 | * sized surface. | |
3285 | * | |
3286 | * To fix this properly, we need to hoist the checks up into | |
3287 | * compute_mode_changes (or above), check the actual pfit state and | |
3288 | * whether the platform allows pfit disable with pipe active, and only | |
3289 | * then update the pipesrc and pfit state, even on the flip path. | |
3290 | */ | |
3291 | ||
6e3c9717 | 3292 | adjusted_mode = &crtc->config->base.adjusted_mode; |
e30e8f75 GP |
3293 | |
3294 | I915_WRITE(PIPESRC(crtc->pipe), | |
3295 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | | |
3296 | (adjusted_mode->crtc_vdisplay - 1)); | |
6e3c9717 | 3297 | if (!crtc->config->pch_pfit.enabled && |
409ee761 ACO |
3298 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
3299 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { | |
e30e8f75 GP |
3300 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
3301 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); | |
3302 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); | |
3303 | } | |
6e3c9717 ACO |
3304 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
3305 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; | |
e30e8f75 GP |
3306 | } |
3307 | ||
5e84e1a4 ZW |
3308 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3309 | { | |
3310 | struct drm_device *dev = crtc->dev; | |
3311 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3312 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3313 | int pipe = intel_crtc->pipe; | |
3314 | u32 reg, temp; | |
3315 | ||
3316 | /* enable normal train */ | |
3317 | reg = FDI_TX_CTL(pipe); | |
3318 | temp = I915_READ(reg); | |
61e499bf | 3319 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3320 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3321 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3322 | } else { |
3323 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3324 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3325 | } |
5e84e1a4 ZW |
3326 | I915_WRITE(reg, temp); |
3327 | ||
3328 | reg = FDI_RX_CTL(pipe); | |
3329 | temp = I915_READ(reg); | |
3330 | if (HAS_PCH_CPT(dev)) { | |
3331 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3332 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3333 | } else { | |
3334 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3335 | temp |= FDI_LINK_TRAIN_NONE; | |
3336 | } | |
3337 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3338 | ||
3339 | /* wait one idle pattern time */ | |
3340 | POSTING_READ(reg); | |
3341 | udelay(1000); | |
357555c0 JB |
3342 | |
3343 | /* IVB wants error correction enabled */ | |
3344 | if (IS_IVYBRIDGE(dev)) | |
3345 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3346 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3347 | } |
3348 | ||
8db9d77b ZW |
3349 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3350 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3351 | { | |
3352 | struct drm_device *dev = crtc->dev; | |
3353 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3354 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3355 | int pipe = intel_crtc->pipe; | |
5eddb70b | 3356 | u32 reg, temp, tries; |
8db9d77b | 3357 | |
1c8562f6 | 3358 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3359 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3360 | |
e1a44743 AJ |
3361 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3362 | for train result */ | |
5eddb70b CW |
3363 | reg = FDI_RX_IMR(pipe); |
3364 | temp = I915_READ(reg); | |
e1a44743 AJ |
3365 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3366 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3367 | I915_WRITE(reg, temp); |
3368 | I915_READ(reg); | |
e1a44743 AJ |
3369 | udelay(150); |
3370 | ||
8db9d77b | 3371 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3372 | reg = FDI_TX_CTL(pipe); |
3373 | temp = I915_READ(reg); | |
627eb5a3 | 3374 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3375 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3376 | temp &= ~FDI_LINK_TRAIN_NONE; |
3377 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3378 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3379 | |
5eddb70b CW |
3380 | reg = FDI_RX_CTL(pipe); |
3381 | temp = I915_READ(reg); | |
8db9d77b ZW |
3382 | temp &= ~FDI_LINK_TRAIN_NONE; |
3383 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3384 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3385 | ||
3386 | POSTING_READ(reg); | |
8db9d77b ZW |
3387 | udelay(150); |
3388 | ||
5b2adf89 | 3389 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3390 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3391 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3392 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3393 | |
5eddb70b | 3394 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3395 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3396 | temp = I915_READ(reg); |
8db9d77b ZW |
3397 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3398 | ||
3399 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3400 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3401 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3402 | break; |
3403 | } | |
8db9d77b | 3404 | } |
e1a44743 | 3405 | if (tries == 5) |
5eddb70b | 3406 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3407 | |
3408 | /* Train 2 */ | |
5eddb70b CW |
3409 | reg = FDI_TX_CTL(pipe); |
3410 | temp = I915_READ(reg); | |
8db9d77b ZW |
3411 | temp &= ~FDI_LINK_TRAIN_NONE; |
3412 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3413 | I915_WRITE(reg, temp); |
8db9d77b | 3414 | |
5eddb70b CW |
3415 | reg = FDI_RX_CTL(pipe); |
3416 | temp = I915_READ(reg); | |
8db9d77b ZW |
3417 | temp &= ~FDI_LINK_TRAIN_NONE; |
3418 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3419 | I915_WRITE(reg, temp); |
8db9d77b | 3420 | |
5eddb70b CW |
3421 | POSTING_READ(reg); |
3422 | udelay(150); | |
8db9d77b | 3423 | |
5eddb70b | 3424 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3425 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3426 | temp = I915_READ(reg); |
8db9d77b ZW |
3427 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3428 | ||
3429 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3430 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3431 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3432 | break; | |
3433 | } | |
8db9d77b | 3434 | } |
e1a44743 | 3435 | if (tries == 5) |
5eddb70b | 3436 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3437 | |
3438 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3439 | |
8db9d77b ZW |
3440 | } |
3441 | ||
0206e353 | 3442 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3443 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3444 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3445 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3446 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3447 | }; | |
3448 | ||
3449 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3450 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3451 | { | |
3452 | struct drm_device *dev = crtc->dev; | |
3453 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3454 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3455 | int pipe = intel_crtc->pipe; | |
fa37d39e | 3456 | u32 reg, temp, i, retry; |
8db9d77b | 3457 | |
e1a44743 AJ |
3458 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3459 | for train result */ | |
5eddb70b CW |
3460 | reg = FDI_RX_IMR(pipe); |
3461 | temp = I915_READ(reg); | |
e1a44743 AJ |
3462 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3463 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3464 | I915_WRITE(reg, temp); |
3465 | ||
3466 | POSTING_READ(reg); | |
e1a44743 AJ |
3467 | udelay(150); |
3468 | ||
8db9d77b | 3469 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3470 | reg = FDI_TX_CTL(pipe); |
3471 | temp = I915_READ(reg); | |
627eb5a3 | 3472 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3473 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3474 | temp &= ~FDI_LINK_TRAIN_NONE; |
3475 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3476 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3477 | /* SNB-B */ | |
3478 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3479 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3480 | |
d74cf324 DV |
3481 | I915_WRITE(FDI_RX_MISC(pipe), |
3482 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3483 | ||
5eddb70b CW |
3484 | reg = FDI_RX_CTL(pipe); |
3485 | temp = I915_READ(reg); | |
8db9d77b ZW |
3486 | if (HAS_PCH_CPT(dev)) { |
3487 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3488 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3489 | } else { | |
3490 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3491 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3492 | } | |
5eddb70b CW |
3493 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3494 | ||
3495 | POSTING_READ(reg); | |
8db9d77b ZW |
3496 | udelay(150); |
3497 | ||
0206e353 | 3498 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3499 | reg = FDI_TX_CTL(pipe); |
3500 | temp = I915_READ(reg); | |
8db9d77b ZW |
3501 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3502 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3503 | I915_WRITE(reg, temp); |
3504 | ||
3505 | POSTING_READ(reg); | |
8db9d77b ZW |
3506 | udelay(500); |
3507 | ||
fa37d39e SP |
3508 | for (retry = 0; retry < 5; retry++) { |
3509 | reg = FDI_RX_IIR(pipe); | |
3510 | temp = I915_READ(reg); | |
3511 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3512 | if (temp & FDI_RX_BIT_LOCK) { | |
3513 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3514 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3515 | break; | |
3516 | } | |
3517 | udelay(50); | |
8db9d77b | 3518 | } |
fa37d39e SP |
3519 | if (retry < 5) |
3520 | break; | |
8db9d77b ZW |
3521 | } |
3522 | if (i == 4) | |
5eddb70b | 3523 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3524 | |
3525 | /* Train 2 */ | |
5eddb70b CW |
3526 | reg = FDI_TX_CTL(pipe); |
3527 | temp = I915_READ(reg); | |
8db9d77b ZW |
3528 | temp &= ~FDI_LINK_TRAIN_NONE; |
3529 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3530 | if (IS_GEN6(dev)) { | |
3531 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3532 | /* SNB-B */ | |
3533 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3534 | } | |
5eddb70b | 3535 | I915_WRITE(reg, temp); |
8db9d77b | 3536 | |
5eddb70b CW |
3537 | reg = FDI_RX_CTL(pipe); |
3538 | temp = I915_READ(reg); | |
8db9d77b ZW |
3539 | if (HAS_PCH_CPT(dev)) { |
3540 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3541 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3542 | } else { | |
3543 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3544 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3545 | } | |
5eddb70b CW |
3546 | I915_WRITE(reg, temp); |
3547 | ||
3548 | POSTING_READ(reg); | |
8db9d77b ZW |
3549 | udelay(150); |
3550 | ||
0206e353 | 3551 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3552 | reg = FDI_TX_CTL(pipe); |
3553 | temp = I915_READ(reg); | |
8db9d77b ZW |
3554 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3555 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3556 | I915_WRITE(reg, temp); |
3557 | ||
3558 | POSTING_READ(reg); | |
8db9d77b ZW |
3559 | udelay(500); |
3560 | ||
fa37d39e SP |
3561 | for (retry = 0; retry < 5; retry++) { |
3562 | reg = FDI_RX_IIR(pipe); | |
3563 | temp = I915_READ(reg); | |
3564 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3565 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3566 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3567 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3568 | break; | |
3569 | } | |
3570 | udelay(50); | |
8db9d77b | 3571 | } |
fa37d39e SP |
3572 | if (retry < 5) |
3573 | break; | |
8db9d77b ZW |
3574 | } |
3575 | if (i == 4) | |
5eddb70b | 3576 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3577 | |
3578 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3579 | } | |
3580 | ||
357555c0 JB |
3581 | /* Manual link training for Ivy Bridge A0 parts */ |
3582 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3583 | { | |
3584 | struct drm_device *dev = crtc->dev; | |
3585 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3586 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3587 | int pipe = intel_crtc->pipe; | |
139ccd3f | 3588 | u32 reg, temp, i, j; |
357555c0 JB |
3589 | |
3590 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3591 | for train result */ | |
3592 | reg = FDI_RX_IMR(pipe); | |
3593 | temp = I915_READ(reg); | |
3594 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3595 | temp &= ~FDI_RX_BIT_LOCK; | |
3596 | I915_WRITE(reg, temp); | |
3597 | ||
3598 | POSTING_READ(reg); | |
3599 | udelay(150); | |
3600 | ||
01a415fd DV |
3601 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3602 | I915_READ(FDI_RX_IIR(pipe))); | |
3603 | ||
139ccd3f JB |
3604 | /* Try each vswing and preemphasis setting twice before moving on */ |
3605 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3606 | /* disable first in case we need to retry */ | |
3607 | reg = FDI_TX_CTL(pipe); | |
3608 | temp = I915_READ(reg); | |
3609 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3610 | temp &= ~FDI_TX_ENABLE; | |
3611 | I915_WRITE(reg, temp); | |
357555c0 | 3612 | |
139ccd3f JB |
3613 | reg = FDI_RX_CTL(pipe); |
3614 | temp = I915_READ(reg); | |
3615 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3616 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3617 | temp &= ~FDI_RX_ENABLE; | |
3618 | I915_WRITE(reg, temp); | |
357555c0 | 3619 | |
139ccd3f | 3620 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3621 | reg = FDI_TX_CTL(pipe); |
3622 | temp = I915_READ(reg); | |
139ccd3f | 3623 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3624 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3625 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3626 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3627 | temp |= snb_b_fdi_train_param[j/2]; |
3628 | temp |= FDI_COMPOSITE_SYNC; | |
3629 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3630 | |
139ccd3f JB |
3631 | I915_WRITE(FDI_RX_MISC(pipe), |
3632 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3633 | |
139ccd3f | 3634 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3635 | temp = I915_READ(reg); |
139ccd3f JB |
3636 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3637 | temp |= FDI_COMPOSITE_SYNC; | |
3638 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3639 | |
139ccd3f JB |
3640 | POSTING_READ(reg); |
3641 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3642 | |
139ccd3f JB |
3643 | for (i = 0; i < 4; i++) { |
3644 | reg = FDI_RX_IIR(pipe); | |
3645 | temp = I915_READ(reg); | |
3646 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3647 | |
139ccd3f JB |
3648 | if (temp & FDI_RX_BIT_LOCK || |
3649 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3650 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3651 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3652 | i); | |
3653 | break; | |
3654 | } | |
3655 | udelay(1); /* should be 0.5us */ | |
3656 | } | |
3657 | if (i == 4) { | |
3658 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3659 | continue; | |
3660 | } | |
357555c0 | 3661 | |
139ccd3f | 3662 | /* Train 2 */ |
357555c0 JB |
3663 | reg = FDI_TX_CTL(pipe); |
3664 | temp = I915_READ(reg); | |
139ccd3f JB |
3665 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3666 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3667 | I915_WRITE(reg, temp); | |
3668 | ||
3669 | reg = FDI_RX_CTL(pipe); | |
3670 | temp = I915_READ(reg); | |
3671 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3672 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3673 | I915_WRITE(reg, temp); |
3674 | ||
3675 | POSTING_READ(reg); | |
139ccd3f | 3676 | udelay(2); /* should be 1.5us */ |
357555c0 | 3677 | |
139ccd3f JB |
3678 | for (i = 0; i < 4; i++) { |
3679 | reg = FDI_RX_IIR(pipe); | |
3680 | temp = I915_READ(reg); | |
3681 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3682 | |
139ccd3f JB |
3683 | if (temp & FDI_RX_SYMBOL_LOCK || |
3684 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3685 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3686 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3687 | i); | |
3688 | goto train_done; | |
3689 | } | |
3690 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3691 | } |
139ccd3f JB |
3692 | if (i == 4) |
3693 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3694 | } |
357555c0 | 3695 | |
139ccd3f | 3696 | train_done: |
357555c0 JB |
3697 | DRM_DEBUG_KMS("FDI train done.\n"); |
3698 | } | |
3699 | ||
88cefb6c | 3700 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3701 | { |
88cefb6c | 3702 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3703 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3704 | int pipe = intel_crtc->pipe; |
5eddb70b | 3705 | u32 reg, temp; |
79e53945 | 3706 | |
c64e311e | 3707 | |
c98e9dcf | 3708 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3709 | reg = FDI_RX_CTL(pipe); |
3710 | temp = I915_READ(reg); | |
627eb5a3 | 3711 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3712 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3713 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3714 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3715 | ||
3716 | POSTING_READ(reg); | |
c98e9dcf JB |
3717 | udelay(200); |
3718 | ||
3719 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3720 | temp = I915_READ(reg); |
3721 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3722 | ||
3723 | POSTING_READ(reg); | |
c98e9dcf JB |
3724 | udelay(200); |
3725 | ||
20749730 PZ |
3726 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3727 | reg = FDI_TX_CTL(pipe); | |
3728 | temp = I915_READ(reg); | |
3729 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3730 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3731 | |
20749730 PZ |
3732 | POSTING_READ(reg); |
3733 | udelay(100); | |
6be4a607 | 3734 | } |
0e23b99d JB |
3735 | } |
3736 | ||
88cefb6c DV |
3737 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3738 | { | |
3739 | struct drm_device *dev = intel_crtc->base.dev; | |
3740 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3741 | int pipe = intel_crtc->pipe; | |
3742 | u32 reg, temp; | |
3743 | ||
3744 | /* Switch from PCDclk to Rawclk */ | |
3745 | reg = FDI_RX_CTL(pipe); | |
3746 | temp = I915_READ(reg); | |
3747 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3748 | ||
3749 | /* Disable CPU FDI TX PLL */ | |
3750 | reg = FDI_TX_CTL(pipe); | |
3751 | temp = I915_READ(reg); | |
3752 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3753 | ||
3754 | POSTING_READ(reg); | |
3755 | udelay(100); | |
3756 | ||
3757 | reg = FDI_RX_CTL(pipe); | |
3758 | temp = I915_READ(reg); | |
3759 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3760 | ||
3761 | /* Wait for the clocks to turn off. */ | |
3762 | POSTING_READ(reg); | |
3763 | udelay(100); | |
3764 | } | |
3765 | ||
0fc932b8 JB |
3766 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3767 | { | |
3768 | struct drm_device *dev = crtc->dev; | |
3769 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3770 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3771 | int pipe = intel_crtc->pipe; | |
3772 | u32 reg, temp; | |
3773 | ||
3774 | /* disable CPU FDI tx and PCH FDI rx */ | |
3775 | reg = FDI_TX_CTL(pipe); | |
3776 | temp = I915_READ(reg); | |
3777 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3778 | POSTING_READ(reg); | |
3779 | ||
3780 | reg = FDI_RX_CTL(pipe); | |
3781 | temp = I915_READ(reg); | |
3782 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3783 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3784 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3785 | ||
3786 | POSTING_READ(reg); | |
3787 | udelay(100); | |
3788 | ||
3789 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3790 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3791 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3792 | |
3793 | /* still set train pattern 1 */ | |
3794 | reg = FDI_TX_CTL(pipe); | |
3795 | temp = I915_READ(reg); | |
3796 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3797 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3798 | I915_WRITE(reg, temp); | |
3799 | ||
3800 | reg = FDI_RX_CTL(pipe); | |
3801 | temp = I915_READ(reg); | |
3802 | if (HAS_PCH_CPT(dev)) { | |
3803 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3804 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3805 | } else { | |
3806 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3807 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3808 | } | |
3809 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3810 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3811 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3812 | I915_WRITE(reg, temp); |
3813 | ||
3814 | POSTING_READ(reg); | |
3815 | udelay(100); | |
3816 | } | |
3817 | ||
5dce5b93 CW |
3818 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3819 | { | |
3820 | struct intel_crtc *crtc; | |
3821 | ||
3822 | /* Note that we don't need to be called with mode_config.lock here | |
3823 | * as our list of CRTC objects is static for the lifetime of the | |
3824 | * device and so cannot disappear as we iterate. Similarly, we can | |
3825 | * happily treat the predicates as racy, atomic checks as userspace | |
3826 | * cannot claim and pin a new fb without at least acquring the | |
3827 | * struct_mutex and so serialising with us. | |
3828 | */ | |
d3fcc808 | 3829 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3830 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3831 | continue; | |
3832 | ||
3833 | if (crtc->unpin_work) | |
3834 | intel_wait_for_vblank(dev, crtc->pipe); | |
3835 | ||
3836 | return true; | |
3837 | } | |
3838 | ||
3839 | return false; | |
3840 | } | |
3841 | ||
d6bbafa1 CW |
3842 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3843 | { | |
3844 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3845 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3846 | ||
3847 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3848 | smp_rmb(); | |
3849 | intel_crtc->unpin_work = NULL; | |
3850 | ||
3851 | if (work->event) | |
3852 | drm_send_vblank_event(intel_crtc->base.dev, | |
3853 | intel_crtc->pipe, | |
3854 | work->event); | |
3855 | ||
3856 | drm_crtc_vblank_put(&intel_crtc->base); | |
3857 | ||
3858 | wake_up_all(&dev_priv->pending_flip_queue); | |
3859 | queue_work(dev_priv->wq, &work->work); | |
3860 | ||
3861 | trace_i915_flip_complete(intel_crtc->plane, | |
3862 | work->pending_flip_obj); | |
3863 | } | |
3864 | ||
46a55d30 | 3865 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3866 | { |
0f91128d | 3867 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3868 | struct drm_i915_private *dev_priv = dev->dev_private; |
e6c3a2a6 | 3869 | |
2c10d571 | 3870 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
9c787942 CW |
3871 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
3872 | !intel_crtc_has_pending_flip(crtc), | |
3873 | 60*HZ) == 0)) { | |
3874 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2c10d571 | 3875 | |
5e2d7afc | 3876 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3877 | if (intel_crtc->unpin_work) { |
3878 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3879 | page_flip_completed(intel_crtc); | |
3880 | } | |
5e2d7afc | 3881 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3882 | } |
5bb61643 | 3883 | |
975d568a CW |
3884 | if (crtc->primary->fb) { |
3885 | mutex_lock(&dev->struct_mutex); | |
3886 | intel_finish_fb(crtc->primary->fb); | |
3887 | mutex_unlock(&dev->struct_mutex); | |
3888 | } | |
e6c3a2a6 CW |
3889 | } |
3890 | ||
e615efe4 ED |
3891 | /* Program iCLKIP clock to the desired frequency */ |
3892 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3893 | { | |
3894 | struct drm_device *dev = crtc->dev; | |
3895 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3896 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3897 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3898 | u32 temp; | |
3899 | ||
a580516d | 3900 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 3901 | |
e615efe4 ED |
3902 | /* It is necessary to ungate the pixclk gate prior to programming |
3903 | * the divisors, and gate it back when it is done. | |
3904 | */ | |
3905 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3906 | ||
3907 | /* Disable SSCCTL */ | |
3908 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3909 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3910 | SBI_SSCCTL_DISABLE, | |
3911 | SBI_ICLK); | |
e615efe4 ED |
3912 | |
3913 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3914 | if (clock == 20000) { |
e615efe4 ED |
3915 | auxdiv = 1; |
3916 | divsel = 0x41; | |
3917 | phaseinc = 0x20; | |
3918 | } else { | |
3919 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3920 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3921 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3922 | * convert the virtual clock precision to KHz here for higher |
3923 | * precision. | |
3924 | */ | |
3925 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3926 | u32 iclk_pi_range = 64; | |
3927 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3928 | ||
12d7ceed | 3929 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3930 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3931 | pi_value = desired_divisor % iclk_pi_range; | |
3932 | ||
3933 | auxdiv = 0; | |
3934 | divsel = msb_divisor_value - 2; | |
3935 | phaseinc = pi_value; | |
3936 | } | |
3937 | ||
3938 | /* This should not happen with any sane values */ | |
3939 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3940 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3941 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3942 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3943 | ||
3944 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3945 | clock, |
e615efe4 ED |
3946 | auxdiv, |
3947 | divsel, | |
3948 | phasedir, | |
3949 | phaseinc); | |
3950 | ||
3951 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 3952 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
3953 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
3954 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
3955 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
3956 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
3957 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
3958 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 3959 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
3960 | |
3961 | /* Program SSCAUXDIV */ | |
988d6ee8 | 3962 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
3963 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
3964 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 3965 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
3966 | |
3967 | /* Enable modulator and associated divider */ | |
988d6ee8 | 3968 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 3969 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 3970 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
3971 | |
3972 | /* Wait for initialization time */ | |
3973 | udelay(24); | |
3974 | ||
3975 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 | 3976 | |
a580516d | 3977 | mutex_unlock(&dev_priv->sb_lock); |
e615efe4 ED |
3978 | } |
3979 | ||
275f01b2 DV |
3980 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
3981 | enum pipe pch_transcoder) | |
3982 | { | |
3983 | struct drm_device *dev = crtc->base.dev; | |
3984 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3985 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
3986 | |
3987 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
3988 | I915_READ(HTOTAL(cpu_transcoder))); | |
3989 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
3990 | I915_READ(HBLANK(cpu_transcoder))); | |
3991 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
3992 | I915_READ(HSYNC(cpu_transcoder))); | |
3993 | ||
3994 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
3995 | I915_READ(VTOTAL(cpu_transcoder))); | |
3996 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
3997 | I915_READ(VBLANK(cpu_transcoder))); | |
3998 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
3999 | I915_READ(VSYNC(cpu_transcoder))); | |
4000 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4001 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4002 | } | |
4003 | ||
003632d9 | 4004 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4005 | { |
4006 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4007 | uint32_t temp; | |
4008 | ||
4009 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4010 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4011 | return; |
4012 | ||
4013 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4014 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4015 | ||
003632d9 ACO |
4016 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4017 | if (enable) | |
4018 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4019 | ||
4020 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4021 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4022 | POSTING_READ(SOUTH_CHICKEN1); | |
4023 | } | |
4024 | ||
4025 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4026 | { | |
4027 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4028 | |
4029 | switch (intel_crtc->pipe) { | |
4030 | case PIPE_A: | |
4031 | break; | |
4032 | case PIPE_B: | |
6e3c9717 | 4033 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4034 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4035 | else |
003632d9 | 4036 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4037 | |
4038 | break; | |
4039 | case PIPE_C: | |
003632d9 | 4040 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4041 | |
4042 | break; | |
4043 | default: | |
4044 | BUG(); | |
4045 | } | |
4046 | } | |
4047 | ||
f67a559d JB |
4048 | /* |
4049 | * Enable PCH resources required for PCH ports: | |
4050 | * - PCH PLLs | |
4051 | * - FDI training & RX/TX | |
4052 | * - update transcoder timings | |
4053 | * - DP transcoding bits | |
4054 | * - transcoder | |
4055 | */ | |
4056 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4057 | { |
4058 | struct drm_device *dev = crtc->dev; | |
4059 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4060 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4061 | int pipe = intel_crtc->pipe; | |
ee7b9f93 | 4062 | u32 reg, temp; |
2c07245f | 4063 | |
ab9412ba | 4064 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4065 | |
1fbc0d78 DV |
4066 | if (IS_IVYBRIDGE(dev)) |
4067 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4068 | ||
cd986abb DV |
4069 | /* Write the TU size bits before fdi link training, so that error |
4070 | * detection works. */ | |
4071 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4072 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4073 | ||
c98e9dcf | 4074 | /* For PCH output, training FDI link */ |
674cf967 | 4075 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4076 | |
3ad8a208 DV |
4077 | /* We need to program the right clock selection before writing the pixel |
4078 | * mutliplier into the DPLL. */ | |
303b81e0 | 4079 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4080 | u32 sel; |
4b645f14 | 4081 | |
c98e9dcf | 4082 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4083 | temp |= TRANS_DPLL_ENABLE(pipe); |
4084 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4085 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4086 | temp |= sel; |
4087 | else | |
4088 | temp &= ~sel; | |
c98e9dcf | 4089 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4090 | } |
5eddb70b | 4091 | |
3ad8a208 DV |
4092 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4093 | * transcoder, and we actually should do this to not upset any PCH | |
4094 | * transcoder that already use the clock when we share it. | |
4095 | * | |
4096 | * Note that enable_shared_dpll tries to do the right thing, but | |
4097 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4098 | * the right LVDS enable sequence. */ | |
85b3894f | 4099 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4100 | |
d9b6cb56 JB |
4101 | /* set transcoder timing, panel must allow it */ |
4102 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4103 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4104 | |
303b81e0 | 4105 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4106 | |
c98e9dcf | 4107 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4108 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
dfd07d72 | 4109 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
5eddb70b CW |
4110 | reg = TRANS_DP_CTL(pipe); |
4111 | temp = I915_READ(reg); | |
4112 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4113 | TRANS_DP_SYNC_MASK | |
4114 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4115 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4116 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf JB |
4117 | |
4118 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) | |
5eddb70b | 4119 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
c98e9dcf | 4120 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4121 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4122 | |
4123 | switch (intel_trans_dp_port_sel(crtc)) { | |
4124 | case PCH_DP_B: | |
5eddb70b | 4125 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf JB |
4126 | break; |
4127 | case PCH_DP_C: | |
5eddb70b | 4128 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf JB |
4129 | break; |
4130 | case PCH_DP_D: | |
5eddb70b | 4131 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4132 | break; |
4133 | default: | |
e95d41e1 | 4134 | BUG(); |
32f9d658 | 4135 | } |
2c07245f | 4136 | |
5eddb70b | 4137 | I915_WRITE(reg, temp); |
6be4a607 | 4138 | } |
b52eb4dc | 4139 | |
b8a4f404 | 4140 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4141 | } |
4142 | ||
1507e5bd PZ |
4143 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4144 | { | |
4145 | struct drm_device *dev = crtc->dev; | |
4146 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4147 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4148 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4149 | |
ab9412ba | 4150 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4151 | |
8c52b5e8 | 4152 | lpt_program_iclkip(crtc); |
1507e5bd | 4153 | |
0540e488 | 4154 | /* Set transcoder timing. */ |
275f01b2 | 4155 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4156 | |
937bb610 | 4157 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4158 | } |
4159 | ||
190f68c5 ACO |
4160 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4161 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4162 | { |
e2b78267 | 4163 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4164 | struct intel_shared_dpll *pll; |
de419ab6 | 4165 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4166 | enum intel_dpll_id i; |
ee7b9f93 | 4167 | |
de419ab6 ML |
4168 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4169 | ||
98b6bd99 DV |
4170 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4171 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4172 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4173 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4174 | |
46edb027 DV |
4175 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4176 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4177 | |
de419ab6 | 4178 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4179 | |
98b6bd99 DV |
4180 | goto found; |
4181 | } | |
4182 | ||
bcddf610 S |
4183 | if (IS_BROXTON(dev_priv->dev)) { |
4184 | /* PLL is attached to port in bxt */ | |
4185 | struct intel_encoder *encoder; | |
4186 | struct intel_digital_port *intel_dig_port; | |
4187 | ||
4188 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4189 | if (WARN_ON(!encoder)) | |
4190 | return NULL; | |
4191 | ||
4192 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4193 | /* 1:1 mapping between ports and PLLs */ | |
4194 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4195 | pll = &dev_priv->shared_dplls[i]; | |
4196 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4197 | crtc->base.base.id, pll->name); | |
de419ab6 | 4198 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4199 | |
4200 | goto found; | |
4201 | } | |
4202 | ||
e72f9fbf DV |
4203 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4204 | pll = &dev_priv->shared_dplls[i]; | |
ee7b9f93 JB |
4205 | |
4206 | /* Only want to check enabled timings first */ | |
de419ab6 | 4207 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4208 | continue; |
4209 | ||
190f68c5 | 4210 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4211 | &shared_dpll[i].hw_state, |
4212 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4213 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4214 | crtc->base.base.id, pll->name, |
de419ab6 | 4215 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4216 | pll->active); |
ee7b9f93 JB |
4217 | goto found; |
4218 | } | |
4219 | } | |
4220 | ||
4221 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4222 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4223 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4224 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4225 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4226 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4227 | goto found; |
4228 | } | |
4229 | } | |
4230 | ||
4231 | return NULL; | |
4232 | ||
4233 | found: | |
de419ab6 ML |
4234 | if (shared_dpll[i].crtc_mask == 0) |
4235 | shared_dpll[i].hw_state = | |
4236 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4237 | |
190f68c5 | 4238 | crtc_state->shared_dpll = i; |
46edb027 DV |
4239 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4240 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4241 | |
de419ab6 | 4242 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4243 | |
ee7b9f93 JB |
4244 | return pll; |
4245 | } | |
4246 | ||
de419ab6 | 4247 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4248 | { |
de419ab6 ML |
4249 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4250 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4251 | struct intel_shared_dpll *pll; |
4252 | enum intel_dpll_id i; | |
4253 | ||
de419ab6 ML |
4254 | if (!to_intel_atomic_state(state)->dpll_set) |
4255 | return; | |
8bd31e67 | 4256 | |
de419ab6 | 4257 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4258 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4259 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4260 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4261 | } |
4262 | } | |
4263 | ||
a1520318 | 4264 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4265 | { |
4266 | struct drm_i915_private *dev_priv = dev->dev_private; | |
23670b32 | 4267 | int dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4268 | u32 temp; |
4269 | ||
4270 | temp = I915_READ(dslreg); | |
4271 | udelay(500); | |
4272 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4273 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4274 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4275 | } |
4276 | } | |
4277 | ||
86adf9d7 ML |
4278 | static int |
4279 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4280 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4281 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4282 | { |
86adf9d7 ML |
4283 | struct intel_crtc_scaler_state *scaler_state = |
4284 | &crtc_state->scaler_state; | |
4285 | struct intel_crtc *intel_crtc = | |
4286 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4287 | int need_scaling; |
6156a456 CK |
4288 | |
4289 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4290 | (src_h != dst_w || src_w != dst_h): | |
4291 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4292 | |
4293 | /* | |
4294 | * if plane is being disabled or scaler is no more required or force detach | |
4295 | * - free scaler binded to this plane/crtc | |
4296 | * - in order to do this, update crtc->scaler_usage | |
4297 | * | |
4298 | * Here scaler state in crtc_state is set free so that | |
4299 | * scaler can be assigned to other user. Actual register | |
4300 | * update to free the scaler is done in plane/panel-fit programming. | |
4301 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4302 | */ | |
86adf9d7 | 4303 | if (force_detach || !need_scaling) { |
a1b2278e | 4304 | if (*scaler_id >= 0) { |
86adf9d7 | 4305 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4306 | scaler_state->scalers[*scaler_id].in_use = 0; |
4307 | ||
86adf9d7 ML |
4308 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4309 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4310 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4311 | scaler_state->scaler_users); |
4312 | *scaler_id = -1; | |
4313 | } | |
4314 | return 0; | |
4315 | } | |
4316 | ||
4317 | /* range checks */ | |
4318 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4319 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4320 | ||
4321 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4322 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4323 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4324 | "size is out of scaler range\n", |
86adf9d7 | 4325 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4326 | return -EINVAL; |
4327 | } | |
4328 | ||
86adf9d7 ML |
4329 | /* mark this plane as a scaler user in crtc_state */ |
4330 | scaler_state->scaler_users |= (1 << scaler_user); | |
4331 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4332 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4333 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4334 | scaler_state->scaler_users); | |
4335 | ||
4336 | return 0; | |
4337 | } | |
4338 | ||
4339 | /** | |
4340 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4341 | * | |
4342 | * @state: crtc's scaler state | |
86adf9d7 ML |
4343 | * |
4344 | * Return | |
4345 | * 0 - scaler_usage updated successfully | |
4346 | * error - requested scaling cannot be supported or other error condition | |
4347 | */ | |
e435d6e5 | 4348 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 ML |
4349 | { |
4350 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
4351 | struct drm_display_mode *adjusted_mode = | |
4352 | &state->base.adjusted_mode; | |
4353 | ||
4354 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4355 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4356 | ||
e435d6e5 | 4357 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
86adf9d7 ML |
4358 | &state->scaler_state.scaler_id, DRM_ROTATE_0, |
4359 | state->pipe_src_w, state->pipe_src_h, | |
8c6cda29 | 4360 | adjusted_mode->hdisplay, adjusted_mode->vdisplay); |
86adf9d7 ML |
4361 | } |
4362 | ||
4363 | /** | |
4364 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4365 | * | |
4366 | * @state: crtc's scaler state | |
86adf9d7 ML |
4367 | * @plane_state: atomic plane state to update |
4368 | * | |
4369 | * Return | |
4370 | * 0 - scaler_usage updated successfully | |
4371 | * error - requested scaling cannot be supported or other error condition | |
4372 | */ | |
da20eabd ML |
4373 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4374 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4375 | { |
4376 | ||
4377 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4378 | struct intel_plane *intel_plane = |
4379 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4380 | struct drm_framebuffer *fb = plane_state->base.fb; |
4381 | int ret; | |
4382 | ||
4383 | bool force_detach = !fb || !plane_state->visible; | |
4384 | ||
4385 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4386 | intel_plane->base.base.id, intel_crtc->pipe, | |
4387 | drm_plane_index(&intel_plane->base)); | |
4388 | ||
4389 | ret = skl_update_scaler(crtc_state, force_detach, | |
4390 | drm_plane_index(&intel_plane->base), | |
4391 | &plane_state->scaler_id, | |
4392 | plane_state->base.rotation, | |
4393 | drm_rect_width(&plane_state->src) >> 16, | |
4394 | drm_rect_height(&plane_state->src) >> 16, | |
4395 | drm_rect_width(&plane_state->dst), | |
4396 | drm_rect_height(&plane_state->dst)); | |
4397 | ||
4398 | if (ret || plane_state->scaler_id < 0) | |
4399 | return ret; | |
4400 | ||
a1b2278e | 4401 | /* check colorkey */ |
818ed961 | 4402 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
86adf9d7 | 4403 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
818ed961 | 4404 | intel_plane->base.base.id); |
a1b2278e CK |
4405 | return -EINVAL; |
4406 | } | |
4407 | ||
4408 | /* Check src format */ | |
86adf9d7 ML |
4409 | switch (fb->pixel_format) { |
4410 | case DRM_FORMAT_RGB565: | |
4411 | case DRM_FORMAT_XBGR8888: | |
4412 | case DRM_FORMAT_XRGB8888: | |
4413 | case DRM_FORMAT_ABGR8888: | |
4414 | case DRM_FORMAT_ARGB8888: | |
4415 | case DRM_FORMAT_XRGB2101010: | |
4416 | case DRM_FORMAT_XBGR2101010: | |
4417 | case DRM_FORMAT_YUYV: | |
4418 | case DRM_FORMAT_YVYU: | |
4419 | case DRM_FORMAT_UYVY: | |
4420 | case DRM_FORMAT_VYUY: | |
4421 | break; | |
4422 | default: | |
4423 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4424 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4425 | return -EINVAL; | |
a1b2278e CK |
4426 | } |
4427 | ||
a1b2278e CK |
4428 | return 0; |
4429 | } | |
4430 | ||
e435d6e5 ML |
4431 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4432 | { | |
4433 | int i; | |
4434 | ||
4435 | for (i = 0; i < crtc->num_scalers; i++) | |
4436 | skl_detach_scaler(crtc, i); | |
4437 | } | |
4438 | ||
4439 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4440 | { |
4441 | struct drm_device *dev = crtc->base.dev; | |
4442 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4443 | int pipe = crtc->pipe; | |
a1b2278e CK |
4444 | struct intel_crtc_scaler_state *scaler_state = |
4445 | &crtc->config->scaler_state; | |
4446 | ||
4447 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4448 | ||
6e3c9717 | 4449 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4450 | int id; |
4451 | ||
4452 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4453 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4454 | return; | |
4455 | } | |
4456 | ||
4457 | id = scaler_state->scaler_id; | |
4458 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4459 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4460 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4461 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4462 | ||
4463 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4464 | } |
4465 | } | |
4466 | ||
b074cec8 JB |
4467 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4468 | { | |
4469 | struct drm_device *dev = crtc->base.dev; | |
4470 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4471 | int pipe = crtc->pipe; | |
4472 | ||
6e3c9717 | 4473 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4474 | /* Force use of hard-coded filter coefficients |
4475 | * as some pre-programmed values are broken, | |
4476 | * e.g. x201. | |
4477 | */ | |
4478 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4479 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4480 | PF_PIPE_SEL_IVB(pipe)); | |
4481 | else | |
4482 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4483 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4484 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4485 | } |
4486 | } | |
4487 | ||
20bc8673 | 4488 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4489 | { |
cea165c3 VS |
4490 | struct drm_device *dev = crtc->base.dev; |
4491 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4492 | |
6e3c9717 | 4493 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4494 | return; |
4495 | ||
cea165c3 VS |
4496 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4497 | intel_wait_for_vblank(dev, crtc->pipe); | |
4498 | ||
d77e4531 | 4499 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4500 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4501 | mutex_lock(&dev_priv->rps.hw_lock); |
4502 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4503 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4504 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4505 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4506 | * mailbox." Moreover, the mailbox may return a bogus state, |
4507 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4508 | */ |
4509 | } else { | |
4510 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4511 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4512 | * is essentially intel_wait_for_vblank. If we don't have this | |
4513 | * and don't wait for vblanks until the end of crtc_enable, then | |
4514 | * the HW state readout code will complain that the expected | |
4515 | * IPS_CTL value is not the one we read. */ | |
4516 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4517 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4518 | } | |
d77e4531 PZ |
4519 | } |
4520 | ||
20bc8673 | 4521 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4522 | { |
4523 | struct drm_device *dev = crtc->base.dev; | |
4524 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4525 | ||
6e3c9717 | 4526 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4527 | return; |
4528 | ||
4529 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4530 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4531 | mutex_lock(&dev_priv->rps.hw_lock); |
4532 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4533 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4534 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4535 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4536 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4537 | } else { |
2a114cc1 | 4538 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4539 | POSTING_READ(IPS_CTL); |
4540 | } | |
d77e4531 PZ |
4541 | |
4542 | /* We need to wait for a vblank before we can disable the plane. */ | |
4543 | intel_wait_for_vblank(dev, crtc->pipe); | |
4544 | } | |
4545 | ||
4546 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4547 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4548 | { | |
4549 | struct drm_device *dev = crtc->dev; | |
4550 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4551 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4552 | enum pipe pipe = intel_crtc->pipe; | |
4553 | int palreg = PALETTE(pipe); | |
4554 | int i; | |
4555 | bool reenable_ips = false; | |
4556 | ||
4557 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4558 | if (!crtc->state->active) |
d77e4531 PZ |
4559 | return; |
4560 | ||
50360403 | 4561 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
409ee761 | 4562 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
d77e4531 PZ |
4563 | assert_dsi_pll_enabled(dev_priv); |
4564 | else | |
4565 | assert_pll_enabled(dev_priv, pipe); | |
4566 | } | |
4567 | ||
4568 | /* use legacy palette for Ironlake */ | |
7a1db49a | 4569 | if (!HAS_GMCH_DISPLAY(dev)) |
d77e4531 PZ |
4570 | palreg = LGC_PALETTE(pipe); |
4571 | ||
4572 | /* Workaround : Do not read or write the pipe palette/gamma data while | |
4573 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4574 | */ | |
6e3c9717 | 4575 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4576 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4577 | GAMMA_MODE_MODE_SPLIT)) { | |
4578 | hsw_disable_ips(intel_crtc); | |
4579 | reenable_ips = true; | |
4580 | } | |
4581 | ||
4582 | for (i = 0; i < 256; i++) { | |
4583 | I915_WRITE(palreg + 4 * i, | |
4584 | (intel_crtc->lut_r[i] << 16) | | |
4585 | (intel_crtc->lut_g[i] << 8) | | |
4586 | intel_crtc->lut_b[i]); | |
4587 | } | |
4588 | ||
4589 | if (reenable_ips) | |
4590 | hsw_enable_ips(intel_crtc); | |
4591 | } | |
4592 | ||
7cac945f | 4593 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4594 | { |
7cac945f | 4595 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4596 | struct drm_device *dev = intel_crtc->base.dev; |
4597 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4598 | ||
4599 | mutex_lock(&dev->struct_mutex); | |
4600 | dev_priv->mm.interruptible = false; | |
4601 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4602 | dev_priv->mm.interruptible = true; | |
4603 | mutex_unlock(&dev->struct_mutex); | |
4604 | } | |
4605 | ||
4606 | /* Let userspace switch the overlay on again. In most cases userspace | |
4607 | * has to recompute where to put it anyway. | |
4608 | */ | |
4609 | } | |
4610 | ||
87d4300a ML |
4611 | /** |
4612 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4613 | * @crtc: the CRTC whose primary plane was just enabled | |
4614 | * | |
4615 | * Performs potentially sleeping operations that must be done after the primary | |
4616 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4617 | * called due to an explicit primary plane update, or due to an implicit | |
4618 | * re-enable that is caused when a sprite plane is updated to no longer | |
4619 | * completely hide the primary plane. | |
4620 | */ | |
4621 | static void | |
4622 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4623 | { |
4624 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4625 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4626 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4627 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4628 | |
87d4300a ML |
4629 | /* |
4630 | * BDW signals flip done immediately if the plane | |
4631 | * is disabled, even if the plane enable is already | |
4632 | * armed to occur at the next vblank :( | |
4633 | */ | |
4634 | if (IS_BROADWELL(dev)) | |
4635 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4636 | |
87d4300a ML |
4637 | /* |
4638 | * FIXME IPS should be fine as long as one plane is | |
4639 | * enabled, but in practice it seems to have problems | |
4640 | * when going from primary only to sprite only and vice | |
4641 | * versa. | |
4642 | */ | |
a5c4d7bc VS |
4643 | hsw_enable_ips(intel_crtc); |
4644 | ||
f99d7069 | 4645 | /* |
87d4300a ML |
4646 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4647 | * So don't enable underrun reporting before at least some planes | |
4648 | * are enabled. | |
4649 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4650 | * but leave the pipe running. | |
f99d7069 | 4651 | */ |
87d4300a ML |
4652 | if (IS_GEN2(dev)) |
4653 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4654 | ||
4655 | /* Underruns don't raise interrupts, so check manually. */ | |
4656 | if (HAS_GMCH_DISPLAY(dev)) | |
4657 | i9xx_check_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4658 | } |
4659 | ||
87d4300a ML |
4660 | /** |
4661 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4662 | * @crtc: the CRTC whose primary plane is to be disabled | |
4663 | * | |
4664 | * Performs potentially sleeping operations that must be done before the | |
4665 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4666 | * be called due to an explicit primary plane update, or due to an implicit | |
4667 | * disable that is caused when a sprite plane completely hides the primary | |
4668 | * plane. | |
4669 | */ | |
4670 | static void | |
4671 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4672 | { |
4673 | struct drm_device *dev = crtc->dev; | |
4674 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4675 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4676 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4677 | |
87d4300a ML |
4678 | /* |
4679 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4680 | * So diasble underrun reporting before all the planes get disabled. | |
4681 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4682 | * but leave the pipe running. | |
4683 | */ | |
4684 | if (IS_GEN2(dev)) | |
4685 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4686 | |
87d4300a ML |
4687 | /* |
4688 | * Vblank time updates from the shadow to live plane control register | |
4689 | * are blocked if the memory self-refresh mode is active at that | |
4690 | * moment. So to make sure the plane gets truly disabled, disable | |
4691 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4692 | * will be checked/applied by the HW only at the next frame start | |
4693 | * event which is after the vblank start event, so we need to have a | |
4694 | * wait-for-vblank between disabling the plane and the pipe. | |
4695 | */ | |
262cd2e1 | 4696 | if (HAS_GMCH_DISPLAY(dev)) { |
87d4300a | 4697 | intel_set_memory_cxsr(dev_priv, false); |
262cd2e1 VS |
4698 | dev_priv->wm.vlv.cxsr = false; |
4699 | intel_wait_for_vblank(dev, pipe); | |
4700 | } | |
87d4300a | 4701 | |
87d4300a ML |
4702 | /* |
4703 | * FIXME IPS should be fine as long as one plane is | |
4704 | * enabled, but in practice it seems to have problems | |
4705 | * when going from primary only to sprite only and vice | |
4706 | * versa. | |
4707 | */ | |
a5c4d7bc | 4708 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4709 | } |
4710 | ||
ac21b225 ML |
4711 | static void intel_post_plane_update(struct intel_crtc *crtc) |
4712 | { | |
4713 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4714 | struct drm_device *dev = crtc->base.dev; | |
7733b49b | 4715 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 ML |
4716 | struct drm_plane *plane; |
4717 | ||
4718 | if (atomic->wait_vblank) | |
4719 | intel_wait_for_vblank(dev, crtc->pipe); | |
4720 | ||
4721 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4722 | ||
852eb00d VS |
4723 | if (atomic->disable_cxsr) |
4724 | crtc->wm.cxsr_allowed = true; | |
4725 | ||
f015c551 VS |
4726 | if (crtc->atomic.update_wm_post) |
4727 | intel_update_watermarks(&crtc->base); | |
4728 | ||
c80ac854 | 4729 | if (atomic->update_fbc) |
7733b49b | 4730 | intel_fbc_update(dev_priv); |
ac21b225 ML |
4731 | |
4732 | if (atomic->post_enable_primary) | |
4733 | intel_post_enable_primary(&crtc->base); | |
4734 | ||
4735 | drm_for_each_plane_mask(plane, dev, atomic->update_sprite_watermarks) | |
4736 | intel_update_sprite_watermarks(plane, &crtc->base, | |
4737 | 0, 0, 0, false, false); | |
4738 | ||
4739 | memset(atomic, 0, sizeof(*atomic)); | |
4740 | } | |
4741 | ||
4742 | static void intel_pre_plane_update(struct intel_crtc *crtc) | |
4743 | { | |
4744 | struct drm_device *dev = crtc->base.dev; | |
eddfcbcd | 4745 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 ML |
4746 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
4747 | struct drm_plane *p; | |
4748 | ||
4749 | /* Track fb's for any planes being disabled */ | |
ac21b225 ML |
4750 | drm_for_each_plane_mask(p, dev, atomic->disabled_planes) { |
4751 | struct intel_plane *plane = to_intel_plane(p); | |
ac21b225 ML |
4752 | |
4753 | mutex_lock(&dev->struct_mutex); | |
a9ff8714 VS |
4754 | i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL, |
4755 | plane->frontbuffer_bit); | |
ac21b225 ML |
4756 | mutex_unlock(&dev->struct_mutex); |
4757 | } | |
4758 | ||
4759 | if (atomic->wait_for_flips) | |
4760 | intel_crtc_wait_for_pending_flips(&crtc->base); | |
4761 | ||
c80ac854 | 4762 | if (atomic->disable_fbc) |
25ad93fd | 4763 | intel_fbc_disable_crtc(crtc); |
ac21b225 | 4764 | |
066cf55b RV |
4765 | if (crtc->atomic.disable_ips) |
4766 | hsw_disable_ips(crtc); | |
4767 | ||
ac21b225 ML |
4768 | if (atomic->pre_disable_primary) |
4769 | intel_pre_disable_primary(&crtc->base); | |
852eb00d VS |
4770 | |
4771 | if (atomic->disable_cxsr) { | |
4772 | crtc->wm.cxsr_allowed = false; | |
4773 | intel_set_memory_cxsr(dev_priv, false); | |
4774 | } | |
ac21b225 ML |
4775 | } |
4776 | ||
d032ffa0 | 4777 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4778 | { |
4779 | struct drm_device *dev = crtc->dev; | |
4780 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4781 | struct drm_plane *p; |
87d4300a ML |
4782 | int pipe = intel_crtc->pipe; |
4783 | ||
7cac945f | 4784 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4785 | |
d032ffa0 ML |
4786 | drm_for_each_plane_mask(p, dev, plane_mask) |
4787 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4788 | |
f99d7069 DV |
4789 | /* |
4790 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4791 | * to compute the mask of flip planes precisely. For the time being | |
4792 | * consider this a flip to a NULL plane. | |
4793 | */ | |
4794 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4795 | } |
4796 | ||
f67a559d JB |
4797 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4798 | { | |
4799 | struct drm_device *dev = crtc->dev; | |
4800 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4801 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4802 | struct intel_encoder *encoder; |
f67a559d | 4803 | int pipe = intel_crtc->pipe; |
f67a559d | 4804 | |
53d9f4e9 | 4805 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4806 | return; |
4807 | ||
6e3c9717 | 4808 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4809 | intel_prepare_shared_dpll(intel_crtc); |
4810 | ||
6e3c9717 | 4811 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4812 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4813 | |
4814 | intel_set_pipe_timings(intel_crtc); | |
4815 | ||
6e3c9717 | 4816 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4817 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4818 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4819 | } |
4820 | ||
4821 | ironlake_set_pipeconf(crtc); | |
4822 | ||
f67a559d | 4823 | intel_crtc->active = true; |
8664281b | 4824 | |
a72e4c9f DV |
4825 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4826 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
8664281b | 4827 | |
f6736a1a | 4828 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4829 | if (encoder->pre_enable) |
4830 | encoder->pre_enable(encoder); | |
f67a559d | 4831 | |
6e3c9717 | 4832 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4833 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4834 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4835 | * enabling. */ | |
88cefb6c | 4836 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4837 | } else { |
4838 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4839 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4840 | } | |
f67a559d | 4841 | |
b074cec8 | 4842 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4843 | |
9c54c0dd JB |
4844 | /* |
4845 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4846 | * clocks enabled | |
4847 | */ | |
4848 | intel_crtc_load_lut(crtc); | |
4849 | ||
f37fcc2a | 4850 | intel_update_watermarks(crtc); |
e1fdc473 | 4851 | intel_enable_pipe(intel_crtc); |
f67a559d | 4852 | |
6e3c9717 | 4853 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4854 | ironlake_pch_enable(crtc); |
c98e9dcf | 4855 | |
f9b61ff6 DV |
4856 | assert_vblank_disabled(crtc); |
4857 | drm_crtc_vblank_on(crtc); | |
4858 | ||
fa5c73b1 DV |
4859 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4860 | encoder->enable(encoder); | |
61b77ddd DV |
4861 | |
4862 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4863 | cpt_verify_modeset(dev, intel_crtc->pipe); |
6be4a607 JB |
4864 | } |
4865 | ||
42db64ef PZ |
4866 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4867 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4868 | { | |
f5adf94e | 4869 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4870 | } |
4871 | ||
4f771f10 PZ |
4872 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4873 | { | |
4874 | struct drm_device *dev = crtc->dev; | |
4875 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4876 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4877 | struct intel_encoder *encoder; | |
99d736a2 ML |
4878 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4879 | struct intel_crtc_state *pipe_config = | |
4880 | to_intel_crtc_state(crtc->state); | |
4f771f10 | 4881 | |
53d9f4e9 | 4882 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4883 | return; |
4884 | ||
df8ad70c DV |
4885 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4886 | intel_enable_shared_dpll(intel_crtc); | |
4887 | ||
6e3c9717 | 4888 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4889 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
4890 | |
4891 | intel_set_pipe_timings(intel_crtc); | |
4892 | ||
6e3c9717 ACO |
4893 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
4894 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
4895 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
4896 | } |
4897 | ||
6e3c9717 | 4898 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4899 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4900 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4901 | } |
4902 | ||
4903 | haswell_set_pipeconf(crtc); | |
4904 | ||
4905 | intel_set_pipe_csc(crtc); | |
4906 | ||
4f771f10 | 4907 | intel_crtc->active = true; |
8664281b | 4908 | |
a72e4c9f | 4909 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4f771f10 PZ |
4910 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4911 | if (encoder->pre_enable) | |
4912 | encoder->pre_enable(encoder); | |
4913 | ||
6e3c9717 | 4914 | if (intel_crtc->config->has_pch_encoder) { |
a72e4c9f DV |
4915 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
4916 | true); | |
4fe9467d ID |
4917 | dev_priv->display.fdi_link_train(crtc); |
4918 | } | |
4919 | ||
1f544388 | 4920 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 4921 | |
ff6d9f55 | 4922 | if (INTEL_INFO(dev)->gen == 9) |
e435d6e5 | 4923 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 4924 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 4925 | ironlake_pfit_enable(intel_crtc); |
ff6d9f55 JB |
4926 | else |
4927 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 PZ |
4928 | |
4929 | /* | |
4930 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4931 | * clocks enabled | |
4932 | */ | |
4933 | intel_crtc_load_lut(crtc); | |
4934 | ||
1f544388 | 4935 | intel_ddi_set_pipe_settings(crtc); |
8228c251 | 4936 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 4937 | |
f37fcc2a | 4938 | intel_update_watermarks(crtc); |
e1fdc473 | 4939 | intel_enable_pipe(intel_crtc); |
42db64ef | 4940 | |
6e3c9717 | 4941 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 4942 | lpt_pch_enable(crtc); |
4f771f10 | 4943 | |
6e3c9717 | 4944 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
4945 | intel_ddi_set_vc_payload_alloc(crtc, true); |
4946 | ||
f9b61ff6 DV |
4947 | assert_vblank_disabled(crtc); |
4948 | drm_crtc_vblank_on(crtc); | |
4949 | ||
8807e55b | 4950 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 4951 | encoder->enable(encoder); |
8807e55b JN |
4952 | intel_opregion_notify_encoder(encoder, true); |
4953 | } | |
4f771f10 | 4954 | |
e4916946 PZ |
4955 | /* If we change the relative order between pipe/planes enabling, we need |
4956 | * to change the workaround. */ | |
99d736a2 ML |
4957 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
4958 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
4959 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4960 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4961 | } | |
4f771f10 PZ |
4962 | } |
4963 | ||
3f8dce3a DV |
4964 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
4965 | { | |
4966 | struct drm_device *dev = crtc->base.dev; | |
4967 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4968 | int pipe = crtc->pipe; | |
4969 | ||
4970 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
4971 | * it's in use. The hw state code will make sure we get this right. */ | |
6e3c9717 | 4972 | if (crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
4973 | I915_WRITE(PF_CTL(pipe), 0); |
4974 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
4975 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
4976 | } | |
4977 | } | |
4978 | ||
6be4a607 JB |
4979 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
4980 | { | |
4981 | struct drm_device *dev = crtc->dev; | |
4982 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4983 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4984 | struct intel_encoder *encoder; |
6be4a607 | 4985 | int pipe = intel_crtc->pipe; |
5eddb70b | 4986 | u32 reg, temp; |
b52eb4dc | 4987 | |
ea9d758d DV |
4988 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4989 | encoder->disable(encoder); | |
4990 | ||
f9b61ff6 DV |
4991 | drm_crtc_vblank_off(crtc); |
4992 | assert_vblank_disabled(crtc); | |
4993 | ||
6e3c9717 | 4994 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f | 4995 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
d925c59a | 4996 | |
575f7ab7 | 4997 | intel_disable_pipe(intel_crtc); |
32f9d658 | 4998 | |
3f8dce3a | 4999 | ironlake_pfit_disable(intel_crtc); |
2c07245f | 5000 | |
5a74f70a VS |
5001 | if (intel_crtc->config->has_pch_encoder) |
5002 | ironlake_fdi_disable(crtc); | |
5003 | ||
bf49ec8c DV |
5004 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5005 | if (encoder->post_disable) | |
5006 | encoder->post_disable(encoder); | |
2c07245f | 5007 | |
6e3c9717 | 5008 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5009 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5010 | |
d925c59a DV |
5011 | if (HAS_PCH_CPT(dev)) { |
5012 | /* disable TRANS_DP_CTL */ | |
5013 | reg = TRANS_DP_CTL(pipe); | |
5014 | temp = I915_READ(reg); | |
5015 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5016 | TRANS_DP_PORT_SEL_MASK); | |
5017 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5018 | I915_WRITE(reg, temp); | |
5019 | ||
5020 | /* disable DPLL_SEL */ | |
5021 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5022 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5023 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5024 | } |
e3421a18 | 5025 | |
d925c59a DV |
5026 | ironlake_fdi_pll_disable(intel_crtc); |
5027 | } | |
e4ca0612 PJ |
5028 | |
5029 | intel_crtc->active = false; | |
5030 | intel_update_watermarks(crtc); | |
6be4a607 | 5031 | } |
1b3c7a47 | 5032 | |
4f771f10 | 5033 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5034 | { |
4f771f10 PZ |
5035 | struct drm_device *dev = crtc->dev; |
5036 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5037 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5038 | struct intel_encoder *encoder; |
6e3c9717 | 5039 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5040 | |
8807e55b JN |
5041 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5042 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5043 | encoder->disable(encoder); |
8807e55b | 5044 | } |
4f771f10 | 5045 | |
f9b61ff6 DV |
5046 | drm_crtc_vblank_off(crtc); |
5047 | assert_vblank_disabled(crtc); | |
5048 | ||
6e3c9717 | 5049 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f DV |
5050 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5051 | false); | |
575f7ab7 | 5052 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5053 | |
6e3c9717 | 5054 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5055 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5056 | ||
ad80a810 | 5057 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5058 | |
ff6d9f55 | 5059 | if (INTEL_INFO(dev)->gen == 9) |
e435d6e5 | 5060 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5061 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 5062 | ironlake_pfit_disable(intel_crtc); |
ff6d9f55 JB |
5063 | else |
5064 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 | 5065 | |
1f544388 | 5066 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5067 | |
6e3c9717 | 5068 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5069 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5070 | intel_ddi_fdi_disable(crtc); |
83616634 | 5071 | } |
4f771f10 | 5072 | |
97b040aa ID |
5073 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5074 | if (encoder->post_disable) | |
5075 | encoder->post_disable(encoder); | |
e4ca0612 PJ |
5076 | |
5077 | intel_crtc->active = false; | |
5078 | intel_update_watermarks(crtc); | |
4f771f10 PZ |
5079 | } |
5080 | ||
2dd24552 JB |
5081 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5082 | { | |
5083 | struct drm_device *dev = crtc->base.dev; | |
5084 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5085 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5086 | |
681a8504 | 5087 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5088 | return; |
5089 | ||
2dd24552 | 5090 | /* |
c0b03411 DV |
5091 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5092 | * according to register description and PRM. | |
2dd24552 | 5093 | */ |
c0b03411 DV |
5094 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5095 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5096 | |
b074cec8 JB |
5097 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5098 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5099 | |
5100 | /* Border color in case we don't scale up to the full screen. Black by | |
5101 | * default, change to something else for debugging. */ | |
5102 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5103 | } |
5104 | ||
d05410f9 DA |
5105 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5106 | { | |
5107 | switch (port) { | |
5108 | case PORT_A: | |
5109 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; | |
5110 | case PORT_B: | |
5111 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; | |
5112 | case PORT_C: | |
5113 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; | |
5114 | case PORT_D: | |
5115 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; | |
d8e19f99 XZ |
5116 | case PORT_E: |
5117 | return POWER_DOMAIN_PORT_DDI_E_2_LANES; | |
d05410f9 DA |
5118 | default: |
5119 | WARN_ON_ONCE(1); | |
5120 | return POWER_DOMAIN_PORT_OTHER; | |
5121 | } | |
5122 | } | |
5123 | ||
77d22dca ID |
5124 | #define for_each_power_domain(domain, mask) \ |
5125 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5126 | if ((1 << (domain)) & (mask)) | |
5127 | ||
319be8ae ID |
5128 | enum intel_display_power_domain |
5129 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5130 | { | |
5131 | struct drm_device *dev = intel_encoder->base.dev; | |
5132 | struct intel_digital_port *intel_dig_port; | |
5133 | ||
5134 | switch (intel_encoder->type) { | |
5135 | case INTEL_OUTPUT_UNKNOWN: | |
5136 | /* Only DDI platforms should ever use this output type */ | |
5137 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5138 | case INTEL_OUTPUT_DISPLAYPORT: | |
5139 | case INTEL_OUTPUT_HDMI: | |
5140 | case INTEL_OUTPUT_EDP: | |
5141 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5142 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5143 | case INTEL_OUTPUT_DP_MST: |
5144 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5145 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5146 | case INTEL_OUTPUT_ANALOG: |
5147 | return POWER_DOMAIN_PORT_CRT; | |
5148 | case INTEL_OUTPUT_DSI: | |
5149 | return POWER_DOMAIN_PORT_DSI; | |
5150 | default: | |
5151 | return POWER_DOMAIN_PORT_OTHER; | |
5152 | } | |
5153 | } | |
5154 | ||
5155 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) | |
77d22dca | 5156 | { |
319be8ae ID |
5157 | struct drm_device *dev = crtc->dev; |
5158 | struct intel_encoder *intel_encoder; | |
5159 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5160 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca ID |
5161 | unsigned long mask; |
5162 | enum transcoder transcoder; | |
5163 | ||
292b990e ML |
5164 | if (!crtc->state->active) |
5165 | return 0; | |
5166 | ||
77d22dca ID |
5167 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
5168 | ||
5169 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); | |
5170 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5171 | if (intel_crtc->config->pch_pfit.enabled || |
5172 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5173 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5174 | ||
319be8ae ID |
5175 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5176 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5177 | ||
77d22dca ID |
5178 | return mask; |
5179 | } | |
5180 | ||
292b990e | 5181 | static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc) |
77d22dca | 5182 | { |
292b990e ML |
5183 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5184 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5185 | enum intel_display_power_domain domain; | |
5186 | unsigned long domains, new_domains, old_domains; | |
77d22dca | 5187 | |
292b990e ML |
5188 | old_domains = intel_crtc->enabled_power_domains; |
5189 | intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc); | |
77d22dca | 5190 | |
292b990e ML |
5191 | domains = new_domains & ~old_domains; |
5192 | ||
5193 | for_each_power_domain(domain, domains) | |
5194 | intel_display_power_get(dev_priv, domain); | |
5195 | ||
5196 | return old_domains & ~new_domains; | |
5197 | } | |
5198 | ||
5199 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5200 | unsigned long domains) | |
5201 | { | |
5202 | enum intel_display_power_domain domain; | |
5203 | ||
5204 | for_each_power_domain(domain, domains) | |
5205 | intel_display_power_put(dev_priv, domain); | |
5206 | } | |
77d22dca | 5207 | |
292b990e ML |
5208 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
5209 | { | |
5210 | struct drm_device *dev = state->dev; | |
5211 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5212 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
5213 | struct drm_crtc_state *crtc_state; | |
5214 | struct drm_crtc *crtc; | |
5215 | int i; | |
77d22dca | 5216 | |
292b990e ML |
5217 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5218 | if (needs_modeset(crtc->state)) | |
5219 | put_domains[to_intel_crtc(crtc)->pipe] = | |
5220 | modeset_get_crtc_power_domains(crtc); | |
77d22dca ID |
5221 | } |
5222 | ||
27c329ed ML |
5223 | if (dev_priv->display.modeset_commit_cdclk) { |
5224 | unsigned int cdclk = to_intel_atomic_state(state)->cdclk; | |
5225 | ||
5226 | if (cdclk != dev_priv->cdclk_freq && | |
5227 | !WARN_ON(!state->allow_modeset)) | |
5228 | dev_priv->display.modeset_commit_cdclk(state); | |
5229 | } | |
50f6e502 | 5230 | |
292b990e ML |
5231 | for (i = 0; i < I915_MAX_PIPES; i++) |
5232 | if (put_domains[i]) | |
5233 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
77d22dca ID |
5234 | } |
5235 | ||
adafdc6f MK |
5236 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5237 | { | |
5238 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5239 | ||
5240 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5241 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5242 | return max_cdclk_freq; | |
5243 | else if (IS_CHERRYVIEW(dev_priv)) | |
5244 | return max_cdclk_freq*95/100; | |
5245 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5246 | return 2*max_cdclk_freq*90/100; | |
5247 | else | |
5248 | return max_cdclk_freq*90/100; | |
5249 | } | |
5250 | ||
560a7ae4 DL |
5251 | static void intel_update_max_cdclk(struct drm_device *dev) |
5252 | { | |
5253 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5254 | ||
5255 | if (IS_SKYLAKE(dev)) { | |
5256 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; | |
5257 | ||
5258 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5259 | dev_priv->max_cdclk_freq = 675000; | |
5260 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5261 | dev_priv->max_cdclk_freq = 540000; | |
5262 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5263 | dev_priv->max_cdclk_freq = 450000; | |
5264 | else | |
5265 | dev_priv->max_cdclk_freq = 337500; | |
5266 | } else if (IS_BROADWELL(dev)) { | |
5267 | /* | |
5268 | * FIXME with extra cooling we can allow | |
5269 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5270 | * How can we know if extra cooling is | |
5271 | * available? PCI ID, VTB, something else? | |
5272 | */ | |
5273 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5274 | dev_priv->max_cdclk_freq = 450000; | |
5275 | else if (IS_BDW_ULX(dev)) | |
5276 | dev_priv->max_cdclk_freq = 450000; | |
5277 | else if (IS_BDW_ULT(dev)) | |
5278 | dev_priv->max_cdclk_freq = 540000; | |
5279 | else | |
5280 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5281 | } else if (IS_CHERRYVIEW(dev)) { |
5282 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5283 | } else if (IS_VALLEYVIEW(dev)) { |
5284 | dev_priv->max_cdclk_freq = 400000; | |
5285 | } else { | |
5286 | /* otherwise assume cdclk is fixed */ | |
5287 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5288 | } | |
5289 | ||
adafdc6f MK |
5290 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5291 | ||
560a7ae4 DL |
5292 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5293 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5294 | |
5295 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5296 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5297 | } |
5298 | ||
5299 | static void intel_update_cdclk(struct drm_device *dev) | |
5300 | { | |
5301 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5302 | ||
5303 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5304 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5305 | dev_priv->cdclk_freq); | |
5306 | ||
5307 | /* | |
5308 | * Program the gmbus_freq based on the cdclk frequency. | |
5309 | * BSpec erroneously claims we should aim for 4MHz, but | |
5310 | * in fact 1MHz is the correct frequency. | |
5311 | */ | |
5312 | if (IS_VALLEYVIEW(dev)) { | |
5313 | /* | |
5314 | * Program the gmbus_freq based on the cdclk frequency. | |
5315 | * BSpec erroneously claims we should aim for 4MHz, but | |
5316 | * in fact 1MHz is the correct frequency. | |
5317 | */ | |
5318 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5319 | } | |
5320 | ||
5321 | if (dev_priv->max_cdclk_freq == 0) | |
5322 | intel_update_max_cdclk(dev); | |
5323 | } | |
5324 | ||
70d0c574 | 5325 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5326 | { |
5327 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5328 | uint32_t divider; | |
5329 | uint32_t ratio; | |
5330 | uint32_t current_freq; | |
5331 | int ret; | |
5332 | ||
5333 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5334 | switch (frequency) { | |
5335 | case 144000: | |
5336 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5337 | ratio = BXT_DE_PLL_RATIO(60); | |
5338 | break; | |
5339 | case 288000: | |
5340 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5341 | ratio = BXT_DE_PLL_RATIO(60); | |
5342 | break; | |
5343 | case 384000: | |
5344 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5345 | ratio = BXT_DE_PLL_RATIO(60); | |
5346 | break; | |
5347 | case 576000: | |
5348 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5349 | ratio = BXT_DE_PLL_RATIO(60); | |
5350 | break; | |
5351 | case 624000: | |
5352 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5353 | ratio = BXT_DE_PLL_RATIO(65); | |
5354 | break; | |
5355 | case 19200: | |
5356 | /* | |
5357 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5358 | * to suppress GCC warning. | |
5359 | */ | |
5360 | ratio = 0; | |
5361 | divider = 0; | |
5362 | break; | |
5363 | default: | |
5364 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5365 | ||
5366 | return; | |
5367 | } | |
5368 | ||
5369 | mutex_lock(&dev_priv->rps.hw_lock); | |
5370 | /* Inform power controller of upcoming frequency change */ | |
5371 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5372 | 0x80000000); | |
5373 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5374 | ||
5375 | if (ret) { | |
5376 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5377 | ret, frequency); | |
5378 | return; | |
5379 | } | |
5380 | ||
5381 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5382 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5383 | current_freq = current_freq * 500 + 1000; | |
5384 | ||
5385 | /* | |
5386 | * DE PLL has to be disabled when | |
5387 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5388 | * - before setting to 624MHz (PLL needs toggling) | |
5389 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5390 | */ | |
5391 | if (frequency == 19200 || frequency == 624000 || | |
5392 | current_freq == 624000) { | |
5393 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5394 | /* Timeout 200us */ | |
5395 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5396 | 1)) | |
5397 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5398 | } | |
5399 | ||
5400 | if (frequency != 19200) { | |
5401 | uint32_t val; | |
5402 | ||
5403 | val = I915_READ(BXT_DE_PLL_CTL); | |
5404 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5405 | val |= ratio; | |
5406 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5407 | ||
5408 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5409 | /* Timeout 200us */ | |
5410 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5411 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5412 | ||
5413 | val = I915_READ(CDCLK_CTL); | |
5414 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5415 | val |= divider; | |
5416 | /* | |
5417 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5418 | * enable otherwise. | |
5419 | */ | |
5420 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5421 | if (frequency >= 500000) | |
5422 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5423 | ||
5424 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5425 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5426 | val |= (frequency - 1000) / 500; | |
5427 | I915_WRITE(CDCLK_CTL, val); | |
5428 | } | |
5429 | ||
5430 | mutex_lock(&dev_priv->rps.hw_lock); | |
5431 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5432 | DIV_ROUND_UP(frequency, 25000)); | |
5433 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5434 | ||
5435 | if (ret) { | |
5436 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5437 | ret, frequency); | |
5438 | return; | |
5439 | } | |
5440 | ||
a47871bd | 5441 | intel_update_cdclk(dev); |
f8437dd1 VK |
5442 | } |
5443 | ||
5444 | void broxton_init_cdclk(struct drm_device *dev) | |
5445 | { | |
5446 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5447 | uint32_t val; | |
5448 | ||
5449 | /* | |
5450 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5451 | * or else the reset will hang because there is no PCH to respond. | |
5452 | * Move the handshake programming to initialization sequence. | |
5453 | * Previously was left up to BIOS. | |
5454 | */ | |
5455 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5456 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5457 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5458 | ||
5459 | /* Enable PG1 for cdclk */ | |
5460 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5461 | ||
5462 | /* check if cd clock is enabled */ | |
5463 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5464 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5465 | return; | |
5466 | } | |
5467 | ||
5468 | /* | |
5469 | * FIXME: | |
5470 | * - The initial CDCLK needs to be read from VBT. | |
5471 | * Need to make this change after VBT has changes for BXT. | |
5472 | * - check if setting the max (or any) cdclk freq is really necessary | |
5473 | * here, it belongs to modeset time | |
5474 | */ | |
5475 | broxton_set_cdclk(dev, 624000); | |
5476 | ||
5477 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5478 | POSTING_READ(DBUF_CTL); |
5479 | ||
f8437dd1 VK |
5480 | udelay(10); |
5481 | ||
5482 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5483 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5484 | } | |
5485 | ||
5486 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5487 | { | |
5488 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5489 | ||
5490 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5491 | POSTING_READ(DBUF_CTL); |
5492 | ||
f8437dd1 VK |
5493 | udelay(10); |
5494 | ||
5495 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5496 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5497 | ||
5498 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5499 | broxton_set_cdclk(dev, 19200); | |
5500 | ||
5501 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5502 | } | |
5503 | ||
5d96d8af DL |
5504 | static const struct skl_cdclk_entry { |
5505 | unsigned int freq; | |
5506 | unsigned int vco; | |
5507 | } skl_cdclk_frequencies[] = { | |
5508 | { .freq = 308570, .vco = 8640 }, | |
5509 | { .freq = 337500, .vco = 8100 }, | |
5510 | { .freq = 432000, .vco = 8640 }, | |
5511 | { .freq = 450000, .vco = 8100 }, | |
5512 | { .freq = 540000, .vco = 8100 }, | |
5513 | { .freq = 617140, .vco = 8640 }, | |
5514 | { .freq = 675000, .vco = 8100 }, | |
5515 | }; | |
5516 | ||
5517 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5518 | { | |
5519 | return (freq - 1000) / 500; | |
5520 | } | |
5521 | ||
5522 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5523 | { | |
5524 | unsigned int i; | |
5525 | ||
5526 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5527 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5528 | ||
5529 | if (e->freq == freq) | |
5530 | return e->vco; | |
5531 | } | |
5532 | ||
5533 | return 8100; | |
5534 | } | |
5535 | ||
5536 | static void | |
5537 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5538 | { | |
5539 | unsigned int min_freq; | |
5540 | u32 val; | |
5541 | ||
5542 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5543 | val = I915_READ(CDCLK_CTL); | |
5544 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5545 | val |= CDCLK_FREQ_337_308; | |
5546 | ||
5547 | if (required_vco == 8640) | |
5548 | min_freq = 308570; | |
5549 | else | |
5550 | min_freq = 337500; | |
5551 | ||
5552 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5553 | ||
5554 | I915_WRITE(CDCLK_CTL, val); | |
5555 | POSTING_READ(CDCLK_CTL); | |
5556 | ||
5557 | /* | |
5558 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5559 | * taking into account the VCO required to operate the eDP panel at the | |
5560 | * desired frequency. The usual DP link rates operate with a VCO of | |
5561 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5562 | * The modeset code is responsible for the selection of the exact link | |
5563 | * rate later on, with the constraint of choosing a frequency that | |
5564 | * works with required_vco. | |
5565 | */ | |
5566 | val = I915_READ(DPLL_CTRL1); | |
5567 | ||
5568 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5569 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5570 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5571 | if (required_vco == 8640) | |
5572 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5573 | SKL_DPLL0); | |
5574 | else | |
5575 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5576 | SKL_DPLL0); | |
5577 | ||
5578 | I915_WRITE(DPLL_CTRL1, val); | |
5579 | POSTING_READ(DPLL_CTRL1); | |
5580 | ||
5581 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5582 | ||
5583 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5584 | DRM_ERROR("DPLL0 not locked\n"); | |
5585 | } | |
5586 | ||
5587 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5588 | { | |
5589 | int ret; | |
5590 | u32 val; | |
5591 | ||
5592 | /* inform PCU we want to change CDCLK */ | |
5593 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5594 | mutex_lock(&dev_priv->rps.hw_lock); | |
5595 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5596 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5597 | ||
5598 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5599 | } | |
5600 | ||
5601 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5602 | { | |
5603 | unsigned int i; | |
5604 | ||
5605 | for (i = 0; i < 15; i++) { | |
5606 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5607 | return true; | |
5608 | udelay(10); | |
5609 | } | |
5610 | ||
5611 | return false; | |
5612 | } | |
5613 | ||
5614 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5615 | { | |
560a7ae4 | 5616 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5617 | u32 freq_select, pcu_ack; |
5618 | ||
5619 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5620 | ||
5621 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5622 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5623 | return; | |
5624 | } | |
5625 | ||
5626 | /* set CDCLK_CTL */ | |
5627 | switch(freq) { | |
5628 | case 450000: | |
5629 | case 432000: | |
5630 | freq_select = CDCLK_FREQ_450_432; | |
5631 | pcu_ack = 1; | |
5632 | break; | |
5633 | case 540000: | |
5634 | freq_select = CDCLK_FREQ_540; | |
5635 | pcu_ack = 2; | |
5636 | break; | |
5637 | case 308570: | |
5638 | case 337500: | |
5639 | default: | |
5640 | freq_select = CDCLK_FREQ_337_308; | |
5641 | pcu_ack = 0; | |
5642 | break; | |
5643 | case 617140: | |
5644 | case 675000: | |
5645 | freq_select = CDCLK_FREQ_675_617; | |
5646 | pcu_ack = 3; | |
5647 | break; | |
5648 | } | |
5649 | ||
5650 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5651 | POSTING_READ(CDCLK_CTL); | |
5652 | ||
5653 | /* inform PCU of the change */ | |
5654 | mutex_lock(&dev_priv->rps.hw_lock); | |
5655 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5656 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5657 | |
5658 | intel_update_cdclk(dev); | |
5d96d8af DL |
5659 | } |
5660 | ||
5661 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5662 | { | |
5663 | /* disable DBUF power */ | |
5664 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5665 | POSTING_READ(DBUF_CTL); | |
5666 | ||
5667 | udelay(10); | |
5668 | ||
5669 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5670 | DRM_ERROR("DBuf power disable timeout\n"); | |
5671 | ||
5672 | /* disable DPLL0 */ | |
5673 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5674 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5675 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5676 | ||
5677 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5678 | } | |
5679 | ||
5680 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5681 | { | |
5682 | u32 val; | |
5683 | unsigned int required_vco; | |
5684 | ||
5685 | /* enable PCH reset handshake */ | |
5686 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5687 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE); | |
5688 | ||
5689 | /* enable PG1 and Misc I/O */ | |
5690 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5691 | ||
39d9b85a GW |
5692 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5693 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5694 | /* enable DPLL0 */ | |
5695 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5696 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5697 | } |
5698 | ||
5d96d8af DL |
5699 | /* set CDCLK to the frequency the BIOS chose */ |
5700 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5701 | ||
5702 | /* enable DBUF power */ | |
5703 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5704 | POSTING_READ(DBUF_CTL); | |
5705 | ||
5706 | udelay(10); | |
5707 | ||
5708 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5709 | DRM_ERROR("DBuf power enable timeout\n"); | |
5710 | } | |
5711 | ||
dfcab17e | 5712 | /* returns HPLL frequency in kHz */ |
f8bf63fd | 5713 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
30a970c6 | 5714 | { |
586f49dc | 5715 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
30a970c6 | 5716 | |
586f49dc | 5717 | /* Obtain SKU information */ |
a580516d | 5718 | mutex_lock(&dev_priv->sb_lock); |
586f49dc JB |
5719 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
5720 | CCK_FUSE_HPLL_FREQ_MASK; | |
a580516d | 5721 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5722 | |
dfcab17e | 5723 | return vco_freq[hpll_freq] * 1000; |
30a970c6 JB |
5724 | } |
5725 | ||
5726 | /* Adjust CDclk dividers to allow high res or save power if possible */ | |
5727 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5728 | { | |
5729 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5730 | u32 val, cmd; | |
5731 | ||
164dfd28 VK |
5732 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5733 | != dev_priv->cdclk_freq); | |
d60c4473 | 5734 | |
dfcab17e | 5735 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5736 | cmd = 2; |
dfcab17e | 5737 | else if (cdclk == 266667) |
30a970c6 JB |
5738 | cmd = 1; |
5739 | else | |
5740 | cmd = 0; | |
5741 | ||
5742 | mutex_lock(&dev_priv->rps.hw_lock); | |
5743 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5744 | val &= ~DSPFREQGUAR_MASK; | |
5745 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5746 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5747 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5748 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5749 | 50)) { | |
5750 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5751 | } | |
5752 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5753 | ||
54433e91 VS |
5754 | mutex_lock(&dev_priv->sb_lock); |
5755 | ||
dfcab17e | 5756 | if (cdclk == 400000) { |
6bcda4f0 | 5757 | u32 divider; |
30a970c6 | 5758 | |
6bcda4f0 | 5759 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5760 | |
30a970c6 JB |
5761 | /* adjust cdclk divider */ |
5762 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
9cf33db5 | 5763 | val &= ~DISPLAY_FREQUENCY_VALUES; |
30a970c6 JB |
5764 | val |= divider; |
5765 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5766 | |
5767 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
5768 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
5769 | 50)) | |
5770 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5771 | } |
5772 | ||
30a970c6 JB |
5773 | /* adjust self-refresh exit latency value */ |
5774 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5775 | val &= ~0x7f; | |
5776 | ||
5777 | /* | |
5778 | * For high bandwidth configs, we set a higher latency in the bunit | |
5779 | * so that the core display fetch happens in time to avoid underruns. | |
5780 | */ | |
dfcab17e | 5781 | if (cdclk == 400000) |
30a970c6 JB |
5782 | val |= 4500 / 250; /* 4.5 usec */ |
5783 | else | |
5784 | val |= 3000 / 250; /* 3.0 usec */ | |
5785 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5786 | |
a580516d | 5787 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5788 | |
b6283055 | 5789 | intel_update_cdclk(dev); |
30a970c6 JB |
5790 | } |
5791 | ||
383c5a6a VS |
5792 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5793 | { | |
5794 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5795 | u32 val, cmd; | |
5796 | ||
164dfd28 VK |
5797 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5798 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5799 | |
5800 | switch (cdclk) { | |
383c5a6a VS |
5801 | case 333333: |
5802 | case 320000: | |
383c5a6a | 5803 | case 266667: |
383c5a6a | 5804 | case 200000: |
383c5a6a VS |
5805 | break; |
5806 | default: | |
5f77eeb0 | 5807 | MISSING_CASE(cdclk); |
383c5a6a VS |
5808 | return; |
5809 | } | |
5810 | ||
9d0d3fda VS |
5811 | /* |
5812 | * Specs are full of misinformation, but testing on actual | |
5813 | * hardware has shown that we just need to write the desired | |
5814 | * CCK divider into the Punit register. | |
5815 | */ | |
5816 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5817 | ||
383c5a6a VS |
5818 | mutex_lock(&dev_priv->rps.hw_lock); |
5819 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5820 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5821 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5822 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5823 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5824 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5825 | 50)) { | |
5826 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5827 | } | |
5828 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5829 | ||
b6283055 | 5830 | intel_update_cdclk(dev); |
383c5a6a VS |
5831 | } |
5832 | ||
30a970c6 JB |
5833 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5834 | int max_pixclk) | |
5835 | { | |
6bcda4f0 | 5836 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5837 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5838 | |
30a970c6 JB |
5839 | /* |
5840 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5841 | * 200MHz | |
5842 | * 267MHz | |
29dc7ef3 | 5843 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5844 | * 400MHz (VLV only) |
5845 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5846 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5847 | * |
5848 | * We seem to get an unstable or solid color picture at 200MHz. | |
5849 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5850 | * are off. | |
30a970c6 | 5851 | */ |
6cca3195 VS |
5852 | if (!IS_CHERRYVIEW(dev_priv) && |
5853 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5854 | return 400000; |
6cca3195 | 5855 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5856 | return freq_320; |
e37c67a1 | 5857 | else if (max_pixclk > 0) |
dfcab17e | 5858 | return 266667; |
e37c67a1 VS |
5859 | else |
5860 | return 200000; | |
30a970c6 JB |
5861 | } |
5862 | ||
f8437dd1 VK |
5863 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5864 | int max_pixclk) | |
5865 | { | |
5866 | /* | |
5867 | * FIXME: | |
5868 | * - remove the guardband, it's not needed on BXT | |
5869 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5870 | */ | |
5871 | if (max_pixclk > 576000*9/10) | |
5872 | return 624000; | |
5873 | else if (max_pixclk > 384000*9/10) | |
5874 | return 576000; | |
5875 | else if (max_pixclk > 288000*9/10) | |
5876 | return 384000; | |
5877 | else if (max_pixclk > 144000*9/10) | |
5878 | return 288000; | |
5879 | else | |
5880 | return 144000; | |
5881 | } | |
5882 | ||
a821fc46 ACO |
5883 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5884 | * that's non-NULL, look at current state otherwise. */ | |
5885 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5886 | struct drm_atomic_state *state) | |
30a970c6 | 5887 | { |
30a970c6 | 5888 | struct intel_crtc *intel_crtc; |
304603f4 | 5889 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5890 | int max_pixclk = 0; |
5891 | ||
d3fcc808 | 5892 | for_each_intel_crtc(dev, intel_crtc) { |
27c329ed | 5893 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
304603f4 ACO |
5894 | if (IS_ERR(crtc_state)) |
5895 | return PTR_ERR(crtc_state); | |
5896 | ||
5897 | if (!crtc_state->base.enable) | |
5898 | continue; | |
5899 | ||
5900 | max_pixclk = max(max_pixclk, | |
5901 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5902 | } |
5903 | ||
5904 | return max_pixclk; | |
5905 | } | |
5906 | ||
27c329ed | 5907 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 5908 | { |
27c329ed ML |
5909 | struct drm_device *dev = state->dev; |
5910 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5911 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
30a970c6 | 5912 | |
304603f4 ACO |
5913 | if (max_pixclk < 0) |
5914 | return max_pixclk; | |
30a970c6 | 5915 | |
27c329ed ML |
5916 | to_intel_atomic_state(state)->cdclk = |
5917 | valleyview_calc_cdclk(dev_priv, max_pixclk); | |
0a9ab303 | 5918 | |
27c329ed ML |
5919 | return 0; |
5920 | } | |
304603f4 | 5921 | |
27c329ed ML |
5922 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
5923 | { | |
5924 | struct drm_device *dev = state->dev; | |
5925 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5926 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
85a96e7a | 5927 | |
27c329ed ML |
5928 | if (max_pixclk < 0) |
5929 | return max_pixclk; | |
85a96e7a | 5930 | |
27c329ed ML |
5931 | to_intel_atomic_state(state)->cdclk = |
5932 | broxton_calc_cdclk(dev_priv, max_pixclk); | |
85a96e7a | 5933 | |
27c329ed | 5934 | return 0; |
30a970c6 JB |
5935 | } |
5936 | ||
1e69cd74 VS |
5937 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
5938 | { | |
5939 | unsigned int credits, default_credits; | |
5940 | ||
5941 | if (IS_CHERRYVIEW(dev_priv)) | |
5942 | default_credits = PFI_CREDIT(12); | |
5943 | else | |
5944 | default_credits = PFI_CREDIT(8); | |
5945 | ||
164dfd28 | 5946 | if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
1e69cd74 VS |
5947 | /* CHV suggested value is 31 or 63 */ |
5948 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 5949 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
5950 | else |
5951 | credits = PFI_CREDIT(15); | |
5952 | } else { | |
5953 | credits = default_credits; | |
5954 | } | |
5955 | ||
5956 | /* | |
5957 | * WA - write default credits before re-programming | |
5958 | * FIXME: should we also set the resend bit here? | |
5959 | */ | |
5960 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
5961 | default_credits); | |
5962 | ||
5963 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
5964 | credits | PFI_CREDIT_RESEND); | |
5965 | ||
5966 | /* | |
5967 | * FIXME is this guaranteed to clear | |
5968 | * immediately or should we poll for it? | |
5969 | */ | |
5970 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
5971 | } | |
5972 | ||
27c329ed | 5973 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 5974 | { |
a821fc46 | 5975 | struct drm_device *dev = old_state->dev; |
27c329ed | 5976 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
30a970c6 | 5977 | struct drm_i915_private *dev_priv = dev->dev_private; |
30a970c6 | 5978 | |
27c329ed ML |
5979 | /* |
5980 | * FIXME: We can end up here with all power domains off, yet | |
5981 | * with a CDCLK frequency other than the minimum. To account | |
5982 | * for this take the PIPE-A power domain, which covers the HW | |
5983 | * blocks needed for the following programming. This can be | |
5984 | * removed once it's guaranteed that we get here either with | |
5985 | * the minimum CDCLK set, or the required power domains | |
5986 | * enabled. | |
5987 | */ | |
5988 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 5989 | |
27c329ed ML |
5990 | if (IS_CHERRYVIEW(dev)) |
5991 | cherryview_set_cdclk(dev, req_cdclk); | |
5992 | else | |
5993 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 5994 | |
27c329ed | 5995 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 5996 | |
27c329ed | 5997 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
5998 | } |
5999 | ||
89b667f8 JB |
6000 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6001 | { | |
6002 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6003 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6004 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6005 | struct intel_encoder *encoder; | |
6006 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6007 | bool is_dsi; |
89b667f8 | 6008 | |
53d9f4e9 | 6009 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6010 | return; |
6011 | ||
409ee761 | 6012 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6013 | |
6e3c9717 | 6014 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6015 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6016 | |
6017 | intel_set_pipe_timings(intel_crtc); | |
6018 | ||
c14b0485 VS |
6019 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6020 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6021 | ||
6022 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6023 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6024 | } | |
6025 | ||
5b18e57c DV |
6026 | i9xx_set_pipeconf(intel_crtc); |
6027 | ||
89b667f8 | 6028 | intel_crtc->active = true; |
89b667f8 | 6029 | |
a72e4c9f | 6030 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6031 | |
89b667f8 JB |
6032 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6033 | if (encoder->pre_pll_enable) | |
6034 | encoder->pre_pll_enable(encoder); | |
6035 | ||
9d556c99 | 6036 | if (!is_dsi) { |
c0b4c660 VS |
6037 | if (IS_CHERRYVIEW(dev)) { |
6038 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6039 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6040 | } else { |
6041 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6042 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6043 | } |
9d556c99 | 6044 | } |
89b667f8 JB |
6045 | |
6046 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6047 | if (encoder->pre_enable) | |
6048 | encoder->pre_enable(encoder); | |
6049 | ||
2dd24552 JB |
6050 | i9xx_pfit_enable(intel_crtc); |
6051 | ||
63cbb074 VS |
6052 | intel_crtc_load_lut(crtc); |
6053 | ||
e1fdc473 | 6054 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6055 | |
4b3a9526 VS |
6056 | assert_vblank_disabled(crtc); |
6057 | drm_crtc_vblank_on(crtc); | |
6058 | ||
f9b61ff6 DV |
6059 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6060 | encoder->enable(encoder); | |
89b667f8 JB |
6061 | } |
6062 | ||
f13c2ef3 DV |
6063 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6064 | { | |
6065 | struct drm_device *dev = crtc->base.dev; | |
6066 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6067 | ||
6e3c9717 ACO |
6068 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6069 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6070 | } |
6071 | ||
0b8765c6 | 6072 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6073 | { |
6074 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6075 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6076 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6077 | struct intel_encoder *encoder; |
79e53945 | 6078 | int pipe = intel_crtc->pipe; |
79e53945 | 6079 | |
53d9f4e9 | 6080 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6081 | return; |
6082 | ||
f13c2ef3 DV |
6083 | i9xx_set_pll_dividers(intel_crtc); |
6084 | ||
6e3c9717 | 6085 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6086 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6087 | |
6088 | intel_set_pipe_timings(intel_crtc); | |
6089 | ||
5b18e57c DV |
6090 | i9xx_set_pipeconf(intel_crtc); |
6091 | ||
f7abfe8b | 6092 | intel_crtc->active = true; |
6b383a7f | 6093 | |
4a3436e8 | 6094 | if (!IS_GEN2(dev)) |
a72e4c9f | 6095 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6096 | |
9d6d9f19 MK |
6097 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6098 | if (encoder->pre_enable) | |
6099 | encoder->pre_enable(encoder); | |
6100 | ||
f6736a1a DV |
6101 | i9xx_enable_pll(intel_crtc); |
6102 | ||
2dd24552 JB |
6103 | i9xx_pfit_enable(intel_crtc); |
6104 | ||
63cbb074 VS |
6105 | intel_crtc_load_lut(crtc); |
6106 | ||
f37fcc2a | 6107 | intel_update_watermarks(crtc); |
e1fdc473 | 6108 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6109 | |
4b3a9526 VS |
6110 | assert_vblank_disabled(crtc); |
6111 | drm_crtc_vblank_on(crtc); | |
6112 | ||
f9b61ff6 DV |
6113 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6114 | encoder->enable(encoder); | |
0b8765c6 | 6115 | } |
79e53945 | 6116 | |
87476d63 DV |
6117 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6118 | { | |
6119 | struct drm_device *dev = crtc->base.dev; | |
6120 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6121 | |
6e3c9717 | 6122 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6123 | return; |
87476d63 | 6124 | |
328d8e82 | 6125 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6126 | |
328d8e82 DV |
6127 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6128 | I915_READ(PFIT_CONTROL)); | |
6129 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6130 | } |
6131 | ||
0b8765c6 JB |
6132 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6133 | { | |
6134 | struct drm_device *dev = crtc->dev; | |
6135 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6136 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6137 | struct intel_encoder *encoder; |
0b8765c6 | 6138 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6139 | |
6304cd91 VS |
6140 | /* |
6141 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6142 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6143 | * We also need to wait on all gmch platforms because of the |
6144 | * self-refresh mode constraint explained above. | |
6304cd91 | 6145 | */ |
564ed191 | 6146 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6147 | |
4b3a9526 VS |
6148 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6149 | encoder->disable(encoder); | |
6150 | ||
f9b61ff6 DV |
6151 | drm_crtc_vblank_off(crtc); |
6152 | assert_vblank_disabled(crtc); | |
6153 | ||
575f7ab7 | 6154 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6155 | |
87476d63 | 6156 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6157 | |
89b667f8 JB |
6158 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6159 | if (encoder->post_disable) | |
6160 | encoder->post_disable(encoder); | |
6161 | ||
409ee761 | 6162 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6163 | if (IS_CHERRYVIEW(dev)) |
6164 | chv_disable_pll(dev_priv, pipe); | |
6165 | else if (IS_VALLEYVIEW(dev)) | |
6166 | vlv_disable_pll(dev_priv, pipe); | |
6167 | else | |
1c4e0274 | 6168 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6169 | } |
0b8765c6 | 6170 | |
d6db995f VS |
6171 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6172 | if (encoder->post_pll_disable) | |
6173 | encoder->post_pll_disable(encoder); | |
6174 | ||
4a3436e8 | 6175 | if (!IS_GEN2(dev)) |
a72e4c9f | 6176 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
e4ca0612 PJ |
6177 | |
6178 | intel_crtc->active = false; | |
6179 | intel_update_watermarks(crtc); | |
0b8765c6 JB |
6180 | } |
6181 | ||
b17d48e2 ML |
6182 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6183 | { | |
6184 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6185 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6186 | enum intel_display_power_domain domain; | |
6187 | unsigned long domains; | |
6188 | ||
6189 | if (!intel_crtc->active) | |
6190 | return; | |
6191 | ||
a539205a ML |
6192 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
6193 | intel_crtc_wait_for_pending_flips(crtc); | |
6194 | intel_pre_disable_primary(crtc); | |
6195 | } | |
6196 | ||
d032ffa0 | 6197 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 | 6198 | dev_priv->display.crtc_disable(crtc); |
1f7457b1 | 6199 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6200 | |
6201 | domains = intel_crtc->enabled_power_domains; | |
6202 | for_each_power_domain(domain, domains) | |
6203 | intel_display_power_put(dev_priv, domain); | |
6204 | intel_crtc->enabled_power_domains = 0; | |
6205 | } | |
6206 | ||
6b72d486 ML |
6207 | /* |
6208 | * turn all crtc's off, but do not adjust state | |
6209 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6210 | */ | |
70e0bd74 | 6211 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6212 | { |
70e0bd74 ML |
6213 | struct drm_mode_config *config = &dev->mode_config; |
6214 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
6215 | struct drm_atomic_state *state; | |
6b72d486 | 6216 | struct drm_crtc *crtc; |
70e0bd74 ML |
6217 | unsigned crtc_mask = 0; |
6218 | int ret = 0; | |
6219 | ||
6220 | if (WARN_ON(!ctx)) | |
6221 | return 0; | |
6222 | ||
6223 | lockdep_assert_held(&ctx->ww_ctx); | |
6224 | state = drm_atomic_state_alloc(dev); | |
6225 | if (WARN_ON(!state)) | |
6226 | return -ENOMEM; | |
6227 | ||
6228 | state->acquire_ctx = ctx; | |
6229 | state->allow_modeset = true; | |
6230 | ||
6231 | for_each_crtc(dev, crtc) { | |
6232 | struct drm_crtc_state *crtc_state = | |
6233 | drm_atomic_get_crtc_state(state, crtc); | |
6b72d486 | 6234 | |
70e0bd74 ML |
6235 | ret = PTR_ERR_OR_ZERO(crtc_state); |
6236 | if (ret) | |
6237 | goto free; | |
6238 | ||
6239 | if (!crtc_state->active) | |
6240 | continue; | |
6241 | ||
6242 | crtc_state->active = false; | |
6243 | crtc_mask |= 1 << drm_crtc_index(crtc); | |
6244 | } | |
6245 | ||
6246 | if (crtc_mask) { | |
74c090b1 | 6247 | ret = drm_atomic_commit(state); |
70e0bd74 ML |
6248 | |
6249 | if (!ret) { | |
6250 | for_each_crtc(dev, crtc) | |
6251 | if (crtc_mask & (1 << drm_crtc_index(crtc))) | |
6252 | crtc->state->active = true; | |
6253 | ||
6254 | return ret; | |
6255 | } | |
6256 | } | |
6257 | ||
6258 | free: | |
6259 | if (ret) | |
6260 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
6261 | drm_atomic_state_free(state); | |
6262 | return ret; | |
ee7b9f93 JB |
6263 | } |
6264 | ||
ea5b213a | 6265 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6266 | { |
4ef69c7a | 6267 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6268 | |
ea5b213a CW |
6269 | drm_encoder_cleanup(encoder); |
6270 | kfree(intel_encoder); | |
7e7d76c3 JB |
6271 | } |
6272 | ||
0a91ca29 DV |
6273 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6274 | * internal consistency). */ | |
b980514c | 6275 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6276 | { |
35dd3c64 ML |
6277 | struct drm_crtc *crtc = connector->base.state->crtc; |
6278 | ||
6279 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6280 | connector->base.base.id, | |
6281 | connector->base.name); | |
6282 | ||
0a91ca29 | 6283 | if (connector->get_hw_state(connector)) { |
35dd3c64 ML |
6284 | struct drm_encoder *encoder = &connector->encoder->base; |
6285 | struct drm_connector_state *conn_state = connector->base.state; | |
0a91ca29 | 6286 | |
35dd3c64 ML |
6287 | I915_STATE_WARN(!crtc, |
6288 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6289 | |
35dd3c64 ML |
6290 | if (!crtc) |
6291 | return; | |
6292 | ||
6293 | I915_STATE_WARN(!crtc->state->active, | |
6294 | "connector is active, but attached crtc isn't\n"); | |
6295 | ||
6296 | if (!encoder) | |
6297 | return; | |
6298 | ||
6299 | I915_STATE_WARN(conn_state->best_encoder != encoder, | |
6300 | "atomic encoder doesn't match attached encoder\n"); | |
6301 | ||
6302 | I915_STATE_WARN(conn_state->crtc != encoder->crtc, | |
6303 | "attached encoder crtc differs from connector crtc\n"); | |
6304 | } else { | |
4d688a2a ML |
6305 | I915_STATE_WARN(crtc && crtc->state->active, |
6306 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6307 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6308 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6309 | } |
79e53945 JB |
6310 | } |
6311 | ||
08d9bc92 ACO |
6312 | int intel_connector_init(struct intel_connector *connector) |
6313 | { | |
6314 | struct drm_connector_state *connector_state; | |
6315 | ||
6316 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6317 | if (!connector_state) | |
6318 | return -ENOMEM; | |
6319 | ||
6320 | connector->base.state = connector_state; | |
6321 | return 0; | |
6322 | } | |
6323 | ||
6324 | struct intel_connector *intel_connector_alloc(void) | |
6325 | { | |
6326 | struct intel_connector *connector; | |
6327 | ||
6328 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6329 | if (!connector) | |
6330 | return NULL; | |
6331 | ||
6332 | if (intel_connector_init(connector) < 0) { | |
6333 | kfree(connector); | |
6334 | return NULL; | |
6335 | } | |
6336 | ||
6337 | return connector; | |
6338 | } | |
6339 | ||
f0947c37 DV |
6340 | /* Simple connector->get_hw_state implementation for encoders that support only |
6341 | * one connector and no cloning and hence the encoder state determines the state | |
6342 | * of the connector. */ | |
6343 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6344 | { |
24929352 | 6345 | enum pipe pipe = 0; |
f0947c37 | 6346 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6347 | |
f0947c37 | 6348 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6349 | } |
6350 | ||
6d293983 | 6351 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6352 | { |
6d293983 ACO |
6353 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6354 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6355 | |
6356 | return 0; | |
6357 | } | |
6358 | ||
6d293983 | 6359 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6360 | struct intel_crtc_state *pipe_config) |
1857e1da | 6361 | { |
6d293983 ACO |
6362 | struct drm_atomic_state *state = pipe_config->base.state; |
6363 | struct intel_crtc *other_crtc; | |
6364 | struct intel_crtc_state *other_crtc_state; | |
6365 | ||
1857e1da DV |
6366 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6367 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6368 | if (pipe_config->fdi_lanes > 4) { | |
6369 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6370 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6371 | return -EINVAL; |
1857e1da DV |
6372 | } |
6373 | ||
bafb6553 | 6374 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6375 | if (pipe_config->fdi_lanes > 2) { |
6376 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6377 | pipe_config->fdi_lanes); | |
6d293983 | 6378 | return -EINVAL; |
1857e1da | 6379 | } else { |
6d293983 | 6380 | return 0; |
1857e1da DV |
6381 | } |
6382 | } | |
6383 | ||
6384 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6385 | return 0; |
1857e1da DV |
6386 | |
6387 | /* Ivybridge 3 pipe is really complicated */ | |
6388 | switch (pipe) { | |
6389 | case PIPE_A: | |
6d293983 | 6390 | return 0; |
1857e1da | 6391 | case PIPE_B: |
6d293983 ACO |
6392 | if (pipe_config->fdi_lanes <= 2) |
6393 | return 0; | |
6394 | ||
6395 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6396 | other_crtc_state = | |
6397 | intel_atomic_get_crtc_state(state, other_crtc); | |
6398 | if (IS_ERR(other_crtc_state)) | |
6399 | return PTR_ERR(other_crtc_state); | |
6400 | ||
6401 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6402 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6403 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6404 | return -EINVAL; |
1857e1da | 6405 | } |
6d293983 | 6406 | return 0; |
1857e1da | 6407 | case PIPE_C: |
251cc67c VS |
6408 | if (pipe_config->fdi_lanes > 2) { |
6409 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6410 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6411 | return -EINVAL; |
251cc67c | 6412 | } |
6d293983 ACO |
6413 | |
6414 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6415 | other_crtc_state = | |
6416 | intel_atomic_get_crtc_state(state, other_crtc); | |
6417 | if (IS_ERR(other_crtc_state)) | |
6418 | return PTR_ERR(other_crtc_state); | |
6419 | ||
6420 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6421 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6422 | return -EINVAL; |
1857e1da | 6423 | } |
6d293983 | 6424 | return 0; |
1857e1da DV |
6425 | default: |
6426 | BUG(); | |
6427 | } | |
6428 | } | |
6429 | ||
e29c22c0 DV |
6430 | #define RETRY 1 |
6431 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6432 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6433 | { |
1857e1da | 6434 | struct drm_device *dev = intel_crtc->base.dev; |
2d112de7 | 6435 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6436 | int lane, link_bw, fdi_dotclock, ret; |
6437 | bool needs_recompute = false; | |
877d48d5 | 6438 | |
e29c22c0 | 6439 | retry: |
877d48d5 DV |
6440 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6441 | * each output octet as 10 bits. The actual frequency | |
6442 | * is stored as a divider into a 100MHz clock, and the | |
6443 | * mode pixel clock is stored in units of 1KHz. | |
6444 | * Hence the bw of each lane in terms of the mode signal | |
6445 | * is: | |
6446 | */ | |
6447 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6448 | ||
241bfc38 | 6449 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6450 | |
2bd89a07 | 6451 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6452 | pipe_config->pipe_bpp); |
6453 | ||
6454 | pipe_config->fdi_lanes = lane; | |
6455 | ||
2bd89a07 | 6456 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6457 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6458 | |
6d293983 ACO |
6459 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6460 | intel_crtc->pipe, pipe_config); | |
6461 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6462 | pipe_config->pipe_bpp -= 2*3; |
6463 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6464 | pipe_config->pipe_bpp); | |
6465 | needs_recompute = true; | |
6466 | pipe_config->bw_constrained = true; | |
6467 | ||
6468 | goto retry; | |
6469 | } | |
6470 | ||
6471 | if (needs_recompute) | |
6472 | return RETRY; | |
6473 | ||
6d293983 | 6474 | return ret; |
877d48d5 DV |
6475 | } |
6476 | ||
8cfb3407 VS |
6477 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6478 | struct intel_crtc_state *pipe_config) | |
6479 | { | |
6480 | if (pipe_config->pipe_bpp > 24) | |
6481 | return false; | |
6482 | ||
6483 | /* HSW can handle pixel rate up to cdclk? */ | |
6484 | if (IS_HASWELL(dev_priv->dev)) | |
6485 | return true; | |
6486 | ||
6487 | /* | |
b432e5cf VS |
6488 | * We compare against max which means we must take |
6489 | * the increased cdclk requirement into account when | |
6490 | * calculating the new cdclk. | |
6491 | * | |
6492 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6493 | */ |
6494 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6495 | dev_priv->max_cdclk_freq * 95 / 100; | |
6496 | } | |
6497 | ||
42db64ef | 6498 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6499 | struct intel_crtc_state *pipe_config) |
42db64ef | 6500 | { |
8cfb3407 VS |
6501 | struct drm_device *dev = crtc->base.dev; |
6502 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6503 | ||
d330a953 | 6504 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6505 | hsw_crtc_supports_ips(crtc) && |
6506 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6507 | } |
6508 | ||
a43f6e0f | 6509 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6510 | struct intel_crtc_state *pipe_config) |
79e53945 | 6511 | { |
a43f6e0f | 6512 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6513 | struct drm_i915_private *dev_priv = dev->dev_private; |
2d112de7 | 6514 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6515 | |
ad3a4479 | 6516 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6517 | if (INTEL_INFO(dev)->gen < 4) { |
44913155 | 6518 | int clock_limit = dev_priv->max_cdclk_freq; |
cf532bb2 VS |
6519 | |
6520 | /* | |
6521 | * Enable pixel doubling when the dot clock | |
6522 | * is > 90% of the (display) core speed. | |
6523 | * | |
b397c96b VS |
6524 | * GDG double wide on either pipe, |
6525 | * otherwise pipe A only. | |
cf532bb2 | 6526 | */ |
b397c96b | 6527 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
241bfc38 | 6528 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
ad3a4479 | 6529 | clock_limit *= 2; |
cf532bb2 | 6530 | pipe_config->double_wide = true; |
ad3a4479 VS |
6531 | } |
6532 | ||
241bfc38 | 6533 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
e29c22c0 | 6534 | return -EINVAL; |
2c07245f | 6535 | } |
89749350 | 6536 | |
1d1d0e27 VS |
6537 | /* |
6538 | * Pipe horizontal size must be even in: | |
6539 | * - DVO ganged mode | |
6540 | * - LVDS dual channel mode | |
6541 | * - Double wide pipe | |
6542 | */ | |
a93e255f | 6543 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6544 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6545 | pipe_config->pipe_src_w &= ~1; | |
6546 | ||
8693a824 DL |
6547 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6548 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6549 | */ |
6550 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
6551 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) | |
e29c22c0 | 6552 | return -EINVAL; |
44f46b42 | 6553 | |
f5adf94e | 6554 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6555 | hsw_compute_ips_config(crtc, pipe_config); |
6556 | ||
877d48d5 | 6557 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6558 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6559 | |
cf5a15be | 6560 | return 0; |
79e53945 JB |
6561 | } |
6562 | ||
1652d19e VS |
6563 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6564 | { | |
6565 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6566 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6567 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6568 | uint32_t linkrate; | |
6569 | ||
414355a7 | 6570 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6571 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6572 | |
6573 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6574 | return 540000; | |
6575 | ||
6576 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6577 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6578 | |
71cd8423 DL |
6579 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6580 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6581 | /* vco 8640 */ |
6582 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6583 | case CDCLK_FREQ_450_432: | |
6584 | return 432000; | |
6585 | case CDCLK_FREQ_337_308: | |
6586 | return 308570; | |
6587 | case CDCLK_FREQ_675_617: | |
6588 | return 617140; | |
6589 | default: | |
6590 | WARN(1, "Unknown cd freq selection\n"); | |
6591 | } | |
6592 | } else { | |
6593 | /* vco 8100 */ | |
6594 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6595 | case CDCLK_FREQ_450_432: | |
6596 | return 450000; | |
6597 | case CDCLK_FREQ_337_308: | |
6598 | return 337500; | |
6599 | case CDCLK_FREQ_675_617: | |
6600 | return 675000; | |
6601 | default: | |
6602 | WARN(1, "Unknown cd freq selection\n"); | |
6603 | } | |
6604 | } | |
6605 | ||
6606 | /* error case, do as if DPLL0 isn't enabled */ | |
6607 | return 24000; | |
6608 | } | |
6609 | ||
acd3f3d3 BP |
6610 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6611 | { | |
6612 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6613 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6614 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6615 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6616 | int cdclk; | |
6617 | ||
6618 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6619 | return 19200; | |
6620 | ||
6621 | cdclk = 19200 * pll_ratio / 2; | |
6622 | ||
6623 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6624 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6625 | return cdclk; /* 576MHz or 624MHz */ | |
6626 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6627 | return cdclk * 2 / 3; /* 384MHz */ | |
6628 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6629 | return cdclk / 2; /* 288MHz */ | |
6630 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6631 | return cdclk / 4; /* 144MHz */ | |
6632 | } | |
6633 | ||
6634 | /* error case, do as if DE PLL isn't enabled */ | |
6635 | return 19200; | |
6636 | } | |
6637 | ||
1652d19e VS |
6638 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6639 | { | |
6640 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6641 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6642 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6643 | ||
6644 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6645 | return 800000; | |
6646 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6647 | return 450000; | |
6648 | else if (freq == LCPLL_CLK_FREQ_450) | |
6649 | return 450000; | |
6650 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6651 | return 540000; | |
6652 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6653 | return 337500; | |
6654 | else | |
6655 | return 675000; | |
6656 | } | |
6657 | ||
6658 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6659 | { | |
6660 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6661 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6662 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6663 | ||
6664 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6665 | return 800000; | |
6666 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6667 | return 450000; | |
6668 | else if (freq == LCPLL_CLK_FREQ_450) | |
6669 | return 450000; | |
6670 | else if (IS_HSW_ULT(dev)) | |
6671 | return 337500; | |
6672 | else | |
6673 | return 540000; | |
79e53945 JB |
6674 | } |
6675 | ||
25eb05fc JB |
6676 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6677 | { | |
d197b7d3 | 6678 | struct drm_i915_private *dev_priv = dev->dev_private; |
d197b7d3 VS |
6679 | u32 val; |
6680 | int divider; | |
6681 | ||
6bcda4f0 VS |
6682 | if (dev_priv->hpll_freq == 0) |
6683 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
6684 | ||
a580516d | 6685 | mutex_lock(&dev_priv->sb_lock); |
d197b7d3 | 6686 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
a580516d | 6687 | mutex_unlock(&dev_priv->sb_lock); |
d197b7d3 VS |
6688 | |
6689 | divider = val & DISPLAY_FREQUENCY_VALUES; | |
6690 | ||
7d007f40 VS |
6691 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
6692 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
6693 | "cdclk change in progress\n"); | |
6694 | ||
6bcda4f0 | 6695 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
25eb05fc JB |
6696 | } |
6697 | ||
b37a6434 VS |
6698 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6699 | { | |
6700 | return 450000; | |
6701 | } | |
6702 | ||
e70236a8 JB |
6703 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6704 | { | |
6705 | return 400000; | |
6706 | } | |
79e53945 | 6707 | |
e70236a8 | 6708 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6709 | { |
e907f170 | 6710 | return 333333; |
e70236a8 | 6711 | } |
79e53945 | 6712 | |
e70236a8 JB |
6713 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6714 | { | |
6715 | return 200000; | |
6716 | } | |
79e53945 | 6717 | |
257a7ffc DV |
6718 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6719 | { | |
6720 | u16 gcfgc = 0; | |
6721 | ||
6722 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6723 | ||
6724 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6725 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6726 | return 266667; |
257a7ffc | 6727 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6728 | return 333333; |
257a7ffc | 6729 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6730 | return 444444; |
257a7ffc DV |
6731 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6732 | return 200000; | |
6733 | default: | |
6734 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6735 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6736 | return 133333; |
257a7ffc | 6737 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6738 | return 166667; |
257a7ffc DV |
6739 | } |
6740 | } | |
6741 | ||
e70236a8 JB |
6742 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6743 | { | |
6744 | u16 gcfgc = 0; | |
79e53945 | 6745 | |
e70236a8 JB |
6746 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6747 | ||
6748 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6749 | return 133333; |
e70236a8 JB |
6750 | else { |
6751 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6752 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6753 | return 333333; |
e70236a8 JB |
6754 | default: |
6755 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6756 | return 190000; | |
79e53945 | 6757 | } |
e70236a8 JB |
6758 | } |
6759 | } | |
6760 | ||
6761 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6762 | { | |
e907f170 | 6763 | return 266667; |
e70236a8 JB |
6764 | } |
6765 | ||
1b1d2716 | 6766 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6767 | { |
6768 | u16 hpllcc = 0; | |
1b1d2716 | 6769 | |
65cd2b3f VS |
6770 | /* |
6771 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6772 | * encoding is different :( | |
6773 | * FIXME is this the right way to detect 852GM/852GMV? | |
6774 | */ | |
6775 | if (dev->pdev->revision == 0x1) | |
6776 | return 133333; | |
6777 | ||
1b1d2716 VS |
6778 | pci_bus_read_config_word(dev->pdev->bus, |
6779 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6780 | ||
e70236a8 JB |
6781 | /* Assume that the hardware is in the high speed state. This |
6782 | * should be the default. | |
6783 | */ | |
6784 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6785 | case GC_CLOCK_133_200: | |
1b1d2716 | 6786 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6787 | case GC_CLOCK_100_200: |
6788 | return 200000; | |
6789 | case GC_CLOCK_166_250: | |
6790 | return 250000; | |
6791 | case GC_CLOCK_100_133: | |
e907f170 | 6792 | return 133333; |
1b1d2716 VS |
6793 | case GC_CLOCK_133_266: |
6794 | case GC_CLOCK_133_266_2: | |
6795 | case GC_CLOCK_166_266: | |
6796 | return 266667; | |
e70236a8 | 6797 | } |
79e53945 | 6798 | |
e70236a8 JB |
6799 | /* Shouldn't happen */ |
6800 | return 0; | |
6801 | } | |
79e53945 | 6802 | |
e70236a8 JB |
6803 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6804 | { | |
e907f170 | 6805 | return 133333; |
79e53945 JB |
6806 | } |
6807 | ||
34edce2f VS |
6808 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6809 | { | |
6810 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6811 | static const unsigned int blb_vco[8] = { | |
6812 | [0] = 3200000, | |
6813 | [1] = 4000000, | |
6814 | [2] = 5333333, | |
6815 | [3] = 4800000, | |
6816 | [4] = 6400000, | |
6817 | }; | |
6818 | static const unsigned int pnv_vco[8] = { | |
6819 | [0] = 3200000, | |
6820 | [1] = 4000000, | |
6821 | [2] = 5333333, | |
6822 | [3] = 4800000, | |
6823 | [4] = 2666667, | |
6824 | }; | |
6825 | static const unsigned int cl_vco[8] = { | |
6826 | [0] = 3200000, | |
6827 | [1] = 4000000, | |
6828 | [2] = 5333333, | |
6829 | [3] = 6400000, | |
6830 | [4] = 3333333, | |
6831 | [5] = 3566667, | |
6832 | [6] = 4266667, | |
6833 | }; | |
6834 | static const unsigned int elk_vco[8] = { | |
6835 | [0] = 3200000, | |
6836 | [1] = 4000000, | |
6837 | [2] = 5333333, | |
6838 | [3] = 4800000, | |
6839 | }; | |
6840 | static const unsigned int ctg_vco[8] = { | |
6841 | [0] = 3200000, | |
6842 | [1] = 4000000, | |
6843 | [2] = 5333333, | |
6844 | [3] = 6400000, | |
6845 | [4] = 2666667, | |
6846 | [5] = 4266667, | |
6847 | }; | |
6848 | const unsigned int *vco_table; | |
6849 | unsigned int vco; | |
6850 | uint8_t tmp = 0; | |
6851 | ||
6852 | /* FIXME other chipsets? */ | |
6853 | if (IS_GM45(dev)) | |
6854 | vco_table = ctg_vco; | |
6855 | else if (IS_G4X(dev)) | |
6856 | vco_table = elk_vco; | |
6857 | else if (IS_CRESTLINE(dev)) | |
6858 | vco_table = cl_vco; | |
6859 | else if (IS_PINEVIEW(dev)) | |
6860 | vco_table = pnv_vco; | |
6861 | else if (IS_G33(dev)) | |
6862 | vco_table = blb_vco; | |
6863 | else | |
6864 | return 0; | |
6865 | ||
6866 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6867 | ||
6868 | vco = vco_table[tmp & 0x7]; | |
6869 | if (vco == 0) | |
6870 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6871 | else | |
6872 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6873 | ||
6874 | return vco; | |
6875 | } | |
6876 | ||
6877 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
6878 | { | |
6879 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6880 | uint16_t tmp = 0; | |
6881 | ||
6882 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6883 | ||
6884 | cdclk_sel = (tmp >> 12) & 0x1; | |
6885 | ||
6886 | switch (vco) { | |
6887 | case 2666667: | |
6888 | case 4000000: | |
6889 | case 5333333: | |
6890 | return cdclk_sel ? 333333 : 222222; | |
6891 | case 3200000: | |
6892 | return cdclk_sel ? 320000 : 228571; | |
6893 | default: | |
6894 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
6895 | return 222222; | |
6896 | } | |
6897 | } | |
6898 | ||
6899 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
6900 | { | |
6901 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
6902 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
6903 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
6904 | const uint8_t *div_table; | |
6905 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6906 | uint16_t tmp = 0; | |
6907 | ||
6908 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6909 | ||
6910 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
6911 | ||
6912 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6913 | goto fail; | |
6914 | ||
6915 | switch (vco) { | |
6916 | case 3200000: | |
6917 | div_table = div_3200; | |
6918 | break; | |
6919 | case 4000000: | |
6920 | div_table = div_4000; | |
6921 | break; | |
6922 | case 5333333: | |
6923 | div_table = div_5333; | |
6924 | break; | |
6925 | default: | |
6926 | goto fail; | |
6927 | } | |
6928 | ||
6929 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
6930 | ||
caf4e252 | 6931 | fail: |
34edce2f VS |
6932 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
6933 | return 200000; | |
6934 | } | |
6935 | ||
6936 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
6937 | { | |
6938 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
6939 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
6940 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
6941 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
6942 | const uint8_t *div_table; | |
6943 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6944 | uint16_t tmp = 0; | |
6945 | ||
6946 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6947 | ||
6948 | cdclk_sel = (tmp >> 4) & 0x7; | |
6949 | ||
6950 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6951 | goto fail; | |
6952 | ||
6953 | switch (vco) { | |
6954 | case 3200000: | |
6955 | div_table = div_3200; | |
6956 | break; | |
6957 | case 4000000: | |
6958 | div_table = div_4000; | |
6959 | break; | |
6960 | case 4800000: | |
6961 | div_table = div_4800; | |
6962 | break; | |
6963 | case 5333333: | |
6964 | div_table = div_5333; | |
6965 | break; | |
6966 | default: | |
6967 | goto fail; | |
6968 | } | |
6969 | ||
6970 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
6971 | ||
caf4e252 | 6972 | fail: |
34edce2f VS |
6973 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
6974 | return 190476; | |
6975 | } | |
6976 | ||
2c07245f | 6977 | static void |
a65851af | 6978 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 6979 | { |
a65851af VS |
6980 | while (*num > DATA_LINK_M_N_MASK || |
6981 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
6982 | *num >>= 1; |
6983 | *den >>= 1; | |
6984 | } | |
6985 | } | |
6986 | ||
a65851af VS |
6987 | static void compute_m_n(unsigned int m, unsigned int n, |
6988 | uint32_t *ret_m, uint32_t *ret_n) | |
6989 | { | |
6990 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
6991 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
6992 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
6993 | } | |
6994 | ||
e69d0bc1 DV |
6995 | void |
6996 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
6997 | int pixel_clock, int link_clock, | |
6998 | struct intel_link_m_n *m_n) | |
2c07245f | 6999 | { |
e69d0bc1 | 7000 | m_n->tu = 64; |
a65851af VS |
7001 | |
7002 | compute_m_n(bits_per_pixel * pixel_clock, | |
7003 | link_clock * nlanes * 8, | |
7004 | &m_n->gmch_m, &m_n->gmch_n); | |
7005 | ||
7006 | compute_m_n(pixel_clock, link_clock, | |
7007 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7008 | } |
7009 | ||
a7615030 CW |
7010 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7011 | { | |
d330a953 JN |
7012 | if (i915.panel_use_ssc >= 0) |
7013 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7014 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7015 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7016 | } |
7017 | ||
a93e255f ACO |
7018 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7019 | int num_connectors) | |
c65d77d8 | 7020 | { |
a93e255f | 7021 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7022 | struct drm_i915_private *dev_priv = dev->dev_private; |
7023 | int refclk; | |
7024 | ||
a93e255f ACO |
7025 | WARN_ON(!crtc_state->base.state); |
7026 | ||
5ab7b0b7 | 7027 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7028 | refclk = 100000; |
a93e255f | 7029 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7030 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7031 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7032 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7033 | } else if (!IS_GEN2(dev)) { |
7034 | refclk = 96000; | |
7035 | } else { | |
7036 | refclk = 48000; | |
7037 | } | |
7038 | ||
7039 | return refclk; | |
7040 | } | |
7041 | ||
7429e9d4 | 7042 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7043 | { |
7df00d7a | 7044 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7045 | } |
f47709a9 | 7046 | |
7429e9d4 DV |
7047 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7048 | { | |
7049 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7050 | } |
7051 | ||
f47709a9 | 7052 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7053 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7054 | intel_clock_t *reduced_clock) |
7055 | { | |
f47709a9 | 7056 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7057 | u32 fp, fp2 = 0; |
7058 | ||
7059 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7060 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7061 | if (reduced_clock) |
7429e9d4 | 7062 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7063 | } else { |
190f68c5 | 7064 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7065 | if (reduced_clock) |
7429e9d4 | 7066 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7067 | } |
7068 | ||
190f68c5 | 7069 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7070 | |
f47709a9 | 7071 | crtc->lowfreq_avail = false; |
a93e255f | 7072 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7073 | reduced_clock) { |
190f68c5 | 7074 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7075 | crtc->lowfreq_avail = true; |
a7516a05 | 7076 | } else { |
190f68c5 | 7077 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7078 | } |
7079 | } | |
7080 | ||
5e69f97f CML |
7081 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7082 | pipe) | |
89b667f8 JB |
7083 | { |
7084 | u32 reg_val; | |
7085 | ||
7086 | /* | |
7087 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7088 | * and set it to a reasonable value instead. | |
7089 | */ | |
ab3c759a | 7090 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7091 | reg_val &= 0xffffff00; |
7092 | reg_val |= 0x00000030; | |
ab3c759a | 7093 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7094 | |
ab3c759a | 7095 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7096 | reg_val &= 0x8cffffff; |
7097 | reg_val = 0x8c000000; | |
ab3c759a | 7098 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7099 | |
ab3c759a | 7100 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7101 | reg_val &= 0xffffff00; |
ab3c759a | 7102 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7103 | |
ab3c759a | 7104 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7105 | reg_val &= 0x00ffffff; |
7106 | reg_val |= 0xb0000000; | |
ab3c759a | 7107 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7108 | } |
7109 | ||
b551842d DV |
7110 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7111 | struct intel_link_m_n *m_n) | |
7112 | { | |
7113 | struct drm_device *dev = crtc->base.dev; | |
7114 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7115 | int pipe = crtc->pipe; | |
7116 | ||
e3b95f1e DV |
7117 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7118 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7119 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7120 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7121 | } |
7122 | ||
7123 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7124 | struct intel_link_m_n *m_n, |
7125 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7126 | { |
7127 | struct drm_device *dev = crtc->base.dev; | |
7128 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7129 | int pipe = crtc->pipe; | |
6e3c9717 | 7130 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7131 | |
7132 | if (INTEL_INFO(dev)->gen >= 5) { | |
7133 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7134 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7135 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7136 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7137 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7138 | * for gen < 8) and if DRRS is supported (to make sure the | |
7139 | * registers are not unnecessarily accessed). | |
7140 | */ | |
44395bfe | 7141 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7142 | crtc->config->has_drrs) { |
f769cd24 VK |
7143 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7144 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7145 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7146 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7147 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7148 | } | |
b551842d | 7149 | } else { |
e3b95f1e DV |
7150 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7151 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7152 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7153 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7154 | } |
7155 | } | |
7156 | ||
fe3cd48d | 7157 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7158 | { |
fe3cd48d R |
7159 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7160 | ||
7161 | if (m_n == M1_N1) { | |
7162 | dp_m_n = &crtc->config->dp_m_n; | |
7163 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7164 | } else if (m_n == M2_N2) { | |
7165 | ||
7166 | /* | |
7167 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7168 | * needs to be programmed into M1_N1. | |
7169 | */ | |
7170 | dp_m_n = &crtc->config->dp_m2_n2; | |
7171 | } else { | |
7172 | DRM_ERROR("Unsupported divider value\n"); | |
7173 | return; | |
7174 | } | |
7175 | ||
6e3c9717 ACO |
7176 | if (crtc->config->has_pch_encoder) |
7177 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7178 | else |
fe3cd48d | 7179 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7180 | } |
7181 | ||
251ac862 DV |
7182 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7183 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7184 | { |
7185 | u32 dpll, dpll_md; | |
7186 | ||
7187 | /* | |
7188 | * Enable DPIO clock input. We should never disable the reference | |
7189 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7190 | * on it. | |
7191 | */ | |
60bfe44f VS |
7192 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7193 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7194 | /* We should never disable this, set it here for state tracking */ |
7195 | if (crtc->pipe == PIPE_B) | |
7196 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7197 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7198 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7199 | |
d288f65f | 7200 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7201 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7202 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7203 | } |
7204 | ||
d288f65f | 7205 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7206 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7207 | { |
f47709a9 | 7208 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7209 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7210 | int pipe = crtc->pipe; |
bdd4b6a6 | 7211 | u32 mdiv; |
a0c4da24 | 7212 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7213 | u32 coreclk, reg_val; |
a0c4da24 | 7214 | |
a580516d | 7215 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7216 | |
d288f65f VS |
7217 | bestn = pipe_config->dpll.n; |
7218 | bestm1 = pipe_config->dpll.m1; | |
7219 | bestm2 = pipe_config->dpll.m2; | |
7220 | bestp1 = pipe_config->dpll.p1; | |
7221 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7222 | |
89b667f8 JB |
7223 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7224 | ||
7225 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7226 | if (pipe == PIPE_B) |
5e69f97f | 7227 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7228 | |
7229 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7230 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7231 | |
7232 | /* Disable target IRef on PLL */ | |
ab3c759a | 7233 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7234 | reg_val &= 0x00ffffff; |
ab3c759a | 7235 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7236 | |
7237 | /* Disable fast lock */ | |
ab3c759a | 7238 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7239 | |
7240 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7241 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7242 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7243 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7244 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7245 | |
7246 | /* | |
7247 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7248 | * but we don't support that). | |
7249 | * Note: don't use the DAC post divider as it seems unstable. | |
7250 | */ | |
7251 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7252 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7253 | |
a0c4da24 | 7254 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7255 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7256 | |
89b667f8 | 7257 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7258 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7259 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7260 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7261 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7262 | 0x009f0003); |
89b667f8 | 7263 | else |
ab3c759a | 7264 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7265 | 0x00d0000f); |
7266 | ||
681a8504 | 7267 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7268 | /* Use SSC source */ |
bdd4b6a6 | 7269 | if (pipe == PIPE_A) |
ab3c759a | 7270 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7271 | 0x0df40000); |
7272 | else | |
ab3c759a | 7273 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7274 | 0x0df70000); |
7275 | } else { /* HDMI or VGA */ | |
7276 | /* Use bend source */ | |
bdd4b6a6 | 7277 | if (pipe == PIPE_A) |
ab3c759a | 7278 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7279 | 0x0df70000); |
7280 | else | |
ab3c759a | 7281 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7282 | 0x0df40000); |
7283 | } | |
a0c4da24 | 7284 | |
ab3c759a | 7285 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7286 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7287 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7288 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7289 | coreclk |= 0x01000000; |
ab3c759a | 7290 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7291 | |
ab3c759a | 7292 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7293 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7294 | } |
7295 | ||
251ac862 DV |
7296 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7297 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7298 | { |
60bfe44f VS |
7299 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7300 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7301 | DPLL_VCO_ENABLE; |
7302 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7303 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7304 | |
d288f65f VS |
7305 | pipe_config->dpll_hw_state.dpll_md = |
7306 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7307 | } |
7308 | ||
d288f65f | 7309 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7310 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7311 | { |
7312 | struct drm_device *dev = crtc->base.dev; | |
7313 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7314 | int pipe = crtc->pipe; | |
7315 | int dpll_reg = DPLL(crtc->pipe); | |
7316 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 7317 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7318 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7319 | u32 dpio_val; |
9cbe40c1 | 7320 | int vco; |
9d556c99 | 7321 | |
d288f65f VS |
7322 | bestn = pipe_config->dpll.n; |
7323 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7324 | bestm1 = pipe_config->dpll.m1; | |
7325 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7326 | bestp1 = pipe_config->dpll.p1; | |
7327 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7328 | vco = pipe_config->dpll.vco; |
a945ce7e | 7329 | dpio_val = 0; |
9cbe40c1 | 7330 | loopfilter = 0; |
9d556c99 CML |
7331 | |
7332 | /* | |
7333 | * Enable Refclk and SSC | |
7334 | */ | |
a11b0703 | 7335 | I915_WRITE(dpll_reg, |
d288f65f | 7336 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7337 | |
a580516d | 7338 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7339 | |
9d556c99 CML |
7340 | /* p1 and p2 divider */ |
7341 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7342 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7343 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7344 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7345 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7346 | ||
7347 | /* Feedback post-divider - m2 */ | |
7348 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7349 | ||
7350 | /* Feedback refclk divider - n and m1 */ | |
7351 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7352 | DPIO_CHV_M1_DIV_BY_2 | | |
7353 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7354 | ||
7355 | /* M2 fraction division */ | |
25a25dfc | 7356 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7357 | |
7358 | /* M2 fraction division enable */ | |
a945ce7e VP |
7359 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7360 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7361 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7362 | if (bestm2_frac) | |
7363 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7364 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7365 | |
de3a0fde VP |
7366 | /* Program digital lock detect threshold */ |
7367 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7368 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7369 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7370 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7371 | if (!bestm2_frac) | |
7372 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7373 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7374 | ||
9d556c99 | 7375 | /* Loop filter */ |
9cbe40c1 VP |
7376 | if (vco == 5400000) { |
7377 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7378 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7379 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7380 | tribuf_calcntr = 0x9; | |
7381 | } else if (vco <= 6200000) { | |
7382 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7383 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7384 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7385 | tribuf_calcntr = 0x9; | |
7386 | } else if (vco <= 6480000) { | |
7387 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7388 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7389 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7390 | tribuf_calcntr = 0x8; | |
7391 | } else { | |
7392 | /* Not supported. Apply the same limits as in the max case */ | |
7393 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7394 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7395 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7396 | tribuf_calcntr = 0; | |
7397 | } | |
9d556c99 CML |
7398 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7399 | ||
968040b2 | 7400 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7401 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7402 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7403 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7404 | ||
9d556c99 CML |
7405 | /* AFC Recal */ |
7406 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7407 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7408 | DPIO_AFC_RECAL); | |
7409 | ||
a580516d | 7410 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7411 | } |
7412 | ||
d288f65f VS |
7413 | /** |
7414 | * vlv_force_pll_on - forcibly enable just the PLL | |
7415 | * @dev_priv: i915 private structure | |
7416 | * @pipe: pipe PLL to enable | |
7417 | * @dpll: PLL configuration | |
7418 | * | |
7419 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7420 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7421 | * be enabled. | |
7422 | */ | |
7423 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7424 | const struct dpll *dpll) | |
7425 | { | |
7426 | struct intel_crtc *crtc = | |
7427 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7428 | struct intel_crtc_state pipe_config = { |
a93e255f | 7429 | .base.crtc = &crtc->base, |
d288f65f VS |
7430 | .pixel_multiplier = 1, |
7431 | .dpll = *dpll, | |
7432 | }; | |
7433 | ||
7434 | if (IS_CHERRYVIEW(dev)) { | |
251ac862 | 7435 | chv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7436 | chv_prepare_pll(crtc, &pipe_config); |
7437 | chv_enable_pll(crtc, &pipe_config); | |
7438 | } else { | |
251ac862 | 7439 | vlv_compute_dpll(crtc, &pipe_config); |
d288f65f VS |
7440 | vlv_prepare_pll(crtc, &pipe_config); |
7441 | vlv_enable_pll(crtc, &pipe_config); | |
7442 | } | |
7443 | } | |
7444 | ||
7445 | /** | |
7446 | * vlv_force_pll_off - forcibly disable just the PLL | |
7447 | * @dev_priv: i915 private structure | |
7448 | * @pipe: pipe PLL to disable | |
7449 | * | |
7450 | * Disable the PLL for @pipe. To be used in cases where we need | |
7451 | * the PLL enabled even when @pipe is not going to be enabled. | |
7452 | */ | |
7453 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7454 | { | |
7455 | if (IS_CHERRYVIEW(dev)) | |
7456 | chv_disable_pll(to_i915(dev), pipe); | |
7457 | else | |
7458 | vlv_disable_pll(to_i915(dev), pipe); | |
7459 | } | |
7460 | ||
251ac862 DV |
7461 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7462 | struct intel_crtc_state *crtc_state, | |
7463 | intel_clock_t *reduced_clock, | |
7464 | int num_connectors) | |
eb1cbe48 | 7465 | { |
f47709a9 | 7466 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7467 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7468 | u32 dpll; |
7469 | bool is_sdvo; | |
190f68c5 | 7470 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7471 | |
190f68c5 | 7472 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7473 | |
a93e255f ACO |
7474 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7475 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7476 | |
7477 | dpll = DPLL_VGA_MODE_DIS; | |
7478 | ||
a93e255f | 7479 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7480 | dpll |= DPLLB_MODE_LVDS; |
7481 | else | |
7482 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7483 | |
ef1b460d | 7484 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7485 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7486 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7487 | } |
198a037f DV |
7488 | |
7489 | if (is_sdvo) | |
4a33e48d | 7490 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7491 | |
190f68c5 | 7492 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7493 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7494 | |
7495 | /* compute bitmask from p1 value */ | |
7496 | if (IS_PINEVIEW(dev)) | |
7497 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7498 | else { | |
7499 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7500 | if (IS_G4X(dev) && reduced_clock) | |
7501 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7502 | } | |
7503 | switch (clock->p2) { | |
7504 | case 5: | |
7505 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7506 | break; | |
7507 | case 7: | |
7508 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7509 | break; | |
7510 | case 10: | |
7511 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7512 | break; | |
7513 | case 14: | |
7514 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7515 | break; | |
7516 | } | |
7517 | if (INTEL_INFO(dev)->gen >= 4) | |
7518 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7519 | ||
190f68c5 | 7520 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7521 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7522 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7523 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7524 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7525 | else | |
7526 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7527 | ||
7528 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7529 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7530 | |
eb1cbe48 | 7531 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7532 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7533 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7534 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7535 | } |
7536 | } | |
7537 | ||
251ac862 DV |
7538 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7539 | struct intel_crtc_state *crtc_state, | |
7540 | intel_clock_t *reduced_clock, | |
7541 | int num_connectors) | |
eb1cbe48 | 7542 | { |
f47709a9 | 7543 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7544 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7545 | u32 dpll; |
190f68c5 | 7546 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7547 | |
190f68c5 | 7548 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7549 | |
eb1cbe48 DV |
7550 | dpll = DPLL_VGA_MODE_DIS; |
7551 | ||
a93e255f | 7552 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7553 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7554 | } else { | |
7555 | if (clock->p1 == 2) | |
7556 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7557 | else | |
7558 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7559 | if (clock->p2 == 4) | |
7560 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7561 | } | |
7562 | ||
a93e255f | 7563 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7564 | dpll |= DPLL_DVO_2X_MODE; |
7565 | ||
a93e255f | 7566 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7567 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7568 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7569 | else | |
7570 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7571 | ||
7572 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7573 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7574 | } |
7575 | ||
8a654f3b | 7576 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7577 | { |
7578 | struct drm_device *dev = intel_crtc->base.dev; | |
7579 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7580 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7581 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
8a654f3b | 7582 | struct drm_display_mode *adjusted_mode = |
6e3c9717 | 7583 | &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7584 | uint32_t crtc_vtotal, crtc_vblank_end; |
7585 | int vsyncshift = 0; | |
4d8a62ea DV |
7586 | |
7587 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7588 | * the hw state checker will get angry at the mismatch. */ | |
7589 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7590 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7591 | |
609aeaca | 7592 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7593 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7594 | crtc_vtotal -= 1; |
7595 | crtc_vblank_end -= 1; | |
609aeaca | 7596 | |
409ee761 | 7597 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7598 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7599 | else | |
7600 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7601 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7602 | if (vsyncshift < 0) |
7603 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7604 | } |
7605 | ||
7606 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7607 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7608 | |
fe2b8f9d | 7609 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7610 | (adjusted_mode->crtc_hdisplay - 1) | |
7611 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7612 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7613 | (adjusted_mode->crtc_hblank_start - 1) | |
7614 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7615 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7616 | (adjusted_mode->crtc_hsync_start - 1) | |
7617 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7618 | ||
fe2b8f9d | 7619 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7620 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7621 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7622 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7623 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7624 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7625 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7626 | (adjusted_mode->crtc_vsync_start - 1) | |
7627 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7628 | ||
b5e508d4 PZ |
7629 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7630 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7631 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7632 | * bits. */ | |
7633 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7634 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7635 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7636 | ||
b0e77b9c PZ |
7637 | /* pipesrc controls the size that is scaled from, which should |
7638 | * always be the user's requested size. | |
7639 | */ | |
7640 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7641 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7642 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7643 | } |
7644 | ||
1bd1bd80 | 7645 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7646 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7647 | { |
7648 | struct drm_device *dev = crtc->base.dev; | |
7649 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7650 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7651 | uint32_t tmp; | |
7652 | ||
7653 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7654 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7655 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7656 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7657 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7658 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7659 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7660 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7661 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7662 | |
7663 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7664 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7665 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7666 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7667 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7668 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7669 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7670 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7671 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7672 | |
7673 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7674 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7675 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7676 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7677 | } |
7678 | ||
7679 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7680 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7681 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7682 | ||
2d112de7 ACO |
7683 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7684 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7685 | } |
7686 | ||
f6a83288 | 7687 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7688 | struct intel_crtc_state *pipe_config) |
babea61d | 7689 | { |
2d112de7 ACO |
7690 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7691 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7692 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7693 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7694 | |
2d112de7 ACO |
7695 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7696 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7697 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7698 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7699 | |
2d112de7 | 7700 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7701 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7702 | |
2d112de7 ACO |
7703 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7704 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7705 | |
7706 | mode->hsync = drm_mode_hsync(mode); | |
7707 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7708 | drm_mode_set_name(mode); | |
babea61d JB |
7709 | } |
7710 | ||
84b046f3 DV |
7711 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7712 | { | |
7713 | struct drm_device *dev = intel_crtc->base.dev; | |
7714 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7715 | uint32_t pipeconf; | |
7716 | ||
9f11a9e4 | 7717 | pipeconf = 0; |
84b046f3 | 7718 | |
b6b5d049 VS |
7719 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7720 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7721 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7722 | |
6e3c9717 | 7723 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7724 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7725 | |
ff9ce46e DV |
7726 | /* only g4x and later have fancy bpc/dither controls */ |
7727 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7728 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7729 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7730 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7731 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7732 | |
6e3c9717 | 7733 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7734 | case 18: |
7735 | pipeconf |= PIPECONF_6BPC; | |
7736 | break; | |
7737 | case 24: | |
7738 | pipeconf |= PIPECONF_8BPC; | |
7739 | break; | |
7740 | case 30: | |
7741 | pipeconf |= PIPECONF_10BPC; | |
7742 | break; | |
7743 | default: | |
7744 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7745 | BUG(); | |
84b046f3 DV |
7746 | } |
7747 | } | |
7748 | ||
7749 | if (HAS_PIPE_CXSR(dev)) { | |
7750 | if (intel_crtc->lowfreq_avail) { | |
7751 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7752 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7753 | } else { | |
7754 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7755 | } |
7756 | } | |
7757 | ||
6e3c9717 | 7758 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7759 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7760 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7761 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7762 | else | |
7763 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7764 | } else | |
84b046f3 DV |
7765 | pipeconf |= PIPECONF_PROGRESSIVE; |
7766 | ||
6e3c9717 | 7767 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7768 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7769 | |
84b046f3 DV |
7770 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7771 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7772 | } | |
7773 | ||
190f68c5 ACO |
7774 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7775 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7776 | { |
c7653199 | 7777 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7778 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7779 | int refclk, num_connectors = 0; |
c329a4ec DV |
7780 | intel_clock_t clock; |
7781 | bool ok; | |
7782 | bool is_dsi = false; | |
5eddb70b | 7783 | struct intel_encoder *encoder; |
d4906093 | 7784 | const intel_limit_t *limit; |
55bb9992 | 7785 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7786 | struct drm_connector *connector; |
55bb9992 ACO |
7787 | struct drm_connector_state *connector_state; |
7788 | int i; | |
79e53945 | 7789 | |
dd3cd74a ACO |
7790 | memset(&crtc_state->dpll_hw_state, 0, |
7791 | sizeof(crtc_state->dpll_hw_state)); | |
7792 | ||
da3ced29 | 7793 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7794 | if (connector_state->crtc != &crtc->base) |
7795 | continue; | |
7796 | ||
7797 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7798 | ||
5eddb70b | 7799 | switch (encoder->type) { |
e9fd1c02 JN |
7800 | case INTEL_OUTPUT_DSI: |
7801 | is_dsi = true; | |
7802 | break; | |
6847d71b PZ |
7803 | default: |
7804 | break; | |
79e53945 | 7805 | } |
43565a06 | 7806 | |
c751ce4f | 7807 | num_connectors++; |
79e53945 JB |
7808 | } |
7809 | ||
f2335330 | 7810 | if (is_dsi) |
5b18e57c | 7811 | return 0; |
f2335330 | 7812 | |
190f68c5 | 7813 | if (!crtc_state->clock_set) { |
a93e255f | 7814 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7815 | |
e9fd1c02 JN |
7816 | /* |
7817 | * Returns a set of divisors for the desired target clock with | |
7818 | * the given refclk, or FALSE. The returned values represent | |
7819 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7820 | * 2) / p1 / p2. | |
7821 | */ | |
a93e255f ACO |
7822 | limit = intel_limit(crtc_state, refclk); |
7823 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7824 | crtc_state->port_clock, |
e9fd1c02 | 7825 | refclk, NULL, &clock); |
f2335330 | 7826 | if (!ok) { |
e9fd1c02 JN |
7827 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7828 | return -EINVAL; | |
7829 | } | |
79e53945 | 7830 | |
f2335330 | 7831 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
7832 | crtc_state->dpll.n = clock.n; |
7833 | crtc_state->dpll.m1 = clock.m1; | |
7834 | crtc_state->dpll.m2 = clock.m2; | |
7835 | crtc_state->dpll.p1 = clock.p1; | |
7836 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7837 | } |
7026d4ac | 7838 | |
e9fd1c02 | 7839 | if (IS_GEN2(dev)) { |
c329a4ec | 7840 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7841 | num_connectors); |
9d556c99 | 7842 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 7843 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7844 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 7845 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 7846 | } else { |
c329a4ec | 7847 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 7848 | num_connectors); |
e9fd1c02 | 7849 | } |
79e53945 | 7850 | |
c8f7a0db | 7851 | return 0; |
f564048e EA |
7852 | } |
7853 | ||
2fa2fe9a | 7854 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7855 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7856 | { |
7857 | struct drm_device *dev = crtc->base.dev; | |
7858 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7859 | uint32_t tmp; | |
7860 | ||
dc9e7dec VS |
7861 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7862 | return; | |
7863 | ||
2fa2fe9a | 7864 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7865 | if (!(tmp & PFIT_ENABLE)) |
7866 | return; | |
2fa2fe9a | 7867 | |
06922821 | 7868 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7869 | if (INTEL_INFO(dev)->gen < 4) { |
7870 | if (crtc->pipe != PIPE_B) | |
7871 | return; | |
2fa2fe9a DV |
7872 | } else { |
7873 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7874 | return; | |
7875 | } | |
7876 | ||
06922821 | 7877 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
7878 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
7879 | if (INTEL_INFO(dev)->gen < 5) | |
7880 | pipe_config->gmch_pfit.lvds_border_bits = | |
7881 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
7882 | } | |
7883 | ||
acbec814 | 7884 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7885 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7886 | { |
7887 | struct drm_device *dev = crtc->base.dev; | |
7888 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7889 | int pipe = pipe_config->cpu_transcoder; | |
7890 | intel_clock_t clock; | |
7891 | u32 mdiv; | |
662c6ecb | 7892 | int refclk = 100000; |
acbec814 | 7893 | |
f573de5a SK |
7894 | /* In case of MIPI DPLL will not even be used */ |
7895 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
7896 | return; | |
7897 | ||
a580516d | 7898 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 7899 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 7900 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
7901 | |
7902 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7903 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7904 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7905 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7906 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7907 | ||
dccbea3b | 7908 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
7909 | } |
7910 | ||
5724dbd1 DL |
7911 | static void |
7912 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7913 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7914 | { |
7915 | struct drm_device *dev = crtc->base.dev; | |
7916 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7917 | u32 val, base, offset; | |
7918 | int pipe = crtc->pipe, plane = crtc->plane; | |
7919 | int fourcc, pixel_format; | |
6761dd31 | 7920 | unsigned int aligned_height; |
b113d5ee | 7921 | struct drm_framebuffer *fb; |
1b842c89 | 7922 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7923 | |
42a7b088 DL |
7924 | val = I915_READ(DSPCNTR(plane)); |
7925 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7926 | return; | |
7927 | ||
d9806c9f | 7928 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7929 | if (!intel_fb) { |
1ad292b5 JB |
7930 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7931 | return; | |
7932 | } | |
7933 | ||
1b842c89 DL |
7934 | fb = &intel_fb->base; |
7935 | ||
18c5247e DV |
7936 | if (INTEL_INFO(dev)->gen >= 4) { |
7937 | if (val & DISPPLANE_TILED) { | |
49af449b | 7938 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
7939 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
7940 | } | |
7941 | } | |
1ad292b5 JB |
7942 | |
7943 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 7944 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
7945 | fb->pixel_format = fourcc; |
7946 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
7947 | |
7948 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 7949 | if (plane_config->tiling) |
1ad292b5 JB |
7950 | offset = I915_READ(DSPTILEOFF(plane)); |
7951 | else | |
7952 | offset = I915_READ(DSPLINOFF(plane)); | |
7953 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
7954 | } else { | |
7955 | base = I915_READ(DSPADDR(plane)); | |
7956 | } | |
7957 | plane_config->base = base; | |
7958 | ||
7959 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
7960 | fb->width = ((val >> 16) & 0xfff) + 1; |
7961 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
7962 | |
7963 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 7964 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 7965 | |
b113d5ee | 7966 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
7967 | fb->pixel_format, |
7968 | fb->modifier[0]); | |
1ad292b5 | 7969 | |
f37b5c2b | 7970 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 7971 | |
2844a921 DL |
7972 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
7973 | pipe_name(pipe), plane, fb->width, fb->height, | |
7974 | fb->bits_per_pixel, base, fb->pitches[0], | |
7975 | plane_config->size); | |
1ad292b5 | 7976 | |
2d14030b | 7977 | plane_config->fb = intel_fb; |
1ad292b5 JB |
7978 | } |
7979 | ||
70b23a98 | 7980 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7981 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
7982 | { |
7983 | struct drm_device *dev = crtc->base.dev; | |
7984 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7985 | int pipe = pipe_config->cpu_transcoder; | |
7986 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
7987 | intel_clock_t clock; | |
0d7b6b11 | 7988 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
7989 | int refclk = 100000; |
7990 | ||
a580516d | 7991 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
7992 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
7993 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
7994 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
7995 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 7996 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 7997 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
7998 | |
7999 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8000 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8001 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8002 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8003 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8004 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8005 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8006 | ||
dccbea3b | 8007 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8008 | } |
8009 | ||
0e8ffe1b | 8010 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8011 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8012 | { |
8013 | struct drm_device *dev = crtc->base.dev; | |
8014 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8015 | uint32_t tmp; | |
8016 | ||
f458ebbc DV |
8017 | if (!intel_display_power_is_enabled(dev_priv, |
8018 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8019 | return false; |
8020 | ||
e143a21c | 8021 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8022 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8023 | |
0e8ffe1b DV |
8024 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8025 | if (!(tmp & PIPECONF_ENABLE)) | |
8026 | return false; | |
8027 | ||
42571aef VS |
8028 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8029 | switch (tmp & PIPECONF_BPC_MASK) { | |
8030 | case PIPECONF_6BPC: | |
8031 | pipe_config->pipe_bpp = 18; | |
8032 | break; | |
8033 | case PIPECONF_8BPC: | |
8034 | pipe_config->pipe_bpp = 24; | |
8035 | break; | |
8036 | case PIPECONF_10BPC: | |
8037 | pipe_config->pipe_bpp = 30; | |
8038 | break; | |
8039 | default: | |
8040 | break; | |
8041 | } | |
8042 | } | |
8043 | ||
b5a9fa09 DV |
8044 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8045 | pipe_config->limited_color_range = true; | |
8046 | ||
282740f7 VS |
8047 | if (INTEL_INFO(dev)->gen < 4) |
8048 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8049 | ||
1bd1bd80 DV |
8050 | intel_get_pipe_timings(crtc, pipe_config); |
8051 | ||
2fa2fe9a DV |
8052 | i9xx_get_pfit_config(crtc, pipe_config); |
8053 | ||
6c49f241 DV |
8054 | if (INTEL_INFO(dev)->gen >= 4) { |
8055 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8056 | pipe_config->pixel_multiplier = | |
8057 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8058 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8059 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8060 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8061 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8062 | pipe_config->pixel_multiplier = | |
8063 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8064 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8065 | } else { | |
8066 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8067 | * port and will be fixed up in the encoder->get_config | |
8068 | * function. */ | |
8069 | pipe_config->pixel_multiplier = 1; | |
8070 | } | |
8bcc2795 DV |
8071 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8072 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8073 | /* |
8074 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8075 | * on 830. Filter it out here so that we don't | |
8076 | * report errors due to that. | |
8077 | */ | |
8078 | if (IS_I830(dev)) | |
8079 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8080 | ||
8bcc2795 DV |
8081 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8082 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8083 | } else { |
8084 | /* Mask out read-only status bits. */ | |
8085 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8086 | DPLL_PORTC_READY_MASK | | |
8087 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8088 | } |
6c49f241 | 8089 | |
70b23a98 VS |
8090 | if (IS_CHERRYVIEW(dev)) |
8091 | chv_crtc_clock_get(crtc, pipe_config); | |
8092 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8093 | vlv_crtc_clock_get(crtc, pipe_config); |
8094 | else | |
8095 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8096 | |
0f64614d VS |
8097 | /* |
8098 | * Normally the dotclock is filled in by the encoder .get_config() | |
8099 | * but in case the pipe is enabled w/o any ports we need a sane | |
8100 | * default. | |
8101 | */ | |
8102 | pipe_config->base.adjusted_mode.crtc_clock = | |
8103 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8104 | ||
0e8ffe1b DV |
8105 | return true; |
8106 | } | |
8107 | ||
dde86e2d | 8108 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8109 | { |
8110 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8111 | struct intel_encoder *encoder; |
74cfd7ac | 8112 | u32 val, final; |
13d83a67 | 8113 | bool has_lvds = false; |
199e5d79 | 8114 | bool has_cpu_edp = false; |
199e5d79 | 8115 | bool has_panel = false; |
99eb6a01 KP |
8116 | bool has_ck505 = false; |
8117 | bool can_ssc = false; | |
13d83a67 JB |
8118 | |
8119 | /* We need to take the global config into account */ | |
b2784e15 | 8120 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8121 | switch (encoder->type) { |
8122 | case INTEL_OUTPUT_LVDS: | |
8123 | has_panel = true; | |
8124 | has_lvds = true; | |
8125 | break; | |
8126 | case INTEL_OUTPUT_EDP: | |
8127 | has_panel = true; | |
2de6905f | 8128 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8129 | has_cpu_edp = true; |
8130 | break; | |
6847d71b PZ |
8131 | default: |
8132 | break; | |
13d83a67 JB |
8133 | } |
8134 | } | |
8135 | ||
99eb6a01 | 8136 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8137 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8138 | can_ssc = has_ck505; |
8139 | } else { | |
8140 | has_ck505 = false; | |
8141 | can_ssc = true; | |
8142 | } | |
8143 | ||
2de6905f ID |
8144 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8145 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8146 | |
8147 | /* Ironlake: try to setup display ref clock before DPLL | |
8148 | * enabling. This is only under driver's control after | |
8149 | * PCH B stepping, previous chipset stepping should be | |
8150 | * ignoring this setting. | |
8151 | */ | |
74cfd7ac CW |
8152 | val = I915_READ(PCH_DREF_CONTROL); |
8153 | ||
8154 | /* As we must carefully and slowly disable/enable each source in turn, | |
8155 | * compute the final state we want first and check if we need to | |
8156 | * make any changes at all. | |
8157 | */ | |
8158 | final = val; | |
8159 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8160 | if (has_ck505) | |
8161 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8162 | else | |
8163 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8164 | ||
8165 | final &= ~DREF_SSC_SOURCE_MASK; | |
8166 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8167 | final &= ~DREF_SSC1_ENABLE; | |
8168 | ||
8169 | if (has_panel) { | |
8170 | final |= DREF_SSC_SOURCE_ENABLE; | |
8171 | ||
8172 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8173 | final |= DREF_SSC1_ENABLE; | |
8174 | ||
8175 | if (has_cpu_edp) { | |
8176 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8177 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8178 | else | |
8179 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8180 | } else | |
8181 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8182 | } else { | |
8183 | final |= DREF_SSC_SOURCE_DISABLE; | |
8184 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8185 | } | |
8186 | ||
8187 | if (final == val) | |
8188 | return; | |
8189 | ||
13d83a67 | 8190 | /* Always enable nonspread source */ |
74cfd7ac | 8191 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8192 | |
99eb6a01 | 8193 | if (has_ck505) |
74cfd7ac | 8194 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8195 | else |
74cfd7ac | 8196 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8197 | |
199e5d79 | 8198 | if (has_panel) { |
74cfd7ac CW |
8199 | val &= ~DREF_SSC_SOURCE_MASK; |
8200 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8201 | |
199e5d79 | 8202 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8203 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8204 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8205 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8206 | } else |
74cfd7ac | 8207 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8208 | |
8209 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8210 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8211 | POSTING_READ(PCH_DREF_CONTROL); |
8212 | udelay(200); | |
8213 | ||
74cfd7ac | 8214 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8215 | |
8216 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8217 | if (has_cpu_edp) { |
99eb6a01 | 8218 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8219 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8220 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8221 | } else |
74cfd7ac | 8222 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8223 | } else |
74cfd7ac | 8224 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8225 | |
74cfd7ac | 8226 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8227 | POSTING_READ(PCH_DREF_CONTROL); |
8228 | udelay(200); | |
8229 | } else { | |
8230 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8231 | ||
74cfd7ac | 8232 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8233 | |
8234 | /* Turn off CPU output */ | |
74cfd7ac | 8235 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8236 | |
74cfd7ac | 8237 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8238 | POSTING_READ(PCH_DREF_CONTROL); |
8239 | udelay(200); | |
8240 | ||
8241 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8242 | val &= ~DREF_SSC_SOURCE_MASK; |
8243 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8244 | |
8245 | /* Turn off SSC1 */ | |
74cfd7ac | 8246 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8247 | |
74cfd7ac | 8248 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8249 | POSTING_READ(PCH_DREF_CONTROL); |
8250 | udelay(200); | |
8251 | } | |
74cfd7ac CW |
8252 | |
8253 | BUG_ON(val != final); | |
13d83a67 JB |
8254 | } |
8255 | ||
f31f2d55 | 8256 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8257 | { |
f31f2d55 | 8258 | uint32_t tmp; |
dde86e2d | 8259 | |
0ff066a9 PZ |
8260 | tmp = I915_READ(SOUTH_CHICKEN2); |
8261 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8262 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8263 | |
0ff066a9 PZ |
8264 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8265 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8266 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8267 | |
0ff066a9 PZ |
8268 | tmp = I915_READ(SOUTH_CHICKEN2); |
8269 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8270 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8271 | |
0ff066a9 PZ |
8272 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8273 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8274 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8275 | } |
8276 | ||
8277 | /* WaMPhyProgramming:hsw */ | |
8278 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8279 | { | |
8280 | uint32_t tmp; | |
dde86e2d PZ |
8281 | |
8282 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8283 | tmp &= ~(0xFF << 24); | |
8284 | tmp |= (0x12 << 24); | |
8285 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8286 | ||
dde86e2d PZ |
8287 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8288 | tmp |= (1 << 11); | |
8289 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8290 | ||
8291 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8292 | tmp |= (1 << 11); | |
8293 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8294 | ||
dde86e2d PZ |
8295 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8296 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8297 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8298 | ||
8299 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8300 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8301 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8302 | ||
0ff066a9 PZ |
8303 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8304 | tmp &= ~(7 << 13); | |
8305 | tmp |= (5 << 13); | |
8306 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8307 | |
0ff066a9 PZ |
8308 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8309 | tmp &= ~(7 << 13); | |
8310 | tmp |= (5 << 13); | |
8311 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8312 | |
8313 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8314 | tmp &= ~0xFF; | |
8315 | tmp |= 0x1C; | |
8316 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8317 | ||
8318 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8319 | tmp &= ~0xFF; | |
8320 | tmp |= 0x1C; | |
8321 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8322 | ||
8323 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8324 | tmp &= ~(0xFF << 16); | |
8325 | tmp |= (0x1C << 16); | |
8326 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8327 | ||
8328 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8329 | tmp &= ~(0xFF << 16); | |
8330 | tmp |= (0x1C << 16); | |
8331 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8332 | ||
0ff066a9 PZ |
8333 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8334 | tmp |= (1 << 27); | |
8335 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8336 | |
0ff066a9 PZ |
8337 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8338 | tmp |= (1 << 27); | |
8339 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8340 | |
0ff066a9 PZ |
8341 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8342 | tmp &= ~(0xF << 28); | |
8343 | tmp |= (4 << 28); | |
8344 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8345 | |
0ff066a9 PZ |
8346 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8347 | tmp &= ~(0xF << 28); | |
8348 | tmp |= (4 << 28); | |
8349 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8350 | } |
8351 | ||
2fa86a1f PZ |
8352 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8353 | * Programming" based on the parameters passed: | |
8354 | * - Sequence to enable CLKOUT_DP | |
8355 | * - Sequence to enable CLKOUT_DP without spread | |
8356 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8357 | */ | |
8358 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8359 | bool with_fdi) | |
f31f2d55 PZ |
8360 | { |
8361 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8362 | uint32_t reg, tmp; |
8363 | ||
8364 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8365 | with_spread = true; | |
c2699524 | 8366 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8367 | with_fdi = false; |
f31f2d55 | 8368 | |
a580516d | 8369 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8370 | |
8371 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8372 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8373 | tmp |= SBI_SSCCTL_PATHALT; | |
8374 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8375 | ||
8376 | udelay(24); | |
8377 | ||
2fa86a1f PZ |
8378 | if (with_spread) { |
8379 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8380 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8381 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8382 | |
2fa86a1f PZ |
8383 | if (with_fdi) { |
8384 | lpt_reset_fdi_mphy(dev_priv); | |
8385 | lpt_program_fdi_mphy(dev_priv); | |
8386 | } | |
8387 | } | |
dde86e2d | 8388 | |
c2699524 | 8389 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8390 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8391 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8392 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8393 | |
a580516d | 8394 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8395 | } |
8396 | ||
47701c3b PZ |
8397 | /* Sequence to disable CLKOUT_DP */ |
8398 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8399 | { | |
8400 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8401 | uint32_t reg, tmp; | |
8402 | ||
a580516d | 8403 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8404 | |
c2699524 | 8405 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8406 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8407 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8408 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8409 | ||
8410 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8411 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8412 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8413 | tmp |= SBI_SSCCTL_PATHALT; | |
8414 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8415 | udelay(32); | |
8416 | } | |
8417 | tmp |= SBI_SSCCTL_DISABLE; | |
8418 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8419 | } | |
8420 | ||
a580516d | 8421 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8422 | } |
8423 | ||
bf8fa3d3 PZ |
8424 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8425 | { | |
bf8fa3d3 PZ |
8426 | struct intel_encoder *encoder; |
8427 | bool has_vga = false; | |
8428 | ||
b2784e15 | 8429 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8430 | switch (encoder->type) { |
8431 | case INTEL_OUTPUT_ANALOG: | |
8432 | has_vga = true; | |
8433 | break; | |
6847d71b PZ |
8434 | default: |
8435 | break; | |
bf8fa3d3 PZ |
8436 | } |
8437 | } | |
8438 | ||
47701c3b PZ |
8439 | if (has_vga) |
8440 | lpt_enable_clkout_dp(dev, true, true); | |
8441 | else | |
8442 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8443 | } |
8444 | ||
dde86e2d PZ |
8445 | /* |
8446 | * Initialize reference clocks when the driver loads | |
8447 | */ | |
8448 | void intel_init_pch_refclk(struct drm_device *dev) | |
8449 | { | |
8450 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8451 | ironlake_init_pch_refclk(dev); | |
8452 | else if (HAS_PCH_LPT(dev)) | |
8453 | lpt_init_pch_refclk(dev); | |
8454 | } | |
8455 | ||
55bb9992 | 8456 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8457 | { |
55bb9992 | 8458 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8459 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8460 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8461 | struct drm_connector *connector; |
55bb9992 | 8462 | struct drm_connector_state *connector_state; |
d9d444cb | 8463 | struct intel_encoder *encoder; |
55bb9992 | 8464 | int num_connectors = 0, i; |
d9d444cb JB |
8465 | bool is_lvds = false; |
8466 | ||
da3ced29 | 8467 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8468 | if (connector_state->crtc != crtc_state->base.crtc) |
8469 | continue; | |
8470 | ||
8471 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8472 | ||
d9d444cb JB |
8473 | switch (encoder->type) { |
8474 | case INTEL_OUTPUT_LVDS: | |
8475 | is_lvds = true; | |
8476 | break; | |
6847d71b PZ |
8477 | default: |
8478 | break; | |
d9d444cb JB |
8479 | } |
8480 | num_connectors++; | |
8481 | } | |
8482 | ||
8483 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8484 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8485 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8486 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8487 | } |
8488 | ||
8489 | return 120000; | |
8490 | } | |
8491 | ||
6ff93609 | 8492 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8493 | { |
c8203565 | 8494 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8495 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8496 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8497 | uint32_t val; |
8498 | ||
78114071 | 8499 | val = 0; |
c8203565 | 8500 | |
6e3c9717 | 8501 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8502 | case 18: |
dfd07d72 | 8503 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8504 | break; |
8505 | case 24: | |
dfd07d72 | 8506 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8507 | break; |
8508 | case 30: | |
dfd07d72 | 8509 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8510 | break; |
8511 | case 36: | |
dfd07d72 | 8512 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8513 | break; |
8514 | default: | |
cc769b62 PZ |
8515 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8516 | BUG(); | |
c8203565 PZ |
8517 | } |
8518 | ||
6e3c9717 | 8519 | if (intel_crtc->config->dither) |
c8203565 PZ |
8520 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8521 | ||
6e3c9717 | 8522 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8523 | val |= PIPECONF_INTERLACED_ILK; |
8524 | else | |
8525 | val |= PIPECONF_PROGRESSIVE; | |
8526 | ||
6e3c9717 | 8527 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8528 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8529 | |
c8203565 PZ |
8530 | I915_WRITE(PIPECONF(pipe), val); |
8531 | POSTING_READ(PIPECONF(pipe)); | |
8532 | } | |
8533 | ||
86d3efce VS |
8534 | /* |
8535 | * Set up the pipe CSC unit. | |
8536 | * | |
8537 | * Currently only full range RGB to limited range RGB conversion | |
8538 | * is supported, but eventually this should handle various | |
8539 | * RGB<->YCbCr scenarios as well. | |
8540 | */ | |
50f3b016 | 8541 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8542 | { |
8543 | struct drm_device *dev = crtc->dev; | |
8544 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8545 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8546 | int pipe = intel_crtc->pipe; | |
8547 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8548 | ||
8549 | /* | |
8550 | * TODO: Check what kind of values actually come out of the pipe | |
8551 | * with these coeff/postoff values and adjust to get the best | |
8552 | * accuracy. Perhaps we even need to take the bpc value into | |
8553 | * consideration. | |
8554 | */ | |
8555 | ||
6e3c9717 | 8556 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8557 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8558 | ||
8559 | /* | |
8560 | * GY/GU and RY/RU should be the other way around according | |
8561 | * to BSpec, but reality doesn't agree. Just set them up in | |
8562 | * a way that results in the correct picture. | |
8563 | */ | |
8564 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8565 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8566 | ||
8567 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8568 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8569 | ||
8570 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8571 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8572 | ||
8573 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8574 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8575 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8576 | ||
8577 | if (INTEL_INFO(dev)->gen > 6) { | |
8578 | uint16_t postoff = 0; | |
8579 | ||
6e3c9717 | 8580 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8581 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8582 | |
8583 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8584 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8585 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8586 | ||
8587 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8588 | } else { | |
8589 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8590 | ||
6e3c9717 | 8591 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8592 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8593 | ||
8594 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8595 | } | |
8596 | } | |
8597 | ||
6ff93609 | 8598 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8599 | { |
756f85cf PZ |
8600 | struct drm_device *dev = crtc->dev; |
8601 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8602 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8603 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8604 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8605 | uint32_t val; |
8606 | ||
3eff4faa | 8607 | val = 0; |
ee2b0b38 | 8608 | |
6e3c9717 | 8609 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8610 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8611 | ||
6e3c9717 | 8612 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8613 | val |= PIPECONF_INTERLACED_ILK; |
8614 | else | |
8615 | val |= PIPECONF_PROGRESSIVE; | |
8616 | ||
702e7a56 PZ |
8617 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8618 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8619 | |
8620 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8621 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8622 | |
3cdf122c | 8623 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8624 | val = 0; |
8625 | ||
6e3c9717 | 8626 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8627 | case 18: |
8628 | val |= PIPEMISC_DITHER_6_BPC; | |
8629 | break; | |
8630 | case 24: | |
8631 | val |= PIPEMISC_DITHER_8_BPC; | |
8632 | break; | |
8633 | case 30: | |
8634 | val |= PIPEMISC_DITHER_10_BPC; | |
8635 | break; | |
8636 | case 36: | |
8637 | val |= PIPEMISC_DITHER_12_BPC; | |
8638 | break; | |
8639 | default: | |
8640 | /* Case prevented by pipe_config_set_bpp. */ | |
8641 | BUG(); | |
8642 | } | |
8643 | ||
6e3c9717 | 8644 | if (intel_crtc->config->dither) |
756f85cf PZ |
8645 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8646 | ||
8647 | I915_WRITE(PIPEMISC(pipe), val); | |
8648 | } | |
ee2b0b38 PZ |
8649 | } |
8650 | ||
6591c6e4 | 8651 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8652 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8653 | intel_clock_t *clock, |
8654 | bool *has_reduced_clock, | |
8655 | intel_clock_t *reduced_clock) | |
8656 | { | |
8657 | struct drm_device *dev = crtc->dev; | |
8658 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8659 | int refclk; |
d4906093 | 8660 | const intel_limit_t *limit; |
c329a4ec | 8661 | bool ret; |
79e53945 | 8662 | |
55bb9992 | 8663 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8664 | |
d4906093 ML |
8665 | /* |
8666 | * Returns a set of divisors for the desired target clock with the given | |
8667 | * refclk, or FALSE. The returned values represent the clock equation: | |
8668 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8669 | */ | |
a93e255f ACO |
8670 | limit = intel_limit(crtc_state, refclk); |
8671 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8672 | crtc_state->port_clock, |
ee9300bb | 8673 | refclk, NULL, clock); |
6591c6e4 PZ |
8674 | if (!ret) |
8675 | return false; | |
cda4b7d3 | 8676 | |
6591c6e4 PZ |
8677 | return true; |
8678 | } | |
8679 | ||
d4b1931c PZ |
8680 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8681 | { | |
8682 | /* | |
8683 | * Account for spread spectrum to avoid | |
8684 | * oversubscribing the link. Max center spread | |
8685 | * is 2.5%; use 5% for safety's sake. | |
8686 | */ | |
8687 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8688 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8689 | } |
8690 | ||
7429e9d4 | 8691 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8692 | { |
7429e9d4 | 8693 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8694 | } |
8695 | ||
de13a2e3 | 8696 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8697 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8698 | u32 *fp, |
9a7c7890 | 8699 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8700 | { |
de13a2e3 | 8701 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8702 | struct drm_device *dev = crtc->dev; |
8703 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8704 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8705 | struct drm_connector *connector; |
55bb9992 ACO |
8706 | struct drm_connector_state *connector_state; |
8707 | struct intel_encoder *encoder; | |
de13a2e3 | 8708 | uint32_t dpll; |
55bb9992 | 8709 | int factor, num_connectors = 0, i; |
09ede541 | 8710 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8711 | |
da3ced29 | 8712 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8713 | if (connector_state->crtc != crtc_state->base.crtc) |
8714 | continue; | |
8715 | ||
8716 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8717 | ||
8718 | switch (encoder->type) { | |
79e53945 JB |
8719 | case INTEL_OUTPUT_LVDS: |
8720 | is_lvds = true; | |
8721 | break; | |
8722 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8723 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8724 | is_sdvo = true; |
79e53945 | 8725 | break; |
6847d71b PZ |
8726 | default: |
8727 | break; | |
79e53945 | 8728 | } |
43565a06 | 8729 | |
c751ce4f | 8730 | num_connectors++; |
79e53945 | 8731 | } |
79e53945 | 8732 | |
c1858123 | 8733 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8734 | factor = 21; |
8735 | if (is_lvds) { | |
8736 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8737 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8738 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8739 | factor = 25; |
190f68c5 | 8740 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8741 | factor = 20; |
c1858123 | 8742 | |
190f68c5 | 8743 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8744 | *fp |= FP_CB_TUNE; |
2c07245f | 8745 | |
9a7c7890 DV |
8746 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8747 | *fp2 |= FP_CB_TUNE; | |
8748 | ||
5eddb70b | 8749 | dpll = 0; |
2c07245f | 8750 | |
a07d6787 EA |
8751 | if (is_lvds) |
8752 | dpll |= DPLLB_MODE_LVDS; | |
8753 | else | |
8754 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8755 | |
190f68c5 | 8756 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8757 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8758 | |
8759 | if (is_sdvo) | |
4a33e48d | 8760 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8761 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8762 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8763 | |
a07d6787 | 8764 | /* compute bitmask from p1 value */ |
190f68c5 | 8765 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8766 | /* also FPA1 */ |
190f68c5 | 8767 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8768 | |
190f68c5 | 8769 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8770 | case 5: |
8771 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8772 | break; | |
8773 | case 7: | |
8774 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8775 | break; | |
8776 | case 10: | |
8777 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8778 | break; | |
8779 | case 14: | |
8780 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8781 | break; | |
79e53945 JB |
8782 | } |
8783 | ||
b4c09f3b | 8784 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8785 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8786 | else |
8787 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8788 | ||
959e16d6 | 8789 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8790 | } |
8791 | ||
190f68c5 ACO |
8792 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8793 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8794 | { |
c7653199 | 8795 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8796 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8797 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8798 | bool ok, has_reduced_clock = false; |
8b47047b | 8799 | bool is_lvds = false; |
e2b78267 | 8800 | struct intel_shared_dpll *pll; |
de13a2e3 | 8801 | |
dd3cd74a ACO |
8802 | memset(&crtc_state->dpll_hw_state, 0, |
8803 | sizeof(crtc_state->dpll_hw_state)); | |
8804 | ||
409ee761 | 8805 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8806 | |
5dc5298b PZ |
8807 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8808 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8809 | |
190f68c5 | 8810 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8811 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8812 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8813 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8814 | return -EINVAL; | |
79e53945 | 8815 | } |
f47709a9 | 8816 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8817 | if (!crtc_state->clock_set) { |
8818 | crtc_state->dpll.n = clock.n; | |
8819 | crtc_state->dpll.m1 = clock.m1; | |
8820 | crtc_state->dpll.m2 = clock.m2; | |
8821 | crtc_state->dpll.p1 = clock.p1; | |
8822 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8823 | } |
79e53945 | 8824 | |
5dc5298b | 8825 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8826 | if (crtc_state->has_pch_encoder) { |
8827 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8828 | if (has_reduced_clock) |
7429e9d4 | 8829 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8830 | |
190f68c5 | 8831 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8832 | &fp, &reduced_clock, |
8833 | has_reduced_clock ? &fp2 : NULL); | |
8834 | ||
190f68c5 ACO |
8835 | crtc_state->dpll_hw_state.dpll = dpll; |
8836 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8837 | if (has_reduced_clock) |
190f68c5 | 8838 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8839 | else |
190f68c5 | 8840 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8841 | |
190f68c5 | 8842 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8843 | if (pll == NULL) { |
84f44ce7 | 8844 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8845 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8846 | return -EINVAL; |
8847 | } | |
3fb37703 | 8848 | } |
79e53945 | 8849 | |
ab585dea | 8850 | if (is_lvds && has_reduced_clock) |
c7653199 | 8851 | crtc->lowfreq_avail = true; |
bcd644e0 | 8852 | else |
c7653199 | 8853 | crtc->lowfreq_avail = false; |
e2b78267 | 8854 | |
c8f7a0db | 8855 | return 0; |
79e53945 JB |
8856 | } |
8857 | ||
eb14cb74 VS |
8858 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8859 | struct intel_link_m_n *m_n) | |
8860 | { | |
8861 | struct drm_device *dev = crtc->base.dev; | |
8862 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8863 | enum pipe pipe = crtc->pipe; | |
8864 | ||
8865 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8866 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8867 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8868 | & ~TU_SIZE_MASK; | |
8869 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8870 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8871 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8872 | } | |
8873 | ||
8874 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8875 | enum transcoder transcoder, | |
b95af8be VK |
8876 | struct intel_link_m_n *m_n, |
8877 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
8878 | { |
8879 | struct drm_device *dev = crtc->base.dev; | |
8880 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 8881 | enum pipe pipe = crtc->pipe; |
72419203 | 8882 | |
eb14cb74 VS |
8883 | if (INTEL_INFO(dev)->gen >= 5) { |
8884 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
8885 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8886 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8887 | & ~TU_SIZE_MASK; | |
8888 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8889 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8890 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8891 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8892 | * gen < 8) and if DRRS is supported (to make sure the | |
8893 | * registers are not unnecessarily read). | |
8894 | */ | |
8895 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 8896 | crtc->config->has_drrs) { |
b95af8be VK |
8897 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8898 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8899 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8900 | & ~TU_SIZE_MASK; | |
8901 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8902 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8903 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8904 | } | |
eb14cb74 VS |
8905 | } else { |
8906 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8907 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8908 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8909 | & ~TU_SIZE_MASK; | |
8910 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8911 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8912 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8913 | } | |
8914 | } | |
8915 | ||
8916 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8917 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8918 | { |
681a8504 | 8919 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8920 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8921 | else | |
8922 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8923 | &pipe_config->dp_m_n, |
8924 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8925 | } |
72419203 | 8926 | |
eb14cb74 | 8927 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 8928 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
8929 | { |
8930 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 8931 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
8932 | } |
8933 | ||
bd2e244f | 8934 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8935 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
8936 | { |
8937 | struct drm_device *dev = crtc->base.dev; | |
8938 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
8939 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
8940 | uint32_t ps_ctrl = 0; | |
8941 | int id = -1; | |
8942 | int i; | |
bd2e244f | 8943 | |
a1b2278e CK |
8944 | /* find scaler attached to this pipe */ |
8945 | for (i = 0; i < crtc->num_scalers; i++) { | |
8946 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
8947 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
8948 | id = i; | |
8949 | pipe_config->pch_pfit.enabled = true; | |
8950 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
8951 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
8952 | break; | |
8953 | } | |
8954 | } | |
bd2e244f | 8955 | |
a1b2278e CK |
8956 | scaler_state->scaler_id = id; |
8957 | if (id >= 0) { | |
8958 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
8959 | } else { | |
8960 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
8961 | } |
8962 | } | |
8963 | ||
5724dbd1 DL |
8964 | static void |
8965 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
8966 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
8967 | { |
8968 | struct drm_device *dev = crtc->base.dev; | |
8969 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 8970 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
8971 | int pipe = crtc->pipe; |
8972 | int fourcc, pixel_format; | |
6761dd31 | 8973 | unsigned int aligned_height; |
bc8d7dff | 8974 | struct drm_framebuffer *fb; |
1b842c89 | 8975 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 8976 | |
d9806c9f | 8977 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8978 | if (!intel_fb) { |
bc8d7dff DL |
8979 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8980 | return; | |
8981 | } | |
8982 | ||
1b842c89 DL |
8983 | fb = &intel_fb->base; |
8984 | ||
bc8d7dff | 8985 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
8986 | if (!(val & PLANE_CTL_ENABLE)) |
8987 | goto error; | |
8988 | ||
bc8d7dff DL |
8989 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
8990 | fourcc = skl_format_to_fourcc(pixel_format, | |
8991 | val & PLANE_CTL_ORDER_RGBX, | |
8992 | val & PLANE_CTL_ALPHA_MASK); | |
8993 | fb->pixel_format = fourcc; | |
8994 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
8995 | ||
40f46283 DL |
8996 | tiling = val & PLANE_CTL_TILED_MASK; |
8997 | switch (tiling) { | |
8998 | case PLANE_CTL_TILED_LINEAR: | |
8999 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9000 | break; | |
9001 | case PLANE_CTL_TILED_X: | |
9002 | plane_config->tiling = I915_TILING_X; | |
9003 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9004 | break; | |
9005 | case PLANE_CTL_TILED_Y: | |
9006 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9007 | break; | |
9008 | case PLANE_CTL_TILED_YF: | |
9009 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9010 | break; | |
9011 | default: | |
9012 | MISSING_CASE(tiling); | |
9013 | goto error; | |
9014 | } | |
9015 | ||
bc8d7dff DL |
9016 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9017 | plane_config->base = base; | |
9018 | ||
9019 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9020 | ||
9021 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9022 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9023 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9024 | ||
9025 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9026 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9027 | fb->pixel_format); | |
bc8d7dff DL |
9028 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9029 | ||
9030 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9031 | fb->pixel_format, |
9032 | fb->modifier[0]); | |
bc8d7dff | 9033 | |
f37b5c2b | 9034 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9035 | |
9036 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9037 | pipe_name(pipe), fb->width, fb->height, | |
9038 | fb->bits_per_pixel, base, fb->pitches[0], | |
9039 | plane_config->size); | |
9040 | ||
2d14030b | 9041 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9042 | return; |
9043 | ||
9044 | error: | |
9045 | kfree(fb); | |
9046 | } | |
9047 | ||
2fa2fe9a | 9048 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9049 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9050 | { |
9051 | struct drm_device *dev = crtc->base.dev; | |
9052 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9053 | uint32_t tmp; | |
9054 | ||
9055 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9056 | ||
9057 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9058 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9059 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9060 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9061 | |
9062 | /* We currently do not free assignements of panel fitters on | |
9063 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9064 | * differentiates them) so just WARN about this case for now. */ | |
9065 | if (IS_GEN7(dev)) { | |
9066 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9067 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9068 | } | |
2fa2fe9a | 9069 | } |
79e53945 JB |
9070 | } |
9071 | ||
5724dbd1 DL |
9072 | static void |
9073 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9074 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9075 | { |
9076 | struct drm_device *dev = crtc->base.dev; | |
9077 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9078 | u32 val, base, offset; | |
aeee5a49 | 9079 | int pipe = crtc->pipe; |
4c6baa59 | 9080 | int fourcc, pixel_format; |
6761dd31 | 9081 | unsigned int aligned_height; |
b113d5ee | 9082 | struct drm_framebuffer *fb; |
1b842c89 | 9083 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9084 | |
42a7b088 DL |
9085 | val = I915_READ(DSPCNTR(pipe)); |
9086 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9087 | return; | |
9088 | ||
d9806c9f | 9089 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9090 | if (!intel_fb) { |
4c6baa59 JB |
9091 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9092 | return; | |
9093 | } | |
9094 | ||
1b842c89 DL |
9095 | fb = &intel_fb->base; |
9096 | ||
18c5247e DV |
9097 | if (INTEL_INFO(dev)->gen >= 4) { |
9098 | if (val & DISPPLANE_TILED) { | |
49af449b | 9099 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9100 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9101 | } | |
9102 | } | |
4c6baa59 JB |
9103 | |
9104 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9105 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9106 | fb->pixel_format = fourcc; |
9107 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9108 | |
aeee5a49 | 9109 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9110 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9111 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9112 | } else { |
49af449b | 9113 | if (plane_config->tiling) |
aeee5a49 | 9114 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9115 | else |
aeee5a49 | 9116 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9117 | } |
9118 | plane_config->base = base; | |
9119 | ||
9120 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9121 | fb->width = ((val >> 16) & 0xfff) + 1; |
9122 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9123 | |
9124 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9125 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9126 | |
b113d5ee | 9127 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9128 | fb->pixel_format, |
9129 | fb->modifier[0]); | |
4c6baa59 | 9130 | |
f37b5c2b | 9131 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9132 | |
2844a921 DL |
9133 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9134 | pipe_name(pipe), fb->width, fb->height, | |
9135 | fb->bits_per_pixel, base, fb->pitches[0], | |
9136 | plane_config->size); | |
b113d5ee | 9137 | |
2d14030b | 9138 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9139 | } |
9140 | ||
0e8ffe1b | 9141 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9142 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9143 | { |
9144 | struct drm_device *dev = crtc->base.dev; | |
9145 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9146 | uint32_t tmp; | |
9147 | ||
f458ebbc DV |
9148 | if (!intel_display_power_is_enabled(dev_priv, |
9149 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9150 | return false; |
9151 | ||
e143a21c | 9152 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9153 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9154 | |
0e8ffe1b DV |
9155 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9156 | if (!(tmp & PIPECONF_ENABLE)) | |
9157 | return false; | |
9158 | ||
42571aef VS |
9159 | switch (tmp & PIPECONF_BPC_MASK) { |
9160 | case PIPECONF_6BPC: | |
9161 | pipe_config->pipe_bpp = 18; | |
9162 | break; | |
9163 | case PIPECONF_8BPC: | |
9164 | pipe_config->pipe_bpp = 24; | |
9165 | break; | |
9166 | case PIPECONF_10BPC: | |
9167 | pipe_config->pipe_bpp = 30; | |
9168 | break; | |
9169 | case PIPECONF_12BPC: | |
9170 | pipe_config->pipe_bpp = 36; | |
9171 | break; | |
9172 | default: | |
9173 | break; | |
9174 | } | |
9175 | ||
b5a9fa09 DV |
9176 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9177 | pipe_config->limited_color_range = true; | |
9178 | ||
ab9412ba | 9179 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9180 | struct intel_shared_dpll *pll; |
9181 | ||
88adfff1 DV |
9182 | pipe_config->has_pch_encoder = true; |
9183 | ||
627eb5a3 DV |
9184 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9185 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9186 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9187 | |
9188 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9189 | |
c0d43d62 | 9190 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9191 | pipe_config->shared_dpll = |
9192 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9193 | } else { |
9194 | tmp = I915_READ(PCH_DPLL_SEL); | |
9195 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9196 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9197 | else | |
9198 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9199 | } | |
66e985c0 DV |
9200 | |
9201 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9202 | ||
9203 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9204 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9205 | |
9206 | tmp = pipe_config->dpll_hw_state.dpll; | |
9207 | pipe_config->pixel_multiplier = | |
9208 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9209 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9210 | |
9211 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9212 | } else { |
9213 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9214 | } |
9215 | ||
1bd1bd80 DV |
9216 | intel_get_pipe_timings(crtc, pipe_config); |
9217 | ||
2fa2fe9a DV |
9218 | ironlake_get_pfit_config(crtc, pipe_config); |
9219 | ||
0e8ffe1b DV |
9220 | return true; |
9221 | } | |
9222 | ||
be256dc7 PZ |
9223 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9224 | { | |
9225 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9226 | struct intel_crtc *crtc; |
be256dc7 | 9227 | |
d3fcc808 | 9228 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9229 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9230 | pipe_name(crtc->pipe)); |
9231 | ||
e2c719b7 RC |
9232 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9233 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
9234 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); | |
9235 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
9236 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); | |
9237 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9238 | "CPU PWM1 enabled\n"); |
c5107b87 | 9239 | if (IS_HASWELL(dev)) |
e2c719b7 | 9240 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9241 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9242 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9243 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9244 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9245 | "Utility pin enabled\n"); |
e2c719b7 | 9246 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9247 | |
9926ada1 PZ |
9248 | /* |
9249 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9250 | * interrupts remain enabled. We used to check for that, but since it's | |
9251 | * gen-specific and since we only disable LCPLL after we fully disable | |
9252 | * the interrupts, the check below should be enough. | |
9253 | */ | |
e2c719b7 | 9254 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9255 | } |
9256 | ||
9ccd5aeb PZ |
9257 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9258 | { | |
9259 | struct drm_device *dev = dev_priv->dev; | |
9260 | ||
9261 | if (IS_HASWELL(dev)) | |
9262 | return I915_READ(D_COMP_HSW); | |
9263 | else | |
9264 | return I915_READ(D_COMP_BDW); | |
9265 | } | |
9266 | ||
3c4c9b81 PZ |
9267 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9268 | { | |
9269 | struct drm_device *dev = dev_priv->dev; | |
9270 | ||
9271 | if (IS_HASWELL(dev)) { | |
9272 | mutex_lock(&dev_priv->rps.hw_lock); | |
9273 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9274 | val)) | |
f475dadf | 9275 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9276 | mutex_unlock(&dev_priv->rps.hw_lock); |
9277 | } else { | |
9ccd5aeb PZ |
9278 | I915_WRITE(D_COMP_BDW, val); |
9279 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9280 | } |
be256dc7 PZ |
9281 | } |
9282 | ||
9283 | /* | |
9284 | * This function implements pieces of two sequences from BSpec: | |
9285 | * - Sequence for display software to disable LCPLL | |
9286 | * - Sequence for display software to allow package C8+ | |
9287 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9288 | * register. Callers should take care of disabling all the display engine | |
9289 | * functions, doing the mode unset, fixing interrupts, etc. | |
9290 | */ | |
6ff58d53 PZ |
9291 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9292 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9293 | { |
9294 | uint32_t val; | |
9295 | ||
9296 | assert_can_disable_lcpll(dev_priv); | |
9297 | ||
9298 | val = I915_READ(LCPLL_CTL); | |
9299 | ||
9300 | if (switch_to_fclk) { | |
9301 | val |= LCPLL_CD_SOURCE_FCLK; | |
9302 | I915_WRITE(LCPLL_CTL, val); | |
9303 | ||
9304 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9305 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9306 | DRM_ERROR("Switching to FCLK failed\n"); | |
9307 | ||
9308 | val = I915_READ(LCPLL_CTL); | |
9309 | } | |
9310 | ||
9311 | val |= LCPLL_PLL_DISABLE; | |
9312 | I915_WRITE(LCPLL_CTL, val); | |
9313 | POSTING_READ(LCPLL_CTL); | |
9314 | ||
9315 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9316 | DRM_ERROR("LCPLL still locked\n"); | |
9317 | ||
9ccd5aeb | 9318 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9319 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9320 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9321 | ndelay(100); |
9322 | ||
9ccd5aeb PZ |
9323 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9324 | 1)) | |
be256dc7 PZ |
9325 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9326 | ||
9327 | if (allow_power_down) { | |
9328 | val = I915_READ(LCPLL_CTL); | |
9329 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9330 | I915_WRITE(LCPLL_CTL, val); | |
9331 | POSTING_READ(LCPLL_CTL); | |
9332 | } | |
9333 | } | |
9334 | ||
9335 | /* | |
9336 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9337 | * source. | |
9338 | */ | |
6ff58d53 | 9339 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9340 | { |
9341 | uint32_t val; | |
9342 | ||
9343 | val = I915_READ(LCPLL_CTL); | |
9344 | ||
9345 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9346 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9347 | return; | |
9348 | ||
a8a8bd54 PZ |
9349 | /* |
9350 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9351 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9352 | */ |
59bad947 | 9353 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9354 | |
be256dc7 PZ |
9355 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9356 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9357 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9358 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9359 | } |
9360 | ||
9ccd5aeb | 9361 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9362 | val |= D_COMP_COMP_FORCE; |
9363 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9364 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9365 | |
9366 | val = I915_READ(LCPLL_CTL); | |
9367 | val &= ~LCPLL_PLL_DISABLE; | |
9368 | I915_WRITE(LCPLL_CTL, val); | |
9369 | ||
9370 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9371 | DRM_ERROR("LCPLL not locked yet\n"); | |
9372 | ||
9373 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9374 | val = I915_READ(LCPLL_CTL); | |
9375 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9376 | I915_WRITE(LCPLL_CTL, val); | |
9377 | ||
9378 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9379 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9380 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9381 | } | |
215733fa | 9382 | |
59bad947 | 9383 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9384 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9385 | } |
9386 | ||
765dab67 PZ |
9387 | /* |
9388 | * Package states C8 and deeper are really deep PC states that can only be | |
9389 | * reached when all the devices on the system allow it, so even if the graphics | |
9390 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9391 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9392 | * | |
9393 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9394 | * well is disabled and most interrupts are disabled, and these are also | |
9395 | * requirements for runtime PM. When these conditions are met, we manually do | |
9396 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9397 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9398 | * hang the machine. | |
9399 | * | |
9400 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9401 | * the state of some registers, so when we come back from PC8+ we need to | |
9402 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9403 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9404 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9405 | * because of the runtime PM support). | |
9406 | * | |
9407 | * For more, read "Display Sequences for Package C8" on the hardware | |
9408 | * documentation. | |
9409 | */ | |
a14cb6fc | 9410 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9411 | { |
c67a470b PZ |
9412 | struct drm_device *dev = dev_priv->dev; |
9413 | uint32_t val; | |
9414 | ||
c67a470b PZ |
9415 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9416 | ||
c2699524 | 9417 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9418 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9419 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9420 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9421 | } | |
9422 | ||
9423 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9424 | hsw_disable_lcpll(dev_priv, true, true); |
9425 | } | |
9426 | ||
a14cb6fc | 9427 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9428 | { |
9429 | struct drm_device *dev = dev_priv->dev; | |
9430 | uint32_t val; | |
9431 | ||
c67a470b PZ |
9432 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9433 | ||
9434 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9435 | lpt_init_pch_refclk(dev); |
9436 | ||
c2699524 | 9437 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9438 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9439 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9440 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9441 | } | |
9442 | ||
9443 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9444 | } |
9445 | ||
27c329ed | 9446 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9447 | { |
a821fc46 | 9448 | struct drm_device *dev = old_state->dev; |
27c329ed | 9449 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
f8437dd1 | 9450 | |
27c329ed | 9451 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9452 | } |
9453 | ||
b432e5cf | 9454 | /* compute the max rate for new configuration */ |
27c329ed | 9455 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9456 | { |
b432e5cf | 9457 | struct intel_crtc *intel_crtc; |
27c329ed | 9458 | struct intel_crtc_state *crtc_state; |
b432e5cf | 9459 | int max_pixel_rate = 0; |
b432e5cf | 9460 | |
27c329ed ML |
9461 | for_each_intel_crtc(state->dev, intel_crtc) { |
9462 | int pixel_rate; | |
9463 | ||
9464 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
9465 | if (IS_ERR(crtc_state)) | |
9466 | return PTR_ERR(crtc_state); | |
9467 | ||
9468 | if (!crtc_state->base.enable) | |
b432e5cf VS |
9469 | continue; |
9470 | ||
27c329ed | 9471 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9472 | |
9473 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
27c329ed | 9474 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
b432e5cf VS |
9475 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9476 | ||
9477 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9478 | } | |
9479 | ||
9480 | return max_pixel_rate; | |
9481 | } | |
9482 | ||
9483 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9484 | { | |
9485 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9486 | uint32_t val, data; | |
9487 | int ret; | |
9488 | ||
9489 | if (WARN((I915_READ(LCPLL_CTL) & | |
9490 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9491 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9492 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9493 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9494 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9495 | return; | |
9496 | ||
9497 | mutex_lock(&dev_priv->rps.hw_lock); | |
9498 | ret = sandybridge_pcode_write(dev_priv, | |
9499 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9500 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9501 | if (ret) { | |
9502 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9503 | return; | |
9504 | } | |
9505 | ||
9506 | val = I915_READ(LCPLL_CTL); | |
9507 | val |= LCPLL_CD_SOURCE_FCLK; | |
9508 | I915_WRITE(LCPLL_CTL, val); | |
9509 | ||
9510 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9511 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9512 | DRM_ERROR("Switching to FCLK failed\n"); | |
9513 | ||
9514 | val = I915_READ(LCPLL_CTL); | |
9515 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9516 | ||
9517 | switch (cdclk) { | |
9518 | case 450000: | |
9519 | val |= LCPLL_CLK_FREQ_450; | |
9520 | data = 0; | |
9521 | break; | |
9522 | case 540000: | |
9523 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9524 | data = 1; | |
9525 | break; | |
9526 | case 337500: | |
9527 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9528 | data = 2; | |
9529 | break; | |
9530 | case 675000: | |
9531 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9532 | data = 3; | |
9533 | break; | |
9534 | default: | |
9535 | WARN(1, "invalid cdclk frequency\n"); | |
9536 | return; | |
9537 | } | |
9538 | ||
9539 | I915_WRITE(LCPLL_CTL, val); | |
9540 | ||
9541 | val = I915_READ(LCPLL_CTL); | |
9542 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9543 | I915_WRITE(LCPLL_CTL, val); | |
9544 | ||
9545 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9546 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9547 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9548 | ||
9549 | mutex_lock(&dev_priv->rps.hw_lock); | |
9550 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9551 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9552 | ||
9553 | intel_update_cdclk(dev); | |
9554 | ||
9555 | WARN(cdclk != dev_priv->cdclk_freq, | |
9556 | "cdclk requested %d kHz but got %d kHz\n", | |
9557 | cdclk, dev_priv->cdclk_freq); | |
9558 | } | |
9559 | ||
27c329ed | 9560 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9561 | { |
27c329ed ML |
9562 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
9563 | int max_pixclk = ilk_max_pixel_rate(state); | |
b432e5cf VS |
9564 | int cdclk; |
9565 | ||
9566 | /* | |
9567 | * FIXME should also account for plane ratio | |
9568 | * once 64bpp pixel formats are supported. | |
9569 | */ | |
27c329ed | 9570 | if (max_pixclk > 540000) |
b432e5cf | 9571 | cdclk = 675000; |
27c329ed | 9572 | else if (max_pixclk > 450000) |
b432e5cf | 9573 | cdclk = 540000; |
27c329ed | 9574 | else if (max_pixclk > 337500) |
b432e5cf VS |
9575 | cdclk = 450000; |
9576 | else | |
9577 | cdclk = 337500; | |
9578 | ||
9579 | /* | |
9580 | * FIXME move the cdclk caclulation to | |
9581 | * compute_config() so we can fail gracegully. | |
9582 | */ | |
9583 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9584 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9585 | cdclk, dev_priv->max_cdclk_freq); | |
9586 | cdclk = dev_priv->max_cdclk_freq; | |
9587 | } | |
9588 | ||
27c329ed | 9589 | to_intel_atomic_state(state)->cdclk = cdclk; |
b432e5cf VS |
9590 | |
9591 | return 0; | |
9592 | } | |
9593 | ||
27c329ed | 9594 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9595 | { |
27c329ed ML |
9596 | struct drm_device *dev = old_state->dev; |
9597 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; | |
b432e5cf | 9598 | |
27c329ed | 9599 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9600 | } |
9601 | ||
190f68c5 ACO |
9602 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9603 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9604 | { |
190f68c5 | 9605 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9606 | return -EINVAL; |
716c2e55 | 9607 | |
c7653199 | 9608 | crtc->lowfreq_avail = false; |
644cef34 | 9609 | |
c8f7a0db | 9610 | return 0; |
79e53945 JB |
9611 | } |
9612 | ||
3760b59c S |
9613 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9614 | enum port port, | |
9615 | struct intel_crtc_state *pipe_config) | |
9616 | { | |
9617 | switch (port) { | |
9618 | case PORT_A: | |
9619 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9620 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9621 | break; | |
9622 | case PORT_B: | |
9623 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9624 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9625 | break; | |
9626 | case PORT_C: | |
9627 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9628 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9629 | break; | |
9630 | default: | |
9631 | DRM_ERROR("Incorrect port type\n"); | |
9632 | } | |
9633 | } | |
9634 | ||
96b7dfb7 S |
9635 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9636 | enum port port, | |
5cec258b | 9637 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9638 | { |
3148ade7 | 9639 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9640 | |
9641 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9642 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9643 | ||
9644 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9645 | case SKL_DPLL0: |
9646 | /* | |
9647 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9648 | * of the shared DPLL framework and thus needs to be read out | |
9649 | * separately | |
9650 | */ | |
9651 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9652 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9653 | break; | |
96b7dfb7 S |
9654 | case SKL_DPLL1: |
9655 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9656 | break; | |
9657 | case SKL_DPLL2: | |
9658 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9659 | break; | |
9660 | case SKL_DPLL3: | |
9661 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9662 | break; | |
96b7dfb7 S |
9663 | } |
9664 | } | |
9665 | ||
7d2c8175 DL |
9666 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9667 | enum port port, | |
5cec258b | 9668 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9669 | { |
9670 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9671 | ||
9672 | switch (pipe_config->ddi_pll_sel) { | |
9673 | case PORT_CLK_SEL_WRPLL1: | |
9674 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9675 | break; | |
9676 | case PORT_CLK_SEL_WRPLL2: | |
9677 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9678 | break; | |
9679 | } | |
9680 | } | |
9681 | ||
26804afd | 9682 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9683 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9684 | { |
9685 | struct drm_device *dev = crtc->base.dev; | |
9686 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9687 | struct intel_shared_dpll *pll; |
26804afd DV |
9688 | enum port port; |
9689 | uint32_t tmp; | |
9690 | ||
9691 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9692 | ||
9693 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9694 | ||
96b7dfb7 S |
9695 | if (IS_SKYLAKE(dev)) |
9696 | skylake_get_ddi_pll(dev_priv, port, pipe_config); | |
3760b59c S |
9697 | else if (IS_BROXTON(dev)) |
9698 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9699 | else |
9700 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9701 | |
d452c5b6 DV |
9702 | if (pipe_config->shared_dpll >= 0) { |
9703 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9704 | ||
9705 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9706 | &pipe_config->dpll_hw_state)); | |
9707 | } | |
9708 | ||
26804afd DV |
9709 | /* |
9710 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9711 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9712 | * the PCH transcoder is on. | |
9713 | */ | |
ca370455 DL |
9714 | if (INTEL_INFO(dev)->gen < 9 && |
9715 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9716 | pipe_config->has_pch_encoder = true; |
9717 | ||
9718 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9719 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9720 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9721 | ||
9722 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9723 | } | |
9724 | } | |
9725 | ||
0e8ffe1b | 9726 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9727 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9728 | { |
9729 | struct drm_device *dev = crtc->base.dev; | |
9730 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9731 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9732 | uint32_t tmp; |
9733 | ||
f458ebbc | 9734 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9735 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9736 | return false; | |
9737 | ||
e143a21c | 9738 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9739 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9740 | ||
eccb140b DV |
9741 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9742 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9743 | enum pipe trans_edp_pipe; | |
9744 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9745 | default: | |
9746 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9747 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9748 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9749 | trans_edp_pipe = PIPE_A; | |
9750 | break; | |
9751 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9752 | trans_edp_pipe = PIPE_B; | |
9753 | break; | |
9754 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9755 | trans_edp_pipe = PIPE_C; | |
9756 | break; | |
9757 | } | |
9758 | ||
9759 | if (trans_edp_pipe == crtc->pipe) | |
9760 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9761 | } | |
9762 | ||
f458ebbc | 9763 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9764 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9765 | return false; |
9766 | ||
eccb140b | 9767 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9768 | if (!(tmp & PIPECONF_ENABLE)) |
9769 | return false; | |
9770 | ||
26804afd | 9771 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9772 | |
1bd1bd80 DV |
9773 | intel_get_pipe_timings(crtc, pipe_config); |
9774 | ||
a1b2278e CK |
9775 | if (INTEL_INFO(dev)->gen >= 9) { |
9776 | skl_init_scalers(dev, crtc, pipe_config); | |
9777 | } | |
9778 | ||
2fa2fe9a | 9779 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9780 | |
9781 | if (INTEL_INFO(dev)->gen >= 9) { | |
9782 | pipe_config->scaler_state.scaler_id = -1; | |
9783 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9784 | } | |
9785 | ||
bd2e244f | 9786 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
ff6d9f55 | 9787 | if (INTEL_INFO(dev)->gen == 9) |
bd2e244f | 9788 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9789 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 9790 | ironlake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 JB |
9791 | else |
9792 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
bd2e244f | 9793 | } |
88adfff1 | 9794 | |
e59150dc JB |
9795 | if (IS_HASWELL(dev)) |
9796 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9797 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9798 | |
ebb69c95 CT |
9799 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9800 | pipe_config->pixel_multiplier = | |
9801 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9802 | } else { | |
9803 | pipe_config->pixel_multiplier = 1; | |
9804 | } | |
6c49f241 | 9805 | |
0e8ffe1b DV |
9806 | return true; |
9807 | } | |
9808 | ||
560b85bb CW |
9809 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9810 | { | |
9811 | struct drm_device *dev = crtc->dev; | |
9812 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9813 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9814 | uint32_t cntl = 0, size = 0; |
560b85bb | 9815 | |
dc41c154 | 9816 | if (base) { |
3dd512fb MR |
9817 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9818 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9819 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9820 | ||
9821 | switch (stride) { | |
9822 | default: | |
9823 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9824 | width, stride); | |
9825 | stride = 256; | |
9826 | /* fallthrough */ | |
9827 | case 256: | |
9828 | case 512: | |
9829 | case 1024: | |
9830 | case 2048: | |
9831 | break; | |
4b0e333e CW |
9832 | } |
9833 | ||
dc41c154 VS |
9834 | cntl |= CURSOR_ENABLE | |
9835 | CURSOR_GAMMA_ENABLE | | |
9836 | CURSOR_FORMAT_ARGB | | |
9837 | CURSOR_STRIDE(stride); | |
9838 | ||
9839 | size = (height << 12) | width; | |
4b0e333e | 9840 | } |
560b85bb | 9841 | |
dc41c154 VS |
9842 | if (intel_crtc->cursor_cntl != 0 && |
9843 | (intel_crtc->cursor_base != base || | |
9844 | intel_crtc->cursor_size != size || | |
9845 | intel_crtc->cursor_cntl != cntl)) { | |
9846 | /* On these chipsets we can only modify the base/size/stride | |
9847 | * whilst the cursor is disabled. | |
9848 | */ | |
9849 | I915_WRITE(_CURACNTR, 0); | |
4b0e333e | 9850 | POSTING_READ(_CURACNTR); |
dc41c154 | 9851 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9852 | } |
560b85bb | 9853 | |
99d1f387 | 9854 | if (intel_crtc->cursor_base != base) { |
9db4a9c7 | 9855 | I915_WRITE(_CURABASE, base); |
99d1f387 VS |
9856 | intel_crtc->cursor_base = base; |
9857 | } | |
4726e0b0 | 9858 | |
dc41c154 VS |
9859 | if (intel_crtc->cursor_size != size) { |
9860 | I915_WRITE(CURSIZE, size); | |
9861 | intel_crtc->cursor_size = size; | |
4b0e333e | 9862 | } |
560b85bb | 9863 | |
4b0e333e | 9864 | if (intel_crtc->cursor_cntl != cntl) { |
4b0e333e CW |
9865 | I915_WRITE(_CURACNTR, cntl); |
9866 | POSTING_READ(_CURACNTR); | |
4b0e333e | 9867 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 9868 | } |
560b85bb CW |
9869 | } |
9870 | ||
560b85bb | 9871 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
9872 | { |
9873 | struct drm_device *dev = crtc->dev; | |
9874 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9875 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9876 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
9877 | uint32_t cntl; |
9878 | ||
9879 | cntl = 0; | |
9880 | if (base) { | |
9881 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 9882 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
9883 | case 64: |
9884 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9885 | break; | |
9886 | case 128: | |
9887 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9888 | break; | |
9889 | case 256: | |
9890 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
9891 | break; | |
9892 | default: | |
3dd512fb | 9893 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 9894 | return; |
65a21cd6 | 9895 | } |
4b0e333e | 9896 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 VS |
9897 | |
9898 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
9899 | cntl |= CURSOR_PIPE_CSC_ENABLE; | |
4b0e333e | 9900 | } |
65a21cd6 | 9901 | |
8e7d688b | 9902 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
9903 | cntl |= CURSOR_ROTATE_180; |
9904 | ||
4b0e333e CW |
9905 | if (intel_crtc->cursor_cntl != cntl) { |
9906 | I915_WRITE(CURCNTR(pipe), cntl); | |
9907 | POSTING_READ(CURCNTR(pipe)); | |
9908 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 9909 | } |
4b0e333e | 9910 | |
65a21cd6 | 9911 | /* and commit changes on next vblank */ |
5efb3e28 VS |
9912 | I915_WRITE(CURBASE(pipe), base); |
9913 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
9914 | |
9915 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
9916 | } |
9917 | ||
cda4b7d3 | 9918 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
9919 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
9920 | bool on) | |
cda4b7d3 CW |
9921 | { |
9922 | struct drm_device *dev = crtc->dev; | |
9923 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9924 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9925 | int pipe = intel_crtc->pipe; | |
3d7d6510 MR |
9926 | int x = crtc->cursor_x; |
9927 | int y = crtc->cursor_y; | |
d6e4db15 | 9928 | u32 base = 0, pos = 0; |
cda4b7d3 | 9929 | |
d6e4db15 | 9930 | if (on) |
cda4b7d3 | 9931 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 9932 | |
6e3c9717 | 9933 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
9934 | base = 0; |
9935 | ||
6e3c9717 | 9936 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
9937 | base = 0; |
9938 | ||
9939 | if (x < 0) { | |
3dd512fb | 9940 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
cda4b7d3 CW |
9941 | base = 0; |
9942 | ||
9943 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
9944 | x = -x; | |
9945 | } | |
9946 | pos |= x << CURSOR_X_SHIFT; | |
9947 | ||
9948 | if (y < 0) { | |
3dd512fb | 9949 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
cda4b7d3 CW |
9950 | base = 0; |
9951 | ||
9952 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
9953 | y = -y; | |
9954 | } | |
9955 | pos |= y << CURSOR_Y_SHIFT; | |
9956 | ||
4b0e333e | 9957 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
9958 | return; |
9959 | ||
5efb3e28 VS |
9960 | I915_WRITE(CURPOS(pipe), pos); |
9961 | ||
4398ad45 VS |
9962 | /* ILK+ do this automagically */ |
9963 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 9964 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
3dd512fb MR |
9965 | base += (intel_crtc->base.cursor->state->crtc_h * |
9966 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; | |
4398ad45 VS |
9967 | } |
9968 | ||
8ac54669 | 9969 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
9970 | i845_update_cursor(crtc, base); |
9971 | else | |
9972 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
9973 | } |
9974 | ||
dc41c154 VS |
9975 | static bool cursor_size_ok(struct drm_device *dev, |
9976 | uint32_t width, uint32_t height) | |
9977 | { | |
9978 | if (width == 0 || height == 0) | |
9979 | return false; | |
9980 | ||
9981 | /* | |
9982 | * 845g/865g are special in that they are only limited by | |
9983 | * the width of their cursors, the height is arbitrary up to | |
9984 | * the precision of the register. Everything else requires | |
9985 | * square cursors, limited to a few power-of-two sizes. | |
9986 | */ | |
9987 | if (IS_845G(dev) || IS_I865G(dev)) { | |
9988 | if ((width & 63) != 0) | |
9989 | return false; | |
9990 | ||
9991 | if (width > (IS_845G(dev) ? 64 : 512)) | |
9992 | return false; | |
9993 | ||
9994 | if (height > 1023) | |
9995 | return false; | |
9996 | } else { | |
9997 | switch (width | height) { | |
9998 | case 256: | |
9999 | case 128: | |
10000 | if (IS_GEN2(dev)) | |
10001 | return false; | |
10002 | case 64: | |
10003 | break; | |
10004 | default: | |
10005 | return false; | |
10006 | } | |
10007 | } | |
10008 | ||
10009 | return true; | |
10010 | } | |
10011 | ||
79e53945 | 10012 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10013 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10014 | { |
7203425a | 10015 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10016 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10017 | |
7203425a | 10018 | for (i = start; i < end; i++) { |
79e53945 JB |
10019 | intel_crtc->lut_r[i] = red[i] >> 8; |
10020 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10021 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10022 | } | |
10023 | ||
10024 | intel_crtc_load_lut(crtc); | |
10025 | } | |
10026 | ||
79e53945 JB |
10027 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10028 | static struct drm_display_mode load_detect_mode = { | |
10029 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10030 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10031 | }; | |
10032 | ||
a8bb6818 DV |
10033 | struct drm_framebuffer * |
10034 | __intel_framebuffer_create(struct drm_device *dev, | |
10035 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10036 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10037 | { |
10038 | struct intel_framebuffer *intel_fb; | |
10039 | int ret; | |
10040 | ||
10041 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
10042 | if (!intel_fb) { | |
6ccb81f2 | 10043 | drm_gem_object_unreference(&obj->base); |
d2dff872 CW |
10044 | return ERR_PTR(-ENOMEM); |
10045 | } | |
10046 | ||
10047 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10048 | if (ret) |
10049 | goto err; | |
d2dff872 CW |
10050 | |
10051 | return &intel_fb->base; | |
dd4916c5 | 10052 | err: |
6ccb81f2 | 10053 | drm_gem_object_unreference(&obj->base); |
dd4916c5 DV |
10054 | kfree(intel_fb); |
10055 | ||
10056 | return ERR_PTR(ret); | |
d2dff872 CW |
10057 | } |
10058 | ||
b5ea642a | 10059 | static struct drm_framebuffer * |
a8bb6818 DV |
10060 | intel_framebuffer_create(struct drm_device *dev, |
10061 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10062 | struct drm_i915_gem_object *obj) | |
10063 | { | |
10064 | struct drm_framebuffer *fb; | |
10065 | int ret; | |
10066 | ||
10067 | ret = i915_mutex_lock_interruptible(dev); | |
10068 | if (ret) | |
10069 | return ERR_PTR(ret); | |
10070 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10071 | mutex_unlock(&dev->struct_mutex); | |
10072 | ||
10073 | return fb; | |
10074 | } | |
10075 | ||
d2dff872 CW |
10076 | static u32 |
10077 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10078 | { | |
10079 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10080 | return ALIGN(pitch, 64); | |
10081 | } | |
10082 | ||
10083 | static u32 | |
10084 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10085 | { | |
10086 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10087 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10088 | } |
10089 | ||
10090 | static struct drm_framebuffer * | |
10091 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10092 | struct drm_display_mode *mode, | |
10093 | int depth, int bpp) | |
10094 | { | |
10095 | struct drm_i915_gem_object *obj; | |
0fed39bd | 10096 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10097 | |
10098 | obj = i915_gem_alloc_object(dev, | |
10099 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10100 | if (obj == NULL) | |
10101 | return ERR_PTR(-ENOMEM); | |
10102 | ||
10103 | mode_cmd.width = mode->hdisplay; | |
10104 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10105 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10106 | bpp); | |
5ca0c34a | 10107 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 CW |
10108 | |
10109 | return intel_framebuffer_create(dev, &mode_cmd, obj); | |
10110 | } | |
10111 | ||
10112 | static struct drm_framebuffer * | |
10113 | mode_fits_in_fbdev(struct drm_device *dev, | |
10114 | struct drm_display_mode *mode) | |
10115 | { | |
0695726e | 10116 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10117 | struct drm_i915_private *dev_priv = dev->dev_private; |
10118 | struct drm_i915_gem_object *obj; | |
10119 | struct drm_framebuffer *fb; | |
10120 | ||
4c0e5528 | 10121 | if (!dev_priv->fbdev) |
d2dff872 CW |
10122 | return NULL; |
10123 | ||
4c0e5528 | 10124 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10125 | return NULL; |
10126 | ||
4c0e5528 DV |
10127 | obj = dev_priv->fbdev->fb->obj; |
10128 | BUG_ON(!obj); | |
10129 | ||
8bcd4553 | 10130 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10131 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10132 | fb->bits_per_pixel)) | |
d2dff872 CW |
10133 | return NULL; |
10134 | ||
01f2c773 | 10135 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10136 | return NULL; |
10137 | ||
10138 | return fb; | |
4520f53a DV |
10139 | #else |
10140 | return NULL; | |
10141 | #endif | |
d2dff872 CW |
10142 | } |
10143 | ||
d3a40d1b ACO |
10144 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10145 | struct drm_crtc *crtc, | |
10146 | struct drm_display_mode *mode, | |
10147 | struct drm_framebuffer *fb, | |
10148 | int x, int y) | |
10149 | { | |
10150 | struct drm_plane_state *plane_state; | |
10151 | int hdisplay, vdisplay; | |
10152 | int ret; | |
10153 | ||
10154 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10155 | if (IS_ERR(plane_state)) | |
10156 | return PTR_ERR(plane_state); | |
10157 | ||
10158 | if (mode) | |
10159 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10160 | else | |
10161 | hdisplay = vdisplay = 0; | |
10162 | ||
10163 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10164 | if (ret) | |
10165 | return ret; | |
10166 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10167 | plane_state->crtc_x = 0; | |
10168 | plane_state->crtc_y = 0; | |
10169 | plane_state->crtc_w = hdisplay; | |
10170 | plane_state->crtc_h = vdisplay; | |
10171 | plane_state->src_x = x << 16; | |
10172 | plane_state->src_y = y << 16; | |
10173 | plane_state->src_w = hdisplay << 16; | |
10174 | plane_state->src_h = vdisplay << 16; | |
10175 | ||
10176 | return 0; | |
10177 | } | |
10178 | ||
d2434ab7 | 10179 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10180 | struct drm_display_mode *mode, |
51fd371b RC |
10181 | struct intel_load_detect_pipe *old, |
10182 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10183 | { |
10184 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10185 | struct intel_encoder *intel_encoder = |
10186 | intel_attached_encoder(connector); | |
79e53945 | 10187 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10188 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10189 | struct drm_crtc *crtc = NULL; |
10190 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10191 | struct drm_framebuffer *fb; |
51fd371b | 10192 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10193 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10194 | struct drm_connector_state *connector_state; |
4be07317 | 10195 | struct intel_crtc_state *crtc_state; |
51fd371b | 10196 | int ret, i = -1; |
79e53945 | 10197 | |
d2dff872 | 10198 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10199 | connector->base.id, connector->name, |
8e329a03 | 10200 | encoder->base.id, encoder->name); |
d2dff872 | 10201 | |
51fd371b RC |
10202 | retry: |
10203 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10204 | if (ret) | |
ad3c558f | 10205 | goto fail; |
6e9f798d | 10206 | |
79e53945 JB |
10207 | /* |
10208 | * Algorithm gets a little messy: | |
7a5e4805 | 10209 | * |
79e53945 JB |
10210 | * - if the connector already has an assigned crtc, use it (but make |
10211 | * sure it's on first) | |
7a5e4805 | 10212 | * |
79e53945 JB |
10213 | * - try to find the first unused crtc that can drive this connector, |
10214 | * and use that if we find one | |
79e53945 JB |
10215 | */ |
10216 | ||
10217 | /* See if we already have a CRTC for this connector */ | |
10218 | if (encoder->crtc) { | |
10219 | crtc = encoder->crtc; | |
8261b191 | 10220 | |
51fd371b | 10221 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10222 | if (ret) |
ad3c558f | 10223 | goto fail; |
4d02e2de | 10224 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
51fd371b | 10225 | if (ret) |
ad3c558f | 10226 | goto fail; |
7b24056b | 10227 | |
24218aac | 10228 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10229 | old->load_detect_temp = false; |
10230 | ||
10231 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10232 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10233 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10234 | |
7173188d | 10235 | return true; |
79e53945 JB |
10236 | } |
10237 | ||
10238 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10239 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10240 | i++; |
10241 | if (!(encoder->possible_crtcs & (1 << i))) | |
10242 | continue; | |
83d65738 | 10243 | if (possible_crtc->state->enable) |
a459249c | 10244 | continue; |
a459249c VS |
10245 | |
10246 | crtc = possible_crtc; | |
10247 | break; | |
79e53945 JB |
10248 | } |
10249 | ||
10250 | /* | |
10251 | * If we didn't find an unused CRTC, don't use any. | |
10252 | */ | |
10253 | if (!crtc) { | |
7173188d | 10254 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10255 | goto fail; |
79e53945 JB |
10256 | } |
10257 | ||
51fd371b RC |
10258 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10259 | if (ret) | |
ad3c558f | 10260 | goto fail; |
4d02e2de DV |
10261 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10262 | if (ret) | |
ad3c558f | 10263 | goto fail; |
79e53945 JB |
10264 | |
10265 | intel_crtc = to_intel_crtc(crtc); | |
24218aac | 10266 | old->dpms_mode = connector->dpms; |
8261b191 | 10267 | old->load_detect_temp = true; |
d2dff872 | 10268 | old->release_fb = NULL; |
79e53945 | 10269 | |
83a57153 ACO |
10270 | state = drm_atomic_state_alloc(dev); |
10271 | if (!state) | |
10272 | return false; | |
10273 | ||
10274 | state->acquire_ctx = ctx; | |
10275 | ||
944b0c76 ACO |
10276 | connector_state = drm_atomic_get_connector_state(state, connector); |
10277 | if (IS_ERR(connector_state)) { | |
10278 | ret = PTR_ERR(connector_state); | |
10279 | goto fail; | |
10280 | } | |
10281 | ||
10282 | connector_state->crtc = crtc; | |
10283 | connector_state->best_encoder = &intel_encoder->base; | |
10284 | ||
4be07317 ACO |
10285 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10286 | if (IS_ERR(crtc_state)) { | |
10287 | ret = PTR_ERR(crtc_state); | |
10288 | goto fail; | |
10289 | } | |
10290 | ||
49d6fa21 | 10291 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10292 | |
6492711d CW |
10293 | if (!mode) |
10294 | mode = &load_detect_mode; | |
79e53945 | 10295 | |
d2dff872 CW |
10296 | /* We need a framebuffer large enough to accommodate all accesses |
10297 | * that the plane may generate whilst we perform load detection. | |
10298 | * We can not rely on the fbcon either being present (we get called | |
10299 | * during its initialisation to detect all boot displays, or it may | |
10300 | * not even exist) or that it is large enough to satisfy the | |
10301 | * requested mode. | |
10302 | */ | |
94352cf9 DV |
10303 | fb = mode_fits_in_fbdev(dev, mode); |
10304 | if (fb == NULL) { | |
d2dff872 | 10305 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10306 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10307 | old->release_fb = fb; | |
d2dff872 CW |
10308 | } else |
10309 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10310 | if (IS_ERR(fb)) { |
d2dff872 | 10311 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10312 | goto fail; |
79e53945 | 10313 | } |
79e53945 | 10314 | |
d3a40d1b ACO |
10315 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10316 | if (ret) | |
10317 | goto fail; | |
10318 | ||
8c7b5ccb ACO |
10319 | drm_mode_copy(&crtc_state->base.mode, mode); |
10320 | ||
74c090b1 | 10321 | if (drm_atomic_commit(state)) { |
6492711d | 10322 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10323 | if (old->release_fb) |
10324 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10325 | goto fail; |
79e53945 | 10326 | } |
9128b040 | 10327 | crtc->primary->crtc = crtc; |
7173188d | 10328 | |
79e53945 | 10329 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10330 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10331 | return true; |
412b61d8 | 10332 | |
ad3c558f | 10333 | fail: |
e5d958ef ACO |
10334 | drm_atomic_state_free(state); |
10335 | state = NULL; | |
83a57153 | 10336 | |
51fd371b RC |
10337 | if (ret == -EDEADLK) { |
10338 | drm_modeset_backoff(ctx); | |
10339 | goto retry; | |
10340 | } | |
10341 | ||
412b61d8 | 10342 | return false; |
79e53945 JB |
10343 | } |
10344 | ||
d2434ab7 | 10345 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10346 | struct intel_load_detect_pipe *old, |
10347 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10348 | { |
83a57153 | 10349 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10350 | struct intel_encoder *intel_encoder = |
10351 | intel_attached_encoder(connector); | |
4ef69c7a | 10352 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10353 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10354 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10355 | struct drm_atomic_state *state; |
944b0c76 | 10356 | struct drm_connector_state *connector_state; |
4be07317 | 10357 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10358 | int ret; |
79e53945 | 10359 | |
d2dff872 | 10360 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10361 | connector->base.id, connector->name, |
8e329a03 | 10362 | encoder->base.id, encoder->name); |
d2dff872 | 10363 | |
8261b191 | 10364 | if (old->load_detect_temp) { |
83a57153 | 10365 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10366 | if (!state) |
10367 | goto fail; | |
83a57153 ACO |
10368 | |
10369 | state->acquire_ctx = ctx; | |
10370 | ||
944b0c76 ACO |
10371 | connector_state = drm_atomic_get_connector_state(state, connector); |
10372 | if (IS_ERR(connector_state)) | |
10373 | goto fail; | |
10374 | ||
4be07317 ACO |
10375 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10376 | if (IS_ERR(crtc_state)) | |
10377 | goto fail; | |
10378 | ||
944b0c76 ACO |
10379 | connector_state->best_encoder = NULL; |
10380 | connector_state->crtc = NULL; | |
10381 | ||
49d6fa21 | 10382 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10383 | |
d3a40d1b ACO |
10384 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10385 | 0, 0); | |
10386 | if (ret) | |
10387 | goto fail; | |
10388 | ||
74c090b1 | 10389 | ret = drm_atomic_commit(state); |
2bfb4627 ACO |
10390 | if (ret) |
10391 | goto fail; | |
d2dff872 | 10392 | |
36206361 DV |
10393 | if (old->release_fb) { |
10394 | drm_framebuffer_unregister_private(old->release_fb); | |
10395 | drm_framebuffer_unreference(old->release_fb); | |
10396 | } | |
d2dff872 | 10397 | |
0622a53c | 10398 | return; |
79e53945 JB |
10399 | } |
10400 | ||
c751ce4f | 10401 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10402 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10403 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10404 | |
10405 | return; | |
10406 | fail: | |
10407 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10408 | drm_atomic_state_free(state); | |
79e53945 JB |
10409 | } |
10410 | ||
da4a1efa | 10411 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10412 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10413 | { |
10414 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10415 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10416 | ||
10417 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10418 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10419 | else if (HAS_PCH_SPLIT(dev)) |
10420 | return 120000; | |
10421 | else if (!IS_GEN2(dev)) | |
10422 | return 96000; | |
10423 | else | |
10424 | return 48000; | |
10425 | } | |
10426 | ||
79e53945 | 10427 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10428 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10429 | struct intel_crtc_state *pipe_config) |
79e53945 | 10430 | { |
f1f644dc | 10431 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10432 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10433 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10434 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10435 | u32 fp; |
10436 | intel_clock_t clock; | |
dccbea3b | 10437 | int port_clock; |
da4a1efa | 10438 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10439 | |
10440 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10441 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10442 | else |
293623f7 | 10443 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10444 | |
10445 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10446 | if (IS_PINEVIEW(dev)) { |
10447 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10448 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10449 | } else { |
10450 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10451 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10452 | } | |
10453 | ||
a6c45cf0 | 10454 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10455 | if (IS_PINEVIEW(dev)) |
10456 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10457 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10458 | else |
10459 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10460 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10461 | ||
10462 | switch (dpll & DPLL_MODE_MASK) { | |
10463 | case DPLLB_MODE_DAC_SERIAL: | |
10464 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10465 | 5 : 10; | |
10466 | break; | |
10467 | case DPLLB_MODE_LVDS: | |
10468 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10469 | 7 : 14; | |
10470 | break; | |
10471 | default: | |
28c97730 | 10472 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10473 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10474 | return; |
79e53945 JB |
10475 | } |
10476 | ||
ac58c3f0 | 10477 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10478 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10479 | else |
dccbea3b | 10480 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10481 | } else { |
0fb58223 | 10482 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10483 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10484 | |
10485 | if (is_lvds) { | |
10486 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10487 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10488 | |
10489 | if (lvds & LVDS_CLKB_POWER_UP) | |
10490 | clock.p2 = 7; | |
10491 | else | |
10492 | clock.p2 = 14; | |
79e53945 JB |
10493 | } else { |
10494 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10495 | clock.p1 = 2; | |
10496 | else { | |
10497 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10498 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10499 | } | |
10500 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10501 | clock.p2 = 4; | |
10502 | else | |
10503 | clock.p2 = 2; | |
79e53945 | 10504 | } |
da4a1efa | 10505 | |
dccbea3b | 10506 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10507 | } |
10508 | ||
18442d08 VS |
10509 | /* |
10510 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10511 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10512 | * encoder's get_config() function. |
10513 | */ | |
dccbea3b | 10514 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10515 | } |
10516 | ||
6878da05 VS |
10517 | int intel_dotclock_calculate(int link_freq, |
10518 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10519 | { |
f1f644dc JB |
10520 | /* |
10521 | * The calculation for the data clock is: | |
1041a02f | 10522 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10523 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10524 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10525 | * |
10526 | * and the link clock is simpler: | |
1041a02f | 10527 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10528 | */ |
10529 | ||
6878da05 VS |
10530 | if (!m_n->link_n) |
10531 | return 0; | |
f1f644dc | 10532 | |
6878da05 VS |
10533 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10534 | } | |
f1f644dc | 10535 | |
18442d08 | 10536 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10537 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10538 | { |
10539 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10540 | |
18442d08 VS |
10541 | /* read out port_clock from the DPLL */ |
10542 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10543 | |
f1f644dc | 10544 | /* |
18442d08 | 10545 | * This value does not include pixel_multiplier. |
241bfc38 | 10546 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10547 | * agree once we know their relationship in the encoder's |
10548 | * get_config() function. | |
79e53945 | 10549 | */ |
2d112de7 | 10550 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10551 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10552 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10553 | } |
10554 | ||
10555 | /** Returns the currently programmed mode of the given pipe. */ | |
10556 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10557 | struct drm_crtc *crtc) | |
10558 | { | |
548f245b | 10559 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10560 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10561 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10562 | struct drm_display_mode *mode; |
5cec258b | 10563 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10564 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10565 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10566 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10567 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10568 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10569 | |
10570 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10571 | if (!mode) | |
10572 | return NULL; | |
10573 | ||
f1f644dc JB |
10574 | /* |
10575 | * Construct a pipe_config sufficient for getting the clock info | |
10576 | * back out of crtc_clock_get. | |
10577 | * | |
10578 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10579 | * to use a real value here instead. | |
10580 | */ | |
293623f7 | 10581 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10582 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10583 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10584 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10585 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10586 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10587 | ||
773ae034 | 10588 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10589 | mode->hdisplay = (htot & 0xffff) + 1; |
10590 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10591 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10592 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10593 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10594 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10595 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10596 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10597 | ||
10598 | drm_mode_set_name(mode); | |
79e53945 JB |
10599 | |
10600 | return mode; | |
10601 | } | |
10602 | ||
f047e395 CW |
10603 | void intel_mark_busy(struct drm_device *dev) |
10604 | { | |
c67a470b PZ |
10605 | struct drm_i915_private *dev_priv = dev->dev_private; |
10606 | ||
f62a0076 CW |
10607 | if (dev_priv->mm.busy) |
10608 | return; | |
10609 | ||
43694d69 | 10610 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10611 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10612 | if (INTEL_INFO(dev)->gen >= 6) |
10613 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10614 | dev_priv->mm.busy = true; |
f047e395 CW |
10615 | } |
10616 | ||
10617 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10618 | { |
c67a470b | 10619 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10620 | |
f62a0076 CW |
10621 | if (!dev_priv->mm.busy) |
10622 | return; | |
10623 | ||
10624 | dev_priv->mm.busy = false; | |
10625 | ||
3d13ef2e | 10626 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10627 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10628 | |
43694d69 | 10629 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10630 | } |
10631 | ||
79e53945 JB |
10632 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10633 | { | |
10634 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10635 | struct drm_device *dev = crtc->dev; |
10636 | struct intel_unpin_work *work; | |
67e77c5a | 10637 | |
5e2d7afc | 10638 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10639 | work = intel_crtc->unpin_work; |
10640 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10641 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10642 | |
10643 | if (work) { | |
10644 | cancel_work_sync(&work->work); | |
10645 | kfree(work); | |
10646 | } | |
79e53945 JB |
10647 | |
10648 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10649 | |
79e53945 JB |
10650 | kfree(intel_crtc); |
10651 | } | |
10652 | ||
6b95a207 KH |
10653 | static void intel_unpin_work_fn(struct work_struct *__work) |
10654 | { | |
10655 | struct intel_unpin_work *work = | |
10656 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10657 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10658 | struct drm_device *dev = crtc->base.dev; | |
10659 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10660 | |
b4a98e57 | 10661 | mutex_lock(&dev->struct_mutex); |
a9ff8714 | 10662 | intel_unpin_fb_obj(work->old_fb, primary->state); |
05394f39 | 10663 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10664 | |
f06cc1b9 | 10665 | if (work->flip_queued_req) |
146d84f0 | 10666 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10667 | mutex_unlock(&dev->struct_mutex); |
10668 | ||
a9ff8714 | 10669 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
89ed88ba | 10670 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10671 | |
a9ff8714 VS |
10672 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10673 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10674 | |
6b95a207 KH |
10675 | kfree(work); |
10676 | } | |
10677 | ||
1afe3e9d | 10678 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10679 | struct drm_crtc *crtc) |
6b95a207 | 10680 | { |
6b95a207 KH |
10681 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10682 | struct intel_unpin_work *work; | |
6b95a207 KH |
10683 | unsigned long flags; |
10684 | ||
10685 | /* Ignore early vblank irqs */ | |
10686 | if (intel_crtc == NULL) | |
10687 | return; | |
10688 | ||
f326038a DV |
10689 | /* |
10690 | * This is called both by irq handlers and the reset code (to complete | |
10691 | * lost pageflips) so needs the full irqsave spinlocks. | |
10692 | */ | |
6b95a207 KH |
10693 | spin_lock_irqsave(&dev->event_lock, flags); |
10694 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10695 | |
10696 | /* Ensure we don't miss a work->pending update ... */ | |
10697 | smp_rmb(); | |
10698 | ||
10699 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10700 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10701 | return; | |
10702 | } | |
10703 | ||
d6bbafa1 | 10704 | page_flip_completed(intel_crtc); |
0af7e4df | 10705 | |
6b95a207 | 10706 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10707 | } |
10708 | ||
1afe3e9d JB |
10709 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10710 | { | |
fbee40df | 10711 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10712 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10713 | ||
49b14a5c | 10714 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10715 | } |
10716 | ||
10717 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10718 | { | |
fbee40df | 10719 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10720 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10721 | ||
49b14a5c | 10722 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10723 | } |
10724 | ||
75f7f3ec VS |
10725 | /* Is 'a' after or equal to 'b'? */ |
10726 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10727 | { | |
10728 | return !((a - b) & 0x80000000); | |
10729 | } | |
10730 | ||
10731 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10732 | { | |
10733 | struct drm_device *dev = crtc->base.dev; | |
10734 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10735 | ||
bdfa7542 VS |
10736 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10737 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10738 | return true; | |
10739 | ||
75f7f3ec VS |
10740 | /* |
10741 | * The relevant registers doen't exist on pre-ctg. | |
10742 | * As the flip done interrupt doesn't trigger for mmio | |
10743 | * flips on gmch platforms, a flip count check isn't | |
10744 | * really needed there. But since ctg has the registers, | |
10745 | * include it in the check anyway. | |
10746 | */ | |
10747 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10748 | return true; | |
10749 | ||
10750 | /* | |
10751 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10752 | * used the same base address. In that case the mmio flip might | |
10753 | * have completed, but the CS hasn't even executed the flip yet. | |
10754 | * | |
10755 | * A flip count check isn't enough as the CS might have updated | |
10756 | * the base address just after start of vblank, but before we | |
10757 | * managed to process the interrupt. This means we'd complete the | |
10758 | * CS flip too soon. | |
10759 | * | |
10760 | * Combining both checks should get us a good enough result. It may | |
10761 | * still happen that the CS flip has been executed, but has not | |
10762 | * yet actually completed. But in case the base address is the same | |
10763 | * anyway, we don't really care. | |
10764 | */ | |
10765 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10766 | crtc->unpin_work->gtt_offset && | |
10767 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), | |
10768 | crtc->unpin_work->flip_count); | |
10769 | } | |
10770 | ||
6b95a207 KH |
10771 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10772 | { | |
fbee40df | 10773 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10774 | struct intel_crtc *intel_crtc = |
10775 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10776 | unsigned long flags; | |
10777 | ||
f326038a DV |
10778 | |
10779 | /* | |
10780 | * This is called both by irq handlers and the reset code (to complete | |
10781 | * lost pageflips) so needs the full irqsave spinlocks. | |
10782 | * | |
10783 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10784 | * generate a page-flip completion irq, i.e. every modeset |
10785 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10786 | */ | |
6b95a207 | 10787 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10788 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10789 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10790 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10791 | } | |
10792 | ||
eba905b2 | 10793 | static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc) |
e7d841ca CW |
10794 | { |
10795 | /* Ensure that the work item is consistent when activating it ... */ | |
10796 | smp_wmb(); | |
10797 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); | |
10798 | /* and that it is marked active as soon as the irq could fire. */ | |
10799 | smp_wmb(); | |
10800 | } | |
10801 | ||
8c9f3aaf JB |
10802 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10803 | struct drm_crtc *crtc, | |
10804 | struct drm_framebuffer *fb, | |
ed8d1975 | 10805 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10806 | struct drm_i915_gem_request *req, |
ed8d1975 | 10807 | uint32_t flags) |
8c9f3aaf | 10808 | { |
6258fbe2 | 10809 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10810 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10811 | u32 flip_mask; |
10812 | int ret; | |
10813 | ||
5fb9de1a | 10814 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10815 | if (ret) |
4fa62c89 | 10816 | return ret; |
8c9f3aaf JB |
10817 | |
10818 | /* Can't queue multiple flips, so wait for the previous | |
10819 | * one to finish before executing the next. | |
10820 | */ | |
10821 | if (intel_crtc->plane) | |
10822 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10823 | else | |
10824 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10825 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10826 | intel_ring_emit(ring, MI_NOOP); | |
10827 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10828 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10829 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10830 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10831 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca CW |
10832 | |
10833 | intel_mark_page_flip_active(intel_crtc); | |
83d4092b | 10834 | return 0; |
8c9f3aaf JB |
10835 | } |
10836 | ||
10837 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10838 | struct drm_crtc *crtc, | |
10839 | struct drm_framebuffer *fb, | |
ed8d1975 | 10840 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10841 | struct drm_i915_gem_request *req, |
ed8d1975 | 10842 | uint32_t flags) |
8c9f3aaf | 10843 | { |
6258fbe2 | 10844 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 10845 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10846 | u32 flip_mask; |
10847 | int ret; | |
10848 | ||
5fb9de1a | 10849 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 10850 | if (ret) |
4fa62c89 | 10851 | return ret; |
8c9f3aaf JB |
10852 | |
10853 | if (intel_crtc->plane) | |
10854 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10855 | else | |
10856 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10857 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10858 | intel_ring_emit(ring, MI_NOOP); | |
10859 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
10860 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10861 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10862 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
10863 | intel_ring_emit(ring, MI_NOOP); |
10864 | ||
e7d841ca | 10865 | intel_mark_page_flip_active(intel_crtc); |
83d4092b | 10866 | return 0; |
8c9f3aaf JB |
10867 | } |
10868 | ||
10869 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
10870 | struct drm_crtc *crtc, | |
10871 | struct drm_framebuffer *fb, | |
ed8d1975 | 10872 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10873 | struct drm_i915_gem_request *req, |
ed8d1975 | 10874 | uint32_t flags) |
8c9f3aaf | 10875 | { |
6258fbe2 | 10876 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10877 | struct drm_i915_private *dev_priv = dev->dev_private; |
10878 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10879 | uint32_t pf, pipesrc; | |
10880 | int ret; | |
10881 | ||
5fb9de1a | 10882 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10883 | if (ret) |
4fa62c89 | 10884 | return ret; |
8c9f3aaf JB |
10885 | |
10886 | /* i965+ uses the linear or tiled offsets from the | |
10887 | * Display Registers (which do not change across a page-flip) | |
10888 | * so we need only reprogram the base address. | |
10889 | */ | |
6d90c952 DV |
10890 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10891 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10892 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10893 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 10894 | obj->tiling_mode); |
8c9f3aaf JB |
10895 | |
10896 | /* XXX Enabling the panel-fitter across page-flip is so far | |
10897 | * untested on non-native modes, so ignore it for now. | |
10898 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
10899 | */ | |
10900 | pf = 0; | |
10901 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 10902 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
10903 | |
10904 | intel_mark_page_flip_active(intel_crtc); | |
83d4092b | 10905 | return 0; |
8c9f3aaf JB |
10906 | } |
10907 | ||
10908 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
10909 | struct drm_crtc *crtc, | |
10910 | struct drm_framebuffer *fb, | |
ed8d1975 | 10911 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10912 | struct drm_i915_gem_request *req, |
ed8d1975 | 10913 | uint32_t flags) |
8c9f3aaf | 10914 | { |
6258fbe2 | 10915 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
10916 | struct drm_i915_private *dev_priv = dev->dev_private; |
10917 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10918 | uint32_t pf, pipesrc; | |
10919 | int ret; | |
10920 | ||
5fb9de1a | 10921 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 10922 | if (ret) |
4fa62c89 | 10923 | return ret; |
8c9f3aaf | 10924 | |
6d90c952 DV |
10925 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10926 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10927 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 10928 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 10929 | |
dc257cf1 DV |
10930 | /* Contrary to the suggestions in the documentation, |
10931 | * "Enable Panel Fitter" does not seem to be required when page | |
10932 | * flipping with a non-native mode, and worse causes a normal | |
10933 | * modeset to fail. | |
10934 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
10935 | */ | |
10936 | pf = 0; | |
8c9f3aaf | 10937 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 10938 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
10939 | |
10940 | intel_mark_page_flip_active(intel_crtc); | |
83d4092b | 10941 | return 0; |
8c9f3aaf JB |
10942 | } |
10943 | ||
7c9017e5 JB |
10944 | static int intel_gen7_queue_flip(struct drm_device *dev, |
10945 | struct drm_crtc *crtc, | |
10946 | struct drm_framebuffer *fb, | |
ed8d1975 | 10947 | struct drm_i915_gem_object *obj, |
6258fbe2 | 10948 | struct drm_i915_gem_request *req, |
ed8d1975 | 10949 | uint32_t flags) |
7c9017e5 | 10950 | { |
6258fbe2 | 10951 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 10952 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 10953 | uint32_t plane_bit = 0; |
ffe74d75 CW |
10954 | int len, ret; |
10955 | ||
eba905b2 | 10956 | switch (intel_crtc->plane) { |
cb05d8de DV |
10957 | case PLANE_A: |
10958 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
10959 | break; | |
10960 | case PLANE_B: | |
10961 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
10962 | break; | |
10963 | case PLANE_C: | |
10964 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
10965 | break; | |
10966 | default: | |
10967 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 10968 | return -ENODEV; |
cb05d8de DV |
10969 | } |
10970 | ||
ffe74d75 | 10971 | len = 4; |
f476828a | 10972 | if (ring->id == RCS) { |
ffe74d75 | 10973 | len += 6; |
f476828a DL |
10974 | /* |
10975 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
10976 | * 48bits addresses, and we need a NOOP for the batch size to | |
10977 | * stay even. | |
10978 | */ | |
10979 | if (IS_GEN8(dev)) | |
10980 | len += 2; | |
10981 | } | |
ffe74d75 | 10982 | |
f66fab8e VS |
10983 | /* |
10984 | * BSpec MI_DISPLAY_FLIP for IVB: | |
10985 | * "The full packet must be contained within the same cache line." | |
10986 | * | |
10987 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
10988 | * cacheline, if we ever start emitting more commands before | |
10989 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
10990 | * then do the cacheline alignment, and finally emit the | |
10991 | * MI_DISPLAY_FLIP. | |
10992 | */ | |
bba09b12 | 10993 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 10994 | if (ret) |
4fa62c89 | 10995 | return ret; |
f66fab8e | 10996 | |
5fb9de1a | 10997 | ret = intel_ring_begin(req, len); |
7c9017e5 | 10998 | if (ret) |
4fa62c89 | 10999 | return ret; |
7c9017e5 | 11000 | |
ffe74d75 CW |
11001 | /* Unmask the flip-done completion message. Note that the bspec says that |
11002 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11003 | * more than one flip event at any time (or ensure that one flip message | |
11004 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11005 | * Experimentation says that BCS works despite DERRMR masking all | |
11006 | * flip-done completion events and that unmasking all planes at once | |
11007 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11008 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11009 | */ | |
11010 | if (ring->id == RCS) { | |
11011 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11012 | intel_ring_emit(ring, DERRMR); | |
11013 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11014 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11015 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11016 | if (IS_GEN8(dev)) |
f1afe24f | 11017 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11018 | MI_SRM_LRM_GLOBAL_GTT); |
11019 | else | |
f1afe24f | 11020 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11021 | MI_SRM_LRM_GLOBAL_GTT); |
ffe74d75 CW |
11022 | intel_ring_emit(ring, DERRMR); |
11023 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
11024 | if (IS_GEN8(dev)) { |
11025 | intel_ring_emit(ring, 0); | |
11026 | intel_ring_emit(ring, MI_NOOP); | |
11027 | } | |
ffe74d75 CW |
11028 | } |
11029 | ||
cb05d8de | 11030 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11031 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11032 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11033 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca CW |
11034 | |
11035 | intel_mark_page_flip_active(intel_crtc); | |
83d4092b | 11036 | return 0; |
7c9017e5 JB |
11037 | } |
11038 | ||
84c33a64 SG |
11039 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11040 | struct drm_i915_gem_object *obj) | |
11041 | { | |
11042 | /* | |
11043 | * This is not being used for older platforms, because | |
11044 | * non-availability of flip done interrupt forces us to use | |
11045 | * CS flips. Older platforms derive flip done using some clever | |
11046 | * tricks involving the flip_pending status bits and vblank irqs. | |
11047 | * So using MMIO flips there would disrupt this mechanism. | |
11048 | */ | |
11049 | ||
8e09bf83 CW |
11050 | if (ring == NULL) |
11051 | return true; | |
11052 | ||
84c33a64 SG |
11053 | if (INTEL_INFO(ring->dev)->gen < 5) |
11054 | return false; | |
11055 | ||
11056 | if (i915.use_mmio_flip < 0) | |
11057 | return false; | |
11058 | else if (i915.use_mmio_flip > 0) | |
11059 | return true; | |
14bf993e OM |
11060 | else if (i915.enable_execlists) |
11061 | return true; | |
84c33a64 | 11062 | else |
b4716185 | 11063 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11064 | } |
11065 | ||
ff944564 DL |
11066 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
11067 | { | |
11068 | struct drm_device *dev = intel_crtc->base.dev; | |
11069 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11070 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 DL |
11071 | const enum pipe pipe = intel_crtc->pipe; |
11072 | u32 ctl, stride; | |
11073 | ||
11074 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11075 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11076 | switch (fb->modifier[0]) { |
11077 | case DRM_FORMAT_MOD_NONE: | |
11078 | break; | |
11079 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11080 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11081 | break; |
11082 | case I915_FORMAT_MOD_Y_TILED: | |
11083 | ctl |= PLANE_CTL_TILED_Y; | |
11084 | break; | |
11085 | case I915_FORMAT_MOD_Yf_TILED: | |
11086 | ctl |= PLANE_CTL_TILED_YF; | |
11087 | break; | |
11088 | default: | |
11089 | MISSING_CASE(fb->modifier[0]); | |
11090 | } | |
ff944564 DL |
11091 | |
11092 | /* | |
11093 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11094 | * linear buffers or in number of tiles for tiled buffers. | |
11095 | */ | |
2ebef630 TU |
11096 | stride = fb->pitches[0] / |
11097 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11098 | fb->pixel_format); | |
ff944564 DL |
11099 | |
11100 | /* | |
11101 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11102 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11103 | */ | |
11104 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11105 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11106 | ||
11107 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); | |
11108 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
11109 | } | |
11110 | ||
11111 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) | |
84c33a64 SG |
11112 | { |
11113 | struct drm_device *dev = intel_crtc->base.dev; | |
11114 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11115 | struct intel_framebuffer *intel_fb = | |
11116 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11117 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11118 | u32 dspcntr; | |
11119 | u32 reg; | |
11120 | ||
84c33a64 SG |
11121 | reg = DSPCNTR(intel_crtc->plane); |
11122 | dspcntr = I915_READ(reg); | |
11123 | ||
c5d97472 DL |
11124 | if (obj->tiling_mode != I915_TILING_NONE) |
11125 | dspcntr |= DISPPLANE_TILED; | |
11126 | else | |
11127 | dspcntr &= ~DISPPLANE_TILED; | |
11128 | ||
84c33a64 SG |
11129 | I915_WRITE(reg, dspcntr); |
11130 | ||
11131 | I915_WRITE(DSPSURF(intel_crtc->plane), | |
11132 | intel_crtc->unpin_work->gtt_offset); | |
11133 | POSTING_READ(DSPSURF(intel_crtc->plane)); | |
84c33a64 | 11134 | |
ff944564 DL |
11135 | } |
11136 | ||
11137 | /* | |
11138 | * XXX: This is the temporary way to update the plane registers until we get | |
11139 | * around to using the usual plane update functions for MMIO flips | |
11140 | */ | |
11141 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) | |
11142 | { | |
11143 | struct drm_device *dev = intel_crtc->base.dev; | |
ff944564 DL |
11144 | |
11145 | intel_mark_page_flip_active(intel_crtc); | |
11146 | ||
34e0adbb | 11147 | intel_pipe_update_start(intel_crtc); |
ff944564 DL |
11148 | |
11149 | if (INTEL_INFO(dev)->gen >= 9) | |
11150 | skl_do_mmio_flip(intel_crtc); | |
11151 | else | |
11152 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
11153 | ilk_do_mmio_flip(intel_crtc); | |
11154 | ||
34e0adbb | 11155 | intel_pipe_update_end(intel_crtc); |
84c33a64 SG |
11156 | } |
11157 | ||
9362c7c5 | 11158 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11159 | { |
b2cfe0ab CW |
11160 | struct intel_mmio_flip *mmio_flip = |
11161 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11162 | |
eed29a5b DV |
11163 | if (mmio_flip->req) |
11164 | WARN_ON(__i915_wait_request(mmio_flip->req, | |
b2cfe0ab | 11165 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11166 | false, NULL, |
11167 | &mmio_flip->i915->rps.mmioflips)); | |
84c33a64 | 11168 | |
b2cfe0ab CW |
11169 | intel_do_mmio_flip(mmio_flip->crtc); |
11170 | ||
eed29a5b | 11171 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
b2cfe0ab | 11172 | kfree(mmio_flip); |
84c33a64 SG |
11173 | } |
11174 | ||
11175 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11176 | struct drm_crtc *crtc, | |
11177 | struct drm_framebuffer *fb, | |
11178 | struct drm_i915_gem_object *obj, | |
11179 | struct intel_engine_cs *ring, | |
11180 | uint32_t flags) | |
11181 | { | |
b2cfe0ab CW |
11182 | struct intel_mmio_flip *mmio_flip; |
11183 | ||
11184 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11185 | if (mmio_flip == NULL) | |
11186 | return -ENOMEM; | |
84c33a64 | 11187 | |
bcafc4e3 | 11188 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11189 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11190 | mmio_flip->crtc = to_intel_crtc(crtc); |
536f5b5e | 11191 | |
b2cfe0ab CW |
11192 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11193 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11194 | |
84c33a64 SG |
11195 | return 0; |
11196 | } | |
11197 | ||
8c9f3aaf JB |
11198 | static int intel_default_queue_flip(struct drm_device *dev, |
11199 | struct drm_crtc *crtc, | |
11200 | struct drm_framebuffer *fb, | |
ed8d1975 | 11201 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11202 | struct drm_i915_gem_request *req, |
ed8d1975 | 11203 | uint32_t flags) |
8c9f3aaf JB |
11204 | { |
11205 | return -ENODEV; | |
11206 | } | |
11207 | ||
d6bbafa1 CW |
11208 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11209 | struct drm_crtc *crtc) | |
11210 | { | |
11211 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11212 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11213 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11214 | u32 addr; | |
11215 | ||
11216 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11217 | return true; | |
11218 | ||
908565c2 CW |
11219 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11220 | return false; | |
11221 | ||
d6bbafa1 CW |
11222 | if (!work->enable_stall_check) |
11223 | return false; | |
11224 | ||
11225 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11226 | if (work->flip_queued_req && |
11227 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11228 | return false; |
11229 | ||
1e3feefd | 11230 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11231 | } |
11232 | ||
1e3feefd | 11233 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11234 | return false; |
11235 | ||
11236 | /* Potential stall - if we see that the flip has happened, | |
11237 | * assume a missed interrupt. */ | |
11238 | if (INTEL_INFO(dev)->gen >= 4) | |
11239 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11240 | else | |
11241 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11242 | ||
11243 | /* There is a potential issue here with a false positive after a flip | |
11244 | * to the same address. We could address this by checking for a | |
11245 | * non-incrementing frame counter. | |
11246 | */ | |
11247 | return addr == work->gtt_offset; | |
11248 | } | |
11249 | ||
11250 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11251 | { | |
11252 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11253 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11254 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11255 | struct intel_unpin_work *work; |
f326038a | 11256 | |
6c51d46f | 11257 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11258 | |
11259 | if (crtc == NULL) | |
11260 | return; | |
11261 | ||
f326038a | 11262 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11263 | work = intel_crtc->unpin_work; |
11264 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11265 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11266 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11267 | page_flip_completed(intel_crtc); |
6ad790c0 | 11268 | work = NULL; |
d6bbafa1 | 11269 | } |
6ad790c0 CW |
11270 | if (work != NULL && |
11271 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11272 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11273 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11274 | } |
11275 | ||
6b95a207 KH |
11276 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11277 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11278 | struct drm_pending_vblank_event *event, |
11279 | uint32_t page_flip_flags) | |
6b95a207 KH |
11280 | { |
11281 | struct drm_device *dev = crtc->dev; | |
11282 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11283 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11284 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11285 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11286 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11287 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11288 | struct intel_unpin_work *work; |
a4872ba6 | 11289 | struct intel_engine_cs *ring; |
cf5d8a46 | 11290 | bool mmio_flip; |
91af127f | 11291 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11292 | int ret; |
6b95a207 | 11293 | |
2ff8fde1 MR |
11294 | /* |
11295 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11296 | * check to be safe. In the future we may enable pageflipping from | |
11297 | * a disabled primary plane. | |
11298 | */ | |
11299 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11300 | return -EBUSY; | |
11301 | ||
e6a595d2 | 11302 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11303 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11304 | return -EINVAL; |
11305 | ||
11306 | /* | |
11307 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11308 | * Note that pitch changes could also affect these register. | |
11309 | */ | |
11310 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11311 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11312 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11313 | return -EINVAL; |
11314 | ||
f900db47 CW |
11315 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11316 | goto out_hang; | |
11317 | ||
b14c5679 | 11318 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11319 | if (work == NULL) |
11320 | return -ENOMEM; | |
11321 | ||
6b95a207 | 11322 | work->event = event; |
b4a98e57 | 11323 | work->crtc = crtc; |
ab8d6675 | 11324 | work->old_fb = old_fb; |
6b95a207 KH |
11325 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11326 | ||
87b6b101 | 11327 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11328 | if (ret) |
11329 | goto free_work; | |
11330 | ||
6b95a207 | 11331 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11332 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11333 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11334 | /* Before declaring the flip queue wedged, check if |
11335 | * the hardware completed the operation behind our backs. | |
11336 | */ | |
11337 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11338 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11339 | page_flip_completed(intel_crtc); | |
11340 | } else { | |
11341 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11342 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11343 | |
d6bbafa1 CW |
11344 | drm_crtc_vblank_put(crtc); |
11345 | kfree(work); | |
11346 | return -EBUSY; | |
11347 | } | |
6b95a207 KH |
11348 | } |
11349 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11350 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11351 | |
b4a98e57 CW |
11352 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11353 | flush_workqueue(dev_priv->wq); | |
11354 | ||
75dfca80 | 11355 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11356 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11357 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11358 | |
f4510a27 | 11359 | crtc->primary->fb = fb; |
afd65eb4 | 11360 | update_state_fb(crtc->primary); |
1ed1f968 | 11361 | |
e1f99ce6 | 11362 | work->pending_flip_obj = obj; |
e1f99ce6 | 11363 | |
89ed88ba CW |
11364 | ret = i915_mutex_lock_interruptible(dev); |
11365 | if (ret) | |
11366 | goto cleanup; | |
11367 | ||
b4a98e57 | 11368 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11369 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11370 | |
75f7f3ec | 11371 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
a071fa00 | 11372 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
75f7f3ec | 11373 | |
4fa62c89 VS |
11374 | if (IS_VALLEYVIEW(dev)) { |
11375 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11376 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11377 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11378 | ring = NULL; | |
48bf5b2d | 11379 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11380 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11381 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11382 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11383 | if (ring == NULL || ring->id != RCS) |
11384 | ring = &dev_priv->ring[BCS]; | |
11385 | } else { | |
11386 | ring = &dev_priv->ring[RCS]; | |
11387 | } | |
11388 | ||
cf5d8a46 CW |
11389 | mmio_flip = use_mmio_flip(ring, obj); |
11390 | ||
11391 | /* When using CS flips, we want to emit semaphores between rings. | |
11392 | * However, when using mmio flips we will create a task to do the | |
11393 | * synchronisation, so all we want here is to pin the framebuffer | |
11394 | * into the display plane and skip any waits. | |
11395 | */ | |
82bc3b2d | 11396 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
cf5d8a46 | 11397 | crtc->primary->state, |
91af127f | 11398 | mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring, &request); |
8c9f3aaf JB |
11399 | if (ret) |
11400 | goto cleanup_pending; | |
6b95a207 | 11401 | |
121920fa TU |
11402 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
11403 | + intel_crtc->dspaddr_offset; | |
4fa62c89 | 11404 | |
cf5d8a46 | 11405 | if (mmio_flip) { |
84c33a64 SG |
11406 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
11407 | page_flip_flags); | |
d6bbafa1 CW |
11408 | if (ret) |
11409 | goto cleanup_unpin; | |
11410 | ||
f06cc1b9 JH |
11411 | i915_gem_request_assign(&work->flip_queued_req, |
11412 | obj->last_write_req); | |
d6bbafa1 | 11413 | } else { |
6258fbe2 JH |
11414 | if (!request) { |
11415 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); | |
11416 | if (ret) | |
11417 | goto cleanup_unpin; | |
11418 | } | |
11419 | ||
11420 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11421 | page_flip_flags); |
11422 | if (ret) | |
11423 | goto cleanup_unpin; | |
11424 | ||
6258fbe2 | 11425 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11426 | } |
11427 | ||
91af127f | 11428 | if (request) |
75289874 | 11429 | i915_add_request_no_flush(request); |
91af127f | 11430 | |
1e3feefd | 11431 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11432 | work->enable_stall_check = true; |
4fa62c89 | 11433 | |
ab8d6675 | 11434 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11435 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11436 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11437 | |
4e1e26f1 | 11438 | intel_fbc_disable_crtc(intel_crtc); |
a9ff8714 VS |
11439 | intel_frontbuffer_flip_prepare(dev, |
11440 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11441 | |
e5510fac JB |
11442 | trace_i915_flip_request(intel_crtc->plane, obj); |
11443 | ||
6b95a207 | 11444 | return 0; |
96b099fd | 11445 | |
4fa62c89 | 11446 | cleanup_unpin: |
82bc3b2d | 11447 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11448 | cleanup_pending: |
91af127f JH |
11449 | if (request) |
11450 | i915_gem_request_cancel(request); | |
b4a98e57 | 11451 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11452 | mutex_unlock(&dev->struct_mutex); |
11453 | cleanup: | |
f4510a27 | 11454 | crtc->primary->fb = old_fb; |
afd65eb4 | 11455 | update_state_fb(crtc->primary); |
89ed88ba CW |
11456 | |
11457 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11458 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11459 | |
5e2d7afc | 11460 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11461 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11462 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11463 | |
87b6b101 | 11464 | drm_crtc_vblank_put(crtc); |
7317c75e | 11465 | free_work: |
96b099fd CW |
11466 | kfree(work); |
11467 | ||
f900db47 | 11468 | if (ret == -EIO) { |
02e0efb5 ML |
11469 | struct drm_atomic_state *state; |
11470 | struct drm_plane_state *plane_state; | |
11471 | ||
f900db47 | 11472 | out_hang: |
02e0efb5 ML |
11473 | state = drm_atomic_state_alloc(dev); |
11474 | if (!state) | |
11475 | return -ENOMEM; | |
11476 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11477 | ||
11478 | retry: | |
11479 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11480 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11481 | if (!ret) { | |
11482 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11483 | ||
11484 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11485 | if (!ret) | |
11486 | ret = drm_atomic_commit(state); | |
11487 | } | |
11488 | ||
11489 | if (ret == -EDEADLK) { | |
11490 | drm_modeset_backoff(state->acquire_ctx); | |
11491 | drm_atomic_state_clear(state); | |
11492 | goto retry; | |
11493 | } | |
11494 | ||
11495 | if (ret) | |
11496 | drm_atomic_state_free(state); | |
11497 | ||
f0d3dad3 | 11498 | if (ret == 0 && event) { |
5e2d7afc | 11499 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11500 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11501 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11502 | } |
f900db47 | 11503 | } |
96b099fd | 11504 | return ret; |
6b95a207 KH |
11505 | } |
11506 | ||
da20eabd ML |
11507 | |
11508 | /** | |
11509 | * intel_wm_need_update - Check whether watermarks need updating | |
11510 | * @plane: drm plane | |
11511 | * @state: new plane state | |
11512 | * | |
11513 | * Check current plane state versus the new one to determine whether | |
11514 | * watermarks need to be recalculated. | |
11515 | * | |
11516 | * Returns true or false. | |
11517 | */ | |
11518 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11519 | struct drm_plane_state *state) | |
11520 | { | |
11521 | /* Update watermarks on tiling changes. */ | |
11522 | if (!plane->state->fb || !state->fb || | |
11523 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
11524 | plane->state->rotation != state->rotation) | |
11525 | return true; | |
11526 | ||
11527 | if (plane->state->crtc_w != state->crtc_w) | |
11528 | return true; | |
11529 | ||
11530 | return false; | |
11531 | } | |
11532 | ||
11533 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, | |
11534 | struct drm_plane_state *plane_state) | |
11535 | { | |
11536 | struct drm_crtc *crtc = crtc_state->crtc; | |
11537 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11538 | struct drm_plane *plane = plane_state->plane; | |
11539 | struct drm_device *dev = crtc->dev; | |
11540 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11541 | struct intel_plane_state *old_plane_state = | |
11542 | to_intel_plane_state(plane->state); | |
11543 | int idx = intel_crtc->base.base.id, ret; | |
11544 | int i = drm_plane_index(plane); | |
11545 | bool mode_changed = needs_modeset(crtc_state); | |
11546 | bool was_crtc_enabled = crtc->state->active; | |
11547 | bool is_crtc_enabled = crtc_state->active; | |
11548 | ||
11549 | bool turn_off, turn_on, visible, was_visible; | |
11550 | struct drm_framebuffer *fb = plane_state->fb; | |
11551 | ||
11552 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11553 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11554 | ret = skl_update_scaler_plane( | |
11555 | to_intel_crtc_state(crtc_state), | |
11556 | to_intel_plane_state(plane_state)); | |
11557 | if (ret) | |
11558 | return ret; | |
11559 | } | |
11560 | ||
11561 | /* | |
11562 | * Disabling a plane is always okay; we just need to update | |
11563 | * fb tracking in a special way since cleanup_fb() won't | |
11564 | * get called by the plane helpers. | |
11565 | */ | |
11566 | if (old_plane_state->base.fb && !fb) | |
11567 | intel_crtc->atomic.disabled_planes |= 1 << i; | |
11568 | ||
da20eabd ML |
11569 | was_visible = old_plane_state->visible; |
11570 | visible = to_intel_plane_state(plane_state)->visible; | |
11571 | ||
11572 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11573 | was_visible = false; | |
11574 | ||
11575 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11576 | visible = false; | |
11577 | ||
11578 | if (!was_visible && !visible) | |
11579 | return 0; | |
11580 | ||
11581 | turn_off = was_visible && (!visible || mode_changed); | |
11582 | turn_on = visible && (!was_visible || mode_changed); | |
11583 | ||
11584 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11585 | plane->base.id, fb ? fb->base.id : -1); | |
11586 | ||
11587 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11588 | plane->base.id, was_visible, visible, | |
11589 | turn_off, turn_on, mode_changed); | |
11590 | ||
852eb00d | 11591 | if (turn_on) { |
f015c551 | 11592 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d VS |
11593 | /* must disable cxsr around plane enable/disable */ |
11594 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11595 | intel_crtc->atomic.disable_cxsr = true; | |
11596 | /* to potentially re-enable cxsr */ | |
11597 | intel_crtc->atomic.wait_vblank = true; | |
11598 | intel_crtc->atomic.update_wm_post = true; | |
11599 | } | |
11600 | } else if (turn_off) { | |
f015c551 | 11601 | intel_crtc->atomic.update_wm_post = true; |
852eb00d VS |
11602 | /* must disable cxsr around plane enable/disable */ |
11603 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11604 | if (is_crtc_enabled) | |
11605 | intel_crtc->atomic.wait_vblank = true; | |
11606 | intel_crtc->atomic.disable_cxsr = true; | |
11607 | } | |
11608 | } else if (intel_wm_need_update(plane, plane_state)) { | |
f015c551 | 11609 | intel_crtc->atomic.update_wm_pre = true; |
852eb00d | 11610 | } |
da20eabd | 11611 | |
8be6ca85 | 11612 | if (visible || was_visible) |
a9ff8714 VS |
11613 | intel_crtc->atomic.fb_bits |= |
11614 | to_intel_plane(plane)->frontbuffer_bit; | |
11615 | ||
da20eabd ML |
11616 | switch (plane->type) { |
11617 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd ML |
11618 | intel_crtc->atomic.wait_for_flips = true; |
11619 | intel_crtc->atomic.pre_disable_primary = turn_off; | |
11620 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11621 | ||
066cf55b RV |
11622 | if (turn_off) { |
11623 | /* | |
11624 | * FIXME: Actually if we will still have any other | |
11625 | * plane enabled on the pipe we could let IPS enabled | |
11626 | * still, but for now lets consider that when we make | |
11627 | * primary invisible by setting DSPCNTR to 0 on | |
11628 | * update_primary_plane function IPS needs to be | |
11629 | * disable. | |
11630 | */ | |
11631 | intel_crtc->atomic.disable_ips = true; | |
11632 | ||
da20eabd | 11633 | intel_crtc->atomic.disable_fbc = true; |
066cf55b | 11634 | } |
da20eabd ML |
11635 | |
11636 | /* | |
11637 | * FBC does not work on some platforms for rotated | |
11638 | * planes, so disable it when rotation is not 0 and | |
11639 | * update it when rotation is set back to 0. | |
11640 | * | |
11641 | * FIXME: This is redundant with the fbc update done in | |
11642 | * the primary plane enable function except that that | |
11643 | * one is done too late. We eventually need to unify | |
11644 | * this. | |
11645 | */ | |
11646 | ||
11647 | if (visible && | |
11648 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11649 | dev_priv->fbc.crtc == intel_crtc && | |
11650 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11651 | intel_crtc->atomic.disable_fbc = true; | |
11652 | ||
11653 | /* | |
11654 | * BDW signals flip done immediately if the plane | |
11655 | * is disabled, even if the plane enable is already | |
11656 | * armed to occur at the next vblank :( | |
11657 | */ | |
11658 | if (turn_on && IS_BROADWELL(dev)) | |
11659 | intel_crtc->atomic.wait_vblank = true; | |
11660 | ||
11661 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11662 | break; | |
11663 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11664 | break; |
11665 | case DRM_PLANE_TYPE_OVERLAY: | |
d032ffa0 | 11666 | if (turn_off && !mode_changed) { |
da20eabd ML |
11667 | intel_crtc->atomic.wait_vblank = true; |
11668 | intel_crtc->atomic.update_sprite_watermarks |= | |
11669 | 1 << i; | |
11670 | } | |
da20eabd ML |
11671 | } |
11672 | return 0; | |
11673 | } | |
11674 | ||
6d3a1ce7 ML |
11675 | static bool encoders_cloneable(const struct intel_encoder *a, |
11676 | const struct intel_encoder *b) | |
11677 | { | |
11678 | /* masks could be asymmetric, so check both ways */ | |
11679 | return a == b || (a->cloneable & (1 << b->type) && | |
11680 | b->cloneable & (1 << a->type)); | |
11681 | } | |
11682 | ||
11683 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11684 | struct intel_crtc *crtc, | |
11685 | struct intel_encoder *encoder) | |
11686 | { | |
11687 | struct intel_encoder *source_encoder; | |
11688 | struct drm_connector *connector; | |
11689 | struct drm_connector_state *connector_state; | |
11690 | int i; | |
11691 | ||
11692 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11693 | if (connector_state->crtc != &crtc->base) | |
11694 | continue; | |
11695 | ||
11696 | source_encoder = | |
11697 | to_intel_encoder(connector_state->best_encoder); | |
11698 | if (!encoders_cloneable(encoder, source_encoder)) | |
11699 | return false; | |
11700 | } | |
11701 | ||
11702 | return true; | |
11703 | } | |
11704 | ||
11705 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11706 | struct intel_crtc *crtc) | |
11707 | { | |
11708 | struct intel_encoder *encoder; | |
11709 | struct drm_connector *connector; | |
11710 | struct drm_connector_state *connector_state; | |
11711 | int i; | |
11712 | ||
11713 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11714 | if (connector_state->crtc != &crtc->base) | |
11715 | continue; | |
11716 | ||
11717 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11718 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11719 | return false; | |
11720 | } | |
11721 | ||
11722 | return true; | |
11723 | } | |
11724 | ||
11725 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11726 | struct drm_crtc_state *crtc_state) | |
11727 | { | |
cf5a15be | 11728 | struct drm_device *dev = crtc->dev; |
ad421372 | 11729 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11730 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11731 | struct intel_crtc_state *pipe_config = |
11732 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11733 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 11734 | int ret; |
6d3a1ce7 ML |
11735 | bool mode_changed = needs_modeset(crtc_state); |
11736 | ||
11737 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11738 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11739 | return -EINVAL; | |
11740 | } | |
11741 | ||
852eb00d VS |
11742 | if (mode_changed && !crtc_state->active) |
11743 | intel_crtc->atomic.update_wm_post = true; | |
eddfcbcd | 11744 | |
ad421372 ML |
11745 | if (mode_changed && crtc_state->enable && |
11746 | dev_priv->display.crtc_compute_clock && | |
11747 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11748 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11749 | pipe_config); | |
11750 | if (ret) | |
11751 | return ret; | |
11752 | } | |
11753 | ||
e435d6e5 ML |
11754 | ret = 0; |
11755 | if (INTEL_INFO(dev)->gen >= 9) { | |
11756 | if (mode_changed) | |
11757 | ret = skl_update_scaler_crtc(pipe_config); | |
11758 | ||
11759 | if (!ret) | |
11760 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
11761 | pipe_config); | |
11762 | } | |
11763 | ||
11764 | return ret; | |
6d3a1ce7 ML |
11765 | } |
11766 | ||
65b38e0d | 11767 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11768 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11769 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11770 | .atomic_begin = intel_begin_crtc_commit, |
11771 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11772 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11773 | }; |
11774 | ||
d29b2f9d ACO |
11775 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
11776 | { | |
11777 | struct intel_connector *connector; | |
11778 | ||
11779 | for_each_intel_connector(dev, connector) { | |
11780 | if (connector->base.encoder) { | |
11781 | connector->base.state->best_encoder = | |
11782 | connector->base.encoder; | |
11783 | connector->base.state->crtc = | |
11784 | connector->base.encoder->crtc; | |
11785 | } else { | |
11786 | connector->base.state->best_encoder = NULL; | |
11787 | connector->base.state->crtc = NULL; | |
11788 | } | |
11789 | } | |
11790 | } | |
11791 | ||
050f7aeb | 11792 | static void |
eba905b2 | 11793 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11794 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11795 | { |
11796 | int bpp = pipe_config->pipe_bpp; | |
11797 | ||
11798 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11799 | connector->base.base.id, | |
c23cc417 | 11800 | connector->base.name); |
050f7aeb DV |
11801 | |
11802 | /* Don't use an invalid EDID bpc value */ | |
11803 | if (connector->base.display_info.bpc && | |
11804 | connector->base.display_info.bpc * 3 < bpp) { | |
11805 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11806 | bpp, connector->base.display_info.bpc*3); | |
11807 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11808 | } | |
11809 | ||
11810 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11811 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11812 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11813 | bpp); | |
11814 | pipe_config->pipe_bpp = 24; | |
11815 | } | |
11816 | } | |
11817 | ||
4e53c2e0 | 11818 | static int |
050f7aeb | 11819 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 11820 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 11821 | { |
050f7aeb | 11822 | struct drm_device *dev = crtc->base.dev; |
1486017f | 11823 | struct drm_atomic_state *state; |
da3ced29 ACO |
11824 | struct drm_connector *connector; |
11825 | struct drm_connector_state *connector_state; | |
1486017f | 11826 | int bpp, i; |
4e53c2e0 | 11827 | |
d328c9d7 | 11828 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 11829 | bpp = 10*3; |
d328c9d7 DV |
11830 | else if (INTEL_INFO(dev)->gen >= 5) |
11831 | bpp = 12*3; | |
11832 | else | |
11833 | bpp = 8*3; | |
11834 | ||
4e53c2e0 | 11835 | |
4e53c2e0 DV |
11836 | pipe_config->pipe_bpp = bpp; |
11837 | ||
1486017f ACO |
11838 | state = pipe_config->base.state; |
11839 | ||
4e53c2e0 | 11840 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
11841 | for_each_connector_in_state(state, connector, connector_state, i) { |
11842 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
11843 | continue; |
11844 | ||
da3ced29 ACO |
11845 | connected_sink_compute_bpp(to_intel_connector(connector), |
11846 | pipe_config); | |
4e53c2e0 DV |
11847 | } |
11848 | ||
11849 | return bpp; | |
11850 | } | |
11851 | ||
644db711 DV |
11852 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
11853 | { | |
11854 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
11855 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 11856 | mode->crtc_clock, |
644db711 DV |
11857 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
11858 | mode->crtc_hsync_end, mode->crtc_htotal, | |
11859 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
11860 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
11861 | } | |
11862 | ||
c0b03411 | 11863 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 11864 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
11865 | const char *context) |
11866 | { | |
6a60cd87 CK |
11867 | struct drm_device *dev = crtc->base.dev; |
11868 | struct drm_plane *plane; | |
11869 | struct intel_plane *intel_plane; | |
11870 | struct intel_plane_state *state; | |
11871 | struct drm_framebuffer *fb; | |
11872 | ||
11873 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
11874 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
11875 | |
11876 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
11877 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
11878 | pipe_config->pipe_bpp, pipe_config->dither); | |
11879 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
11880 | pipe_config->has_pch_encoder, | |
11881 | pipe_config->fdi_lanes, | |
11882 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
11883 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
11884 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 11885 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 11886 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11887 | pipe_config->lane_count, |
eb14cb74 VS |
11888 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
11889 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
11890 | pipe_config->dp_m_n.tu); | |
b95af8be | 11891 | |
90a6b7b0 | 11892 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 11893 | pipe_config->has_dp_encoder, |
90a6b7b0 | 11894 | pipe_config->lane_count, |
b95af8be VK |
11895 | pipe_config->dp_m2_n2.gmch_m, |
11896 | pipe_config->dp_m2_n2.gmch_n, | |
11897 | pipe_config->dp_m2_n2.link_m, | |
11898 | pipe_config->dp_m2_n2.link_n, | |
11899 | pipe_config->dp_m2_n2.tu); | |
11900 | ||
55072d19 DV |
11901 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
11902 | pipe_config->has_audio, | |
11903 | pipe_config->has_infoframe); | |
11904 | ||
c0b03411 | 11905 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 11906 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 11907 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
11908 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
11909 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 11910 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
11911 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
11912 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
11913 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
11914 | crtc->num_scalers, | |
11915 | pipe_config->scaler_state.scaler_users, | |
11916 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
11917 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
11918 | pipe_config->gmch_pfit.control, | |
11919 | pipe_config->gmch_pfit.pgm_ratios, | |
11920 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 11921 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 11922 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
11923 | pipe_config->pch_pfit.size, |
11924 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 11925 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 11926 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 11927 | |
415ff0f6 | 11928 | if (IS_BROXTON(dev)) { |
05712c15 | 11929 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 11930 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 11931 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
11932 | pipe_config->ddi_pll_sel, |
11933 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 11934 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
11935 | pipe_config->dpll_hw_state.pll0, |
11936 | pipe_config->dpll_hw_state.pll1, | |
11937 | pipe_config->dpll_hw_state.pll2, | |
11938 | pipe_config->dpll_hw_state.pll3, | |
11939 | pipe_config->dpll_hw_state.pll6, | |
11940 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 11941 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 11942 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 TU |
11943 | pipe_config->dpll_hw_state.pcsdw12); |
11944 | } else if (IS_SKYLAKE(dev)) { | |
11945 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " | |
11946 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
11947 | pipe_config->ddi_pll_sel, | |
11948 | pipe_config->dpll_hw_state.ctrl1, | |
11949 | pipe_config->dpll_hw_state.cfgcr1, | |
11950 | pipe_config->dpll_hw_state.cfgcr2); | |
11951 | } else if (HAS_DDI(dev)) { | |
11952 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
11953 | pipe_config->ddi_pll_sel, | |
11954 | pipe_config->dpll_hw_state.wrpll); | |
11955 | } else { | |
11956 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
11957 | "fp0: 0x%x, fp1: 0x%x\n", | |
11958 | pipe_config->dpll_hw_state.dpll, | |
11959 | pipe_config->dpll_hw_state.dpll_md, | |
11960 | pipe_config->dpll_hw_state.fp0, | |
11961 | pipe_config->dpll_hw_state.fp1); | |
11962 | } | |
11963 | ||
6a60cd87 CK |
11964 | DRM_DEBUG_KMS("planes on this crtc\n"); |
11965 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
11966 | intel_plane = to_intel_plane(plane); | |
11967 | if (intel_plane->pipe != crtc->pipe) | |
11968 | continue; | |
11969 | ||
11970 | state = to_intel_plane_state(plane->state); | |
11971 | fb = state->base.fb; | |
11972 | if (!fb) { | |
11973 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
11974 | "disabled, scaler_id = %d\n", | |
11975 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
11976 | plane->base.id, intel_plane->pipe, | |
11977 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
11978 | drm_plane_index(plane), state->scaler_id); | |
11979 | continue; | |
11980 | } | |
11981 | ||
11982 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
11983 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
11984 | plane->base.id, intel_plane->pipe, | |
11985 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
11986 | drm_plane_index(plane)); | |
11987 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
11988 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
11989 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
11990 | state->scaler_id, | |
11991 | state->src.x1 >> 16, state->src.y1 >> 16, | |
11992 | drm_rect_width(&state->src) >> 16, | |
11993 | drm_rect_height(&state->src) >> 16, | |
11994 | state->dst.x1, state->dst.y1, | |
11995 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
11996 | } | |
c0b03411 DV |
11997 | } |
11998 | ||
5448a00d | 11999 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12000 | { |
5448a00d ACO |
12001 | struct drm_device *dev = state->dev; |
12002 | struct intel_encoder *encoder; | |
da3ced29 | 12003 | struct drm_connector *connector; |
5448a00d | 12004 | struct drm_connector_state *connector_state; |
00f0b378 | 12005 | unsigned int used_ports = 0; |
5448a00d | 12006 | int i; |
00f0b378 VS |
12007 | |
12008 | /* | |
12009 | * Walk the connector list instead of the encoder | |
12010 | * list to detect the problem on ddi platforms | |
12011 | * where there's just one encoder per digital port. | |
12012 | */ | |
da3ced29 | 12013 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12014 | if (!connector_state->best_encoder) |
00f0b378 VS |
12015 | continue; |
12016 | ||
5448a00d ACO |
12017 | encoder = to_intel_encoder(connector_state->best_encoder); |
12018 | ||
12019 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12020 | |
12021 | switch (encoder->type) { | |
12022 | unsigned int port_mask; | |
12023 | case INTEL_OUTPUT_UNKNOWN: | |
12024 | if (WARN_ON(!HAS_DDI(dev))) | |
12025 | break; | |
12026 | case INTEL_OUTPUT_DISPLAYPORT: | |
12027 | case INTEL_OUTPUT_HDMI: | |
12028 | case INTEL_OUTPUT_EDP: | |
12029 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12030 | ||
12031 | /* the same port mustn't appear more than once */ | |
12032 | if (used_ports & port_mask) | |
12033 | return false; | |
12034 | ||
12035 | used_ports |= port_mask; | |
12036 | default: | |
12037 | break; | |
12038 | } | |
12039 | } | |
12040 | ||
12041 | return true; | |
12042 | } | |
12043 | ||
83a57153 ACO |
12044 | static void |
12045 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12046 | { | |
12047 | struct drm_crtc_state tmp_state; | |
663a3640 | 12048 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12049 | struct intel_dpll_hw_state dpll_hw_state; |
12050 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12051 | uint32_t ddi_pll_sel; |
c4e2d043 | 12052 | bool force_thru; |
83a57153 | 12053 | |
7546a384 ACO |
12054 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12055 | * kzalloc'd. Code that depends on any field being zero should be | |
12056 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12057 | * only fields that are know to not cause problems are preserved. */ | |
12058 | ||
83a57153 | 12059 | tmp_state = crtc_state->base; |
663a3640 | 12060 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12061 | shared_dpll = crtc_state->shared_dpll; |
12062 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12063 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12064 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12065 | |
83a57153 | 12066 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12067 | |
83a57153 | 12068 | crtc_state->base = tmp_state; |
663a3640 | 12069 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12070 | crtc_state->shared_dpll = shared_dpll; |
12071 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12072 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12073 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12074 | } |
12075 | ||
548ee15b | 12076 | static int |
b8cecdf5 | 12077 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12078 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12079 | { |
b359283a | 12080 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12081 | struct intel_encoder *encoder; |
da3ced29 | 12082 | struct drm_connector *connector; |
0b901879 | 12083 | struct drm_connector_state *connector_state; |
d328c9d7 | 12084 | int base_bpp, ret = -EINVAL; |
0b901879 | 12085 | int i; |
e29c22c0 | 12086 | bool retry = true; |
ee7b9f93 | 12087 | |
83a57153 | 12088 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12089 | |
e143a21c DV |
12090 | pipe_config->cpu_transcoder = |
12091 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12092 | |
2960bc9c ID |
12093 | /* |
12094 | * Sanitize sync polarity flags based on requested ones. If neither | |
12095 | * positive or negative polarity is requested, treat this as meaning | |
12096 | * negative polarity. | |
12097 | */ | |
2d112de7 | 12098 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12099 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12100 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12101 | |
2d112de7 | 12102 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12103 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12104 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12105 | |
d328c9d7 DV |
12106 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12107 | pipe_config); | |
12108 | if (base_bpp < 0) | |
4e53c2e0 DV |
12109 | goto fail; |
12110 | ||
e41a56be VS |
12111 | /* |
12112 | * Determine the real pipe dimensions. Note that stereo modes can | |
12113 | * increase the actual pipe size due to the frame doubling and | |
12114 | * insertion of additional space for blanks between the frame. This | |
12115 | * is stored in the crtc timings. We use the requested mode to do this | |
12116 | * computation to clearly distinguish it from the adjusted mode, which | |
12117 | * can be changed by the connectors in the below retry loop. | |
12118 | */ | |
2d112de7 | 12119 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12120 | &pipe_config->pipe_src_w, |
12121 | &pipe_config->pipe_src_h); | |
e41a56be | 12122 | |
e29c22c0 | 12123 | encoder_retry: |
ef1b460d | 12124 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12125 | pipe_config->port_clock = 0; |
ef1b460d | 12126 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12127 | |
135c81b8 | 12128 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12129 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12130 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12131 | |
7758a113 DV |
12132 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12133 | * adjust it according to limitations or connector properties, and also | |
12134 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12135 | */ |
da3ced29 | 12136 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12137 | if (connector_state->crtc != crtc) |
7758a113 | 12138 | continue; |
7ae89233 | 12139 | |
0b901879 ACO |
12140 | encoder = to_intel_encoder(connector_state->best_encoder); |
12141 | ||
efea6e8e DV |
12142 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12143 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12144 | goto fail; |
12145 | } | |
ee7b9f93 | 12146 | } |
47f1c6c9 | 12147 | |
ff9a6750 DV |
12148 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12149 | * done afterwards in case the encoder adjusts the mode. */ | |
12150 | if (!pipe_config->port_clock) | |
2d112de7 | 12151 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12152 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12153 | |
a43f6e0f | 12154 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12155 | if (ret < 0) { |
7758a113 DV |
12156 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12157 | goto fail; | |
ee7b9f93 | 12158 | } |
e29c22c0 DV |
12159 | |
12160 | if (ret == RETRY) { | |
12161 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12162 | ret = -EINVAL; | |
12163 | goto fail; | |
12164 | } | |
12165 | ||
12166 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12167 | retry = false; | |
12168 | goto encoder_retry; | |
12169 | } | |
12170 | ||
e8fa4270 DV |
12171 | /* Dithering seems to not pass-through bits correctly when it should, so |
12172 | * only enable it on 6bpc panels. */ | |
12173 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12174 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12175 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12176 | |
7758a113 | 12177 | fail: |
548ee15b | 12178 | return ret; |
ee7b9f93 | 12179 | } |
47f1c6c9 | 12180 | |
ea9d758d | 12181 | static void |
4740b0f2 | 12182 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12183 | { |
0a9ab303 ACO |
12184 | struct drm_crtc *crtc; |
12185 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12186 | int i; |
ea9d758d | 12187 | |
7668851f | 12188 | /* Double check state. */ |
8a75d157 | 12189 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12190 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12191 | |
12192 | /* Update hwmode for vblank functions */ | |
12193 | if (crtc->state->active) | |
12194 | crtc->hwmode = crtc->state->adjusted_mode; | |
12195 | else | |
12196 | crtc->hwmode.crtc_clock = 0; | |
ea9d758d | 12197 | } |
ea9d758d DV |
12198 | } |
12199 | ||
3bd26263 | 12200 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12201 | { |
3bd26263 | 12202 | int diff; |
f1f644dc JB |
12203 | |
12204 | if (clock1 == clock2) | |
12205 | return true; | |
12206 | ||
12207 | if (!clock1 || !clock2) | |
12208 | return false; | |
12209 | ||
12210 | diff = abs(clock1 - clock2); | |
12211 | ||
12212 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12213 | return true; | |
12214 | ||
12215 | return false; | |
12216 | } | |
12217 | ||
25c5b266 DV |
12218 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12219 | list_for_each_entry((intel_crtc), \ | |
12220 | &(dev)->mode_config.crtc_list, \ | |
12221 | base.head) \ | |
0973f18f | 12222 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12223 | |
cfb23ed6 ML |
12224 | |
12225 | static bool | |
12226 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12227 | unsigned int m2, unsigned int n2, | |
12228 | bool exact) | |
12229 | { | |
12230 | if (m == m2 && n == n2) | |
12231 | return true; | |
12232 | ||
12233 | if (exact || !m || !n || !m2 || !n2) | |
12234 | return false; | |
12235 | ||
12236 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12237 | ||
12238 | if (m > m2) { | |
12239 | while (m > m2) { | |
12240 | m2 <<= 1; | |
12241 | n2 <<= 1; | |
12242 | } | |
12243 | } else if (m < m2) { | |
12244 | while (m < m2) { | |
12245 | m <<= 1; | |
12246 | n <<= 1; | |
12247 | } | |
12248 | } | |
12249 | ||
12250 | return m == m2 && n == n2; | |
12251 | } | |
12252 | ||
12253 | static bool | |
12254 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12255 | struct intel_link_m_n *m2_n2, | |
12256 | bool adjust) | |
12257 | { | |
12258 | if (m_n->tu == m2_n2->tu && | |
12259 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12260 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12261 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12262 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12263 | if (adjust) | |
12264 | *m2_n2 = *m_n; | |
12265 | ||
12266 | return true; | |
12267 | } | |
12268 | ||
12269 | return false; | |
12270 | } | |
12271 | ||
0e8ffe1b | 12272 | static bool |
2fa2fe9a | 12273 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12274 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12275 | struct intel_crtc_state *pipe_config, |
12276 | bool adjust) | |
0e8ffe1b | 12277 | { |
cfb23ed6 ML |
12278 | bool ret = true; |
12279 | ||
12280 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12281 | do { \ | |
12282 | if (!adjust) \ | |
12283 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12284 | else \ | |
12285 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12286 | } while (0) | |
12287 | ||
66e985c0 DV |
12288 | #define PIPE_CONF_CHECK_X(name) \ |
12289 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12290 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12291 | "(expected 0x%08x, found 0x%08x)\n", \ |
12292 | current_config->name, \ | |
12293 | pipe_config->name); \ | |
cfb23ed6 | 12294 | ret = false; \ |
66e985c0 DV |
12295 | } |
12296 | ||
08a24034 DV |
12297 | #define PIPE_CONF_CHECK_I(name) \ |
12298 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12299 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12300 | "(expected %i, found %i)\n", \ |
12301 | current_config->name, \ | |
12302 | pipe_config->name); \ | |
cfb23ed6 ML |
12303 | ret = false; \ |
12304 | } | |
12305 | ||
12306 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12307 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12308 | &pipe_config->name,\ | |
12309 | adjust)) { \ | |
12310 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12311 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12312 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12313 | current_config->name.tu, \ | |
12314 | current_config->name.gmch_m, \ | |
12315 | current_config->name.gmch_n, \ | |
12316 | current_config->name.link_m, \ | |
12317 | current_config->name.link_n, \ | |
12318 | pipe_config->name.tu, \ | |
12319 | pipe_config->name.gmch_m, \ | |
12320 | pipe_config->name.gmch_n, \ | |
12321 | pipe_config->name.link_m, \ | |
12322 | pipe_config->name.link_n); \ | |
12323 | ret = false; \ | |
12324 | } | |
12325 | ||
12326 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12327 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12328 | &pipe_config->name, adjust) && \ | |
12329 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12330 | &pipe_config->name, adjust)) { \ | |
12331 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12332 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12333 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12334 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12335 | current_config->name.tu, \ | |
12336 | current_config->name.gmch_m, \ | |
12337 | current_config->name.gmch_n, \ | |
12338 | current_config->name.link_m, \ | |
12339 | current_config->name.link_n, \ | |
12340 | current_config->alt_name.tu, \ | |
12341 | current_config->alt_name.gmch_m, \ | |
12342 | current_config->alt_name.gmch_n, \ | |
12343 | current_config->alt_name.link_m, \ | |
12344 | current_config->alt_name.link_n, \ | |
12345 | pipe_config->name.tu, \ | |
12346 | pipe_config->name.gmch_m, \ | |
12347 | pipe_config->name.gmch_n, \ | |
12348 | pipe_config->name.link_m, \ | |
12349 | pipe_config->name.link_n); \ | |
12350 | ret = false; \ | |
88adfff1 DV |
12351 | } |
12352 | ||
b95af8be VK |
12353 | /* This is required for BDW+ where there is only one set of registers for |
12354 | * switching between high and low RR. | |
12355 | * This macro can be used whenever a comparison has to be made between one | |
12356 | * hw state and multiple sw state variables. | |
12357 | */ | |
12358 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12359 | if ((current_config->name != pipe_config->name) && \ | |
12360 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12361 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12362 | "(expected %i or %i, found %i)\n", \ |
12363 | current_config->name, \ | |
12364 | current_config->alt_name, \ | |
12365 | pipe_config->name); \ | |
cfb23ed6 | 12366 | ret = false; \ |
b95af8be VK |
12367 | } |
12368 | ||
1bd1bd80 DV |
12369 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12370 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12371 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12372 | "(expected %i, found %i)\n", \ |
12373 | current_config->name & (mask), \ | |
12374 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12375 | ret = false; \ |
1bd1bd80 DV |
12376 | } |
12377 | ||
5e550656 VS |
12378 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12379 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12380 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12381 | "(expected %i, found %i)\n", \ |
12382 | current_config->name, \ | |
12383 | pipe_config->name); \ | |
cfb23ed6 | 12384 | ret = false; \ |
5e550656 VS |
12385 | } |
12386 | ||
bb760063 DV |
12387 | #define PIPE_CONF_QUIRK(quirk) \ |
12388 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12389 | ||
eccb140b DV |
12390 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12391 | ||
08a24034 DV |
12392 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12393 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12394 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12395 | |
eb14cb74 | 12396 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12397 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12398 | |
12399 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12400 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12401 | ||
12402 | PIPE_CONF_CHECK_I(has_drrs); | |
12403 | if (current_config->has_drrs) | |
12404 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12405 | } else | |
12406 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12407 | |
2d112de7 ACO |
12408 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12409 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12410 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12411 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12412 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12413 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12414 | |
2d112de7 ACO |
12415 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12416 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12417 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12418 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12419 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12420 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12421 | |
c93f54cf | 12422 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12423 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12424 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12425 | IS_VALLEYVIEW(dev)) | |
12426 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12427 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12428 | |
9ed109a7 DV |
12429 | PIPE_CONF_CHECK_I(has_audio); |
12430 | ||
2d112de7 | 12431 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12432 | DRM_MODE_FLAG_INTERLACE); |
12433 | ||
bb760063 | 12434 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12435 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12436 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12437 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12438 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12439 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12440 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12441 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12442 | DRM_MODE_FLAG_NVSYNC); |
12443 | } | |
045ac3b5 | 12444 | |
37327abd VS |
12445 | PIPE_CONF_CHECK_I(pipe_src_w); |
12446 | PIPE_CONF_CHECK_I(pipe_src_h); | |
1bd1bd80 | 12447 | |
e2ff2d4a DV |
12448 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
12449 | /* pfit ratios are autocomputed by the hw on gen4+ */ | |
12450 | if (INTEL_INFO(dev)->gen < 4) | |
12451 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
12452 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); | |
9953599b | 12453 | |
fd4daa9c CW |
12454 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
12455 | if (current_config->pch_pfit.enabled) { | |
12456 | PIPE_CONF_CHECK_I(pch_pfit.pos); | |
12457 | PIPE_CONF_CHECK_I(pch_pfit.size); | |
12458 | } | |
2fa2fe9a | 12459 | |
a1b2278e CK |
12460 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12461 | ||
e59150dc JB |
12462 | /* BDW+ don't expose a synchronous way to read the state */ |
12463 | if (IS_HASWELL(dev)) | |
12464 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12465 | |
282740f7 VS |
12466 | PIPE_CONF_CHECK_I(double_wide); |
12467 | ||
26804afd DV |
12468 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12469 | ||
c0d43d62 | 12470 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12471 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12472 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12473 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12474 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12475 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
12476 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12477 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12478 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12479 | |
42571aef VS |
12480 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12481 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12482 | ||
2d112de7 | 12483 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12484 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12485 | |
66e985c0 | 12486 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12487 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12488 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12489 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12490 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12491 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12492 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12493 | |
cfb23ed6 | 12494 | return ret; |
0e8ffe1b DV |
12495 | } |
12496 | ||
08db6652 DL |
12497 | static void check_wm_state(struct drm_device *dev) |
12498 | { | |
12499 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12500 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12501 | struct intel_crtc *intel_crtc; | |
12502 | int plane; | |
12503 | ||
12504 | if (INTEL_INFO(dev)->gen < 9) | |
12505 | return; | |
12506 | ||
12507 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12508 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12509 | ||
12510 | for_each_intel_crtc(dev, intel_crtc) { | |
12511 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12512 | const enum pipe pipe = intel_crtc->pipe; | |
12513 | ||
12514 | if (!intel_crtc->active) | |
12515 | continue; | |
12516 | ||
12517 | /* planes */ | |
dd740780 | 12518 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12519 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12520 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12521 | ||
12522 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12523 | continue; | |
12524 | ||
12525 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12526 | "(expected (%u,%u), found (%u,%u))\n", | |
12527 | pipe_name(pipe), plane + 1, | |
12528 | sw_entry->start, sw_entry->end, | |
12529 | hw_entry->start, hw_entry->end); | |
12530 | } | |
12531 | ||
12532 | /* cursor */ | |
12533 | hw_entry = &hw_ddb.cursor[pipe]; | |
12534 | sw_entry = &sw_ddb->cursor[pipe]; | |
12535 | ||
12536 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12537 | continue; | |
12538 | ||
12539 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12540 | "(expected (%u,%u), found (%u,%u))\n", | |
12541 | pipe_name(pipe), | |
12542 | sw_entry->start, sw_entry->end, | |
12543 | hw_entry->start, hw_entry->end); | |
12544 | } | |
12545 | } | |
12546 | ||
91d1b4bd | 12547 | static void |
35dd3c64 ML |
12548 | check_connector_state(struct drm_device *dev, |
12549 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12550 | { |
35dd3c64 ML |
12551 | struct drm_connector_state *old_conn_state; |
12552 | struct drm_connector *connector; | |
12553 | int i; | |
8af6cf88 | 12554 | |
35dd3c64 ML |
12555 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12556 | struct drm_encoder *encoder = connector->encoder; | |
12557 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12558 | |
8af6cf88 DV |
12559 | /* This also checks the encoder/connector hw state with the |
12560 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12561 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12562 | |
ad3c558f | 12563 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12564 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12565 | } |
91d1b4bd DV |
12566 | } |
12567 | ||
12568 | static void | |
12569 | check_encoder_state(struct drm_device *dev) | |
12570 | { | |
12571 | struct intel_encoder *encoder; | |
12572 | struct intel_connector *connector; | |
8af6cf88 | 12573 | |
b2784e15 | 12574 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12575 | bool enabled = false; |
4d20cd86 | 12576 | enum pipe pipe; |
8af6cf88 DV |
12577 | |
12578 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12579 | encoder->base.base.id, | |
8e329a03 | 12580 | encoder->base.name); |
8af6cf88 | 12581 | |
3a3371ff | 12582 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12583 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12584 | continue; |
12585 | enabled = true; | |
ad3c558f ML |
12586 | |
12587 | I915_STATE_WARN(connector->base.state->crtc != | |
12588 | encoder->base.crtc, | |
12589 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12590 | } |
0e32b39c | 12591 | |
e2c719b7 | 12592 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12593 | "encoder's enabled state mismatch " |
12594 | "(expected %i, found %i)\n", | |
12595 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12596 | |
12597 | if (!encoder->base.crtc) { | |
4d20cd86 | 12598 | bool active; |
7c60d198 | 12599 | |
4d20cd86 ML |
12600 | active = encoder->get_hw_state(encoder, &pipe); |
12601 | I915_STATE_WARN(active, | |
12602 | "encoder detached but still enabled on pipe %c.\n", | |
12603 | pipe_name(pipe)); | |
7c60d198 | 12604 | } |
8af6cf88 | 12605 | } |
91d1b4bd DV |
12606 | } |
12607 | ||
12608 | static void | |
4d20cd86 | 12609 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12610 | { |
fbee40df | 12611 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12612 | struct intel_encoder *encoder; |
4d20cd86 ML |
12613 | struct drm_crtc_state *old_crtc_state; |
12614 | struct drm_crtc *crtc; | |
12615 | int i; | |
8af6cf88 | 12616 | |
4d20cd86 ML |
12617 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12618 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12619 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12620 | bool active; |
8af6cf88 | 12621 | |
4d20cd86 ML |
12622 | if (!needs_modeset(crtc->state)) |
12623 | continue; | |
045ac3b5 | 12624 | |
4d20cd86 ML |
12625 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
12626 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
12627 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
12628 | pipe_config->base.crtc = crtc; | |
12629 | pipe_config->base.state = old_state; | |
8af6cf88 | 12630 | |
4d20cd86 ML |
12631 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12632 | crtc->base.id); | |
8af6cf88 | 12633 | |
4d20cd86 ML |
12634 | active = dev_priv->display.get_pipe_config(intel_crtc, |
12635 | pipe_config); | |
d62cf62a | 12636 | |
b6b5d049 | 12637 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
12638 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
12639 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
12640 | active = crtc->state->active; | |
6c49f241 | 12641 | |
4d20cd86 | 12642 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 12643 | "crtc active state doesn't match with hw state " |
4d20cd86 | 12644 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 12645 | |
4d20cd86 | 12646 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 12647 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
12648 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
12649 | ||
12650 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
12651 | enum pipe pipe; | |
12652 | ||
12653 | active = encoder->get_hw_state(encoder, &pipe); | |
12654 | I915_STATE_WARN(active != crtc->state->active, | |
12655 | "[ENCODER:%i] active %i with crtc active %i\n", | |
12656 | encoder->base.base.id, active, crtc->state->active); | |
12657 | ||
12658 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
12659 | "Encoder connected to wrong pipe %c\n", | |
12660 | pipe_name(pipe)); | |
12661 | ||
12662 | if (active) | |
12663 | encoder->get_config(encoder, pipe_config); | |
12664 | } | |
53d9f4e9 | 12665 | |
4d20cd86 | 12666 | if (!crtc->state->active) |
cfb23ed6 ML |
12667 | continue; |
12668 | ||
4d20cd86 ML |
12669 | sw_config = to_intel_crtc_state(crtc->state); |
12670 | if (!intel_pipe_config_compare(dev, sw_config, | |
12671 | pipe_config, false)) { | |
e2c719b7 | 12672 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 12673 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 12674 | "[hw state]"); |
4d20cd86 | 12675 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
12676 | "[sw state]"); |
12677 | } | |
8af6cf88 DV |
12678 | } |
12679 | } | |
12680 | ||
91d1b4bd DV |
12681 | static void |
12682 | check_shared_dpll_state(struct drm_device *dev) | |
12683 | { | |
fbee40df | 12684 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12685 | struct intel_crtc *crtc; |
12686 | struct intel_dpll_hw_state dpll_hw_state; | |
12687 | int i; | |
5358901f DV |
12688 | |
12689 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12690 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12691 | int enabled_crtcs = 0, active_crtcs = 0; | |
12692 | bool active; | |
12693 | ||
12694 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12695 | ||
12696 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12697 | ||
12698 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12699 | ||
e2c719b7 | 12700 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12701 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12702 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12703 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12704 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12705 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12706 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12707 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12708 | "pll on state mismatch (expected %i, found %i)\n", |
12709 | pll->on, active); | |
12710 | ||
d3fcc808 | 12711 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12712 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12713 | enabled_crtcs++; |
12714 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12715 | active_crtcs++; | |
12716 | } | |
e2c719b7 | 12717 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12718 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12719 | pll->active, active_crtcs); | |
e2c719b7 | 12720 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12721 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12722 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12723 | |
e2c719b7 | 12724 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12725 | sizeof(dpll_hw_state)), |
12726 | "pll hw state mismatch\n"); | |
5358901f | 12727 | } |
8af6cf88 DV |
12728 | } |
12729 | ||
ee165b1a ML |
12730 | static void |
12731 | intel_modeset_check_state(struct drm_device *dev, | |
12732 | struct drm_atomic_state *old_state) | |
91d1b4bd | 12733 | { |
08db6652 | 12734 | check_wm_state(dev); |
35dd3c64 | 12735 | check_connector_state(dev, old_state); |
91d1b4bd | 12736 | check_encoder_state(dev); |
4d20cd86 | 12737 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
12738 | check_shared_dpll_state(dev); |
12739 | } | |
12740 | ||
5cec258b | 12741 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12742 | int dotclock) |
12743 | { | |
12744 | /* | |
12745 | * FDI already provided one idea for the dotclock. | |
12746 | * Yell if the encoder disagrees. | |
12747 | */ | |
2d112de7 | 12748 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12749 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12750 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12751 | } |
12752 | ||
80715b2f VS |
12753 | static void update_scanline_offset(struct intel_crtc *crtc) |
12754 | { | |
12755 | struct drm_device *dev = crtc->base.dev; | |
12756 | ||
12757 | /* | |
12758 | * The scanline counter increments at the leading edge of hsync. | |
12759 | * | |
12760 | * On most platforms it starts counting from vtotal-1 on the | |
12761 | * first active line. That means the scanline counter value is | |
12762 | * always one less than what we would expect. Ie. just after | |
12763 | * start of vblank, which also occurs at start of hsync (on the | |
12764 | * last active line), the scanline counter will read vblank_start-1. | |
12765 | * | |
12766 | * On gen2 the scanline counter starts counting from 1 instead | |
12767 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12768 | * to keep the value positive), instead of adding one. | |
12769 | * | |
12770 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12771 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12772 | * there's an extra 1 line difference. So we need to add two instead of | |
12773 | * one to the value. | |
12774 | */ | |
12775 | if (IS_GEN2(dev)) { | |
6e3c9717 | 12776 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12777 | int vtotal; |
12778 | ||
12779 | vtotal = mode->crtc_vtotal; | |
12780 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
12781 | vtotal /= 2; | |
12782 | ||
12783 | crtc->scanline_offset = vtotal - 1; | |
12784 | } else if (HAS_DDI(dev) && | |
409ee761 | 12785 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12786 | crtc->scanline_offset = 2; |
12787 | } else | |
12788 | crtc->scanline_offset = 1; | |
12789 | } | |
12790 | ||
ad421372 | 12791 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 12792 | { |
225da59b | 12793 | struct drm_device *dev = state->dev; |
ed6739ef | 12794 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 12795 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 12796 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12797 | struct intel_crtc_state *intel_crtc_state; |
12798 | struct drm_crtc *crtc; | |
12799 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 12800 | int i; |
ed6739ef ACO |
12801 | |
12802 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 12803 | return; |
ed6739ef | 12804 | |
0a9ab303 | 12805 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
12806 | int dpll; |
12807 | ||
0a9ab303 | 12808 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 12809 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 12810 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 12811 | |
ad421372 | 12812 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
12813 | continue; |
12814 | ||
ad421372 | 12815 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 12816 | |
ad421372 ML |
12817 | if (!shared_dpll) |
12818 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 12819 | |
ad421372 ML |
12820 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
12821 | } | |
ed6739ef ACO |
12822 | } |
12823 | ||
99d736a2 ML |
12824 | /* |
12825 | * This implements the workaround described in the "notes" section of the mode | |
12826 | * set sequence documentation. When going from no pipes or single pipe to | |
12827 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
12828 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
12829 | */ | |
12830 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
12831 | { | |
12832 | struct drm_crtc_state *crtc_state; | |
12833 | struct intel_crtc *intel_crtc; | |
12834 | struct drm_crtc *crtc; | |
12835 | struct intel_crtc_state *first_crtc_state = NULL; | |
12836 | struct intel_crtc_state *other_crtc_state = NULL; | |
12837 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
12838 | int i; | |
12839 | ||
12840 | /* look at all crtc's that are going to be enabled in during modeset */ | |
12841 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
12842 | intel_crtc = to_intel_crtc(crtc); | |
12843 | ||
12844 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
12845 | continue; | |
12846 | ||
12847 | if (first_crtc_state) { | |
12848 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
12849 | break; | |
12850 | } else { | |
12851 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
12852 | first_pipe = intel_crtc->pipe; | |
12853 | } | |
12854 | } | |
12855 | ||
12856 | /* No workaround needed? */ | |
12857 | if (!first_crtc_state) | |
12858 | return 0; | |
12859 | ||
12860 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
12861 | for_each_intel_crtc(state->dev, intel_crtc) { | |
12862 | struct intel_crtc_state *pipe_config; | |
12863 | ||
12864 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
12865 | if (IS_ERR(pipe_config)) | |
12866 | return PTR_ERR(pipe_config); | |
12867 | ||
12868 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
12869 | ||
12870 | if (!pipe_config->base.active || | |
12871 | needs_modeset(&pipe_config->base)) | |
12872 | continue; | |
12873 | ||
12874 | /* 2 or more enabled crtcs means no need for w/a */ | |
12875 | if (enabled_pipe != INVALID_PIPE) | |
12876 | return 0; | |
12877 | ||
12878 | enabled_pipe = intel_crtc->pipe; | |
12879 | } | |
12880 | ||
12881 | if (enabled_pipe != INVALID_PIPE) | |
12882 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
12883 | else if (other_crtc_state) | |
12884 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
12885 | ||
12886 | return 0; | |
12887 | } | |
12888 | ||
27c329ed ML |
12889 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
12890 | { | |
12891 | struct drm_crtc *crtc; | |
12892 | struct drm_crtc_state *crtc_state; | |
12893 | int ret = 0; | |
12894 | ||
12895 | /* add all active pipes to the state */ | |
12896 | for_each_crtc(state->dev, crtc) { | |
12897 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
12898 | if (IS_ERR(crtc_state)) | |
12899 | return PTR_ERR(crtc_state); | |
12900 | ||
12901 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
12902 | continue; | |
12903 | ||
12904 | crtc_state->mode_changed = true; | |
12905 | ||
12906 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
12907 | if (ret) | |
12908 | break; | |
12909 | ||
12910 | ret = drm_atomic_add_affected_planes(state, crtc); | |
12911 | if (ret) | |
12912 | break; | |
12913 | } | |
12914 | ||
12915 | return ret; | |
12916 | } | |
12917 | ||
12918 | ||
c347a676 | 12919 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
12920 | { |
12921 | struct drm_device *dev = state->dev; | |
27c329ed | 12922 | struct drm_i915_private *dev_priv = dev->dev_private; |
054518dd ACO |
12923 | int ret; |
12924 | ||
b359283a ML |
12925 | if (!check_digital_port_conflicts(state)) { |
12926 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
12927 | return -EINVAL; | |
12928 | } | |
12929 | ||
054518dd ACO |
12930 | /* |
12931 | * See if the config requires any additional preparation, e.g. | |
12932 | * to adjust global state with pipes off. We need to do this | |
12933 | * here so we can get the modeset_pipe updated config for the new | |
12934 | * mode set on this crtc. For other crtcs we need to use the | |
12935 | * adjusted_mode bits in the crtc directly. | |
12936 | */ | |
27c329ed ML |
12937 | if (dev_priv->display.modeset_calc_cdclk) { |
12938 | unsigned int cdclk; | |
b432e5cf | 12939 | |
27c329ed ML |
12940 | ret = dev_priv->display.modeset_calc_cdclk(state); |
12941 | ||
12942 | cdclk = to_intel_atomic_state(state)->cdclk; | |
12943 | if (!ret && cdclk != dev_priv->cdclk_freq) | |
12944 | ret = intel_modeset_all_pipes(state); | |
12945 | ||
12946 | if (ret < 0) | |
054518dd | 12947 | return ret; |
27c329ed ML |
12948 | } else |
12949 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; | |
054518dd | 12950 | |
ad421372 | 12951 | intel_modeset_clear_plls(state); |
054518dd | 12952 | |
99d736a2 | 12953 | if (IS_HASWELL(dev)) |
ad421372 | 12954 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 12955 | |
ad421372 | 12956 | return 0; |
c347a676 ACO |
12957 | } |
12958 | ||
74c090b1 ML |
12959 | /** |
12960 | * intel_atomic_check - validate state object | |
12961 | * @dev: drm device | |
12962 | * @state: state to validate | |
12963 | */ | |
12964 | static int intel_atomic_check(struct drm_device *dev, | |
12965 | struct drm_atomic_state *state) | |
c347a676 ACO |
12966 | { |
12967 | struct drm_crtc *crtc; | |
12968 | struct drm_crtc_state *crtc_state; | |
12969 | int ret, i; | |
61333b60 | 12970 | bool any_ms = false; |
c347a676 | 12971 | |
74c090b1 | 12972 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
12973 | if (ret) |
12974 | return ret; | |
12975 | ||
c347a676 | 12976 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
12977 | struct intel_crtc_state *pipe_config = |
12978 | to_intel_crtc_state(crtc_state); | |
1ed51de9 DV |
12979 | |
12980 | /* Catch I915_MODE_FLAG_INHERITED */ | |
12981 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
12982 | crtc_state->mode_changed = true; | |
cfb23ed6 | 12983 | |
61333b60 ML |
12984 | if (!crtc_state->enable) { |
12985 | if (needs_modeset(crtc_state)) | |
12986 | any_ms = true; | |
c347a676 | 12987 | continue; |
61333b60 | 12988 | } |
c347a676 | 12989 | |
26495481 | 12990 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
12991 | continue; |
12992 | ||
26495481 DV |
12993 | /* FIXME: For only active_changed we shouldn't need to do any |
12994 | * state recomputation at all. */ | |
12995 | ||
1ed51de9 DV |
12996 | ret = drm_atomic_add_affected_connectors(state, crtc); |
12997 | if (ret) | |
12998 | return ret; | |
b359283a | 12999 | |
cfb23ed6 | 13000 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13001 | if (ret) |
13002 | return ret; | |
13003 | ||
26495481 DV |
13004 | if (i915.fastboot && |
13005 | intel_pipe_config_compare(state->dev, | |
cfb23ed6 | 13006 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13007 | pipe_config, true)) { |
26495481 DV |
13008 | crtc_state->mode_changed = false; |
13009 | } | |
13010 | ||
13011 | if (needs_modeset(crtc_state)) { | |
13012 | any_ms = true; | |
cfb23ed6 ML |
13013 | |
13014 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13015 | if (ret) | |
13016 | return ret; | |
13017 | } | |
61333b60 | 13018 | |
26495481 DV |
13019 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13020 | needs_modeset(crtc_state) ? | |
13021 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13022 | } |
13023 | ||
61333b60 ML |
13024 | if (any_ms) { |
13025 | ret = intel_modeset_checks(state); | |
13026 | ||
13027 | if (ret) | |
13028 | return ret; | |
27c329ed ML |
13029 | } else |
13030 | to_intel_atomic_state(state)->cdclk = | |
13031 | to_i915(state->dev)->cdclk_freq; | |
c347a676 ACO |
13032 | |
13033 | return drm_atomic_helper_check_planes(state->dev, state); | |
054518dd ACO |
13034 | } |
13035 | ||
74c090b1 ML |
13036 | /** |
13037 | * intel_atomic_commit - commit validated state object | |
13038 | * @dev: DRM device | |
13039 | * @state: the top-level driver state object | |
13040 | * @async: asynchronous commit | |
13041 | * | |
13042 | * This function commits a top-level state object that has been validated | |
13043 | * with drm_atomic_helper_check(). | |
13044 | * | |
13045 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13046 | * we can only handle plane-related operations and do not yet support | |
13047 | * asynchronous commit. | |
13048 | * | |
13049 | * RETURNS | |
13050 | * Zero for success or -errno. | |
13051 | */ | |
13052 | static int intel_atomic_commit(struct drm_device *dev, | |
13053 | struct drm_atomic_state *state, | |
13054 | bool async) | |
a6778b3c | 13055 | { |
fbee40df | 13056 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 ACO |
13057 | struct drm_crtc *crtc; |
13058 | struct drm_crtc_state *crtc_state; | |
c0c36b94 | 13059 | int ret = 0; |
0a9ab303 | 13060 | int i; |
61333b60 | 13061 | bool any_ms = false; |
a6778b3c | 13062 | |
74c090b1 ML |
13063 | if (async) { |
13064 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13065 | return -EINVAL; | |
13066 | } | |
13067 | ||
d4afb8cc ACO |
13068 | ret = drm_atomic_helper_prepare_planes(dev, state); |
13069 | if (ret) | |
13070 | return ret; | |
13071 | ||
1c5e19f8 ML |
13072 | drm_atomic_helper_swap_state(dev, state); |
13073 | ||
0a9ab303 | 13074 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13075 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13076 | ||
61333b60 ML |
13077 | if (!needs_modeset(crtc->state)) |
13078 | continue; | |
13079 | ||
13080 | any_ms = true; | |
a539205a | 13081 | intel_pre_plane_update(intel_crtc); |
460da916 | 13082 | |
a539205a ML |
13083 | if (crtc_state->active) { |
13084 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13085 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd ML |
13086 | intel_crtc->active = false; |
13087 | intel_disable_shared_dpll(intel_crtc); | |
a539205a | 13088 | } |
b8cecdf5 | 13089 | } |
7758a113 | 13090 | |
ea9d758d DV |
13091 | /* Only after disabling all output pipelines that will be changed can we |
13092 | * update the the output configuration. */ | |
4740b0f2 | 13093 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13094 | |
4740b0f2 ML |
13095 | if (any_ms) { |
13096 | intel_shared_dpll_commit(state); | |
13097 | ||
13098 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
61333b60 | 13099 | modeset_update_crtc_power_domains(state); |
4740b0f2 | 13100 | } |
47fab737 | 13101 | |
a6778b3c | 13102 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13103 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13104 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13105 | bool modeset = needs_modeset(crtc->state); | |
13106 | ||
13107 | if (modeset && crtc->state->active) { | |
a539205a ML |
13108 | update_scanline_offset(to_intel_crtc(crtc)); |
13109 | dev_priv->display.crtc_enable(crtc); | |
13110 | } | |
80715b2f | 13111 | |
f6ac4b2a ML |
13112 | if (!modeset) |
13113 | intel_pre_plane_update(intel_crtc); | |
13114 | ||
a539205a | 13115 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
f6ac4b2a | 13116 | intel_post_plane_update(intel_crtc); |
80715b2f | 13117 | } |
a6778b3c | 13118 | |
a6778b3c | 13119 | /* FIXME: add subpixel order */ |
83a57153 | 13120 | |
74c090b1 | 13121 | drm_atomic_helper_wait_for_vblanks(dev, state); |
d4afb8cc | 13122 | drm_atomic_helper_cleanup_planes(dev, state); |
2bfb4627 | 13123 | |
74c090b1 | 13124 | if (any_ms) |
ee165b1a ML |
13125 | intel_modeset_check_state(dev, state); |
13126 | ||
13127 | drm_atomic_state_free(state); | |
f30da187 | 13128 | |
74c090b1 | 13129 | return 0; |
7f27126e JB |
13130 | } |
13131 | ||
c0c36b94 CW |
13132 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13133 | { | |
83a57153 ACO |
13134 | struct drm_device *dev = crtc->dev; |
13135 | struct drm_atomic_state *state; | |
e694eb02 | 13136 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13137 | int ret; |
83a57153 ACO |
13138 | |
13139 | state = drm_atomic_state_alloc(dev); | |
13140 | if (!state) { | |
e694eb02 | 13141 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13142 | crtc->base.id); |
13143 | return; | |
13144 | } | |
13145 | ||
e694eb02 | 13146 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13147 | |
e694eb02 ML |
13148 | retry: |
13149 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13150 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13151 | if (!ret) { | |
13152 | if (!crtc_state->active) | |
13153 | goto out; | |
83a57153 | 13154 | |
e694eb02 | 13155 | crtc_state->mode_changed = true; |
74c090b1 | 13156 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13157 | } |
13158 | ||
e694eb02 ML |
13159 | if (ret == -EDEADLK) { |
13160 | drm_atomic_state_clear(state); | |
13161 | drm_modeset_backoff(state->acquire_ctx); | |
13162 | goto retry; | |
4ed9fb37 | 13163 | } |
4be07317 | 13164 | |
2bfb4627 | 13165 | if (ret) |
e694eb02 | 13166 | out: |
2bfb4627 | 13167 | drm_atomic_state_free(state); |
c0c36b94 CW |
13168 | } |
13169 | ||
25c5b266 DV |
13170 | #undef for_each_intel_crtc_masked |
13171 | ||
f6e5b160 | 13172 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13173 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13174 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13175 | .destroy = intel_crtc_destroy, |
13176 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13177 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13178 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13179 | }; |
13180 | ||
5358901f DV |
13181 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13182 | struct intel_shared_dpll *pll, | |
13183 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13184 | { |
5358901f | 13185 | uint32_t val; |
ee7b9f93 | 13186 | |
f458ebbc | 13187 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13188 | return false; |
13189 | ||
5358901f | 13190 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13191 | hw_state->dpll = val; |
13192 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13193 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13194 | |
13195 | return val & DPLL_VCO_ENABLE; | |
13196 | } | |
13197 | ||
15bdd4cf DV |
13198 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13199 | struct intel_shared_dpll *pll) | |
13200 | { | |
3e369b76 ACO |
13201 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13202 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13203 | } |
13204 | ||
e7b903d2 DV |
13205 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13206 | struct intel_shared_dpll *pll) | |
13207 | { | |
e7b903d2 | 13208 | /* PCH refclock must be enabled first */ |
89eff4be | 13209 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13210 | |
3e369b76 | 13211 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13212 | |
13213 | /* Wait for the clocks to stabilize. */ | |
13214 | POSTING_READ(PCH_DPLL(pll->id)); | |
13215 | udelay(150); | |
13216 | ||
13217 | /* The pixel multiplier can only be updated once the | |
13218 | * DPLL is enabled and the clocks are stable. | |
13219 | * | |
13220 | * So write it again. | |
13221 | */ | |
3e369b76 | 13222 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13223 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13224 | udelay(200); |
13225 | } | |
13226 | ||
13227 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13228 | struct intel_shared_dpll *pll) | |
13229 | { | |
13230 | struct drm_device *dev = dev_priv->dev; | |
13231 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13232 | |
13233 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13234 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13235 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13236 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13237 | } |
13238 | ||
15bdd4cf DV |
13239 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13240 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13241 | udelay(200); |
13242 | } | |
13243 | ||
46edb027 DV |
13244 | static char *ibx_pch_dpll_names[] = { |
13245 | "PCH DPLL A", | |
13246 | "PCH DPLL B", | |
13247 | }; | |
13248 | ||
7c74ade1 | 13249 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13250 | { |
e7b903d2 | 13251 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13252 | int i; |
13253 | ||
7c74ade1 | 13254 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13255 | |
e72f9fbf | 13256 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13257 | dev_priv->shared_dplls[i].id = i; |
13258 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13259 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13260 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13261 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13262 | dev_priv->shared_dplls[i].get_hw_state = |
13263 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13264 | } |
13265 | } | |
13266 | ||
7c74ade1 DV |
13267 | static void intel_shared_dpll_init(struct drm_device *dev) |
13268 | { | |
e7b903d2 | 13269 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13270 | |
b6283055 VS |
13271 | intel_update_cdclk(dev); |
13272 | ||
9cd86933 DV |
13273 | if (HAS_DDI(dev)) |
13274 | intel_ddi_pll_init(dev); | |
13275 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13276 | ibx_pch_dpll_init(dev); |
13277 | else | |
13278 | dev_priv->num_shared_dpll = 0; | |
13279 | ||
13280 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13281 | } |
13282 | ||
6beb8c23 MR |
13283 | /** |
13284 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13285 | * @plane: drm plane to prepare for | |
13286 | * @fb: framebuffer to prepare for presentation | |
13287 | * | |
13288 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13289 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13290 | * bits. Some older platforms need special physical address handling for | |
13291 | * cursor planes. | |
13292 | * | |
13293 | * Returns 0 on success, negative error code on failure. | |
13294 | */ | |
13295 | int | |
13296 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
13297 | struct drm_framebuffer *fb, |
13298 | const struct drm_plane_state *new_state) | |
465c120c MR |
13299 | { |
13300 | struct drm_device *dev = plane->dev; | |
6beb8c23 | 13301 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 MR |
13302 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
13303 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); | |
6beb8c23 | 13304 | int ret = 0; |
465c120c | 13305 | |
ea2c67bb | 13306 | if (!obj) |
465c120c MR |
13307 | return 0; |
13308 | ||
6beb8c23 | 13309 | mutex_lock(&dev->struct_mutex); |
465c120c | 13310 | |
6beb8c23 MR |
13311 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
13312 | INTEL_INFO(dev)->cursor_needs_physical) { | |
13313 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13314 | ret = i915_gem_object_attach_phys(obj, align); | |
13315 | if (ret) | |
13316 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13317 | } else { | |
91af127f | 13318 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL, NULL); |
6beb8c23 | 13319 | } |
465c120c | 13320 | |
6beb8c23 | 13321 | if (ret == 0) |
a9ff8714 | 13322 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
fdd508a6 | 13323 | |
4c34574f | 13324 | mutex_unlock(&dev->struct_mutex); |
465c120c | 13325 | |
6beb8c23 MR |
13326 | return ret; |
13327 | } | |
13328 | ||
38f3ce3a MR |
13329 | /** |
13330 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13331 | * @plane: drm plane to clean up for | |
13332 | * @fb: old framebuffer that was on plane | |
13333 | * | |
13334 | * Cleans up a framebuffer that has just been removed from a plane. | |
13335 | */ | |
13336 | void | |
13337 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
13338 | struct drm_framebuffer *fb, |
13339 | const struct drm_plane_state *old_state) | |
38f3ce3a MR |
13340 | { |
13341 | struct drm_device *dev = plane->dev; | |
13342 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
13343 | ||
13344 | if (WARN_ON(!obj)) | |
13345 | return; | |
13346 | ||
13347 | if (plane->type != DRM_PLANE_TYPE_CURSOR || | |
13348 | !INTEL_INFO(dev)->cursor_needs_physical) { | |
13349 | mutex_lock(&dev->struct_mutex); | |
82bc3b2d | 13350 | intel_unpin_fb_obj(fb, old_state); |
38f3ce3a MR |
13351 | mutex_unlock(&dev->struct_mutex); |
13352 | } | |
465c120c MR |
13353 | } |
13354 | ||
6156a456 CK |
13355 | int |
13356 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13357 | { | |
13358 | int max_scale; | |
13359 | struct drm_device *dev; | |
13360 | struct drm_i915_private *dev_priv; | |
13361 | int crtc_clock, cdclk; | |
13362 | ||
13363 | if (!intel_crtc || !crtc_state) | |
13364 | return DRM_PLANE_HELPER_NO_SCALING; | |
13365 | ||
13366 | dev = intel_crtc->base.dev; | |
13367 | dev_priv = dev->dev_private; | |
13368 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 13369 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 CK |
13370 | |
13371 | if (!crtc_clock || !cdclk) | |
13372 | return DRM_PLANE_HELPER_NO_SCALING; | |
13373 | ||
13374 | /* | |
13375 | * skl max scale is lower of: | |
13376 | * close to 3 but not 3, -1 is for that purpose | |
13377 | * or | |
13378 | * cdclk/crtc_clock | |
13379 | */ | |
13380 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13381 | ||
13382 | return max_scale; | |
13383 | } | |
13384 | ||
465c120c | 13385 | static int |
3c692a41 | 13386 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13387 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13388 | struct intel_plane_state *state) |
13389 | { | |
2b875c22 MR |
13390 | struct drm_crtc *crtc = state->base.crtc; |
13391 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13392 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13393 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13394 | bool can_position = false; | |
465c120c | 13395 | |
061e4b8d ML |
13396 | /* use scaler when colorkey is not required */ |
13397 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
818ed961 | 13398 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
061e4b8d ML |
13399 | min_scale = 1; |
13400 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13401 | can_position = true; |
6156a456 | 13402 | } |
d8106366 | 13403 | |
061e4b8d ML |
13404 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13405 | &state->dst, &state->clip, | |
da20eabd ML |
13406 | min_scale, max_scale, |
13407 | can_position, true, | |
13408 | &state->visible); | |
14af293f GP |
13409 | } |
13410 | ||
13411 | static void | |
13412 | intel_commit_primary_plane(struct drm_plane *plane, | |
13413 | struct intel_plane_state *state) | |
13414 | { | |
2b875c22 MR |
13415 | struct drm_crtc *crtc = state->base.crtc; |
13416 | struct drm_framebuffer *fb = state->base.fb; | |
13417 | struct drm_device *dev = plane->dev; | |
14af293f | 13418 | struct drm_i915_private *dev_priv = dev->dev_private; |
ea2c67bb | 13419 | struct intel_crtc *intel_crtc; |
14af293f GP |
13420 | struct drm_rect *src = &state->src; |
13421 | ||
ea2c67bb MR |
13422 | crtc = crtc ? crtc : plane->crtc; |
13423 | intel_crtc = to_intel_crtc(crtc); | |
cf4c7c12 MR |
13424 | |
13425 | plane->fb = fb; | |
9dc806fc MR |
13426 | crtc->x = src->x1 >> 16; |
13427 | crtc->y = src->y1 >> 16; | |
ccc759dc | 13428 | |
a539205a | 13429 | if (!crtc->state->active) |
302d19ac | 13430 | return; |
465c120c | 13431 | |
302d19ac ML |
13432 | if (state->visible) |
13433 | /* FIXME: kill this fastboot hack */ | |
13434 | intel_update_pipe_size(intel_crtc); | |
13435 | ||
13436 | dev_priv->display.update_primary_plane(crtc, fb, crtc->x, crtc->y); | |
465c120c MR |
13437 | } |
13438 | ||
a8ad0d8e ML |
13439 | static void |
13440 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13441 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13442 | { |
13443 | struct drm_device *dev = plane->dev; | |
13444 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13445 | ||
a8ad0d8e ML |
13446 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13447 | } | |
13448 | ||
613d2b27 ML |
13449 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
13450 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 13451 | { |
32b7eeec | 13452 | struct drm_device *dev = crtc->dev; |
3c692a41 | 13453 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3c692a41 | 13454 | |
f015c551 | 13455 | if (intel_crtc->atomic.update_wm_pre) |
32b7eeec | 13456 | intel_update_watermarks(crtc); |
3c692a41 | 13457 | |
c34c9ee4 | 13458 | /* Perform vblank evasion around commit operation */ |
a539205a | 13459 | if (crtc->state->active) |
34e0adbb | 13460 | intel_pipe_update_start(intel_crtc); |
0583236e ML |
13461 | |
13462 | if (!needs_modeset(crtc->state) && INTEL_INFO(dev)->gen >= 9) | |
13463 | skl_detach_scalers(intel_crtc); | |
32b7eeec MR |
13464 | } |
13465 | ||
613d2b27 ML |
13466 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
13467 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 13468 | { |
32b7eeec | 13469 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 13470 | |
8f539a83 | 13471 | if (crtc->state->active) |
34e0adbb | 13472 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
13473 | } |
13474 | ||
cf4c7c12 | 13475 | /** |
4a3b8769 MR |
13476 | * intel_plane_destroy - destroy a plane |
13477 | * @plane: plane to destroy | |
cf4c7c12 | 13478 | * |
4a3b8769 MR |
13479 | * Common destruction function for all types of planes (primary, cursor, |
13480 | * sprite). | |
cf4c7c12 | 13481 | */ |
4a3b8769 | 13482 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13483 | { |
13484 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13485 | drm_plane_cleanup(plane); | |
13486 | kfree(intel_plane); | |
13487 | } | |
13488 | ||
65a3fea0 | 13489 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13490 | .update_plane = drm_atomic_helper_update_plane, |
13491 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13492 | .destroy = intel_plane_destroy, |
c196e1d6 | 13493 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13494 | .atomic_get_property = intel_plane_atomic_get_property, |
13495 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13496 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13497 | .atomic_destroy_state = intel_plane_destroy_state, | |
13498 | ||
465c120c MR |
13499 | }; |
13500 | ||
13501 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13502 | int pipe) | |
13503 | { | |
13504 | struct intel_plane *primary; | |
8e7d688b | 13505 | struct intel_plane_state *state; |
465c120c | 13506 | const uint32_t *intel_primary_formats; |
45e3743a | 13507 | unsigned int num_formats; |
465c120c MR |
13508 | |
13509 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13510 | if (primary == NULL) | |
13511 | return NULL; | |
13512 | ||
8e7d688b MR |
13513 | state = intel_create_plane_state(&primary->base); |
13514 | if (!state) { | |
ea2c67bb MR |
13515 | kfree(primary); |
13516 | return NULL; | |
13517 | } | |
8e7d688b | 13518 | primary->base.state = &state->base; |
ea2c67bb | 13519 | |
465c120c MR |
13520 | primary->can_scale = false; |
13521 | primary->max_downscale = 1; | |
6156a456 CK |
13522 | if (INTEL_INFO(dev)->gen >= 9) { |
13523 | primary->can_scale = true; | |
af99ceda | 13524 | state->scaler_id = -1; |
6156a456 | 13525 | } |
465c120c MR |
13526 | primary->pipe = pipe; |
13527 | primary->plane = pipe; | |
a9ff8714 | 13528 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 MR |
13529 | primary->check_plane = intel_check_primary_plane; |
13530 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13531 | primary->disable_plane = intel_disable_primary_plane; |
465c120c MR |
13532 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13533 | primary->plane = !pipe; | |
13534 | ||
6c0fd451 DL |
13535 | if (INTEL_INFO(dev)->gen >= 9) { |
13536 | intel_primary_formats = skl_primary_formats; | |
13537 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13538 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13539 | intel_primary_formats = i965_primary_formats; |
13540 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13541 | } else { |
13542 | intel_primary_formats = i8xx_primary_formats; | |
13543 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13544 | } |
13545 | ||
13546 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13547 | &intel_plane_funcs, |
465c120c MR |
13548 | intel_primary_formats, num_formats, |
13549 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13550 | |
3b7a5119 SJ |
13551 | if (INTEL_INFO(dev)->gen >= 4) |
13552 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13553 | |
ea2c67bb MR |
13554 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13555 | ||
465c120c MR |
13556 | return &primary->base; |
13557 | } | |
13558 | ||
3b7a5119 SJ |
13559 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13560 | { | |
13561 | if (!dev->mode_config.rotation_property) { | |
13562 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13563 | BIT(DRM_ROTATE_180); | |
13564 | ||
13565 | if (INTEL_INFO(dev)->gen >= 9) | |
13566 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13567 | ||
13568 | dev->mode_config.rotation_property = | |
13569 | drm_mode_create_rotation_property(dev, flags); | |
13570 | } | |
13571 | if (dev->mode_config.rotation_property) | |
13572 | drm_object_attach_property(&plane->base.base, | |
13573 | dev->mode_config.rotation_property, | |
13574 | plane->base.state->rotation); | |
13575 | } | |
13576 | ||
3d7d6510 | 13577 | static int |
852e787c | 13578 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 13579 | struct intel_crtc_state *crtc_state, |
852e787c | 13580 | struct intel_plane_state *state) |
3d7d6510 | 13581 | { |
061e4b8d | 13582 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 13583 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 13584 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
13585 | unsigned stride; |
13586 | int ret; | |
3d7d6510 | 13587 | |
061e4b8d ML |
13588 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13589 | &state->dst, &state->clip, | |
3d7d6510 MR |
13590 | DRM_PLANE_HELPER_NO_SCALING, |
13591 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13592 | true, true, &state->visible); |
757f9a3e GP |
13593 | if (ret) |
13594 | return ret; | |
13595 | ||
757f9a3e GP |
13596 | /* if we want to turn off the cursor ignore width and height */ |
13597 | if (!obj) | |
da20eabd | 13598 | return 0; |
757f9a3e | 13599 | |
757f9a3e | 13600 | /* Check for which cursor types we support */ |
061e4b8d | 13601 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
13602 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
13603 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13604 | return -EINVAL; |
13605 | } | |
13606 | ||
ea2c67bb MR |
13607 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13608 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13609 | DRM_DEBUG_KMS("buffer is too small\n"); |
13610 | return -ENOMEM; | |
13611 | } | |
13612 | ||
3a656b54 | 13613 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 13614 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 13615 | return -EINVAL; |
32b7eeec MR |
13616 | } |
13617 | ||
da20eabd | 13618 | return 0; |
852e787c | 13619 | } |
3d7d6510 | 13620 | |
a8ad0d8e ML |
13621 | static void |
13622 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 13623 | struct drm_crtc *crtc) |
a8ad0d8e | 13624 | { |
a8ad0d8e ML |
13625 | intel_crtc_update_cursor(crtc, false); |
13626 | } | |
13627 | ||
f4a2cf29 | 13628 | static void |
852e787c GP |
13629 | intel_commit_cursor_plane(struct drm_plane *plane, |
13630 | struct intel_plane_state *state) | |
13631 | { | |
2b875c22 | 13632 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
13633 | struct drm_device *dev = plane->dev; |
13634 | struct intel_crtc *intel_crtc; | |
2b875c22 | 13635 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 13636 | uint32_t addr; |
852e787c | 13637 | |
ea2c67bb MR |
13638 | crtc = crtc ? crtc : plane->crtc; |
13639 | intel_crtc = to_intel_crtc(crtc); | |
13640 | ||
2b875c22 | 13641 | plane->fb = state->base.fb; |
ea2c67bb MR |
13642 | crtc->cursor_x = state->base.crtc_x; |
13643 | crtc->cursor_y = state->base.crtc_y; | |
13644 | ||
a912f12f GP |
13645 | if (intel_crtc->cursor_bo == obj) |
13646 | goto update; | |
4ed91096 | 13647 | |
f4a2cf29 | 13648 | if (!obj) |
a912f12f | 13649 | addr = 0; |
f4a2cf29 | 13650 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 13651 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 13652 | else |
a912f12f | 13653 | addr = obj->phys_handle->busaddr; |
852e787c | 13654 | |
a912f12f GP |
13655 | intel_crtc->cursor_addr = addr; |
13656 | intel_crtc->cursor_bo = obj; | |
852e787c | 13657 | |
302d19ac | 13658 | update: |
a539205a | 13659 | if (crtc->state->active) |
a912f12f | 13660 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
13661 | } |
13662 | ||
3d7d6510 MR |
13663 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
13664 | int pipe) | |
13665 | { | |
13666 | struct intel_plane *cursor; | |
8e7d688b | 13667 | struct intel_plane_state *state; |
3d7d6510 MR |
13668 | |
13669 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
13670 | if (cursor == NULL) | |
13671 | return NULL; | |
13672 | ||
8e7d688b MR |
13673 | state = intel_create_plane_state(&cursor->base); |
13674 | if (!state) { | |
ea2c67bb MR |
13675 | kfree(cursor); |
13676 | return NULL; | |
13677 | } | |
8e7d688b | 13678 | cursor->base.state = &state->base; |
ea2c67bb | 13679 | |
3d7d6510 MR |
13680 | cursor->can_scale = false; |
13681 | cursor->max_downscale = 1; | |
13682 | cursor->pipe = pipe; | |
13683 | cursor->plane = pipe; | |
a9ff8714 | 13684 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 MR |
13685 | cursor->check_plane = intel_check_cursor_plane; |
13686 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 13687 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
13688 | |
13689 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 13690 | &intel_plane_funcs, |
3d7d6510 MR |
13691 | intel_cursor_formats, |
13692 | ARRAY_SIZE(intel_cursor_formats), | |
13693 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
13694 | |
13695 | if (INTEL_INFO(dev)->gen >= 4) { | |
13696 | if (!dev->mode_config.rotation_property) | |
13697 | dev->mode_config.rotation_property = | |
13698 | drm_mode_create_rotation_property(dev, | |
13699 | BIT(DRM_ROTATE_0) | | |
13700 | BIT(DRM_ROTATE_180)); | |
13701 | if (dev->mode_config.rotation_property) | |
13702 | drm_object_attach_property(&cursor->base.base, | |
13703 | dev->mode_config.rotation_property, | |
8e7d688b | 13704 | state->base.rotation); |
4398ad45 VS |
13705 | } |
13706 | ||
af99ceda CK |
13707 | if (INTEL_INFO(dev)->gen >=9) |
13708 | state->scaler_id = -1; | |
13709 | ||
ea2c67bb MR |
13710 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
13711 | ||
3d7d6510 MR |
13712 | return &cursor->base; |
13713 | } | |
13714 | ||
549e2bfb CK |
13715 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
13716 | struct intel_crtc_state *crtc_state) | |
13717 | { | |
13718 | int i; | |
13719 | struct intel_scaler *intel_scaler; | |
13720 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
13721 | ||
13722 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
13723 | intel_scaler = &scaler_state->scalers[i]; | |
13724 | intel_scaler->in_use = 0; | |
549e2bfb CK |
13725 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
13726 | } | |
13727 | ||
13728 | scaler_state->scaler_id = -1; | |
13729 | } | |
13730 | ||
b358d0a6 | 13731 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 13732 | { |
fbee40df | 13733 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 13734 | struct intel_crtc *intel_crtc; |
f5de6e07 | 13735 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
13736 | struct drm_plane *primary = NULL; |
13737 | struct drm_plane *cursor = NULL; | |
465c120c | 13738 | int i, ret; |
79e53945 | 13739 | |
955382f3 | 13740 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
13741 | if (intel_crtc == NULL) |
13742 | return; | |
13743 | ||
f5de6e07 ACO |
13744 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
13745 | if (!crtc_state) | |
13746 | goto fail; | |
550acefd ACO |
13747 | intel_crtc->config = crtc_state; |
13748 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 13749 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 13750 | |
549e2bfb CK |
13751 | /* initialize shared scalers */ |
13752 | if (INTEL_INFO(dev)->gen >= 9) { | |
13753 | if (pipe == PIPE_C) | |
13754 | intel_crtc->num_scalers = 1; | |
13755 | else | |
13756 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
13757 | ||
13758 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
13759 | } | |
13760 | ||
465c120c | 13761 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
13762 | if (!primary) |
13763 | goto fail; | |
13764 | ||
13765 | cursor = intel_cursor_plane_create(dev, pipe); | |
13766 | if (!cursor) | |
13767 | goto fail; | |
13768 | ||
465c120c | 13769 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
13770 | cursor, &intel_crtc_funcs); |
13771 | if (ret) | |
13772 | goto fail; | |
79e53945 JB |
13773 | |
13774 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
13775 | for (i = 0; i < 256; i++) { |
13776 | intel_crtc->lut_r[i] = i; | |
13777 | intel_crtc->lut_g[i] = i; | |
13778 | intel_crtc->lut_b[i] = i; | |
13779 | } | |
13780 | ||
1f1c2e24 VS |
13781 | /* |
13782 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 13783 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 13784 | */ |
80824003 JB |
13785 | intel_crtc->pipe = pipe; |
13786 | intel_crtc->plane = pipe; | |
3a77c4c4 | 13787 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 13788 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 13789 | intel_crtc->plane = !pipe; |
80824003 JB |
13790 | } |
13791 | ||
4b0e333e CW |
13792 | intel_crtc->cursor_base = ~0; |
13793 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 13794 | intel_crtc->cursor_size = ~0; |
8d7849db | 13795 | |
852eb00d VS |
13796 | intel_crtc->wm.cxsr_allowed = true; |
13797 | ||
22fd0fab JB |
13798 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
13799 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
13800 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
13801 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
13802 | ||
79e53945 | 13803 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
13804 | |
13805 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
13806 | return; |
13807 | ||
13808 | fail: | |
13809 | if (primary) | |
13810 | drm_plane_cleanup(primary); | |
13811 | if (cursor) | |
13812 | drm_plane_cleanup(cursor); | |
f5de6e07 | 13813 | kfree(crtc_state); |
3d7d6510 | 13814 | kfree(intel_crtc); |
79e53945 JB |
13815 | } |
13816 | ||
752aa88a JB |
13817 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
13818 | { | |
13819 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 13820 | struct drm_device *dev = connector->base.dev; |
752aa88a | 13821 | |
51fd371b | 13822 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 13823 | |
d3babd3f | 13824 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
13825 | return INVALID_PIPE; |
13826 | ||
13827 | return to_intel_crtc(encoder->crtc)->pipe; | |
13828 | } | |
13829 | ||
08d7b3d1 | 13830 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 13831 | struct drm_file *file) |
08d7b3d1 | 13832 | { |
08d7b3d1 | 13833 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 13834 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 13835 | struct intel_crtc *crtc; |
08d7b3d1 | 13836 | |
7707e653 | 13837 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 13838 | |
7707e653 | 13839 | if (!drmmode_crtc) { |
08d7b3d1 | 13840 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 13841 | return -ENOENT; |
08d7b3d1 CW |
13842 | } |
13843 | ||
7707e653 | 13844 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 13845 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 13846 | |
c05422d5 | 13847 | return 0; |
08d7b3d1 CW |
13848 | } |
13849 | ||
66a9278e | 13850 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 13851 | { |
66a9278e DV |
13852 | struct drm_device *dev = encoder->base.dev; |
13853 | struct intel_encoder *source_encoder; | |
79e53945 | 13854 | int index_mask = 0; |
79e53945 JB |
13855 | int entry = 0; |
13856 | ||
b2784e15 | 13857 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 13858 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
13859 | index_mask |= (1 << entry); |
13860 | ||
79e53945 JB |
13861 | entry++; |
13862 | } | |
4ef69c7a | 13863 | |
79e53945 JB |
13864 | return index_mask; |
13865 | } | |
13866 | ||
4d302442 CW |
13867 | static bool has_edp_a(struct drm_device *dev) |
13868 | { | |
13869 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13870 | ||
13871 | if (!IS_MOBILE(dev)) | |
13872 | return false; | |
13873 | ||
13874 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
13875 | return false; | |
13876 | ||
e3589908 | 13877 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
13878 | return false; |
13879 | ||
13880 | return true; | |
13881 | } | |
13882 | ||
84b4e042 JB |
13883 | static bool intel_crt_present(struct drm_device *dev) |
13884 | { | |
13885 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13886 | ||
884497ed DL |
13887 | if (INTEL_INFO(dev)->gen >= 9) |
13888 | return false; | |
13889 | ||
cf404ce4 | 13890 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
13891 | return false; |
13892 | ||
13893 | if (IS_CHERRYVIEW(dev)) | |
13894 | return false; | |
13895 | ||
13896 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
13897 | return false; | |
13898 | ||
13899 | return true; | |
13900 | } | |
13901 | ||
79e53945 JB |
13902 | static void intel_setup_outputs(struct drm_device *dev) |
13903 | { | |
725e30ad | 13904 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 13905 | struct intel_encoder *encoder; |
cb0953d7 | 13906 | bool dpd_is_edp = false; |
79e53945 | 13907 | |
c9093354 | 13908 | intel_lvds_init(dev); |
79e53945 | 13909 | |
84b4e042 | 13910 | if (intel_crt_present(dev)) |
79935fca | 13911 | intel_crt_init(dev); |
cb0953d7 | 13912 | |
c776eb2e VK |
13913 | if (IS_BROXTON(dev)) { |
13914 | /* | |
13915 | * FIXME: Broxton doesn't support port detection via the | |
13916 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
13917 | * detect the ports. | |
13918 | */ | |
13919 | intel_ddi_init(dev, PORT_A); | |
13920 | intel_ddi_init(dev, PORT_B); | |
13921 | intel_ddi_init(dev, PORT_C); | |
13922 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
13923 | int found; |
13924 | ||
de31facd JB |
13925 | /* |
13926 | * Haswell uses DDI functions to detect digital outputs. | |
13927 | * On SKL pre-D0 the strap isn't connected, so we assume | |
13928 | * it's there. | |
13929 | */ | |
0e72a5b5 | 13930 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 13931 | /* WaIgnoreDDIAStrap: skl */ |
5a2376d1 | 13932 | if (found || IS_SKYLAKE(dev)) |
0e72a5b5 ED |
13933 | intel_ddi_init(dev, PORT_A); |
13934 | ||
13935 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
13936 | * register */ | |
13937 | found = I915_READ(SFUSE_STRAP); | |
13938 | ||
13939 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
13940 | intel_ddi_init(dev, PORT_B); | |
13941 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
13942 | intel_ddi_init(dev, PORT_C); | |
13943 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
13944 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
13945 | /* |
13946 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
13947 | */ | |
13948 | if (IS_SKYLAKE(dev) && | |
13949 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || | |
13950 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
13951 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
13952 | intel_ddi_init(dev, PORT_E); | |
13953 | ||
0e72a5b5 | 13954 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 13955 | int found; |
5d8a7752 | 13956 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
13957 | |
13958 | if (has_edp_a(dev)) | |
13959 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 13960 | |
dc0fa718 | 13961 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 13962 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 13963 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 13964 | if (!found) |
e2debe91 | 13965 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 13966 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 13967 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
13968 | } |
13969 | ||
dc0fa718 | 13970 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 13971 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 13972 | |
dc0fa718 | 13973 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 13974 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 13975 | |
5eb08b69 | 13976 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 13977 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 13978 | |
270b3042 | 13979 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 13980 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 13981 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
13982 | /* |
13983 | * The DP_DETECTED bit is the latched state of the DDC | |
13984 | * SDA pin at boot. However since eDP doesn't require DDC | |
13985 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
13986 | * eDP ports may have been muxed to an alternate function. | |
13987 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
13988 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
13989 | * detect eDP ports. | |
13990 | */ | |
d2182a66 VS |
13991 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
13992 | !intel_dp_is_edp(dev, PORT_B)) | |
585a94b8 AB |
13993 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
13994 | PORT_B); | |
e17ac6db VS |
13995 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
13996 | intel_dp_is_edp(dev, PORT_B)) | |
13997 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); | |
585a94b8 | 13998 | |
d2182a66 VS |
13999 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
14000 | !intel_dp_is_edp(dev, PORT_C)) | |
6f6005a5 JB |
14001 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
14002 | PORT_C); | |
e17ac6db VS |
14003 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
14004 | intel_dp_is_edp(dev, PORT_C)) | |
14005 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); | |
19c03924 | 14006 | |
9418c1f1 | 14007 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14008 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
9418c1f1 VS |
14009 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
14010 | PORT_D); | |
e17ac6db VS |
14011 | /* eDP not supported on port D, so don't check VBT */ |
14012 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) | |
14013 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); | |
9418c1f1 VS |
14014 | } |
14015 | ||
3cfca973 | 14016 | intel_dsi_init(dev); |
09da55dc | 14017 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14018 | bool found = false; |
7d57382e | 14019 | |
e2debe91 | 14020 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14021 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 14022 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
3fec3d2f | 14023 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14024 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14025 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14026 | } |
27185ae1 | 14027 | |
3fec3d2f | 14028 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14029 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14030 | } |
13520b05 KH |
14031 | |
14032 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14033 | |
e2debe91 | 14034 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14035 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 14036 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 14037 | } |
27185ae1 | 14038 | |
e2debe91 | 14039 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14040 | |
3fec3d2f | 14041 | if (IS_G4X(dev)) { |
b01f2c3a | 14042 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14043 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14044 | } |
3fec3d2f | 14045 | if (IS_G4X(dev)) |
ab9d7c30 | 14046 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14047 | } |
27185ae1 | 14048 | |
3fec3d2f | 14049 | if (IS_G4X(dev) && |
e7281eab | 14050 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14051 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14052 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14053 | intel_dvo_init(dev); |
14054 | ||
103a196f | 14055 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14056 | intel_tv_init(dev); |
14057 | ||
0bc12bcb | 14058 | intel_psr_init(dev); |
7c8f8a70 | 14059 | |
b2784e15 | 14060 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14061 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14062 | encoder->base.possible_clones = | |
66a9278e | 14063 | intel_encoder_clones(encoder); |
79e53945 | 14064 | } |
47356eb6 | 14065 | |
dde86e2d | 14066 | intel_init_pch_refclk(dev); |
270b3042 DV |
14067 | |
14068 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14069 | } |
14070 | ||
14071 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14072 | { | |
60a5ca01 | 14073 | struct drm_device *dev = fb->dev; |
79e53945 | 14074 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14075 | |
ef2d633e | 14076 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14077 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14078 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14079 | drm_gem_object_unreference(&intel_fb->obj->base); |
14080 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14081 | kfree(intel_fb); |
14082 | } | |
14083 | ||
14084 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14085 | struct drm_file *file, |
79e53945 JB |
14086 | unsigned int *handle) |
14087 | { | |
14088 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14089 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14090 | |
05394f39 | 14091 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14092 | } |
14093 | ||
86c98588 RV |
14094 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14095 | struct drm_file *file, | |
14096 | unsigned flags, unsigned color, | |
14097 | struct drm_clip_rect *clips, | |
14098 | unsigned num_clips) | |
14099 | { | |
14100 | struct drm_device *dev = fb->dev; | |
14101 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14102 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14103 | ||
14104 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14105 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14106 | mutex_unlock(&dev->struct_mutex); |
14107 | ||
14108 | return 0; | |
14109 | } | |
14110 | ||
79e53945 JB |
14111 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14112 | .destroy = intel_user_framebuffer_destroy, | |
14113 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14114 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14115 | }; |
14116 | ||
b321803d DL |
14117 | static |
14118 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14119 | uint32_t pixel_format) | |
14120 | { | |
14121 | u32 gen = INTEL_INFO(dev)->gen; | |
14122 | ||
14123 | if (gen >= 9) { | |
14124 | /* "The stride in bytes must not exceed the of the size of 8K | |
14125 | * pixels and 32K bytes." | |
14126 | */ | |
14127 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14128 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14129 | return 32*1024; | |
14130 | } else if (gen >= 4) { | |
14131 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14132 | return 16*1024; | |
14133 | else | |
14134 | return 32*1024; | |
14135 | } else if (gen >= 3) { | |
14136 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14137 | return 8*1024; | |
14138 | else | |
14139 | return 16*1024; | |
14140 | } else { | |
14141 | /* XXX DSPC is limited to 4k tiled */ | |
14142 | return 8*1024; | |
14143 | } | |
14144 | } | |
14145 | ||
b5ea642a DV |
14146 | static int intel_framebuffer_init(struct drm_device *dev, |
14147 | struct intel_framebuffer *intel_fb, | |
14148 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14149 | struct drm_i915_gem_object *obj) | |
79e53945 | 14150 | { |
6761dd31 | 14151 | unsigned int aligned_height; |
79e53945 | 14152 | int ret; |
b321803d | 14153 | u32 pitch_limit, stride_alignment; |
79e53945 | 14154 | |
dd4916c5 DV |
14155 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14156 | ||
2a80eada DV |
14157 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14158 | /* Enforce that fb modifier and tiling mode match, but only for | |
14159 | * X-tiled. This is needed for FBC. */ | |
14160 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14161 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14162 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14163 | return -EINVAL; | |
14164 | } | |
14165 | } else { | |
14166 | if (obj->tiling_mode == I915_TILING_X) | |
14167 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14168 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14169 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14170 | return -EINVAL; | |
14171 | } | |
14172 | } | |
14173 | ||
9a8f0a12 TU |
14174 | /* Passed in modifier sanity checking. */ |
14175 | switch (mode_cmd->modifier[0]) { | |
14176 | case I915_FORMAT_MOD_Y_TILED: | |
14177 | case I915_FORMAT_MOD_Yf_TILED: | |
14178 | if (INTEL_INFO(dev)->gen < 9) { | |
14179 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14180 | mode_cmd->modifier[0]); | |
14181 | return -EINVAL; | |
14182 | } | |
14183 | case DRM_FORMAT_MOD_NONE: | |
14184 | case I915_FORMAT_MOD_X_TILED: | |
14185 | break; | |
14186 | default: | |
c0f40428 JB |
14187 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14188 | mode_cmd->modifier[0]); | |
57cd6508 | 14189 | return -EINVAL; |
c16ed4be | 14190 | } |
57cd6508 | 14191 | |
b321803d DL |
14192 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14193 | mode_cmd->pixel_format); | |
14194 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14195 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14196 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14197 | return -EINVAL; |
c16ed4be | 14198 | } |
57cd6508 | 14199 | |
b321803d DL |
14200 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14201 | mode_cmd->pixel_format); | |
a35cdaa0 | 14202 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14203 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14204 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14205 | "tiled" : "linear", |
a35cdaa0 | 14206 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14207 | return -EINVAL; |
c16ed4be | 14208 | } |
5d7bd705 | 14209 | |
2a80eada | 14210 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14211 | mode_cmd->pitches[0] != obj->stride) { |
14212 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14213 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14214 | return -EINVAL; |
c16ed4be | 14215 | } |
5d7bd705 | 14216 | |
57779d06 | 14217 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14218 | switch (mode_cmd->pixel_format) { |
57779d06 | 14219 | case DRM_FORMAT_C8: |
04b3924d VS |
14220 | case DRM_FORMAT_RGB565: |
14221 | case DRM_FORMAT_XRGB8888: | |
14222 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14223 | break; |
14224 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14225 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14226 | DRM_DEBUG("unsupported pixel format: %s\n", |
14227 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14228 | return -EINVAL; |
c16ed4be | 14229 | } |
57779d06 | 14230 | break; |
57779d06 | 14231 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14232 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14233 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14234 | drm_get_format_name(mode_cmd->pixel_format)); | |
14235 | return -EINVAL; | |
14236 | } | |
14237 | break; | |
14238 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14239 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14240 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14241 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14242 | DRM_DEBUG("unsupported pixel format: %s\n", |
14243 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14244 | return -EINVAL; |
c16ed4be | 14245 | } |
b5626747 | 14246 | break; |
7531208b DL |
14247 | case DRM_FORMAT_ABGR2101010: |
14248 | if (!IS_VALLEYVIEW(dev)) { | |
14249 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14250 | drm_get_format_name(mode_cmd->pixel_format)); | |
14251 | return -EINVAL; | |
14252 | } | |
14253 | break; | |
04b3924d VS |
14254 | case DRM_FORMAT_YUYV: |
14255 | case DRM_FORMAT_UYVY: | |
14256 | case DRM_FORMAT_YVYU: | |
14257 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14258 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14259 | DRM_DEBUG("unsupported pixel format: %s\n", |
14260 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14261 | return -EINVAL; |
c16ed4be | 14262 | } |
57cd6508 CW |
14263 | break; |
14264 | default: | |
4ee62c76 VS |
14265 | DRM_DEBUG("unsupported pixel format: %s\n", |
14266 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14267 | return -EINVAL; |
14268 | } | |
14269 | ||
90f9a336 VS |
14270 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14271 | if (mode_cmd->offsets[0] != 0) | |
14272 | return -EINVAL; | |
14273 | ||
ec2c981e | 14274 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14275 | mode_cmd->pixel_format, |
14276 | mode_cmd->modifier[0]); | |
53155c0a DV |
14277 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14278 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14279 | return -EINVAL; | |
14280 | ||
c7d73f6a DV |
14281 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14282 | intel_fb->obj = obj; | |
80075d49 | 14283 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14284 | |
79e53945 JB |
14285 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14286 | if (ret) { | |
14287 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14288 | return ret; | |
14289 | } | |
14290 | ||
79e53945 JB |
14291 | return 0; |
14292 | } | |
14293 | ||
79e53945 JB |
14294 | static struct drm_framebuffer * |
14295 | intel_user_framebuffer_create(struct drm_device *dev, | |
14296 | struct drm_file *filp, | |
308e5bcb | 14297 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14298 | { |
05394f39 | 14299 | struct drm_i915_gem_object *obj; |
79e53945 | 14300 | |
308e5bcb JB |
14301 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14302 | mode_cmd->handles[0])); | |
c8725226 | 14303 | if (&obj->base == NULL) |
cce13ff7 | 14304 | return ERR_PTR(-ENOENT); |
79e53945 | 14305 | |
d2dff872 | 14306 | return intel_framebuffer_create(dev, mode_cmd, obj); |
79e53945 JB |
14307 | } |
14308 | ||
0695726e | 14309 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 14310 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14311 | { |
14312 | } | |
14313 | #endif | |
14314 | ||
79e53945 | 14315 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14316 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14317 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14318 | .atomic_check = intel_atomic_check, |
14319 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14320 | .atomic_state_alloc = intel_atomic_state_alloc, |
14321 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14322 | }; |
14323 | ||
e70236a8 JB |
14324 | /* Set up chip specific display functions */ |
14325 | static void intel_init_display(struct drm_device *dev) | |
14326 | { | |
14327 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14328 | ||
ee9300bb DV |
14329 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14330 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14331 | else if (IS_CHERRYVIEW(dev)) |
14332 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14333 | else if (IS_VALLEYVIEW(dev)) |
14334 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14335 | else if (IS_PINEVIEW(dev)) | |
14336 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14337 | else | |
14338 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14339 | ||
bc8d7dff DL |
14340 | if (INTEL_INFO(dev)->gen >= 9) { |
14341 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14342 | dev_priv->display.get_initial_plane_config = |
14343 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14344 | dev_priv->display.crtc_compute_clock = |
14345 | haswell_crtc_compute_clock; | |
14346 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14347 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14348 | dev_priv->display.update_primary_plane = |
14349 | skylake_update_primary_plane; | |
14350 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14351 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14352 | dev_priv->display.get_initial_plane_config = |
14353 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14354 | dev_priv->display.crtc_compute_clock = |
14355 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14356 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14357 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14358 | dev_priv->display.update_primary_plane = |
14359 | ironlake_update_primary_plane; | |
09b4ddf9 | 14360 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14361 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14362 | dev_priv->display.get_initial_plane_config = |
14363 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14364 | dev_priv->display.crtc_compute_clock = |
14365 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14366 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14367 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14368 | dev_priv->display.update_primary_plane = |
14369 | ironlake_update_primary_plane; | |
89b667f8 JB |
14370 | } else if (IS_VALLEYVIEW(dev)) { |
14371 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14372 | dev_priv->display.get_initial_plane_config = |
14373 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14374 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14375 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14376 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14377 | dev_priv->display.update_primary_plane = |
14378 | i9xx_update_primary_plane; | |
f564048e | 14379 | } else { |
0e8ffe1b | 14380 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14381 | dev_priv->display.get_initial_plane_config = |
14382 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14383 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14384 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14385 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14386 | dev_priv->display.update_primary_plane = |
14387 | i9xx_update_primary_plane; | |
f564048e | 14388 | } |
e70236a8 | 14389 | |
e70236a8 | 14390 | /* Returns the core display clock speed */ |
1652d19e VS |
14391 | if (IS_SKYLAKE(dev)) |
14392 | dev_priv->display.get_display_clock_speed = | |
14393 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
14394 | else if (IS_BROXTON(dev)) |
14395 | dev_priv->display.get_display_clock_speed = | |
14396 | broxton_get_display_clock_speed; | |
1652d19e VS |
14397 | else if (IS_BROADWELL(dev)) |
14398 | dev_priv->display.get_display_clock_speed = | |
14399 | broadwell_get_display_clock_speed; | |
14400 | else if (IS_HASWELL(dev)) | |
14401 | dev_priv->display.get_display_clock_speed = | |
14402 | haswell_get_display_clock_speed; | |
14403 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14404 | dev_priv->display.get_display_clock_speed = |
14405 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14406 | else if (IS_GEN5(dev)) |
14407 | dev_priv->display.get_display_clock_speed = | |
14408 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14409 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14410 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14411 | dev_priv->display.get_display_clock_speed = |
14412 | i945_get_display_clock_speed; | |
34edce2f VS |
14413 | else if (IS_GM45(dev)) |
14414 | dev_priv->display.get_display_clock_speed = | |
14415 | gm45_get_display_clock_speed; | |
14416 | else if (IS_CRESTLINE(dev)) | |
14417 | dev_priv->display.get_display_clock_speed = | |
14418 | i965gm_get_display_clock_speed; | |
14419 | else if (IS_PINEVIEW(dev)) | |
14420 | dev_priv->display.get_display_clock_speed = | |
14421 | pnv_get_display_clock_speed; | |
14422 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14423 | dev_priv->display.get_display_clock_speed = | |
14424 | g33_get_display_clock_speed; | |
e70236a8 JB |
14425 | else if (IS_I915G(dev)) |
14426 | dev_priv->display.get_display_clock_speed = | |
14427 | i915_get_display_clock_speed; | |
257a7ffc | 14428 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14429 | dev_priv->display.get_display_clock_speed = |
14430 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14431 | else if (IS_PINEVIEW(dev)) |
14432 | dev_priv->display.get_display_clock_speed = | |
14433 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14434 | else if (IS_I915GM(dev)) |
14435 | dev_priv->display.get_display_clock_speed = | |
14436 | i915gm_get_display_clock_speed; | |
14437 | else if (IS_I865G(dev)) | |
14438 | dev_priv->display.get_display_clock_speed = | |
14439 | i865_get_display_clock_speed; | |
f0f8a9ce | 14440 | else if (IS_I85X(dev)) |
e70236a8 | 14441 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14442 | i85x_get_display_clock_speed; |
623e01e5 VS |
14443 | else { /* 830 */ |
14444 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14445 | dev_priv->display.get_display_clock_speed = |
14446 | i830_get_display_clock_speed; | |
623e01e5 | 14447 | } |
e70236a8 | 14448 | |
7c10a2b5 | 14449 | if (IS_GEN5(dev)) { |
3bb11b53 | 14450 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14451 | } else if (IS_GEN6(dev)) { |
14452 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14453 | } else if (IS_IVYBRIDGE(dev)) { |
14454 | /* FIXME: detect B0+ stepping and use auto training */ | |
14455 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14456 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14457 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
14458 | if (IS_BROADWELL(dev)) { |
14459 | dev_priv->display.modeset_commit_cdclk = | |
14460 | broadwell_modeset_commit_cdclk; | |
14461 | dev_priv->display.modeset_calc_cdclk = | |
14462 | broadwell_modeset_calc_cdclk; | |
14463 | } | |
30a970c6 | 14464 | } else if (IS_VALLEYVIEW(dev)) { |
27c329ed ML |
14465 | dev_priv->display.modeset_commit_cdclk = |
14466 | valleyview_modeset_commit_cdclk; | |
14467 | dev_priv->display.modeset_calc_cdclk = | |
14468 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 14469 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
14470 | dev_priv->display.modeset_commit_cdclk = |
14471 | broxton_modeset_commit_cdclk; | |
14472 | dev_priv->display.modeset_calc_cdclk = | |
14473 | broxton_modeset_calc_cdclk; | |
e70236a8 | 14474 | } |
8c9f3aaf | 14475 | |
8c9f3aaf JB |
14476 | switch (INTEL_INFO(dev)->gen) { |
14477 | case 2: | |
14478 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14479 | break; | |
14480 | ||
14481 | case 3: | |
14482 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14483 | break; | |
14484 | ||
14485 | case 4: | |
14486 | case 5: | |
14487 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14488 | break; | |
14489 | ||
14490 | case 6: | |
14491 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14492 | break; | |
7c9017e5 | 14493 | case 7: |
4e0bbc31 | 14494 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14495 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14496 | break; | |
830c81db | 14497 | case 9: |
ba343e02 TU |
14498 | /* Drop through - unsupported since execlist only. */ |
14499 | default: | |
14500 | /* Default just returns -ENODEV to indicate unsupported */ | |
14501 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14502 | } |
7bd688cd JN |
14503 | |
14504 | intel_panel_init_backlight_funcs(dev); | |
e39b999a VS |
14505 | |
14506 | mutex_init(&dev_priv->pps_mutex); | |
e70236a8 JB |
14507 | } |
14508 | ||
b690e96c JB |
14509 | /* |
14510 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14511 | * resume, or other times. This quirk makes sure that's the case for | |
14512 | * affected systems. | |
14513 | */ | |
0206e353 | 14514 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14515 | { |
14516 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14517 | ||
14518 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14519 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14520 | } |
14521 | ||
b6b5d049 VS |
14522 | static void quirk_pipeb_force(struct drm_device *dev) |
14523 | { | |
14524 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14525 | ||
14526 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14527 | DRM_INFO("applying pipe b force quirk\n"); | |
14528 | } | |
14529 | ||
435793df KP |
14530 | /* |
14531 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14532 | */ | |
14533 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14534 | { | |
14535 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14536 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14537 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14538 | } |
14539 | ||
4dca20ef | 14540 | /* |
5a15ab5b CE |
14541 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14542 | * brightness value | |
4dca20ef CE |
14543 | */ |
14544 | static void quirk_invert_brightness(struct drm_device *dev) | |
14545 | { | |
14546 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14547 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14548 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14549 | } |
14550 | ||
9c72cc6f SD |
14551 | /* Some VBT's incorrectly indicate no backlight is present */ |
14552 | static void quirk_backlight_present(struct drm_device *dev) | |
14553 | { | |
14554 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14555 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14556 | DRM_INFO("applying backlight present quirk\n"); | |
14557 | } | |
14558 | ||
b690e96c JB |
14559 | struct intel_quirk { |
14560 | int device; | |
14561 | int subsystem_vendor; | |
14562 | int subsystem_device; | |
14563 | void (*hook)(struct drm_device *dev); | |
14564 | }; | |
14565 | ||
5f85f176 EE |
14566 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14567 | struct intel_dmi_quirk { | |
14568 | void (*hook)(struct drm_device *dev); | |
14569 | const struct dmi_system_id (*dmi_id_list)[]; | |
14570 | }; | |
14571 | ||
14572 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14573 | { | |
14574 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14575 | return 1; | |
14576 | } | |
14577 | ||
14578 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14579 | { | |
14580 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14581 | { | |
14582 | .callback = intel_dmi_reverse_brightness, | |
14583 | .ident = "NCR Corporation", | |
14584 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14585 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14586 | }, | |
14587 | }, | |
14588 | { } /* terminating entry */ | |
14589 | }, | |
14590 | .hook = quirk_invert_brightness, | |
14591 | }, | |
14592 | }; | |
14593 | ||
c43b5634 | 14594 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14595 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14596 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14597 | ||
b690e96c JB |
14598 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14599 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14600 | ||
5f080c0f VS |
14601 | /* 830 needs to leave pipe A & dpll A up */ |
14602 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14603 | ||
b6b5d049 VS |
14604 | /* 830 needs to leave pipe B & dpll B up */ |
14605 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14606 | ||
435793df KP |
14607 | /* Lenovo U160 cannot use SSC on LVDS */ |
14608 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14609 | |
14610 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14611 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14612 | |
be505f64 AH |
14613 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14614 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14615 | ||
14616 | /* Acer/eMachines G725 */ | |
14617 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14618 | ||
14619 | /* Acer/eMachines e725 */ | |
14620 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14621 | ||
14622 | /* Acer/Packard Bell NCL20 */ | |
14623 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14624 | ||
14625 | /* Acer Aspire 4736Z */ | |
14626 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14627 | |
14628 | /* Acer Aspire 5336 */ | |
14629 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14630 | |
14631 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14632 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14633 | |
dfb3d47b SD |
14634 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14635 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14636 | ||
b2a9601c | 14637 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14638 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14639 | ||
d4967d8c SD |
14640 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14641 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14642 | |
14643 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14644 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14645 | |
14646 | /* Dell Chromebook 11 */ | |
14647 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
14648 | }; |
14649 | ||
14650 | static void intel_init_quirks(struct drm_device *dev) | |
14651 | { | |
14652 | struct pci_dev *d = dev->pdev; | |
14653 | int i; | |
14654 | ||
14655 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14656 | struct intel_quirk *q = &intel_quirks[i]; | |
14657 | ||
14658 | if (d->device == q->device && | |
14659 | (d->subsystem_vendor == q->subsystem_vendor || | |
14660 | q->subsystem_vendor == PCI_ANY_ID) && | |
14661 | (d->subsystem_device == q->subsystem_device || | |
14662 | q->subsystem_device == PCI_ANY_ID)) | |
14663 | q->hook(dev); | |
14664 | } | |
5f85f176 EE |
14665 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14666 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14667 | intel_dmi_quirks[i].hook(dev); | |
14668 | } | |
b690e96c JB |
14669 | } |
14670 | ||
9cce37f4 JB |
14671 | /* Disable the VGA plane that we never use */ |
14672 | static void i915_disable_vga(struct drm_device *dev) | |
14673 | { | |
14674 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14675 | u8 sr1; | |
766aa1c4 | 14676 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 14677 | |
2b37c616 | 14678 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 14679 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 14680 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
14681 | sr1 = inb(VGA_SR_DATA); |
14682 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
14683 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
14684 | udelay(300); | |
14685 | ||
01f5a626 | 14686 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
14687 | POSTING_READ(vga_reg); |
14688 | } | |
14689 | ||
f817586c DV |
14690 | void intel_modeset_init_hw(struct drm_device *dev) |
14691 | { | |
b6283055 | 14692 | intel_update_cdclk(dev); |
a8f78b58 | 14693 | intel_prepare_ddi(dev); |
f817586c | 14694 | intel_init_clock_gating(dev); |
8090c6b9 | 14695 | intel_enable_gt_powersave(dev); |
f817586c DV |
14696 | } |
14697 | ||
79e53945 JB |
14698 | void intel_modeset_init(struct drm_device *dev) |
14699 | { | |
652c393a | 14700 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 14701 | int sprite, ret; |
8cc87b75 | 14702 | enum pipe pipe; |
46f297fb | 14703 | struct intel_crtc *crtc; |
79e53945 JB |
14704 | |
14705 | drm_mode_config_init(dev); | |
14706 | ||
14707 | dev->mode_config.min_width = 0; | |
14708 | dev->mode_config.min_height = 0; | |
14709 | ||
019d96cb DA |
14710 | dev->mode_config.preferred_depth = 24; |
14711 | dev->mode_config.prefer_shadow = 1; | |
14712 | ||
25bab385 TU |
14713 | dev->mode_config.allow_fb_modifiers = true; |
14714 | ||
e6ecefaa | 14715 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 14716 | |
b690e96c JB |
14717 | intel_init_quirks(dev); |
14718 | ||
1fa61106 ED |
14719 | intel_init_pm(dev); |
14720 | ||
e3c74757 BW |
14721 | if (INTEL_INFO(dev)->num_pipes == 0) |
14722 | return; | |
14723 | ||
69f92f67 LW |
14724 | /* |
14725 | * There may be no VBT; and if the BIOS enabled SSC we can | |
14726 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
14727 | * BIOS isn't using it, don't assume it will work even if the VBT | |
14728 | * indicates as much. | |
14729 | */ | |
14730 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
14731 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
14732 | DREF_SSC1_ENABLE); | |
14733 | ||
14734 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
14735 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
14736 | bios_lvds_use_ssc ? "en" : "dis", | |
14737 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
14738 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
14739 | } | |
14740 | } | |
14741 | ||
e70236a8 | 14742 | intel_init_display(dev); |
7c10a2b5 | 14743 | intel_init_audio(dev); |
e70236a8 | 14744 | |
a6c45cf0 CW |
14745 | if (IS_GEN2(dev)) { |
14746 | dev->mode_config.max_width = 2048; | |
14747 | dev->mode_config.max_height = 2048; | |
14748 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
14749 | dev->mode_config.max_width = 4096; |
14750 | dev->mode_config.max_height = 4096; | |
79e53945 | 14751 | } else { |
a6c45cf0 CW |
14752 | dev->mode_config.max_width = 8192; |
14753 | dev->mode_config.max_height = 8192; | |
79e53945 | 14754 | } |
068be561 | 14755 | |
dc41c154 VS |
14756 | if (IS_845G(dev) || IS_I865G(dev)) { |
14757 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
14758 | dev->mode_config.cursor_height = 1023; | |
14759 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
14760 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
14761 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
14762 | } else { | |
14763 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
14764 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
14765 | } | |
14766 | ||
5d4545ae | 14767 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 14768 | |
28c97730 | 14769 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
14770 | INTEL_INFO(dev)->num_pipes, |
14771 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 14772 | |
055e393f | 14773 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 14774 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 14775 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 14776 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 14777 | if (ret) |
06da8da2 | 14778 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 14779 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 14780 | } |
79e53945 JB |
14781 | } |
14782 | ||
e72f9fbf | 14783 | intel_shared_dpll_init(dev); |
ee7b9f93 | 14784 | |
9cce37f4 JB |
14785 | /* Just disable it once at startup */ |
14786 | i915_disable_vga(dev); | |
79e53945 | 14787 | intel_setup_outputs(dev); |
11be49eb CW |
14788 | |
14789 | /* Just in case the BIOS is doing something questionable. */ | |
7733b49b | 14790 | intel_fbc_disable(dev_priv); |
fa9fa083 | 14791 | |
6e9f798d | 14792 | drm_modeset_lock_all(dev); |
043e9bda | 14793 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 14794 | drm_modeset_unlock_all(dev); |
46f297fb | 14795 | |
d3fcc808 | 14796 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
14797 | struct intel_initial_plane_config plane_config = {}; |
14798 | ||
46f297fb JB |
14799 | if (!crtc->active) |
14800 | continue; | |
14801 | ||
46f297fb | 14802 | /* |
46f297fb JB |
14803 | * Note that reserving the BIOS fb up front prevents us |
14804 | * from stuffing other stolen allocations like the ring | |
14805 | * on top. This prevents some ugliness at boot time, and | |
14806 | * can even allow for smooth boot transitions if the BIOS | |
14807 | * fb is large enough for the active pipe configuration. | |
14808 | */ | |
eeebeac5 ML |
14809 | dev_priv->display.get_initial_plane_config(crtc, |
14810 | &plane_config); | |
14811 | ||
14812 | /* | |
14813 | * If the fb is shared between multiple heads, we'll | |
14814 | * just get the first one. | |
14815 | */ | |
14816 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 14817 | } |
2c7111db CW |
14818 | } |
14819 | ||
7fad798e DV |
14820 | static void intel_enable_pipe_a(struct drm_device *dev) |
14821 | { | |
14822 | struct intel_connector *connector; | |
14823 | struct drm_connector *crt = NULL; | |
14824 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 14825 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
14826 | |
14827 | /* We can't just switch on the pipe A, we need to set things up with a | |
14828 | * proper mode and output configuration. As a gross hack, enable pipe A | |
14829 | * by enabling the load detect pipe once. */ | |
3a3371ff | 14830 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
14831 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
14832 | crt = &connector->base; | |
14833 | break; | |
14834 | } | |
14835 | } | |
14836 | ||
14837 | if (!crt) | |
14838 | return; | |
14839 | ||
208bf9fd | 14840 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 14841 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
14842 | } |
14843 | ||
fa555837 DV |
14844 | static bool |
14845 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
14846 | { | |
7eb552ae BW |
14847 | struct drm_device *dev = crtc->base.dev; |
14848 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 DV |
14849 | u32 reg, val; |
14850 | ||
7eb552ae | 14851 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
14852 | return true; |
14853 | ||
14854 | reg = DSPCNTR(!crtc->plane); | |
14855 | val = I915_READ(reg); | |
14856 | ||
14857 | if ((val & DISPLAY_PLANE_ENABLE) && | |
14858 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
14859 | return false; | |
14860 | ||
14861 | return true; | |
14862 | } | |
14863 | ||
02e93c35 VS |
14864 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
14865 | { | |
14866 | struct drm_device *dev = crtc->base.dev; | |
14867 | struct intel_encoder *encoder; | |
14868 | ||
14869 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
14870 | return true; | |
14871 | ||
14872 | return false; | |
14873 | } | |
14874 | ||
24929352 DV |
14875 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
14876 | { | |
14877 | struct drm_device *dev = crtc->base.dev; | |
14878 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 | 14879 | u32 reg; |
24929352 | 14880 | |
24929352 | 14881 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 14882 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
14883 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
14884 | ||
d3eaf884 | 14885 | /* restore vblank interrupts to correct state */ |
9625604c | 14886 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 14887 | if (crtc->active) { |
3a03dfb0 | 14888 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); |
d297e103 | 14889 | update_scanline_offset(crtc); |
9625604c DV |
14890 | drm_crtc_vblank_on(&crtc->base); |
14891 | } | |
d3eaf884 | 14892 | |
24929352 | 14893 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
14894 | * disable the crtc (and hence change the state) if it is wrong. Note |
14895 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
14896 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
14897 | bool plane; |
14898 | ||
24929352 DV |
14899 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
14900 | crtc->base.base.id); | |
14901 | ||
14902 | /* Pipe has the wrong plane attached and the plane is active. | |
14903 | * Temporarily change the plane mapping and disable everything | |
14904 | * ... */ | |
14905 | plane = crtc->plane; | |
b70709a6 | 14906 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 14907 | crtc->plane = !plane; |
b17d48e2 | 14908 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 14909 | crtc->plane = plane; |
24929352 | 14910 | } |
24929352 | 14911 | |
7fad798e DV |
14912 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
14913 | crtc->pipe == PIPE_A && !crtc->active) { | |
14914 | /* BIOS forgot to enable pipe A, this mostly happens after | |
14915 | * resume. Force-enable the pipe to fix this, the update_dpms | |
14916 | * call below we restore the pipe to the right state, but leave | |
14917 | * the required bits on. */ | |
14918 | intel_enable_pipe_a(dev); | |
14919 | } | |
14920 | ||
24929352 DV |
14921 | /* Adjust the state of the output pipe according to whether we |
14922 | * have active connectors/encoders. */ | |
02e93c35 | 14923 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 14924 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 14925 | |
53d9f4e9 | 14926 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 14927 | struct intel_encoder *encoder; |
24929352 DV |
14928 | |
14929 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
14930 | * functions or because of calls to intel_crtc_disable_noatomic, |
14931 | * or because the pipe is force-enabled due to the | |
24929352 DV |
14932 | * pipe A quirk. */ |
14933 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
14934 | crtc->base.base.id, | |
83d65738 | 14935 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
14936 | crtc->active ? "enabled" : "disabled"); |
14937 | ||
4be40c98 | 14938 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 14939 | crtc->base.state->active = crtc->active; |
24929352 DV |
14940 | crtc->base.enabled = crtc->active; |
14941 | ||
14942 | /* Because we only establish the connector -> encoder -> | |
14943 | * crtc links if something is active, this means the | |
14944 | * crtc is now deactivated. Break the links. connector | |
14945 | * -> encoder links are only establish when things are | |
14946 | * actually up, hence no need to break them. */ | |
14947 | WARN_ON(crtc->active); | |
14948 | ||
2d406bb0 | 14949 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 14950 | encoder->base.crtc = NULL; |
24929352 | 14951 | } |
c5ab3bc0 | 14952 | |
a3ed6aad | 14953 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
14954 | /* |
14955 | * We start out with underrun reporting disabled to avoid races. | |
14956 | * For correct bookkeeping mark this on active crtcs. | |
14957 | * | |
c5ab3bc0 DV |
14958 | * Also on gmch platforms we dont have any hardware bits to |
14959 | * disable the underrun reporting. Which means we need to start | |
14960 | * out with underrun reporting disabled also on inactive pipes, | |
14961 | * since otherwise we'll complain about the garbage we read when | |
14962 | * e.g. coming up after runtime pm. | |
14963 | * | |
4cc31489 DV |
14964 | * No protection against concurrent access is required - at |
14965 | * worst a fifo underrun happens which also sets this to false. | |
14966 | */ | |
14967 | crtc->cpu_fifo_underrun_disabled = true; | |
14968 | crtc->pch_fifo_underrun_disabled = true; | |
14969 | } | |
24929352 DV |
14970 | } |
14971 | ||
14972 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
14973 | { | |
14974 | struct intel_connector *connector; | |
14975 | struct drm_device *dev = encoder->base.dev; | |
873ffe69 | 14976 | bool active = false; |
24929352 DV |
14977 | |
14978 | /* We need to check both for a crtc link (meaning that the | |
14979 | * encoder is active and trying to read from a pipe) and the | |
14980 | * pipe itself being active. */ | |
14981 | bool has_active_crtc = encoder->base.crtc && | |
14982 | to_intel_crtc(encoder->base.crtc)->active; | |
14983 | ||
873ffe69 ML |
14984 | for_each_intel_connector(dev, connector) { |
14985 | if (connector->base.encoder != &encoder->base) | |
14986 | continue; | |
14987 | ||
14988 | active = true; | |
14989 | break; | |
14990 | } | |
14991 | ||
14992 | if (active && !has_active_crtc) { | |
24929352 DV |
14993 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
14994 | encoder->base.base.id, | |
8e329a03 | 14995 | encoder->base.name); |
24929352 DV |
14996 | |
14997 | /* Connector is active, but has no active pipe. This is | |
14998 | * fallout from our resume register restoring. Disable | |
14999 | * the encoder manually again. */ | |
15000 | if (encoder->base.crtc) { | |
15001 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15002 | encoder->base.base.id, | |
8e329a03 | 15003 | encoder->base.name); |
24929352 | 15004 | encoder->disable(encoder); |
a62d1497 VS |
15005 | if (encoder->post_disable) |
15006 | encoder->post_disable(encoder); | |
24929352 | 15007 | } |
7f1950fb | 15008 | encoder->base.crtc = NULL; |
24929352 DV |
15009 | |
15010 | /* Inconsistent output/port/pipe state happens presumably due to | |
15011 | * a bug in one of the get_hw_state functions. Or someplace else | |
15012 | * in our code, like the register restore mess on resume. Clamp | |
15013 | * things to off as a safer default. */ | |
3a3371ff | 15014 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15015 | if (connector->encoder != encoder) |
15016 | continue; | |
7f1950fb EE |
15017 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15018 | connector->base.encoder = NULL; | |
24929352 DV |
15019 | } |
15020 | } | |
15021 | /* Enabled encoders without active connectors will be fixed in | |
15022 | * the crtc fixup. */ | |
15023 | } | |
15024 | ||
04098753 | 15025 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15026 | { |
15027 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 15028 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15029 | |
04098753 ID |
15030 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15031 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15032 | i915_disable_vga(dev); | |
15033 | } | |
15034 | } | |
15035 | ||
15036 | void i915_redisable_vga(struct drm_device *dev) | |
15037 | { | |
15038 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15039 | ||
8dc8a27c PZ |
15040 | /* This function can be called both from intel_modeset_setup_hw_state or |
15041 | * at a very early point in our resume sequence, where the power well | |
15042 | * structures are not yet restored. Since this function is at a very | |
15043 | * paranoid "someone might have enabled VGA while we were not looking" | |
15044 | * level, just check if the power well is enabled instead of trying to | |
15045 | * follow the "don't touch the power well if we don't need it" policy | |
15046 | * the rest of the driver uses. */ | |
f458ebbc | 15047 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15048 | return; |
15049 | ||
04098753 | 15050 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15051 | } |
15052 | ||
98ec7739 VS |
15053 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
15054 | { | |
15055 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
15056 | ||
d032ffa0 ML |
15057 | return !!(I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE); |
15058 | } | |
15059 | ||
15060 | static void readout_plane_state(struct intel_crtc *crtc, | |
15061 | struct intel_crtc_state *crtc_state) | |
15062 | { | |
15063 | struct intel_plane *p; | |
4cf0ebbd | 15064 | struct intel_plane_state *plane_state; |
d032ffa0 ML |
15065 | bool active = crtc_state->base.active; |
15066 | ||
d032ffa0 | 15067 | for_each_intel_plane(crtc->base.dev, p) { |
d032ffa0 ML |
15068 | if (crtc->pipe != p->pipe) |
15069 | continue; | |
15070 | ||
4cf0ebbd | 15071 | plane_state = to_intel_plane_state(p->base.state); |
e435d6e5 | 15072 | |
4cf0ebbd ML |
15073 | if (p->base.type == DRM_PLANE_TYPE_PRIMARY) |
15074 | plane_state->visible = primary_get_hw_state(crtc); | |
15075 | else { | |
15076 | if (active) | |
15077 | p->disable_plane(&p->base, &crtc->base); | |
d032ffa0 | 15078 | |
4cf0ebbd | 15079 | plane_state->visible = false; |
d032ffa0 ML |
15080 | } |
15081 | } | |
98ec7739 VS |
15082 | } |
15083 | ||
30e984df | 15084 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15085 | { |
15086 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15087 | enum pipe pipe; | |
24929352 DV |
15088 | struct intel_crtc *crtc; |
15089 | struct intel_encoder *encoder; | |
15090 | struct intel_connector *connector; | |
5358901f | 15091 | int i; |
24929352 | 15092 | |
d3fcc808 | 15093 | for_each_intel_crtc(dev, crtc) { |
b06f8b0d | 15094 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
6e3c9717 | 15095 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15096 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15097 | |
0e8ffe1b | 15098 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15099 | crtc->config); |
24929352 | 15100 | |
49d6fa21 | 15101 | crtc->base.state->active = crtc->active; |
24929352 | 15102 | crtc->base.enabled = crtc->active; |
b70709a6 | 15103 | |
5c1e3426 ML |
15104 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
15105 | if (crtc->base.state->active) { | |
15106 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
15107 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
15108 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
15109 | ||
15110 | /* | |
15111 | * The initial mode needs to be set in order to keep | |
15112 | * the atomic core happy. It wants a valid mode if the | |
15113 | * crtc's enabled, so we do the above call. | |
15114 | * | |
15115 | * At this point some state updated by the connectors | |
15116 | * in their ->detect() callback has not run yet, so | |
15117 | * no recalculation can be done yet. | |
15118 | * | |
15119 | * Even if we could do a recalculation and modeset | |
15120 | * right now it would cause a double modeset if | |
15121 | * fbdev or userspace chooses a different initial mode. | |
15122 | * | |
5c1e3426 ML |
15123 | * If that happens, someone indicated they wanted a |
15124 | * mode change, which means it's safe to do a full | |
15125 | * recalculation. | |
15126 | */ | |
1ed51de9 | 15127 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; |
5c1e3426 ML |
15128 | } |
15129 | ||
15130 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
d032ffa0 | 15131 | readout_plane_state(crtc, to_intel_crtc_state(crtc->base.state)); |
24929352 DV |
15132 | |
15133 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15134 | crtc->base.base.id, | |
15135 | crtc->active ? "enabled" : "disabled"); | |
15136 | } | |
15137 | ||
5358901f DV |
15138 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15139 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15140 | ||
3e369b76 ACO |
15141 | pll->on = pll->get_hw_state(dev_priv, pll, |
15142 | &pll->config.hw_state); | |
5358901f | 15143 | pll->active = 0; |
3e369b76 | 15144 | pll->config.crtc_mask = 0; |
d3fcc808 | 15145 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15146 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15147 | pll->active++; |
3e369b76 | 15148 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15149 | } |
5358901f | 15150 | } |
5358901f | 15151 | |
1e6f2ddc | 15152 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15153 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15154 | |
3e369b76 | 15155 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15156 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15157 | } |
15158 | ||
b2784e15 | 15159 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15160 | pipe = 0; |
15161 | ||
15162 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15163 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15164 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15165 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15166 | } else { |
15167 | encoder->base.crtc = NULL; | |
15168 | } | |
15169 | ||
6f2bcceb | 15170 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15171 | encoder->base.base.id, |
8e329a03 | 15172 | encoder->base.name, |
24929352 | 15173 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15174 | pipe_name(pipe)); |
24929352 DV |
15175 | } |
15176 | ||
3a3371ff | 15177 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15178 | if (connector->get_hw_state(connector)) { |
15179 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
24929352 DV |
15180 | connector->base.encoder = &connector->encoder->base; |
15181 | } else { | |
15182 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15183 | connector->base.encoder = NULL; | |
15184 | } | |
15185 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15186 | connector->base.base.id, | |
c23cc417 | 15187 | connector->base.name, |
24929352 DV |
15188 | connector->base.encoder ? "enabled" : "disabled"); |
15189 | } | |
30e984df DV |
15190 | } |
15191 | ||
043e9bda ML |
15192 | /* Scan out the current hw modeset state, |
15193 | * and sanitizes it to the current state | |
15194 | */ | |
15195 | static void | |
15196 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
15197 | { |
15198 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15199 | enum pipe pipe; | |
30e984df DV |
15200 | struct intel_crtc *crtc; |
15201 | struct intel_encoder *encoder; | |
35c95375 | 15202 | int i; |
30e984df DV |
15203 | |
15204 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
15205 | |
15206 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 15207 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15208 | intel_sanitize_encoder(encoder); |
15209 | } | |
15210 | ||
055e393f | 15211 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15212 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15213 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15214 | intel_dump_pipe_config(crtc, crtc->config, |
15215 | "[setup_hw_state]"); | |
24929352 | 15216 | } |
9a935856 | 15217 | |
d29b2f9d ACO |
15218 | intel_modeset_update_connector_atomic_state(dev); |
15219 | ||
35c95375 DV |
15220 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15221 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15222 | ||
15223 | if (!pll->on || pll->active) | |
15224 | continue; | |
15225 | ||
15226 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15227 | ||
15228 | pll->disable(dev_priv, pll); | |
15229 | pll->on = false; | |
15230 | } | |
15231 | ||
26e1fe4f | 15232 | if (IS_VALLEYVIEW(dev)) |
6eb1a681 VS |
15233 | vlv_wm_get_hw_state(dev); |
15234 | else if (IS_GEN9(dev)) | |
3078999f PB |
15235 | skl_wm_get_hw_state(dev); |
15236 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 15237 | ilk_wm_get_hw_state(dev); |
292b990e ML |
15238 | |
15239 | for_each_intel_crtc(dev, crtc) { | |
15240 | unsigned long put_domains; | |
15241 | ||
15242 | put_domains = modeset_get_crtc_power_domains(&crtc->base); | |
15243 | if (WARN_ON(put_domains)) | |
15244 | modeset_put_power_domains(dev_priv, put_domains); | |
15245 | } | |
15246 | intel_display_set_init_power(dev_priv, false); | |
043e9bda | 15247 | } |
7d0bc1ea | 15248 | |
043e9bda ML |
15249 | void intel_display_resume(struct drm_device *dev) |
15250 | { | |
15251 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); | |
15252 | struct intel_connector *conn; | |
15253 | struct intel_plane *plane; | |
15254 | struct drm_crtc *crtc; | |
15255 | int ret; | |
f30da187 | 15256 | |
043e9bda ML |
15257 | if (!state) |
15258 | return; | |
15259 | ||
15260 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
15261 | ||
15262 | /* preserve complete old state, including dpll */ | |
15263 | intel_atomic_get_shared_dpll_state(state); | |
15264 | ||
15265 | for_each_crtc(dev, crtc) { | |
15266 | struct drm_crtc_state *crtc_state = | |
15267 | drm_atomic_get_crtc_state(state, crtc); | |
15268 | ||
15269 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
15270 | if (ret) | |
15271 | goto err; | |
15272 | ||
15273 | /* force a restore */ | |
15274 | crtc_state->mode_changed = true; | |
45e2b5f6 | 15275 | } |
8af6cf88 | 15276 | |
043e9bda ML |
15277 | for_each_intel_plane(dev, plane) { |
15278 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); | |
15279 | if (ret) | |
15280 | goto err; | |
15281 | } | |
15282 | ||
15283 | for_each_intel_connector(dev, conn) { | |
15284 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); | |
15285 | if (ret) | |
15286 | goto err; | |
15287 | } | |
15288 | ||
15289 | intel_modeset_setup_hw_state(dev); | |
15290 | ||
15291 | i915_redisable_vga(dev); | |
74c090b1 | 15292 | ret = drm_atomic_commit(state); |
043e9bda ML |
15293 | if (!ret) |
15294 | return; | |
15295 | ||
15296 | err: | |
15297 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
15298 | drm_atomic_state_free(state); | |
2c7111db CW |
15299 | } |
15300 | ||
15301 | void intel_modeset_gem_init(struct drm_device *dev) | |
15302 | { | |
484b41dd | 15303 | struct drm_crtc *c; |
2ff8fde1 | 15304 | struct drm_i915_gem_object *obj; |
e0d6149b | 15305 | int ret; |
484b41dd | 15306 | |
ae48434c ID |
15307 | mutex_lock(&dev->struct_mutex); |
15308 | intel_init_gt_powersave(dev); | |
15309 | mutex_unlock(&dev->struct_mutex); | |
15310 | ||
1833b134 | 15311 | intel_modeset_init_hw(dev); |
02e792fb DV |
15312 | |
15313 | intel_setup_overlay(dev); | |
484b41dd JB |
15314 | |
15315 | /* | |
15316 | * Make sure any fbs we allocated at startup are properly | |
15317 | * pinned & fenced. When we do the allocation it's too early | |
15318 | * for this. | |
15319 | */ | |
70e1e0ec | 15320 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15321 | obj = intel_fb_obj(c->primary->fb); |
15322 | if (obj == NULL) | |
484b41dd JB |
15323 | continue; |
15324 | ||
e0d6149b TU |
15325 | mutex_lock(&dev->struct_mutex); |
15326 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15327 | c->primary->fb, | |
15328 | c->primary->state, | |
91af127f | 15329 | NULL, NULL); |
e0d6149b TU |
15330 | mutex_unlock(&dev->struct_mutex); |
15331 | if (ret) { | |
484b41dd JB |
15332 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15333 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15334 | drm_framebuffer_unreference(c->primary->fb); |
15335 | c->primary->fb = NULL; | |
36750f28 | 15336 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15337 | update_state_fb(c->primary); |
36750f28 | 15338 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15339 | } |
15340 | } | |
0962c3c9 VS |
15341 | |
15342 | intel_backlight_register(dev); | |
79e53945 JB |
15343 | } |
15344 | ||
4932e2c3 ID |
15345 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15346 | { | |
15347 | struct drm_connector *connector = &intel_connector->base; | |
15348 | ||
15349 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15350 | drm_connector_unregister(connector); |
4932e2c3 ID |
15351 | } |
15352 | ||
79e53945 JB |
15353 | void intel_modeset_cleanup(struct drm_device *dev) |
15354 | { | |
652c393a | 15355 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15356 | struct drm_connector *connector; |
652c393a | 15357 | |
2eb5252e ID |
15358 | intel_disable_gt_powersave(dev); |
15359 | ||
0962c3c9 VS |
15360 | intel_backlight_unregister(dev); |
15361 | ||
fd0c0642 DV |
15362 | /* |
15363 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15364 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15365 | * experience fancy races otherwise. |
15366 | */ | |
2aeb7d3a | 15367 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15368 | |
fd0c0642 DV |
15369 | /* |
15370 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15371 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15372 | */ | |
f87ea761 | 15373 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15374 | |
723bfd70 JB |
15375 | intel_unregister_dsm_handler(); |
15376 | ||
7733b49b | 15377 | intel_fbc_disable(dev_priv); |
69341a5e | 15378 | |
1630fe75 CW |
15379 | /* flush any delayed tasks or pending work */ |
15380 | flush_scheduled_work(); | |
15381 | ||
db31af1d JN |
15382 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15383 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15384 | struct intel_connector *intel_connector; |
15385 | ||
15386 | intel_connector = to_intel_connector(connector); | |
15387 | intel_connector->unregister(intel_connector); | |
db31af1d | 15388 | } |
d9255d57 | 15389 | |
79e53945 | 15390 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15391 | |
15392 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15393 | |
15394 | mutex_lock(&dev->struct_mutex); | |
15395 | intel_cleanup_gt_powersave(dev); | |
15396 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15397 | } |
15398 | ||
f1c79df3 ZW |
15399 | /* |
15400 | * Return which encoder is currently attached for connector. | |
15401 | */ | |
df0e9248 | 15402 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15403 | { |
df0e9248 CW |
15404 | return &intel_attached_encoder(connector)->base; |
15405 | } | |
f1c79df3 | 15406 | |
df0e9248 CW |
15407 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15408 | struct intel_encoder *encoder) | |
15409 | { | |
15410 | connector->encoder = encoder; | |
15411 | drm_mode_connector_attach_encoder(&connector->base, | |
15412 | &encoder->base); | |
79e53945 | 15413 | } |
28d52043 DA |
15414 | |
15415 | /* | |
15416 | * set vga decode state - true == enable VGA decode | |
15417 | */ | |
15418 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15419 | { | |
15420 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15421 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15422 | u16 gmch_ctrl; |
15423 | ||
75fa041d CW |
15424 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15425 | DRM_ERROR("failed to read control word\n"); | |
15426 | return -EIO; | |
15427 | } | |
15428 | ||
c0cc8a55 CW |
15429 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15430 | return 0; | |
15431 | ||
28d52043 DA |
15432 | if (state) |
15433 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15434 | else | |
15435 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15436 | |
15437 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15438 | DRM_ERROR("failed to write control word\n"); | |
15439 | return -EIO; | |
15440 | } | |
15441 | ||
28d52043 DA |
15442 | return 0; |
15443 | } | |
c4a1d9e4 | 15444 | |
c4a1d9e4 | 15445 | struct intel_display_error_state { |
ff57f1b0 PZ |
15446 | |
15447 | u32 power_well_driver; | |
15448 | ||
63b66e5b CW |
15449 | int num_transcoders; |
15450 | ||
c4a1d9e4 CW |
15451 | struct intel_cursor_error_state { |
15452 | u32 control; | |
15453 | u32 position; | |
15454 | u32 base; | |
15455 | u32 size; | |
52331309 | 15456 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15457 | |
15458 | struct intel_pipe_error_state { | |
ddf9c536 | 15459 | bool power_domain_on; |
c4a1d9e4 | 15460 | u32 source; |
f301b1e1 | 15461 | u32 stat; |
52331309 | 15462 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15463 | |
15464 | struct intel_plane_error_state { | |
15465 | u32 control; | |
15466 | u32 stride; | |
15467 | u32 size; | |
15468 | u32 pos; | |
15469 | u32 addr; | |
15470 | u32 surface; | |
15471 | u32 tile_offset; | |
52331309 | 15472 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15473 | |
15474 | struct intel_transcoder_error_state { | |
ddf9c536 | 15475 | bool power_domain_on; |
63b66e5b CW |
15476 | enum transcoder cpu_transcoder; |
15477 | ||
15478 | u32 conf; | |
15479 | ||
15480 | u32 htotal; | |
15481 | u32 hblank; | |
15482 | u32 hsync; | |
15483 | u32 vtotal; | |
15484 | u32 vblank; | |
15485 | u32 vsync; | |
15486 | } transcoder[4]; | |
c4a1d9e4 CW |
15487 | }; |
15488 | ||
15489 | struct intel_display_error_state * | |
15490 | intel_display_capture_error_state(struct drm_device *dev) | |
15491 | { | |
fbee40df | 15492 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15493 | struct intel_display_error_state *error; |
63b66e5b CW |
15494 | int transcoders[] = { |
15495 | TRANSCODER_A, | |
15496 | TRANSCODER_B, | |
15497 | TRANSCODER_C, | |
15498 | TRANSCODER_EDP, | |
15499 | }; | |
c4a1d9e4 CW |
15500 | int i; |
15501 | ||
63b66e5b CW |
15502 | if (INTEL_INFO(dev)->num_pipes == 0) |
15503 | return NULL; | |
15504 | ||
9d1cb914 | 15505 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15506 | if (error == NULL) |
15507 | return NULL; | |
15508 | ||
190be112 | 15509 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15510 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15511 | ||
055e393f | 15512 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15513 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15514 | __intel_display_power_is_enabled(dev_priv, |
15515 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15516 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15517 | continue; |
15518 | ||
5efb3e28 VS |
15519 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15520 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15521 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15522 | |
15523 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15524 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15525 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15526 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15527 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15528 | } | |
ca291363 PZ |
15529 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15530 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15531 | if (INTEL_INFO(dev)->gen >= 4) { |
15532 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15533 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15534 | } | |
15535 | ||
c4a1d9e4 | 15536 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15537 | |
3abfce77 | 15538 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15539 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15540 | } |
15541 | ||
15542 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15543 | if (HAS_DDI(dev_priv->dev)) | |
15544 | error->num_transcoders++; /* Account for eDP. */ | |
15545 | ||
15546 | for (i = 0; i < error->num_transcoders; i++) { | |
15547 | enum transcoder cpu_transcoder = transcoders[i]; | |
15548 | ||
ddf9c536 | 15549 | error->transcoder[i].power_domain_on = |
f458ebbc | 15550 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15551 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15552 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15553 | continue; |
15554 | ||
63b66e5b CW |
15555 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15556 | ||
15557 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15558 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15559 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15560 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15561 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15562 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15563 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15564 | } |
15565 | ||
15566 | return error; | |
15567 | } | |
15568 | ||
edc3d884 MK |
15569 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15570 | ||
c4a1d9e4 | 15571 | void |
edc3d884 | 15572 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15573 | struct drm_device *dev, |
15574 | struct intel_display_error_state *error) | |
15575 | { | |
055e393f | 15576 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15577 | int i; |
15578 | ||
63b66e5b CW |
15579 | if (!error) |
15580 | return; | |
15581 | ||
edc3d884 | 15582 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15583 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15584 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15585 | error->power_well_driver); |
055e393f | 15586 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15587 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15588 | err_printf(m, " Power: %s\n", |
15589 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15590 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15591 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15592 | |
15593 | err_printf(m, "Plane [%d]:\n", i); | |
15594 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15595 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15596 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15597 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15598 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15599 | } |
4b71a570 | 15600 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15601 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15602 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15603 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15604 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15605 | } |
15606 | ||
edc3d884 MK |
15607 | err_printf(m, "Cursor [%d]:\n", i); |
15608 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15609 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15610 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15611 | } |
63b66e5b CW |
15612 | |
15613 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15614 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15615 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15616 | err_printf(m, " Power: %s\n", |
15617 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15618 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15619 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15620 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15621 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15622 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15623 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15624 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15625 | } | |
c4a1d9e4 | 15626 | } |
e2fcdaa9 VS |
15627 | |
15628 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
15629 | { | |
15630 | struct intel_crtc *crtc; | |
15631 | ||
15632 | for_each_intel_crtc(dev, crtc) { | |
15633 | struct intel_unpin_work *work; | |
e2fcdaa9 | 15634 | |
5e2d7afc | 15635 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15636 | |
15637 | work = crtc->unpin_work; | |
15638 | ||
15639 | if (work && work->event && | |
15640 | work->event->base.file_priv == file) { | |
15641 | kfree(work->event); | |
15642 | work->event = NULL; | |
15643 | } | |
15644 | ||
5e2d7afc | 15645 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15646 | } |
15647 | } |