]>
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, |
465c120c MR |
75 | }; |
76 | ||
3d7d6510 MR |
77 | /* Cursor formats */ |
78 | static const uint32_t intel_cursor_formats[] = { | |
79 | DRM_FORMAT_ARGB8888, | |
80 | }; | |
81 | ||
6b383a7f | 82 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
79e53945 | 83 | |
f1f644dc | 84 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 85 | struct intel_crtc_state *pipe_config); |
18442d08 | 86 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 87 | struct intel_crtc_state *pipe_config); |
f1f644dc | 88 | |
568c634a | 89 | static int intel_set_mode(struct drm_atomic_state *state); |
eb1bfe80 JB |
90 | static int intel_framebuffer_init(struct drm_device *dev, |
91 | struct intel_framebuffer *ifb, | |
92 | struct drm_mode_fb_cmd2 *mode_cmd, | |
93 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
94 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
95 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
29407aab | 96 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
97 | struct intel_link_m_n *m_n, |
98 | struct intel_link_m_n *m2_n2); | |
29407aab | 99 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 DV |
100 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
101 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
d288f65f | 102 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 103 | const struct intel_crtc_state *pipe_config); |
d288f65f | 104 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 105 | const struct intel_crtc_state *pipe_config); |
ea2c67bb MR |
106 | static void intel_begin_crtc_commit(struct drm_crtc *crtc); |
107 | static void intel_finish_crtc_commit(struct drm_crtc *crtc); | |
549e2bfb CK |
108 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
109 | struct intel_crtc_state *crtc_state); | |
5ab7b0b7 ID |
110 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
111 | int num_connectors); | |
e7457a9a | 112 | |
0e32b39c DA |
113 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
114 | { | |
115 | if (!connector->mst_port) | |
116 | return connector->encoder; | |
117 | else | |
118 | return &connector->mst_port->mst_encoders[pipe]->base; | |
119 | } | |
120 | ||
79e53945 | 121 | typedef struct { |
0206e353 | 122 | int min, max; |
79e53945 JB |
123 | } intel_range_t; |
124 | ||
125 | typedef struct { | |
0206e353 AJ |
126 | int dot_limit; |
127 | int p2_slow, p2_fast; | |
79e53945 JB |
128 | } intel_p2_t; |
129 | ||
d4906093 ML |
130 | typedef struct intel_limit intel_limit_t; |
131 | struct intel_limit { | |
0206e353 AJ |
132 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
133 | intel_p2_t p2; | |
d4906093 | 134 | }; |
79e53945 | 135 | |
d2acd215 DV |
136 | int |
137 | intel_pch_rawclk(struct drm_device *dev) | |
138 | { | |
139 | struct drm_i915_private *dev_priv = dev->dev_private; | |
140 | ||
141 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
142 | ||
143 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
144 | } | |
145 | ||
021357ac CW |
146 | static inline u32 /* units of 100MHz */ |
147 | intel_fdi_link_freq(struct drm_device *dev) | |
148 | { | |
8b99e68c CW |
149 | if (IS_GEN5(dev)) { |
150 | struct drm_i915_private *dev_priv = dev->dev_private; | |
151 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
152 | } else | |
153 | return 27; | |
021357ac CW |
154 | } |
155 | ||
5d536e28 | 156 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 157 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 158 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 159 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
160 | .m = { .min = 96, .max = 140 }, |
161 | .m1 = { .min = 18, .max = 26 }, | |
162 | .m2 = { .min = 6, .max = 16 }, | |
163 | .p = { .min = 4, .max = 128 }, | |
164 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
165 | .p2 = { .dot_limit = 165000, |
166 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
167 | }; |
168 | ||
5d536e28 DV |
169 | static const intel_limit_t intel_limits_i8xx_dvo = { |
170 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 171 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 172 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
173 | .m = { .min = 96, .max = 140 }, |
174 | .m1 = { .min = 18, .max = 26 }, | |
175 | .m2 = { .min = 6, .max = 16 }, | |
176 | .p = { .min = 4, .max = 128 }, | |
177 | .p1 = { .min = 2, .max = 33 }, | |
178 | .p2 = { .dot_limit = 165000, | |
179 | .p2_slow = 4, .p2_fast = 4 }, | |
180 | }; | |
181 | ||
e4b36699 | 182 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 183 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 184 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 185 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
186 | .m = { .min = 96, .max = 140 }, |
187 | .m1 = { .min = 18, .max = 26 }, | |
188 | .m2 = { .min = 6, .max = 16 }, | |
189 | .p = { .min = 4, .max = 128 }, | |
190 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
191 | .p2 = { .dot_limit = 165000, |
192 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 193 | }; |
273e27ca | 194 | |
e4b36699 | 195 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
196 | .dot = { .min = 20000, .max = 400000 }, |
197 | .vco = { .min = 1400000, .max = 2800000 }, | |
198 | .n = { .min = 1, .max = 6 }, | |
199 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
200 | .m1 = { .min = 8, .max = 18 }, |
201 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
202 | .p = { .min = 5, .max = 80 }, |
203 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
204 | .p2 = { .dot_limit = 200000, |
205 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
206 | }; |
207 | ||
208 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
209 | .dot = { .min = 20000, .max = 400000 }, |
210 | .vco = { .min = 1400000, .max = 2800000 }, | |
211 | .n = { .min = 1, .max = 6 }, | |
212 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
213 | .m1 = { .min = 8, .max = 18 }, |
214 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
215 | .p = { .min = 7, .max = 98 }, |
216 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
217 | .p2 = { .dot_limit = 112000, |
218 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
219 | }; |
220 | ||
273e27ca | 221 | |
e4b36699 | 222 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
223 | .dot = { .min = 25000, .max = 270000 }, |
224 | .vco = { .min = 1750000, .max = 3500000}, | |
225 | .n = { .min = 1, .max = 4 }, | |
226 | .m = { .min = 104, .max = 138 }, | |
227 | .m1 = { .min = 17, .max = 23 }, | |
228 | .m2 = { .min = 5, .max = 11 }, | |
229 | .p = { .min = 10, .max = 30 }, | |
230 | .p1 = { .min = 1, .max = 3}, | |
231 | .p2 = { .dot_limit = 270000, | |
232 | .p2_slow = 10, | |
233 | .p2_fast = 10 | |
044c7c41 | 234 | }, |
e4b36699 KP |
235 | }; |
236 | ||
237 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
238 | .dot = { .min = 22000, .max = 400000 }, |
239 | .vco = { .min = 1750000, .max = 3500000}, | |
240 | .n = { .min = 1, .max = 4 }, | |
241 | .m = { .min = 104, .max = 138 }, | |
242 | .m1 = { .min = 16, .max = 23 }, | |
243 | .m2 = { .min = 5, .max = 11 }, | |
244 | .p = { .min = 5, .max = 80 }, | |
245 | .p1 = { .min = 1, .max = 8}, | |
246 | .p2 = { .dot_limit = 165000, | |
247 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
248 | }; |
249 | ||
250 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
251 | .dot = { .min = 20000, .max = 115000 }, |
252 | .vco = { .min = 1750000, .max = 3500000 }, | |
253 | .n = { .min = 1, .max = 3 }, | |
254 | .m = { .min = 104, .max = 138 }, | |
255 | .m1 = { .min = 17, .max = 23 }, | |
256 | .m2 = { .min = 5, .max = 11 }, | |
257 | .p = { .min = 28, .max = 112 }, | |
258 | .p1 = { .min = 2, .max = 8 }, | |
259 | .p2 = { .dot_limit = 0, | |
260 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 261 | }, |
e4b36699 KP |
262 | }; |
263 | ||
264 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
265 | .dot = { .min = 80000, .max = 224000 }, |
266 | .vco = { .min = 1750000, .max = 3500000 }, | |
267 | .n = { .min = 1, .max = 3 }, | |
268 | .m = { .min = 104, .max = 138 }, | |
269 | .m1 = { .min = 17, .max = 23 }, | |
270 | .m2 = { .min = 5, .max = 11 }, | |
271 | .p = { .min = 14, .max = 42 }, | |
272 | .p1 = { .min = 2, .max = 6 }, | |
273 | .p2 = { .dot_limit = 0, | |
274 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 275 | }, |
e4b36699 KP |
276 | }; |
277 | ||
f2b115e6 | 278 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
279 | .dot = { .min = 20000, .max = 400000}, |
280 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 281 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
282 | .n = { .min = 3, .max = 6 }, |
283 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 284 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
285 | .m1 = { .min = 0, .max = 0 }, |
286 | .m2 = { .min = 0, .max = 254 }, | |
287 | .p = { .min = 5, .max = 80 }, | |
288 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
289 | .p2 = { .dot_limit = 200000, |
290 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
291 | }; |
292 | ||
f2b115e6 | 293 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
294 | .dot = { .min = 20000, .max = 400000 }, |
295 | .vco = { .min = 1700000, .max = 3500000 }, | |
296 | .n = { .min = 3, .max = 6 }, | |
297 | .m = { .min = 2, .max = 256 }, | |
298 | .m1 = { .min = 0, .max = 0 }, | |
299 | .m2 = { .min = 0, .max = 254 }, | |
300 | .p = { .min = 7, .max = 112 }, | |
301 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
302 | .p2 = { .dot_limit = 112000, |
303 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
304 | }; |
305 | ||
273e27ca EA |
306 | /* Ironlake / Sandybridge |
307 | * | |
308 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
309 | * the range value for them is (actual_value - 2). | |
310 | */ | |
b91ad0ec | 311 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
312 | .dot = { .min = 25000, .max = 350000 }, |
313 | .vco = { .min = 1760000, .max = 3510000 }, | |
314 | .n = { .min = 1, .max = 5 }, | |
315 | .m = { .min = 79, .max = 127 }, | |
316 | .m1 = { .min = 12, .max = 22 }, | |
317 | .m2 = { .min = 5, .max = 9 }, | |
318 | .p = { .min = 5, .max = 80 }, | |
319 | .p1 = { .min = 1, .max = 8 }, | |
320 | .p2 = { .dot_limit = 225000, | |
321 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
322 | }; |
323 | ||
b91ad0ec | 324 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
325 | .dot = { .min = 25000, .max = 350000 }, |
326 | .vco = { .min = 1760000, .max = 3510000 }, | |
327 | .n = { .min = 1, .max = 3 }, | |
328 | .m = { .min = 79, .max = 118 }, | |
329 | .m1 = { .min = 12, .max = 22 }, | |
330 | .m2 = { .min = 5, .max = 9 }, | |
331 | .p = { .min = 28, .max = 112 }, | |
332 | .p1 = { .min = 2, .max = 8 }, | |
333 | .p2 = { .dot_limit = 225000, | |
334 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
335 | }; |
336 | ||
337 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
338 | .dot = { .min = 25000, .max = 350000 }, |
339 | .vco = { .min = 1760000, .max = 3510000 }, | |
340 | .n = { .min = 1, .max = 3 }, | |
341 | .m = { .min = 79, .max = 127 }, | |
342 | .m1 = { .min = 12, .max = 22 }, | |
343 | .m2 = { .min = 5, .max = 9 }, | |
344 | .p = { .min = 14, .max = 56 }, | |
345 | .p1 = { .min = 2, .max = 8 }, | |
346 | .p2 = { .dot_limit = 225000, | |
347 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
348 | }; |
349 | ||
273e27ca | 350 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 351 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
352 | .dot = { .min = 25000, .max = 350000 }, |
353 | .vco = { .min = 1760000, .max = 3510000 }, | |
354 | .n = { .min = 1, .max = 2 }, | |
355 | .m = { .min = 79, .max = 126 }, | |
356 | .m1 = { .min = 12, .max = 22 }, | |
357 | .m2 = { .min = 5, .max = 9 }, | |
358 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 359 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
360 | .p2 = { .dot_limit = 225000, |
361 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
362 | }; |
363 | ||
364 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
365 | .dot = { .min = 25000, .max = 350000 }, |
366 | .vco = { .min = 1760000, .max = 3510000 }, | |
367 | .n = { .min = 1, .max = 3 }, | |
368 | .m = { .min = 79, .max = 126 }, | |
369 | .m1 = { .min = 12, .max = 22 }, | |
370 | .m2 = { .min = 5, .max = 9 }, | |
371 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 372 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
373 | .p2 = { .dot_limit = 225000, |
374 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
375 | }; |
376 | ||
dc730512 | 377 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
378 | /* |
379 | * These are the data rate limits (measured in fast clocks) | |
380 | * since those are the strictest limits we have. The fast | |
381 | * clock and actual rate limits are more relaxed, so checking | |
382 | * them would make no difference. | |
383 | */ | |
384 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 385 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 386 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
387 | .m1 = { .min = 2, .max = 3 }, |
388 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 389 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 390 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
391 | }; |
392 | ||
ef9348c8 CML |
393 | static const intel_limit_t intel_limits_chv = { |
394 | /* | |
395 | * These are the data rate limits (measured in fast clocks) | |
396 | * since those are the strictest limits we have. The fast | |
397 | * clock and actual rate limits are more relaxed, so checking | |
398 | * them would make no difference. | |
399 | */ | |
400 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 401 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
402 | .n = { .min = 1, .max = 1 }, |
403 | .m1 = { .min = 2, .max = 2 }, | |
404 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
405 | .p1 = { .min = 2, .max = 4 }, | |
406 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
407 | }; | |
408 | ||
5ab7b0b7 ID |
409 | static const intel_limit_t intel_limits_bxt = { |
410 | /* FIXME: find real dot limits */ | |
411 | .dot = { .min = 0, .max = INT_MAX }, | |
412 | .vco = { .min = 4800000, .max = 6480000 }, | |
413 | .n = { .min = 1, .max = 1 }, | |
414 | .m1 = { .min = 2, .max = 2 }, | |
415 | /* FIXME: find real m2 limits */ | |
416 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
417 | .p1 = { .min = 2, .max = 4 }, | |
418 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
419 | }; | |
420 | ||
6b4bf1c4 VS |
421 | static void vlv_clock(int refclk, intel_clock_t *clock) |
422 | { | |
423 | clock->m = clock->m1 * clock->m2; | |
424 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e VS |
425 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
426 | return; | |
fb03ac01 VS |
427 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
428 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
6b4bf1c4 VS |
429 | } |
430 | ||
cdba954e ACO |
431 | static bool |
432 | needs_modeset(struct drm_crtc_state *state) | |
433 | { | |
434 | return state->mode_changed || state->active_changed; | |
435 | } | |
436 | ||
e0638cdf PZ |
437 | /** |
438 | * Returns whether any output on the specified pipe is of the specified type | |
439 | */ | |
4093561b | 440 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 441 | { |
409ee761 | 442 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
443 | struct intel_encoder *encoder; |
444 | ||
409ee761 | 445 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
446 | if (encoder->type == type) |
447 | return true; | |
448 | ||
449 | return false; | |
450 | } | |
451 | ||
d0737e1d ACO |
452 | /** |
453 | * Returns whether any output on the specified pipe will have the specified | |
454 | * type after a staged modeset is complete, i.e., the same as | |
455 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
456 | * encoder->crtc. | |
457 | */ | |
a93e255f ACO |
458 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
459 | int type) | |
d0737e1d | 460 | { |
a93e255f | 461 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 462 | struct drm_connector *connector; |
a93e255f | 463 | struct drm_connector_state *connector_state; |
d0737e1d | 464 | struct intel_encoder *encoder; |
a93e255f ACO |
465 | int i, num_connectors = 0; |
466 | ||
da3ced29 | 467 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
468 | if (connector_state->crtc != crtc_state->base.crtc) |
469 | continue; | |
470 | ||
471 | num_connectors++; | |
d0737e1d | 472 | |
a93e255f ACO |
473 | encoder = to_intel_encoder(connector_state->best_encoder); |
474 | if (encoder->type == type) | |
d0737e1d | 475 | return true; |
a93e255f ACO |
476 | } |
477 | ||
478 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
479 | |
480 | return false; | |
481 | } | |
482 | ||
a93e255f ACO |
483 | static const intel_limit_t * |
484 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 485 | { |
a93e255f | 486 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 487 | const intel_limit_t *limit; |
b91ad0ec | 488 | |
a93e255f | 489 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 490 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 491 | if (refclk == 100000) |
b91ad0ec ZW |
492 | limit = &intel_limits_ironlake_dual_lvds_100m; |
493 | else | |
494 | limit = &intel_limits_ironlake_dual_lvds; | |
495 | } else { | |
1b894b59 | 496 | if (refclk == 100000) |
b91ad0ec ZW |
497 | limit = &intel_limits_ironlake_single_lvds_100m; |
498 | else | |
499 | limit = &intel_limits_ironlake_single_lvds; | |
500 | } | |
c6bb3538 | 501 | } else |
b91ad0ec | 502 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
503 | |
504 | return limit; | |
505 | } | |
506 | ||
a93e255f ACO |
507 | static const intel_limit_t * |
508 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 509 | { |
a93e255f | 510 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
511 | const intel_limit_t *limit; |
512 | ||
a93e255f | 513 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 514 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 515 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 516 | else |
e4b36699 | 517 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
518 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
519 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 520 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 521 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 522 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 523 | } else /* The option is for other outputs */ |
e4b36699 | 524 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
525 | |
526 | return limit; | |
527 | } | |
528 | ||
a93e255f ACO |
529 | static const intel_limit_t * |
530 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 531 | { |
a93e255f | 532 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
533 | const intel_limit_t *limit; |
534 | ||
5ab7b0b7 ID |
535 | if (IS_BROXTON(dev)) |
536 | limit = &intel_limits_bxt; | |
537 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 538 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 539 | else if (IS_G4X(dev)) { |
a93e255f | 540 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 541 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 542 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 543 | limit = &intel_limits_pineview_lvds; |
2177832f | 544 | else |
f2b115e6 | 545 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
546 | } else if (IS_CHERRYVIEW(dev)) { |
547 | limit = &intel_limits_chv; | |
a0c4da24 | 548 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 549 | limit = &intel_limits_vlv; |
a6c45cf0 | 550 | } else if (!IS_GEN2(dev)) { |
a93e255f | 551 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
552 | limit = &intel_limits_i9xx_lvds; |
553 | else | |
554 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 555 | } else { |
a93e255f | 556 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 557 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 558 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 559 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
560 | else |
561 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
562 | } |
563 | return limit; | |
564 | } | |
565 | ||
f2b115e6 AJ |
566 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
567 | static void pineview_clock(int refclk, intel_clock_t *clock) | |
79e53945 | 568 | { |
2177832f SL |
569 | clock->m = clock->m2 + 2; |
570 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e VS |
571 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
572 | return; | |
fb03ac01 VS |
573 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
574 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
2177832f SL |
575 | } |
576 | ||
7429e9d4 DV |
577 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
578 | { | |
579 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
580 | } | |
581 | ||
ac58c3f0 | 582 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
2177832f | 583 | { |
7429e9d4 | 584 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 585 | clock->p = clock->p1 * clock->p2; |
ed5ca77e VS |
586 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
587 | return; | |
fb03ac01 VS |
588 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
589 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
79e53945 JB |
590 | } |
591 | ||
ef9348c8 CML |
592 | static void chv_clock(int refclk, intel_clock_t *clock) |
593 | { | |
594 | clock->m = clock->m1 * clock->m2; | |
595 | clock->p = clock->p1 * clock->p2; | |
596 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
597 | return; | |
598 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, | |
599 | clock->n << 22); | |
600 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
601 | } | |
602 | ||
7c04d1d9 | 603 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
604 | /** |
605 | * Returns whether the given set of divisors are valid for a given refclk with | |
606 | * the given connectors. | |
607 | */ | |
608 | ||
1b894b59 CW |
609 | static bool intel_PLL_is_valid(struct drm_device *dev, |
610 | const intel_limit_t *limit, | |
611 | const intel_clock_t *clock) | |
79e53945 | 612 | { |
f01b7962 VS |
613 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
614 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 615 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 616 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 617 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 618 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 619 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 620 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 621 | |
5ab7b0b7 | 622 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
f01b7962 VS |
623 | if (clock->m1 <= clock->m2) |
624 | INTELPllInvalid("m1 <= m2\n"); | |
625 | ||
5ab7b0b7 | 626 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
627 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
628 | INTELPllInvalid("p out of range\n"); | |
629 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
630 | INTELPllInvalid("m out of range\n"); | |
631 | } | |
632 | ||
79e53945 | 633 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 634 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
635 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
636 | * connector, etc., rather than just a single range. | |
637 | */ | |
638 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 639 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
640 | |
641 | return true; | |
642 | } | |
643 | ||
d4906093 | 644 | static bool |
a93e255f ACO |
645 | i9xx_find_best_dpll(const intel_limit_t *limit, |
646 | struct intel_crtc_state *crtc_state, | |
cec2f356 SP |
647 | int target, int refclk, intel_clock_t *match_clock, |
648 | intel_clock_t *best_clock) | |
79e53945 | 649 | { |
a93e255f | 650 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 651 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 652 | intel_clock_t clock; |
79e53945 JB |
653 | int err = target; |
654 | ||
a93e255f | 655 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 656 | /* |
a210b028 DV |
657 | * For LVDS just rely on its current settings for dual-channel. |
658 | * We haven't figured out how to reliably set up different | |
659 | * single/dual channel state, if we even can. | |
79e53945 | 660 | */ |
1974cad0 | 661 | if (intel_is_dual_link_lvds(dev)) |
79e53945 JB |
662 | clock.p2 = limit->p2.p2_fast; |
663 | else | |
664 | clock.p2 = limit->p2.p2_slow; | |
665 | } else { | |
666 | if (target < limit->p2.dot_limit) | |
667 | clock.p2 = limit->p2.p2_slow; | |
668 | else | |
669 | clock.p2 = limit->p2.p2_fast; | |
670 | } | |
671 | ||
0206e353 | 672 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 673 | |
42158660 ZY |
674 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
675 | clock.m1++) { | |
676 | for (clock.m2 = limit->m2.min; | |
677 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 678 | if (clock.m2 >= clock.m1) |
42158660 ZY |
679 | break; |
680 | for (clock.n = limit->n.min; | |
681 | clock.n <= limit->n.max; clock.n++) { | |
682 | for (clock.p1 = limit->p1.min; | |
683 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
684 | int this_err; |
685 | ||
ac58c3f0 DV |
686 | i9xx_clock(refclk, &clock); |
687 | if (!intel_PLL_is_valid(dev, limit, | |
688 | &clock)) | |
689 | continue; | |
690 | if (match_clock && | |
691 | clock.p != match_clock->p) | |
692 | continue; | |
693 | ||
694 | this_err = abs(clock.dot - target); | |
695 | if (this_err < err) { | |
696 | *best_clock = clock; | |
697 | err = this_err; | |
698 | } | |
699 | } | |
700 | } | |
701 | } | |
702 | } | |
703 | ||
704 | return (err != target); | |
705 | } | |
706 | ||
707 | static bool | |
a93e255f ACO |
708 | pnv_find_best_dpll(const intel_limit_t *limit, |
709 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
710 | int target, int refclk, intel_clock_t *match_clock, |
711 | intel_clock_t *best_clock) | |
79e53945 | 712 | { |
a93e255f | 713 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 714 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 715 | intel_clock_t clock; |
79e53945 JB |
716 | int err = target; |
717 | ||
a93e255f | 718 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 719 | /* |
a210b028 DV |
720 | * For LVDS just rely on its current settings for dual-channel. |
721 | * We haven't figured out how to reliably set up different | |
722 | * single/dual channel state, if we even can. | |
79e53945 | 723 | */ |
1974cad0 | 724 | if (intel_is_dual_link_lvds(dev)) |
79e53945 JB |
725 | clock.p2 = limit->p2.p2_fast; |
726 | else | |
727 | clock.p2 = limit->p2.p2_slow; | |
728 | } else { | |
729 | if (target < limit->p2.dot_limit) | |
730 | clock.p2 = limit->p2.p2_slow; | |
731 | else | |
732 | clock.p2 = limit->p2.p2_fast; | |
733 | } | |
734 | ||
0206e353 | 735 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 736 | |
42158660 ZY |
737 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
738 | clock.m1++) { | |
739 | for (clock.m2 = limit->m2.min; | |
740 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
741 | for (clock.n = limit->n.min; |
742 | clock.n <= limit->n.max; clock.n++) { | |
743 | for (clock.p1 = limit->p1.min; | |
744 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
745 | int this_err; |
746 | ||
ac58c3f0 | 747 | pineview_clock(refclk, &clock); |
1b894b59 CW |
748 | if (!intel_PLL_is_valid(dev, limit, |
749 | &clock)) | |
79e53945 | 750 | continue; |
cec2f356 SP |
751 | if (match_clock && |
752 | clock.p != match_clock->p) | |
753 | continue; | |
79e53945 JB |
754 | |
755 | this_err = abs(clock.dot - target); | |
756 | if (this_err < err) { | |
757 | *best_clock = clock; | |
758 | err = this_err; | |
759 | } | |
760 | } | |
761 | } | |
762 | } | |
763 | } | |
764 | ||
765 | return (err != target); | |
766 | } | |
767 | ||
d4906093 | 768 | static bool |
a93e255f ACO |
769 | g4x_find_best_dpll(const intel_limit_t *limit, |
770 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
771 | int target, int refclk, intel_clock_t *match_clock, |
772 | intel_clock_t *best_clock) | |
d4906093 | 773 | { |
a93e255f | 774 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 775 | struct drm_device *dev = crtc->base.dev; |
d4906093 ML |
776 | intel_clock_t clock; |
777 | int max_n; | |
778 | bool found; | |
6ba770dc AJ |
779 | /* approximately equals target * 0.00585 */ |
780 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
781 | found = false; |
782 | ||
a93e255f | 783 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 784 | if (intel_is_dual_link_lvds(dev)) |
d4906093 ML |
785 | clock.p2 = limit->p2.p2_fast; |
786 | else | |
787 | clock.p2 = limit->p2.p2_slow; | |
788 | } else { | |
789 | if (target < limit->p2.dot_limit) | |
790 | clock.p2 = limit->p2.p2_slow; | |
791 | else | |
792 | clock.p2 = limit->p2.p2_fast; | |
793 | } | |
794 | ||
795 | memset(best_clock, 0, sizeof(*best_clock)); | |
796 | max_n = limit->n.max; | |
f77f13e2 | 797 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 798 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 799 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
800 | for (clock.m1 = limit->m1.max; |
801 | clock.m1 >= limit->m1.min; clock.m1--) { | |
802 | for (clock.m2 = limit->m2.max; | |
803 | clock.m2 >= limit->m2.min; clock.m2--) { | |
804 | for (clock.p1 = limit->p1.max; | |
805 | clock.p1 >= limit->p1.min; clock.p1--) { | |
806 | int this_err; | |
807 | ||
ac58c3f0 | 808 | i9xx_clock(refclk, &clock); |
1b894b59 CW |
809 | if (!intel_PLL_is_valid(dev, limit, |
810 | &clock)) | |
d4906093 | 811 | continue; |
1b894b59 CW |
812 | |
813 | this_err = abs(clock.dot - target); | |
d4906093 ML |
814 | if (this_err < err_most) { |
815 | *best_clock = clock; | |
816 | err_most = this_err; | |
817 | max_n = clock.n; | |
818 | found = true; | |
819 | } | |
820 | } | |
821 | } | |
822 | } | |
823 | } | |
2c07245f ZW |
824 | return found; |
825 | } | |
826 | ||
d5dd62bd ID |
827 | /* |
828 | * Check if the calculated PLL configuration is more optimal compared to the | |
829 | * best configuration and error found so far. Return the calculated error. | |
830 | */ | |
831 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
832 | const intel_clock_t *calculated_clock, | |
833 | const intel_clock_t *best_clock, | |
834 | unsigned int best_error_ppm, | |
835 | unsigned int *error_ppm) | |
836 | { | |
9ca3ba01 ID |
837 | /* |
838 | * For CHV ignore the error and consider only the P value. | |
839 | * Prefer a bigger P value based on HW requirements. | |
840 | */ | |
841 | if (IS_CHERRYVIEW(dev)) { | |
842 | *error_ppm = 0; | |
843 | ||
844 | return calculated_clock->p > best_clock->p; | |
845 | } | |
846 | ||
24be4e46 ID |
847 | if (WARN_ON_ONCE(!target_freq)) |
848 | return false; | |
849 | ||
d5dd62bd ID |
850 | *error_ppm = div_u64(1000000ULL * |
851 | abs(target_freq - calculated_clock->dot), | |
852 | target_freq); | |
853 | /* | |
854 | * Prefer a better P value over a better (smaller) error if the error | |
855 | * is small. Ensure this preference for future configurations too by | |
856 | * setting the error to 0. | |
857 | */ | |
858 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
859 | *error_ppm = 0; | |
860 | ||
861 | return true; | |
862 | } | |
863 | ||
864 | return *error_ppm + 10 < best_error_ppm; | |
865 | } | |
866 | ||
a0c4da24 | 867 | static bool |
a93e255f ACO |
868 | vlv_find_best_dpll(const intel_limit_t *limit, |
869 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
870 | int target, int refclk, intel_clock_t *match_clock, |
871 | intel_clock_t *best_clock) | |
a0c4da24 | 872 | { |
a93e255f | 873 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 874 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 875 | intel_clock_t clock; |
69e4f900 | 876 | unsigned int bestppm = 1000000; |
27e639bf VS |
877 | /* min update 19.2 MHz */ |
878 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 879 | bool found = false; |
a0c4da24 | 880 | |
6b4bf1c4 VS |
881 | target *= 5; /* fast clock */ |
882 | ||
883 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
884 | |
885 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 886 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 887 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 888 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 889 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 890 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 891 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 892 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 893 | unsigned int ppm; |
69e4f900 | 894 | |
6b4bf1c4 VS |
895 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
896 | refclk * clock.m1); | |
897 | ||
898 | vlv_clock(refclk, &clock); | |
43b0ac53 | 899 | |
f01b7962 VS |
900 | if (!intel_PLL_is_valid(dev, limit, |
901 | &clock)) | |
43b0ac53 VS |
902 | continue; |
903 | ||
d5dd62bd ID |
904 | if (!vlv_PLL_is_optimal(dev, target, |
905 | &clock, | |
906 | best_clock, | |
907 | bestppm, &ppm)) | |
908 | continue; | |
6b4bf1c4 | 909 | |
d5dd62bd ID |
910 | *best_clock = clock; |
911 | bestppm = ppm; | |
912 | found = true; | |
a0c4da24 JB |
913 | } |
914 | } | |
915 | } | |
916 | } | |
a0c4da24 | 917 | |
49e497ef | 918 | return found; |
a0c4da24 | 919 | } |
a4fc5ed6 | 920 | |
ef9348c8 | 921 | static bool |
a93e255f ACO |
922 | chv_find_best_dpll(const intel_limit_t *limit, |
923 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
924 | int target, int refclk, intel_clock_t *match_clock, |
925 | intel_clock_t *best_clock) | |
926 | { | |
a93e255f | 927 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 928 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 929 | unsigned int best_error_ppm; |
ef9348c8 CML |
930 | intel_clock_t clock; |
931 | uint64_t m2; | |
932 | int found = false; | |
933 | ||
934 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 935 | best_error_ppm = 1000000; |
ef9348c8 CML |
936 | |
937 | /* | |
938 | * Based on hardware doc, the n always set to 1, and m1 always | |
939 | * set to 2. If requires to support 200Mhz refclk, we need to | |
940 | * revisit this because n may not 1 anymore. | |
941 | */ | |
942 | clock.n = 1, clock.m1 = 2; | |
943 | target *= 5; /* fast clock */ | |
944 | ||
945 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
946 | for (clock.p2 = limit->p2.p2_fast; | |
947 | clock.p2 >= limit->p2.p2_slow; | |
948 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 949 | unsigned int error_ppm; |
ef9348c8 CML |
950 | |
951 | clock.p = clock.p1 * clock.p2; | |
952 | ||
953 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
954 | clock.n) << 22, refclk * clock.m1); | |
955 | ||
956 | if (m2 > INT_MAX/clock.m1) | |
957 | continue; | |
958 | ||
959 | clock.m2 = m2; | |
960 | ||
961 | chv_clock(refclk, &clock); | |
962 | ||
963 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
964 | continue; | |
965 | ||
9ca3ba01 ID |
966 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
967 | best_error_ppm, &error_ppm)) | |
968 | continue; | |
969 | ||
970 | *best_clock = clock; | |
971 | best_error_ppm = error_ppm; | |
972 | found = true; | |
ef9348c8 CML |
973 | } |
974 | } | |
975 | ||
976 | return found; | |
977 | } | |
978 | ||
5ab7b0b7 ID |
979 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
980 | intel_clock_t *best_clock) | |
981 | { | |
982 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
983 | ||
984 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
985 | target_clock, refclk, NULL, best_clock); | |
986 | } | |
987 | ||
20ddf665 VS |
988 | bool intel_crtc_active(struct drm_crtc *crtc) |
989 | { | |
990 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
991 | ||
992 | /* Be paranoid as we can arrive here with only partial | |
993 | * state retrieved from the hardware during setup. | |
994 | * | |
241bfc38 | 995 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
996 | * as Haswell has gained clock readout/fastboot support. |
997 | * | |
66e514c1 | 998 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 999 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1000 | * |
1001 | * FIXME: The intel_crtc->active here should be switched to | |
1002 | * crtc->state->active once we have proper CRTC states wired up | |
1003 | * for atomic. | |
20ddf665 | 1004 | */ |
c3d1f436 | 1005 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1006 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1007 | } |
1008 | ||
a5c961d1 PZ |
1009 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1010 | enum pipe pipe) | |
1011 | { | |
1012 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1013 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1014 | ||
6e3c9717 | 1015 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1016 | } |
1017 | ||
fbf49ea2 VS |
1018 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1019 | { | |
1020 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1021 | u32 reg = PIPEDSL(pipe); | |
1022 | u32 line1, line2; | |
1023 | u32 line_mask; | |
1024 | ||
1025 | if (IS_GEN2(dev)) | |
1026 | line_mask = DSL_LINEMASK_GEN2; | |
1027 | else | |
1028 | line_mask = DSL_LINEMASK_GEN3; | |
1029 | ||
1030 | line1 = I915_READ(reg) & line_mask; | |
1031 | mdelay(5); | |
1032 | line2 = I915_READ(reg) & line_mask; | |
1033 | ||
1034 | return line1 == line2; | |
1035 | } | |
1036 | ||
ab7ad7f6 KP |
1037 | /* |
1038 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1039 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1040 | * |
1041 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1042 | * spinning on the vblank interrupt status bit, since we won't actually | |
1043 | * see an interrupt when the pipe is disabled. | |
1044 | * | |
ab7ad7f6 KP |
1045 | * On Gen4 and above: |
1046 | * wait for the pipe register state bit to turn off | |
1047 | * | |
1048 | * Otherwise: | |
1049 | * wait for the display line value to settle (it usually | |
1050 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1051 | * |
9d0498a2 | 1052 | */ |
575f7ab7 | 1053 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1054 | { |
575f7ab7 | 1055 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1056 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1057 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1058 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1059 | |
1060 | if (INTEL_INFO(dev)->gen >= 4) { | |
702e7a56 | 1061 | int reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1062 | |
1063 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1064 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1065 | 100)) | |
284637d9 | 1066 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1067 | } else { |
ab7ad7f6 | 1068 | /* Wait for the display line to settle */ |
fbf49ea2 | 1069 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1070 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1071 | } |
79e53945 JB |
1072 | } |
1073 | ||
b0ea7d37 DL |
1074 | /* |
1075 | * ibx_digital_port_connected - is the specified port connected? | |
1076 | * @dev_priv: i915 private structure | |
1077 | * @port: the port to test | |
1078 | * | |
1079 | * Returns true if @port is connected, false otherwise. | |
1080 | */ | |
1081 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, | |
1082 | struct intel_digital_port *port) | |
1083 | { | |
1084 | u32 bit; | |
1085 | ||
c36346e3 | 1086 | if (HAS_PCH_IBX(dev_priv->dev)) { |
eba905b2 | 1087 | switch (port->port) { |
c36346e3 DL |
1088 | case PORT_B: |
1089 | bit = SDE_PORTB_HOTPLUG; | |
1090 | break; | |
1091 | case PORT_C: | |
1092 | bit = SDE_PORTC_HOTPLUG; | |
1093 | break; | |
1094 | case PORT_D: | |
1095 | bit = SDE_PORTD_HOTPLUG; | |
1096 | break; | |
1097 | default: | |
1098 | return true; | |
1099 | } | |
1100 | } else { | |
eba905b2 | 1101 | switch (port->port) { |
c36346e3 DL |
1102 | case PORT_B: |
1103 | bit = SDE_PORTB_HOTPLUG_CPT; | |
1104 | break; | |
1105 | case PORT_C: | |
1106 | bit = SDE_PORTC_HOTPLUG_CPT; | |
1107 | break; | |
1108 | case PORT_D: | |
1109 | bit = SDE_PORTD_HOTPLUG_CPT; | |
1110 | break; | |
1111 | default: | |
1112 | return true; | |
1113 | } | |
b0ea7d37 DL |
1114 | } |
1115 | ||
1116 | return I915_READ(SDEISR) & bit; | |
1117 | } | |
1118 | ||
b24e7179 JB |
1119 | static const char *state_string(bool enabled) |
1120 | { | |
1121 | return enabled ? "on" : "off"; | |
1122 | } | |
1123 | ||
1124 | /* Only for pre-ILK configs */ | |
55607e8a DV |
1125 | void assert_pll(struct drm_i915_private *dev_priv, |
1126 | enum pipe pipe, bool state) | |
b24e7179 JB |
1127 | { |
1128 | int reg; | |
1129 | u32 val; | |
1130 | bool cur_state; | |
1131 | ||
1132 | reg = DPLL(pipe); | |
1133 | val = I915_READ(reg); | |
1134 | cur_state = !!(val & DPLL_VCO_ENABLE); | |
e2c719b7 | 1135 | I915_STATE_WARN(cur_state != state, |
b24e7179 JB |
1136 | "PLL state assertion failure (expected %s, current %s)\n", |
1137 | state_string(state), state_string(cur_state)); | |
1138 | } | |
b24e7179 | 1139 | |
23538ef1 JN |
1140 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1141 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1142 | { | |
1143 | u32 val; | |
1144 | bool cur_state; | |
1145 | ||
a580516d | 1146 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1147 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1148 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1149 | |
1150 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1151 | I915_STATE_WARN(cur_state != state, |
23538ef1 JN |
1152 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
1153 | state_string(state), state_string(cur_state)); | |
1154 | } | |
1155 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1156 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1157 | ||
55607e8a | 1158 | struct intel_shared_dpll * |
e2b78267 DV |
1159 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1160 | { | |
1161 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1162 | ||
6e3c9717 | 1163 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1164 | return NULL; |
1165 | ||
6e3c9717 | 1166 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1167 | } |
1168 | ||
040484af | 1169 | /* For ILK+ */ |
55607e8a DV |
1170 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1171 | struct intel_shared_dpll *pll, | |
1172 | bool state) | |
040484af | 1173 | { |
040484af | 1174 | bool cur_state; |
5358901f | 1175 | struct intel_dpll_hw_state hw_state; |
040484af | 1176 | |
92b27b08 | 1177 | if (WARN (!pll, |
46edb027 | 1178 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
ee7b9f93 | 1179 | return; |
ee7b9f93 | 1180 | |
5358901f | 1181 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1182 | I915_STATE_WARN(cur_state != state, |
5358901f DV |
1183 | "%s assertion failure (expected %s, current %s)\n", |
1184 | pll->name, state_string(state), state_string(cur_state)); | |
040484af | 1185 | } |
040484af JB |
1186 | |
1187 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1188 | enum pipe pipe, bool state) | |
1189 | { | |
1190 | int reg; | |
1191 | u32 val; | |
1192 | bool cur_state; | |
ad80a810 PZ |
1193 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1194 | pipe); | |
040484af | 1195 | |
affa9354 PZ |
1196 | if (HAS_DDI(dev_priv->dev)) { |
1197 | /* DDI does not have a specific FDI_TX register */ | |
ad80a810 | 1198 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
bf507ef7 | 1199 | val = I915_READ(reg); |
ad80a810 | 1200 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 ED |
1201 | } else { |
1202 | reg = FDI_TX_CTL(pipe); | |
1203 | val = I915_READ(reg); | |
1204 | cur_state = !!(val & FDI_TX_ENABLE); | |
1205 | } | |
e2c719b7 | 1206 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1207 | "FDI TX state assertion failure (expected %s, current %s)\n", |
1208 | state_string(state), state_string(cur_state)); | |
1209 | } | |
1210 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1211 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1212 | ||
1213 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1214 | enum pipe pipe, bool state) | |
1215 | { | |
1216 | int reg; | |
1217 | u32 val; | |
1218 | bool cur_state; | |
1219 | ||
d63fa0dc PZ |
1220 | reg = FDI_RX_CTL(pipe); |
1221 | val = I915_READ(reg); | |
1222 | cur_state = !!(val & FDI_RX_ENABLE); | |
e2c719b7 | 1223 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1224 | "FDI RX state assertion failure (expected %s, current %s)\n", |
1225 | state_string(state), state_string(cur_state)); | |
1226 | } | |
1227 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1228 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1229 | ||
1230 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1231 | enum pipe pipe) | |
1232 | { | |
1233 | int reg; | |
1234 | u32 val; | |
1235 | ||
1236 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1237 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1238 | return; |
1239 | ||
bf507ef7 | 1240 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1241 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1242 | return; |
1243 | ||
040484af JB |
1244 | reg = FDI_TX_CTL(pipe); |
1245 | val = I915_READ(reg); | |
e2c719b7 | 1246 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1247 | } |
1248 | ||
55607e8a DV |
1249 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1250 | enum pipe pipe, bool state) | |
040484af JB |
1251 | { |
1252 | int reg; | |
1253 | u32 val; | |
55607e8a | 1254 | bool cur_state; |
040484af JB |
1255 | |
1256 | reg = FDI_RX_CTL(pipe); | |
1257 | val = I915_READ(reg); | |
55607e8a | 1258 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1259 | I915_STATE_WARN(cur_state != state, |
55607e8a DV |
1260 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
1261 | state_string(state), state_string(cur_state)); | |
040484af JB |
1262 | } |
1263 | ||
b680c37a DV |
1264 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1265 | enum pipe pipe) | |
ea0760cf | 1266 | { |
bedd4dba JN |
1267 | struct drm_device *dev = dev_priv->dev; |
1268 | int pp_reg; | |
ea0760cf JB |
1269 | u32 val; |
1270 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1271 | bool locked = true; |
ea0760cf | 1272 | |
bedd4dba JN |
1273 | if (WARN_ON(HAS_DDI(dev))) |
1274 | return; | |
1275 | ||
1276 | if (HAS_PCH_SPLIT(dev)) { | |
1277 | u32 port_sel; | |
1278 | ||
ea0760cf | 1279 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1280 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1281 | ||
1282 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1283 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1284 | panel_pipe = PIPE_B; | |
1285 | /* XXX: else fix for eDP */ | |
1286 | } else if (IS_VALLEYVIEW(dev)) { | |
1287 | /* presumably write lock depends on pipe, not port select */ | |
1288 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1289 | panel_pipe = pipe; | |
ea0760cf JB |
1290 | } else { |
1291 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1292 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1293 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1294 | } |
1295 | ||
1296 | val = I915_READ(pp_reg); | |
1297 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1298 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1299 | locked = false; |
1300 | ||
e2c719b7 | 1301 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1302 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1303 | pipe_name(pipe)); |
ea0760cf JB |
1304 | } |
1305 | ||
93ce0ba6 JN |
1306 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1307 | enum pipe pipe, bool state) | |
1308 | { | |
1309 | struct drm_device *dev = dev_priv->dev; | |
1310 | bool cur_state; | |
1311 | ||
d9d82081 | 1312 | if (IS_845G(dev) || IS_I865G(dev)) |
93ce0ba6 | 1313 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
d9d82081 | 1314 | else |
5efb3e28 | 1315 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1316 | |
e2c719b7 | 1317 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 JN |
1318 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
1319 | pipe_name(pipe), state_string(state), state_string(cur_state)); | |
1320 | } | |
1321 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1322 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1323 | ||
b840d907 JB |
1324 | void assert_pipe(struct drm_i915_private *dev_priv, |
1325 | enum pipe pipe, bool state) | |
b24e7179 JB |
1326 | { |
1327 | int reg; | |
1328 | u32 val; | |
63d7bbe9 | 1329 | bool cur_state; |
702e7a56 PZ |
1330 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1331 | pipe); | |
b24e7179 | 1332 | |
b6b5d049 VS |
1333 | /* if we need the pipe quirk it must be always on */ |
1334 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1335 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1336 | state = true; |
1337 | ||
f458ebbc | 1338 | if (!intel_display_power_is_enabled(dev_priv, |
b97186f0 | 1339 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
69310161 PZ |
1340 | cur_state = false; |
1341 | } else { | |
1342 | reg = PIPECONF(cpu_transcoder); | |
1343 | val = I915_READ(reg); | |
1344 | cur_state = !!(val & PIPECONF_ENABLE); | |
1345 | } | |
1346 | ||
e2c719b7 | 1347 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1348 | "pipe %c assertion failure (expected %s, current %s)\n", |
9db4a9c7 | 1349 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
b24e7179 JB |
1350 | } |
1351 | ||
931872fc CW |
1352 | static void assert_plane(struct drm_i915_private *dev_priv, |
1353 | enum plane plane, bool state) | |
b24e7179 JB |
1354 | { |
1355 | int reg; | |
1356 | u32 val; | |
931872fc | 1357 | bool cur_state; |
b24e7179 JB |
1358 | |
1359 | reg = DSPCNTR(plane); | |
1360 | val = I915_READ(reg); | |
931872fc | 1361 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1362 | I915_STATE_WARN(cur_state != state, |
931872fc CW |
1363 | "plane %c assertion failure (expected %s, current %s)\n", |
1364 | plane_name(plane), state_string(state), state_string(cur_state)); | |
b24e7179 JB |
1365 | } |
1366 | ||
931872fc CW |
1367 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1368 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1369 | ||
b24e7179 JB |
1370 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1371 | enum pipe pipe) | |
1372 | { | |
653e1026 | 1373 | struct drm_device *dev = dev_priv->dev; |
b24e7179 JB |
1374 | int reg, i; |
1375 | u32 val; | |
1376 | int cur_pipe; | |
1377 | ||
653e1026 VS |
1378 | /* Primary planes are fixed to pipes on gen4+ */ |
1379 | if (INTEL_INFO(dev)->gen >= 4) { | |
28c05794 AJ |
1380 | reg = DSPCNTR(pipe); |
1381 | val = I915_READ(reg); | |
e2c719b7 | 1382 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1383 | "plane %c assertion failure, should be disabled but not\n", |
1384 | plane_name(pipe)); | |
19ec1358 | 1385 | return; |
28c05794 | 1386 | } |
19ec1358 | 1387 | |
b24e7179 | 1388 | /* Need to check both planes against the pipe */ |
055e393f | 1389 | for_each_pipe(dev_priv, i) { |
b24e7179 JB |
1390 | reg = DSPCNTR(i); |
1391 | val = I915_READ(reg); | |
1392 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
1393 | DISPPLANE_SEL_PIPE_SHIFT; | |
e2c719b7 | 1394 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1395 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1396 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1397 | } |
1398 | } | |
1399 | ||
19332d7a JB |
1400 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1401 | enum pipe pipe) | |
1402 | { | |
20674eef | 1403 | struct drm_device *dev = dev_priv->dev; |
1fe47785 | 1404 | int reg, sprite; |
19332d7a JB |
1405 | u32 val; |
1406 | ||
7feb8b88 | 1407 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1408 | for_each_sprite(dev_priv, pipe, sprite) { |
7feb8b88 | 1409 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1410 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1411 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1412 | sprite, pipe_name(pipe)); | |
1413 | } | |
1414 | } else if (IS_VALLEYVIEW(dev)) { | |
3bdcfc0c | 1415 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 1416 | reg = SPCNTR(pipe, sprite); |
20674eef | 1417 | val = I915_READ(reg); |
e2c719b7 | 1418 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1419 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1420 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1421 | } |
1422 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
1423 | reg = SPRCTL(pipe); | |
19332d7a | 1424 | val = I915_READ(reg); |
e2c719b7 | 1425 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1426 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1427 | plane_name(pipe), pipe_name(pipe)); |
1428 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
1429 | reg = DVSCNTR(pipe); | |
19332d7a | 1430 | val = I915_READ(reg); |
e2c719b7 | 1431 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1432 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1433 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1434 | } |
1435 | } | |
1436 | ||
08c71e5e VS |
1437 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1438 | { | |
e2c719b7 | 1439 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1440 | drm_crtc_vblank_put(crtc); |
1441 | } | |
1442 | ||
89eff4be | 1443 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1444 | { |
1445 | u32 val; | |
1446 | bool enabled; | |
1447 | ||
e2c719b7 | 1448 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1449 | |
92f2584a JB |
1450 | val = I915_READ(PCH_DREF_CONTROL); |
1451 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1452 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1453 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1454 | } |
1455 | ||
ab9412ba DV |
1456 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1457 | enum pipe pipe) | |
92f2584a JB |
1458 | { |
1459 | int reg; | |
1460 | u32 val; | |
1461 | bool enabled; | |
1462 | ||
ab9412ba | 1463 | reg = PCH_TRANSCONF(pipe); |
92f2584a JB |
1464 | val = I915_READ(reg); |
1465 | enabled = !!(val & TRANS_ENABLE); | |
e2c719b7 | 1466 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1467 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1468 | pipe_name(pipe)); | |
92f2584a JB |
1469 | } |
1470 | ||
4e634389 KP |
1471 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1472 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1473 | { |
1474 | if ((val & DP_PORT_EN) == 0) | |
1475 | return false; | |
1476 | ||
1477 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1478 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); | |
1479 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); | |
1480 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1481 | return false; | |
44f37d1f CML |
1482 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1483 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1484 | return false; | |
f0575e92 KP |
1485 | } else { |
1486 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1487 | return false; | |
1488 | } | |
1489 | return true; | |
1490 | } | |
1491 | ||
1519b995 KP |
1492 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1493 | enum pipe pipe, u32 val) | |
1494 | { | |
dc0fa718 | 1495 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1496 | return false; |
1497 | ||
1498 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1499 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1500 | return false; |
44f37d1f CML |
1501 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1502 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1503 | return false; | |
1519b995 | 1504 | } else { |
dc0fa718 | 1505 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1506 | return false; |
1507 | } | |
1508 | return true; | |
1509 | } | |
1510 | ||
1511 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1512 | enum pipe pipe, u32 val) | |
1513 | { | |
1514 | if ((val & LVDS_PORT_EN) == 0) | |
1515 | return false; | |
1516 | ||
1517 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1518 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1519 | return false; | |
1520 | } else { | |
1521 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1522 | return false; | |
1523 | } | |
1524 | return true; | |
1525 | } | |
1526 | ||
1527 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1528 | enum pipe pipe, u32 val) | |
1529 | { | |
1530 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1531 | return false; | |
1532 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1533 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1534 | return false; | |
1535 | } else { | |
1536 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1537 | return false; | |
1538 | } | |
1539 | return true; | |
1540 | } | |
1541 | ||
291906f1 | 1542 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0575e92 | 1543 | enum pipe pipe, int reg, u32 port_sel) |
291906f1 | 1544 | { |
47a05eca | 1545 | u32 val = I915_READ(reg); |
e2c719b7 | 1546 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1547 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1548 | reg, pipe_name(pipe)); |
de9a35ab | 1549 | |
e2c719b7 | 1550 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1551 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1552 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1553 | } |
1554 | ||
1555 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1556 | enum pipe pipe, int reg) | |
1557 | { | |
47a05eca | 1558 | u32 val = I915_READ(reg); |
e2c719b7 | 1559 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1560 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1561 | reg, pipe_name(pipe)); |
de9a35ab | 1562 | |
e2c719b7 | 1563 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1564 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1565 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1566 | } |
1567 | ||
1568 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1569 | enum pipe pipe) | |
1570 | { | |
1571 | int reg; | |
1572 | u32 val; | |
291906f1 | 1573 | |
f0575e92 KP |
1574 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1575 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1576 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 JB |
1577 | |
1578 | reg = PCH_ADPA; | |
1579 | val = I915_READ(reg); | |
e2c719b7 | 1580 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1581 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1582 | pipe_name(pipe)); |
291906f1 JB |
1583 | |
1584 | reg = PCH_LVDS; | |
1585 | val = I915_READ(reg); | |
e2c719b7 | 1586 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1587 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1588 | pipe_name(pipe)); |
291906f1 | 1589 | |
e2debe91 PZ |
1590 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1591 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1592 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1593 | } |
1594 | ||
40e9cf64 JB |
1595 | static void intel_init_dpio(struct drm_device *dev) |
1596 | { | |
1597 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1598 | ||
1599 | if (!IS_VALLEYVIEW(dev)) | |
1600 | return; | |
1601 | ||
a09caddd CML |
1602 | /* |
1603 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), | |
1604 | * CHV x1 PHY (DP/HDMI D) | |
1605 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) | |
1606 | */ | |
1607 | if (IS_CHERRYVIEW(dev)) { | |
1608 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; | |
1609 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; | |
1610 | } else { | |
1611 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; | |
1612 | } | |
5382f5f3 JB |
1613 | } |
1614 | ||
d288f65f | 1615 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1616 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1617 | { |
426115cf DV |
1618 | struct drm_device *dev = crtc->base.dev; |
1619 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1620 | int reg = DPLL(crtc->pipe); | |
d288f65f | 1621 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1622 | |
426115cf | 1623 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 DV |
1624 | |
1625 | /* No really, not for ILK+ */ | |
1626 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); | |
1627 | ||
1628 | /* PLL is protected by panel, make sure we can write it */ | |
6a9e7363 | 1629 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1630 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1631 | |
426115cf DV |
1632 | I915_WRITE(reg, dpll); |
1633 | POSTING_READ(reg); | |
1634 | udelay(150); | |
1635 | ||
1636 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1637 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1638 | ||
d288f65f | 1639 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1640 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1641 | |
1642 | /* We do this three times for luck */ | |
426115cf | 1643 | I915_WRITE(reg, dpll); |
87442f73 DV |
1644 | POSTING_READ(reg); |
1645 | udelay(150); /* wait for warmup */ | |
426115cf | 1646 | I915_WRITE(reg, dpll); |
87442f73 DV |
1647 | POSTING_READ(reg); |
1648 | udelay(150); /* wait for warmup */ | |
426115cf | 1649 | I915_WRITE(reg, dpll); |
87442f73 DV |
1650 | POSTING_READ(reg); |
1651 | udelay(150); /* wait for warmup */ | |
1652 | } | |
1653 | ||
d288f65f | 1654 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1655 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1656 | { |
1657 | struct drm_device *dev = crtc->base.dev; | |
1658 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1659 | int pipe = crtc->pipe; | |
1660 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1661 | u32 tmp; |
1662 | ||
1663 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1664 | ||
1665 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); | |
1666 | ||
a580516d | 1667 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1668 | |
1669 | /* Enable back the 10bit clock to display controller */ | |
1670 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1671 | tmp |= DPIO_DCLKP_EN; | |
1672 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1673 | ||
54433e91 VS |
1674 | mutex_unlock(&dev_priv->sb_lock); |
1675 | ||
9d556c99 CML |
1676 | /* |
1677 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1678 | */ | |
1679 | udelay(1); | |
1680 | ||
1681 | /* Enable PLL */ | |
d288f65f | 1682 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1683 | |
1684 | /* Check PLL is locked */ | |
a11b0703 | 1685 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1686 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1687 | ||
a11b0703 | 1688 | /* not sure when this should be written */ |
d288f65f | 1689 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 | 1690 | POSTING_READ(DPLL_MD(pipe)); |
9d556c99 CML |
1691 | } |
1692 | ||
1c4e0274 VS |
1693 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1694 | { | |
1695 | struct intel_crtc *crtc; | |
1696 | int count = 0; | |
1697 | ||
1698 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1699 | count += crtc->base.state->active && |
409ee761 | 1700 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1701 | |
1702 | return count; | |
1703 | } | |
1704 | ||
66e3d5c0 | 1705 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1706 | { |
66e3d5c0 DV |
1707 | struct drm_device *dev = crtc->base.dev; |
1708 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1709 | int reg = DPLL(crtc->pipe); | |
6e3c9717 | 1710 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1711 | |
66e3d5c0 | 1712 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1713 | |
63d7bbe9 | 1714 | /* No really, not for ILK+ */ |
3d13ef2e | 1715 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1716 | |
1717 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1718 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1719 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1720 | |
1c4e0274 VS |
1721 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1722 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1723 | /* | |
1724 | * It appears to be important that we don't enable this | |
1725 | * for the current pipe before otherwise configuring the | |
1726 | * PLL. No idea how this should be handled if multiple | |
1727 | * DVO outputs are enabled simultaneosly. | |
1728 | */ | |
1729 | dpll |= DPLL_DVO_2X_MODE; | |
1730 | I915_WRITE(DPLL(!crtc->pipe), | |
1731 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1732 | } | |
66e3d5c0 DV |
1733 | |
1734 | /* Wait for the clocks to stabilize. */ | |
1735 | POSTING_READ(reg); | |
1736 | udelay(150); | |
1737 | ||
1738 | if (INTEL_INFO(dev)->gen >= 4) { | |
1739 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1740 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1741 | } else { |
1742 | /* The pixel multiplier can only be updated once the | |
1743 | * DPLL is enabled and the clocks are stable. | |
1744 | * | |
1745 | * So write it again. | |
1746 | */ | |
1747 | I915_WRITE(reg, dpll); | |
1748 | } | |
63d7bbe9 JB |
1749 | |
1750 | /* We do this three times for luck */ | |
66e3d5c0 | 1751 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1752 | POSTING_READ(reg); |
1753 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1754 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1755 | POSTING_READ(reg); |
1756 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1757 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1758 | POSTING_READ(reg); |
1759 | udelay(150); /* wait for warmup */ | |
1760 | } | |
1761 | ||
1762 | /** | |
50b44a44 | 1763 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1764 | * @dev_priv: i915 private structure |
1765 | * @pipe: pipe PLL to disable | |
1766 | * | |
1767 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1768 | * | |
1769 | * Note! This is for pre-ILK only. | |
1770 | */ | |
1c4e0274 | 1771 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1772 | { |
1c4e0274 VS |
1773 | struct drm_device *dev = crtc->base.dev; |
1774 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1775 | enum pipe pipe = crtc->pipe; | |
1776 | ||
1777 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1778 | if (IS_I830(dev) && | |
409ee761 | 1779 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1780 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1781 | I915_WRITE(DPLL(PIPE_B), |
1782 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1783 | I915_WRITE(DPLL(PIPE_A), | |
1784 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1785 | } | |
1786 | ||
b6b5d049 VS |
1787 | /* Don't disable pipe or pipe PLLs if needed */ |
1788 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1789 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1790 | return; |
1791 | ||
1792 | /* Make sure the pipe isn't still relying on us */ | |
1793 | assert_pipe_disabled(dev_priv, pipe); | |
1794 | ||
50b44a44 DV |
1795 | I915_WRITE(DPLL(pipe), 0); |
1796 | POSTING_READ(DPLL(pipe)); | |
63d7bbe9 JB |
1797 | } |
1798 | ||
f6071166 JB |
1799 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1800 | { | |
1801 | u32 val = 0; | |
1802 | ||
1803 | /* Make sure the pipe isn't still relying on us */ | |
1804 | assert_pipe_disabled(dev_priv, pipe); | |
1805 | ||
e5cbfbfb ID |
1806 | /* |
1807 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1808 | * The latter is needed for VGA hotplug / manual detection. | |
1809 | */ | |
f6071166 | 1810 | if (pipe == PIPE_B) |
e5cbfbfb | 1811 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
f6071166 JB |
1812 | I915_WRITE(DPLL(pipe), val); |
1813 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1814 | |
1815 | } | |
1816 | ||
1817 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1818 | { | |
d752048d | 1819 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1820 | u32 val; |
1821 | ||
a11b0703 VS |
1822 | /* Make sure the pipe isn't still relying on us */ |
1823 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1824 | |
a11b0703 | 1825 | /* Set PLL en = 0 */ |
d17ec4ce | 1826 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
a11b0703 VS |
1827 | if (pipe != PIPE_A) |
1828 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1829 | I915_WRITE(DPLL(pipe), val); | |
1830 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1831 | |
a580516d | 1832 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1833 | |
1834 | /* Disable 10bit clock to display controller */ | |
1835 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1836 | val &= ~DPIO_DCLKP_EN; | |
1837 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1838 | ||
61407f6d VS |
1839 | /* disable left/right clock distribution */ |
1840 | if (pipe != PIPE_B) { | |
1841 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); | |
1842 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); | |
1843 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); | |
1844 | } else { | |
1845 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); | |
1846 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); | |
1847 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); | |
1848 | } | |
1849 | ||
a580516d | 1850 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1851 | } |
1852 | ||
e4607fcf | 1853 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1854 | struct intel_digital_port *dport, |
1855 | unsigned int expected_mask) | |
89b667f8 JB |
1856 | { |
1857 | u32 port_mask; | |
00fc31b7 | 1858 | int dpll_reg; |
89b667f8 | 1859 | |
e4607fcf CML |
1860 | switch (dport->port) { |
1861 | case PORT_B: | |
89b667f8 | 1862 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1863 | dpll_reg = DPLL(0); |
e4607fcf CML |
1864 | break; |
1865 | case PORT_C: | |
89b667f8 | 1866 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1867 | dpll_reg = DPLL(0); |
9b6de0a1 | 1868 | expected_mask <<= 4; |
00fc31b7 CML |
1869 | break; |
1870 | case PORT_D: | |
1871 | port_mask = DPLL_PORTD_READY_MASK; | |
1872 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1873 | break; |
1874 | default: | |
1875 | BUG(); | |
1876 | } | |
89b667f8 | 1877 | |
9b6de0a1 VS |
1878 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1879 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1880 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1881 | } |
1882 | ||
b14b1055 DV |
1883 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1884 | { | |
1885 | struct drm_device *dev = crtc->base.dev; | |
1886 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1887 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1888 | ||
be19f0ff CW |
1889 | if (WARN_ON(pll == NULL)) |
1890 | return; | |
1891 | ||
3e369b76 | 1892 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1893 | if (pll->active == 0) { |
1894 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1895 | WARN_ON(pll->on); | |
1896 | assert_shared_dpll_disabled(dev_priv, pll); | |
1897 | ||
1898 | pll->mode_set(dev_priv, pll); | |
1899 | } | |
1900 | } | |
1901 | ||
92f2584a | 1902 | /** |
85b3894f | 1903 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1904 | * @dev_priv: i915 private structure |
1905 | * @pipe: pipe PLL to enable | |
1906 | * | |
1907 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1908 | * drives the transcoder clock. | |
1909 | */ | |
85b3894f | 1910 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1911 | { |
3d13ef2e DL |
1912 | struct drm_device *dev = crtc->base.dev; |
1913 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1914 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1915 | |
87a875bb | 1916 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1917 | return; |
1918 | ||
3e369b76 | 1919 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1920 | return; |
ee7b9f93 | 1921 | |
74dd6928 | 1922 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1923 | pll->name, pll->active, pll->on, |
e2b78267 | 1924 | crtc->base.base.id); |
92f2584a | 1925 | |
cdbd2316 DV |
1926 | if (pll->active++) { |
1927 | WARN_ON(!pll->on); | |
e9d6944e | 1928 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1929 | return; |
1930 | } | |
f4a091c7 | 1931 | WARN_ON(pll->on); |
ee7b9f93 | 1932 | |
bd2bb1b9 PZ |
1933 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1934 | ||
46edb027 | 1935 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1936 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1937 | pll->on = true; |
92f2584a JB |
1938 | } |
1939 | ||
f6daaec2 | 1940 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1941 | { |
3d13ef2e DL |
1942 | struct drm_device *dev = crtc->base.dev; |
1943 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1944 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1945 | |
92f2584a | 1946 | /* PCH only available on ILK+ */ |
3d13ef2e | 1947 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
87a875bb | 1948 | if (WARN_ON(pll == NULL)) |
ee7b9f93 | 1949 | return; |
92f2584a | 1950 | |
3e369b76 | 1951 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1952 | return; |
7a419866 | 1953 | |
46edb027 DV |
1954 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1955 | pll->name, pll->active, pll->on, | |
e2b78267 | 1956 | crtc->base.base.id); |
7a419866 | 1957 | |
48da64a8 | 1958 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1959 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1960 | return; |
1961 | } | |
1962 | ||
e9d6944e | 1963 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1964 | WARN_ON(!pll->on); |
cdbd2316 | 1965 | if (--pll->active) |
7a419866 | 1966 | return; |
ee7b9f93 | 1967 | |
46edb027 | 1968 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1969 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1970 | pll->on = false; |
bd2bb1b9 PZ |
1971 | |
1972 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1973 | } |
1974 | ||
b8a4f404 PZ |
1975 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1976 | enum pipe pipe) | |
040484af | 1977 | { |
23670b32 | 1978 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1979 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1980 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
23670b32 | 1981 | uint32_t reg, val, pipeconf_val; |
040484af JB |
1982 | |
1983 | /* PCH only available on ILK+ */ | |
55522f37 | 1984 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1985 | |
1986 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1987 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1988 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1989 | |
1990 | /* FDI must be feeding us bits for PCH ports */ | |
1991 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1992 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1993 | ||
23670b32 DV |
1994 | if (HAS_PCH_CPT(dev)) { |
1995 | /* Workaround: Set the timing override bit before enabling the | |
1996 | * pch transcoder. */ | |
1997 | reg = TRANS_CHICKEN2(pipe); | |
1998 | val = I915_READ(reg); | |
1999 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2000 | I915_WRITE(reg, val); | |
59c859d6 | 2001 | } |
23670b32 | 2002 | |
ab9412ba | 2003 | reg = PCH_TRANSCONF(pipe); |
040484af | 2004 | val = I915_READ(reg); |
5f7f726d | 2005 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
2006 | |
2007 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
2008 | /* | |
c5de7c6f VS |
2009 | * Make the BPC in transcoder be consistent with |
2010 | * that in pipeconf reg. For HDMI we must use 8bpc | |
2011 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 2012 | */ |
dfd07d72 | 2013 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
2014 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
2015 | val |= PIPECONF_8BPC; | |
2016 | else | |
2017 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 2018 | } |
5f7f726d PZ |
2019 | |
2020 | val &= ~TRANS_INTERLACE_MASK; | |
2021 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 2022 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 2023 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
2024 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2025 | else | |
2026 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2027 | else |
2028 | val |= TRANS_PROGRESSIVE; | |
2029 | ||
040484af JB |
2030 | I915_WRITE(reg, val | TRANS_ENABLE); |
2031 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2032 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2033 | } |
2034 | ||
8fb033d7 | 2035 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2036 | enum transcoder cpu_transcoder) |
040484af | 2037 | { |
8fb033d7 | 2038 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2039 | |
2040 | /* PCH only available on ILK+ */ | |
55522f37 | 2041 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2042 | |
8fb033d7 | 2043 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2044 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2045 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2046 | |
223a6fdf PZ |
2047 | /* Workaround: set timing override bit. */ |
2048 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2049 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf PZ |
2050 | I915_WRITE(_TRANSA_CHICKEN2, val); |
2051 | ||
25f3ef11 | 2052 | val = TRANS_ENABLE; |
937bb610 | 2053 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2054 | |
9a76b1c6 PZ |
2055 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2056 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2057 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2058 | else |
2059 | val |= TRANS_PROGRESSIVE; | |
2060 | ||
ab9412ba DV |
2061 | I915_WRITE(LPT_TRANSCONF, val); |
2062 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2063 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2064 | } |
2065 | ||
b8a4f404 PZ |
2066 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2067 | enum pipe pipe) | |
040484af | 2068 | { |
23670b32 DV |
2069 | struct drm_device *dev = dev_priv->dev; |
2070 | uint32_t reg, val; | |
040484af JB |
2071 | |
2072 | /* FDI relies on the transcoder */ | |
2073 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2074 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2075 | ||
291906f1 JB |
2076 | /* Ports must be off as well */ |
2077 | assert_pch_ports_disabled(dev_priv, pipe); | |
2078 | ||
ab9412ba | 2079 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2080 | val = I915_READ(reg); |
2081 | val &= ~TRANS_ENABLE; | |
2082 | I915_WRITE(reg, val); | |
2083 | /* wait for PCH transcoder off, transcoder state */ | |
2084 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2085 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 DV |
2086 | |
2087 | if (!HAS_PCH_IBX(dev)) { | |
2088 | /* Workaround: Clear the timing override chicken bit again. */ | |
2089 | reg = TRANS_CHICKEN2(pipe); | |
2090 | val = I915_READ(reg); | |
2091 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2092 | I915_WRITE(reg, val); | |
2093 | } | |
040484af JB |
2094 | } |
2095 | ||
ab4d966c | 2096 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2097 | { |
8fb033d7 PZ |
2098 | u32 val; |
2099 | ||
ab9412ba | 2100 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2101 | val &= ~TRANS_ENABLE; |
ab9412ba | 2102 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2103 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2104 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2105 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2106 | |
2107 | /* Workaround: clear timing override bit. */ | |
2108 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2109 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf | 2110 | I915_WRITE(_TRANSA_CHICKEN2, val); |
040484af JB |
2111 | } |
2112 | ||
b24e7179 | 2113 | /** |
309cfea8 | 2114 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2115 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2116 | * |
0372264a | 2117 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2118 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2119 | */ |
e1fdc473 | 2120 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2121 | { |
0372264a PZ |
2122 | struct drm_device *dev = crtc->base.dev; |
2123 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2124 | enum pipe pipe = crtc->pipe; | |
702e7a56 PZ |
2125 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
2126 | pipe); | |
1a240d4d | 2127 | enum pipe pch_transcoder; |
b24e7179 JB |
2128 | int reg; |
2129 | u32 val; | |
2130 | ||
58c6eaa2 | 2131 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2132 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2133 | assert_sprites_disabled(dev_priv, pipe); |
2134 | ||
681e5811 | 2135 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2136 | pch_transcoder = TRANSCODER_A; |
2137 | else | |
2138 | pch_transcoder = pipe; | |
2139 | ||
b24e7179 JB |
2140 | /* |
2141 | * A pipe without a PLL won't actually be able to drive bits from | |
2142 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2143 | * need the check. | |
2144 | */ | |
50360403 | 2145 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
409ee761 | 2146 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
2147 | assert_dsi_pll_enabled(dev_priv); |
2148 | else | |
2149 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2150 | else { |
6e3c9717 | 2151 | if (crtc->config->has_pch_encoder) { |
040484af | 2152 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2153 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2154 | assert_fdi_tx_pll_enabled(dev_priv, |
2155 | (enum pipe) cpu_transcoder); | |
040484af JB |
2156 | } |
2157 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2158 | } | |
b24e7179 | 2159 | |
702e7a56 | 2160 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2161 | val = I915_READ(reg); |
7ad25d48 | 2162 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2163 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2164 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2165 | return; |
7ad25d48 | 2166 | } |
00d70b15 CW |
2167 | |
2168 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2169 | POSTING_READ(reg); |
b24e7179 JB |
2170 | } |
2171 | ||
2172 | /** | |
309cfea8 | 2173 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2174 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2175 | * |
575f7ab7 VS |
2176 | * Disable the pipe of @crtc, making sure that various hardware |
2177 | * specific requirements are met, if applicable, e.g. plane | |
2178 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2179 | * |
2180 | * Will wait until the pipe has shut down before returning. | |
2181 | */ | |
575f7ab7 | 2182 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2183 | { |
575f7ab7 | 2184 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2185 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2186 | enum pipe pipe = crtc->pipe; |
b24e7179 JB |
2187 | int reg; |
2188 | u32 val; | |
2189 | ||
2190 | /* | |
2191 | * Make sure planes won't keep trying to pump pixels to us, | |
2192 | * or we might hang the display. | |
2193 | */ | |
2194 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2195 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2196 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2197 | |
702e7a56 | 2198 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2199 | val = I915_READ(reg); |
00d70b15 CW |
2200 | if ((val & PIPECONF_ENABLE) == 0) |
2201 | return; | |
2202 | ||
67adc644 VS |
2203 | /* |
2204 | * Double wide has implications for planes | |
2205 | * so best keep it disabled when not needed. | |
2206 | */ | |
6e3c9717 | 2207 | if (crtc->config->double_wide) |
67adc644 VS |
2208 | val &= ~PIPECONF_DOUBLE_WIDE; |
2209 | ||
2210 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2211 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2212 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2213 | val &= ~PIPECONF_ENABLE; |
2214 | ||
2215 | I915_WRITE(reg, val); | |
2216 | if ((val & PIPECONF_ENABLE) == 0) | |
2217 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2218 | } |
2219 | ||
2220 | /** | |
262ca2b0 | 2221 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
fdd508a6 VS |
2222 | * @plane: plane to be enabled |
2223 | * @crtc: crtc for the plane | |
b24e7179 | 2224 | * |
fdd508a6 | 2225 | * Enable @plane on @crtc, making sure that the pipe is running first. |
b24e7179 | 2226 | */ |
fdd508a6 VS |
2227 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
2228 | struct drm_crtc *crtc) | |
b24e7179 | 2229 | { |
fdd508a6 VS |
2230 | struct drm_device *dev = plane->dev; |
2231 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2232 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b24e7179 JB |
2233 | |
2234 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ | |
fdd508a6 | 2235 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
b70709a6 | 2236 | to_intel_plane_state(plane->state)->visible = true; |
939c2fe8 | 2237 | |
fdd508a6 VS |
2238 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
2239 | crtc->x, crtc->y); | |
b24e7179 JB |
2240 | } |
2241 | ||
693db184 CW |
2242 | static bool need_vtd_wa(struct drm_device *dev) |
2243 | { | |
2244 | #ifdef CONFIG_INTEL_IOMMU | |
2245 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2246 | return true; | |
2247 | #endif | |
2248 | return false; | |
2249 | } | |
2250 | ||
50470bb0 | 2251 | unsigned int |
6761dd31 TU |
2252 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
2253 | uint64_t fb_format_modifier) | |
a57ce0b2 | 2254 | { |
6761dd31 TU |
2255 | unsigned int tile_height; |
2256 | uint32_t pixel_bytes; | |
a57ce0b2 | 2257 | |
b5d0e9bf DL |
2258 | switch (fb_format_modifier) { |
2259 | case DRM_FORMAT_MOD_NONE: | |
2260 | tile_height = 1; | |
2261 | break; | |
2262 | case I915_FORMAT_MOD_X_TILED: | |
2263 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2264 | break; | |
2265 | case I915_FORMAT_MOD_Y_TILED: | |
2266 | tile_height = 32; | |
2267 | break; | |
2268 | case I915_FORMAT_MOD_Yf_TILED: | |
6761dd31 TU |
2269 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
2270 | switch (pixel_bytes) { | |
b5d0e9bf | 2271 | default: |
6761dd31 | 2272 | case 1: |
b5d0e9bf DL |
2273 | tile_height = 64; |
2274 | break; | |
6761dd31 TU |
2275 | case 2: |
2276 | case 4: | |
b5d0e9bf DL |
2277 | tile_height = 32; |
2278 | break; | |
6761dd31 | 2279 | case 8: |
b5d0e9bf DL |
2280 | tile_height = 16; |
2281 | break; | |
6761dd31 | 2282 | case 16: |
b5d0e9bf DL |
2283 | WARN_ONCE(1, |
2284 | "128-bit pixels are not supported for display!"); | |
2285 | tile_height = 16; | |
2286 | break; | |
2287 | } | |
2288 | break; | |
2289 | default: | |
2290 | MISSING_CASE(fb_format_modifier); | |
2291 | tile_height = 1; | |
2292 | break; | |
2293 | } | |
091df6cb | 2294 | |
6761dd31 TU |
2295 | return tile_height; |
2296 | } | |
2297 | ||
2298 | unsigned int | |
2299 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2300 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2301 | { | |
2302 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
2303 | fb_format_modifier)); | |
a57ce0b2 JB |
2304 | } |
2305 | ||
f64b98cd TU |
2306 | static int |
2307 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, | |
2308 | const struct drm_plane_state *plane_state) | |
2309 | { | |
50470bb0 | 2310 | struct intel_rotation_info *info = &view->rotation_info; |
50470bb0 | 2311 | |
f64b98cd TU |
2312 | *view = i915_ggtt_view_normal; |
2313 | ||
50470bb0 TU |
2314 | if (!plane_state) |
2315 | return 0; | |
2316 | ||
121920fa | 2317 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
50470bb0 TU |
2318 | return 0; |
2319 | ||
9abc4648 | 2320 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2321 | |
2322 | info->height = fb->height; | |
2323 | info->pixel_format = fb->pixel_format; | |
2324 | info->pitch = fb->pitches[0]; | |
2325 | info->fb_modifier = fb->modifier[0]; | |
2326 | ||
f64b98cd TU |
2327 | return 0; |
2328 | } | |
2329 | ||
4e9a86b6 VS |
2330 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
2331 | { | |
2332 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2333 | return 256 * 1024; | |
985b8bb4 VS |
2334 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
2335 | IS_VALLEYVIEW(dev_priv)) | |
4e9a86b6 VS |
2336 | return 128 * 1024; |
2337 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2338 | return 4 * 1024; | |
2339 | else | |
44c5905e | 2340 | return 0; |
4e9a86b6 VS |
2341 | } |
2342 | ||
127bd2ac | 2343 | int |
850c4cdc TU |
2344 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2345 | struct drm_framebuffer *fb, | |
82bc3b2d | 2346 | const struct drm_plane_state *plane_state, |
a4872ba6 | 2347 | struct intel_engine_cs *pipelined) |
6b95a207 | 2348 | { |
850c4cdc | 2349 | struct drm_device *dev = fb->dev; |
ce453d81 | 2350 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2351 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2352 | struct i915_ggtt_view view; |
6b95a207 KH |
2353 | u32 alignment; |
2354 | int ret; | |
2355 | ||
ebcdd39e MR |
2356 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2357 | ||
7b911adc TU |
2358 | switch (fb->modifier[0]) { |
2359 | case DRM_FORMAT_MOD_NONE: | |
4e9a86b6 | 2360 | alignment = intel_linear_alignment(dev_priv); |
6b95a207 | 2361 | break; |
7b911adc | 2362 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2363 | if (INTEL_INFO(dev)->gen >= 9) |
2364 | alignment = 256 * 1024; | |
2365 | else { | |
2366 | /* pin() will align the object as required by fence */ | |
2367 | alignment = 0; | |
2368 | } | |
6b95a207 | 2369 | break; |
7b911adc | 2370 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2371 | case I915_FORMAT_MOD_Yf_TILED: |
2372 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2373 | "Y tiling bo slipped through, driver bug!\n")) | |
2374 | return -EINVAL; | |
2375 | alignment = 1 * 1024 * 1024; | |
2376 | break; | |
6b95a207 | 2377 | default: |
7b911adc TU |
2378 | MISSING_CASE(fb->modifier[0]); |
2379 | return -EINVAL; | |
6b95a207 KH |
2380 | } |
2381 | ||
f64b98cd TU |
2382 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2383 | if (ret) | |
2384 | return ret; | |
2385 | ||
693db184 CW |
2386 | /* Note that the w/a also requires 64 PTE of padding following the |
2387 | * bo. We currently fill all unused PTE with the shadow page and so | |
2388 | * we should always have valid PTE following the scanout preventing | |
2389 | * the VT-d warning. | |
2390 | */ | |
2391 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2392 | alignment = 256 * 1024; | |
2393 | ||
d6dd6843 PZ |
2394 | /* |
2395 | * Global gtt pte registers are special registers which actually forward | |
2396 | * writes to a chunk of system memory. Which means that there is no risk | |
2397 | * that the register values disappear as soon as we call | |
2398 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2399 | * pin/unpin/fence and not more. | |
2400 | */ | |
2401 | intel_runtime_pm_get(dev_priv); | |
2402 | ||
ce453d81 | 2403 | dev_priv->mm.interruptible = false; |
e6617330 | 2404 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
f64b98cd | 2405 | &view); |
48b956c5 | 2406 | if (ret) |
ce453d81 | 2407 | goto err_interruptible; |
6b95a207 KH |
2408 | |
2409 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2410 | * fence, whereas 965+ only requires a fence if using | |
2411 | * framebuffer compression. For simplicity, we always install | |
2412 | * a fence as the cost is not that onerous. | |
2413 | */ | |
06d98131 | 2414 | ret = i915_gem_object_get_fence(obj); |
9a5a53b3 CW |
2415 | if (ret) |
2416 | goto err_unpin; | |
1690e1eb | 2417 | |
9a5a53b3 | 2418 | i915_gem_object_pin_fence(obj); |
6b95a207 | 2419 | |
ce453d81 | 2420 | dev_priv->mm.interruptible = true; |
d6dd6843 | 2421 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2422 | return 0; |
48b956c5 CW |
2423 | |
2424 | err_unpin: | |
f64b98cd | 2425 | i915_gem_object_unpin_from_display_plane(obj, &view); |
ce453d81 CW |
2426 | err_interruptible: |
2427 | dev_priv->mm.interruptible = true; | |
d6dd6843 | 2428 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2429 | return ret; |
6b95a207 KH |
2430 | } |
2431 | ||
82bc3b2d TU |
2432 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2433 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2434 | { |
82bc3b2d | 2435 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd TU |
2436 | struct i915_ggtt_view view; |
2437 | int ret; | |
82bc3b2d | 2438 | |
ebcdd39e MR |
2439 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2440 | ||
f64b98cd TU |
2441 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2442 | WARN_ONCE(ret, "Couldn't get view from plane state!"); | |
2443 | ||
1690e1eb | 2444 | i915_gem_object_unpin_fence(obj); |
f64b98cd | 2445 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2446 | } |
2447 | ||
c2c75131 DV |
2448 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2449 | * is assumed to be a power-of-two. */ | |
4e9a86b6 VS |
2450 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
2451 | int *x, int *y, | |
bc752862 CW |
2452 | unsigned int tiling_mode, |
2453 | unsigned int cpp, | |
2454 | unsigned int pitch) | |
c2c75131 | 2455 | { |
bc752862 CW |
2456 | if (tiling_mode != I915_TILING_NONE) { |
2457 | unsigned int tile_rows, tiles; | |
c2c75131 | 2458 | |
bc752862 CW |
2459 | tile_rows = *y / 8; |
2460 | *y %= 8; | |
c2c75131 | 2461 | |
bc752862 CW |
2462 | tiles = *x / (512/cpp); |
2463 | *x %= 512/cpp; | |
2464 | ||
2465 | return tile_rows * pitch * 8 + tiles * 4096; | |
2466 | } else { | |
4e9a86b6 | 2467 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
bc752862 CW |
2468 | unsigned int offset; |
2469 | ||
2470 | offset = *y * pitch + *x * cpp; | |
4e9a86b6 VS |
2471 | *y = (offset & alignment) / pitch; |
2472 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2473 | return offset & ~alignment; | |
bc752862 | 2474 | } |
c2c75131 DV |
2475 | } |
2476 | ||
b35d63fa | 2477 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2478 | { |
2479 | switch (format) { | |
2480 | case DISPPLANE_8BPP: | |
2481 | return DRM_FORMAT_C8; | |
2482 | case DISPPLANE_BGRX555: | |
2483 | return DRM_FORMAT_XRGB1555; | |
2484 | case DISPPLANE_BGRX565: | |
2485 | return DRM_FORMAT_RGB565; | |
2486 | default: | |
2487 | case DISPPLANE_BGRX888: | |
2488 | return DRM_FORMAT_XRGB8888; | |
2489 | case DISPPLANE_RGBX888: | |
2490 | return DRM_FORMAT_XBGR8888; | |
2491 | case DISPPLANE_BGRX101010: | |
2492 | return DRM_FORMAT_XRGB2101010; | |
2493 | case DISPPLANE_RGBX101010: | |
2494 | return DRM_FORMAT_XBGR2101010; | |
2495 | } | |
2496 | } | |
2497 | ||
bc8d7dff DL |
2498 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2499 | { | |
2500 | switch (format) { | |
2501 | case PLANE_CTL_FORMAT_RGB_565: | |
2502 | return DRM_FORMAT_RGB565; | |
2503 | default: | |
2504 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2505 | if (rgb_order) { | |
2506 | if (alpha) | |
2507 | return DRM_FORMAT_ABGR8888; | |
2508 | else | |
2509 | return DRM_FORMAT_XBGR8888; | |
2510 | } else { | |
2511 | if (alpha) | |
2512 | return DRM_FORMAT_ARGB8888; | |
2513 | else | |
2514 | return DRM_FORMAT_XRGB8888; | |
2515 | } | |
2516 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2517 | if (rgb_order) | |
2518 | return DRM_FORMAT_XBGR2101010; | |
2519 | else | |
2520 | return DRM_FORMAT_XRGB2101010; | |
2521 | } | |
2522 | } | |
2523 | ||
5724dbd1 | 2524 | static bool |
f6936e29 DV |
2525 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2526 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2527 | { |
2528 | struct drm_device *dev = crtc->base.dev; | |
2529 | struct drm_i915_gem_object *obj = NULL; | |
2530 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2531 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2532 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2533 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2534 | PAGE_SIZE); | |
2535 | ||
2536 | size_aligned -= base_aligned; | |
46f297fb | 2537 | |
ff2652ea CW |
2538 | if (plane_config->size == 0) |
2539 | return false; | |
2540 | ||
f37b5c2b DV |
2541 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2542 | base_aligned, | |
2543 | base_aligned, | |
2544 | size_aligned); | |
46f297fb | 2545 | if (!obj) |
484b41dd | 2546 | return false; |
46f297fb | 2547 | |
49af449b DL |
2548 | obj->tiling_mode = plane_config->tiling; |
2549 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2550 | obj->stride = fb->pitches[0]; |
46f297fb | 2551 | |
6bf129df DL |
2552 | mode_cmd.pixel_format = fb->pixel_format; |
2553 | mode_cmd.width = fb->width; | |
2554 | mode_cmd.height = fb->height; | |
2555 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2556 | mode_cmd.modifier[0] = fb->modifier[0]; |
2557 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2558 | |
2559 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2560 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2561 | &mode_cmd, obj)) { |
46f297fb JB |
2562 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2563 | goto out_unref_obj; | |
2564 | } | |
46f297fb | 2565 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2566 | |
f6936e29 | 2567 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2568 | return true; |
46f297fb JB |
2569 | |
2570 | out_unref_obj: | |
2571 | drm_gem_object_unreference(&obj->base); | |
2572 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2573 | return false; |
2574 | } | |
2575 | ||
afd65eb4 MR |
2576 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2577 | static void | |
2578 | update_state_fb(struct drm_plane *plane) | |
2579 | { | |
2580 | if (plane->fb == plane->state->fb) | |
2581 | return; | |
2582 | ||
2583 | if (plane->state->fb) | |
2584 | drm_framebuffer_unreference(plane->state->fb); | |
2585 | plane->state->fb = plane->fb; | |
2586 | if (plane->state->fb) | |
2587 | drm_framebuffer_reference(plane->state->fb); | |
2588 | } | |
2589 | ||
5724dbd1 | 2590 | static void |
f6936e29 DV |
2591 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2592 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2593 | { |
2594 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2595 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2596 | struct drm_crtc *c; |
2597 | struct intel_crtc *i; | |
2ff8fde1 | 2598 | struct drm_i915_gem_object *obj; |
88595ac9 DV |
2599 | struct drm_plane *primary = intel_crtc->base.primary; |
2600 | struct drm_framebuffer *fb; | |
484b41dd | 2601 | |
2d14030b | 2602 | if (!plane_config->fb) |
484b41dd JB |
2603 | return; |
2604 | ||
f6936e29 | 2605 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2606 | fb = &plane_config->fb->base; |
2607 | goto valid_fb; | |
f55548b5 | 2608 | } |
484b41dd | 2609 | |
2d14030b | 2610 | kfree(plane_config->fb); |
484b41dd JB |
2611 | |
2612 | /* | |
2613 | * Failed to alloc the obj, check to see if we should share | |
2614 | * an fb with another CRTC instead | |
2615 | */ | |
70e1e0ec | 2616 | for_each_crtc(dev, c) { |
484b41dd JB |
2617 | i = to_intel_crtc(c); |
2618 | ||
2619 | if (c == &intel_crtc->base) | |
2620 | continue; | |
2621 | ||
2ff8fde1 MR |
2622 | if (!i->active) |
2623 | continue; | |
2624 | ||
88595ac9 DV |
2625 | fb = c->primary->fb; |
2626 | if (!fb) | |
484b41dd JB |
2627 | continue; |
2628 | ||
88595ac9 | 2629 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2630 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2631 | drm_framebuffer_reference(fb); |
2632 | goto valid_fb; | |
484b41dd JB |
2633 | } |
2634 | } | |
88595ac9 DV |
2635 | |
2636 | return; | |
2637 | ||
2638 | valid_fb: | |
2639 | obj = intel_fb_obj(fb); | |
2640 | if (obj->tiling_mode != I915_TILING_NONE) | |
2641 | dev_priv->preserve_bios_swizzle = true; | |
2642 | ||
2643 | primary->fb = fb; | |
36750f28 | 2644 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
88595ac9 | 2645 | update_state_fb(primary); |
36750f28 | 2646 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
88595ac9 | 2647 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
46f297fb JB |
2648 | } |
2649 | ||
29b9bde6 DV |
2650 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2651 | struct drm_framebuffer *fb, | |
2652 | int x, int y) | |
81255565 JB |
2653 | { |
2654 | struct drm_device *dev = crtc->dev; | |
2655 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2656 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2657 | struct drm_plane *primary = crtc->primary; |
2658 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2659 | struct drm_i915_gem_object *obj; |
81255565 | 2660 | int plane = intel_crtc->plane; |
e506a0c6 | 2661 | unsigned long linear_offset; |
81255565 | 2662 | u32 dspcntr; |
f45651ba | 2663 | u32 reg = DSPCNTR(plane); |
48404c1e | 2664 | int pixel_size; |
f45651ba | 2665 | |
b70709a6 | 2666 | if (!visible || !fb) { |
fdd508a6 VS |
2667 | I915_WRITE(reg, 0); |
2668 | if (INTEL_INFO(dev)->gen >= 4) | |
2669 | I915_WRITE(DSPSURF(plane), 0); | |
2670 | else | |
2671 | I915_WRITE(DSPADDR(plane), 0); | |
2672 | POSTING_READ(reg); | |
2673 | return; | |
2674 | } | |
2675 | ||
c9ba6fad VS |
2676 | obj = intel_fb_obj(fb); |
2677 | if (WARN_ON(obj == NULL)) | |
2678 | return; | |
2679 | ||
2680 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2681 | ||
f45651ba VS |
2682 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2683 | ||
fdd508a6 | 2684 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2685 | |
2686 | if (INTEL_INFO(dev)->gen < 4) { | |
2687 | if (intel_crtc->pipe == PIPE_B) | |
2688 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2689 | ||
2690 | /* pipesrc and dspsize control the size that is scaled from, | |
2691 | * which should always be the user's requested size. | |
2692 | */ | |
2693 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2694 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2695 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2696 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2697 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2698 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2699 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2700 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2701 | I915_WRITE(PRIMPOS(plane), 0); |
2702 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2703 | } |
81255565 | 2704 | |
57779d06 VS |
2705 | switch (fb->pixel_format) { |
2706 | case DRM_FORMAT_C8: | |
81255565 JB |
2707 | dspcntr |= DISPPLANE_8BPP; |
2708 | break; | |
57779d06 | 2709 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2710 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2711 | break; |
57779d06 VS |
2712 | case DRM_FORMAT_RGB565: |
2713 | dspcntr |= DISPPLANE_BGRX565; | |
2714 | break; | |
2715 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2716 | dspcntr |= DISPPLANE_BGRX888; |
2717 | break; | |
2718 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2719 | dspcntr |= DISPPLANE_RGBX888; |
2720 | break; | |
2721 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2722 | dspcntr |= DISPPLANE_BGRX101010; |
2723 | break; | |
2724 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2725 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2726 | break; |
2727 | default: | |
baba133a | 2728 | BUG(); |
81255565 | 2729 | } |
57779d06 | 2730 | |
f45651ba VS |
2731 | if (INTEL_INFO(dev)->gen >= 4 && |
2732 | obj->tiling_mode != I915_TILING_NONE) | |
2733 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2734 | |
de1aa629 VS |
2735 | if (IS_G4X(dev)) |
2736 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2737 | ||
b9897127 | 2738 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2739 | |
c2c75131 DV |
2740 | if (INTEL_INFO(dev)->gen >= 4) { |
2741 | intel_crtc->dspaddr_offset = | |
4e9a86b6 VS |
2742 | intel_gen4_compute_page_offset(dev_priv, |
2743 | &x, &y, obj->tiling_mode, | |
b9897127 | 2744 | pixel_size, |
bc752862 | 2745 | fb->pitches[0]); |
c2c75131 DV |
2746 | linear_offset -= intel_crtc->dspaddr_offset; |
2747 | } else { | |
e506a0c6 | 2748 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2749 | } |
e506a0c6 | 2750 | |
8e7d688b | 2751 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2752 | dspcntr |= DISPPLANE_ROTATE_180; |
2753 | ||
6e3c9717 ACO |
2754 | x += (intel_crtc->config->pipe_src_w - 1); |
2755 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2756 | |
2757 | /* Finding the last pixel of the last line of the display | |
2758 | data and adding to linear_offset*/ | |
2759 | linear_offset += | |
6e3c9717 ACO |
2760 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2761 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2762 | } |
2763 | ||
2764 | I915_WRITE(reg, dspcntr); | |
2765 | ||
01f2c773 | 2766 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2767 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2768 | I915_WRITE(DSPSURF(plane), |
2769 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2770 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2771 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2772 | } else |
f343c5f6 | 2773 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2774 | POSTING_READ(reg); |
17638cd6 JB |
2775 | } |
2776 | ||
29b9bde6 DV |
2777 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2778 | struct drm_framebuffer *fb, | |
2779 | int x, int y) | |
17638cd6 JB |
2780 | { |
2781 | struct drm_device *dev = crtc->dev; | |
2782 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2783 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2784 | struct drm_plane *primary = crtc->primary; |
2785 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2786 | struct drm_i915_gem_object *obj; |
17638cd6 | 2787 | int plane = intel_crtc->plane; |
e506a0c6 | 2788 | unsigned long linear_offset; |
17638cd6 | 2789 | u32 dspcntr; |
f45651ba | 2790 | u32 reg = DSPCNTR(plane); |
48404c1e | 2791 | int pixel_size; |
f45651ba | 2792 | |
b70709a6 | 2793 | if (!visible || !fb) { |
fdd508a6 VS |
2794 | I915_WRITE(reg, 0); |
2795 | I915_WRITE(DSPSURF(plane), 0); | |
2796 | POSTING_READ(reg); | |
2797 | return; | |
2798 | } | |
2799 | ||
c9ba6fad VS |
2800 | obj = intel_fb_obj(fb); |
2801 | if (WARN_ON(obj == NULL)) | |
2802 | return; | |
2803 | ||
2804 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2805 | ||
f45651ba VS |
2806 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2807 | ||
fdd508a6 | 2808 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2809 | |
2810 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2811 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2812 | |
57779d06 VS |
2813 | switch (fb->pixel_format) { |
2814 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2815 | dspcntr |= DISPPLANE_8BPP; |
2816 | break; | |
57779d06 VS |
2817 | case DRM_FORMAT_RGB565: |
2818 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2819 | break; |
57779d06 | 2820 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2821 | dspcntr |= DISPPLANE_BGRX888; |
2822 | break; | |
2823 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2824 | dspcntr |= DISPPLANE_RGBX888; |
2825 | break; | |
2826 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2827 | dspcntr |= DISPPLANE_BGRX101010; |
2828 | break; | |
2829 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2830 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2831 | break; |
2832 | default: | |
baba133a | 2833 | BUG(); |
17638cd6 JB |
2834 | } |
2835 | ||
2836 | if (obj->tiling_mode != I915_TILING_NONE) | |
2837 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2838 | |
f45651ba | 2839 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2840 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2841 | |
b9897127 | 2842 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2843 | intel_crtc->dspaddr_offset = |
4e9a86b6 VS |
2844 | intel_gen4_compute_page_offset(dev_priv, |
2845 | &x, &y, obj->tiling_mode, | |
b9897127 | 2846 | pixel_size, |
bc752862 | 2847 | fb->pitches[0]); |
c2c75131 | 2848 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2849 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2850 | dspcntr |= DISPPLANE_ROTATE_180; |
2851 | ||
2852 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2853 | x += (intel_crtc->config->pipe_src_w - 1); |
2854 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2855 | |
2856 | /* Finding the last pixel of the last line of the display | |
2857 | data and adding to linear_offset*/ | |
2858 | linear_offset += | |
6e3c9717 ACO |
2859 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2860 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2861 | } |
2862 | } | |
2863 | ||
2864 | I915_WRITE(reg, dspcntr); | |
17638cd6 | 2865 | |
01f2c773 | 2866 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2867 | I915_WRITE(DSPSURF(plane), |
2868 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2869 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2870 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2871 | } else { | |
2872 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2873 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2874 | } | |
17638cd6 | 2875 | POSTING_READ(reg); |
17638cd6 JB |
2876 | } |
2877 | ||
b321803d DL |
2878 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2879 | uint32_t pixel_format) | |
2880 | { | |
2881 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2882 | ||
2883 | /* | |
2884 | * The stride is either expressed as a multiple of 64 bytes | |
2885 | * chunks for linear buffers or in number of tiles for tiled | |
2886 | * buffers. | |
2887 | */ | |
2888 | switch (fb_modifier) { | |
2889 | case DRM_FORMAT_MOD_NONE: | |
2890 | return 64; | |
2891 | case I915_FORMAT_MOD_X_TILED: | |
2892 | if (INTEL_INFO(dev)->gen == 2) | |
2893 | return 128; | |
2894 | return 512; | |
2895 | case I915_FORMAT_MOD_Y_TILED: | |
2896 | /* No need to check for old gens and Y tiling since this is | |
2897 | * about the display engine and those will be blocked before | |
2898 | * we get here. | |
2899 | */ | |
2900 | return 128; | |
2901 | case I915_FORMAT_MOD_Yf_TILED: | |
2902 | if (bits_per_pixel == 8) | |
2903 | return 64; | |
2904 | else | |
2905 | return 128; | |
2906 | default: | |
2907 | MISSING_CASE(fb_modifier); | |
2908 | return 64; | |
2909 | } | |
2910 | } | |
2911 | ||
121920fa TU |
2912 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
2913 | struct drm_i915_gem_object *obj) | |
2914 | { | |
9abc4648 | 2915 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
121920fa TU |
2916 | |
2917 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) | |
9abc4648 | 2918 | view = &i915_ggtt_view_rotated; |
121920fa TU |
2919 | |
2920 | return i915_gem_obj_ggtt_offset_view(obj, view); | |
2921 | } | |
2922 | ||
a1b2278e CK |
2923 | /* |
2924 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2925 | */ | |
0583236e | 2926 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e CK |
2927 | { |
2928 | struct drm_device *dev; | |
2929 | struct drm_i915_private *dev_priv; | |
2930 | struct intel_crtc_scaler_state *scaler_state; | |
2931 | int i; | |
2932 | ||
a1b2278e CK |
2933 | dev = intel_crtc->base.dev; |
2934 | dev_priv = dev->dev_private; | |
2935 | scaler_state = &intel_crtc->config->scaler_state; | |
2936 | ||
2937 | /* loop through and disable scalers that aren't in use */ | |
2938 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
2939 | if (!scaler_state->scalers[i].in_use) { | |
2940 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, i), 0); | |
2941 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, i), 0); | |
2942 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, i), 0); | |
2943 | DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n", | |
2944 | intel_crtc->base.base.id, intel_crtc->pipe, i); | |
2945 | } | |
2946 | } | |
2947 | } | |
2948 | ||
6156a456 | 2949 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2950 | { |
6156a456 | 2951 | switch (pixel_format) { |
d161cf7a | 2952 | case DRM_FORMAT_C8: |
c34ce3d1 | 2953 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2954 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2955 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2956 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2957 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2958 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2959 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2960 | /* |
2961 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2962 | * to be already pre-multiplied. We need to add a knob (or a different | |
2963 | * DRM_FORMAT) for user-space to configure that. | |
2964 | */ | |
f75fb42a | 2965 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 2966 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 2967 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 2968 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 2969 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 2970 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 2971 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 2972 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 2973 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 2974 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 2975 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 2976 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 2977 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 2978 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 2979 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 2980 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 2981 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 2982 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 2983 | default: |
4249eeef | 2984 | MISSING_CASE(pixel_format); |
70d21f0e | 2985 | } |
8cfcba41 | 2986 | |
c34ce3d1 | 2987 | return 0; |
6156a456 | 2988 | } |
70d21f0e | 2989 | |
6156a456 CK |
2990 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
2991 | { | |
6156a456 | 2992 | switch (fb_modifier) { |
30af77c4 | 2993 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 2994 | break; |
30af77c4 | 2995 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 2996 | return PLANE_CTL_TILED_X; |
b321803d | 2997 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 2998 | return PLANE_CTL_TILED_Y; |
b321803d | 2999 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3000 | return PLANE_CTL_TILED_YF; |
70d21f0e | 3001 | default: |
6156a456 | 3002 | MISSING_CASE(fb_modifier); |
70d21f0e | 3003 | } |
8cfcba41 | 3004 | |
c34ce3d1 | 3005 | return 0; |
6156a456 | 3006 | } |
70d21f0e | 3007 | |
6156a456 CK |
3008 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
3009 | { | |
3b7a5119 | 3010 | switch (rotation) { |
6156a456 CK |
3011 | case BIT(DRM_ROTATE_0): |
3012 | break; | |
1e8df167 SJ |
3013 | /* |
3014 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3015 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3016 | */ | |
3b7a5119 | 3017 | case BIT(DRM_ROTATE_90): |
1e8df167 | 3018 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 3019 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3020 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3021 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3022 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3023 | default: |
3024 | MISSING_CASE(rotation); | |
3025 | } | |
3026 | ||
c34ce3d1 | 3027 | return 0; |
6156a456 CK |
3028 | } |
3029 | ||
3030 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
3031 | struct drm_framebuffer *fb, | |
3032 | int x, int y) | |
3033 | { | |
3034 | struct drm_device *dev = crtc->dev; | |
3035 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3036 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3037 | struct drm_plane *plane = crtc->primary; |
3038 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3039 | struct drm_i915_gem_object *obj; |
3040 | int pipe = intel_crtc->pipe; | |
3041 | u32 plane_ctl, stride_div, stride; | |
3042 | u32 tile_height, plane_offset, plane_size; | |
3043 | unsigned int rotation; | |
3044 | int x_offset, y_offset; | |
3045 | unsigned long surf_addr; | |
6156a456 CK |
3046 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3047 | struct intel_plane_state *plane_state; | |
3048 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3049 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3050 | int scaler_id = -1; | |
3051 | ||
6156a456 CK |
3052 | plane_state = to_intel_plane_state(plane->state); |
3053 | ||
b70709a6 | 3054 | if (!visible || !fb) { |
6156a456 CK |
3055 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3056 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3057 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3058 | return; | |
3b7a5119 | 3059 | } |
70d21f0e | 3060 | |
6156a456 CK |
3061 | plane_ctl = PLANE_CTL_ENABLE | |
3062 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3063 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3064 | ||
3065 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3066 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3067 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3068 | ||
3069 | rotation = plane->state->rotation; | |
3070 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3071 | ||
b321803d DL |
3072 | obj = intel_fb_obj(fb); |
3073 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3074 | fb->pixel_format); | |
3b7a5119 SJ |
3075 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
3076 | ||
6156a456 CK |
3077 | /* |
3078 | * FIXME: intel_plane_state->src, dst aren't set when transitional | |
3079 | * update_plane helpers are called from legacy paths. | |
3080 | * Once full atomic crtc is available, below check can be avoided. | |
3081 | */ | |
3082 | if (drm_rect_width(&plane_state->src)) { | |
3083 | scaler_id = plane_state->scaler_id; | |
3084 | src_x = plane_state->src.x1 >> 16; | |
3085 | src_y = plane_state->src.y1 >> 16; | |
3086 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3087 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3088 | dst_x = plane_state->dst.x1; | |
3089 | dst_y = plane_state->dst.y1; | |
3090 | dst_w = drm_rect_width(&plane_state->dst); | |
3091 | dst_h = drm_rect_height(&plane_state->dst); | |
3092 | ||
3093 | WARN_ON(x != src_x || y != src_y); | |
3094 | } else { | |
3095 | src_w = intel_crtc->config->pipe_src_w; | |
3096 | src_h = intel_crtc->config->pipe_src_h; | |
3097 | } | |
3098 | ||
3b7a5119 SJ |
3099 | if (intel_rotation_90_or_270(rotation)) { |
3100 | /* stride = Surface height in tiles */ | |
2614f17d | 3101 | tile_height = intel_tile_height(dev, fb->pixel_format, |
3b7a5119 SJ |
3102 | fb->modifier[0]); |
3103 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
6156a456 | 3104 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3105 | y_offset = x; |
6156a456 | 3106 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3107 | } else { |
3108 | stride = fb->pitches[0] / stride_div; | |
3109 | x_offset = x; | |
3110 | y_offset = y; | |
6156a456 | 3111 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3112 | } |
3113 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3114 | |
70d21f0e | 3115 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3116 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3117 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3118 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3119 | |
3120 | if (scaler_id >= 0) { | |
3121 | uint32_t ps_ctrl = 0; | |
3122 | ||
3123 | WARN_ON(!dst_w || !dst_h); | |
3124 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3125 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3126 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3127 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3128 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3129 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3130 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3131 | } else { | |
3132 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3133 | } | |
3134 | ||
121920fa | 3135 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3136 | |
3137 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3138 | } | |
3139 | ||
17638cd6 JB |
3140 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3141 | static int | |
3142 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3143 | int x, int y, enum mode_set_atomic state) | |
3144 | { | |
3145 | struct drm_device *dev = crtc->dev; | |
3146 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3147 | |
6b8e6ed0 CW |
3148 | if (dev_priv->display.disable_fbc) |
3149 | dev_priv->display.disable_fbc(dev); | |
81255565 | 3150 | |
29b9bde6 DV |
3151 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3152 | ||
3153 | return 0; | |
81255565 JB |
3154 | } |
3155 | ||
7514747d | 3156 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3157 | { |
96a02917 VS |
3158 | struct drm_crtc *crtc; |
3159 | ||
70e1e0ec | 3160 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3161 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3162 | enum plane plane = intel_crtc->plane; | |
3163 | ||
3164 | intel_prepare_page_flip(dev, plane); | |
3165 | intel_finish_page_flip_plane(dev, plane); | |
3166 | } | |
7514747d VS |
3167 | } |
3168 | ||
3169 | static void intel_update_primary_planes(struct drm_device *dev) | |
3170 | { | |
3171 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3172 | struct drm_crtc *crtc; | |
96a02917 | 3173 | |
70e1e0ec | 3174 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3175 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3176 | ||
51fd371b | 3177 | drm_modeset_lock(&crtc->mutex, NULL); |
947fdaad CW |
3178 | /* |
3179 | * FIXME: Once we have proper support for primary planes (and | |
3180 | * disabling them without disabling the entire crtc) allow again | |
66e514c1 | 3181 | * a NULL crtc->primary->fb. |
947fdaad | 3182 | */ |
f4510a27 | 3183 | if (intel_crtc->active && crtc->primary->fb) |
262ca2b0 | 3184 | dev_priv->display.update_primary_plane(crtc, |
66e514c1 | 3185 | crtc->primary->fb, |
262ca2b0 MR |
3186 | crtc->x, |
3187 | crtc->y); | |
51fd371b | 3188 | drm_modeset_unlock(&crtc->mutex); |
96a02917 VS |
3189 | } |
3190 | } | |
3191 | ||
7514747d VS |
3192 | void intel_prepare_reset(struct drm_device *dev) |
3193 | { | |
3194 | /* no reset support for gen2 */ | |
3195 | if (IS_GEN2(dev)) | |
3196 | return; | |
3197 | ||
3198 | /* reset doesn't touch the display */ | |
3199 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3200 | return; | |
3201 | ||
3202 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3203 | /* |
3204 | * Disabling the crtcs gracefully seems nicer. Also the | |
3205 | * g33 docs say we should at least disable all the planes. | |
3206 | */ | |
6b72d486 | 3207 | intel_display_suspend(dev); |
7514747d VS |
3208 | } |
3209 | ||
3210 | void intel_finish_reset(struct drm_device *dev) | |
3211 | { | |
3212 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3213 | ||
3214 | /* | |
3215 | * Flips in the rings will be nuked by the reset, | |
3216 | * so complete all pending flips so that user space | |
3217 | * will get its events and not get stuck. | |
3218 | */ | |
3219 | intel_complete_page_flips(dev); | |
3220 | ||
3221 | /* no reset support for gen2 */ | |
3222 | if (IS_GEN2(dev)) | |
3223 | return; | |
3224 | ||
3225 | /* reset doesn't touch the display */ | |
3226 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3227 | /* | |
3228 | * Flips in the rings have been nuked by the reset, | |
3229 | * so update the base address of all primary | |
3230 | * planes to the the last fb to make sure we're | |
3231 | * showing the correct fb after a reset. | |
3232 | */ | |
3233 | intel_update_primary_planes(dev); | |
3234 | return; | |
3235 | } | |
3236 | ||
3237 | /* | |
3238 | * The display has been reset as well, | |
3239 | * so need a full re-initialization. | |
3240 | */ | |
3241 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3242 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3243 | ||
3244 | intel_modeset_init_hw(dev); | |
3245 | ||
3246 | spin_lock_irq(&dev_priv->irq_lock); | |
3247 | if (dev_priv->display.hpd_irq_setup) | |
3248 | dev_priv->display.hpd_irq_setup(dev); | |
3249 | spin_unlock_irq(&dev_priv->irq_lock); | |
3250 | ||
3251 | intel_modeset_setup_hw_state(dev, true); | |
3252 | ||
3253 | intel_hpd_init(dev_priv); | |
3254 | ||
3255 | drm_modeset_unlock_all(dev); | |
3256 | } | |
3257 | ||
2e2f351d | 3258 | static void |
14667a4b CW |
3259 | intel_finish_fb(struct drm_framebuffer *old_fb) |
3260 | { | |
2ff8fde1 | 3261 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
2e2f351d | 3262 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
14667a4b CW |
3263 | bool was_interruptible = dev_priv->mm.interruptible; |
3264 | int ret; | |
3265 | ||
14667a4b CW |
3266 | /* Big Hammer, we also need to ensure that any pending |
3267 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
3268 | * current scanout is retired before unpinning the old | |
2e2f351d CW |
3269 | * framebuffer. Note that we rely on userspace rendering |
3270 | * into the buffer attached to the pipe they are waiting | |
3271 | * on. If not, userspace generates a GPU hang with IPEHR | |
3272 | * point to the MI_WAIT_FOR_EVENT. | |
14667a4b CW |
3273 | * |
3274 | * This should only fail upon a hung GPU, in which case we | |
3275 | * can safely continue. | |
3276 | */ | |
3277 | dev_priv->mm.interruptible = false; | |
2e2f351d | 3278 | ret = i915_gem_object_wait_rendering(obj, true); |
14667a4b CW |
3279 | dev_priv->mm.interruptible = was_interruptible; |
3280 | ||
2e2f351d | 3281 | WARN_ON(ret); |
14667a4b CW |
3282 | } |
3283 | ||
7d5e3799 CW |
3284 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3285 | { | |
3286 | struct drm_device *dev = crtc->dev; | |
3287 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3288 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3289 | bool pending; |
3290 | ||
3291 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3292 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3293 | return false; | |
3294 | ||
5e2d7afc | 3295 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3296 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3297 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3298 | |
3299 | return pending; | |
3300 | } | |
3301 | ||
e30e8f75 GP |
3302 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
3303 | { | |
3304 | struct drm_device *dev = crtc->base.dev; | |
3305 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3306 | const struct drm_display_mode *adjusted_mode; | |
3307 | ||
3308 | if (!i915.fastboot) | |
3309 | return; | |
3310 | ||
3311 | /* | |
3312 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3313 | * that in compute_mode_changes we check the native mode (not the pfit | |
3314 | * mode) to see if we can flip rather than do a full mode set. In the | |
3315 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3316 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3317 | * sized surface. | |
3318 | * | |
3319 | * To fix this properly, we need to hoist the checks up into | |
3320 | * compute_mode_changes (or above), check the actual pfit state and | |
3321 | * whether the platform allows pfit disable with pipe active, and only | |
3322 | * then update the pipesrc and pfit state, even on the flip path. | |
3323 | */ | |
3324 | ||
6e3c9717 | 3325 | adjusted_mode = &crtc->config->base.adjusted_mode; |
e30e8f75 GP |
3326 | |
3327 | I915_WRITE(PIPESRC(crtc->pipe), | |
3328 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | | |
3329 | (adjusted_mode->crtc_vdisplay - 1)); | |
6e3c9717 | 3330 | if (!crtc->config->pch_pfit.enabled && |
409ee761 ACO |
3331 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
3332 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { | |
e30e8f75 GP |
3333 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
3334 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); | |
3335 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); | |
3336 | } | |
6e3c9717 ACO |
3337 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
3338 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; | |
e30e8f75 GP |
3339 | } |
3340 | ||
5e84e1a4 ZW |
3341 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3342 | { | |
3343 | struct drm_device *dev = crtc->dev; | |
3344 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3345 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3346 | int pipe = intel_crtc->pipe; | |
3347 | u32 reg, temp; | |
3348 | ||
3349 | /* enable normal train */ | |
3350 | reg = FDI_TX_CTL(pipe); | |
3351 | temp = I915_READ(reg); | |
61e499bf | 3352 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3353 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3354 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3355 | } else { |
3356 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3357 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3358 | } |
5e84e1a4 ZW |
3359 | I915_WRITE(reg, temp); |
3360 | ||
3361 | reg = FDI_RX_CTL(pipe); | |
3362 | temp = I915_READ(reg); | |
3363 | if (HAS_PCH_CPT(dev)) { | |
3364 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3365 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3366 | } else { | |
3367 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3368 | temp |= FDI_LINK_TRAIN_NONE; | |
3369 | } | |
3370 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3371 | ||
3372 | /* wait one idle pattern time */ | |
3373 | POSTING_READ(reg); | |
3374 | udelay(1000); | |
357555c0 JB |
3375 | |
3376 | /* IVB wants error correction enabled */ | |
3377 | if (IS_IVYBRIDGE(dev)) | |
3378 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3379 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3380 | } |
3381 | ||
8db9d77b ZW |
3382 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3383 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3384 | { | |
3385 | struct drm_device *dev = crtc->dev; | |
3386 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3387 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3388 | int pipe = intel_crtc->pipe; | |
5eddb70b | 3389 | u32 reg, temp, tries; |
8db9d77b | 3390 | |
1c8562f6 | 3391 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3392 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3393 | |
e1a44743 AJ |
3394 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3395 | for train result */ | |
5eddb70b CW |
3396 | reg = FDI_RX_IMR(pipe); |
3397 | temp = I915_READ(reg); | |
e1a44743 AJ |
3398 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3399 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3400 | I915_WRITE(reg, temp); |
3401 | I915_READ(reg); | |
e1a44743 AJ |
3402 | udelay(150); |
3403 | ||
8db9d77b | 3404 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3405 | reg = FDI_TX_CTL(pipe); |
3406 | temp = I915_READ(reg); | |
627eb5a3 | 3407 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3408 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3409 | temp &= ~FDI_LINK_TRAIN_NONE; |
3410 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3411 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3412 | |
5eddb70b CW |
3413 | reg = FDI_RX_CTL(pipe); |
3414 | temp = I915_READ(reg); | |
8db9d77b ZW |
3415 | temp &= ~FDI_LINK_TRAIN_NONE; |
3416 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3417 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3418 | ||
3419 | POSTING_READ(reg); | |
8db9d77b ZW |
3420 | udelay(150); |
3421 | ||
5b2adf89 | 3422 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3423 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3424 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3425 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3426 | |
5eddb70b | 3427 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3428 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3429 | temp = I915_READ(reg); |
8db9d77b ZW |
3430 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3431 | ||
3432 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3433 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3434 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3435 | break; |
3436 | } | |
8db9d77b | 3437 | } |
e1a44743 | 3438 | if (tries == 5) |
5eddb70b | 3439 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3440 | |
3441 | /* Train 2 */ | |
5eddb70b CW |
3442 | reg = FDI_TX_CTL(pipe); |
3443 | temp = I915_READ(reg); | |
8db9d77b ZW |
3444 | temp &= ~FDI_LINK_TRAIN_NONE; |
3445 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3446 | I915_WRITE(reg, temp); |
8db9d77b | 3447 | |
5eddb70b CW |
3448 | reg = FDI_RX_CTL(pipe); |
3449 | temp = I915_READ(reg); | |
8db9d77b ZW |
3450 | temp &= ~FDI_LINK_TRAIN_NONE; |
3451 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3452 | I915_WRITE(reg, temp); |
8db9d77b | 3453 | |
5eddb70b CW |
3454 | POSTING_READ(reg); |
3455 | udelay(150); | |
8db9d77b | 3456 | |
5eddb70b | 3457 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3458 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3459 | temp = I915_READ(reg); |
8db9d77b ZW |
3460 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3461 | ||
3462 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3463 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3464 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3465 | break; | |
3466 | } | |
8db9d77b | 3467 | } |
e1a44743 | 3468 | if (tries == 5) |
5eddb70b | 3469 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3470 | |
3471 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3472 | |
8db9d77b ZW |
3473 | } |
3474 | ||
0206e353 | 3475 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3476 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3477 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3478 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3479 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3480 | }; | |
3481 | ||
3482 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3483 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3484 | { | |
3485 | struct drm_device *dev = crtc->dev; | |
3486 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3487 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3488 | int pipe = intel_crtc->pipe; | |
fa37d39e | 3489 | u32 reg, temp, i, retry; |
8db9d77b | 3490 | |
e1a44743 AJ |
3491 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3492 | for train result */ | |
5eddb70b CW |
3493 | reg = FDI_RX_IMR(pipe); |
3494 | temp = I915_READ(reg); | |
e1a44743 AJ |
3495 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3496 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3497 | I915_WRITE(reg, temp); |
3498 | ||
3499 | POSTING_READ(reg); | |
e1a44743 AJ |
3500 | udelay(150); |
3501 | ||
8db9d77b | 3502 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3503 | reg = FDI_TX_CTL(pipe); |
3504 | temp = I915_READ(reg); | |
627eb5a3 | 3505 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3506 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3507 | temp &= ~FDI_LINK_TRAIN_NONE; |
3508 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3509 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3510 | /* SNB-B */ | |
3511 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3512 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3513 | |
d74cf324 DV |
3514 | I915_WRITE(FDI_RX_MISC(pipe), |
3515 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3516 | ||
5eddb70b CW |
3517 | reg = FDI_RX_CTL(pipe); |
3518 | temp = I915_READ(reg); | |
8db9d77b ZW |
3519 | if (HAS_PCH_CPT(dev)) { |
3520 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3521 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3522 | } else { | |
3523 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3524 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3525 | } | |
5eddb70b CW |
3526 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3527 | ||
3528 | POSTING_READ(reg); | |
8db9d77b ZW |
3529 | udelay(150); |
3530 | ||
0206e353 | 3531 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3532 | reg = FDI_TX_CTL(pipe); |
3533 | temp = I915_READ(reg); | |
8db9d77b ZW |
3534 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3535 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3536 | I915_WRITE(reg, temp); |
3537 | ||
3538 | POSTING_READ(reg); | |
8db9d77b ZW |
3539 | udelay(500); |
3540 | ||
fa37d39e SP |
3541 | for (retry = 0; retry < 5; retry++) { |
3542 | reg = FDI_RX_IIR(pipe); | |
3543 | temp = I915_READ(reg); | |
3544 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3545 | if (temp & FDI_RX_BIT_LOCK) { | |
3546 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3547 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3548 | break; | |
3549 | } | |
3550 | udelay(50); | |
8db9d77b | 3551 | } |
fa37d39e SP |
3552 | if (retry < 5) |
3553 | break; | |
8db9d77b ZW |
3554 | } |
3555 | if (i == 4) | |
5eddb70b | 3556 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3557 | |
3558 | /* Train 2 */ | |
5eddb70b CW |
3559 | reg = FDI_TX_CTL(pipe); |
3560 | temp = I915_READ(reg); | |
8db9d77b ZW |
3561 | temp &= ~FDI_LINK_TRAIN_NONE; |
3562 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3563 | if (IS_GEN6(dev)) { | |
3564 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3565 | /* SNB-B */ | |
3566 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3567 | } | |
5eddb70b | 3568 | I915_WRITE(reg, temp); |
8db9d77b | 3569 | |
5eddb70b CW |
3570 | reg = FDI_RX_CTL(pipe); |
3571 | temp = I915_READ(reg); | |
8db9d77b ZW |
3572 | if (HAS_PCH_CPT(dev)) { |
3573 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3574 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3575 | } else { | |
3576 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3577 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3578 | } | |
5eddb70b CW |
3579 | I915_WRITE(reg, temp); |
3580 | ||
3581 | POSTING_READ(reg); | |
8db9d77b ZW |
3582 | udelay(150); |
3583 | ||
0206e353 | 3584 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3585 | reg = FDI_TX_CTL(pipe); |
3586 | temp = I915_READ(reg); | |
8db9d77b ZW |
3587 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3588 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3589 | I915_WRITE(reg, temp); |
3590 | ||
3591 | POSTING_READ(reg); | |
8db9d77b ZW |
3592 | udelay(500); |
3593 | ||
fa37d39e SP |
3594 | for (retry = 0; retry < 5; retry++) { |
3595 | reg = FDI_RX_IIR(pipe); | |
3596 | temp = I915_READ(reg); | |
3597 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3598 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3599 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3600 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3601 | break; | |
3602 | } | |
3603 | udelay(50); | |
8db9d77b | 3604 | } |
fa37d39e SP |
3605 | if (retry < 5) |
3606 | break; | |
8db9d77b ZW |
3607 | } |
3608 | if (i == 4) | |
5eddb70b | 3609 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3610 | |
3611 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3612 | } | |
3613 | ||
357555c0 JB |
3614 | /* Manual link training for Ivy Bridge A0 parts */ |
3615 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3616 | { | |
3617 | struct drm_device *dev = crtc->dev; | |
3618 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3619 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3620 | int pipe = intel_crtc->pipe; | |
139ccd3f | 3621 | u32 reg, temp, i, j; |
357555c0 JB |
3622 | |
3623 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3624 | for train result */ | |
3625 | reg = FDI_RX_IMR(pipe); | |
3626 | temp = I915_READ(reg); | |
3627 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3628 | temp &= ~FDI_RX_BIT_LOCK; | |
3629 | I915_WRITE(reg, temp); | |
3630 | ||
3631 | POSTING_READ(reg); | |
3632 | udelay(150); | |
3633 | ||
01a415fd DV |
3634 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3635 | I915_READ(FDI_RX_IIR(pipe))); | |
3636 | ||
139ccd3f JB |
3637 | /* Try each vswing and preemphasis setting twice before moving on */ |
3638 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3639 | /* disable first in case we need to retry */ | |
3640 | reg = FDI_TX_CTL(pipe); | |
3641 | temp = I915_READ(reg); | |
3642 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3643 | temp &= ~FDI_TX_ENABLE; | |
3644 | I915_WRITE(reg, temp); | |
357555c0 | 3645 | |
139ccd3f JB |
3646 | reg = FDI_RX_CTL(pipe); |
3647 | temp = I915_READ(reg); | |
3648 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3649 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3650 | temp &= ~FDI_RX_ENABLE; | |
3651 | I915_WRITE(reg, temp); | |
357555c0 | 3652 | |
139ccd3f | 3653 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3654 | reg = FDI_TX_CTL(pipe); |
3655 | temp = I915_READ(reg); | |
139ccd3f | 3656 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3657 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3658 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3659 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3660 | temp |= snb_b_fdi_train_param[j/2]; |
3661 | temp |= FDI_COMPOSITE_SYNC; | |
3662 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3663 | |
139ccd3f JB |
3664 | I915_WRITE(FDI_RX_MISC(pipe), |
3665 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3666 | |
139ccd3f | 3667 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3668 | temp = I915_READ(reg); |
139ccd3f JB |
3669 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3670 | temp |= FDI_COMPOSITE_SYNC; | |
3671 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3672 | |
139ccd3f JB |
3673 | POSTING_READ(reg); |
3674 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3675 | |
139ccd3f JB |
3676 | for (i = 0; i < 4; i++) { |
3677 | reg = FDI_RX_IIR(pipe); | |
3678 | temp = I915_READ(reg); | |
3679 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3680 | |
139ccd3f JB |
3681 | if (temp & FDI_RX_BIT_LOCK || |
3682 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3683 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3684 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3685 | i); | |
3686 | break; | |
3687 | } | |
3688 | udelay(1); /* should be 0.5us */ | |
3689 | } | |
3690 | if (i == 4) { | |
3691 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3692 | continue; | |
3693 | } | |
357555c0 | 3694 | |
139ccd3f | 3695 | /* Train 2 */ |
357555c0 JB |
3696 | reg = FDI_TX_CTL(pipe); |
3697 | temp = I915_READ(reg); | |
139ccd3f JB |
3698 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3699 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3700 | I915_WRITE(reg, temp); | |
3701 | ||
3702 | reg = FDI_RX_CTL(pipe); | |
3703 | temp = I915_READ(reg); | |
3704 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3705 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3706 | I915_WRITE(reg, temp); |
3707 | ||
3708 | POSTING_READ(reg); | |
139ccd3f | 3709 | udelay(2); /* should be 1.5us */ |
357555c0 | 3710 | |
139ccd3f JB |
3711 | for (i = 0; i < 4; i++) { |
3712 | reg = FDI_RX_IIR(pipe); | |
3713 | temp = I915_READ(reg); | |
3714 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3715 | |
139ccd3f JB |
3716 | if (temp & FDI_RX_SYMBOL_LOCK || |
3717 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3718 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3719 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3720 | i); | |
3721 | goto train_done; | |
3722 | } | |
3723 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3724 | } |
139ccd3f JB |
3725 | if (i == 4) |
3726 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3727 | } |
357555c0 | 3728 | |
139ccd3f | 3729 | train_done: |
357555c0 JB |
3730 | DRM_DEBUG_KMS("FDI train done.\n"); |
3731 | } | |
3732 | ||
88cefb6c | 3733 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3734 | { |
88cefb6c | 3735 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3736 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3737 | int pipe = intel_crtc->pipe; |
5eddb70b | 3738 | u32 reg, temp; |
79e53945 | 3739 | |
c64e311e | 3740 | |
c98e9dcf | 3741 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3742 | reg = FDI_RX_CTL(pipe); |
3743 | temp = I915_READ(reg); | |
627eb5a3 | 3744 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3745 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3746 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3747 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3748 | ||
3749 | POSTING_READ(reg); | |
c98e9dcf JB |
3750 | udelay(200); |
3751 | ||
3752 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3753 | temp = I915_READ(reg); |
3754 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3755 | ||
3756 | POSTING_READ(reg); | |
c98e9dcf JB |
3757 | udelay(200); |
3758 | ||
20749730 PZ |
3759 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3760 | reg = FDI_TX_CTL(pipe); | |
3761 | temp = I915_READ(reg); | |
3762 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3763 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3764 | |
20749730 PZ |
3765 | POSTING_READ(reg); |
3766 | udelay(100); | |
6be4a607 | 3767 | } |
0e23b99d JB |
3768 | } |
3769 | ||
88cefb6c DV |
3770 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3771 | { | |
3772 | struct drm_device *dev = intel_crtc->base.dev; | |
3773 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3774 | int pipe = intel_crtc->pipe; | |
3775 | u32 reg, temp; | |
3776 | ||
3777 | /* Switch from PCDclk to Rawclk */ | |
3778 | reg = FDI_RX_CTL(pipe); | |
3779 | temp = I915_READ(reg); | |
3780 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3781 | ||
3782 | /* Disable CPU FDI TX PLL */ | |
3783 | reg = FDI_TX_CTL(pipe); | |
3784 | temp = I915_READ(reg); | |
3785 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3786 | ||
3787 | POSTING_READ(reg); | |
3788 | udelay(100); | |
3789 | ||
3790 | reg = FDI_RX_CTL(pipe); | |
3791 | temp = I915_READ(reg); | |
3792 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3793 | ||
3794 | /* Wait for the clocks to turn off. */ | |
3795 | POSTING_READ(reg); | |
3796 | udelay(100); | |
3797 | } | |
3798 | ||
0fc932b8 JB |
3799 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3800 | { | |
3801 | struct drm_device *dev = crtc->dev; | |
3802 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3803 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3804 | int pipe = intel_crtc->pipe; | |
3805 | u32 reg, temp; | |
3806 | ||
3807 | /* disable CPU FDI tx and PCH FDI rx */ | |
3808 | reg = FDI_TX_CTL(pipe); | |
3809 | temp = I915_READ(reg); | |
3810 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3811 | POSTING_READ(reg); | |
3812 | ||
3813 | reg = FDI_RX_CTL(pipe); | |
3814 | temp = I915_READ(reg); | |
3815 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3816 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3817 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3818 | ||
3819 | POSTING_READ(reg); | |
3820 | udelay(100); | |
3821 | ||
3822 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3823 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3824 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3825 | |
3826 | /* still set train pattern 1 */ | |
3827 | reg = FDI_TX_CTL(pipe); | |
3828 | temp = I915_READ(reg); | |
3829 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3830 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3831 | I915_WRITE(reg, temp); | |
3832 | ||
3833 | reg = FDI_RX_CTL(pipe); | |
3834 | temp = I915_READ(reg); | |
3835 | if (HAS_PCH_CPT(dev)) { | |
3836 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3837 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3838 | } else { | |
3839 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3840 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3841 | } | |
3842 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3843 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3844 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3845 | I915_WRITE(reg, temp); |
3846 | ||
3847 | POSTING_READ(reg); | |
3848 | udelay(100); | |
3849 | } | |
3850 | ||
5dce5b93 CW |
3851 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3852 | { | |
3853 | struct intel_crtc *crtc; | |
3854 | ||
3855 | /* Note that we don't need to be called with mode_config.lock here | |
3856 | * as our list of CRTC objects is static for the lifetime of the | |
3857 | * device and so cannot disappear as we iterate. Similarly, we can | |
3858 | * happily treat the predicates as racy, atomic checks as userspace | |
3859 | * cannot claim and pin a new fb without at least acquring the | |
3860 | * struct_mutex and so serialising with us. | |
3861 | */ | |
d3fcc808 | 3862 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3863 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3864 | continue; | |
3865 | ||
3866 | if (crtc->unpin_work) | |
3867 | intel_wait_for_vblank(dev, crtc->pipe); | |
3868 | ||
3869 | return true; | |
3870 | } | |
3871 | ||
3872 | return false; | |
3873 | } | |
3874 | ||
d6bbafa1 CW |
3875 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3876 | { | |
3877 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3878 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3879 | ||
3880 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3881 | smp_rmb(); | |
3882 | intel_crtc->unpin_work = NULL; | |
3883 | ||
3884 | if (work->event) | |
3885 | drm_send_vblank_event(intel_crtc->base.dev, | |
3886 | intel_crtc->pipe, | |
3887 | work->event); | |
3888 | ||
3889 | drm_crtc_vblank_put(&intel_crtc->base); | |
3890 | ||
3891 | wake_up_all(&dev_priv->pending_flip_queue); | |
3892 | queue_work(dev_priv->wq, &work->work); | |
3893 | ||
3894 | trace_i915_flip_complete(intel_crtc->plane, | |
3895 | work->pending_flip_obj); | |
3896 | } | |
3897 | ||
46a55d30 | 3898 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3899 | { |
0f91128d | 3900 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3901 | struct drm_i915_private *dev_priv = dev->dev_private; |
e6c3a2a6 | 3902 | |
2c10d571 | 3903 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
9c787942 CW |
3904 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
3905 | !intel_crtc_has_pending_flip(crtc), | |
3906 | 60*HZ) == 0)) { | |
3907 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2c10d571 | 3908 | |
5e2d7afc | 3909 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3910 | if (intel_crtc->unpin_work) { |
3911 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3912 | page_flip_completed(intel_crtc); | |
3913 | } | |
5e2d7afc | 3914 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3915 | } |
5bb61643 | 3916 | |
975d568a CW |
3917 | if (crtc->primary->fb) { |
3918 | mutex_lock(&dev->struct_mutex); | |
3919 | intel_finish_fb(crtc->primary->fb); | |
3920 | mutex_unlock(&dev->struct_mutex); | |
3921 | } | |
e6c3a2a6 CW |
3922 | } |
3923 | ||
e615efe4 ED |
3924 | /* Program iCLKIP clock to the desired frequency */ |
3925 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3926 | { | |
3927 | struct drm_device *dev = crtc->dev; | |
3928 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3929 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3930 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3931 | u32 temp; | |
3932 | ||
a580516d | 3933 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 3934 | |
e615efe4 ED |
3935 | /* It is necessary to ungate the pixclk gate prior to programming |
3936 | * the divisors, and gate it back when it is done. | |
3937 | */ | |
3938 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3939 | ||
3940 | /* Disable SSCCTL */ | |
3941 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3942 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3943 | SBI_SSCCTL_DISABLE, | |
3944 | SBI_ICLK); | |
e615efe4 ED |
3945 | |
3946 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3947 | if (clock == 20000) { |
e615efe4 ED |
3948 | auxdiv = 1; |
3949 | divsel = 0x41; | |
3950 | phaseinc = 0x20; | |
3951 | } else { | |
3952 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3953 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3954 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3955 | * convert the virtual clock precision to KHz here for higher |
3956 | * precision. | |
3957 | */ | |
3958 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3959 | u32 iclk_pi_range = 64; | |
3960 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3961 | ||
12d7ceed | 3962 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3963 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3964 | pi_value = desired_divisor % iclk_pi_range; | |
3965 | ||
3966 | auxdiv = 0; | |
3967 | divsel = msb_divisor_value - 2; | |
3968 | phaseinc = pi_value; | |
3969 | } | |
3970 | ||
3971 | /* This should not happen with any sane values */ | |
3972 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3973 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3974 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3975 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3976 | ||
3977 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3978 | clock, |
e615efe4 ED |
3979 | auxdiv, |
3980 | divsel, | |
3981 | phasedir, | |
3982 | phaseinc); | |
3983 | ||
3984 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 3985 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
3986 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
3987 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
3988 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
3989 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
3990 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
3991 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 3992 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
3993 | |
3994 | /* Program SSCAUXDIV */ | |
988d6ee8 | 3995 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
3996 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
3997 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 3998 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
3999 | |
4000 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4001 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4002 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4003 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
4004 | |
4005 | /* Wait for initialization time */ | |
4006 | udelay(24); | |
4007 | ||
4008 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 | 4009 | |
a580516d | 4010 | mutex_unlock(&dev_priv->sb_lock); |
e615efe4 ED |
4011 | } |
4012 | ||
275f01b2 DV |
4013 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4014 | enum pipe pch_transcoder) | |
4015 | { | |
4016 | struct drm_device *dev = crtc->base.dev; | |
4017 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4018 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4019 | |
4020 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4021 | I915_READ(HTOTAL(cpu_transcoder))); | |
4022 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4023 | I915_READ(HBLANK(cpu_transcoder))); | |
4024 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4025 | I915_READ(HSYNC(cpu_transcoder))); | |
4026 | ||
4027 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4028 | I915_READ(VTOTAL(cpu_transcoder))); | |
4029 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4030 | I915_READ(VBLANK(cpu_transcoder))); | |
4031 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4032 | I915_READ(VSYNC(cpu_transcoder))); | |
4033 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4034 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4035 | } | |
4036 | ||
003632d9 | 4037 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4038 | { |
4039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4040 | uint32_t temp; | |
4041 | ||
4042 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4043 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4044 | return; |
4045 | ||
4046 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4047 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4048 | ||
003632d9 ACO |
4049 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4050 | if (enable) | |
4051 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4052 | ||
4053 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4054 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4055 | POSTING_READ(SOUTH_CHICKEN1); | |
4056 | } | |
4057 | ||
4058 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4059 | { | |
4060 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4061 | |
4062 | switch (intel_crtc->pipe) { | |
4063 | case PIPE_A: | |
4064 | break; | |
4065 | case PIPE_B: | |
6e3c9717 | 4066 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4067 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4068 | else |
003632d9 | 4069 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4070 | |
4071 | break; | |
4072 | case PIPE_C: | |
003632d9 | 4073 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4074 | |
4075 | break; | |
4076 | default: | |
4077 | BUG(); | |
4078 | } | |
4079 | } | |
4080 | ||
f67a559d JB |
4081 | /* |
4082 | * Enable PCH resources required for PCH ports: | |
4083 | * - PCH PLLs | |
4084 | * - FDI training & RX/TX | |
4085 | * - update transcoder timings | |
4086 | * - DP transcoding bits | |
4087 | * - transcoder | |
4088 | */ | |
4089 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4090 | { |
4091 | struct drm_device *dev = crtc->dev; | |
4092 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4093 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4094 | int pipe = intel_crtc->pipe; | |
ee7b9f93 | 4095 | u32 reg, temp; |
2c07245f | 4096 | |
ab9412ba | 4097 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4098 | |
1fbc0d78 DV |
4099 | if (IS_IVYBRIDGE(dev)) |
4100 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4101 | ||
cd986abb DV |
4102 | /* Write the TU size bits before fdi link training, so that error |
4103 | * detection works. */ | |
4104 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4105 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4106 | ||
c98e9dcf | 4107 | /* For PCH output, training FDI link */ |
674cf967 | 4108 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4109 | |
3ad8a208 DV |
4110 | /* We need to program the right clock selection before writing the pixel |
4111 | * mutliplier into the DPLL. */ | |
303b81e0 | 4112 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4113 | u32 sel; |
4b645f14 | 4114 | |
c98e9dcf | 4115 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4116 | temp |= TRANS_DPLL_ENABLE(pipe); |
4117 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4118 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4119 | temp |= sel; |
4120 | else | |
4121 | temp &= ~sel; | |
c98e9dcf | 4122 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4123 | } |
5eddb70b | 4124 | |
3ad8a208 DV |
4125 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4126 | * transcoder, and we actually should do this to not upset any PCH | |
4127 | * transcoder that already use the clock when we share it. | |
4128 | * | |
4129 | * Note that enable_shared_dpll tries to do the right thing, but | |
4130 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4131 | * the right LVDS enable sequence. */ | |
85b3894f | 4132 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4133 | |
d9b6cb56 JB |
4134 | /* set transcoder timing, panel must allow it */ |
4135 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4136 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4137 | |
303b81e0 | 4138 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4139 | |
c98e9dcf | 4140 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4141 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
dfd07d72 | 4142 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
5eddb70b CW |
4143 | reg = TRANS_DP_CTL(pipe); |
4144 | temp = I915_READ(reg); | |
4145 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4146 | TRANS_DP_SYNC_MASK | |
4147 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4148 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4149 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf JB |
4150 | |
4151 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) | |
5eddb70b | 4152 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
c98e9dcf | 4153 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4154 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4155 | |
4156 | switch (intel_trans_dp_port_sel(crtc)) { | |
4157 | case PCH_DP_B: | |
5eddb70b | 4158 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf JB |
4159 | break; |
4160 | case PCH_DP_C: | |
5eddb70b | 4161 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf JB |
4162 | break; |
4163 | case PCH_DP_D: | |
5eddb70b | 4164 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4165 | break; |
4166 | default: | |
e95d41e1 | 4167 | BUG(); |
32f9d658 | 4168 | } |
2c07245f | 4169 | |
5eddb70b | 4170 | I915_WRITE(reg, temp); |
6be4a607 | 4171 | } |
b52eb4dc | 4172 | |
b8a4f404 | 4173 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4174 | } |
4175 | ||
1507e5bd PZ |
4176 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4177 | { | |
4178 | struct drm_device *dev = crtc->dev; | |
4179 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4181 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4182 | |
ab9412ba | 4183 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4184 | |
8c52b5e8 | 4185 | lpt_program_iclkip(crtc); |
1507e5bd | 4186 | |
0540e488 | 4187 | /* Set transcoder timing. */ |
275f01b2 | 4188 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4189 | |
937bb610 | 4190 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4191 | } |
4192 | ||
190f68c5 ACO |
4193 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4194 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4195 | { |
e2b78267 | 4196 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4197 | struct intel_shared_dpll *pll; |
de419ab6 | 4198 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4199 | enum intel_dpll_id i; |
ee7b9f93 | 4200 | |
de419ab6 ML |
4201 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4202 | ||
98b6bd99 DV |
4203 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4204 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4205 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4206 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4207 | |
46edb027 DV |
4208 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4209 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4210 | |
de419ab6 | 4211 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4212 | |
98b6bd99 DV |
4213 | goto found; |
4214 | } | |
4215 | ||
bcddf610 S |
4216 | if (IS_BROXTON(dev_priv->dev)) { |
4217 | /* PLL is attached to port in bxt */ | |
4218 | struct intel_encoder *encoder; | |
4219 | struct intel_digital_port *intel_dig_port; | |
4220 | ||
4221 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4222 | if (WARN_ON(!encoder)) | |
4223 | return NULL; | |
4224 | ||
4225 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4226 | /* 1:1 mapping between ports and PLLs */ | |
4227 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4228 | pll = &dev_priv->shared_dplls[i]; | |
4229 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4230 | crtc->base.base.id, pll->name); | |
de419ab6 | 4231 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4232 | |
4233 | goto found; | |
4234 | } | |
4235 | ||
e72f9fbf DV |
4236 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4237 | pll = &dev_priv->shared_dplls[i]; | |
ee7b9f93 JB |
4238 | |
4239 | /* Only want to check enabled timings first */ | |
de419ab6 | 4240 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4241 | continue; |
4242 | ||
190f68c5 | 4243 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4244 | &shared_dpll[i].hw_state, |
4245 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4246 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4247 | crtc->base.base.id, pll->name, |
de419ab6 | 4248 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4249 | pll->active); |
ee7b9f93 JB |
4250 | goto found; |
4251 | } | |
4252 | } | |
4253 | ||
4254 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4255 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4256 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4257 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4258 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4259 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4260 | goto found; |
4261 | } | |
4262 | } | |
4263 | ||
4264 | return NULL; | |
4265 | ||
4266 | found: | |
de419ab6 ML |
4267 | if (shared_dpll[i].crtc_mask == 0) |
4268 | shared_dpll[i].hw_state = | |
4269 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4270 | |
190f68c5 | 4271 | crtc_state->shared_dpll = i; |
46edb027 DV |
4272 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4273 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4274 | |
de419ab6 | 4275 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4276 | |
ee7b9f93 JB |
4277 | return pll; |
4278 | } | |
4279 | ||
de419ab6 | 4280 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4281 | { |
de419ab6 ML |
4282 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4283 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4284 | struct intel_shared_dpll *pll; |
4285 | enum intel_dpll_id i; | |
4286 | ||
de419ab6 ML |
4287 | if (!to_intel_atomic_state(state)->dpll_set) |
4288 | return; | |
8bd31e67 | 4289 | |
de419ab6 | 4290 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4291 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4292 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4293 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4294 | } |
4295 | } | |
4296 | ||
a1520318 | 4297 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4298 | { |
4299 | struct drm_i915_private *dev_priv = dev->dev_private; | |
23670b32 | 4300 | int dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4301 | u32 temp; |
4302 | ||
4303 | temp = I915_READ(dslreg); | |
4304 | udelay(500); | |
4305 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4306 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4307 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4308 | } |
4309 | } | |
4310 | ||
86adf9d7 ML |
4311 | static int |
4312 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4313 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4314 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4315 | { |
86adf9d7 ML |
4316 | struct intel_crtc_scaler_state *scaler_state = |
4317 | &crtc_state->scaler_state; | |
4318 | struct intel_crtc *intel_crtc = | |
4319 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4320 | int need_scaling; |
6156a456 CK |
4321 | |
4322 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4323 | (src_h != dst_w || src_w != dst_h): | |
4324 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4325 | |
4326 | /* | |
4327 | * if plane is being disabled or scaler is no more required or force detach | |
4328 | * - free scaler binded to this plane/crtc | |
4329 | * - in order to do this, update crtc->scaler_usage | |
4330 | * | |
4331 | * Here scaler state in crtc_state is set free so that | |
4332 | * scaler can be assigned to other user. Actual register | |
4333 | * update to free the scaler is done in plane/panel-fit programming. | |
4334 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4335 | */ | |
86adf9d7 | 4336 | if (force_detach || !need_scaling) { |
a1b2278e | 4337 | if (*scaler_id >= 0) { |
86adf9d7 | 4338 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4339 | scaler_state->scalers[*scaler_id].in_use = 0; |
4340 | ||
86adf9d7 ML |
4341 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4342 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4343 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4344 | scaler_state->scaler_users); |
4345 | *scaler_id = -1; | |
4346 | } | |
4347 | return 0; | |
4348 | } | |
4349 | ||
4350 | /* range checks */ | |
4351 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4352 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4353 | ||
4354 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4355 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4356 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4357 | "size is out of scaler range\n", |
86adf9d7 | 4358 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4359 | return -EINVAL; |
4360 | } | |
4361 | ||
86adf9d7 ML |
4362 | /* mark this plane as a scaler user in crtc_state */ |
4363 | scaler_state->scaler_users |= (1 << scaler_user); | |
4364 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4365 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4366 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4367 | scaler_state->scaler_users); | |
4368 | ||
4369 | return 0; | |
4370 | } | |
4371 | ||
4372 | /** | |
4373 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4374 | * | |
4375 | * @state: crtc's scaler state | |
4376 | * @force_detach: whether to forcibly disable scaler | |
4377 | * | |
4378 | * Return | |
4379 | * 0 - scaler_usage updated successfully | |
4380 | * error - requested scaling cannot be supported or other error condition | |
4381 | */ | |
4382 | int skl_update_scaler_crtc(struct intel_crtc_state *state, int force_detach) | |
4383 | { | |
4384 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
4385 | struct drm_display_mode *adjusted_mode = | |
4386 | &state->base.adjusted_mode; | |
4387 | ||
4388 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4389 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4390 | ||
4391 | return skl_update_scaler(state, force_detach, SKL_CRTC_INDEX, | |
4392 | &state->scaler_state.scaler_id, DRM_ROTATE_0, | |
4393 | state->pipe_src_w, state->pipe_src_h, | |
4394 | adjusted_mode->hdisplay, adjusted_mode->hdisplay); | |
4395 | } | |
4396 | ||
4397 | /** | |
4398 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4399 | * | |
4400 | * @state: crtc's scaler state | |
86adf9d7 ML |
4401 | * @plane_state: atomic plane state to update |
4402 | * | |
4403 | * Return | |
4404 | * 0 - scaler_usage updated successfully | |
4405 | * error - requested scaling cannot be supported or other error condition | |
4406 | */ | |
da20eabd ML |
4407 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4408 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4409 | { |
4410 | ||
4411 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4412 | struct intel_plane *intel_plane = |
4413 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4414 | struct drm_framebuffer *fb = plane_state->base.fb; |
4415 | int ret; | |
4416 | ||
4417 | bool force_detach = !fb || !plane_state->visible; | |
4418 | ||
4419 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4420 | intel_plane->base.base.id, intel_crtc->pipe, | |
4421 | drm_plane_index(&intel_plane->base)); | |
4422 | ||
4423 | ret = skl_update_scaler(crtc_state, force_detach, | |
4424 | drm_plane_index(&intel_plane->base), | |
4425 | &plane_state->scaler_id, | |
4426 | plane_state->base.rotation, | |
4427 | drm_rect_width(&plane_state->src) >> 16, | |
4428 | drm_rect_height(&plane_state->src) >> 16, | |
4429 | drm_rect_width(&plane_state->dst), | |
4430 | drm_rect_height(&plane_state->dst)); | |
4431 | ||
4432 | if (ret || plane_state->scaler_id < 0) | |
4433 | return ret; | |
4434 | ||
a1b2278e | 4435 | /* check colorkey */ |
86adf9d7 ML |
4436 | if (WARN_ON(intel_plane->ckey.flags != I915_SET_COLORKEY_NONE)) { |
4437 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", | |
4438 | intel_plane->base.base.id); | |
a1b2278e CK |
4439 | return -EINVAL; |
4440 | } | |
4441 | ||
4442 | /* Check src format */ | |
86adf9d7 ML |
4443 | switch (fb->pixel_format) { |
4444 | case DRM_FORMAT_RGB565: | |
4445 | case DRM_FORMAT_XBGR8888: | |
4446 | case DRM_FORMAT_XRGB8888: | |
4447 | case DRM_FORMAT_ABGR8888: | |
4448 | case DRM_FORMAT_ARGB8888: | |
4449 | case DRM_FORMAT_XRGB2101010: | |
4450 | case DRM_FORMAT_XBGR2101010: | |
4451 | case DRM_FORMAT_YUYV: | |
4452 | case DRM_FORMAT_YVYU: | |
4453 | case DRM_FORMAT_UYVY: | |
4454 | case DRM_FORMAT_VYUY: | |
4455 | break; | |
4456 | default: | |
4457 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4458 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4459 | return -EINVAL; | |
a1b2278e CK |
4460 | } |
4461 | ||
a1b2278e CK |
4462 | return 0; |
4463 | } | |
4464 | ||
4465 | static void skylake_pfit_update(struct intel_crtc *crtc, int enable) | |
bd2e244f JB |
4466 | { |
4467 | struct drm_device *dev = crtc->base.dev; | |
4468 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4469 | int pipe = crtc->pipe; | |
a1b2278e CK |
4470 | struct intel_crtc_scaler_state *scaler_state = |
4471 | &crtc->config->scaler_state; | |
4472 | ||
4473 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4474 | ||
4475 | /* To update pfit, first update scaler state */ | |
86adf9d7 | 4476 | skl_update_scaler_crtc(crtc->config, !enable); |
a1b2278e CK |
4477 | intel_atomic_setup_scalers(crtc->base.dev, crtc, crtc->config); |
4478 | skl_detach_scalers(crtc); | |
4479 | if (!enable) | |
4480 | return; | |
bd2e244f | 4481 | |
6e3c9717 | 4482 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4483 | int id; |
4484 | ||
4485 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4486 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4487 | return; | |
4488 | } | |
4489 | ||
4490 | id = scaler_state->scaler_id; | |
4491 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4492 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4493 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4494 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4495 | ||
4496 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4497 | } |
4498 | } | |
4499 | ||
b074cec8 JB |
4500 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4501 | { | |
4502 | struct drm_device *dev = crtc->base.dev; | |
4503 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4504 | int pipe = crtc->pipe; | |
4505 | ||
6e3c9717 | 4506 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4507 | /* Force use of hard-coded filter coefficients |
4508 | * as some pre-programmed values are broken, | |
4509 | * e.g. x201. | |
4510 | */ | |
4511 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4512 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4513 | PF_PIPE_SEL_IVB(pipe)); | |
4514 | else | |
4515 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4516 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4517 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4518 | } |
4519 | } | |
4520 | ||
4a3b8769 | 4521 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
bb53d4ae VS |
4522 | { |
4523 | struct drm_device *dev = crtc->dev; | |
4524 | enum pipe pipe = to_intel_crtc(crtc)->pipe; | |
af2b653b | 4525 | struct drm_plane *plane; |
bb53d4ae VS |
4526 | struct intel_plane *intel_plane; |
4527 | ||
af2b653b MR |
4528 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
4529 | intel_plane = to_intel_plane(plane); | |
bb53d4ae VS |
4530 | if (intel_plane->pipe == pipe) |
4531 | intel_plane_restore(&intel_plane->base); | |
af2b653b | 4532 | } |
bb53d4ae VS |
4533 | } |
4534 | ||
20bc8673 | 4535 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4536 | { |
cea165c3 VS |
4537 | struct drm_device *dev = crtc->base.dev; |
4538 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4539 | |
6e3c9717 | 4540 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4541 | return; |
4542 | ||
cea165c3 VS |
4543 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4544 | intel_wait_for_vblank(dev, crtc->pipe); | |
4545 | ||
d77e4531 | 4546 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4547 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4548 | mutex_lock(&dev_priv->rps.hw_lock); |
4549 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4550 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4551 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4552 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4553 | * mailbox." Moreover, the mailbox may return a bogus state, |
4554 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4555 | */ |
4556 | } else { | |
4557 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4558 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4559 | * is essentially intel_wait_for_vblank. If we don't have this | |
4560 | * and don't wait for vblanks until the end of crtc_enable, then | |
4561 | * the HW state readout code will complain that the expected | |
4562 | * IPS_CTL value is not the one we read. */ | |
4563 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4564 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4565 | } | |
d77e4531 PZ |
4566 | } |
4567 | ||
20bc8673 | 4568 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4569 | { |
4570 | struct drm_device *dev = crtc->base.dev; | |
4571 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4572 | ||
6e3c9717 | 4573 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4574 | return; |
4575 | ||
4576 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4577 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4578 | mutex_lock(&dev_priv->rps.hw_lock); |
4579 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4580 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4581 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4582 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4583 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4584 | } else { |
2a114cc1 | 4585 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4586 | POSTING_READ(IPS_CTL); |
4587 | } | |
d77e4531 PZ |
4588 | |
4589 | /* We need to wait for a vblank before we can disable the plane. */ | |
4590 | intel_wait_for_vblank(dev, crtc->pipe); | |
4591 | } | |
4592 | ||
4593 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4594 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4595 | { | |
4596 | struct drm_device *dev = crtc->dev; | |
4597 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4598 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4599 | enum pipe pipe = intel_crtc->pipe; | |
4600 | int palreg = PALETTE(pipe); | |
4601 | int i; | |
4602 | bool reenable_ips = false; | |
4603 | ||
4604 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4605 | if (!crtc->state->active) |
d77e4531 PZ |
4606 | return; |
4607 | ||
50360403 | 4608 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
409ee761 | 4609 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
d77e4531 PZ |
4610 | assert_dsi_pll_enabled(dev_priv); |
4611 | else | |
4612 | assert_pll_enabled(dev_priv, pipe); | |
4613 | } | |
4614 | ||
4615 | /* use legacy palette for Ironlake */ | |
7a1db49a | 4616 | if (!HAS_GMCH_DISPLAY(dev)) |
d77e4531 PZ |
4617 | palreg = LGC_PALETTE(pipe); |
4618 | ||
4619 | /* Workaround : Do not read or write the pipe palette/gamma data while | |
4620 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4621 | */ | |
6e3c9717 | 4622 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4623 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4624 | GAMMA_MODE_MODE_SPLIT)) { | |
4625 | hsw_disable_ips(intel_crtc); | |
4626 | reenable_ips = true; | |
4627 | } | |
4628 | ||
4629 | for (i = 0; i < 256; i++) { | |
4630 | I915_WRITE(palreg + 4 * i, | |
4631 | (intel_crtc->lut_r[i] << 16) | | |
4632 | (intel_crtc->lut_g[i] << 8) | | |
4633 | intel_crtc->lut_b[i]); | |
4634 | } | |
4635 | ||
4636 | if (reenable_ips) | |
4637 | hsw_enable_ips(intel_crtc); | |
4638 | } | |
4639 | ||
7cac945f | 4640 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4641 | { |
7cac945f | 4642 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4643 | struct drm_device *dev = intel_crtc->base.dev; |
4644 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4645 | ||
4646 | mutex_lock(&dev->struct_mutex); | |
4647 | dev_priv->mm.interruptible = false; | |
4648 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4649 | dev_priv->mm.interruptible = true; | |
4650 | mutex_unlock(&dev->struct_mutex); | |
4651 | } | |
4652 | ||
4653 | /* Let userspace switch the overlay on again. In most cases userspace | |
4654 | * has to recompute where to put it anyway. | |
4655 | */ | |
4656 | } | |
4657 | ||
87d4300a ML |
4658 | /** |
4659 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4660 | * @crtc: the CRTC whose primary plane was just enabled | |
4661 | * | |
4662 | * Performs potentially sleeping operations that must be done after the primary | |
4663 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4664 | * called due to an explicit primary plane update, or due to an implicit | |
4665 | * re-enable that is caused when a sprite plane is updated to no longer | |
4666 | * completely hide the primary plane. | |
4667 | */ | |
4668 | static void | |
4669 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4670 | { |
4671 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4672 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4673 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4674 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4675 | |
87d4300a ML |
4676 | /* |
4677 | * BDW signals flip done immediately if the plane | |
4678 | * is disabled, even if the plane enable is already | |
4679 | * armed to occur at the next vblank :( | |
4680 | */ | |
4681 | if (IS_BROADWELL(dev)) | |
4682 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4683 | |
87d4300a ML |
4684 | /* |
4685 | * FIXME IPS should be fine as long as one plane is | |
4686 | * enabled, but in practice it seems to have problems | |
4687 | * when going from primary only to sprite only and vice | |
4688 | * versa. | |
4689 | */ | |
a5c4d7bc VS |
4690 | hsw_enable_ips(intel_crtc); |
4691 | ||
4692 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 4693 | intel_fbc_update(dev); |
a5c4d7bc | 4694 | mutex_unlock(&dev->struct_mutex); |
f99d7069 DV |
4695 | |
4696 | /* | |
87d4300a ML |
4697 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4698 | * So don't enable underrun reporting before at least some planes | |
4699 | * are enabled. | |
4700 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4701 | * but leave the pipe running. | |
f99d7069 | 4702 | */ |
87d4300a ML |
4703 | if (IS_GEN2(dev)) |
4704 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4705 | ||
4706 | /* Underruns don't raise interrupts, so check manually. */ | |
4707 | if (HAS_GMCH_DISPLAY(dev)) | |
4708 | i9xx_check_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4709 | } |
4710 | ||
87d4300a ML |
4711 | /** |
4712 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4713 | * @crtc: the CRTC whose primary plane is to be disabled | |
4714 | * | |
4715 | * Performs potentially sleeping operations that must be done before the | |
4716 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4717 | * be called due to an explicit primary plane update, or due to an implicit | |
4718 | * disable that is caused when a sprite plane completely hides the primary | |
4719 | * plane. | |
4720 | */ | |
4721 | static void | |
4722 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4723 | { |
4724 | struct drm_device *dev = crtc->dev; | |
4725 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4726 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4727 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4728 | |
87d4300a ML |
4729 | /* |
4730 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4731 | * So diasble underrun reporting before all the planes get disabled. | |
4732 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4733 | * but leave the pipe running. | |
4734 | */ | |
4735 | if (IS_GEN2(dev)) | |
4736 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4737 | |
87d4300a ML |
4738 | /* |
4739 | * Vblank time updates from the shadow to live plane control register | |
4740 | * are blocked if the memory self-refresh mode is active at that | |
4741 | * moment. So to make sure the plane gets truly disabled, disable | |
4742 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4743 | * will be checked/applied by the HW only at the next frame start | |
4744 | * event which is after the vblank start event, so we need to have a | |
4745 | * wait-for-vblank between disabling the plane and the pipe. | |
4746 | */ | |
4747 | if (HAS_GMCH_DISPLAY(dev)) | |
4748 | intel_set_memory_cxsr(dev_priv, false); | |
4749 | ||
4750 | mutex_lock(&dev->struct_mutex); | |
e35fef21 | 4751 | if (dev_priv->fbc.crtc == intel_crtc) |
7ff0ebcc | 4752 | intel_fbc_disable(dev); |
87d4300a | 4753 | mutex_unlock(&dev->struct_mutex); |
a5c4d7bc | 4754 | |
87d4300a ML |
4755 | /* |
4756 | * FIXME IPS should be fine as long as one plane is | |
4757 | * enabled, but in practice it seems to have problems | |
4758 | * when going from primary only to sprite only and vice | |
4759 | * versa. | |
4760 | */ | |
a5c4d7bc | 4761 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4762 | } |
4763 | ||
ac21b225 ML |
4764 | static void intel_post_plane_update(struct intel_crtc *crtc) |
4765 | { | |
4766 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4767 | struct drm_device *dev = crtc->base.dev; | |
4768 | struct drm_plane *plane; | |
4769 | ||
4770 | if (atomic->wait_vblank) | |
4771 | intel_wait_for_vblank(dev, crtc->pipe); | |
4772 | ||
4773 | intel_frontbuffer_flip(dev, atomic->fb_bits); | |
4774 | ||
4775 | if (atomic->update_fbc) { | |
4776 | mutex_lock(&dev->struct_mutex); | |
4777 | intel_fbc_update(dev); | |
4778 | mutex_unlock(&dev->struct_mutex); | |
4779 | } | |
4780 | ||
4781 | if (atomic->post_enable_primary) | |
4782 | intel_post_enable_primary(&crtc->base); | |
4783 | ||
4784 | drm_for_each_plane_mask(plane, dev, atomic->update_sprite_watermarks) | |
4785 | intel_update_sprite_watermarks(plane, &crtc->base, | |
4786 | 0, 0, 0, false, false); | |
4787 | ||
4788 | memset(atomic, 0, sizeof(*atomic)); | |
4789 | } | |
4790 | ||
4791 | static void intel_pre_plane_update(struct intel_crtc *crtc) | |
4792 | { | |
4793 | struct drm_device *dev = crtc->base.dev; | |
4794 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
4795 | struct drm_plane *p; | |
4796 | ||
4797 | /* Track fb's for any planes being disabled */ | |
4798 | ||
4799 | drm_for_each_plane_mask(p, dev, atomic->disabled_planes) { | |
4800 | struct intel_plane *plane = to_intel_plane(p); | |
4801 | unsigned fb_bits = 0; | |
4802 | ||
4803 | switch (p->type) { | |
4804 | case DRM_PLANE_TYPE_PRIMARY: | |
4805 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(plane->pipe); | |
4806 | break; | |
4807 | case DRM_PLANE_TYPE_CURSOR: | |
4808 | fb_bits = INTEL_FRONTBUFFER_CURSOR(plane->pipe); | |
4809 | break; | |
4810 | case DRM_PLANE_TYPE_OVERLAY: | |
4811 | fb_bits = INTEL_FRONTBUFFER_SPRITE(plane->pipe); | |
4812 | break; | |
4813 | } | |
4814 | ||
4815 | mutex_lock(&dev->struct_mutex); | |
4816 | i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL, fb_bits); | |
4817 | mutex_unlock(&dev->struct_mutex); | |
4818 | } | |
4819 | ||
4820 | if (atomic->wait_for_flips) | |
4821 | intel_crtc_wait_for_pending_flips(&crtc->base); | |
4822 | ||
4823 | if (atomic->disable_fbc) | |
4824 | intel_fbc_disable(dev); | |
4825 | ||
4826 | if (atomic->pre_disable_primary) | |
4827 | intel_pre_disable_primary(&crtc->base); | |
4828 | } | |
4829 | ||
87d4300a ML |
4830 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
4831 | { | |
2d847d45 RV |
4832 | struct drm_device *dev = crtc->dev; |
4833 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4834 | int pipe = intel_crtc->pipe; | |
4835 | ||
87d4300a ML |
4836 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
4837 | intel_enable_sprite_planes(crtc); | |
c0165304 ML |
4838 | if (to_intel_plane_state(crtc->cursor->state)->visible) |
4839 | intel_crtc_update_cursor(crtc, true); | |
87d4300a ML |
4840 | |
4841 | intel_post_enable_primary(crtc); | |
2d847d45 RV |
4842 | |
4843 | /* | |
4844 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4845 | * to compute the mask of flip planes precisely. For the time being | |
4846 | * consider this a flip to a NULL plane. | |
4847 | */ | |
4848 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
87d4300a ML |
4849 | } |
4850 | ||
d032ffa0 | 4851 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4852 | { |
4853 | struct drm_device *dev = crtc->dev; | |
4854 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4855 | struct drm_plane *p; |
87d4300a ML |
4856 | int pipe = intel_crtc->pipe; |
4857 | ||
4858 | intel_crtc_wait_for_pending_flips(crtc); | |
4859 | ||
4860 | intel_pre_disable_primary(crtc); | |
a5c4d7bc | 4861 | |
7cac945f | 4862 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4863 | |
d032ffa0 ML |
4864 | drm_for_each_plane_mask(p, dev, plane_mask) |
4865 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4866 | |
f99d7069 DV |
4867 | /* |
4868 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4869 | * to compute the mask of flip planes precisely. For the time being | |
4870 | * consider this a flip to a NULL plane. | |
4871 | */ | |
4872 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4873 | } |
4874 | ||
f67a559d JB |
4875 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4876 | { | |
4877 | struct drm_device *dev = crtc->dev; | |
4878 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4879 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4880 | struct intel_encoder *encoder; |
f67a559d | 4881 | int pipe = intel_crtc->pipe; |
f67a559d | 4882 | |
53d9f4e9 | 4883 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4884 | return; |
4885 | ||
6e3c9717 | 4886 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4887 | intel_prepare_shared_dpll(intel_crtc); |
4888 | ||
6e3c9717 | 4889 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4890 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4891 | |
4892 | intel_set_pipe_timings(intel_crtc); | |
4893 | ||
6e3c9717 | 4894 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4895 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4896 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4897 | } |
4898 | ||
4899 | ironlake_set_pipeconf(crtc); | |
4900 | ||
f67a559d | 4901 | intel_crtc->active = true; |
8664281b | 4902 | |
a72e4c9f DV |
4903 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4904 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
8664281b | 4905 | |
f6736a1a | 4906 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4907 | if (encoder->pre_enable) |
4908 | encoder->pre_enable(encoder); | |
f67a559d | 4909 | |
6e3c9717 | 4910 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4911 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4912 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4913 | * enabling. */ | |
88cefb6c | 4914 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4915 | } else { |
4916 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4917 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4918 | } | |
f67a559d | 4919 | |
b074cec8 | 4920 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4921 | |
9c54c0dd JB |
4922 | /* |
4923 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4924 | * clocks enabled | |
4925 | */ | |
4926 | intel_crtc_load_lut(crtc); | |
4927 | ||
f37fcc2a | 4928 | intel_update_watermarks(crtc); |
e1fdc473 | 4929 | intel_enable_pipe(intel_crtc); |
f67a559d | 4930 | |
6e3c9717 | 4931 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4932 | ironlake_pch_enable(crtc); |
c98e9dcf | 4933 | |
f9b61ff6 DV |
4934 | assert_vblank_disabled(crtc); |
4935 | drm_crtc_vblank_on(crtc); | |
4936 | ||
fa5c73b1 DV |
4937 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4938 | encoder->enable(encoder); | |
61b77ddd DV |
4939 | |
4940 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4941 | cpt_verify_modeset(dev, intel_crtc->pipe); |
6be4a607 JB |
4942 | } |
4943 | ||
42db64ef PZ |
4944 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4945 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4946 | { | |
f5adf94e | 4947 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4948 | } |
4949 | ||
4f771f10 PZ |
4950 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4951 | { | |
4952 | struct drm_device *dev = crtc->dev; | |
4953 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4954 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4955 | struct intel_encoder *encoder; | |
99d736a2 ML |
4956 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4957 | struct intel_crtc_state *pipe_config = | |
4958 | to_intel_crtc_state(crtc->state); | |
4f771f10 | 4959 | |
53d9f4e9 | 4960 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4961 | return; |
4962 | ||
df8ad70c DV |
4963 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4964 | intel_enable_shared_dpll(intel_crtc); | |
4965 | ||
6e3c9717 | 4966 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4967 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
4968 | |
4969 | intel_set_pipe_timings(intel_crtc); | |
4970 | ||
6e3c9717 ACO |
4971 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
4972 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
4973 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
4974 | } |
4975 | ||
6e3c9717 | 4976 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4977 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4978 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4979 | } |
4980 | ||
4981 | haswell_set_pipeconf(crtc); | |
4982 | ||
4983 | intel_set_pipe_csc(crtc); | |
4984 | ||
4f771f10 | 4985 | intel_crtc->active = true; |
8664281b | 4986 | |
a72e4c9f | 4987 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4f771f10 PZ |
4988 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4989 | if (encoder->pre_enable) | |
4990 | encoder->pre_enable(encoder); | |
4991 | ||
6e3c9717 | 4992 | if (intel_crtc->config->has_pch_encoder) { |
a72e4c9f DV |
4993 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
4994 | true); | |
4fe9467d ID |
4995 | dev_priv->display.fdi_link_train(crtc); |
4996 | } | |
4997 | ||
1f544388 | 4998 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 4999 | |
ff6d9f55 | 5000 | if (INTEL_INFO(dev)->gen == 9) |
a1b2278e | 5001 | skylake_pfit_update(intel_crtc, 1); |
ff6d9f55 | 5002 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 5003 | ironlake_pfit_enable(intel_crtc); |
ff6d9f55 JB |
5004 | else |
5005 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 PZ |
5006 | |
5007 | /* | |
5008 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5009 | * clocks enabled | |
5010 | */ | |
5011 | intel_crtc_load_lut(crtc); | |
5012 | ||
1f544388 | 5013 | intel_ddi_set_pipe_settings(crtc); |
8228c251 | 5014 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 5015 | |
f37fcc2a | 5016 | intel_update_watermarks(crtc); |
e1fdc473 | 5017 | intel_enable_pipe(intel_crtc); |
42db64ef | 5018 | |
6e3c9717 | 5019 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 5020 | lpt_pch_enable(crtc); |
4f771f10 | 5021 | |
6e3c9717 | 5022 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
5023 | intel_ddi_set_vc_payload_alloc(crtc, true); |
5024 | ||
f9b61ff6 DV |
5025 | assert_vblank_disabled(crtc); |
5026 | drm_crtc_vblank_on(crtc); | |
5027 | ||
8807e55b | 5028 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 5029 | encoder->enable(encoder); |
8807e55b JN |
5030 | intel_opregion_notify_encoder(encoder, true); |
5031 | } | |
4f771f10 | 5032 | |
e4916946 PZ |
5033 | /* If we change the relative order between pipe/planes enabling, we need |
5034 | * to change the workaround. */ | |
99d736a2 ML |
5035 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
5036 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
5037 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5038 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5039 | } | |
4f771f10 PZ |
5040 | } |
5041 | ||
3f8dce3a DV |
5042 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
5043 | { | |
5044 | struct drm_device *dev = crtc->base.dev; | |
5045 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5046 | int pipe = crtc->pipe; | |
5047 | ||
5048 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5049 | * it's in use. The hw state code will make sure we get this right. */ | |
6e3c9717 | 5050 | if (crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5051 | I915_WRITE(PF_CTL(pipe), 0); |
5052 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5053 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5054 | } | |
5055 | } | |
5056 | ||
6be4a607 JB |
5057 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
5058 | { | |
5059 | struct drm_device *dev = crtc->dev; | |
5060 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5061 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5062 | struct intel_encoder *encoder; |
6be4a607 | 5063 | int pipe = intel_crtc->pipe; |
5eddb70b | 5064 | u32 reg, temp; |
b52eb4dc | 5065 | |
53d9f4e9 | 5066 | if (WARN_ON(!intel_crtc->active)) |
f7abfe8b CW |
5067 | return; |
5068 | ||
ea9d758d DV |
5069 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5070 | encoder->disable(encoder); | |
5071 | ||
f9b61ff6 DV |
5072 | drm_crtc_vblank_off(crtc); |
5073 | assert_vblank_disabled(crtc); | |
5074 | ||
6e3c9717 | 5075 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f | 5076 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
d925c59a | 5077 | |
575f7ab7 | 5078 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5079 | |
3f8dce3a | 5080 | ironlake_pfit_disable(intel_crtc); |
2c07245f | 5081 | |
5a74f70a VS |
5082 | if (intel_crtc->config->has_pch_encoder) |
5083 | ironlake_fdi_disable(crtc); | |
5084 | ||
bf49ec8c DV |
5085 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5086 | if (encoder->post_disable) | |
5087 | encoder->post_disable(encoder); | |
2c07245f | 5088 | |
6e3c9717 | 5089 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5090 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5091 | |
d925c59a DV |
5092 | if (HAS_PCH_CPT(dev)) { |
5093 | /* disable TRANS_DP_CTL */ | |
5094 | reg = TRANS_DP_CTL(pipe); | |
5095 | temp = I915_READ(reg); | |
5096 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5097 | TRANS_DP_PORT_SEL_MASK); | |
5098 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5099 | I915_WRITE(reg, temp); | |
5100 | ||
5101 | /* disable DPLL_SEL */ | |
5102 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5103 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5104 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5105 | } |
e3421a18 | 5106 | |
d925c59a | 5107 | /* disable PCH DPLL */ |
e72f9fbf | 5108 | intel_disable_shared_dpll(intel_crtc); |
8db9d77b | 5109 | |
d925c59a DV |
5110 | ironlake_fdi_pll_disable(intel_crtc); |
5111 | } | |
6b383a7f | 5112 | |
f7abfe8b | 5113 | intel_crtc->active = false; |
46ba614c | 5114 | intel_update_watermarks(crtc); |
d1ebd816 BW |
5115 | |
5116 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 5117 | intel_fbc_update(dev); |
d1ebd816 | 5118 | mutex_unlock(&dev->struct_mutex); |
6be4a607 | 5119 | } |
1b3c7a47 | 5120 | |
4f771f10 | 5121 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5122 | { |
4f771f10 PZ |
5123 | struct drm_device *dev = crtc->dev; |
5124 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5125 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5126 | struct intel_encoder *encoder; |
6e3c9717 | 5127 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5128 | |
53d9f4e9 | 5129 | if (WARN_ON(!intel_crtc->active)) |
4f771f10 PZ |
5130 | return; |
5131 | ||
8807e55b JN |
5132 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5133 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5134 | encoder->disable(encoder); |
8807e55b | 5135 | } |
4f771f10 | 5136 | |
f9b61ff6 DV |
5137 | drm_crtc_vblank_off(crtc); |
5138 | assert_vblank_disabled(crtc); | |
5139 | ||
6e3c9717 | 5140 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f DV |
5141 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5142 | false); | |
575f7ab7 | 5143 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5144 | |
6e3c9717 | 5145 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5146 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5147 | ||
ad80a810 | 5148 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5149 | |
ff6d9f55 | 5150 | if (INTEL_INFO(dev)->gen == 9) |
a1b2278e | 5151 | skylake_pfit_update(intel_crtc, 0); |
ff6d9f55 | 5152 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 5153 | ironlake_pfit_disable(intel_crtc); |
ff6d9f55 JB |
5154 | else |
5155 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 | 5156 | |
1f544388 | 5157 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5158 | |
6e3c9717 | 5159 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5160 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5161 | intel_ddi_fdi_disable(crtc); |
83616634 | 5162 | } |
4f771f10 | 5163 | |
97b040aa ID |
5164 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5165 | if (encoder->post_disable) | |
5166 | encoder->post_disable(encoder); | |
5167 | ||
4f771f10 | 5168 | intel_crtc->active = false; |
46ba614c | 5169 | intel_update_watermarks(crtc); |
4f771f10 PZ |
5170 | |
5171 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 5172 | intel_fbc_update(dev); |
4f771f10 | 5173 | mutex_unlock(&dev->struct_mutex); |
df8ad70c DV |
5174 | |
5175 | if (intel_crtc_to_shared_dpll(intel_crtc)) | |
5176 | intel_disable_shared_dpll(intel_crtc); | |
4f771f10 PZ |
5177 | } |
5178 | ||
2dd24552 JB |
5179 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5180 | { | |
5181 | struct drm_device *dev = crtc->base.dev; | |
5182 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5183 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5184 | |
681a8504 | 5185 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5186 | return; |
5187 | ||
2dd24552 | 5188 | /* |
c0b03411 DV |
5189 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5190 | * according to register description and PRM. | |
2dd24552 | 5191 | */ |
c0b03411 DV |
5192 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5193 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5194 | |
b074cec8 JB |
5195 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5196 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5197 | |
5198 | /* Border color in case we don't scale up to the full screen. Black by | |
5199 | * default, change to something else for debugging. */ | |
5200 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5201 | } |
5202 | ||
d05410f9 DA |
5203 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5204 | { | |
5205 | switch (port) { | |
5206 | case PORT_A: | |
5207 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; | |
5208 | case PORT_B: | |
5209 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; | |
5210 | case PORT_C: | |
5211 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; | |
5212 | case PORT_D: | |
5213 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; | |
5214 | default: | |
5215 | WARN_ON_ONCE(1); | |
5216 | return POWER_DOMAIN_PORT_OTHER; | |
5217 | } | |
5218 | } | |
5219 | ||
77d22dca ID |
5220 | #define for_each_power_domain(domain, mask) \ |
5221 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5222 | if ((1 << (domain)) & (mask)) | |
5223 | ||
319be8ae ID |
5224 | enum intel_display_power_domain |
5225 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5226 | { | |
5227 | struct drm_device *dev = intel_encoder->base.dev; | |
5228 | struct intel_digital_port *intel_dig_port; | |
5229 | ||
5230 | switch (intel_encoder->type) { | |
5231 | case INTEL_OUTPUT_UNKNOWN: | |
5232 | /* Only DDI platforms should ever use this output type */ | |
5233 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5234 | case INTEL_OUTPUT_DISPLAYPORT: | |
5235 | case INTEL_OUTPUT_HDMI: | |
5236 | case INTEL_OUTPUT_EDP: | |
5237 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5238 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5239 | case INTEL_OUTPUT_DP_MST: |
5240 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5241 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5242 | case INTEL_OUTPUT_ANALOG: |
5243 | return POWER_DOMAIN_PORT_CRT; | |
5244 | case INTEL_OUTPUT_DSI: | |
5245 | return POWER_DOMAIN_PORT_DSI; | |
5246 | default: | |
5247 | return POWER_DOMAIN_PORT_OTHER; | |
5248 | } | |
5249 | } | |
5250 | ||
5251 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) | |
77d22dca | 5252 | { |
319be8ae ID |
5253 | struct drm_device *dev = crtc->dev; |
5254 | struct intel_encoder *intel_encoder; | |
5255 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5256 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca ID |
5257 | unsigned long mask; |
5258 | enum transcoder transcoder; | |
5259 | ||
5260 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); | |
5261 | ||
5262 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); | |
5263 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5264 | if (intel_crtc->config->pch_pfit.enabled || |
5265 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5266 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5267 | ||
319be8ae ID |
5268 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5269 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5270 | ||
77d22dca ID |
5271 | return mask; |
5272 | } | |
5273 | ||
679dacd4 | 5274 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
77d22dca | 5275 | { |
679dacd4 | 5276 | struct drm_device *dev = state->dev; |
77d22dca ID |
5277 | struct drm_i915_private *dev_priv = dev->dev_private; |
5278 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; | |
5279 | struct intel_crtc *crtc; | |
5280 | ||
5281 | /* | |
5282 | * First get all needed power domains, then put all unneeded, to avoid | |
5283 | * any unnecessary toggling of the power wells. | |
5284 | */ | |
d3fcc808 | 5285 | for_each_intel_crtc(dev, crtc) { |
77d22dca ID |
5286 | enum intel_display_power_domain domain; |
5287 | ||
83d65738 | 5288 | if (!crtc->base.state->enable) |
77d22dca ID |
5289 | continue; |
5290 | ||
319be8ae | 5291 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
77d22dca ID |
5292 | |
5293 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) | |
5294 | intel_display_power_get(dev_priv, domain); | |
5295 | } | |
5296 | ||
50f6e502 | 5297 | if (dev_priv->display.modeset_global_resources) |
679dacd4 | 5298 | dev_priv->display.modeset_global_resources(state); |
50f6e502 | 5299 | |
d3fcc808 | 5300 | for_each_intel_crtc(dev, crtc) { |
77d22dca ID |
5301 | enum intel_display_power_domain domain; |
5302 | ||
5303 | for_each_power_domain(domain, crtc->enabled_power_domains) | |
5304 | intel_display_power_put(dev_priv, domain); | |
5305 | ||
5306 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; | |
5307 | } | |
5308 | ||
5309 | intel_display_set_init_power(dev_priv, false); | |
5310 | } | |
5311 | ||
560a7ae4 DL |
5312 | static void intel_update_max_cdclk(struct drm_device *dev) |
5313 | { | |
5314 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5315 | ||
5316 | if (IS_SKYLAKE(dev)) { | |
5317 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; | |
5318 | ||
5319 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5320 | dev_priv->max_cdclk_freq = 675000; | |
5321 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5322 | dev_priv->max_cdclk_freq = 540000; | |
5323 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5324 | dev_priv->max_cdclk_freq = 450000; | |
5325 | else | |
5326 | dev_priv->max_cdclk_freq = 337500; | |
5327 | } else if (IS_BROADWELL(dev)) { | |
5328 | /* | |
5329 | * FIXME with extra cooling we can allow | |
5330 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5331 | * How can we know if extra cooling is | |
5332 | * available? PCI ID, VTB, something else? | |
5333 | */ | |
5334 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5335 | dev_priv->max_cdclk_freq = 450000; | |
5336 | else if (IS_BDW_ULX(dev)) | |
5337 | dev_priv->max_cdclk_freq = 450000; | |
5338 | else if (IS_BDW_ULT(dev)) | |
5339 | dev_priv->max_cdclk_freq = 540000; | |
5340 | else | |
5341 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5342 | } else if (IS_CHERRYVIEW(dev)) { |
5343 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5344 | } else if (IS_VALLEYVIEW(dev)) { |
5345 | dev_priv->max_cdclk_freq = 400000; | |
5346 | } else { | |
5347 | /* otherwise assume cdclk is fixed */ | |
5348 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5349 | } | |
5350 | ||
5351 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", | |
5352 | dev_priv->max_cdclk_freq); | |
5353 | } | |
5354 | ||
5355 | static void intel_update_cdclk(struct drm_device *dev) | |
5356 | { | |
5357 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5358 | ||
5359 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5360 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5361 | dev_priv->cdclk_freq); | |
5362 | ||
5363 | /* | |
5364 | * Program the gmbus_freq based on the cdclk frequency. | |
5365 | * BSpec erroneously claims we should aim for 4MHz, but | |
5366 | * in fact 1MHz is the correct frequency. | |
5367 | */ | |
5368 | if (IS_VALLEYVIEW(dev)) { | |
5369 | /* | |
5370 | * Program the gmbus_freq based on the cdclk frequency. | |
5371 | * BSpec erroneously claims we should aim for 4MHz, but | |
5372 | * in fact 1MHz is the correct frequency. | |
5373 | */ | |
5374 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5375 | } | |
5376 | ||
5377 | if (dev_priv->max_cdclk_freq == 0) | |
5378 | intel_update_max_cdclk(dev); | |
5379 | } | |
5380 | ||
70d0c574 | 5381 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5382 | { |
5383 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5384 | uint32_t divider; | |
5385 | uint32_t ratio; | |
5386 | uint32_t current_freq; | |
5387 | int ret; | |
5388 | ||
5389 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5390 | switch (frequency) { | |
5391 | case 144000: | |
5392 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5393 | ratio = BXT_DE_PLL_RATIO(60); | |
5394 | break; | |
5395 | case 288000: | |
5396 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5397 | ratio = BXT_DE_PLL_RATIO(60); | |
5398 | break; | |
5399 | case 384000: | |
5400 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5401 | ratio = BXT_DE_PLL_RATIO(60); | |
5402 | break; | |
5403 | case 576000: | |
5404 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5405 | ratio = BXT_DE_PLL_RATIO(60); | |
5406 | break; | |
5407 | case 624000: | |
5408 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5409 | ratio = BXT_DE_PLL_RATIO(65); | |
5410 | break; | |
5411 | case 19200: | |
5412 | /* | |
5413 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5414 | * to suppress GCC warning. | |
5415 | */ | |
5416 | ratio = 0; | |
5417 | divider = 0; | |
5418 | break; | |
5419 | default: | |
5420 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5421 | ||
5422 | return; | |
5423 | } | |
5424 | ||
5425 | mutex_lock(&dev_priv->rps.hw_lock); | |
5426 | /* Inform power controller of upcoming frequency change */ | |
5427 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5428 | 0x80000000); | |
5429 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5430 | ||
5431 | if (ret) { | |
5432 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5433 | ret, frequency); | |
5434 | return; | |
5435 | } | |
5436 | ||
5437 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5438 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5439 | current_freq = current_freq * 500 + 1000; | |
5440 | ||
5441 | /* | |
5442 | * DE PLL has to be disabled when | |
5443 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5444 | * - before setting to 624MHz (PLL needs toggling) | |
5445 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5446 | */ | |
5447 | if (frequency == 19200 || frequency == 624000 || | |
5448 | current_freq == 624000) { | |
5449 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5450 | /* Timeout 200us */ | |
5451 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5452 | 1)) | |
5453 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5454 | } | |
5455 | ||
5456 | if (frequency != 19200) { | |
5457 | uint32_t val; | |
5458 | ||
5459 | val = I915_READ(BXT_DE_PLL_CTL); | |
5460 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5461 | val |= ratio; | |
5462 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5463 | ||
5464 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5465 | /* Timeout 200us */ | |
5466 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5467 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5468 | ||
5469 | val = I915_READ(CDCLK_CTL); | |
5470 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5471 | val |= divider; | |
5472 | /* | |
5473 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5474 | * enable otherwise. | |
5475 | */ | |
5476 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5477 | if (frequency >= 500000) | |
5478 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5479 | ||
5480 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5481 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5482 | val |= (frequency - 1000) / 500; | |
5483 | I915_WRITE(CDCLK_CTL, val); | |
5484 | } | |
5485 | ||
5486 | mutex_lock(&dev_priv->rps.hw_lock); | |
5487 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5488 | DIV_ROUND_UP(frequency, 25000)); | |
5489 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5490 | ||
5491 | if (ret) { | |
5492 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5493 | ret, frequency); | |
5494 | return; | |
5495 | } | |
5496 | ||
a47871bd | 5497 | intel_update_cdclk(dev); |
f8437dd1 VK |
5498 | } |
5499 | ||
5500 | void broxton_init_cdclk(struct drm_device *dev) | |
5501 | { | |
5502 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5503 | uint32_t val; | |
5504 | ||
5505 | /* | |
5506 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5507 | * or else the reset will hang because there is no PCH to respond. | |
5508 | * Move the handshake programming to initialization sequence. | |
5509 | * Previously was left up to BIOS. | |
5510 | */ | |
5511 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5512 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5513 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5514 | ||
5515 | /* Enable PG1 for cdclk */ | |
5516 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5517 | ||
5518 | /* check if cd clock is enabled */ | |
5519 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5520 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5521 | return; | |
5522 | } | |
5523 | ||
5524 | /* | |
5525 | * FIXME: | |
5526 | * - The initial CDCLK needs to be read from VBT. | |
5527 | * Need to make this change after VBT has changes for BXT. | |
5528 | * - check if setting the max (or any) cdclk freq is really necessary | |
5529 | * here, it belongs to modeset time | |
5530 | */ | |
5531 | broxton_set_cdclk(dev, 624000); | |
5532 | ||
5533 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5534 | POSTING_READ(DBUF_CTL); |
5535 | ||
f8437dd1 VK |
5536 | udelay(10); |
5537 | ||
5538 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5539 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5540 | } | |
5541 | ||
5542 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5543 | { | |
5544 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5545 | ||
5546 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5547 | POSTING_READ(DBUF_CTL); |
5548 | ||
f8437dd1 VK |
5549 | udelay(10); |
5550 | ||
5551 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5552 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5553 | ||
5554 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5555 | broxton_set_cdclk(dev, 19200); | |
5556 | ||
5557 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5558 | } | |
5559 | ||
5d96d8af DL |
5560 | static const struct skl_cdclk_entry { |
5561 | unsigned int freq; | |
5562 | unsigned int vco; | |
5563 | } skl_cdclk_frequencies[] = { | |
5564 | { .freq = 308570, .vco = 8640 }, | |
5565 | { .freq = 337500, .vco = 8100 }, | |
5566 | { .freq = 432000, .vco = 8640 }, | |
5567 | { .freq = 450000, .vco = 8100 }, | |
5568 | { .freq = 540000, .vco = 8100 }, | |
5569 | { .freq = 617140, .vco = 8640 }, | |
5570 | { .freq = 675000, .vco = 8100 }, | |
5571 | }; | |
5572 | ||
5573 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5574 | { | |
5575 | return (freq - 1000) / 500; | |
5576 | } | |
5577 | ||
5578 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5579 | { | |
5580 | unsigned int i; | |
5581 | ||
5582 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5583 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5584 | ||
5585 | if (e->freq == freq) | |
5586 | return e->vco; | |
5587 | } | |
5588 | ||
5589 | return 8100; | |
5590 | } | |
5591 | ||
5592 | static void | |
5593 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5594 | { | |
5595 | unsigned int min_freq; | |
5596 | u32 val; | |
5597 | ||
5598 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5599 | val = I915_READ(CDCLK_CTL); | |
5600 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5601 | val |= CDCLK_FREQ_337_308; | |
5602 | ||
5603 | if (required_vco == 8640) | |
5604 | min_freq = 308570; | |
5605 | else | |
5606 | min_freq = 337500; | |
5607 | ||
5608 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5609 | ||
5610 | I915_WRITE(CDCLK_CTL, val); | |
5611 | POSTING_READ(CDCLK_CTL); | |
5612 | ||
5613 | /* | |
5614 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5615 | * taking into account the VCO required to operate the eDP panel at the | |
5616 | * desired frequency. The usual DP link rates operate with a VCO of | |
5617 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5618 | * The modeset code is responsible for the selection of the exact link | |
5619 | * rate later on, with the constraint of choosing a frequency that | |
5620 | * works with required_vco. | |
5621 | */ | |
5622 | val = I915_READ(DPLL_CTRL1); | |
5623 | ||
5624 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5625 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5626 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5627 | if (required_vco == 8640) | |
5628 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5629 | SKL_DPLL0); | |
5630 | else | |
5631 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5632 | SKL_DPLL0); | |
5633 | ||
5634 | I915_WRITE(DPLL_CTRL1, val); | |
5635 | POSTING_READ(DPLL_CTRL1); | |
5636 | ||
5637 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5638 | ||
5639 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5640 | DRM_ERROR("DPLL0 not locked\n"); | |
5641 | } | |
5642 | ||
5643 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5644 | { | |
5645 | int ret; | |
5646 | u32 val; | |
5647 | ||
5648 | /* inform PCU we want to change CDCLK */ | |
5649 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5650 | mutex_lock(&dev_priv->rps.hw_lock); | |
5651 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5652 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5653 | ||
5654 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5655 | } | |
5656 | ||
5657 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5658 | { | |
5659 | unsigned int i; | |
5660 | ||
5661 | for (i = 0; i < 15; i++) { | |
5662 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5663 | return true; | |
5664 | udelay(10); | |
5665 | } | |
5666 | ||
5667 | return false; | |
5668 | } | |
5669 | ||
5670 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5671 | { | |
560a7ae4 | 5672 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5673 | u32 freq_select, pcu_ack; |
5674 | ||
5675 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5676 | ||
5677 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5678 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5679 | return; | |
5680 | } | |
5681 | ||
5682 | /* set CDCLK_CTL */ | |
5683 | switch(freq) { | |
5684 | case 450000: | |
5685 | case 432000: | |
5686 | freq_select = CDCLK_FREQ_450_432; | |
5687 | pcu_ack = 1; | |
5688 | break; | |
5689 | case 540000: | |
5690 | freq_select = CDCLK_FREQ_540; | |
5691 | pcu_ack = 2; | |
5692 | break; | |
5693 | case 308570: | |
5694 | case 337500: | |
5695 | default: | |
5696 | freq_select = CDCLK_FREQ_337_308; | |
5697 | pcu_ack = 0; | |
5698 | break; | |
5699 | case 617140: | |
5700 | case 675000: | |
5701 | freq_select = CDCLK_FREQ_675_617; | |
5702 | pcu_ack = 3; | |
5703 | break; | |
5704 | } | |
5705 | ||
5706 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5707 | POSTING_READ(CDCLK_CTL); | |
5708 | ||
5709 | /* inform PCU of the change */ | |
5710 | mutex_lock(&dev_priv->rps.hw_lock); | |
5711 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5712 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5713 | |
5714 | intel_update_cdclk(dev); | |
5d96d8af DL |
5715 | } |
5716 | ||
5717 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5718 | { | |
5719 | /* disable DBUF power */ | |
5720 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5721 | POSTING_READ(DBUF_CTL); | |
5722 | ||
5723 | udelay(10); | |
5724 | ||
5725 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5726 | DRM_ERROR("DBuf power disable timeout\n"); | |
5727 | ||
5728 | /* disable DPLL0 */ | |
5729 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5730 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5731 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5732 | ||
5733 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5734 | } | |
5735 | ||
5736 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5737 | { | |
5738 | u32 val; | |
5739 | unsigned int required_vco; | |
5740 | ||
5741 | /* enable PCH reset handshake */ | |
5742 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5743 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE); | |
5744 | ||
5745 | /* enable PG1 and Misc I/O */ | |
5746 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5747 | ||
5748 | /* DPLL0 already enabed !? */ | |
5749 | if (I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE) { | |
5750 | DRM_DEBUG_DRIVER("DPLL0 already running\n"); | |
5751 | return; | |
5752 | } | |
5753 | ||
5754 | /* enable DPLL0 */ | |
5755 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5756 | skl_dpll0_enable(dev_priv, required_vco); | |
5757 | ||
5758 | /* set CDCLK to the frequency the BIOS chose */ | |
5759 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5760 | ||
5761 | /* enable DBUF power */ | |
5762 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5763 | POSTING_READ(DBUF_CTL); | |
5764 | ||
5765 | udelay(10); | |
5766 | ||
5767 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5768 | DRM_ERROR("DBuf power enable timeout\n"); | |
5769 | } | |
5770 | ||
dfcab17e | 5771 | /* returns HPLL frequency in kHz */ |
f8bf63fd | 5772 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
30a970c6 | 5773 | { |
586f49dc | 5774 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
30a970c6 | 5775 | |
586f49dc | 5776 | /* Obtain SKU information */ |
a580516d | 5777 | mutex_lock(&dev_priv->sb_lock); |
586f49dc JB |
5778 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
5779 | CCK_FUSE_HPLL_FREQ_MASK; | |
a580516d | 5780 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5781 | |
dfcab17e | 5782 | return vco_freq[hpll_freq] * 1000; |
30a970c6 JB |
5783 | } |
5784 | ||
5785 | /* Adjust CDclk dividers to allow high res or save power if possible */ | |
5786 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5787 | { | |
5788 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5789 | u32 val, cmd; | |
5790 | ||
164dfd28 VK |
5791 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5792 | != dev_priv->cdclk_freq); | |
d60c4473 | 5793 | |
dfcab17e | 5794 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5795 | cmd = 2; |
dfcab17e | 5796 | else if (cdclk == 266667) |
30a970c6 JB |
5797 | cmd = 1; |
5798 | else | |
5799 | cmd = 0; | |
5800 | ||
5801 | mutex_lock(&dev_priv->rps.hw_lock); | |
5802 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5803 | val &= ~DSPFREQGUAR_MASK; | |
5804 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5805 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5806 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5807 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5808 | 50)) { | |
5809 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5810 | } | |
5811 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5812 | ||
54433e91 VS |
5813 | mutex_lock(&dev_priv->sb_lock); |
5814 | ||
dfcab17e | 5815 | if (cdclk == 400000) { |
6bcda4f0 | 5816 | u32 divider; |
30a970c6 | 5817 | |
6bcda4f0 | 5818 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5819 | |
30a970c6 JB |
5820 | /* adjust cdclk divider */ |
5821 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
9cf33db5 | 5822 | val &= ~DISPLAY_FREQUENCY_VALUES; |
30a970c6 JB |
5823 | val |= divider; |
5824 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5825 | |
5826 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
5827 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
5828 | 50)) | |
5829 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5830 | } |
5831 | ||
30a970c6 JB |
5832 | /* adjust self-refresh exit latency value */ |
5833 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5834 | val &= ~0x7f; | |
5835 | ||
5836 | /* | |
5837 | * For high bandwidth configs, we set a higher latency in the bunit | |
5838 | * so that the core display fetch happens in time to avoid underruns. | |
5839 | */ | |
dfcab17e | 5840 | if (cdclk == 400000) |
30a970c6 JB |
5841 | val |= 4500 / 250; /* 4.5 usec */ |
5842 | else | |
5843 | val |= 3000 / 250; /* 3.0 usec */ | |
5844 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5845 | |
a580516d | 5846 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5847 | |
b6283055 | 5848 | intel_update_cdclk(dev); |
30a970c6 JB |
5849 | } |
5850 | ||
383c5a6a VS |
5851 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5852 | { | |
5853 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5854 | u32 val, cmd; | |
5855 | ||
164dfd28 VK |
5856 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5857 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5858 | |
5859 | switch (cdclk) { | |
383c5a6a VS |
5860 | case 333333: |
5861 | case 320000: | |
383c5a6a | 5862 | case 266667: |
383c5a6a | 5863 | case 200000: |
383c5a6a VS |
5864 | break; |
5865 | default: | |
5f77eeb0 | 5866 | MISSING_CASE(cdclk); |
383c5a6a VS |
5867 | return; |
5868 | } | |
5869 | ||
9d0d3fda VS |
5870 | /* |
5871 | * Specs are full of misinformation, but testing on actual | |
5872 | * hardware has shown that we just need to write the desired | |
5873 | * CCK divider into the Punit register. | |
5874 | */ | |
5875 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5876 | ||
383c5a6a VS |
5877 | mutex_lock(&dev_priv->rps.hw_lock); |
5878 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5879 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5880 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5881 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5882 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5883 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5884 | 50)) { | |
5885 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5886 | } | |
5887 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5888 | ||
b6283055 | 5889 | intel_update_cdclk(dev); |
383c5a6a VS |
5890 | } |
5891 | ||
30a970c6 JB |
5892 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5893 | int max_pixclk) | |
5894 | { | |
6bcda4f0 | 5895 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5896 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5897 | |
30a970c6 JB |
5898 | /* |
5899 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5900 | * 200MHz | |
5901 | * 267MHz | |
29dc7ef3 | 5902 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5903 | * 400MHz (VLV only) |
5904 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5905 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5906 | * |
5907 | * We seem to get an unstable or solid color picture at 200MHz. | |
5908 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5909 | * are off. | |
30a970c6 | 5910 | */ |
6cca3195 VS |
5911 | if (!IS_CHERRYVIEW(dev_priv) && |
5912 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5913 | return 400000; |
6cca3195 | 5914 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5915 | return freq_320; |
e37c67a1 | 5916 | else if (max_pixclk > 0) |
dfcab17e | 5917 | return 266667; |
e37c67a1 VS |
5918 | else |
5919 | return 200000; | |
30a970c6 JB |
5920 | } |
5921 | ||
f8437dd1 VK |
5922 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5923 | int max_pixclk) | |
5924 | { | |
5925 | /* | |
5926 | * FIXME: | |
5927 | * - remove the guardband, it's not needed on BXT | |
5928 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5929 | */ | |
5930 | if (max_pixclk > 576000*9/10) | |
5931 | return 624000; | |
5932 | else if (max_pixclk > 384000*9/10) | |
5933 | return 576000; | |
5934 | else if (max_pixclk > 288000*9/10) | |
5935 | return 384000; | |
5936 | else if (max_pixclk > 144000*9/10) | |
5937 | return 288000; | |
5938 | else | |
5939 | return 144000; | |
5940 | } | |
5941 | ||
a821fc46 ACO |
5942 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5943 | * that's non-NULL, look at current state otherwise. */ | |
5944 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5945 | struct drm_atomic_state *state) | |
30a970c6 | 5946 | { |
30a970c6 | 5947 | struct intel_crtc *intel_crtc; |
304603f4 | 5948 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5949 | int max_pixclk = 0; |
5950 | ||
d3fcc808 | 5951 | for_each_intel_crtc(dev, intel_crtc) { |
a821fc46 ACO |
5952 | if (state) |
5953 | crtc_state = | |
5954 | intel_atomic_get_crtc_state(state, intel_crtc); | |
5955 | else | |
5956 | crtc_state = intel_crtc->config; | |
304603f4 ACO |
5957 | if (IS_ERR(crtc_state)) |
5958 | return PTR_ERR(crtc_state); | |
5959 | ||
5960 | if (!crtc_state->base.enable) | |
5961 | continue; | |
5962 | ||
5963 | max_pixclk = max(max_pixclk, | |
5964 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5965 | } |
5966 | ||
5967 | return max_pixclk; | |
5968 | } | |
5969 | ||
0a9ab303 | 5970 | static int valleyview_modeset_global_pipes(struct drm_atomic_state *state) |
30a970c6 | 5971 | { |
304603f4 | 5972 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
0a9ab303 ACO |
5973 | struct drm_crtc *crtc; |
5974 | struct drm_crtc_state *crtc_state; | |
a821fc46 | 5975 | int max_pixclk = intel_mode_max_pixclk(state->dev, state); |
85a96e7a | 5976 | int cdclk, ret = 0; |
30a970c6 | 5977 | |
304603f4 ACO |
5978 | if (max_pixclk < 0) |
5979 | return max_pixclk; | |
30a970c6 | 5980 | |
f8437dd1 VK |
5981 | if (IS_VALLEYVIEW(dev_priv)) |
5982 | cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); | |
5983 | else | |
5984 | cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); | |
5985 | ||
5986 | if (cdclk == dev_priv->cdclk_freq) | |
304603f4 | 5987 | return 0; |
30a970c6 | 5988 | |
0a9ab303 ACO |
5989 | /* add all active pipes to the state */ |
5990 | for_each_crtc(state->dev, crtc) { | |
0a9ab303 ACO |
5991 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
5992 | if (IS_ERR(crtc_state)) | |
5993 | return PTR_ERR(crtc_state); | |
0a9ab303 | 5994 | |
85a96e7a ML |
5995 | if (!crtc_state->active || needs_modeset(crtc_state)) |
5996 | continue; | |
304603f4 | 5997 | |
85a96e7a ML |
5998 | crtc_state->mode_changed = true; |
5999 | ||
6000 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
6001 | if (ret) | |
6002 | break; | |
6003 | ||
6004 | ret = drm_atomic_add_affected_planes(state, crtc); | |
6005 | if (ret) | |
6006 | break; | |
6007 | } | |
6008 | ||
6009 | return ret; | |
30a970c6 JB |
6010 | } |
6011 | ||
1e69cd74 VS |
6012 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
6013 | { | |
6014 | unsigned int credits, default_credits; | |
6015 | ||
6016 | if (IS_CHERRYVIEW(dev_priv)) | |
6017 | default_credits = PFI_CREDIT(12); | |
6018 | else | |
6019 | default_credits = PFI_CREDIT(8); | |
6020 | ||
164dfd28 | 6021 | if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
1e69cd74 VS |
6022 | /* CHV suggested value is 31 or 63 */ |
6023 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 6024 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
6025 | else |
6026 | credits = PFI_CREDIT(15); | |
6027 | } else { | |
6028 | credits = default_credits; | |
6029 | } | |
6030 | ||
6031 | /* | |
6032 | * WA - write default credits before re-programming | |
6033 | * FIXME: should we also set the resend bit here? | |
6034 | */ | |
6035 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6036 | default_credits); | |
6037 | ||
6038 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6039 | credits | PFI_CREDIT_RESEND); | |
6040 | ||
6041 | /* | |
6042 | * FIXME is this guaranteed to clear | |
6043 | * immediately or should we poll for it? | |
6044 | */ | |
6045 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6046 | } | |
6047 | ||
a821fc46 | 6048 | static void valleyview_modeset_global_resources(struct drm_atomic_state *old_state) |
30a970c6 | 6049 | { |
a821fc46 | 6050 | struct drm_device *dev = old_state->dev; |
30a970c6 | 6051 | struct drm_i915_private *dev_priv = dev->dev_private; |
a821fc46 | 6052 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
304603f4 ACO |
6053 | int req_cdclk; |
6054 | ||
a821fc46 ACO |
6055 | /* The path in intel_mode_max_pixclk() with a NULL atomic state should |
6056 | * never fail. */ | |
304603f4 ACO |
6057 | if (WARN_ON(max_pixclk < 0)) |
6058 | return; | |
30a970c6 | 6059 | |
304603f4 | 6060 | req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
30a970c6 | 6061 | |
164dfd28 | 6062 | if (req_cdclk != dev_priv->cdclk_freq) { |
738c05c0 ID |
6063 | /* |
6064 | * FIXME: We can end up here with all power domains off, yet | |
6065 | * with a CDCLK frequency other than the minimum. To account | |
6066 | * for this take the PIPE-A power domain, which covers the HW | |
6067 | * blocks needed for the following programming. This can be | |
6068 | * removed once it's guaranteed that we get here either with | |
6069 | * the minimum CDCLK set, or the required power domains | |
6070 | * enabled. | |
6071 | */ | |
6072 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
6073 | ||
383c5a6a VS |
6074 | if (IS_CHERRYVIEW(dev)) |
6075 | cherryview_set_cdclk(dev, req_cdclk); | |
6076 | else | |
6077 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6078 | |
1e69cd74 VS |
6079 | vlv_program_pfi_credits(dev_priv); |
6080 | ||
738c05c0 | 6081 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
383c5a6a | 6082 | } |
30a970c6 JB |
6083 | } |
6084 | ||
89b667f8 JB |
6085 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6086 | { | |
6087 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6088 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6089 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6090 | struct intel_encoder *encoder; | |
6091 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6092 | bool is_dsi; |
89b667f8 | 6093 | |
53d9f4e9 | 6094 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6095 | return; |
6096 | ||
409ee761 | 6097 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6098 | |
1ae0d137 VS |
6099 | if (!is_dsi) { |
6100 | if (IS_CHERRYVIEW(dev)) | |
6e3c9717 | 6101 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
1ae0d137 | 6102 | else |
6e3c9717 | 6103 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
1ae0d137 | 6104 | } |
5b18e57c | 6105 | |
6e3c9717 | 6106 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6107 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6108 | |
6109 | intel_set_pipe_timings(intel_crtc); | |
6110 | ||
c14b0485 VS |
6111 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6112 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6113 | ||
6114 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6115 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6116 | } | |
6117 | ||
5b18e57c DV |
6118 | i9xx_set_pipeconf(intel_crtc); |
6119 | ||
89b667f8 | 6120 | intel_crtc->active = true; |
89b667f8 | 6121 | |
a72e4c9f | 6122 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6123 | |
89b667f8 JB |
6124 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6125 | if (encoder->pre_pll_enable) | |
6126 | encoder->pre_pll_enable(encoder); | |
6127 | ||
9d556c99 CML |
6128 | if (!is_dsi) { |
6129 | if (IS_CHERRYVIEW(dev)) | |
6e3c9717 | 6130 | chv_enable_pll(intel_crtc, intel_crtc->config); |
9d556c99 | 6131 | else |
6e3c9717 | 6132 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
9d556c99 | 6133 | } |
89b667f8 JB |
6134 | |
6135 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6136 | if (encoder->pre_enable) | |
6137 | encoder->pre_enable(encoder); | |
6138 | ||
2dd24552 JB |
6139 | i9xx_pfit_enable(intel_crtc); |
6140 | ||
63cbb074 VS |
6141 | intel_crtc_load_lut(crtc); |
6142 | ||
f37fcc2a | 6143 | intel_update_watermarks(crtc); |
e1fdc473 | 6144 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6145 | |
4b3a9526 VS |
6146 | assert_vblank_disabled(crtc); |
6147 | drm_crtc_vblank_on(crtc); | |
6148 | ||
f9b61ff6 DV |
6149 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6150 | encoder->enable(encoder); | |
89b667f8 JB |
6151 | } |
6152 | ||
f13c2ef3 DV |
6153 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6154 | { | |
6155 | struct drm_device *dev = crtc->base.dev; | |
6156 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6157 | ||
6e3c9717 ACO |
6158 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6159 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6160 | } |
6161 | ||
0b8765c6 | 6162 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6163 | { |
6164 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6165 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6166 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6167 | struct intel_encoder *encoder; |
79e53945 | 6168 | int pipe = intel_crtc->pipe; |
79e53945 | 6169 | |
53d9f4e9 | 6170 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6171 | return; |
6172 | ||
f13c2ef3 DV |
6173 | i9xx_set_pll_dividers(intel_crtc); |
6174 | ||
6e3c9717 | 6175 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6176 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6177 | |
6178 | intel_set_pipe_timings(intel_crtc); | |
6179 | ||
5b18e57c DV |
6180 | i9xx_set_pipeconf(intel_crtc); |
6181 | ||
f7abfe8b | 6182 | intel_crtc->active = true; |
6b383a7f | 6183 | |
4a3436e8 | 6184 | if (!IS_GEN2(dev)) |
a72e4c9f | 6185 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6186 | |
9d6d9f19 MK |
6187 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6188 | if (encoder->pre_enable) | |
6189 | encoder->pre_enable(encoder); | |
6190 | ||
f6736a1a DV |
6191 | i9xx_enable_pll(intel_crtc); |
6192 | ||
2dd24552 JB |
6193 | i9xx_pfit_enable(intel_crtc); |
6194 | ||
63cbb074 VS |
6195 | intel_crtc_load_lut(crtc); |
6196 | ||
f37fcc2a | 6197 | intel_update_watermarks(crtc); |
e1fdc473 | 6198 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6199 | |
4b3a9526 VS |
6200 | assert_vblank_disabled(crtc); |
6201 | drm_crtc_vblank_on(crtc); | |
6202 | ||
f9b61ff6 DV |
6203 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6204 | encoder->enable(encoder); | |
0b8765c6 | 6205 | } |
79e53945 | 6206 | |
87476d63 DV |
6207 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6208 | { | |
6209 | struct drm_device *dev = crtc->base.dev; | |
6210 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6211 | |
6e3c9717 | 6212 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6213 | return; |
87476d63 | 6214 | |
328d8e82 | 6215 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6216 | |
328d8e82 DV |
6217 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6218 | I915_READ(PFIT_CONTROL)); | |
6219 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6220 | } |
6221 | ||
0b8765c6 JB |
6222 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6223 | { | |
6224 | struct drm_device *dev = crtc->dev; | |
6225 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6226 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6227 | struct intel_encoder *encoder; |
0b8765c6 | 6228 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6229 | |
53d9f4e9 | 6230 | if (WARN_ON(!intel_crtc->active)) |
f7abfe8b CW |
6231 | return; |
6232 | ||
6304cd91 VS |
6233 | /* |
6234 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6235 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6236 | * We also need to wait on all gmch platforms because of the |
6237 | * self-refresh mode constraint explained above. | |
6304cd91 | 6238 | */ |
564ed191 | 6239 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6240 | |
4b3a9526 VS |
6241 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6242 | encoder->disable(encoder); | |
6243 | ||
f9b61ff6 DV |
6244 | drm_crtc_vblank_off(crtc); |
6245 | assert_vblank_disabled(crtc); | |
6246 | ||
575f7ab7 | 6247 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6248 | |
87476d63 | 6249 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6250 | |
89b667f8 JB |
6251 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6252 | if (encoder->post_disable) | |
6253 | encoder->post_disable(encoder); | |
6254 | ||
409ee761 | 6255 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6256 | if (IS_CHERRYVIEW(dev)) |
6257 | chv_disable_pll(dev_priv, pipe); | |
6258 | else if (IS_VALLEYVIEW(dev)) | |
6259 | vlv_disable_pll(dev_priv, pipe); | |
6260 | else | |
1c4e0274 | 6261 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6262 | } |
0b8765c6 | 6263 | |
4a3436e8 | 6264 | if (!IS_GEN2(dev)) |
a72e4c9f | 6265 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
4a3436e8 | 6266 | |
f7abfe8b | 6267 | intel_crtc->active = false; |
46ba614c | 6268 | intel_update_watermarks(crtc); |
f37fcc2a | 6269 | |
efa9624e | 6270 | mutex_lock(&dev->struct_mutex); |
7ff0ebcc | 6271 | intel_fbc_update(dev); |
efa9624e | 6272 | mutex_unlock(&dev->struct_mutex); |
0b8765c6 JB |
6273 | } |
6274 | ||
b17d48e2 ML |
6275 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6276 | { | |
6277 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6278 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6279 | enum intel_display_power_domain domain; | |
6280 | unsigned long domains; | |
6281 | ||
6282 | if (!intel_crtc->active) | |
6283 | return; | |
6284 | ||
d032ffa0 | 6285 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
b17d48e2 ML |
6286 | dev_priv->display.crtc_disable(crtc); |
6287 | ||
6288 | domains = intel_crtc->enabled_power_domains; | |
6289 | for_each_power_domain(domain, domains) | |
6290 | intel_display_power_put(dev_priv, domain); | |
6291 | intel_crtc->enabled_power_domains = 0; | |
6292 | } | |
6293 | ||
6b72d486 ML |
6294 | /* |
6295 | * turn all crtc's off, but do not adjust state | |
6296 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6297 | */ | |
9716c691 | 6298 | void intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6299 | { |
6b72d486 ML |
6300 | struct drm_crtc *crtc; |
6301 | ||
b17d48e2 ML |
6302 | for_each_crtc(dev, crtc) |
6303 | intel_crtc_disable_noatomic(crtc); | |
ee7b9f93 JB |
6304 | } |
6305 | ||
b04c5bd6 | 6306 | /* Master function to enable/disable CRTC and corresponding power wells */ |
5da76e94 | 6307 | int intel_crtc_control(struct drm_crtc *crtc, bool enable) |
976f8a20 DV |
6308 | { |
6309 | struct drm_device *dev = crtc->dev; | |
5da76e94 ML |
6310 | struct drm_mode_config *config = &dev->mode_config; |
6311 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
0e572fe7 | 6312 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5da76e94 ML |
6313 | struct intel_crtc_state *pipe_config; |
6314 | struct drm_atomic_state *state; | |
6315 | int ret; | |
976f8a20 | 6316 | |
1b509259 | 6317 | if (enable == intel_crtc->active) |
5da76e94 | 6318 | return 0; |
0e572fe7 | 6319 | |
1b509259 | 6320 | if (enable && !crtc->state->enable) |
5da76e94 | 6321 | return 0; |
1b509259 | 6322 | |
5da76e94 ML |
6323 | /* this function should be called with drm_modeset_lock_all for now */ |
6324 | if (WARN_ON(!ctx)) | |
6325 | return -EIO; | |
6326 | lockdep_assert_held(&ctx->ww_ctx); | |
1b509259 | 6327 | |
5da76e94 ML |
6328 | state = drm_atomic_state_alloc(dev); |
6329 | if (WARN_ON(!state)) | |
6330 | return -ENOMEM; | |
1b509259 | 6331 | |
5da76e94 ML |
6332 | state->acquire_ctx = ctx; |
6333 | state->allow_modeset = true; | |
6334 | ||
6335 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
6336 | if (IS_ERR(pipe_config)) { | |
6337 | ret = PTR_ERR(pipe_config); | |
6338 | goto err; | |
0e572fe7 | 6339 | } |
5da76e94 ML |
6340 | pipe_config->base.active = enable; |
6341 | ||
6342 | ret = intel_set_mode(state); | |
6343 | if (!ret) | |
6344 | return ret; | |
6345 | ||
6346 | err: | |
6347 | DRM_ERROR("Updating crtc active failed with %i\n", ret); | |
6348 | drm_atomic_state_free(state); | |
6349 | return ret; | |
b04c5bd6 BF |
6350 | } |
6351 | ||
6352 | /** | |
6353 | * Sets the power management mode of the pipe and plane. | |
6354 | */ | |
6355 | void intel_crtc_update_dpms(struct drm_crtc *crtc) | |
6356 | { | |
6357 | struct drm_device *dev = crtc->dev; | |
6358 | struct intel_encoder *intel_encoder; | |
6359 | bool enable = false; | |
6360 | ||
6361 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) | |
6362 | enable |= intel_encoder->connectors_active; | |
6363 | ||
6364 | intel_crtc_control(crtc, enable); | |
cdd59983 CW |
6365 | } |
6366 | ||
ea5b213a | 6367 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6368 | { |
4ef69c7a | 6369 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6370 | |
ea5b213a CW |
6371 | drm_encoder_cleanup(encoder); |
6372 | kfree(intel_encoder); | |
7e7d76c3 JB |
6373 | } |
6374 | ||
9237329d | 6375 | /* Simple dpms helper for encoders with just one connector, no cloning and only |
5ab432ef DV |
6376 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
6377 | * state of the entire output pipe. */ | |
9237329d | 6378 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
7e7d76c3 | 6379 | { |
5ab432ef DV |
6380 | if (mode == DRM_MODE_DPMS_ON) { |
6381 | encoder->connectors_active = true; | |
6382 | ||
b2cabb0e | 6383 | intel_crtc_update_dpms(encoder->base.crtc); |
5ab432ef DV |
6384 | } else { |
6385 | encoder->connectors_active = false; | |
6386 | ||
b2cabb0e | 6387 | intel_crtc_update_dpms(encoder->base.crtc); |
5ab432ef | 6388 | } |
79e53945 JB |
6389 | } |
6390 | ||
0a91ca29 DV |
6391 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6392 | * internal consistency). */ | |
b980514c | 6393 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6394 | { |
0a91ca29 DV |
6395 | if (connector->get_hw_state(connector)) { |
6396 | struct intel_encoder *encoder = connector->encoder; | |
6397 | struct drm_crtc *crtc; | |
6398 | bool encoder_enabled; | |
6399 | enum pipe pipe; | |
6400 | ||
6401 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6402 | connector->base.base.id, | |
c23cc417 | 6403 | connector->base.name); |
0a91ca29 | 6404 | |
0e32b39c DA |
6405 | /* there is no real hw state for MST connectors */ |
6406 | if (connector->mst_port) | |
6407 | return; | |
6408 | ||
e2c719b7 | 6409 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
0a91ca29 | 6410 | "wrong connector dpms state\n"); |
e2c719b7 | 6411 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
0a91ca29 | 6412 | "active connector not linked to encoder\n"); |
0a91ca29 | 6413 | |
36cd7444 | 6414 | if (encoder) { |
e2c719b7 | 6415 | I915_STATE_WARN(!encoder->connectors_active, |
36cd7444 DA |
6416 | "encoder->connectors_active not set\n"); |
6417 | ||
6418 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); | |
e2c719b7 RC |
6419 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
6420 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) | |
36cd7444 | 6421 | return; |
0a91ca29 | 6422 | |
36cd7444 | 6423 | crtc = encoder->base.crtc; |
0a91ca29 | 6424 | |
83d65738 MR |
6425 | I915_STATE_WARN(!crtc->state->enable, |
6426 | "crtc not enabled\n"); | |
e2c719b7 RC |
6427 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
6428 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, | |
36cd7444 DA |
6429 | "encoder active on the wrong pipe\n"); |
6430 | } | |
0a91ca29 | 6431 | } |
79e53945 JB |
6432 | } |
6433 | ||
08d9bc92 ACO |
6434 | int intel_connector_init(struct intel_connector *connector) |
6435 | { | |
6436 | struct drm_connector_state *connector_state; | |
6437 | ||
6438 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6439 | if (!connector_state) | |
6440 | return -ENOMEM; | |
6441 | ||
6442 | connector->base.state = connector_state; | |
6443 | return 0; | |
6444 | } | |
6445 | ||
6446 | struct intel_connector *intel_connector_alloc(void) | |
6447 | { | |
6448 | struct intel_connector *connector; | |
6449 | ||
6450 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6451 | if (!connector) | |
6452 | return NULL; | |
6453 | ||
6454 | if (intel_connector_init(connector) < 0) { | |
6455 | kfree(connector); | |
6456 | return NULL; | |
6457 | } | |
6458 | ||
6459 | return connector; | |
6460 | } | |
6461 | ||
5ab432ef DV |
6462 | /* Even simpler default implementation, if there's really no special case to |
6463 | * consider. */ | |
6464 | void intel_connector_dpms(struct drm_connector *connector, int mode) | |
79e53945 | 6465 | { |
5ab432ef DV |
6466 | /* All the simple cases only support two dpms states. */ |
6467 | if (mode != DRM_MODE_DPMS_ON) | |
6468 | mode = DRM_MODE_DPMS_OFF; | |
d4270e57 | 6469 | |
5ab432ef DV |
6470 | if (mode == connector->dpms) |
6471 | return; | |
6472 | ||
6473 | connector->dpms = mode; | |
6474 | ||
6475 | /* Only need to change hw state when actually enabled */ | |
c9976dcf CW |
6476 | if (connector->encoder) |
6477 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); | |
0a91ca29 | 6478 | |
b980514c | 6479 | intel_modeset_check_state(connector->dev); |
79e53945 JB |
6480 | } |
6481 | ||
f0947c37 DV |
6482 | /* Simple connector->get_hw_state implementation for encoders that support only |
6483 | * one connector and no cloning and hence the encoder state determines the state | |
6484 | * of the connector. */ | |
6485 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6486 | { |
24929352 | 6487 | enum pipe pipe = 0; |
f0947c37 | 6488 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6489 | |
f0947c37 | 6490 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6491 | } |
6492 | ||
6d293983 | 6493 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6494 | { |
6d293983 ACO |
6495 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6496 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6497 | |
6498 | return 0; | |
6499 | } | |
6500 | ||
6d293983 | 6501 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6502 | struct intel_crtc_state *pipe_config) |
1857e1da | 6503 | { |
6d293983 ACO |
6504 | struct drm_atomic_state *state = pipe_config->base.state; |
6505 | struct intel_crtc *other_crtc; | |
6506 | struct intel_crtc_state *other_crtc_state; | |
6507 | ||
1857e1da DV |
6508 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6509 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6510 | if (pipe_config->fdi_lanes > 4) { | |
6511 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6512 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6513 | return -EINVAL; |
1857e1da DV |
6514 | } |
6515 | ||
bafb6553 | 6516 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6517 | if (pipe_config->fdi_lanes > 2) { |
6518 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6519 | pipe_config->fdi_lanes); | |
6d293983 | 6520 | return -EINVAL; |
1857e1da | 6521 | } else { |
6d293983 | 6522 | return 0; |
1857e1da DV |
6523 | } |
6524 | } | |
6525 | ||
6526 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6527 | return 0; |
1857e1da DV |
6528 | |
6529 | /* Ivybridge 3 pipe is really complicated */ | |
6530 | switch (pipe) { | |
6531 | case PIPE_A: | |
6d293983 | 6532 | return 0; |
1857e1da | 6533 | case PIPE_B: |
6d293983 ACO |
6534 | if (pipe_config->fdi_lanes <= 2) |
6535 | return 0; | |
6536 | ||
6537 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6538 | other_crtc_state = | |
6539 | intel_atomic_get_crtc_state(state, other_crtc); | |
6540 | if (IS_ERR(other_crtc_state)) | |
6541 | return PTR_ERR(other_crtc_state); | |
6542 | ||
6543 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6544 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6545 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6546 | return -EINVAL; |
1857e1da | 6547 | } |
6d293983 | 6548 | return 0; |
1857e1da | 6549 | case PIPE_C: |
251cc67c VS |
6550 | if (pipe_config->fdi_lanes > 2) { |
6551 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6552 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6553 | return -EINVAL; |
251cc67c | 6554 | } |
6d293983 ACO |
6555 | |
6556 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6557 | other_crtc_state = | |
6558 | intel_atomic_get_crtc_state(state, other_crtc); | |
6559 | if (IS_ERR(other_crtc_state)) | |
6560 | return PTR_ERR(other_crtc_state); | |
6561 | ||
6562 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6563 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6564 | return -EINVAL; |
1857e1da | 6565 | } |
6d293983 | 6566 | return 0; |
1857e1da DV |
6567 | default: |
6568 | BUG(); | |
6569 | } | |
6570 | } | |
6571 | ||
e29c22c0 DV |
6572 | #define RETRY 1 |
6573 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6574 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6575 | { |
1857e1da | 6576 | struct drm_device *dev = intel_crtc->base.dev; |
2d112de7 | 6577 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6578 | int lane, link_bw, fdi_dotclock, ret; |
6579 | bool needs_recompute = false; | |
877d48d5 | 6580 | |
e29c22c0 | 6581 | retry: |
877d48d5 DV |
6582 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6583 | * each output octet as 10 bits. The actual frequency | |
6584 | * is stored as a divider into a 100MHz clock, and the | |
6585 | * mode pixel clock is stored in units of 1KHz. | |
6586 | * Hence the bw of each lane in terms of the mode signal | |
6587 | * is: | |
6588 | */ | |
6589 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6590 | ||
241bfc38 | 6591 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6592 | |
2bd89a07 | 6593 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6594 | pipe_config->pipe_bpp); |
6595 | ||
6596 | pipe_config->fdi_lanes = lane; | |
6597 | ||
2bd89a07 | 6598 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6599 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6600 | |
6d293983 ACO |
6601 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6602 | intel_crtc->pipe, pipe_config); | |
6603 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6604 | pipe_config->pipe_bpp -= 2*3; |
6605 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6606 | pipe_config->pipe_bpp); | |
6607 | needs_recompute = true; | |
6608 | pipe_config->bw_constrained = true; | |
6609 | ||
6610 | goto retry; | |
6611 | } | |
6612 | ||
6613 | if (needs_recompute) | |
6614 | return RETRY; | |
6615 | ||
6d293983 | 6616 | return ret; |
877d48d5 DV |
6617 | } |
6618 | ||
8cfb3407 VS |
6619 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6620 | struct intel_crtc_state *pipe_config) | |
6621 | { | |
6622 | if (pipe_config->pipe_bpp > 24) | |
6623 | return false; | |
6624 | ||
6625 | /* HSW can handle pixel rate up to cdclk? */ | |
6626 | if (IS_HASWELL(dev_priv->dev)) | |
6627 | return true; | |
6628 | ||
6629 | /* | |
b432e5cf VS |
6630 | * We compare against max which means we must take |
6631 | * the increased cdclk requirement into account when | |
6632 | * calculating the new cdclk. | |
6633 | * | |
6634 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6635 | */ |
6636 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6637 | dev_priv->max_cdclk_freq * 95 / 100; | |
6638 | } | |
6639 | ||
42db64ef | 6640 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6641 | struct intel_crtc_state *pipe_config) |
42db64ef | 6642 | { |
8cfb3407 VS |
6643 | struct drm_device *dev = crtc->base.dev; |
6644 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6645 | ||
d330a953 | 6646 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6647 | hsw_crtc_supports_ips(crtc) && |
6648 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6649 | } |
6650 | ||
a43f6e0f | 6651 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6652 | struct intel_crtc_state *pipe_config) |
79e53945 | 6653 | { |
a43f6e0f | 6654 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6655 | struct drm_i915_private *dev_priv = dev->dev_private; |
2d112de7 | 6656 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6657 | |
ad3a4479 | 6658 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6659 | if (INTEL_INFO(dev)->gen < 4) { |
44913155 | 6660 | int clock_limit = dev_priv->max_cdclk_freq; |
cf532bb2 VS |
6661 | |
6662 | /* | |
6663 | * Enable pixel doubling when the dot clock | |
6664 | * is > 90% of the (display) core speed. | |
6665 | * | |
b397c96b VS |
6666 | * GDG double wide on either pipe, |
6667 | * otherwise pipe A only. | |
cf532bb2 | 6668 | */ |
b397c96b | 6669 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
241bfc38 | 6670 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
ad3a4479 | 6671 | clock_limit *= 2; |
cf532bb2 | 6672 | pipe_config->double_wide = true; |
ad3a4479 VS |
6673 | } |
6674 | ||
241bfc38 | 6675 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
e29c22c0 | 6676 | return -EINVAL; |
2c07245f | 6677 | } |
89749350 | 6678 | |
1d1d0e27 VS |
6679 | /* |
6680 | * Pipe horizontal size must be even in: | |
6681 | * - DVO ganged mode | |
6682 | * - LVDS dual channel mode | |
6683 | * - Double wide pipe | |
6684 | */ | |
a93e255f | 6685 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6686 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6687 | pipe_config->pipe_src_w &= ~1; | |
6688 | ||
8693a824 DL |
6689 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6690 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6691 | */ |
6692 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
6693 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) | |
e29c22c0 | 6694 | return -EINVAL; |
44f46b42 | 6695 | |
f5adf94e | 6696 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6697 | hsw_compute_ips_config(crtc, pipe_config); |
6698 | ||
877d48d5 | 6699 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6700 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6701 | |
cf5a15be | 6702 | return 0; |
79e53945 JB |
6703 | } |
6704 | ||
1652d19e VS |
6705 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6706 | { | |
6707 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6708 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6709 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6710 | uint32_t linkrate; | |
6711 | ||
414355a7 | 6712 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6713 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6714 | |
6715 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6716 | return 540000; | |
6717 | ||
6718 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6719 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6720 | |
71cd8423 DL |
6721 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6722 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6723 | /* vco 8640 */ |
6724 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6725 | case CDCLK_FREQ_450_432: | |
6726 | return 432000; | |
6727 | case CDCLK_FREQ_337_308: | |
6728 | return 308570; | |
6729 | case CDCLK_FREQ_675_617: | |
6730 | return 617140; | |
6731 | default: | |
6732 | WARN(1, "Unknown cd freq selection\n"); | |
6733 | } | |
6734 | } else { | |
6735 | /* vco 8100 */ | |
6736 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6737 | case CDCLK_FREQ_450_432: | |
6738 | return 450000; | |
6739 | case CDCLK_FREQ_337_308: | |
6740 | return 337500; | |
6741 | case CDCLK_FREQ_675_617: | |
6742 | return 675000; | |
6743 | default: | |
6744 | WARN(1, "Unknown cd freq selection\n"); | |
6745 | } | |
6746 | } | |
6747 | ||
6748 | /* error case, do as if DPLL0 isn't enabled */ | |
6749 | return 24000; | |
6750 | } | |
6751 | ||
6752 | static int broadwell_get_display_clock_speed(struct drm_device *dev) | |
6753 | { | |
6754 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6755 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6756 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6757 | ||
6758 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6759 | return 800000; | |
6760 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6761 | return 450000; | |
6762 | else if (freq == LCPLL_CLK_FREQ_450) | |
6763 | return 450000; | |
6764 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6765 | return 540000; | |
6766 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6767 | return 337500; | |
6768 | else | |
6769 | return 675000; | |
6770 | } | |
6771 | ||
6772 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6773 | { | |
6774 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6775 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6776 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6777 | ||
6778 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6779 | return 800000; | |
6780 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6781 | return 450000; | |
6782 | else if (freq == LCPLL_CLK_FREQ_450) | |
6783 | return 450000; | |
6784 | else if (IS_HSW_ULT(dev)) | |
6785 | return 337500; | |
6786 | else | |
6787 | return 540000; | |
79e53945 JB |
6788 | } |
6789 | ||
25eb05fc JB |
6790 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6791 | { | |
d197b7d3 | 6792 | struct drm_i915_private *dev_priv = dev->dev_private; |
d197b7d3 VS |
6793 | u32 val; |
6794 | int divider; | |
6795 | ||
6bcda4f0 VS |
6796 | if (dev_priv->hpll_freq == 0) |
6797 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
6798 | ||
a580516d | 6799 | mutex_lock(&dev_priv->sb_lock); |
d197b7d3 | 6800 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
a580516d | 6801 | mutex_unlock(&dev_priv->sb_lock); |
d197b7d3 VS |
6802 | |
6803 | divider = val & DISPLAY_FREQUENCY_VALUES; | |
6804 | ||
7d007f40 VS |
6805 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
6806 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
6807 | "cdclk change in progress\n"); | |
6808 | ||
6bcda4f0 | 6809 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
25eb05fc JB |
6810 | } |
6811 | ||
b37a6434 VS |
6812 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6813 | { | |
6814 | return 450000; | |
6815 | } | |
6816 | ||
e70236a8 JB |
6817 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6818 | { | |
6819 | return 400000; | |
6820 | } | |
79e53945 | 6821 | |
e70236a8 | 6822 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6823 | { |
e907f170 | 6824 | return 333333; |
e70236a8 | 6825 | } |
79e53945 | 6826 | |
e70236a8 JB |
6827 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6828 | { | |
6829 | return 200000; | |
6830 | } | |
79e53945 | 6831 | |
257a7ffc DV |
6832 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6833 | { | |
6834 | u16 gcfgc = 0; | |
6835 | ||
6836 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6837 | ||
6838 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6839 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6840 | return 266667; |
257a7ffc | 6841 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6842 | return 333333; |
257a7ffc | 6843 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6844 | return 444444; |
257a7ffc DV |
6845 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6846 | return 200000; | |
6847 | default: | |
6848 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6849 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6850 | return 133333; |
257a7ffc | 6851 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6852 | return 166667; |
257a7ffc DV |
6853 | } |
6854 | } | |
6855 | ||
e70236a8 JB |
6856 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6857 | { | |
6858 | u16 gcfgc = 0; | |
79e53945 | 6859 | |
e70236a8 JB |
6860 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6861 | ||
6862 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6863 | return 133333; |
e70236a8 JB |
6864 | else { |
6865 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6866 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6867 | return 333333; |
e70236a8 JB |
6868 | default: |
6869 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6870 | return 190000; | |
79e53945 | 6871 | } |
e70236a8 JB |
6872 | } |
6873 | } | |
6874 | ||
6875 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6876 | { | |
e907f170 | 6877 | return 266667; |
e70236a8 JB |
6878 | } |
6879 | ||
1b1d2716 | 6880 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6881 | { |
6882 | u16 hpllcc = 0; | |
1b1d2716 | 6883 | |
65cd2b3f VS |
6884 | /* |
6885 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6886 | * encoding is different :( | |
6887 | * FIXME is this the right way to detect 852GM/852GMV? | |
6888 | */ | |
6889 | if (dev->pdev->revision == 0x1) | |
6890 | return 133333; | |
6891 | ||
1b1d2716 VS |
6892 | pci_bus_read_config_word(dev->pdev->bus, |
6893 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6894 | ||
e70236a8 JB |
6895 | /* Assume that the hardware is in the high speed state. This |
6896 | * should be the default. | |
6897 | */ | |
6898 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6899 | case GC_CLOCK_133_200: | |
1b1d2716 | 6900 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6901 | case GC_CLOCK_100_200: |
6902 | return 200000; | |
6903 | case GC_CLOCK_166_250: | |
6904 | return 250000; | |
6905 | case GC_CLOCK_100_133: | |
e907f170 | 6906 | return 133333; |
1b1d2716 VS |
6907 | case GC_CLOCK_133_266: |
6908 | case GC_CLOCK_133_266_2: | |
6909 | case GC_CLOCK_166_266: | |
6910 | return 266667; | |
e70236a8 | 6911 | } |
79e53945 | 6912 | |
e70236a8 JB |
6913 | /* Shouldn't happen */ |
6914 | return 0; | |
6915 | } | |
79e53945 | 6916 | |
e70236a8 JB |
6917 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6918 | { | |
e907f170 | 6919 | return 133333; |
79e53945 JB |
6920 | } |
6921 | ||
34edce2f VS |
6922 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6923 | { | |
6924 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6925 | static const unsigned int blb_vco[8] = { | |
6926 | [0] = 3200000, | |
6927 | [1] = 4000000, | |
6928 | [2] = 5333333, | |
6929 | [3] = 4800000, | |
6930 | [4] = 6400000, | |
6931 | }; | |
6932 | static const unsigned int pnv_vco[8] = { | |
6933 | [0] = 3200000, | |
6934 | [1] = 4000000, | |
6935 | [2] = 5333333, | |
6936 | [3] = 4800000, | |
6937 | [4] = 2666667, | |
6938 | }; | |
6939 | static const unsigned int cl_vco[8] = { | |
6940 | [0] = 3200000, | |
6941 | [1] = 4000000, | |
6942 | [2] = 5333333, | |
6943 | [3] = 6400000, | |
6944 | [4] = 3333333, | |
6945 | [5] = 3566667, | |
6946 | [6] = 4266667, | |
6947 | }; | |
6948 | static const unsigned int elk_vco[8] = { | |
6949 | [0] = 3200000, | |
6950 | [1] = 4000000, | |
6951 | [2] = 5333333, | |
6952 | [3] = 4800000, | |
6953 | }; | |
6954 | static const unsigned int ctg_vco[8] = { | |
6955 | [0] = 3200000, | |
6956 | [1] = 4000000, | |
6957 | [2] = 5333333, | |
6958 | [3] = 6400000, | |
6959 | [4] = 2666667, | |
6960 | [5] = 4266667, | |
6961 | }; | |
6962 | const unsigned int *vco_table; | |
6963 | unsigned int vco; | |
6964 | uint8_t tmp = 0; | |
6965 | ||
6966 | /* FIXME other chipsets? */ | |
6967 | if (IS_GM45(dev)) | |
6968 | vco_table = ctg_vco; | |
6969 | else if (IS_G4X(dev)) | |
6970 | vco_table = elk_vco; | |
6971 | else if (IS_CRESTLINE(dev)) | |
6972 | vco_table = cl_vco; | |
6973 | else if (IS_PINEVIEW(dev)) | |
6974 | vco_table = pnv_vco; | |
6975 | else if (IS_G33(dev)) | |
6976 | vco_table = blb_vco; | |
6977 | else | |
6978 | return 0; | |
6979 | ||
6980 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6981 | ||
6982 | vco = vco_table[tmp & 0x7]; | |
6983 | if (vco == 0) | |
6984 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6985 | else | |
6986 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6987 | ||
6988 | return vco; | |
6989 | } | |
6990 | ||
6991 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
6992 | { | |
6993 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6994 | uint16_t tmp = 0; | |
6995 | ||
6996 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6997 | ||
6998 | cdclk_sel = (tmp >> 12) & 0x1; | |
6999 | ||
7000 | switch (vco) { | |
7001 | case 2666667: | |
7002 | case 4000000: | |
7003 | case 5333333: | |
7004 | return cdclk_sel ? 333333 : 222222; | |
7005 | case 3200000: | |
7006 | return cdclk_sel ? 320000 : 228571; | |
7007 | default: | |
7008 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
7009 | return 222222; | |
7010 | } | |
7011 | } | |
7012 | ||
7013 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
7014 | { | |
7015 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
7016 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
7017 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
7018 | const uint8_t *div_table; | |
7019 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7020 | uint16_t tmp = 0; | |
7021 | ||
7022 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7023 | ||
7024 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
7025 | ||
7026 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7027 | goto fail; | |
7028 | ||
7029 | switch (vco) { | |
7030 | case 3200000: | |
7031 | div_table = div_3200; | |
7032 | break; | |
7033 | case 4000000: | |
7034 | div_table = div_4000; | |
7035 | break; | |
7036 | case 5333333: | |
7037 | div_table = div_5333; | |
7038 | break; | |
7039 | default: | |
7040 | goto fail; | |
7041 | } | |
7042 | ||
7043 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7044 | ||
caf4e252 | 7045 | fail: |
34edce2f VS |
7046 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
7047 | return 200000; | |
7048 | } | |
7049 | ||
7050 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
7051 | { | |
7052 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
7053 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
7054 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
7055 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
7056 | const uint8_t *div_table; | |
7057 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7058 | uint16_t tmp = 0; | |
7059 | ||
7060 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7061 | ||
7062 | cdclk_sel = (tmp >> 4) & 0x7; | |
7063 | ||
7064 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7065 | goto fail; | |
7066 | ||
7067 | switch (vco) { | |
7068 | case 3200000: | |
7069 | div_table = div_3200; | |
7070 | break; | |
7071 | case 4000000: | |
7072 | div_table = div_4000; | |
7073 | break; | |
7074 | case 4800000: | |
7075 | div_table = div_4800; | |
7076 | break; | |
7077 | case 5333333: | |
7078 | div_table = div_5333; | |
7079 | break; | |
7080 | default: | |
7081 | goto fail; | |
7082 | } | |
7083 | ||
7084 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7085 | ||
caf4e252 | 7086 | fail: |
34edce2f VS |
7087 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7088 | return 190476; | |
7089 | } | |
7090 | ||
2c07245f | 7091 | static void |
a65851af | 7092 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7093 | { |
a65851af VS |
7094 | while (*num > DATA_LINK_M_N_MASK || |
7095 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7096 | *num >>= 1; |
7097 | *den >>= 1; | |
7098 | } | |
7099 | } | |
7100 | ||
a65851af VS |
7101 | static void compute_m_n(unsigned int m, unsigned int n, |
7102 | uint32_t *ret_m, uint32_t *ret_n) | |
7103 | { | |
7104 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7105 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7106 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7107 | } | |
7108 | ||
e69d0bc1 DV |
7109 | void |
7110 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7111 | int pixel_clock, int link_clock, | |
7112 | struct intel_link_m_n *m_n) | |
2c07245f | 7113 | { |
e69d0bc1 | 7114 | m_n->tu = 64; |
a65851af VS |
7115 | |
7116 | compute_m_n(bits_per_pixel * pixel_clock, | |
7117 | link_clock * nlanes * 8, | |
7118 | &m_n->gmch_m, &m_n->gmch_n); | |
7119 | ||
7120 | compute_m_n(pixel_clock, link_clock, | |
7121 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7122 | } |
7123 | ||
a7615030 CW |
7124 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7125 | { | |
d330a953 JN |
7126 | if (i915.panel_use_ssc >= 0) |
7127 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7128 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7129 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7130 | } |
7131 | ||
a93e255f ACO |
7132 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7133 | int num_connectors) | |
c65d77d8 | 7134 | { |
a93e255f | 7135 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7136 | struct drm_i915_private *dev_priv = dev->dev_private; |
7137 | int refclk; | |
7138 | ||
a93e255f ACO |
7139 | WARN_ON(!crtc_state->base.state); |
7140 | ||
5ab7b0b7 | 7141 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7142 | refclk = 100000; |
a93e255f | 7143 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7144 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7145 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7146 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7147 | } else if (!IS_GEN2(dev)) { |
7148 | refclk = 96000; | |
7149 | } else { | |
7150 | refclk = 48000; | |
7151 | } | |
7152 | ||
7153 | return refclk; | |
7154 | } | |
7155 | ||
7429e9d4 | 7156 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7157 | { |
7df00d7a | 7158 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7159 | } |
f47709a9 | 7160 | |
7429e9d4 DV |
7161 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7162 | { | |
7163 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7164 | } |
7165 | ||
f47709a9 | 7166 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7167 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7168 | intel_clock_t *reduced_clock) |
7169 | { | |
f47709a9 | 7170 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7171 | u32 fp, fp2 = 0; |
7172 | ||
7173 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7174 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7175 | if (reduced_clock) |
7429e9d4 | 7176 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7177 | } else { |
190f68c5 | 7178 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7179 | if (reduced_clock) |
7429e9d4 | 7180 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7181 | } |
7182 | ||
190f68c5 | 7183 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7184 | |
f47709a9 | 7185 | crtc->lowfreq_avail = false; |
a93e255f | 7186 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7187 | reduced_clock) { |
190f68c5 | 7188 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7189 | crtc->lowfreq_avail = true; |
a7516a05 | 7190 | } else { |
190f68c5 | 7191 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7192 | } |
7193 | } | |
7194 | ||
5e69f97f CML |
7195 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7196 | pipe) | |
89b667f8 JB |
7197 | { |
7198 | u32 reg_val; | |
7199 | ||
7200 | /* | |
7201 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7202 | * and set it to a reasonable value instead. | |
7203 | */ | |
ab3c759a | 7204 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7205 | reg_val &= 0xffffff00; |
7206 | reg_val |= 0x00000030; | |
ab3c759a | 7207 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7208 | |
ab3c759a | 7209 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7210 | reg_val &= 0x8cffffff; |
7211 | reg_val = 0x8c000000; | |
ab3c759a | 7212 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7213 | |
ab3c759a | 7214 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7215 | reg_val &= 0xffffff00; |
ab3c759a | 7216 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7217 | |
ab3c759a | 7218 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7219 | reg_val &= 0x00ffffff; |
7220 | reg_val |= 0xb0000000; | |
ab3c759a | 7221 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7222 | } |
7223 | ||
b551842d DV |
7224 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7225 | struct intel_link_m_n *m_n) | |
7226 | { | |
7227 | struct drm_device *dev = crtc->base.dev; | |
7228 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7229 | int pipe = crtc->pipe; | |
7230 | ||
e3b95f1e DV |
7231 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7232 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7233 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7234 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7235 | } |
7236 | ||
7237 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7238 | struct intel_link_m_n *m_n, |
7239 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7240 | { |
7241 | struct drm_device *dev = crtc->base.dev; | |
7242 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7243 | int pipe = crtc->pipe; | |
6e3c9717 | 7244 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7245 | |
7246 | if (INTEL_INFO(dev)->gen >= 5) { | |
7247 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7248 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7249 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7250 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7251 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7252 | * for gen < 8) and if DRRS is supported (to make sure the | |
7253 | * registers are not unnecessarily accessed). | |
7254 | */ | |
44395bfe | 7255 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7256 | crtc->config->has_drrs) { |
f769cd24 VK |
7257 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7258 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7259 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7260 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7261 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7262 | } | |
b551842d | 7263 | } else { |
e3b95f1e DV |
7264 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7265 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7266 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7267 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7268 | } |
7269 | } | |
7270 | ||
fe3cd48d | 7271 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7272 | { |
fe3cd48d R |
7273 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7274 | ||
7275 | if (m_n == M1_N1) { | |
7276 | dp_m_n = &crtc->config->dp_m_n; | |
7277 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7278 | } else if (m_n == M2_N2) { | |
7279 | ||
7280 | /* | |
7281 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7282 | * needs to be programmed into M1_N1. | |
7283 | */ | |
7284 | dp_m_n = &crtc->config->dp_m2_n2; | |
7285 | } else { | |
7286 | DRM_ERROR("Unsupported divider value\n"); | |
7287 | return; | |
7288 | } | |
7289 | ||
6e3c9717 ACO |
7290 | if (crtc->config->has_pch_encoder) |
7291 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7292 | else |
fe3cd48d | 7293 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7294 | } |
7295 | ||
d288f65f | 7296 | static void vlv_update_pll(struct intel_crtc *crtc, |
5cec258b | 7297 | struct intel_crtc_state *pipe_config) |
bdd4b6a6 DV |
7298 | { |
7299 | u32 dpll, dpll_md; | |
7300 | ||
7301 | /* | |
7302 | * Enable DPIO clock input. We should never disable the reference | |
7303 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7304 | * on it. | |
7305 | */ | |
7306 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | | |
7307 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; | |
7308 | /* We should never disable this, set it here for state tracking */ | |
7309 | if (crtc->pipe == PIPE_B) | |
7310 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7311 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7312 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7313 | |
d288f65f | 7314 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7315 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7316 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7317 | } |
7318 | ||
d288f65f | 7319 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7320 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7321 | { |
f47709a9 | 7322 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7323 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7324 | int pipe = crtc->pipe; |
bdd4b6a6 | 7325 | u32 mdiv; |
a0c4da24 | 7326 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7327 | u32 coreclk, reg_val; |
a0c4da24 | 7328 | |
a580516d | 7329 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7330 | |
d288f65f VS |
7331 | bestn = pipe_config->dpll.n; |
7332 | bestm1 = pipe_config->dpll.m1; | |
7333 | bestm2 = pipe_config->dpll.m2; | |
7334 | bestp1 = pipe_config->dpll.p1; | |
7335 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7336 | |
89b667f8 JB |
7337 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7338 | ||
7339 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7340 | if (pipe == PIPE_B) |
5e69f97f | 7341 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7342 | |
7343 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7344 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7345 | |
7346 | /* Disable target IRef on PLL */ | |
ab3c759a | 7347 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7348 | reg_val &= 0x00ffffff; |
ab3c759a | 7349 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7350 | |
7351 | /* Disable fast lock */ | |
ab3c759a | 7352 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7353 | |
7354 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7355 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7356 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7357 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7358 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7359 | |
7360 | /* | |
7361 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7362 | * but we don't support that). | |
7363 | * Note: don't use the DAC post divider as it seems unstable. | |
7364 | */ | |
7365 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7366 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7367 | |
a0c4da24 | 7368 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7369 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7370 | |
89b667f8 | 7371 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7372 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7373 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7374 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7375 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7376 | 0x009f0003); |
89b667f8 | 7377 | else |
ab3c759a | 7378 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7379 | 0x00d0000f); |
7380 | ||
681a8504 | 7381 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7382 | /* Use SSC source */ |
bdd4b6a6 | 7383 | if (pipe == PIPE_A) |
ab3c759a | 7384 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7385 | 0x0df40000); |
7386 | else | |
ab3c759a | 7387 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7388 | 0x0df70000); |
7389 | } else { /* HDMI or VGA */ | |
7390 | /* Use bend source */ | |
bdd4b6a6 | 7391 | if (pipe == PIPE_A) |
ab3c759a | 7392 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7393 | 0x0df70000); |
7394 | else | |
ab3c759a | 7395 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7396 | 0x0df40000); |
7397 | } | |
a0c4da24 | 7398 | |
ab3c759a | 7399 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7400 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7401 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7402 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7403 | coreclk |= 0x01000000; |
ab3c759a | 7404 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7405 | |
ab3c759a | 7406 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7407 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7408 | } |
7409 | ||
d288f65f | 7410 | static void chv_update_pll(struct intel_crtc *crtc, |
5cec258b | 7411 | struct intel_crtc_state *pipe_config) |
1ae0d137 | 7412 | { |
d288f65f | 7413 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
1ae0d137 VS |
7414 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
7415 | DPLL_VCO_ENABLE; | |
7416 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7417 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7418 | |
d288f65f VS |
7419 | pipe_config->dpll_hw_state.dpll_md = |
7420 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7421 | } |
7422 | ||
d288f65f | 7423 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7424 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7425 | { |
7426 | struct drm_device *dev = crtc->base.dev; | |
7427 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7428 | int pipe = crtc->pipe; | |
7429 | int dpll_reg = DPLL(crtc->pipe); | |
7430 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 7431 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7432 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7433 | u32 dpio_val; |
9cbe40c1 | 7434 | int vco; |
9d556c99 | 7435 | |
d288f65f VS |
7436 | bestn = pipe_config->dpll.n; |
7437 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7438 | bestm1 = pipe_config->dpll.m1; | |
7439 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7440 | bestp1 = pipe_config->dpll.p1; | |
7441 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7442 | vco = pipe_config->dpll.vco; |
a945ce7e | 7443 | dpio_val = 0; |
9cbe40c1 | 7444 | loopfilter = 0; |
9d556c99 CML |
7445 | |
7446 | /* | |
7447 | * Enable Refclk and SSC | |
7448 | */ | |
a11b0703 | 7449 | I915_WRITE(dpll_reg, |
d288f65f | 7450 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7451 | |
a580516d | 7452 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7453 | |
9d556c99 CML |
7454 | /* p1 and p2 divider */ |
7455 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7456 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7457 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7458 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7459 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7460 | ||
7461 | /* Feedback post-divider - m2 */ | |
7462 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7463 | ||
7464 | /* Feedback refclk divider - n and m1 */ | |
7465 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7466 | DPIO_CHV_M1_DIV_BY_2 | | |
7467 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7468 | ||
7469 | /* M2 fraction division */ | |
a945ce7e VP |
7470 | if (bestm2_frac) |
7471 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); | |
9d556c99 CML |
7472 | |
7473 | /* M2 fraction division enable */ | |
a945ce7e VP |
7474 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7475 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7476 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7477 | if (bestm2_frac) | |
7478 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7479 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7480 | |
de3a0fde VP |
7481 | /* Program digital lock detect threshold */ |
7482 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7483 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7484 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7485 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7486 | if (!bestm2_frac) | |
7487 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7488 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7489 | ||
9d556c99 | 7490 | /* Loop filter */ |
9cbe40c1 VP |
7491 | if (vco == 5400000) { |
7492 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7493 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7494 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7495 | tribuf_calcntr = 0x9; | |
7496 | } else if (vco <= 6200000) { | |
7497 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7498 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7499 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7500 | tribuf_calcntr = 0x9; | |
7501 | } else if (vco <= 6480000) { | |
7502 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7503 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7504 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7505 | tribuf_calcntr = 0x8; | |
7506 | } else { | |
7507 | /* Not supported. Apply the same limits as in the max case */ | |
7508 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7509 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7510 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7511 | tribuf_calcntr = 0; | |
7512 | } | |
9d556c99 CML |
7513 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7514 | ||
968040b2 | 7515 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7516 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7517 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7518 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7519 | ||
9d556c99 CML |
7520 | /* AFC Recal */ |
7521 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7522 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7523 | DPIO_AFC_RECAL); | |
7524 | ||
a580516d | 7525 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7526 | } |
7527 | ||
d288f65f VS |
7528 | /** |
7529 | * vlv_force_pll_on - forcibly enable just the PLL | |
7530 | * @dev_priv: i915 private structure | |
7531 | * @pipe: pipe PLL to enable | |
7532 | * @dpll: PLL configuration | |
7533 | * | |
7534 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7535 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7536 | * be enabled. | |
7537 | */ | |
7538 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7539 | const struct dpll *dpll) | |
7540 | { | |
7541 | struct intel_crtc *crtc = | |
7542 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7543 | struct intel_crtc_state pipe_config = { |
a93e255f | 7544 | .base.crtc = &crtc->base, |
d288f65f VS |
7545 | .pixel_multiplier = 1, |
7546 | .dpll = *dpll, | |
7547 | }; | |
7548 | ||
7549 | if (IS_CHERRYVIEW(dev)) { | |
7550 | chv_update_pll(crtc, &pipe_config); | |
7551 | chv_prepare_pll(crtc, &pipe_config); | |
7552 | chv_enable_pll(crtc, &pipe_config); | |
7553 | } else { | |
7554 | vlv_update_pll(crtc, &pipe_config); | |
7555 | vlv_prepare_pll(crtc, &pipe_config); | |
7556 | vlv_enable_pll(crtc, &pipe_config); | |
7557 | } | |
7558 | } | |
7559 | ||
7560 | /** | |
7561 | * vlv_force_pll_off - forcibly disable just the PLL | |
7562 | * @dev_priv: i915 private structure | |
7563 | * @pipe: pipe PLL to disable | |
7564 | * | |
7565 | * Disable the PLL for @pipe. To be used in cases where we need | |
7566 | * the PLL enabled even when @pipe is not going to be enabled. | |
7567 | */ | |
7568 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7569 | { | |
7570 | if (IS_CHERRYVIEW(dev)) | |
7571 | chv_disable_pll(to_i915(dev), pipe); | |
7572 | else | |
7573 | vlv_disable_pll(to_i915(dev), pipe); | |
7574 | } | |
7575 | ||
f47709a9 | 7576 | static void i9xx_update_pll(struct intel_crtc *crtc, |
190f68c5 | 7577 | struct intel_crtc_state *crtc_state, |
f47709a9 | 7578 | intel_clock_t *reduced_clock, |
eb1cbe48 DV |
7579 | int num_connectors) |
7580 | { | |
f47709a9 | 7581 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7582 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7583 | u32 dpll; |
7584 | bool is_sdvo; | |
190f68c5 | 7585 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7586 | |
190f68c5 | 7587 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7588 | |
a93e255f ACO |
7589 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7590 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7591 | |
7592 | dpll = DPLL_VGA_MODE_DIS; | |
7593 | ||
a93e255f | 7594 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7595 | dpll |= DPLLB_MODE_LVDS; |
7596 | else | |
7597 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7598 | |
ef1b460d | 7599 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7600 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7601 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7602 | } |
198a037f DV |
7603 | |
7604 | if (is_sdvo) | |
4a33e48d | 7605 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7606 | |
190f68c5 | 7607 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7608 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7609 | |
7610 | /* compute bitmask from p1 value */ | |
7611 | if (IS_PINEVIEW(dev)) | |
7612 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7613 | else { | |
7614 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7615 | if (IS_G4X(dev) && reduced_clock) | |
7616 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7617 | } | |
7618 | switch (clock->p2) { | |
7619 | case 5: | |
7620 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7621 | break; | |
7622 | case 7: | |
7623 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7624 | break; | |
7625 | case 10: | |
7626 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7627 | break; | |
7628 | case 14: | |
7629 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7630 | break; | |
7631 | } | |
7632 | if (INTEL_INFO(dev)->gen >= 4) | |
7633 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7634 | ||
190f68c5 | 7635 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7636 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7637 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7638 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7639 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7640 | else | |
7641 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7642 | ||
7643 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7644 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7645 | |
eb1cbe48 | 7646 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7647 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7648 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7649 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7650 | } |
7651 | } | |
7652 | ||
f47709a9 | 7653 | static void i8xx_update_pll(struct intel_crtc *crtc, |
190f68c5 | 7654 | struct intel_crtc_state *crtc_state, |
f47709a9 | 7655 | intel_clock_t *reduced_clock, |
eb1cbe48 DV |
7656 | int num_connectors) |
7657 | { | |
f47709a9 | 7658 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7659 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7660 | u32 dpll; |
190f68c5 | 7661 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7662 | |
190f68c5 | 7663 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7664 | |
eb1cbe48 DV |
7665 | dpll = DPLL_VGA_MODE_DIS; |
7666 | ||
a93e255f | 7667 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7668 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7669 | } else { | |
7670 | if (clock->p1 == 2) | |
7671 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7672 | else | |
7673 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7674 | if (clock->p2 == 4) | |
7675 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7676 | } | |
7677 | ||
a93e255f | 7678 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7679 | dpll |= DPLL_DVO_2X_MODE; |
7680 | ||
a93e255f | 7681 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7682 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7683 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7684 | else | |
7685 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7686 | ||
7687 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7688 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7689 | } |
7690 | ||
8a654f3b | 7691 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7692 | { |
7693 | struct drm_device *dev = intel_crtc->base.dev; | |
7694 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7695 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7696 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
8a654f3b | 7697 | struct drm_display_mode *adjusted_mode = |
6e3c9717 | 7698 | &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7699 | uint32_t crtc_vtotal, crtc_vblank_end; |
7700 | int vsyncshift = 0; | |
4d8a62ea DV |
7701 | |
7702 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7703 | * the hw state checker will get angry at the mismatch. */ | |
7704 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7705 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7706 | |
609aeaca | 7707 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7708 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7709 | crtc_vtotal -= 1; |
7710 | crtc_vblank_end -= 1; | |
609aeaca | 7711 | |
409ee761 | 7712 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7713 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7714 | else | |
7715 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7716 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7717 | if (vsyncshift < 0) |
7718 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7719 | } |
7720 | ||
7721 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7722 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7723 | |
fe2b8f9d | 7724 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7725 | (adjusted_mode->crtc_hdisplay - 1) | |
7726 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7727 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7728 | (adjusted_mode->crtc_hblank_start - 1) | |
7729 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7730 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7731 | (adjusted_mode->crtc_hsync_start - 1) | |
7732 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7733 | ||
fe2b8f9d | 7734 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7735 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7736 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7737 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7738 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7739 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7740 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7741 | (adjusted_mode->crtc_vsync_start - 1) | |
7742 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7743 | ||
b5e508d4 PZ |
7744 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7745 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7746 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7747 | * bits. */ | |
7748 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7749 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7750 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7751 | ||
b0e77b9c PZ |
7752 | /* pipesrc controls the size that is scaled from, which should |
7753 | * always be the user's requested size. | |
7754 | */ | |
7755 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7756 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7757 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7758 | } |
7759 | ||
1bd1bd80 | 7760 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7761 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7762 | { |
7763 | struct drm_device *dev = crtc->base.dev; | |
7764 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7765 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7766 | uint32_t tmp; | |
7767 | ||
7768 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7769 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7770 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7771 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7772 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7773 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7774 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7775 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7776 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7777 | |
7778 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7779 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7780 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7781 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7782 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7783 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7784 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7785 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7786 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7787 | |
7788 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7789 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7790 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7791 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7792 | } |
7793 | ||
7794 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7795 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7796 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7797 | ||
2d112de7 ACO |
7798 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7799 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7800 | } |
7801 | ||
f6a83288 | 7802 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7803 | struct intel_crtc_state *pipe_config) |
babea61d | 7804 | { |
2d112de7 ACO |
7805 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7806 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7807 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7808 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7809 | |
2d112de7 ACO |
7810 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7811 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7812 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7813 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7814 | |
2d112de7 | 7815 | mode->flags = pipe_config->base.adjusted_mode.flags; |
babea61d | 7816 | |
2d112de7 ACO |
7817 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7818 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
babea61d JB |
7819 | } |
7820 | ||
84b046f3 DV |
7821 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7822 | { | |
7823 | struct drm_device *dev = intel_crtc->base.dev; | |
7824 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7825 | uint32_t pipeconf; | |
7826 | ||
9f11a9e4 | 7827 | pipeconf = 0; |
84b046f3 | 7828 | |
b6b5d049 VS |
7829 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7830 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7831 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7832 | |
6e3c9717 | 7833 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7834 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7835 | |
ff9ce46e DV |
7836 | /* only g4x and later have fancy bpc/dither controls */ |
7837 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7838 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7839 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7840 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7841 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7842 | |
6e3c9717 | 7843 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7844 | case 18: |
7845 | pipeconf |= PIPECONF_6BPC; | |
7846 | break; | |
7847 | case 24: | |
7848 | pipeconf |= PIPECONF_8BPC; | |
7849 | break; | |
7850 | case 30: | |
7851 | pipeconf |= PIPECONF_10BPC; | |
7852 | break; | |
7853 | default: | |
7854 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7855 | BUG(); | |
84b046f3 DV |
7856 | } |
7857 | } | |
7858 | ||
7859 | if (HAS_PIPE_CXSR(dev)) { | |
7860 | if (intel_crtc->lowfreq_avail) { | |
7861 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7862 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7863 | } else { | |
7864 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7865 | } |
7866 | } | |
7867 | ||
6e3c9717 | 7868 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7869 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7870 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7871 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7872 | else | |
7873 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7874 | } else | |
84b046f3 DV |
7875 | pipeconf |= PIPECONF_PROGRESSIVE; |
7876 | ||
6e3c9717 | 7877 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7878 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7879 | |
84b046f3 DV |
7880 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7881 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7882 | } | |
7883 | ||
190f68c5 ACO |
7884 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7885 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7886 | { |
c7653199 | 7887 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7888 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7889 | int refclk, num_connectors = 0; |
652c393a | 7890 | intel_clock_t clock, reduced_clock; |
a16af721 | 7891 | bool ok, has_reduced_clock = false; |
e9fd1c02 | 7892 | bool is_lvds = false, is_dsi = false; |
5eddb70b | 7893 | struct intel_encoder *encoder; |
d4906093 | 7894 | const intel_limit_t *limit; |
55bb9992 | 7895 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7896 | struct drm_connector *connector; |
55bb9992 ACO |
7897 | struct drm_connector_state *connector_state; |
7898 | int i; | |
79e53945 | 7899 | |
dd3cd74a ACO |
7900 | memset(&crtc_state->dpll_hw_state, 0, |
7901 | sizeof(crtc_state->dpll_hw_state)); | |
7902 | ||
da3ced29 | 7903 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7904 | if (connector_state->crtc != &crtc->base) |
7905 | continue; | |
7906 | ||
7907 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7908 | ||
5eddb70b | 7909 | switch (encoder->type) { |
79e53945 JB |
7910 | case INTEL_OUTPUT_LVDS: |
7911 | is_lvds = true; | |
7912 | break; | |
e9fd1c02 JN |
7913 | case INTEL_OUTPUT_DSI: |
7914 | is_dsi = true; | |
7915 | break; | |
6847d71b PZ |
7916 | default: |
7917 | break; | |
79e53945 | 7918 | } |
43565a06 | 7919 | |
c751ce4f | 7920 | num_connectors++; |
79e53945 JB |
7921 | } |
7922 | ||
f2335330 | 7923 | if (is_dsi) |
5b18e57c | 7924 | return 0; |
f2335330 | 7925 | |
190f68c5 | 7926 | if (!crtc_state->clock_set) { |
a93e255f | 7927 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7928 | |
e9fd1c02 JN |
7929 | /* |
7930 | * Returns a set of divisors for the desired target clock with | |
7931 | * the given refclk, or FALSE. The returned values represent | |
7932 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7933 | * 2) / p1 / p2. | |
7934 | */ | |
a93e255f ACO |
7935 | limit = intel_limit(crtc_state, refclk); |
7936 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7937 | crtc_state->port_clock, |
e9fd1c02 | 7938 | refclk, NULL, &clock); |
f2335330 | 7939 | if (!ok) { |
e9fd1c02 JN |
7940 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7941 | return -EINVAL; | |
7942 | } | |
79e53945 | 7943 | |
f2335330 JN |
7944 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
7945 | /* | |
7946 | * Ensure we match the reduced clock's P to the target | |
7947 | * clock. If the clocks don't match, we can't switch | |
7948 | * the display clock by using the FP0/FP1. In such case | |
7949 | * we will disable the LVDS downclock feature. | |
7950 | */ | |
7951 | has_reduced_clock = | |
a93e255f | 7952 | dev_priv->display.find_dpll(limit, crtc_state, |
f2335330 JN |
7953 | dev_priv->lvds_downclock, |
7954 | refclk, &clock, | |
7955 | &reduced_clock); | |
7956 | } | |
7957 | /* Compat-code for transition, will disappear. */ | |
190f68c5 ACO |
7958 | crtc_state->dpll.n = clock.n; |
7959 | crtc_state->dpll.m1 = clock.m1; | |
7960 | crtc_state->dpll.m2 = clock.m2; | |
7961 | crtc_state->dpll.p1 = clock.p1; | |
7962 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7963 | } |
7026d4ac | 7964 | |
e9fd1c02 | 7965 | if (IS_GEN2(dev)) { |
190f68c5 | 7966 | i8xx_update_pll(crtc, crtc_state, |
2a8f64ca VP |
7967 | has_reduced_clock ? &reduced_clock : NULL, |
7968 | num_connectors); | |
9d556c99 | 7969 | } else if (IS_CHERRYVIEW(dev)) { |
190f68c5 | 7970 | chv_update_pll(crtc, crtc_state); |
e9fd1c02 | 7971 | } else if (IS_VALLEYVIEW(dev)) { |
190f68c5 | 7972 | vlv_update_pll(crtc, crtc_state); |
e9fd1c02 | 7973 | } else { |
190f68c5 | 7974 | i9xx_update_pll(crtc, crtc_state, |
eb1cbe48 | 7975 | has_reduced_clock ? &reduced_clock : NULL, |
eba905b2 | 7976 | num_connectors); |
e9fd1c02 | 7977 | } |
79e53945 | 7978 | |
c8f7a0db | 7979 | return 0; |
f564048e EA |
7980 | } |
7981 | ||
2fa2fe9a | 7982 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7983 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7984 | { |
7985 | struct drm_device *dev = crtc->base.dev; | |
7986 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7987 | uint32_t tmp; | |
7988 | ||
dc9e7dec VS |
7989 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7990 | return; | |
7991 | ||
2fa2fe9a | 7992 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7993 | if (!(tmp & PFIT_ENABLE)) |
7994 | return; | |
2fa2fe9a | 7995 | |
06922821 | 7996 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7997 | if (INTEL_INFO(dev)->gen < 4) { |
7998 | if (crtc->pipe != PIPE_B) | |
7999 | return; | |
2fa2fe9a DV |
8000 | } else { |
8001 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
8002 | return; | |
8003 | } | |
8004 | ||
06922821 | 8005 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
8006 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
8007 | if (INTEL_INFO(dev)->gen < 5) | |
8008 | pipe_config->gmch_pfit.lvds_border_bits = | |
8009 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
8010 | } | |
8011 | ||
acbec814 | 8012 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8013 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
8014 | { |
8015 | struct drm_device *dev = crtc->base.dev; | |
8016 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8017 | int pipe = pipe_config->cpu_transcoder; | |
8018 | intel_clock_t clock; | |
8019 | u32 mdiv; | |
662c6ecb | 8020 | int refclk = 100000; |
acbec814 | 8021 | |
f573de5a SK |
8022 | /* In case of MIPI DPLL will not even be used */ |
8023 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
8024 | return; | |
8025 | ||
a580516d | 8026 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 8027 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 8028 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
8029 | |
8030 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
8031 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
8032 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
8033 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
8034 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
8035 | ||
f646628b | 8036 | vlv_clock(refclk, &clock); |
acbec814 | 8037 | |
f646628b VS |
8038 | /* clock.dot is the fast clock */ |
8039 | pipe_config->port_clock = clock.dot / 5; | |
acbec814 JB |
8040 | } |
8041 | ||
5724dbd1 DL |
8042 | static void |
8043 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
8044 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
8045 | { |
8046 | struct drm_device *dev = crtc->base.dev; | |
8047 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8048 | u32 val, base, offset; | |
8049 | int pipe = crtc->pipe, plane = crtc->plane; | |
8050 | int fourcc, pixel_format; | |
6761dd31 | 8051 | unsigned int aligned_height; |
b113d5ee | 8052 | struct drm_framebuffer *fb; |
1b842c89 | 8053 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 8054 | |
42a7b088 DL |
8055 | val = I915_READ(DSPCNTR(plane)); |
8056 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8057 | return; | |
8058 | ||
d9806c9f | 8059 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8060 | if (!intel_fb) { |
1ad292b5 JB |
8061 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8062 | return; | |
8063 | } | |
8064 | ||
1b842c89 DL |
8065 | fb = &intel_fb->base; |
8066 | ||
18c5247e DV |
8067 | if (INTEL_INFO(dev)->gen >= 4) { |
8068 | if (val & DISPPLANE_TILED) { | |
49af449b | 8069 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8070 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8071 | } | |
8072 | } | |
1ad292b5 JB |
8073 | |
8074 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8075 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8076 | fb->pixel_format = fourcc; |
8077 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
8078 | |
8079 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 8080 | if (plane_config->tiling) |
1ad292b5 JB |
8081 | offset = I915_READ(DSPTILEOFF(plane)); |
8082 | else | |
8083 | offset = I915_READ(DSPLINOFF(plane)); | |
8084 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8085 | } else { | |
8086 | base = I915_READ(DSPADDR(plane)); | |
8087 | } | |
8088 | plane_config->base = base; | |
8089 | ||
8090 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8091 | fb->width = ((val >> 16) & 0xfff) + 1; |
8092 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8093 | |
8094 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8095 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8096 | |
b113d5ee | 8097 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8098 | fb->pixel_format, |
8099 | fb->modifier[0]); | |
1ad292b5 | 8100 | |
f37b5c2b | 8101 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8102 | |
2844a921 DL |
8103 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8104 | pipe_name(pipe), plane, fb->width, fb->height, | |
8105 | fb->bits_per_pixel, base, fb->pitches[0], | |
8106 | plane_config->size); | |
1ad292b5 | 8107 | |
2d14030b | 8108 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8109 | } |
8110 | ||
70b23a98 | 8111 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8112 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8113 | { |
8114 | struct drm_device *dev = crtc->base.dev; | |
8115 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8116 | int pipe = pipe_config->cpu_transcoder; | |
8117 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8118 | intel_clock_t clock; | |
8119 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; | |
8120 | int refclk = 100000; | |
8121 | ||
a580516d | 8122 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8123 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8124 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8125 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8126 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
a580516d | 8127 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8128 | |
8129 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
8130 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); | |
8131 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; | |
8132 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8133 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8134 | ||
8135 | chv_clock(refclk, &clock); | |
8136 | ||
8137 | /* clock.dot is the fast clock */ | |
8138 | pipe_config->port_clock = clock.dot / 5; | |
8139 | } | |
8140 | ||
0e8ffe1b | 8141 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8142 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8143 | { |
8144 | struct drm_device *dev = crtc->base.dev; | |
8145 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8146 | uint32_t tmp; | |
8147 | ||
f458ebbc DV |
8148 | if (!intel_display_power_is_enabled(dev_priv, |
8149 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8150 | return false; |
8151 | ||
e143a21c | 8152 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8153 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8154 | |
0e8ffe1b DV |
8155 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8156 | if (!(tmp & PIPECONF_ENABLE)) | |
8157 | return false; | |
8158 | ||
42571aef VS |
8159 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8160 | switch (tmp & PIPECONF_BPC_MASK) { | |
8161 | case PIPECONF_6BPC: | |
8162 | pipe_config->pipe_bpp = 18; | |
8163 | break; | |
8164 | case PIPECONF_8BPC: | |
8165 | pipe_config->pipe_bpp = 24; | |
8166 | break; | |
8167 | case PIPECONF_10BPC: | |
8168 | pipe_config->pipe_bpp = 30; | |
8169 | break; | |
8170 | default: | |
8171 | break; | |
8172 | } | |
8173 | } | |
8174 | ||
b5a9fa09 DV |
8175 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8176 | pipe_config->limited_color_range = true; | |
8177 | ||
282740f7 VS |
8178 | if (INTEL_INFO(dev)->gen < 4) |
8179 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8180 | ||
1bd1bd80 DV |
8181 | intel_get_pipe_timings(crtc, pipe_config); |
8182 | ||
2fa2fe9a DV |
8183 | i9xx_get_pfit_config(crtc, pipe_config); |
8184 | ||
6c49f241 DV |
8185 | if (INTEL_INFO(dev)->gen >= 4) { |
8186 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8187 | pipe_config->pixel_multiplier = | |
8188 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8189 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8190 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8191 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8192 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8193 | pipe_config->pixel_multiplier = | |
8194 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8195 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8196 | } else { | |
8197 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8198 | * port and will be fixed up in the encoder->get_config | |
8199 | * function. */ | |
8200 | pipe_config->pixel_multiplier = 1; | |
8201 | } | |
8bcc2795 DV |
8202 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8203 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8204 | /* |
8205 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8206 | * on 830. Filter it out here so that we don't | |
8207 | * report errors due to that. | |
8208 | */ | |
8209 | if (IS_I830(dev)) | |
8210 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8211 | ||
8bcc2795 DV |
8212 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8213 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8214 | } else { |
8215 | /* Mask out read-only status bits. */ | |
8216 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8217 | DPLL_PORTC_READY_MASK | | |
8218 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8219 | } |
6c49f241 | 8220 | |
70b23a98 VS |
8221 | if (IS_CHERRYVIEW(dev)) |
8222 | chv_crtc_clock_get(crtc, pipe_config); | |
8223 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8224 | vlv_crtc_clock_get(crtc, pipe_config); |
8225 | else | |
8226 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8227 | |
0e8ffe1b DV |
8228 | return true; |
8229 | } | |
8230 | ||
dde86e2d | 8231 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8232 | { |
8233 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8234 | struct intel_encoder *encoder; |
74cfd7ac | 8235 | u32 val, final; |
13d83a67 | 8236 | bool has_lvds = false; |
199e5d79 | 8237 | bool has_cpu_edp = false; |
199e5d79 | 8238 | bool has_panel = false; |
99eb6a01 KP |
8239 | bool has_ck505 = false; |
8240 | bool can_ssc = false; | |
13d83a67 JB |
8241 | |
8242 | /* We need to take the global config into account */ | |
b2784e15 | 8243 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8244 | switch (encoder->type) { |
8245 | case INTEL_OUTPUT_LVDS: | |
8246 | has_panel = true; | |
8247 | has_lvds = true; | |
8248 | break; | |
8249 | case INTEL_OUTPUT_EDP: | |
8250 | has_panel = true; | |
2de6905f | 8251 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8252 | has_cpu_edp = true; |
8253 | break; | |
6847d71b PZ |
8254 | default: |
8255 | break; | |
13d83a67 JB |
8256 | } |
8257 | } | |
8258 | ||
99eb6a01 | 8259 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8260 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8261 | can_ssc = has_ck505; |
8262 | } else { | |
8263 | has_ck505 = false; | |
8264 | can_ssc = true; | |
8265 | } | |
8266 | ||
2de6905f ID |
8267 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8268 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8269 | |
8270 | /* Ironlake: try to setup display ref clock before DPLL | |
8271 | * enabling. This is only under driver's control after | |
8272 | * PCH B stepping, previous chipset stepping should be | |
8273 | * ignoring this setting. | |
8274 | */ | |
74cfd7ac CW |
8275 | val = I915_READ(PCH_DREF_CONTROL); |
8276 | ||
8277 | /* As we must carefully and slowly disable/enable each source in turn, | |
8278 | * compute the final state we want first and check if we need to | |
8279 | * make any changes at all. | |
8280 | */ | |
8281 | final = val; | |
8282 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8283 | if (has_ck505) | |
8284 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8285 | else | |
8286 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8287 | ||
8288 | final &= ~DREF_SSC_SOURCE_MASK; | |
8289 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8290 | final &= ~DREF_SSC1_ENABLE; | |
8291 | ||
8292 | if (has_panel) { | |
8293 | final |= DREF_SSC_SOURCE_ENABLE; | |
8294 | ||
8295 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8296 | final |= DREF_SSC1_ENABLE; | |
8297 | ||
8298 | if (has_cpu_edp) { | |
8299 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8300 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8301 | else | |
8302 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8303 | } else | |
8304 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8305 | } else { | |
8306 | final |= DREF_SSC_SOURCE_DISABLE; | |
8307 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8308 | } | |
8309 | ||
8310 | if (final == val) | |
8311 | return; | |
8312 | ||
13d83a67 | 8313 | /* Always enable nonspread source */ |
74cfd7ac | 8314 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8315 | |
99eb6a01 | 8316 | if (has_ck505) |
74cfd7ac | 8317 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8318 | else |
74cfd7ac | 8319 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8320 | |
199e5d79 | 8321 | if (has_panel) { |
74cfd7ac CW |
8322 | val &= ~DREF_SSC_SOURCE_MASK; |
8323 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8324 | |
199e5d79 | 8325 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8326 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8327 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8328 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8329 | } else |
74cfd7ac | 8330 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8331 | |
8332 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8333 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8334 | POSTING_READ(PCH_DREF_CONTROL); |
8335 | udelay(200); | |
8336 | ||
74cfd7ac | 8337 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8338 | |
8339 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8340 | if (has_cpu_edp) { |
99eb6a01 | 8341 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8342 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8343 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8344 | } else |
74cfd7ac | 8345 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8346 | } else |
74cfd7ac | 8347 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8348 | |
74cfd7ac | 8349 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8350 | POSTING_READ(PCH_DREF_CONTROL); |
8351 | udelay(200); | |
8352 | } else { | |
8353 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8354 | ||
74cfd7ac | 8355 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8356 | |
8357 | /* Turn off CPU output */ | |
74cfd7ac | 8358 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8359 | |
74cfd7ac | 8360 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8361 | POSTING_READ(PCH_DREF_CONTROL); |
8362 | udelay(200); | |
8363 | ||
8364 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8365 | val &= ~DREF_SSC_SOURCE_MASK; |
8366 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8367 | |
8368 | /* Turn off SSC1 */ | |
74cfd7ac | 8369 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8370 | |
74cfd7ac | 8371 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8372 | POSTING_READ(PCH_DREF_CONTROL); |
8373 | udelay(200); | |
8374 | } | |
74cfd7ac CW |
8375 | |
8376 | BUG_ON(val != final); | |
13d83a67 JB |
8377 | } |
8378 | ||
f31f2d55 | 8379 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8380 | { |
f31f2d55 | 8381 | uint32_t tmp; |
dde86e2d | 8382 | |
0ff066a9 PZ |
8383 | tmp = I915_READ(SOUTH_CHICKEN2); |
8384 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8385 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8386 | |
0ff066a9 PZ |
8387 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8388 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8389 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8390 | |
0ff066a9 PZ |
8391 | tmp = I915_READ(SOUTH_CHICKEN2); |
8392 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8393 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8394 | |
0ff066a9 PZ |
8395 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8396 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8397 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8398 | } |
8399 | ||
8400 | /* WaMPhyProgramming:hsw */ | |
8401 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8402 | { | |
8403 | uint32_t tmp; | |
dde86e2d PZ |
8404 | |
8405 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8406 | tmp &= ~(0xFF << 24); | |
8407 | tmp |= (0x12 << 24); | |
8408 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8409 | ||
dde86e2d PZ |
8410 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8411 | tmp |= (1 << 11); | |
8412 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8413 | ||
8414 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8415 | tmp |= (1 << 11); | |
8416 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8417 | ||
dde86e2d PZ |
8418 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8419 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8420 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8421 | ||
8422 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8423 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8424 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8425 | ||
0ff066a9 PZ |
8426 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8427 | tmp &= ~(7 << 13); | |
8428 | tmp |= (5 << 13); | |
8429 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8430 | |
0ff066a9 PZ |
8431 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8432 | tmp &= ~(7 << 13); | |
8433 | tmp |= (5 << 13); | |
8434 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8435 | |
8436 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8437 | tmp &= ~0xFF; | |
8438 | tmp |= 0x1C; | |
8439 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8440 | ||
8441 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8442 | tmp &= ~0xFF; | |
8443 | tmp |= 0x1C; | |
8444 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8445 | ||
8446 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8447 | tmp &= ~(0xFF << 16); | |
8448 | tmp |= (0x1C << 16); | |
8449 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8450 | ||
8451 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8452 | tmp &= ~(0xFF << 16); | |
8453 | tmp |= (0x1C << 16); | |
8454 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8455 | ||
0ff066a9 PZ |
8456 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8457 | tmp |= (1 << 27); | |
8458 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8459 | |
0ff066a9 PZ |
8460 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8461 | tmp |= (1 << 27); | |
8462 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8463 | |
0ff066a9 PZ |
8464 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8465 | tmp &= ~(0xF << 28); | |
8466 | tmp |= (4 << 28); | |
8467 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8468 | |
0ff066a9 PZ |
8469 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8470 | tmp &= ~(0xF << 28); | |
8471 | tmp |= (4 << 28); | |
8472 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8473 | } |
8474 | ||
2fa86a1f PZ |
8475 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8476 | * Programming" based on the parameters passed: | |
8477 | * - Sequence to enable CLKOUT_DP | |
8478 | * - Sequence to enable CLKOUT_DP without spread | |
8479 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8480 | */ | |
8481 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8482 | bool with_fdi) | |
f31f2d55 PZ |
8483 | { |
8484 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8485 | uint32_t reg, tmp; |
8486 | ||
8487 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8488 | with_spread = true; | |
8489 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && | |
8490 | with_fdi, "LP PCH doesn't have FDI\n")) | |
8491 | with_fdi = false; | |
f31f2d55 | 8492 | |
a580516d | 8493 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8494 | |
8495 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8496 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8497 | tmp |= SBI_SSCCTL_PATHALT; | |
8498 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8499 | ||
8500 | udelay(24); | |
8501 | ||
2fa86a1f PZ |
8502 | if (with_spread) { |
8503 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8504 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8505 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8506 | |
2fa86a1f PZ |
8507 | if (with_fdi) { |
8508 | lpt_reset_fdi_mphy(dev_priv); | |
8509 | lpt_program_fdi_mphy(dev_priv); | |
8510 | } | |
8511 | } | |
dde86e2d | 8512 | |
2fa86a1f PZ |
8513 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
8514 | SBI_GEN0 : SBI_DBUFF0; | |
8515 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8516 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8517 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8518 | |
a580516d | 8519 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8520 | } |
8521 | ||
47701c3b PZ |
8522 | /* Sequence to disable CLKOUT_DP */ |
8523 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8524 | { | |
8525 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8526 | uint32_t reg, tmp; | |
8527 | ||
a580516d | 8528 | mutex_lock(&dev_priv->sb_lock); |
47701c3b PZ |
8529 | |
8530 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? | |
8531 | SBI_GEN0 : SBI_DBUFF0; | |
8532 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8533 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8534 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8535 | ||
8536 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8537 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8538 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8539 | tmp |= SBI_SSCCTL_PATHALT; | |
8540 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8541 | udelay(32); | |
8542 | } | |
8543 | tmp |= SBI_SSCCTL_DISABLE; | |
8544 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8545 | } | |
8546 | ||
a580516d | 8547 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8548 | } |
8549 | ||
bf8fa3d3 PZ |
8550 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8551 | { | |
bf8fa3d3 PZ |
8552 | struct intel_encoder *encoder; |
8553 | bool has_vga = false; | |
8554 | ||
b2784e15 | 8555 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8556 | switch (encoder->type) { |
8557 | case INTEL_OUTPUT_ANALOG: | |
8558 | has_vga = true; | |
8559 | break; | |
6847d71b PZ |
8560 | default: |
8561 | break; | |
bf8fa3d3 PZ |
8562 | } |
8563 | } | |
8564 | ||
47701c3b PZ |
8565 | if (has_vga) |
8566 | lpt_enable_clkout_dp(dev, true, true); | |
8567 | else | |
8568 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8569 | } |
8570 | ||
dde86e2d PZ |
8571 | /* |
8572 | * Initialize reference clocks when the driver loads | |
8573 | */ | |
8574 | void intel_init_pch_refclk(struct drm_device *dev) | |
8575 | { | |
8576 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8577 | ironlake_init_pch_refclk(dev); | |
8578 | else if (HAS_PCH_LPT(dev)) | |
8579 | lpt_init_pch_refclk(dev); | |
8580 | } | |
8581 | ||
55bb9992 | 8582 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8583 | { |
55bb9992 | 8584 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8585 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8586 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8587 | struct drm_connector *connector; |
55bb9992 | 8588 | struct drm_connector_state *connector_state; |
d9d444cb | 8589 | struct intel_encoder *encoder; |
55bb9992 | 8590 | int num_connectors = 0, i; |
d9d444cb JB |
8591 | bool is_lvds = false; |
8592 | ||
da3ced29 | 8593 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8594 | if (connector_state->crtc != crtc_state->base.crtc) |
8595 | continue; | |
8596 | ||
8597 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8598 | ||
d9d444cb JB |
8599 | switch (encoder->type) { |
8600 | case INTEL_OUTPUT_LVDS: | |
8601 | is_lvds = true; | |
8602 | break; | |
6847d71b PZ |
8603 | default: |
8604 | break; | |
d9d444cb JB |
8605 | } |
8606 | num_connectors++; | |
8607 | } | |
8608 | ||
8609 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8610 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8611 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8612 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8613 | } |
8614 | ||
8615 | return 120000; | |
8616 | } | |
8617 | ||
6ff93609 | 8618 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8619 | { |
c8203565 | 8620 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8621 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8622 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8623 | uint32_t val; |
8624 | ||
78114071 | 8625 | val = 0; |
c8203565 | 8626 | |
6e3c9717 | 8627 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8628 | case 18: |
dfd07d72 | 8629 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8630 | break; |
8631 | case 24: | |
dfd07d72 | 8632 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8633 | break; |
8634 | case 30: | |
dfd07d72 | 8635 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8636 | break; |
8637 | case 36: | |
dfd07d72 | 8638 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8639 | break; |
8640 | default: | |
cc769b62 PZ |
8641 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8642 | BUG(); | |
c8203565 PZ |
8643 | } |
8644 | ||
6e3c9717 | 8645 | if (intel_crtc->config->dither) |
c8203565 PZ |
8646 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8647 | ||
6e3c9717 | 8648 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8649 | val |= PIPECONF_INTERLACED_ILK; |
8650 | else | |
8651 | val |= PIPECONF_PROGRESSIVE; | |
8652 | ||
6e3c9717 | 8653 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8654 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8655 | |
c8203565 PZ |
8656 | I915_WRITE(PIPECONF(pipe), val); |
8657 | POSTING_READ(PIPECONF(pipe)); | |
8658 | } | |
8659 | ||
86d3efce VS |
8660 | /* |
8661 | * Set up the pipe CSC unit. | |
8662 | * | |
8663 | * Currently only full range RGB to limited range RGB conversion | |
8664 | * is supported, but eventually this should handle various | |
8665 | * RGB<->YCbCr scenarios as well. | |
8666 | */ | |
50f3b016 | 8667 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8668 | { |
8669 | struct drm_device *dev = crtc->dev; | |
8670 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8671 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8672 | int pipe = intel_crtc->pipe; | |
8673 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8674 | ||
8675 | /* | |
8676 | * TODO: Check what kind of values actually come out of the pipe | |
8677 | * with these coeff/postoff values and adjust to get the best | |
8678 | * accuracy. Perhaps we even need to take the bpc value into | |
8679 | * consideration. | |
8680 | */ | |
8681 | ||
6e3c9717 | 8682 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8683 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8684 | ||
8685 | /* | |
8686 | * GY/GU and RY/RU should be the other way around according | |
8687 | * to BSpec, but reality doesn't agree. Just set them up in | |
8688 | * a way that results in the correct picture. | |
8689 | */ | |
8690 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8691 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8692 | ||
8693 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8694 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8695 | ||
8696 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8697 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8698 | ||
8699 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8700 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8701 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8702 | ||
8703 | if (INTEL_INFO(dev)->gen > 6) { | |
8704 | uint16_t postoff = 0; | |
8705 | ||
6e3c9717 | 8706 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8707 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8708 | |
8709 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8710 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8711 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8712 | ||
8713 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8714 | } else { | |
8715 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8716 | ||
6e3c9717 | 8717 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8718 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8719 | ||
8720 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8721 | } | |
8722 | } | |
8723 | ||
6ff93609 | 8724 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8725 | { |
756f85cf PZ |
8726 | struct drm_device *dev = crtc->dev; |
8727 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8728 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8729 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8730 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8731 | uint32_t val; |
8732 | ||
3eff4faa | 8733 | val = 0; |
ee2b0b38 | 8734 | |
6e3c9717 | 8735 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8736 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8737 | ||
6e3c9717 | 8738 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8739 | val |= PIPECONF_INTERLACED_ILK; |
8740 | else | |
8741 | val |= PIPECONF_PROGRESSIVE; | |
8742 | ||
702e7a56 PZ |
8743 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8744 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8745 | |
8746 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8747 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8748 | |
3cdf122c | 8749 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8750 | val = 0; |
8751 | ||
6e3c9717 | 8752 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8753 | case 18: |
8754 | val |= PIPEMISC_DITHER_6_BPC; | |
8755 | break; | |
8756 | case 24: | |
8757 | val |= PIPEMISC_DITHER_8_BPC; | |
8758 | break; | |
8759 | case 30: | |
8760 | val |= PIPEMISC_DITHER_10_BPC; | |
8761 | break; | |
8762 | case 36: | |
8763 | val |= PIPEMISC_DITHER_12_BPC; | |
8764 | break; | |
8765 | default: | |
8766 | /* Case prevented by pipe_config_set_bpp. */ | |
8767 | BUG(); | |
8768 | } | |
8769 | ||
6e3c9717 | 8770 | if (intel_crtc->config->dither) |
756f85cf PZ |
8771 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8772 | ||
8773 | I915_WRITE(PIPEMISC(pipe), val); | |
8774 | } | |
ee2b0b38 PZ |
8775 | } |
8776 | ||
6591c6e4 | 8777 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8778 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8779 | intel_clock_t *clock, |
8780 | bool *has_reduced_clock, | |
8781 | intel_clock_t *reduced_clock) | |
8782 | { | |
8783 | struct drm_device *dev = crtc->dev; | |
8784 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8785 | int refclk; |
d4906093 | 8786 | const intel_limit_t *limit; |
a16af721 | 8787 | bool ret, is_lvds = false; |
79e53945 | 8788 | |
a93e255f | 8789 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
79e53945 | 8790 | |
55bb9992 | 8791 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8792 | |
d4906093 ML |
8793 | /* |
8794 | * Returns a set of divisors for the desired target clock with the given | |
8795 | * refclk, or FALSE. The returned values represent the clock equation: | |
8796 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8797 | */ | |
a93e255f ACO |
8798 | limit = intel_limit(crtc_state, refclk); |
8799 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8800 | crtc_state->port_clock, |
ee9300bb | 8801 | refclk, NULL, clock); |
6591c6e4 PZ |
8802 | if (!ret) |
8803 | return false; | |
cda4b7d3 | 8804 | |
ddc9003c | 8805 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
cec2f356 SP |
8806 | /* |
8807 | * Ensure we match the reduced clock's P to the target clock. | |
8808 | * If the clocks don't match, we can't switch the display clock | |
8809 | * by using the FP0/FP1. In such case we will disable the LVDS | |
8810 | * downclock feature. | |
8811 | */ | |
ee9300bb | 8812 | *has_reduced_clock = |
a93e255f | 8813 | dev_priv->display.find_dpll(limit, crtc_state, |
ee9300bb DV |
8814 | dev_priv->lvds_downclock, |
8815 | refclk, clock, | |
8816 | reduced_clock); | |
652c393a | 8817 | } |
61e9653f | 8818 | |
6591c6e4 PZ |
8819 | return true; |
8820 | } | |
8821 | ||
d4b1931c PZ |
8822 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8823 | { | |
8824 | /* | |
8825 | * Account for spread spectrum to avoid | |
8826 | * oversubscribing the link. Max center spread | |
8827 | * is 2.5%; use 5% for safety's sake. | |
8828 | */ | |
8829 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8830 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8831 | } |
8832 | ||
7429e9d4 | 8833 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8834 | { |
7429e9d4 | 8835 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8836 | } |
8837 | ||
de13a2e3 | 8838 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8839 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8840 | u32 *fp, |
9a7c7890 | 8841 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8842 | { |
de13a2e3 | 8843 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8844 | struct drm_device *dev = crtc->dev; |
8845 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8846 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8847 | struct drm_connector *connector; |
55bb9992 ACO |
8848 | struct drm_connector_state *connector_state; |
8849 | struct intel_encoder *encoder; | |
de13a2e3 | 8850 | uint32_t dpll; |
55bb9992 | 8851 | int factor, num_connectors = 0, i; |
09ede541 | 8852 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8853 | |
da3ced29 | 8854 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8855 | if (connector_state->crtc != crtc_state->base.crtc) |
8856 | continue; | |
8857 | ||
8858 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8859 | ||
8860 | switch (encoder->type) { | |
79e53945 JB |
8861 | case INTEL_OUTPUT_LVDS: |
8862 | is_lvds = true; | |
8863 | break; | |
8864 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8865 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8866 | is_sdvo = true; |
79e53945 | 8867 | break; |
6847d71b PZ |
8868 | default: |
8869 | break; | |
79e53945 | 8870 | } |
43565a06 | 8871 | |
c751ce4f | 8872 | num_connectors++; |
79e53945 | 8873 | } |
79e53945 | 8874 | |
c1858123 | 8875 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8876 | factor = 21; |
8877 | if (is_lvds) { | |
8878 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8879 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8880 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8881 | factor = 25; |
190f68c5 | 8882 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8883 | factor = 20; |
c1858123 | 8884 | |
190f68c5 | 8885 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8886 | *fp |= FP_CB_TUNE; |
2c07245f | 8887 | |
9a7c7890 DV |
8888 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8889 | *fp2 |= FP_CB_TUNE; | |
8890 | ||
5eddb70b | 8891 | dpll = 0; |
2c07245f | 8892 | |
a07d6787 EA |
8893 | if (is_lvds) |
8894 | dpll |= DPLLB_MODE_LVDS; | |
8895 | else | |
8896 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8897 | |
190f68c5 | 8898 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8899 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8900 | |
8901 | if (is_sdvo) | |
4a33e48d | 8902 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8903 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8904 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8905 | |
a07d6787 | 8906 | /* compute bitmask from p1 value */ |
190f68c5 | 8907 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8908 | /* also FPA1 */ |
190f68c5 | 8909 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8910 | |
190f68c5 | 8911 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8912 | case 5: |
8913 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8914 | break; | |
8915 | case 7: | |
8916 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8917 | break; | |
8918 | case 10: | |
8919 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8920 | break; | |
8921 | case 14: | |
8922 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8923 | break; | |
79e53945 JB |
8924 | } |
8925 | ||
b4c09f3b | 8926 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8927 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8928 | else |
8929 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8930 | ||
959e16d6 | 8931 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8932 | } |
8933 | ||
190f68c5 ACO |
8934 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8935 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8936 | { |
c7653199 | 8937 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8938 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8939 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8940 | bool ok, has_reduced_clock = false; |
8b47047b | 8941 | bool is_lvds = false; |
e2b78267 | 8942 | struct intel_shared_dpll *pll; |
de13a2e3 | 8943 | |
dd3cd74a ACO |
8944 | memset(&crtc_state->dpll_hw_state, 0, |
8945 | sizeof(crtc_state->dpll_hw_state)); | |
8946 | ||
409ee761 | 8947 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8948 | |
5dc5298b PZ |
8949 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8950 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8951 | |
190f68c5 | 8952 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8953 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8954 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8955 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8956 | return -EINVAL; | |
79e53945 | 8957 | } |
f47709a9 | 8958 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8959 | if (!crtc_state->clock_set) { |
8960 | crtc_state->dpll.n = clock.n; | |
8961 | crtc_state->dpll.m1 = clock.m1; | |
8962 | crtc_state->dpll.m2 = clock.m2; | |
8963 | crtc_state->dpll.p1 = clock.p1; | |
8964 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8965 | } |
79e53945 | 8966 | |
5dc5298b | 8967 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8968 | if (crtc_state->has_pch_encoder) { |
8969 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8970 | if (has_reduced_clock) |
7429e9d4 | 8971 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8972 | |
190f68c5 | 8973 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8974 | &fp, &reduced_clock, |
8975 | has_reduced_clock ? &fp2 : NULL); | |
8976 | ||
190f68c5 ACO |
8977 | crtc_state->dpll_hw_state.dpll = dpll; |
8978 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8979 | if (has_reduced_clock) |
190f68c5 | 8980 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8981 | else |
190f68c5 | 8982 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8983 | |
190f68c5 | 8984 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8985 | if (pll == NULL) { |
84f44ce7 | 8986 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8987 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8988 | return -EINVAL; |
8989 | } | |
3fb37703 | 8990 | } |
79e53945 | 8991 | |
ab585dea | 8992 | if (is_lvds && has_reduced_clock) |
c7653199 | 8993 | crtc->lowfreq_avail = true; |
bcd644e0 | 8994 | else |
c7653199 | 8995 | crtc->lowfreq_avail = false; |
e2b78267 | 8996 | |
c8f7a0db | 8997 | return 0; |
79e53945 JB |
8998 | } |
8999 | ||
eb14cb74 VS |
9000 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
9001 | struct intel_link_m_n *m_n) | |
9002 | { | |
9003 | struct drm_device *dev = crtc->base.dev; | |
9004 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9005 | enum pipe pipe = crtc->pipe; | |
9006 | ||
9007 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
9008 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
9009 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9010 | & ~TU_SIZE_MASK; | |
9011 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
9012 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9013 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9014 | } | |
9015 | ||
9016 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
9017 | enum transcoder transcoder, | |
b95af8be VK |
9018 | struct intel_link_m_n *m_n, |
9019 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
9020 | { |
9021 | struct drm_device *dev = crtc->base.dev; | |
9022 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 9023 | enum pipe pipe = crtc->pipe; |
72419203 | 9024 | |
eb14cb74 VS |
9025 | if (INTEL_INFO(dev)->gen >= 5) { |
9026 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
9027 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
9028 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
9029 | & ~TU_SIZE_MASK; | |
9030 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
9031 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
9032 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
9033 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
9034 | * gen < 8) and if DRRS is supported (to make sure the | |
9035 | * registers are not unnecessarily read). | |
9036 | */ | |
9037 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 9038 | crtc->config->has_drrs) { |
b95af8be VK |
9039 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
9040 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
9041 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
9042 | & ~TU_SIZE_MASK; | |
9043 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
9044 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
9045 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9046 | } | |
eb14cb74 VS |
9047 | } else { |
9048 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
9049 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
9050 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9051 | & ~TU_SIZE_MASK; | |
9052 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
9053 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9054 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9055 | } | |
9056 | } | |
9057 | ||
9058 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 9059 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 9060 | { |
681a8504 | 9061 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
9062 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
9063 | else | |
9064 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
9065 | &pipe_config->dp_m_n, |
9066 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 9067 | } |
72419203 | 9068 | |
eb14cb74 | 9069 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 9070 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
9071 | { |
9072 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 9073 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
9074 | } |
9075 | ||
bd2e244f | 9076 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9077 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
9078 | { |
9079 | struct drm_device *dev = crtc->base.dev; | |
9080 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
9081 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
9082 | uint32_t ps_ctrl = 0; | |
9083 | int id = -1; | |
9084 | int i; | |
bd2e244f | 9085 | |
a1b2278e CK |
9086 | /* find scaler attached to this pipe */ |
9087 | for (i = 0; i < crtc->num_scalers; i++) { | |
9088 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9089 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9090 | id = i; | |
9091 | pipe_config->pch_pfit.enabled = true; | |
9092 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9093 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9094 | break; | |
9095 | } | |
9096 | } | |
bd2e244f | 9097 | |
a1b2278e CK |
9098 | scaler_state->scaler_id = id; |
9099 | if (id >= 0) { | |
9100 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9101 | } else { | |
9102 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9103 | } |
9104 | } | |
9105 | ||
5724dbd1 DL |
9106 | static void |
9107 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9108 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9109 | { |
9110 | struct drm_device *dev = crtc->base.dev; | |
9111 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9112 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9113 | int pipe = crtc->pipe; |
9114 | int fourcc, pixel_format; | |
6761dd31 | 9115 | unsigned int aligned_height; |
bc8d7dff | 9116 | struct drm_framebuffer *fb; |
1b842c89 | 9117 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9118 | |
d9806c9f | 9119 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9120 | if (!intel_fb) { |
bc8d7dff DL |
9121 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9122 | return; | |
9123 | } | |
9124 | ||
1b842c89 DL |
9125 | fb = &intel_fb->base; |
9126 | ||
bc8d7dff | 9127 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9128 | if (!(val & PLANE_CTL_ENABLE)) |
9129 | goto error; | |
9130 | ||
bc8d7dff DL |
9131 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9132 | fourcc = skl_format_to_fourcc(pixel_format, | |
9133 | val & PLANE_CTL_ORDER_RGBX, | |
9134 | val & PLANE_CTL_ALPHA_MASK); | |
9135 | fb->pixel_format = fourcc; | |
9136 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9137 | ||
40f46283 DL |
9138 | tiling = val & PLANE_CTL_TILED_MASK; |
9139 | switch (tiling) { | |
9140 | case PLANE_CTL_TILED_LINEAR: | |
9141 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9142 | break; | |
9143 | case PLANE_CTL_TILED_X: | |
9144 | plane_config->tiling = I915_TILING_X; | |
9145 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9146 | break; | |
9147 | case PLANE_CTL_TILED_Y: | |
9148 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9149 | break; | |
9150 | case PLANE_CTL_TILED_YF: | |
9151 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9152 | break; | |
9153 | default: | |
9154 | MISSING_CASE(tiling); | |
9155 | goto error; | |
9156 | } | |
9157 | ||
bc8d7dff DL |
9158 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9159 | plane_config->base = base; | |
9160 | ||
9161 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9162 | ||
9163 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9164 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9165 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9166 | ||
9167 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9168 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9169 | fb->pixel_format); | |
bc8d7dff DL |
9170 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9171 | ||
9172 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9173 | fb->pixel_format, |
9174 | fb->modifier[0]); | |
bc8d7dff | 9175 | |
f37b5c2b | 9176 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9177 | |
9178 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9179 | pipe_name(pipe), fb->width, fb->height, | |
9180 | fb->bits_per_pixel, base, fb->pitches[0], | |
9181 | plane_config->size); | |
9182 | ||
2d14030b | 9183 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9184 | return; |
9185 | ||
9186 | error: | |
9187 | kfree(fb); | |
9188 | } | |
9189 | ||
2fa2fe9a | 9190 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9191 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9192 | { |
9193 | struct drm_device *dev = crtc->base.dev; | |
9194 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9195 | uint32_t tmp; | |
9196 | ||
9197 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9198 | ||
9199 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9200 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9201 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9202 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9203 | |
9204 | /* We currently do not free assignements of panel fitters on | |
9205 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9206 | * differentiates them) so just WARN about this case for now. */ | |
9207 | if (IS_GEN7(dev)) { | |
9208 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9209 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9210 | } | |
2fa2fe9a | 9211 | } |
79e53945 JB |
9212 | } |
9213 | ||
5724dbd1 DL |
9214 | static void |
9215 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9216 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9217 | { |
9218 | struct drm_device *dev = crtc->base.dev; | |
9219 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9220 | u32 val, base, offset; | |
aeee5a49 | 9221 | int pipe = crtc->pipe; |
4c6baa59 | 9222 | int fourcc, pixel_format; |
6761dd31 | 9223 | unsigned int aligned_height; |
b113d5ee | 9224 | struct drm_framebuffer *fb; |
1b842c89 | 9225 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9226 | |
42a7b088 DL |
9227 | val = I915_READ(DSPCNTR(pipe)); |
9228 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9229 | return; | |
9230 | ||
d9806c9f | 9231 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9232 | if (!intel_fb) { |
4c6baa59 JB |
9233 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9234 | return; | |
9235 | } | |
9236 | ||
1b842c89 DL |
9237 | fb = &intel_fb->base; |
9238 | ||
18c5247e DV |
9239 | if (INTEL_INFO(dev)->gen >= 4) { |
9240 | if (val & DISPPLANE_TILED) { | |
49af449b | 9241 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9242 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9243 | } | |
9244 | } | |
4c6baa59 JB |
9245 | |
9246 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9247 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9248 | fb->pixel_format = fourcc; |
9249 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9250 | |
aeee5a49 | 9251 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9252 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9253 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9254 | } else { |
49af449b | 9255 | if (plane_config->tiling) |
aeee5a49 | 9256 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9257 | else |
aeee5a49 | 9258 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9259 | } |
9260 | plane_config->base = base; | |
9261 | ||
9262 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9263 | fb->width = ((val >> 16) & 0xfff) + 1; |
9264 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9265 | |
9266 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9267 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9268 | |
b113d5ee | 9269 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9270 | fb->pixel_format, |
9271 | fb->modifier[0]); | |
4c6baa59 | 9272 | |
f37b5c2b | 9273 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9274 | |
2844a921 DL |
9275 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9276 | pipe_name(pipe), fb->width, fb->height, | |
9277 | fb->bits_per_pixel, base, fb->pitches[0], | |
9278 | plane_config->size); | |
b113d5ee | 9279 | |
2d14030b | 9280 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9281 | } |
9282 | ||
0e8ffe1b | 9283 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9284 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9285 | { |
9286 | struct drm_device *dev = crtc->base.dev; | |
9287 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9288 | uint32_t tmp; | |
9289 | ||
f458ebbc DV |
9290 | if (!intel_display_power_is_enabled(dev_priv, |
9291 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9292 | return false; |
9293 | ||
e143a21c | 9294 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9295 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9296 | |
0e8ffe1b DV |
9297 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9298 | if (!(tmp & PIPECONF_ENABLE)) | |
9299 | return false; | |
9300 | ||
42571aef VS |
9301 | switch (tmp & PIPECONF_BPC_MASK) { |
9302 | case PIPECONF_6BPC: | |
9303 | pipe_config->pipe_bpp = 18; | |
9304 | break; | |
9305 | case PIPECONF_8BPC: | |
9306 | pipe_config->pipe_bpp = 24; | |
9307 | break; | |
9308 | case PIPECONF_10BPC: | |
9309 | pipe_config->pipe_bpp = 30; | |
9310 | break; | |
9311 | case PIPECONF_12BPC: | |
9312 | pipe_config->pipe_bpp = 36; | |
9313 | break; | |
9314 | default: | |
9315 | break; | |
9316 | } | |
9317 | ||
b5a9fa09 DV |
9318 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9319 | pipe_config->limited_color_range = true; | |
9320 | ||
ab9412ba | 9321 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9322 | struct intel_shared_dpll *pll; |
9323 | ||
88adfff1 DV |
9324 | pipe_config->has_pch_encoder = true; |
9325 | ||
627eb5a3 DV |
9326 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9327 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9328 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9329 | |
9330 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9331 | |
c0d43d62 | 9332 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9333 | pipe_config->shared_dpll = |
9334 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9335 | } else { |
9336 | tmp = I915_READ(PCH_DPLL_SEL); | |
9337 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9338 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9339 | else | |
9340 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9341 | } | |
66e985c0 DV |
9342 | |
9343 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9344 | ||
9345 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9346 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9347 | |
9348 | tmp = pipe_config->dpll_hw_state.dpll; | |
9349 | pipe_config->pixel_multiplier = | |
9350 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9351 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9352 | |
9353 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9354 | } else { |
9355 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9356 | } |
9357 | ||
1bd1bd80 DV |
9358 | intel_get_pipe_timings(crtc, pipe_config); |
9359 | ||
2fa2fe9a DV |
9360 | ironlake_get_pfit_config(crtc, pipe_config); |
9361 | ||
0e8ffe1b DV |
9362 | return true; |
9363 | } | |
9364 | ||
be256dc7 PZ |
9365 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9366 | { | |
9367 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9368 | struct intel_crtc *crtc; |
be256dc7 | 9369 | |
d3fcc808 | 9370 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9371 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9372 | pipe_name(crtc->pipe)); |
9373 | ||
e2c719b7 RC |
9374 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9375 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
9376 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); | |
9377 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
9378 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); | |
9379 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9380 | "CPU PWM1 enabled\n"); |
c5107b87 | 9381 | if (IS_HASWELL(dev)) |
e2c719b7 | 9382 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9383 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9384 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9385 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9386 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9387 | "Utility pin enabled\n"); |
e2c719b7 | 9388 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9389 | |
9926ada1 PZ |
9390 | /* |
9391 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9392 | * interrupts remain enabled. We used to check for that, but since it's | |
9393 | * gen-specific and since we only disable LCPLL after we fully disable | |
9394 | * the interrupts, the check below should be enough. | |
9395 | */ | |
e2c719b7 | 9396 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9397 | } |
9398 | ||
9ccd5aeb PZ |
9399 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9400 | { | |
9401 | struct drm_device *dev = dev_priv->dev; | |
9402 | ||
9403 | if (IS_HASWELL(dev)) | |
9404 | return I915_READ(D_COMP_HSW); | |
9405 | else | |
9406 | return I915_READ(D_COMP_BDW); | |
9407 | } | |
9408 | ||
3c4c9b81 PZ |
9409 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9410 | { | |
9411 | struct drm_device *dev = dev_priv->dev; | |
9412 | ||
9413 | if (IS_HASWELL(dev)) { | |
9414 | mutex_lock(&dev_priv->rps.hw_lock); | |
9415 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9416 | val)) | |
f475dadf | 9417 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9418 | mutex_unlock(&dev_priv->rps.hw_lock); |
9419 | } else { | |
9ccd5aeb PZ |
9420 | I915_WRITE(D_COMP_BDW, val); |
9421 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9422 | } |
be256dc7 PZ |
9423 | } |
9424 | ||
9425 | /* | |
9426 | * This function implements pieces of two sequences from BSpec: | |
9427 | * - Sequence for display software to disable LCPLL | |
9428 | * - Sequence for display software to allow package C8+ | |
9429 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9430 | * register. Callers should take care of disabling all the display engine | |
9431 | * functions, doing the mode unset, fixing interrupts, etc. | |
9432 | */ | |
6ff58d53 PZ |
9433 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9434 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9435 | { |
9436 | uint32_t val; | |
9437 | ||
9438 | assert_can_disable_lcpll(dev_priv); | |
9439 | ||
9440 | val = I915_READ(LCPLL_CTL); | |
9441 | ||
9442 | if (switch_to_fclk) { | |
9443 | val |= LCPLL_CD_SOURCE_FCLK; | |
9444 | I915_WRITE(LCPLL_CTL, val); | |
9445 | ||
9446 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9447 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9448 | DRM_ERROR("Switching to FCLK failed\n"); | |
9449 | ||
9450 | val = I915_READ(LCPLL_CTL); | |
9451 | } | |
9452 | ||
9453 | val |= LCPLL_PLL_DISABLE; | |
9454 | I915_WRITE(LCPLL_CTL, val); | |
9455 | POSTING_READ(LCPLL_CTL); | |
9456 | ||
9457 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9458 | DRM_ERROR("LCPLL still locked\n"); | |
9459 | ||
9ccd5aeb | 9460 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9461 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9462 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9463 | ndelay(100); |
9464 | ||
9ccd5aeb PZ |
9465 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9466 | 1)) | |
be256dc7 PZ |
9467 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9468 | ||
9469 | if (allow_power_down) { | |
9470 | val = I915_READ(LCPLL_CTL); | |
9471 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9472 | I915_WRITE(LCPLL_CTL, val); | |
9473 | POSTING_READ(LCPLL_CTL); | |
9474 | } | |
9475 | } | |
9476 | ||
9477 | /* | |
9478 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9479 | * source. | |
9480 | */ | |
6ff58d53 | 9481 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9482 | { |
9483 | uint32_t val; | |
9484 | ||
9485 | val = I915_READ(LCPLL_CTL); | |
9486 | ||
9487 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9488 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9489 | return; | |
9490 | ||
a8a8bd54 PZ |
9491 | /* |
9492 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9493 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9494 | */ |
59bad947 | 9495 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9496 | |
be256dc7 PZ |
9497 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9498 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9499 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9500 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9501 | } |
9502 | ||
9ccd5aeb | 9503 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9504 | val |= D_COMP_COMP_FORCE; |
9505 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9506 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9507 | |
9508 | val = I915_READ(LCPLL_CTL); | |
9509 | val &= ~LCPLL_PLL_DISABLE; | |
9510 | I915_WRITE(LCPLL_CTL, val); | |
9511 | ||
9512 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9513 | DRM_ERROR("LCPLL not locked yet\n"); | |
9514 | ||
9515 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9516 | val = I915_READ(LCPLL_CTL); | |
9517 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9518 | I915_WRITE(LCPLL_CTL, val); | |
9519 | ||
9520 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9521 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9522 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9523 | } | |
215733fa | 9524 | |
59bad947 | 9525 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9526 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9527 | } |
9528 | ||
765dab67 PZ |
9529 | /* |
9530 | * Package states C8 and deeper are really deep PC states that can only be | |
9531 | * reached when all the devices on the system allow it, so even if the graphics | |
9532 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9533 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9534 | * | |
9535 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9536 | * well is disabled and most interrupts are disabled, and these are also | |
9537 | * requirements for runtime PM. When these conditions are met, we manually do | |
9538 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9539 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9540 | * hang the machine. | |
9541 | * | |
9542 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9543 | * the state of some registers, so when we come back from PC8+ we need to | |
9544 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9545 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9546 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9547 | * because of the runtime PM support). | |
9548 | * | |
9549 | * For more, read "Display Sequences for Package C8" on the hardware | |
9550 | * documentation. | |
9551 | */ | |
a14cb6fc | 9552 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9553 | { |
c67a470b PZ |
9554 | struct drm_device *dev = dev_priv->dev; |
9555 | uint32_t val; | |
9556 | ||
c67a470b PZ |
9557 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9558 | ||
c67a470b PZ |
9559 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
9560 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9561 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9562 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9563 | } | |
9564 | ||
9565 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9566 | hsw_disable_lcpll(dev_priv, true, true); |
9567 | } | |
9568 | ||
a14cb6fc | 9569 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9570 | { |
9571 | struct drm_device *dev = dev_priv->dev; | |
9572 | uint32_t val; | |
9573 | ||
c67a470b PZ |
9574 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9575 | ||
9576 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9577 | lpt_init_pch_refclk(dev); |
9578 | ||
9579 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { | |
9580 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9581 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9582 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9583 | } | |
9584 | ||
9585 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9586 | } |
9587 | ||
a821fc46 | 9588 | static void broxton_modeset_global_resources(struct drm_atomic_state *old_state) |
f8437dd1 | 9589 | { |
a821fc46 | 9590 | struct drm_device *dev = old_state->dev; |
f8437dd1 | 9591 | struct drm_i915_private *dev_priv = dev->dev_private; |
a821fc46 | 9592 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
f8437dd1 VK |
9593 | int req_cdclk; |
9594 | ||
9595 | /* see the comment in valleyview_modeset_global_resources */ | |
9596 | if (WARN_ON(max_pixclk < 0)) | |
9597 | return; | |
9598 | ||
9599 | req_cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); | |
9600 | ||
9601 | if (req_cdclk != dev_priv->cdclk_freq) | |
9602 | broxton_set_cdclk(dev, req_cdclk); | |
9603 | } | |
9604 | ||
b432e5cf VS |
9605 | /* compute the max rate for new configuration */ |
9606 | static int ilk_max_pixel_rate(struct drm_i915_private *dev_priv) | |
9607 | { | |
9608 | struct drm_device *dev = dev_priv->dev; | |
9609 | struct intel_crtc *intel_crtc; | |
9610 | struct drm_crtc *crtc; | |
9611 | int max_pixel_rate = 0; | |
9612 | int pixel_rate; | |
9613 | ||
9614 | for_each_crtc(dev, crtc) { | |
9615 | if (!crtc->state->enable) | |
9616 | continue; | |
9617 | ||
9618 | intel_crtc = to_intel_crtc(crtc); | |
9619 | pixel_rate = ilk_pipe_pixel_rate(intel_crtc->config); | |
9620 | ||
9621 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
9622 | if (IS_BROADWELL(dev) && intel_crtc->config->ips_enabled) | |
9623 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); | |
9624 | ||
9625 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9626 | } | |
9627 | ||
9628 | return max_pixel_rate; | |
9629 | } | |
9630 | ||
9631 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9632 | { | |
9633 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9634 | uint32_t val, data; | |
9635 | int ret; | |
9636 | ||
9637 | if (WARN((I915_READ(LCPLL_CTL) & | |
9638 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9639 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9640 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9641 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9642 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9643 | return; | |
9644 | ||
9645 | mutex_lock(&dev_priv->rps.hw_lock); | |
9646 | ret = sandybridge_pcode_write(dev_priv, | |
9647 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9648 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9649 | if (ret) { | |
9650 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9651 | return; | |
9652 | } | |
9653 | ||
9654 | val = I915_READ(LCPLL_CTL); | |
9655 | val |= LCPLL_CD_SOURCE_FCLK; | |
9656 | I915_WRITE(LCPLL_CTL, val); | |
9657 | ||
9658 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9659 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9660 | DRM_ERROR("Switching to FCLK failed\n"); | |
9661 | ||
9662 | val = I915_READ(LCPLL_CTL); | |
9663 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9664 | ||
9665 | switch (cdclk) { | |
9666 | case 450000: | |
9667 | val |= LCPLL_CLK_FREQ_450; | |
9668 | data = 0; | |
9669 | break; | |
9670 | case 540000: | |
9671 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9672 | data = 1; | |
9673 | break; | |
9674 | case 337500: | |
9675 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9676 | data = 2; | |
9677 | break; | |
9678 | case 675000: | |
9679 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9680 | data = 3; | |
9681 | break; | |
9682 | default: | |
9683 | WARN(1, "invalid cdclk frequency\n"); | |
9684 | return; | |
9685 | } | |
9686 | ||
9687 | I915_WRITE(LCPLL_CTL, val); | |
9688 | ||
9689 | val = I915_READ(LCPLL_CTL); | |
9690 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9691 | I915_WRITE(LCPLL_CTL, val); | |
9692 | ||
9693 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9694 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9695 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9696 | ||
9697 | mutex_lock(&dev_priv->rps.hw_lock); | |
9698 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9699 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9700 | ||
9701 | intel_update_cdclk(dev); | |
9702 | ||
9703 | WARN(cdclk != dev_priv->cdclk_freq, | |
9704 | "cdclk requested %d kHz but got %d kHz\n", | |
9705 | cdclk, dev_priv->cdclk_freq); | |
9706 | } | |
9707 | ||
9708 | static int broadwell_calc_cdclk(struct drm_i915_private *dev_priv, | |
9709 | int max_pixel_rate) | |
9710 | { | |
9711 | int cdclk; | |
9712 | ||
9713 | /* | |
9714 | * FIXME should also account for plane ratio | |
9715 | * once 64bpp pixel formats are supported. | |
9716 | */ | |
9717 | if (max_pixel_rate > 540000) | |
9718 | cdclk = 675000; | |
9719 | else if (max_pixel_rate > 450000) | |
9720 | cdclk = 540000; | |
9721 | else if (max_pixel_rate > 337500) | |
9722 | cdclk = 450000; | |
9723 | else | |
9724 | cdclk = 337500; | |
9725 | ||
9726 | /* | |
9727 | * FIXME move the cdclk caclulation to | |
9728 | * compute_config() so we can fail gracegully. | |
9729 | */ | |
9730 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9731 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9732 | cdclk, dev_priv->max_cdclk_freq); | |
9733 | cdclk = dev_priv->max_cdclk_freq; | |
9734 | } | |
9735 | ||
9736 | return cdclk; | |
9737 | } | |
9738 | ||
9739 | static int broadwell_modeset_global_pipes(struct drm_atomic_state *state) | |
9740 | { | |
9741 | struct drm_i915_private *dev_priv = to_i915(state->dev); | |
9742 | struct drm_crtc *crtc; | |
9743 | struct drm_crtc_state *crtc_state; | |
9744 | int max_pixclk = ilk_max_pixel_rate(dev_priv); | |
9745 | int cdclk, i; | |
9746 | ||
9747 | cdclk = broadwell_calc_cdclk(dev_priv, max_pixclk); | |
9748 | ||
9749 | if (cdclk == dev_priv->cdclk_freq) | |
9750 | return 0; | |
9751 | ||
9752 | /* add all active pipes to the state */ | |
9753 | for_each_crtc(state->dev, crtc) { | |
9754 | if (!crtc->state->enable) | |
9755 | continue; | |
9756 | ||
9757 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
9758 | if (IS_ERR(crtc_state)) | |
9759 | return PTR_ERR(crtc_state); | |
9760 | } | |
9761 | ||
9762 | /* disable/enable all currently active pipes while we change cdclk */ | |
9763 | for_each_crtc_in_state(state, crtc, crtc_state, i) | |
9764 | if (crtc_state->enable) | |
9765 | crtc_state->mode_changed = true; | |
9766 | ||
9767 | return 0; | |
9768 | } | |
9769 | ||
9770 | static void broadwell_modeset_global_resources(struct drm_atomic_state *state) | |
9771 | { | |
9772 | struct drm_device *dev = state->dev; | |
9773 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9774 | int max_pixel_rate = ilk_max_pixel_rate(dev_priv); | |
9775 | int req_cdclk = broadwell_calc_cdclk(dev_priv, max_pixel_rate); | |
9776 | ||
9777 | if (req_cdclk != dev_priv->cdclk_freq) | |
9778 | broadwell_set_cdclk(dev, req_cdclk); | |
9779 | } | |
9780 | ||
190f68c5 ACO |
9781 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9782 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9783 | { |
190f68c5 | 9784 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9785 | return -EINVAL; |
716c2e55 | 9786 | |
c7653199 | 9787 | crtc->lowfreq_avail = false; |
644cef34 | 9788 | |
c8f7a0db | 9789 | return 0; |
79e53945 JB |
9790 | } |
9791 | ||
3760b59c S |
9792 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9793 | enum port port, | |
9794 | struct intel_crtc_state *pipe_config) | |
9795 | { | |
9796 | switch (port) { | |
9797 | case PORT_A: | |
9798 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9799 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9800 | break; | |
9801 | case PORT_B: | |
9802 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9803 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9804 | break; | |
9805 | case PORT_C: | |
9806 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9807 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9808 | break; | |
9809 | default: | |
9810 | DRM_ERROR("Incorrect port type\n"); | |
9811 | } | |
9812 | } | |
9813 | ||
96b7dfb7 S |
9814 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9815 | enum port port, | |
5cec258b | 9816 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9817 | { |
3148ade7 | 9818 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9819 | |
9820 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9821 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9822 | ||
9823 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9824 | case SKL_DPLL0: |
9825 | /* | |
9826 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9827 | * of the shared DPLL framework and thus needs to be read out | |
9828 | * separately | |
9829 | */ | |
9830 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9831 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9832 | break; | |
96b7dfb7 S |
9833 | case SKL_DPLL1: |
9834 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9835 | break; | |
9836 | case SKL_DPLL2: | |
9837 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9838 | break; | |
9839 | case SKL_DPLL3: | |
9840 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9841 | break; | |
96b7dfb7 S |
9842 | } |
9843 | } | |
9844 | ||
7d2c8175 DL |
9845 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9846 | enum port port, | |
5cec258b | 9847 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9848 | { |
9849 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9850 | ||
9851 | switch (pipe_config->ddi_pll_sel) { | |
9852 | case PORT_CLK_SEL_WRPLL1: | |
9853 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9854 | break; | |
9855 | case PORT_CLK_SEL_WRPLL2: | |
9856 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9857 | break; | |
9858 | } | |
9859 | } | |
9860 | ||
26804afd | 9861 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9862 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9863 | { |
9864 | struct drm_device *dev = crtc->base.dev; | |
9865 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9866 | struct intel_shared_dpll *pll; |
26804afd DV |
9867 | enum port port; |
9868 | uint32_t tmp; | |
9869 | ||
9870 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9871 | ||
9872 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9873 | ||
96b7dfb7 S |
9874 | if (IS_SKYLAKE(dev)) |
9875 | skylake_get_ddi_pll(dev_priv, port, pipe_config); | |
3760b59c S |
9876 | else if (IS_BROXTON(dev)) |
9877 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9878 | else |
9879 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9880 | |
d452c5b6 DV |
9881 | if (pipe_config->shared_dpll >= 0) { |
9882 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9883 | ||
9884 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9885 | &pipe_config->dpll_hw_state)); | |
9886 | } | |
9887 | ||
26804afd DV |
9888 | /* |
9889 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9890 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9891 | * the PCH transcoder is on. | |
9892 | */ | |
ca370455 DL |
9893 | if (INTEL_INFO(dev)->gen < 9 && |
9894 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9895 | pipe_config->has_pch_encoder = true; |
9896 | ||
9897 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9898 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9899 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9900 | ||
9901 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9902 | } | |
9903 | } | |
9904 | ||
0e8ffe1b | 9905 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9906 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9907 | { |
9908 | struct drm_device *dev = crtc->base.dev; | |
9909 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9910 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9911 | uint32_t tmp; |
9912 | ||
f458ebbc | 9913 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9914 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9915 | return false; | |
9916 | ||
e143a21c | 9917 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9918 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9919 | ||
eccb140b DV |
9920 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9921 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9922 | enum pipe trans_edp_pipe; | |
9923 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9924 | default: | |
9925 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9926 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9927 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9928 | trans_edp_pipe = PIPE_A; | |
9929 | break; | |
9930 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9931 | trans_edp_pipe = PIPE_B; | |
9932 | break; | |
9933 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9934 | trans_edp_pipe = PIPE_C; | |
9935 | break; | |
9936 | } | |
9937 | ||
9938 | if (trans_edp_pipe == crtc->pipe) | |
9939 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9940 | } | |
9941 | ||
f458ebbc | 9942 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9943 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9944 | return false; |
9945 | ||
eccb140b | 9946 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9947 | if (!(tmp & PIPECONF_ENABLE)) |
9948 | return false; | |
9949 | ||
26804afd | 9950 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9951 | |
1bd1bd80 DV |
9952 | intel_get_pipe_timings(crtc, pipe_config); |
9953 | ||
a1b2278e CK |
9954 | if (INTEL_INFO(dev)->gen >= 9) { |
9955 | skl_init_scalers(dev, crtc, pipe_config); | |
9956 | } | |
9957 | ||
2fa2fe9a | 9958 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9959 | |
9960 | if (INTEL_INFO(dev)->gen >= 9) { | |
9961 | pipe_config->scaler_state.scaler_id = -1; | |
9962 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9963 | } | |
9964 | ||
bd2e244f | 9965 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
ff6d9f55 | 9966 | if (INTEL_INFO(dev)->gen == 9) |
bd2e244f | 9967 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9968 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 9969 | ironlake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 JB |
9970 | else |
9971 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
bd2e244f | 9972 | } |
88adfff1 | 9973 | |
e59150dc JB |
9974 | if (IS_HASWELL(dev)) |
9975 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9976 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9977 | |
ebb69c95 CT |
9978 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9979 | pipe_config->pixel_multiplier = | |
9980 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9981 | } else { | |
9982 | pipe_config->pixel_multiplier = 1; | |
9983 | } | |
6c49f241 | 9984 | |
0e8ffe1b DV |
9985 | return true; |
9986 | } | |
9987 | ||
560b85bb CW |
9988 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9989 | { | |
9990 | struct drm_device *dev = crtc->dev; | |
9991 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9992 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9993 | uint32_t cntl = 0, size = 0; |
560b85bb | 9994 | |
dc41c154 | 9995 | if (base) { |
3dd512fb MR |
9996 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9997 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9998 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9999 | ||
10000 | switch (stride) { | |
10001 | default: | |
10002 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
10003 | width, stride); | |
10004 | stride = 256; | |
10005 | /* fallthrough */ | |
10006 | case 256: | |
10007 | case 512: | |
10008 | case 1024: | |
10009 | case 2048: | |
10010 | break; | |
4b0e333e CW |
10011 | } |
10012 | ||
dc41c154 VS |
10013 | cntl |= CURSOR_ENABLE | |
10014 | CURSOR_GAMMA_ENABLE | | |
10015 | CURSOR_FORMAT_ARGB | | |
10016 | CURSOR_STRIDE(stride); | |
10017 | ||
10018 | size = (height << 12) | width; | |
4b0e333e | 10019 | } |
560b85bb | 10020 | |
dc41c154 VS |
10021 | if (intel_crtc->cursor_cntl != 0 && |
10022 | (intel_crtc->cursor_base != base || | |
10023 | intel_crtc->cursor_size != size || | |
10024 | intel_crtc->cursor_cntl != cntl)) { | |
10025 | /* On these chipsets we can only modify the base/size/stride | |
10026 | * whilst the cursor is disabled. | |
10027 | */ | |
10028 | I915_WRITE(_CURACNTR, 0); | |
4b0e333e | 10029 | POSTING_READ(_CURACNTR); |
dc41c154 | 10030 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 10031 | } |
560b85bb | 10032 | |
99d1f387 | 10033 | if (intel_crtc->cursor_base != base) { |
9db4a9c7 | 10034 | I915_WRITE(_CURABASE, base); |
99d1f387 VS |
10035 | intel_crtc->cursor_base = base; |
10036 | } | |
4726e0b0 | 10037 | |
dc41c154 VS |
10038 | if (intel_crtc->cursor_size != size) { |
10039 | I915_WRITE(CURSIZE, size); | |
10040 | intel_crtc->cursor_size = size; | |
4b0e333e | 10041 | } |
560b85bb | 10042 | |
4b0e333e | 10043 | if (intel_crtc->cursor_cntl != cntl) { |
4b0e333e CW |
10044 | I915_WRITE(_CURACNTR, cntl); |
10045 | POSTING_READ(_CURACNTR); | |
4b0e333e | 10046 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 10047 | } |
560b85bb CW |
10048 | } |
10049 | ||
560b85bb | 10050 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
10051 | { |
10052 | struct drm_device *dev = crtc->dev; | |
10053 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10054 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10055 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
10056 | uint32_t cntl; |
10057 | ||
10058 | cntl = 0; | |
10059 | if (base) { | |
10060 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 10061 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
10062 | case 64: |
10063 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
10064 | break; | |
10065 | case 128: | |
10066 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
10067 | break; | |
10068 | case 256: | |
10069 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10070 | break; | |
10071 | default: | |
3dd512fb | 10072 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 10073 | return; |
65a21cd6 | 10074 | } |
4b0e333e | 10075 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 VS |
10076 | |
10077 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
10078 | cntl |= CURSOR_PIPE_CSC_ENABLE; | |
4b0e333e | 10079 | } |
65a21cd6 | 10080 | |
8e7d688b | 10081 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
10082 | cntl |= CURSOR_ROTATE_180; |
10083 | ||
4b0e333e CW |
10084 | if (intel_crtc->cursor_cntl != cntl) { |
10085 | I915_WRITE(CURCNTR(pipe), cntl); | |
10086 | POSTING_READ(CURCNTR(pipe)); | |
10087 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 10088 | } |
4b0e333e | 10089 | |
65a21cd6 | 10090 | /* and commit changes on next vblank */ |
5efb3e28 VS |
10091 | I915_WRITE(CURBASE(pipe), base); |
10092 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
10093 | |
10094 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
10095 | } |
10096 | ||
cda4b7d3 | 10097 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
10098 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
10099 | bool on) | |
cda4b7d3 CW |
10100 | { |
10101 | struct drm_device *dev = crtc->dev; | |
10102 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10103 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10104 | int pipe = intel_crtc->pipe; | |
3d7d6510 MR |
10105 | int x = crtc->cursor_x; |
10106 | int y = crtc->cursor_y; | |
d6e4db15 | 10107 | u32 base = 0, pos = 0; |
cda4b7d3 | 10108 | |
d6e4db15 | 10109 | if (on) |
cda4b7d3 | 10110 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 10111 | |
6e3c9717 | 10112 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
10113 | base = 0; |
10114 | ||
6e3c9717 | 10115 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
10116 | base = 0; |
10117 | ||
10118 | if (x < 0) { | |
3dd512fb | 10119 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
cda4b7d3 CW |
10120 | base = 0; |
10121 | ||
10122 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10123 | x = -x; | |
10124 | } | |
10125 | pos |= x << CURSOR_X_SHIFT; | |
10126 | ||
10127 | if (y < 0) { | |
3dd512fb | 10128 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
cda4b7d3 CW |
10129 | base = 0; |
10130 | ||
10131 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10132 | y = -y; | |
10133 | } | |
10134 | pos |= y << CURSOR_Y_SHIFT; | |
10135 | ||
4b0e333e | 10136 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
10137 | return; |
10138 | ||
5efb3e28 VS |
10139 | I915_WRITE(CURPOS(pipe), pos); |
10140 | ||
4398ad45 VS |
10141 | /* ILK+ do this automagically */ |
10142 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 10143 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
3dd512fb MR |
10144 | base += (intel_crtc->base.cursor->state->crtc_h * |
10145 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; | |
4398ad45 VS |
10146 | } |
10147 | ||
8ac54669 | 10148 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10149 | i845_update_cursor(crtc, base); |
10150 | else | |
10151 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10152 | } |
10153 | ||
dc41c154 VS |
10154 | static bool cursor_size_ok(struct drm_device *dev, |
10155 | uint32_t width, uint32_t height) | |
10156 | { | |
10157 | if (width == 0 || height == 0) | |
10158 | return false; | |
10159 | ||
10160 | /* | |
10161 | * 845g/865g are special in that they are only limited by | |
10162 | * the width of their cursors, the height is arbitrary up to | |
10163 | * the precision of the register. Everything else requires | |
10164 | * square cursors, limited to a few power-of-two sizes. | |
10165 | */ | |
10166 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10167 | if ((width & 63) != 0) | |
10168 | return false; | |
10169 | ||
10170 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10171 | return false; | |
10172 | ||
10173 | if (height > 1023) | |
10174 | return false; | |
10175 | } else { | |
10176 | switch (width | height) { | |
10177 | case 256: | |
10178 | case 128: | |
10179 | if (IS_GEN2(dev)) | |
10180 | return false; | |
10181 | case 64: | |
10182 | break; | |
10183 | default: | |
10184 | return false; | |
10185 | } | |
10186 | } | |
10187 | ||
10188 | return true; | |
10189 | } | |
10190 | ||
79e53945 | 10191 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10192 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10193 | { |
7203425a | 10194 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10195 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10196 | |
7203425a | 10197 | for (i = start; i < end; i++) { |
79e53945 JB |
10198 | intel_crtc->lut_r[i] = red[i] >> 8; |
10199 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10200 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10201 | } | |
10202 | ||
10203 | intel_crtc_load_lut(crtc); | |
10204 | } | |
10205 | ||
79e53945 JB |
10206 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10207 | static struct drm_display_mode load_detect_mode = { | |
10208 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10209 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10210 | }; | |
10211 | ||
a8bb6818 DV |
10212 | struct drm_framebuffer * |
10213 | __intel_framebuffer_create(struct drm_device *dev, | |
10214 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10215 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10216 | { |
10217 | struct intel_framebuffer *intel_fb; | |
10218 | int ret; | |
10219 | ||
10220 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
10221 | if (!intel_fb) { | |
6ccb81f2 | 10222 | drm_gem_object_unreference(&obj->base); |
d2dff872 CW |
10223 | return ERR_PTR(-ENOMEM); |
10224 | } | |
10225 | ||
10226 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10227 | if (ret) |
10228 | goto err; | |
d2dff872 CW |
10229 | |
10230 | return &intel_fb->base; | |
dd4916c5 | 10231 | err: |
6ccb81f2 | 10232 | drm_gem_object_unreference(&obj->base); |
dd4916c5 DV |
10233 | kfree(intel_fb); |
10234 | ||
10235 | return ERR_PTR(ret); | |
d2dff872 CW |
10236 | } |
10237 | ||
b5ea642a | 10238 | static struct drm_framebuffer * |
a8bb6818 DV |
10239 | intel_framebuffer_create(struct drm_device *dev, |
10240 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10241 | struct drm_i915_gem_object *obj) | |
10242 | { | |
10243 | struct drm_framebuffer *fb; | |
10244 | int ret; | |
10245 | ||
10246 | ret = i915_mutex_lock_interruptible(dev); | |
10247 | if (ret) | |
10248 | return ERR_PTR(ret); | |
10249 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10250 | mutex_unlock(&dev->struct_mutex); | |
10251 | ||
10252 | return fb; | |
10253 | } | |
10254 | ||
d2dff872 CW |
10255 | static u32 |
10256 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10257 | { | |
10258 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10259 | return ALIGN(pitch, 64); | |
10260 | } | |
10261 | ||
10262 | static u32 | |
10263 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10264 | { | |
10265 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10266 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10267 | } |
10268 | ||
10269 | static struct drm_framebuffer * | |
10270 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10271 | struct drm_display_mode *mode, | |
10272 | int depth, int bpp) | |
10273 | { | |
10274 | struct drm_i915_gem_object *obj; | |
0fed39bd | 10275 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10276 | |
10277 | obj = i915_gem_alloc_object(dev, | |
10278 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10279 | if (obj == NULL) | |
10280 | return ERR_PTR(-ENOMEM); | |
10281 | ||
10282 | mode_cmd.width = mode->hdisplay; | |
10283 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10284 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10285 | bpp); | |
5ca0c34a | 10286 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 CW |
10287 | |
10288 | return intel_framebuffer_create(dev, &mode_cmd, obj); | |
10289 | } | |
10290 | ||
10291 | static struct drm_framebuffer * | |
10292 | mode_fits_in_fbdev(struct drm_device *dev, | |
10293 | struct drm_display_mode *mode) | |
10294 | { | |
4520f53a | 10295 | #ifdef CONFIG_DRM_I915_FBDEV |
d2dff872 CW |
10296 | struct drm_i915_private *dev_priv = dev->dev_private; |
10297 | struct drm_i915_gem_object *obj; | |
10298 | struct drm_framebuffer *fb; | |
10299 | ||
4c0e5528 | 10300 | if (!dev_priv->fbdev) |
d2dff872 CW |
10301 | return NULL; |
10302 | ||
4c0e5528 | 10303 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10304 | return NULL; |
10305 | ||
4c0e5528 DV |
10306 | obj = dev_priv->fbdev->fb->obj; |
10307 | BUG_ON(!obj); | |
10308 | ||
8bcd4553 | 10309 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10310 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10311 | fb->bits_per_pixel)) | |
d2dff872 CW |
10312 | return NULL; |
10313 | ||
01f2c773 | 10314 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10315 | return NULL; |
10316 | ||
10317 | return fb; | |
4520f53a DV |
10318 | #else |
10319 | return NULL; | |
10320 | #endif | |
d2dff872 CW |
10321 | } |
10322 | ||
d3a40d1b ACO |
10323 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10324 | struct drm_crtc *crtc, | |
10325 | struct drm_display_mode *mode, | |
10326 | struct drm_framebuffer *fb, | |
10327 | int x, int y) | |
10328 | { | |
10329 | struct drm_plane_state *plane_state; | |
10330 | int hdisplay, vdisplay; | |
10331 | int ret; | |
10332 | ||
10333 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10334 | if (IS_ERR(plane_state)) | |
10335 | return PTR_ERR(plane_state); | |
10336 | ||
10337 | if (mode) | |
10338 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10339 | else | |
10340 | hdisplay = vdisplay = 0; | |
10341 | ||
10342 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10343 | if (ret) | |
10344 | return ret; | |
10345 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10346 | plane_state->crtc_x = 0; | |
10347 | plane_state->crtc_y = 0; | |
10348 | plane_state->crtc_w = hdisplay; | |
10349 | plane_state->crtc_h = vdisplay; | |
10350 | plane_state->src_x = x << 16; | |
10351 | plane_state->src_y = y << 16; | |
10352 | plane_state->src_w = hdisplay << 16; | |
10353 | plane_state->src_h = vdisplay << 16; | |
10354 | ||
10355 | return 0; | |
10356 | } | |
10357 | ||
d2434ab7 | 10358 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10359 | struct drm_display_mode *mode, |
51fd371b RC |
10360 | struct intel_load_detect_pipe *old, |
10361 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10362 | { |
10363 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10364 | struct intel_encoder *intel_encoder = |
10365 | intel_attached_encoder(connector); | |
79e53945 | 10366 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10367 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10368 | struct drm_crtc *crtc = NULL; |
10369 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10370 | struct drm_framebuffer *fb; |
51fd371b | 10371 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10372 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10373 | struct drm_connector_state *connector_state; |
4be07317 | 10374 | struct intel_crtc_state *crtc_state; |
51fd371b | 10375 | int ret, i = -1; |
79e53945 | 10376 | |
d2dff872 | 10377 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10378 | connector->base.id, connector->name, |
8e329a03 | 10379 | encoder->base.id, encoder->name); |
d2dff872 | 10380 | |
51fd371b RC |
10381 | retry: |
10382 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10383 | if (ret) | |
10384 | goto fail_unlock; | |
6e9f798d | 10385 | |
79e53945 JB |
10386 | /* |
10387 | * Algorithm gets a little messy: | |
7a5e4805 | 10388 | * |
79e53945 JB |
10389 | * - if the connector already has an assigned crtc, use it (but make |
10390 | * sure it's on first) | |
7a5e4805 | 10391 | * |
79e53945 JB |
10392 | * - try to find the first unused crtc that can drive this connector, |
10393 | * and use that if we find one | |
79e53945 JB |
10394 | */ |
10395 | ||
10396 | /* See if we already have a CRTC for this connector */ | |
10397 | if (encoder->crtc) { | |
10398 | crtc = encoder->crtc; | |
8261b191 | 10399 | |
51fd371b | 10400 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de DV |
10401 | if (ret) |
10402 | goto fail_unlock; | |
10403 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
51fd371b RC |
10404 | if (ret) |
10405 | goto fail_unlock; | |
7b24056b | 10406 | |
24218aac | 10407 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10408 | old->load_detect_temp = false; |
10409 | ||
10410 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10411 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10412 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10413 | |
7173188d | 10414 | return true; |
79e53945 JB |
10415 | } |
10416 | ||
10417 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10418 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10419 | i++; |
10420 | if (!(encoder->possible_crtcs & (1 << i))) | |
10421 | continue; | |
83d65738 | 10422 | if (possible_crtc->state->enable) |
a459249c VS |
10423 | continue; |
10424 | /* This can occur when applying the pipe A quirk on resume. */ | |
10425 | if (to_intel_crtc(possible_crtc)->new_enabled) | |
10426 | continue; | |
10427 | ||
10428 | crtc = possible_crtc; | |
10429 | break; | |
79e53945 JB |
10430 | } |
10431 | ||
10432 | /* | |
10433 | * If we didn't find an unused CRTC, don't use any. | |
10434 | */ | |
10435 | if (!crtc) { | |
7173188d | 10436 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
51fd371b | 10437 | goto fail_unlock; |
79e53945 JB |
10438 | } |
10439 | ||
51fd371b RC |
10440 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10441 | if (ret) | |
4d02e2de DV |
10442 | goto fail_unlock; |
10443 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
10444 | if (ret) | |
51fd371b | 10445 | goto fail_unlock; |
fc303101 DV |
10446 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
10447 | to_intel_connector(connector)->new_encoder = intel_encoder; | |
79e53945 JB |
10448 | |
10449 | intel_crtc = to_intel_crtc(crtc); | |
412b61d8 | 10450 | intel_crtc->new_enabled = true; |
24218aac | 10451 | old->dpms_mode = connector->dpms; |
8261b191 | 10452 | old->load_detect_temp = true; |
d2dff872 | 10453 | old->release_fb = NULL; |
79e53945 | 10454 | |
83a57153 ACO |
10455 | state = drm_atomic_state_alloc(dev); |
10456 | if (!state) | |
10457 | return false; | |
10458 | ||
10459 | state->acquire_ctx = ctx; | |
10460 | ||
944b0c76 ACO |
10461 | connector_state = drm_atomic_get_connector_state(state, connector); |
10462 | if (IS_ERR(connector_state)) { | |
10463 | ret = PTR_ERR(connector_state); | |
10464 | goto fail; | |
10465 | } | |
10466 | ||
10467 | connector_state->crtc = crtc; | |
10468 | connector_state->best_encoder = &intel_encoder->base; | |
10469 | ||
4be07317 ACO |
10470 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10471 | if (IS_ERR(crtc_state)) { | |
10472 | ret = PTR_ERR(crtc_state); | |
10473 | goto fail; | |
10474 | } | |
10475 | ||
49d6fa21 | 10476 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10477 | |
6492711d CW |
10478 | if (!mode) |
10479 | mode = &load_detect_mode; | |
79e53945 | 10480 | |
d2dff872 CW |
10481 | /* We need a framebuffer large enough to accommodate all accesses |
10482 | * that the plane may generate whilst we perform load detection. | |
10483 | * We can not rely on the fbcon either being present (we get called | |
10484 | * during its initialisation to detect all boot displays, or it may | |
10485 | * not even exist) or that it is large enough to satisfy the | |
10486 | * requested mode. | |
10487 | */ | |
94352cf9 DV |
10488 | fb = mode_fits_in_fbdev(dev, mode); |
10489 | if (fb == NULL) { | |
d2dff872 | 10490 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10491 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10492 | old->release_fb = fb; | |
d2dff872 CW |
10493 | } else |
10494 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10495 | if (IS_ERR(fb)) { |
d2dff872 | 10496 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10497 | goto fail; |
79e53945 | 10498 | } |
79e53945 | 10499 | |
d3a40d1b ACO |
10500 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10501 | if (ret) | |
10502 | goto fail; | |
10503 | ||
8c7b5ccb ACO |
10504 | drm_mode_copy(&crtc_state->base.mode, mode); |
10505 | ||
568c634a | 10506 | if (intel_set_mode(state)) { |
6492711d | 10507 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10508 | if (old->release_fb) |
10509 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10510 | goto fail; |
79e53945 | 10511 | } |
9128b040 | 10512 | crtc->primary->crtc = crtc; |
7173188d | 10513 | |
79e53945 | 10514 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10515 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10516 | return true; |
412b61d8 VS |
10517 | |
10518 | fail: | |
83d65738 | 10519 | intel_crtc->new_enabled = crtc->state->enable; |
51fd371b | 10520 | fail_unlock: |
e5d958ef ACO |
10521 | drm_atomic_state_free(state); |
10522 | state = NULL; | |
83a57153 | 10523 | |
51fd371b RC |
10524 | if (ret == -EDEADLK) { |
10525 | drm_modeset_backoff(ctx); | |
10526 | goto retry; | |
10527 | } | |
10528 | ||
412b61d8 | 10529 | return false; |
79e53945 JB |
10530 | } |
10531 | ||
d2434ab7 | 10532 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10533 | struct intel_load_detect_pipe *old, |
10534 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10535 | { |
83a57153 | 10536 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10537 | struct intel_encoder *intel_encoder = |
10538 | intel_attached_encoder(connector); | |
4ef69c7a | 10539 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10540 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10541 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10542 | struct drm_atomic_state *state; |
944b0c76 | 10543 | struct drm_connector_state *connector_state; |
4be07317 | 10544 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10545 | int ret; |
79e53945 | 10546 | |
d2dff872 | 10547 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10548 | connector->base.id, connector->name, |
8e329a03 | 10549 | encoder->base.id, encoder->name); |
d2dff872 | 10550 | |
8261b191 | 10551 | if (old->load_detect_temp) { |
83a57153 | 10552 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10553 | if (!state) |
10554 | goto fail; | |
83a57153 ACO |
10555 | |
10556 | state->acquire_ctx = ctx; | |
10557 | ||
944b0c76 ACO |
10558 | connector_state = drm_atomic_get_connector_state(state, connector); |
10559 | if (IS_ERR(connector_state)) | |
10560 | goto fail; | |
10561 | ||
4be07317 ACO |
10562 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10563 | if (IS_ERR(crtc_state)) | |
10564 | goto fail; | |
10565 | ||
fc303101 DV |
10566 | to_intel_connector(connector)->new_encoder = NULL; |
10567 | intel_encoder->new_crtc = NULL; | |
412b61d8 | 10568 | intel_crtc->new_enabled = false; |
944b0c76 ACO |
10569 | |
10570 | connector_state->best_encoder = NULL; | |
10571 | connector_state->crtc = NULL; | |
10572 | ||
49d6fa21 | 10573 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10574 | |
d3a40d1b ACO |
10575 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10576 | 0, 0); | |
10577 | if (ret) | |
10578 | goto fail; | |
10579 | ||
568c634a | 10580 | ret = intel_set_mode(state); |
2bfb4627 ACO |
10581 | if (ret) |
10582 | goto fail; | |
d2dff872 | 10583 | |
36206361 DV |
10584 | if (old->release_fb) { |
10585 | drm_framebuffer_unregister_private(old->release_fb); | |
10586 | drm_framebuffer_unreference(old->release_fb); | |
10587 | } | |
d2dff872 | 10588 | |
0622a53c | 10589 | return; |
79e53945 JB |
10590 | } |
10591 | ||
c751ce4f | 10592 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10593 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10594 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10595 | |
10596 | return; | |
10597 | fail: | |
10598 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10599 | drm_atomic_state_free(state); | |
79e53945 JB |
10600 | } |
10601 | ||
da4a1efa | 10602 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10603 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10604 | { |
10605 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10606 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10607 | ||
10608 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10609 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10610 | else if (HAS_PCH_SPLIT(dev)) |
10611 | return 120000; | |
10612 | else if (!IS_GEN2(dev)) | |
10613 | return 96000; | |
10614 | else | |
10615 | return 48000; | |
10616 | } | |
10617 | ||
79e53945 | 10618 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10619 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10620 | struct intel_crtc_state *pipe_config) |
79e53945 | 10621 | { |
f1f644dc | 10622 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10623 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10624 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10625 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10626 | u32 fp; |
10627 | intel_clock_t clock; | |
da4a1efa | 10628 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10629 | |
10630 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10631 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10632 | else |
293623f7 | 10633 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10634 | |
10635 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10636 | if (IS_PINEVIEW(dev)) { |
10637 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10638 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10639 | } else { |
10640 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10641 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10642 | } | |
10643 | ||
a6c45cf0 | 10644 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10645 | if (IS_PINEVIEW(dev)) |
10646 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10647 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10648 | else |
10649 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10650 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10651 | ||
10652 | switch (dpll & DPLL_MODE_MASK) { | |
10653 | case DPLLB_MODE_DAC_SERIAL: | |
10654 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10655 | 5 : 10; | |
10656 | break; | |
10657 | case DPLLB_MODE_LVDS: | |
10658 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10659 | 7 : 14; | |
10660 | break; | |
10661 | default: | |
28c97730 | 10662 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10663 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10664 | return; |
79e53945 JB |
10665 | } |
10666 | ||
ac58c3f0 | 10667 | if (IS_PINEVIEW(dev)) |
da4a1efa | 10668 | pineview_clock(refclk, &clock); |
ac58c3f0 | 10669 | else |
da4a1efa | 10670 | i9xx_clock(refclk, &clock); |
79e53945 | 10671 | } else { |
0fb58223 | 10672 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10673 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10674 | |
10675 | if (is_lvds) { | |
10676 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10677 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10678 | |
10679 | if (lvds & LVDS_CLKB_POWER_UP) | |
10680 | clock.p2 = 7; | |
10681 | else | |
10682 | clock.p2 = 14; | |
79e53945 JB |
10683 | } else { |
10684 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10685 | clock.p1 = 2; | |
10686 | else { | |
10687 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10688 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10689 | } | |
10690 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10691 | clock.p2 = 4; | |
10692 | else | |
10693 | clock.p2 = 2; | |
79e53945 | 10694 | } |
da4a1efa VS |
10695 | |
10696 | i9xx_clock(refclk, &clock); | |
79e53945 JB |
10697 | } |
10698 | ||
18442d08 VS |
10699 | /* |
10700 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10701 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10702 | * encoder's get_config() function. |
10703 | */ | |
10704 | pipe_config->port_clock = clock.dot; | |
f1f644dc JB |
10705 | } |
10706 | ||
6878da05 VS |
10707 | int intel_dotclock_calculate(int link_freq, |
10708 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10709 | { |
f1f644dc JB |
10710 | /* |
10711 | * The calculation for the data clock is: | |
1041a02f | 10712 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10713 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10714 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10715 | * |
10716 | * and the link clock is simpler: | |
1041a02f | 10717 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10718 | */ |
10719 | ||
6878da05 VS |
10720 | if (!m_n->link_n) |
10721 | return 0; | |
f1f644dc | 10722 | |
6878da05 VS |
10723 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10724 | } | |
f1f644dc | 10725 | |
18442d08 | 10726 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10727 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10728 | { |
10729 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10730 | |
18442d08 VS |
10731 | /* read out port_clock from the DPLL */ |
10732 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10733 | |
f1f644dc | 10734 | /* |
18442d08 | 10735 | * This value does not include pixel_multiplier. |
241bfc38 | 10736 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10737 | * agree once we know their relationship in the encoder's |
10738 | * get_config() function. | |
79e53945 | 10739 | */ |
2d112de7 | 10740 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10741 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10742 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10743 | } |
10744 | ||
10745 | /** Returns the currently programmed mode of the given pipe. */ | |
10746 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10747 | struct drm_crtc *crtc) | |
10748 | { | |
548f245b | 10749 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10750 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10751 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10752 | struct drm_display_mode *mode; |
5cec258b | 10753 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10754 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10755 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10756 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10757 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10758 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10759 | |
10760 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10761 | if (!mode) | |
10762 | return NULL; | |
10763 | ||
f1f644dc JB |
10764 | /* |
10765 | * Construct a pipe_config sufficient for getting the clock info | |
10766 | * back out of crtc_clock_get. | |
10767 | * | |
10768 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10769 | * to use a real value here instead. | |
10770 | */ | |
293623f7 | 10771 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10772 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10773 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10774 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10775 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10776 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10777 | ||
773ae034 | 10778 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10779 | mode->hdisplay = (htot & 0xffff) + 1; |
10780 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10781 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10782 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10783 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10784 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10785 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10786 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10787 | ||
10788 | drm_mode_set_name(mode); | |
79e53945 JB |
10789 | |
10790 | return mode; | |
10791 | } | |
10792 | ||
652c393a JB |
10793 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
10794 | { | |
10795 | struct drm_device *dev = crtc->dev; | |
fbee40df | 10796 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10797 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
652c393a | 10798 | |
baff296c | 10799 | if (!HAS_GMCH_DISPLAY(dev)) |
652c393a JB |
10800 | return; |
10801 | ||
10802 | if (!dev_priv->lvds_downclock_avail) | |
10803 | return; | |
10804 | ||
10805 | /* | |
10806 | * Since this is called by a timer, we should never get here in | |
10807 | * the manual case. | |
10808 | */ | |
10809 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { | |
dc257cf1 DV |
10810 | int pipe = intel_crtc->pipe; |
10811 | int dpll_reg = DPLL(pipe); | |
10812 | int dpll; | |
f6e5b160 | 10813 | |
44d98a61 | 10814 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
652c393a | 10815 | |
8ac5a6d5 | 10816 | assert_panel_unlocked(dev_priv, pipe); |
652c393a | 10817 | |
dc257cf1 | 10818 | dpll = I915_READ(dpll_reg); |
652c393a JB |
10819 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
10820 | I915_WRITE(dpll_reg, dpll); | |
9d0498a2 | 10821 | intel_wait_for_vblank(dev, pipe); |
652c393a JB |
10822 | dpll = I915_READ(dpll_reg); |
10823 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) | |
44d98a61 | 10824 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
652c393a JB |
10825 | } |
10826 | ||
10827 | } | |
10828 | ||
f047e395 CW |
10829 | void intel_mark_busy(struct drm_device *dev) |
10830 | { | |
c67a470b PZ |
10831 | struct drm_i915_private *dev_priv = dev->dev_private; |
10832 | ||
f62a0076 CW |
10833 | if (dev_priv->mm.busy) |
10834 | return; | |
10835 | ||
43694d69 | 10836 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10837 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10838 | if (INTEL_INFO(dev)->gen >= 6) |
10839 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10840 | dev_priv->mm.busy = true; |
f047e395 CW |
10841 | } |
10842 | ||
10843 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10844 | { |
c67a470b | 10845 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10846 | struct drm_crtc *crtc; |
652c393a | 10847 | |
f62a0076 CW |
10848 | if (!dev_priv->mm.busy) |
10849 | return; | |
10850 | ||
10851 | dev_priv->mm.busy = false; | |
10852 | ||
70e1e0ec | 10853 | for_each_crtc(dev, crtc) { |
f4510a27 | 10854 | if (!crtc->primary->fb) |
652c393a JB |
10855 | continue; |
10856 | ||
725a5b54 | 10857 | intel_decrease_pllclock(crtc); |
652c393a | 10858 | } |
b29c19b6 | 10859 | |
3d13ef2e | 10860 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10861 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10862 | |
43694d69 | 10863 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10864 | } |
10865 | ||
79e53945 JB |
10866 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10867 | { | |
10868 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10869 | struct drm_device *dev = crtc->dev; |
10870 | struct intel_unpin_work *work; | |
67e77c5a | 10871 | |
5e2d7afc | 10872 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10873 | work = intel_crtc->unpin_work; |
10874 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10875 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10876 | |
10877 | if (work) { | |
10878 | cancel_work_sync(&work->work); | |
10879 | kfree(work); | |
10880 | } | |
79e53945 JB |
10881 | |
10882 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10883 | |
79e53945 JB |
10884 | kfree(intel_crtc); |
10885 | } | |
10886 | ||
6b95a207 KH |
10887 | static void intel_unpin_work_fn(struct work_struct *__work) |
10888 | { | |
10889 | struct intel_unpin_work *work = | |
10890 | container_of(__work, struct intel_unpin_work, work); | |
b4a98e57 | 10891 | struct drm_device *dev = work->crtc->dev; |
f99d7069 | 10892 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
6b95a207 | 10893 | |
b4a98e57 | 10894 | mutex_lock(&dev->struct_mutex); |
82bc3b2d | 10895 | intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state); |
05394f39 | 10896 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10897 | |
7ff0ebcc | 10898 | intel_fbc_update(dev); |
f06cc1b9 JH |
10899 | |
10900 | if (work->flip_queued_req) | |
146d84f0 | 10901 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10902 | mutex_unlock(&dev->struct_mutex); |
10903 | ||
f99d7069 | 10904 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
89ed88ba | 10905 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10906 | |
b4a98e57 CW |
10907 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
10908 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); | |
10909 | ||
6b95a207 KH |
10910 | kfree(work); |
10911 | } | |
10912 | ||
1afe3e9d | 10913 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10914 | struct drm_crtc *crtc) |
6b95a207 | 10915 | { |
6b95a207 KH |
10916 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10917 | struct intel_unpin_work *work; | |
6b95a207 KH |
10918 | unsigned long flags; |
10919 | ||
10920 | /* Ignore early vblank irqs */ | |
10921 | if (intel_crtc == NULL) | |
10922 | return; | |
10923 | ||
f326038a DV |
10924 | /* |
10925 | * This is called both by irq handlers and the reset code (to complete | |
10926 | * lost pageflips) so needs the full irqsave spinlocks. | |
10927 | */ | |
6b95a207 KH |
10928 | spin_lock_irqsave(&dev->event_lock, flags); |
10929 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10930 | |
10931 | /* Ensure we don't miss a work->pending update ... */ | |
10932 | smp_rmb(); | |
10933 | ||
10934 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10935 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10936 | return; | |
10937 | } | |
10938 | ||
d6bbafa1 | 10939 | page_flip_completed(intel_crtc); |
0af7e4df | 10940 | |
6b95a207 | 10941 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10942 | } |
10943 | ||
1afe3e9d JB |
10944 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10945 | { | |
fbee40df | 10946 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10947 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10948 | ||
49b14a5c | 10949 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10950 | } |
10951 | ||
10952 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10953 | { | |
fbee40df | 10954 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10955 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10956 | ||
49b14a5c | 10957 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10958 | } |
10959 | ||
75f7f3ec VS |
10960 | /* Is 'a' after or equal to 'b'? */ |
10961 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10962 | { | |
10963 | return !((a - b) & 0x80000000); | |
10964 | } | |
10965 | ||
10966 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10967 | { | |
10968 | struct drm_device *dev = crtc->base.dev; | |
10969 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10970 | ||
bdfa7542 VS |
10971 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10972 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10973 | return true; | |
10974 | ||
75f7f3ec VS |
10975 | /* |
10976 | * The relevant registers doen't exist on pre-ctg. | |
10977 | * As the flip done interrupt doesn't trigger for mmio | |
10978 | * flips on gmch platforms, a flip count check isn't | |
10979 | * really needed there. But since ctg has the registers, | |
10980 | * include it in the check anyway. | |
10981 | */ | |
10982 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10983 | return true; | |
10984 | ||
10985 | /* | |
10986 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10987 | * used the same base address. In that case the mmio flip might | |
10988 | * have completed, but the CS hasn't even executed the flip yet. | |
10989 | * | |
10990 | * A flip count check isn't enough as the CS might have updated | |
10991 | * the base address just after start of vblank, but before we | |
10992 | * managed to process the interrupt. This means we'd complete the | |
10993 | * CS flip too soon. | |
10994 | * | |
10995 | * Combining both checks should get us a good enough result. It may | |
10996 | * still happen that the CS flip has been executed, but has not | |
10997 | * yet actually completed. But in case the base address is the same | |
10998 | * anyway, we don't really care. | |
10999 | */ | |
11000 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
11001 | crtc->unpin_work->gtt_offset && | |
11002 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), | |
11003 | crtc->unpin_work->flip_count); | |
11004 | } | |
11005 | ||
6b95a207 KH |
11006 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
11007 | { | |
fbee40df | 11008 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
11009 | struct intel_crtc *intel_crtc = |
11010 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
11011 | unsigned long flags; | |
11012 | ||
f326038a DV |
11013 | |
11014 | /* | |
11015 | * This is called both by irq handlers and the reset code (to complete | |
11016 | * lost pageflips) so needs the full irqsave spinlocks. | |
11017 | * | |
11018 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
11019 | * generate a page-flip completion irq, i.e. every modeset |
11020 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
11021 | */ | |
6b95a207 | 11022 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 11023 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 11024 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
11025 | spin_unlock_irqrestore(&dev->event_lock, flags); |
11026 | } | |
11027 | ||
eba905b2 | 11028 | static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc) |
e7d841ca CW |
11029 | { |
11030 | /* Ensure that the work item is consistent when activating it ... */ | |
11031 | smp_wmb(); | |
11032 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); | |
11033 | /* and that it is marked active as soon as the irq could fire. */ | |
11034 | smp_wmb(); | |
11035 | } | |
11036 | ||
8c9f3aaf JB |
11037 | static int intel_gen2_queue_flip(struct drm_device *dev, |
11038 | struct drm_crtc *crtc, | |
11039 | struct drm_framebuffer *fb, | |
ed8d1975 | 11040 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11041 | struct intel_engine_cs *ring, |
ed8d1975 | 11042 | uint32_t flags) |
8c9f3aaf | 11043 | { |
8c9f3aaf | 11044 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
11045 | u32 flip_mask; |
11046 | int ret; | |
11047 | ||
6d90c952 | 11048 | ret = intel_ring_begin(ring, 6); |
8c9f3aaf | 11049 | if (ret) |
4fa62c89 | 11050 | return ret; |
8c9f3aaf JB |
11051 | |
11052 | /* Can't queue multiple flips, so wait for the previous | |
11053 | * one to finish before executing the next. | |
11054 | */ | |
11055 | if (intel_crtc->plane) | |
11056 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11057 | else | |
11058 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11059 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11060 | intel_ring_emit(ring, MI_NOOP); | |
11061 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
11062 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11063 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11064 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 11065 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca CW |
11066 | |
11067 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11068 | __intel_ring_advance(ring); |
83d4092b | 11069 | return 0; |
8c9f3aaf JB |
11070 | } |
11071 | ||
11072 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
11073 | struct drm_crtc *crtc, | |
11074 | struct drm_framebuffer *fb, | |
ed8d1975 | 11075 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11076 | struct intel_engine_cs *ring, |
ed8d1975 | 11077 | uint32_t flags) |
8c9f3aaf | 11078 | { |
8c9f3aaf | 11079 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
11080 | u32 flip_mask; |
11081 | int ret; | |
11082 | ||
6d90c952 | 11083 | ret = intel_ring_begin(ring, 6); |
8c9f3aaf | 11084 | if (ret) |
4fa62c89 | 11085 | return ret; |
8c9f3aaf JB |
11086 | |
11087 | if (intel_crtc->plane) | |
11088 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11089 | else | |
11090 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11091 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11092 | intel_ring_emit(ring, MI_NOOP); | |
11093 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
11094 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11095 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11096 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
11097 | intel_ring_emit(ring, MI_NOOP); |
11098 | ||
e7d841ca | 11099 | intel_mark_page_flip_active(intel_crtc); |
09246732 | 11100 | __intel_ring_advance(ring); |
83d4092b | 11101 | return 0; |
8c9f3aaf JB |
11102 | } |
11103 | ||
11104 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
11105 | struct drm_crtc *crtc, | |
11106 | struct drm_framebuffer *fb, | |
ed8d1975 | 11107 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11108 | struct intel_engine_cs *ring, |
ed8d1975 | 11109 | uint32_t flags) |
8c9f3aaf JB |
11110 | { |
11111 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11112 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11113 | uint32_t pf, pipesrc; | |
11114 | int ret; | |
11115 | ||
6d90c952 | 11116 | ret = intel_ring_begin(ring, 4); |
8c9f3aaf | 11117 | if (ret) |
4fa62c89 | 11118 | return ret; |
8c9f3aaf JB |
11119 | |
11120 | /* i965+ uses the linear or tiled offsets from the | |
11121 | * Display Registers (which do not change across a page-flip) | |
11122 | * so we need only reprogram the base address. | |
11123 | */ | |
6d90c952 DV |
11124 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11125 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11126 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11127 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 11128 | obj->tiling_mode); |
8c9f3aaf JB |
11129 | |
11130 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11131 | * untested on non-native modes, so ignore it for now. | |
11132 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11133 | */ | |
11134 | pf = 0; | |
11135 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 11136 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
11137 | |
11138 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11139 | __intel_ring_advance(ring); |
83d4092b | 11140 | return 0; |
8c9f3aaf JB |
11141 | } |
11142 | ||
11143 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
11144 | struct drm_crtc *crtc, | |
11145 | struct drm_framebuffer *fb, | |
ed8d1975 | 11146 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11147 | struct intel_engine_cs *ring, |
ed8d1975 | 11148 | uint32_t flags) |
8c9f3aaf JB |
11149 | { |
11150 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11151 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11152 | uint32_t pf, pipesrc; | |
11153 | int ret; | |
11154 | ||
6d90c952 | 11155 | ret = intel_ring_begin(ring, 4); |
8c9f3aaf | 11156 | if (ret) |
4fa62c89 | 11157 | return ret; |
8c9f3aaf | 11158 | |
6d90c952 DV |
11159 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11160 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11161 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 11162 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 11163 | |
dc257cf1 DV |
11164 | /* Contrary to the suggestions in the documentation, |
11165 | * "Enable Panel Fitter" does not seem to be required when page | |
11166 | * flipping with a non-native mode, and worse causes a normal | |
11167 | * modeset to fail. | |
11168 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11169 | */ | |
11170 | pf = 0; | |
8c9f3aaf | 11171 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 11172 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
11173 | |
11174 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11175 | __intel_ring_advance(ring); |
83d4092b | 11176 | return 0; |
8c9f3aaf JB |
11177 | } |
11178 | ||
7c9017e5 JB |
11179 | static int intel_gen7_queue_flip(struct drm_device *dev, |
11180 | struct drm_crtc *crtc, | |
11181 | struct drm_framebuffer *fb, | |
ed8d1975 | 11182 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11183 | struct intel_engine_cs *ring, |
ed8d1975 | 11184 | uint32_t flags) |
7c9017e5 | 11185 | { |
7c9017e5 | 11186 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 11187 | uint32_t plane_bit = 0; |
ffe74d75 CW |
11188 | int len, ret; |
11189 | ||
eba905b2 | 11190 | switch (intel_crtc->plane) { |
cb05d8de DV |
11191 | case PLANE_A: |
11192 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11193 | break; | |
11194 | case PLANE_B: | |
11195 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11196 | break; | |
11197 | case PLANE_C: | |
11198 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11199 | break; | |
11200 | default: | |
11201 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11202 | return -ENODEV; |
cb05d8de DV |
11203 | } |
11204 | ||
ffe74d75 | 11205 | len = 4; |
f476828a | 11206 | if (ring->id == RCS) { |
ffe74d75 | 11207 | len += 6; |
f476828a DL |
11208 | /* |
11209 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11210 | * 48bits addresses, and we need a NOOP for the batch size to | |
11211 | * stay even. | |
11212 | */ | |
11213 | if (IS_GEN8(dev)) | |
11214 | len += 2; | |
11215 | } | |
ffe74d75 | 11216 | |
f66fab8e VS |
11217 | /* |
11218 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11219 | * "The full packet must be contained within the same cache line." | |
11220 | * | |
11221 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11222 | * cacheline, if we ever start emitting more commands before | |
11223 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11224 | * then do the cacheline alignment, and finally emit the | |
11225 | * MI_DISPLAY_FLIP. | |
11226 | */ | |
11227 | ret = intel_ring_cacheline_align(ring); | |
11228 | if (ret) | |
4fa62c89 | 11229 | return ret; |
f66fab8e | 11230 | |
ffe74d75 | 11231 | ret = intel_ring_begin(ring, len); |
7c9017e5 | 11232 | if (ret) |
4fa62c89 | 11233 | return ret; |
7c9017e5 | 11234 | |
ffe74d75 CW |
11235 | /* Unmask the flip-done completion message. Note that the bspec says that |
11236 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11237 | * more than one flip event at any time (or ensure that one flip message | |
11238 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11239 | * Experimentation says that BCS works despite DERRMR masking all | |
11240 | * flip-done completion events and that unmasking all planes at once | |
11241 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11242 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11243 | */ | |
11244 | if (ring->id == RCS) { | |
11245 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11246 | intel_ring_emit(ring, DERRMR); | |
11247 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11248 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11249 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a DL |
11250 | if (IS_GEN8(dev)) |
11251 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | | |
11252 | MI_SRM_LRM_GLOBAL_GTT); | |
11253 | else | |
11254 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | | |
11255 | MI_SRM_LRM_GLOBAL_GTT); | |
ffe74d75 CW |
11256 | intel_ring_emit(ring, DERRMR); |
11257 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
11258 | if (IS_GEN8(dev)) { |
11259 | intel_ring_emit(ring, 0); | |
11260 | intel_ring_emit(ring, MI_NOOP); | |
11261 | } | |
ffe74d75 CW |
11262 | } |
11263 | ||
cb05d8de | 11264 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11265 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11266 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11267 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca CW |
11268 | |
11269 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11270 | __intel_ring_advance(ring); |
83d4092b | 11271 | return 0; |
7c9017e5 JB |
11272 | } |
11273 | ||
84c33a64 SG |
11274 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11275 | struct drm_i915_gem_object *obj) | |
11276 | { | |
11277 | /* | |
11278 | * This is not being used for older platforms, because | |
11279 | * non-availability of flip done interrupt forces us to use | |
11280 | * CS flips. Older platforms derive flip done using some clever | |
11281 | * tricks involving the flip_pending status bits and vblank irqs. | |
11282 | * So using MMIO flips there would disrupt this mechanism. | |
11283 | */ | |
11284 | ||
8e09bf83 CW |
11285 | if (ring == NULL) |
11286 | return true; | |
11287 | ||
84c33a64 SG |
11288 | if (INTEL_INFO(ring->dev)->gen < 5) |
11289 | return false; | |
11290 | ||
11291 | if (i915.use_mmio_flip < 0) | |
11292 | return false; | |
11293 | else if (i915.use_mmio_flip > 0) | |
11294 | return true; | |
14bf993e OM |
11295 | else if (i915.enable_execlists) |
11296 | return true; | |
84c33a64 | 11297 | else |
b4716185 | 11298 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11299 | } |
11300 | ||
ff944564 DL |
11301 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
11302 | { | |
11303 | struct drm_device *dev = intel_crtc->base.dev; | |
11304 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11305 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 DL |
11306 | const enum pipe pipe = intel_crtc->pipe; |
11307 | u32 ctl, stride; | |
11308 | ||
11309 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11310 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11311 | switch (fb->modifier[0]) { |
11312 | case DRM_FORMAT_MOD_NONE: | |
11313 | break; | |
11314 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11315 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11316 | break; |
11317 | case I915_FORMAT_MOD_Y_TILED: | |
11318 | ctl |= PLANE_CTL_TILED_Y; | |
11319 | break; | |
11320 | case I915_FORMAT_MOD_Yf_TILED: | |
11321 | ctl |= PLANE_CTL_TILED_YF; | |
11322 | break; | |
11323 | default: | |
11324 | MISSING_CASE(fb->modifier[0]); | |
11325 | } | |
ff944564 DL |
11326 | |
11327 | /* | |
11328 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11329 | * linear buffers or in number of tiles for tiled buffers. | |
11330 | */ | |
2ebef630 TU |
11331 | stride = fb->pitches[0] / |
11332 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11333 | fb->pixel_format); | |
ff944564 DL |
11334 | |
11335 | /* | |
11336 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11337 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11338 | */ | |
11339 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11340 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11341 | ||
11342 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); | |
11343 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
11344 | } | |
11345 | ||
11346 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) | |
84c33a64 SG |
11347 | { |
11348 | struct drm_device *dev = intel_crtc->base.dev; | |
11349 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11350 | struct intel_framebuffer *intel_fb = | |
11351 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11352 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11353 | u32 dspcntr; | |
11354 | u32 reg; | |
11355 | ||
84c33a64 SG |
11356 | reg = DSPCNTR(intel_crtc->plane); |
11357 | dspcntr = I915_READ(reg); | |
11358 | ||
c5d97472 DL |
11359 | if (obj->tiling_mode != I915_TILING_NONE) |
11360 | dspcntr |= DISPPLANE_TILED; | |
11361 | else | |
11362 | dspcntr &= ~DISPPLANE_TILED; | |
11363 | ||
84c33a64 SG |
11364 | I915_WRITE(reg, dspcntr); |
11365 | ||
11366 | I915_WRITE(DSPSURF(intel_crtc->plane), | |
11367 | intel_crtc->unpin_work->gtt_offset); | |
11368 | POSTING_READ(DSPSURF(intel_crtc->plane)); | |
84c33a64 | 11369 | |
ff944564 DL |
11370 | } |
11371 | ||
11372 | /* | |
11373 | * XXX: This is the temporary way to update the plane registers until we get | |
11374 | * around to using the usual plane update functions for MMIO flips | |
11375 | */ | |
11376 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) | |
11377 | { | |
11378 | struct drm_device *dev = intel_crtc->base.dev; | |
11379 | bool atomic_update; | |
11380 | u32 start_vbl_count; | |
11381 | ||
11382 | intel_mark_page_flip_active(intel_crtc); | |
11383 | ||
11384 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); | |
11385 | ||
11386 | if (INTEL_INFO(dev)->gen >= 9) | |
11387 | skl_do_mmio_flip(intel_crtc); | |
11388 | else | |
11389 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
11390 | ilk_do_mmio_flip(intel_crtc); | |
11391 | ||
9362c7c5 ACO |
11392 | if (atomic_update) |
11393 | intel_pipe_update_end(intel_crtc, start_vbl_count); | |
84c33a64 SG |
11394 | } |
11395 | ||
9362c7c5 | 11396 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11397 | { |
b2cfe0ab CW |
11398 | struct intel_mmio_flip *mmio_flip = |
11399 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11400 | |
eed29a5b DV |
11401 | if (mmio_flip->req) |
11402 | WARN_ON(__i915_wait_request(mmio_flip->req, | |
b2cfe0ab | 11403 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11404 | false, NULL, |
11405 | &mmio_flip->i915->rps.mmioflips)); | |
84c33a64 | 11406 | |
b2cfe0ab CW |
11407 | intel_do_mmio_flip(mmio_flip->crtc); |
11408 | ||
eed29a5b | 11409 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
b2cfe0ab | 11410 | kfree(mmio_flip); |
84c33a64 SG |
11411 | } |
11412 | ||
11413 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11414 | struct drm_crtc *crtc, | |
11415 | struct drm_framebuffer *fb, | |
11416 | struct drm_i915_gem_object *obj, | |
11417 | struct intel_engine_cs *ring, | |
11418 | uint32_t flags) | |
11419 | { | |
b2cfe0ab CW |
11420 | struct intel_mmio_flip *mmio_flip; |
11421 | ||
11422 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11423 | if (mmio_flip == NULL) | |
11424 | return -ENOMEM; | |
84c33a64 | 11425 | |
bcafc4e3 | 11426 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11427 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11428 | mmio_flip->crtc = to_intel_crtc(crtc); |
536f5b5e | 11429 | |
b2cfe0ab CW |
11430 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11431 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11432 | |
84c33a64 SG |
11433 | return 0; |
11434 | } | |
11435 | ||
8c9f3aaf JB |
11436 | static int intel_default_queue_flip(struct drm_device *dev, |
11437 | struct drm_crtc *crtc, | |
11438 | struct drm_framebuffer *fb, | |
ed8d1975 | 11439 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11440 | struct intel_engine_cs *ring, |
ed8d1975 | 11441 | uint32_t flags) |
8c9f3aaf JB |
11442 | { |
11443 | return -ENODEV; | |
11444 | } | |
11445 | ||
d6bbafa1 CW |
11446 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11447 | struct drm_crtc *crtc) | |
11448 | { | |
11449 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11450 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11451 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11452 | u32 addr; | |
11453 | ||
11454 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11455 | return true; | |
11456 | ||
11457 | if (!work->enable_stall_check) | |
11458 | return false; | |
11459 | ||
11460 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11461 | if (work->flip_queued_req && |
11462 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11463 | return false; |
11464 | ||
1e3feefd | 11465 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11466 | } |
11467 | ||
1e3feefd | 11468 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11469 | return false; |
11470 | ||
11471 | /* Potential stall - if we see that the flip has happened, | |
11472 | * assume a missed interrupt. */ | |
11473 | if (INTEL_INFO(dev)->gen >= 4) | |
11474 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11475 | else | |
11476 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11477 | ||
11478 | /* There is a potential issue here with a false positive after a flip | |
11479 | * to the same address. We could address this by checking for a | |
11480 | * non-incrementing frame counter. | |
11481 | */ | |
11482 | return addr == work->gtt_offset; | |
11483 | } | |
11484 | ||
11485 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11486 | { | |
11487 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11488 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11489 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11490 | struct intel_unpin_work *work; |
f326038a | 11491 | |
6c51d46f | 11492 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11493 | |
11494 | if (crtc == NULL) | |
11495 | return; | |
11496 | ||
f326038a | 11497 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11498 | work = intel_crtc->unpin_work; |
11499 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11500 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11501 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11502 | page_flip_completed(intel_crtc); |
6ad790c0 | 11503 | work = NULL; |
d6bbafa1 | 11504 | } |
6ad790c0 CW |
11505 | if (work != NULL && |
11506 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11507 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11508 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11509 | } |
11510 | ||
6b95a207 KH |
11511 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11512 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11513 | struct drm_pending_vblank_event *event, |
11514 | uint32_t page_flip_flags) | |
6b95a207 KH |
11515 | { |
11516 | struct drm_device *dev = crtc->dev; | |
11517 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11518 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11519 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11520 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11521 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11522 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11523 | struct intel_unpin_work *work; |
a4872ba6 | 11524 | struct intel_engine_cs *ring; |
cf5d8a46 | 11525 | bool mmio_flip; |
52e68630 | 11526 | int ret; |
6b95a207 | 11527 | |
2ff8fde1 MR |
11528 | /* |
11529 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11530 | * check to be safe. In the future we may enable pageflipping from | |
11531 | * a disabled primary plane. | |
11532 | */ | |
11533 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11534 | return -EBUSY; | |
11535 | ||
e6a595d2 | 11536 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11537 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11538 | return -EINVAL; |
11539 | ||
11540 | /* | |
11541 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11542 | * Note that pitch changes could also affect these register. | |
11543 | */ | |
11544 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11545 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11546 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11547 | return -EINVAL; |
11548 | ||
f900db47 CW |
11549 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11550 | goto out_hang; | |
11551 | ||
b14c5679 | 11552 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11553 | if (work == NULL) |
11554 | return -ENOMEM; | |
11555 | ||
6b95a207 | 11556 | work->event = event; |
b4a98e57 | 11557 | work->crtc = crtc; |
ab8d6675 | 11558 | work->old_fb = old_fb; |
6b95a207 KH |
11559 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11560 | ||
87b6b101 | 11561 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11562 | if (ret) |
11563 | goto free_work; | |
11564 | ||
6b95a207 | 11565 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11566 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11567 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11568 | /* Before declaring the flip queue wedged, check if |
11569 | * the hardware completed the operation behind our backs. | |
11570 | */ | |
11571 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11572 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11573 | page_flip_completed(intel_crtc); | |
11574 | } else { | |
11575 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11576 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11577 | |
d6bbafa1 CW |
11578 | drm_crtc_vblank_put(crtc); |
11579 | kfree(work); | |
11580 | return -EBUSY; | |
11581 | } | |
6b95a207 KH |
11582 | } |
11583 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11584 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11585 | |
b4a98e57 CW |
11586 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11587 | flush_workqueue(dev_priv->wq); | |
11588 | ||
75dfca80 | 11589 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11590 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11591 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11592 | |
f4510a27 | 11593 | crtc->primary->fb = fb; |
afd65eb4 | 11594 | update_state_fb(crtc->primary); |
1ed1f968 | 11595 | |
e1f99ce6 | 11596 | work->pending_flip_obj = obj; |
e1f99ce6 | 11597 | |
89ed88ba CW |
11598 | ret = i915_mutex_lock_interruptible(dev); |
11599 | if (ret) | |
11600 | goto cleanup; | |
11601 | ||
b4a98e57 | 11602 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11603 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11604 | |
75f7f3ec | 11605 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
a071fa00 | 11606 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
75f7f3ec | 11607 | |
4fa62c89 VS |
11608 | if (IS_VALLEYVIEW(dev)) { |
11609 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11610 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11611 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11612 | ring = NULL; | |
48bf5b2d | 11613 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11614 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11615 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11616 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11617 | if (ring == NULL || ring->id != RCS) |
11618 | ring = &dev_priv->ring[BCS]; | |
11619 | } else { | |
11620 | ring = &dev_priv->ring[RCS]; | |
11621 | } | |
11622 | ||
cf5d8a46 CW |
11623 | mmio_flip = use_mmio_flip(ring, obj); |
11624 | ||
11625 | /* When using CS flips, we want to emit semaphores between rings. | |
11626 | * However, when using mmio flips we will create a task to do the | |
11627 | * synchronisation, so all we want here is to pin the framebuffer | |
11628 | * into the display plane and skip any waits. | |
11629 | */ | |
82bc3b2d | 11630 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
cf5d8a46 | 11631 | crtc->primary->state, |
b4716185 | 11632 | mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring); |
8c9f3aaf JB |
11633 | if (ret) |
11634 | goto cleanup_pending; | |
6b95a207 | 11635 | |
121920fa TU |
11636 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
11637 | + intel_crtc->dspaddr_offset; | |
4fa62c89 | 11638 | |
cf5d8a46 | 11639 | if (mmio_flip) { |
84c33a64 SG |
11640 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
11641 | page_flip_flags); | |
d6bbafa1 CW |
11642 | if (ret) |
11643 | goto cleanup_unpin; | |
11644 | ||
f06cc1b9 JH |
11645 | i915_gem_request_assign(&work->flip_queued_req, |
11646 | obj->last_write_req); | |
d6bbafa1 | 11647 | } else { |
d94b5030 CW |
11648 | if (obj->last_write_req) { |
11649 | ret = i915_gem_check_olr(obj->last_write_req); | |
11650 | if (ret) | |
11651 | goto cleanup_unpin; | |
11652 | } | |
11653 | ||
84c33a64 | 11654 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
d6bbafa1 CW |
11655 | page_flip_flags); |
11656 | if (ret) | |
11657 | goto cleanup_unpin; | |
11658 | ||
f06cc1b9 JH |
11659 | i915_gem_request_assign(&work->flip_queued_req, |
11660 | intel_ring_get_request(ring)); | |
d6bbafa1 CW |
11661 | } |
11662 | ||
1e3feefd | 11663 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11664 | work->enable_stall_check = true; |
4fa62c89 | 11665 | |
ab8d6675 | 11666 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a071fa00 DV |
11667 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
11668 | ||
7ff0ebcc | 11669 | intel_fbc_disable(dev); |
f99d7069 | 11670 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
6b95a207 KH |
11671 | mutex_unlock(&dev->struct_mutex); |
11672 | ||
e5510fac JB |
11673 | trace_i915_flip_request(intel_crtc->plane, obj); |
11674 | ||
6b95a207 | 11675 | return 0; |
96b099fd | 11676 | |
4fa62c89 | 11677 | cleanup_unpin: |
82bc3b2d | 11678 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11679 | cleanup_pending: |
b4a98e57 | 11680 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11681 | mutex_unlock(&dev->struct_mutex); |
11682 | cleanup: | |
f4510a27 | 11683 | crtc->primary->fb = old_fb; |
afd65eb4 | 11684 | update_state_fb(crtc->primary); |
89ed88ba CW |
11685 | |
11686 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11687 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11688 | |
5e2d7afc | 11689 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11690 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11691 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11692 | |
87b6b101 | 11693 | drm_crtc_vblank_put(crtc); |
7317c75e | 11694 | free_work: |
96b099fd CW |
11695 | kfree(work); |
11696 | ||
f900db47 | 11697 | if (ret == -EIO) { |
02e0efb5 ML |
11698 | struct drm_atomic_state *state; |
11699 | struct drm_plane_state *plane_state; | |
11700 | ||
f900db47 | 11701 | out_hang: |
02e0efb5 ML |
11702 | state = drm_atomic_state_alloc(dev); |
11703 | if (!state) | |
11704 | return -ENOMEM; | |
11705 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11706 | ||
11707 | retry: | |
11708 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11709 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11710 | if (!ret) { | |
11711 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11712 | ||
11713 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11714 | if (!ret) | |
11715 | ret = drm_atomic_commit(state); | |
11716 | } | |
11717 | ||
11718 | if (ret == -EDEADLK) { | |
11719 | drm_modeset_backoff(state->acquire_ctx); | |
11720 | drm_atomic_state_clear(state); | |
11721 | goto retry; | |
11722 | } | |
11723 | ||
11724 | if (ret) | |
11725 | drm_atomic_state_free(state); | |
11726 | ||
f0d3dad3 | 11727 | if (ret == 0 && event) { |
5e2d7afc | 11728 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11729 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11730 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11731 | } |
f900db47 | 11732 | } |
96b099fd | 11733 | return ret; |
6b95a207 KH |
11734 | } |
11735 | ||
da20eabd ML |
11736 | |
11737 | /** | |
11738 | * intel_wm_need_update - Check whether watermarks need updating | |
11739 | * @plane: drm plane | |
11740 | * @state: new plane state | |
11741 | * | |
11742 | * Check current plane state versus the new one to determine whether | |
11743 | * watermarks need to be recalculated. | |
11744 | * | |
11745 | * Returns true or false. | |
11746 | */ | |
11747 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11748 | struct drm_plane_state *state) | |
11749 | { | |
11750 | /* Update watermarks on tiling changes. */ | |
11751 | if (!plane->state->fb || !state->fb || | |
11752 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
11753 | plane->state->rotation != state->rotation) | |
11754 | return true; | |
11755 | ||
11756 | if (plane->state->crtc_w != state->crtc_w) | |
11757 | return true; | |
11758 | ||
11759 | return false; | |
11760 | } | |
11761 | ||
11762 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, | |
11763 | struct drm_plane_state *plane_state) | |
11764 | { | |
11765 | struct drm_crtc *crtc = crtc_state->crtc; | |
11766 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11767 | struct drm_plane *plane = plane_state->plane; | |
11768 | struct drm_device *dev = crtc->dev; | |
11769 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11770 | struct intel_plane_state *old_plane_state = | |
11771 | to_intel_plane_state(plane->state); | |
11772 | int idx = intel_crtc->base.base.id, ret; | |
11773 | int i = drm_plane_index(plane); | |
11774 | bool mode_changed = needs_modeset(crtc_state); | |
11775 | bool was_crtc_enabled = crtc->state->active; | |
11776 | bool is_crtc_enabled = crtc_state->active; | |
11777 | ||
11778 | bool turn_off, turn_on, visible, was_visible; | |
11779 | struct drm_framebuffer *fb = plane_state->fb; | |
11780 | ||
11781 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11782 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11783 | ret = skl_update_scaler_plane( | |
11784 | to_intel_crtc_state(crtc_state), | |
11785 | to_intel_plane_state(plane_state)); | |
11786 | if (ret) | |
11787 | return ret; | |
11788 | } | |
11789 | ||
11790 | /* | |
11791 | * Disabling a plane is always okay; we just need to update | |
11792 | * fb tracking in a special way since cleanup_fb() won't | |
11793 | * get called by the plane helpers. | |
11794 | */ | |
11795 | if (old_plane_state->base.fb && !fb) | |
11796 | intel_crtc->atomic.disabled_planes |= 1 << i; | |
11797 | ||
11798 | /* don't run rest during modeset yet */ | |
11799 | if (!intel_crtc->active || mode_changed) | |
11800 | return 0; | |
11801 | ||
11802 | was_visible = old_plane_state->visible; | |
11803 | visible = to_intel_plane_state(plane_state)->visible; | |
11804 | ||
11805 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11806 | was_visible = false; | |
11807 | ||
11808 | if (!is_crtc_enabled && WARN_ON(visible)) | |
11809 | visible = false; | |
11810 | ||
11811 | if (!was_visible && !visible) | |
11812 | return 0; | |
11813 | ||
11814 | turn_off = was_visible && (!visible || mode_changed); | |
11815 | turn_on = visible && (!was_visible || mode_changed); | |
11816 | ||
11817 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11818 | plane->base.id, fb ? fb->base.id : -1); | |
11819 | ||
11820 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11821 | plane->base.id, was_visible, visible, | |
11822 | turn_off, turn_on, mode_changed); | |
11823 | ||
11824 | if (intel_wm_need_update(plane, plane_state)) | |
11825 | intel_crtc->atomic.update_wm = true; | |
11826 | ||
11827 | switch (plane->type) { | |
11828 | case DRM_PLANE_TYPE_PRIMARY: | |
11829 | if (visible) | |
11830 | intel_crtc->atomic.fb_bits |= | |
11831 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); | |
11832 | ||
11833 | intel_crtc->atomic.wait_for_flips = true; | |
11834 | intel_crtc->atomic.pre_disable_primary = turn_off; | |
11835 | intel_crtc->atomic.post_enable_primary = turn_on; | |
11836 | ||
11837 | if (turn_off) | |
11838 | intel_crtc->atomic.disable_fbc = true; | |
11839 | ||
11840 | /* | |
11841 | * FBC does not work on some platforms for rotated | |
11842 | * planes, so disable it when rotation is not 0 and | |
11843 | * update it when rotation is set back to 0. | |
11844 | * | |
11845 | * FIXME: This is redundant with the fbc update done in | |
11846 | * the primary plane enable function except that that | |
11847 | * one is done too late. We eventually need to unify | |
11848 | * this. | |
11849 | */ | |
11850 | ||
11851 | if (visible && | |
11852 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && | |
11853 | dev_priv->fbc.crtc == intel_crtc && | |
11854 | plane_state->rotation != BIT(DRM_ROTATE_0)) | |
11855 | intel_crtc->atomic.disable_fbc = true; | |
11856 | ||
11857 | /* | |
11858 | * BDW signals flip done immediately if the plane | |
11859 | * is disabled, even if the plane enable is already | |
11860 | * armed to occur at the next vblank :( | |
11861 | */ | |
11862 | if (turn_on && IS_BROADWELL(dev)) | |
11863 | intel_crtc->atomic.wait_vblank = true; | |
11864 | ||
11865 | intel_crtc->atomic.update_fbc |= visible || mode_changed; | |
11866 | break; | |
11867 | case DRM_PLANE_TYPE_CURSOR: | |
11868 | if (visible) | |
11869 | intel_crtc->atomic.fb_bits |= | |
11870 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); | |
11871 | break; | |
11872 | case DRM_PLANE_TYPE_OVERLAY: | |
11873 | /* | |
11874 | * 'prepare' is never called when plane is being disabled, so | |
11875 | * we need to handle frontbuffer tracking as a special case | |
11876 | */ | |
11877 | if (visible) | |
11878 | intel_crtc->atomic.fb_bits |= | |
11879 | INTEL_FRONTBUFFER_SPRITE(intel_crtc->pipe); | |
11880 | ||
d032ffa0 | 11881 | if (turn_off && !mode_changed) { |
da20eabd ML |
11882 | intel_crtc->atomic.wait_vblank = true; |
11883 | intel_crtc->atomic.update_sprite_watermarks |= | |
11884 | 1 << i; | |
11885 | } | |
11886 | break; | |
11887 | } | |
11888 | return 0; | |
11889 | } | |
11890 | ||
6d3a1ce7 ML |
11891 | static bool encoders_cloneable(const struct intel_encoder *a, |
11892 | const struct intel_encoder *b) | |
11893 | { | |
11894 | /* masks could be asymmetric, so check both ways */ | |
11895 | return a == b || (a->cloneable & (1 << b->type) && | |
11896 | b->cloneable & (1 << a->type)); | |
11897 | } | |
11898 | ||
11899 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11900 | struct intel_crtc *crtc, | |
11901 | struct intel_encoder *encoder) | |
11902 | { | |
11903 | struct intel_encoder *source_encoder; | |
11904 | struct drm_connector *connector; | |
11905 | struct drm_connector_state *connector_state; | |
11906 | int i; | |
11907 | ||
11908 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11909 | if (connector_state->crtc != &crtc->base) | |
11910 | continue; | |
11911 | ||
11912 | source_encoder = | |
11913 | to_intel_encoder(connector_state->best_encoder); | |
11914 | if (!encoders_cloneable(encoder, source_encoder)) | |
11915 | return false; | |
11916 | } | |
11917 | ||
11918 | return true; | |
11919 | } | |
11920 | ||
11921 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11922 | struct intel_crtc *crtc) | |
11923 | { | |
11924 | struct intel_encoder *encoder; | |
11925 | struct drm_connector *connector; | |
11926 | struct drm_connector_state *connector_state; | |
11927 | int i; | |
11928 | ||
11929 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11930 | if (connector_state->crtc != &crtc->base) | |
11931 | continue; | |
11932 | ||
11933 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11934 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11935 | return false; | |
11936 | } | |
11937 | ||
11938 | return true; | |
11939 | } | |
11940 | ||
d032ffa0 ML |
11941 | static void intel_crtc_check_initial_planes(struct drm_crtc *crtc, |
11942 | struct drm_crtc_state *crtc_state) | |
11943 | { | |
11944 | struct intel_crtc_state *pipe_config = | |
11945 | to_intel_crtc_state(crtc_state); | |
11946 | struct drm_plane *p; | |
11947 | unsigned visible_mask = 0; | |
11948 | ||
11949 | drm_for_each_plane_mask(p, crtc->dev, crtc_state->plane_mask) { | |
11950 | struct drm_plane_state *plane_state = | |
11951 | drm_atomic_get_existing_plane_state(crtc_state->state, p); | |
11952 | ||
11953 | if (WARN_ON(!plane_state)) | |
11954 | continue; | |
11955 | ||
11956 | if (!plane_state->fb) | |
11957 | crtc_state->plane_mask &= | |
11958 | ~(1 << drm_plane_index(p)); | |
11959 | else if (to_intel_plane_state(plane_state)->visible) | |
11960 | visible_mask |= 1 << drm_plane_index(p); | |
11961 | } | |
11962 | ||
11963 | if (!visible_mask) | |
11964 | return; | |
11965 | ||
11966 | pipe_config->quirks &= ~PIPE_CONFIG_QUIRK_INITIAL_PLANES; | |
11967 | } | |
11968 | ||
6d3a1ce7 ML |
11969 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
11970 | struct drm_crtc_state *crtc_state) | |
11971 | { | |
cf5a15be | 11972 | struct drm_device *dev = crtc->dev; |
ad421372 | 11973 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 11974 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11975 | struct intel_crtc_state *pipe_config = |
11976 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 11977 | struct drm_atomic_state *state = crtc_state->state; |
ad421372 | 11978 | int ret, idx = crtc->base.id; |
6d3a1ce7 ML |
11979 | bool mode_changed = needs_modeset(crtc_state); |
11980 | ||
11981 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11982 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11983 | return -EINVAL; | |
11984 | } | |
11985 | ||
11986 | I915_STATE_WARN(crtc->state->active != intel_crtc->active, | |
11987 | "[CRTC:%i] mismatch between state->active(%i) and crtc->active(%i)\n", | |
11988 | idx, crtc->state->active, intel_crtc->active); | |
11989 | ||
d032ffa0 ML |
11990 | /* plane mask is fixed up after all initial planes are calculated */ |
11991 | if (pipe_config->quirks & PIPE_CONFIG_QUIRK_INITIAL_PLANES) | |
11992 | intel_crtc_check_initial_planes(crtc, crtc_state); | |
11993 | ||
ad421372 ML |
11994 | if (mode_changed && crtc_state->enable && |
11995 | dev_priv->display.crtc_compute_clock && | |
11996 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
11997 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
11998 | pipe_config); | |
11999 | if (ret) | |
12000 | return ret; | |
12001 | } | |
12002 | ||
cf5a15be | 12003 | return intel_atomic_setup_scalers(dev, intel_crtc, pipe_config); |
6d3a1ce7 ML |
12004 | } |
12005 | ||
65b38e0d | 12006 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
12007 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
12008 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
12009 | .atomic_begin = intel_begin_crtc_commit, |
12010 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 12011 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
12012 | }; |
12013 | ||
9a935856 DV |
12014 | /** |
12015 | * intel_modeset_update_staged_output_state | |
12016 | * | |
12017 | * Updates the staged output configuration state, e.g. after we've read out the | |
12018 | * current hw state. | |
12019 | */ | |
12020 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) | |
f6e5b160 | 12021 | { |
7668851f | 12022 | struct intel_crtc *crtc; |
9a935856 DV |
12023 | struct intel_encoder *encoder; |
12024 | struct intel_connector *connector; | |
f6e5b160 | 12025 | |
3a3371ff | 12026 | for_each_intel_connector(dev, connector) { |
9a935856 DV |
12027 | connector->new_encoder = |
12028 | to_intel_encoder(connector->base.encoder); | |
12029 | } | |
f6e5b160 | 12030 | |
b2784e15 | 12031 | for_each_intel_encoder(dev, encoder) { |
9a935856 DV |
12032 | encoder->new_crtc = |
12033 | to_intel_crtc(encoder->base.crtc); | |
12034 | } | |
7668851f | 12035 | |
d3fcc808 | 12036 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12037 | crtc->new_enabled = crtc->base.state->enable; |
7668851f | 12038 | } |
f6e5b160 CW |
12039 | } |
12040 | ||
d29b2f9d ACO |
12041 | /* Transitional helper to copy current connector/encoder state to |
12042 | * connector->state. This is needed so that code that is partially | |
12043 | * converted to atomic does the right thing. | |
12044 | */ | |
12045 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) | |
12046 | { | |
12047 | struct intel_connector *connector; | |
12048 | ||
12049 | for_each_intel_connector(dev, connector) { | |
12050 | if (connector->base.encoder) { | |
12051 | connector->base.state->best_encoder = | |
12052 | connector->base.encoder; | |
12053 | connector->base.state->crtc = | |
12054 | connector->base.encoder->crtc; | |
12055 | } else { | |
12056 | connector->base.state->best_encoder = NULL; | |
12057 | connector->base.state->crtc = NULL; | |
12058 | } | |
12059 | } | |
12060 | } | |
12061 | ||
050f7aeb | 12062 | static void |
eba905b2 | 12063 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 12064 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
12065 | { |
12066 | int bpp = pipe_config->pipe_bpp; | |
12067 | ||
12068 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
12069 | connector->base.base.id, | |
c23cc417 | 12070 | connector->base.name); |
050f7aeb DV |
12071 | |
12072 | /* Don't use an invalid EDID bpc value */ | |
12073 | if (connector->base.display_info.bpc && | |
12074 | connector->base.display_info.bpc * 3 < bpp) { | |
12075 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
12076 | bpp, connector->base.display_info.bpc*3); | |
12077 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
12078 | } | |
12079 | ||
12080 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
12081 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
12082 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
12083 | bpp); | |
12084 | pipe_config->pipe_bpp = 24; | |
12085 | } | |
12086 | } | |
12087 | ||
4e53c2e0 | 12088 | static int |
050f7aeb | 12089 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 12090 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 12091 | { |
050f7aeb | 12092 | struct drm_device *dev = crtc->base.dev; |
1486017f | 12093 | struct drm_atomic_state *state; |
da3ced29 ACO |
12094 | struct drm_connector *connector; |
12095 | struct drm_connector_state *connector_state; | |
1486017f | 12096 | int bpp, i; |
4e53c2e0 | 12097 | |
d328c9d7 | 12098 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 12099 | bpp = 10*3; |
d328c9d7 DV |
12100 | else if (INTEL_INFO(dev)->gen >= 5) |
12101 | bpp = 12*3; | |
12102 | else | |
12103 | bpp = 8*3; | |
12104 | ||
4e53c2e0 | 12105 | |
4e53c2e0 DV |
12106 | pipe_config->pipe_bpp = bpp; |
12107 | ||
1486017f ACO |
12108 | state = pipe_config->base.state; |
12109 | ||
4e53c2e0 | 12110 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
12111 | for_each_connector_in_state(state, connector, connector_state, i) { |
12112 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
12113 | continue; |
12114 | ||
da3ced29 ACO |
12115 | connected_sink_compute_bpp(to_intel_connector(connector), |
12116 | pipe_config); | |
4e53c2e0 DV |
12117 | } |
12118 | ||
12119 | return bpp; | |
12120 | } | |
12121 | ||
644db711 DV |
12122 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
12123 | { | |
12124 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
12125 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 12126 | mode->crtc_clock, |
644db711 DV |
12127 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
12128 | mode->crtc_hsync_end, mode->crtc_htotal, | |
12129 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
12130 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
12131 | } | |
12132 | ||
c0b03411 | 12133 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 12134 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
12135 | const char *context) |
12136 | { | |
6a60cd87 CK |
12137 | struct drm_device *dev = crtc->base.dev; |
12138 | struct drm_plane *plane; | |
12139 | struct intel_plane *intel_plane; | |
12140 | struct intel_plane_state *state; | |
12141 | struct drm_framebuffer *fb; | |
12142 | ||
12143 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
12144 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
12145 | |
12146 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
12147 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
12148 | pipe_config->pipe_bpp, pipe_config->dither); | |
12149 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12150 | pipe_config->has_pch_encoder, | |
12151 | pipe_config->fdi_lanes, | |
12152 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
12153 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
12154 | pipe_config->fdi_m_n.tu); | |
eb14cb74 VS |
12155 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
12156 | pipe_config->has_dp_encoder, | |
12157 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, | |
12158 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
12159 | pipe_config->dp_m_n.tu); | |
b95af8be VK |
12160 | |
12161 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", | |
12162 | pipe_config->has_dp_encoder, | |
12163 | pipe_config->dp_m2_n2.gmch_m, | |
12164 | pipe_config->dp_m2_n2.gmch_n, | |
12165 | pipe_config->dp_m2_n2.link_m, | |
12166 | pipe_config->dp_m2_n2.link_n, | |
12167 | pipe_config->dp_m2_n2.tu); | |
12168 | ||
55072d19 DV |
12169 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
12170 | pipe_config->has_audio, | |
12171 | pipe_config->has_infoframe); | |
12172 | ||
c0b03411 | 12173 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 12174 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 12175 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
12176 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
12177 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 12178 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
12179 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
12180 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
12181 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
12182 | crtc->num_scalers, | |
12183 | pipe_config->scaler_state.scaler_users, | |
12184 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
12185 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12186 | pipe_config->gmch_pfit.control, | |
12187 | pipe_config->gmch_pfit.pgm_ratios, | |
12188 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12189 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12190 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12191 | pipe_config->pch_pfit.size, |
12192 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12193 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12194 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12195 | |
415ff0f6 TU |
12196 | if (IS_BROXTON(dev)) { |
12197 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, " | |
12198 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " | |
12199 | "pll6: 0x%x, pll8: 0x%x, pcsdw12: 0x%x\n", | |
12200 | pipe_config->ddi_pll_sel, | |
12201 | pipe_config->dpll_hw_state.ebb0, | |
12202 | pipe_config->dpll_hw_state.pll0, | |
12203 | pipe_config->dpll_hw_state.pll1, | |
12204 | pipe_config->dpll_hw_state.pll2, | |
12205 | pipe_config->dpll_hw_state.pll3, | |
12206 | pipe_config->dpll_hw_state.pll6, | |
12207 | pipe_config->dpll_hw_state.pll8, | |
12208 | pipe_config->dpll_hw_state.pcsdw12); | |
12209 | } else if (IS_SKYLAKE(dev)) { | |
12210 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " | |
12211 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12212 | pipe_config->ddi_pll_sel, | |
12213 | pipe_config->dpll_hw_state.ctrl1, | |
12214 | pipe_config->dpll_hw_state.cfgcr1, | |
12215 | pipe_config->dpll_hw_state.cfgcr2); | |
12216 | } else if (HAS_DDI(dev)) { | |
12217 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
12218 | pipe_config->ddi_pll_sel, | |
12219 | pipe_config->dpll_hw_state.wrpll); | |
12220 | } else { | |
12221 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12222 | "fp0: 0x%x, fp1: 0x%x\n", | |
12223 | pipe_config->dpll_hw_state.dpll, | |
12224 | pipe_config->dpll_hw_state.dpll_md, | |
12225 | pipe_config->dpll_hw_state.fp0, | |
12226 | pipe_config->dpll_hw_state.fp1); | |
12227 | } | |
12228 | ||
6a60cd87 CK |
12229 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12230 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12231 | intel_plane = to_intel_plane(plane); | |
12232 | if (intel_plane->pipe != crtc->pipe) | |
12233 | continue; | |
12234 | ||
12235 | state = to_intel_plane_state(plane->state); | |
12236 | fb = state->base.fb; | |
12237 | if (!fb) { | |
12238 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12239 | "disabled, scaler_id = %d\n", | |
12240 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12241 | plane->base.id, intel_plane->pipe, | |
12242 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12243 | drm_plane_index(plane), state->scaler_id); | |
12244 | continue; | |
12245 | } | |
12246 | ||
12247 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12248 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12249 | plane->base.id, intel_plane->pipe, | |
12250 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12251 | drm_plane_index(plane)); | |
12252 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12253 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12254 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12255 | state->scaler_id, | |
12256 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12257 | drm_rect_width(&state->src) >> 16, | |
12258 | drm_rect_height(&state->src) >> 16, | |
12259 | state->dst.x1, state->dst.y1, | |
12260 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12261 | } | |
c0b03411 DV |
12262 | } |
12263 | ||
5448a00d | 12264 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12265 | { |
5448a00d ACO |
12266 | struct drm_device *dev = state->dev; |
12267 | struct intel_encoder *encoder; | |
da3ced29 | 12268 | struct drm_connector *connector; |
5448a00d | 12269 | struct drm_connector_state *connector_state; |
00f0b378 | 12270 | unsigned int used_ports = 0; |
5448a00d | 12271 | int i; |
00f0b378 VS |
12272 | |
12273 | /* | |
12274 | * Walk the connector list instead of the encoder | |
12275 | * list to detect the problem on ddi platforms | |
12276 | * where there's just one encoder per digital port. | |
12277 | */ | |
da3ced29 | 12278 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12279 | if (!connector_state->best_encoder) |
00f0b378 VS |
12280 | continue; |
12281 | ||
5448a00d ACO |
12282 | encoder = to_intel_encoder(connector_state->best_encoder); |
12283 | ||
12284 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12285 | |
12286 | switch (encoder->type) { | |
12287 | unsigned int port_mask; | |
12288 | case INTEL_OUTPUT_UNKNOWN: | |
12289 | if (WARN_ON(!HAS_DDI(dev))) | |
12290 | break; | |
12291 | case INTEL_OUTPUT_DISPLAYPORT: | |
12292 | case INTEL_OUTPUT_HDMI: | |
12293 | case INTEL_OUTPUT_EDP: | |
12294 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12295 | ||
12296 | /* the same port mustn't appear more than once */ | |
12297 | if (used_ports & port_mask) | |
12298 | return false; | |
12299 | ||
12300 | used_ports |= port_mask; | |
12301 | default: | |
12302 | break; | |
12303 | } | |
12304 | } | |
12305 | ||
12306 | return true; | |
12307 | } | |
12308 | ||
83a57153 ACO |
12309 | static void |
12310 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12311 | { | |
12312 | struct drm_crtc_state tmp_state; | |
663a3640 | 12313 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12314 | struct intel_dpll_hw_state dpll_hw_state; |
12315 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12316 | uint32_t ddi_pll_sel; |
83a57153 | 12317 | |
7546a384 ACO |
12318 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12319 | * kzalloc'd. Code that depends on any field being zero should be | |
12320 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12321 | * only fields that are know to not cause problems are preserved. */ | |
12322 | ||
83a57153 | 12323 | tmp_state = crtc_state->base; |
663a3640 | 12324 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12325 | shared_dpll = crtc_state->shared_dpll; |
12326 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12327 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
4978cc93 | 12328 | |
83a57153 | 12329 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12330 | |
83a57153 | 12331 | crtc_state->base = tmp_state; |
663a3640 | 12332 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12333 | crtc_state->shared_dpll = shared_dpll; |
12334 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12335 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
83a57153 ACO |
12336 | } |
12337 | ||
548ee15b | 12338 | static int |
b8cecdf5 | 12339 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12340 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12341 | { |
b359283a | 12342 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12343 | struct intel_encoder *encoder; |
da3ced29 | 12344 | struct drm_connector *connector; |
0b901879 | 12345 | struct drm_connector_state *connector_state; |
d328c9d7 | 12346 | int base_bpp, ret = -EINVAL; |
0b901879 | 12347 | int i; |
e29c22c0 | 12348 | bool retry = true; |
ee7b9f93 | 12349 | |
83a57153 | 12350 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12351 | |
e143a21c DV |
12352 | pipe_config->cpu_transcoder = |
12353 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12354 | |
2960bc9c ID |
12355 | /* |
12356 | * Sanitize sync polarity flags based on requested ones. If neither | |
12357 | * positive or negative polarity is requested, treat this as meaning | |
12358 | * negative polarity. | |
12359 | */ | |
2d112de7 | 12360 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12361 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12362 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12363 | |
2d112de7 | 12364 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12365 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12366 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12367 | |
050f7aeb DV |
12368 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
12369 | * plane pixel format and any sink constraints into account. Returns the | |
12370 | * source plane bpp so that dithering can be selected on mismatches | |
12371 | * after encoders and crtc also have had their say. */ | |
d328c9d7 DV |
12372 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12373 | pipe_config); | |
12374 | if (base_bpp < 0) | |
4e53c2e0 DV |
12375 | goto fail; |
12376 | ||
e41a56be VS |
12377 | /* |
12378 | * Determine the real pipe dimensions. Note that stereo modes can | |
12379 | * increase the actual pipe size due to the frame doubling and | |
12380 | * insertion of additional space for blanks between the frame. This | |
12381 | * is stored in the crtc timings. We use the requested mode to do this | |
12382 | * computation to clearly distinguish it from the adjusted mode, which | |
12383 | * can be changed by the connectors in the below retry loop. | |
12384 | */ | |
2d112de7 | 12385 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12386 | &pipe_config->pipe_src_w, |
12387 | &pipe_config->pipe_src_h); | |
e41a56be | 12388 | |
e29c22c0 | 12389 | encoder_retry: |
ef1b460d | 12390 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12391 | pipe_config->port_clock = 0; |
ef1b460d | 12392 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12393 | |
135c81b8 | 12394 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12395 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12396 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12397 | |
7758a113 DV |
12398 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12399 | * adjust it according to limitations or connector properties, and also | |
12400 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12401 | */ |
da3ced29 | 12402 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12403 | if (connector_state->crtc != crtc) |
7758a113 | 12404 | continue; |
7ae89233 | 12405 | |
0b901879 ACO |
12406 | encoder = to_intel_encoder(connector_state->best_encoder); |
12407 | ||
efea6e8e DV |
12408 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12409 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12410 | goto fail; |
12411 | } | |
ee7b9f93 | 12412 | } |
47f1c6c9 | 12413 | |
ff9a6750 DV |
12414 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12415 | * done afterwards in case the encoder adjusts the mode. */ | |
12416 | if (!pipe_config->port_clock) | |
2d112de7 | 12417 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12418 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12419 | |
a43f6e0f | 12420 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12421 | if (ret < 0) { |
7758a113 DV |
12422 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12423 | goto fail; | |
ee7b9f93 | 12424 | } |
e29c22c0 DV |
12425 | |
12426 | if (ret == RETRY) { | |
12427 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12428 | ret = -EINVAL; | |
12429 | goto fail; | |
12430 | } | |
12431 | ||
12432 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12433 | retry = false; | |
12434 | goto encoder_retry; | |
12435 | } | |
12436 | ||
d328c9d7 | 12437 | pipe_config->dither = pipe_config->pipe_bpp != base_bpp; |
4e53c2e0 | 12438 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12439 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12440 | |
cdba954e ACO |
12441 | /* Check if we need to force a modeset */ |
12442 | if (pipe_config->has_audio != | |
85a96e7a | 12443 | to_intel_crtc_state(crtc->state)->has_audio) { |
cdba954e | 12444 | pipe_config->base.mode_changed = true; |
85a96e7a ML |
12445 | ret = drm_atomic_add_affected_planes(state, crtc); |
12446 | } | |
cdba954e ACO |
12447 | |
12448 | /* | |
12449 | * Note we have an issue here with infoframes: current code | |
12450 | * only updates them on the full mode set path per hw | |
12451 | * requirements. So here we should be checking for any | |
12452 | * required changes and forcing a mode set. | |
12453 | */ | |
7758a113 | 12454 | fail: |
548ee15b | 12455 | return ret; |
ee7b9f93 | 12456 | } |
47f1c6c9 | 12457 | |
ea9d758d | 12458 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
f6e5b160 | 12459 | { |
ea9d758d | 12460 | struct drm_encoder *encoder; |
f6e5b160 | 12461 | struct drm_device *dev = crtc->dev; |
f6e5b160 | 12462 | |
ea9d758d DV |
12463 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
12464 | if (encoder->crtc == crtc) | |
12465 | return true; | |
12466 | ||
12467 | return false; | |
12468 | } | |
12469 | ||
12470 | static void | |
0a9ab303 | 12471 | intel_modeset_update_state(struct drm_atomic_state *state) |
ea9d758d | 12472 | { |
0a9ab303 | 12473 | struct drm_device *dev = state->dev; |
ea9d758d | 12474 | struct intel_encoder *intel_encoder; |
0a9ab303 ACO |
12475 | struct drm_crtc *crtc; |
12476 | struct drm_crtc_state *crtc_state; | |
ea9d758d DV |
12477 | struct drm_connector *connector; |
12478 | ||
de419ab6 | 12479 | intel_shared_dpll_commit(state); |
ba41c0de | 12480 | |
b2784e15 | 12481 | for_each_intel_encoder(dev, intel_encoder) { |
ea9d758d DV |
12482 | if (!intel_encoder->base.crtc) |
12483 | continue; | |
12484 | ||
69024de8 ML |
12485 | crtc = intel_encoder->base.crtc; |
12486 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); | |
12487 | if (!crtc_state || !needs_modeset(crtc->state)) | |
12488 | continue; | |
ea9d758d | 12489 | |
69024de8 | 12490 | intel_encoder->connectors_active = false; |
ea9d758d DV |
12491 | } |
12492 | ||
3cb480bc | 12493 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
f7217905 | 12494 | intel_modeset_update_staged_output_state(state->dev); |
ea9d758d | 12495 | |
7668851f | 12496 | /* Double check state. */ |
0a9ab303 ACO |
12497 | for_each_crtc(dev, crtc) { |
12498 | WARN_ON(crtc->state->enable != intel_crtc_in_use(crtc)); | |
3cb480bc ML |
12499 | |
12500 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); | |
fc467a22 ML |
12501 | |
12502 | /* Update hwmode for vblank functions */ | |
12503 | if (crtc->state->active) | |
12504 | crtc->hwmode = crtc->state->adjusted_mode; | |
12505 | else | |
12506 | crtc->hwmode.crtc_clock = 0; | |
ea9d758d DV |
12507 | } |
12508 | ||
12509 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
12510 | if (!connector->encoder || !connector->encoder->crtc) | |
12511 | continue; | |
12512 | ||
69024de8 ML |
12513 | crtc = connector->encoder->crtc; |
12514 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); | |
12515 | if (!crtc_state || !needs_modeset(crtc->state)) | |
12516 | continue; | |
ea9d758d | 12517 | |
53d9f4e9 | 12518 | if (crtc->state->active) { |
69024de8 ML |
12519 | struct drm_property *dpms_property = |
12520 | dev->mode_config.dpms_property; | |
68d34720 | 12521 | |
69024de8 ML |
12522 | connector->dpms = DRM_MODE_DPMS_ON; |
12523 | drm_object_property_set_value(&connector->base, dpms_property, DRM_MODE_DPMS_ON); | |
ea9d758d | 12524 | |
69024de8 ML |
12525 | intel_encoder = to_intel_encoder(connector->encoder); |
12526 | intel_encoder->connectors_active = true; | |
12527 | } else | |
12528 | connector->dpms = DRM_MODE_DPMS_OFF; | |
ea9d758d | 12529 | } |
ea9d758d DV |
12530 | } |
12531 | ||
3bd26263 | 12532 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12533 | { |
3bd26263 | 12534 | int diff; |
f1f644dc JB |
12535 | |
12536 | if (clock1 == clock2) | |
12537 | return true; | |
12538 | ||
12539 | if (!clock1 || !clock2) | |
12540 | return false; | |
12541 | ||
12542 | diff = abs(clock1 - clock2); | |
12543 | ||
12544 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12545 | return true; | |
12546 | ||
12547 | return false; | |
12548 | } | |
12549 | ||
25c5b266 DV |
12550 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12551 | list_for_each_entry((intel_crtc), \ | |
12552 | &(dev)->mode_config.crtc_list, \ | |
12553 | base.head) \ | |
0973f18f | 12554 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12555 | |
0e8ffe1b | 12556 | static bool |
2fa2fe9a | 12557 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b ACO |
12558 | struct intel_crtc_state *current_config, |
12559 | struct intel_crtc_state *pipe_config) | |
0e8ffe1b | 12560 | { |
66e985c0 DV |
12561 | #define PIPE_CONF_CHECK_X(name) \ |
12562 | if (current_config->name != pipe_config->name) { \ | |
12563 | DRM_ERROR("mismatch in " #name " " \ | |
12564 | "(expected 0x%08x, found 0x%08x)\n", \ | |
12565 | current_config->name, \ | |
12566 | pipe_config->name); \ | |
12567 | return false; \ | |
12568 | } | |
12569 | ||
08a24034 DV |
12570 | #define PIPE_CONF_CHECK_I(name) \ |
12571 | if (current_config->name != pipe_config->name) { \ | |
12572 | DRM_ERROR("mismatch in " #name " " \ | |
12573 | "(expected %i, found %i)\n", \ | |
12574 | current_config->name, \ | |
12575 | pipe_config->name); \ | |
12576 | return false; \ | |
88adfff1 DV |
12577 | } |
12578 | ||
b95af8be VK |
12579 | /* This is required for BDW+ where there is only one set of registers for |
12580 | * switching between high and low RR. | |
12581 | * This macro can be used whenever a comparison has to be made between one | |
12582 | * hw state and multiple sw state variables. | |
12583 | */ | |
12584 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12585 | if ((current_config->name != pipe_config->name) && \ | |
12586 | (current_config->alt_name != pipe_config->name)) { \ | |
12587 | DRM_ERROR("mismatch in " #name " " \ | |
12588 | "(expected %i or %i, found %i)\n", \ | |
12589 | current_config->name, \ | |
12590 | current_config->alt_name, \ | |
12591 | pipe_config->name); \ | |
12592 | return false; \ | |
12593 | } | |
12594 | ||
1bd1bd80 DV |
12595 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12596 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
6f02488e | 12597 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12598 | "(expected %i, found %i)\n", \ |
12599 | current_config->name & (mask), \ | |
12600 | pipe_config->name & (mask)); \ | |
12601 | return false; \ | |
12602 | } | |
12603 | ||
5e550656 VS |
12604 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12605 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
12606 | DRM_ERROR("mismatch in " #name " " \ | |
12607 | "(expected %i, found %i)\n", \ | |
12608 | current_config->name, \ | |
12609 | pipe_config->name); \ | |
12610 | return false; \ | |
12611 | } | |
12612 | ||
bb760063 DV |
12613 | #define PIPE_CONF_QUIRK(quirk) \ |
12614 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12615 | ||
eccb140b DV |
12616 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12617 | ||
08a24034 DV |
12618 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12619 | PIPE_CONF_CHECK_I(fdi_lanes); | |
72419203 DV |
12620 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
12621 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); | |
12622 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); | |
12623 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); | |
12624 | PIPE_CONF_CHECK_I(fdi_m_n.tu); | |
08a24034 | 12625 | |
eb14cb74 | 12626 | PIPE_CONF_CHECK_I(has_dp_encoder); |
b95af8be VK |
12627 | |
12628 | if (INTEL_INFO(dev)->gen < 8) { | |
12629 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); | |
12630 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); | |
12631 | PIPE_CONF_CHECK_I(dp_m_n.link_m); | |
12632 | PIPE_CONF_CHECK_I(dp_m_n.link_n); | |
12633 | PIPE_CONF_CHECK_I(dp_m_n.tu); | |
12634 | ||
12635 | if (current_config->has_drrs) { | |
12636 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); | |
12637 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); | |
12638 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); | |
12639 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); | |
12640 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); | |
12641 | } | |
12642 | } else { | |
12643 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); | |
12644 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); | |
12645 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); | |
12646 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); | |
12647 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); | |
12648 | } | |
eb14cb74 | 12649 | |
2d112de7 ACO |
12650 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12651 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12652 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12653 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12654 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12655 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12656 | |
2d112de7 ACO |
12657 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12658 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12659 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12660 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12661 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12662 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12663 | |
c93f54cf | 12664 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12665 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12666 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12667 | IS_VALLEYVIEW(dev)) | |
12668 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12669 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12670 | |
9ed109a7 DV |
12671 | PIPE_CONF_CHECK_I(has_audio); |
12672 | ||
2d112de7 | 12673 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12674 | DRM_MODE_FLAG_INTERLACE); |
12675 | ||
bb760063 | 12676 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12677 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12678 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12679 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12680 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12681 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12682 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12683 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12684 | DRM_MODE_FLAG_NVSYNC); |
12685 | } | |
045ac3b5 | 12686 | |
37327abd VS |
12687 | PIPE_CONF_CHECK_I(pipe_src_w); |
12688 | PIPE_CONF_CHECK_I(pipe_src_h); | |
1bd1bd80 | 12689 | |
9953599b DV |
12690 | /* |
12691 | * FIXME: BIOS likes to set up a cloned config with lvds+external | |
12692 | * screen. Since we don't yet re-compute the pipe config when moving | |
12693 | * just the lvds port away to another pipe the sw tracking won't match. | |
12694 | * | |
12695 | * Proper atomic modesets with recomputed global state will fix this. | |
12696 | * Until then just don't check gmch state for inherited modes. | |
12697 | */ | |
12698 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { | |
12699 | PIPE_CONF_CHECK_I(gmch_pfit.control); | |
12700 | /* pfit ratios are autocomputed by the hw on gen4+ */ | |
12701 | if (INTEL_INFO(dev)->gen < 4) | |
12702 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
12703 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); | |
12704 | } | |
12705 | ||
fd4daa9c CW |
12706 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
12707 | if (current_config->pch_pfit.enabled) { | |
12708 | PIPE_CONF_CHECK_I(pch_pfit.pos); | |
12709 | PIPE_CONF_CHECK_I(pch_pfit.size); | |
12710 | } | |
2fa2fe9a | 12711 | |
a1b2278e CK |
12712 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12713 | ||
e59150dc JB |
12714 | /* BDW+ don't expose a synchronous way to read the state */ |
12715 | if (IS_HASWELL(dev)) | |
12716 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12717 | |
282740f7 VS |
12718 | PIPE_CONF_CHECK_I(double_wide); |
12719 | ||
26804afd DV |
12720 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12721 | ||
c0d43d62 | 12722 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12723 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12724 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12725 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12726 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12727 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
12728 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12729 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12730 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12731 | |
42571aef VS |
12732 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12733 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12734 | ||
2d112de7 | 12735 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12736 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12737 | |
66e985c0 | 12738 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12739 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12740 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12741 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12742 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12743 | #undef PIPE_CONF_QUIRK |
88adfff1 | 12744 | |
0e8ffe1b DV |
12745 | return true; |
12746 | } | |
12747 | ||
08db6652 DL |
12748 | static void check_wm_state(struct drm_device *dev) |
12749 | { | |
12750 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12751 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12752 | struct intel_crtc *intel_crtc; | |
12753 | int plane; | |
12754 | ||
12755 | if (INTEL_INFO(dev)->gen < 9) | |
12756 | return; | |
12757 | ||
12758 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12759 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12760 | ||
12761 | for_each_intel_crtc(dev, intel_crtc) { | |
12762 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12763 | const enum pipe pipe = intel_crtc->pipe; | |
12764 | ||
12765 | if (!intel_crtc->active) | |
12766 | continue; | |
12767 | ||
12768 | /* planes */ | |
dd740780 | 12769 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12770 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12771 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12772 | ||
12773 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12774 | continue; | |
12775 | ||
12776 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12777 | "(expected (%u,%u), found (%u,%u))\n", | |
12778 | pipe_name(pipe), plane + 1, | |
12779 | sw_entry->start, sw_entry->end, | |
12780 | hw_entry->start, hw_entry->end); | |
12781 | } | |
12782 | ||
12783 | /* cursor */ | |
12784 | hw_entry = &hw_ddb.cursor[pipe]; | |
12785 | sw_entry = &sw_ddb->cursor[pipe]; | |
12786 | ||
12787 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12788 | continue; | |
12789 | ||
12790 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12791 | "(expected (%u,%u), found (%u,%u))\n", | |
12792 | pipe_name(pipe), | |
12793 | sw_entry->start, sw_entry->end, | |
12794 | hw_entry->start, hw_entry->end); | |
12795 | } | |
12796 | } | |
12797 | ||
91d1b4bd DV |
12798 | static void |
12799 | check_connector_state(struct drm_device *dev) | |
8af6cf88 | 12800 | { |
8af6cf88 DV |
12801 | struct intel_connector *connector; |
12802 | ||
3a3371ff | 12803 | for_each_intel_connector(dev, connector) { |
8af6cf88 DV |
12804 | /* This also checks the encoder/connector hw state with the |
12805 | * ->get_hw_state callbacks. */ | |
12806 | intel_connector_check_state(connector); | |
12807 | ||
e2c719b7 | 12808 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
8af6cf88 DV |
12809 | "connector's staged encoder doesn't match current encoder\n"); |
12810 | } | |
91d1b4bd DV |
12811 | } |
12812 | ||
12813 | static void | |
12814 | check_encoder_state(struct drm_device *dev) | |
12815 | { | |
12816 | struct intel_encoder *encoder; | |
12817 | struct intel_connector *connector; | |
8af6cf88 | 12818 | |
b2784e15 | 12819 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 DV |
12820 | bool enabled = false; |
12821 | bool active = false; | |
12822 | enum pipe pipe, tracked_pipe; | |
12823 | ||
12824 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12825 | encoder->base.base.id, | |
8e329a03 | 12826 | encoder->base.name); |
8af6cf88 | 12827 | |
e2c719b7 | 12828 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
8af6cf88 | 12829 | "encoder's stage crtc doesn't match current crtc\n"); |
e2c719b7 | 12830 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
8af6cf88 DV |
12831 | "encoder's active_connectors set, but no crtc\n"); |
12832 | ||
3a3371ff | 12833 | for_each_intel_connector(dev, connector) { |
8af6cf88 DV |
12834 | if (connector->base.encoder != &encoder->base) |
12835 | continue; | |
12836 | enabled = true; | |
12837 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) | |
12838 | active = true; | |
12839 | } | |
0e32b39c DA |
12840 | /* |
12841 | * for MST connectors if we unplug the connector is gone | |
12842 | * away but the encoder is still connected to a crtc | |
12843 | * until a modeset happens in response to the hotplug. | |
12844 | */ | |
12845 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) | |
12846 | continue; | |
12847 | ||
e2c719b7 | 12848 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12849 | "encoder's enabled state mismatch " |
12850 | "(expected %i, found %i)\n", | |
12851 | !!encoder->base.crtc, enabled); | |
e2c719b7 | 12852 | I915_STATE_WARN(active && !encoder->base.crtc, |
8af6cf88 DV |
12853 | "active encoder with no crtc\n"); |
12854 | ||
e2c719b7 | 12855 | I915_STATE_WARN(encoder->connectors_active != active, |
8af6cf88 DV |
12856 | "encoder's computed active state doesn't match tracked active state " |
12857 | "(expected %i, found %i)\n", active, encoder->connectors_active); | |
12858 | ||
12859 | active = encoder->get_hw_state(encoder, &pipe); | |
e2c719b7 | 12860 | I915_STATE_WARN(active != encoder->connectors_active, |
8af6cf88 DV |
12861 | "encoder's hw state doesn't match sw tracking " |
12862 | "(expected %i, found %i)\n", | |
12863 | encoder->connectors_active, active); | |
12864 | ||
12865 | if (!encoder->base.crtc) | |
12866 | continue; | |
12867 | ||
12868 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; | |
e2c719b7 | 12869 | I915_STATE_WARN(active && pipe != tracked_pipe, |
8af6cf88 DV |
12870 | "active encoder's pipe doesn't match" |
12871 | "(expected %i, found %i)\n", | |
12872 | tracked_pipe, pipe); | |
12873 | ||
12874 | } | |
91d1b4bd DV |
12875 | } |
12876 | ||
12877 | static void | |
12878 | check_crtc_state(struct drm_device *dev) | |
12879 | { | |
fbee40df | 12880 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12881 | struct intel_crtc *crtc; |
12882 | struct intel_encoder *encoder; | |
5cec258b | 12883 | struct intel_crtc_state pipe_config; |
8af6cf88 | 12884 | |
d3fcc808 | 12885 | for_each_intel_crtc(dev, crtc) { |
8af6cf88 DV |
12886 | bool enabled = false; |
12887 | bool active = false; | |
12888 | ||
045ac3b5 JB |
12889 | memset(&pipe_config, 0, sizeof(pipe_config)); |
12890 | ||
8af6cf88 DV |
12891 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12892 | crtc->base.base.id); | |
12893 | ||
83d65738 | 12894 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
8af6cf88 DV |
12895 | "active crtc, but not enabled in sw tracking\n"); |
12896 | ||
b2784e15 | 12897 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 DV |
12898 | if (encoder->base.crtc != &crtc->base) |
12899 | continue; | |
12900 | enabled = true; | |
12901 | if (encoder->connectors_active) | |
12902 | active = true; | |
12903 | } | |
6c49f241 | 12904 | |
e2c719b7 | 12905 | I915_STATE_WARN(active != crtc->active, |
8af6cf88 DV |
12906 | "crtc's computed active state doesn't match tracked active state " |
12907 | "(expected %i, found %i)\n", active, crtc->active); | |
83d65738 | 12908 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
8af6cf88 | 12909 | "crtc's computed enabled state doesn't match tracked enabled state " |
83d65738 MR |
12910 | "(expected %i, found %i)\n", enabled, |
12911 | crtc->base.state->enable); | |
8af6cf88 | 12912 | |
0e8ffe1b DV |
12913 | active = dev_priv->display.get_pipe_config(crtc, |
12914 | &pipe_config); | |
d62cf62a | 12915 | |
b6b5d049 VS |
12916 | /* hw state is inconsistent with the pipe quirk */ |
12917 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
12918 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
d62cf62a DV |
12919 | active = crtc->active; |
12920 | ||
b2784e15 | 12921 | for_each_intel_encoder(dev, encoder) { |
3eaba51c | 12922 | enum pipe pipe; |
6c49f241 DV |
12923 | if (encoder->base.crtc != &crtc->base) |
12924 | continue; | |
1d37b689 | 12925 | if (encoder->get_hw_state(encoder, &pipe)) |
6c49f241 DV |
12926 | encoder->get_config(encoder, &pipe_config); |
12927 | } | |
12928 | ||
e2c719b7 | 12929 | I915_STATE_WARN(crtc->active != active, |
0e8ffe1b DV |
12930 | "crtc active state doesn't match with hw state " |
12931 | "(expected %i, found %i)\n", crtc->active, active); | |
12932 | ||
53d9f4e9 ML |
12933 | I915_STATE_WARN(crtc->active != crtc->base.state->active, |
12934 | "transitional active state does not match atomic hw state " | |
12935 | "(expected %i, found %i)\n", crtc->base.state->active, crtc->active); | |
12936 | ||
c0b03411 | 12937 | if (active && |
6e3c9717 | 12938 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
e2c719b7 | 12939 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
c0b03411 DV |
12940 | intel_dump_pipe_config(crtc, &pipe_config, |
12941 | "[hw state]"); | |
6e3c9717 | 12942 | intel_dump_pipe_config(crtc, crtc->config, |
c0b03411 DV |
12943 | "[sw state]"); |
12944 | } | |
8af6cf88 DV |
12945 | } |
12946 | } | |
12947 | ||
91d1b4bd DV |
12948 | static void |
12949 | check_shared_dpll_state(struct drm_device *dev) | |
12950 | { | |
fbee40df | 12951 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12952 | struct intel_crtc *crtc; |
12953 | struct intel_dpll_hw_state dpll_hw_state; | |
12954 | int i; | |
5358901f DV |
12955 | |
12956 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12957 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12958 | int enabled_crtcs = 0, active_crtcs = 0; | |
12959 | bool active; | |
12960 | ||
12961 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12962 | ||
12963 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12964 | ||
12965 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12966 | ||
e2c719b7 | 12967 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12968 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12969 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12970 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12971 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12972 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12973 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12974 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12975 | "pll on state mismatch (expected %i, found %i)\n", |
12976 | pll->on, active); | |
12977 | ||
d3fcc808 | 12978 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12979 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12980 | enabled_crtcs++; |
12981 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12982 | active_crtcs++; | |
12983 | } | |
e2c719b7 | 12984 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12985 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12986 | pll->active, active_crtcs); | |
e2c719b7 | 12987 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12988 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12989 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12990 | |
e2c719b7 | 12991 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12992 | sizeof(dpll_hw_state)), |
12993 | "pll hw state mismatch\n"); | |
5358901f | 12994 | } |
8af6cf88 DV |
12995 | } |
12996 | ||
91d1b4bd DV |
12997 | void |
12998 | intel_modeset_check_state(struct drm_device *dev) | |
12999 | { | |
08db6652 | 13000 | check_wm_state(dev); |
91d1b4bd DV |
13001 | check_connector_state(dev); |
13002 | check_encoder_state(dev); | |
13003 | check_crtc_state(dev); | |
13004 | check_shared_dpll_state(dev); | |
13005 | } | |
13006 | ||
5cec258b | 13007 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
13008 | int dotclock) |
13009 | { | |
13010 | /* | |
13011 | * FDI already provided one idea for the dotclock. | |
13012 | * Yell if the encoder disagrees. | |
13013 | */ | |
2d112de7 | 13014 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 13015 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 13016 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
13017 | } |
13018 | ||
80715b2f VS |
13019 | static void update_scanline_offset(struct intel_crtc *crtc) |
13020 | { | |
13021 | struct drm_device *dev = crtc->base.dev; | |
13022 | ||
13023 | /* | |
13024 | * The scanline counter increments at the leading edge of hsync. | |
13025 | * | |
13026 | * On most platforms it starts counting from vtotal-1 on the | |
13027 | * first active line. That means the scanline counter value is | |
13028 | * always one less than what we would expect. Ie. just after | |
13029 | * start of vblank, which also occurs at start of hsync (on the | |
13030 | * last active line), the scanline counter will read vblank_start-1. | |
13031 | * | |
13032 | * On gen2 the scanline counter starts counting from 1 instead | |
13033 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
13034 | * to keep the value positive), instead of adding one. | |
13035 | * | |
13036 | * On HSW+ the behaviour of the scanline counter depends on the output | |
13037 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
13038 | * there's an extra 1 line difference. So we need to add two instead of | |
13039 | * one to the value. | |
13040 | */ | |
13041 | if (IS_GEN2(dev)) { | |
6e3c9717 | 13042 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
13043 | int vtotal; |
13044 | ||
13045 | vtotal = mode->crtc_vtotal; | |
13046 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
13047 | vtotal /= 2; | |
13048 | ||
13049 | crtc->scanline_offset = vtotal - 1; | |
13050 | } else if (HAS_DDI(dev) && | |
409ee761 | 13051 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
13052 | crtc->scanline_offset = 2; |
13053 | } else | |
13054 | crtc->scanline_offset = 1; | |
13055 | } | |
13056 | ||
ad421372 | 13057 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 13058 | { |
225da59b | 13059 | struct drm_device *dev = state->dev; |
ed6739ef | 13060 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 13061 | struct intel_shared_dpll_config *shared_dpll = NULL; |
ed6739ef | 13062 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
13063 | struct intel_crtc_state *intel_crtc_state; |
13064 | struct drm_crtc *crtc; | |
13065 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 13066 | int i; |
ed6739ef ACO |
13067 | |
13068 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 13069 | return; |
ed6739ef | 13070 | |
0a9ab303 | 13071 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
ad421372 ML |
13072 | int dpll; |
13073 | ||
0a9ab303 | 13074 | intel_crtc = to_intel_crtc(crtc); |
4978cc93 | 13075 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
ad421372 | 13076 | dpll = intel_crtc_state->shared_dpll; |
0a9ab303 | 13077 | |
ad421372 | 13078 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
225da59b ACO |
13079 | continue; |
13080 | ||
ad421372 | 13081 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
0a9ab303 | 13082 | |
ad421372 ML |
13083 | if (!shared_dpll) |
13084 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 13085 | |
ad421372 ML |
13086 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
13087 | } | |
ed6739ef ACO |
13088 | } |
13089 | ||
99d736a2 ML |
13090 | /* |
13091 | * This implements the workaround described in the "notes" section of the mode | |
13092 | * set sequence documentation. When going from no pipes or single pipe to | |
13093 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
13094 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
13095 | */ | |
13096 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
13097 | { | |
13098 | struct drm_crtc_state *crtc_state; | |
13099 | struct intel_crtc *intel_crtc; | |
13100 | struct drm_crtc *crtc; | |
13101 | struct intel_crtc_state *first_crtc_state = NULL; | |
13102 | struct intel_crtc_state *other_crtc_state = NULL; | |
13103 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
13104 | int i; | |
13105 | ||
13106 | /* look at all crtc's that are going to be enabled in during modeset */ | |
13107 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13108 | intel_crtc = to_intel_crtc(crtc); | |
13109 | ||
13110 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
13111 | continue; | |
13112 | ||
13113 | if (first_crtc_state) { | |
13114 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
13115 | break; | |
13116 | } else { | |
13117 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
13118 | first_pipe = intel_crtc->pipe; | |
13119 | } | |
13120 | } | |
13121 | ||
13122 | /* No workaround needed? */ | |
13123 | if (!first_crtc_state) | |
13124 | return 0; | |
13125 | ||
13126 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
13127 | for_each_intel_crtc(state->dev, intel_crtc) { | |
13128 | struct intel_crtc_state *pipe_config; | |
13129 | ||
13130 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
13131 | if (IS_ERR(pipe_config)) | |
13132 | return PTR_ERR(pipe_config); | |
13133 | ||
13134 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
13135 | ||
13136 | if (!pipe_config->base.active || | |
13137 | needs_modeset(&pipe_config->base)) | |
13138 | continue; | |
13139 | ||
13140 | /* 2 or more enabled crtcs means no need for w/a */ | |
13141 | if (enabled_pipe != INVALID_PIPE) | |
13142 | return 0; | |
13143 | ||
13144 | enabled_pipe = intel_crtc->pipe; | |
13145 | } | |
13146 | ||
13147 | if (enabled_pipe != INVALID_PIPE) | |
13148 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
13149 | else if (other_crtc_state) | |
13150 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
13151 | ||
13152 | return 0; | |
13153 | } | |
13154 | ||
054518dd | 13155 | /* Code that should eventually be part of atomic_check() */ |
c347a676 | 13156 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
13157 | { |
13158 | struct drm_device *dev = state->dev; | |
13159 | int ret; | |
13160 | ||
b359283a ML |
13161 | if (!check_digital_port_conflicts(state)) { |
13162 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13163 | return -EINVAL; | |
13164 | } | |
13165 | ||
054518dd ACO |
13166 | /* |
13167 | * See if the config requires any additional preparation, e.g. | |
13168 | * to adjust global state with pipes off. We need to do this | |
13169 | * here so we can get the modeset_pipe updated config for the new | |
13170 | * mode set on this crtc. For other crtcs we need to use the | |
13171 | * adjusted_mode bits in the crtc directly. | |
13172 | */ | |
b432e5cf VS |
13173 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev) || IS_BROADWELL(dev)) { |
13174 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) | |
13175 | ret = valleyview_modeset_global_pipes(state); | |
13176 | else | |
13177 | ret = broadwell_modeset_global_pipes(state); | |
13178 | ||
054518dd ACO |
13179 | if (ret) |
13180 | return ret; | |
13181 | } | |
13182 | ||
ad421372 | 13183 | intel_modeset_clear_plls(state); |
054518dd | 13184 | |
99d736a2 | 13185 | if (IS_HASWELL(dev)) |
ad421372 | 13186 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13187 | |
ad421372 | 13188 | return 0; |
c347a676 ACO |
13189 | } |
13190 | ||
13191 | static int | |
13192 | intel_modeset_compute_config(struct drm_atomic_state *state) | |
13193 | { | |
13194 | struct drm_crtc *crtc; | |
13195 | struct drm_crtc_state *crtc_state; | |
13196 | int ret, i; | |
61333b60 | 13197 | bool any_ms = false; |
c347a676 ACO |
13198 | |
13199 | ret = drm_atomic_helper_check_modeset(state->dev, state); | |
054518dd ACO |
13200 | if (ret) |
13201 | return ret; | |
13202 | ||
c347a676 | 13203 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
61333b60 ML |
13204 | if (!crtc_state->enable) { |
13205 | if (needs_modeset(crtc_state)) | |
13206 | any_ms = true; | |
c347a676 | 13207 | continue; |
61333b60 | 13208 | } |
c347a676 | 13209 | |
d032ffa0 ML |
13210 | if (to_intel_crtc_state(crtc_state)->quirks & |
13211 | PIPE_CONFIG_QUIRK_INITIAL_PLANES) { | |
13212 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13213 | if (ret) | |
13214 | return ret; | |
13215 | ||
13216 | /* | |
13217 | * We ought to handle i915.fastboot here. | |
13218 | * If no modeset is required and the primary plane has | |
13219 | * a fb, update the members of crtc_state as needed, | |
13220 | * and run the necessary updates during vblank evasion. | |
13221 | */ | |
13222 | } | |
13223 | ||
b359283a ML |
13224 | if (!needs_modeset(crtc_state)) { |
13225 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13226 | if (ret) | |
13227 | return ret; | |
13228 | } | |
13229 | ||
13230 | ret = intel_modeset_pipe_config(crtc, | |
13231 | to_intel_crtc_state(crtc_state)); | |
c347a676 ACO |
13232 | if (ret) |
13233 | return ret; | |
13234 | ||
61333b60 ML |
13235 | if (needs_modeset(crtc_state)) |
13236 | any_ms = true; | |
13237 | ||
c347a676 ACO |
13238 | intel_dump_pipe_config(to_intel_crtc(crtc), |
13239 | to_intel_crtc_state(crtc_state), | |
13240 | "[modeset]"); | |
13241 | } | |
13242 | ||
61333b60 ML |
13243 | if (any_ms) { |
13244 | ret = intel_modeset_checks(state); | |
13245 | ||
13246 | if (ret) | |
13247 | return ret; | |
13248 | } | |
c347a676 ACO |
13249 | |
13250 | return drm_atomic_helper_check_planes(state->dev, state); | |
054518dd ACO |
13251 | } |
13252 | ||
c72d969b | 13253 | static int __intel_set_mode(struct drm_atomic_state *state) |
a6778b3c | 13254 | { |
c72d969b | 13255 | struct drm_device *dev = state->dev; |
fbee40df | 13256 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 ACO |
13257 | struct drm_crtc *crtc; |
13258 | struct drm_crtc_state *crtc_state; | |
c0c36b94 | 13259 | int ret = 0; |
0a9ab303 | 13260 | int i; |
61333b60 | 13261 | bool any_ms = false; |
a6778b3c | 13262 | |
d4afb8cc ACO |
13263 | ret = drm_atomic_helper_prepare_planes(dev, state); |
13264 | if (ret) | |
13265 | return ret; | |
13266 | ||
1c5e19f8 ML |
13267 | drm_atomic_helper_swap_state(dev, state); |
13268 | ||
0a9ab303 | 13269 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
61333b60 ML |
13270 | if (!needs_modeset(crtc->state)) |
13271 | continue; | |
13272 | ||
13273 | any_ms = true; | |
13274 | if (!crtc_state->active) | |
0a9ab303 | 13275 | continue; |
460da916 | 13276 | |
d032ffa0 | 13277 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); |
69024de8 | 13278 | dev_priv->display.crtc_disable(crtc); |
b8cecdf5 | 13279 | } |
7758a113 | 13280 | |
ea9d758d DV |
13281 | /* Only after disabling all output pipelines that will be changed can we |
13282 | * update the the output configuration. */ | |
0a9ab303 | 13283 | intel_modeset_update_state(state); |
f6e5b160 | 13284 | |
a821fc46 ACO |
13285 | /* The state has been swaped above, so state actually contains the |
13286 | * old state now. */ | |
61333b60 ML |
13287 | if (any_ms) |
13288 | modeset_update_crtc_power_domains(state); | |
47fab737 | 13289 | |
a6778b3c | 13290 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13291 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5ac1c4bc ML |
13292 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
13293 | ||
53d9f4e9 | 13294 | if (!needs_modeset(crtc->state) || !crtc->state->active) |
0a9ab303 ACO |
13295 | continue; |
13296 | ||
13297 | update_scanline_offset(to_intel_crtc(crtc)); | |
80715b2f | 13298 | |
0a9ab303 ACO |
13299 | dev_priv->display.crtc_enable(crtc); |
13300 | intel_crtc_enable_planes(crtc); | |
80715b2f | 13301 | } |
a6778b3c | 13302 | |
a6778b3c | 13303 | /* FIXME: add subpixel order */ |
83a57153 | 13304 | |
d4afb8cc ACO |
13305 | drm_atomic_helper_cleanup_planes(dev, state); |
13306 | ||
2bfb4627 ACO |
13307 | drm_atomic_state_free(state); |
13308 | ||
9eb45f22 | 13309 | return 0; |
f6e5b160 CW |
13310 | } |
13311 | ||
568c634a | 13312 | static int intel_set_mode_checked(struct drm_atomic_state *state) |
f30da187 | 13313 | { |
568c634a | 13314 | struct drm_device *dev = state->dev; |
f30da187 DV |
13315 | int ret; |
13316 | ||
568c634a | 13317 | ret = __intel_set_mode(state); |
f30da187 | 13318 | if (ret == 0) |
568c634a | 13319 | intel_modeset_check_state(dev); |
f30da187 DV |
13320 | |
13321 | return ret; | |
13322 | } | |
13323 | ||
568c634a | 13324 | static int intel_set_mode(struct drm_atomic_state *state) |
7f27126e | 13325 | { |
568c634a | 13326 | int ret; |
83a57153 | 13327 | |
568c634a | 13328 | ret = intel_modeset_compute_config(state); |
83a57153 | 13329 | if (ret) |
568c634a | 13330 | return ret; |
7f27126e | 13331 | |
568c634a | 13332 | return intel_set_mode_checked(state); |
7f27126e JB |
13333 | } |
13334 | ||
c0c36b94 CW |
13335 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13336 | { | |
83a57153 ACO |
13337 | struct drm_device *dev = crtc->dev; |
13338 | struct drm_atomic_state *state; | |
4be07317 | 13339 | struct intel_crtc *intel_crtc; |
83a57153 ACO |
13340 | struct intel_encoder *encoder; |
13341 | struct intel_connector *connector; | |
13342 | struct drm_connector_state *connector_state; | |
4be07317 | 13343 | struct intel_crtc_state *crtc_state; |
2bfb4627 | 13344 | int ret; |
83a57153 ACO |
13345 | |
13346 | state = drm_atomic_state_alloc(dev); | |
13347 | if (!state) { | |
13348 | DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory", | |
13349 | crtc->base.id); | |
13350 | return; | |
13351 | } | |
13352 | ||
13353 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
13354 | ||
13355 | /* The force restore path in the HW readout code relies on the staged | |
13356 | * config still keeping the user requested config while the actual | |
13357 | * state has been overwritten by the configuration read from HW. We | |
13358 | * need to copy the staged config to the atomic state, otherwise the | |
13359 | * mode set will just reapply the state the HW is already in. */ | |
13360 | for_each_intel_encoder(dev, encoder) { | |
13361 | if (&encoder->new_crtc->base != crtc) | |
13362 | continue; | |
13363 | ||
13364 | for_each_intel_connector(dev, connector) { | |
13365 | if (connector->new_encoder != encoder) | |
13366 | continue; | |
13367 | ||
13368 | connector_state = drm_atomic_get_connector_state(state, &connector->base); | |
13369 | if (IS_ERR(connector_state)) { | |
13370 | DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n", | |
13371 | connector->base.base.id, | |
13372 | connector->base.name, | |
13373 | PTR_ERR(connector_state)); | |
13374 | continue; | |
13375 | } | |
13376 | ||
13377 | connector_state->crtc = crtc; | |
13378 | connector_state->best_encoder = &encoder->base; | |
13379 | } | |
13380 | } | |
13381 | ||
4be07317 ACO |
13382 | for_each_intel_crtc(dev, intel_crtc) { |
13383 | if (intel_crtc->new_enabled == intel_crtc->base.enabled) | |
13384 | continue; | |
13385 | ||
13386 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
13387 | if (IS_ERR(crtc_state)) { | |
13388 | DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n", | |
13389 | intel_crtc->base.base.id, | |
13390 | PTR_ERR(crtc_state)); | |
13391 | continue; | |
13392 | } | |
13393 | ||
49d6fa21 ML |
13394 | crtc_state->base.active = crtc_state->base.enable = |
13395 | intel_crtc->new_enabled; | |
8c7b5ccb ACO |
13396 | |
13397 | if (&intel_crtc->base == crtc) | |
13398 | drm_mode_copy(&crtc_state->base.mode, &crtc->mode); | |
4be07317 ACO |
13399 | } |
13400 | ||
d3a40d1b ACO |
13401 | intel_modeset_setup_plane_state(state, crtc, &crtc->mode, |
13402 | crtc->primary->fb, crtc->x, crtc->y); | |
13403 | ||
568c634a | 13404 | ret = intel_set_mode(state); |
2bfb4627 ACO |
13405 | if (ret) |
13406 | drm_atomic_state_free(state); | |
c0c36b94 CW |
13407 | } |
13408 | ||
25c5b266 DV |
13409 | #undef for_each_intel_crtc_masked |
13410 | ||
b7885264 ACO |
13411 | static bool intel_connector_in_mode_set(struct intel_connector *connector, |
13412 | struct drm_mode_set *set) | |
13413 | { | |
13414 | int ro; | |
13415 | ||
13416 | for (ro = 0; ro < set->num_connectors; ro++) | |
13417 | if (set->connectors[ro] == &connector->base) | |
13418 | return true; | |
13419 | ||
13420 | return false; | |
13421 | } | |
13422 | ||
2e431051 | 13423 | static int |
9a935856 DV |
13424 | intel_modeset_stage_output_state(struct drm_device *dev, |
13425 | struct drm_mode_set *set, | |
944b0c76 | 13426 | struct drm_atomic_state *state) |
50f56119 | 13427 | { |
9a935856 | 13428 | struct intel_connector *connector; |
d5432a9d | 13429 | struct drm_connector *drm_connector; |
944b0c76 | 13430 | struct drm_connector_state *connector_state; |
d5432a9d ACO |
13431 | struct drm_crtc *crtc; |
13432 | struct drm_crtc_state *crtc_state; | |
13433 | int i, ret; | |
50f56119 | 13434 | |
9abdda74 | 13435 | /* The upper layers ensure that we either disable a crtc or have a list |
9a935856 DV |
13436 | * of connectors. For paranoia, double-check this. */ |
13437 | WARN_ON(!set->fb && (set->num_connectors != 0)); | |
13438 | WARN_ON(set->fb && (set->num_connectors == 0)); | |
13439 | ||
3a3371ff | 13440 | for_each_intel_connector(dev, connector) { |
b7885264 ACO |
13441 | bool in_mode_set = intel_connector_in_mode_set(connector, set); |
13442 | ||
d5432a9d ACO |
13443 | if (!in_mode_set && connector->base.state->crtc != set->crtc) |
13444 | continue; | |
13445 | ||
13446 | connector_state = | |
13447 | drm_atomic_get_connector_state(state, &connector->base); | |
13448 | if (IS_ERR(connector_state)) | |
13449 | return PTR_ERR(connector_state); | |
13450 | ||
b7885264 ACO |
13451 | if (in_mode_set) { |
13452 | int pipe = to_intel_crtc(set->crtc)->pipe; | |
d5432a9d ACO |
13453 | connector_state->best_encoder = |
13454 | &intel_find_encoder(connector, pipe)->base; | |
50f56119 DV |
13455 | } |
13456 | ||
d5432a9d | 13457 | if (connector->base.state->crtc != set->crtc) |
b7885264 ACO |
13458 | continue; |
13459 | ||
9a935856 DV |
13460 | /* If we disable the crtc, disable all its connectors. Also, if |
13461 | * the connector is on the changing crtc but not on the new | |
13462 | * connector list, disable it. */ | |
b7885264 | 13463 | if (!set->fb || !in_mode_set) { |
d5432a9d | 13464 | connector_state->best_encoder = NULL; |
9a935856 DV |
13465 | |
13466 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", | |
13467 | connector->base.base.id, | |
c23cc417 | 13468 | connector->base.name); |
9a935856 | 13469 | } |
50f56119 | 13470 | } |
9a935856 | 13471 | /* connector->new_encoder is now updated for all connectors. */ |
50f56119 | 13472 | |
d5432a9d ACO |
13473 | for_each_connector_in_state(state, drm_connector, connector_state, i) { |
13474 | connector = to_intel_connector(drm_connector); | |
13475 | ||
13476 | if (!connector_state->best_encoder) { | |
13477 | ret = drm_atomic_set_crtc_for_connector(connector_state, | |
13478 | NULL); | |
13479 | if (ret) | |
13480 | return ret; | |
7668851f | 13481 | |
50f56119 | 13482 | continue; |
d5432a9d | 13483 | } |
50f56119 | 13484 | |
d5432a9d ACO |
13485 | if (intel_connector_in_mode_set(connector, set)) { |
13486 | struct drm_crtc *crtc = connector->base.state->crtc; | |
13487 | ||
13488 | /* If this connector was in a previous crtc, add it | |
13489 | * to the state. We might need to disable it. */ | |
13490 | if (crtc) { | |
13491 | crtc_state = | |
13492 | drm_atomic_get_crtc_state(state, crtc); | |
13493 | if (IS_ERR(crtc_state)) | |
13494 | return PTR_ERR(crtc_state); | |
13495 | } | |
13496 | ||
13497 | ret = drm_atomic_set_crtc_for_connector(connector_state, | |
13498 | set->crtc); | |
13499 | if (ret) | |
13500 | return ret; | |
13501 | } | |
50f56119 DV |
13502 | |
13503 | /* Make sure the new CRTC will work with the encoder */ | |
d5432a9d ACO |
13504 | if (!drm_encoder_crtc_ok(connector_state->best_encoder, |
13505 | connector_state->crtc)) { | |
5e2b584e | 13506 | return -EINVAL; |
50f56119 | 13507 | } |
944b0c76 | 13508 | |
9a935856 DV |
13509 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
13510 | connector->base.base.id, | |
c23cc417 | 13511 | connector->base.name, |
d5432a9d | 13512 | connector_state->crtc->base.id); |
944b0c76 | 13513 | |
d5432a9d ACO |
13514 | if (connector_state->best_encoder != &connector->encoder->base) |
13515 | connector->encoder = | |
13516 | to_intel_encoder(connector_state->best_encoder); | |
0e32b39c | 13517 | } |
7668851f | 13518 | |
d5432a9d | 13519 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
49d6fa21 ML |
13520 | bool has_connectors; |
13521 | ||
d5432a9d ACO |
13522 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13523 | if (ret) | |
13524 | return ret; | |
4be07317 | 13525 | |
49d6fa21 ML |
13526 | has_connectors = !!drm_atomic_connectors_for_crtc(state, crtc); |
13527 | if (has_connectors != crtc_state->enable) | |
13528 | crtc_state->enable = | |
13529 | crtc_state->active = has_connectors; | |
7668851f VS |
13530 | } |
13531 | ||
8c7b5ccb ACO |
13532 | ret = intel_modeset_setup_plane_state(state, set->crtc, set->mode, |
13533 | set->fb, set->x, set->y); | |
13534 | if (ret) | |
13535 | return ret; | |
13536 | ||
13537 | crtc_state = drm_atomic_get_crtc_state(state, set->crtc); | |
13538 | if (IS_ERR(crtc_state)) | |
13539 | return PTR_ERR(crtc_state); | |
13540 | ||
ce52299c MR |
13541 | ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); |
13542 | if (ret) | |
13543 | return ret; | |
8c7b5ccb ACO |
13544 | |
13545 | if (set->num_connectors) | |
13546 | crtc_state->active = true; | |
13547 | ||
2e431051 DV |
13548 | return 0; |
13549 | } | |
13550 | ||
13551 | static int intel_crtc_set_config(struct drm_mode_set *set) | |
13552 | { | |
13553 | struct drm_device *dev; | |
83a57153 | 13554 | struct drm_atomic_state *state = NULL; |
2e431051 | 13555 | int ret; |
2e431051 | 13556 | |
8d3e375e DV |
13557 | BUG_ON(!set); |
13558 | BUG_ON(!set->crtc); | |
13559 | BUG_ON(!set->crtc->helper_private); | |
2e431051 | 13560 | |
7e53f3a4 DV |
13561 | /* Enforce sane interface api - has been abused by the fb helper. */ |
13562 | BUG_ON(!set->mode && set->fb); | |
13563 | BUG_ON(set->fb && set->num_connectors == 0); | |
431e50f7 | 13564 | |
2e431051 DV |
13565 | if (set->fb) { |
13566 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", | |
13567 | set->crtc->base.id, set->fb->base.id, | |
13568 | (int)set->num_connectors, set->x, set->y); | |
13569 | } else { | |
13570 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); | |
2e431051 DV |
13571 | } |
13572 | ||
13573 | dev = set->crtc->dev; | |
13574 | ||
83a57153 | 13575 | state = drm_atomic_state_alloc(dev); |
7cbf41d6 ACO |
13576 | if (!state) |
13577 | return -ENOMEM; | |
83a57153 ACO |
13578 | |
13579 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
13580 | ||
462a425a | 13581 | ret = intel_modeset_stage_output_state(dev, set, state); |
2e431051 | 13582 | if (ret) |
7cbf41d6 | 13583 | goto out; |
2e431051 | 13584 | |
568c634a ACO |
13585 | ret = intel_modeset_compute_config(state); |
13586 | if (ret) | |
7cbf41d6 | 13587 | goto out; |
50f52756 | 13588 | |
1f9954d0 JB |
13589 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
13590 | ||
568c634a | 13591 | ret = intel_set_mode_checked(state); |
2d05eae1 | 13592 | if (ret) { |
bf67dfeb DV |
13593 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
13594 | set->crtc->base.id, ret); | |
2d05eae1 | 13595 | } |
50f56119 | 13596 | |
7cbf41d6 | 13597 | out: |
2bfb4627 ACO |
13598 | if (ret) |
13599 | drm_atomic_state_free(state); | |
50f56119 DV |
13600 | return ret; |
13601 | } | |
f6e5b160 CW |
13602 | |
13603 | static const struct drm_crtc_funcs intel_crtc_funcs = { | |
f6e5b160 | 13604 | .gamma_set = intel_crtc_gamma_set, |
50f56119 | 13605 | .set_config = intel_crtc_set_config, |
f6e5b160 CW |
13606 | .destroy = intel_crtc_destroy, |
13607 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13608 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13609 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13610 | }; |
13611 | ||
5358901f DV |
13612 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13613 | struct intel_shared_dpll *pll, | |
13614 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13615 | { |
5358901f | 13616 | uint32_t val; |
ee7b9f93 | 13617 | |
f458ebbc | 13618 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13619 | return false; |
13620 | ||
5358901f | 13621 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13622 | hw_state->dpll = val; |
13623 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13624 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13625 | |
13626 | return val & DPLL_VCO_ENABLE; | |
13627 | } | |
13628 | ||
15bdd4cf DV |
13629 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13630 | struct intel_shared_dpll *pll) | |
13631 | { | |
3e369b76 ACO |
13632 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13633 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13634 | } |
13635 | ||
e7b903d2 DV |
13636 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13637 | struct intel_shared_dpll *pll) | |
13638 | { | |
e7b903d2 | 13639 | /* PCH refclock must be enabled first */ |
89eff4be | 13640 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13641 | |
3e369b76 | 13642 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13643 | |
13644 | /* Wait for the clocks to stabilize. */ | |
13645 | POSTING_READ(PCH_DPLL(pll->id)); | |
13646 | udelay(150); | |
13647 | ||
13648 | /* The pixel multiplier can only be updated once the | |
13649 | * DPLL is enabled and the clocks are stable. | |
13650 | * | |
13651 | * So write it again. | |
13652 | */ | |
3e369b76 | 13653 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13654 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13655 | udelay(200); |
13656 | } | |
13657 | ||
13658 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13659 | struct intel_shared_dpll *pll) | |
13660 | { | |
13661 | struct drm_device *dev = dev_priv->dev; | |
13662 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13663 | |
13664 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13665 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13666 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13667 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13668 | } |
13669 | ||
15bdd4cf DV |
13670 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13671 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13672 | udelay(200); |
13673 | } | |
13674 | ||
46edb027 DV |
13675 | static char *ibx_pch_dpll_names[] = { |
13676 | "PCH DPLL A", | |
13677 | "PCH DPLL B", | |
13678 | }; | |
13679 | ||
7c74ade1 | 13680 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13681 | { |
e7b903d2 | 13682 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13683 | int i; |
13684 | ||
7c74ade1 | 13685 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13686 | |
e72f9fbf | 13687 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13688 | dev_priv->shared_dplls[i].id = i; |
13689 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13690 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13691 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13692 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13693 | dev_priv->shared_dplls[i].get_hw_state = |
13694 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13695 | } |
13696 | } | |
13697 | ||
7c74ade1 DV |
13698 | static void intel_shared_dpll_init(struct drm_device *dev) |
13699 | { | |
e7b903d2 | 13700 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13701 | |
b6283055 VS |
13702 | intel_update_cdclk(dev); |
13703 | ||
9cd86933 DV |
13704 | if (HAS_DDI(dev)) |
13705 | intel_ddi_pll_init(dev); | |
13706 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13707 | ibx_pch_dpll_init(dev); |
13708 | else | |
13709 | dev_priv->num_shared_dpll = 0; | |
13710 | ||
13711 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13712 | } |
13713 | ||
6beb8c23 MR |
13714 | /** |
13715 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13716 | * @plane: drm plane to prepare for | |
13717 | * @fb: framebuffer to prepare for presentation | |
13718 | * | |
13719 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13720 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13721 | * bits. Some older platforms need special physical address handling for | |
13722 | * cursor planes. | |
13723 | * | |
13724 | * Returns 0 on success, negative error code on failure. | |
13725 | */ | |
13726 | int | |
13727 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
13728 | struct drm_framebuffer *fb, |
13729 | const struct drm_plane_state *new_state) | |
465c120c MR |
13730 | { |
13731 | struct drm_device *dev = plane->dev; | |
6beb8c23 MR |
13732 | struct intel_plane *intel_plane = to_intel_plane(plane); |
13733 | enum pipe pipe = intel_plane->pipe; | |
13734 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
13735 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); | |
13736 | unsigned frontbuffer_bits = 0; | |
13737 | int ret = 0; | |
465c120c | 13738 | |
ea2c67bb | 13739 | if (!obj) |
465c120c MR |
13740 | return 0; |
13741 | ||
6beb8c23 MR |
13742 | switch (plane->type) { |
13743 | case DRM_PLANE_TYPE_PRIMARY: | |
13744 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); | |
13745 | break; | |
13746 | case DRM_PLANE_TYPE_CURSOR: | |
13747 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); | |
13748 | break; | |
13749 | case DRM_PLANE_TYPE_OVERLAY: | |
13750 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); | |
13751 | break; | |
13752 | } | |
465c120c | 13753 | |
6beb8c23 | 13754 | mutex_lock(&dev->struct_mutex); |
465c120c | 13755 | |
6beb8c23 MR |
13756 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
13757 | INTEL_INFO(dev)->cursor_needs_physical) { | |
13758 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13759 | ret = i915_gem_object_attach_phys(obj, align); | |
13760 | if (ret) | |
13761 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13762 | } else { | |
82bc3b2d | 13763 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL); |
6beb8c23 | 13764 | } |
465c120c | 13765 | |
6beb8c23 MR |
13766 | if (ret == 0) |
13767 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); | |
fdd508a6 | 13768 | |
4c34574f | 13769 | mutex_unlock(&dev->struct_mutex); |
465c120c | 13770 | |
6beb8c23 MR |
13771 | return ret; |
13772 | } | |
13773 | ||
38f3ce3a MR |
13774 | /** |
13775 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13776 | * @plane: drm plane to clean up for | |
13777 | * @fb: old framebuffer that was on plane | |
13778 | * | |
13779 | * Cleans up a framebuffer that has just been removed from a plane. | |
13780 | */ | |
13781 | void | |
13782 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
13783 | struct drm_framebuffer *fb, |
13784 | const struct drm_plane_state *old_state) | |
38f3ce3a MR |
13785 | { |
13786 | struct drm_device *dev = plane->dev; | |
13787 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
13788 | ||
13789 | if (WARN_ON(!obj)) | |
13790 | return; | |
13791 | ||
13792 | if (plane->type != DRM_PLANE_TYPE_CURSOR || | |
13793 | !INTEL_INFO(dev)->cursor_needs_physical) { | |
13794 | mutex_lock(&dev->struct_mutex); | |
82bc3b2d | 13795 | intel_unpin_fb_obj(fb, old_state); |
38f3ce3a MR |
13796 | mutex_unlock(&dev->struct_mutex); |
13797 | } | |
465c120c MR |
13798 | } |
13799 | ||
6156a456 CK |
13800 | int |
13801 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13802 | { | |
13803 | int max_scale; | |
13804 | struct drm_device *dev; | |
13805 | struct drm_i915_private *dev_priv; | |
13806 | int crtc_clock, cdclk; | |
13807 | ||
13808 | if (!intel_crtc || !crtc_state) | |
13809 | return DRM_PLANE_HELPER_NO_SCALING; | |
13810 | ||
13811 | dev = intel_crtc->base.dev; | |
13812 | dev_priv = dev->dev_private; | |
13813 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
13814 | cdclk = dev_priv->display.get_display_clock_speed(dev); | |
13815 | ||
13816 | if (!crtc_clock || !cdclk) | |
13817 | return DRM_PLANE_HELPER_NO_SCALING; | |
13818 | ||
13819 | /* | |
13820 | * skl max scale is lower of: | |
13821 | * close to 3 but not 3, -1 is for that purpose | |
13822 | * or | |
13823 | * cdclk/crtc_clock | |
13824 | */ | |
13825 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13826 | ||
13827 | return max_scale; | |
13828 | } | |
13829 | ||
465c120c | 13830 | static int |
3c692a41 | 13831 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 13832 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
13833 | struct intel_plane_state *state) |
13834 | { | |
2b875c22 MR |
13835 | struct drm_crtc *crtc = state->base.crtc; |
13836 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 13837 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
13838 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13839 | bool can_position = false; | |
465c120c | 13840 | |
061e4b8d ML |
13841 | /* use scaler when colorkey is not required */ |
13842 | if (INTEL_INFO(plane->dev)->gen >= 9 && | |
13843 | to_intel_plane(plane)->ckey.flags == I915_SET_COLORKEY_NONE) { | |
13844 | min_scale = 1; | |
13845 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
d8106366 | 13846 | can_position = true; |
6156a456 | 13847 | } |
d8106366 | 13848 | |
061e4b8d ML |
13849 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
13850 | &state->dst, &state->clip, | |
da20eabd ML |
13851 | min_scale, max_scale, |
13852 | can_position, true, | |
13853 | &state->visible); | |
14af293f GP |
13854 | } |
13855 | ||
13856 | static void | |
13857 | intel_commit_primary_plane(struct drm_plane *plane, | |
13858 | struct intel_plane_state *state) | |
13859 | { | |
2b875c22 MR |
13860 | struct drm_crtc *crtc = state->base.crtc; |
13861 | struct drm_framebuffer *fb = state->base.fb; | |
13862 | struct drm_device *dev = plane->dev; | |
14af293f | 13863 | struct drm_i915_private *dev_priv = dev->dev_private; |
ea2c67bb | 13864 | struct intel_crtc *intel_crtc; |
14af293f GP |
13865 | struct drm_rect *src = &state->src; |
13866 | ||
ea2c67bb MR |
13867 | crtc = crtc ? crtc : plane->crtc; |
13868 | intel_crtc = to_intel_crtc(crtc); | |
cf4c7c12 MR |
13869 | |
13870 | plane->fb = fb; | |
9dc806fc MR |
13871 | crtc->x = src->x1 >> 16; |
13872 | crtc->y = src->y1 >> 16; | |
ccc759dc | 13873 | |
302d19ac ML |
13874 | if (!intel_crtc->active) |
13875 | return; | |
465c120c | 13876 | |
302d19ac ML |
13877 | if (state->visible) |
13878 | /* FIXME: kill this fastboot hack */ | |
13879 | intel_update_pipe_size(intel_crtc); | |
13880 | ||
13881 | dev_priv->display.update_primary_plane(crtc, fb, crtc->x, crtc->y); | |
465c120c MR |
13882 | } |
13883 | ||
a8ad0d8e ML |
13884 | static void |
13885 | intel_disable_primary_plane(struct drm_plane *plane, | |
7fabf5ef | 13886 | struct drm_crtc *crtc) |
a8ad0d8e ML |
13887 | { |
13888 | struct drm_device *dev = plane->dev; | |
13889 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13890 | ||
a8ad0d8e ML |
13891 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13892 | } | |
13893 | ||
32b7eeec | 13894 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
3c692a41 | 13895 | { |
32b7eeec | 13896 | struct drm_device *dev = crtc->dev; |
140fd38d | 13897 | struct drm_i915_private *dev_priv = dev->dev_private; |
3c692a41 | 13898 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3c692a41 | 13899 | |
ac21b225 | 13900 | intel_pre_plane_update(intel_crtc); |
3c692a41 | 13901 | |
32b7eeec MR |
13902 | if (intel_crtc->atomic.update_wm) |
13903 | intel_update_watermarks(crtc); | |
3c692a41 | 13904 | |
32b7eeec | 13905 | intel_runtime_pm_get(dev_priv); |
3c692a41 | 13906 | |
c34c9ee4 | 13907 | /* Perform vblank evasion around commit operation */ |
ac21b225 | 13908 | if (crtc->state->active && !needs_modeset(crtc->state)) |
c34c9ee4 MR |
13909 | intel_crtc->atomic.evade = |
13910 | intel_pipe_update_start(intel_crtc, | |
13911 | &intel_crtc->atomic.start_vbl_count); | |
0583236e ML |
13912 | |
13913 | if (!needs_modeset(crtc->state) && INTEL_INFO(dev)->gen >= 9) | |
13914 | skl_detach_scalers(intel_crtc); | |
32b7eeec MR |
13915 | } |
13916 | ||
13917 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) | |
13918 | { | |
13919 | struct drm_device *dev = crtc->dev; | |
13920 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13921 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
32b7eeec | 13922 | |
c34c9ee4 MR |
13923 | if (intel_crtc->atomic.evade) |
13924 | intel_pipe_update_end(intel_crtc, | |
13925 | intel_crtc->atomic.start_vbl_count); | |
3c692a41 | 13926 | |
140fd38d | 13927 | intel_runtime_pm_put(dev_priv); |
3c692a41 | 13928 | |
ac21b225 | 13929 | intel_post_plane_update(intel_crtc); |
3c692a41 GP |
13930 | } |
13931 | ||
cf4c7c12 | 13932 | /** |
4a3b8769 MR |
13933 | * intel_plane_destroy - destroy a plane |
13934 | * @plane: plane to destroy | |
cf4c7c12 | 13935 | * |
4a3b8769 MR |
13936 | * Common destruction function for all types of planes (primary, cursor, |
13937 | * sprite). | |
cf4c7c12 | 13938 | */ |
4a3b8769 | 13939 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13940 | { |
13941 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13942 | drm_plane_cleanup(plane); | |
13943 | kfree(intel_plane); | |
13944 | } | |
13945 | ||
65a3fea0 | 13946 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13947 | .update_plane = drm_atomic_helper_update_plane, |
13948 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13949 | .destroy = intel_plane_destroy, |
c196e1d6 | 13950 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13951 | .atomic_get_property = intel_plane_atomic_get_property, |
13952 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13953 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13954 | .atomic_destroy_state = intel_plane_destroy_state, | |
13955 | ||
465c120c MR |
13956 | }; |
13957 | ||
13958 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13959 | int pipe) | |
13960 | { | |
13961 | struct intel_plane *primary; | |
8e7d688b | 13962 | struct intel_plane_state *state; |
465c120c MR |
13963 | const uint32_t *intel_primary_formats; |
13964 | int num_formats; | |
13965 | ||
13966 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13967 | if (primary == NULL) | |
13968 | return NULL; | |
13969 | ||
8e7d688b MR |
13970 | state = intel_create_plane_state(&primary->base); |
13971 | if (!state) { | |
ea2c67bb MR |
13972 | kfree(primary); |
13973 | return NULL; | |
13974 | } | |
8e7d688b | 13975 | primary->base.state = &state->base; |
ea2c67bb | 13976 | |
465c120c MR |
13977 | primary->can_scale = false; |
13978 | primary->max_downscale = 1; | |
6156a456 CK |
13979 | if (INTEL_INFO(dev)->gen >= 9) { |
13980 | primary->can_scale = true; | |
af99ceda | 13981 | state->scaler_id = -1; |
6156a456 | 13982 | } |
465c120c MR |
13983 | primary->pipe = pipe; |
13984 | primary->plane = pipe; | |
c59cb179 MR |
13985 | primary->check_plane = intel_check_primary_plane; |
13986 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13987 | primary->disable_plane = intel_disable_primary_plane; |
08e221fb | 13988 | primary->ckey.flags = I915_SET_COLORKEY_NONE; |
465c120c MR |
13989 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13990 | primary->plane = !pipe; | |
13991 | ||
6c0fd451 DL |
13992 | if (INTEL_INFO(dev)->gen >= 9) { |
13993 | intel_primary_formats = skl_primary_formats; | |
13994 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13995 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13996 | intel_primary_formats = i965_primary_formats; |
13997 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13998 | } else { |
13999 | intel_primary_formats = i8xx_primary_formats; | |
14000 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
14001 | } |
14002 | ||
14003 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 14004 | &intel_plane_funcs, |
465c120c MR |
14005 | intel_primary_formats, num_formats, |
14006 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 14007 | |
3b7a5119 SJ |
14008 | if (INTEL_INFO(dev)->gen >= 4) |
14009 | intel_create_rotation_property(dev, primary); | |
48404c1e | 14010 | |
ea2c67bb MR |
14011 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
14012 | ||
465c120c MR |
14013 | return &primary->base; |
14014 | } | |
14015 | ||
3b7a5119 SJ |
14016 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
14017 | { | |
14018 | if (!dev->mode_config.rotation_property) { | |
14019 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
14020 | BIT(DRM_ROTATE_180); | |
14021 | ||
14022 | if (INTEL_INFO(dev)->gen >= 9) | |
14023 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
14024 | ||
14025 | dev->mode_config.rotation_property = | |
14026 | drm_mode_create_rotation_property(dev, flags); | |
14027 | } | |
14028 | if (dev->mode_config.rotation_property) | |
14029 | drm_object_attach_property(&plane->base.base, | |
14030 | dev->mode_config.rotation_property, | |
14031 | plane->base.state->rotation); | |
14032 | } | |
14033 | ||
3d7d6510 | 14034 | static int |
852e787c | 14035 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 14036 | struct intel_crtc_state *crtc_state, |
852e787c | 14037 | struct intel_plane_state *state) |
3d7d6510 | 14038 | { |
061e4b8d | 14039 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 14040 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 14041 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
757f9a3e GP |
14042 | unsigned stride; |
14043 | int ret; | |
3d7d6510 | 14044 | |
061e4b8d ML |
14045 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
14046 | &state->dst, &state->clip, | |
3d7d6510 MR |
14047 | DRM_PLANE_HELPER_NO_SCALING, |
14048 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 14049 | true, true, &state->visible); |
757f9a3e GP |
14050 | if (ret) |
14051 | return ret; | |
14052 | ||
757f9a3e GP |
14053 | /* if we want to turn off the cursor ignore width and height */ |
14054 | if (!obj) | |
da20eabd | 14055 | return 0; |
757f9a3e | 14056 | |
757f9a3e | 14057 | /* Check for which cursor types we support */ |
061e4b8d | 14058 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
14059 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
14060 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
14061 | return -EINVAL; |
14062 | } | |
14063 | ||
ea2c67bb MR |
14064 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
14065 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
14066 | DRM_DEBUG_KMS("buffer is too small\n"); |
14067 | return -ENOMEM; | |
14068 | } | |
14069 | ||
3a656b54 | 14070 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 14071 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 14072 | return -EINVAL; |
32b7eeec MR |
14073 | } |
14074 | ||
da20eabd | 14075 | return 0; |
852e787c | 14076 | } |
3d7d6510 | 14077 | |
a8ad0d8e ML |
14078 | static void |
14079 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 14080 | struct drm_crtc *crtc) |
a8ad0d8e | 14081 | { |
a8ad0d8e ML |
14082 | intel_crtc_update_cursor(crtc, false); |
14083 | } | |
14084 | ||
f4a2cf29 | 14085 | static void |
852e787c GP |
14086 | intel_commit_cursor_plane(struct drm_plane *plane, |
14087 | struct intel_plane_state *state) | |
14088 | { | |
2b875c22 | 14089 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
14090 | struct drm_device *dev = plane->dev; |
14091 | struct intel_crtc *intel_crtc; | |
2b875c22 | 14092 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 14093 | uint32_t addr; |
852e787c | 14094 | |
ea2c67bb MR |
14095 | crtc = crtc ? crtc : plane->crtc; |
14096 | intel_crtc = to_intel_crtc(crtc); | |
14097 | ||
2b875c22 | 14098 | plane->fb = state->base.fb; |
ea2c67bb MR |
14099 | crtc->cursor_x = state->base.crtc_x; |
14100 | crtc->cursor_y = state->base.crtc_y; | |
14101 | ||
a912f12f GP |
14102 | if (intel_crtc->cursor_bo == obj) |
14103 | goto update; | |
4ed91096 | 14104 | |
f4a2cf29 | 14105 | if (!obj) |
a912f12f | 14106 | addr = 0; |
f4a2cf29 | 14107 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 14108 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 14109 | else |
a912f12f | 14110 | addr = obj->phys_handle->busaddr; |
852e787c | 14111 | |
a912f12f GP |
14112 | intel_crtc->cursor_addr = addr; |
14113 | intel_crtc->cursor_bo = obj; | |
852e787c | 14114 | |
302d19ac | 14115 | update: |
32b7eeec | 14116 | if (intel_crtc->active) |
a912f12f | 14117 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
14118 | } |
14119 | ||
3d7d6510 MR |
14120 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
14121 | int pipe) | |
14122 | { | |
14123 | struct intel_plane *cursor; | |
8e7d688b | 14124 | struct intel_plane_state *state; |
3d7d6510 MR |
14125 | |
14126 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
14127 | if (cursor == NULL) | |
14128 | return NULL; | |
14129 | ||
8e7d688b MR |
14130 | state = intel_create_plane_state(&cursor->base); |
14131 | if (!state) { | |
ea2c67bb MR |
14132 | kfree(cursor); |
14133 | return NULL; | |
14134 | } | |
8e7d688b | 14135 | cursor->base.state = &state->base; |
ea2c67bb | 14136 | |
3d7d6510 MR |
14137 | cursor->can_scale = false; |
14138 | cursor->max_downscale = 1; | |
14139 | cursor->pipe = pipe; | |
14140 | cursor->plane = pipe; | |
c59cb179 MR |
14141 | cursor->check_plane = intel_check_cursor_plane; |
14142 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 14143 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
14144 | |
14145 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 14146 | &intel_plane_funcs, |
3d7d6510 MR |
14147 | intel_cursor_formats, |
14148 | ARRAY_SIZE(intel_cursor_formats), | |
14149 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
14150 | |
14151 | if (INTEL_INFO(dev)->gen >= 4) { | |
14152 | if (!dev->mode_config.rotation_property) | |
14153 | dev->mode_config.rotation_property = | |
14154 | drm_mode_create_rotation_property(dev, | |
14155 | BIT(DRM_ROTATE_0) | | |
14156 | BIT(DRM_ROTATE_180)); | |
14157 | if (dev->mode_config.rotation_property) | |
14158 | drm_object_attach_property(&cursor->base.base, | |
14159 | dev->mode_config.rotation_property, | |
8e7d688b | 14160 | state->base.rotation); |
4398ad45 VS |
14161 | } |
14162 | ||
af99ceda CK |
14163 | if (INTEL_INFO(dev)->gen >=9) |
14164 | state->scaler_id = -1; | |
14165 | ||
ea2c67bb MR |
14166 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
14167 | ||
3d7d6510 MR |
14168 | return &cursor->base; |
14169 | } | |
14170 | ||
549e2bfb CK |
14171 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
14172 | struct intel_crtc_state *crtc_state) | |
14173 | { | |
14174 | int i; | |
14175 | struct intel_scaler *intel_scaler; | |
14176 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14177 | ||
14178 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14179 | intel_scaler = &scaler_state->scalers[i]; | |
14180 | intel_scaler->in_use = 0; | |
549e2bfb CK |
14181 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
14182 | } | |
14183 | ||
14184 | scaler_state->scaler_id = -1; | |
14185 | } | |
14186 | ||
b358d0a6 | 14187 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 14188 | { |
fbee40df | 14189 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 14190 | struct intel_crtc *intel_crtc; |
f5de6e07 | 14191 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
14192 | struct drm_plane *primary = NULL; |
14193 | struct drm_plane *cursor = NULL; | |
465c120c | 14194 | int i, ret; |
79e53945 | 14195 | |
955382f3 | 14196 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14197 | if (intel_crtc == NULL) |
14198 | return; | |
14199 | ||
f5de6e07 ACO |
14200 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14201 | if (!crtc_state) | |
14202 | goto fail; | |
550acefd ACO |
14203 | intel_crtc->config = crtc_state; |
14204 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14205 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14206 | |
549e2bfb CK |
14207 | /* initialize shared scalers */ |
14208 | if (INTEL_INFO(dev)->gen >= 9) { | |
14209 | if (pipe == PIPE_C) | |
14210 | intel_crtc->num_scalers = 1; | |
14211 | else | |
14212 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14213 | ||
14214 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14215 | } | |
14216 | ||
465c120c | 14217 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14218 | if (!primary) |
14219 | goto fail; | |
14220 | ||
14221 | cursor = intel_cursor_plane_create(dev, pipe); | |
14222 | if (!cursor) | |
14223 | goto fail; | |
14224 | ||
465c120c | 14225 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14226 | cursor, &intel_crtc_funcs); |
14227 | if (ret) | |
14228 | goto fail; | |
79e53945 JB |
14229 | |
14230 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14231 | for (i = 0; i < 256; i++) { |
14232 | intel_crtc->lut_r[i] = i; | |
14233 | intel_crtc->lut_g[i] = i; | |
14234 | intel_crtc->lut_b[i] = i; | |
14235 | } | |
14236 | ||
1f1c2e24 VS |
14237 | /* |
14238 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14239 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14240 | */ |
80824003 JB |
14241 | intel_crtc->pipe = pipe; |
14242 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14243 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14244 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14245 | intel_crtc->plane = !pipe; |
80824003 JB |
14246 | } |
14247 | ||
4b0e333e CW |
14248 | intel_crtc->cursor_base = ~0; |
14249 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14250 | intel_crtc->cursor_size = ~0; |
8d7849db | 14251 | |
22fd0fab JB |
14252 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14253 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14254 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14255 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14256 | ||
79e53945 | 14257 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14258 | |
14259 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14260 | return; |
14261 | ||
14262 | fail: | |
14263 | if (primary) | |
14264 | drm_plane_cleanup(primary); | |
14265 | if (cursor) | |
14266 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14267 | kfree(crtc_state); |
3d7d6510 | 14268 | kfree(intel_crtc); |
79e53945 JB |
14269 | } |
14270 | ||
752aa88a JB |
14271 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14272 | { | |
14273 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14274 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14275 | |
51fd371b | 14276 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14277 | |
d3babd3f | 14278 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14279 | return INVALID_PIPE; |
14280 | ||
14281 | return to_intel_crtc(encoder->crtc)->pipe; | |
14282 | } | |
14283 | ||
08d7b3d1 | 14284 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14285 | struct drm_file *file) |
08d7b3d1 | 14286 | { |
08d7b3d1 | 14287 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14288 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14289 | struct intel_crtc *crtc; |
08d7b3d1 | 14290 | |
7707e653 | 14291 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14292 | |
7707e653 | 14293 | if (!drmmode_crtc) { |
08d7b3d1 | 14294 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14295 | return -ENOENT; |
08d7b3d1 CW |
14296 | } |
14297 | ||
7707e653 | 14298 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14299 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14300 | |
c05422d5 | 14301 | return 0; |
08d7b3d1 CW |
14302 | } |
14303 | ||
66a9278e | 14304 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14305 | { |
66a9278e DV |
14306 | struct drm_device *dev = encoder->base.dev; |
14307 | struct intel_encoder *source_encoder; | |
79e53945 | 14308 | int index_mask = 0; |
79e53945 JB |
14309 | int entry = 0; |
14310 | ||
b2784e15 | 14311 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14312 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14313 | index_mask |= (1 << entry); |
14314 | ||
79e53945 JB |
14315 | entry++; |
14316 | } | |
4ef69c7a | 14317 | |
79e53945 JB |
14318 | return index_mask; |
14319 | } | |
14320 | ||
4d302442 CW |
14321 | static bool has_edp_a(struct drm_device *dev) |
14322 | { | |
14323 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14324 | ||
14325 | if (!IS_MOBILE(dev)) | |
14326 | return false; | |
14327 | ||
14328 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14329 | return false; | |
14330 | ||
e3589908 | 14331 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14332 | return false; |
14333 | ||
14334 | return true; | |
14335 | } | |
14336 | ||
84b4e042 JB |
14337 | static bool intel_crt_present(struct drm_device *dev) |
14338 | { | |
14339 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14340 | ||
884497ed DL |
14341 | if (INTEL_INFO(dev)->gen >= 9) |
14342 | return false; | |
14343 | ||
cf404ce4 | 14344 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14345 | return false; |
14346 | ||
14347 | if (IS_CHERRYVIEW(dev)) | |
14348 | return false; | |
14349 | ||
14350 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
14351 | return false; | |
14352 | ||
14353 | return true; | |
14354 | } | |
14355 | ||
79e53945 JB |
14356 | static void intel_setup_outputs(struct drm_device *dev) |
14357 | { | |
725e30ad | 14358 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14359 | struct intel_encoder *encoder; |
cb0953d7 | 14360 | bool dpd_is_edp = false; |
79e53945 | 14361 | |
c9093354 | 14362 | intel_lvds_init(dev); |
79e53945 | 14363 | |
84b4e042 | 14364 | if (intel_crt_present(dev)) |
79935fca | 14365 | intel_crt_init(dev); |
cb0953d7 | 14366 | |
c776eb2e VK |
14367 | if (IS_BROXTON(dev)) { |
14368 | /* | |
14369 | * FIXME: Broxton doesn't support port detection via the | |
14370 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14371 | * detect the ports. | |
14372 | */ | |
14373 | intel_ddi_init(dev, PORT_A); | |
14374 | intel_ddi_init(dev, PORT_B); | |
14375 | intel_ddi_init(dev, PORT_C); | |
14376 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14377 | int found; |
14378 | ||
de31facd JB |
14379 | /* |
14380 | * Haswell uses DDI functions to detect digital outputs. | |
14381 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14382 | * it's there. | |
14383 | */ | |
0e72a5b5 | 14384 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
de31facd JB |
14385 | /* WaIgnoreDDIAStrap: skl */ |
14386 | if (found || | |
14387 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) | |
0e72a5b5 ED |
14388 | intel_ddi_init(dev, PORT_A); |
14389 | ||
14390 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14391 | * register */ | |
14392 | found = I915_READ(SFUSE_STRAP); | |
14393 | ||
14394 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14395 | intel_ddi_init(dev, PORT_B); | |
14396 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14397 | intel_ddi_init(dev, PORT_C); | |
14398 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14399 | intel_ddi_init(dev, PORT_D); | |
14400 | } else if (HAS_PCH_SPLIT(dev)) { | |
cb0953d7 | 14401 | int found; |
5d8a7752 | 14402 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14403 | |
14404 | if (has_edp_a(dev)) | |
14405 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14406 | |
dc0fa718 | 14407 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14408 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 14409 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 14410 | if (!found) |
e2debe91 | 14411 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14412 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14413 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14414 | } |
14415 | ||
dc0fa718 | 14416 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14417 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14418 | |
dc0fa718 | 14419 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14420 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14421 | |
5eb08b69 | 14422 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14423 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14424 | |
270b3042 | 14425 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14426 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14427 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14428 | /* |
14429 | * The DP_DETECTED bit is the latched state of the DDC | |
14430 | * SDA pin at boot. However since eDP doesn't require DDC | |
14431 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14432 | * eDP ports may have been muxed to an alternate function. | |
14433 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14434 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14435 | * detect eDP ports. | |
14436 | */ | |
d2182a66 VS |
14437 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
14438 | !intel_dp_is_edp(dev, PORT_B)) | |
585a94b8 AB |
14439 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
14440 | PORT_B); | |
e17ac6db VS |
14441 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
14442 | intel_dp_is_edp(dev, PORT_B)) | |
14443 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); | |
585a94b8 | 14444 | |
d2182a66 VS |
14445 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
14446 | !intel_dp_is_edp(dev, PORT_C)) | |
6f6005a5 JB |
14447 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
14448 | PORT_C); | |
e17ac6db VS |
14449 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
14450 | intel_dp_is_edp(dev, PORT_C)) | |
14451 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); | |
19c03924 | 14452 | |
9418c1f1 | 14453 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14454 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
9418c1f1 VS |
14455 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
14456 | PORT_D); | |
e17ac6db VS |
14457 | /* eDP not supported on port D, so don't check VBT */ |
14458 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) | |
14459 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); | |
9418c1f1 VS |
14460 | } |
14461 | ||
3cfca973 | 14462 | intel_dsi_init(dev); |
103a196f | 14463 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
27185ae1 | 14464 | bool found = false; |
7d57382e | 14465 | |
e2debe91 | 14466 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14467 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 14468 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
b01f2c3a JB |
14469 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
14470 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); | |
e2debe91 | 14471 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14472 | } |
27185ae1 | 14473 | |
e7281eab | 14474 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
ab9d7c30 | 14475 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14476 | } |
13520b05 KH |
14477 | |
14478 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14479 | |
e2debe91 | 14480 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14481 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 14482 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 14483 | } |
27185ae1 | 14484 | |
e2debe91 | 14485 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14486 | |
b01f2c3a JB |
14487 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
14488 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); | |
e2debe91 | 14489 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14490 | } |
e7281eab | 14491 | if (SUPPORTS_INTEGRATED_DP(dev)) |
ab9d7c30 | 14492 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14493 | } |
27185ae1 | 14494 | |
b01f2c3a | 14495 | if (SUPPORTS_INTEGRATED_DP(dev) && |
e7281eab | 14496 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14497 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14498 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14499 | intel_dvo_init(dev); |
14500 | ||
103a196f | 14501 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14502 | intel_tv_init(dev); |
14503 | ||
0bc12bcb | 14504 | intel_psr_init(dev); |
7c8f8a70 | 14505 | |
b2784e15 | 14506 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14507 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14508 | encoder->base.possible_clones = | |
66a9278e | 14509 | intel_encoder_clones(encoder); |
79e53945 | 14510 | } |
47356eb6 | 14511 | |
dde86e2d | 14512 | intel_init_pch_refclk(dev); |
270b3042 DV |
14513 | |
14514 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14515 | } |
14516 | ||
14517 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14518 | { | |
60a5ca01 | 14519 | struct drm_device *dev = fb->dev; |
79e53945 | 14520 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14521 | |
ef2d633e | 14522 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14523 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14524 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14525 | drm_gem_object_unreference(&intel_fb->obj->base); |
14526 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14527 | kfree(intel_fb); |
14528 | } | |
14529 | ||
14530 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14531 | struct drm_file *file, |
79e53945 JB |
14532 | unsigned int *handle) |
14533 | { | |
14534 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14535 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14536 | |
05394f39 | 14537 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14538 | } |
14539 | ||
14540 | static const struct drm_framebuffer_funcs intel_fb_funcs = { | |
14541 | .destroy = intel_user_framebuffer_destroy, | |
14542 | .create_handle = intel_user_framebuffer_create_handle, | |
14543 | }; | |
14544 | ||
b321803d DL |
14545 | static |
14546 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14547 | uint32_t pixel_format) | |
14548 | { | |
14549 | u32 gen = INTEL_INFO(dev)->gen; | |
14550 | ||
14551 | if (gen >= 9) { | |
14552 | /* "The stride in bytes must not exceed the of the size of 8K | |
14553 | * pixels and 32K bytes." | |
14554 | */ | |
14555 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14556 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14557 | return 32*1024; | |
14558 | } else if (gen >= 4) { | |
14559 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14560 | return 16*1024; | |
14561 | else | |
14562 | return 32*1024; | |
14563 | } else if (gen >= 3) { | |
14564 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14565 | return 8*1024; | |
14566 | else | |
14567 | return 16*1024; | |
14568 | } else { | |
14569 | /* XXX DSPC is limited to 4k tiled */ | |
14570 | return 8*1024; | |
14571 | } | |
14572 | } | |
14573 | ||
b5ea642a DV |
14574 | static int intel_framebuffer_init(struct drm_device *dev, |
14575 | struct intel_framebuffer *intel_fb, | |
14576 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14577 | struct drm_i915_gem_object *obj) | |
79e53945 | 14578 | { |
6761dd31 | 14579 | unsigned int aligned_height; |
79e53945 | 14580 | int ret; |
b321803d | 14581 | u32 pitch_limit, stride_alignment; |
79e53945 | 14582 | |
dd4916c5 DV |
14583 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14584 | ||
2a80eada DV |
14585 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14586 | /* Enforce that fb modifier and tiling mode match, but only for | |
14587 | * X-tiled. This is needed for FBC. */ | |
14588 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14589 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14590 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14591 | return -EINVAL; | |
14592 | } | |
14593 | } else { | |
14594 | if (obj->tiling_mode == I915_TILING_X) | |
14595 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14596 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14597 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14598 | return -EINVAL; | |
14599 | } | |
14600 | } | |
14601 | ||
9a8f0a12 TU |
14602 | /* Passed in modifier sanity checking. */ |
14603 | switch (mode_cmd->modifier[0]) { | |
14604 | case I915_FORMAT_MOD_Y_TILED: | |
14605 | case I915_FORMAT_MOD_Yf_TILED: | |
14606 | if (INTEL_INFO(dev)->gen < 9) { | |
14607 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14608 | mode_cmd->modifier[0]); | |
14609 | return -EINVAL; | |
14610 | } | |
14611 | case DRM_FORMAT_MOD_NONE: | |
14612 | case I915_FORMAT_MOD_X_TILED: | |
14613 | break; | |
14614 | default: | |
c0f40428 JB |
14615 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14616 | mode_cmd->modifier[0]); | |
57cd6508 | 14617 | return -EINVAL; |
c16ed4be | 14618 | } |
57cd6508 | 14619 | |
b321803d DL |
14620 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14621 | mode_cmd->pixel_format); | |
14622 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14623 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14624 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14625 | return -EINVAL; |
c16ed4be | 14626 | } |
57cd6508 | 14627 | |
b321803d DL |
14628 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14629 | mode_cmd->pixel_format); | |
a35cdaa0 | 14630 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14631 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14632 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14633 | "tiled" : "linear", |
a35cdaa0 | 14634 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14635 | return -EINVAL; |
c16ed4be | 14636 | } |
5d7bd705 | 14637 | |
2a80eada | 14638 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14639 | mode_cmd->pitches[0] != obj->stride) { |
14640 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14641 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14642 | return -EINVAL; |
c16ed4be | 14643 | } |
5d7bd705 | 14644 | |
57779d06 | 14645 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14646 | switch (mode_cmd->pixel_format) { |
57779d06 | 14647 | case DRM_FORMAT_C8: |
04b3924d VS |
14648 | case DRM_FORMAT_RGB565: |
14649 | case DRM_FORMAT_XRGB8888: | |
14650 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14651 | break; |
14652 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14653 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14654 | DRM_DEBUG("unsupported pixel format: %s\n", |
14655 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14656 | return -EINVAL; |
c16ed4be | 14657 | } |
57779d06 | 14658 | break; |
57779d06 | 14659 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14660 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14661 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14662 | drm_get_format_name(mode_cmd->pixel_format)); | |
14663 | return -EINVAL; | |
14664 | } | |
14665 | break; | |
14666 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14667 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14668 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14669 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14670 | DRM_DEBUG("unsupported pixel format: %s\n", |
14671 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14672 | return -EINVAL; |
c16ed4be | 14673 | } |
b5626747 | 14674 | break; |
7531208b DL |
14675 | case DRM_FORMAT_ABGR2101010: |
14676 | if (!IS_VALLEYVIEW(dev)) { | |
14677 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14678 | drm_get_format_name(mode_cmd->pixel_format)); | |
14679 | return -EINVAL; | |
14680 | } | |
14681 | break; | |
04b3924d VS |
14682 | case DRM_FORMAT_YUYV: |
14683 | case DRM_FORMAT_UYVY: | |
14684 | case DRM_FORMAT_YVYU: | |
14685 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14686 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14687 | DRM_DEBUG("unsupported pixel format: %s\n", |
14688 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14689 | return -EINVAL; |
c16ed4be | 14690 | } |
57cd6508 CW |
14691 | break; |
14692 | default: | |
4ee62c76 VS |
14693 | DRM_DEBUG("unsupported pixel format: %s\n", |
14694 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14695 | return -EINVAL; |
14696 | } | |
14697 | ||
90f9a336 VS |
14698 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14699 | if (mode_cmd->offsets[0] != 0) | |
14700 | return -EINVAL; | |
14701 | ||
ec2c981e | 14702 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14703 | mode_cmd->pixel_format, |
14704 | mode_cmd->modifier[0]); | |
53155c0a DV |
14705 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14706 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14707 | return -EINVAL; | |
14708 | ||
c7d73f6a DV |
14709 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14710 | intel_fb->obj = obj; | |
80075d49 | 14711 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14712 | |
79e53945 JB |
14713 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14714 | if (ret) { | |
14715 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14716 | return ret; | |
14717 | } | |
14718 | ||
79e53945 JB |
14719 | return 0; |
14720 | } | |
14721 | ||
79e53945 JB |
14722 | static struct drm_framebuffer * |
14723 | intel_user_framebuffer_create(struct drm_device *dev, | |
14724 | struct drm_file *filp, | |
308e5bcb | 14725 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14726 | { |
05394f39 | 14727 | struct drm_i915_gem_object *obj; |
79e53945 | 14728 | |
308e5bcb JB |
14729 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14730 | mode_cmd->handles[0])); | |
c8725226 | 14731 | if (&obj->base == NULL) |
cce13ff7 | 14732 | return ERR_PTR(-ENOENT); |
79e53945 | 14733 | |
d2dff872 | 14734 | return intel_framebuffer_create(dev, mode_cmd, obj); |
79e53945 JB |
14735 | } |
14736 | ||
4520f53a | 14737 | #ifndef CONFIG_DRM_I915_FBDEV |
0632fef6 | 14738 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14739 | { |
14740 | } | |
14741 | #endif | |
14742 | ||
79e53945 | 14743 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14744 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14745 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14746 | .atomic_check = intel_atomic_check, |
14747 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14748 | .atomic_state_alloc = intel_atomic_state_alloc, |
14749 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14750 | }; |
14751 | ||
e70236a8 JB |
14752 | /* Set up chip specific display functions */ |
14753 | static void intel_init_display(struct drm_device *dev) | |
14754 | { | |
14755 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14756 | ||
ee9300bb DV |
14757 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14758 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14759 | else if (IS_CHERRYVIEW(dev)) |
14760 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14761 | else if (IS_VALLEYVIEW(dev)) |
14762 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14763 | else if (IS_PINEVIEW(dev)) | |
14764 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14765 | else | |
14766 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14767 | ||
bc8d7dff DL |
14768 | if (INTEL_INFO(dev)->gen >= 9) { |
14769 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14770 | dev_priv->display.get_initial_plane_config = |
14771 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14772 | dev_priv->display.crtc_compute_clock = |
14773 | haswell_crtc_compute_clock; | |
14774 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14775 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14776 | dev_priv->display.update_primary_plane = |
14777 | skylake_update_primary_plane; | |
14778 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14779 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14780 | dev_priv->display.get_initial_plane_config = |
14781 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14782 | dev_priv->display.crtc_compute_clock = |
14783 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14784 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14785 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14786 | dev_priv->display.update_primary_plane = |
14787 | ironlake_update_primary_plane; | |
09b4ddf9 | 14788 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14789 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14790 | dev_priv->display.get_initial_plane_config = |
14791 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14792 | dev_priv->display.crtc_compute_clock = |
14793 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14794 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14795 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14796 | dev_priv->display.update_primary_plane = |
14797 | ironlake_update_primary_plane; | |
89b667f8 JB |
14798 | } else if (IS_VALLEYVIEW(dev)) { |
14799 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14800 | dev_priv->display.get_initial_plane_config = |
14801 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14802 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14803 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14804 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14805 | dev_priv->display.update_primary_plane = |
14806 | i9xx_update_primary_plane; | |
f564048e | 14807 | } else { |
0e8ffe1b | 14808 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14809 | dev_priv->display.get_initial_plane_config = |
14810 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14811 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14812 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14813 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14814 | dev_priv->display.update_primary_plane = |
14815 | i9xx_update_primary_plane; | |
f564048e | 14816 | } |
e70236a8 | 14817 | |
e70236a8 | 14818 | /* Returns the core display clock speed */ |
1652d19e VS |
14819 | if (IS_SKYLAKE(dev)) |
14820 | dev_priv->display.get_display_clock_speed = | |
14821 | skylake_get_display_clock_speed; | |
14822 | else if (IS_BROADWELL(dev)) | |
14823 | dev_priv->display.get_display_clock_speed = | |
14824 | broadwell_get_display_clock_speed; | |
14825 | else if (IS_HASWELL(dev)) | |
14826 | dev_priv->display.get_display_clock_speed = | |
14827 | haswell_get_display_clock_speed; | |
14828 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14829 | dev_priv->display.get_display_clock_speed = |
14830 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14831 | else if (IS_GEN5(dev)) |
14832 | dev_priv->display.get_display_clock_speed = | |
14833 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14834 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14835 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14836 | dev_priv->display.get_display_clock_speed = |
14837 | i945_get_display_clock_speed; | |
34edce2f VS |
14838 | else if (IS_GM45(dev)) |
14839 | dev_priv->display.get_display_clock_speed = | |
14840 | gm45_get_display_clock_speed; | |
14841 | else if (IS_CRESTLINE(dev)) | |
14842 | dev_priv->display.get_display_clock_speed = | |
14843 | i965gm_get_display_clock_speed; | |
14844 | else if (IS_PINEVIEW(dev)) | |
14845 | dev_priv->display.get_display_clock_speed = | |
14846 | pnv_get_display_clock_speed; | |
14847 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14848 | dev_priv->display.get_display_clock_speed = | |
14849 | g33_get_display_clock_speed; | |
e70236a8 JB |
14850 | else if (IS_I915G(dev)) |
14851 | dev_priv->display.get_display_clock_speed = | |
14852 | i915_get_display_clock_speed; | |
257a7ffc | 14853 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14854 | dev_priv->display.get_display_clock_speed = |
14855 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14856 | else if (IS_PINEVIEW(dev)) |
14857 | dev_priv->display.get_display_clock_speed = | |
14858 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14859 | else if (IS_I915GM(dev)) |
14860 | dev_priv->display.get_display_clock_speed = | |
14861 | i915gm_get_display_clock_speed; | |
14862 | else if (IS_I865G(dev)) | |
14863 | dev_priv->display.get_display_clock_speed = | |
14864 | i865_get_display_clock_speed; | |
f0f8a9ce | 14865 | else if (IS_I85X(dev)) |
e70236a8 | 14866 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14867 | i85x_get_display_clock_speed; |
623e01e5 VS |
14868 | else { /* 830 */ |
14869 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14870 | dev_priv->display.get_display_clock_speed = |
14871 | i830_get_display_clock_speed; | |
623e01e5 | 14872 | } |
e70236a8 | 14873 | |
7c10a2b5 | 14874 | if (IS_GEN5(dev)) { |
3bb11b53 | 14875 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14876 | } else if (IS_GEN6(dev)) { |
14877 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14878 | } else if (IS_IVYBRIDGE(dev)) { |
14879 | /* FIXME: detect B0+ stepping and use auto training */ | |
14880 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14881 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14882 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
b432e5cf VS |
14883 | if (IS_BROADWELL(dev)) |
14884 | dev_priv->display.modeset_global_resources = | |
14885 | broadwell_modeset_global_resources; | |
30a970c6 JB |
14886 | } else if (IS_VALLEYVIEW(dev)) { |
14887 | dev_priv->display.modeset_global_resources = | |
14888 | valleyview_modeset_global_resources; | |
f8437dd1 VK |
14889 | } else if (IS_BROXTON(dev)) { |
14890 | dev_priv->display.modeset_global_resources = | |
14891 | broxton_modeset_global_resources; | |
e70236a8 | 14892 | } |
8c9f3aaf | 14893 | |
8c9f3aaf JB |
14894 | switch (INTEL_INFO(dev)->gen) { |
14895 | case 2: | |
14896 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14897 | break; | |
14898 | ||
14899 | case 3: | |
14900 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14901 | break; | |
14902 | ||
14903 | case 4: | |
14904 | case 5: | |
14905 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14906 | break; | |
14907 | ||
14908 | case 6: | |
14909 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14910 | break; | |
7c9017e5 | 14911 | case 7: |
4e0bbc31 | 14912 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14913 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14914 | break; | |
830c81db | 14915 | case 9: |
ba343e02 TU |
14916 | /* Drop through - unsupported since execlist only. */ |
14917 | default: | |
14918 | /* Default just returns -ENODEV to indicate unsupported */ | |
14919 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14920 | } |
7bd688cd JN |
14921 | |
14922 | intel_panel_init_backlight_funcs(dev); | |
e39b999a VS |
14923 | |
14924 | mutex_init(&dev_priv->pps_mutex); | |
e70236a8 JB |
14925 | } |
14926 | ||
b690e96c JB |
14927 | /* |
14928 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14929 | * resume, or other times. This quirk makes sure that's the case for | |
14930 | * affected systems. | |
14931 | */ | |
0206e353 | 14932 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14933 | { |
14934 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14935 | ||
14936 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14937 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14938 | } |
14939 | ||
b6b5d049 VS |
14940 | static void quirk_pipeb_force(struct drm_device *dev) |
14941 | { | |
14942 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14943 | ||
14944 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14945 | DRM_INFO("applying pipe b force quirk\n"); | |
14946 | } | |
14947 | ||
435793df KP |
14948 | /* |
14949 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14950 | */ | |
14951 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14952 | { | |
14953 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14954 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14955 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14956 | } |
14957 | ||
4dca20ef | 14958 | /* |
5a15ab5b CE |
14959 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14960 | * brightness value | |
4dca20ef CE |
14961 | */ |
14962 | static void quirk_invert_brightness(struct drm_device *dev) | |
14963 | { | |
14964 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14965 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14966 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14967 | } |
14968 | ||
9c72cc6f SD |
14969 | /* Some VBT's incorrectly indicate no backlight is present */ |
14970 | static void quirk_backlight_present(struct drm_device *dev) | |
14971 | { | |
14972 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14973 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14974 | DRM_INFO("applying backlight present quirk\n"); | |
14975 | } | |
14976 | ||
b690e96c JB |
14977 | struct intel_quirk { |
14978 | int device; | |
14979 | int subsystem_vendor; | |
14980 | int subsystem_device; | |
14981 | void (*hook)(struct drm_device *dev); | |
14982 | }; | |
14983 | ||
5f85f176 EE |
14984 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14985 | struct intel_dmi_quirk { | |
14986 | void (*hook)(struct drm_device *dev); | |
14987 | const struct dmi_system_id (*dmi_id_list)[]; | |
14988 | }; | |
14989 | ||
14990 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14991 | { | |
14992 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14993 | return 1; | |
14994 | } | |
14995 | ||
14996 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14997 | { | |
14998 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14999 | { | |
15000 | .callback = intel_dmi_reverse_brightness, | |
15001 | .ident = "NCR Corporation", | |
15002 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
15003 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
15004 | }, | |
15005 | }, | |
15006 | { } /* terminating entry */ | |
15007 | }, | |
15008 | .hook = quirk_invert_brightness, | |
15009 | }, | |
15010 | }; | |
15011 | ||
c43b5634 | 15012 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
15013 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
15014 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
15015 | ||
b690e96c JB |
15016 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
15017 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
15018 | ||
5f080c0f VS |
15019 | /* 830 needs to leave pipe A & dpll A up */ |
15020 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
15021 | ||
b6b5d049 VS |
15022 | /* 830 needs to leave pipe B & dpll B up */ |
15023 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
15024 | ||
435793df KP |
15025 | /* Lenovo U160 cannot use SSC on LVDS */ |
15026 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
15027 | |
15028 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
15029 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 15030 | |
be505f64 AH |
15031 | /* Acer Aspire 5734Z must invert backlight brightness */ |
15032 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
15033 | ||
15034 | /* Acer/eMachines G725 */ | |
15035 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
15036 | ||
15037 | /* Acer/eMachines e725 */ | |
15038 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
15039 | ||
15040 | /* Acer/Packard Bell NCL20 */ | |
15041 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
15042 | ||
15043 | /* Acer Aspire 4736Z */ | |
15044 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
15045 | |
15046 | /* Acer Aspire 5336 */ | |
15047 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
15048 | |
15049 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
15050 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 15051 | |
dfb3d47b SD |
15052 | /* Acer C720 Chromebook (Core i3 4005U) */ |
15053 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
15054 | ||
b2a9601c | 15055 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
15056 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
15057 | ||
d4967d8c SD |
15058 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
15059 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
15060 | |
15061 | /* HP Chromebook 14 (Celeron 2955U) */ | |
15062 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
15063 | |
15064 | /* Dell Chromebook 11 */ | |
15065 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
15066 | }; |
15067 | ||
15068 | static void intel_init_quirks(struct drm_device *dev) | |
15069 | { | |
15070 | struct pci_dev *d = dev->pdev; | |
15071 | int i; | |
15072 | ||
15073 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
15074 | struct intel_quirk *q = &intel_quirks[i]; | |
15075 | ||
15076 | if (d->device == q->device && | |
15077 | (d->subsystem_vendor == q->subsystem_vendor || | |
15078 | q->subsystem_vendor == PCI_ANY_ID) && | |
15079 | (d->subsystem_device == q->subsystem_device || | |
15080 | q->subsystem_device == PCI_ANY_ID)) | |
15081 | q->hook(dev); | |
15082 | } | |
5f85f176 EE |
15083 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
15084 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
15085 | intel_dmi_quirks[i].hook(dev); | |
15086 | } | |
b690e96c JB |
15087 | } |
15088 | ||
9cce37f4 JB |
15089 | /* Disable the VGA plane that we never use */ |
15090 | static void i915_disable_vga(struct drm_device *dev) | |
15091 | { | |
15092 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15093 | u8 sr1; | |
766aa1c4 | 15094 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 15095 | |
2b37c616 | 15096 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 15097 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 15098 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
15099 | sr1 = inb(VGA_SR_DATA); |
15100 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15101 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15102 | udelay(300); | |
15103 | ||
01f5a626 | 15104 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
15105 | POSTING_READ(vga_reg); |
15106 | } | |
15107 | ||
f817586c DV |
15108 | void intel_modeset_init_hw(struct drm_device *dev) |
15109 | { | |
b6283055 | 15110 | intel_update_cdclk(dev); |
a8f78b58 | 15111 | intel_prepare_ddi(dev); |
f817586c | 15112 | intel_init_clock_gating(dev); |
8090c6b9 | 15113 | intel_enable_gt_powersave(dev); |
f817586c DV |
15114 | } |
15115 | ||
79e53945 JB |
15116 | void intel_modeset_init(struct drm_device *dev) |
15117 | { | |
652c393a | 15118 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 15119 | int sprite, ret; |
8cc87b75 | 15120 | enum pipe pipe; |
46f297fb | 15121 | struct intel_crtc *crtc; |
79e53945 JB |
15122 | |
15123 | drm_mode_config_init(dev); | |
15124 | ||
15125 | dev->mode_config.min_width = 0; | |
15126 | dev->mode_config.min_height = 0; | |
15127 | ||
019d96cb DA |
15128 | dev->mode_config.preferred_depth = 24; |
15129 | dev->mode_config.prefer_shadow = 1; | |
15130 | ||
25bab385 TU |
15131 | dev->mode_config.allow_fb_modifiers = true; |
15132 | ||
e6ecefaa | 15133 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 15134 | |
b690e96c JB |
15135 | intel_init_quirks(dev); |
15136 | ||
1fa61106 ED |
15137 | intel_init_pm(dev); |
15138 | ||
e3c74757 BW |
15139 | if (INTEL_INFO(dev)->num_pipes == 0) |
15140 | return; | |
15141 | ||
e70236a8 | 15142 | intel_init_display(dev); |
7c10a2b5 | 15143 | intel_init_audio(dev); |
e70236a8 | 15144 | |
a6c45cf0 CW |
15145 | if (IS_GEN2(dev)) { |
15146 | dev->mode_config.max_width = 2048; | |
15147 | dev->mode_config.max_height = 2048; | |
15148 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15149 | dev->mode_config.max_width = 4096; |
15150 | dev->mode_config.max_height = 4096; | |
79e53945 | 15151 | } else { |
a6c45cf0 CW |
15152 | dev->mode_config.max_width = 8192; |
15153 | dev->mode_config.max_height = 8192; | |
79e53945 | 15154 | } |
068be561 | 15155 | |
dc41c154 VS |
15156 | if (IS_845G(dev) || IS_I865G(dev)) { |
15157 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15158 | dev->mode_config.cursor_height = 1023; | |
15159 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15160 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15161 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15162 | } else { | |
15163 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15164 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15165 | } | |
15166 | ||
5d4545ae | 15167 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15168 | |
28c97730 | 15169 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15170 | INTEL_INFO(dev)->num_pipes, |
15171 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15172 | |
055e393f | 15173 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15174 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15175 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15176 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15177 | if (ret) |
06da8da2 | 15178 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15179 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15180 | } |
79e53945 JB |
15181 | } |
15182 | ||
f42bb70d JB |
15183 | intel_init_dpio(dev); |
15184 | ||
e72f9fbf | 15185 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15186 | |
9cce37f4 JB |
15187 | /* Just disable it once at startup */ |
15188 | i915_disable_vga(dev); | |
79e53945 | 15189 | intel_setup_outputs(dev); |
11be49eb CW |
15190 | |
15191 | /* Just in case the BIOS is doing something questionable. */ | |
7ff0ebcc | 15192 | intel_fbc_disable(dev); |
fa9fa083 | 15193 | |
6e9f798d | 15194 | drm_modeset_lock_all(dev); |
fa9fa083 | 15195 | intel_modeset_setup_hw_state(dev, false); |
6e9f798d | 15196 | drm_modeset_unlock_all(dev); |
46f297fb | 15197 | |
d3fcc808 | 15198 | for_each_intel_crtc(dev, crtc) { |
46f297fb JB |
15199 | if (!crtc->active) |
15200 | continue; | |
15201 | ||
46f297fb | 15202 | /* |
46f297fb JB |
15203 | * Note that reserving the BIOS fb up front prevents us |
15204 | * from stuffing other stolen allocations like the ring | |
15205 | * on top. This prevents some ugliness at boot time, and | |
15206 | * can even allow for smooth boot transitions if the BIOS | |
15207 | * fb is large enough for the active pipe configuration. | |
15208 | */ | |
5724dbd1 DL |
15209 | if (dev_priv->display.get_initial_plane_config) { |
15210 | dev_priv->display.get_initial_plane_config(crtc, | |
46f297fb JB |
15211 | &crtc->plane_config); |
15212 | /* | |
15213 | * If the fb is shared between multiple heads, we'll | |
15214 | * just get the first one. | |
15215 | */ | |
f6936e29 | 15216 | intel_find_initial_plane_obj(crtc, &crtc->plane_config); |
46f297fb | 15217 | } |
46f297fb | 15218 | } |
2c7111db CW |
15219 | } |
15220 | ||
7fad798e DV |
15221 | static void intel_enable_pipe_a(struct drm_device *dev) |
15222 | { | |
15223 | struct intel_connector *connector; | |
15224 | struct drm_connector *crt = NULL; | |
15225 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15226 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15227 | |
15228 | /* We can't just switch on the pipe A, we need to set things up with a | |
15229 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15230 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15231 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15232 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15233 | crt = &connector->base; | |
15234 | break; | |
15235 | } | |
15236 | } | |
15237 | ||
15238 | if (!crt) | |
15239 | return; | |
15240 | ||
208bf9fd | 15241 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15242 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15243 | } |
15244 | ||
fa555837 DV |
15245 | static bool |
15246 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15247 | { | |
7eb552ae BW |
15248 | struct drm_device *dev = crtc->base.dev; |
15249 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 DV |
15250 | u32 reg, val; |
15251 | ||
7eb552ae | 15252 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15253 | return true; |
15254 | ||
15255 | reg = DSPCNTR(!crtc->plane); | |
15256 | val = I915_READ(reg); | |
15257 | ||
15258 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15259 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15260 | return false; | |
15261 | ||
15262 | return true; | |
15263 | } | |
15264 | ||
24929352 DV |
15265 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15266 | { | |
15267 | struct drm_device *dev = crtc->base.dev; | |
15268 | struct drm_i915_private *dev_priv = dev->dev_private; | |
b17d48e2 | 15269 | struct intel_encoder *encoder; |
fa555837 | 15270 | u32 reg; |
b17d48e2 | 15271 | bool enable; |
24929352 | 15272 | |
24929352 | 15273 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 15274 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
15275 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15276 | ||
d3eaf884 | 15277 | /* restore vblank interrupts to correct state */ |
9625604c | 15278 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 VS |
15279 | if (crtc->active) { |
15280 | update_scanline_offset(crtc); | |
9625604c DV |
15281 | drm_crtc_vblank_on(&crtc->base); |
15282 | } | |
d3eaf884 | 15283 | |
24929352 | 15284 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15285 | * disable the crtc (and hence change the state) if it is wrong. Note |
15286 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15287 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15288 | bool plane; |
15289 | ||
24929352 DV |
15290 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15291 | crtc->base.base.id); | |
15292 | ||
15293 | /* Pipe has the wrong plane attached and the plane is active. | |
15294 | * Temporarily change the plane mapping and disable everything | |
15295 | * ... */ | |
15296 | plane = crtc->plane; | |
b70709a6 | 15297 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15298 | crtc->plane = !plane; |
b17d48e2 | 15299 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15300 | crtc->plane = plane; |
24929352 | 15301 | } |
24929352 | 15302 | |
7fad798e DV |
15303 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15304 | crtc->pipe == PIPE_A && !crtc->active) { | |
15305 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15306 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15307 | * call below we restore the pipe to the right state, but leave | |
15308 | * the required bits on. */ | |
15309 | intel_enable_pipe_a(dev); | |
15310 | } | |
15311 | ||
24929352 DV |
15312 | /* Adjust the state of the output pipe according to whether we |
15313 | * have active connectors/encoders. */ | |
b17d48e2 ML |
15314 | enable = false; |
15315 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15316 | enable |= encoder->connectors_active; | |
24929352 | 15317 | |
b17d48e2 ML |
15318 | if (!enable) |
15319 | intel_crtc_disable_noatomic(&crtc->base); | |
24929352 | 15320 | |
53d9f4e9 | 15321 | if (crtc->active != crtc->base.state->active) { |
24929352 DV |
15322 | |
15323 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15324 | * functions or because of calls to intel_crtc_disable_noatomic, |
15325 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15326 | * pipe A quirk. */ |
15327 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15328 | crtc->base.base.id, | |
83d65738 | 15329 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15330 | crtc->active ? "enabled" : "disabled"); |
15331 | ||
83d65738 | 15332 | crtc->base.state->enable = crtc->active; |
49d6fa21 | 15333 | crtc->base.state->active = crtc->active; |
24929352 DV |
15334 | crtc->base.enabled = crtc->active; |
15335 | ||
15336 | /* Because we only establish the connector -> encoder -> | |
15337 | * crtc links if something is active, this means the | |
15338 | * crtc is now deactivated. Break the links. connector | |
15339 | * -> encoder links are only establish when things are | |
15340 | * actually up, hence no need to break them. */ | |
15341 | WARN_ON(crtc->active); | |
15342 | ||
15343 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { | |
15344 | WARN_ON(encoder->connectors_active); | |
15345 | encoder->base.crtc = NULL; | |
15346 | } | |
15347 | } | |
c5ab3bc0 | 15348 | |
a3ed6aad | 15349 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15350 | /* |
15351 | * We start out with underrun reporting disabled to avoid races. | |
15352 | * For correct bookkeeping mark this on active crtcs. | |
15353 | * | |
c5ab3bc0 DV |
15354 | * Also on gmch platforms we dont have any hardware bits to |
15355 | * disable the underrun reporting. Which means we need to start | |
15356 | * out with underrun reporting disabled also on inactive pipes, | |
15357 | * since otherwise we'll complain about the garbage we read when | |
15358 | * e.g. coming up after runtime pm. | |
15359 | * | |
4cc31489 DV |
15360 | * No protection against concurrent access is required - at |
15361 | * worst a fifo underrun happens which also sets this to false. | |
15362 | */ | |
15363 | crtc->cpu_fifo_underrun_disabled = true; | |
15364 | crtc->pch_fifo_underrun_disabled = true; | |
15365 | } | |
24929352 DV |
15366 | } |
15367 | ||
15368 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15369 | { | |
15370 | struct intel_connector *connector; | |
15371 | struct drm_device *dev = encoder->base.dev; | |
15372 | ||
15373 | /* We need to check both for a crtc link (meaning that the | |
15374 | * encoder is active and trying to read from a pipe) and the | |
15375 | * pipe itself being active. */ | |
15376 | bool has_active_crtc = encoder->base.crtc && | |
15377 | to_intel_crtc(encoder->base.crtc)->active; | |
15378 | ||
15379 | if (encoder->connectors_active && !has_active_crtc) { | |
15380 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", | |
15381 | encoder->base.base.id, | |
8e329a03 | 15382 | encoder->base.name); |
24929352 DV |
15383 | |
15384 | /* Connector is active, but has no active pipe. This is | |
15385 | * fallout from our resume register restoring. Disable | |
15386 | * the encoder manually again. */ | |
15387 | if (encoder->base.crtc) { | |
15388 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15389 | encoder->base.base.id, | |
8e329a03 | 15390 | encoder->base.name); |
24929352 | 15391 | encoder->disable(encoder); |
a62d1497 VS |
15392 | if (encoder->post_disable) |
15393 | encoder->post_disable(encoder); | |
24929352 | 15394 | } |
7f1950fb EE |
15395 | encoder->base.crtc = NULL; |
15396 | encoder->connectors_active = false; | |
24929352 DV |
15397 | |
15398 | /* Inconsistent output/port/pipe state happens presumably due to | |
15399 | * a bug in one of the get_hw_state functions. Or someplace else | |
15400 | * in our code, like the register restore mess on resume. Clamp | |
15401 | * things to off as a safer default. */ | |
3a3371ff | 15402 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15403 | if (connector->encoder != encoder) |
15404 | continue; | |
7f1950fb EE |
15405 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15406 | connector->base.encoder = NULL; | |
24929352 DV |
15407 | } |
15408 | } | |
15409 | /* Enabled encoders without active connectors will be fixed in | |
15410 | * the crtc fixup. */ | |
15411 | } | |
15412 | ||
04098753 | 15413 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15414 | { |
15415 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 15416 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15417 | |
04098753 ID |
15418 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15419 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15420 | i915_disable_vga(dev); | |
15421 | } | |
15422 | } | |
15423 | ||
15424 | void i915_redisable_vga(struct drm_device *dev) | |
15425 | { | |
15426 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15427 | ||
8dc8a27c PZ |
15428 | /* This function can be called both from intel_modeset_setup_hw_state or |
15429 | * at a very early point in our resume sequence, where the power well | |
15430 | * structures are not yet restored. Since this function is at a very | |
15431 | * paranoid "someone might have enabled VGA while we were not looking" | |
15432 | * level, just check if the power well is enabled instead of trying to | |
15433 | * follow the "don't touch the power well if we don't need it" policy | |
15434 | * the rest of the driver uses. */ | |
f458ebbc | 15435 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15436 | return; |
15437 | ||
04098753 | 15438 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15439 | } |
15440 | ||
98ec7739 VS |
15441 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
15442 | { | |
15443 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
15444 | ||
d032ffa0 ML |
15445 | return !!(I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE); |
15446 | } | |
15447 | ||
15448 | static void readout_plane_state(struct intel_crtc *crtc, | |
15449 | struct intel_crtc_state *crtc_state) | |
15450 | { | |
15451 | struct intel_plane *p; | |
15452 | struct drm_plane_state *drm_plane_state; | |
15453 | bool active = crtc_state->base.active; | |
15454 | ||
15455 | if (active) { | |
15456 | crtc_state->quirks |= PIPE_CONFIG_QUIRK_INITIAL_PLANES; | |
15457 | ||
15458 | /* apply to previous sw state too */ | |
15459 | to_intel_crtc_state(crtc->base.state)->quirks |= | |
15460 | PIPE_CONFIG_QUIRK_INITIAL_PLANES; | |
15461 | } | |
98ec7739 | 15462 | |
d032ffa0 ML |
15463 | for_each_intel_plane(crtc->base.dev, p) { |
15464 | bool visible = active; | |
15465 | ||
15466 | if (crtc->pipe != p->pipe) | |
15467 | continue; | |
15468 | ||
15469 | drm_plane_state = p->base.state; | |
15470 | if (active && p->base.type == DRM_PLANE_TYPE_PRIMARY) { | |
15471 | visible = primary_get_hw_state(crtc); | |
15472 | to_intel_plane_state(drm_plane_state)->visible = visible; | |
15473 | } else { | |
15474 | /* | |
15475 | * unknown state, assume it's off to force a transition | |
15476 | * to on when calculating state changes. | |
15477 | */ | |
15478 | to_intel_plane_state(drm_plane_state)->visible = false; | |
15479 | } | |
15480 | ||
15481 | if (visible) { | |
15482 | crtc_state->base.plane_mask |= | |
15483 | 1 << drm_plane_index(&p->base); | |
15484 | } else if (crtc_state->base.state) { | |
15485 | /* Make this unconditional for atomic hw readout. */ | |
15486 | crtc_state->base.plane_mask &= | |
15487 | ~(1 << drm_plane_index(&p->base)); | |
15488 | } | |
15489 | } | |
98ec7739 VS |
15490 | } |
15491 | ||
30e984df | 15492 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15493 | { |
15494 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15495 | enum pipe pipe; | |
24929352 DV |
15496 | struct intel_crtc *crtc; |
15497 | struct intel_encoder *encoder; | |
15498 | struct intel_connector *connector; | |
5358901f | 15499 | int i; |
24929352 | 15500 | |
d3fcc808 | 15501 | for_each_intel_crtc(dev, crtc) { |
6e3c9717 | 15502 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15503 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15504 | |
6e3c9717 | 15505 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
9953599b | 15506 | |
0e8ffe1b | 15507 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15508 | crtc->config); |
24929352 | 15509 | |
83d65738 | 15510 | crtc->base.state->enable = crtc->active; |
49d6fa21 | 15511 | crtc->base.state->active = crtc->active; |
24929352 | 15512 | crtc->base.enabled = crtc->active; |
b8b7fade | 15513 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
b70709a6 | 15514 | |
d032ffa0 | 15515 | readout_plane_state(crtc, to_intel_crtc_state(crtc->base.state)); |
24929352 DV |
15516 | |
15517 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15518 | crtc->base.base.id, | |
15519 | crtc->active ? "enabled" : "disabled"); | |
15520 | } | |
15521 | ||
5358901f DV |
15522 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15523 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15524 | ||
3e369b76 ACO |
15525 | pll->on = pll->get_hw_state(dev_priv, pll, |
15526 | &pll->config.hw_state); | |
5358901f | 15527 | pll->active = 0; |
3e369b76 | 15528 | pll->config.crtc_mask = 0; |
d3fcc808 | 15529 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15530 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15531 | pll->active++; |
3e369b76 | 15532 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15533 | } |
5358901f | 15534 | } |
5358901f | 15535 | |
1e6f2ddc | 15536 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15537 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15538 | |
3e369b76 | 15539 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15540 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15541 | } |
15542 | ||
b2784e15 | 15543 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15544 | pipe = 0; |
15545 | ||
15546 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15547 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15548 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15549 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15550 | } else { |
15551 | encoder->base.crtc = NULL; | |
15552 | } | |
15553 | ||
15554 | encoder->connectors_active = false; | |
6f2bcceb | 15555 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15556 | encoder->base.base.id, |
8e329a03 | 15557 | encoder->base.name, |
24929352 | 15558 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15559 | pipe_name(pipe)); |
24929352 DV |
15560 | } |
15561 | ||
3a3371ff | 15562 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15563 | if (connector->get_hw_state(connector)) { |
15564 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
15565 | connector->encoder->connectors_active = true; | |
15566 | connector->base.encoder = &connector->encoder->base; | |
15567 | } else { | |
15568 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15569 | connector->base.encoder = NULL; | |
15570 | } | |
15571 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15572 | connector->base.base.id, | |
c23cc417 | 15573 | connector->base.name, |
24929352 DV |
15574 | connector->base.encoder ? "enabled" : "disabled"); |
15575 | } | |
30e984df DV |
15576 | } |
15577 | ||
15578 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm | |
15579 | * and i915 state tracking structures. */ | |
15580 | void intel_modeset_setup_hw_state(struct drm_device *dev, | |
15581 | bool force_restore) | |
15582 | { | |
15583 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15584 | enum pipe pipe; | |
30e984df DV |
15585 | struct intel_crtc *crtc; |
15586 | struct intel_encoder *encoder; | |
35c95375 | 15587 | int i; |
30e984df DV |
15588 | |
15589 | intel_modeset_readout_hw_state(dev); | |
24929352 | 15590 | |
babea61d JB |
15591 | /* |
15592 | * Now that we have the config, copy it to each CRTC struct | |
15593 | * Note that this could go away if we move to using crtc_config | |
15594 | * checking everywhere. | |
15595 | */ | |
d3fcc808 | 15596 | for_each_intel_crtc(dev, crtc) { |
d330a953 | 15597 | if (crtc->active && i915.fastboot) { |
6e3c9717 ACO |
15598 | intel_mode_from_pipe_config(&crtc->base.mode, |
15599 | crtc->config); | |
babea61d JB |
15600 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
15601 | crtc->base.base.id); | |
15602 | drm_mode_debug_printmodeline(&crtc->base.mode); | |
15603 | } | |
15604 | } | |
15605 | ||
24929352 | 15606 | /* HW state is read out, now we need to sanitize this mess. */ |
b2784e15 | 15607 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15608 | intel_sanitize_encoder(encoder); |
15609 | } | |
15610 | ||
055e393f | 15611 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15612 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15613 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15614 | intel_dump_pipe_config(crtc, crtc->config, |
15615 | "[setup_hw_state]"); | |
24929352 | 15616 | } |
9a935856 | 15617 | |
d29b2f9d ACO |
15618 | intel_modeset_update_connector_atomic_state(dev); |
15619 | ||
35c95375 DV |
15620 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15621 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15622 | ||
15623 | if (!pll->on || pll->active) | |
15624 | continue; | |
15625 | ||
15626 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15627 | ||
15628 | pll->disable(dev_priv, pll); | |
15629 | pll->on = false; | |
15630 | } | |
15631 | ||
3078999f PB |
15632 | if (IS_GEN9(dev)) |
15633 | skl_wm_get_hw_state(dev); | |
15634 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 VS |
15635 | ilk_wm_get_hw_state(dev); |
15636 | ||
45e2b5f6 | 15637 | if (force_restore) { |
7d0bc1ea VS |
15638 | i915_redisable_vga(dev); |
15639 | ||
f30da187 DV |
15640 | /* |
15641 | * We need to use raw interfaces for restoring state to avoid | |
15642 | * checking (bogus) intermediate states. | |
15643 | */ | |
055e393f | 15644 | for_each_pipe(dev_priv, pipe) { |
b5644d05 JB |
15645 | struct drm_crtc *crtc = |
15646 | dev_priv->pipe_to_crtc_mapping[pipe]; | |
f30da187 | 15647 | |
83a57153 | 15648 | intel_crtc_restore_mode(crtc); |
45e2b5f6 DV |
15649 | } |
15650 | } else { | |
15651 | intel_modeset_update_staged_output_state(dev); | |
15652 | } | |
8af6cf88 DV |
15653 | |
15654 | intel_modeset_check_state(dev); | |
2c7111db CW |
15655 | } |
15656 | ||
15657 | void intel_modeset_gem_init(struct drm_device *dev) | |
15658 | { | |
92122789 | 15659 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd | 15660 | struct drm_crtc *c; |
2ff8fde1 | 15661 | struct drm_i915_gem_object *obj; |
e0d6149b | 15662 | int ret; |
484b41dd | 15663 | |
ae48434c ID |
15664 | mutex_lock(&dev->struct_mutex); |
15665 | intel_init_gt_powersave(dev); | |
15666 | mutex_unlock(&dev->struct_mutex); | |
15667 | ||
92122789 JB |
15668 | /* |
15669 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15670 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15671 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15672 | * indicates as much. | |
15673 | */ | |
15674 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
15675 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15676 | DREF_SSC1_ENABLE); | |
15677 | ||
1833b134 | 15678 | intel_modeset_init_hw(dev); |
02e792fb DV |
15679 | |
15680 | intel_setup_overlay(dev); | |
484b41dd JB |
15681 | |
15682 | /* | |
15683 | * Make sure any fbs we allocated at startup are properly | |
15684 | * pinned & fenced. When we do the allocation it's too early | |
15685 | * for this. | |
15686 | */ | |
70e1e0ec | 15687 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15688 | obj = intel_fb_obj(c->primary->fb); |
15689 | if (obj == NULL) | |
484b41dd JB |
15690 | continue; |
15691 | ||
e0d6149b TU |
15692 | mutex_lock(&dev->struct_mutex); |
15693 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15694 | c->primary->fb, | |
15695 | c->primary->state, | |
15696 | NULL); | |
15697 | mutex_unlock(&dev->struct_mutex); | |
15698 | if (ret) { | |
484b41dd JB |
15699 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15700 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15701 | drm_framebuffer_unreference(c->primary->fb); |
15702 | c->primary->fb = NULL; | |
36750f28 | 15703 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15704 | update_state_fb(c->primary); |
36750f28 | 15705 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15706 | } |
15707 | } | |
0962c3c9 VS |
15708 | |
15709 | intel_backlight_register(dev); | |
79e53945 JB |
15710 | } |
15711 | ||
4932e2c3 ID |
15712 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15713 | { | |
15714 | struct drm_connector *connector = &intel_connector->base; | |
15715 | ||
15716 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15717 | drm_connector_unregister(connector); |
4932e2c3 ID |
15718 | } |
15719 | ||
79e53945 JB |
15720 | void intel_modeset_cleanup(struct drm_device *dev) |
15721 | { | |
652c393a | 15722 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15723 | struct drm_connector *connector; |
652c393a | 15724 | |
2eb5252e ID |
15725 | intel_disable_gt_powersave(dev); |
15726 | ||
0962c3c9 VS |
15727 | intel_backlight_unregister(dev); |
15728 | ||
fd0c0642 DV |
15729 | /* |
15730 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15731 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15732 | * experience fancy races otherwise. |
15733 | */ | |
2aeb7d3a | 15734 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15735 | |
fd0c0642 DV |
15736 | /* |
15737 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15738 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15739 | */ | |
f87ea761 | 15740 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15741 | |
652c393a JB |
15742 | mutex_lock(&dev->struct_mutex); |
15743 | ||
723bfd70 JB |
15744 | intel_unregister_dsm_handler(); |
15745 | ||
7ff0ebcc | 15746 | intel_fbc_disable(dev); |
e70236a8 | 15747 | |
69341a5e KH |
15748 | mutex_unlock(&dev->struct_mutex); |
15749 | ||
1630fe75 CW |
15750 | /* flush any delayed tasks or pending work */ |
15751 | flush_scheduled_work(); | |
15752 | ||
db31af1d JN |
15753 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15754 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15755 | struct intel_connector *intel_connector; |
15756 | ||
15757 | intel_connector = to_intel_connector(connector); | |
15758 | intel_connector->unregister(intel_connector); | |
db31af1d | 15759 | } |
d9255d57 | 15760 | |
79e53945 | 15761 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15762 | |
15763 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15764 | |
15765 | mutex_lock(&dev->struct_mutex); | |
15766 | intel_cleanup_gt_powersave(dev); | |
15767 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15768 | } |
15769 | ||
f1c79df3 ZW |
15770 | /* |
15771 | * Return which encoder is currently attached for connector. | |
15772 | */ | |
df0e9248 | 15773 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15774 | { |
df0e9248 CW |
15775 | return &intel_attached_encoder(connector)->base; |
15776 | } | |
f1c79df3 | 15777 | |
df0e9248 CW |
15778 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15779 | struct intel_encoder *encoder) | |
15780 | { | |
15781 | connector->encoder = encoder; | |
15782 | drm_mode_connector_attach_encoder(&connector->base, | |
15783 | &encoder->base); | |
79e53945 | 15784 | } |
28d52043 DA |
15785 | |
15786 | /* | |
15787 | * set vga decode state - true == enable VGA decode | |
15788 | */ | |
15789 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15790 | { | |
15791 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15792 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15793 | u16 gmch_ctrl; |
15794 | ||
75fa041d CW |
15795 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15796 | DRM_ERROR("failed to read control word\n"); | |
15797 | return -EIO; | |
15798 | } | |
15799 | ||
c0cc8a55 CW |
15800 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15801 | return 0; | |
15802 | ||
28d52043 DA |
15803 | if (state) |
15804 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15805 | else | |
15806 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15807 | |
15808 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15809 | DRM_ERROR("failed to write control word\n"); | |
15810 | return -EIO; | |
15811 | } | |
15812 | ||
28d52043 DA |
15813 | return 0; |
15814 | } | |
c4a1d9e4 | 15815 | |
c4a1d9e4 | 15816 | struct intel_display_error_state { |
ff57f1b0 PZ |
15817 | |
15818 | u32 power_well_driver; | |
15819 | ||
63b66e5b CW |
15820 | int num_transcoders; |
15821 | ||
c4a1d9e4 CW |
15822 | struct intel_cursor_error_state { |
15823 | u32 control; | |
15824 | u32 position; | |
15825 | u32 base; | |
15826 | u32 size; | |
52331309 | 15827 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15828 | |
15829 | struct intel_pipe_error_state { | |
ddf9c536 | 15830 | bool power_domain_on; |
c4a1d9e4 | 15831 | u32 source; |
f301b1e1 | 15832 | u32 stat; |
52331309 | 15833 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15834 | |
15835 | struct intel_plane_error_state { | |
15836 | u32 control; | |
15837 | u32 stride; | |
15838 | u32 size; | |
15839 | u32 pos; | |
15840 | u32 addr; | |
15841 | u32 surface; | |
15842 | u32 tile_offset; | |
52331309 | 15843 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15844 | |
15845 | struct intel_transcoder_error_state { | |
ddf9c536 | 15846 | bool power_domain_on; |
63b66e5b CW |
15847 | enum transcoder cpu_transcoder; |
15848 | ||
15849 | u32 conf; | |
15850 | ||
15851 | u32 htotal; | |
15852 | u32 hblank; | |
15853 | u32 hsync; | |
15854 | u32 vtotal; | |
15855 | u32 vblank; | |
15856 | u32 vsync; | |
15857 | } transcoder[4]; | |
c4a1d9e4 CW |
15858 | }; |
15859 | ||
15860 | struct intel_display_error_state * | |
15861 | intel_display_capture_error_state(struct drm_device *dev) | |
15862 | { | |
fbee40df | 15863 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15864 | struct intel_display_error_state *error; |
63b66e5b CW |
15865 | int transcoders[] = { |
15866 | TRANSCODER_A, | |
15867 | TRANSCODER_B, | |
15868 | TRANSCODER_C, | |
15869 | TRANSCODER_EDP, | |
15870 | }; | |
c4a1d9e4 CW |
15871 | int i; |
15872 | ||
63b66e5b CW |
15873 | if (INTEL_INFO(dev)->num_pipes == 0) |
15874 | return NULL; | |
15875 | ||
9d1cb914 | 15876 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15877 | if (error == NULL) |
15878 | return NULL; | |
15879 | ||
190be112 | 15880 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15881 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15882 | ||
055e393f | 15883 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15884 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15885 | __intel_display_power_is_enabled(dev_priv, |
15886 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15887 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15888 | continue; |
15889 | ||
5efb3e28 VS |
15890 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15891 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15892 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15893 | |
15894 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15895 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15896 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15897 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15898 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15899 | } | |
ca291363 PZ |
15900 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15901 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15902 | if (INTEL_INFO(dev)->gen >= 4) { |
15903 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15904 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15905 | } | |
15906 | ||
c4a1d9e4 | 15907 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15908 | |
3abfce77 | 15909 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15910 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15911 | } |
15912 | ||
15913 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15914 | if (HAS_DDI(dev_priv->dev)) | |
15915 | error->num_transcoders++; /* Account for eDP. */ | |
15916 | ||
15917 | for (i = 0; i < error->num_transcoders; i++) { | |
15918 | enum transcoder cpu_transcoder = transcoders[i]; | |
15919 | ||
ddf9c536 | 15920 | error->transcoder[i].power_domain_on = |
f458ebbc | 15921 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15922 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15923 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15924 | continue; |
15925 | ||
63b66e5b CW |
15926 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15927 | ||
15928 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15929 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15930 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15931 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15932 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15933 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15934 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15935 | } |
15936 | ||
15937 | return error; | |
15938 | } | |
15939 | ||
edc3d884 MK |
15940 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15941 | ||
c4a1d9e4 | 15942 | void |
edc3d884 | 15943 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15944 | struct drm_device *dev, |
15945 | struct intel_display_error_state *error) | |
15946 | { | |
055e393f | 15947 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15948 | int i; |
15949 | ||
63b66e5b CW |
15950 | if (!error) |
15951 | return; | |
15952 | ||
edc3d884 | 15953 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15954 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15955 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15956 | error->power_well_driver); |
055e393f | 15957 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15958 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15959 | err_printf(m, " Power: %s\n", |
15960 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15961 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15962 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15963 | |
15964 | err_printf(m, "Plane [%d]:\n", i); | |
15965 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15966 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15967 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15968 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15969 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15970 | } |
4b71a570 | 15971 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15972 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15973 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15974 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15975 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15976 | } |
15977 | ||
edc3d884 MK |
15978 | err_printf(m, "Cursor [%d]:\n", i); |
15979 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15980 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15981 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15982 | } |
63b66e5b CW |
15983 | |
15984 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15985 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15986 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15987 | err_printf(m, " Power: %s\n", |
15988 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15989 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15990 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15991 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15992 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15993 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15994 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15995 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15996 | } | |
c4a1d9e4 | 15997 | } |
e2fcdaa9 VS |
15998 | |
15999 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
16000 | { | |
16001 | struct intel_crtc *crtc; | |
16002 | ||
16003 | for_each_intel_crtc(dev, crtc) { | |
16004 | struct intel_unpin_work *work; | |
e2fcdaa9 | 16005 | |
5e2d7afc | 16006 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
16007 | |
16008 | work = crtc->unpin_work; | |
16009 | ||
16010 | if (work && work->event && | |
16011 | work->event->base.file_priv == file) { | |
16012 | kfree(work->event); | |
16013 | work->event = NULL; | |
16014 | } | |
16015 | ||
5e2d7afc | 16016 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
16017 | } |
16018 | } |