]>
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 | |
8c7b5ccb | 89 | static int intel_set_mode(struct drm_crtc *crtc, |
83a57153 | 90 | struct drm_atomic_state *state); |
eb1bfe80 JB |
91 | static int intel_framebuffer_init(struct drm_device *dev, |
92 | struct intel_framebuffer *ifb, | |
93 | struct drm_mode_fb_cmd2 *mode_cmd, | |
94 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
95 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
96 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
29407aab | 97 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
98 | struct intel_link_m_n *m_n, |
99 | struct intel_link_m_n *m2_n2); | |
29407aab | 100 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 DV |
101 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
102 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
d288f65f | 103 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 104 | const struct intel_crtc_state *pipe_config); |
d288f65f | 105 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 106 | const struct intel_crtc_state *pipe_config); |
ea2c67bb MR |
107 | static void intel_begin_crtc_commit(struct drm_crtc *crtc); |
108 | static void intel_finish_crtc_commit(struct drm_crtc *crtc); | |
549e2bfb CK |
109 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
110 | struct intel_crtc_state *crtc_state); | |
5ab7b0b7 ID |
111 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
112 | int num_connectors); | |
ce22dba9 ML |
113 | static void intel_crtc_enable_planes(struct drm_crtc *crtc); |
114 | static void intel_crtc_disable_planes(struct drm_crtc *crtc); | |
e7457a9a | 115 | |
0e32b39c DA |
116 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
117 | { | |
118 | if (!connector->mst_port) | |
119 | return connector->encoder; | |
120 | else | |
121 | return &connector->mst_port->mst_encoders[pipe]->base; | |
122 | } | |
123 | ||
79e53945 | 124 | typedef struct { |
0206e353 | 125 | int min, max; |
79e53945 JB |
126 | } intel_range_t; |
127 | ||
128 | typedef struct { | |
0206e353 AJ |
129 | int dot_limit; |
130 | int p2_slow, p2_fast; | |
79e53945 JB |
131 | } intel_p2_t; |
132 | ||
d4906093 ML |
133 | typedef struct intel_limit intel_limit_t; |
134 | struct intel_limit { | |
0206e353 AJ |
135 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
136 | intel_p2_t p2; | |
d4906093 | 137 | }; |
79e53945 | 138 | |
d2acd215 DV |
139 | int |
140 | intel_pch_rawclk(struct drm_device *dev) | |
141 | { | |
142 | struct drm_i915_private *dev_priv = dev->dev_private; | |
143 | ||
144 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
145 | ||
146 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
147 | } | |
148 | ||
021357ac CW |
149 | static inline u32 /* units of 100MHz */ |
150 | intel_fdi_link_freq(struct drm_device *dev) | |
151 | { | |
8b99e68c CW |
152 | if (IS_GEN5(dev)) { |
153 | struct drm_i915_private *dev_priv = dev->dev_private; | |
154 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
155 | } else | |
156 | return 27; | |
021357ac CW |
157 | } |
158 | ||
5d536e28 | 159 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 160 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 161 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 162 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
163 | .m = { .min = 96, .max = 140 }, |
164 | .m1 = { .min = 18, .max = 26 }, | |
165 | .m2 = { .min = 6, .max = 16 }, | |
166 | .p = { .min = 4, .max = 128 }, | |
167 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
168 | .p2 = { .dot_limit = 165000, |
169 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
170 | }; |
171 | ||
5d536e28 DV |
172 | static const intel_limit_t intel_limits_i8xx_dvo = { |
173 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 174 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 175 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
176 | .m = { .min = 96, .max = 140 }, |
177 | .m1 = { .min = 18, .max = 26 }, | |
178 | .m2 = { .min = 6, .max = 16 }, | |
179 | .p = { .min = 4, .max = 128 }, | |
180 | .p1 = { .min = 2, .max = 33 }, | |
181 | .p2 = { .dot_limit = 165000, | |
182 | .p2_slow = 4, .p2_fast = 4 }, | |
183 | }; | |
184 | ||
e4b36699 | 185 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 186 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 187 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 188 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
189 | .m = { .min = 96, .max = 140 }, |
190 | .m1 = { .min = 18, .max = 26 }, | |
191 | .m2 = { .min = 6, .max = 16 }, | |
192 | .p = { .min = 4, .max = 128 }, | |
193 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
194 | .p2 = { .dot_limit = 165000, |
195 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 196 | }; |
273e27ca | 197 | |
e4b36699 | 198 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
199 | .dot = { .min = 20000, .max = 400000 }, |
200 | .vco = { .min = 1400000, .max = 2800000 }, | |
201 | .n = { .min = 1, .max = 6 }, | |
202 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
203 | .m1 = { .min = 8, .max = 18 }, |
204 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
205 | .p = { .min = 5, .max = 80 }, |
206 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
207 | .p2 = { .dot_limit = 200000, |
208 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
209 | }; |
210 | ||
211 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
212 | .dot = { .min = 20000, .max = 400000 }, |
213 | .vco = { .min = 1400000, .max = 2800000 }, | |
214 | .n = { .min = 1, .max = 6 }, | |
215 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
216 | .m1 = { .min = 8, .max = 18 }, |
217 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
218 | .p = { .min = 7, .max = 98 }, |
219 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
220 | .p2 = { .dot_limit = 112000, |
221 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
222 | }; |
223 | ||
273e27ca | 224 | |
e4b36699 | 225 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
226 | .dot = { .min = 25000, .max = 270000 }, |
227 | .vco = { .min = 1750000, .max = 3500000}, | |
228 | .n = { .min = 1, .max = 4 }, | |
229 | .m = { .min = 104, .max = 138 }, | |
230 | .m1 = { .min = 17, .max = 23 }, | |
231 | .m2 = { .min = 5, .max = 11 }, | |
232 | .p = { .min = 10, .max = 30 }, | |
233 | .p1 = { .min = 1, .max = 3}, | |
234 | .p2 = { .dot_limit = 270000, | |
235 | .p2_slow = 10, | |
236 | .p2_fast = 10 | |
044c7c41 | 237 | }, |
e4b36699 KP |
238 | }; |
239 | ||
240 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
241 | .dot = { .min = 22000, .max = 400000 }, |
242 | .vco = { .min = 1750000, .max = 3500000}, | |
243 | .n = { .min = 1, .max = 4 }, | |
244 | .m = { .min = 104, .max = 138 }, | |
245 | .m1 = { .min = 16, .max = 23 }, | |
246 | .m2 = { .min = 5, .max = 11 }, | |
247 | .p = { .min = 5, .max = 80 }, | |
248 | .p1 = { .min = 1, .max = 8}, | |
249 | .p2 = { .dot_limit = 165000, | |
250 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
251 | }; |
252 | ||
253 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
254 | .dot = { .min = 20000, .max = 115000 }, |
255 | .vco = { .min = 1750000, .max = 3500000 }, | |
256 | .n = { .min = 1, .max = 3 }, | |
257 | .m = { .min = 104, .max = 138 }, | |
258 | .m1 = { .min = 17, .max = 23 }, | |
259 | .m2 = { .min = 5, .max = 11 }, | |
260 | .p = { .min = 28, .max = 112 }, | |
261 | .p1 = { .min = 2, .max = 8 }, | |
262 | .p2 = { .dot_limit = 0, | |
263 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 264 | }, |
e4b36699 KP |
265 | }; |
266 | ||
267 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
268 | .dot = { .min = 80000, .max = 224000 }, |
269 | .vco = { .min = 1750000, .max = 3500000 }, | |
270 | .n = { .min = 1, .max = 3 }, | |
271 | .m = { .min = 104, .max = 138 }, | |
272 | .m1 = { .min = 17, .max = 23 }, | |
273 | .m2 = { .min = 5, .max = 11 }, | |
274 | .p = { .min = 14, .max = 42 }, | |
275 | .p1 = { .min = 2, .max = 6 }, | |
276 | .p2 = { .dot_limit = 0, | |
277 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 278 | }, |
e4b36699 KP |
279 | }; |
280 | ||
f2b115e6 | 281 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
282 | .dot = { .min = 20000, .max = 400000}, |
283 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 284 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
285 | .n = { .min = 3, .max = 6 }, |
286 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 287 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
288 | .m1 = { .min = 0, .max = 0 }, |
289 | .m2 = { .min = 0, .max = 254 }, | |
290 | .p = { .min = 5, .max = 80 }, | |
291 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
292 | .p2 = { .dot_limit = 200000, |
293 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
294 | }; |
295 | ||
f2b115e6 | 296 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
297 | .dot = { .min = 20000, .max = 400000 }, |
298 | .vco = { .min = 1700000, .max = 3500000 }, | |
299 | .n = { .min = 3, .max = 6 }, | |
300 | .m = { .min = 2, .max = 256 }, | |
301 | .m1 = { .min = 0, .max = 0 }, | |
302 | .m2 = { .min = 0, .max = 254 }, | |
303 | .p = { .min = 7, .max = 112 }, | |
304 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
305 | .p2 = { .dot_limit = 112000, |
306 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
307 | }; |
308 | ||
273e27ca EA |
309 | /* Ironlake / Sandybridge |
310 | * | |
311 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
312 | * the range value for them is (actual_value - 2). | |
313 | */ | |
b91ad0ec | 314 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
315 | .dot = { .min = 25000, .max = 350000 }, |
316 | .vco = { .min = 1760000, .max = 3510000 }, | |
317 | .n = { .min = 1, .max = 5 }, | |
318 | .m = { .min = 79, .max = 127 }, | |
319 | .m1 = { .min = 12, .max = 22 }, | |
320 | .m2 = { .min = 5, .max = 9 }, | |
321 | .p = { .min = 5, .max = 80 }, | |
322 | .p1 = { .min = 1, .max = 8 }, | |
323 | .p2 = { .dot_limit = 225000, | |
324 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
325 | }; |
326 | ||
b91ad0ec | 327 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
328 | .dot = { .min = 25000, .max = 350000 }, |
329 | .vco = { .min = 1760000, .max = 3510000 }, | |
330 | .n = { .min = 1, .max = 3 }, | |
331 | .m = { .min = 79, .max = 118 }, | |
332 | .m1 = { .min = 12, .max = 22 }, | |
333 | .m2 = { .min = 5, .max = 9 }, | |
334 | .p = { .min = 28, .max = 112 }, | |
335 | .p1 = { .min = 2, .max = 8 }, | |
336 | .p2 = { .dot_limit = 225000, | |
337 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
338 | }; |
339 | ||
340 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
341 | .dot = { .min = 25000, .max = 350000 }, |
342 | .vco = { .min = 1760000, .max = 3510000 }, | |
343 | .n = { .min = 1, .max = 3 }, | |
344 | .m = { .min = 79, .max = 127 }, | |
345 | .m1 = { .min = 12, .max = 22 }, | |
346 | .m2 = { .min = 5, .max = 9 }, | |
347 | .p = { .min = 14, .max = 56 }, | |
348 | .p1 = { .min = 2, .max = 8 }, | |
349 | .p2 = { .dot_limit = 225000, | |
350 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
351 | }; |
352 | ||
273e27ca | 353 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 354 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
355 | .dot = { .min = 25000, .max = 350000 }, |
356 | .vco = { .min = 1760000, .max = 3510000 }, | |
357 | .n = { .min = 1, .max = 2 }, | |
358 | .m = { .min = 79, .max = 126 }, | |
359 | .m1 = { .min = 12, .max = 22 }, | |
360 | .m2 = { .min = 5, .max = 9 }, | |
361 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 362 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
363 | .p2 = { .dot_limit = 225000, |
364 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
365 | }; |
366 | ||
367 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
368 | .dot = { .min = 25000, .max = 350000 }, |
369 | .vco = { .min = 1760000, .max = 3510000 }, | |
370 | .n = { .min = 1, .max = 3 }, | |
371 | .m = { .min = 79, .max = 126 }, | |
372 | .m1 = { .min = 12, .max = 22 }, | |
373 | .m2 = { .min = 5, .max = 9 }, | |
374 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 375 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
376 | .p2 = { .dot_limit = 225000, |
377 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
378 | }; |
379 | ||
dc730512 | 380 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
381 | /* |
382 | * These are the data rate limits (measured in fast clocks) | |
383 | * since those are the strictest limits we have. The fast | |
384 | * clock and actual rate limits are more relaxed, so checking | |
385 | * them would make no difference. | |
386 | */ | |
387 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 388 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 389 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
390 | .m1 = { .min = 2, .max = 3 }, |
391 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 392 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 393 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
394 | }; |
395 | ||
ef9348c8 CML |
396 | static const intel_limit_t intel_limits_chv = { |
397 | /* | |
398 | * These are the data rate limits (measured in fast clocks) | |
399 | * since those are the strictest limits we have. The fast | |
400 | * clock and actual rate limits are more relaxed, so checking | |
401 | * them would make no difference. | |
402 | */ | |
403 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 404 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
405 | .n = { .min = 1, .max = 1 }, |
406 | .m1 = { .min = 2, .max = 2 }, | |
407 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
408 | .p1 = { .min = 2, .max = 4 }, | |
409 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
410 | }; | |
411 | ||
5ab7b0b7 ID |
412 | static const intel_limit_t intel_limits_bxt = { |
413 | /* FIXME: find real dot limits */ | |
414 | .dot = { .min = 0, .max = INT_MAX }, | |
415 | .vco = { .min = 4800000, .max = 6480000 }, | |
416 | .n = { .min = 1, .max = 1 }, | |
417 | .m1 = { .min = 2, .max = 2 }, | |
418 | /* FIXME: find real m2 limits */ | |
419 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
420 | .p1 = { .min = 2, .max = 4 }, | |
421 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
422 | }; | |
423 | ||
6b4bf1c4 VS |
424 | static void vlv_clock(int refclk, intel_clock_t *clock) |
425 | { | |
426 | clock->m = clock->m1 * clock->m2; | |
427 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e VS |
428 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
429 | return; | |
fb03ac01 VS |
430 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
431 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
6b4bf1c4 VS |
432 | } |
433 | ||
e0638cdf PZ |
434 | /** |
435 | * Returns whether any output on the specified pipe is of the specified type | |
436 | */ | |
4093561b | 437 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 438 | { |
409ee761 | 439 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
440 | struct intel_encoder *encoder; |
441 | ||
409ee761 | 442 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
443 | if (encoder->type == type) |
444 | return true; | |
445 | ||
446 | return false; | |
447 | } | |
448 | ||
d0737e1d ACO |
449 | /** |
450 | * Returns whether any output on the specified pipe will have the specified | |
451 | * type after a staged modeset is complete, i.e., the same as | |
452 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
453 | * encoder->crtc. | |
454 | */ | |
a93e255f ACO |
455 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
456 | int type) | |
d0737e1d | 457 | { |
a93e255f | 458 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 459 | struct drm_connector *connector; |
a93e255f | 460 | struct drm_connector_state *connector_state; |
d0737e1d | 461 | struct intel_encoder *encoder; |
a93e255f ACO |
462 | int i, num_connectors = 0; |
463 | ||
da3ced29 | 464 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
465 | if (connector_state->crtc != crtc_state->base.crtc) |
466 | continue; | |
467 | ||
468 | num_connectors++; | |
d0737e1d | 469 | |
a93e255f ACO |
470 | encoder = to_intel_encoder(connector_state->best_encoder); |
471 | if (encoder->type == type) | |
d0737e1d | 472 | return true; |
a93e255f ACO |
473 | } |
474 | ||
475 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
476 | |
477 | return false; | |
478 | } | |
479 | ||
a93e255f ACO |
480 | static const intel_limit_t * |
481 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 482 | { |
a93e255f | 483 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 484 | const intel_limit_t *limit; |
b91ad0ec | 485 | |
a93e255f | 486 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 487 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 488 | if (refclk == 100000) |
b91ad0ec ZW |
489 | limit = &intel_limits_ironlake_dual_lvds_100m; |
490 | else | |
491 | limit = &intel_limits_ironlake_dual_lvds; | |
492 | } else { | |
1b894b59 | 493 | if (refclk == 100000) |
b91ad0ec ZW |
494 | limit = &intel_limits_ironlake_single_lvds_100m; |
495 | else | |
496 | limit = &intel_limits_ironlake_single_lvds; | |
497 | } | |
c6bb3538 | 498 | } else |
b91ad0ec | 499 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
500 | |
501 | return limit; | |
502 | } | |
503 | ||
a93e255f ACO |
504 | static const intel_limit_t * |
505 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 506 | { |
a93e255f | 507 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
508 | const intel_limit_t *limit; |
509 | ||
a93e255f | 510 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 511 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 512 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 513 | else |
e4b36699 | 514 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
515 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
516 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 517 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 518 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 519 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 520 | } else /* The option is for other outputs */ |
e4b36699 | 521 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
522 | |
523 | return limit; | |
524 | } | |
525 | ||
a93e255f ACO |
526 | static const intel_limit_t * |
527 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 528 | { |
a93e255f | 529 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
530 | const intel_limit_t *limit; |
531 | ||
5ab7b0b7 ID |
532 | if (IS_BROXTON(dev)) |
533 | limit = &intel_limits_bxt; | |
534 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 535 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 536 | else if (IS_G4X(dev)) { |
a93e255f | 537 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 538 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 539 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 540 | limit = &intel_limits_pineview_lvds; |
2177832f | 541 | else |
f2b115e6 | 542 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
543 | } else if (IS_CHERRYVIEW(dev)) { |
544 | limit = &intel_limits_chv; | |
a0c4da24 | 545 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 546 | limit = &intel_limits_vlv; |
a6c45cf0 | 547 | } else if (!IS_GEN2(dev)) { |
a93e255f | 548 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
549 | limit = &intel_limits_i9xx_lvds; |
550 | else | |
551 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 552 | } else { |
a93e255f | 553 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 554 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 555 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 556 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
557 | else |
558 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
559 | } |
560 | return limit; | |
561 | } | |
562 | ||
f2b115e6 AJ |
563 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
564 | static void pineview_clock(int refclk, intel_clock_t *clock) | |
79e53945 | 565 | { |
2177832f SL |
566 | clock->m = clock->m2 + 2; |
567 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e VS |
568 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
569 | return; | |
fb03ac01 VS |
570 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
571 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
2177832f SL |
572 | } |
573 | ||
7429e9d4 DV |
574 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
575 | { | |
576 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
577 | } | |
578 | ||
ac58c3f0 | 579 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
2177832f | 580 | { |
7429e9d4 | 581 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 582 | clock->p = clock->p1 * clock->p2; |
ed5ca77e VS |
583 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
584 | return; | |
fb03ac01 VS |
585 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
586 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
79e53945 JB |
587 | } |
588 | ||
ef9348c8 CML |
589 | static void chv_clock(int refclk, intel_clock_t *clock) |
590 | { | |
591 | clock->m = clock->m1 * clock->m2; | |
592 | clock->p = clock->p1 * clock->p2; | |
593 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
594 | return; | |
595 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, | |
596 | clock->n << 22); | |
597 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
598 | } | |
599 | ||
7c04d1d9 | 600 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
601 | /** |
602 | * Returns whether the given set of divisors are valid for a given refclk with | |
603 | * the given connectors. | |
604 | */ | |
605 | ||
1b894b59 CW |
606 | static bool intel_PLL_is_valid(struct drm_device *dev, |
607 | const intel_limit_t *limit, | |
608 | const intel_clock_t *clock) | |
79e53945 | 609 | { |
f01b7962 VS |
610 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
611 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 612 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 613 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 614 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 615 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 616 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 617 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 618 | |
5ab7b0b7 | 619 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
f01b7962 VS |
620 | if (clock->m1 <= clock->m2) |
621 | INTELPllInvalid("m1 <= m2\n"); | |
622 | ||
5ab7b0b7 | 623 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
624 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
625 | INTELPllInvalid("p out of range\n"); | |
626 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
627 | INTELPllInvalid("m out of range\n"); | |
628 | } | |
629 | ||
79e53945 | 630 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 631 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
632 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
633 | * connector, etc., rather than just a single range. | |
634 | */ | |
635 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 636 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
637 | |
638 | return true; | |
639 | } | |
640 | ||
d4906093 | 641 | static bool |
a93e255f ACO |
642 | i9xx_find_best_dpll(const intel_limit_t *limit, |
643 | struct intel_crtc_state *crtc_state, | |
cec2f356 SP |
644 | int target, int refclk, intel_clock_t *match_clock, |
645 | intel_clock_t *best_clock) | |
79e53945 | 646 | { |
a93e255f | 647 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 648 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 649 | intel_clock_t clock; |
79e53945 JB |
650 | int err = target; |
651 | ||
a93e255f | 652 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 653 | /* |
a210b028 DV |
654 | * For LVDS just rely on its current settings for dual-channel. |
655 | * We haven't figured out how to reliably set up different | |
656 | * single/dual channel state, if we even can. | |
79e53945 | 657 | */ |
1974cad0 | 658 | if (intel_is_dual_link_lvds(dev)) |
79e53945 JB |
659 | clock.p2 = limit->p2.p2_fast; |
660 | else | |
661 | clock.p2 = limit->p2.p2_slow; | |
662 | } else { | |
663 | if (target < limit->p2.dot_limit) | |
664 | clock.p2 = limit->p2.p2_slow; | |
665 | else | |
666 | clock.p2 = limit->p2.p2_fast; | |
667 | } | |
668 | ||
0206e353 | 669 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 670 | |
42158660 ZY |
671 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
672 | clock.m1++) { | |
673 | for (clock.m2 = limit->m2.min; | |
674 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 675 | if (clock.m2 >= clock.m1) |
42158660 ZY |
676 | break; |
677 | for (clock.n = limit->n.min; | |
678 | clock.n <= limit->n.max; clock.n++) { | |
679 | for (clock.p1 = limit->p1.min; | |
680 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
681 | int this_err; |
682 | ||
ac58c3f0 DV |
683 | i9xx_clock(refclk, &clock); |
684 | if (!intel_PLL_is_valid(dev, limit, | |
685 | &clock)) | |
686 | continue; | |
687 | if (match_clock && | |
688 | clock.p != match_clock->p) | |
689 | continue; | |
690 | ||
691 | this_err = abs(clock.dot - target); | |
692 | if (this_err < err) { | |
693 | *best_clock = clock; | |
694 | err = this_err; | |
695 | } | |
696 | } | |
697 | } | |
698 | } | |
699 | } | |
700 | ||
701 | return (err != target); | |
702 | } | |
703 | ||
704 | static bool | |
a93e255f ACO |
705 | pnv_find_best_dpll(const intel_limit_t *limit, |
706 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
707 | int target, int refclk, intel_clock_t *match_clock, |
708 | intel_clock_t *best_clock) | |
79e53945 | 709 | { |
a93e255f | 710 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 711 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 712 | intel_clock_t clock; |
79e53945 JB |
713 | int err = target; |
714 | ||
a93e255f | 715 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 716 | /* |
a210b028 DV |
717 | * For LVDS just rely on its current settings for dual-channel. |
718 | * We haven't figured out how to reliably set up different | |
719 | * single/dual channel state, if we even can. | |
79e53945 | 720 | */ |
1974cad0 | 721 | if (intel_is_dual_link_lvds(dev)) |
79e53945 JB |
722 | clock.p2 = limit->p2.p2_fast; |
723 | else | |
724 | clock.p2 = limit->p2.p2_slow; | |
725 | } else { | |
726 | if (target < limit->p2.dot_limit) | |
727 | clock.p2 = limit->p2.p2_slow; | |
728 | else | |
729 | clock.p2 = limit->p2.p2_fast; | |
730 | } | |
731 | ||
0206e353 | 732 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 733 | |
42158660 ZY |
734 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
735 | clock.m1++) { | |
736 | for (clock.m2 = limit->m2.min; | |
737 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
738 | for (clock.n = limit->n.min; |
739 | clock.n <= limit->n.max; clock.n++) { | |
740 | for (clock.p1 = limit->p1.min; | |
741 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
742 | int this_err; |
743 | ||
ac58c3f0 | 744 | pineview_clock(refclk, &clock); |
1b894b59 CW |
745 | if (!intel_PLL_is_valid(dev, limit, |
746 | &clock)) | |
79e53945 | 747 | continue; |
cec2f356 SP |
748 | if (match_clock && |
749 | clock.p != match_clock->p) | |
750 | continue; | |
79e53945 JB |
751 | |
752 | this_err = abs(clock.dot - target); | |
753 | if (this_err < err) { | |
754 | *best_clock = clock; | |
755 | err = this_err; | |
756 | } | |
757 | } | |
758 | } | |
759 | } | |
760 | } | |
761 | ||
762 | return (err != target); | |
763 | } | |
764 | ||
d4906093 | 765 | static bool |
a93e255f ACO |
766 | g4x_find_best_dpll(const intel_limit_t *limit, |
767 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
768 | int target, int refclk, intel_clock_t *match_clock, |
769 | intel_clock_t *best_clock) | |
d4906093 | 770 | { |
a93e255f | 771 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 772 | struct drm_device *dev = crtc->base.dev; |
d4906093 ML |
773 | intel_clock_t clock; |
774 | int max_n; | |
775 | bool found; | |
6ba770dc AJ |
776 | /* approximately equals target * 0.00585 */ |
777 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
778 | found = false; |
779 | ||
a93e255f | 780 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 781 | if (intel_is_dual_link_lvds(dev)) |
d4906093 ML |
782 | clock.p2 = limit->p2.p2_fast; |
783 | else | |
784 | clock.p2 = limit->p2.p2_slow; | |
785 | } else { | |
786 | if (target < limit->p2.dot_limit) | |
787 | clock.p2 = limit->p2.p2_slow; | |
788 | else | |
789 | clock.p2 = limit->p2.p2_fast; | |
790 | } | |
791 | ||
792 | memset(best_clock, 0, sizeof(*best_clock)); | |
793 | max_n = limit->n.max; | |
f77f13e2 | 794 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 795 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 796 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
797 | for (clock.m1 = limit->m1.max; |
798 | clock.m1 >= limit->m1.min; clock.m1--) { | |
799 | for (clock.m2 = limit->m2.max; | |
800 | clock.m2 >= limit->m2.min; clock.m2--) { | |
801 | for (clock.p1 = limit->p1.max; | |
802 | clock.p1 >= limit->p1.min; clock.p1--) { | |
803 | int this_err; | |
804 | ||
ac58c3f0 | 805 | i9xx_clock(refclk, &clock); |
1b894b59 CW |
806 | if (!intel_PLL_is_valid(dev, limit, |
807 | &clock)) | |
d4906093 | 808 | continue; |
1b894b59 CW |
809 | |
810 | this_err = abs(clock.dot - target); | |
d4906093 ML |
811 | if (this_err < err_most) { |
812 | *best_clock = clock; | |
813 | err_most = this_err; | |
814 | max_n = clock.n; | |
815 | found = true; | |
816 | } | |
817 | } | |
818 | } | |
819 | } | |
820 | } | |
2c07245f ZW |
821 | return found; |
822 | } | |
823 | ||
d5dd62bd ID |
824 | /* |
825 | * Check if the calculated PLL configuration is more optimal compared to the | |
826 | * best configuration and error found so far. Return the calculated error. | |
827 | */ | |
828 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
829 | const intel_clock_t *calculated_clock, | |
830 | const intel_clock_t *best_clock, | |
831 | unsigned int best_error_ppm, | |
832 | unsigned int *error_ppm) | |
833 | { | |
9ca3ba01 ID |
834 | /* |
835 | * For CHV ignore the error and consider only the P value. | |
836 | * Prefer a bigger P value based on HW requirements. | |
837 | */ | |
838 | if (IS_CHERRYVIEW(dev)) { | |
839 | *error_ppm = 0; | |
840 | ||
841 | return calculated_clock->p > best_clock->p; | |
842 | } | |
843 | ||
24be4e46 ID |
844 | if (WARN_ON_ONCE(!target_freq)) |
845 | return false; | |
846 | ||
d5dd62bd ID |
847 | *error_ppm = div_u64(1000000ULL * |
848 | abs(target_freq - calculated_clock->dot), | |
849 | target_freq); | |
850 | /* | |
851 | * Prefer a better P value over a better (smaller) error if the error | |
852 | * is small. Ensure this preference for future configurations too by | |
853 | * setting the error to 0. | |
854 | */ | |
855 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
856 | *error_ppm = 0; | |
857 | ||
858 | return true; | |
859 | } | |
860 | ||
861 | return *error_ppm + 10 < best_error_ppm; | |
862 | } | |
863 | ||
a0c4da24 | 864 | static bool |
a93e255f ACO |
865 | vlv_find_best_dpll(const intel_limit_t *limit, |
866 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
867 | int target, int refclk, intel_clock_t *match_clock, |
868 | intel_clock_t *best_clock) | |
a0c4da24 | 869 | { |
a93e255f | 870 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 871 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 872 | intel_clock_t clock; |
69e4f900 | 873 | unsigned int bestppm = 1000000; |
27e639bf VS |
874 | /* min update 19.2 MHz */ |
875 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 876 | bool found = false; |
a0c4da24 | 877 | |
6b4bf1c4 VS |
878 | target *= 5; /* fast clock */ |
879 | ||
880 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
881 | |
882 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 883 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 884 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 885 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 886 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 887 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 888 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 889 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 890 | unsigned int ppm; |
69e4f900 | 891 | |
6b4bf1c4 VS |
892 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
893 | refclk * clock.m1); | |
894 | ||
895 | vlv_clock(refclk, &clock); | |
43b0ac53 | 896 | |
f01b7962 VS |
897 | if (!intel_PLL_is_valid(dev, limit, |
898 | &clock)) | |
43b0ac53 VS |
899 | continue; |
900 | ||
d5dd62bd ID |
901 | if (!vlv_PLL_is_optimal(dev, target, |
902 | &clock, | |
903 | best_clock, | |
904 | bestppm, &ppm)) | |
905 | continue; | |
6b4bf1c4 | 906 | |
d5dd62bd ID |
907 | *best_clock = clock; |
908 | bestppm = ppm; | |
909 | found = true; | |
a0c4da24 JB |
910 | } |
911 | } | |
912 | } | |
913 | } | |
a0c4da24 | 914 | |
49e497ef | 915 | return found; |
a0c4da24 | 916 | } |
a4fc5ed6 | 917 | |
ef9348c8 | 918 | static bool |
a93e255f ACO |
919 | chv_find_best_dpll(const intel_limit_t *limit, |
920 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
921 | int target, int refclk, intel_clock_t *match_clock, |
922 | intel_clock_t *best_clock) | |
923 | { | |
a93e255f | 924 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 925 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 926 | unsigned int best_error_ppm; |
ef9348c8 CML |
927 | intel_clock_t clock; |
928 | uint64_t m2; | |
929 | int found = false; | |
930 | ||
931 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 932 | best_error_ppm = 1000000; |
ef9348c8 CML |
933 | |
934 | /* | |
935 | * Based on hardware doc, the n always set to 1, and m1 always | |
936 | * set to 2. If requires to support 200Mhz refclk, we need to | |
937 | * revisit this because n may not 1 anymore. | |
938 | */ | |
939 | clock.n = 1, clock.m1 = 2; | |
940 | target *= 5; /* fast clock */ | |
941 | ||
942 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
943 | for (clock.p2 = limit->p2.p2_fast; | |
944 | clock.p2 >= limit->p2.p2_slow; | |
945 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 946 | unsigned int error_ppm; |
ef9348c8 CML |
947 | |
948 | clock.p = clock.p1 * clock.p2; | |
949 | ||
950 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
951 | clock.n) << 22, refclk * clock.m1); | |
952 | ||
953 | if (m2 > INT_MAX/clock.m1) | |
954 | continue; | |
955 | ||
956 | clock.m2 = m2; | |
957 | ||
958 | chv_clock(refclk, &clock); | |
959 | ||
960 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
961 | continue; | |
962 | ||
9ca3ba01 ID |
963 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
964 | best_error_ppm, &error_ppm)) | |
965 | continue; | |
966 | ||
967 | *best_clock = clock; | |
968 | best_error_ppm = error_ppm; | |
969 | found = true; | |
ef9348c8 CML |
970 | } |
971 | } | |
972 | ||
973 | return found; | |
974 | } | |
975 | ||
5ab7b0b7 ID |
976 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
977 | intel_clock_t *best_clock) | |
978 | { | |
979 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
980 | ||
981 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
982 | target_clock, refclk, NULL, best_clock); | |
983 | } | |
984 | ||
20ddf665 VS |
985 | bool intel_crtc_active(struct drm_crtc *crtc) |
986 | { | |
987 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
988 | ||
989 | /* Be paranoid as we can arrive here with only partial | |
990 | * state retrieved from the hardware during setup. | |
991 | * | |
241bfc38 | 992 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
993 | * as Haswell has gained clock readout/fastboot support. |
994 | * | |
66e514c1 | 995 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 996 | * properly reconstruct framebuffers. |
c3d1f436 MR |
997 | * |
998 | * FIXME: The intel_crtc->active here should be switched to | |
999 | * crtc->state->active once we have proper CRTC states wired up | |
1000 | * for atomic. | |
20ddf665 | 1001 | */ |
c3d1f436 | 1002 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1003 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1004 | } |
1005 | ||
a5c961d1 PZ |
1006 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1007 | enum pipe pipe) | |
1008 | { | |
1009 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1010 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1011 | ||
6e3c9717 | 1012 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1013 | } |
1014 | ||
fbf49ea2 VS |
1015 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1016 | { | |
1017 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1018 | u32 reg = PIPEDSL(pipe); | |
1019 | u32 line1, line2; | |
1020 | u32 line_mask; | |
1021 | ||
1022 | if (IS_GEN2(dev)) | |
1023 | line_mask = DSL_LINEMASK_GEN2; | |
1024 | else | |
1025 | line_mask = DSL_LINEMASK_GEN3; | |
1026 | ||
1027 | line1 = I915_READ(reg) & line_mask; | |
1028 | mdelay(5); | |
1029 | line2 = I915_READ(reg) & line_mask; | |
1030 | ||
1031 | return line1 == line2; | |
1032 | } | |
1033 | ||
ab7ad7f6 KP |
1034 | /* |
1035 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1036 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1037 | * |
1038 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1039 | * spinning on the vblank interrupt status bit, since we won't actually | |
1040 | * see an interrupt when the pipe is disabled. | |
1041 | * | |
ab7ad7f6 KP |
1042 | * On Gen4 and above: |
1043 | * wait for the pipe register state bit to turn off | |
1044 | * | |
1045 | * Otherwise: | |
1046 | * wait for the display line value to settle (it usually | |
1047 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1048 | * |
9d0498a2 | 1049 | */ |
575f7ab7 | 1050 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1051 | { |
575f7ab7 | 1052 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1053 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1054 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1055 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1056 | |
1057 | if (INTEL_INFO(dev)->gen >= 4) { | |
702e7a56 | 1058 | int reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1059 | |
1060 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1061 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1062 | 100)) | |
284637d9 | 1063 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1064 | } else { |
ab7ad7f6 | 1065 | /* Wait for the display line to settle */ |
fbf49ea2 | 1066 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1067 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1068 | } |
79e53945 JB |
1069 | } |
1070 | ||
b0ea7d37 DL |
1071 | /* |
1072 | * ibx_digital_port_connected - is the specified port connected? | |
1073 | * @dev_priv: i915 private structure | |
1074 | * @port: the port to test | |
1075 | * | |
1076 | * Returns true if @port is connected, false otherwise. | |
1077 | */ | |
1078 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, | |
1079 | struct intel_digital_port *port) | |
1080 | { | |
1081 | u32 bit; | |
1082 | ||
c36346e3 | 1083 | if (HAS_PCH_IBX(dev_priv->dev)) { |
eba905b2 | 1084 | switch (port->port) { |
c36346e3 DL |
1085 | case PORT_B: |
1086 | bit = SDE_PORTB_HOTPLUG; | |
1087 | break; | |
1088 | case PORT_C: | |
1089 | bit = SDE_PORTC_HOTPLUG; | |
1090 | break; | |
1091 | case PORT_D: | |
1092 | bit = SDE_PORTD_HOTPLUG; | |
1093 | break; | |
1094 | default: | |
1095 | return true; | |
1096 | } | |
1097 | } else { | |
eba905b2 | 1098 | switch (port->port) { |
c36346e3 DL |
1099 | case PORT_B: |
1100 | bit = SDE_PORTB_HOTPLUG_CPT; | |
1101 | break; | |
1102 | case PORT_C: | |
1103 | bit = SDE_PORTC_HOTPLUG_CPT; | |
1104 | break; | |
1105 | case PORT_D: | |
1106 | bit = SDE_PORTD_HOTPLUG_CPT; | |
1107 | break; | |
1108 | default: | |
1109 | return true; | |
1110 | } | |
b0ea7d37 DL |
1111 | } |
1112 | ||
1113 | return I915_READ(SDEISR) & bit; | |
1114 | } | |
1115 | ||
b24e7179 JB |
1116 | static const char *state_string(bool enabled) |
1117 | { | |
1118 | return enabled ? "on" : "off"; | |
1119 | } | |
1120 | ||
1121 | /* Only for pre-ILK configs */ | |
55607e8a DV |
1122 | void assert_pll(struct drm_i915_private *dev_priv, |
1123 | enum pipe pipe, bool state) | |
b24e7179 JB |
1124 | { |
1125 | int reg; | |
1126 | u32 val; | |
1127 | bool cur_state; | |
1128 | ||
1129 | reg = DPLL(pipe); | |
1130 | val = I915_READ(reg); | |
1131 | cur_state = !!(val & DPLL_VCO_ENABLE); | |
e2c719b7 | 1132 | I915_STATE_WARN(cur_state != state, |
b24e7179 JB |
1133 | "PLL state assertion failure (expected %s, current %s)\n", |
1134 | state_string(state), state_string(cur_state)); | |
1135 | } | |
b24e7179 | 1136 | |
23538ef1 JN |
1137 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1138 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1139 | { | |
1140 | u32 val; | |
1141 | bool cur_state; | |
1142 | ||
1143 | mutex_lock(&dev_priv->dpio_lock); | |
1144 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); | |
1145 | mutex_unlock(&dev_priv->dpio_lock); | |
1146 | ||
1147 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1148 | I915_STATE_WARN(cur_state != state, |
23538ef1 JN |
1149 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
1150 | state_string(state), state_string(cur_state)); | |
1151 | } | |
1152 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1153 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1154 | ||
55607e8a | 1155 | struct intel_shared_dpll * |
e2b78267 DV |
1156 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1157 | { | |
1158 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1159 | ||
6e3c9717 | 1160 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1161 | return NULL; |
1162 | ||
6e3c9717 | 1163 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1164 | } |
1165 | ||
040484af | 1166 | /* For ILK+ */ |
55607e8a DV |
1167 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1168 | struct intel_shared_dpll *pll, | |
1169 | bool state) | |
040484af | 1170 | { |
040484af | 1171 | bool cur_state; |
5358901f | 1172 | struct intel_dpll_hw_state hw_state; |
040484af | 1173 | |
92b27b08 | 1174 | if (WARN (!pll, |
46edb027 | 1175 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
ee7b9f93 | 1176 | return; |
ee7b9f93 | 1177 | |
5358901f | 1178 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1179 | I915_STATE_WARN(cur_state != state, |
5358901f DV |
1180 | "%s assertion failure (expected %s, current %s)\n", |
1181 | pll->name, state_string(state), state_string(cur_state)); | |
040484af | 1182 | } |
040484af JB |
1183 | |
1184 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1185 | enum pipe pipe, bool state) | |
1186 | { | |
1187 | int reg; | |
1188 | u32 val; | |
1189 | bool cur_state; | |
ad80a810 PZ |
1190 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1191 | pipe); | |
040484af | 1192 | |
affa9354 PZ |
1193 | if (HAS_DDI(dev_priv->dev)) { |
1194 | /* DDI does not have a specific FDI_TX register */ | |
ad80a810 | 1195 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
bf507ef7 | 1196 | val = I915_READ(reg); |
ad80a810 | 1197 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 ED |
1198 | } else { |
1199 | reg = FDI_TX_CTL(pipe); | |
1200 | val = I915_READ(reg); | |
1201 | cur_state = !!(val & FDI_TX_ENABLE); | |
1202 | } | |
e2c719b7 | 1203 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1204 | "FDI TX state assertion failure (expected %s, current %s)\n", |
1205 | state_string(state), state_string(cur_state)); | |
1206 | } | |
1207 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1208 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1209 | ||
1210 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1211 | enum pipe pipe, bool state) | |
1212 | { | |
1213 | int reg; | |
1214 | u32 val; | |
1215 | bool cur_state; | |
1216 | ||
d63fa0dc PZ |
1217 | reg = FDI_RX_CTL(pipe); |
1218 | val = I915_READ(reg); | |
1219 | cur_state = !!(val & FDI_RX_ENABLE); | |
e2c719b7 | 1220 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1221 | "FDI RX state assertion failure (expected %s, current %s)\n", |
1222 | state_string(state), state_string(cur_state)); | |
1223 | } | |
1224 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1225 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1226 | ||
1227 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1228 | enum pipe pipe) | |
1229 | { | |
1230 | int reg; | |
1231 | u32 val; | |
1232 | ||
1233 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1234 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1235 | return; |
1236 | ||
bf507ef7 | 1237 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1238 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1239 | return; |
1240 | ||
040484af JB |
1241 | reg = FDI_TX_CTL(pipe); |
1242 | val = I915_READ(reg); | |
e2c719b7 | 1243 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1244 | } |
1245 | ||
55607e8a DV |
1246 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1247 | enum pipe pipe, bool state) | |
040484af JB |
1248 | { |
1249 | int reg; | |
1250 | u32 val; | |
55607e8a | 1251 | bool cur_state; |
040484af JB |
1252 | |
1253 | reg = FDI_RX_CTL(pipe); | |
1254 | val = I915_READ(reg); | |
55607e8a | 1255 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1256 | I915_STATE_WARN(cur_state != state, |
55607e8a DV |
1257 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
1258 | state_string(state), state_string(cur_state)); | |
040484af JB |
1259 | } |
1260 | ||
b680c37a DV |
1261 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1262 | enum pipe pipe) | |
ea0760cf | 1263 | { |
bedd4dba JN |
1264 | struct drm_device *dev = dev_priv->dev; |
1265 | int pp_reg; | |
ea0760cf JB |
1266 | u32 val; |
1267 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1268 | bool locked = true; |
ea0760cf | 1269 | |
bedd4dba JN |
1270 | if (WARN_ON(HAS_DDI(dev))) |
1271 | return; | |
1272 | ||
1273 | if (HAS_PCH_SPLIT(dev)) { | |
1274 | u32 port_sel; | |
1275 | ||
ea0760cf | 1276 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1277 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1278 | ||
1279 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1280 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1281 | panel_pipe = PIPE_B; | |
1282 | /* XXX: else fix for eDP */ | |
1283 | } else if (IS_VALLEYVIEW(dev)) { | |
1284 | /* presumably write lock depends on pipe, not port select */ | |
1285 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1286 | panel_pipe = pipe; | |
ea0760cf JB |
1287 | } else { |
1288 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1289 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1290 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1291 | } |
1292 | ||
1293 | val = I915_READ(pp_reg); | |
1294 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1295 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1296 | locked = false; |
1297 | ||
e2c719b7 | 1298 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1299 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1300 | pipe_name(pipe)); |
ea0760cf JB |
1301 | } |
1302 | ||
93ce0ba6 JN |
1303 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1304 | enum pipe pipe, bool state) | |
1305 | { | |
1306 | struct drm_device *dev = dev_priv->dev; | |
1307 | bool cur_state; | |
1308 | ||
d9d82081 | 1309 | if (IS_845G(dev) || IS_I865G(dev)) |
93ce0ba6 | 1310 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
d9d82081 | 1311 | else |
5efb3e28 | 1312 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1313 | |
e2c719b7 | 1314 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 JN |
1315 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
1316 | pipe_name(pipe), state_string(state), state_string(cur_state)); | |
1317 | } | |
1318 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1319 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1320 | ||
b840d907 JB |
1321 | void assert_pipe(struct drm_i915_private *dev_priv, |
1322 | enum pipe pipe, bool state) | |
b24e7179 JB |
1323 | { |
1324 | int reg; | |
1325 | u32 val; | |
63d7bbe9 | 1326 | bool cur_state; |
702e7a56 PZ |
1327 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1328 | pipe); | |
b24e7179 | 1329 | |
b6b5d049 VS |
1330 | /* if we need the pipe quirk it must be always on */ |
1331 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1332 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1333 | state = true; |
1334 | ||
f458ebbc | 1335 | if (!intel_display_power_is_enabled(dev_priv, |
b97186f0 | 1336 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
69310161 PZ |
1337 | cur_state = false; |
1338 | } else { | |
1339 | reg = PIPECONF(cpu_transcoder); | |
1340 | val = I915_READ(reg); | |
1341 | cur_state = !!(val & PIPECONF_ENABLE); | |
1342 | } | |
1343 | ||
e2c719b7 | 1344 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1345 | "pipe %c assertion failure (expected %s, current %s)\n", |
9db4a9c7 | 1346 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
b24e7179 JB |
1347 | } |
1348 | ||
931872fc CW |
1349 | static void assert_plane(struct drm_i915_private *dev_priv, |
1350 | enum plane plane, bool state) | |
b24e7179 JB |
1351 | { |
1352 | int reg; | |
1353 | u32 val; | |
931872fc | 1354 | bool cur_state; |
b24e7179 JB |
1355 | |
1356 | reg = DSPCNTR(plane); | |
1357 | val = I915_READ(reg); | |
931872fc | 1358 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1359 | I915_STATE_WARN(cur_state != state, |
931872fc CW |
1360 | "plane %c assertion failure (expected %s, current %s)\n", |
1361 | plane_name(plane), state_string(state), state_string(cur_state)); | |
b24e7179 JB |
1362 | } |
1363 | ||
931872fc CW |
1364 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1365 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1366 | ||
b24e7179 JB |
1367 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1368 | enum pipe pipe) | |
1369 | { | |
653e1026 | 1370 | struct drm_device *dev = dev_priv->dev; |
b24e7179 JB |
1371 | int reg, i; |
1372 | u32 val; | |
1373 | int cur_pipe; | |
1374 | ||
653e1026 VS |
1375 | /* Primary planes are fixed to pipes on gen4+ */ |
1376 | if (INTEL_INFO(dev)->gen >= 4) { | |
28c05794 AJ |
1377 | reg = DSPCNTR(pipe); |
1378 | val = I915_READ(reg); | |
e2c719b7 | 1379 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1380 | "plane %c assertion failure, should be disabled but not\n", |
1381 | plane_name(pipe)); | |
19ec1358 | 1382 | return; |
28c05794 | 1383 | } |
19ec1358 | 1384 | |
b24e7179 | 1385 | /* Need to check both planes against the pipe */ |
055e393f | 1386 | for_each_pipe(dev_priv, i) { |
b24e7179 JB |
1387 | reg = DSPCNTR(i); |
1388 | val = I915_READ(reg); | |
1389 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
1390 | DISPPLANE_SEL_PIPE_SHIFT; | |
e2c719b7 | 1391 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1392 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1393 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1394 | } |
1395 | } | |
1396 | ||
19332d7a JB |
1397 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1398 | enum pipe pipe) | |
1399 | { | |
20674eef | 1400 | struct drm_device *dev = dev_priv->dev; |
1fe47785 | 1401 | int reg, sprite; |
19332d7a JB |
1402 | u32 val; |
1403 | ||
7feb8b88 | 1404 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1405 | for_each_sprite(dev_priv, pipe, sprite) { |
7feb8b88 | 1406 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1407 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1408 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1409 | sprite, pipe_name(pipe)); | |
1410 | } | |
1411 | } else if (IS_VALLEYVIEW(dev)) { | |
3bdcfc0c | 1412 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 1413 | reg = SPCNTR(pipe, sprite); |
20674eef | 1414 | val = I915_READ(reg); |
e2c719b7 | 1415 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1416 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1417 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1418 | } |
1419 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
1420 | reg = SPRCTL(pipe); | |
19332d7a | 1421 | val = I915_READ(reg); |
e2c719b7 | 1422 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1423 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1424 | plane_name(pipe), pipe_name(pipe)); |
1425 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
1426 | reg = DVSCNTR(pipe); | |
19332d7a | 1427 | val = I915_READ(reg); |
e2c719b7 | 1428 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1429 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1430 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1431 | } |
1432 | } | |
1433 | ||
08c71e5e VS |
1434 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1435 | { | |
e2c719b7 | 1436 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1437 | drm_crtc_vblank_put(crtc); |
1438 | } | |
1439 | ||
89eff4be | 1440 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1441 | { |
1442 | u32 val; | |
1443 | bool enabled; | |
1444 | ||
e2c719b7 | 1445 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1446 | |
92f2584a JB |
1447 | val = I915_READ(PCH_DREF_CONTROL); |
1448 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1449 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1450 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1451 | } |
1452 | ||
ab9412ba DV |
1453 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1454 | enum pipe pipe) | |
92f2584a JB |
1455 | { |
1456 | int reg; | |
1457 | u32 val; | |
1458 | bool enabled; | |
1459 | ||
ab9412ba | 1460 | reg = PCH_TRANSCONF(pipe); |
92f2584a JB |
1461 | val = I915_READ(reg); |
1462 | enabled = !!(val & TRANS_ENABLE); | |
e2c719b7 | 1463 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1464 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1465 | pipe_name(pipe)); | |
92f2584a JB |
1466 | } |
1467 | ||
4e634389 KP |
1468 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1469 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1470 | { |
1471 | if ((val & DP_PORT_EN) == 0) | |
1472 | return false; | |
1473 | ||
1474 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1475 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); | |
1476 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); | |
1477 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1478 | return false; | |
44f37d1f CML |
1479 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1480 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1481 | return false; | |
f0575e92 KP |
1482 | } else { |
1483 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1484 | return false; | |
1485 | } | |
1486 | return true; | |
1487 | } | |
1488 | ||
1519b995 KP |
1489 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1490 | enum pipe pipe, u32 val) | |
1491 | { | |
dc0fa718 | 1492 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1493 | return false; |
1494 | ||
1495 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1496 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1497 | return false; |
44f37d1f CML |
1498 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1499 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1500 | return false; | |
1519b995 | 1501 | } else { |
dc0fa718 | 1502 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1503 | return false; |
1504 | } | |
1505 | return true; | |
1506 | } | |
1507 | ||
1508 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1509 | enum pipe pipe, u32 val) | |
1510 | { | |
1511 | if ((val & LVDS_PORT_EN) == 0) | |
1512 | return false; | |
1513 | ||
1514 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1515 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1516 | return false; | |
1517 | } else { | |
1518 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1519 | return false; | |
1520 | } | |
1521 | return true; | |
1522 | } | |
1523 | ||
1524 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1525 | enum pipe pipe, u32 val) | |
1526 | { | |
1527 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1528 | return false; | |
1529 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1530 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1531 | return false; | |
1532 | } else { | |
1533 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1534 | return false; | |
1535 | } | |
1536 | return true; | |
1537 | } | |
1538 | ||
291906f1 | 1539 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0575e92 | 1540 | enum pipe pipe, int reg, u32 port_sel) |
291906f1 | 1541 | { |
47a05eca | 1542 | u32 val = I915_READ(reg); |
e2c719b7 | 1543 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1544 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1545 | reg, pipe_name(pipe)); |
de9a35ab | 1546 | |
e2c719b7 | 1547 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1548 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1549 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1550 | } |
1551 | ||
1552 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1553 | enum pipe pipe, int reg) | |
1554 | { | |
47a05eca | 1555 | u32 val = I915_READ(reg); |
e2c719b7 | 1556 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1557 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1558 | reg, pipe_name(pipe)); |
de9a35ab | 1559 | |
e2c719b7 | 1560 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1561 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1562 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1563 | } |
1564 | ||
1565 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1566 | enum pipe pipe) | |
1567 | { | |
1568 | int reg; | |
1569 | u32 val; | |
291906f1 | 1570 | |
f0575e92 KP |
1571 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1572 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1573 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 JB |
1574 | |
1575 | reg = PCH_ADPA; | |
1576 | val = I915_READ(reg); | |
e2c719b7 | 1577 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1578 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1579 | pipe_name(pipe)); |
291906f1 JB |
1580 | |
1581 | reg = PCH_LVDS; | |
1582 | val = I915_READ(reg); | |
e2c719b7 | 1583 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1584 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1585 | pipe_name(pipe)); |
291906f1 | 1586 | |
e2debe91 PZ |
1587 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1588 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1589 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1590 | } |
1591 | ||
40e9cf64 JB |
1592 | static void intel_init_dpio(struct drm_device *dev) |
1593 | { | |
1594 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1595 | ||
1596 | if (!IS_VALLEYVIEW(dev)) | |
1597 | return; | |
1598 | ||
a09caddd CML |
1599 | /* |
1600 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), | |
1601 | * CHV x1 PHY (DP/HDMI D) | |
1602 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) | |
1603 | */ | |
1604 | if (IS_CHERRYVIEW(dev)) { | |
1605 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; | |
1606 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; | |
1607 | } else { | |
1608 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; | |
1609 | } | |
5382f5f3 JB |
1610 | } |
1611 | ||
d288f65f | 1612 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1613 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1614 | { |
426115cf DV |
1615 | struct drm_device *dev = crtc->base.dev; |
1616 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1617 | int reg = DPLL(crtc->pipe); | |
d288f65f | 1618 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1619 | |
426115cf | 1620 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 DV |
1621 | |
1622 | /* No really, not for ILK+ */ | |
1623 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); | |
1624 | ||
1625 | /* PLL is protected by panel, make sure we can write it */ | |
6a9e7363 | 1626 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1627 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1628 | |
426115cf DV |
1629 | I915_WRITE(reg, dpll); |
1630 | POSTING_READ(reg); | |
1631 | udelay(150); | |
1632 | ||
1633 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1634 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1635 | ||
d288f65f | 1636 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1637 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1638 | |
1639 | /* We do this three times for luck */ | |
426115cf | 1640 | I915_WRITE(reg, dpll); |
87442f73 DV |
1641 | POSTING_READ(reg); |
1642 | udelay(150); /* wait for warmup */ | |
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 */ | |
1649 | } | |
1650 | ||
d288f65f | 1651 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1652 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1653 | { |
1654 | struct drm_device *dev = crtc->base.dev; | |
1655 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1656 | int pipe = crtc->pipe; | |
1657 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1658 | u32 tmp; |
1659 | ||
1660 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1661 | ||
1662 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); | |
1663 | ||
1664 | mutex_lock(&dev_priv->dpio_lock); | |
1665 | ||
1666 | /* Enable back the 10bit clock to display controller */ | |
1667 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1668 | tmp |= DPIO_DCLKP_EN; | |
1669 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1670 | ||
1671 | /* | |
1672 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1673 | */ | |
1674 | udelay(1); | |
1675 | ||
1676 | /* Enable PLL */ | |
d288f65f | 1677 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1678 | |
1679 | /* Check PLL is locked */ | |
a11b0703 | 1680 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1681 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1682 | ||
a11b0703 | 1683 | /* not sure when this should be written */ |
d288f65f | 1684 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 VS |
1685 | POSTING_READ(DPLL_MD(pipe)); |
1686 | ||
9d556c99 CML |
1687 | mutex_unlock(&dev_priv->dpio_lock); |
1688 | } | |
1689 | ||
1c4e0274 VS |
1690 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1691 | { | |
1692 | struct intel_crtc *crtc; | |
1693 | int count = 0; | |
1694 | ||
1695 | for_each_intel_crtc(dev, crtc) | |
1696 | count += crtc->active && | |
409ee761 | 1697 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1698 | |
1699 | return count; | |
1700 | } | |
1701 | ||
66e3d5c0 | 1702 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1703 | { |
66e3d5c0 DV |
1704 | struct drm_device *dev = crtc->base.dev; |
1705 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1706 | int reg = DPLL(crtc->pipe); | |
6e3c9717 | 1707 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1708 | |
66e3d5c0 | 1709 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1710 | |
63d7bbe9 | 1711 | /* No really, not for ILK+ */ |
3d13ef2e | 1712 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1713 | |
1714 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1715 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1716 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1717 | |
1c4e0274 VS |
1718 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1719 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1720 | /* | |
1721 | * It appears to be important that we don't enable this | |
1722 | * for the current pipe before otherwise configuring the | |
1723 | * PLL. No idea how this should be handled if multiple | |
1724 | * DVO outputs are enabled simultaneosly. | |
1725 | */ | |
1726 | dpll |= DPLL_DVO_2X_MODE; | |
1727 | I915_WRITE(DPLL(!crtc->pipe), | |
1728 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1729 | } | |
66e3d5c0 DV |
1730 | |
1731 | /* Wait for the clocks to stabilize. */ | |
1732 | POSTING_READ(reg); | |
1733 | udelay(150); | |
1734 | ||
1735 | if (INTEL_INFO(dev)->gen >= 4) { | |
1736 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1737 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1738 | } else { |
1739 | /* The pixel multiplier can only be updated once the | |
1740 | * DPLL is enabled and the clocks are stable. | |
1741 | * | |
1742 | * So write it again. | |
1743 | */ | |
1744 | I915_WRITE(reg, dpll); | |
1745 | } | |
63d7bbe9 JB |
1746 | |
1747 | /* We do this three times for luck */ | |
66e3d5c0 | 1748 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1749 | POSTING_READ(reg); |
1750 | udelay(150); /* wait for warmup */ | |
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 */ | |
1757 | } | |
1758 | ||
1759 | /** | |
50b44a44 | 1760 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1761 | * @dev_priv: i915 private structure |
1762 | * @pipe: pipe PLL to disable | |
1763 | * | |
1764 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1765 | * | |
1766 | * Note! This is for pre-ILK only. | |
1767 | */ | |
1c4e0274 | 1768 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1769 | { |
1c4e0274 VS |
1770 | struct drm_device *dev = crtc->base.dev; |
1771 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1772 | enum pipe pipe = crtc->pipe; | |
1773 | ||
1774 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1775 | if (IS_I830(dev) && | |
409ee761 | 1776 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
1c4e0274 VS |
1777 | intel_num_dvo_pipes(dev) == 1) { |
1778 | I915_WRITE(DPLL(PIPE_B), | |
1779 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1780 | I915_WRITE(DPLL(PIPE_A), | |
1781 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1782 | } | |
1783 | ||
b6b5d049 VS |
1784 | /* Don't disable pipe or pipe PLLs if needed */ |
1785 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1786 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1787 | return; |
1788 | ||
1789 | /* Make sure the pipe isn't still relying on us */ | |
1790 | assert_pipe_disabled(dev_priv, pipe); | |
1791 | ||
50b44a44 DV |
1792 | I915_WRITE(DPLL(pipe), 0); |
1793 | POSTING_READ(DPLL(pipe)); | |
63d7bbe9 JB |
1794 | } |
1795 | ||
f6071166 JB |
1796 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1797 | { | |
1798 | u32 val = 0; | |
1799 | ||
1800 | /* Make sure the pipe isn't still relying on us */ | |
1801 | assert_pipe_disabled(dev_priv, pipe); | |
1802 | ||
e5cbfbfb ID |
1803 | /* |
1804 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1805 | * The latter is needed for VGA hotplug / manual detection. | |
1806 | */ | |
f6071166 | 1807 | if (pipe == PIPE_B) |
e5cbfbfb | 1808 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
f6071166 JB |
1809 | I915_WRITE(DPLL(pipe), val); |
1810 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1811 | |
1812 | } | |
1813 | ||
1814 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1815 | { | |
d752048d | 1816 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1817 | u32 val; |
1818 | ||
a11b0703 VS |
1819 | /* Make sure the pipe isn't still relying on us */ |
1820 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1821 | |
a11b0703 | 1822 | /* Set PLL en = 0 */ |
d17ec4ce | 1823 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
a11b0703 VS |
1824 | if (pipe != PIPE_A) |
1825 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1826 | I915_WRITE(DPLL(pipe), val); | |
1827 | POSTING_READ(DPLL(pipe)); | |
d752048d VS |
1828 | |
1829 | mutex_lock(&dev_priv->dpio_lock); | |
1830 | ||
1831 | /* Disable 10bit clock to display controller */ | |
1832 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1833 | val &= ~DPIO_DCLKP_EN; | |
1834 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1835 | ||
61407f6d VS |
1836 | /* disable left/right clock distribution */ |
1837 | if (pipe != PIPE_B) { | |
1838 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); | |
1839 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); | |
1840 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); | |
1841 | } else { | |
1842 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); | |
1843 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); | |
1844 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); | |
1845 | } | |
1846 | ||
d752048d | 1847 | mutex_unlock(&dev_priv->dpio_lock); |
f6071166 JB |
1848 | } |
1849 | ||
e4607fcf | 1850 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1851 | struct intel_digital_port *dport, |
1852 | unsigned int expected_mask) | |
89b667f8 JB |
1853 | { |
1854 | u32 port_mask; | |
00fc31b7 | 1855 | int dpll_reg; |
89b667f8 | 1856 | |
e4607fcf CML |
1857 | switch (dport->port) { |
1858 | case PORT_B: | |
89b667f8 | 1859 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1860 | dpll_reg = DPLL(0); |
e4607fcf CML |
1861 | break; |
1862 | case PORT_C: | |
89b667f8 | 1863 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1864 | dpll_reg = DPLL(0); |
9b6de0a1 | 1865 | expected_mask <<= 4; |
00fc31b7 CML |
1866 | break; |
1867 | case PORT_D: | |
1868 | port_mask = DPLL_PORTD_READY_MASK; | |
1869 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1870 | break; |
1871 | default: | |
1872 | BUG(); | |
1873 | } | |
89b667f8 | 1874 | |
9b6de0a1 VS |
1875 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1876 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1877 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1878 | } |
1879 | ||
b14b1055 DV |
1880 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1881 | { | |
1882 | struct drm_device *dev = crtc->base.dev; | |
1883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1884 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1885 | ||
be19f0ff CW |
1886 | if (WARN_ON(pll == NULL)) |
1887 | return; | |
1888 | ||
3e369b76 | 1889 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1890 | if (pll->active == 0) { |
1891 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1892 | WARN_ON(pll->on); | |
1893 | assert_shared_dpll_disabled(dev_priv, pll); | |
1894 | ||
1895 | pll->mode_set(dev_priv, pll); | |
1896 | } | |
1897 | } | |
1898 | ||
92f2584a | 1899 | /** |
85b3894f | 1900 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1901 | * @dev_priv: i915 private structure |
1902 | * @pipe: pipe PLL to enable | |
1903 | * | |
1904 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1905 | * drives the transcoder clock. | |
1906 | */ | |
85b3894f | 1907 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1908 | { |
3d13ef2e DL |
1909 | struct drm_device *dev = crtc->base.dev; |
1910 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1911 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1912 | |
87a875bb | 1913 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1914 | return; |
1915 | ||
3e369b76 | 1916 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1917 | return; |
ee7b9f93 | 1918 | |
74dd6928 | 1919 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1920 | pll->name, pll->active, pll->on, |
e2b78267 | 1921 | crtc->base.base.id); |
92f2584a | 1922 | |
cdbd2316 DV |
1923 | if (pll->active++) { |
1924 | WARN_ON(!pll->on); | |
e9d6944e | 1925 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1926 | return; |
1927 | } | |
f4a091c7 | 1928 | WARN_ON(pll->on); |
ee7b9f93 | 1929 | |
bd2bb1b9 PZ |
1930 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1931 | ||
46edb027 | 1932 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1933 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1934 | pll->on = true; |
92f2584a JB |
1935 | } |
1936 | ||
f6daaec2 | 1937 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1938 | { |
3d13ef2e DL |
1939 | struct drm_device *dev = crtc->base.dev; |
1940 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1941 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1942 | |
92f2584a | 1943 | /* PCH only available on ILK+ */ |
3d13ef2e | 1944 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
87a875bb | 1945 | if (WARN_ON(pll == NULL)) |
ee7b9f93 | 1946 | return; |
92f2584a | 1947 | |
3e369b76 | 1948 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1949 | return; |
7a419866 | 1950 | |
46edb027 DV |
1951 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1952 | pll->name, pll->active, pll->on, | |
e2b78267 | 1953 | crtc->base.base.id); |
7a419866 | 1954 | |
48da64a8 | 1955 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1956 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1957 | return; |
1958 | } | |
1959 | ||
e9d6944e | 1960 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1961 | WARN_ON(!pll->on); |
cdbd2316 | 1962 | if (--pll->active) |
7a419866 | 1963 | return; |
ee7b9f93 | 1964 | |
46edb027 | 1965 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1966 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1967 | pll->on = false; |
bd2bb1b9 PZ |
1968 | |
1969 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1970 | } |
1971 | ||
b8a4f404 PZ |
1972 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1973 | enum pipe pipe) | |
040484af | 1974 | { |
23670b32 | 1975 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1976 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1977 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
23670b32 | 1978 | uint32_t reg, val, pipeconf_val; |
040484af JB |
1979 | |
1980 | /* PCH only available on ILK+ */ | |
55522f37 | 1981 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1982 | |
1983 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1984 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1985 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1986 | |
1987 | /* FDI must be feeding us bits for PCH ports */ | |
1988 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1989 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1990 | ||
23670b32 DV |
1991 | if (HAS_PCH_CPT(dev)) { |
1992 | /* Workaround: Set the timing override bit before enabling the | |
1993 | * pch transcoder. */ | |
1994 | reg = TRANS_CHICKEN2(pipe); | |
1995 | val = I915_READ(reg); | |
1996 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1997 | I915_WRITE(reg, val); | |
59c859d6 | 1998 | } |
23670b32 | 1999 | |
ab9412ba | 2000 | reg = PCH_TRANSCONF(pipe); |
040484af | 2001 | val = I915_READ(reg); |
5f7f726d | 2002 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
2003 | |
2004 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
2005 | /* | |
2006 | * make the BPC in transcoder be consistent with | |
2007 | * that in pipeconf reg. | |
2008 | */ | |
dfd07d72 DV |
2009 | val &= ~PIPECONF_BPC_MASK; |
2010 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 2011 | } |
5f7f726d PZ |
2012 | |
2013 | val &= ~TRANS_INTERLACE_MASK; | |
2014 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 2015 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 2016 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
2017 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2018 | else | |
2019 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2020 | else |
2021 | val |= TRANS_PROGRESSIVE; | |
2022 | ||
040484af JB |
2023 | I915_WRITE(reg, val | TRANS_ENABLE); |
2024 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2025 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2026 | } |
2027 | ||
8fb033d7 | 2028 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2029 | enum transcoder cpu_transcoder) |
040484af | 2030 | { |
8fb033d7 | 2031 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2032 | |
2033 | /* PCH only available on ILK+ */ | |
55522f37 | 2034 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2035 | |
8fb033d7 | 2036 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2037 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2038 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2039 | |
223a6fdf PZ |
2040 | /* Workaround: set timing override bit. */ |
2041 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2042 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf PZ |
2043 | I915_WRITE(_TRANSA_CHICKEN2, val); |
2044 | ||
25f3ef11 | 2045 | val = TRANS_ENABLE; |
937bb610 | 2046 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2047 | |
9a76b1c6 PZ |
2048 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2049 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2050 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2051 | else |
2052 | val |= TRANS_PROGRESSIVE; | |
2053 | ||
ab9412ba DV |
2054 | I915_WRITE(LPT_TRANSCONF, val); |
2055 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2056 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2057 | } |
2058 | ||
b8a4f404 PZ |
2059 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2060 | enum pipe pipe) | |
040484af | 2061 | { |
23670b32 DV |
2062 | struct drm_device *dev = dev_priv->dev; |
2063 | uint32_t reg, val; | |
040484af JB |
2064 | |
2065 | /* FDI relies on the transcoder */ | |
2066 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2067 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2068 | ||
291906f1 JB |
2069 | /* Ports must be off as well */ |
2070 | assert_pch_ports_disabled(dev_priv, pipe); | |
2071 | ||
ab9412ba | 2072 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2073 | val = I915_READ(reg); |
2074 | val &= ~TRANS_ENABLE; | |
2075 | I915_WRITE(reg, val); | |
2076 | /* wait for PCH transcoder off, transcoder state */ | |
2077 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2078 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 DV |
2079 | |
2080 | if (!HAS_PCH_IBX(dev)) { | |
2081 | /* Workaround: Clear the timing override chicken bit again. */ | |
2082 | reg = TRANS_CHICKEN2(pipe); | |
2083 | val = I915_READ(reg); | |
2084 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2085 | I915_WRITE(reg, val); | |
2086 | } | |
040484af JB |
2087 | } |
2088 | ||
ab4d966c | 2089 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2090 | { |
8fb033d7 PZ |
2091 | u32 val; |
2092 | ||
ab9412ba | 2093 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2094 | val &= ~TRANS_ENABLE; |
ab9412ba | 2095 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2096 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2097 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2098 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2099 | |
2100 | /* Workaround: clear timing override bit. */ | |
2101 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2102 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf | 2103 | I915_WRITE(_TRANSA_CHICKEN2, val); |
040484af JB |
2104 | } |
2105 | ||
b24e7179 | 2106 | /** |
309cfea8 | 2107 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2108 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2109 | * |
0372264a | 2110 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2111 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2112 | */ |
e1fdc473 | 2113 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2114 | { |
0372264a PZ |
2115 | struct drm_device *dev = crtc->base.dev; |
2116 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2117 | enum pipe pipe = crtc->pipe; | |
702e7a56 PZ |
2118 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
2119 | pipe); | |
1a240d4d | 2120 | enum pipe pch_transcoder; |
b24e7179 JB |
2121 | int reg; |
2122 | u32 val; | |
2123 | ||
58c6eaa2 | 2124 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2125 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2126 | assert_sprites_disabled(dev_priv, pipe); |
2127 | ||
681e5811 | 2128 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2129 | pch_transcoder = TRANSCODER_A; |
2130 | else | |
2131 | pch_transcoder = pipe; | |
2132 | ||
b24e7179 JB |
2133 | /* |
2134 | * A pipe without a PLL won't actually be able to drive bits from | |
2135 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2136 | * need the check. | |
2137 | */ | |
50360403 | 2138 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
409ee761 | 2139 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
2140 | assert_dsi_pll_enabled(dev_priv); |
2141 | else | |
2142 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2143 | else { |
6e3c9717 | 2144 | if (crtc->config->has_pch_encoder) { |
040484af | 2145 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2146 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2147 | assert_fdi_tx_pll_enabled(dev_priv, |
2148 | (enum pipe) cpu_transcoder); | |
040484af JB |
2149 | } |
2150 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2151 | } | |
b24e7179 | 2152 | |
702e7a56 | 2153 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2154 | val = I915_READ(reg); |
7ad25d48 | 2155 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2156 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2157 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2158 | return; |
7ad25d48 | 2159 | } |
00d70b15 CW |
2160 | |
2161 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2162 | POSTING_READ(reg); |
b24e7179 JB |
2163 | } |
2164 | ||
2165 | /** | |
309cfea8 | 2166 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2167 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2168 | * |
575f7ab7 VS |
2169 | * Disable the pipe of @crtc, making sure that various hardware |
2170 | * specific requirements are met, if applicable, e.g. plane | |
2171 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2172 | * |
2173 | * Will wait until the pipe has shut down before returning. | |
2174 | */ | |
575f7ab7 | 2175 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2176 | { |
575f7ab7 | 2177 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2178 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2179 | enum pipe pipe = crtc->pipe; |
b24e7179 JB |
2180 | int reg; |
2181 | u32 val; | |
2182 | ||
2183 | /* | |
2184 | * Make sure planes won't keep trying to pump pixels to us, | |
2185 | * or we might hang the display. | |
2186 | */ | |
2187 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2188 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2189 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2190 | |
702e7a56 | 2191 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2192 | val = I915_READ(reg); |
00d70b15 CW |
2193 | if ((val & PIPECONF_ENABLE) == 0) |
2194 | return; | |
2195 | ||
67adc644 VS |
2196 | /* |
2197 | * Double wide has implications for planes | |
2198 | * so best keep it disabled when not needed. | |
2199 | */ | |
6e3c9717 | 2200 | if (crtc->config->double_wide) |
67adc644 VS |
2201 | val &= ~PIPECONF_DOUBLE_WIDE; |
2202 | ||
2203 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2204 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2205 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2206 | val &= ~PIPECONF_ENABLE; |
2207 | ||
2208 | I915_WRITE(reg, val); | |
2209 | if ((val & PIPECONF_ENABLE) == 0) | |
2210 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2211 | } |
2212 | ||
d74362c9 KP |
2213 | /* |
2214 | * Plane regs are double buffered, going from enabled->disabled needs a | |
2215 | * trigger in order to latch. The display address reg provides this. | |
2216 | */ | |
1dba99f4 VS |
2217 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
2218 | enum plane plane) | |
d74362c9 | 2219 | { |
3d13ef2e DL |
2220 | struct drm_device *dev = dev_priv->dev; |
2221 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); | |
1dba99f4 VS |
2222 | |
2223 | I915_WRITE(reg, I915_READ(reg)); | |
2224 | POSTING_READ(reg); | |
d74362c9 KP |
2225 | } |
2226 | ||
b24e7179 | 2227 | /** |
262ca2b0 | 2228 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
fdd508a6 VS |
2229 | * @plane: plane to be enabled |
2230 | * @crtc: crtc for the plane | |
b24e7179 | 2231 | * |
fdd508a6 | 2232 | * Enable @plane on @crtc, making sure that the pipe is running first. |
b24e7179 | 2233 | */ |
fdd508a6 VS |
2234 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
2235 | struct drm_crtc *crtc) | |
b24e7179 | 2236 | { |
fdd508a6 VS |
2237 | struct drm_device *dev = plane->dev; |
2238 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2239 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b24e7179 JB |
2240 | |
2241 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ | |
fdd508a6 | 2242 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
b70709a6 | 2243 | to_intel_plane_state(plane->state)->visible = true; |
939c2fe8 | 2244 | |
fdd508a6 VS |
2245 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
2246 | crtc->x, crtc->y); | |
b24e7179 JB |
2247 | } |
2248 | ||
693db184 CW |
2249 | static bool need_vtd_wa(struct drm_device *dev) |
2250 | { | |
2251 | #ifdef CONFIG_INTEL_IOMMU | |
2252 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2253 | return true; | |
2254 | #endif | |
2255 | return false; | |
2256 | } | |
2257 | ||
50470bb0 | 2258 | unsigned int |
6761dd31 TU |
2259 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
2260 | uint64_t fb_format_modifier) | |
a57ce0b2 | 2261 | { |
6761dd31 TU |
2262 | unsigned int tile_height; |
2263 | uint32_t pixel_bytes; | |
a57ce0b2 | 2264 | |
b5d0e9bf DL |
2265 | switch (fb_format_modifier) { |
2266 | case DRM_FORMAT_MOD_NONE: | |
2267 | tile_height = 1; | |
2268 | break; | |
2269 | case I915_FORMAT_MOD_X_TILED: | |
2270 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2271 | break; | |
2272 | case I915_FORMAT_MOD_Y_TILED: | |
2273 | tile_height = 32; | |
2274 | break; | |
2275 | case I915_FORMAT_MOD_Yf_TILED: | |
6761dd31 TU |
2276 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
2277 | switch (pixel_bytes) { | |
b5d0e9bf | 2278 | default: |
6761dd31 | 2279 | case 1: |
b5d0e9bf DL |
2280 | tile_height = 64; |
2281 | break; | |
6761dd31 TU |
2282 | case 2: |
2283 | case 4: | |
b5d0e9bf DL |
2284 | tile_height = 32; |
2285 | break; | |
6761dd31 | 2286 | case 8: |
b5d0e9bf DL |
2287 | tile_height = 16; |
2288 | break; | |
6761dd31 | 2289 | case 16: |
b5d0e9bf DL |
2290 | WARN_ONCE(1, |
2291 | "128-bit pixels are not supported for display!"); | |
2292 | tile_height = 16; | |
2293 | break; | |
2294 | } | |
2295 | break; | |
2296 | default: | |
2297 | MISSING_CASE(fb_format_modifier); | |
2298 | tile_height = 1; | |
2299 | break; | |
2300 | } | |
091df6cb | 2301 | |
6761dd31 TU |
2302 | return tile_height; |
2303 | } | |
2304 | ||
2305 | unsigned int | |
2306 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2307 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2308 | { | |
2309 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
2310 | fb_format_modifier)); | |
a57ce0b2 JB |
2311 | } |
2312 | ||
f64b98cd TU |
2313 | static int |
2314 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, | |
2315 | const struct drm_plane_state *plane_state) | |
2316 | { | |
50470bb0 | 2317 | struct intel_rotation_info *info = &view->rotation_info; |
50470bb0 | 2318 | |
f64b98cd TU |
2319 | *view = i915_ggtt_view_normal; |
2320 | ||
50470bb0 TU |
2321 | if (!plane_state) |
2322 | return 0; | |
2323 | ||
121920fa | 2324 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
50470bb0 TU |
2325 | return 0; |
2326 | ||
9abc4648 | 2327 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2328 | |
2329 | info->height = fb->height; | |
2330 | info->pixel_format = fb->pixel_format; | |
2331 | info->pitch = fb->pitches[0]; | |
2332 | info->fb_modifier = fb->modifier[0]; | |
2333 | ||
f64b98cd TU |
2334 | return 0; |
2335 | } | |
2336 | ||
127bd2ac | 2337 | int |
850c4cdc TU |
2338 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2339 | struct drm_framebuffer *fb, | |
82bc3b2d | 2340 | const struct drm_plane_state *plane_state, |
a4872ba6 | 2341 | struct intel_engine_cs *pipelined) |
6b95a207 | 2342 | { |
850c4cdc | 2343 | struct drm_device *dev = fb->dev; |
ce453d81 | 2344 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2345 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2346 | struct i915_ggtt_view view; |
6b95a207 KH |
2347 | u32 alignment; |
2348 | int ret; | |
2349 | ||
ebcdd39e MR |
2350 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2351 | ||
7b911adc TU |
2352 | switch (fb->modifier[0]) { |
2353 | case DRM_FORMAT_MOD_NONE: | |
1fada4cc DL |
2354 | if (INTEL_INFO(dev)->gen >= 9) |
2355 | alignment = 256 * 1024; | |
2356 | else if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) | |
534843da | 2357 | alignment = 128 * 1024; |
a6c45cf0 | 2358 | else if (INTEL_INFO(dev)->gen >= 4) |
534843da CW |
2359 | alignment = 4 * 1024; |
2360 | else | |
2361 | alignment = 64 * 1024; | |
6b95a207 | 2362 | break; |
7b911adc | 2363 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2364 | if (INTEL_INFO(dev)->gen >= 9) |
2365 | alignment = 256 * 1024; | |
2366 | else { | |
2367 | /* pin() will align the object as required by fence */ | |
2368 | alignment = 0; | |
2369 | } | |
6b95a207 | 2370 | break; |
7b911adc | 2371 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2372 | case I915_FORMAT_MOD_Yf_TILED: |
2373 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2374 | "Y tiling bo slipped through, driver bug!\n")) | |
2375 | return -EINVAL; | |
2376 | alignment = 1 * 1024 * 1024; | |
2377 | break; | |
6b95a207 | 2378 | default: |
7b911adc TU |
2379 | MISSING_CASE(fb->modifier[0]); |
2380 | return -EINVAL; | |
6b95a207 KH |
2381 | } |
2382 | ||
f64b98cd TU |
2383 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2384 | if (ret) | |
2385 | return ret; | |
2386 | ||
693db184 CW |
2387 | /* Note that the w/a also requires 64 PTE of padding following the |
2388 | * bo. We currently fill all unused PTE with the shadow page and so | |
2389 | * we should always have valid PTE following the scanout preventing | |
2390 | * the VT-d warning. | |
2391 | */ | |
2392 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2393 | alignment = 256 * 1024; | |
2394 | ||
d6dd6843 PZ |
2395 | /* |
2396 | * Global gtt pte registers are special registers which actually forward | |
2397 | * writes to a chunk of system memory. Which means that there is no risk | |
2398 | * that the register values disappear as soon as we call | |
2399 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2400 | * pin/unpin/fence and not more. | |
2401 | */ | |
2402 | intel_runtime_pm_get(dev_priv); | |
2403 | ||
ce453d81 | 2404 | dev_priv->mm.interruptible = false; |
e6617330 | 2405 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
f64b98cd | 2406 | &view); |
48b956c5 | 2407 | if (ret) |
ce453d81 | 2408 | goto err_interruptible; |
6b95a207 KH |
2409 | |
2410 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2411 | * fence, whereas 965+ only requires a fence if using | |
2412 | * framebuffer compression. For simplicity, we always install | |
2413 | * a fence as the cost is not that onerous. | |
2414 | */ | |
06d98131 | 2415 | ret = i915_gem_object_get_fence(obj); |
9a5a53b3 CW |
2416 | if (ret) |
2417 | goto err_unpin; | |
1690e1eb | 2418 | |
9a5a53b3 | 2419 | i915_gem_object_pin_fence(obj); |
6b95a207 | 2420 | |
ce453d81 | 2421 | dev_priv->mm.interruptible = true; |
d6dd6843 | 2422 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2423 | return 0; |
48b956c5 CW |
2424 | |
2425 | err_unpin: | |
f64b98cd | 2426 | i915_gem_object_unpin_from_display_plane(obj, &view); |
ce453d81 CW |
2427 | err_interruptible: |
2428 | dev_priv->mm.interruptible = true; | |
d6dd6843 | 2429 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2430 | return ret; |
6b95a207 KH |
2431 | } |
2432 | ||
82bc3b2d TU |
2433 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2434 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2435 | { |
82bc3b2d | 2436 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd TU |
2437 | struct i915_ggtt_view view; |
2438 | int ret; | |
82bc3b2d | 2439 | |
ebcdd39e MR |
2440 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2441 | ||
f64b98cd TU |
2442 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2443 | WARN_ONCE(ret, "Couldn't get view from plane state!"); | |
2444 | ||
1690e1eb | 2445 | i915_gem_object_unpin_fence(obj); |
f64b98cd | 2446 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2447 | } |
2448 | ||
c2c75131 DV |
2449 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2450 | * is assumed to be a power-of-two. */ | |
bc752862 CW |
2451 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
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 { | |
2467 | unsigned int offset; | |
2468 | ||
2469 | offset = *y * pitch + *x * cpp; | |
2470 | *y = 0; | |
2471 | *x = (offset & 4095) / cpp; | |
2472 | return offset & -4096; | |
2473 | } | |
c2c75131 DV |
2474 | } |
2475 | ||
b35d63fa | 2476 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2477 | { |
2478 | switch (format) { | |
2479 | case DISPPLANE_8BPP: | |
2480 | return DRM_FORMAT_C8; | |
2481 | case DISPPLANE_BGRX555: | |
2482 | return DRM_FORMAT_XRGB1555; | |
2483 | case DISPPLANE_BGRX565: | |
2484 | return DRM_FORMAT_RGB565; | |
2485 | default: | |
2486 | case DISPPLANE_BGRX888: | |
2487 | return DRM_FORMAT_XRGB8888; | |
2488 | case DISPPLANE_RGBX888: | |
2489 | return DRM_FORMAT_XBGR8888; | |
2490 | case DISPPLANE_BGRX101010: | |
2491 | return DRM_FORMAT_XRGB2101010; | |
2492 | case DISPPLANE_RGBX101010: | |
2493 | return DRM_FORMAT_XBGR2101010; | |
2494 | } | |
2495 | } | |
2496 | ||
bc8d7dff DL |
2497 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2498 | { | |
2499 | switch (format) { | |
2500 | case PLANE_CTL_FORMAT_RGB_565: | |
2501 | return DRM_FORMAT_RGB565; | |
2502 | default: | |
2503 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2504 | if (rgb_order) { | |
2505 | if (alpha) | |
2506 | return DRM_FORMAT_ABGR8888; | |
2507 | else | |
2508 | return DRM_FORMAT_XBGR8888; | |
2509 | } else { | |
2510 | if (alpha) | |
2511 | return DRM_FORMAT_ARGB8888; | |
2512 | else | |
2513 | return DRM_FORMAT_XRGB8888; | |
2514 | } | |
2515 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2516 | if (rgb_order) | |
2517 | return DRM_FORMAT_XBGR2101010; | |
2518 | else | |
2519 | return DRM_FORMAT_XRGB2101010; | |
2520 | } | |
2521 | } | |
2522 | ||
5724dbd1 | 2523 | static bool |
f6936e29 DV |
2524 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2525 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2526 | { |
2527 | struct drm_device *dev = crtc->base.dev; | |
2528 | struct drm_i915_gem_object *obj = NULL; | |
2529 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2530 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2531 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2532 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2533 | PAGE_SIZE); | |
2534 | ||
2535 | size_aligned -= base_aligned; | |
46f297fb | 2536 | |
ff2652ea CW |
2537 | if (plane_config->size == 0) |
2538 | return false; | |
2539 | ||
f37b5c2b DV |
2540 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2541 | base_aligned, | |
2542 | base_aligned, | |
2543 | size_aligned); | |
46f297fb | 2544 | if (!obj) |
484b41dd | 2545 | return false; |
46f297fb | 2546 | |
49af449b DL |
2547 | obj->tiling_mode = plane_config->tiling; |
2548 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2549 | obj->stride = fb->pitches[0]; |
46f297fb | 2550 | |
6bf129df DL |
2551 | mode_cmd.pixel_format = fb->pixel_format; |
2552 | mode_cmd.width = fb->width; | |
2553 | mode_cmd.height = fb->height; | |
2554 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2555 | mode_cmd.modifier[0] = fb->modifier[0]; |
2556 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2557 | |
2558 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2559 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2560 | &mode_cmd, obj)) { |
46f297fb JB |
2561 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2562 | goto out_unref_obj; | |
2563 | } | |
46f297fb | 2564 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2565 | |
f6936e29 | 2566 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2567 | return true; |
46f297fb JB |
2568 | |
2569 | out_unref_obj: | |
2570 | drm_gem_object_unreference(&obj->base); | |
2571 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2572 | return false; |
2573 | } | |
2574 | ||
afd65eb4 MR |
2575 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2576 | static void | |
2577 | update_state_fb(struct drm_plane *plane) | |
2578 | { | |
2579 | if (plane->fb == plane->state->fb) | |
2580 | return; | |
2581 | ||
2582 | if (plane->state->fb) | |
2583 | drm_framebuffer_unreference(plane->state->fb); | |
2584 | plane->state->fb = plane->fb; | |
2585 | if (plane->state->fb) | |
2586 | drm_framebuffer_reference(plane->state->fb); | |
2587 | } | |
2588 | ||
5724dbd1 | 2589 | static void |
f6936e29 DV |
2590 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2591 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2592 | { |
2593 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2594 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2595 | struct drm_crtc *c; |
2596 | struct intel_crtc *i; | |
2ff8fde1 | 2597 | struct drm_i915_gem_object *obj; |
88595ac9 DV |
2598 | struct drm_plane *primary = intel_crtc->base.primary; |
2599 | struct drm_framebuffer *fb; | |
484b41dd | 2600 | |
2d14030b | 2601 | if (!plane_config->fb) |
484b41dd JB |
2602 | return; |
2603 | ||
f6936e29 | 2604 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2605 | fb = &plane_config->fb->base; |
2606 | goto valid_fb; | |
f55548b5 | 2607 | } |
484b41dd | 2608 | |
2d14030b | 2609 | kfree(plane_config->fb); |
484b41dd JB |
2610 | |
2611 | /* | |
2612 | * Failed to alloc the obj, check to see if we should share | |
2613 | * an fb with another CRTC instead | |
2614 | */ | |
70e1e0ec | 2615 | for_each_crtc(dev, c) { |
484b41dd JB |
2616 | i = to_intel_crtc(c); |
2617 | ||
2618 | if (c == &intel_crtc->base) | |
2619 | continue; | |
2620 | ||
2ff8fde1 MR |
2621 | if (!i->active) |
2622 | continue; | |
2623 | ||
88595ac9 DV |
2624 | fb = c->primary->fb; |
2625 | if (!fb) | |
484b41dd JB |
2626 | continue; |
2627 | ||
88595ac9 | 2628 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2629 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2630 | drm_framebuffer_reference(fb); |
2631 | goto valid_fb; | |
484b41dd JB |
2632 | } |
2633 | } | |
88595ac9 DV |
2634 | |
2635 | return; | |
2636 | ||
2637 | valid_fb: | |
2638 | obj = intel_fb_obj(fb); | |
2639 | if (obj->tiling_mode != I915_TILING_NONE) | |
2640 | dev_priv->preserve_bios_swizzle = true; | |
2641 | ||
2642 | primary->fb = fb; | |
2643 | primary->state->crtc = &intel_crtc->base; | |
2644 | primary->crtc = &intel_crtc->base; | |
2645 | update_state_fb(primary); | |
2646 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); | |
46f297fb JB |
2647 | } |
2648 | ||
29b9bde6 DV |
2649 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2650 | struct drm_framebuffer *fb, | |
2651 | int x, int y) | |
81255565 JB |
2652 | { |
2653 | struct drm_device *dev = crtc->dev; | |
2654 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2655 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2656 | struct drm_plane *primary = crtc->primary; |
2657 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2658 | struct drm_i915_gem_object *obj; |
81255565 | 2659 | int plane = intel_crtc->plane; |
e506a0c6 | 2660 | unsigned long linear_offset; |
81255565 | 2661 | u32 dspcntr; |
f45651ba | 2662 | u32 reg = DSPCNTR(plane); |
48404c1e | 2663 | int pixel_size; |
f45651ba | 2664 | |
b70709a6 | 2665 | if (!visible || !fb) { |
fdd508a6 VS |
2666 | I915_WRITE(reg, 0); |
2667 | if (INTEL_INFO(dev)->gen >= 4) | |
2668 | I915_WRITE(DSPSURF(plane), 0); | |
2669 | else | |
2670 | I915_WRITE(DSPADDR(plane), 0); | |
2671 | POSTING_READ(reg); | |
2672 | return; | |
2673 | } | |
2674 | ||
c9ba6fad VS |
2675 | obj = intel_fb_obj(fb); |
2676 | if (WARN_ON(obj == NULL)) | |
2677 | return; | |
2678 | ||
2679 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2680 | ||
f45651ba VS |
2681 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2682 | ||
fdd508a6 | 2683 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2684 | |
2685 | if (INTEL_INFO(dev)->gen < 4) { | |
2686 | if (intel_crtc->pipe == PIPE_B) | |
2687 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2688 | ||
2689 | /* pipesrc and dspsize control the size that is scaled from, | |
2690 | * which should always be the user's requested size. | |
2691 | */ | |
2692 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2693 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2694 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2695 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2696 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2697 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2698 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2699 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2700 | I915_WRITE(PRIMPOS(plane), 0); |
2701 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2702 | } |
81255565 | 2703 | |
57779d06 VS |
2704 | switch (fb->pixel_format) { |
2705 | case DRM_FORMAT_C8: | |
81255565 JB |
2706 | dspcntr |= DISPPLANE_8BPP; |
2707 | break; | |
57779d06 | 2708 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2709 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2710 | break; |
57779d06 VS |
2711 | case DRM_FORMAT_RGB565: |
2712 | dspcntr |= DISPPLANE_BGRX565; | |
2713 | break; | |
2714 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2715 | dspcntr |= DISPPLANE_BGRX888; |
2716 | break; | |
2717 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2718 | dspcntr |= DISPPLANE_RGBX888; |
2719 | break; | |
2720 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2721 | dspcntr |= DISPPLANE_BGRX101010; |
2722 | break; | |
2723 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2724 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2725 | break; |
2726 | default: | |
baba133a | 2727 | BUG(); |
81255565 | 2728 | } |
57779d06 | 2729 | |
f45651ba VS |
2730 | if (INTEL_INFO(dev)->gen >= 4 && |
2731 | obj->tiling_mode != I915_TILING_NONE) | |
2732 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2733 | |
de1aa629 VS |
2734 | if (IS_G4X(dev)) |
2735 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2736 | ||
b9897127 | 2737 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2738 | |
c2c75131 DV |
2739 | if (INTEL_INFO(dev)->gen >= 4) { |
2740 | intel_crtc->dspaddr_offset = | |
bc752862 | 2741 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
b9897127 | 2742 | pixel_size, |
bc752862 | 2743 | fb->pitches[0]); |
c2c75131 DV |
2744 | linear_offset -= intel_crtc->dspaddr_offset; |
2745 | } else { | |
e506a0c6 | 2746 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2747 | } |
e506a0c6 | 2748 | |
8e7d688b | 2749 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2750 | dspcntr |= DISPPLANE_ROTATE_180; |
2751 | ||
6e3c9717 ACO |
2752 | x += (intel_crtc->config->pipe_src_w - 1); |
2753 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2754 | |
2755 | /* Finding the last pixel of the last line of the display | |
2756 | data and adding to linear_offset*/ | |
2757 | linear_offset += | |
6e3c9717 ACO |
2758 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2759 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2760 | } |
2761 | ||
2762 | I915_WRITE(reg, dspcntr); | |
2763 | ||
01f2c773 | 2764 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2765 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2766 | I915_WRITE(DSPSURF(plane), |
2767 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2768 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2769 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2770 | } else |
f343c5f6 | 2771 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2772 | POSTING_READ(reg); |
17638cd6 JB |
2773 | } |
2774 | ||
29b9bde6 DV |
2775 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2776 | struct drm_framebuffer *fb, | |
2777 | int x, int y) | |
17638cd6 JB |
2778 | { |
2779 | struct drm_device *dev = crtc->dev; | |
2780 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2781 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2782 | struct drm_plane *primary = crtc->primary; |
2783 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2784 | struct drm_i915_gem_object *obj; |
17638cd6 | 2785 | int plane = intel_crtc->plane; |
e506a0c6 | 2786 | unsigned long linear_offset; |
17638cd6 | 2787 | u32 dspcntr; |
f45651ba | 2788 | u32 reg = DSPCNTR(plane); |
48404c1e | 2789 | int pixel_size; |
f45651ba | 2790 | |
b70709a6 | 2791 | if (!visible || !fb) { |
fdd508a6 VS |
2792 | I915_WRITE(reg, 0); |
2793 | I915_WRITE(DSPSURF(plane), 0); | |
2794 | POSTING_READ(reg); | |
2795 | return; | |
2796 | } | |
2797 | ||
c9ba6fad VS |
2798 | obj = intel_fb_obj(fb); |
2799 | if (WARN_ON(obj == NULL)) | |
2800 | return; | |
2801 | ||
2802 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2803 | ||
f45651ba VS |
2804 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2805 | ||
fdd508a6 | 2806 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2807 | |
2808 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2809 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2810 | |
57779d06 VS |
2811 | switch (fb->pixel_format) { |
2812 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2813 | dspcntr |= DISPPLANE_8BPP; |
2814 | break; | |
57779d06 VS |
2815 | case DRM_FORMAT_RGB565: |
2816 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2817 | break; |
57779d06 | 2818 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2819 | dspcntr |= DISPPLANE_BGRX888; |
2820 | break; | |
2821 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2822 | dspcntr |= DISPPLANE_RGBX888; |
2823 | break; | |
2824 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2825 | dspcntr |= DISPPLANE_BGRX101010; |
2826 | break; | |
2827 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2828 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2829 | break; |
2830 | default: | |
baba133a | 2831 | BUG(); |
17638cd6 JB |
2832 | } |
2833 | ||
2834 | if (obj->tiling_mode != I915_TILING_NONE) | |
2835 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2836 | |
f45651ba | 2837 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2838 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2839 | |
b9897127 | 2840 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2841 | intel_crtc->dspaddr_offset = |
bc752862 | 2842 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
b9897127 | 2843 | pixel_size, |
bc752862 | 2844 | fb->pitches[0]); |
c2c75131 | 2845 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2846 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2847 | dspcntr |= DISPPLANE_ROTATE_180; |
2848 | ||
2849 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2850 | x += (intel_crtc->config->pipe_src_w - 1); |
2851 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2852 | |
2853 | /* Finding the last pixel of the last line of the display | |
2854 | data and adding to linear_offset*/ | |
2855 | linear_offset += | |
6e3c9717 ACO |
2856 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2857 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2858 | } |
2859 | } | |
2860 | ||
2861 | I915_WRITE(reg, dspcntr); | |
17638cd6 | 2862 | |
01f2c773 | 2863 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2864 | I915_WRITE(DSPSURF(plane), |
2865 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2866 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2867 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2868 | } else { | |
2869 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2870 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2871 | } | |
17638cd6 | 2872 | POSTING_READ(reg); |
17638cd6 JB |
2873 | } |
2874 | ||
b321803d DL |
2875 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2876 | uint32_t pixel_format) | |
2877 | { | |
2878 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2879 | ||
2880 | /* | |
2881 | * The stride is either expressed as a multiple of 64 bytes | |
2882 | * chunks for linear buffers or in number of tiles for tiled | |
2883 | * buffers. | |
2884 | */ | |
2885 | switch (fb_modifier) { | |
2886 | case DRM_FORMAT_MOD_NONE: | |
2887 | return 64; | |
2888 | case I915_FORMAT_MOD_X_TILED: | |
2889 | if (INTEL_INFO(dev)->gen == 2) | |
2890 | return 128; | |
2891 | return 512; | |
2892 | case I915_FORMAT_MOD_Y_TILED: | |
2893 | /* No need to check for old gens and Y tiling since this is | |
2894 | * about the display engine and those will be blocked before | |
2895 | * we get here. | |
2896 | */ | |
2897 | return 128; | |
2898 | case I915_FORMAT_MOD_Yf_TILED: | |
2899 | if (bits_per_pixel == 8) | |
2900 | return 64; | |
2901 | else | |
2902 | return 128; | |
2903 | default: | |
2904 | MISSING_CASE(fb_modifier); | |
2905 | return 64; | |
2906 | } | |
2907 | } | |
2908 | ||
121920fa TU |
2909 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
2910 | struct drm_i915_gem_object *obj) | |
2911 | { | |
9abc4648 | 2912 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
121920fa TU |
2913 | |
2914 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) | |
9abc4648 | 2915 | view = &i915_ggtt_view_rotated; |
121920fa TU |
2916 | |
2917 | return i915_gem_obj_ggtt_offset_view(obj, view); | |
2918 | } | |
2919 | ||
a1b2278e CK |
2920 | /* |
2921 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2922 | */ | |
2923 | void skl_detach_scalers(struct intel_crtc *intel_crtc) | |
2924 | { | |
2925 | struct drm_device *dev; | |
2926 | struct drm_i915_private *dev_priv; | |
2927 | struct intel_crtc_scaler_state *scaler_state; | |
2928 | int i; | |
2929 | ||
2930 | if (!intel_crtc || !intel_crtc->config) | |
2931 | return; | |
2932 | ||
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; | |
3b7a5119 | 3013 | case BIT(DRM_ROTATE_90): |
c34ce3d1 | 3014 | return PLANE_CTL_ROTATE_90; |
3b7a5119 | 3015 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3016 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3017 | case BIT(DRM_ROTATE_270): |
c34ce3d1 | 3018 | return PLANE_CTL_ROTATE_270; |
6156a456 CK |
3019 | default: |
3020 | MISSING_CASE(rotation); | |
3021 | } | |
3022 | ||
c34ce3d1 | 3023 | return 0; |
6156a456 CK |
3024 | } |
3025 | ||
3026 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
3027 | struct drm_framebuffer *fb, | |
3028 | int x, int y) | |
3029 | { | |
3030 | struct drm_device *dev = crtc->dev; | |
3031 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3032 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3033 | struct drm_plane *plane = crtc->primary; |
3034 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3035 | struct drm_i915_gem_object *obj; |
3036 | int pipe = intel_crtc->pipe; | |
3037 | u32 plane_ctl, stride_div, stride; | |
3038 | u32 tile_height, plane_offset, plane_size; | |
3039 | unsigned int rotation; | |
3040 | int x_offset, y_offset; | |
3041 | unsigned long surf_addr; | |
6156a456 CK |
3042 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3043 | struct intel_plane_state *plane_state; | |
3044 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3045 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3046 | int scaler_id = -1; | |
3047 | ||
6156a456 CK |
3048 | plane_state = to_intel_plane_state(plane->state); |
3049 | ||
b70709a6 | 3050 | if (!visible || !fb) { |
6156a456 CK |
3051 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3052 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3053 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3054 | return; | |
3b7a5119 | 3055 | } |
70d21f0e | 3056 | |
6156a456 CK |
3057 | plane_ctl = PLANE_CTL_ENABLE | |
3058 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3059 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3060 | ||
3061 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3062 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3063 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3064 | ||
3065 | rotation = plane->state->rotation; | |
3066 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3067 | ||
b321803d DL |
3068 | obj = intel_fb_obj(fb); |
3069 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3070 | fb->pixel_format); | |
3b7a5119 SJ |
3071 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
3072 | ||
6156a456 CK |
3073 | /* |
3074 | * FIXME: intel_plane_state->src, dst aren't set when transitional | |
3075 | * update_plane helpers are called from legacy paths. | |
3076 | * Once full atomic crtc is available, below check can be avoided. | |
3077 | */ | |
3078 | if (drm_rect_width(&plane_state->src)) { | |
3079 | scaler_id = plane_state->scaler_id; | |
3080 | src_x = plane_state->src.x1 >> 16; | |
3081 | src_y = plane_state->src.y1 >> 16; | |
3082 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3083 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3084 | dst_x = plane_state->dst.x1; | |
3085 | dst_y = plane_state->dst.y1; | |
3086 | dst_w = drm_rect_width(&plane_state->dst); | |
3087 | dst_h = drm_rect_height(&plane_state->dst); | |
3088 | ||
3089 | WARN_ON(x != src_x || y != src_y); | |
3090 | } else { | |
3091 | src_w = intel_crtc->config->pipe_src_w; | |
3092 | src_h = intel_crtc->config->pipe_src_h; | |
3093 | } | |
3094 | ||
3b7a5119 SJ |
3095 | if (intel_rotation_90_or_270(rotation)) { |
3096 | /* stride = Surface height in tiles */ | |
2614f17d | 3097 | tile_height = intel_tile_height(dev, fb->pixel_format, |
3b7a5119 SJ |
3098 | fb->modifier[0]); |
3099 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
6156a456 | 3100 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3101 | y_offset = x; |
6156a456 | 3102 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3103 | } else { |
3104 | stride = fb->pitches[0] / stride_div; | |
3105 | x_offset = x; | |
3106 | y_offset = y; | |
6156a456 | 3107 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3108 | } |
3109 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3110 | |
70d21f0e | 3111 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3112 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3113 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3114 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3115 | |
3116 | if (scaler_id >= 0) { | |
3117 | uint32_t ps_ctrl = 0; | |
3118 | ||
3119 | WARN_ON(!dst_w || !dst_h); | |
3120 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3121 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3122 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3123 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3124 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3125 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3126 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3127 | } else { | |
3128 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3129 | } | |
3130 | ||
121920fa | 3131 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3132 | |
3133 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3134 | } | |
3135 | ||
17638cd6 JB |
3136 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3137 | static int | |
3138 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3139 | int x, int y, enum mode_set_atomic state) | |
3140 | { | |
3141 | struct drm_device *dev = crtc->dev; | |
3142 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3143 | |
6b8e6ed0 CW |
3144 | if (dev_priv->display.disable_fbc) |
3145 | dev_priv->display.disable_fbc(dev); | |
81255565 | 3146 | |
29b9bde6 DV |
3147 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3148 | ||
3149 | return 0; | |
81255565 JB |
3150 | } |
3151 | ||
7514747d | 3152 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3153 | { |
96a02917 VS |
3154 | struct drm_crtc *crtc; |
3155 | ||
70e1e0ec | 3156 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3157 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3158 | enum plane plane = intel_crtc->plane; | |
3159 | ||
3160 | intel_prepare_page_flip(dev, plane); | |
3161 | intel_finish_page_flip_plane(dev, plane); | |
3162 | } | |
7514747d VS |
3163 | } |
3164 | ||
3165 | static void intel_update_primary_planes(struct drm_device *dev) | |
3166 | { | |
3167 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3168 | struct drm_crtc *crtc; | |
96a02917 | 3169 | |
70e1e0ec | 3170 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3171 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3172 | ||
51fd371b | 3173 | drm_modeset_lock(&crtc->mutex, NULL); |
947fdaad CW |
3174 | /* |
3175 | * FIXME: Once we have proper support for primary planes (and | |
3176 | * disabling them without disabling the entire crtc) allow again | |
66e514c1 | 3177 | * a NULL crtc->primary->fb. |
947fdaad | 3178 | */ |
f4510a27 | 3179 | if (intel_crtc->active && crtc->primary->fb) |
262ca2b0 | 3180 | dev_priv->display.update_primary_plane(crtc, |
66e514c1 | 3181 | crtc->primary->fb, |
262ca2b0 MR |
3182 | crtc->x, |
3183 | crtc->y); | |
51fd371b | 3184 | drm_modeset_unlock(&crtc->mutex); |
96a02917 VS |
3185 | } |
3186 | } | |
3187 | ||
ce22dba9 ML |
3188 | void intel_crtc_reset(struct intel_crtc *crtc) |
3189 | { | |
3190 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
3191 | ||
3192 | if (!crtc->active) | |
3193 | return; | |
3194 | ||
3195 | intel_crtc_disable_planes(&crtc->base); | |
3196 | dev_priv->display.crtc_disable(&crtc->base); | |
3197 | dev_priv->display.crtc_enable(&crtc->base); | |
3198 | intel_crtc_enable_planes(&crtc->base); | |
3199 | } | |
3200 | ||
7514747d VS |
3201 | void intel_prepare_reset(struct drm_device *dev) |
3202 | { | |
f98ce92f VS |
3203 | struct drm_i915_private *dev_priv = to_i915(dev); |
3204 | struct intel_crtc *crtc; | |
3205 | ||
7514747d VS |
3206 | /* no reset support for gen2 */ |
3207 | if (IS_GEN2(dev)) | |
3208 | return; | |
3209 | ||
3210 | /* reset doesn't touch the display */ | |
3211 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3212 | return; | |
3213 | ||
3214 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3215 | |
3216 | /* | |
3217 | * Disabling the crtcs gracefully seems nicer. Also the | |
3218 | * g33 docs say we should at least disable all the planes. | |
3219 | */ | |
3220 | for_each_intel_crtc(dev, crtc) { | |
ce22dba9 ML |
3221 | if (!crtc->active) |
3222 | continue; | |
3223 | ||
3224 | intel_crtc_disable_planes(&crtc->base); | |
3225 | dev_priv->display.crtc_disable(&crtc->base); | |
f98ce92f | 3226 | } |
7514747d VS |
3227 | } |
3228 | ||
3229 | void intel_finish_reset(struct drm_device *dev) | |
3230 | { | |
3231 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3232 | ||
3233 | /* | |
3234 | * Flips in the rings will be nuked by the reset, | |
3235 | * so complete all pending flips so that user space | |
3236 | * will get its events and not get stuck. | |
3237 | */ | |
3238 | intel_complete_page_flips(dev); | |
3239 | ||
3240 | /* no reset support for gen2 */ | |
3241 | if (IS_GEN2(dev)) | |
3242 | return; | |
3243 | ||
3244 | /* reset doesn't touch the display */ | |
3245 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3246 | /* | |
3247 | * Flips in the rings have been nuked by the reset, | |
3248 | * so update the base address of all primary | |
3249 | * planes to the the last fb to make sure we're | |
3250 | * showing the correct fb after a reset. | |
3251 | */ | |
3252 | intel_update_primary_planes(dev); | |
3253 | return; | |
3254 | } | |
3255 | ||
3256 | /* | |
3257 | * The display has been reset as well, | |
3258 | * so need a full re-initialization. | |
3259 | */ | |
3260 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3261 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3262 | ||
3263 | intel_modeset_init_hw(dev); | |
3264 | ||
3265 | spin_lock_irq(&dev_priv->irq_lock); | |
3266 | if (dev_priv->display.hpd_irq_setup) | |
3267 | dev_priv->display.hpd_irq_setup(dev); | |
3268 | spin_unlock_irq(&dev_priv->irq_lock); | |
3269 | ||
3270 | intel_modeset_setup_hw_state(dev, true); | |
3271 | ||
3272 | intel_hpd_init(dev_priv); | |
3273 | ||
3274 | drm_modeset_unlock_all(dev); | |
3275 | } | |
3276 | ||
2e2f351d | 3277 | static void |
14667a4b CW |
3278 | intel_finish_fb(struct drm_framebuffer *old_fb) |
3279 | { | |
2ff8fde1 | 3280 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
2e2f351d | 3281 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
14667a4b CW |
3282 | bool was_interruptible = dev_priv->mm.interruptible; |
3283 | int ret; | |
3284 | ||
14667a4b CW |
3285 | /* Big Hammer, we also need to ensure that any pending |
3286 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
3287 | * current scanout is retired before unpinning the old | |
2e2f351d CW |
3288 | * framebuffer. Note that we rely on userspace rendering |
3289 | * into the buffer attached to the pipe they are waiting | |
3290 | * on. If not, userspace generates a GPU hang with IPEHR | |
3291 | * point to the MI_WAIT_FOR_EVENT. | |
14667a4b CW |
3292 | * |
3293 | * This should only fail upon a hung GPU, in which case we | |
3294 | * can safely continue. | |
3295 | */ | |
3296 | dev_priv->mm.interruptible = false; | |
2e2f351d | 3297 | ret = i915_gem_object_wait_rendering(obj, true); |
14667a4b CW |
3298 | dev_priv->mm.interruptible = was_interruptible; |
3299 | ||
2e2f351d | 3300 | WARN_ON(ret); |
14667a4b CW |
3301 | } |
3302 | ||
7d5e3799 CW |
3303 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3304 | { | |
3305 | struct drm_device *dev = crtc->dev; | |
3306 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3307 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3308 | bool pending; |
3309 | ||
3310 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3311 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3312 | return false; | |
3313 | ||
5e2d7afc | 3314 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3315 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3316 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3317 | |
3318 | return pending; | |
3319 | } | |
3320 | ||
e30e8f75 GP |
3321 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
3322 | { | |
3323 | struct drm_device *dev = crtc->base.dev; | |
3324 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3325 | const struct drm_display_mode *adjusted_mode; | |
3326 | ||
3327 | if (!i915.fastboot) | |
3328 | return; | |
3329 | ||
3330 | /* | |
3331 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3332 | * that in compute_mode_changes we check the native mode (not the pfit | |
3333 | * mode) to see if we can flip rather than do a full mode set. In the | |
3334 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3335 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3336 | * sized surface. | |
3337 | * | |
3338 | * To fix this properly, we need to hoist the checks up into | |
3339 | * compute_mode_changes (or above), check the actual pfit state and | |
3340 | * whether the platform allows pfit disable with pipe active, and only | |
3341 | * then update the pipesrc and pfit state, even on the flip path. | |
3342 | */ | |
3343 | ||
6e3c9717 | 3344 | adjusted_mode = &crtc->config->base.adjusted_mode; |
e30e8f75 GP |
3345 | |
3346 | I915_WRITE(PIPESRC(crtc->pipe), | |
3347 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | | |
3348 | (adjusted_mode->crtc_vdisplay - 1)); | |
6e3c9717 | 3349 | if (!crtc->config->pch_pfit.enabled && |
409ee761 ACO |
3350 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
3351 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { | |
e30e8f75 GP |
3352 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
3353 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); | |
3354 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); | |
3355 | } | |
6e3c9717 ACO |
3356 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
3357 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; | |
e30e8f75 GP |
3358 | } |
3359 | ||
5e84e1a4 ZW |
3360 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3361 | { | |
3362 | struct drm_device *dev = crtc->dev; | |
3363 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3364 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3365 | int pipe = intel_crtc->pipe; | |
3366 | u32 reg, temp; | |
3367 | ||
3368 | /* enable normal train */ | |
3369 | reg = FDI_TX_CTL(pipe); | |
3370 | temp = I915_READ(reg); | |
61e499bf | 3371 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3372 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3373 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3374 | } else { |
3375 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3376 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3377 | } |
5e84e1a4 ZW |
3378 | I915_WRITE(reg, temp); |
3379 | ||
3380 | reg = FDI_RX_CTL(pipe); | |
3381 | temp = I915_READ(reg); | |
3382 | if (HAS_PCH_CPT(dev)) { | |
3383 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3384 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3385 | } else { | |
3386 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3387 | temp |= FDI_LINK_TRAIN_NONE; | |
3388 | } | |
3389 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3390 | ||
3391 | /* wait one idle pattern time */ | |
3392 | POSTING_READ(reg); | |
3393 | udelay(1000); | |
357555c0 JB |
3394 | |
3395 | /* IVB wants error correction enabled */ | |
3396 | if (IS_IVYBRIDGE(dev)) | |
3397 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3398 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3399 | } |
3400 | ||
8db9d77b ZW |
3401 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3402 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3403 | { | |
3404 | struct drm_device *dev = crtc->dev; | |
3405 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3406 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3407 | int pipe = intel_crtc->pipe; | |
5eddb70b | 3408 | u32 reg, temp, tries; |
8db9d77b | 3409 | |
1c8562f6 | 3410 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3411 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3412 | |
e1a44743 AJ |
3413 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3414 | for train result */ | |
5eddb70b CW |
3415 | reg = FDI_RX_IMR(pipe); |
3416 | temp = I915_READ(reg); | |
e1a44743 AJ |
3417 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3418 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3419 | I915_WRITE(reg, temp); |
3420 | I915_READ(reg); | |
e1a44743 AJ |
3421 | udelay(150); |
3422 | ||
8db9d77b | 3423 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3424 | reg = FDI_TX_CTL(pipe); |
3425 | temp = I915_READ(reg); | |
627eb5a3 | 3426 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3427 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3428 | temp &= ~FDI_LINK_TRAIN_NONE; |
3429 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3430 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3431 | |
5eddb70b CW |
3432 | reg = FDI_RX_CTL(pipe); |
3433 | temp = I915_READ(reg); | |
8db9d77b ZW |
3434 | temp &= ~FDI_LINK_TRAIN_NONE; |
3435 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3436 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3437 | ||
3438 | POSTING_READ(reg); | |
8db9d77b ZW |
3439 | udelay(150); |
3440 | ||
5b2adf89 | 3441 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3442 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3443 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3444 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3445 | |
5eddb70b | 3446 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3447 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3448 | temp = I915_READ(reg); |
8db9d77b ZW |
3449 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3450 | ||
3451 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3452 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3453 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3454 | break; |
3455 | } | |
8db9d77b | 3456 | } |
e1a44743 | 3457 | if (tries == 5) |
5eddb70b | 3458 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3459 | |
3460 | /* Train 2 */ | |
5eddb70b CW |
3461 | reg = FDI_TX_CTL(pipe); |
3462 | temp = I915_READ(reg); | |
8db9d77b ZW |
3463 | temp &= ~FDI_LINK_TRAIN_NONE; |
3464 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3465 | I915_WRITE(reg, temp); |
8db9d77b | 3466 | |
5eddb70b CW |
3467 | reg = FDI_RX_CTL(pipe); |
3468 | temp = I915_READ(reg); | |
8db9d77b ZW |
3469 | temp &= ~FDI_LINK_TRAIN_NONE; |
3470 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3471 | I915_WRITE(reg, temp); |
8db9d77b | 3472 | |
5eddb70b CW |
3473 | POSTING_READ(reg); |
3474 | udelay(150); | |
8db9d77b | 3475 | |
5eddb70b | 3476 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3477 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3478 | temp = I915_READ(reg); |
8db9d77b ZW |
3479 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3480 | ||
3481 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3482 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3483 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3484 | break; | |
3485 | } | |
8db9d77b | 3486 | } |
e1a44743 | 3487 | if (tries == 5) |
5eddb70b | 3488 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3489 | |
3490 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3491 | |
8db9d77b ZW |
3492 | } |
3493 | ||
0206e353 | 3494 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3495 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3496 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3497 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3498 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3499 | }; | |
3500 | ||
3501 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3502 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3503 | { | |
3504 | struct drm_device *dev = crtc->dev; | |
3505 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3506 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3507 | int pipe = intel_crtc->pipe; | |
fa37d39e | 3508 | u32 reg, temp, i, retry; |
8db9d77b | 3509 | |
e1a44743 AJ |
3510 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3511 | for train result */ | |
5eddb70b CW |
3512 | reg = FDI_RX_IMR(pipe); |
3513 | temp = I915_READ(reg); | |
e1a44743 AJ |
3514 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3515 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3516 | I915_WRITE(reg, temp); |
3517 | ||
3518 | POSTING_READ(reg); | |
e1a44743 AJ |
3519 | udelay(150); |
3520 | ||
8db9d77b | 3521 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3522 | reg = FDI_TX_CTL(pipe); |
3523 | temp = I915_READ(reg); | |
627eb5a3 | 3524 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3525 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3526 | temp &= ~FDI_LINK_TRAIN_NONE; |
3527 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3528 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3529 | /* SNB-B */ | |
3530 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3531 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3532 | |
d74cf324 DV |
3533 | I915_WRITE(FDI_RX_MISC(pipe), |
3534 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3535 | ||
5eddb70b CW |
3536 | reg = FDI_RX_CTL(pipe); |
3537 | temp = I915_READ(reg); | |
8db9d77b ZW |
3538 | if (HAS_PCH_CPT(dev)) { |
3539 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3540 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3541 | } else { | |
3542 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3543 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3544 | } | |
5eddb70b CW |
3545 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3546 | ||
3547 | POSTING_READ(reg); | |
8db9d77b ZW |
3548 | udelay(150); |
3549 | ||
0206e353 | 3550 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3551 | reg = FDI_TX_CTL(pipe); |
3552 | temp = I915_READ(reg); | |
8db9d77b ZW |
3553 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3554 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3555 | I915_WRITE(reg, temp); |
3556 | ||
3557 | POSTING_READ(reg); | |
8db9d77b ZW |
3558 | udelay(500); |
3559 | ||
fa37d39e SP |
3560 | for (retry = 0; retry < 5; retry++) { |
3561 | reg = FDI_RX_IIR(pipe); | |
3562 | temp = I915_READ(reg); | |
3563 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3564 | if (temp & FDI_RX_BIT_LOCK) { | |
3565 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3566 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3567 | break; | |
3568 | } | |
3569 | udelay(50); | |
8db9d77b | 3570 | } |
fa37d39e SP |
3571 | if (retry < 5) |
3572 | break; | |
8db9d77b ZW |
3573 | } |
3574 | if (i == 4) | |
5eddb70b | 3575 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3576 | |
3577 | /* Train 2 */ | |
5eddb70b CW |
3578 | reg = FDI_TX_CTL(pipe); |
3579 | temp = I915_READ(reg); | |
8db9d77b ZW |
3580 | temp &= ~FDI_LINK_TRAIN_NONE; |
3581 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3582 | if (IS_GEN6(dev)) { | |
3583 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3584 | /* SNB-B */ | |
3585 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3586 | } | |
5eddb70b | 3587 | I915_WRITE(reg, temp); |
8db9d77b | 3588 | |
5eddb70b CW |
3589 | reg = FDI_RX_CTL(pipe); |
3590 | temp = I915_READ(reg); | |
8db9d77b ZW |
3591 | if (HAS_PCH_CPT(dev)) { |
3592 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3593 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3594 | } else { | |
3595 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3596 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3597 | } | |
5eddb70b CW |
3598 | I915_WRITE(reg, temp); |
3599 | ||
3600 | POSTING_READ(reg); | |
8db9d77b ZW |
3601 | udelay(150); |
3602 | ||
0206e353 | 3603 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3604 | reg = FDI_TX_CTL(pipe); |
3605 | temp = I915_READ(reg); | |
8db9d77b ZW |
3606 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3607 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3608 | I915_WRITE(reg, temp); |
3609 | ||
3610 | POSTING_READ(reg); | |
8db9d77b ZW |
3611 | udelay(500); |
3612 | ||
fa37d39e SP |
3613 | for (retry = 0; retry < 5; retry++) { |
3614 | reg = FDI_RX_IIR(pipe); | |
3615 | temp = I915_READ(reg); | |
3616 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3617 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3618 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3619 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3620 | break; | |
3621 | } | |
3622 | udelay(50); | |
8db9d77b | 3623 | } |
fa37d39e SP |
3624 | if (retry < 5) |
3625 | break; | |
8db9d77b ZW |
3626 | } |
3627 | if (i == 4) | |
5eddb70b | 3628 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3629 | |
3630 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3631 | } | |
3632 | ||
357555c0 JB |
3633 | /* Manual link training for Ivy Bridge A0 parts */ |
3634 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3635 | { | |
3636 | struct drm_device *dev = crtc->dev; | |
3637 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3638 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3639 | int pipe = intel_crtc->pipe; | |
139ccd3f | 3640 | u32 reg, temp, i, j; |
357555c0 JB |
3641 | |
3642 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3643 | for train result */ | |
3644 | reg = FDI_RX_IMR(pipe); | |
3645 | temp = I915_READ(reg); | |
3646 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3647 | temp &= ~FDI_RX_BIT_LOCK; | |
3648 | I915_WRITE(reg, temp); | |
3649 | ||
3650 | POSTING_READ(reg); | |
3651 | udelay(150); | |
3652 | ||
01a415fd DV |
3653 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3654 | I915_READ(FDI_RX_IIR(pipe))); | |
3655 | ||
139ccd3f JB |
3656 | /* Try each vswing and preemphasis setting twice before moving on */ |
3657 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3658 | /* disable first in case we need to retry */ | |
3659 | reg = FDI_TX_CTL(pipe); | |
3660 | temp = I915_READ(reg); | |
3661 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3662 | temp &= ~FDI_TX_ENABLE; | |
3663 | I915_WRITE(reg, temp); | |
357555c0 | 3664 | |
139ccd3f JB |
3665 | reg = FDI_RX_CTL(pipe); |
3666 | temp = I915_READ(reg); | |
3667 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3668 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3669 | temp &= ~FDI_RX_ENABLE; | |
3670 | I915_WRITE(reg, temp); | |
357555c0 | 3671 | |
139ccd3f | 3672 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3673 | reg = FDI_TX_CTL(pipe); |
3674 | temp = I915_READ(reg); | |
139ccd3f | 3675 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3676 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3677 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3678 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3679 | temp |= snb_b_fdi_train_param[j/2]; |
3680 | temp |= FDI_COMPOSITE_SYNC; | |
3681 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3682 | |
139ccd3f JB |
3683 | I915_WRITE(FDI_RX_MISC(pipe), |
3684 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3685 | |
139ccd3f | 3686 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3687 | temp = I915_READ(reg); |
139ccd3f JB |
3688 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3689 | temp |= FDI_COMPOSITE_SYNC; | |
3690 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3691 | |
139ccd3f JB |
3692 | POSTING_READ(reg); |
3693 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3694 | |
139ccd3f JB |
3695 | for (i = 0; i < 4; i++) { |
3696 | reg = FDI_RX_IIR(pipe); | |
3697 | temp = I915_READ(reg); | |
3698 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3699 | |
139ccd3f JB |
3700 | if (temp & FDI_RX_BIT_LOCK || |
3701 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3702 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3703 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3704 | i); | |
3705 | break; | |
3706 | } | |
3707 | udelay(1); /* should be 0.5us */ | |
3708 | } | |
3709 | if (i == 4) { | |
3710 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3711 | continue; | |
3712 | } | |
357555c0 | 3713 | |
139ccd3f | 3714 | /* Train 2 */ |
357555c0 JB |
3715 | reg = FDI_TX_CTL(pipe); |
3716 | temp = I915_READ(reg); | |
139ccd3f JB |
3717 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3718 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3719 | I915_WRITE(reg, temp); | |
3720 | ||
3721 | reg = FDI_RX_CTL(pipe); | |
3722 | temp = I915_READ(reg); | |
3723 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3724 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3725 | I915_WRITE(reg, temp); |
3726 | ||
3727 | POSTING_READ(reg); | |
139ccd3f | 3728 | udelay(2); /* should be 1.5us */ |
357555c0 | 3729 | |
139ccd3f JB |
3730 | for (i = 0; i < 4; i++) { |
3731 | reg = FDI_RX_IIR(pipe); | |
3732 | temp = I915_READ(reg); | |
3733 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3734 | |
139ccd3f JB |
3735 | if (temp & FDI_RX_SYMBOL_LOCK || |
3736 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3737 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3738 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3739 | i); | |
3740 | goto train_done; | |
3741 | } | |
3742 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3743 | } |
139ccd3f JB |
3744 | if (i == 4) |
3745 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3746 | } |
357555c0 | 3747 | |
139ccd3f | 3748 | train_done: |
357555c0 JB |
3749 | DRM_DEBUG_KMS("FDI train done.\n"); |
3750 | } | |
3751 | ||
88cefb6c | 3752 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3753 | { |
88cefb6c | 3754 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3755 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3756 | int pipe = intel_crtc->pipe; |
5eddb70b | 3757 | u32 reg, temp; |
79e53945 | 3758 | |
c64e311e | 3759 | |
c98e9dcf | 3760 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3761 | reg = FDI_RX_CTL(pipe); |
3762 | temp = I915_READ(reg); | |
627eb5a3 | 3763 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3764 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3765 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3766 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3767 | ||
3768 | POSTING_READ(reg); | |
c98e9dcf JB |
3769 | udelay(200); |
3770 | ||
3771 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3772 | temp = I915_READ(reg); |
3773 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3774 | ||
3775 | POSTING_READ(reg); | |
c98e9dcf JB |
3776 | udelay(200); |
3777 | ||
20749730 PZ |
3778 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3779 | reg = FDI_TX_CTL(pipe); | |
3780 | temp = I915_READ(reg); | |
3781 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3782 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3783 | |
20749730 PZ |
3784 | POSTING_READ(reg); |
3785 | udelay(100); | |
6be4a607 | 3786 | } |
0e23b99d JB |
3787 | } |
3788 | ||
88cefb6c DV |
3789 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3790 | { | |
3791 | struct drm_device *dev = intel_crtc->base.dev; | |
3792 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3793 | int pipe = intel_crtc->pipe; | |
3794 | u32 reg, temp; | |
3795 | ||
3796 | /* Switch from PCDclk to Rawclk */ | |
3797 | reg = FDI_RX_CTL(pipe); | |
3798 | temp = I915_READ(reg); | |
3799 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3800 | ||
3801 | /* Disable CPU FDI TX PLL */ | |
3802 | reg = FDI_TX_CTL(pipe); | |
3803 | temp = I915_READ(reg); | |
3804 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3805 | ||
3806 | POSTING_READ(reg); | |
3807 | udelay(100); | |
3808 | ||
3809 | reg = FDI_RX_CTL(pipe); | |
3810 | temp = I915_READ(reg); | |
3811 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3812 | ||
3813 | /* Wait for the clocks to turn off. */ | |
3814 | POSTING_READ(reg); | |
3815 | udelay(100); | |
3816 | } | |
3817 | ||
0fc932b8 JB |
3818 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3819 | { | |
3820 | struct drm_device *dev = crtc->dev; | |
3821 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3823 | int pipe = intel_crtc->pipe; | |
3824 | u32 reg, temp; | |
3825 | ||
3826 | /* disable CPU FDI tx and PCH FDI rx */ | |
3827 | reg = FDI_TX_CTL(pipe); | |
3828 | temp = I915_READ(reg); | |
3829 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3830 | POSTING_READ(reg); | |
3831 | ||
3832 | reg = FDI_RX_CTL(pipe); | |
3833 | temp = I915_READ(reg); | |
3834 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3835 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3836 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3837 | ||
3838 | POSTING_READ(reg); | |
3839 | udelay(100); | |
3840 | ||
3841 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3842 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3843 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3844 | |
3845 | /* still set train pattern 1 */ | |
3846 | reg = FDI_TX_CTL(pipe); | |
3847 | temp = I915_READ(reg); | |
3848 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3849 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3850 | I915_WRITE(reg, temp); | |
3851 | ||
3852 | reg = FDI_RX_CTL(pipe); | |
3853 | temp = I915_READ(reg); | |
3854 | if (HAS_PCH_CPT(dev)) { | |
3855 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3856 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3857 | } else { | |
3858 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3859 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3860 | } | |
3861 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3862 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3863 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3864 | I915_WRITE(reg, temp); |
3865 | ||
3866 | POSTING_READ(reg); | |
3867 | udelay(100); | |
3868 | } | |
3869 | ||
5dce5b93 CW |
3870 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3871 | { | |
3872 | struct intel_crtc *crtc; | |
3873 | ||
3874 | /* Note that we don't need to be called with mode_config.lock here | |
3875 | * as our list of CRTC objects is static for the lifetime of the | |
3876 | * device and so cannot disappear as we iterate. Similarly, we can | |
3877 | * happily treat the predicates as racy, atomic checks as userspace | |
3878 | * cannot claim and pin a new fb without at least acquring the | |
3879 | * struct_mutex and so serialising with us. | |
3880 | */ | |
d3fcc808 | 3881 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3882 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3883 | continue; | |
3884 | ||
3885 | if (crtc->unpin_work) | |
3886 | intel_wait_for_vblank(dev, crtc->pipe); | |
3887 | ||
3888 | return true; | |
3889 | } | |
3890 | ||
3891 | return false; | |
3892 | } | |
3893 | ||
d6bbafa1 CW |
3894 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3895 | { | |
3896 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3897 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3898 | ||
3899 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3900 | smp_rmb(); | |
3901 | intel_crtc->unpin_work = NULL; | |
3902 | ||
3903 | if (work->event) | |
3904 | drm_send_vblank_event(intel_crtc->base.dev, | |
3905 | intel_crtc->pipe, | |
3906 | work->event); | |
3907 | ||
3908 | drm_crtc_vblank_put(&intel_crtc->base); | |
3909 | ||
3910 | wake_up_all(&dev_priv->pending_flip_queue); | |
3911 | queue_work(dev_priv->wq, &work->work); | |
3912 | ||
3913 | trace_i915_flip_complete(intel_crtc->plane, | |
3914 | work->pending_flip_obj); | |
3915 | } | |
3916 | ||
46a55d30 | 3917 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3918 | { |
0f91128d | 3919 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3920 | struct drm_i915_private *dev_priv = dev->dev_private; |
e6c3a2a6 | 3921 | |
2c10d571 | 3922 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
9c787942 CW |
3923 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
3924 | !intel_crtc_has_pending_flip(crtc), | |
3925 | 60*HZ) == 0)) { | |
3926 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2c10d571 | 3927 | |
5e2d7afc | 3928 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3929 | if (intel_crtc->unpin_work) { |
3930 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3931 | page_flip_completed(intel_crtc); | |
3932 | } | |
5e2d7afc | 3933 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3934 | } |
5bb61643 | 3935 | |
975d568a CW |
3936 | if (crtc->primary->fb) { |
3937 | mutex_lock(&dev->struct_mutex); | |
3938 | intel_finish_fb(crtc->primary->fb); | |
3939 | mutex_unlock(&dev->struct_mutex); | |
3940 | } | |
e6c3a2a6 CW |
3941 | } |
3942 | ||
e615efe4 ED |
3943 | /* Program iCLKIP clock to the desired frequency */ |
3944 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3945 | { | |
3946 | struct drm_device *dev = crtc->dev; | |
3947 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3948 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3949 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3950 | u32 temp; | |
3951 | ||
09153000 DV |
3952 | mutex_lock(&dev_priv->dpio_lock); |
3953 | ||
e615efe4 ED |
3954 | /* It is necessary to ungate the pixclk gate prior to programming |
3955 | * the divisors, and gate it back when it is done. | |
3956 | */ | |
3957 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3958 | ||
3959 | /* Disable SSCCTL */ | |
3960 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3961 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3962 | SBI_SSCCTL_DISABLE, | |
3963 | SBI_ICLK); | |
e615efe4 ED |
3964 | |
3965 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3966 | if (clock == 20000) { |
e615efe4 ED |
3967 | auxdiv = 1; |
3968 | divsel = 0x41; | |
3969 | phaseinc = 0x20; | |
3970 | } else { | |
3971 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3972 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3973 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3974 | * convert the virtual clock precision to KHz here for higher |
3975 | * precision. | |
3976 | */ | |
3977 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3978 | u32 iclk_pi_range = 64; | |
3979 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3980 | ||
12d7ceed | 3981 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3982 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3983 | pi_value = desired_divisor % iclk_pi_range; | |
3984 | ||
3985 | auxdiv = 0; | |
3986 | divsel = msb_divisor_value - 2; | |
3987 | phaseinc = pi_value; | |
3988 | } | |
3989 | ||
3990 | /* This should not happen with any sane values */ | |
3991 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3992 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3993 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3994 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3995 | ||
3996 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3997 | clock, |
e615efe4 ED |
3998 | auxdiv, |
3999 | divsel, | |
4000 | phasedir, | |
4001 | phaseinc); | |
4002 | ||
4003 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 4004 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
4005 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
4006 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
4007 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
4008 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
4009 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
4010 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 4011 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
4012 | |
4013 | /* Program SSCAUXDIV */ | |
988d6ee8 | 4014 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
4015 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
4016 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 4017 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
4018 | |
4019 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4020 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4021 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4022 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
4023 | |
4024 | /* Wait for initialization time */ | |
4025 | udelay(24); | |
4026 | ||
4027 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 DV |
4028 | |
4029 | mutex_unlock(&dev_priv->dpio_lock); | |
e615efe4 ED |
4030 | } |
4031 | ||
275f01b2 DV |
4032 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4033 | enum pipe pch_transcoder) | |
4034 | { | |
4035 | struct drm_device *dev = crtc->base.dev; | |
4036 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4037 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4038 | |
4039 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4040 | I915_READ(HTOTAL(cpu_transcoder))); | |
4041 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4042 | I915_READ(HBLANK(cpu_transcoder))); | |
4043 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4044 | I915_READ(HSYNC(cpu_transcoder))); | |
4045 | ||
4046 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4047 | I915_READ(VTOTAL(cpu_transcoder))); | |
4048 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4049 | I915_READ(VBLANK(cpu_transcoder))); | |
4050 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4051 | I915_READ(VSYNC(cpu_transcoder))); | |
4052 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4053 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4054 | } | |
4055 | ||
003632d9 | 4056 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4057 | { |
4058 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4059 | uint32_t temp; | |
4060 | ||
4061 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4062 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4063 | return; |
4064 | ||
4065 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4066 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4067 | ||
003632d9 ACO |
4068 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4069 | if (enable) | |
4070 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4071 | ||
4072 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4073 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4074 | POSTING_READ(SOUTH_CHICKEN1); | |
4075 | } | |
4076 | ||
4077 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4078 | { | |
4079 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4080 | |
4081 | switch (intel_crtc->pipe) { | |
4082 | case PIPE_A: | |
4083 | break; | |
4084 | case PIPE_B: | |
6e3c9717 | 4085 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4086 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4087 | else |
003632d9 | 4088 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4089 | |
4090 | break; | |
4091 | case PIPE_C: | |
003632d9 | 4092 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4093 | |
4094 | break; | |
4095 | default: | |
4096 | BUG(); | |
4097 | } | |
4098 | } | |
4099 | ||
f67a559d JB |
4100 | /* |
4101 | * Enable PCH resources required for PCH ports: | |
4102 | * - PCH PLLs | |
4103 | * - FDI training & RX/TX | |
4104 | * - update transcoder timings | |
4105 | * - DP transcoding bits | |
4106 | * - transcoder | |
4107 | */ | |
4108 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4109 | { |
4110 | struct drm_device *dev = crtc->dev; | |
4111 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4112 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4113 | int pipe = intel_crtc->pipe; | |
ee7b9f93 | 4114 | u32 reg, temp; |
2c07245f | 4115 | |
ab9412ba | 4116 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4117 | |
1fbc0d78 DV |
4118 | if (IS_IVYBRIDGE(dev)) |
4119 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4120 | ||
cd986abb DV |
4121 | /* Write the TU size bits before fdi link training, so that error |
4122 | * detection works. */ | |
4123 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4124 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4125 | ||
c98e9dcf | 4126 | /* For PCH output, training FDI link */ |
674cf967 | 4127 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4128 | |
3ad8a208 DV |
4129 | /* We need to program the right clock selection before writing the pixel |
4130 | * mutliplier into the DPLL. */ | |
303b81e0 | 4131 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4132 | u32 sel; |
4b645f14 | 4133 | |
c98e9dcf | 4134 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4135 | temp |= TRANS_DPLL_ENABLE(pipe); |
4136 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4137 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4138 | temp |= sel; |
4139 | else | |
4140 | temp &= ~sel; | |
c98e9dcf | 4141 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4142 | } |
5eddb70b | 4143 | |
3ad8a208 DV |
4144 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4145 | * transcoder, and we actually should do this to not upset any PCH | |
4146 | * transcoder that already use the clock when we share it. | |
4147 | * | |
4148 | * Note that enable_shared_dpll tries to do the right thing, but | |
4149 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4150 | * the right LVDS enable sequence. */ | |
85b3894f | 4151 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4152 | |
d9b6cb56 JB |
4153 | /* set transcoder timing, panel must allow it */ |
4154 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4155 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4156 | |
303b81e0 | 4157 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4158 | |
c98e9dcf | 4159 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4160 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
dfd07d72 | 4161 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
5eddb70b CW |
4162 | reg = TRANS_DP_CTL(pipe); |
4163 | temp = I915_READ(reg); | |
4164 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4165 | TRANS_DP_SYNC_MASK | |
4166 | TRANS_DP_BPC_MASK); | |
5eddb70b CW |
4167 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
4168 | TRANS_DP_ENH_FRAMING); | |
9325c9f0 | 4169 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf JB |
4170 | |
4171 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) | |
5eddb70b | 4172 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
c98e9dcf | 4173 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4174 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4175 | |
4176 | switch (intel_trans_dp_port_sel(crtc)) { | |
4177 | case PCH_DP_B: | |
5eddb70b | 4178 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf JB |
4179 | break; |
4180 | case PCH_DP_C: | |
5eddb70b | 4181 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf JB |
4182 | break; |
4183 | case PCH_DP_D: | |
5eddb70b | 4184 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4185 | break; |
4186 | default: | |
e95d41e1 | 4187 | BUG(); |
32f9d658 | 4188 | } |
2c07245f | 4189 | |
5eddb70b | 4190 | I915_WRITE(reg, temp); |
6be4a607 | 4191 | } |
b52eb4dc | 4192 | |
b8a4f404 | 4193 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4194 | } |
4195 | ||
1507e5bd PZ |
4196 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4197 | { | |
4198 | struct drm_device *dev = crtc->dev; | |
4199 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4200 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4201 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4202 | |
ab9412ba | 4203 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4204 | |
8c52b5e8 | 4205 | lpt_program_iclkip(crtc); |
1507e5bd | 4206 | |
0540e488 | 4207 | /* Set transcoder timing. */ |
275f01b2 | 4208 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4209 | |
937bb610 | 4210 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4211 | } |
4212 | ||
716c2e55 | 4213 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
ee7b9f93 | 4214 | { |
e2b78267 | 4215 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
ee7b9f93 JB |
4216 | |
4217 | if (pll == NULL) | |
4218 | return; | |
4219 | ||
3e369b76 | 4220 | if (!(pll->config.crtc_mask & (1 << crtc->pipe))) { |
1e6f2ddc | 4221 | WARN(1, "bad %s crtc mask\n", pll->name); |
ee7b9f93 JB |
4222 | return; |
4223 | } | |
4224 | ||
3e369b76 ACO |
4225 | pll->config.crtc_mask &= ~(1 << crtc->pipe); |
4226 | if (pll->config.crtc_mask == 0) { | |
f4a091c7 DV |
4227 | WARN_ON(pll->on); |
4228 | WARN_ON(pll->active); | |
4229 | } | |
4230 | ||
6e3c9717 | 4231 | crtc->config->shared_dpll = DPLL_ID_PRIVATE; |
ee7b9f93 JB |
4232 | } |
4233 | ||
190f68c5 ACO |
4234 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4235 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4236 | { |
e2b78267 | 4237 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4238 | struct intel_shared_dpll *pll; |
e2b78267 | 4239 | enum intel_dpll_id i; |
ee7b9f93 | 4240 | |
98b6bd99 DV |
4241 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4242 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4243 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4244 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4245 | |
46edb027 DV |
4246 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4247 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4248 | |
8bd31e67 | 4249 | WARN_ON(pll->new_config->crtc_mask); |
f2a69f44 | 4250 | |
98b6bd99 DV |
4251 | goto found; |
4252 | } | |
4253 | ||
bcddf610 S |
4254 | if (IS_BROXTON(dev_priv->dev)) { |
4255 | /* PLL is attached to port in bxt */ | |
4256 | struct intel_encoder *encoder; | |
4257 | struct intel_digital_port *intel_dig_port; | |
4258 | ||
4259 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4260 | if (WARN_ON(!encoder)) | |
4261 | return NULL; | |
4262 | ||
4263 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4264 | /* 1:1 mapping between ports and PLLs */ | |
4265 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4266 | pll = &dev_priv->shared_dplls[i]; | |
4267 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4268 | crtc->base.base.id, pll->name); | |
4269 | WARN_ON(pll->new_config->crtc_mask); | |
4270 | ||
4271 | goto found; | |
4272 | } | |
4273 | ||
e72f9fbf DV |
4274 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4275 | pll = &dev_priv->shared_dplls[i]; | |
ee7b9f93 JB |
4276 | |
4277 | /* Only want to check enabled timings first */ | |
8bd31e67 | 4278 | if (pll->new_config->crtc_mask == 0) |
ee7b9f93 JB |
4279 | continue; |
4280 | ||
190f68c5 | 4281 | if (memcmp(&crtc_state->dpll_hw_state, |
8bd31e67 ACO |
4282 | &pll->new_config->hw_state, |
4283 | sizeof(pll->new_config->hw_state)) == 0) { | |
4284 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", | |
1e6f2ddc | 4285 | crtc->base.base.id, pll->name, |
8bd31e67 ACO |
4286 | pll->new_config->crtc_mask, |
4287 | pll->active); | |
ee7b9f93 JB |
4288 | goto found; |
4289 | } | |
4290 | } | |
4291 | ||
4292 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4293 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4294 | pll = &dev_priv->shared_dplls[i]; | |
8bd31e67 | 4295 | if (pll->new_config->crtc_mask == 0) { |
46edb027 DV |
4296 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4297 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4298 | goto found; |
4299 | } | |
4300 | } | |
4301 | ||
4302 | return NULL; | |
4303 | ||
4304 | found: | |
8bd31e67 | 4305 | if (pll->new_config->crtc_mask == 0) |
190f68c5 | 4306 | pll->new_config->hw_state = crtc_state->dpll_hw_state; |
f2a69f44 | 4307 | |
190f68c5 | 4308 | crtc_state->shared_dpll = i; |
46edb027 DV |
4309 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4310 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4311 | |
8bd31e67 | 4312 | pll->new_config->crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4313 | |
ee7b9f93 JB |
4314 | return pll; |
4315 | } | |
4316 | ||
8bd31e67 ACO |
4317 | /** |
4318 | * intel_shared_dpll_start_config - start a new PLL staged config | |
4319 | * @dev_priv: DRM device | |
4320 | * @clear_pipes: mask of pipes that will have their PLLs freed | |
4321 | * | |
4322 | * Starts a new PLL staged config, copying the current config but | |
4323 | * releasing the references of pipes specified in clear_pipes. | |
4324 | */ | |
4325 | static int intel_shared_dpll_start_config(struct drm_i915_private *dev_priv, | |
4326 | unsigned clear_pipes) | |
4327 | { | |
4328 | struct intel_shared_dpll *pll; | |
4329 | enum intel_dpll_id i; | |
4330 | ||
4331 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
4332 | pll = &dev_priv->shared_dplls[i]; | |
4333 | ||
4334 | pll->new_config = kmemdup(&pll->config, sizeof pll->config, | |
4335 | GFP_KERNEL); | |
4336 | if (!pll->new_config) | |
4337 | goto cleanup; | |
4338 | ||
4339 | pll->new_config->crtc_mask &= ~clear_pipes; | |
4340 | } | |
4341 | ||
4342 | return 0; | |
4343 | ||
4344 | cleanup: | |
4345 | while (--i >= 0) { | |
4346 | pll = &dev_priv->shared_dplls[i]; | |
f354d733 | 4347 | kfree(pll->new_config); |
8bd31e67 ACO |
4348 | pll->new_config = NULL; |
4349 | } | |
4350 | ||
4351 | return -ENOMEM; | |
4352 | } | |
4353 | ||
4354 | static void intel_shared_dpll_commit(struct drm_i915_private *dev_priv) | |
4355 | { | |
4356 | struct intel_shared_dpll *pll; | |
4357 | enum intel_dpll_id i; | |
4358 | ||
4359 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
4360 | pll = &dev_priv->shared_dplls[i]; | |
4361 | ||
4362 | WARN_ON(pll->new_config == &pll->config); | |
4363 | ||
4364 | pll->config = *pll->new_config; | |
4365 | kfree(pll->new_config); | |
4366 | pll->new_config = NULL; | |
4367 | } | |
4368 | } | |
4369 | ||
4370 | static void intel_shared_dpll_abort_config(struct drm_i915_private *dev_priv) | |
4371 | { | |
4372 | struct intel_shared_dpll *pll; | |
4373 | enum intel_dpll_id i; | |
4374 | ||
4375 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
4376 | pll = &dev_priv->shared_dplls[i]; | |
4377 | ||
4378 | WARN_ON(pll->new_config == &pll->config); | |
4379 | ||
4380 | kfree(pll->new_config); | |
4381 | pll->new_config = NULL; | |
4382 | } | |
4383 | } | |
4384 | ||
a1520318 | 4385 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4386 | { |
4387 | struct drm_i915_private *dev_priv = dev->dev_private; | |
23670b32 | 4388 | int dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4389 | u32 temp; |
4390 | ||
4391 | temp = I915_READ(dslreg); | |
4392 | udelay(500); | |
4393 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4394 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4395 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4396 | } |
4397 | } | |
4398 | ||
a1b2278e CK |
4399 | /** |
4400 | * skl_update_scaler_users - Stages update to crtc's scaler state | |
4401 | * @intel_crtc: crtc | |
4402 | * @crtc_state: crtc_state | |
4403 | * @plane: plane (NULL indicates crtc is requesting update) | |
4404 | * @plane_state: plane's state | |
4405 | * @force_detach: request unconditional detachment of scaler | |
4406 | * | |
4407 | * This function updates scaler state for requested plane or crtc. | |
4408 | * To request scaler usage update for a plane, caller shall pass plane pointer. | |
4409 | * To request scaler usage update for crtc, caller shall pass plane pointer | |
4410 | * as NULL. | |
4411 | * | |
4412 | * Return | |
4413 | * 0 - scaler_usage updated successfully | |
4414 | * error - requested scaling cannot be supported or other error condition | |
4415 | */ | |
4416 | int | |
4417 | skl_update_scaler_users( | |
4418 | struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state, | |
4419 | struct intel_plane *intel_plane, struct intel_plane_state *plane_state, | |
4420 | int force_detach) | |
4421 | { | |
4422 | int need_scaling; | |
4423 | int idx; | |
4424 | int src_w, src_h, dst_w, dst_h; | |
4425 | int *scaler_id; | |
4426 | struct drm_framebuffer *fb; | |
4427 | struct intel_crtc_scaler_state *scaler_state; | |
6156a456 | 4428 | unsigned int rotation; |
a1b2278e CK |
4429 | |
4430 | if (!intel_crtc || !crtc_state) | |
4431 | return 0; | |
4432 | ||
4433 | scaler_state = &crtc_state->scaler_state; | |
4434 | ||
4435 | idx = intel_plane ? drm_plane_index(&intel_plane->base) : SKL_CRTC_INDEX; | |
4436 | fb = intel_plane ? plane_state->base.fb : NULL; | |
4437 | ||
4438 | if (intel_plane) { | |
4439 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
4440 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
4441 | dst_w = drm_rect_width(&plane_state->dst); | |
4442 | dst_h = drm_rect_height(&plane_state->dst); | |
4443 | scaler_id = &plane_state->scaler_id; | |
6156a456 | 4444 | rotation = plane_state->base.rotation; |
a1b2278e CK |
4445 | } else { |
4446 | struct drm_display_mode *adjusted_mode = | |
4447 | &crtc_state->base.adjusted_mode; | |
4448 | src_w = crtc_state->pipe_src_w; | |
4449 | src_h = crtc_state->pipe_src_h; | |
4450 | dst_w = adjusted_mode->hdisplay; | |
4451 | dst_h = adjusted_mode->vdisplay; | |
4452 | scaler_id = &scaler_state->scaler_id; | |
6156a456 | 4453 | rotation = DRM_ROTATE_0; |
a1b2278e | 4454 | } |
6156a456 CK |
4455 | |
4456 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4457 | (src_h != dst_w || src_w != dst_h): | |
4458 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4459 | |
4460 | /* | |
4461 | * if plane is being disabled or scaler is no more required or force detach | |
4462 | * - free scaler binded to this plane/crtc | |
4463 | * - in order to do this, update crtc->scaler_usage | |
4464 | * | |
4465 | * Here scaler state in crtc_state is set free so that | |
4466 | * scaler can be assigned to other user. Actual register | |
4467 | * update to free the scaler is done in plane/panel-fit programming. | |
4468 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4469 | */ | |
4470 | if (force_detach || !need_scaling || (intel_plane && | |
4471 | (!fb || !plane_state->visible))) { | |
4472 | if (*scaler_id >= 0) { | |
4473 | scaler_state->scaler_users &= ~(1 << idx); | |
4474 | scaler_state->scalers[*scaler_id].in_use = 0; | |
4475 | ||
4476 | DRM_DEBUG_KMS("Staged freeing scaler id %d.%d from %s:%d " | |
4477 | "crtc_state = %p scaler_users = 0x%x\n", | |
4478 | intel_crtc->pipe, *scaler_id, intel_plane ? "PLANE" : "CRTC", | |
4479 | intel_plane ? intel_plane->base.base.id : | |
4480 | intel_crtc->base.base.id, crtc_state, | |
4481 | scaler_state->scaler_users); | |
4482 | *scaler_id = -1; | |
4483 | } | |
4484 | return 0; | |
4485 | } | |
4486 | ||
4487 | /* range checks */ | |
4488 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4489 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4490 | ||
4491 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4492 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
4493 | DRM_DEBUG_KMS("%s:%d scaler_user index %u.%u: src %ux%u dst %ux%u " | |
4494 | "size is out of scaler range\n", | |
4495 | intel_plane ? "PLANE" : "CRTC", | |
4496 | intel_plane ? intel_plane->base.base.id : intel_crtc->base.base.id, | |
4497 | intel_crtc->pipe, idx, src_w, src_h, dst_w, dst_h); | |
4498 | return -EINVAL; | |
4499 | } | |
4500 | ||
4501 | /* check colorkey */ | |
4502 | if (intel_plane && intel_plane->ckey.flags != I915_SET_COLORKEY_NONE) { | |
4503 | DRM_DEBUG_KMS("PLANE:%d scaling with color key not allowed", | |
4504 | intel_plane->base.base.id); | |
4505 | return -EINVAL; | |
4506 | } | |
4507 | ||
4508 | /* Check src format */ | |
4509 | if (intel_plane) { | |
4510 | switch (fb->pixel_format) { | |
4511 | case DRM_FORMAT_RGB565: | |
4512 | case DRM_FORMAT_XBGR8888: | |
4513 | case DRM_FORMAT_XRGB8888: | |
4514 | case DRM_FORMAT_ABGR8888: | |
4515 | case DRM_FORMAT_ARGB8888: | |
4516 | case DRM_FORMAT_XRGB2101010: | |
a1b2278e | 4517 | case DRM_FORMAT_XBGR2101010: |
a1b2278e CK |
4518 | case DRM_FORMAT_YUYV: |
4519 | case DRM_FORMAT_YVYU: | |
4520 | case DRM_FORMAT_UYVY: | |
4521 | case DRM_FORMAT_VYUY: | |
4522 | break; | |
4523 | default: | |
4524 | DRM_DEBUG_KMS("PLANE:%d FB:%d unsupported scaling format 0x%x\n", | |
4525 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4526 | return -EINVAL; | |
4527 | } | |
4528 | } | |
4529 | ||
4530 | /* mark this plane as a scaler user in crtc_state */ | |
4531 | scaler_state->scaler_users |= (1 << idx); | |
4532 | DRM_DEBUG_KMS("%s:%d staged scaling request for %ux%u->%ux%u " | |
4533 | "crtc_state = %p scaler_users = 0x%x\n", | |
4534 | intel_plane ? "PLANE" : "CRTC", | |
4535 | intel_plane ? intel_plane->base.base.id : intel_crtc->base.base.id, | |
4536 | src_w, src_h, dst_w, dst_h, crtc_state, scaler_state->scaler_users); | |
4537 | return 0; | |
4538 | } | |
4539 | ||
4540 | static void skylake_pfit_update(struct intel_crtc *crtc, int enable) | |
bd2e244f JB |
4541 | { |
4542 | struct drm_device *dev = crtc->base.dev; | |
4543 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4544 | int pipe = crtc->pipe; | |
a1b2278e CK |
4545 | struct intel_crtc_scaler_state *scaler_state = |
4546 | &crtc->config->scaler_state; | |
4547 | ||
4548 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4549 | ||
4550 | /* To update pfit, first update scaler state */ | |
4551 | skl_update_scaler_users(crtc, crtc->config, NULL, NULL, !enable); | |
4552 | intel_atomic_setup_scalers(crtc->base.dev, crtc, crtc->config); | |
4553 | skl_detach_scalers(crtc); | |
4554 | if (!enable) | |
4555 | return; | |
bd2e244f | 4556 | |
6e3c9717 | 4557 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4558 | int id; |
4559 | ||
4560 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4561 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4562 | return; | |
4563 | } | |
4564 | ||
4565 | id = scaler_state->scaler_id; | |
4566 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4567 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4568 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4569 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4570 | ||
4571 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4572 | } |
4573 | } | |
4574 | ||
b074cec8 JB |
4575 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4576 | { | |
4577 | struct drm_device *dev = crtc->base.dev; | |
4578 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4579 | int pipe = crtc->pipe; | |
4580 | ||
6e3c9717 | 4581 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4582 | /* Force use of hard-coded filter coefficients |
4583 | * as some pre-programmed values are broken, | |
4584 | * e.g. x201. | |
4585 | */ | |
4586 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4587 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4588 | PF_PIPE_SEL_IVB(pipe)); | |
4589 | else | |
4590 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4591 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4592 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4593 | } |
4594 | } | |
4595 | ||
4a3b8769 | 4596 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
bb53d4ae VS |
4597 | { |
4598 | struct drm_device *dev = crtc->dev; | |
4599 | enum pipe pipe = to_intel_crtc(crtc)->pipe; | |
af2b653b | 4600 | struct drm_plane *plane; |
bb53d4ae VS |
4601 | struct intel_plane *intel_plane; |
4602 | ||
af2b653b MR |
4603 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
4604 | intel_plane = to_intel_plane(plane); | |
bb53d4ae VS |
4605 | if (intel_plane->pipe == pipe) |
4606 | intel_plane_restore(&intel_plane->base); | |
af2b653b | 4607 | } |
bb53d4ae VS |
4608 | } |
4609 | ||
20bc8673 | 4610 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4611 | { |
cea165c3 VS |
4612 | struct drm_device *dev = crtc->base.dev; |
4613 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4614 | |
6e3c9717 | 4615 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4616 | return; |
4617 | ||
cea165c3 VS |
4618 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4619 | intel_wait_for_vblank(dev, crtc->pipe); | |
4620 | ||
d77e4531 | 4621 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4622 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4623 | mutex_lock(&dev_priv->rps.hw_lock); |
4624 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4625 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4626 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4627 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4628 | * mailbox." Moreover, the mailbox may return a bogus state, |
4629 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4630 | */ |
4631 | } else { | |
4632 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4633 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4634 | * is essentially intel_wait_for_vblank. If we don't have this | |
4635 | * and don't wait for vblanks until the end of crtc_enable, then | |
4636 | * the HW state readout code will complain that the expected | |
4637 | * IPS_CTL value is not the one we read. */ | |
4638 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4639 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4640 | } | |
d77e4531 PZ |
4641 | } |
4642 | ||
20bc8673 | 4643 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4644 | { |
4645 | struct drm_device *dev = crtc->base.dev; | |
4646 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4647 | ||
6e3c9717 | 4648 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4649 | return; |
4650 | ||
4651 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4652 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4653 | mutex_lock(&dev_priv->rps.hw_lock); |
4654 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4655 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4656 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4657 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4658 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4659 | } else { |
2a114cc1 | 4660 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4661 | POSTING_READ(IPS_CTL); |
4662 | } | |
d77e4531 PZ |
4663 | |
4664 | /* We need to wait for a vblank before we can disable the plane. */ | |
4665 | intel_wait_for_vblank(dev, crtc->pipe); | |
4666 | } | |
4667 | ||
4668 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4669 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4670 | { | |
4671 | struct drm_device *dev = crtc->dev; | |
4672 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4673 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4674 | enum pipe pipe = intel_crtc->pipe; | |
4675 | int palreg = PALETTE(pipe); | |
4676 | int i; | |
4677 | bool reenable_ips = false; | |
4678 | ||
4679 | /* The clocks have to be on to load the palette. */ | |
83d65738 | 4680 | if (!crtc->state->enable || !intel_crtc->active) |
d77e4531 PZ |
4681 | return; |
4682 | ||
50360403 | 4683 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
409ee761 | 4684 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
d77e4531 PZ |
4685 | assert_dsi_pll_enabled(dev_priv); |
4686 | else | |
4687 | assert_pll_enabled(dev_priv, pipe); | |
4688 | } | |
4689 | ||
4690 | /* use legacy palette for Ironlake */ | |
7a1db49a | 4691 | if (!HAS_GMCH_DISPLAY(dev)) |
d77e4531 PZ |
4692 | palreg = LGC_PALETTE(pipe); |
4693 | ||
4694 | /* Workaround : Do not read or write the pipe palette/gamma data while | |
4695 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4696 | */ | |
6e3c9717 | 4697 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4698 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4699 | GAMMA_MODE_MODE_SPLIT)) { | |
4700 | hsw_disable_ips(intel_crtc); | |
4701 | reenable_ips = true; | |
4702 | } | |
4703 | ||
4704 | for (i = 0; i < 256; i++) { | |
4705 | I915_WRITE(palreg + 4 * i, | |
4706 | (intel_crtc->lut_r[i] << 16) | | |
4707 | (intel_crtc->lut_g[i] << 8) | | |
4708 | intel_crtc->lut_b[i]); | |
4709 | } | |
4710 | ||
4711 | if (reenable_ips) | |
4712 | hsw_enable_ips(intel_crtc); | |
4713 | } | |
4714 | ||
7cac945f | 4715 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4716 | { |
7cac945f | 4717 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4718 | struct drm_device *dev = intel_crtc->base.dev; |
4719 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4720 | ||
4721 | mutex_lock(&dev->struct_mutex); | |
4722 | dev_priv->mm.interruptible = false; | |
4723 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4724 | dev_priv->mm.interruptible = true; | |
4725 | mutex_unlock(&dev->struct_mutex); | |
4726 | } | |
4727 | ||
4728 | /* Let userspace switch the overlay on again. In most cases userspace | |
4729 | * has to recompute where to put it anyway. | |
4730 | */ | |
4731 | } | |
4732 | ||
87d4300a ML |
4733 | /** |
4734 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4735 | * @crtc: the CRTC whose primary plane was just enabled | |
4736 | * | |
4737 | * Performs potentially sleeping operations that must be done after the primary | |
4738 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4739 | * called due to an explicit primary plane update, or due to an implicit | |
4740 | * re-enable that is caused when a sprite plane is updated to no longer | |
4741 | * completely hide the primary plane. | |
4742 | */ | |
4743 | static void | |
4744 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4745 | { |
4746 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4747 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4748 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4749 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4750 | |
87d4300a ML |
4751 | /* |
4752 | * BDW signals flip done immediately if the plane | |
4753 | * is disabled, even if the plane enable is already | |
4754 | * armed to occur at the next vblank :( | |
4755 | */ | |
4756 | if (IS_BROADWELL(dev)) | |
4757 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4758 | |
87d4300a ML |
4759 | /* |
4760 | * FIXME IPS should be fine as long as one plane is | |
4761 | * enabled, but in practice it seems to have problems | |
4762 | * when going from primary only to sprite only and vice | |
4763 | * versa. | |
4764 | */ | |
a5c4d7bc VS |
4765 | hsw_enable_ips(intel_crtc); |
4766 | ||
4767 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 4768 | intel_fbc_update(dev); |
a5c4d7bc | 4769 | mutex_unlock(&dev->struct_mutex); |
f99d7069 DV |
4770 | |
4771 | /* | |
87d4300a ML |
4772 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4773 | * So don't enable underrun reporting before at least some planes | |
4774 | * are enabled. | |
4775 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4776 | * but leave the pipe running. | |
f99d7069 | 4777 | */ |
87d4300a ML |
4778 | if (IS_GEN2(dev)) |
4779 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4780 | ||
4781 | /* Underruns don't raise interrupts, so check manually. */ | |
4782 | if (HAS_GMCH_DISPLAY(dev)) | |
4783 | i9xx_check_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4784 | } |
4785 | ||
87d4300a ML |
4786 | /** |
4787 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4788 | * @crtc: the CRTC whose primary plane is to be disabled | |
4789 | * | |
4790 | * Performs potentially sleeping operations that must be done before the | |
4791 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4792 | * be called due to an explicit primary plane update, or due to an implicit | |
4793 | * disable that is caused when a sprite plane completely hides the primary | |
4794 | * plane. | |
4795 | */ | |
4796 | static void | |
4797 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4798 | { |
4799 | struct drm_device *dev = crtc->dev; | |
4800 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4801 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4802 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4803 | |
87d4300a ML |
4804 | /* |
4805 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4806 | * So diasble underrun reporting before all the planes get disabled. | |
4807 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4808 | * but leave the pipe running. | |
4809 | */ | |
4810 | if (IS_GEN2(dev)) | |
4811 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4812 | |
87d4300a ML |
4813 | /* |
4814 | * Vblank time updates from the shadow to live plane control register | |
4815 | * are blocked if the memory self-refresh mode is active at that | |
4816 | * moment. So to make sure the plane gets truly disabled, disable | |
4817 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4818 | * will be checked/applied by the HW only at the next frame start | |
4819 | * event which is after the vblank start event, so we need to have a | |
4820 | * wait-for-vblank between disabling the plane and the pipe. | |
4821 | */ | |
4822 | if (HAS_GMCH_DISPLAY(dev)) | |
4823 | intel_set_memory_cxsr(dev_priv, false); | |
4824 | ||
4825 | mutex_lock(&dev->struct_mutex); | |
e35fef21 | 4826 | if (dev_priv->fbc.crtc == intel_crtc) |
7ff0ebcc | 4827 | intel_fbc_disable(dev); |
87d4300a | 4828 | mutex_unlock(&dev->struct_mutex); |
a5c4d7bc | 4829 | |
87d4300a ML |
4830 | /* |
4831 | * FIXME IPS should be fine as long as one plane is | |
4832 | * enabled, but in practice it seems to have problems | |
4833 | * when going from primary only to sprite only and vice | |
4834 | * versa. | |
4835 | */ | |
a5c4d7bc | 4836 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4837 | } |
4838 | ||
4839 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) | |
4840 | { | |
87d4300a ML |
4841 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
4842 | intel_enable_sprite_planes(crtc); | |
4843 | intel_crtc_update_cursor(crtc, true); | |
87d4300a ML |
4844 | |
4845 | intel_post_enable_primary(crtc); | |
4846 | } | |
4847 | ||
4848 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) | |
4849 | { | |
4850 | struct drm_device *dev = crtc->dev; | |
4851 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4852 | struct intel_plane *intel_plane; | |
4853 | int pipe = intel_crtc->pipe; | |
4854 | ||
4855 | intel_crtc_wait_for_pending_flips(crtc); | |
4856 | ||
4857 | intel_pre_disable_primary(crtc); | |
a5c4d7bc | 4858 | |
7cac945f | 4859 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 ML |
4860 | for_each_intel_plane(dev, intel_plane) { |
4861 | if (intel_plane->pipe == pipe) { | |
4862 | struct drm_crtc *from = intel_plane->base.crtc; | |
4863 | ||
4864 | intel_plane->disable_plane(&intel_plane->base, | |
4865 | from ?: crtc, true); | |
4866 | } | |
4867 | } | |
f98551ae | 4868 | |
f99d7069 DV |
4869 | /* |
4870 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4871 | * to compute the mask of flip planes precisely. For the time being | |
4872 | * consider this a flip to a NULL plane. | |
4873 | */ | |
4874 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4875 | } |
4876 | ||
f67a559d JB |
4877 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4878 | { | |
4879 | struct drm_device *dev = crtc->dev; | |
4880 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4881 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4882 | struct intel_encoder *encoder; |
f67a559d | 4883 | int pipe = intel_crtc->pipe; |
f67a559d | 4884 | |
83d65738 | 4885 | WARN_ON(!crtc->state->enable); |
08a48469 | 4886 | |
f67a559d JB |
4887 | if (intel_crtc->active) |
4888 | return; | |
4889 | ||
6e3c9717 | 4890 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4891 | intel_prepare_shared_dpll(intel_crtc); |
4892 | ||
6e3c9717 | 4893 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4894 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4895 | |
4896 | intel_set_pipe_timings(intel_crtc); | |
4897 | ||
6e3c9717 | 4898 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4899 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4900 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4901 | } |
4902 | ||
4903 | ironlake_set_pipeconf(crtc); | |
4904 | ||
f67a559d | 4905 | intel_crtc->active = true; |
8664281b | 4906 | |
a72e4c9f DV |
4907 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4908 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
8664281b | 4909 | |
f6736a1a | 4910 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4911 | if (encoder->pre_enable) |
4912 | encoder->pre_enable(encoder); | |
f67a559d | 4913 | |
6e3c9717 | 4914 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4915 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4916 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4917 | * enabling. */ | |
88cefb6c | 4918 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4919 | } else { |
4920 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4921 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4922 | } | |
f67a559d | 4923 | |
b074cec8 | 4924 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4925 | |
9c54c0dd JB |
4926 | /* |
4927 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4928 | * clocks enabled | |
4929 | */ | |
4930 | intel_crtc_load_lut(crtc); | |
4931 | ||
f37fcc2a | 4932 | intel_update_watermarks(crtc); |
e1fdc473 | 4933 | intel_enable_pipe(intel_crtc); |
f67a559d | 4934 | |
6e3c9717 | 4935 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4936 | ironlake_pch_enable(crtc); |
c98e9dcf | 4937 | |
f9b61ff6 DV |
4938 | assert_vblank_disabled(crtc); |
4939 | drm_crtc_vblank_on(crtc); | |
4940 | ||
fa5c73b1 DV |
4941 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4942 | encoder->enable(encoder); | |
61b77ddd DV |
4943 | |
4944 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4945 | cpt_verify_modeset(dev, intel_crtc->pipe); |
6be4a607 JB |
4946 | } |
4947 | ||
42db64ef PZ |
4948 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4949 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4950 | { | |
f5adf94e | 4951 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4952 | } |
4953 | ||
e4916946 PZ |
4954 | /* |
4955 | * This implements the workaround described in the "notes" section of the mode | |
4956 | * set sequence documentation. When going from no pipes or single pipe to | |
4957 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
4958 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
4959 | */ | |
4960 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) | |
4961 | { | |
4962 | struct drm_device *dev = crtc->base.dev; | |
4963 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; | |
4964 | ||
4965 | /* We want to get the other_active_crtc only if there's only 1 other | |
4966 | * active crtc. */ | |
d3fcc808 | 4967 | for_each_intel_crtc(dev, crtc_it) { |
e4916946 PZ |
4968 | if (!crtc_it->active || crtc_it == crtc) |
4969 | continue; | |
4970 | ||
4971 | if (other_active_crtc) | |
4972 | return; | |
4973 | ||
4974 | other_active_crtc = crtc_it; | |
4975 | } | |
4976 | if (!other_active_crtc) | |
4977 | return; | |
4978 | ||
4979 | intel_wait_for_vblank(dev, other_active_crtc->pipe); | |
4980 | intel_wait_for_vblank(dev, other_active_crtc->pipe); | |
4981 | } | |
4982 | ||
4f771f10 PZ |
4983 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4984 | { | |
4985 | struct drm_device *dev = crtc->dev; | |
4986 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4987 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4988 | struct intel_encoder *encoder; | |
4989 | int pipe = intel_crtc->pipe; | |
4f771f10 | 4990 | |
83d65738 | 4991 | WARN_ON(!crtc->state->enable); |
4f771f10 PZ |
4992 | |
4993 | if (intel_crtc->active) | |
4994 | return; | |
4995 | ||
df8ad70c DV |
4996 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4997 | intel_enable_shared_dpll(intel_crtc); | |
4998 | ||
6e3c9717 | 4999 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 5000 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
5001 | |
5002 | intel_set_pipe_timings(intel_crtc); | |
5003 | ||
6e3c9717 ACO |
5004 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
5005 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
5006 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
5007 | } |
5008 | ||
6e3c9717 | 5009 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 5010 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 5011 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
5012 | } |
5013 | ||
5014 | haswell_set_pipeconf(crtc); | |
5015 | ||
5016 | intel_set_pipe_csc(crtc); | |
5017 | ||
4f771f10 | 5018 | intel_crtc->active = true; |
8664281b | 5019 | |
a72e4c9f | 5020 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4f771f10 PZ |
5021 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5022 | if (encoder->pre_enable) | |
5023 | encoder->pre_enable(encoder); | |
5024 | ||
6e3c9717 | 5025 | if (intel_crtc->config->has_pch_encoder) { |
a72e4c9f DV |
5026 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5027 | true); | |
4fe9467d ID |
5028 | dev_priv->display.fdi_link_train(crtc); |
5029 | } | |
5030 | ||
1f544388 | 5031 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 5032 | |
ff6d9f55 | 5033 | if (INTEL_INFO(dev)->gen == 9) |
a1b2278e | 5034 | skylake_pfit_update(intel_crtc, 1); |
ff6d9f55 | 5035 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 5036 | ironlake_pfit_enable(intel_crtc); |
ff6d9f55 JB |
5037 | else |
5038 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 PZ |
5039 | |
5040 | /* | |
5041 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5042 | * clocks enabled | |
5043 | */ | |
5044 | intel_crtc_load_lut(crtc); | |
5045 | ||
1f544388 | 5046 | intel_ddi_set_pipe_settings(crtc); |
8228c251 | 5047 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 5048 | |
f37fcc2a | 5049 | intel_update_watermarks(crtc); |
e1fdc473 | 5050 | intel_enable_pipe(intel_crtc); |
42db64ef | 5051 | |
6e3c9717 | 5052 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 5053 | lpt_pch_enable(crtc); |
4f771f10 | 5054 | |
6e3c9717 | 5055 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
5056 | intel_ddi_set_vc_payload_alloc(crtc, true); |
5057 | ||
f9b61ff6 DV |
5058 | assert_vblank_disabled(crtc); |
5059 | drm_crtc_vblank_on(crtc); | |
5060 | ||
8807e55b | 5061 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 5062 | encoder->enable(encoder); |
8807e55b JN |
5063 | intel_opregion_notify_encoder(encoder, true); |
5064 | } | |
4f771f10 | 5065 | |
e4916946 PZ |
5066 | /* If we change the relative order between pipe/planes enabling, we need |
5067 | * to change the workaround. */ | |
5068 | haswell_mode_set_planes_workaround(intel_crtc); | |
4f771f10 PZ |
5069 | } |
5070 | ||
3f8dce3a DV |
5071 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
5072 | { | |
5073 | struct drm_device *dev = crtc->base.dev; | |
5074 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5075 | int pipe = crtc->pipe; | |
5076 | ||
5077 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5078 | * it's in use. The hw state code will make sure we get this right. */ | |
6e3c9717 | 5079 | if (crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5080 | I915_WRITE(PF_CTL(pipe), 0); |
5081 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5082 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5083 | } | |
5084 | } | |
5085 | ||
6be4a607 JB |
5086 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
5087 | { | |
5088 | struct drm_device *dev = crtc->dev; | |
5089 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5090 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5091 | struct intel_encoder *encoder; |
6be4a607 | 5092 | int pipe = intel_crtc->pipe; |
5eddb70b | 5093 | u32 reg, temp; |
b52eb4dc | 5094 | |
f7abfe8b CW |
5095 | if (!intel_crtc->active) |
5096 | return; | |
5097 | ||
ea9d758d DV |
5098 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5099 | encoder->disable(encoder); | |
5100 | ||
f9b61ff6 DV |
5101 | drm_crtc_vblank_off(crtc); |
5102 | assert_vblank_disabled(crtc); | |
5103 | ||
6e3c9717 | 5104 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f | 5105 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
d925c59a | 5106 | |
575f7ab7 | 5107 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5108 | |
3f8dce3a | 5109 | ironlake_pfit_disable(intel_crtc); |
2c07245f | 5110 | |
bf49ec8c DV |
5111 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5112 | if (encoder->post_disable) | |
5113 | encoder->post_disable(encoder); | |
2c07245f | 5114 | |
6e3c9717 | 5115 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5116 | ironlake_fdi_disable(crtc); |
913d8d11 | 5117 | |
d925c59a | 5118 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5119 | |
d925c59a DV |
5120 | if (HAS_PCH_CPT(dev)) { |
5121 | /* disable TRANS_DP_CTL */ | |
5122 | reg = TRANS_DP_CTL(pipe); | |
5123 | temp = I915_READ(reg); | |
5124 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5125 | TRANS_DP_PORT_SEL_MASK); | |
5126 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5127 | I915_WRITE(reg, temp); | |
5128 | ||
5129 | /* disable DPLL_SEL */ | |
5130 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5131 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5132 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5133 | } |
e3421a18 | 5134 | |
d925c59a | 5135 | /* disable PCH DPLL */ |
e72f9fbf | 5136 | intel_disable_shared_dpll(intel_crtc); |
8db9d77b | 5137 | |
d925c59a DV |
5138 | ironlake_fdi_pll_disable(intel_crtc); |
5139 | } | |
6b383a7f | 5140 | |
f7abfe8b | 5141 | intel_crtc->active = false; |
46ba614c | 5142 | intel_update_watermarks(crtc); |
d1ebd816 BW |
5143 | |
5144 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 5145 | intel_fbc_update(dev); |
d1ebd816 | 5146 | mutex_unlock(&dev->struct_mutex); |
6be4a607 | 5147 | } |
1b3c7a47 | 5148 | |
4f771f10 | 5149 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5150 | { |
4f771f10 PZ |
5151 | struct drm_device *dev = crtc->dev; |
5152 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5153 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5154 | struct intel_encoder *encoder; |
6e3c9717 | 5155 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5156 | |
4f771f10 PZ |
5157 | if (!intel_crtc->active) |
5158 | return; | |
5159 | ||
8807e55b JN |
5160 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5161 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5162 | encoder->disable(encoder); |
8807e55b | 5163 | } |
4f771f10 | 5164 | |
f9b61ff6 DV |
5165 | drm_crtc_vblank_off(crtc); |
5166 | assert_vblank_disabled(crtc); | |
5167 | ||
6e3c9717 | 5168 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f DV |
5169 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5170 | false); | |
575f7ab7 | 5171 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5172 | |
6e3c9717 | 5173 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5174 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5175 | ||
ad80a810 | 5176 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5177 | |
ff6d9f55 | 5178 | if (INTEL_INFO(dev)->gen == 9) |
a1b2278e | 5179 | skylake_pfit_update(intel_crtc, 0); |
ff6d9f55 | 5180 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 5181 | ironlake_pfit_disable(intel_crtc); |
ff6d9f55 JB |
5182 | else |
5183 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 | 5184 | |
1f544388 | 5185 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5186 | |
6e3c9717 | 5187 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5188 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5189 | intel_ddi_fdi_disable(crtc); |
83616634 | 5190 | } |
4f771f10 | 5191 | |
97b040aa ID |
5192 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5193 | if (encoder->post_disable) | |
5194 | encoder->post_disable(encoder); | |
5195 | ||
4f771f10 | 5196 | intel_crtc->active = false; |
46ba614c | 5197 | intel_update_watermarks(crtc); |
4f771f10 PZ |
5198 | |
5199 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 5200 | intel_fbc_update(dev); |
4f771f10 | 5201 | mutex_unlock(&dev->struct_mutex); |
df8ad70c DV |
5202 | |
5203 | if (intel_crtc_to_shared_dpll(intel_crtc)) | |
5204 | intel_disable_shared_dpll(intel_crtc); | |
4f771f10 PZ |
5205 | } |
5206 | ||
ee7b9f93 JB |
5207 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
5208 | { | |
5209 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
e72f9fbf | 5210 | intel_put_shared_dpll(intel_crtc); |
ee7b9f93 JB |
5211 | } |
5212 | ||
6441ab5f | 5213 | |
2dd24552 JB |
5214 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5215 | { | |
5216 | struct drm_device *dev = crtc->base.dev; | |
5217 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5218 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5219 | |
681a8504 | 5220 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5221 | return; |
5222 | ||
2dd24552 | 5223 | /* |
c0b03411 DV |
5224 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5225 | * according to register description and PRM. | |
2dd24552 | 5226 | */ |
c0b03411 DV |
5227 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5228 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5229 | |
b074cec8 JB |
5230 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5231 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5232 | |
5233 | /* Border color in case we don't scale up to the full screen. Black by | |
5234 | * default, change to something else for debugging. */ | |
5235 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5236 | } |
5237 | ||
d05410f9 DA |
5238 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5239 | { | |
5240 | switch (port) { | |
5241 | case PORT_A: | |
5242 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; | |
5243 | case PORT_B: | |
5244 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; | |
5245 | case PORT_C: | |
5246 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; | |
5247 | case PORT_D: | |
5248 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; | |
5249 | default: | |
5250 | WARN_ON_ONCE(1); | |
5251 | return POWER_DOMAIN_PORT_OTHER; | |
5252 | } | |
5253 | } | |
5254 | ||
77d22dca ID |
5255 | #define for_each_power_domain(domain, mask) \ |
5256 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5257 | if ((1 << (domain)) & (mask)) | |
5258 | ||
319be8ae ID |
5259 | enum intel_display_power_domain |
5260 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5261 | { | |
5262 | struct drm_device *dev = intel_encoder->base.dev; | |
5263 | struct intel_digital_port *intel_dig_port; | |
5264 | ||
5265 | switch (intel_encoder->type) { | |
5266 | case INTEL_OUTPUT_UNKNOWN: | |
5267 | /* Only DDI platforms should ever use this output type */ | |
5268 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5269 | case INTEL_OUTPUT_DISPLAYPORT: | |
5270 | case INTEL_OUTPUT_HDMI: | |
5271 | case INTEL_OUTPUT_EDP: | |
5272 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5273 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5274 | case INTEL_OUTPUT_DP_MST: |
5275 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5276 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5277 | case INTEL_OUTPUT_ANALOG: |
5278 | return POWER_DOMAIN_PORT_CRT; | |
5279 | case INTEL_OUTPUT_DSI: | |
5280 | return POWER_DOMAIN_PORT_DSI; | |
5281 | default: | |
5282 | return POWER_DOMAIN_PORT_OTHER; | |
5283 | } | |
5284 | } | |
5285 | ||
5286 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) | |
77d22dca | 5287 | { |
319be8ae ID |
5288 | struct drm_device *dev = crtc->dev; |
5289 | struct intel_encoder *intel_encoder; | |
5290 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5291 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca ID |
5292 | unsigned long mask; |
5293 | enum transcoder transcoder; | |
5294 | ||
5295 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); | |
5296 | ||
5297 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); | |
5298 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5299 | if (intel_crtc->config->pch_pfit.enabled || |
5300 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5301 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5302 | ||
319be8ae ID |
5303 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5304 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5305 | ||
77d22dca ID |
5306 | return mask; |
5307 | } | |
5308 | ||
679dacd4 | 5309 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
77d22dca | 5310 | { |
679dacd4 | 5311 | struct drm_device *dev = state->dev; |
77d22dca ID |
5312 | struct drm_i915_private *dev_priv = dev->dev_private; |
5313 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; | |
5314 | struct intel_crtc *crtc; | |
5315 | ||
5316 | /* | |
5317 | * First get all needed power domains, then put all unneeded, to avoid | |
5318 | * any unnecessary toggling of the power wells. | |
5319 | */ | |
d3fcc808 | 5320 | for_each_intel_crtc(dev, crtc) { |
77d22dca ID |
5321 | enum intel_display_power_domain domain; |
5322 | ||
83d65738 | 5323 | if (!crtc->base.state->enable) |
77d22dca ID |
5324 | continue; |
5325 | ||
319be8ae | 5326 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
77d22dca ID |
5327 | |
5328 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) | |
5329 | intel_display_power_get(dev_priv, domain); | |
5330 | } | |
5331 | ||
50f6e502 | 5332 | if (dev_priv->display.modeset_global_resources) |
679dacd4 | 5333 | dev_priv->display.modeset_global_resources(state); |
50f6e502 | 5334 | |
d3fcc808 | 5335 | for_each_intel_crtc(dev, crtc) { |
77d22dca ID |
5336 | enum intel_display_power_domain domain; |
5337 | ||
5338 | for_each_power_domain(domain, crtc->enabled_power_domains) | |
5339 | intel_display_power_put(dev_priv, domain); | |
5340 | ||
5341 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; | |
5342 | } | |
5343 | ||
5344 | intel_display_set_init_power(dev_priv, false); | |
5345 | } | |
5346 | ||
f8437dd1 VK |
5347 | void broxton_set_cdclk(struct drm_device *dev, int frequency) |
5348 | { | |
5349 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5350 | uint32_t divider; | |
5351 | uint32_t ratio; | |
5352 | uint32_t current_freq; | |
5353 | int ret; | |
5354 | ||
5355 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5356 | switch (frequency) { | |
5357 | case 144000: | |
5358 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5359 | ratio = BXT_DE_PLL_RATIO(60); | |
5360 | break; | |
5361 | case 288000: | |
5362 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5363 | ratio = BXT_DE_PLL_RATIO(60); | |
5364 | break; | |
5365 | case 384000: | |
5366 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5367 | ratio = BXT_DE_PLL_RATIO(60); | |
5368 | break; | |
5369 | case 576000: | |
5370 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5371 | ratio = BXT_DE_PLL_RATIO(60); | |
5372 | break; | |
5373 | case 624000: | |
5374 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5375 | ratio = BXT_DE_PLL_RATIO(65); | |
5376 | break; | |
5377 | case 19200: | |
5378 | /* | |
5379 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5380 | * to suppress GCC warning. | |
5381 | */ | |
5382 | ratio = 0; | |
5383 | divider = 0; | |
5384 | break; | |
5385 | default: | |
5386 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5387 | ||
5388 | return; | |
5389 | } | |
5390 | ||
5391 | mutex_lock(&dev_priv->rps.hw_lock); | |
5392 | /* Inform power controller of upcoming frequency change */ | |
5393 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5394 | 0x80000000); | |
5395 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5396 | ||
5397 | if (ret) { | |
5398 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5399 | ret, frequency); | |
5400 | return; | |
5401 | } | |
5402 | ||
5403 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5404 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5405 | current_freq = current_freq * 500 + 1000; | |
5406 | ||
5407 | /* | |
5408 | * DE PLL has to be disabled when | |
5409 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5410 | * - before setting to 624MHz (PLL needs toggling) | |
5411 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5412 | */ | |
5413 | if (frequency == 19200 || frequency == 624000 || | |
5414 | current_freq == 624000) { | |
5415 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5416 | /* Timeout 200us */ | |
5417 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5418 | 1)) | |
5419 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5420 | } | |
5421 | ||
5422 | if (frequency != 19200) { | |
5423 | uint32_t val; | |
5424 | ||
5425 | val = I915_READ(BXT_DE_PLL_CTL); | |
5426 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5427 | val |= ratio; | |
5428 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5429 | ||
5430 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5431 | /* Timeout 200us */ | |
5432 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5433 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5434 | ||
5435 | val = I915_READ(CDCLK_CTL); | |
5436 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5437 | val |= divider; | |
5438 | /* | |
5439 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5440 | * enable otherwise. | |
5441 | */ | |
5442 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5443 | if (frequency >= 500000) | |
5444 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5445 | ||
5446 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5447 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5448 | val |= (frequency - 1000) / 500; | |
5449 | I915_WRITE(CDCLK_CTL, val); | |
5450 | } | |
5451 | ||
5452 | mutex_lock(&dev_priv->rps.hw_lock); | |
5453 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5454 | DIV_ROUND_UP(frequency, 25000)); | |
5455 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5456 | ||
5457 | if (ret) { | |
5458 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5459 | ret, frequency); | |
5460 | return; | |
5461 | } | |
5462 | ||
5463 | dev_priv->cdclk_freq = frequency; | |
5464 | } | |
5465 | ||
5466 | void broxton_init_cdclk(struct drm_device *dev) | |
5467 | { | |
5468 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5469 | uint32_t val; | |
5470 | ||
5471 | /* | |
5472 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5473 | * or else the reset will hang because there is no PCH to respond. | |
5474 | * Move the handshake programming to initialization sequence. | |
5475 | * Previously was left up to BIOS. | |
5476 | */ | |
5477 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5478 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5479 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5480 | ||
5481 | /* Enable PG1 for cdclk */ | |
5482 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5483 | ||
5484 | /* check if cd clock is enabled */ | |
5485 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5486 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5487 | return; | |
5488 | } | |
5489 | ||
5490 | /* | |
5491 | * FIXME: | |
5492 | * - The initial CDCLK needs to be read from VBT. | |
5493 | * Need to make this change after VBT has changes for BXT. | |
5494 | * - check if setting the max (or any) cdclk freq is really necessary | |
5495 | * here, it belongs to modeset time | |
5496 | */ | |
5497 | broxton_set_cdclk(dev, 624000); | |
5498 | ||
5499 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5500 | POSTING_READ(DBUF_CTL); |
5501 | ||
f8437dd1 VK |
5502 | udelay(10); |
5503 | ||
5504 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5505 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5506 | } | |
5507 | ||
5508 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5509 | { | |
5510 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5511 | ||
5512 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5513 | POSTING_READ(DBUF_CTL); |
5514 | ||
f8437dd1 VK |
5515 | udelay(10); |
5516 | ||
5517 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5518 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5519 | ||
5520 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5521 | broxton_set_cdclk(dev, 19200); | |
5522 | ||
5523 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5524 | } | |
5525 | ||
dfcab17e | 5526 | /* returns HPLL frequency in kHz */ |
f8bf63fd | 5527 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
30a970c6 | 5528 | { |
586f49dc | 5529 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
30a970c6 | 5530 | |
586f49dc JB |
5531 | /* Obtain SKU information */ |
5532 | mutex_lock(&dev_priv->dpio_lock); | |
5533 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
5534 | CCK_FUSE_HPLL_FREQ_MASK; | |
5535 | mutex_unlock(&dev_priv->dpio_lock); | |
30a970c6 | 5536 | |
dfcab17e | 5537 | return vco_freq[hpll_freq] * 1000; |
30a970c6 JB |
5538 | } |
5539 | ||
f8bf63fd VS |
5540 | static void vlv_update_cdclk(struct drm_device *dev) |
5541 | { | |
5542 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5543 | ||
164dfd28 | 5544 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
43dc52c3 | 5545 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
164dfd28 | 5546 | dev_priv->cdclk_freq); |
f8bf63fd VS |
5547 | |
5548 | /* | |
5549 | * Program the gmbus_freq based on the cdclk frequency. | |
5550 | * BSpec erroneously claims we should aim for 4MHz, but | |
5551 | * in fact 1MHz is the correct frequency. | |
5552 | */ | |
164dfd28 | 5553 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
f8bf63fd VS |
5554 | } |
5555 | ||
30a970c6 JB |
5556 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5557 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5558 | { | |
5559 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5560 | u32 val, cmd; | |
5561 | ||
164dfd28 VK |
5562 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5563 | != dev_priv->cdclk_freq); | |
d60c4473 | 5564 | |
dfcab17e | 5565 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5566 | cmd = 2; |
dfcab17e | 5567 | else if (cdclk == 266667) |
30a970c6 JB |
5568 | cmd = 1; |
5569 | else | |
5570 | cmd = 0; | |
5571 | ||
5572 | mutex_lock(&dev_priv->rps.hw_lock); | |
5573 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5574 | val &= ~DSPFREQGUAR_MASK; | |
5575 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5576 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5577 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5578 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5579 | 50)) { | |
5580 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5581 | } | |
5582 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5583 | ||
dfcab17e | 5584 | if (cdclk == 400000) { |
6bcda4f0 | 5585 | u32 divider; |
30a970c6 | 5586 | |
6bcda4f0 | 5587 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 JB |
5588 | |
5589 | mutex_lock(&dev_priv->dpio_lock); | |
5590 | /* adjust cdclk divider */ | |
5591 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
9cf33db5 | 5592 | val &= ~DISPLAY_FREQUENCY_VALUES; |
30a970c6 JB |
5593 | val |= divider; |
5594 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5595 | |
5596 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
5597 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
5598 | 50)) | |
5599 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5600 | mutex_unlock(&dev_priv->dpio_lock); |
5601 | } | |
5602 | ||
5603 | mutex_lock(&dev_priv->dpio_lock); | |
5604 | /* adjust self-refresh exit latency value */ | |
5605 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5606 | val &= ~0x7f; | |
5607 | ||
5608 | /* | |
5609 | * For high bandwidth configs, we set a higher latency in the bunit | |
5610 | * so that the core display fetch happens in time to avoid underruns. | |
5611 | */ | |
dfcab17e | 5612 | if (cdclk == 400000) |
30a970c6 JB |
5613 | val |= 4500 / 250; /* 4.5 usec */ |
5614 | else | |
5615 | val |= 3000 / 250; /* 3.0 usec */ | |
5616 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
5617 | mutex_unlock(&dev_priv->dpio_lock); | |
5618 | ||
f8bf63fd | 5619 | vlv_update_cdclk(dev); |
30a970c6 JB |
5620 | } |
5621 | ||
383c5a6a VS |
5622 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5623 | { | |
5624 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5625 | u32 val, cmd; | |
5626 | ||
164dfd28 VK |
5627 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5628 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5629 | |
5630 | switch (cdclk) { | |
383c5a6a VS |
5631 | case 333333: |
5632 | case 320000: | |
383c5a6a | 5633 | case 266667: |
383c5a6a | 5634 | case 200000: |
383c5a6a VS |
5635 | break; |
5636 | default: | |
5f77eeb0 | 5637 | MISSING_CASE(cdclk); |
383c5a6a VS |
5638 | return; |
5639 | } | |
5640 | ||
9d0d3fda VS |
5641 | /* |
5642 | * Specs are full of misinformation, but testing on actual | |
5643 | * hardware has shown that we just need to write the desired | |
5644 | * CCK divider into the Punit register. | |
5645 | */ | |
5646 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5647 | ||
383c5a6a VS |
5648 | mutex_lock(&dev_priv->rps.hw_lock); |
5649 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5650 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5651 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5652 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5653 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5654 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5655 | 50)) { | |
5656 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5657 | } | |
5658 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5659 | ||
5660 | vlv_update_cdclk(dev); | |
5661 | } | |
5662 | ||
30a970c6 JB |
5663 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5664 | int max_pixclk) | |
5665 | { | |
6bcda4f0 | 5666 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5667 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5668 | |
30a970c6 JB |
5669 | /* |
5670 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5671 | * 200MHz | |
5672 | * 267MHz | |
29dc7ef3 | 5673 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5674 | * 400MHz (VLV only) |
5675 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5676 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5677 | * |
5678 | * We seem to get an unstable or solid color picture at 200MHz. | |
5679 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5680 | * are off. | |
30a970c6 | 5681 | */ |
6cca3195 VS |
5682 | if (!IS_CHERRYVIEW(dev_priv) && |
5683 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5684 | return 400000; |
6cca3195 | 5685 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5686 | return freq_320; |
e37c67a1 | 5687 | else if (max_pixclk > 0) |
dfcab17e | 5688 | return 266667; |
e37c67a1 VS |
5689 | else |
5690 | return 200000; | |
30a970c6 JB |
5691 | } |
5692 | ||
f8437dd1 VK |
5693 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5694 | int max_pixclk) | |
5695 | { | |
5696 | /* | |
5697 | * FIXME: | |
5698 | * - remove the guardband, it's not needed on BXT | |
5699 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5700 | */ | |
5701 | if (max_pixclk > 576000*9/10) | |
5702 | return 624000; | |
5703 | else if (max_pixclk > 384000*9/10) | |
5704 | return 576000; | |
5705 | else if (max_pixclk > 288000*9/10) | |
5706 | return 384000; | |
5707 | else if (max_pixclk > 144000*9/10) | |
5708 | return 288000; | |
5709 | else | |
5710 | return 144000; | |
5711 | } | |
5712 | ||
a821fc46 ACO |
5713 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5714 | * that's non-NULL, look at current state otherwise. */ | |
5715 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5716 | struct drm_atomic_state *state) | |
30a970c6 | 5717 | { |
30a970c6 | 5718 | struct intel_crtc *intel_crtc; |
304603f4 | 5719 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5720 | int max_pixclk = 0; |
5721 | ||
d3fcc808 | 5722 | for_each_intel_crtc(dev, intel_crtc) { |
a821fc46 ACO |
5723 | if (state) |
5724 | crtc_state = | |
5725 | intel_atomic_get_crtc_state(state, intel_crtc); | |
5726 | else | |
5727 | crtc_state = intel_crtc->config; | |
304603f4 ACO |
5728 | if (IS_ERR(crtc_state)) |
5729 | return PTR_ERR(crtc_state); | |
5730 | ||
5731 | if (!crtc_state->base.enable) | |
5732 | continue; | |
5733 | ||
5734 | max_pixclk = max(max_pixclk, | |
5735 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5736 | } |
5737 | ||
5738 | return max_pixclk; | |
5739 | } | |
5740 | ||
0a9ab303 | 5741 | static int valleyview_modeset_global_pipes(struct drm_atomic_state *state) |
30a970c6 | 5742 | { |
304603f4 | 5743 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
0a9ab303 ACO |
5744 | struct drm_crtc *crtc; |
5745 | struct drm_crtc_state *crtc_state; | |
a821fc46 | 5746 | int max_pixclk = intel_mode_max_pixclk(state->dev, state); |
0a9ab303 | 5747 | int cdclk, i; |
30a970c6 | 5748 | |
304603f4 ACO |
5749 | if (max_pixclk < 0) |
5750 | return max_pixclk; | |
30a970c6 | 5751 | |
f8437dd1 VK |
5752 | if (IS_VALLEYVIEW(dev_priv)) |
5753 | cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); | |
5754 | else | |
5755 | cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); | |
5756 | ||
5757 | if (cdclk == dev_priv->cdclk_freq) | |
304603f4 | 5758 | return 0; |
30a970c6 | 5759 | |
0a9ab303 ACO |
5760 | /* add all active pipes to the state */ |
5761 | for_each_crtc(state->dev, crtc) { | |
5762 | if (!crtc->state->enable) | |
5763 | continue; | |
5764 | ||
5765 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
5766 | if (IS_ERR(crtc_state)) | |
5767 | return PTR_ERR(crtc_state); | |
5768 | } | |
5769 | ||
2f2d7aa1 | 5770 | /* disable/enable all currently active pipes while we change cdclk */ |
0a9ab303 ACO |
5771 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
5772 | if (crtc_state->enable) | |
5773 | crtc_state->mode_changed = true; | |
304603f4 ACO |
5774 | |
5775 | return 0; | |
30a970c6 JB |
5776 | } |
5777 | ||
1e69cd74 VS |
5778 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
5779 | { | |
5780 | unsigned int credits, default_credits; | |
5781 | ||
5782 | if (IS_CHERRYVIEW(dev_priv)) | |
5783 | default_credits = PFI_CREDIT(12); | |
5784 | else | |
5785 | default_credits = PFI_CREDIT(8); | |
5786 | ||
164dfd28 | 5787 | if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
1e69cd74 VS |
5788 | /* CHV suggested value is 31 or 63 */ |
5789 | if (IS_CHERRYVIEW(dev_priv)) | |
5790 | credits = PFI_CREDIT_31; | |
5791 | else | |
5792 | credits = PFI_CREDIT(15); | |
5793 | } else { | |
5794 | credits = default_credits; | |
5795 | } | |
5796 | ||
5797 | /* | |
5798 | * WA - write default credits before re-programming | |
5799 | * FIXME: should we also set the resend bit here? | |
5800 | */ | |
5801 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
5802 | default_credits); | |
5803 | ||
5804 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
5805 | credits | PFI_CREDIT_RESEND); | |
5806 | ||
5807 | /* | |
5808 | * FIXME is this guaranteed to clear | |
5809 | * immediately or should we poll for it? | |
5810 | */ | |
5811 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
5812 | } | |
5813 | ||
a821fc46 | 5814 | static void valleyview_modeset_global_resources(struct drm_atomic_state *old_state) |
30a970c6 | 5815 | { |
a821fc46 | 5816 | struct drm_device *dev = old_state->dev; |
30a970c6 | 5817 | struct drm_i915_private *dev_priv = dev->dev_private; |
a821fc46 | 5818 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
304603f4 ACO |
5819 | int req_cdclk; |
5820 | ||
a821fc46 ACO |
5821 | /* The path in intel_mode_max_pixclk() with a NULL atomic state should |
5822 | * never fail. */ | |
304603f4 ACO |
5823 | if (WARN_ON(max_pixclk < 0)) |
5824 | return; | |
30a970c6 | 5825 | |
304603f4 | 5826 | req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
30a970c6 | 5827 | |
164dfd28 | 5828 | if (req_cdclk != dev_priv->cdclk_freq) { |
738c05c0 ID |
5829 | /* |
5830 | * FIXME: We can end up here with all power domains off, yet | |
5831 | * with a CDCLK frequency other than the minimum. To account | |
5832 | * for this take the PIPE-A power domain, which covers the HW | |
5833 | * blocks needed for the following programming. This can be | |
5834 | * removed once it's guaranteed that we get here either with | |
5835 | * the minimum CDCLK set, or the required power domains | |
5836 | * enabled. | |
5837 | */ | |
5838 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
5839 | ||
383c5a6a VS |
5840 | if (IS_CHERRYVIEW(dev)) |
5841 | cherryview_set_cdclk(dev, req_cdclk); | |
5842 | else | |
5843 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 5844 | |
1e69cd74 VS |
5845 | vlv_program_pfi_credits(dev_priv); |
5846 | ||
738c05c0 | 5847 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
383c5a6a | 5848 | } |
30a970c6 JB |
5849 | } |
5850 | ||
89b667f8 JB |
5851 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
5852 | { | |
5853 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 5854 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
5855 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5856 | struct intel_encoder *encoder; | |
5857 | int pipe = intel_crtc->pipe; | |
23538ef1 | 5858 | bool is_dsi; |
89b667f8 | 5859 | |
83d65738 | 5860 | WARN_ON(!crtc->state->enable); |
89b667f8 JB |
5861 | |
5862 | if (intel_crtc->active) | |
5863 | return; | |
5864 | ||
409ee761 | 5865 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 5866 | |
1ae0d137 VS |
5867 | if (!is_dsi) { |
5868 | if (IS_CHERRYVIEW(dev)) | |
6e3c9717 | 5869 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
1ae0d137 | 5870 | else |
6e3c9717 | 5871 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
1ae0d137 | 5872 | } |
5b18e57c | 5873 | |
6e3c9717 | 5874 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 5875 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
5876 | |
5877 | intel_set_pipe_timings(intel_crtc); | |
5878 | ||
c14b0485 VS |
5879 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
5880 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5881 | ||
5882 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
5883 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
5884 | } | |
5885 | ||
5b18e57c DV |
5886 | i9xx_set_pipeconf(intel_crtc); |
5887 | ||
89b667f8 | 5888 | intel_crtc->active = true; |
89b667f8 | 5889 | |
a72e4c9f | 5890 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 5891 | |
89b667f8 JB |
5892 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5893 | if (encoder->pre_pll_enable) | |
5894 | encoder->pre_pll_enable(encoder); | |
5895 | ||
9d556c99 CML |
5896 | if (!is_dsi) { |
5897 | if (IS_CHERRYVIEW(dev)) | |
6e3c9717 | 5898 | chv_enable_pll(intel_crtc, intel_crtc->config); |
9d556c99 | 5899 | else |
6e3c9717 | 5900 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
9d556c99 | 5901 | } |
89b667f8 JB |
5902 | |
5903 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
5904 | if (encoder->pre_enable) | |
5905 | encoder->pre_enable(encoder); | |
5906 | ||
2dd24552 JB |
5907 | i9xx_pfit_enable(intel_crtc); |
5908 | ||
63cbb074 VS |
5909 | intel_crtc_load_lut(crtc); |
5910 | ||
f37fcc2a | 5911 | intel_update_watermarks(crtc); |
e1fdc473 | 5912 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 5913 | |
4b3a9526 VS |
5914 | assert_vblank_disabled(crtc); |
5915 | drm_crtc_vblank_on(crtc); | |
5916 | ||
f9b61ff6 DV |
5917 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5918 | encoder->enable(encoder); | |
89b667f8 JB |
5919 | } |
5920 | ||
f13c2ef3 DV |
5921 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
5922 | { | |
5923 | struct drm_device *dev = crtc->base.dev; | |
5924 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5925 | ||
6e3c9717 ACO |
5926 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
5927 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
5928 | } |
5929 | ||
0b8765c6 | 5930 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
5931 | { |
5932 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 5933 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 5934 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 5935 | struct intel_encoder *encoder; |
79e53945 | 5936 | int pipe = intel_crtc->pipe; |
79e53945 | 5937 | |
83d65738 | 5938 | WARN_ON(!crtc->state->enable); |
08a48469 | 5939 | |
f7abfe8b CW |
5940 | if (intel_crtc->active) |
5941 | return; | |
5942 | ||
f13c2ef3 DV |
5943 | i9xx_set_pll_dividers(intel_crtc); |
5944 | ||
6e3c9717 | 5945 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 5946 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
5947 | |
5948 | intel_set_pipe_timings(intel_crtc); | |
5949 | ||
5b18e57c DV |
5950 | i9xx_set_pipeconf(intel_crtc); |
5951 | ||
f7abfe8b | 5952 | intel_crtc->active = true; |
6b383a7f | 5953 | |
4a3436e8 | 5954 | if (!IS_GEN2(dev)) |
a72e4c9f | 5955 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 5956 | |
9d6d9f19 MK |
5957 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5958 | if (encoder->pre_enable) | |
5959 | encoder->pre_enable(encoder); | |
5960 | ||
f6736a1a DV |
5961 | i9xx_enable_pll(intel_crtc); |
5962 | ||
2dd24552 JB |
5963 | i9xx_pfit_enable(intel_crtc); |
5964 | ||
63cbb074 VS |
5965 | intel_crtc_load_lut(crtc); |
5966 | ||
f37fcc2a | 5967 | intel_update_watermarks(crtc); |
e1fdc473 | 5968 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 5969 | |
4b3a9526 VS |
5970 | assert_vblank_disabled(crtc); |
5971 | drm_crtc_vblank_on(crtc); | |
5972 | ||
f9b61ff6 DV |
5973 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5974 | encoder->enable(encoder); | |
0b8765c6 | 5975 | } |
79e53945 | 5976 | |
87476d63 DV |
5977 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
5978 | { | |
5979 | struct drm_device *dev = crtc->base.dev; | |
5980 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 5981 | |
6e3c9717 | 5982 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 5983 | return; |
87476d63 | 5984 | |
328d8e82 | 5985 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 5986 | |
328d8e82 DV |
5987 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
5988 | I915_READ(PFIT_CONTROL)); | |
5989 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
5990 | } |
5991 | ||
0b8765c6 JB |
5992 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
5993 | { | |
5994 | struct drm_device *dev = crtc->dev; | |
5995 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5996 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5997 | struct intel_encoder *encoder; |
0b8765c6 | 5998 | int pipe = intel_crtc->pipe; |
ef9c3aee | 5999 | |
f7abfe8b CW |
6000 | if (!intel_crtc->active) |
6001 | return; | |
6002 | ||
6304cd91 VS |
6003 | /* |
6004 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6005 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6006 | * We also need to wait on all gmch platforms because of the |
6007 | * self-refresh mode constraint explained above. | |
6304cd91 | 6008 | */ |
564ed191 | 6009 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6010 | |
4b3a9526 VS |
6011 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6012 | encoder->disable(encoder); | |
6013 | ||
f9b61ff6 DV |
6014 | drm_crtc_vblank_off(crtc); |
6015 | assert_vblank_disabled(crtc); | |
6016 | ||
575f7ab7 | 6017 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6018 | |
87476d63 | 6019 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6020 | |
89b667f8 JB |
6021 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6022 | if (encoder->post_disable) | |
6023 | encoder->post_disable(encoder); | |
6024 | ||
409ee761 | 6025 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6026 | if (IS_CHERRYVIEW(dev)) |
6027 | chv_disable_pll(dev_priv, pipe); | |
6028 | else if (IS_VALLEYVIEW(dev)) | |
6029 | vlv_disable_pll(dev_priv, pipe); | |
6030 | else | |
1c4e0274 | 6031 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6032 | } |
0b8765c6 | 6033 | |
4a3436e8 | 6034 | if (!IS_GEN2(dev)) |
a72e4c9f | 6035 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
4a3436e8 | 6036 | |
f7abfe8b | 6037 | intel_crtc->active = false; |
46ba614c | 6038 | intel_update_watermarks(crtc); |
f37fcc2a | 6039 | |
efa9624e | 6040 | mutex_lock(&dev->struct_mutex); |
7ff0ebcc | 6041 | intel_fbc_update(dev); |
efa9624e | 6042 | mutex_unlock(&dev->struct_mutex); |
0b8765c6 JB |
6043 | } |
6044 | ||
ee7b9f93 JB |
6045 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
6046 | { | |
6047 | } | |
6048 | ||
b04c5bd6 BF |
6049 | /* Master function to enable/disable CRTC and corresponding power wells */ |
6050 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) | |
976f8a20 DV |
6051 | { |
6052 | struct drm_device *dev = crtc->dev; | |
6053 | struct drm_i915_private *dev_priv = dev->dev_private; | |
0e572fe7 | 6054 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
0e572fe7 DV |
6055 | enum intel_display_power_domain domain; |
6056 | unsigned long domains; | |
976f8a20 | 6057 | |
0e572fe7 DV |
6058 | if (enable) { |
6059 | if (!intel_crtc->active) { | |
e1e9fb84 DV |
6060 | domains = get_crtc_power_domains(crtc); |
6061 | for_each_power_domain(domain, domains) | |
6062 | intel_display_power_get(dev_priv, domain); | |
6063 | intel_crtc->enabled_power_domains = domains; | |
0e572fe7 DV |
6064 | |
6065 | dev_priv->display.crtc_enable(crtc); | |
ce22dba9 | 6066 | intel_crtc_enable_planes(crtc); |
0e572fe7 DV |
6067 | } |
6068 | } else { | |
6069 | if (intel_crtc->active) { | |
ce22dba9 | 6070 | intel_crtc_disable_planes(crtc); |
0e572fe7 DV |
6071 | dev_priv->display.crtc_disable(crtc); |
6072 | ||
e1e9fb84 DV |
6073 | domains = intel_crtc->enabled_power_domains; |
6074 | for_each_power_domain(domain, domains) | |
6075 | intel_display_power_put(dev_priv, domain); | |
6076 | intel_crtc->enabled_power_domains = 0; | |
0e572fe7 DV |
6077 | } |
6078 | } | |
b04c5bd6 BF |
6079 | } |
6080 | ||
6081 | /** | |
6082 | * Sets the power management mode of the pipe and plane. | |
6083 | */ | |
6084 | void intel_crtc_update_dpms(struct drm_crtc *crtc) | |
6085 | { | |
6086 | struct drm_device *dev = crtc->dev; | |
6087 | struct intel_encoder *intel_encoder; | |
6088 | bool enable = false; | |
6089 | ||
6090 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) | |
6091 | enable |= intel_encoder->connectors_active; | |
6092 | ||
6093 | intel_crtc_control(crtc, enable); | |
0f63cca2 ACO |
6094 | |
6095 | crtc->state->active = enable; | |
976f8a20 DV |
6096 | } |
6097 | ||
cdd59983 CW |
6098 | static void intel_crtc_disable(struct drm_crtc *crtc) |
6099 | { | |
cdd59983 | 6100 | struct drm_device *dev = crtc->dev; |
976f8a20 | 6101 | struct drm_connector *connector; |
ee7b9f93 | 6102 | struct drm_i915_private *dev_priv = dev->dev_private; |
cdd59983 | 6103 | |
976f8a20 | 6104 | /* crtc should still be enabled when we disable it. */ |
83d65738 | 6105 | WARN_ON(!crtc->state->enable); |
976f8a20 | 6106 | |
ce22dba9 | 6107 | intel_crtc_disable_planes(crtc); |
976f8a20 | 6108 | dev_priv->display.crtc_disable(crtc); |
ee7b9f93 JB |
6109 | dev_priv->display.off(crtc); |
6110 | ||
70a101f8 | 6111 | drm_plane_helper_disable(crtc->primary); |
976f8a20 DV |
6112 | |
6113 | /* Update computed state. */ | |
6114 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
6115 | if (!connector->encoder || !connector->encoder->crtc) | |
6116 | continue; | |
6117 | ||
6118 | if (connector->encoder->crtc != crtc) | |
6119 | continue; | |
6120 | ||
6121 | connector->dpms = DRM_MODE_DPMS_OFF; | |
6122 | to_intel_encoder(connector->encoder)->connectors_active = false; | |
cdd59983 CW |
6123 | } |
6124 | } | |
6125 | ||
ea5b213a | 6126 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6127 | { |
4ef69c7a | 6128 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6129 | |
ea5b213a CW |
6130 | drm_encoder_cleanup(encoder); |
6131 | kfree(intel_encoder); | |
7e7d76c3 JB |
6132 | } |
6133 | ||
9237329d | 6134 | /* Simple dpms helper for encoders with just one connector, no cloning and only |
5ab432ef DV |
6135 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
6136 | * state of the entire output pipe. */ | |
9237329d | 6137 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
7e7d76c3 | 6138 | { |
5ab432ef DV |
6139 | if (mode == DRM_MODE_DPMS_ON) { |
6140 | encoder->connectors_active = true; | |
6141 | ||
b2cabb0e | 6142 | intel_crtc_update_dpms(encoder->base.crtc); |
5ab432ef DV |
6143 | } else { |
6144 | encoder->connectors_active = false; | |
6145 | ||
b2cabb0e | 6146 | intel_crtc_update_dpms(encoder->base.crtc); |
5ab432ef | 6147 | } |
79e53945 JB |
6148 | } |
6149 | ||
0a91ca29 DV |
6150 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6151 | * internal consistency). */ | |
b980514c | 6152 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6153 | { |
0a91ca29 DV |
6154 | if (connector->get_hw_state(connector)) { |
6155 | struct intel_encoder *encoder = connector->encoder; | |
6156 | struct drm_crtc *crtc; | |
6157 | bool encoder_enabled; | |
6158 | enum pipe pipe; | |
6159 | ||
6160 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6161 | connector->base.base.id, | |
c23cc417 | 6162 | connector->base.name); |
0a91ca29 | 6163 | |
0e32b39c DA |
6164 | /* there is no real hw state for MST connectors */ |
6165 | if (connector->mst_port) | |
6166 | return; | |
6167 | ||
e2c719b7 | 6168 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
0a91ca29 | 6169 | "wrong connector dpms state\n"); |
e2c719b7 | 6170 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
0a91ca29 | 6171 | "active connector not linked to encoder\n"); |
0a91ca29 | 6172 | |
36cd7444 | 6173 | if (encoder) { |
e2c719b7 | 6174 | I915_STATE_WARN(!encoder->connectors_active, |
36cd7444 DA |
6175 | "encoder->connectors_active not set\n"); |
6176 | ||
6177 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); | |
e2c719b7 RC |
6178 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
6179 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) | |
36cd7444 | 6180 | return; |
0a91ca29 | 6181 | |
36cd7444 | 6182 | crtc = encoder->base.crtc; |
0a91ca29 | 6183 | |
83d65738 MR |
6184 | I915_STATE_WARN(!crtc->state->enable, |
6185 | "crtc not enabled\n"); | |
e2c719b7 RC |
6186 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
6187 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, | |
36cd7444 DA |
6188 | "encoder active on the wrong pipe\n"); |
6189 | } | |
0a91ca29 | 6190 | } |
79e53945 JB |
6191 | } |
6192 | ||
08d9bc92 ACO |
6193 | int intel_connector_init(struct intel_connector *connector) |
6194 | { | |
6195 | struct drm_connector_state *connector_state; | |
6196 | ||
6197 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6198 | if (!connector_state) | |
6199 | return -ENOMEM; | |
6200 | ||
6201 | connector->base.state = connector_state; | |
6202 | return 0; | |
6203 | } | |
6204 | ||
6205 | struct intel_connector *intel_connector_alloc(void) | |
6206 | { | |
6207 | struct intel_connector *connector; | |
6208 | ||
6209 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6210 | if (!connector) | |
6211 | return NULL; | |
6212 | ||
6213 | if (intel_connector_init(connector) < 0) { | |
6214 | kfree(connector); | |
6215 | return NULL; | |
6216 | } | |
6217 | ||
6218 | return connector; | |
6219 | } | |
6220 | ||
5ab432ef DV |
6221 | /* Even simpler default implementation, if there's really no special case to |
6222 | * consider. */ | |
6223 | void intel_connector_dpms(struct drm_connector *connector, int mode) | |
79e53945 | 6224 | { |
5ab432ef DV |
6225 | /* All the simple cases only support two dpms states. */ |
6226 | if (mode != DRM_MODE_DPMS_ON) | |
6227 | mode = DRM_MODE_DPMS_OFF; | |
d4270e57 | 6228 | |
5ab432ef DV |
6229 | if (mode == connector->dpms) |
6230 | return; | |
6231 | ||
6232 | connector->dpms = mode; | |
6233 | ||
6234 | /* Only need to change hw state when actually enabled */ | |
c9976dcf CW |
6235 | if (connector->encoder) |
6236 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); | |
0a91ca29 | 6237 | |
b980514c | 6238 | intel_modeset_check_state(connector->dev); |
79e53945 JB |
6239 | } |
6240 | ||
f0947c37 DV |
6241 | /* Simple connector->get_hw_state implementation for encoders that support only |
6242 | * one connector and no cloning and hence the encoder state determines the state | |
6243 | * of the connector. */ | |
6244 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6245 | { |
24929352 | 6246 | enum pipe pipe = 0; |
f0947c37 | 6247 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6248 | |
f0947c37 | 6249 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6250 | } |
6251 | ||
6d293983 | 6252 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6253 | { |
6d293983 ACO |
6254 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6255 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6256 | |
6257 | return 0; | |
6258 | } | |
6259 | ||
6d293983 | 6260 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6261 | struct intel_crtc_state *pipe_config) |
1857e1da | 6262 | { |
6d293983 ACO |
6263 | struct drm_atomic_state *state = pipe_config->base.state; |
6264 | struct intel_crtc *other_crtc; | |
6265 | struct intel_crtc_state *other_crtc_state; | |
6266 | ||
1857e1da DV |
6267 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6268 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6269 | if (pipe_config->fdi_lanes > 4) { | |
6270 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6271 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6272 | return -EINVAL; |
1857e1da DV |
6273 | } |
6274 | ||
bafb6553 | 6275 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6276 | if (pipe_config->fdi_lanes > 2) { |
6277 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6278 | pipe_config->fdi_lanes); | |
6d293983 | 6279 | return -EINVAL; |
1857e1da | 6280 | } else { |
6d293983 | 6281 | return 0; |
1857e1da DV |
6282 | } |
6283 | } | |
6284 | ||
6285 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6286 | return 0; |
1857e1da DV |
6287 | |
6288 | /* Ivybridge 3 pipe is really complicated */ | |
6289 | switch (pipe) { | |
6290 | case PIPE_A: | |
6d293983 | 6291 | return 0; |
1857e1da | 6292 | case PIPE_B: |
6d293983 ACO |
6293 | if (pipe_config->fdi_lanes <= 2) |
6294 | return 0; | |
6295 | ||
6296 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6297 | other_crtc_state = | |
6298 | intel_atomic_get_crtc_state(state, other_crtc); | |
6299 | if (IS_ERR(other_crtc_state)) | |
6300 | return PTR_ERR(other_crtc_state); | |
6301 | ||
6302 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6303 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6304 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6305 | return -EINVAL; |
1857e1da | 6306 | } |
6d293983 | 6307 | return 0; |
1857e1da | 6308 | case PIPE_C: |
251cc67c VS |
6309 | if (pipe_config->fdi_lanes > 2) { |
6310 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6311 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6312 | return -EINVAL; |
251cc67c | 6313 | } |
6d293983 ACO |
6314 | |
6315 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6316 | other_crtc_state = | |
6317 | intel_atomic_get_crtc_state(state, other_crtc); | |
6318 | if (IS_ERR(other_crtc_state)) | |
6319 | return PTR_ERR(other_crtc_state); | |
6320 | ||
6321 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6322 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6323 | return -EINVAL; |
1857e1da | 6324 | } |
6d293983 | 6325 | return 0; |
1857e1da DV |
6326 | default: |
6327 | BUG(); | |
6328 | } | |
6329 | } | |
6330 | ||
e29c22c0 DV |
6331 | #define RETRY 1 |
6332 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6333 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6334 | { |
1857e1da | 6335 | struct drm_device *dev = intel_crtc->base.dev; |
2d112de7 | 6336 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6337 | int lane, link_bw, fdi_dotclock, ret; |
6338 | bool needs_recompute = false; | |
877d48d5 | 6339 | |
e29c22c0 | 6340 | retry: |
877d48d5 DV |
6341 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6342 | * each output octet as 10 bits. The actual frequency | |
6343 | * is stored as a divider into a 100MHz clock, and the | |
6344 | * mode pixel clock is stored in units of 1KHz. | |
6345 | * Hence the bw of each lane in terms of the mode signal | |
6346 | * is: | |
6347 | */ | |
6348 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6349 | ||
241bfc38 | 6350 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6351 | |
2bd89a07 | 6352 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6353 | pipe_config->pipe_bpp); |
6354 | ||
6355 | pipe_config->fdi_lanes = lane; | |
6356 | ||
2bd89a07 | 6357 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6358 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6359 | |
6d293983 ACO |
6360 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6361 | intel_crtc->pipe, pipe_config); | |
6362 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6363 | pipe_config->pipe_bpp -= 2*3; |
6364 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6365 | pipe_config->pipe_bpp); | |
6366 | needs_recompute = true; | |
6367 | pipe_config->bw_constrained = true; | |
6368 | ||
6369 | goto retry; | |
6370 | } | |
6371 | ||
6372 | if (needs_recompute) | |
6373 | return RETRY; | |
6374 | ||
6d293983 | 6375 | return ret; |
877d48d5 DV |
6376 | } |
6377 | ||
42db64ef | 6378 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6379 | struct intel_crtc_state *pipe_config) |
42db64ef | 6380 | { |
d330a953 | 6381 | pipe_config->ips_enabled = i915.enable_ips && |
3c4ca58c | 6382 | hsw_crtc_supports_ips(crtc) && |
b6dfdc9b | 6383 | pipe_config->pipe_bpp <= 24; |
42db64ef PZ |
6384 | } |
6385 | ||
a43f6e0f | 6386 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6387 | struct intel_crtc_state *pipe_config) |
79e53945 | 6388 | { |
a43f6e0f | 6389 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6390 | struct drm_i915_private *dev_priv = dev->dev_private; |
2d112de7 | 6391 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
d03c93d4 | 6392 | int ret; |
89749350 | 6393 | |
ad3a4479 | 6394 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6395 | if (INTEL_INFO(dev)->gen < 4) { |
cf532bb2 VS |
6396 | int clock_limit = |
6397 | dev_priv->display.get_display_clock_speed(dev); | |
6398 | ||
6399 | /* | |
6400 | * Enable pixel doubling when the dot clock | |
6401 | * is > 90% of the (display) core speed. | |
6402 | * | |
b397c96b VS |
6403 | * GDG double wide on either pipe, |
6404 | * otherwise pipe A only. | |
cf532bb2 | 6405 | */ |
b397c96b | 6406 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
241bfc38 | 6407 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
ad3a4479 | 6408 | clock_limit *= 2; |
cf532bb2 | 6409 | pipe_config->double_wide = true; |
ad3a4479 VS |
6410 | } |
6411 | ||
241bfc38 | 6412 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
e29c22c0 | 6413 | return -EINVAL; |
2c07245f | 6414 | } |
89749350 | 6415 | |
1d1d0e27 VS |
6416 | /* |
6417 | * Pipe horizontal size must be even in: | |
6418 | * - DVO ganged mode | |
6419 | * - LVDS dual channel mode | |
6420 | * - Double wide pipe | |
6421 | */ | |
a93e255f | 6422 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6423 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6424 | pipe_config->pipe_src_w &= ~1; | |
6425 | ||
8693a824 DL |
6426 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6427 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6428 | */ |
6429 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
6430 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) | |
e29c22c0 | 6431 | return -EINVAL; |
44f46b42 | 6432 | |
f5adf94e | 6433 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6434 | hsw_compute_ips_config(crtc, pipe_config); |
6435 | ||
877d48d5 | 6436 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6437 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6438 | |
d03c93d4 CK |
6439 | /* FIXME: remove below call once atomic mode set is place and all crtc |
6440 | * related checks called from atomic_crtc_check function */ | |
6441 | ret = 0; | |
6442 | DRM_DEBUG_KMS("intel_crtc = %p drm_state (pipe_config->base.state) = %p\n", | |
6443 | crtc, pipe_config->base.state); | |
6444 | ret = intel_atomic_setup_scalers(dev, crtc, pipe_config); | |
6445 | ||
6446 | return ret; | |
79e53945 JB |
6447 | } |
6448 | ||
1652d19e VS |
6449 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6450 | { | |
6451 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6452 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6453 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6454 | uint32_t linkrate; | |
6455 | ||
6456 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) { | |
6457 | WARN(1, "LCPLL1 not enabled\n"); | |
6458 | return 24000; /* 24MHz is the cd freq with NSSC ref */ | |
6459 | } | |
6460 | ||
6461 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6462 | return 540000; | |
6463 | ||
6464 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6465 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6466 | |
71cd8423 DL |
6467 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6468 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6469 | /* vco 8640 */ |
6470 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6471 | case CDCLK_FREQ_450_432: | |
6472 | return 432000; | |
6473 | case CDCLK_FREQ_337_308: | |
6474 | return 308570; | |
6475 | case CDCLK_FREQ_675_617: | |
6476 | return 617140; | |
6477 | default: | |
6478 | WARN(1, "Unknown cd freq selection\n"); | |
6479 | } | |
6480 | } else { | |
6481 | /* vco 8100 */ | |
6482 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6483 | case CDCLK_FREQ_450_432: | |
6484 | return 450000; | |
6485 | case CDCLK_FREQ_337_308: | |
6486 | return 337500; | |
6487 | case CDCLK_FREQ_675_617: | |
6488 | return 675000; | |
6489 | default: | |
6490 | WARN(1, "Unknown cd freq selection\n"); | |
6491 | } | |
6492 | } | |
6493 | ||
6494 | /* error case, do as if DPLL0 isn't enabled */ | |
6495 | return 24000; | |
6496 | } | |
6497 | ||
6498 | static int broadwell_get_display_clock_speed(struct drm_device *dev) | |
6499 | { | |
6500 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6501 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6502 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6503 | ||
6504 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6505 | return 800000; | |
6506 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6507 | return 450000; | |
6508 | else if (freq == LCPLL_CLK_FREQ_450) | |
6509 | return 450000; | |
6510 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6511 | return 540000; | |
6512 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6513 | return 337500; | |
6514 | else | |
6515 | return 675000; | |
6516 | } | |
6517 | ||
6518 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6519 | { | |
6520 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6521 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6522 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6523 | ||
6524 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6525 | return 800000; | |
6526 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6527 | return 450000; | |
6528 | else if (freq == LCPLL_CLK_FREQ_450) | |
6529 | return 450000; | |
6530 | else if (IS_HSW_ULT(dev)) | |
6531 | return 337500; | |
6532 | else | |
6533 | return 540000; | |
79e53945 JB |
6534 | } |
6535 | ||
25eb05fc JB |
6536 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6537 | { | |
d197b7d3 | 6538 | struct drm_i915_private *dev_priv = dev->dev_private; |
d197b7d3 VS |
6539 | u32 val; |
6540 | int divider; | |
6541 | ||
6bcda4f0 VS |
6542 | if (dev_priv->hpll_freq == 0) |
6543 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
6544 | ||
d197b7d3 VS |
6545 | mutex_lock(&dev_priv->dpio_lock); |
6546 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
6547 | mutex_unlock(&dev_priv->dpio_lock); | |
6548 | ||
6549 | divider = val & DISPLAY_FREQUENCY_VALUES; | |
6550 | ||
7d007f40 VS |
6551 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
6552 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
6553 | "cdclk change in progress\n"); | |
6554 | ||
6bcda4f0 | 6555 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
25eb05fc JB |
6556 | } |
6557 | ||
b37a6434 VS |
6558 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6559 | { | |
6560 | return 450000; | |
6561 | } | |
6562 | ||
e70236a8 JB |
6563 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6564 | { | |
6565 | return 400000; | |
6566 | } | |
79e53945 | 6567 | |
e70236a8 | 6568 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6569 | { |
e907f170 | 6570 | return 333333; |
e70236a8 | 6571 | } |
79e53945 | 6572 | |
e70236a8 JB |
6573 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6574 | { | |
6575 | return 200000; | |
6576 | } | |
79e53945 | 6577 | |
257a7ffc DV |
6578 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6579 | { | |
6580 | u16 gcfgc = 0; | |
6581 | ||
6582 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6583 | ||
6584 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6585 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6586 | return 266667; |
257a7ffc | 6587 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6588 | return 333333; |
257a7ffc | 6589 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6590 | return 444444; |
257a7ffc DV |
6591 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6592 | return 200000; | |
6593 | default: | |
6594 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6595 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6596 | return 133333; |
257a7ffc | 6597 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6598 | return 166667; |
257a7ffc DV |
6599 | } |
6600 | } | |
6601 | ||
e70236a8 JB |
6602 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6603 | { | |
6604 | u16 gcfgc = 0; | |
79e53945 | 6605 | |
e70236a8 JB |
6606 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6607 | ||
6608 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6609 | return 133333; |
e70236a8 JB |
6610 | else { |
6611 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6612 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6613 | return 333333; |
e70236a8 JB |
6614 | default: |
6615 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6616 | return 190000; | |
79e53945 | 6617 | } |
e70236a8 JB |
6618 | } |
6619 | } | |
6620 | ||
6621 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6622 | { | |
e907f170 | 6623 | return 266667; |
e70236a8 JB |
6624 | } |
6625 | ||
6626 | static int i855_get_display_clock_speed(struct drm_device *dev) | |
6627 | { | |
6628 | u16 hpllcc = 0; | |
6629 | /* Assume that the hardware is in the high speed state. This | |
6630 | * should be the default. | |
6631 | */ | |
6632 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6633 | case GC_CLOCK_133_200: | |
6634 | case GC_CLOCK_100_200: | |
6635 | return 200000; | |
6636 | case GC_CLOCK_166_250: | |
6637 | return 250000; | |
6638 | case GC_CLOCK_100_133: | |
e907f170 | 6639 | return 133333; |
e70236a8 | 6640 | } |
79e53945 | 6641 | |
e70236a8 JB |
6642 | /* Shouldn't happen */ |
6643 | return 0; | |
6644 | } | |
79e53945 | 6645 | |
e70236a8 JB |
6646 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6647 | { | |
e907f170 | 6648 | return 133333; |
79e53945 JB |
6649 | } |
6650 | ||
2c07245f | 6651 | static void |
a65851af | 6652 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 6653 | { |
a65851af VS |
6654 | while (*num > DATA_LINK_M_N_MASK || |
6655 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
6656 | *num >>= 1; |
6657 | *den >>= 1; | |
6658 | } | |
6659 | } | |
6660 | ||
a65851af VS |
6661 | static void compute_m_n(unsigned int m, unsigned int n, |
6662 | uint32_t *ret_m, uint32_t *ret_n) | |
6663 | { | |
6664 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
6665 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
6666 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
6667 | } | |
6668 | ||
e69d0bc1 DV |
6669 | void |
6670 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
6671 | int pixel_clock, int link_clock, | |
6672 | struct intel_link_m_n *m_n) | |
2c07245f | 6673 | { |
e69d0bc1 | 6674 | m_n->tu = 64; |
a65851af VS |
6675 | |
6676 | compute_m_n(bits_per_pixel * pixel_clock, | |
6677 | link_clock * nlanes * 8, | |
6678 | &m_n->gmch_m, &m_n->gmch_n); | |
6679 | ||
6680 | compute_m_n(pixel_clock, link_clock, | |
6681 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
6682 | } |
6683 | ||
a7615030 CW |
6684 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
6685 | { | |
d330a953 JN |
6686 | if (i915.panel_use_ssc >= 0) |
6687 | return i915.panel_use_ssc != 0; | |
41aa3448 | 6688 | return dev_priv->vbt.lvds_use_ssc |
435793df | 6689 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
6690 | } |
6691 | ||
a93e255f ACO |
6692 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
6693 | int num_connectors) | |
c65d77d8 | 6694 | { |
a93e255f | 6695 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
6696 | struct drm_i915_private *dev_priv = dev->dev_private; |
6697 | int refclk; | |
6698 | ||
a93e255f ACO |
6699 | WARN_ON(!crtc_state->base.state); |
6700 | ||
5ab7b0b7 | 6701 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 6702 | refclk = 100000; |
a93e255f | 6703 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 6704 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
6705 | refclk = dev_priv->vbt.lvds_ssc_freq; |
6706 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
6707 | } else if (!IS_GEN2(dev)) { |
6708 | refclk = 96000; | |
6709 | } else { | |
6710 | refclk = 48000; | |
6711 | } | |
6712 | ||
6713 | return refclk; | |
6714 | } | |
6715 | ||
7429e9d4 | 6716 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 6717 | { |
7df00d7a | 6718 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 6719 | } |
f47709a9 | 6720 | |
7429e9d4 DV |
6721 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
6722 | { | |
6723 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
6724 | } |
6725 | ||
f47709a9 | 6726 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 6727 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
6728 | intel_clock_t *reduced_clock) |
6729 | { | |
f47709a9 | 6730 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
6731 | u32 fp, fp2 = 0; |
6732 | ||
6733 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 6734 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 6735 | if (reduced_clock) |
7429e9d4 | 6736 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 6737 | } else { |
190f68c5 | 6738 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 6739 | if (reduced_clock) |
7429e9d4 | 6740 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
6741 | } |
6742 | ||
190f68c5 | 6743 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 6744 | |
f47709a9 | 6745 | crtc->lowfreq_avail = false; |
a93e255f | 6746 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 6747 | reduced_clock) { |
190f68c5 | 6748 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 6749 | crtc->lowfreq_avail = true; |
a7516a05 | 6750 | } else { |
190f68c5 | 6751 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
6752 | } |
6753 | } | |
6754 | ||
5e69f97f CML |
6755 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
6756 | pipe) | |
89b667f8 JB |
6757 | { |
6758 | u32 reg_val; | |
6759 | ||
6760 | /* | |
6761 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
6762 | * and set it to a reasonable value instead. | |
6763 | */ | |
ab3c759a | 6764 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
6765 | reg_val &= 0xffffff00; |
6766 | reg_val |= 0x00000030; | |
ab3c759a | 6767 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 6768 | |
ab3c759a | 6769 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
6770 | reg_val &= 0x8cffffff; |
6771 | reg_val = 0x8c000000; | |
ab3c759a | 6772 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 6773 | |
ab3c759a | 6774 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 6775 | reg_val &= 0xffffff00; |
ab3c759a | 6776 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 6777 | |
ab3c759a | 6778 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
6779 | reg_val &= 0x00ffffff; |
6780 | reg_val |= 0xb0000000; | |
ab3c759a | 6781 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
6782 | } |
6783 | ||
b551842d DV |
6784 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
6785 | struct intel_link_m_n *m_n) | |
6786 | { | |
6787 | struct drm_device *dev = crtc->base.dev; | |
6788 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6789 | int pipe = crtc->pipe; | |
6790 | ||
e3b95f1e DV |
6791 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
6792 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
6793 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
6794 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
6795 | } |
6796 | ||
6797 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
6798 | struct intel_link_m_n *m_n, |
6799 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
6800 | { |
6801 | struct drm_device *dev = crtc->base.dev; | |
6802 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6803 | int pipe = crtc->pipe; | |
6e3c9717 | 6804 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
6805 | |
6806 | if (INTEL_INFO(dev)->gen >= 5) { | |
6807 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
6808 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
6809 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
6810 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
6811 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
6812 | * for gen < 8) and if DRRS is supported (to make sure the | |
6813 | * registers are not unnecessarily accessed). | |
6814 | */ | |
44395bfe | 6815 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 6816 | crtc->config->has_drrs) { |
f769cd24 VK |
6817 | I915_WRITE(PIPE_DATA_M2(transcoder), |
6818 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
6819 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
6820 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
6821 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
6822 | } | |
b551842d | 6823 | } else { |
e3b95f1e DV |
6824 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
6825 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
6826 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
6827 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
6828 | } |
6829 | } | |
6830 | ||
fe3cd48d | 6831 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 6832 | { |
fe3cd48d R |
6833 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
6834 | ||
6835 | if (m_n == M1_N1) { | |
6836 | dp_m_n = &crtc->config->dp_m_n; | |
6837 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
6838 | } else if (m_n == M2_N2) { | |
6839 | ||
6840 | /* | |
6841 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
6842 | * needs to be programmed into M1_N1. | |
6843 | */ | |
6844 | dp_m_n = &crtc->config->dp_m2_n2; | |
6845 | } else { | |
6846 | DRM_ERROR("Unsupported divider value\n"); | |
6847 | return; | |
6848 | } | |
6849 | ||
6e3c9717 ACO |
6850 | if (crtc->config->has_pch_encoder) |
6851 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 6852 | else |
fe3cd48d | 6853 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
6854 | } |
6855 | ||
d288f65f | 6856 | static void vlv_update_pll(struct intel_crtc *crtc, |
5cec258b | 6857 | struct intel_crtc_state *pipe_config) |
bdd4b6a6 DV |
6858 | { |
6859 | u32 dpll, dpll_md; | |
6860 | ||
6861 | /* | |
6862 | * Enable DPIO clock input. We should never disable the reference | |
6863 | * clock for pipe B, since VGA hotplug / manual detection depends | |
6864 | * on it. | |
6865 | */ | |
6866 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | | |
6867 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; | |
6868 | /* We should never disable this, set it here for state tracking */ | |
6869 | if (crtc->pipe == PIPE_B) | |
6870 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
6871 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 6872 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 6873 | |
d288f65f | 6874 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 6875 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 6876 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
6877 | } |
6878 | ||
d288f65f | 6879 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 6880 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 6881 | { |
f47709a9 | 6882 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 6883 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 6884 | int pipe = crtc->pipe; |
bdd4b6a6 | 6885 | u32 mdiv; |
a0c4da24 | 6886 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 6887 | u32 coreclk, reg_val; |
a0c4da24 | 6888 | |
09153000 DV |
6889 | mutex_lock(&dev_priv->dpio_lock); |
6890 | ||
d288f65f VS |
6891 | bestn = pipe_config->dpll.n; |
6892 | bestm1 = pipe_config->dpll.m1; | |
6893 | bestm2 = pipe_config->dpll.m2; | |
6894 | bestp1 = pipe_config->dpll.p1; | |
6895 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 6896 | |
89b667f8 JB |
6897 | /* See eDP HDMI DPIO driver vbios notes doc */ |
6898 | ||
6899 | /* PLL B needs special handling */ | |
bdd4b6a6 | 6900 | if (pipe == PIPE_B) |
5e69f97f | 6901 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
6902 | |
6903 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 6904 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
6905 | |
6906 | /* Disable target IRef on PLL */ | |
ab3c759a | 6907 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 6908 | reg_val &= 0x00ffffff; |
ab3c759a | 6909 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
6910 | |
6911 | /* Disable fast lock */ | |
ab3c759a | 6912 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
6913 | |
6914 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
6915 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
6916 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
6917 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 6918 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
6919 | |
6920 | /* | |
6921 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
6922 | * but we don't support that). | |
6923 | * Note: don't use the DAC post divider as it seems unstable. | |
6924 | */ | |
6925 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 6926 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 6927 | |
a0c4da24 | 6928 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 6929 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 6930 | |
89b667f8 | 6931 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 6932 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
6933 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
6934 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 6935 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 6936 | 0x009f0003); |
89b667f8 | 6937 | else |
ab3c759a | 6938 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
6939 | 0x00d0000f); |
6940 | ||
681a8504 | 6941 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 6942 | /* Use SSC source */ |
bdd4b6a6 | 6943 | if (pipe == PIPE_A) |
ab3c759a | 6944 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6945 | 0x0df40000); |
6946 | else | |
ab3c759a | 6947 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6948 | 0x0df70000); |
6949 | } else { /* HDMI or VGA */ | |
6950 | /* Use bend source */ | |
bdd4b6a6 | 6951 | if (pipe == PIPE_A) |
ab3c759a | 6952 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6953 | 0x0df70000); |
6954 | else | |
ab3c759a | 6955 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6956 | 0x0df40000); |
6957 | } | |
a0c4da24 | 6958 | |
ab3c759a | 6959 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 6960 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
6961 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
6962 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 6963 | coreclk |= 0x01000000; |
ab3c759a | 6964 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 6965 | |
ab3c759a | 6966 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
09153000 | 6967 | mutex_unlock(&dev_priv->dpio_lock); |
a0c4da24 JB |
6968 | } |
6969 | ||
d288f65f | 6970 | static void chv_update_pll(struct intel_crtc *crtc, |
5cec258b | 6971 | struct intel_crtc_state *pipe_config) |
1ae0d137 | 6972 | { |
d288f65f | 6973 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
1ae0d137 VS |
6974 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
6975 | DPLL_VCO_ENABLE; | |
6976 | if (crtc->pipe != PIPE_A) | |
d288f65f | 6977 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 6978 | |
d288f65f VS |
6979 | pipe_config->dpll_hw_state.dpll_md = |
6980 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
6981 | } |
6982 | ||
d288f65f | 6983 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 6984 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
6985 | { |
6986 | struct drm_device *dev = crtc->base.dev; | |
6987 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6988 | int pipe = crtc->pipe; | |
6989 | int dpll_reg = DPLL(crtc->pipe); | |
6990 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 6991 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 6992 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 6993 | u32 dpio_val; |
9cbe40c1 | 6994 | int vco; |
9d556c99 | 6995 | |
d288f65f VS |
6996 | bestn = pipe_config->dpll.n; |
6997 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
6998 | bestm1 = pipe_config->dpll.m1; | |
6999 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7000 | bestp1 = pipe_config->dpll.p1; | |
7001 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7002 | vco = pipe_config->dpll.vco; |
a945ce7e | 7003 | dpio_val = 0; |
9cbe40c1 | 7004 | loopfilter = 0; |
9d556c99 CML |
7005 | |
7006 | /* | |
7007 | * Enable Refclk and SSC | |
7008 | */ | |
a11b0703 | 7009 | I915_WRITE(dpll_reg, |
d288f65f | 7010 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 VS |
7011 | |
7012 | mutex_lock(&dev_priv->dpio_lock); | |
9d556c99 | 7013 | |
9d556c99 CML |
7014 | /* p1 and p2 divider */ |
7015 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7016 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7017 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7018 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7019 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7020 | ||
7021 | /* Feedback post-divider - m2 */ | |
7022 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7023 | ||
7024 | /* Feedback refclk divider - n and m1 */ | |
7025 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7026 | DPIO_CHV_M1_DIV_BY_2 | | |
7027 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7028 | ||
7029 | /* M2 fraction division */ | |
a945ce7e VP |
7030 | if (bestm2_frac) |
7031 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); | |
9d556c99 CML |
7032 | |
7033 | /* M2 fraction division enable */ | |
a945ce7e VP |
7034 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7035 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7036 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7037 | if (bestm2_frac) | |
7038 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7039 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7040 | |
de3a0fde VP |
7041 | /* Program digital lock detect threshold */ |
7042 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7043 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7044 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7045 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7046 | if (!bestm2_frac) | |
7047 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7048 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7049 | ||
9d556c99 | 7050 | /* Loop filter */ |
9cbe40c1 VP |
7051 | if (vco == 5400000) { |
7052 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7053 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7054 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7055 | tribuf_calcntr = 0x9; | |
7056 | } else if (vco <= 6200000) { | |
7057 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7058 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7059 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7060 | tribuf_calcntr = 0x9; | |
7061 | } else if (vco <= 6480000) { | |
7062 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7063 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7064 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7065 | tribuf_calcntr = 0x8; | |
7066 | } else { | |
7067 | /* Not supported. Apply the same limits as in the max case */ | |
7068 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7069 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7070 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7071 | tribuf_calcntr = 0; | |
7072 | } | |
9d556c99 CML |
7073 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7074 | ||
968040b2 | 7075 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7076 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7077 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7078 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7079 | ||
9d556c99 CML |
7080 | /* AFC Recal */ |
7081 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7082 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7083 | DPIO_AFC_RECAL); | |
7084 | ||
7085 | mutex_unlock(&dev_priv->dpio_lock); | |
7086 | } | |
7087 | ||
d288f65f VS |
7088 | /** |
7089 | * vlv_force_pll_on - forcibly enable just the PLL | |
7090 | * @dev_priv: i915 private structure | |
7091 | * @pipe: pipe PLL to enable | |
7092 | * @dpll: PLL configuration | |
7093 | * | |
7094 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7095 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7096 | * be enabled. | |
7097 | */ | |
7098 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7099 | const struct dpll *dpll) | |
7100 | { | |
7101 | struct intel_crtc *crtc = | |
7102 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7103 | struct intel_crtc_state pipe_config = { |
a93e255f | 7104 | .base.crtc = &crtc->base, |
d288f65f VS |
7105 | .pixel_multiplier = 1, |
7106 | .dpll = *dpll, | |
7107 | }; | |
7108 | ||
7109 | if (IS_CHERRYVIEW(dev)) { | |
7110 | chv_update_pll(crtc, &pipe_config); | |
7111 | chv_prepare_pll(crtc, &pipe_config); | |
7112 | chv_enable_pll(crtc, &pipe_config); | |
7113 | } else { | |
7114 | vlv_update_pll(crtc, &pipe_config); | |
7115 | vlv_prepare_pll(crtc, &pipe_config); | |
7116 | vlv_enable_pll(crtc, &pipe_config); | |
7117 | } | |
7118 | } | |
7119 | ||
7120 | /** | |
7121 | * vlv_force_pll_off - forcibly disable just the PLL | |
7122 | * @dev_priv: i915 private structure | |
7123 | * @pipe: pipe PLL to disable | |
7124 | * | |
7125 | * Disable the PLL for @pipe. To be used in cases where we need | |
7126 | * the PLL enabled even when @pipe is not going to be enabled. | |
7127 | */ | |
7128 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7129 | { | |
7130 | if (IS_CHERRYVIEW(dev)) | |
7131 | chv_disable_pll(to_i915(dev), pipe); | |
7132 | else | |
7133 | vlv_disable_pll(to_i915(dev), pipe); | |
7134 | } | |
7135 | ||
f47709a9 | 7136 | static void i9xx_update_pll(struct intel_crtc *crtc, |
190f68c5 | 7137 | struct intel_crtc_state *crtc_state, |
f47709a9 | 7138 | intel_clock_t *reduced_clock, |
eb1cbe48 DV |
7139 | int num_connectors) |
7140 | { | |
f47709a9 | 7141 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7142 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7143 | u32 dpll; |
7144 | bool is_sdvo; | |
190f68c5 | 7145 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7146 | |
190f68c5 | 7147 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7148 | |
a93e255f ACO |
7149 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7150 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7151 | |
7152 | dpll = DPLL_VGA_MODE_DIS; | |
7153 | ||
a93e255f | 7154 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7155 | dpll |= DPLLB_MODE_LVDS; |
7156 | else | |
7157 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7158 | |
ef1b460d | 7159 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7160 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7161 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7162 | } |
198a037f DV |
7163 | |
7164 | if (is_sdvo) | |
4a33e48d | 7165 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7166 | |
190f68c5 | 7167 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7168 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7169 | |
7170 | /* compute bitmask from p1 value */ | |
7171 | if (IS_PINEVIEW(dev)) | |
7172 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7173 | else { | |
7174 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7175 | if (IS_G4X(dev) && reduced_clock) | |
7176 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7177 | } | |
7178 | switch (clock->p2) { | |
7179 | case 5: | |
7180 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7181 | break; | |
7182 | case 7: | |
7183 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7184 | break; | |
7185 | case 10: | |
7186 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7187 | break; | |
7188 | case 14: | |
7189 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7190 | break; | |
7191 | } | |
7192 | if (INTEL_INFO(dev)->gen >= 4) | |
7193 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7194 | ||
190f68c5 | 7195 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7196 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7197 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7198 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7199 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7200 | else | |
7201 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7202 | ||
7203 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7204 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7205 | |
eb1cbe48 | 7206 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7207 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7208 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7209 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7210 | } |
7211 | } | |
7212 | ||
f47709a9 | 7213 | static void i8xx_update_pll(struct intel_crtc *crtc, |
190f68c5 | 7214 | struct intel_crtc_state *crtc_state, |
f47709a9 | 7215 | intel_clock_t *reduced_clock, |
eb1cbe48 DV |
7216 | int num_connectors) |
7217 | { | |
f47709a9 | 7218 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7219 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7220 | u32 dpll; |
190f68c5 | 7221 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7222 | |
190f68c5 | 7223 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7224 | |
eb1cbe48 DV |
7225 | dpll = DPLL_VGA_MODE_DIS; |
7226 | ||
a93e255f | 7227 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7228 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7229 | } else { | |
7230 | if (clock->p1 == 2) | |
7231 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7232 | else | |
7233 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7234 | if (clock->p2 == 4) | |
7235 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7236 | } | |
7237 | ||
a93e255f | 7238 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7239 | dpll |= DPLL_DVO_2X_MODE; |
7240 | ||
a93e255f | 7241 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7242 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7243 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7244 | else | |
7245 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7246 | ||
7247 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7248 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7249 | } |
7250 | ||
8a654f3b | 7251 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7252 | { |
7253 | struct drm_device *dev = intel_crtc->base.dev; | |
7254 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7255 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7256 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
8a654f3b | 7257 | struct drm_display_mode *adjusted_mode = |
6e3c9717 | 7258 | &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7259 | uint32_t crtc_vtotal, crtc_vblank_end; |
7260 | int vsyncshift = 0; | |
4d8a62ea DV |
7261 | |
7262 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7263 | * the hw state checker will get angry at the mismatch. */ | |
7264 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7265 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7266 | |
609aeaca | 7267 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7268 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7269 | crtc_vtotal -= 1; |
7270 | crtc_vblank_end -= 1; | |
609aeaca | 7271 | |
409ee761 | 7272 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7273 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7274 | else | |
7275 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7276 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7277 | if (vsyncshift < 0) |
7278 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7279 | } |
7280 | ||
7281 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7282 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7283 | |
fe2b8f9d | 7284 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7285 | (adjusted_mode->crtc_hdisplay - 1) | |
7286 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7287 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7288 | (adjusted_mode->crtc_hblank_start - 1) | |
7289 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7290 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7291 | (adjusted_mode->crtc_hsync_start - 1) | |
7292 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7293 | ||
fe2b8f9d | 7294 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7295 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7296 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7297 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7298 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7299 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7300 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7301 | (adjusted_mode->crtc_vsync_start - 1) | |
7302 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7303 | ||
b5e508d4 PZ |
7304 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7305 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7306 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7307 | * bits. */ | |
7308 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7309 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7310 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7311 | ||
b0e77b9c PZ |
7312 | /* pipesrc controls the size that is scaled from, which should |
7313 | * always be the user's requested size. | |
7314 | */ | |
7315 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7316 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7317 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7318 | } |
7319 | ||
1bd1bd80 | 7320 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7321 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7322 | { |
7323 | struct drm_device *dev = crtc->base.dev; | |
7324 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7325 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7326 | uint32_t tmp; | |
7327 | ||
7328 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7329 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7330 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7331 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7332 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7333 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7334 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7335 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7336 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7337 | |
7338 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7339 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7340 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7341 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7342 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7343 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7344 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7345 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7346 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7347 | |
7348 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7349 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7350 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7351 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7352 | } |
7353 | ||
7354 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7355 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7356 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7357 | ||
2d112de7 ACO |
7358 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7359 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7360 | } |
7361 | ||
f6a83288 | 7362 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7363 | struct intel_crtc_state *pipe_config) |
babea61d | 7364 | { |
2d112de7 ACO |
7365 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7366 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7367 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7368 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7369 | |
2d112de7 ACO |
7370 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7371 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7372 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7373 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7374 | |
2d112de7 | 7375 | mode->flags = pipe_config->base.adjusted_mode.flags; |
babea61d | 7376 | |
2d112de7 ACO |
7377 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7378 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
babea61d JB |
7379 | } |
7380 | ||
84b046f3 DV |
7381 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7382 | { | |
7383 | struct drm_device *dev = intel_crtc->base.dev; | |
7384 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7385 | uint32_t pipeconf; | |
7386 | ||
9f11a9e4 | 7387 | pipeconf = 0; |
84b046f3 | 7388 | |
b6b5d049 VS |
7389 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7390 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7391 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7392 | |
6e3c9717 | 7393 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7394 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7395 | |
ff9ce46e DV |
7396 | /* only g4x and later have fancy bpc/dither controls */ |
7397 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7398 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7399 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7400 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7401 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7402 | |
6e3c9717 | 7403 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7404 | case 18: |
7405 | pipeconf |= PIPECONF_6BPC; | |
7406 | break; | |
7407 | case 24: | |
7408 | pipeconf |= PIPECONF_8BPC; | |
7409 | break; | |
7410 | case 30: | |
7411 | pipeconf |= PIPECONF_10BPC; | |
7412 | break; | |
7413 | default: | |
7414 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7415 | BUG(); | |
84b046f3 DV |
7416 | } |
7417 | } | |
7418 | ||
7419 | if (HAS_PIPE_CXSR(dev)) { | |
7420 | if (intel_crtc->lowfreq_avail) { | |
7421 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7422 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7423 | } else { | |
7424 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7425 | } |
7426 | } | |
7427 | ||
6e3c9717 | 7428 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7429 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7430 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7431 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7432 | else | |
7433 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7434 | } else | |
84b046f3 DV |
7435 | pipeconf |= PIPECONF_PROGRESSIVE; |
7436 | ||
6e3c9717 | 7437 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7438 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7439 | |
84b046f3 DV |
7440 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7441 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7442 | } | |
7443 | ||
190f68c5 ACO |
7444 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7445 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7446 | { |
c7653199 | 7447 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7448 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7449 | int refclk, num_connectors = 0; |
652c393a | 7450 | intel_clock_t clock, reduced_clock; |
a16af721 | 7451 | bool ok, has_reduced_clock = false; |
e9fd1c02 | 7452 | bool is_lvds = false, is_dsi = false; |
5eddb70b | 7453 | struct intel_encoder *encoder; |
d4906093 | 7454 | const intel_limit_t *limit; |
55bb9992 | 7455 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7456 | struct drm_connector *connector; |
55bb9992 ACO |
7457 | struct drm_connector_state *connector_state; |
7458 | int i; | |
79e53945 | 7459 | |
dd3cd74a ACO |
7460 | memset(&crtc_state->dpll_hw_state, 0, |
7461 | sizeof(crtc_state->dpll_hw_state)); | |
7462 | ||
da3ced29 | 7463 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7464 | if (connector_state->crtc != &crtc->base) |
7465 | continue; | |
7466 | ||
7467 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7468 | ||
5eddb70b | 7469 | switch (encoder->type) { |
79e53945 JB |
7470 | case INTEL_OUTPUT_LVDS: |
7471 | is_lvds = true; | |
7472 | break; | |
e9fd1c02 JN |
7473 | case INTEL_OUTPUT_DSI: |
7474 | is_dsi = true; | |
7475 | break; | |
6847d71b PZ |
7476 | default: |
7477 | break; | |
79e53945 | 7478 | } |
43565a06 | 7479 | |
c751ce4f | 7480 | num_connectors++; |
79e53945 JB |
7481 | } |
7482 | ||
f2335330 | 7483 | if (is_dsi) |
5b18e57c | 7484 | return 0; |
f2335330 | 7485 | |
190f68c5 | 7486 | if (!crtc_state->clock_set) { |
a93e255f | 7487 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7488 | |
e9fd1c02 JN |
7489 | /* |
7490 | * Returns a set of divisors for the desired target clock with | |
7491 | * the given refclk, or FALSE. The returned values represent | |
7492 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7493 | * 2) / p1 / p2. | |
7494 | */ | |
a93e255f ACO |
7495 | limit = intel_limit(crtc_state, refclk); |
7496 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7497 | crtc_state->port_clock, |
e9fd1c02 | 7498 | refclk, NULL, &clock); |
f2335330 | 7499 | if (!ok) { |
e9fd1c02 JN |
7500 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7501 | return -EINVAL; | |
7502 | } | |
79e53945 | 7503 | |
f2335330 JN |
7504 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
7505 | /* | |
7506 | * Ensure we match the reduced clock's P to the target | |
7507 | * clock. If the clocks don't match, we can't switch | |
7508 | * the display clock by using the FP0/FP1. In such case | |
7509 | * we will disable the LVDS downclock feature. | |
7510 | */ | |
7511 | has_reduced_clock = | |
a93e255f | 7512 | dev_priv->display.find_dpll(limit, crtc_state, |
f2335330 JN |
7513 | dev_priv->lvds_downclock, |
7514 | refclk, &clock, | |
7515 | &reduced_clock); | |
7516 | } | |
7517 | /* Compat-code for transition, will disappear. */ | |
190f68c5 ACO |
7518 | crtc_state->dpll.n = clock.n; |
7519 | crtc_state->dpll.m1 = clock.m1; | |
7520 | crtc_state->dpll.m2 = clock.m2; | |
7521 | crtc_state->dpll.p1 = clock.p1; | |
7522 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7523 | } |
7026d4ac | 7524 | |
e9fd1c02 | 7525 | if (IS_GEN2(dev)) { |
190f68c5 | 7526 | i8xx_update_pll(crtc, crtc_state, |
2a8f64ca VP |
7527 | has_reduced_clock ? &reduced_clock : NULL, |
7528 | num_connectors); | |
9d556c99 | 7529 | } else if (IS_CHERRYVIEW(dev)) { |
190f68c5 | 7530 | chv_update_pll(crtc, crtc_state); |
e9fd1c02 | 7531 | } else if (IS_VALLEYVIEW(dev)) { |
190f68c5 | 7532 | vlv_update_pll(crtc, crtc_state); |
e9fd1c02 | 7533 | } else { |
190f68c5 | 7534 | i9xx_update_pll(crtc, crtc_state, |
eb1cbe48 | 7535 | has_reduced_clock ? &reduced_clock : NULL, |
eba905b2 | 7536 | num_connectors); |
e9fd1c02 | 7537 | } |
79e53945 | 7538 | |
c8f7a0db | 7539 | return 0; |
f564048e EA |
7540 | } |
7541 | ||
2fa2fe9a | 7542 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7543 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7544 | { |
7545 | struct drm_device *dev = crtc->base.dev; | |
7546 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7547 | uint32_t tmp; | |
7548 | ||
dc9e7dec VS |
7549 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7550 | return; | |
7551 | ||
2fa2fe9a | 7552 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7553 | if (!(tmp & PFIT_ENABLE)) |
7554 | return; | |
2fa2fe9a | 7555 | |
06922821 | 7556 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7557 | if (INTEL_INFO(dev)->gen < 4) { |
7558 | if (crtc->pipe != PIPE_B) | |
7559 | return; | |
2fa2fe9a DV |
7560 | } else { |
7561 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7562 | return; | |
7563 | } | |
7564 | ||
06922821 | 7565 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
7566 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
7567 | if (INTEL_INFO(dev)->gen < 5) | |
7568 | pipe_config->gmch_pfit.lvds_border_bits = | |
7569 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
7570 | } | |
7571 | ||
acbec814 | 7572 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7573 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7574 | { |
7575 | struct drm_device *dev = crtc->base.dev; | |
7576 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7577 | int pipe = pipe_config->cpu_transcoder; | |
7578 | intel_clock_t clock; | |
7579 | u32 mdiv; | |
662c6ecb | 7580 | int refclk = 100000; |
acbec814 | 7581 | |
f573de5a SK |
7582 | /* In case of MIPI DPLL will not even be used */ |
7583 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
7584 | return; | |
7585 | ||
acbec814 | 7586 | mutex_lock(&dev_priv->dpio_lock); |
ab3c759a | 7587 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
acbec814 JB |
7588 | mutex_unlock(&dev_priv->dpio_lock); |
7589 | ||
7590 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7591 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7592 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7593 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7594 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7595 | ||
f646628b | 7596 | vlv_clock(refclk, &clock); |
acbec814 | 7597 | |
f646628b VS |
7598 | /* clock.dot is the fast clock */ |
7599 | pipe_config->port_clock = clock.dot / 5; | |
acbec814 JB |
7600 | } |
7601 | ||
5724dbd1 DL |
7602 | static void |
7603 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7604 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7605 | { |
7606 | struct drm_device *dev = crtc->base.dev; | |
7607 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7608 | u32 val, base, offset; | |
7609 | int pipe = crtc->pipe, plane = crtc->plane; | |
7610 | int fourcc, pixel_format; | |
6761dd31 | 7611 | unsigned int aligned_height; |
b113d5ee | 7612 | struct drm_framebuffer *fb; |
1b842c89 | 7613 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7614 | |
42a7b088 DL |
7615 | val = I915_READ(DSPCNTR(plane)); |
7616 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7617 | return; | |
7618 | ||
d9806c9f | 7619 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7620 | if (!intel_fb) { |
1ad292b5 JB |
7621 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7622 | return; | |
7623 | } | |
7624 | ||
1b842c89 DL |
7625 | fb = &intel_fb->base; |
7626 | ||
18c5247e DV |
7627 | if (INTEL_INFO(dev)->gen >= 4) { |
7628 | if (val & DISPPLANE_TILED) { | |
49af449b | 7629 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
7630 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
7631 | } | |
7632 | } | |
1ad292b5 JB |
7633 | |
7634 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 7635 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
7636 | fb->pixel_format = fourcc; |
7637 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
7638 | |
7639 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 7640 | if (plane_config->tiling) |
1ad292b5 JB |
7641 | offset = I915_READ(DSPTILEOFF(plane)); |
7642 | else | |
7643 | offset = I915_READ(DSPLINOFF(plane)); | |
7644 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
7645 | } else { | |
7646 | base = I915_READ(DSPADDR(plane)); | |
7647 | } | |
7648 | plane_config->base = base; | |
7649 | ||
7650 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
7651 | fb->width = ((val >> 16) & 0xfff) + 1; |
7652 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
7653 | |
7654 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 7655 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 7656 | |
b113d5ee | 7657 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
7658 | fb->pixel_format, |
7659 | fb->modifier[0]); | |
1ad292b5 | 7660 | |
f37b5c2b | 7661 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 7662 | |
2844a921 DL |
7663 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
7664 | pipe_name(pipe), plane, fb->width, fb->height, | |
7665 | fb->bits_per_pixel, base, fb->pitches[0], | |
7666 | plane_config->size); | |
1ad292b5 | 7667 | |
2d14030b | 7668 | plane_config->fb = intel_fb; |
1ad292b5 JB |
7669 | } |
7670 | ||
70b23a98 | 7671 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7672 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
7673 | { |
7674 | struct drm_device *dev = crtc->base.dev; | |
7675 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7676 | int pipe = pipe_config->cpu_transcoder; | |
7677 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
7678 | intel_clock_t clock; | |
7679 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; | |
7680 | int refclk = 100000; | |
7681 | ||
7682 | mutex_lock(&dev_priv->dpio_lock); | |
7683 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); | |
7684 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
7685 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
7686 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
7687 | mutex_unlock(&dev_priv->dpio_lock); | |
7688 | ||
7689 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
7690 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); | |
7691 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; | |
7692 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
7693 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
7694 | ||
7695 | chv_clock(refclk, &clock); | |
7696 | ||
7697 | /* clock.dot is the fast clock */ | |
7698 | pipe_config->port_clock = clock.dot / 5; | |
7699 | } | |
7700 | ||
0e8ffe1b | 7701 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 7702 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
7703 | { |
7704 | struct drm_device *dev = crtc->base.dev; | |
7705 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7706 | uint32_t tmp; | |
7707 | ||
f458ebbc DV |
7708 | if (!intel_display_power_is_enabled(dev_priv, |
7709 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
7710 | return false; |
7711 | ||
e143a21c | 7712 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 7713 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 7714 | |
0e8ffe1b DV |
7715 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
7716 | if (!(tmp & PIPECONF_ENABLE)) | |
7717 | return false; | |
7718 | ||
42571aef VS |
7719 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
7720 | switch (tmp & PIPECONF_BPC_MASK) { | |
7721 | case PIPECONF_6BPC: | |
7722 | pipe_config->pipe_bpp = 18; | |
7723 | break; | |
7724 | case PIPECONF_8BPC: | |
7725 | pipe_config->pipe_bpp = 24; | |
7726 | break; | |
7727 | case PIPECONF_10BPC: | |
7728 | pipe_config->pipe_bpp = 30; | |
7729 | break; | |
7730 | default: | |
7731 | break; | |
7732 | } | |
7733 | } | |
7734 | ||
b5a9fa09 DV |
7735 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
7736 | pipe_config->limited_color_range = true; | |
7737 | ||
282740f7 VS |
7738 | if (INTEL_INFO(dev)->gen < 4) |
7739 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
7740 | ||
1bd1bd80 DV |
7741 | intel_get_pipe_timings(crtc, pipe_config); |
7742 | ||
2fa2fe9a DV |
7743 | i9xx_get_pfit_config(crtc, pipe_config); |
7744 | ||
6c49f241 DV |
7745 | if (INTEL_INFO(dev)->gen >= 4) { |
7746 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
7747 | pipe_config->pixel_multiplier = | |
7748 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
7749 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 7750 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
7751 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
7752 | tmp = I915_READ(DPLL(crtc->pipe)); | |
7753 | pipe_config->pixel_multiplier = | |
7754 | ((tmp & SDVO_MULTIPLIER_MASK) | |
7755 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
7756 | } else { | |
7757 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
7758 | * port and will be fixed up in the encoder->get_config | |
7759 | * function. */ | |
7760 | pipe_config->pixel_multiplier = 1; | |
7761 | } | |
8bcc2795 DV |
7762 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
7763 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
7764 | /* |
7765 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
7766 | * on 830. Filter it out here so that we don't | |
7767 | * report errors due to that. | |
7768 | */ | |
7769 | if (IS_I830(dev)) | |
7770 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
7771 | ||
8bcc2795 DV |
7772 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
7773 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
7774 | } else { |
7775 | /* Mask out read-only status bits. */ | |
7776 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
7777 | DPLL_PORTC_READY_MASK | | |
7778 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 7779 | } |
6c49f241 | 7780 | |
70b23a98 VS |
7781 | if (IS_CHERRYVIEW(dev)) |
7782 | chv_crtc_clock_get(crtc, pipe_config); | |
7783 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
7784 | vlv_crtc_clock_get(crtc, pipe_config); |
7785 | else | |
7786 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 7787 | |
0e8ffe1b DV |
7788 | return true; |
7789 | } | |
7790 | ||
dde86e2d | 7791 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
7792 | { |
7793 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 7794 | struct intel_encoder *encoder; |
74cfd7ac | 7795 | u32 val, final; |
13d83a67 | 7796 | bool has_lvds = false; |
199e5d79 | 7797 | bool has_cpu_edp = false; |
199e5d79 | 7798 | bool has_panel = false; |
99eb6a01 KP |
7799 | bool has_ck505 = false; |
7800 | bool can_ssc = false; | |
13d83a67 JB |
7801 | |
7802 | /* We need to take the global config into account */ | |
b2784e15 | 7803 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
7804 | switch (encoder->type) { |
7805 | case INTEL_OUTPUT_LVDS: | |
7806 | has_panel = true; | |
7807 | has_lvds = true; | |
7808 | break; | |
7809 | case INTEL_OUTPUT_EDP: | |
7810 | has_panel = true; | |
2de6905f | 7811 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
7812 | has_cpu_edp = true; |
7813 | break; | |
6847d71b PZ |
7814 | default: |
7815 | break; | |
13d83a67 JB |
7816 | } |
7817 | } | |
7818 | ||
99eb6a01 | 7819 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 7820 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
7821 | can_ssc = has_ck505; |
7822 | } else { | |
7823 | has_ck505 = false; | |
7824 | can_ssc = true; | |
7825 | } | |
7826 | ||
2de6905f ID |
7827 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
7828 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
7829 | |
7830 | /* Ironlake: try to setup display ref clock before DPLL | |
7831 | * enabling. This is only under driver's control after | |
7832 | * PCH B stepping, previous chipset stepping should be | |
7833 | * ignoring this setting. | |
7834 | */ | |
74cfd7ac CW |
7835 | val = I915_READ(PCH_DREF_CONTROL); |
7836 | ||
7837 | /* As we must carefully and slowly disable/enable each source in turn, | |
7838 | * compute the final state we want first and check if we need to | |
7839 | * make any changes at all. | |
7840 | */ | |
7841 | final = val; | |
7842 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
7843 | if (has_ck505) | |
7844 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
7845 | else | |
7846 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
7847 | ||
7848 | final &= ~DREF_SSC_SOURCE_MASK; | |
7849 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
7850 | final &= ~DREF_SSC1_ENABLE; | |
7851 | ||
7852 | if (has_panel) { | |
7853 | final |= DREF_SSC_SOURCE_ENABLE; | |
7854 | ||
7855 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
7856 | final |= DREF_SSC1_ENABLE; | |
7857 | ||
7858 | if (has_cpu_edp) { | |
7859 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
7860 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
7861 | else | |
7862 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
7863 | } else | |
7864 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
7865 | } else { | |
7866 | final |= DREF_SSC_SOURCE_DISABLE; | |
7867 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
7868 | } | |
7869 | ||
7870 | if (final == val) | |
7871 | return; | |
7872 | ||
13d83a67 | 7873 | /* Always enable nonspread source */ |
74cfd7ac | 7874 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 7875 | |
99eb6a01 | 7876 | if (has_ck505) |
74cfd7ac | 7877 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 7878 | else |
74cfd7ac | 7879 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 7880 | |
199e5d79 | 7881 | if (has_panel) { |
74cfd7ac CW |
7882 | val &= ~DREF_SSC_SOURCE_MASK; |
7883 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 7884 | |
199e5d79 | 7885 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 7886 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 7887 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 7888 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 7889 | } else |
74cfd7ac | 7890 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
7891 | |
7892 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 7893 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
7894 | POSTING_READ(PCH_DREF_CONTROL); |
7895 | udelay(200); | |
7896 | ||
74cfd7ac | 7897 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
7898 | |
7899 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 7900 | if (has_cpu_edp) { |
99eb6a01 | 7901 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 7902 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 7903 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 7904 | } else |
74cfd7ac | 7905 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 7906 | } else |
74cfd7ac | 7907 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 7908 | |
74cfd7ac | 7909 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
7910 | POSTING_READ(PCH_DREF_CONTROL); |
7911 | udelay(200); | |
7912 | } else { | |
7913 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
7914 | ||
74cfd7ac | 7915 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
7916 | |
7917 | /* Turn off CPU output */ | |
74cfd7ac | 7918 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 7919 | |
74cfd7ac | 7920 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
7921 | POSTING_READ(PCH_DREF_CONTROL); |
7922 | udelay(200); | |
7923 | ||
7924 | /* Turn off the SSC source */ | |
74cfd7ac CW |
7925 | val &= ~DREF_SSC_SOURCE_MASK; |
7926 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
7927 | |
7928 | /* Turn off SSC1 */ | |
74cfd7ac | 7929 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 7930 | |
74cfd7ac | 7931 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
7932 | POSTING_READ(PCH_DREF_CONTROL); |
7933 | udelay(200); | |
7934 | } | |
74cfd7ac CW |
7935 | |
7936 | BUG_ON(val != final); | |
13d83a67 JB |
7937 | } |
7938 | ||
f31f2d55 | 7939 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 7940 | { |
f31f2d55 | 7941 | uint32_t tmp; |
dde86e2d | 7942 | |
0ff066a9 PZ |
7943 | tmp = I915_READ(SOUTH_CHICKEN2); |
7944 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
7945 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 7946 | |
0ff066a9 PZ |
7947 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
7948 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
7949 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 7950 | |
0ff066a9 PZ |
7951 | tmp = I915_READ(SOUTH_CHICKEN2); |
7952 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
7953 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 7954 | |
0ff066a9 PZ |
7955 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
7956 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
7957 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
7958 | } |
7959 | ||
7960 | /* WaMPhyProgramming:hsw */ | |
7961 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
7962 | { | |
7963 | uint32_t tmp; | |
dde86e2d PZ |
7964 | |
7965 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
7966 | tmp &= ~(0xFF << 24); | |
7967 | tmp |= (0x12 << 24); | |
7968 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
7969 | ||
dde86e2d PZ |
7970 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
7971 | tmp |= (1 << 11); | |
7972 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
7973 | ||
7974 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
7975 | tmp |= (1 << 11); | |
7976 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
7977 | ||
dde86e2d PZ |
7978 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
7979 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
7980 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
7981 | ||
7982 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
7983 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
7984 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
7985 | ||
0ff066a9 PZ |
7986 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
7987 | tmp &= ~(7 << 13); | |
7988 | tmp |= (5 << 13); | |
7989 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 7990 | |
0ff066a9 PZ |
7991 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
7992 | tmp &= ~(7 << 13); | |
7993 | tmp |= (5 << 13); | |
7994 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
7995 | |
7996 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
7997 | tmp &= ~0xFF; | |
7998 | tmp |= 0x1C; | |
7999 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8000 | ||
8001 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8002 | tmp &= ~0xFF; | |
8003 | tmp |= 0x1C; | |
8004 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8005 | ||
8006 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8007 | tmp &= ~(0xFF << 16); | |
8008 | tmp |= (0x1C << 16); | |
8009 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8010 | ||
8011 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8012 | tmp &= ~(0xFF << 16); | |
8013 | tmp |= (0x1C << 16); | |
8014 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8015 | ||
0ff066a9 PZ |
8016 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8017 | tmp |= (1 << 27); | |
8018 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8019 | |
0ff066a9 PZ |
8020 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8021 | tmp |= (1 << 27); | |
8022 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8023 | |
0ff066a9 PZ |
8024 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8025 | tmp &= ~(0xF << 28); | |
8026 | tmp |= (4 << 28); | |
8027 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8028 | |
0ff066a9 PZ |
8029 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8030 | tmp &= ~(0xF << 28); | |
8031 | tmp |= (4 << 28); | |
8032 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8033 | } |
8034 | ||
2fa86a1f PZ |
8035 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8036 | * Programming" based on the parameters passed: | |
8037 | * - Sequence to enable CLKOUT_DP | |
8038 | * - Sequence to enable CLKOUT_DP without spread | |
8039 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8040 | */ | |
8041 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8042 | bool with_fdi) | |
f31f2d55 PZ |
8043 | { |
8044 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8045 | uint32_t reg, tmp; |
8046 | ||
8047 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8048 | with_spread = true; | |
8049 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && | |
8050 | with_fdi, "LP PCH doesn't have FDI\n")) | |
8051 | with_fdi = false; | |
f31f2d55 PZ |
8052 | |
8053 | mutex_lock(&dev_priv->dpio_lock); | |
8054 | ||
8055 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8056 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8057 | tmp |= SBI_SSCCTL_PATHALT; | |
8058 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8059 | ||
8060 | udelay(24); | |
8061 | ||
2fa86a1f PZ |
8062 | if (with_spread) { |
8063 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8064 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8065 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8066 | |
2fa86a1f PZ |
8067 | if (with_fdi) { |
8068 | lpt_reset_fdi_mphy(dev_priv); | |
8069 | lpt_program_fdi_mphy(dev_priv); | |
8070 | } | |
8071 | } | |
dde86e2d | 8072 | |
2fa86a1f PZ |
8073 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
8074 | SBI_GEN0 : SBI_DBUFF0; | |
8075 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8076 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8077 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 DV |
8078 | |
8079 | mutex_unlock(&dev_priv->dpio_lock); | |
dde86e2d PZ |
8080 | } |
8081 | ||
47701c3b PZ |
8082 | /* Sequence to disable CLKOUT_DP */ |
8083 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8084 | { | |
8085 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8086 | uint32_t reg, tmp; | |
8087 | ||
8088 | mutex_lock(&dev_priv->dpio_lock); | |
8089 | ||
8090 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? | |
8091 | SBI_GEN0 : SBI_DBUFF0; | |
8092 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8093 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8094 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8095 | ||
8096 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8097 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8098 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8099 | tmp |= SBI_SSCCTL_PATHALT; | |
8100 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8101 | udelay(32); | |
8102 | } | |
8103 | tmp |= SBI_SSCCTL_DISABLE; | |
8104 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8105 | } | |
8106 | ||
8107 | mutex_unlock(&dev_priv->dpio_lock); | |
8108 | } | |
8109 | ||
bf8fa3d3 PZ |
8110 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8111 | { | |
bf8fa3d3 PZ |
8112 | struct intel_encoder *encoder; |
8113 | bool has_vga = false; | |
8114 | ||
b2784e15 | 8115 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8116 | switch (encoder->type) { |
8117 | case INTEL_OUTPUT_ANALOG: | |
8118 | has_vga = true; | |
8119 | break; | |
6847d71b PZ |
8120 | default: |
8121 | break; | |
bf8fa3d3 PZ |
8122 | } |
8123 | } | |
8124 | ||
47701c3b PZ |
8125 | if (has_vga) |
8126 | lpt_enable_clkout_dp(dev, true, true); | |
8127 | else | |
8128 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8129 | } |
8130 | ||
dde86e2d PZ |
8131 | /* |
8132 | * Initialize reference clocks when the driver loads | |
8133 | */ | |
8134 | void intel_init_pch_refclk(struct drm_device *dev) | |
8135 | { | |
8136 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8137 | ironlake_init_pch_refclk(dev); | |
8138 | else if (HAS_PCH_LPT(dev)) | |
8139 | lpt_init_pch_refclk(dev); | |
8140 | } | |
8141 | ||
55bb9992 | 8142 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8143 | { |
55bb9992 | 8144 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8145 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8146 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8147 | struct drm_connector *connector; |
55bb9992 | 8148 | struct drm_connector_state *connector_state; |
d9d444cb | 8149 | struct intel_encoder *encoder; |
55bb9992 | 8150 | int num_connectors = 0, i; |
d9d444cb JB |
8151 | bool is_lvds = false; |
8152 | ||
da3ced29 | 8153 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8154 | if (connector_state->crtc != crtc_state->base.crtc) |
8155 | continue; | |
8156 | ||
8157 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8158 | ||
d9d444cb JB |
8159 | switch (encoder->type) { |
8160 | case INTEL_OUTPUT_LVDS: | |
8161 | is_lvds = true; | |
8162 | break; | |
6847d71b PZ |
8163 | default: |
8164 | break; | |
d9d444cb JB |
8165 | } |
8166 | num_connectors++; | |
8167 | } | |
8168 | ||
8169 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8170 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8171 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8172 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8173 | } |
8174 | ||
8175 | return 120000; | |
8176 | } | |
8177 | ||
6ff93609 | 8178 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8179 | { |
c8203565 | 8180 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8181 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8182 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8183 | uint32_t val; |
8184 | ||
78114071 | 8185 | val = 0; |
c8203565 | 8186 | |
6e3c9717 | 8187 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8188 | case 18: |
dfd07d72 | 8189 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8190 | break; |
8191 | case 24: | |
dfd07d72 | 8192 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8193 | break; |
8194 | case 30: | |
dfd07d72 | 8195 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8196 | break; |
8197 | case 36: | |
dfd07d72 | 8198 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8199 | break; |
8200 | default: | |
cc769b62 PZ |
8201 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8202 | BUG(); | |
c8203565 PZ |
8203 | } |
8204 | ||
6e3c9717 | 8205 | if (intel_crtc->config->dither) |
c8203565 PZ |
8206 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8207 | ||
6e3c9717 | 8208 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8209 | val |= PIPECONF_INTERLACED_ILK; |
8210 | else | |
8211 | val |= PIPECONF_PROGRESSIVE; | |
8212 | ||
6e3c9717 | 8213 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8214 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8215 | |
c8203565 PZ |
8216 | I915_WRITE(PIPECONF(pipe), val); |
8217 | POSTING_READ(PIPECONF(pipe)); | |
8218 | } | |
8219 | ||
86d3efce VS |
8220 | /* |
8221 | * Set up the pipe CSC unit. | |
8222 | * | |
8223 | * Currently only full range RGB to limited range RGB conversion | |
8224 | * is supported, but eventually this should handle various | |
8225 | * RGB<->YCbCr scenarios as well. | |
8226 | */ | |
50f3b016 | 8227 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8228 | { |
8229 | struct drm_device *dev = crtc->dev; | |
8230 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8231 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8232 | int pipe = intel_crtc->pipe; | |
8233 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8234 | ||
8235 | /* | |
8236 | * TODO: Check what kind of values actually come out of the pipe | |
8237 | * with these coeff/postoff values and adjust to get the best | |
8238 | * accuracy. Perhaps we even need to take the bpc value into | |
8239 | * consideration. | |
8240 | */ | |
8241 | ||
6e3c9717 | 8242 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8243 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8244 | ||
8245 | /* | |
8246 | * GY/GU and RY/RU should be the other way around according | |
8247 | * to BSpec, but reality doesn't agree. Just set them up in | |
8248 | * a way that results in the correct picture. | |
8249 | */ | |
8250 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8251 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8252 | ||
8253 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8254 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8255 | ||
8256 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8257 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8258 | ||
8259 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8260 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8261 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8262 | ||
8263 | if (INTEL_INFO(dev)->gen > 6) { | |
8264 | uint16_t postoff = 0; | |
8265 | ||
6e3c9717 | 8266 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8267 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8268 | |
8269 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8270 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8271 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8272 | ||
8273 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8274 | } else { | |
8275 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8276 | ||
6e3c9717 | 8277 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8278 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8279 | ||
8280 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8281 | } | |
8282 | } | |
8283 | ||
6ff93609 | 8284 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8285 | { |
756f85cf PZ |
8286 | struct drm_device *dev = crtc->dev; |
8287 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8288 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8289 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8290 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8291 | uint32_t val; |
8292 | ||
3eff4faa | 8293 | val = 0; |
ee2b0b38 | 8294 | |
6e3c9717 | 8295 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8296 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8297 | ||
6e3c9717 | 8298 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8299 | val |= PIPECONF_INTERLACED_ILK; |
8300 | else | |
8301 | val |= PIPECONF_PROGRESSIVE; | |
8302 | ||
702e7a56 PZ |
8303 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8304 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8305 | |
8306 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8307 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8308 | |
3cdf122c | 8309 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8310 | val = 0; |
8311 | ||
6e3c9717 | 8312 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8313 | case 18: |
8314 | val |= PIPEMISC_DITHER_6_BPC; | |
8315 | break; | |
8316 | case 24: | |
8317 | val |= PIPEMISC_DITHER_8_BPC; | |
8318 | break; | |
8319 | case 30: | |
8320 | val |= PIPEMISC_DITHER_10_BPC; | |
8321 | break; | |
8322 | case 36: | |
8323 | val |= PIPEMISC_DITHER_12_BPC; | |
8324 | break; | |
8325 | default: | |
8326 | /* Case prevented by pipe_config_set_bpp. */ | |
8327 | BUG(); | |
8328 | } | |
8329 | ||
6e3c9717 | 8330 | if (intel_crtc->config->dither) |
756f85cf PZ |
8331 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8332 | ||
8333 | I915_WRITE(PIPEMISC(pipe), val); | |
8334 | } | |
ee2b0b38 PZ |
8335 | } |
8336 | ||
6591c6e4 | 8337 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8338 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8339 | intel_clock_t *clock, |
8340 | bool *has_reduced_clock, | |
8341 | intel_clock_t *reduced_clock) | |
8342 | { | |
8343 | struct drm_device *dev = crtc->dev; | |
8344 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8345 | int refclk; |
d4906093 | 8346 | const intel_limit_t *limit; |
a16af721 | 8347 | bool ret, is_lvds = false; |
79e53945 | 8348 | |
a93e255f | 8349 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
79e53945 | 8350 | |
55bb9992 | 8351 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8352 | |
d4906093 ML |
8353 | /* |
8354 | * Returns a set of divisors for the desired target clock with the given | |
8355 | * refclk, or FALSE. The returned values represent the clock equation: | |
8356 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8357 | */ | |
a93e255f ACO |
8358 | limit = intel_limit(crtc_state, refclk); |
8359 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8360 | crtc_state->port_clock, |
ee9300bb | 8361 | refclk, NULL, clock); |
6591c6e4 PZ |
8362 | if (!ret) |
8363 | return false; | |
cda4b7d3 | 8364 | |
ddc9003c | 8365 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
cec2f356 SP |
8366 | /* |
8367 | * Ensure we match the reduced clock's P to the target clock. | |
8368 | * If the clocks don't match, we can't switch the display clock | |
8369 | * by using the FP0/FP1. In such case we will disable the LVDS | |
8370 | * downclock feature. | |
8371 | */ | |
ee9300bb | 8372 | *has_reduced_clock = |
a93e255f | 8373 | dev_priv->display.find_dpll(limit, crtc_state, |
ee9300bb DV |
8374 | dev_priv->lvds_downclock, |
8375 | refclk, clock, | |
8376 | reduced_clock); | |
652c393a | 8377 | } |
61e9653f | 8378 | |
6591c6e4 PZ |
8379 | return true; |
8380 | } | |
8381 | ||
d4b1931c PZ |
8382 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8383 | { | |
8384 | /* | |
8385 | * Account for spread spectrum to avoid | |
8386 | * oversubscribing the link. Max center spread | |
8387 | * is 2.5%; use 5% for safety's sake. | |
8388 | */ | |
8389 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8390 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8391 | } |
8392 | ||
7429e9d4 | 8393 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8394 | { |
7429e9d4 | 8395 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8396 | } |
8397 | ||
de13a2e3 | 8398 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8399 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8400 | u32 *fp, |
9a7c7890 | 8401 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8402 | { |
de13a2e3 | 8403 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8404 | struct drm_device *dev = crtc->dev; |
8405 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8406 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8407 | struct drm_connector *connector; |
55bb9992 ACO |
8408 | struct drm_connector_state *connector_state; |
8409 | struct intel_encoder *encoder; | |
de13a2e3 | 8410 | uint32_t dpll; |
55bb9992 | 8411 | int factor, num_connectors = 0, i; |
09ede541 | 8412 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8413 | |
da3ced29 | 8414 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8415 | if (connector_state->crtc != crtc_state->base.crtc) |
8416 | continue; | |
8417 | ||
8418 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8419 | ||
8420 | switch (encoder->type) { | |
79e53945 JB |
8421 | case INTEL_OUTPUT_LVDS: |
8422 | is_lvds = true; | |
8423 | break; | |
8424 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8425 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8426 | is_sdvo = true; |
79e53945 | 8427 | break; |
6847d71b PZ |
8428 | default: |
8429 | break; | |
79e53945 | 8430 | } |
43565a06 | 8431 | |
c751ce4f | 8432 | num_connectors++; |
79e53945 | 8433 | } |
79e53945 | 8434 | |
c1858123 | 8435 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8436 | factor = 21; |
8437 | if (is_lvds) { | |
8438 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8439 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8440 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8441 | factor = 25; |
190f68c5 | 8442 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8443 | factor = 20; |
c1858123 | 8444 | |
190f68c5 | 8445 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8446 | *fp |= FP_CB_TUNE; |
2c07245f | 8447 | |
9a7c7890 DV |
8448 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8449 | *fp2 |= FP_CB_TUNE; | |
8450 | ||
5eddb70b | 8451 | dpll = 0; |
2c07245f | 8452 | |
a07d6787 EA |
8453 | if (is_lvds) |
8454 | dpll |= DPLLB_MODE_LVDS; | |
8455 | else | |
8456 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8457 | |
190f68c5 | 8458 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8459 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8460 | |
8461 | if (is_sdvo) | |
4a33e48d | 8462 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8463 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8464 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8465 | |
a07d6787 | 8466 | /* compute bitmask from p1 value */ |
190f68c5 | 8467 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8468 | /* also FPA1 */ |
190f68c5 | 8469 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8470 | |
190f68c5 | 8471 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8472 | case 5: |
8473 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8474 | break; | |
8475 | case 7: | |
8476 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8477 | break; | |
8478 | case 10: | |
8479 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8480 | break; | |
8481 | case 14: | |
8482 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8483 | break; | |
79e53945 JB |
8484 | } |
8485 | ||
b4c09f3b | 8486 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8487 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8488 | else |
8489 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8490 | ||
959e16d6 | 8491 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8492 | } |
8493 | ||
190f68c5 ACO |
8494 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8495 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8496 | { |
c7653199 | 8497 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8498 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8499 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8500 | bool ok, has_reduced_clock = false; |
8b47047b | 8501 | bool is_lvds = false; |
e2b78267 | 8502 | struct intel_shared_dpll *pll; |
de13a2e3 | 8503 | |
dd3cd74a ACO |
8504 | memset(&crtc_state->dpll_hw_state, 0, |
8505 | sizeof(crtc_state->dpll_hw_state)); | |
8506 | ||
409ee761 | 8507 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8508 | |
5dc5298b PZ |
8509 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8510 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8511 | |
190f68c5 | 8512 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8513 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8514 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8515 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8516 | return -EINVAL; | |
79e53945 | 8517 | } |
f47709a9 | 8518 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8519 | if (!crtc_state->clock_set) { |
8520 | crtc_state->dpll.n = clock.n; | |
8521 | crtc_state->dpll.m1 = clock.m1; | |
8522 | crtc_state->dpll.m2 = clock.m2; | |
8523 | crtc_state->dpll.p1 = clock.p1; | |
8524 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8525 | } |
79e53945 | 8526 | |
5dc5298b | 8527 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8528 | if (crtc_state->has_pch_encoder) { |
8529 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8530 | if (has_reduced_clock) |
7429e9d4 | 8531 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8532 | |
190f68c5 | 8533 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8534 | &fp, &reduced_clock, |
8535 | has_reduced_clock ? &fp2 : NULL); | |
8536 | ||
190f68c5 ACO |
8537 | crtc_state->dpll_hw_state.dpll = dpll; |
8538 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8539 | if (has_reduced_clock) |
190f68c5 | 8540 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8541 | else |
190f68c5 | 8542 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8543 | |
190f68c5 | 8544 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8545 | if (pll == NULL) { |
84f44ce7 | 8546 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8547 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8548 | return -EINVAL; |
8549 | } | |
3fb37703 | 8550 | } |
79e53945 | 8551 | |
ab585dea | 8552 | if (is_lvds && has_reduced_clock) |
c7653199 | 8553 | crtc->lowfreq_avail = true; |
bcd644e0 | 8554 | else |
c7653199 | 8555 | crtc->lowfreq_avail = false; |
e2b78267 | 8556 | |
c8f7a0db | 8557 | return 0; |
79e53945 JB |
8558 | } |
8559 | ||
eb14cb74 VS |
8560 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8561 | struct intel_link_m_n *m_n) | |
8562 | { | |
8563 | struct drm_device *dev = crtc->base.dev; | |
8564 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8565 | enum pipe pipe = crtc->pipe; | |
8566 | ||
8567 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8568 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8569 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8570 | & ~TU_SIZE_MASK; | |
8571 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8572 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8573 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8574 | } | |
8575 | ||
8576 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8577 | enum transcoder transcoder, | |
b95af8be VK |
8578 | struct intel_link_m_n *m_n, |
8579 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
8580 | { |
8581 | struct drm_device *dev = crtc->base.dev; | |
8582 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 8583 | enum pipe pipe = crtc->pipe; |
72419203 | 8584 | |
eb14cb74 VS |
8585 | if (INTEL_INFO(dev)->gen >= 5) { |
8586 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
8587 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8588 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8589 | & ~TU_SIZE_MASK; | |
8590 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8591 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8592 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8593 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8594 | * gen < 8) and if DRRS is supported (to make sure the | |
8595 | * registers are not unnecessarily read). | |
8596 | */ | |
8597 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 8598 | crtc->config->has_drrs) { |
b95af8be VK |
8599 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8600 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8601 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8602 | & ~TU_SIZE_MASK; | |
8603 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8604 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8605 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8606 | } | |
eb14cb74 VS |
8607 | } else { |
8608 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8609 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8610 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8611 | & ~TU_SIZE_MASK; | |
8612 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8613 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8614 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8615 | } | |
8616 | } | |
8617 | ||
8618 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8619 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8620 | { |
681a8504 | 8621 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8622 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8623 | else | |
8624 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8625 | &pipe_config->dp_m_n, |
8626 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8627 | } |
72419203 | 8628 | |
eb14cb74 | 8629 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 8630 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
8631 | { |
8632 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 8633 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
8634 | } |
8635 | ||
bd2e244f | 8636 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8637 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
8638 | { |
8639 | struct drm_device *dev = crtc->base.dev; | |
8640 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
8641 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
8642 | uint32_t ps_ctrl = 0; | |
8643 | int id = -1; | |
8644 | int i; | |
bd2e244f | 8645 | |
a1b2278e CK |
8646 | /* find scaler attached to this pipe */ |
8647 | for (i = 0; i < crtc->num_scalers; i++) { | |
8648 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
8649 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
8650 | id = i; | |
8651 | pipe_config->pch_pfit.enabled = true; | |
8652 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
8653 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
8654 | break; | |
8655 | } | |
8656 | } | |
bd2e244f | 8657 | |
a1b2278e CK |
8658 | scaler_state->scaler_id = id; |
8659 | if (id >= 0) { | |
8660 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
8661 | } else { | |
8662 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
8663 | } |
8664 | } | |
8665 | ||
5724dbd1 DL |
8666 | static void |
8667 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
8668 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
8669 | { |
8670 | struct drm_device *dev = crtc->base.dev; | |
8671 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 8672 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
8673 | int pipe = crtc->pipe; |
8674 | int fourcc, pixel_format; | |
6761dd31 | 8675 | unsigned int aligned_height; |
bc8d7dff | 8676 | struct drm_framebuffer *fb; |
1b842c89 | 8677 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 8678 | |
d9806c9f | 8679 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8680 | if (!intel_fb) { |
bc8d7dff DL |
8681 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8682 | return; | |
8683 | } | |
8684 | ||
1b842c89 DL |
8685 | fb = &intel_fb->base; |
8686 | ||
bc8d7dff | 8687 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
8688 | if (!(val & PLANE_CTL_ENABLE)) |
8689 | goto error; | |
8690 | ||
bc8d7dff DL |
8691 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
8692 | fourcc = skl_format_to_fourcc(pixel_format, | |
8693 | val & PLANE_CTL_ORDER_RGBX, | |
8694 | val & PLANE_CTL_ALPHA_MASK); | |
8695 | fb->pixel_format = fourcc; | |
8696 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
8697 | ||
40f46283 DL |
8698 | tiling = val & PLANE_CTL_TILED_MASK; |
8699 | switch (tiling) { | |
8700 | case PLANE_CTL_TILED_LINEAR: | |
8701 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
8702 | break; | |
8703 | case PLANE_CTL_TILED_X: | |
8704 | plane_config->tiling = I915_TILING_X; | |
8705 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
8706 | break; | |
8707 | case PLANE_CTL_TILED_Y: | |
8708 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
8709 | break; | |
8710 | case PLANE_CTL_TILED_YF: | |
8711 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
8712 | break; | |
8713 | default: | |
8714 | MISSING_CASE(tiling); | |
8715 | goto error; | |
8716 | } | |
8717 | ||
bc8d7dff DL |
8718 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
8719 | plane_config->base = base; | |
8720 | ||
8721 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
8722 | ||
8723 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
8724 | fb->height = ((val >> 16) & 0xfff) + 1; | |
8725 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
8726 | ||
8727 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
8728 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
8729 | fb->pixel_format); | |
bc8d7dff DL |
8730 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
8731 | ||
8732 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
8733 | fb->pixel_format, |
8734 | fb->modifier[0]); | |
bc8d7dff | 8735 | |
f37b5c2b | 8736 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
8737 | |
8738 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
8739 | pipe_name(pipe), fb->width, fb->height, | |
8740 | fb->bits_per_pixel, base, fb->pitches[0], | |
8741 | plane_config->size); | |
8742 | ||
2d14030b | 8743 | plane_config->fb = intel_fb; |
bc8d7dff DL |
8744 | return; |
8745 | ||
8746 | error: | |
8747 | kfree(fb); | |
8748 | } | |
8749 | ||
2fa2fe9a | 8750 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8751 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
8752 | { |
8753 | struct drm_device *dev = crtc->base.dev; | |
8754 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8755 | uint32_t tmp; | |
8756 | ||
8757 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
8758 | ||
8759 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 8760 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
8761 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
8762 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
8763 | |
8764 | /* We currently do not free assignements of panel fitters on | |
8765 | * ivb/hsw (since we don't use the higher upscaling modes which | |
8766 | * differentiates them) so just WARN about this case for now. */ | |
8767 | if (IS_GEN7(dev)) { | |
8768 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
8769 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
8770 | } | |
2fa2fe9a | 8771 | } |
79e53945 JB |
8772 | } |
8773 | ||
5724dbd1 DL |
8774 | static void |
8775 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
8776 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
8777 | { |
8778 | struct drm_device *dev = crtc->base.dev; | |
8779 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8780 | u32 val, base, offset; | |
aeee5a49 | 8781 | int pipe = crtc->pipe; |
4c6baa59 | 8782 | int fourcc, pixel_format; |
6761dd31 | 8783 | unsigned int aligned_height; |
b113d5ee | 8784 | struct drm_framebuffer *fb; |
1b842c89 | 8785 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 8786 | |
42a7b088 DL |
8787 | val = I915_READ(DSPCNTR(pipe)); |
8788 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8789 | return; | |
8790 | ||
d9806c9f | 8791 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8792 | if (!intel_fb) { |
4c6baa59 JB |
8793 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8794 | return; | |
8795 | } | |
8796 | ||
1b842c89 DL |
8797 | fb = &intel_fb->base; |
8798 | ||
18c5247e DV |
8799 | if (INTEL_INFO(dev)->gen >= 4) { |
8800 | if (val & DISPPLANE_TILED) { | |
49af449b | 8801 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8802 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8803 | } | |
8804 | } | |
4c6baa59 JB |
8805 | |
8806 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8807 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8808 | fb->pixel_format = fourcc; |
8809 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 8810 | |
aeee5a49 | 8811 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 8812 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 8813 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 8814 | } else { |
49af449b | 8815 | if (plane_config->tiling) |
aeee5a49 | 8816 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 8817 | else |
aeee5a49 | 8818 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
8819 | } |
8820 | plane_config->base = base; | |
8821 | ||
8822 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8823 | fb->width = ((val >> 16) & 0xfff) + 1; |
8824 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
8825 | |
8826 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8827 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 8828 | |
b113d5ee | 8829 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8830 | fb->pixel_format, |
8831 | fb->modifier[0]); | |
4c6baa59 | 8832 | |
f37b5c2b | 8833 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 8834 | |
2844a921 DL |
8835 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8836 | pipe_name(pipe), fb->width, fb->height, | |
8837 | fb->bits_per_pixel, base, fb->pitches[0], | |
8838 | plane_config->size); | |
b113d5ee | 8839 | |
2d14030b | 8840 | plane_config->fb = intel_fb; |
4c6baa59 JB |
8841 | } |
8842 | ||
0e8ffe1b | 8843 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8844 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8845 | { |
8846 | struct drm_device *dev = crtc->base.dev; | |
8847 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8848 | uint32_t tmp; | |
8849 | ||
f458ebbc DV |
8850 | if (!intel_display_power_is_enabled(dev_priv, |
8851 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
8852 | return false; |
8853 | ||
e143a21c | 8854 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8855 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8856 | |
0e8ffe1b DV |
8857 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8858 | if (!(tmp & PIPECONF_ENABLE)) | |
8859 | return false; | |
8860 | ||
42571aef VS |
8861 | switch (tmp & PIPECONF_BPC_MASK) { |
8862 | case PIPECONF_6BPC: | |
8863 | pipe_config->pipe_bpp = 18; | |
8864 | break; | |
8865 | case PIPECONF_8BPC: | |
8866 | pipe_config->pipe_bpp = 24; | |
8867 | break; | |
8868 | case PIPECONF_10BPC: | |
8869 | pipe_config->pipe_bpp = 30; | |
8870 | break; | |
8871 | case PIPECONF_12BPC: | |
8872 | pipe_config->pipe_bpp = 36; | |
8873 | break; | |
8874 | default: | |
8875 | break; | |
8876 | } | |
8877 | ||
b5a9fa09 DV |
8878 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
8879 | pipe_config->limited_color_range = true; | |
8880 | ||
ab9412ba | 8881 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
8882 | struct intel_shared_dpll *pll; |
8883 | ||
88adfff1 DV |
8884 | pipe_config->has_pch_encoder = true; |
8885 | ||
627eb5a3 DV |
8886 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
8887 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
8888 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
8889 | |
8890 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 8891 | |
c0d43d62 | 8892 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
8893 | pipe_config->shared_dpll = |
8894 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
8895 | } else { |
8896 | tmp = I915_READ(PCH_DPLL_SEL); | |
8897 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
8898 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
8899 | else | |
8900 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
8901 | } | |
66e985c0 DV |
8902 | |
8903 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
8904 | ||
8905 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
8906 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
8907 | |
8908 | tmp = pipe_config->dpll_hw_state.dpll; | |
8909 | pipe_config->pixel_multiplier = | |
8910 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
8911 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
8912 | |
8913 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
8914 | } else { |
8915 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
8916 | } |
8917 | ||
1bd1bd80 DV |
8918 | intel_get_pipe_timings(crtc, pipe_config); |
8919 | ||
2fa2fe9a DV |
8920 | ironlake_get_pfit_config(crtc, pipe_config); |
8921 | ||
0e8ffe1b DV |
8922 | return true; |
8923 | } | |
8924 | ||
be256dc7 PZ |
8925 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
8926 | { | |
8927 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 8928 | struct intel_crtc *crtc; |
be256dc7 | 8929 | |
d3fcc808 | 8930 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 8931 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
8932 | pipe_name(crtc->pipe)); |
8933 | ||
e2c719b7 RC |
8934 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
8935 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
8936 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); | |
8937 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
8938 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); | |
8939 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 8940 | "CPU PWM1 enabled\n"); |
c5107b87 | 8941 | if (IS_HASWELL(dev)) |
e2c719b7 | 8942 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 8943 | "CPU PWM2 enabled\n"); |
e2c719b7 | 8944 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 8945 | "PCH PWM1 enabled\n"); |
e2c719b7 | 8946 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 8947 | "Utility pin enabled\n"); |
e2c719b7 | 8948 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 8949 | |
9926ada1 PZ |
8950 | /* |
8951 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
8952 | * interrupts remain enabled. We used to check for that, but since it's | |
8953 | * gen-specific and since we only disable LCPLL after we fully disable | |
8954 | * the interrupts, the check below should be enough. | |
8955 | */ | |
e2c719b7 | 8956 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
8957 | } |
8958 | ||
9ccd5aeb PZ |
8959 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
8960 | { | |
8961 | struct drm_device *dev = dev_priv->dev; | |
8962 | ||
8963 | if (IS_HASWELL(dev)) | |
8964 | return I915_READ(D_COMP_HSW); | |
8965 | else | |
8966 | return I915_READ(D_COMP_BDW); | |
8967 | } | |
8968 | ||
3c4c9b81 PZ |
8969 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
8970 | { | |
8971 | struct drm_device *dev = dev_priv->dev; | |
8972 | ||
8973 | if (IS_HASWELL(dev)) { | |
8974 | mutex_lock(&dev_priv->rps.hw_lock); | |
8975 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
8976 | val)) | |
f475dadf | 8977 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
8978 | mutex_unlock(&dev_priv->rps.hw_lock); |
8979 | } else { | |
9ccd5aeb PZ |
8980 | I915_WRITE(D_COMP_BDW, val); |
8981 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 8982 | } |
be256dc7 PZ |
8983 | } |
8984 | ||
8985 | /* | |
8986 | * This function implements pieces of two sequences from BSpec: | |
8987 | * - Sequence for display software to disable LCPLL | |
8988 | * - Sequence for display software to allow package C8+ | |
8989 | * The steps implemented here are just the steps that actually touch the LCPLL | |
8990 | * register. Callers should take care of disabling all the display engine | |
8991 | * functions, doing the mode unset, fixing interrupts, etc. | |
8992 | */ | |
6ff58d53 PZ |
8993 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
8994 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
8995 | { |
8996 | uint32_t val; | |
8997 | ||
8998 | assert_can_disable_lcpll(dev_priv); | |
8999 | ||
9000 | val = I915_READ(LCPLL_CTL); | |
9001 | ||
9002 | if (switch_to_fclk) { | |
9003 | val |= LCPLL_CD_SOURCE_FCLK; | |
9004 | I915_WRITE(LCPLL_CTL, val); | |
9005 | ||
9006 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9007 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9008 | DRM_ERROR("Switching to FCLK failed\n"); | |
9009 | ||
9010 | val = I915_READ(LCPLL_CTL); | |
9011 | } | |
9012 | ||
9013 | val |= LCPLL_PLL_DISABLE; | |
9014 | I915_WRITE(LCPLL_CTL, val); | |
9015 | POSTING_READ(LCPLL_CTL); | |
9016 | ||
9017 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9018 | DRM_ERROR("LCPLL still locked\n"); | |
9019 | ||
9ccd5aeb | 9020 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9021 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9022 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9023 | ndelay(100); |
9024 | ||
9ccd5aeb PZ |
9025 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9026 | 1)) | |
be256dc7 PZ |
9027 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9028 | ||
9029 | if (allow_power_down) { | |
9030 | val = I915_READ(LCPLL_CTL); | |
9031 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9032 | I915_WRITE(LCPLL_CTL, val); | |
9033 | POSTING_READ(LCPLL_CTL); | |
9034 | } | |
9035 | } | |
9036 | ||
9037 | /* | |
9038 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9039 | * source. | |
9040 | */ | |
6ff58d53 | 9041 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9042 | { |
9043 | uint32_t val; | |
9044 | ||
9045 | val = I915_READ(LCPLL_CTL); | |
9046 | ||
9047 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9048 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9049 | return; | |
9050 | ||
a8a8bd54 PZ |
9051 | /* |
9052 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9053 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9054 | */ |
59bad947 | 9055 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9056 | |
be256dc7 PZ |
9057 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9058 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9059 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9060 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9061 | } |
9062 | ||
9ccd5aeb | 9063 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9064 | val |= D_COMP_COMP_FORCE; |
9065 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9066 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9067 | |
9068 | val = I915_READ(LCPLL_CTL); | |
9069 | val &= ~LCPLL_PLL_DISABLE; | |
9070 | I915_WRITE(LCPLL_CTL, val); | |
9071 | ||
9072 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9073 | DRM_ERROR("LCPLL not locked yet\n"); | |
9074 | ||
9075 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9076 | val = I915_READ(LCPLL_CTL); | |
9077 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9078 | I915_WRITE(LCPLL_CTL, val); | |
9079 | ||
9080 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9081 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9082 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9083 | } | |
215733fa | 9084 | |
59bad947 | 9085 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
be256dc7 PZ |
9086 | } |
9087 | ||
765dab67 PZ |
9088 | /* |
9089 | * Package states C8 and deeper are really deep PC states that can only be | |
9090 | * reached when all the devices on the system allow it, so even if the graphics | |
9091 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9092 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9093 | * | |
9094 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9095 | * well is disabled and most interrupts are disabled, and these are also | |
9096 | * requirements for runtime PM. When these conditions are met, we manually do | |
9097 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9098 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9099 | * hang the machine. | |
9100 | * | |
9101 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9102 | * the state of some registers, so when we come back from PC8+ we need to | |
9103 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9104 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9105 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9106 | * because of the runtime PM support). | |
9107 | * | |
9108 | * For more, read "Display Sequences for Package C8" on the hardware | |
9109 | * documentation. | |
9110 | */ | |
a14cb6fc | 9111 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9112 | { |
c67a470b PZ |
9113 | struct drm_device *dev = dev_priv->dev; |
9114 | uint32_t val; | |
9115 | ||
c67a470b PZ |
9116 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9117 | ||
c67a470b PZ |
9118 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
9119 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9120 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9121 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9122 | } | |
9123 | ||
9124 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9125 | hsw_disable_lcpll(dev_priv, true, true); |
9126 | } | |
9127 | ||
a14cb6fc | 9128 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9129 | { |
9130 | struct drm_device *dev = dev_priv->dev; | |
9131 | uint32_t val; | |
9132 | ||
c67a470b PZ |
9133 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9134 | ||
9135 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9136 | lpt_init_pch_refclk(dev); |
9137 | ||
9138 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { | |
9139 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9140 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9141 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9142 | } | |
9143 | ||
9144 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9145 | } |
9146 | ||
a821fc46 | 9147 | static void broxton_modeset_global_resources(struct drm_atomic_state *old_state) |
f8437dd1 | 9148 | { |
a821fc46 | 9149 | struct drm_device *dev = old_state->dev; |
f8437dd1 | 9150 | struct drm_i915_private *dev_priv = dev->dev_private; |
a821fc46 | 9151 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
f8437dd1 VK |
9152 | int req_cdclk; |
9153 | ||
9154 | /* see the comment in valleyview_modeset_global_resources */ | |
9155 | if (WARN_ON(max_pixclk < 0)) | |
9156 | return; | |
9157 | ||
9158 | req_cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); | |
9159 | ||
9160 | if (req_cdclk != dev_priv->cdclk_freq) | |
9161 | broxton_set_cdclk(dev, req_cdclk); | |
9162 | } | |
9163 | ||
190f68c5 ACO |
9164 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9165 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9166 | { |
190f68c5 | 9167 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9168 | return -EINVAL; |
716c2e55 | 9169 | |
c7653199 | 9170 | crtc->lowfreq_avail = false; |
644cef34 | 9171 | |
c8f7a0db | 9172 | return 0; |
79e53945 JB |
9173 | } |
9174 | ||
3760b59c S |
9175 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9176 | enum port port, | |
9177 | struct intel_crtc_state *pipe_config) | |
9178 | { | |
9179 | switch (port) { | |
9180 | case PORT_A: | |
9181 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9182 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9183 | break; | |
9184 | case PORT_B: | |
9185 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9186 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9187 | break; | |
9188 | case PORT_C: | |
9189 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9190 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9191 | break; | |
9192 | default: | |
9193 | DRM_ERROR("Incorrect port type\n"); | |
9194 | } | |
9195 | } | |
9196 | ||
96b7dfb7 S |
9197 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9198 | enum port port, | |
5cec258b | 9199 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9200 | { |
3148ade7 | 9201 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9202 | |
9203 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9204 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9205 | ||
9206 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9207 | case SKL_DPLL0: |
9208 | /* | |
9209 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9210 | * of the shared DPLL framework and thus needs to be read out | |
9211 | * separately | |
9212 | */ | |
9213 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9214 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9215 | break; | |
96b7dfb7 S |
9216 | case SKL_DPLL1: |
9217 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9218 | break; | |
9219 | case SKL_DPLL2: | |
9220 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9221 | break; | |
9222 | case SKL_DPLL3: | |
9223 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9224 | break; | |
96b7dfb7 S |
9225 | } |
9226 | } | |
9227 | ||
7d2c8175 DL |
9228 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9229 | enum port port, | |
5cec258b | 9230 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9231 | { |
9232 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9233 | ||
9234 | switch (pipe_config->ddi_pll_sel) { | |
9235 | case PORT_CLK_SEL_WRPLL1: | |
9236 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9237 | break; | |
9238 | case PORT_CLK_SEL_WRPLL2: | |
9239 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9240 | break; | |
9241 | } | |
9242 | } | |
9243 | ||
26804afd | 9244 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9245 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9246 | { |
9247 | struct drm_device *dev = crtc->base.dev; | |
9248 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9249 | struct intel_shared_dpll *pll; |
26804afd DV |
9250 | enum port port; |
9251 | uint32_t tmp; | |
9252 | ||
9253 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9254 | ||
9255 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9256 | ||
96b7dfb7 S |
9257 | if (IS_SKYLAKE(dev)) |
9258 | skylake_get_ddi_pll(dev_priv, port, pipe_config); | |
3760b59c S |
9259 | else if (IS_BROXTON(dev)) |
9260 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9261 | else |
9262 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9263 | |
d452c5b6 DV |
9264 | if (pipe_config->shared_dpll >= 0) { |
9265 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9266 | ||
9267 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9268 | &pipe_config->dpll_hw_state)); | |
9269 | } | |
9270 | ||
26804afd DV |
9271 | /* |
9272 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9273 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9274 | * the PCH transcoder is on. | |
9275 | */ | |
ca370455 DL |
9276 | if (INTEL_INFO(dev)->gen < 9 && |
9277 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9278 | pipe_config->has_pch_encoder = true; |
9279 | ||
9280 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9281 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9282 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9283 | ||
9284 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9285 | } | |
9286 | } | |
9287 | ||
0e8ffe1b | 9288 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9289 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9290 | { |
9291 | struct drm_device *dev = crtc->base.dev; | |
9292 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9293 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9294 | uint32_t tmp; |
9295 | ||
f458ebbc | 9296 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9297 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9298 | return false; | |
9299 | ||
e143a21c | 9300 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9301 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9302 | ||
eccb140b DV |
9303 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9304 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9305 | enum pipe trans_edp_pipe; | |
9306 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9307 | default: | |
9308 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9309 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9310 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9311 | trans_edp_pipe = PIPE_A; | |
9312 | break; | |
9313 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9314 | trans_edp_pipe = PIPE_B; | |
9315 | break; | |
9316 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9317 | trans_edp_pipe = PIPE_C; | |
9318 | break; | |
9319 | } | |
9320 | ||
9321 | if (trans_edp_pipe == crtc->pipe) | |
9322 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9323 | } | |
9324 | ||
f458ebbc | 9325 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9326 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9327 | return false; |
9328 | ||
eccb140b | 9329 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9330 | if (!(tmp & PIPECONF_ENABLE)) |
9331 | return false; | |
9332 | ||
26804afd | 9333 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9334 | |
1bd1bd80 DV |
9335 | intel_get_pipe_timings(crtc, pipe_config); |
9336 | ||
a1b2278e CK |
9337 | if (INTEL_INFO(dev)->gen >= 9) { |
9338 | skl_init_scalers(dev, crtc, pipe_config); | |
9339 | } | |
9340 | ||
2fa2fe9a | 9341 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9342 | |
9343 | if (INTEL_INFO(dev)->gen >= 9) { | |
9344 | pipe_config->scaler_state.scaler_id = -1; | |
9345 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9346 | } | |
9347 | ||
bd2e244f | 9348 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
ff6d9f55 | 9349 | if (INTEL_INFO(dev)->gen == 9) |
bd2e244f | 9350 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9351 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 9352 | ironlake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 JB |
9353 | else |
9354 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
bd2e244f | 9355 | } |
88adfff1 | 9356 | |
e59150dc JB |
9357 | if (IS_HASWELL(dev)) |
9358 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9359 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9360 | |
ebb69c95 CT |
9361 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9362 | pipe_config->pixel_multiplier = | |
9363 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9364 | } else { | |
9365 | pipe_config->pixel_multiplier = 1; | |
9366 | } | |
6c49f241 | 9367 | |
0e8ffe1b DV |
9368 | return true; |
9369 | } | |
9370 | ||
560b85bb CW |
9371 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9372 | { | |
9373 | struct drm_device *dev = crtc->dev; | |
9374 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9375 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9376 | uint32_t cntl = 0, size = 0; |
560b85bb | 9377 | |
dc41c154 | 9378 | if (base) { |
3dd512fb MR |
9379 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9380 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9381 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9382 | ||
9383 | switch (stride) { | |
9384 | default: | |
9385 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9386 | width, stride); | |
9387 | stride = 256; | |
9388 | /* fallthrough */ | |
9389 | case 256: | |
9390 | case 512: | |
9391 | case 1024: | |
9392 | case 2048: | |
9393 | break; | |
4b0e333e CW |
9394 | } |
9395 | ||
dc41c154 VS |
9396 | cntl |= CURSOR_ENABLE | |
9397 | CURSOR_GAMMA_ENABLE | | |
9398 | CURSOR_FORMAT_ARGB | | |
9399 | CURSOR_STRIDE(stride); | |
9400 | ||
9401 | size = (height << 12) | width; | |
4b0e333e | 9402 | } |
560b85bb | 9403 | |
dc41c154 VS |
9404 | if (intel_crtc->cursor_cntl != 0 && |
9405 | (intel_crtc->cursor_base != base || | |
9406 | intel_crtc->cursor_size != size || | |
9407 | intel_crtc->cursor_cntl != cntl)) { | |
9408 | /* On these chipsets we can only modify the base/size/stride | |
9409 | * whilst the cursor is disabled. | |
9410 | */ | |
9411 | I915_WRITE(_CURACNTR, 0); | |
4b0e333e | 9412 | POSTING_READ(_CURACNTR); |
dc41c154 | 9413 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9414 | } |
560b85bb | 9415 | |
99d1f387 | 9416 | if (intel_crtc->cursor_base != base) { |
9db4a9c7 | 9417 | I915_WRITE(_CURABASE, base); |
99d1f387 VS |
9418 | intel_crtc->cursor_base = base; |
9419 | } | |
4726e0b0 | 9420 | |
dc41c154 VS |
9421 | if (intel_crtc->cursor_size != size) { |
9422 | I915_WRITE(CURSIZE, size); | |
9423 | intel_crtc->cursor_size = size; | |
4b0e333e | 9424 | } |
560b85bb | 9425 | |
4b0e333e | 9426 | if (intel_crtc->cursor_cntl != cntl) { |
4b0e333e CW |
9427 | I915_WRITE(_CURACNTR, cntl); |
9428 | POSTING_READ(_CURACNTR); | |
4b0e333e | 9429 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 9430 | } |
560b85bb CW |
9431 | } |
9432 | ||
560b85bb | 9433 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
9434 | { |
9435 | struct drm_device *dev = crtc->dev; | |
9436 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9437 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9438 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
9439 | uint32_t cntl; |
9440 | ||
9441 | cntl = 0; | |
9442 | if (base) { | |
9443 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 9444 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
9445 | case 64: |
9446 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9447 | break; | |
9448 | case 128: | |
9449 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9450 | break; | |
9451 | case 256: | |
9452 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
9453 | break; | |
9454 | default: | |
3dd512fb | 9455 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 9456 | return; |
65a21cd6 | 9457 | } |
4b0e333e | 9458 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 VS |
9459 | |
9460 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
9461 | cntl |= CURSOR_PIPE_CSC_ENABLE; | |
4b0e333e | 9462 | } |
65a21cd6 | 9463 | |
8e7d688b | 9464 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
9465 | cntl |= CURSOR_ROTATE_180; |
9466 | ||
4b0e333e CW |
9467 | if (intel_crtc->cursor_cntl != cntl) { |
9468 | I915_WRITE(CURCNTR(pipe), cntl); | |
9469 | POSTING_READ(CURCNTR(pipe)); | |
9470 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 9471 | } |
4b0e333e | 9472 | |
65a21cd6 | 9473 | /* and commit changes on next vblank */ |
5efb3e28 VS |
9474 | I915_WRITE(CURBASE(pipe), base); |
9475 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
9476 | |
9477 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
9478 | } |
9479 | ||
cda4b7d3 | 9480 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
9481 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
9482 | bool on) | |
cda4b7d3 CW |
9483 | { |
9484 | struct drm_device *dev = crtc->dev; | |
9485 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9486 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9487 | int pipe = intel_crtc->pipe; | |
3d7d6510 MR |
9488 | int x = crtc->cursor_x; |
9489 | int y = crtc->cursor_y; | |
d6e4db15 | 9490 | u32 base = 0, pos = 0; |
cda4b7d3 | 9491 | |
d6e4db15 | 9492 | if (on) |
cda4b7d3 | 9493 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 9494 | |
6e3c9717 | 9495 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
9496 | base = 0; |
9497 | ||
6e3c9717 | 9498 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
9499 | base = 0; |
9500 | ||
9501 | if (x < 0) { | |
3dd512fb | 9502 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
cda4b7d3 CW |
9503 | base = 0; |
9504 | ||
9505 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
9506 | x = -x; | |
9507 | } | |
9508 | pos |= x << CURSOR_X_SHIFT; | |
9509 | ||
9510 | if (y < 0) { | |
3dd512fb | 9511 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
cda4b7d3 CW |
9512 | base = 0; |
9513 | ||
9514 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
9515 | y = -y; | |
9516 | } | |
9517 | pos |= y << CURSOR_Y_SHIFT; | |
9518 | ||
4b0e333e | 9519 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
9520 | return; |
9521 | ||
5efb3e28 VS |
9522 | I915_WRITE(CURPOS(pipe), pos); |
9523 | ||
4398ad45 VS |
9524 | /* ILK+ do this automagically */ |
9525 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 9526 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
3dd512fb MR |
9527 | base += (intel_crtc->base.cursor->state->crtc_h * |
9528 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; | |
4398ad45 VS |
9529 | } |
9530 | ||
8ac54669 | 9531 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
9532 | i845_update_cursor(crtc, base); |
9533 | else | |
9534 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
9535 | } |
9536 | ||
dc41c154 VS |
9537 | static bool cursor_size_ok(struct drm_device *dev, |
9538 | uint32_t width, uint32_t height) | |
9539 | { | |
9540 | if (width == 0 || height == 0) | |
9541 | return false; | |
9542 | ||
9543 | /* | |
9544 | * 845g/865g are special in that they are only limited by | |
9545 | * the width of their cursors, the height is arbitrary up to | |
9546 | * the precision of the register. Everything else requires | |
9547 | * square cursors, limited to a few power-of-two sizes. | |
9548 | */ | |
9549 | if (IS_845G(dev) || IS_I865G(dev)) { | |
9550 | if ((width & 63) != 0) | |
9551 | return false; | |
9552 | ||
9553 | if (width > (IS_845G(dev) ? 64 : 512)) | |
9554 | return false; | |
9555 | ||
9556 | if (height > 1023) | |
9557 | return false; | |
9558 | } else { | |
9559 | switch (width | height) { | |
9560 | case 256: | |
9561 | case 128: | |
9562 | if (IS_GEN2(dev)) | |
9563 | return false; | |
9564 | case 64: | |
9565 | break; | |
9566 | default: | |
9567 | return false; | |
9568 | } | |
9569 | } | |
9570 | ||
9571 | return true; | |
9572 | } | |
9573 | ||
79e53945 | 9574 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 9575 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 9576 | { |
7203425a | 9577 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 9578 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 9579 | |
7203425a | 9580 | for (i = start; i < end; i++) { |
79e53945 JB |
9581 | intel_crtc->lut_r[i] = red[i] >> 8; |
9582 | intel_crtc->lut_g[i] = green[i] >> 8; | |
9583 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
9584 | } | |
9585 | ||
9586 | intel_crtc_load_lut(crtc); | |
9587 | } | |
9588 | ||
79e53945 JB |
9589 | /* VESA 640x480x72Hz mode to set on the pipe */ |
9590 | static struct drm_display_mode load_detect_mode = { | |
9591 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
9592 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
9593 | }; | |
9594 | ||
a8bb6818 DV |
9595 | struct drm_framebuffer * |
9596 | __intel_framebuffer_create(struct drm_device *dev, | |
9597 | struct drm_mode_fb_cmd2 *mode_cmd, | |
9598 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
9599 | { |
9600 | struct intel_framebuffer *intel_fb; | |
9601 | int ret; | |
9602 | ||
9603 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
9604 | if (!intel_fb) { | |
6ccb81f2 | 9605 | drm_gem_object_unreference(&obj->base); |
d2dff872 CW |
9606 | return ERR_PTR(-ENOMEM); |
9607 | } | |
9608 | ||
9609 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
9610 | if (ret) |
9611 | goto err; | |
d2dff872 CW |
9612 | |
9613 | return &intel_fb->base; | |
dd4916c5 | 9614 | err: |
6ccb81f2 | 9615 | drm_gem_object_unreference(&obj->base); |
dd4916c5 DV |
9616 | kfree(intel_fb); |
9617 | ||
9618 | return ERR_PTR(ret); | |
d2dff872 CW |
9619 | } |
9620 | ||
b5ea642a | 9621 | static struct drm_framebuffer * |
a8bb6818 DV |
9622 | intel_framebuffer_create(struct drm_device *dev, |
9623 | struct drm_mode_fb_cmd2 *mode_cmd, | |
9624 | struct drm_i915_gem_object *obj) | |
9625 | { | |
9626 | struct drm_framebuffer *fb; | |
9627 | int ret; | |
9628 | ||
9629 | ret = i915_mutex_lock_interruptible(dev); | |
9630 | if (ret) | |
9631 | return ERR_PTR(ret); | |
9632 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
9633 | mutex_unlock(&dev->struct_mutex); | |
9634 | ||
9635 | return fb; | |
9636 | } | |
9637 | ||
d2dff872 CW |
9638 | static u32 |
9639 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
9640 | { | |
9641 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
9642 | return ALIGN(pitch, 64); | |
9643 | } | |
9644 | ||
9645 | static u32 | |
9646 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
9647 | { | |
9648 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 9649 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
9650 | } |
9651 | ||
9652 | static struct drm_framebuffer * | |
9653 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
9654 | struct drm_display_mode *mode, | |
9655 | int depth, int bpp) | |
9656 | { | |
9657 | struct drm_i915_gem_object *obj; | |
0fed39bd | 9658 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
9659 | |
9660 | obj = i915_gem_alloc_object(dev, | |
9661 | intel_framebuffer_size_for_mode(mode, bpp)); | |
9662 | if (obj == NULL) | |
9663 | return ERR_PTR(-ENOMEM); | |
9664 | ||
9665 | mode_cmd.width = mode->hdisplay; | |
9666 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
9667 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
9668 | bpp); | |
5ca0c34a | 9669 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 CW |
9670 | |
9671 | return intel_framebuffer_create(dev, &mode_cmd, obj); | |
9672 | } | |
9673 | ||
9674 | static struct drm_framebuffer * | |
9675 | mode_fits_in_fbdev(struct drm_device *dev, | |
9676 | struct drm_display_mode *mode) | |
9677 | { | |
4520f53a | 9678 | #ifdef CONFIG_DRM_I915_FBDEV |
d2dff872 CW |
9679 | struct drm_i915_private *dev_priv = dev->dev_private; |
9680 | struct drm_i915_gem_object *obj; | |
9681 | struct drm_framebuffer *fb; | |
9682 | ||
4c0e5528 | 9683 | if (!dev_priv->fbdev) |
d2dff872 CW |
9684 | return NULL; |
9685 | ||
4c0e5528 | 9686 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
9687 | return NULL; |
9688 | ||
4c0e5528 DV |
9689 | obj = dev_priv->fbdev->fb->obj; |
9690 | BUG_ON(!obj); | |
9691 | ||
8bcd4553 | 9692 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
9693 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
9694 | fb->bits_per_pixel)) | |
d2dff872 CW |
9695 | return NULL; |
9696 | ||
01f2c773 | 9697 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
9698 | return NULL; |
9699 | ||
9700 | return fb; | |
4520f53a DV |
9701 | #else |
9702 | return NULL; | |
9703 | #endif | |
d2dff872 CW |
9704 | } |
9705 | ||
d3a40d1b ACO |
9706 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
9707 | struct drm_crtc *crtc, | |
9708 | struct drm_display_mode *mode, | |
9709 | struct drm_framebuffer *fb, | |
9710 | int x, int y) | |
9711 | { | |
9712 | struct drm_plane_state *plane_state; | |
9713 | int hdisplay, vdisplay; | |
9714 | int ret; | |
9715 | ||
9716 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
9717 | if (IS_ERR(plane_state)) | |
9718 | return PTR_ERR(plane_state); | |
9719 | ||
9720 | if (mode) | |
9721 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
9722 | else | |
9723 | hdisplay = vdisplay = 0; | |
9724 | ||
9725 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
9726 | if (ret) | |
9727 | return ret; | |
9728 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
9729 | plane_state->crtc_x = 0; | |
9730 | plane_state->crtc_y = 0; | |
9731 | plane_state->crtc_w = hdisplay; | |
9732 | plane_state->crtc_h = vdisplay; | |
9733 | plane_state->src_x = x << 16; | |
9734 | plane_state->src_y = y << 16; | |
9735 | plane_state->src_w = hdisplay << 16; | |
9736 | plane_state->src_h = vdisplay << 16; | |
9737 | ||
9738 | return 0; | |
9739 | } | |
9740 | ||
d2434ab7 | 9741 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 9742 | struct drm_display_mode *mode, |
51fd371b RC |
9743 | struct intel_load_detect_pipe *old, |
9744 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
9745 | { |
9746 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
9747 | struct intel_encoder *intel_encoder = |
9748 | intel_attached_encoder(connector); | |
79e53945 | 9749 | struct drm_crtc *possible_crtc; |
4ef69c7a | 9750 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
9751 | struct drm_crtc *crtc = NULL; |
9752 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 9753 | struct drm_framebuffer *fb; |
51fd371b | 9754 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 9755 | struct drm_atomic_state *state = NULL; |
944b0c76 | 9756 | struct drm_connector_state *connector_state; |
4be07317 | 9757 | struct intel_crtc_state *crtc_state; |
51fd371b | 9758 | int ret, i = -1; |
79e53945 | 9759 | |
d2dff872 | 9760 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 9761 | connector->base.id, connector->name, |
8e329a03 | 9762 | encoder->base.id, encoder->name); |
d2dff872 | 9763 | |
51fd371b RC |
9764 | retry: |
9765 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
9766 | if (ret) | |
9767 | goto fail_unlock; | |
6e9f798d | 9768 | |
79e53945 JB |
9769 | /* |
9770 | * Algorithm gets a little messy: | |
7a5e4805 | 9771 | * |
79e53945 JB |
9772 | * - if the connector already has an assigned crtc, use it (but make |
9773 | * sure it's on first) | |
7a5e4805 | 9774 | * |
79e53945 JB |
9775 | * - try to find the first unused crtc that can drive this connector, |
9776 | * and use that if we find one | |
79e53945 JB |
9777 | */ |
9778 | ||
9779 | /* See if we already have a CRTC for this connector */ | |
9780 | if (encoder->crtc) { | |
9781 | crtc = encoder->crtc; | |
8261b191 | 9782 | |
51fd371b | 9783 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de DV |
9784 | if (ret) |
9785 | goto fail_unlock; | |
9786 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
51fd371b RC |
9787 | if (ret) |
9788 | goto fail_unlock; | |
7b24056b | 9789 | |
24218aac | 9790 | old->dpms_mode = connector->dpms; |
8261b191 CW |
9791 | old->load_detect_temp = false; |
9792 | ||
9793 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
9794 | if (connector->dpms != DRM_MODE_DPMS_ON) |
9795 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 9796 | |
7173188d | 9797 | return true; |
79e53945 JB |
9798 | } |
9799 | ||
9800 | /* Find an unused one (if possible) */ | |
70e1e0ec | 9801 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
9802 | i++; |
9803 | if (!(encoder->possible_crtcs & (1 << i))) | |
9804 | continue; | |
83d65738 | 9805 | if (possible_crtc->state->enable) |
a459249c VS |
9806 | continue; |
9807 | /* This can occur when applying the pipe A quirk on resume. */ | |
9808 | if (to_intel_crtc(possible_crtc)->new_enabled) | |
9809 | continue; | |
9810 | ||
9811 | crtc = possible_crtc; | |
9812 | break; | |
79e53945 JB |
9813 | } |
9814 | ||
9815 | /* | |
9816 | * If we didn't find an unused CRTC, don't use any. | |
9817 | */ | |
9818 | if (!crtc) { | |
7173188d | 9819 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
51fd371b | 9820 | goto fail_unlock; |
79e53945 JB |
9821 | } |
9822 | ||
51fd371b RC |
9823 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
9824 | if (ret) | |
4d02e2de DV |
9825 | goto fail_unlock; |
9826 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
9827 | if (ret) | |
51fd371b | 9828 | goto fail_unlock; |
fc303101 DV |
9829 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
9830 | to_intel_connector(connector)->new_encoder = intel_encoder; | |
79e53945 JB |
9831 | |
9832 | intel_crtc = to_intel_crtc(crtc); | |
412b61d8 | 9833 | intel_crtc->new_enabled = true; |
24218aac | 9834 | old->dpms_mode = connector->dpms; |
8261b191 | 9835 | old->load_detect_temp = true; |
d2dff872 | 9836 | old->release_fb = NULL; |
79e53945 | 9837 | |
83a57153 ACO |
9838 | state = drm_atomic_state_alloc(dev); |
9839 | if (!state) | |
9840 | return false; | |
9841 | ||
9842 | state->acquire_ctx = ctx; | |
9843 | ||
944b0c76 ACO |
9844 | connector_state = drm_atomic_get_connector_state(state, connector); |
9845 | if (IS_ERR(connector_state)) { | |
9846 | ret = PTR_ERR(connector_state); | |
9847 | goto fail; | |
9848 | } | |
9849 | ||
9850 | connector_state->crtc = crtc; | |
9851 | connector_state->best_encoder = &intel_encoder->base; | |
9852 | ||
4be07317 ACO |
9853 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
9854 | if (IS_ERR(crtc_state)) { | |
9855 | ret = PTR_ERR(crtc_state); | |
9856 | goto fail; | |
9857 | } | |
9858 | ||
49d6fa21 | 9859 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 9860 | |
6492711d CW |
9861 | if (!mode) |
9862 | mode = &load_detect_mode; | |
79e53945 | 9863 | |
d2dff872 CW |
9864 | /* We need a framebuffer large enough to accommodate all accesses |
9865 | * that the plane may generate whilst we perform load detection. | |
9866 | * We can not rely on the fbcon either being present (we get called | |
9867 | * during its initialisation to detect all boot displays, or it may | |
9868 | * not even exist) or that it is large enough to satisfy the | |
9869 | * requested mode. | |
9870 | */ | |
94352cf9 DV |
9871 | fb = mode_fits_in_fbdev(dev, mode); |
9872 | if (fb == NULL) { | |
d2dff872 | 9873 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
9874 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
9875 | old->release_fb = fb; | |
d2dff872 CW |
9876 | } else |
9877 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 9878 | if (IS_ERR(fb)) { |
d2dff872 | 9879 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 9880 | goto fail; |
79e53945 | 9881 | } |
79e53945 | 9882 | |
d3a40d1b ACO |
9883 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
9884 | if (ret) | |
9885 | goto fail; | |
9886 | ||
8c7b5ccb ACO |
9887 | drm_mode_copy(&crtc_state->base.mode, mode); |
9888 | ||
9889 | if (intel_set_mode(crtc, state)) { | |
6492711d | 9890 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
9891 | if (old->release_fb) |
9892 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 9893 | goto fail; |
79e53945 | 9894 | } |
9128b040 | 9895 | crtc->primary->crtc = crtc; |
7173188d | 9896 | |
79e53945 | 9897 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 9898 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 9899 | return true; |
412b61d8 VS |
9900 | |
9901 | fail: | |
83d65738 | 9902 | intel_crtc->new_enabled = crtc->state->enable; |
51fd371b | 9903 | fail_unlock: |
e5d958ef ACO |
9904 | drm_atomic_state_free(state); |
9905 | state = NULL; | |
83a57153 | 9906 | |
51fd371b RC |
9907 | if (ret == -EDEADLK) { |
9908 | drm_modeset_backoff(ctx); | |
9909 | goto retry; | |
9910 | } | |
9911 | ||
412b61d8 | 9912 | return false; |
79e53945 JB |
9913 | } |
9914 | ||
d2434ab7 | 9915 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
9916 | struct intel_load_detect_pipe *old, |
9917 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 9918 | { |
83a57153 | 9919 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
9920 | struct intel_encoder *intel_encoder = |
9921 | intel_attached_encoder(connector); | |
4ef69c7a | 9922 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 9923 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 9924 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 9925 | struct drm_atomic_state *state; |
944b0c76 | 9926 | struct drm_connector_state *connector_state; |
4be07317 | 9927 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 9928 | int ret; |
79e53945 | 9929 | |
d2dff872 | 9930 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 9931 | connector->base.id, connector->name, |
8e329a03 | 9932 | encoder->base.id, encoder->name); |
d2dff872 | 9933 | |
8261b191 | 9934 | if (old->load_detect_temp) { |
83a57153 | 9935 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
9936 | if (!state) |
9937 | goto fail; | |
83a57153 ACO |
9938 | |
9939 | state->acquire_ctx = ctx; | |
9940 | ||
944b0c76 ACO |
9941 | connector_state = drm_atomic_get_connector_state(state, connector); |
9942 | if (IS_ERR(connector_state)) | |
9943 | goto fail; | |
9944 | ||
4be07317 ACO |
9945 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
9946 | if (IS_ERR(crtc_state)) | |
9947 | goto fail; | |
9948 | ||
fc303101 DV |
9949 | to_intel_connector(connector)->new_encoder = NULL; |
9950 | intel_encoder->new_crtc = NULL; | |
412b61d8 | 9951 | intel_crtc->new_enabled = false; |
944b0c76 ACO |
9952 | |
9953 | connector_state->best_encoder = NULL; | |
9954 | connector_state->crtc = NULL; | |
9955 | ||
49d6fa21 | 9956 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 9957 | |
d3a40d1b ACO |
9958 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
9959 | 0, 0); | |
9960 | if (ret) | |
9961 | goto fail; | |
9962 | ||
2bfb4627 ACO |
9963 | ret = intel_set_mode(crtc, state); |
9964 | if (ret) | |
9965 | goto fail; | |
d2dff872 | 9966 | |
36206361 DV |
9967 | if (old->release_fb) { |
9968 | drm_framebuffer_unregister_private(old->release_fb); | |
9969 | drm_framebuffer_unreference(old->release_fb); | |
9970 | } | |
d2dff872 | 9971 | |
0622a53c | 9972 | return; |
79e53945 JB |
9973 | } |
9974 | ||
c751ce4f | 9975 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
9976 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
9977 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
9978 | |
9979 | return; | |
9980 | fail: | |
9981 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
9982 | drm_atomic_state_free(state); | |
79e53945 JB |
9983 | } |
9984 | ||
da4a1efa | 9985 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 9986 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
9987 | { |
9988 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9989 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
9990 | ||
9991 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 9992 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
9993 | else if (HAS_PCH_SPLIT(dev)) |
9994 | return 120000; | |
9995 | else if (!IS_GEN2(dev)) | |
9996 | return 96000; | |
9997 | else | |
9998 | return 48000; | |
9999 | } | |
10000 | ||
79e53945 | 10001 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10002 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10003 | struct intel_crtc_state *pipe_config) |
79e53945 | 10004 | { |
f1f644dc | 10005 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10006 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10007 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10008 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10009 | u32 fp; |
10010 | intel_clock_t clock; | |
da4a1efa | 10011 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10012 | |
10013 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10014 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10015 | else |
293623f7 | 10016 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10017 | |
10018 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10019 | if (IS_PINEVIEW(dev)) { |
10020 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10021 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10022 | } else { |
10023 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10024 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10025 | } | |
10026 | ||
a6c45cf0 | 10027 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10028 | if (IS_PINEVIEW(dev)) |
10029 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10030 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10031 | else |
10032 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10033 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10034 | ||
10035 | switch (dpll & DPLL_MODE_MASK) { | |
10036 | case DPLLB_MODE_DAC_SERIAL: | |
10037 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10038 | 5 : 10; | |
10039 | break; | |
10040 | case DPLLB_MODE_LVDS: | |
10041 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10042 | 7 : 14; | |
10043 | break; | |
10044 | default: | |
28c97730 | 10045 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10046 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10047 | return; |
79e53945 JB |
10048 | } |
10049 | ||
ac58c3f0 | 10050 | if (IS_PINEVIEW(dev)) |
da4a1efa | 10051 | pineview_clock(refclk, &clock); |
ac58c3f0 | 10052 | else |
da4a1efa | 10053 | i9xx_clock(refclk, &clock); |
79e53945 | 10054 | } else { |
0fb58223 | 10055 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10056 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10057 | |
10058 | if (is_lvds) { | |
10059 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10060 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10061 | |
10062 | if (lvds & LVDS_CLKB_POWER_UP) | |
10063 | clock.p2 = 7; | |
10064 | else | |
10065 | clock.p2 = 14; | |
79e53945 JB |
10066 | } else { |
10067 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10068 | clock.p1 = 2; | |
10069 | else { | |
10070 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10071 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10072 | } | |
10073 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10074 | clock.p2 = 4; | |
10075 | else | |
10076 | clock.p2 = 2; | |
79e53945 | 10077 | } |
da4a1efa VS |
10078 | |
10079 | i9xx_clock(refclk, &clock); | |
79e53945 JB |
10080 | } |
10081 | ||
18442d08 VS |
10082 | /* |
10083 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10084 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10085 | * encoder's get_config() function. |
10086 | */ | |
10087 | pipe_config->port_clock = clock.dot; | |
f1f644dc JB |
10088 | } |
10089 | ||
6878da05 VS |
10090 | int intel_dotclock_calculate(int link_freq, |
10091 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10092 | { |
f1f644dc JB |
10093 | /* |
10094 | * The calculation for the data clock is: | |
1041a02f | 10095 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10096 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10097 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10098 | * |
10099 | * and the link clock is simpler: | |
1041a02f | 10100 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10101 | */ |
10102 | ||
6878da05 VS |
10103 | if (!m_n->link_n) |
10104 | return 0; | |
f1f644dc | 10105 | |
6878da05 VS |
10106 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10107 | } | |
f1f644dc | 10108 | |
18442d08 | 10109 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10110 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10111 | { |
10112 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10113 | |
18442d08 VS |
10114 | /* read out port_clock from the DPLL */ |
10115 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10116 | |
f1f644dc | 10117 | /* |
18442d08 | 10118 | * This value does not include pixel_multiplier. |
241bfc38 | 10119 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10120 | * agree once we know their relationship in the encoder's |
10121 | * get_config() function. | |
79e53945 | 10122 | */ |
2d112de7 | 10123 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10124 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10125 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10126 | } |
10127 | ||
10128 | /** Returns the currently programmed mode of the given pipe. */ | |
10129 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10130 | struct drm_crtc *crtc) | |
10131 | { | |
548f245b | 10132 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10133 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10134 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10135 | struct drm_display_mode *mode; |
5cec258b | 10136 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10137 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10138 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10139 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10140 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10141 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10142 | |
10143 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10144 | if (!mode) | |
10145 | return NULL; | |
10146 | ||
f1f644dc JB |
10147 | /* |
10148 | * Construct a pipe_config sufficient for getting the clock info | |
10149 | * back out of crtc_clock_get. | |
10150 | * | |
10151 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10152 | * to use a real value here instead. | |
10153 | */ | |
293623f7 | 10154 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10155 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10156 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10157 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10158 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10159 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10160 | ||
773ae034 | 10161 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10162 | mode->hdisplay = (htot & 0xffff) + 1; |
10163 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10164 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10165 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10166 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10167 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10168 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10169 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10170 | ||
10171 | drm_mode_set_name(mode); | |
79e53945 JB |
10172 | |
10173 | return mode; | |
10174 | } | |
10175 | ||
652c393a JB |
10176 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
10177 | { | |
10178 | struct drm_device *dev = crtc->dev; | |
fbee40df | 10179 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
652c393a | 10181 | |
baff296c | 10182 | if (!HAS_GMCH_DISPLAY(dev)) |
652c393a JB |
10183 | return; |
10184 | ||
10185 | if (!dev_priv->lvds_downclock_avail) | |
10186 | return; | |
10187 | ||
10188 | /* | |
10189 | * Since this is called by a timer, we should never get here in | |
10190 | * the manual case. | |
10191 | */ | |
10192 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { | |
dc257cf1 DV |
10193 | int pipe = intel_crtc->pipe; |
10194 | int dpll_reg = DPLL(pipe); | |
10195 | int dpll; | |
f6e5b160 | 10196 | |
44d98a61 | 10197 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
652c393a | 10198 | |
8ac5a6d5 | 10199 | assert_panel_unlocked(dev_priv, pipe); |
652c393a | 10200 | |
dc257cf1 | 10201 | dpll = I915_READ(dpll_reg); |
652c393a JB |
10202 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
10203 | I915_WRITE(dpll_reg, dpll); | |
9d0498a2 | 10204 | intel_wait_for_vblank(dev, pipe); |
652c393a JB |
10205 | dpll = I915_READ(dpll_reg); |
10206 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) | |
44d98a61 | 10207 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
652c393a JB |
10208 | } |
10209 | ||
10210 | } | |
10211 | ||
f047e395 CW |
10212 | void intel_mark_busy(struct drm_device *dev) |
10213 | { | |
c67a470b PZ |
10214 | struct drm_i915_private *dev_priv = dev->dev_private; |
10215 | ||
f62a0076 CW |
10216 | if (dev_priv->mm.busy) |
10217 | return; | |
10218 | ||
43694d69 | 10219 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10220 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10221 | if (INTEL_INFO(dev)->gen >= 6) |
10222 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10223 | dev_priv->mm.busy = true; |
f047e395 CW |
10224 | } |
10225 | ||
10226 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10227 | { |
c67a470b | 10228 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10229 | struct drm_crtc *crtc; |
652c393a | 10230 | |
f62a0076 CW |
10231 | if (!dev_priv->mm.busy) |
10232 | return; | |
10233 | ||
10234 | dev_priv->mm.busy = false; | |
10235 | ||
70e1e0ec | 10236 | for_each_crtc(dev, crtc) { |
f4510a27 | 10237 | if (!crtc->primary->fb) |
652c393a JB |
10238 | continue; |
10239 | ||
725a5b54 | 10240 | intel_decrease_pllclock(crtc); |
652c393a | 10241 | } |
b29c19b6 | 10242 | |
3d13ef2e | 10243 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10244 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10245 | |
43694d69 | 10246 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10247 | } |
10248 | ||
79e53945 JB |
10249 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10250 | { | |
10251 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10252 | struct drm_device *dev = crtc->dev; |
10253 | struct intel_unpin_work *work; | |
67e77c5a | 10254 | |
5e2d7afc | 10255 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10256 | work = intel_crtc->unpin_work; |
10257 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10258 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10259 | |
10260 | if (work) { | |
10261 | cancel_work_sync(&work->work); | |
10262 | kfree(work); | |
10263 | } | |
79e53945 JB |
10264 | |
10265 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10266 | |
79e53945 JB |
10267 | kfree(intel_crtc); |
10268 | } | |
10269 | ||
6b95a207 KH |
10270 | static void intel_unpin_work_fn(struct work_struct *__work) |
10271 | { | |
10272 | struct intel_unpin_work *work = | |
10273 | container_of(__work, struct intel_unpin_work, work); | |
b4a98e57 | 10274 | struct drm_device *dev = work->crtc->dev; |
f99d7069 | 10275 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
6b95a207 | 10276 | |
b4a98e57 | 10277 | mutex_lock(&dev->struct_mutex); |
82bc3b2d | 10278 | intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state); |
05394f39 | 10279 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10280 | |
7ff0ebcc | 10281 | intel_fbc_update(dev); |
f06cc1b9 JH |
10282 | |
10283 | if (work->flip_queued_req) | |
146d84f0 | 10284 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10285 | mutex_unlock(&dev->struct_mutex); |
10286 | ||
f99d7069 | 10287 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
89ed88ba | 10288 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10289 | |
b4a98e57 CW |
10290 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
10291 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); | |
10292 | ||
6b95a207 KH |
10293 | kfree(work); |
10294 | } | |
10295 | ||
1afe3e9d | 10296 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10297 | struct drm_crtc *crtc) |
6b95a207 | 10298 | { |
6b95a207 KH |
10299 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10300 | struct intel_unpin_work *work; | |
6b95a207 KH |
10301 | unsigned long flags; |
10302 | ||
10303 | /* Ignore early vblank irqs */ | |
10304 | if (intel_crtc == NULL) | |
10305 | return; | |
10306 | ||
f326038a DV |
10307 | /* |
10308 | * This is called both by irq handlers and the reset code (to complete | |
10309 | * lost pageflips) so needs the full irqsave spinlocks. | |
10310 | */ | |
6b95a207 KH |
10311 | spin_lock_irqsave(&dev->event_lock, flags); |
10312 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10313 | |
10314 | /* Ensure we don't miss a work->pending update ... */ | |
10315 | smp_rmb(); | |
10316 | ||
10317 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10318 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10319 | return; | |
10320 | } | |
10321 | ||
d6bbafa1 | 10322 | page_flip_completed(intel_crtc); |
0af7e4df | 10323 | |
6b95a207 | 10324 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10325 | } |
10326 | ||
1afe3e9d JB |
10327 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10328 | { | |
fbee40df | 10329 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10330 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10331 | ||
49b14a5c | 10332 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10333 | } |
10334 | ||
10335 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10336 | { | |
fbee40df | 10337 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10338 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10339 | ||
49b14a5c | 10340 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10341 | } |
10342 | ||
75f7f3ec VS |
10343 | /* Is 'a' after or equal to 'b'? */ |
10344 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10345 | { | |
10346 | return !((a - b) & 0x80000000); | |
10347 | } | |
10348 | ||
10349 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10350 | { | |
10351 | struct drm_device *dev = crtc->base.dev; | |
10352 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10353 | ||
bdfa7542 VS |
10354 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10355 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10356 | return true; | |
10357 | ||
75f7f3ec VS |
10358 | /* |
10359 | * The relevant registers doen't exist on pre-ctg. | |
10360 | * As the flip done interrupt doesn't trigger for mmio | |
10361 | * flips on gmch platforms, a flip count check isn't | |
10362 | * really needed there. But since ctg has the registers, | |
10363 | * include it in the check anyway. | |
10364 | */ | |
10365 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10366 | return true; | |
10367 | ||
10368 | /* | |
10369 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10370 | * used the same base address. In that case the mmio flip might | |
10371 | * have completed, but the CS hasn't even executed the flip yet. | |
10372 | * | |
10373 | * A flip count check isn't enough as the CS might have updated | |
10374 | * the base address just after start of vblank, but before we | |
10375 | * managed to process the interrupt. This means we'd complete the | |
10376 | * CS flip too soon. | |
10377 | * | |
10378 | * Combining both checks should get us a good enough result. It may | |
10379 | * still happen that the CS flip has been executed, but has not | |
10380 | * yet actually completed. But in case the base address is the same | |
10381 | * anyway, we don't really care. | |
10382 | */ | |
10383 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10384 | crtc->unpin_work->gtt_offset && | |
10385 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), | |
10386 | crtc->unpin_work->flip_count); | |
10387 | } | |
10388 | ||
6b95a207 KH |
10389 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10390 | { | |
fbee40df | 10391 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10392 | struct intel_crtc *intel_crtc = |
10393 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10394 | unsigned long flags; | |
10395 | ||
f326038a DV |
10396 | |
10397 | /* | |
10398 | * This is called both by irq handlers and the reset code (to complete | |
10399 | * lost pageflips) so needs the full irqsave spinlocks. | |
10400 | * | |
10401 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10402 | * generate a page-flip completion irq, i.e. every modeset |
10403 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10404 | */ | |
6b95a207 | 10405 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10406 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10407 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10408 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10409 | } | |
10410 | ||
eba905b2 | 10411 | static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc) |
e7d841ca CW |
10412 | { |
10413 | /* Ensure that the work item is consistent when activating it ... */ | |
10414 | smp_wmb(); | |
10415 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); | |
10416 | /* and that it is marked active as soon as the irq could fire. */ | |
10417 | smp_wmb(); | |
10418 | } | |
10419 | ||
8c9f3aaf JB |
10420 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10421 | struct drm_crtc *crtc, | |
10422 | struct drm_framebuffer *fb, | |
ed8d1975 | 10423 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10424 | struct intel_engine_cs *ring, |
ed8d1975 | 10425 | uint32_t flags) |
8c9f3aaf | 10426 | { |
8c9f3aaf | 10427 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10428 | u32 flip_mask; |
10429 | int ret; | |
10430 | ||
6d90c952 | 10431 | ret = intel_ring_begin(ring, 6); |
8c9f3aaf | 10432 | if (ret) |
4fa62c89 | 10433 | return ret; |
8c9f3aaf JB |
10434 | |
10435 | /* Can't queue multiple flips, so wait for the previous | |
10436 | * one to finish before executing the next. | |
10437 | */ | |
10438 | if (intel_crtc->plane) | |
10439 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10440 | else | |
10441 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10442 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10443 | intel_ring_emit(ring, MI_NOOP); | |
10444 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10445 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10446 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10447 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10448 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca CW |
10449 | |
10450 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 10451 | __intel_ring_advance(ring); |
83d4092b | 10452 | return 0; |
8c9f3aaf JB |
10453 | } |
10454 | ||
10455 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
10456 | struct drm_crtc *crtc, | |
10457 | struct drm_framebuffer *fb, | |
ed8d1975 | 10458 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10459 | struct intel_engine_cs *ring, |
ed8d1975 | 10460 | uint32_t flags) |
8c9f3aaf | 10461 | { |
8c9f3aaf | 10462 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10463 | u32 flip_mask; |
10464 | int ret; | |
10465 | ||
6d90c952 | 10466 | ret = intel_ring_begin(ring, 6); |
8c9f3aaf | 10467 | if (ret) |
4fa62c89 | 10468 | return ret; |
8c9f3aaf JB |
10469 | |
10470 | if (intel_crtc->plane) | |
10471 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10472 | else | |
10473 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10474 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10475 | intel_ring_emit(ring, MI_NOOP); | |
10476 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
10477 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10478 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10479 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
10480 | intel_ring_emit(ring, MI_NOOP); |
10481 | ||
e7d841ca | 10482 | intel_mark_page_flip_active(intel_crtc); |
09246732 | 10483 | __intel_ring_advance(ring); |
83d4092b | 10484 | return 0; |
8c9f3aaf JB |
10485 | } |
10486 | ||
10487 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
10488 | struct drm_crtc *crtc, | |
10489 | struct drm_framebuffer *fb, | |
ed8d1975 | 10490 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10491 | struct intel_engine_cs *ring, |
ed8d1975 | 10492 | uint32_t flags) |
8c9f3aaf JB |
10493 | { |
10494 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10495 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10496 | uint32_t pf, pipesrc; | |
10497 | int ret; | |
10498 | ||
6d90c952 | 10499 | ret = intel_ring_begin(ring, 4); |
8c9f3aaf | 10500 | if (ret) |
4fa62c89 | 10501 | return ret; |
8c9f3aaf JB |
10502 | |
10503 | /* i965+ uses the linear or tiled offsets from the | |
10504 | * Display Registers (which do not change across a page-flip) | |
10505 | * so we need only reprogram the base address. | |
10506 | */ | |
6d90c952 DV |
10507 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10508 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10509 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10510 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 10511 | obj->tiling_mode); |
8c9f3aaf JB |
10512 | |
10513 | /* XXX Enabling the panel-fitter across page-flip is so far | |
10514 | * untested on non-native modes, so ignore it for now. | |
10515 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
10516 | */ | |
10517 | pf = 0; | |
10518 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 10519 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
10520 | |
10521 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 10522 | __intel_ring_advance(ring); |
83d4092b | 10523 | return 0; |
8c9f3aaf JB |
10524 | } |
10525 | ||
10526 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
10527 | struct drm_crtc *crtc, | |
10528 | struct drm_framebuffer *fb, | |
ed8d1975 | 10529 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10530 | struct intel_engine_cs *ring, |
ed8d1975 | 10531 | uint32_t flags) |
8c9f3aaf JB |
10532 | { |
10533 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10534 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10535 | uint32_t pf, pipesrc; | |
10536 | int ret; | |
10537 | ||
6d90c952 | 10538 | ret = intel_ring_begin(ring, 4); |
8c9f3aaf | 10539 | if (ret) |
4fa62c89 | 10540 | return ret; |
8c9f3aaf | 10541 | |
6d90c952 DV |
10542 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
10543 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10544 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 10545 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 10546 | |
dc257cf1 DV |
10547 | /* Contrary to the suggestions in the documentation, |
10548 | * "Enable Panel Fitter" does not seem to be required when page | |
10549 | * flipping with a non-native mode, and worse causes a normal | |
10550 | * modeset to fail. | |
10551 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
10552 | */ | |
10553 | pf = 0; | |
8c9f3aaf | 10554 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 10555 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
10556 | |
10557 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 10558 | __intel_ring_advance(ring); |
83d4092b | 10559 | return 0; |
8c9f3aaf JB |
10560 | } |
10561 | ||
7c9017e5 JB |
10562 | static int intel_gen7_queue_flip(struct drm_device *dev, |
10563 | struct drm_crtc *crtc, | |
10564 | struct drm_framebuffer *fb, | |
ed8d1975 | 10565 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10566 | struct intel_engine_cs *ring, |
ed8d1975 | 10567 | uint32_t flags) |
7c9017e5 | 10568 | { |
7c9017e5 | 10569 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 10570 | uint32_t plane_bit = 0; |
ffe74d75 CW |
10571 | int len, ret; |
10572 | ||
eba905b2 | 10573 | switch (intel_crtc->plane) { |
cb05d8de DV |
10574 | case PLANE_A: |
10575 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
10576 | break; | |
10577 | case PLANE_B: | |
10578 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
10579 | break; | |
10580 | case PLANE_C: | |
10581 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
10582 | break; | |
10583 | default: | |
10584 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 10585 | return -ENODEV; |
cb05d8de DV |
10586 | } |
10587 | ||
ffe74d75 | 10588 | len = 4; |
f476828a | 10589 | if (ring->id == RCS) { |
ffe74d75 | 10590 | len += 6; |
f476828a DL |
10591 | /* |
10592 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
10593 | * 48bits addresses, and we need a NOOP for the batch size to | |
10594 | * stay even. | |
10595 | */ | |
10596 | if (IS_GEN8(dev)) | |
10597 | len += 2; | |
10598 | } | |
ffe74d75 | 10599 | |
f66fab8e VS |
10600 | /* |
10601 | * BSpec MI_DISPLAY_FLIP for IVB: | |
10602 | * "The full packet must be contained within the same cache line." | |
10603 | * | |
10604 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
10605 | * cacheline, if we ever start emitting more commands before | |
10606 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
10607 | * then do the cacheline alignment, and finally emit the | |
10608 | * MI_DISPLAY_FLIP. | |
10609 | */ | |
10610 | ret = intel_ring_cacheline_align(ring); | |
10611 | if (ret) | |
4fa62c89 | 10612 | return ret; |
f66fab8e | 10613 | |
ffe74d75 | 10614 | ret = intel_ring_begin(ring, len); |
7c9017e5 | 10615 | if (ret) |
4fa62c89 | 10616 | return ret; |
7c9017e5 | 10617 | |
ffe74d75 CW |
10618 | /* Unmask the flip-done completion message. Note that the bspec says that |
10619 | * we should do this for both the BCS and RCS, and that we must not unmask | |
10620 | * more than one flip event at any time (or ensure that one flip message | |
10621 | * can be sent by waiting for flip-done prior to queueing new flips). | |
10622 | * Experimentation says that BCS works despite DERRMR masking all | |
10623 | * flip-done completion events and that unmasking all planes at once | |
10624 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
10625 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
10626 | */ | |
10627 | if (ring->id == RCS) { | |
10628 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
10629 | intel_ring_emit(ring, DERRMR); | |
10630 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
10631 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
10632 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a DL |
10633 | if (IS_GEN8(dev)) |
10634 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | | |
10635 | MI_SRM_LRM_GLOBAL_GTT); | |
10636 | else | |
10637 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | | |
10638 | MI_SRM_LRM_GLOBAL_GTT); | |
ffe74d75 CW |
10639 | intel_ring_emit(ring, DERRMR); |
10640 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
10641 | if (IS_GEN8(dev)) { |
10642 | intel_ring_emit(ring, 0); | |
10643 | intel_ring_emit(ring, MI_NOOP); | |
10644 | } | |
ffe74d75 CW |
10645 | } |
10646 | ||
cb05d8de | 10647 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 10648 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 10649 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 10650 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca CW |
10651 | |
10652 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 10653 | __intel_ring_advance(ring); |
83d4092b | 10654 | return 0; |
7c9017e5 JB |
10655 | } |
10656 | ||
84c33a64 SG |
10657 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
10658 | struct drm_i915_gem_object *obj) | |
10659 | { | |
10660 | /* | |
10661 | * This is not being used for older platforms, because | |
10662 | * non-availability of flip done interrupt forces us to use | |
10663 | * CS flips. Older platforms derive flip done using some clever | |
10664 | * tricks involving the flip_pending status bits and vblank irqs. | |
10665 | * So using MMIO flips there would disrupt this mechanism. | |
10666 | */ | |
10667 | ||
8e09bf83 CW |
10668 | if (ring == NULL) |
10669 | return true; | |
10670 | ||
84c33a64 SG |
10671 | if (INTEL_INFO(ring->dev)->gen < 5) |
10672 | return false; | |
10673 | ||
10674 | if (i915.use_mmio_flip < 0) | |
10675 | return false; | |
10676 | else if (i915.use_mmio_flip > 0) | |
10677 | return true; | |
14bf993e OM |
10678 | else if (i915.enable_execlists) |
10679 | return true; | |
84c33a64 | 10680 | else |
41c52415 | 10681 | return ring != i915_gem_request_get_ring(obj->last_read_req); |
84c33a64 SG |
10682 | } |
10683 | ||
ff944564 DL |
10684 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
10685 | { | |
10686 | struct drm_device *dev = intel_crtc->base.dev; | |
10687 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10688 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 DL |
10689 | const enum pipe pipe = intel_crtc->pipe; |
10690 | u32 ctl, stride; | |
10691 | ||
10692 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
10693 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
10694 | switch (fb->modifier[0]) { |
10695 | case DRM_FORMAT_MOD_NONE: | |
10696 | break; | |
10697 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 10698 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
10699 | break; |
10700 | case I915_FORMAT_MOD_Y_TILED: | |
10701 | ctl |= PLANE_CTL_TILED_Y; | |
10702 | break; | |
10703 | case I915_FORMAT_MOD_Yf_TILED: | |
10704 | ctl |= PLANE_CTL_TILED_YF; | |
10705 | break; | |
10706 | default: | |
10707 | MISSING_CASE(fb->modifier[0]); | |
10708 | } | |
ff944564 DL |
10709 | |
10710 | /* | |
10711 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
10712 | * linear buffers or in number of tiles for tiled buffers. | |
10713 | */ | |
2ebef630 TU |
10714 | stride = fb->pitches[0] / |
10715 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
10716 | fb->pixel_format); | |
ff944564 DL |
10717 | |
10718 | /* | |
10719 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
10720 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
10721 | */ | |
10722 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
10723 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
10724 | ||
10725 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); | |
10726 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
10727 | } | |
10728 | ||
10729 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) | |
84c33a64 SG |
10730 | { |
10731 | struct drm_device *dev = intel_crtc->base.dev; | |
10732 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10733 | struct intel_framebuffer *intel_fb = | |
10734 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
10735 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
10736 | u32 dspcntr; | |
10737 | u32 reg; | |
10738 | ||
84c33a64 SG |
10739 | reg = DSPCNTR(intel_crtc->plane); |
10740 | dspcntr = I915_READ(reg); | |
10741 | ||
c5d97472 DL |
10742 | if (obj->tiling_mode != I915_TILING_NONE) |
10743 | dspcntr |= DISPPLANE_TILED; | |
10744 | else | |
10745 | dspcntr &= ~DISPPLANE_TILED; | |
10746 | ||
84c33a64 SG |
10747 | I915_WRITE(reg, dspcntr); |
10748 | ||
10749 | I915_WRITE(DSPSURF(intel_crtc->plane), | |
10750 | intel_crtc->unpin_work->gtt_offset); | |
10751 | POSTING_READ(DSPSURF(intel_crtc->plane)); | |
84c33a64 | 10752 | |
ff944564 DL |
10753 | } |
10754 | ||
10755 | /* | |
10756 | * XXX: This is the temporary way to update the plane registers until we get | |
10757 | * around to using the usual plane update functions for MMIO flips | |
10758 | */ | |
10759 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) | |
10760 | { | |
10761 | struct drm_device *dev = intel_crtc->base.dev; | |
10762 | bool atomic_update; | |
10763 | u32 start_vbl_count; | |
10764 | ||
10765 | intel_mark_page_flip_active(intel_crtc); | |
10766 | ||
10767 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); | |
10768 | ||
10769 | if (INTEL_INFO(dev)->gen >= 9) | |
10770 | skl_do_mmio_flip(intel_crtc); | |
10771 | else | |
10772 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
10773 | ilk_do_mmio_flip(intel_crtc); | |
10774 | ||
9362c7c5 ACO |
10775 | if (atomic_update) |
10776 | intel_pipe_update_end(intel_crtc, start_vbl_count); | |
84c33a64 SG |
10777 | } |
10778 | ||
9362c7c5 | 10779 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 10780 | { |
b2cfe0ab CW |
10781 | struct intel_mmio_flip *mmio_flip = |
10782 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 10783 | |
b2cfe0ab CW |
10784 | if (mmio_flip->rq) |
10785 | WARN_ON(__i915_wait_request(mmio_flip->rq, | |
10786 | mmio_flip->crtc->reset_counter, | |
10787 | false, NULL, NULL)); | |
84c33a64 | 10788 | |
b2cfe0ab CW |
10789 | intel_do_mmio_flip(mmio_flip->crtc); |
10790 | ||
10791 | i915_gem_request_unreference__unlocked(mmio_flip->rq); | |
10792 | kfree(mmio_flip); | |
84c33a64 SG |
10793 | } |
10794 | ||
10795 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
10796 | struct drm_crtc *crtc, | |
10797 | struct drm_framebuffer *fb, | |
10798 | struct drm_i915_gem_object *obj, | |
10799 | struct intel_engine_cs *ring, | |
10800 | uint32_t flags) | |
10801 | { | |
b2cfe0ab CW |
10802 | struct intel_mmio_flip *mmio_flip; |
10803 | ||
10804 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
10805 | if (mmio_flip == NULL) | |
10806 | return -ENOMEM; | |
84c33a64 | 10807 | |
b2cfe0ab CW |
10808 | mmio_flip->rq = i915_gem_request_reference(obj->last_write_req); |
10809 | mmio_flip->crtc = to_intel_crtc(crtc); | |
536f5b5e | 10810 | |
b2cfe0ab CW |
10811 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
10812 | schedule_work(&mmio_flip->work); | |
84c33a64 | 10813 | |
84c33a64 SG |
10814 | return 0; |
10815 | } | |
10816 | ||
8c9f3aaf JB |
10817 | static int intel_default_queue_flip(struct drm_device *dev, |
10818 | struct drm_crtc *crtc, | |
10819 | struct drm_framebuffer *fb, | |
ed8d1975 | 10820 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10821 | struct intel_engine_cs *ring, |
ed8d1975 | 10822 | uint32_t flags) |
8c9f3aaf JB |
10823 | { |
10824 | return -ENODEV; | |
10825 | } | |
10826 | ||
d6bbafa1 CW |
10827 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
10828 | struct drm_crtc *crtc) | |
10829 | { | |
10830 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10831 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10832 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
10833 | u32 addr; | |
10834 | ||
10835 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
10836 | return true; | |
10837 | ||
10838 | if (!work->enable_stall_check) | |
10839 | return false; | |
10840 | ||
10841 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
10842 | if (work->flip_queued_req && |
10843 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
10844 | return false; |
10845 | ||
1e3feefd | 10846 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
10847 | } |
10848 | ||
1e3feefd | 10849 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
10850 | return false; |
10851 | ||
10852 | /* Potential stall - if we see that the flip has happened, | |
10853 | * assume a missed interrupt. */ | |
10854 | if (INTEL_INFO(dev)->gen >= 4) | |
10855 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
10856 | else | |
10857 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
10858 | ||
10859 | /* There is a potential issue here with a false positive after a flip | |
10860 | * to the same address. We could address this by checking for a | |
10861 | * non-incrementing frame counter. | |
10862 | */ | |
10863 | return addr == work->gtt_offset; | |
10864 | } | |
10865 | ||
10866 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
10867 | { | |
10868 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10869 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
10870 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 10871 | struct intel_unpin_work *work; |
f326038a | 10872 | |
6c51d46f | 10873 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
10874 | |
10875 | if (crtc == NULL) | |
10876 | return; | |
10877 | ||
f326038a | 10878 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
10879 | work = intel_crtc->unpin_work; |
10880 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 10881 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 10882 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 10883 | page_flip_completed(intel_crtc); |
6ad790c0 | 10884 | work = NULL; |
d6bbafa1 | 10885 | } |
6ad790c0 CW |
10886 | if (work != NULL && |
10887 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
10888 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 10889 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
10890 | } |
10891 | ||
6b95a207 KH |
10892 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
10893 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
10894 | struct drm_pending_vblank_event *event, |
10895 | uint32_t page_flip_flags) | |
6b95a207 KH |
10896 | { |
10897 | struct drm_device *dev = crtc->dev; | |
10898 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 10899 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 10900 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 10901 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 10902 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 10903 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 10904 | struct intel_unpin_work *work; |
a4872ba6 | 10905 | struct intel_engine_cs *ring; |
cf5d8a46 | 10906 | bool mmio_flip; |
52e68630 | 10907 | int ret; |
6b95a207 | 10908 | |
2ff8fde1 MR |
10909 | /* |
10910 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
10911 | * check to be safe. In the future we may enable pageflipping from | |
10912 | * a disabled primary plane. | |
10913 | */ | |
10914 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
10915 | return -EBUSY; | |
10916 | ||
e6a595d2 | 10917 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 10918 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
10919 | return -EINVAL; |
10920 | ||
10921 | /* | |
10922 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
10923 | * Note that pitch changes could also affect these register. | |
10924 | */ | |
10925 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
10926 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
10927 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
10928 | return -EINVAL; |
10929 | ||
f900db47 CW |
10930 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
10931 | goto out_hang; | |
10932 | ||
b14c5679 | 10933 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
10934 | if (work == NULL) |
10935 | return -ENOMEM; | |
10936 | ||
6b95a207 | 10937 | work->event = event; |
b4a98e57 | 10938 | work->crtc = crtc; |
ab8d6675 | 10939 | work->old_fb = old_fb; |
6b95a207 KH |
10940 | INIT_WORK(&work->work, intel_unpin_work_fn); |
10941 | ||
87b6b101 | 10942 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
10943 | if (ret) |
10944 | goto free_work; | |
10945 | ||
6b95a207 | 10946 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 10947 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 10948 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
10949 | /* Before declaring the flip queue wedged, check if |
10950 | * the hardware completed the operation behind our backs. | |
10951 | */ | |
10952 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
10953 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
10954 | page_flip_completed(intel_crtc); | |
10955 | } else { | |
10956 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 10957 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 10958 | |
d6bbafa1 CW |
10959 | drm_crtc_vblank_put(crtc); |
10960 | kfree(work); | |
10961 | return -EBUSY; | |
10962 | } | |
6b95a207 KH |
10963 | } |
10964 | intel_crtc->unpin_work = work; | |
5e2d7afc | 10965 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 10966 | |
b4a98e57 CW |
10967 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
10968 | flush_workqueue(dev_priv->wq); | |
10969 | ||
75dfca80 | 10970 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 10971 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 10972 | drm_gem_object_reference(&obj->base); |
6b95a207 | 10973 | |
f4510a27 | 10974 | crtc->primary->fb = fb; |
afd65eb4 | 10975 | update_state_fb(crtc->primary); |
1ed1f968 | 10976 | |
e1f99ce6 | 10977 | work->pending_flip_obj = obj; |
e1f99ce6 | 10978 | |
89ed88ba CW |
10979 | ret = i915_mutex_lock_interruptible(dev); |
10980 | if (ret) | |
10981 | goto cleanup; | |
10982 | ||
b4a98e57 | 10983 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 10984 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 10985 | |
75f7f3ec | 10986 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
a071fa00 | 10987 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
75f7f3ec | 10988 | |
4fa62c89 VS |
10989 | if (IS_VALLEYVIEW(dev)) { |
10990 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 10991 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
10992 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
10993 | ring = NULL; | |
48bf5b2d | 10994 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 10995 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 10996 | } else if (INTEL_INFO(dev)->gen >= 7) { |
41c52415 | 10997 | ring = i915_gem_request_get_ring(obj->last_read_req); |
4fa62c89 VS |
10998 | if (ring == NULL || ring->id != RCS) |
10999 | ring = &dev_priv->ring[BCS]; | |
11000 | } else { | |
11001 | ring = &dev_priv->ring[RCS]; | |
11002 | } | |
11003 | ||
cf5d8a46 CW |
11004 | mmio_flip = use_mmio_flip(ring, obj); |
11005 | ||
11006 | /* When using CS flips, we want to emit semaphores between rings. | |
11007 | * However, when using mmio flips we will create a task to do the | |
11008 | * synchronisation, so all we want here is to pin the framebuffer | |
11009 | * into the display plane and skip any waits. | |
11010 | */ | |
82bc3b2d | 11011 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
cf5d8a46 CW |
11012 | crtc->primary->state, |
11013 | mmio_flip ? i915_gem_request_get_ring(obj->last_read_req) : ring); | |
8c9f3aaf JB |
11014 | if (ret) |
11015 | goto cleanup_pending; | |
6b95a207 | 11016 | |
121920fa TU |
11017 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
11018 | + intel_crtc->dspaddr_offset; | |
4fa62c89 | 11019 | |
cf5d8a46 | 11020 | if (mmio_flip) { |
84c33a64 SG |
11021 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
11022 | page_flip_flags); | |
d6bbafa1 CW |
11023 | if (ret) |
11024 | goto cleanup_unpin; | |
11025 | ||
f06cc1b9 JH |
11026 | i915_gem_request_assign(&work->flip_queued_req, |
11027 | obj->last_write_req); | |
d6bbafa1 | 11028 | } else { |
d94b5030 CW |
11029 | if (obj->last_write_req) { |
11030 | ret = i915_gem_check_olr(obj->last_write_req); | |
11031 | if (ret) | |
11032 | goto cleanup_unpin; | |
11033 | } | |
11034 | ||
84c33a64 | 11035 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
d6bbafa1 CW |
11036 | page_flip_flags); |
11037 | if (ret) | |
11038 | goto cleanup_unpin; | |
11039 | ||
f06cc1b9 JH |
11040 | i915_gem_request_assign(&work->flip_queued_req, |
11041 | intel_ring_get_request(ring)); | |
d6bbafa1 CW |
11042 | } |
11043 | ||
1e3feefd | 11044 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11045 | work->enable_stall_check = true; |
4fa62c89 | 11046 | |
ab8d6675 | 11047 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a071fa00 DV |
11048 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
11049 | ||
7ff0ebcc | 11050 | intel_fbc_disable(dev); |
f99d7069 | 11051 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
6b95a207 KH |
11052 | mutex_unlock(&dev->struct_mutex); |
11053 | ||
e5510fac JB |
11054 | trace_i915_flip_request(intel_crtc->plane, obj); |
11055 | ||
6b95a207 | 11056 | return 0; |
96b099fd | 11057 | |
4fa62c89 | 11058 | cleanup_unpin: |
82bc3b2d | 11059 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11060 | cleanup_pending: |
b4a98e57 | 11061 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11062 | mutex_unlock(&dev->struct_mutex); |
11063 | cleanup: | |
f4510a27 | 11064 | crtc->primary->fb = old_fb; |
afd65eb4 | 11065 | update_state_fb(crtc->primary); |
89ed88ba CW |
11066 | |
11067 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11068 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11069 | |
5e2d7afc | 11070 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11071 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11072 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11073 | |
87b6b101 | 11074 | drm_crtc_vblank_put(crtc); |
7317c75e | 11075 | free_work: |
96b099fd CW |
11076 | kfree(work); |
11077 | ||
f900db47 CW |
11078 | if (ret == -EIO) { |
11079 | out_hang: | |
53a366b9 | 11080 | ret = intel_plane_restore(primary); |
f0d3dad3 | 11081 | if (ret == 0 && event) { |
5e2d7afc | 11082 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11083 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11084 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11085 | } |
f900db47 | 11086 | } |
96b099fd | 11087 | return ret; |
6b95a207 KH |
11088 | } |
11089 | ||
65b38e0d | 11090 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11091 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11092 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11093 | .atomic_begin = intel_begin_crtc_commit, |
11094 | .atomic_flush = intel_finish_crtc_commit, | |
f6e5b160 CW |
11095 | }; |
11096 | ||
9a935856 DV |
11097 | /** |
11098 | * intel_modeset_update_staged_output_state | |
11099 | * | |
11100 | * Updates the staged output configuration state, e.g. after we've read out the | |
11101 | * current hw state. | |
11102 | */ | |
11103 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) | |
f6e5b160 | 11104 | { |
7668851f | 11105 | struct intel_crtc *crtc; |
9a935856 DV |
11106 | struct intel_encoder *encoder; |
11107 | struct intel_connector *connector; | |
f6e5b160 | 11108 | |
3a3371ff | 11109 | for_each_intel_connector(dev, connector) { |
9a935856 DV |
11110 | connector->new_encoder = |
11111 | to_intel_encoder(connector->base.encoder); | |
11112 | } | |
f6e5b160 | 11113 | |
b2784e15 | 11114 | for_each_intel_encoder(dev, encoder) { |
9a935856 DV |
11115 | encoder->new_crtc = |
11116 | to_intel_crtc(encoder->base.crtc); | |
11117 | } | |
7668851f | 11118 | |
d3fcc808 | 11119 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 11120 | crtc->new_enabled = crtc->base.state->enable; |
7668851f | 11121 | } |
f6e5b160 CW |
11122 | } |
11123 | ||
d29b2f9d ACO |
11124 | /* Transitional helper to copy current connector/encoder state to |
11125 | * connector->state. This is needed so that code that is partially | |
11126 | * converted to atomic does the right thing. | |
11127 | */ | |
11128 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) | |
11129 | { | |
11130 | struct intel_connector *connector; | |
11131 | ||
11132 | for_each_intel_connector(dev, connector) { | |
11133 | if (connector->base.encoder) { | |
11134 | connector->base.state->best_encoder = | |
11135 | connector->base.encoder; | |
11136 | connector->base.state->crtc = | |
11137 | connector->base.encoder->crtc; | |
11138 | } else { | |
11139 | connector->base.state->best_encoder = NULL; | |
11140 | connector->base.state->crtc = NULL; | |
11141 | } | |
11142 | } | |
11143 | } | |
11144 | ||
a821fc46 | 11145 | /* Fixup legacy state after an atomic state swap. |
9a935856 | 11146 | */ |
a821fc46 | 11147 | static void intel_modeset_fixup_state(struct drm_atomic_state *state) |
9a935856 | 11148 | { |
a821fc46 | 11149 | struct intel_crtc *crtc; |
9a935856 | 11150 | struct intel_encoder *encoder; |
a821fc46 | 11151 | struct intel_connector *connector; |
d5432a9d | 11152 | |
a821fc46 ACO |
11153 | for_each_intel_connector(state->dev, connector) { |
11154 | connector->base.encoder = connector->base.state->best_encoder; | |
11155 | if (connector->base.encoder) | |
11156 | connector->base.encoder->crtc = | |
11157 | connector->base.state->crtc; | |
9a935856 | 11158 | } |
f6e5b160 | 11159 | |
d5432a9d ACO |
11160 | /* Update crtc of disabled encoders */ |
11161 | for_each_intel_encoder(state->dev, encoder) { | |
11162 | int num_connectors = 0; | |
11163 | ||
a821fc46 ACO |
11164 | for_each_intel_connector(state->dev, connector) |
11165 | if (connector->base.encoder == &encoder->base) | |
d5432a9d ACO |
11166 | num_connectors++; |
11167 | ||
11168 | if (num_connectors == 0) | |
11169 | encoder->base.crtc = NULL; | |
9a935856 | 11170 | } |
7668851f | 11171 | |
a821fc46 ACO |
11172 | for_each_intel_crtc(state->dev, crtc) { |
11173 | crtc->base.enabled = crtc->base.state->enable; | |
11174 | crtc->config = to_intel_crtc_state(crtc->base.state); | |
7668851f | 11175 | } |
d29b2f9d | 11176 | |
d5432a9d ACO |
11177 | /* Copy the new configuration to the staged state, to keep the few |
11178 | * pieces of code that haven't been converted yet happy */ | |
11179 | intel_modeset_update_staged_output_state(state->dev); | |
9a935856 DV |
11180 | } |
11181 | ||
050f7aeb | 11182 | static void |
eba905b2 | 11183 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11184 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11185 | { |
11186 | int bpp = pipe_config->pipe_bpp; | |
11187 | ||
11188 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11189 | connector->base.base.id, | |
c23cc417 | 11190 | connector->base.name); |
050f7aeb DV |
11191 | |
11192 | /* Don't use an invalid EDID bpc value */ | |
11193 | if (connector->base.display_info.bpc && | |
11194 | connector->base.display_info.bpc * 3 < bpp) { | |
11195 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11196 | bpp, connector->base.display_info.bpc*3); | |
11197 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11198 | } | |
11199 | ||
11200 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11201 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11202 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11203 | bpp); | |
11204 | pipe_config->pipe_bpp = 24; | |
11205 | } | |
11206 | } | |
11207 | ||
4e53c2e0 | 11208 | static int |
050f7aeb | 11209 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 11210 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 11211 | { |
050f7aeb | 11212 | struct drm_device *dev = crtc->base.dev; |
1486017f | 11213 | struct drm_atomic_state *state; |
da3ced29 ACO |
11214 | struct drm_connector *connector; |
11215 | struct drm_connector_state *connector_state; | |
1486017f | 11216 | int bpp, i; |
4e53c2e0 | 11217 | |
d328c9d7 | 11218 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 11219 | bpp = 10*3; |
d328c9d7 DV |
11220 | else if (INTEL_INFO(dev)->gen >= 5) |
11221 | bpp = 12*3; | |
11222 | else | |
11223 | bpp = 8*3; | |
11224 | ||
4e53c2e0 | 11225 | |
4e53c2e0 DV |
11226 | pipe_config->pipe_bpp = bpp; |
11227 | ||
1486017f ACO |
11228 | state = pipe_config->base.state; |
11229 | ||
4e53c2e0 | 11230 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
11231 | for_each_connector_in_state(state, connector, connector_state, i) { |
11232 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
11233 | continue; |
11234 | ||
da3ced29 ACO |
11235 | connected_sink_compute_bpp(to_intel_connector(connector), |
11236 | pipe_config); | |
4e53c2e0 DV |
11237 | } |
11238 | ||
11239 | return bpp; | |
11240 | } | |
11241 | ||
644db711 DV |
11242 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
11243 | { | |
11244 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
11245 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 11246 | mode->crtc_clock, |
644db711 DV |
11247 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
11248 | mode->crtc_hsync_end, mode->crtc_htotal, | |
11249 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
11250 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
11251 | } | |
11252 | ||
c0b03411 | 11253 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 11254 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
11255 | const char *context) |
11256 | { | |
6a60cd87 CK |
11257 | struct drm_device *dev = crtc->base.dev; |
11258 | struct drm_plane *plane; | |
11259 | struct intel_plane *intel_plane; | |
11260 | struct intel_plane_state *state; | |
11261 | struct drm_framebuffer *fb; | |
11262 | ||
11263 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
11264 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
11265 | |
11266 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
11267 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
11268 | pipe_config->pipe_bpp, pipe_config->dither); | |
11269 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
11270 | pipe_config->has_pch_encoder, | |
11271 | pipe_config->fdi_lanes, | |
11272 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
11273 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
11274 | pipe_config->fdi_m_n.tu); | |
eb14cb74 VS |
11275 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
11276 | pipe_config->has_dp_encoder, | |
11277 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, | |
11278 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
11279 | pipe_config->dp_m_n.tu); | |
b95af8be VK |
11280 | |
11281 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", | |
11282 | pipe_config->has_dp_encoder, | |
11283 | pipe_config->dp_m2_n2.gmch_m, | |
11284 | pipe_config->dp_m2_n2.gmch_n, | |
11285 | pipe_config->dp_m2_n2.link_m, | |
11286 | pipe_config->dp_m2_n2.link_n, | |
11287 | pipe_config->dp_m2_n2.tu); | |
11288 | ||
55072d19 DV |
11289 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
11290 | pipe_config->has_audio, | |
11291 | pipe_config->has_infoframe); | |
11292 | ||
c0b03411 | 11293 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 11294 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 11295 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
11296 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
11297 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 11298 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
11299 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
11300 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
11301 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
11302 | crtc->num_scalers, | |
11303 | pipe_config->scaler_state.scaler_users, | |
11304 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
11305 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
11306 | pipe_config->gmch_pfit.control, | |
11307 | pipe_config->gmch_pfit.pgm_ratios, | |
11308 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 11309 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 11310 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
11311 | pipe_config->pch_pfit.size, |
11312 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 11313 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 11314 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 11315 | |
415ff0f6 TU |
11316 | if (IS_BROXTON(dev)) { |
11317 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, " | |
11318 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " | |
11319 | "pll6: 0x%x, pll8: 0x%x, pcsdw12: 0x%x\n", | |
11320 | pipe_config->ddi_pll_sel, | |
11321 | pipe_config->dpll_hw_state.ebb0, | |
11322 | pipe_config->dpll_hw_state.pll0, | |
11323 | pipe_config->dpll_hw_state.pll1, | |
11324 | pipe_config->dpll_hw_state.pll2, | |
11325 | pipe_config->dpll_hw_state.pll3, | |
11326 | pipe_config->dpll_hw_state.pll6, | |
11327 | pipe_config->dpll_hw_state.pll8, | |
11328 | pipe_config->dpll_hw_state.pcsdw12); | |
11329 | } else if (IS_SKYLAKE(dev)) { | |
11330 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " | |
11331 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
11332 | pipe_config->ddi_pll_sel, | |
11333 | pipe_config->dpll_hw_state.ctrl1, | |
11334 | pipe_config->dpll_hw_state.cfgcr1, | |
11335 | pipe_config->dpll_hw_state.cfgcr2); | |
11336 | } else if (HAS_DDI(dev)) { | |
11337 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
11338 | pipe_config->ddi_pll_sel, | |
11339 | pipe_config->dpll_hw_state.wrpll); | |
11340 | } else { | |
11341 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
11342 | "fp0: 0x%x, fp1: 0x%x\n", | |
11343 | pipe_config->dpll_hw_state.dpll, | |
11344 | pipe_config->dpll_hw_state.dpll_md, | |
11345 | pipe_config->dpll_hw_state.fp0, | |
11346 | pipe_config->dpll_hw_state.fp1); | |
11347 | } | |
11348 | ||
6a60cd87 CK |
11349 | DRM_DEBUG_KMS("planes on this crtc\n"); |
11350 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
11351 | intel_plane = to_intel_plane(plane); | |
11352 | if (intel_plane->pipe != crtc->pipe) | |
11353 | continue; | |
11354 | ||
11355 | state = to_intel_plane_state(plane->state); | |
11356 | fb = state->base.fb; | |
11357 | if (!fb) { | |
11358 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
11359 | "disabled, scaler_id = %d\n", | |
11360 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
11361 | plane->base.id, intel_plane->pipe, | |
11362 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
11363 | drm_plane_index(plane), state->scaler_id); | |
11364 | continue; | |
11365 | } | |
11366 | ||
11367 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
11368 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
11369 | plane->base.id, intel_plane->pipe, | |
11370 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
11371 | drm_plane_index(plane)); | |
11372 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
11373 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
11374 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
11375 | state->scaler_id, | |
11376 | state->src.x1 >> 16, state->src.y1 >> 16, | |
11377 | drm_rect_width(&state->src) >> 16, | |
11378 | drm_rect_height(&state->src) >> 16, | |
11379 | state->dst.x1, state->dst.y1, | |
11380 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
11381 | } | |
c0b03411 DV |
11382 | } |
11383 | ||
bc079e8b VS |
11384 | static bool encoders_cloneable(const struct intel_encoder *a, |
11385 | const struct intel_encoder *b) | |
accfc0c5 | 11386 | { |
bc079e8b VS |
11387 | /* masks could be asymmetric, so check both ways */ |
11388 | return a == b || (a->cloneable & (1 << b->type) && | |
11389 | b->cloneable & (1 << a->type)); | |
11390 | } | |
11391 | ||
98a221da ACO |
11392 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
11393 | struct intel_crtc *crtc, | |
bc079e8b VS |
11394 | struct intel_encoder *encoder) |
11395 | { | |
bc079e8b | 11396 | struct intel_encoder *source_encoder; |
da3ced29 | 11397 | struct drm_connector *connector; |
98a221da ACO |
11398 | struct drm_connector_state *connector_state; |
11399 | int i; | |
bc079e8b | 11400 | |
da3ced29 | 11401 | for_each_connector_in_state(state, connector, connector_state, i) { |
98a221da | 11402 | if (connector_state->crtc != &crtc->base) |
bc079e8b VS |
11403 | continue; |
11404 | ||
98a221da ACO |
11405 | source_encoder = |
11406 | to_intel_encoder(connector_state->best_encoder); | |
bc079e8b VS |
11407 | if (!encoders_cloneable(encoder, source_encoder)) |
11408 | return false; | |
11409 | } | |
11410 | ||
11411 | return true; | |
11412 | } | |
11413 | ||
98a221da ACO |
11414 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
11415 | struct intel_crtc *crtc) | |
bc079e8b | 11416 | { |
accfc0c5 | 11417 | struct intel_encoder *encoder; |
da3ced29 | 11418 | struct drm_connector *connector; |
98a221da ACO |
11419 | struct drm_connector_state *connector_state; |
11420 | int i; | |
accfc0c5 | 11421 | |
da3ced29 | 11422 | for_each_connector_in_state(state, connector, connector_state, i) { |
98a221da ACO |
11423 | if (connector_state->crtc != &crtc->base) |
11424 | continue; | |
11425 | ||
11426 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11427 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
bc079e8b | 11428 | return false; |
accfc0c5 DV |
11429 | } |
11430 | ||
bc079e8b | 11431 | return true; |
accfc0c5 DV |
11432 | } |
11433 | ||
5448a00d | 11434 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 11435 | { |
5448a00d ACO |
11436 | struct drm_device *dev = state->dev; |
11437 | struct intel_encoder *encoder; | |
da3ced29 | 11438 | struct drm_connector *connector; |
5448a00d | 11439 | struct drm_connector_state *connector_state; |
00f0b378 | 11440 | unsigned int used_ports = 0; |
5448a00d | 11441 | int i; |
00f0b378 VS |
11442 | |
11443 | /* | |
11444 | * Walk the connector list instead of the encoder | |
11445 | * list to detect the problem on ddi platforms | |
11446 | * where there's just one encoder per digital port. | |
11447 | */ | |
da3ced29 | 11448 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 11449 | if (!connector_state->best_encoder) |
00f0b378 VS |
11450 | continue; |
11451 | ||
5448a00d ACO |
11452 | encoder = to_intel_encoder(connector_state->best_encoder); |
11453 | ||
11454 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
11455 | |
11456 | switch (encoder->type) { | |
11457 | unsigned int port_mask; | |
11458 | case INTEL_OUTPUT_UNKNOWN: | |
11459 | if (WARN_ON(!HAS_DDI(dev))) | |
11460 | break; | |
11461 | case INTEL_OUTPUT_DISPLAYPORT: | |
11462 | case INTEL_OUTPUT_HDMI: | |
11463 | case INTEL_OUTPUT_EDP: | |
11464 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
11465 | ||
11466 | /* the same port mustn't appear more than once */ | |
11467 | if (used_ports & port_mask) | |
11468 | return false; | |
11469 | ||
11470 | used_ports |= port_mask; | |
11471 | default: | |
11472 | break; | |
11473 | } | |
11474 | } | |
11475 | ||
11476 | return true; | |
11477 | } | |
11478 | ||
83a57153 ACO |
11479 | static void |
11480 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
11481 | { | |
11482 | struct drm_crtc_state tmp_state; | |
663a3640 | 11483 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
11484 | struct intel_dpll_hw_state dpll_hw_state; |
11485 | enum intel_dpll_id shared_dpll; | |
8504c74c | 11486 | uint32_t ddi_pll_sel; |
83a57153 | 11487 | |
663a3640 | 11488 | /* Clear only the intel specific part of the crtc state excluding scalers */ |
83a57153 | 11489 | tmp_state = crtc_state->base; |
663a3640 | 11490 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
11491 | shared_dpll = crtc_state->shared_dpll; |
11492 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 11493 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
4978cc93 | 11494 | |
83a57153 | 11495 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 11496 | |
83a57153 | 11497 | crtc_state->base = tmp_state; |
663a3640 | 11498 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
11499 | crtc_state->shared_dpll = shared_dpll; |
11500 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 11501 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
83a57153 ACO |
11502 | } |
11503 | ||
548ee15b | 11504 | static int |
b8cecdf5 | 11505 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
548ee15b ACO |
11506 | struct drm_atomic_state *state, |
11507 | struct intel_crtc_state *pipe_config) | |
ee7b9f93 | 11508 | { |
7758a113 | 11509 | struct intel_encoder *encoder; |
da3ced29 | 11510 | struct drm_connector *connector; |
0b901879 | 11511 | struct drm_connector_state *connector_state; |
d328c9d7 | 11512 | int base_bpp, ret = -EINVAL; |
0b901879 | 11513 | int i; |
e29c22c0 | 11514 | bool retry = true; |
ee7b9f93 | 11515 | |
98a221da | 11516 | if (!check_encoder_cloning(state, to_intel_crtc(crtc))) { |
accfc0c5 | 11517 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
548ee15b | 11518 | return -EINVAL; |
accfc0c5 DV |
11519 | } |
11520 | ||
5448a00d | 11521 | if (!check_digital_port_conflicts(state)) { |
00f0b378 | 11522 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
548ee15b | 11523 | return -EINVAL; |
00f0b378 VS |
11524 | } |
11525 | ||
83a57153 | 11526 | clear_intel_crtc_state(pipe_config); |
7758a113 | 11527 | |
e143a21c DV |
11528 | pipe_config->cpu_transcoder = |
11529 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 11530 | |
2960bc9c ID |
11531 | /* |
11532 | * Sanitize sync polarity flags based on requested ones. If neither | |
11533 | * positive or negative polarity is requested, treat this as meaning | |
11534 | * negative polarity. | |
11535 | */ | |
2d112de7 | 11536 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 11537 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 11538 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 11539 | |
2d112de7 | 11540 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 11541 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 11542 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 11543 | |
050f7aeb DV |
11544 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
11545 | * plane pixel format and any sink constraints into account. Returns the | |
11546 | * source plane bpp so that dithering can be selected on mismatches | |
11547 | * after encoders and crtc also have had their say. */ | |
d328c9d7 DV |
11548 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
11549 | pipe_config); | |
11550 | if (base_bpp < 0) | |
4e53c2e0 DV |
11551 | goto fail; |
11552 | ||
e41a56be VS |
11553 | /* |
11554 | * Determine the real pipe dimensions. Note that stereo modes can | |
11555 | * increase the actual pipe size due to the frame doubling and | |
11556 | * insertion of additional space for blanks between the frame. This | |
11557 | * is stored in the crtc timings. We use the requested mode to do this | |
11558 | * computation to clearly distinguish it from the adjusted mode, which | |
11559 | * can be changed by the connectors in the below retry loop. | |
11560 | */ | |
2d112de7 | 11561 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
11562 | &pipe_config->pipe_src_w, |
11563 | &pipe_config->pipe_src_h); | |
e41a56be | 11564 | |
e29c22c0 | 11565 | encoder_retry: |
ef1b460d | 11566 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 11567 | pipe_config->port_clock = 0; |
ef1b460d | 11568 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 11569 | |
135c81b8 | 11570 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
11571 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
11572 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 11573 | |
7758a113 DV |
11574 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
11575 | * adjust it according to limitations or connector properties, and also | |
11576 | * a chance to reject the mode entirely. | |
47f1c6c9 | 11577 | */ |
da3ced29 | 11578 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 11579 | if (connector_state->crtc != crtc) |
7758a113 | 11580 | continue; |
7ae89233 | 11581 | |
0b901879 ACO |
11582 | encoder = to_intel_encoder(connector_state->best_encoder); |
11583 | ||
efea6e8e DV |
11584 | if (!(encoder->compute_config(encoder, pipe_config))) { |
11585 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
11586 | goto fail; |
11587 | } | |
ee7b9f93 | 11588 | } |
47f1c6c9 | 11589 | |
ff9a6750 DV |
11590 | /* Set default port clock if not overwritten by the encoder. Needs to be |
11591 | * done afterwards in case the encoder adjusts the mode. */ | |
11592 | if (!pipe_config->port_clock) | |
2d112de7 | 11593 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 11594 | * pipe_config->pixel_multiplier; |
ff9a6750 | 11595 | |
a43f6e0f | 11596 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 11597 | if (ret < 0) { |
7758a113 DV |
11598 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
11599 | goto fail; | |
ee7b9f93 | 11600 | } |
e29c22c0 DV |
11601 | |
11602 | if (ret == RETRY) { | |
11603 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
11604 | ret = -EINVAL; | |
11605 | goto fail; | |
11606 | } | |
11607 | ||
11608 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
11609 | retry = false; | |
11610 | goto encoder_retry; | |
11611 | } | |
11612 | ||
d328c9d7 | 11613 | pipe_config->dither = pipe_config->pipe_bpp != base_bpp; |
4e53c2e0 | 11614 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 11615 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 11616 | |
548ee15b | 11617 | return 0; |
7758a113 | 11618 | fail: |
548ee15b | 11619 | return ret; |
ee7b9f93 | 11620 | } |
47f1c6c9 | 11621 | |
ea9d758d | 11622 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
f6e5b160 | 11623 | { |
ea9d758d | 11624 | struct drm_encoder *encoder; |
f6e5b160 | 11625 | struct drm_device *dev = crtc->dev; |
f6e5b160 | 11626 | |
ea9d758d DV |
11627 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
11628 | if (encoder->crtc == crtc) | |
11629 | return true; | |
11630 | ||
11631 | return false; | |
11632 | } | |
11633 | ||
0a9ab303 ACO |
11634 | static bool |
11635 | needs_modeset(struct drm_crtc_state *state) | |
11636 | { | |
11637 | return state->mode_changed || state->active_changed; | |
11638 | } | |
11639 | ||
ea9d758d | 11640 | static void |
0a9ab303 | 11641 | intel_modeset_update_state(struct drm_atomic_state *state) |
ea9d758d | 11642 | { |
0a9ab303 | 11643 | struct drm_device *dev = state->dev; |
ba41c0de | 11644 | struct drm_i915_private *dev_priv = dev->dev_private; |
ea9d758d | 11645 | struct intel_encoder *intel_encoder; |
0a9ab303 ACO |
11646 | struct drm_crtc *crtc; |
11647 | struct drm_crtc_state *crtc_state; | |
ea9d758d | 11648 | struct drm_connector *connector; |
0a9ab303 | 11649 | int i; |
ea9d758d | 11650 | |
ba41c0de DV |
11651 | intel_shared_dpll_commit(dev_priv); |
11652 | ||
b2784e15 | 11653 | for_each_intel_encoder(dev, intel_encoder) { |
ea9d758d DV |
11654 | if (!intel_encoder->base.crtc) |
11655 | continue; | |
11656 | ||
0a9ab303 ACO |
11657 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
11658 | if (crtc == intel_encoder->base.crtc) | |
11659 | break; | |
11660 | ||
11661 | if (crtc != intel_encoder->base.crtc) | |
11662 | continue; | |
ea9d758d | 11663 | |
0a9ab303 | 11664 | if (crtc_state->enable && needs_modeset(crtc_state)) |
ea9d758d DV |
11665 | intel_encoder->connectors_active = false; |
11666 | } | |
11667 | ||
a821fc46 ACO |
11668 | drm_atomic_helper_swap_state(state->dev, state); |
11669 | intel_modeset_fixup_state(state); | |
ea9d758d | 11670 | |
7668851f | 11671 | /* Double check state. */ |
0a9ab303 ACO |
11672 | for_each_crtc(dev, crtc) { |
11673 | WARN_ON(crtc->state->enable != intel_crtc_in_use(crtc)); | |
ea9d758d DV |
11674 | } |
11675 | ||
11676 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
11677 | if (!connector->encoder || !connector->encoder->crtc) | |
11678 | continue; | |
11679 | ||
0a9ab303 ACO |
11680 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
11681 | if (crtc == connector->encoder->crtc) | |
11682 | break; | |
11683 | ||
11684 | if (crtc != connector->encoder->crtc) | |
11685 | continue; | |
ea9d758d | 11686 | |
a821fc46 | 11687 | if (crtc->state->enable && needs_modeset(crtc->state)) { |
68d34720 DV |
11688 | struct drm_property *dpms_property = |
11689 | dev->mode_config.dpms_property; | |
11690 | ||
ea9d758d | 11691 | connector->dpms = DRM_MODE_DPMS_ON; |
662595df | 11692 | drm_object_property_set_value(&connector->base, |
68d34720 DV |
11693 | dpms_property, |
11694 | DRM_MODE_DPMS_ON); | |
ea9d758d DV |
11695 | |
11696 | intel_encoder = to_intel_encoder(connector->encoder); | |
11697 | intel_encoder->connectors_active = true; | |
11698 | } | |
11699 | } | |
11700 | ||
11701 | } | |
11702 | ||
3bd26263 | 11703 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 11704 | { |
3bd26263 | 11705 | int diff; |
f1f644dc JB |
11706 | |
11707 | if (clock1 == clock2) | |
11708 | return true; | |
11709 | ||
11710 | if (!clock1 || !clock2) | |
11711 | return false; | |
11712 | ||
11713 | diff = abs(clock1 - clock2); | |
11714 | ||
11715 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
11716 | return true; | |
11717 | ||
11718 | return false; | |
11719 | } | |
11720 | ||
25c5b266 DV |
11721 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
11722 | list_for_each_entry((intel_crtc), \ | |
11723 | &(dev)->mode_config.crtc_list, \ | |
11724 | base.head) \ | |
0973f18f | 11725 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 11726 | |
0e8ffe1b | 11727 | static bool |
2fa2fe9a | 11728 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b ACO |
11729 | struct intel_crtc_state *current_config, |
11730 | struct intel_crtc_state *pipe_config) | |
0e8ffe1b | 11731 | { |
66e985c0 DV |
11732 | #define PIPE_CONF_CHECK_X(name) \ |
11733 | if (current_config->name != pipe_config->name) { \ | |
11734 | DRM_ERROR("mismatch in " #name " " \ | |
11735 | "(expected 0x%08x, found 0x%08x)\n", \ | |
11736 | current_config->name, \ | |
11737 | pipe_config->name); \ | |
11738 | return false; \ | |
11739 | } | |
11740 | ||
08a24034 DV |
11741 | #define PIPE_CONF_CHECK_I(name) \ |
11742 | if (current_config->name != pipe_config->name) { \ | |
11743 | DRM_ERROR("mismatch in " #name " " \ | |
11744 | "(expected %i, found %i)\n", \ | |
11745 | current_config->name, \ | |
11746 | pipe_config->name); \ | |
11747 | return false; \ | |
88adfff1 DV |
11748 | } |
11749 | ||
b95af8be VK |
11750 | /* This is required for BDW+ where there is only one set of registers for |
11751 | * switching between high and low RR. | |
11752 | * This macro can be used whenever a comparison has to be made between one | |
11753 | * hw state and multiple sw state variables. | |
11754 | */ | |
11755 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
11756 | if ((current_config->name != pipe_config->name) && \ | |
11757 | (current_config->alt_name != pipe_config->name)) { \ | |
11758 | DRM_ERROR("mismatch in " #name " " \ | |
11759 | "(expected %i or %i, found %i)\n", \ | |
11760 | current_config->name, \ | |
11761 | current_config->alt_name, \ | |
11762 | pipe_config->name); \ | |
11763 | return false; \ | |
11764 | } | |
11765 | ||
1bd1bd80 DV |
11766 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
11767 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
6f02488e | 11768 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
11769 | "(expected %i, found %i)\n", \ |
11770 | current_config->name & (mask), \ | |
11771 | pipe_config->name & (mask)); \ | |
11772 | return false; \ | |
11773 | } | |
11774 | ||
5e550656 VS |
11775 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
11776 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
11777 | DRM_ERROR("mismatch in " #name " " \ | |
11778 | "(expected %i, found %i)\n", \ | |
11779 | current_config->name, \ | |
11780 | pipe_config->name); \ | |
11781 | return false; \ | |
11782 | } | |
11783 | ||
bb760063 DV |
11784 | #define PIPE_CONF_QUIRK(quirk) \ |
11785 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
11786 | ||
eccb140b DV |
11787 | PIPE_CONF_CHECK_I(cpu_transcoder); |
11788 | ||
08a24034 DV |
11789 | PIPE_CONF_CHECK_I(has_pch_encoder); |
11790 | PIPE_CONF_CHECK_I(fdi_lanes); | |
72419203 DV |
11791 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
11792 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); | |
11793 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); | |
11794 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); | |
11795 | PIPE_CONF_CHECK_I(fdi_m_n.tu); | |
08a24034 | 11796 | |
eb14cb74 | 11797 | PIPE_CONF_CHECK_I(has_dp_encoder); |
b95af8be VK |
11798 | |
11799 | if (INTEL_INFO(dev)->gen < 8) { | |
11800 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); | |
11801 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); | |
11802 | PIPE_CONF_CHECK_I(dp_m_n.link_m); | |
11803 | PIPE_CONF_CHECK_I(dp_m_n.link_n); | |
11804 | PIPE_CONF_CHECK_I(dp_m_n.tu); | |
11805 | ||
11806 | if (current_config->has_drrs) { | |
11807 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); | |
11808 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); | |
11809 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); | |
11810 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); | |
11811 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); | |
11812 | } | |
11813 | } else { | |
11814 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); | |
11815 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); | |
11816 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); | |
11817 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); | |
11818 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); | |
11819 | } | |
eb14cb74 | 11820 | |
2d112de7 ACO |
11821 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
11822 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
11823 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
11824 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
11825 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
11826 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 11827 | |
2d112de7 ACO |
11828 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
11829 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
11830 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
11831 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
11832 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
11833 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 11834 | |
c93f54cf | 11835 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 11836 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
11837 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
11838 | IS_VALLEYVIEW(dev)) | |
11839 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 11840 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 11841 | |
9ed109a7 DV |
11842 | PIPE_CONF_CHECK_I(has_audio); |
11843 | ||
2d112de7 | 11844 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
11845 | DRM_MODE_FLAG_INTERLACE); |
11846 | ||
bb760063 | 11847 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 11848 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 11849 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 11850 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 11851 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 11852 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 11853 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 11854 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
11855 | DRM_MODE_FLAG_NVSYNC); |
11856 | } | |
045ac3b5 | 11857 | |
37327abd VS |
11858 | PIPE_CONF_CHECK_I(pipe_src_w); |
11859 | PIPE_CONF_CHECK_I(pipe_src_h); | |
1bd1bd80 | 11860 | |
9953599b DV |
11861 | /* |
11862 | * FIXME: BIOS likes to set up a cloned config with lvds+external | |
11863 | * screen. Since we don't yet re-compute the pipe config when moving | |
11864 | * just the lvds port away to another pipe the sw tracking won't match. | |
11865 | * | |
11866 | * Proper atomic modesets with recomputed global state will fix this. | |
11867 | * Until then just don't check gmch state for inherited modes. | |
11868 | */ | |
11869 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { | |
11870 | PIPE_CONF_CHECK_I(gmch_pfit.control); | |
11871 | /* pfit ratios are autocomputed by the hw on gen4+ */ | |
11872 | if (INTEL_INFO(dev)->gen < 4) | |
11873 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
11874 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); | |
11875 | } | |
11876 | ||
fd4daa9c CW |
11877 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
11878 | if (current_config->pch_pfit.enabled) { | |
11879 | PIPE_CONF_CHECK_I(pch_pfit.pos); | |
11880 | PIPE_CONF_CHECK_I(pch_pfit.size); | |
11881 | } | |
2fa2fe9a | 11882 | |
a1b2278e CK |
11883 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
11884 | ||
e59150dc JB |
11885 | /* BDW+ don't expose a synchronous way to read the state */ |
11886 | if (IS_HASWELL(dev)) | |
11887 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 11888 | |
282740f7 VS |
11889 | PIPE_CONF_CHECK_I(double_wide); |
11890 | ||
26804afd DV |
11891 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
11892 | ||
c0d43d62 | 11893 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 11894 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 11895 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
11896 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
11897 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 11898 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
11899 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
11900 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
11901 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 11902 | |
42571aef VS |
11903 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
11904 | PIPE_CONF_CHECK_I(pipe_bpp); | |
11905 | ||
2d112de7 | 11906 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 11907 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 11908 | |
66e985c0 | 11909 | #undef PIPE_CONF_CHECK_X |
08a24034 | 11910 | #undef PIPE_CONF_CHECK_I |
b95af8be | 11911 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 11912 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 11913 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 11914 | #undef PIPE_CONF_QUIRK |
88adfff1 | 11915 | |
0e8ffe1b DV |
11916 | return true; |
11917 | } | |
11918 | ||
08db6652 DL |
11919 | static void check_wm_state(struct drm_device *dev) |
11920 | { | |
11921 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11922 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
11923 | struct intel_crtc *intel_crtc; | |
11924 | int plane; | |
11925 | ||
11926 | if (INTEL_INFO(dev)->gen < 9) | |
11927 | return; | |
11928 | ||
11929 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
11930 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
11931 | ||
11932 | for_each_intel_crtc(dev, intel_crtc) { | |
11933 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
11934 | const enum pipe pipe = intel_crtc->pipe; | |
11935 | ||
11936 | if (!intel_crtc->active) | |
11937 | continue; | |
11938 | ||
11939 | /* planes */ | |
dd740780 | 11940 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
11941 | hw_entry = &hw_ddb.plane[pipe][plane]; |
11942 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
11943 | ||
11944 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
11945 | continue; | |
11946 | ||
11947 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
11948 | "(expected (%u,%u), found (%u,%u))\n", | |
11949 | pipe_name(pipe), plane + 1, | |
11950 | sw_entry->start, sw_entry->end, | |
11951 | hw_entry->start, hw_entry->end); | |
11952 | } | |
11953 | ||
11954 | /* cursor */ | |
11955 | hw_entry = &hw_ddb.cursor[pipe]; | |
11956 | sw_entry = &sw_ddb->cursor[pipe]; | |
11957 | ||
11958 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
11959 | continue; | |
11960 | ||
11961 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
11962 | "(expected (%u,%u), found (%u,%u))\n", | |
11963 | pipe_name(pipe), | |
11964 | sw_entry->start, sw_entry->end, | |
11965 | hw_entry->start, hw_entry->end); | |
11966 | } | |
11967 | } | |
11968 | ||
91d1b4bd DV |
11969 | static void |
11970 | check_connector_state(struct drm_device *dev) | |
8af6cf88 | 11971 | { |
8af6cf88 DV |
11972 | struct intel_connector *connector; |
11973 | ||
3a3371ff | 11974 | for_each_intel_connector(dev, connector) { |
8af6cf88 DV |
11975 | /* This also checks the encoder/connector hw state with the |
11976 | * ->get_hw_state callbacks. */ | |
11977 | intel_connector_check_state(connector); | |
11978 | ||
e2c719b7 | 11979 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
8af6cf88 DV |
11980 | "connector's staged encoder doesn't match current encoder\n"); |
11981 | } | |
91d1b4bd DV |
11982 | } |
11983 | ||
11984 | static void | |
11985 | check_encoder_state(struct drm_device *dev) | |
11986 | { | |
11987 | struct intel_encoder *encoder; | |
11988 | struct intel_connector *connector; | |
8af6cf88 | 11989 | |
b2784e15 | 11990 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 DV |
11991 | bool enabled = false; |
11992 | bool active = false; | |
11993 | enum pipe pipe, tracked_pipe; | |
11994 | ||
11995 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
11996 | encoder->base.base.id, | |
8e329a03 | 11997 | encoder->base.name); |
8af6cf88 | 11998 | |
e2c719b7 | 11999 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
8af6cf88 | 12000 | "encoder's stage crtc doesn't match current crtc\n"); |
e2c719b7 | 12001 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
8af6cf88 DV |
12002 | "encoder's active_connectors set, but no crtc\n"); |
12003 | ||
3a3371ff | 12004 | for_each_intel_connector(dev, connector) { |
8af6cf88 DV |
12005 | if (connector->base.encoder != &encoder->base) |
12006 | continue; | |
12007 | enabled = true; | |
12008 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) | |
12009 | active = true; | |
12010 | } | |
0e32b39c DA |
12011 | /* |
12012 | * for MST connectors if we unplug the connector is gone | |
12013 | * away but the encoder is still connected to a crtc | |
12014 | * until a modeset happens in response to the hotplug. | |
12015 | */ | |
12016 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) | |
12017 | continue; | |
12018 | ||
e2c719b7 | 12019 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12020 | "encoder's enabled state mismatch " |
12021 | "(expected %i, found %i)\n", | |
12022 | !!encoder->base.crtc, enabled); | |
e2c719b7 | 12023 | I915_STATE_WARN(active && !encoder->base.crtc, |
8af6cf88 DV |
12024 | "active encoder with no crtc\n"); |
12025 | ||
e2c719b7 | 12026 | I915_STATE_WARN(encoder->connectors_active != active, |
8af6cf88 DV |
12027 | "encoder's computed active state doesn't match tracked active state " |
12028 | "(expected %i, found %i)\n", active, encoder->connectors_active); | |
12029 | ||
12030 | active = encoder->get_hw_state(encoder, &pipe); | |
e2c719b7 | 12031 | I915_STATE_WARN(active != encoder->connectors_active, |
8af6cf88 DV |
12032 | "encoder's hw state doesn't match sw tracking " |
12033 | "(expected %i, found %i)\n", | |
12034 | encoder->connectors_active, active); | |
12035 | ||
12036 | if (!encoder->base.crtc) | |
12037 | continue; | |
12038 | ||
12039 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; | |
e2c719b7 | 12040 | I915_STATE_WARN(active && pipe != tracked_pipe, |
8af6cf88 DV |
12041 | "active encoder's pipe doesn't match" |
12042 | "(expected %i, found %i)\n", | |
12043 | tracked_pipe, pipe); | |
12044 | ||
12045 | } | |
91d1b4bd DV |
12046 | } |
12047 | ||
12048 | static void | |
12049 | check_crtc_state(struct drm_device *dev) | |
12050 | { | |
fbee40df | 12051 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12052 | struct intel_crtc *crtc; |
12053 | struct intel_encoder *encoder; | |
5cec258b | 12054 | struct intel_crtc_state pipe_config; |
8af6cf88 | 12055 | |
d3fcc808 | 12056 | for_each_intel_crtc(dev, crtc) { |
8af6cf88 DV |
12057 | bool enabled = false; |
12058 | bool active = false; | |
12059 | ||
045ac3b5 JB |
12060 | memset(&pipe_config, 0, sizeof(pipe_config)); |
12061 | ||
8af6cf88 DV |
12062 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12063 | crtc->base.base.id); | |
12064 | ||
83d65738 | 12065 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
8af6cf88 DV |
12066 | "active crtc, but not enabled in sw tracking\n"); |
12067 | ||
b2784e15 | 12068 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 DV |
12069 | if (encoder->base.crtc != &crtc->base) |
12070 | continue; | |
12071 | enabled = true; | |
12072 | if (encoder->connectors_active) | |
12073 | active = true; | |
12074 | } | |
6c49f241 | 12075 | |
e2c719b7 | 12076 | I915_STATE_WARN(active != crtc->active, |
8af6cf88 DV |
12077 | "crtc's computed active state doesn't match tracked active state " |
12078 | "(expected %i, found %i)\n", active, crtc->active); | |
83d65738 | 12079 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
8af6cf88 | 12080 | "crtc's computed enabled state doesn't match tracked enabled state " |
83d65738 MR |
12081 | "(expected %i, found %i)\n", enabled, |
12082 | crtc->base.state->enable); | |
8af6cf88 | 12083 | |
0e8ffe1b DV |
12084 | active = dev_priv->display.get_pipe_config(crtc, |
12085 | &pipe_config); | |
d62cf62a | 12086 | |
b6b5d049 VS |
12087 | /* hw state is inconsistent with the pipe quirk */ |
12088 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
12089 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
d62cf62a DV |
12090 | active = crtc->active; |
12091 | ||
b2784e15 | 12092 | for_each_intel_encoder(dev, encoder) { |
3eaba51c | 12093 | enum pipe pipe; |
6c49f241 DV |
12094 | if (encoder->base.crtc != &crtc->base) |
12095 | continue; | |
1d37b689 | 12096 | if (encoder->get_hw_state(encoder, &pipe)) |
6c49f241 DV |
12097 | encoder->get_config(encoder, &pipe_config); |
12098 | } | |
12099 | ||
e2c719b7 | 12100 | I915_STATE_WARN(crtc->active != active, |
0e8ffe1b DV |
12101 | "crtc active state doesn't match with hw state " |
12102 | "(expected %i, found %i)\n", crtc->active, active); | |
12103 | ||
c0b03411 | 12104 | if (active && |
6e3c9717 | 12105 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
e2c719b7 | 12106 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
c0b03411 DV |
12107 | intel_dump_pipe_config(crtc, &pipe_config, |
12108 | "[hw state]"); | |
6e3c9717 | 12109 | intel_dump_pipe_config(crtc, crtc->config, |
c0b03411 DV |
12110 | "[sw state]"); |
12111 | } | |
8af6cf88 DV |
12112 | } |
12113 | } | |
12114 | ||
91d1b4bd DV |
12115 | static void |
12116 | check_shared_dpll_state(struct drm_device *dev) | |
12117 | { | |
fbee40df | 12118 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12119 | struct intel_crtc *crtc; |
12120 | struct intel_dpll_hw_state dpll_hw_state; | |
12121 | int i; | |
5358901f DV |
12122 | |
12123 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12124 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12125 | int enabled_crtcs = 0, active_crtcs = 0; | |
12126 | bool active; | |
12127 | ||
12128 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12129 | ||
12130 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12131 | ||
12132 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12133 | ||
e2c719b7 | 12134 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12135 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12136 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12137 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12138 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12139 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12140 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12141 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12142 | "pll on state mismatch (expected %i, found %i)\n", |
12143 | pll->on, active); | |
12144 | ||
d3fcc808 | 12145 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12146 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12147 | enabled_crtcs++; |
12148 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12149 | active_crtcs++; | |
12150 | } | |
e2c719b7 | 12151 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12152 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12153 | pll->active, active_crtcs); | |
e2c719b7 | 12154 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12155 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12156 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12157 | |
e2c719b7 | 12158 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12159 | sizeof(dpll_hw_state)), |
12160 | "pll hw state mismatch\n"); | |
5358901f | 12161 | } |
8af6cf88 DV |
12162 | } |
12163 | ||
91d1b4bd DV |
12164 | void |
12165 | intel_modeset_check_state(struct drm_device *dev) | |
12166 | { | |
08db6652 | 12167 | check_wm_state(dev); |
91d1b4bd DV |
12168 | check_connector_state(dev); |
12169 | check_encoder_state(dev); | |
12170 | check_crtc_state(dev); | |
12171 | check_shared_dpll_state(dev); | |
12172 | } | |
12173 | ||
5cec258b | 12174 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12175 | int dotclock) |
12176 | { | |
12177 | /* | |
12178 | * FDI already provided one idea for the dotclock. | |
12179 | * Yell if the encoder disagrees. | |
12180 | */ | |
2d112de7 | 12181 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12182 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12183 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12184 | } |
12185 | ||
80715b2f VS |
12186 | static void update_scanline_offset(struct intel_crtc *crtc) |
12187 | { | |
12188 | struct drm_device *dev = crtc->base.dev; | |
12189 | ||
12190 | /* | |
12191 | * The scanline counter increments at the leading edge of hsync. | |
12192 | * | |
12193 | * On most platforms it starts counting from vtotal-1 on the | |
12194 | * first active line. That means the scanline counter value is | |
12195 | * always one less than what we would expect. Ie. just after | |
12196 | * start of vblank, which also occurs at start of hsync (on the | |
12197 | * last active line), the scanline counter will read vblank_start-1. | |
12198 | * | |
12199 | * On gen2 the scanline counter starts counting from 1 instead | |
12200 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12201 | * to keep the value positive), instead of adding one. | |
12202 | * | |
12203 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12204 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12205 | * there's an extra 1 line difference. So we need to add two instead of | |
12206 | * one to the value. | |
12207 | */ | |
12208 | if (IS_GEN2(dev)) { | |
6e3c9717 | 12209 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12210 | int vtotal; |
12211 | ||
12212 | vtotal = mode->crtc_vtotal; | |
12213 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
12214 | vtotal /= 2; | |
12215 | ||
12216 | crtc->scanline_offset = vtotal - 1; | |
12217 | } else if (HAS_DDI(dev) && | |
409ee761 | 12218 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12219 | crtc->scanline_offset = 2; |
12220 | } else | |
12221 | crtc->scanline_offset = 1; | |
12222 | } | |
12223 | ||
5cec258b | 12224 | static struct intel_crtc_state * |
7f27126e | 12225 | intel_modeset_compute_config(struct drm_crtc *crtc, |
0a9ab303 | 12226 | struct drm_atomic_state *state) |
7f27126e | 12227 | { |
548ee15b | 12228 | struct intel_crtc_state *pipe_config; |
0b901879 ACO |
12229 | int ret = 0; |
12230 | ||
12231 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
12232 | if (ret) | |
12233 | return ERR_PTR(ret); | |
7f27126e | 12234 | |
8c7b5ccb ACO |
12235 | ret = drm_atomic_helper_check_modeset(state->dev, state); |
12236 | if (ret) | |
12237 | return ERR_PTR(ret); | |
7f27126e | 12238 | |
7f27126e JB |
12239 | /* |
12240 | * Note this needs changes when we start tracking multiple modes | |
12241 | * and crtcs. At that point we'll need to compute the whole config | |
12242 | * (i.e. one pipe_config for each crtc) rather than just the one | |
12243 | * for this crtc. | |
12244 | */ | |
548ee15b ACO |
12245 | pipe_config = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc)); |
12246 | if (IS_ERR(pipe_config)) | |
12247 | return pipe_config; | |
83a57153 | 12248 | |
4fed33f6 | 12249 | if (!pipe_config->base.enable) |
548ee15b | 12250 | return pipe_config; |
7f27126e | 12251 | |
8c7b5ccb | 12252 | ret = intel_modeset_pipe_config(crtc, state, pipe_config); |
548ee15b ACO |
12253 | if (ret) |
12254 | return ERR_PTR(ret); | |
12255 | ||
8d8c9b51 ACO |
12256 | /* Check things that can only be changed through modeset */ |
12257 | if (pipe_config->has_audio != | |
12258 | to_intel_crtc(crtc)->config->has_audio) | |
12259 | pipe_config->base.mode_changed = true; | |
12260 | ||
12261 | /* | |
12262 | * Note we have an issue here with infoframes: current code | |
12263 | * only updates them on the full mode set path per hw | |
12264 | * requirements. So here we should be checking for any | |
12265 | * required changes and forcing a mode set. | |
12266 | */ | |
12267 | ||
548ee15b | 12268 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,"[modeset]"); |
db7542dd | 12269 | |
8c7b5ccb ACO |
12270 | ret = drm_atomic_helper_check_planes(state->dev, state); |
12271 | if (ret) | |
12272 | return ERR_PTR(ret); | |
12273 | ||
548ee15b | 12274 | return pipe_config; |
7f27126e JB |
12275 | } |
12276 | ||
0a9ab303 | 12277 | static int __intel_set_mode_setup_plls(struct drm_atomic_state *state) |
ed6739ef | 12278 | { |
225da59b | 12279 | struct drm_device *dev = state->dev; |
ed6739ef | 12280 | struct drm_i915_private *dev_priv = to_i915(dev); |
0a9ab303 | 12281 | unsigned clear_pipes = 0; |
ed6739ef | 12282 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12283 | struct intel_crtc_state *intel_crtc_state; |
12284 | struct drm_crtc *crtc; | |
12285 | struct drm_crtc_state *crtc_state; | |
ed6739ef | 12286 | int ret = 0; |
0a9ab303 | 12287 | int i; |
ed6739ef ACO |
12288 | |
12289 | if (!dev_priv->display.crtc_compute_clock) | |
12290 | return 0; | |
12291 | ||
0a9ab303 ACO |
12292 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
12293 | intel_crtc = to_intel_crtc(crtc); | |
4978cc93 | 12294 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
0a9ab303 | 12295 | |
4978cc93 | 12296 | if (needs_modeset(crtc_state)) { |
0a9ab303 | 12297 | clear_pipes |= 1 << intel_crtc->pipe; |
4978cc93 | 12298 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
4978cc93 | 12299 | } |
0a9ab303 ACO |
12300 | } |
12301 | ||
ed6739ef ACO |
12302 | ret = intel_shared_dpll_start_config(dev_priv, clear_pipes); |
12303 | if (ret) | |
12304 | goto done; | |
12305 | ||
0a9ab303 ACO |
12306 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
12307 | if (!needs_modeset(crtc_state) || !crtc_state->enable) | |
225da59b ACO |
12308 | continue; |
12309 | ||
0a9ab303 ACO |
12310 | intel_crtc = to_intel_crtc(crtc); |
12311 | intel_crtc_state = to_intel_crtc_state(crtc_state); | |
12312 | ||
ed6739ef | 12313 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
0a9ab303 | 12314 | intel_crtc_state); |
ed6739ef ACO |
12315 | if (ret) { |
12316 | intel_shared_dpll_abort_config(dev_priv); | |
12317 | goto done; | |
12318 | } | |
12319 | } | |
12320 | ||
12321 | done: | |
12322 | return ret; | |
12323 | } | |
12324 | ||
054518dd ACO |
12325 | /* Code that should eventually be part of atomic_check() */ |
12326 | static int __intel_set_mode_checks(struct drm_atomic_state *state) | |
12327 | { | |
12328 | struct drm_device *dev = state->dev; | |
12329 | int ret; | |
12330 | ||
12331 | /* | |
12332 | * See if the config requires any additional preparation, e.g. | |
12333 | * to adjust global state with pipes off. We need to do this | |
12334 | * here so we can get the modeset_pipe updated config for the new | |
12335 | * mode set on this crtc. For other crtcs we need to use the | |
12336 | * adjusted_mode bits in the crtc directly. | |
12337 | */ | |
12338 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { | |
12339 | ret = valleyview_modeset_global_pipes(state); | |
12340 | if (ret) | |
12341 | return ret; | |
12342 | } | |
12343 | ||
12344 | ret = __intel_set_mode_setup_plls(state); | |
12345 | if (ret) | |
12346 | return ret; | |
12347 | ||
12348 | return 0; | |
12349 | } | |
12350 | ||
0a9ab303 | 12351 | static int __intel_set_mode(struct drm_crtc *modeset_crtc, |
0a9ab303 | 12352 | struct intel_crtc_state *pipe_config) |
a6778b3c | 12353 | { |
0a9ab303 | 12354 | struct drm_device *dev = modeset_crtc->dev; |
fbee40df | 12355 | struct drm_i915_private *dev_priv = dev->dev_private; |
304603f4 | 12356 | struct drm_atomic_state *state = pipe_config->base.state; |
0a9ab303 ACO |
12357 | struct drm_crtc *crtc; |
12358 | struct drm_crtc_state *crtc_state; | |
c0c36b94 | 12359 | int ret = 0; |
0a9ab303 | 12360 | int i; |
a6778b3c | 12361 | |
054518dd ACO |
12362 | ret = __intel_set_mode_checks(state); |
12363 | if (ret < 0) | |
12364 | return ret; | |
12365 | ||
d4afb8cc ACO |
12366 | ret = drm_atomic_helper_prepare_planes(dev, state); |
12367 | if (ret) | |
12368 | return ret; | |
12369 | ||
0a9ab303 ACO |
12370 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
12371 | if (!needs_modeset(crtc_state)) | |
12372 | continue; | |
460da916 | 12373 | |
0a9ab303 ACO |
12374 | if (!crtc_state->enable) { |
12375 | intel_crtc_disable(crtc); | |
12376 | } else if (crtc->state->enable) { | |
12377 | intel_crtc_disable_planes(crtc); | |
12378 | dev_priv->display.crtc_disable(crtc); | |
ce22dba9 | 12379 | } |
ea9d758d | 12380 | } |
a6778b3c | 12381 | |
6c4c86f5 DV |
12382 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
12383 | * to set it here already despite that we pass it down the callchain. | |
7f27126e JB |
12384 | * |
12385 | * Note we'll need to fix this up when we start tracking multiple | |
12386 | * pipes; here we assume a single modeset_pipe and only track the | |
12387 | * single crtc and mode. | |
f6e5b160 | 12388 | */ |
0a9ab303 | 12389 | if (pipe_config->base.enable && needs_modeset(&pipe_config->base)) { |
8c7b5ccb | 12390 | modeset_crtc->mode = pipe_config->base.mode; |
c326c0a9 VS |
12391 | |
12392 | /* | |
12393 | * Calculate and store various constants which | |
12394 | * are later needed by vblank and swap-completion | |
12395 | * timestamping. They are derived from true hwmode. | |
12396 | */ | |
0a9ab303 | 12397 | drm_calc_timestamping_constants(modeset_crtc, |
2d112de7 | 12398 | &pipe_config->base.adjusted_mode); |
b8cecdf5 | 12399 | } |
7758a113 | 12400 | |
ea9d758d DV |
12401 | /* Only after disabling all output pipelines that will be changed can we |
12402 | * update the the output configuration. */ | |
0a9ab303 | 12403 | intel_modeset_update_state(state); |
f6e5b160 | 12404 | |
a821fc46 ACO |
12405 | /* The state has been swaped above, so state actually contains the |
12406 | * old state now. */ | |
12407 | ||
304603f4 | 12408 | modeset_update_crtc_power_domains(state); |
47fab737 | 12409 | |
d4afb8cc | 12410 | drm_atomic_helper_commit_planes(dev, state); |
a6778b3c DV |
12411 | |
12412 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ | |
0a9ab303 | 12413 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a821fc46 | 12414 | if (!needs_modeset(crtc->state) || !crtc->state->enable) |
0a9ab303 ACO |
12415 | continue; |
12416 | ||
12417 | update_scanline_offset(to_intel_crtc(crtc)); | |
80715b2f | 12418 | |
0a9ab303 ACO |
12419 | dev_priv->display.crtc_enable(crtc); |
12420 | intel_crtc_enable_planes(crtc); | |
80715b2f | 12421 | } |
a6778b3c | 12422 | |
a6778b3c | 12423 | /* FIXME: add subpixel order */ |
83a57153 | 12424 | |
d4afb8cc ACO |
12425 | drm_atomic_helper_cleanup_planes(dev, state); |
12426 | ||
2bfb4627 ACO |
12427 | drm_atomic_state_free(state); |
12428 | ||
9eb45f22 | 12429 | return 0; |
f6e5b160 CW |
12430 | } |
12431 | ||
0a9ab303 | 12432 | static int intel_set_mode_with_config(struct drm_crtc *crtc, |
0a9ab303 | 12433 | struct intel_crtc_state *pipe_config) |
f30da187 DV |
12434 | { |
12435 | int ret; | |
12436 | ||
8c7b5ccb | 12437 | ret = __intel_set_mode(crtc, pipe_config); |
f30da187 DV |
12438 | |
12439 | if (ret == 0) | |
12440 | intel_modeset_check_state(crtc->dev); | |
12441 | ||
12442 | return ret; | |
12443 | } | |
12444 | ||
7f27126e | 12445 | static int intel_set_mode(struct drm_crtc *crtc, |
83a57153 | 12446 | struct drm_atomic_state *state) |
7f27126e | 12447 | { |
5cec258b | 12448 | struct intel_crtc_state *pipe_config; |
83a57153 | 12449 | int ret = 0; |
7f27126e | 12450 | |
8c7b5ccb | 12451 | pipe_config = intel_modeset_compute_config(crtc, state); |
83a57153 ACO |
12452 | if (IS_ERR(pipe_config)) { |
12453 | ret = PTR_ERR(pipe_config); | |
12454 | goto out; | |
12455 | } | |
12456 | ||
8c7b5ccb | 12457 | ret = intel_set_mode_with_config(crtc, pipe_config); |
83a57153 ACO |
12458 | if (ret) |
12459 | goto out; | |
7f27126e | 12460 | |
83a57153 ACO |
12461 | out: |
12462 | return ret; | |
7f27126e JB |
12463 | } |
12464 | ||
c0c36b94 CW |
12465 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
12466 | { | |
83a57153 ACO |
12467 | struct drm_device *dev = crtc->dev; |
12468 | struct drm_atomic_state *state; | |
4be07317 | 12469 | struct intel_crtc *intel_crtc; |
83a57153 ACO |
12470 | struct intel_encoder *encoder; |
12471 | struct intel_connector *connector; | |
12472 | struct drm_connector_state *connector_state; | |
4be07317 | 12473 | struct intel_crtc_state *crtc_state; |
2bfb4627 | 12474 | int ret; |
83a57153 ACO |
12475 | |
12476 | state = drm_atomic_state_alloc(dev); | |
12477 | if (!state) { | |
12478 | DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory", | |
12479 | crtc->base.id); | |
12480 | return; | |
12481 | } | |
12482 | ||
12483 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
12484 | ||
12485 | /* The force restore path in the HW readout code relies on the staged | |
12486 | * config still keeping the user requested config while the actual | |
12487 | * state has been overwritten by the configuration read from HW. We | |
12488 | * need to copy the staged config to the atomic state, otherwise the | |
12489 | * mode set will just reapply the state the HW is already in. */ | |
12490 | for_each_intel_encoder(dev, encoder) { | |
12491 | if (&encoder->new_crtc->base != crtc) | |
12492 | continue; | |
12493 | ||
12494 | for_each_intel_connector(dev, connector) { | |
12495 | if (connector->new_encoder != encoder) | |
12496 | continue; | |
12497 | ||
12498 | connector_state = drm_atomic_get_connector_state(state, &connector->base); | |
12499 | if (IS_ERR(connector_state)) { | |
12500 | DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n", | |
12501 | connector->base.base.id, | |
12502 | connector->base.name, | |
12503 | PTR_ERR(connector_state)); | |
12504 | continue; | |
12505 | } | |
12506 | ||
12507 | connector_state->crtc = crtc; | |
12508 | connector_state->best_encoder = &encoder->base; | |
12509 | } | |
12510 | } | |
12511 | ||
4be07317 ACO |
12512 | for_each_intel_crtc(dev, intel_crtc) { |
12513 | if (intel_crtc->new_enabled == intel_crtc->base.enabled) | |
12514 | continue; | |
12515 | ||
12516 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
12517 | if (IS_ERR(crtc_state)) { | |
12518 | DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n", | |
12519 | intel_crtc->base.base.id, | |
12520 | PTR_ERR(crtc_state)); | |
12521 | continue; | |
12522 | } | |
12523 | ||
49d6fa21 ML |
12524 | crtc_state->base.active = crtc_state->base.enable = |
12525 | intel_crtc->new_enabled; | |
8c7b5ccb ACO |
12526 | |
12527 | if (&intel_crtc->base == crtc) | |
12528 | drm_mode_copy(&crtc_state->base.mode, &crtc->mode); | |
4be07317 ACO |
12529 | } |
12530 | ||
d3a40d1b ACO |
12531 | intel_modeset_setup_plane_state(state, crtc, &crtc->mode, |
12532 | crtc->primary->fb, crtc->x, crtc->y); | |
12533 | ||
2bfb4627 ACO |
12534 | ret = intel_set_mode(crtc, state); |
12535 | if (ret) | |
12536 | drm_atomic_state_free(state); | |
c0c36b94 CW |
12537 | } |
12538 | ||
25c5b266 DV |
12539 | #undef for_each_intel_crtc_masked |
12540 | ||
b7885264 ACO |
12541 | static bool intel_connector_in_mode_set(struct intel_connector *connector, |
12542 | struct drm_mode_set *set) | |
12543 | { | |
12544 | int ro; | |
12545 | ||
12546 | for (ro = 0; ro < set->num_connectors; ro++) | |
12547 | if (set->connectors[ro] == &connector->base) | |
12548 | return true; | |
12549 | ||
12550 | return false; | |
12551 | } | |
12552 | ||
2e431051 | 12553 | static int |
9a935856 DV |
12554 | intel_modeset_stage_output_state(struct drm_device *dev, |
12555 | struct drm_mode_set *set, | |
944b0c76 | 12556 | struct drm_atomic_state *state) |
50f56119 | 12557 | { |
9a935856 | 12558 | struct intel_connector *connector; |
d5432a9d | 12559 | struct drm_connector *drm_connector; |
944b0c76 | 12560 | struct drm_connector_state *connector_state; |
d5432a9d ACO |
12561 | struct drm_crtc *crtc; |
12562 | struct drm_crtc_state *crtc_state; | |
12563 | int i, ret; | |
50f56119 | 12564 | |
9abdda74 | 12565 | /* The upper layers ensure that we either disable a crtc or have a list |
9a935856 DV |
12566 | * of connectors. For paranoia, double-check this. */ |
12567 | WARN_ON(!set->fb && (set->num_connectors != 0)); | |
12568 | WARN_ON(set->fb && (set->num_connectors == 0)); | |
12569 | ||
3a3371ff | 12570 | for_each_intel_connector(dev, connector) { |
b7885264 ACO |
12571 | bool in_mode_set = intel_connector_in_mode_set(connector, set); |
12572 | ||
d5432a9d ACO |
12573 | if (!in_mode_set && connector->base.state->crtc != set->crtc) |
12574 | continue; | |
12575 | ||
12576 | connector_state = | |
12577 | drm_atomic_get_connector_state(state, &connector->base); | |
12578 | if (IS_ERR(connector_state)) | |
12579 | return PTR_ERR(connector_state); | |
12580 | ||
b7885264 ACO |
12581 | if (in_mode_set) { |
12582 | int pipe = to_intel_crtc(set->crtc)->pipe; | |
d5432a9d ACO |
12583 | connector_state->best_encoder = |
12584 | &intel_find_encoder(connector, pipe)->base; | |
50f56119 DV |
12585 | } |
12586 | ||
d5432a9d | 12587 | if (connector->base.state->crtc != set->crtc) |
b7885264 ACO |
12588 | continue; |
12589 | ||
9a935856 DV |
12590 | /* If we disable the crtc, disable all its connectors. Also, if |
12591 | * the connector is on the changing crtc but not on the new | |
12592 | * connector list, disable it. */ | |
b7885264 | 12593 | if (!set->fb || !in_mode_set) { |
d5432a9d | 12594 | connector_state->best_encoder = NULL; |
9a935856 DV |
12595 | |
12596 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", | |
12597 | connector->base.base.id, | |
c23cc417 | 12598 | connector->base.name); |
9a935856 | 12599 | } |
50f56119 | 12600 | } |
9a935856 | 12601 | /* connector->new_encoder is now updated for all connectors. */ |
50f56119 | 12602 | |
d5432a9d ACO |
12603 | for_each_connector_in_state(state, drm_connector, connector_state, i) { |
12604 | connector = to_intel_connector(drm_connector); | |
12605 | ||
12606 | if (!connector_state->best_encoder) { | |
12607 | ret = drm_atomic_set_crtc_for_connector(connector_state, | |
12608 | NULL); | |
12609 | if (ret) | |
12610 | return ret; | |
7668851f | 12611 | |
50f56119 | 12612 | continue; |
d5432a9d | 12613 | } |
50f56119 | 12614 | |
d5432a9d ACO |
12615 | if (intel_connector_in_mode_set(connector, set)) { |
12616 | struct drm_crtc *crtc = connector->base.state->crtc; | |
12617 | ||
12618 | /* If this connector was in a previous crtc, add it | |
12619 | * to the state. We might need to disable it. */ | |
12620 | if (crtc) { | |
12621 | crtc_state = | |
12622 | drm_atomic_get_crtc_state(state, crtc); | |
12623 | if (IS_ERR(crtc_state)) | |
12624 | return PTR_ERR(crtc_state); | |
12625 | } | |
12626 | ||
12627 | ret = drm_atomic_set_crtc_for_connector(connector_state, | |
12628 | set->crtc); | |
12629 | if (ret) | |
12630 | return ret; | |
12631 | } | |
50f56119 DV |
12632 | |
12633 | /* Make sure the new CRTC will work with the encoder */ | |
d5432a9d ACO |
12634 | if (!drm_encoder_crtc_ok(connector_state->best_encoder, |
12635 | connector_state->crtc)) { | |
5e2b584e | 12636 | return -EINVAL; |
50f56119 | 12637 | } |
944b0c76 | 12638 | |
9a935856 DV |
12639 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
12640 | connector->base.base.id, | |
c23cc417 | 12641 | connector->base.name, |
d5432a9d | 12642 | connector_state->crtc->base.id); |
944b0c76 | 12643 | |
d5432a9d ACO |
12644 | if (connector_state->best_encoder != &connector->encoder->base) |
12645 | connector->encoder = | |
12646 | to_intel_encoder(connector_state->best_encoder); | |
0e32b39c | 12647 | } |
7668851f | 12648 | |
d5432a9d | 12649 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
49d6fa21 ML |
12650 | bool has_connectors; |
12651 | ||
d5432a9d ACO |
12652 | ret = drm_atomic_add_affected_connectors(state, crtc); |
12653 | if (ret) | |
12654 | return ret; | |
4be07317 | 12655 | |
49d6fa21 ML |
12656 | has_connectors = !!drm_atomic_connectors_for_crtc(state, crtc); |
12657 | if (has_connectors != crtc_state->enable) | |
12658 | crtc_state->enable = | |
12659 | crtc_state->active = has_connectors; | |
7668851f VS |
12660 | } |
12661 | ||
8c7b5ccb ACO |
12662 | ret = intel_modeset_setup_plane_state(state, set->crtc, set->mode, |
12663 | set->fb, set->x, set->y); | |
12664 | if (ret) | |
12665 | return ret; | |
12666 | ||
12667 | crtc_state = drm_atomic_get_crtc_state(state, set->crtc); | |
12668 | if (IS_ERR(crtc_state)) | |
12669 | return PTR_ERR(crtc_state); | |
12670 | ||
12671 | if (set->mode) | |
12672 | drm_mode_copy(&crtc_state->mode, set->mode); | |
12673 | ||
12674 | if (set->num_connectors) | |
12675 | crtc_state->active = true; | |
12676 | ||
2e431051 DV |
12677 | return 0; |
12678 | } | |
12679 | ||
bb546623 ACO |
12680 | static bool primary_plane_visible(struct drm_crtc *crtc) |
12681 | { | |
12682 | struct intel_plane_state *plane_state = | |
12683 | to_intel_plane_state(crtc->primary->state); | |
12684 | ||
12685 | return plane_state->visible; | |
12686 | } | |
12687 | ||
2e431051 DV |
12688 | static int intel_crtc_set_config(struct drm_mode_set *set) |
12689 | { | |
12690 | struct drm_device *dev; | |
83a57153 | 12691 | struct drm_atomic_state *state = NULL; |
5cec258b | 12692 | struct intel_crtc_state *pipe_config; |
bb546623 | 12693 | bool primary_plane_was_visible; |
2e431051 | 12694 | int ret; |
2e431051 | 12695 | |
8d3e375e DV |
12696 | BUG_ON(!set); |
12697 | BUG_ON(!set->crtc); | |
12698 | BUG_ON(!set->crtc->helper_private); | |
2e431051 | 12699 | |
7e53f3a4 DV |
12700 | /* Enforce sane interface api - has been abused by the fb helper. */ |
12701 | BUG_ON(!set->mode && set->fb); | |
12702 | BUG_ON(set->fb && set->num_connectors == 0); | |
431e50f7 | 12703 | |
2e431051 DV |
12704 | if (set->fb) { |
12705 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", | |
12706 | set->crtc->base.id, set->fb->base.id, | |
12707 | (int)set->num_connectors, set->x, set->y); | |
12708 | } else { | |
12709 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); | |
2e431051 DV |
12710 | } |
12711 | ||
12712 | dev = set->crtc->dev; | |
12713 | ||
83a57153 | 12714 | state = drm_atomic_state_alloc(dev); |
7cbf41d6 ACO |
12715 | if (!state) |
12716 | return -ENOMEM; | |
83a57153 ACO |
12717 | |
12718 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
12719 | ||
462a425a | 12720 | ret = intel_modeset_stage_output_state(dev, set, state); |
2e431051 | 12721 | if (ret) |
7cbf41d6 | 12722 | goto out; |
2e431051 | 12723 | |
8c7b5ccb | 12724 | pipe_config = intel_modeset_compute_config(set->crtc, state); |
20664591 | 12725 | if (IS_ERR(pipe_config)) { |
6ac0483b | 12726 | ret = PTR_ERR(pipe_config); |
7cbf41d6 | 12727 | goto out; |
20664591 | 12728 | } |
50f52756 | 12729 | |
1f9954d0 JB |
12730 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
12731 | ||
bb546623 ACO |
12732 | primary_plane_was_visible = primary_plane_visible(set->crtc); |
12733 | ||
8c7b5ccb | 12734 | ret = intel_set_mode_with_config(set->crtc, pipe_config); |
bb546623 ACO |
12735 | |
12736 | if (ret == 0 && | |
12737 | pipe_config->base.enable && | |
12738 | pipe_config->base.planes_changed && | |
12739 | !needs_modeset(&pipe_config->base)) { | |
3b150f08 | 12740 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
3b150f08 MR |
12741 | |
12742 | /* | |
12743 | * We need to make sure the primary plane is re-enabled if it | |
12744 | * has previously been turned off. | |
12745 | */ | |
bb546623 ACO |
12746 | if (ret == 0 && !primary_plane_was_visible && |
12747 | primary_plane_visible(set->crtc)) { | |
3b150f08 | 12748 | WARN_ON(!intel_crtc->active); |
87d4300a | 12749 | intel_post_enable_primary(set->crtc); |
3b150f08 MR |
12750 | } |
12751 | ||
7ca51a3a JB |
12752 | /* |
12753 | * In the fastboot case this may be our only check of the | |
12754 | * state after boot. It would be better to only do it on | |
12755 | * the first update, but we don't have a nice way of doing that | |
12756 | * (and really, set_config isn't used much for high freq page | |
12757 | * flipping, so increasing its cost here shouldn't be a big | |
12758 | * deal). | |
12759 | */ | |
d330a953 | 12760 | if (i915.fastboot && ret == 0) |
7ca51a3a | 12761 | intel_modeset_check_state(set->crtc->dev); |
50f56119 DV |
12762 | } |
12763 | ||
2d05eae1 | 12764 | if (ret) { |
bf67dfeb DV |
12765 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
12766 | set->crtc->base.id, ret); | |
2d05eae1 | 12767 | } |
50f56119 | 12768 | |
7cbf41d6 | 12769 | out: |
2bfb4627 ACO |
12770 | if (ret) |
12771 | drm_atomic_state_free(state); | |
50f56119 DV |
12772 | return ret; |
12773 | } | |
f6e5b160 CW |
12774 | |
12775 | static const struct drm_crtc_funcs intel_crtc_funcs = { | |
f6e5b160 | 12776 | .gamma_set = intel_crtc_gamma_set, |
50f56119 | 12777 | .set_config = intel_crtc_set_config, |
f6e5b160 CW |
12778 | .destroy = intel_crtc_destroy, |
12779 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
12780 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
12781 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
12782 | }; |
12783 | ||
5358901f DV |
12784 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
12785 | struct intel_shared_dpll *pll, | |
12786 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 12787 | { |
5358901f | 12788 | uint32_t val; |
ee7b9f93 | 12789 | |
f458ebbc | 12790 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
12791 | return false; |
12792 | ||
5358901f | 12793 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
12794 | hw_state->dpll = val; |
12795 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
12796 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
12797 | |
12798 | return val & DPLL_VCO_ENABLE; | |
12799 | } | |
12800 | ||
15bdd4cf DV |
12801 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
12802 | struct intel_shared_dpll *pll) | |
12803 | { | |
3e369b76 ACO |
12804 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
12805 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
12806 | } |
12807 | ||
e7b903d2 DV |
12808 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
12809 | struct intel_shared_dpll *pll) | |
12810 | { | |
e7b903d2 | 12811 | /* PCH refclock must be enabled first */ |
89eff4be | 12812 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 12813 | |
3e369b76 | 12814 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
12815 | |
12816 | /* Wait for the clocks to stabilize. */ | |
12817 | POSTING_READ(PCH_DPLL(pll->id)); | |
12818 | udelay(150); | |
12819 | ||
12820 | /* The pixel multiplier can only be updated once the | |
12821 | * DPLL is enabled and the clocks are stable. | |
12822 | * | |
12823 | * So write it again. | |
12824 | */ | |
3e369b76 | 12825 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 12826 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
12827 | udelay(200); |
12828 | } | |
12829 | ||
12830 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
12831 | struct intel_shared_dpll *pll) | |
12832 | { | |
12833 | struct drm_device *dev = dev_priv->dev; | |
12834 | struct intel_crtc *crtc; | |
e7b903d2 DV |
12835 | |
12836 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 12837 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
12838 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
12839 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
12840 | } |
12841 | ||
15bdd4cf DV |
12842 | I915_WRITE(PCH_DPLL(pll->id), 0); |
12843 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
12844 | udelay(200); |
12845 | } | |
12846 | ||
46edb027 DV |
12847 | static char *ibx_pch_dpll_names[] = { |
12848 | "PCH DPLL A", | |
12849 | "PCH DPLL B", | |
12850 | }; | |
12851 | ||
7c74ade1 | 12852 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 12853 | { |
e7b903d2 | 12854 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
12855 | int i; |
12856 | ||
7c74ade1 | 12857 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 12858 | |
e72f9fbf | 12859 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
12860 | dev_priv->shared_dplls[i].id = i; |
12861 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 12862 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
12863 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
12864 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
12865 | dev_priv->shared_dplls[i].get_hw_state = |
12866 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
12867 | } |
12868 | } | |
12869 | ||
7c74ade1 DV |
12870 | static void intel_shared_dpll_init(struct drm_device *dev) |
12871 | { | |
e7b903d2 | 12872 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 12873 | |
9cd86933 DV |
12874 | if (HAS_DDI(dev)) |
12875 | intel_ddi_pll_init(dev); | |
12876 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
12877 | ibx_pch_dpll_init(dev); |
12878 | else | |
12879 | dev_priv->num_shared_dpll = 0; | |
12880 | ||
12881 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
12882 | } |
12883 | ||
1fc0a8f7 TU |
12884 | /** |
12885 | * intel_wm_need_update - Check whether watermarks need updating | |
12886 | * @plane: drm plane | |
12887 | * @state: new plane state | |
12888 | * | |
12889 | * Check current plane state versus the new one to determine whether | |
12890 | * watermarks need to be recalculated. | |
12891 | * | |
12892 | * Returns true or false. | |
12893 | */ | |
12894 | bool intel_wm_need_update(struct drm_plane *plane, | |
12895 | struct drm_plane_state *state) | |
12896 | { | |
12897 | /* Update watermarks on tiling changes. */ | |
12898 | if (!plane->state->fb || !state->fb || | |
12899 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
12900 | plane->state->rotation != state->rotation) | |
12901 | return true; | |
12902 | ||
12903 | return false; | |
12904 | } | |
12905 | ||
6beb8c23 MR |
12906 | /** |
12907 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
12908 | * @plane: drm plane to prepare for | |
12909 | * @fb: framebuffer to prepare for presentation | |
12910 | * | |
12911 | * Prepares a framebuffer for usage on a display plane. Generally this | |
12912 | * involves pinning the underlying object and updating the frontbuffer tracking | |
12913 | * bits. Some older platforms need special physical address handling for | |
12914 | * cursor planes. | |
12915 | * | |
12916 | * Returns 0 on success, negative error code on failure. | |
12917 | */ | |
12918 | int | |
12919 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
12920 | struct drm_framebuffer *fb, |
12921 | const struct drm_plane_state *new_state) | |
465c120c MR |
12922 | { |
12923 | struct drm_device *dev = plane->dev; | |
6beb8c23 MR |
12924 | struct intel_plane *intel_plane = to_intel_plane(plane); |
12925 | enum pipe pipe = intel_plane->pipe; | |
12926 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
12927 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); | |
12928 | unsigned frontbuffer_bits = 0; | |
12929 | int ret = 0; | |
465c120c | 12930 | |
ea2c67bb | 12931 | if (!obj) |
465c120c MR |
12932 | return 0; |
12933 | ||
6beb8c23 MR |
12934 | switch (plane->type) { |
12935 | case DRM_PLANE_TYPE_PRIMARY: | |
12936 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); | |
12937 | break; | |
12938 | case DRM_PLANE_TYPE_CURSOR: | |
12939 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); | |
12940 | break; | |
12941 | case DRM_PLANE_TYPE_OVERLAY: | |
12942 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); | |
12943 | break; | |
12944 | } | |
465c120c | 12945 | |
6beb8c23 | 12946 | mutex_lock(&dev->struct_mutex); |
465c120c | 12947 | |
6beb8c23 MR |
12948 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
12949 | INTEL_INFO(dev)->cursor_needs_physical) { | |
12950 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
12951 | ret = i915_gem_object_attach_phys(obj, align); | |
12952 | if (ret) | |
12953 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
12954 | } else { | |
82bc3b2d | 12955 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL); |
6beb8c23 | 12956 | } |
465c120c | 12957 | |
6beb8c23 MR |
12958 | if (ret == 0) |
12959 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); | |
fdd508a6 | 12960 | |
4c34574f | 12961 | mutex_unlock(&dev->struct_mutex); |
465c120c | 12962 | |
6beb8c23 MR |
12963 | return ret; |
12964 | } | |
12965 | ||
38f3ce3a MR |
12966 | /** |
12967 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
12968 | * @plane: drm plane to clean up for | |
12969 | * @fb: old framebuffer that was on plane | |
12970 | * | |
12971 | * Cleans up a framebuffer that has just been removed from a plane. | |
12972 | */ | |
12973 | void | |
12974 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
12975 | struct drm_framebuffer *fb, |
12976 | const struct drm_plane_state *old_state) | |
38f3ce3a MR |
12977 | { |
12978 | struct drm_device *dev = plane->dev; | |
12979 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
12980 | ||
12981 | if (WARN_ON(!obj)) | |
12982 | return; | |
12983 | ||
12984 | if (plane->type != DRM_PLANE_TYPE_CURSOR || | |
12985 | !INTEL_INFO(dev)->cursor_needs_physical) { | |
12986 | mutex_lock(&dev->struct_mutex); | |
82bc3b2d | 12987 | intel_unpin_fb_obj(fb, old_state); |
38f3ce3a MR |
12988 | mutex_unlock(&dev->struct_mutex); |
12989 | } | |
465c120c MR |
12990 | } |
12991 | ||
6156a456 CK |
12992 | int |
12993 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
12994 | { | |
12995 | int max_scale; | |
12996 | struct drm_device *dev; | |
12997 | struct drm_i915_private *dev_priv; | |
12998 | int crtc_clock, cdclk; | |
12999 | ||
13000 | if (!intel_crtc || !crtc_state) | |
13001 | return DRM_PLANE_HELPER_NO_SCALING; | |
13002 | ||
13003 | dev = intel_crtc->base.dev; | |
13004 | dev_priv = dev->dev_private; | |
13005 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
13006 | cdclk = dev_priv->display.get_display_clock_speed(dev); | |
13007 | ||
13008 | if (!crtc_clock || !cdclk) | |
13009 | return DRM_PLANE_HELPER_NO_SCALING; | |
13010 | ||
13011 | /* | |
13012 | * skl max scale is lower of: | |
13013 | * close to 3 but not 3, -1 is for that purpose | |
13014 | * or | |
13015 | * cdclk/crtc_clock | |
13016 | */ | |
13017 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13018 | ||
13019 | return max_scale; | |
13020 | } | |
13021 | ||
465c120c | 13022 | static int |
3c692a41 GP |
13023 | intel_check_primary_plane(struct drm_plane *plane, |
13024 | struct intel_plane_state *state) | |
13025 | { | |
32b7eeec MR |
13026 | struct drm_device *dev = plane->dev; |
13027 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2b875c22 | 13028 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb | 13029 | struct intel_crtc *intel_crtc; |
6156a456 | 13030 | struct intel_crtc_state *crtc_state; |
2b875c22 | 13031 | struct drm_framebuffer *fb = state->base.fb; |
3c692a41 GP |
13032 | struct drm_rect *dest = &state->dst; |
13033 | struct drm_rect *src = &state->src; | |
13034 | const struct drm_rect *clip = &state->clip; | |
d8106366 | 13035 | bool can_position = false; |
6156a456 CK |
13036 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13037 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; | |
465c120c MR |
13038 | int ret; |
13039 | ||
ea2c67bb MR |
13040 | crtc = crtc ? crtc : plane->crtc; |
13041 | intel_crtc = to_intel_crtc(crtc); | |
6156a456 CK |
13042 | crtc_state = state->base.state ? |
13043 | intel_atomic_get_crtc_state(state->base.state, intel_crtc) : NULL; | |
ea2c67bb | 13044 | |
6156a456 CK |
13045 | if (INTEL_INFO(dev)->gen >= 9) { |
13046 | min_scale = 1; | |
13047 | max_scale = skl_max_scale(intel_crtc, crtc_state); | |
d8106366 | 13048 | can_position = true; |
6156a456 | 13049 | } |
d8106366 | 13050 | |
c59cb179 MR |
13051 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
13052 | src, dest, clip, | |
6156a456 CK |
13053 | min_scale, |
13054 | max_scale, | |
d8106366 SJ |
13055 | can_position, true, |
13056 | &state->visible); | |
c59cb179 MR |
13057 | if (ret) |
13058 | return ret; | |
465c120c | 13059 | |
32b7eeec | 13060 | if (intel_crtc->active) { |
b70709a6 ML |
13061 | struct intel_plane_state *old_state = |
13062 | to_intel_plane_state(plane->state); | |
13063 | ||
32b7eeec MR |
13064 | intel_crtc->atomic.wait_for_flips = true; |
13065 | ||
13066 | /* | |
13067 | * FBC does not work on some platforms for rotated | |
13068 | * planes, so disable it when rotation is not 0 and | |
13069 | * update it when rotation is set back to 0. | |
13070 | * | |
13071 | * FIXME: This is redundant with the fbc update done in | |
13072 | * the primary plane enable function except that that | |
13073 | * one is done too late. We eventually need to unify | |
13074 | * this. | |
13075 | */ | |
b70709a6 | 13076 | if (state->visible && |
32b7eeec | 13077 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
e35fef21 | 13078 | dev_priv->fbc.crtc == intel_crtc && |
8e7d688b | 13079 | state->base.rotation != BIT(DRM_ROTATE_0)) { |
32b7eeec MR |
13080 | intel_crtc->atomic.disable_fbc = true; |
13081 | } | |
13082 | ||
b70709a6 | 13083 | if (state->visible && !old_state->visible) { |
32b7eeec MR |
13084 | /* |
13085 | * BDW signals flip done immediately if the plane | |
13086 | * is disabled, even if the plane enable is already | |
13087 | * armed to occur at the next vblank :( | |
13088 | */ | |
b70709a6 | 13089 | if (IS_BROADWELL(dev)) |
32b7eeec MR |
13090 | intel_crtc->atomic.wait_vblank = true; |
13091 | } | |
13092 | ||
13093 | intel_crtc->atomic.fb_bits |= | |
13094 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); | |
13095 | ||
13096 | intel_crtc->atomic.update_fbc = true; | |
0fda6568 | 13097 | |
1fc0a8f7 | 13098 | if (intel_wm_need_update(plane, &state->base)) |
0fda6568 | 13099 | intel_crtc->atomic.update_wm = true; |
ccc759dc GP |
13100 | } |
13101 | ||
6156a456 CK |
13102 | if (INTEL_INFO(dev)->gen >= 9) { |
13103 | ret = skl_update_scaler_users(intel_crtc, crtc_state, | |
13104 | to_intel_plane(plane), state, 0); | |
13105 | if (ret) | |
13106 | return ret; | |
13107 | } | |
13108 | ||
14af293f GP |
13109 | return 0; |
13110 | } | |
13111 | ||
13112 | static void | |
13113 | intel_commit_primary_plane(struct drm_plane *plane, | |
13114 | struct intel_plane_state *state) | |
13115 | { | |
2b875c22 MR |
13116 | struct drm_crtc *crtc = state->base.crtc; |
13117 | struct drm_framebuffer *fb = state->base.fb; | |
13118 | struct drm_device *dev = plane->dev; | |
14af293f | 13119 | struct drm_i915_private *dev_priv = dev->dev_private; |
ea2c67bb | 13120 | struct intel_crtc *intel_crtc; |
14af293f GP |
13121 | struct drm_rect *src = &state->src; |
13122 | ||
ea2c67bb MR |
13123 | crtc = crtc ? crtc : plane->crtc; |
13124 | intel_crtc = to_intel_crtc(crtc); | |
cf4c7c12 MR |
13125 | |
13126 | plane->fb = fb; | |
9dc806fc MR |
13127 | crtc->x = src->x1 >> 16; |
13128 | crtc->y = src->y1 >> 16; | |
ccc759dc | 13129 | |
ccc759dc | 13130 | if (intel_crtc->active) { |
27321ae8 | 13131 | if (state->visible) |
ccc759dc GP |
13132 | /* FIXME: kill this fastboot hack */ |
13133 | intel_update_pipe_size(intel_crtc); | |
465c120c | 13134 | |
27321ae8 ML |
13135 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
13136 | crtc->x, crtc->y); | |
ccc759dc | 13137 | } |
465c120c MR |
13138 | } |
13139 | ||
a8ad0d8e ML |
13140 | static void |
13141 | intel_disable_primary_plane(struct drm_plane *plane, | |
13142 | struct drm_crtc *crtc, | |
13143 | bool force) | |
13144 | { | |
13145 | struct drm_device *dev = plane->dev; | |
13146 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13147 | ||
a8ad0d8e ML |
13148 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13149 | } | |
13150 | ||
32b7eeec | 13151 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
3c692a41 | 13152 | { |
32b7eeec | 13153 | struct drm_device *dev = crtc->dev; |
140fd38d | 13154 | struct drm_i915_private *dev_priv = dev->dev_private; |
3c692a41 | 13155 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ea2c67bb MR |
13156 | struct intel_plane *intel_plane; |
13157 | struct drm_plane *p; | |
13158 | unsigned fb_bits = 0; | |
13159 | ||
13160 | /* Track fb's for any planes being disabled */ | |
13161 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { | |
13162 | intel_plane = to_intel_plane(p); | |
13163 | ||
13164 | if (intel_crtc->atomic.disabled_planes & | |
13165 | (1 << drm_plane_index(p))) { | |
13166 | switch (p->type) { | |
13167 | case DRM_PLANE_TYPE_PRIMARY: | |
13168 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe); | |
13169 | break; | |
13170 | case DRM_PLANE_TYPE_CURSOR: | |
13171 | fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe); | |
13172 | break; | |
13173 | case DRM_PLANE_TYPE_OVERLAY: | |
13174 | fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe); | |
13175 | break; | |
13176 | } | |
3c692a41 | 13177 | |
ea2c67bb MR |
13178 | mutex_lock(&dev->struct_mutex); |
13179 | i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits); | |
13180 | mutex_unlock(&dev->struct_mutex); | |
13181 | } | |
13182 | } | |
3c692a41 | 13183 | |
32b7eeec MR |
13184 | if (intel_crtc->atomic.wait_for_flips) |
13185 | intel_crtc_wait_for_pending_flips(crtc); | |
3c692a41 | 13186 | |
32b7eeec MR |
13187 | if (intel_crtc->atomic.disable_fbc) |
13188 | intel_fbc_disable(dev); | |
3c692a41 | 13189 | |
32b7eeec MR |
13190 | if (intel_crtc->atomic.pre_disable_primary) |
13191 | intel_pre_disable_primary(crtc); | |
3c692a41 | 13192 | |
32b7eeec MR |
13193 | if (intel_crtc->atomic.update_wm) |
13194 | intel_update_watermarks(crtc); | |
3c692a41 | 13195 | |
32b7eeec | 13196 | intel_runtime_pm_get(dev_priv); |
3c692a41 | 13197 | |
c34c9ee4 MR |
13198 | /* Perform vblank evasion around commit operation */ |
13199 | if (intel_crtc->active) | |
13200 | intel_crtc->atomic.evade = | |
13201 | intel_pipe_update_start(intel_crtc, | |
13202 | &intel_crtc->atomic.start_vbl_count); | |
32b7eeec MR |
13203 | } |
13204 | ||
13205 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) | |
13206 | { | |
13207 | struct drm_device *dev = crtc->dev; | |
13208 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13209 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13210 | struct drm_plane *p; | |
13211 | ||
c34c9ee4 MR |
13212 | if (intel_crtc->atomic.evade) |
13213 | intel_pipe_update_end(intel_crtc, | |
13214 | intel_crtc->atomic.start_vbl_count); | |
3c692a41 | 13215 | |
140fd38d | 13216 | intel_runtime_pm_put(dev_priv); |
3c692a41 | 13217 | |
32b7eeec MR |
13218 | if (intel_crtc->atomic.wait_vblank) |
13219 | intel_wait_for_vblank(dev, intel_crtc->pipe); | |
13220 | ||
13221 | intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits); | |
13222 | ||
13223 | if (intel_crtc->atomic.update_fbc) { | |
ccc759dc | 13224 | mutex_lock(&dev->struct_mutex); |
7ff0ebcc | 13225 | intel_fbc_update(dev); |
ccc759dc | 13226 | mutex_unlock(&dev->struct_mutex); |
38f3ce3a | 13227 | } |
3c692a41 | 13228 | |
32b7eeec MR |
13229 | if (intel_crtc->atomic.post_enable_primary) |
13230 | intel_post_enable_primary(crtc); | |
3c692a41 | 13231 | |
32b7eeec MR |
13232 | drm_for_each_legacy_plane(p, &dev->mode_config.plane_list) |
13233 | if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p)) | |
13234 | intel_update_sprite_watermarks(p, crtc, 0, 0, 0, | |
13235 | false, false); | |
13236 | ||
13237 | memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic)); | |
3c692a41 GP |
13238 | } |
13239 | ||
cf4c7c12 | 13240 | /** |
4a3b8769 MR |
13241 | * intel_plane_destroy - destroy a plane |
13242 | * @plane: plane to destroy | |
cf4c7c12 | 13243 | * |
4a3b8769 MR |
13244 | * Common destruction function for all types of planes (primary, cursor, |
13245 | * sprite). | |
cf4c7c12 | 13246 | */ |
4a3b8769 | 13247 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13248 | { |
13249 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13250 | drm_plane_cleanup(plane); | |
13251 | kfree(intel_plane); | |
13252 | } | |
13253 | ||
65a3fea0 | 13254 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13255 | .update_plane = drm_atomic_helper_update_plane, |
13256 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13257 | .destroy = intel_plane_destroy, |
c196e1d6 | 13258 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13259 | .atomic_get_property = intel_plane_atomic_get_property, |
13260 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13261 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13262 | .atomic_destroy_state = intel_plane_destroy_state, | |
13263 | ||
465c120c MR |
13264 | }; |
13265 | ||
13266 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13267 | int pipe) | |
13268 | { | |
13269 | struct intel_plane *primary; | |
8e7d688b | 13270 | struct intel_plane_state *state; |
465c120c MR |
13271 | const uint32_t *intel_primary_formats; |
13272 | int num_formats; | |
13273 | ||
13274 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13275 | if (primary == NULL) | |
13276 | return NULL; | |
13277 | ||
8e7d688b MR |
13278 | state = intel_create_plane_state(&primary->base); |
13279 | if (!state) { | |
ea2c67bb MR |
13280 | kfree(primary); |
13281 | return NULL; | |
13282 | } | |
8e7d688b | 13283 | primary->base.state = &state->base; |
ea2c67bb | 13284 | |
465c120c MR |
13285 | primary->can_scale = false; |
13286 | primary->max_downscale = 1; | |
6156a456 CK |
13287 | if (INTEL_INFO(dev)->gen >= 9) { |
13288 | primary->can_scale = true; | |
af99ceda | 13289 | state->scaler_id = -1; |
6156a456 | 13290 | } |
465c120c MR |
13291 | primary->pipe = pipe; |
13292 | primary->plane = pipe; | |
c59cb179 MR |
13293 | primary->check_plane = intel_check_primary_plane; |
13294 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13295 | primary->disable_plane = intel_disable_primary_plane; |
08e221fb | 13296 | primary->ckey.flags = I915_SET_COLORKEY_NONE; |
465c120c MR |
13297 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13298 | primary->plane = !pipe; | |
13299 | ||
6c0fd451 DL |
13300 | if (INTEL_INFO(dev)->gen >= 9) { |
13301 | intel_primary_formats = skl_primary_formats; | |
13302 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13303 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13304 | intel_primary_formats = i965_primary_formats; |
13305 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13306 | } else { |
13307 | intel_primary_formats = i8xx_primary_formats; | |
13308 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13309 | } |
13310 | ||
13311 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13312 | &intel_plane_funcs, |
465c120c MR |
13313 | intel_primary_formats, num_formats, |
13314 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13315 | |
3b7a5119 SJ |
13316 | if (INTEL_INFO(dev)->gen >= 4) |
13317 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13318 | |
ea2c67bb MR |
13319 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13320 | ||
465c120c MR |
13321 | return &primary->base; |
13322 | } | |
13323 | ||
3b7a5119 SJ |
13324 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13325 | { | |
13326 | if (!dev->mode_config.rotation_property) { | |
13327 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13328 | BIT(DRM_ROTATE_180); | |
13329 | ||
13330 | if (INTEL_INFO(dev)->gen >= 9) | |
13331 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13332 | ||
13333 | dev->mode_config.rotation_property = | |
13334 | drm_mode_create_rotation_property(dev, flags); | |
13335 | } | |
13336 | if (dev->mode_config.rotation_property) | |
13337 | drm_object_attach_property(&plane->base.base, | |
13338 | dev->mode_config.rotation_property, | |
13339 | plane->base.state->rotation); | |
13340 | } | |
13341 | ||
3d7d6510 | 13342 | static int |
852e787c GP |
13343 | intel_check_cursor_plane(struct drm_plane *plane, |
13344 | struct intel_plane_state *state) | |
3d7d6510 | 13345 | { |
2b875c22 | 13346 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb | 13347 | struct drm_device *dev = plane->dev; |
2b875c22 | 13348 | struct drm_framebuffer *fb = state->base.fb; |
852e787c GP |
13349 | struct drm_rect *dest = &state->dst; |
13350 | struct drm_rect *src = &state->src; | |
13351 | const struct drm_rect *clip = &state->clip; | |
757f9a3e | 13352 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
ea2c67bb | 13353 | struct intel_crtc *intel_crtc; |
757f9a3e GP |
13354 | unsigned stride; |
13355 | int ret; | |
3d7d6510 | 13356 | |
ea2c67bb MR |
13357 | crtc = crtc ? crtc : plane->crtc; |
13358 | intel_crtc = to_intel_crtc(crtc); | |
13359 | ||
757f9a3e | 13360 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
852e787c | 13361 | src, dest, clip, |
3d7d6510 MR |
13362 | DRM_PLANE_HELPER_NO_SCALING, |
13363 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13364 | true, true, &state->visible); |
757f9a3e GP |
13365 | if (ret) |
13366 | return ret; | |
13367 | ||
13368 | ||
13369 | /* if we want to turn off the cursor ignore width and height */ | |
13370 | if (!obj) | |
32b7eeec | 13371 | goto finish; |
757f9a3e | 13372 | |
757f9a3e | 13373 | /* Check for which cursor types we support */ |
ea2c67bb MR |
13374 | if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) { |
13375 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", | |
13376 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13377 | return -EINVAL; |
13378 | } | |
13379 | ||
ea2c67bb MR |
13380 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13381 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13382 | DRM_DEBUG_KMS("buffer is too small\n"); |
13383 | return -ENOMEM; | |
13384 | } | |
13385 | ||
3a656b54 | 13386 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e GP |
13387 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
13388 | ret = -EINVAL; | |
13389 | } | |
757f9a3e | 13390 | |
32b7eeec MR |
13391 | finish: |
13392 | if (intel_crtc->active) { | |
3749f463 | 13393 | if (plane->state->crtc_w != state->base.crtc_w) |
32b7eeec MR |
13394 | intel_crtc->atomic.update_wm = true; |
13395 | ||
13396 | intel_crtc->atomic.fb_bits |= | |
13397 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); | |
13398 | } | |
13399 | ||
757f9a3e | 13400 | return ret; |
852e787c | 13401 | } |
3d7d6510 | 13402 | |
a8ad0d8e ML |
13403 | static void |
13404 | intel_disable_cursor_plane(struct drm_plane *plane, | |
13405 | struct drm_crtc *crtc, | |
13406 | bool force) | |
13407 | { | |
13408 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13409 | ||
13410 | if (!force) { | |
13411 | plane->fb = NULL; | |
13412 | intel_crtc->cursor_bo = NULL; | |
13413 | intel_crtc->cursor_addr = 0; | |
13414 | } | |
13415 | ||
13416 | intel_crtc_update_cursor(crtc, false); | |
13417 | } | |
13418 | ||
f4a2cf29 | 13419 | static void |
852e787c GP |
13420 | intel_commit_cursor_plane(struct drm_plane *plane, |
13421 | struct intel_plane_state *state) | |
13422 | { | |
2b875c22 | 13423 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
13424 | struct drm_device *dev = plane->dev; |
13425 | struct intel_crtc *intel_crtc; | |
2b875c22 | 13426 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 13427 | uint32_t addr; |
852e787c | 13428 | |
ea2c67bb MR |
13429 | crtc = crtc ? crtc : plane->crtc; |
13430 | intel_crtc = to_intel_crtc(crtc); | |
13431 | ||
2b875c22 | 13432 | plane->fb = state->base.fb; |
ea2c67bb MR |
13433 | crtc->cursor_x = state->base.crtc_x; |
13434 | crtc->cursor_y = state->base.crtc_y; | |
13435 | ||
a912f12f GP |
13436 | if (intel_crtc->cursor_bo == obj) |
13437 | goto update; | |
4ed91096 | 13438 | |
f4a2cf29 | 13439 | if (!obj) |
a912f12f | 13440 | addr = 0; |
f4a2cf29 | 13441 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 13442 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 13443 | else |
a912f12f | 13444 | addr = obj->phys_handle->busaddr; |
852e787c | 13445 | |
a912f12f GP |
13446 | intel_crtc->cursor_addr = addr; |
13447 | intel_crtc->cursor_bo = obj; | |
13448 | update: | |
852e787c | 13449 | |
32b7eeec | 13450 | if (intel_crtc->active) |
a912f12f | 13451 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
13452 | } |
13453 | ||
3d7d6510 MR |
13454 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
13455 | int pipe) | |
13456 | { | |
13457 | struct intel_plane *cursor; | |
8e7d688b | 13458 | struct intel_plane_state *state; |
3d7d6510 MR |
13459 | |
13460 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
13461 | if (cursor == NULL) | |
13462 | return NULL; | |
13463 | ||
8e7d688b MR |
13464 | state = intel_create_plane_state(&cursor->base); |
13465 | if (!state) { | |
ea2c67bb MR |
13466 | kfree(cursor); |
13467 | return NULL; | |
13468 | } | |
8e7d688b | 13469 | cursor->base.state = &state->base; |
ea2c67bb | 13470 | |
3d7d6510 MR |
13471 | cursor->can_scale = false; |
13472 | cursor->max_downscale = 1; | |
13473 | cursor->pipe = pipe; | |
13474 | cursor->plane = pipe; | |
c59cb179 MR |
13475 | cursor->check_plane = intel_check_cursor_plane; |
13476 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 13477 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
13478 | |
13479 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 13480 | &intel_plane_funcs, |
3d7d6510 MR |
13481 | intel_cursor_formats, |
13482 | ARRAY_SIZE(intel_cursor_formats), | |
13483 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
13484 | |
13485 | if (INTEL_INFO(dev)->gen >= 4) { | |
13486 | if (!dev->mode_config.rotation_property) | |
13487 | dev->mode_config.rotation_property = | |
13488 | drm_mode_create_rotation_property(dev, | |
13489 | BIT(DRM_ROTATE_0) | | |
13490 | BIT(DRM_ROTATE_180)); | |
13491 | if (dev->mode_config.rotation_property) | |
13492 | drm_object_attach_property(&cursor->base.base, | |
13493 | dev->mode_config.rotation_property, | |
8e7d688b | 13494 | state->base.rotation); |
4398ad45 VS |
13495 | } |
13496 | ||
af99ceda CK |
13497 | if (INTEL_INFO(dev)->gen >=9) |
13498 | state->scaler_id = -1; | |
13499 | ||
ea2c67bb MR |
13500 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
13501 | ||
3d7d6510 MR |
13502 | return &cursor->base; |
13503 | } | |
13504 | ||
549e2bfb CK |
13505 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
13506 | struct intel_crtc_state *crtc_state) | |
13507 | { | |
13508 | int i; | |
13509 | struct intel_scaler *intel_scaler; | |
13510 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
13511 | ||
13512 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
13513 | intel_scaler = &scaler_state->scalers[i]; | |
13514 | intel_scaler->in_use = 0; | |
13515 | intel_scaler->id = i; | |
13516 | ||
13517 | intel_scaler->mode = PS_SCALER_MODE_DYN; | |
13518 | } | |
13519 | ||
13520 | scaler_state->scaler_id = -1; | |
13521 | } | |
13522 | ||
b358d0a6 | 13523 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 13524 | { |
fbee40df | 13525 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 13526 | struct intel_crtc *intel_crtc; |
f5de6e07 | 13527 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
13528 | struct drm_plane *primary = NULL; |
13529 | struct drm_plane *cursor = NULL; | |
465c120c | 13530 | int i, ret; |
79e53945 | 13531 | |
955382f3 | 13532 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
13533 | if (intel_crtc == NULL) |
13534 | return; | |
13535 | ||
f5de6e07 ACO |
13536 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
13537 | if (!crtc_state) | |
13538 | goto fail; | |
550acefd ACO |
13539 | intel_crtc->config = crtc_state; |
13540 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 13541 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 13542 | |
549e2bfb CK |
13543 | /* initialize shared scalers */ |
13544 | if (INTEL_INFO(dev)->gen >= 9) { | |
13545 | if (pipe == PIPE_C) | |
13546 | intel_crtc->num_scalers = 1; | |
13547 | else | |
13548 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
13549 | ||
13550 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
13551 | } | |
13552 | ||
465c120c | 13553 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
13554 | if (!primary) |
13555 | goto fail; | |
13556 | ||
13557 | cursor = intel_cursor_plane_create(dev, pipe); | |
13558 | if (!cursor) | |
13559 | goto fail; | |
13560 | ||
465c120c | 13561 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
13562 | cursor, &intel_crtc_funcs); |
13563 | if (ret) | |
13564 | goto fail; | |
79e53945 JB |
13565 | |
13566 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
13567 | for (i = 0; i < 256; i++) { |
13568 | intel_crtc->lut_r[i] = i; | |
13569 | intel_crtc->lut_g[i] = i; | |
13570 | intel_crtc->lut_b[i] = i; | |
13571 | } | |
13572 | ||
1f1c2e24 VS |
13573 | /* |
13574 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 13575 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 13576 | */ |
80824003 JB |
13577 | intel_crtc->pipe = pipe; |
13578 | intel_crtc->plane = pipe; | |
3a77c4c4 | 13579 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 13580 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 13581 | intel_crtc->plane = !pipe; |
80824003 JB |
13582 | } |
13583 | ||
4b0e333e CW |
13584 | intel_crtc->cursor_base = ~0; |
13585 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 13586 | intel_crtc->cursor_size = ~0; |
8d7849db | 13587 | |
22fd0fab JB |
13588 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
13589 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
13590 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
13591 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
13592 | ||
79e53945 | 13593 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
13594 | |
13595 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
13596 | return; |
13597 | ||
13598 | fail: | |
13599 | if (primary) | |
13600 | drm_plane_cleanup(primary); | |
13601 | if (cursor) | |
13602 | drm_plane_cleanup(cursor); | |
f5de6e07 | 13603 | kfree(crtc_state); |
3d7d6510 | 13604 | kfree(intel_crtc); |
79e53945 JB |
13605 | } |
13606 | ||
752aa88a JB |
13607 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
13608 | { | |
13609 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 13610 | struct drm_device *dev = connector->base.dev; |
752aa88a | 13611 | |
51fd371b | 13612 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 13613 | |
d3babd3f | 13614 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
13615 | return INVALID_PIPE; |
13616 | ||
13617 | return to_intel_crtc(encoder->crtc)->pipe; | |
13618 | } | |
13619 | ||
08d7b3d1 | 13620 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 13621 | struct drm_file *file) |
08d7b3d1 | 13622 | { |
08d7b3d1 | 13623 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 13624 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 13625 | struct intel_crtc *crtc; |
08d7b3d1 | 13626 | |
7707e653 | 13627 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 13628 | |
7707e653 | 13629 | if (!drmmode_crtc) { |
08d7b3d1 | 13630 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 13631 | return -ENOENT; |
08d7b3d1 CW |
13632 | } |
13633 | ||
7707e653 | 13634 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 13635 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 13636 | |
c05422d5 | 13637 | return 0; |
08d7b3d1 CW |
13638 | } |
13639 | ||
66a9278e | 13640 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 13641 | { |
66a9278e DV |
13642 | struct drm_device *dev = encoder->base.dev; |
13643 | struct intel_encoder *source_encoder; | |
79e53945 | 13644 | int index_mask = 0; |
79e53945 JB |
13645 | int entry = 0; |
13646 | ||
b2784e15 | 13647 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 13648 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
13649 | index_mask |= (1 << entry); |
13650 | ||
79e53945 JB |
13651 | entry++; |
13652 | } | |
4ef69c7a | 13653 | |
79e53945 JB |
13654 | return index_mask; |
13655 | } | |
13656 | ||
4d302442 CW |
13657 | static bool has_edp_a(struct drm_device *dev) |
13658 | { | |
13659 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13660 | ||
13661 | if (!IS_MOBILE(dev)) | |
13662 | return false; | |
13663 | ||
13664 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
13665 | return false; | |
13666 | ||
e3589908 | 13667 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
13668 | return false; |
13669 | ||
13670 | return true; | |
13671 | } | |
13672 | ||
84b4e042 JB |
13673 | static bool intel_crt_present(struct drm_device *dev) |
13674 | { | |
13675 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13676 | ||
884497ed DL |
13677 | if (INTEL_INFO(dev)->gen >= 9) |
13678 | return false; | |
13679 | ||
cf404ce4 | 13680 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
13681 | return false; |
13682 | ||
13683 | if (IS_CHERRYVIEW(dev)) | |
13684 | return false; | |
13685 | ||
13686 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
13687 | return false; | |
13688 | ||
13689 | return true; | |
13690 | } | |
13691 | ||
79e53945 JB |
13692 | static void intel_setup_outputs(struct drm_device *dev) |
13693 | { | |
725e30ad | 13694 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 13695 | struct intel_encoder *encoder; |
cb0953d7 | 13696 | bool dpd_is_edp = false; |
79e53945 | 13697 | |
c9093354 | 13698 | intel_lvds_init(dev); |
79e53945 | 13699 | |
84b4e042 | 13700 | if (intel_crt_present(dev)) |
79935fca | 13701 | intel_crt_init(dev); |
cb0953d7 | 13702 | |
c776eb2e VK |
13703 | if (IS_BROXTON(dev)) { |
13704 | /* | |
13705 | * FIXME: Broxton doesn't support port detection via the | |
13706 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
13707 | * detect the ports. | |
13708 | */ | |
13709 | intel_ddi_init(dev, PORT_A); | |
13710 | intel_ddi_init(dev, PORT_B); | |
13711 | intel_ddi_init(dev, PORT_C); | |
13712 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
13713 | int found; |
13714 | ||
de31facd JB |
13715 | /* |
13716 | * Haswell uses DDI functions to detect digital outputs. | |
13717 | * On SKL pre-D0 the strap isn't connected, so we assume | |
13718 | * it's there. | |
13719 | */ | |
0e72a5b5 | 13720 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
de31facd JB |
13721 | /* WaIgnoreDDIAStrap: skl */ |
13722 | if (found || | |
13723 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) | |
0e72a5b5 ED |
13724 | intel_ddi_init(dev, PORT_A); |
13725 | ||
13726 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
13727 | * register */ | |
13728 | found = I915_READ(SFUSE_STRAP); | |
13729 | ||
13730 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
13731 | intel_ddi_init(dev, PORT_B); | |
13732 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
13733 | intel_ddi_init(dev, PORT_C); | |
13734 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
13735 | intel_ddi_init(dev, PORT_D); | |
13736 | } else if (HAS_PCH_SPLIT(dev)) { | |
cb0953d7 | 13737 | int found; |
5d8a7752 | 13738 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
13739 | |
13740 | if (has_edp_a(dev)) | |
13741 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 13742 | |
dc0fa718 | 13743 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 13744 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 13745 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 13746 | if (!found) |
e2debe91 | 13747 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 13748 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 13749 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
13750 | } |
13751 | ||
dc0fa718 | 13752 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 13753 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 13754 | |
dc0fa718 | 13755 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 13756 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 13757 | |
5eb08b69 | 13758 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 13759 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 13760 | |
270b3042 | 13761 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 13762 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 13763 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
13764 | /* |
13765 | * The DP_DETECTED bit is the latched state of the DDC | |
13766 | * SDA pin at boot. However since eDP doesn't require DDC | |
13767 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
13768 | * eDP ports may have been muxed to an alternate function. | |
13769 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
13770 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
13771 | * detect eDP ports. | |
13772 | */ | |
d2182a66 VS |
13773 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
13774 | !intel_dp_is_edp(dev, PORT_B)) | |
585a94b8 AB |
13775 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
13776 | PORT_B); | |
e17ac6db VS |
13777 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
13778 | intel_dp_is_edp(dev, PORT_B)) | |
13779 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); | |
585a94b8 | 13780 | |
d2182a66 VS |
13781 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
13782 | !intel_dp_is_edp(dev, PORT_C)) | |
6f6005a5 JB |
13783 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
13784 | PORT_C); | |
e17ac6db VS |
13785 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
13786 | intel_dp_is_edp(dev, PORT_C)) | |
13787 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); | |
19c03924 | 13788 | |
9418c1f1 | 13789 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 13790 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
9418c1f1 VS |
13791 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
13792 | PORT_D); | |
e17ac6db VS |
13793 | /* eDP not supported on port D, so don't check VBT */ |
13794 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) | |
13795 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); | |
9418c1f1 VS |
13796 | } |
13797 | ||
3cfca973 | 13798 | intel_dsi_init(dev); |
103a196f | 13799 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
27185ae1 | 13800 | bool found = false; |
7d57382e | 13801 | |
e2debe91 | 13802 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 13803 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 13804 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
b01f2c3a JB |
13805 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
13806 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); | |
e2debe91 | 13807 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 13808 | } |
27185ae1 | 13809 | |
e7281eab | 13810 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
ab9d7c30 | 13811 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 13812 | } |
13520b05 KH |
13813 | |
13814 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 13815 | |
e2debe91 | 13816 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 13817 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 13818 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 13819 | } |
27185ae1 | 13820 | |
e2debe91 | 13821 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 13822 | |
b01f2c3a JB |
13823 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
13824 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); | |
e2debe91 | 13825 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 13826 | } |
e7281eab | 13827 | if (SUPPORTS_INTEGRATED_DP(dev)) |
ab9d7c30 | 13828 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 13829 | } |
27185ae1 | 13830 | |
b01f2c3a | 13831 | if (SUPPORTS_INTEGRATED_DP(dev) && |
e7281eab | 13832 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 13833 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 13834 | } else if (IS_GEN2(dev)) |
79e53945 JB |
13835 | intel_dvo_init(dev); |
13836 | ||
103a196f | 13837 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
13838 | intel_tv_init(dev); |
13839 | ||
0bc12bcb | 13840 | intel_psr_init(dev); |
7c8f8a70 | 13841 | |
b2784e15 | 13842 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
13843 | encoder->base.possible_crtcs = encoder->crtc_mask; |
13844 | encoder->base.possible_clones = | |
66a9278e | 13845 | intel_encoder_clones(encoder); |
79e53945 | 13846 | } |
47356eb6 | 13847 | |
dde86e2d | 13848 | intel_init_pch_refclk(dev); |
270b3042 DV |
13849 | |
13850 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
13851 | } |
13852 | ||
13853 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
13854 | { | |
60a5ca01 | 13855 | struct drm_device *dev = fb->dev; |
79e53945 | 13856 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 13857 | |
ef2d633e | 13858 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 13859 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 13860 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
13861 | drm_gem_object_unreference(&intel_fb->obj->base); |
13862 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
13863 | kfree(intel_fb); |
13864 | } | |
13865 | ||
13866 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 13867 | struct drm_file *file, |
79e53945 JB |
13868 | unsigned int *handle) |
13869 | { | |
13870 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 13871 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 13872 | |
05394f39 | 13873 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
13874 | } |
13875 | ||
13876 | static const struct drm_framebuffer_funcs intel_fb_funcs = { | |
13877 | .destroy = intel_user_framebuffer_destroy, | |
13878 | .create_handle = intel_user_framebuffer_create_handle, | |
13879 | }; | |
13880 | ||
b321803d DL |
13881 | static |
13882 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
13883 | uint32_t pixel_format) | |
13884 | { | |
13885 | u32 gen = INTEL_INFO(dev)->gen; | |
13886 | ||
13887 | if (gen >= 9) { | |
13888 | /* "The stride in bytes must not exceed the of the size of 8K | |
13889 | * pixels and 32K bytes." | |
13890 | */ | |
13891 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
13892 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
13893 | return 32*1024; | |
13894 | } else if (gen >= 4) { | |
13895 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
13896 | return 16*1024; | |
13897 | else | |
13898 | return 32*1024; | |
13899 | } else if (gen >= 3) { | |
13900 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
13901 | return 8*1024; | |
13902 | else | |
13903 | return 16*1024; | |
13904 | } else { | |
13905 | /* XXX DSPC is limited to 4k tiled */ | |
13906 | return 8*1024; | |
13907 | } | |
13908 | } | |
13909 | ||
b5ea642a DV |
13910 | static int intel_framebuffer_init(struct drm_device *dev, |
13911 | struct intel_framebuffer *intel_fb, | |
13912 | struct drm_mode_fb_cmd2 *mode_cmd, | |
13913 | struct drm_i915_gem_object *obj) | |
79e53945 | 13914 | { |
6761dd31 | 13915 | unsigned int aligned_height; |
79e53945 | 13916 | int ret; |
b321803d | 13917 | u32 pitch_limit, stride_alignment; |
79e53945 | 13918 | |
dd4916c5 DV |
13919 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
13920 | ||
2a80eada DV |
13921 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
13922 | /* Enforce that fb modifier and tiling mode match, but only for | |
13923 | * X-tiled. This is needed for FBC. */ | |
13924 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
13925 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
13926 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
13927 | return -EINVAL; | |
13928 | } | |
13929 | } else { | |
13930 | if (obj->tiling_mode == I915_TILING_X) | |
13931 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
13932 | else if (obj->tiling_mode == I915_TILING_Y) { | |
13933 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
13934 | return -EINVAL; | |
13935 | } | |
13936 | } | |
13937 | ||
9a8f0a12 TU |
13938 | /* Passed in modifier sanity checking. */ |
13939 | switch (mode_cmd->modifier[0]) { | |
13940 | case I915_FORMAT_MOD_Y_TILED: | |
13941 | case I915_FORMAT_MOD_Yf_TILED: | |
13942 | if (INTEL_INFO(dev)->gen < 9) { | |
13943 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
13944 | mode_cmd->modifier[0]); | |
13945 | return -EINVAL; | |
13946 | } | |
13947 | case DRM_FORMAT_MOD_NONE: | |
13948 | case I915_FORMAT_MOD_X_TILED: | |
13949 | break; | |
13950 | default: | |
c0f40428 JB |
13951 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
13952 | mode_cmd->modifier[0]); | |
57cd6508 | 13953 | return -EINVAL; |
c16ed4be | 13954 | } |
57cd6508 | 13955 | |
b321803d DL |
13956 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
13957 | mode_cmd->pixel_format); | |
13958 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
13959 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
13960 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 13961 | return -EINVAL; |
c16ed4be | 13962 | } |
57cd6508 | 13963 | |
b321803d DL |
13964 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
13965 | mode_cmd->pixel_format); | |
a35cdaa0 | 13966 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
13967 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
13968 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 13969 | "tiled" : "linear", |
a35cdaa0 | 13970 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 13971 | return -EINVAL; |
c16ed4be | 13972 | } |
5d7bd705 | 13973 | |
2a80eada | 13974 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
13975 | mode_cmd->pitches[0] != obj->stride) { |
13976 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
13977 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 13978 | return -EINVAL; |
c16ed4be | 13979 | } |
5d7bd705 | 13980 | |
57779d06 | 13981 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 13982 | switch (mode_cmd->pixel_format) { |
57779d06 | 13983 | case DRM_FORMAT_C8: |
04b3924d VS |
13984 | case DRM_FORMAT_RGB565: |
13985 | case DRM_FORMAT_XRGB8888: | |
13986 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
13987 | break; |
13988 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 13989 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
13990 | DRM_DEBUG("unsupported pixel format: %s\n", |
13991 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 13992 | return -EINVAL; |
c16ed4be | 13993 | } |
57779d06 | 13994 | break; |
57779d06 | 13995 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
13996 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
13997 | DRM_DEBUG("unsupported pixel format: %s\n", | |
13998 | drm_get_format_name(mode_cmd->pixel_format)); | |
13999 | return -EINVAL; | |
14000 | } | |
14001 | break; | |
14002 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14003 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14004 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14005 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14006 | DRM_DEBUG("unsupported pixel format: %s\n", |
14007 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14008 | return -EINVAL; |
c16ed4be | 14009 | } |
b5626747 | 14010 | break; |
7531208b DL |
14011 | case DRM_FORMAT_ABGR2101010: |
14012 | if (!IS_VALLEYVIEW(dev)) { | |
14013 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14014 | drm_get_format_name(mode_cmd->pixel_format)); | |
14015 | return -EINVAL; | |
14016 | } | |
14017 | break; | |
04b3924d VS |
14018 | case DRM_FORMAT_YUYV: |
14019 | case DRM_FORMAT_UYVY: | |
14020 | case DRM_FORMAT_YVYU: | |
14021 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14022 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14023 | DRM_DEBUG("unsupported pixel format: %s\n", |
14024 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14025 | return -EINVAL; |
c16ed4be | 14026 | } |
57cd6508 CW |
14027 | break; |
14028 | default: | |
4ee62c76 VS |
14029 | DRM_DEBUG("unsupported pixel format: %s\n", |
14030 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14031 | return -EINVAL; |
14032 | } | |
14033 | ||
90f9a336 VS |
14034 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14035 | if (mode_cmd->offsets[0] != 0) | |
14036 | return -EINVAL; | |
14037 | ||
ec2c981e | 14038 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14039 | mode_cmd->pixel_format, |
14040 | mode_cmd->modifier[0]); | |
53155c0a DV |
14041 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14042 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14043 | return -EINVAL; | |
14044 | ||
c7d73f6a DV |
14045 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14046 | intel_fb->obj = obj; | |
80075d49 | 14047 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14048 | |
79e53945 JB |
14049 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14050 | if (ret) { | |
14051 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14052 | return ret; | |
14053 | } | |
14054 | ||
79e53945 JB |
14055 | return 0; |
14056 | } | |
14057 | ||
79e53945 JB |
14058 | static struct drm_framebuffer * |
14059 | intel_user_framebuffer_create(struct drm_device *dev, | |
14060 | struct drm_file *filp, | |
308e5bcb | 14061 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14062 | { |
05394f39 | 14063 | struct drm_i915_gem_object *obj; |
79e53945 | 14064 | |
308e5bcb JB |
14065 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14066 | mode_cmd->handles[0])); | |
c8725226 | 14067 | if (&obj->base == NULL) |
cce13ff7 | 14068 | return ERR_PTR(-ENOENT); |
79e53945 | 14069 | |
d2dff872 | 14070 | return intel_framebuffer_create(dev, mode_cmd, obj); |
79e53945 JB |
14071 | } |
14072 | ||
4520f53a | 14073 | #ifndef CONFIG_DRM_I915_FBDEV |
0632fef6 | 14074 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14075 | { |
14076 | } | |
14077 | #endif | |
14078 | ||
79e53945 | 14079 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14080 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14081 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14082 | .atomic_check = intel_atomic_check, |
14083 | .atomic_commit = intel_atomic_commit, | |
79e53945 JB |
14084 | }; |
14085 | ||
e70236a8 JB |
14086 | /* Set up chip specific display functions */ |
14087 | static void intel_init_display(struct drm_device *dev) | |
14088 | { | |
14089 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14090 | ||
ee9300bb DV |
14091 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14092 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14093 | else if (IS_CHERRYVIEW(dev)) |
14094 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14095 | else if (IS_VALLEYVIEW(dev)) |
14096 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14097 | else if (IS_PINEVIEW(dev)) | |
14098 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14099 | else | |
14100 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14101 | ||
bc8d7dff DL |
14102 | if (INTEL_INFO(dev)->gen >= 9) { |
14103 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14104 | dev_priv->display.get_initial_plane_config = |
14105 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14106 | dev_priv->display.crtc_compute_clock = |
14107 | haswell_crtc_compute_clock; | |
14108 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14109 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
14110 | dev_priv->display.off = ironlake_crtc_off; | |
14111 | dev_priv->display.update_primary_plane = | |
14112 | skylake_update_primary_plane; | |
14113 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14114 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14115 | dev_priv->display.get_initial_plane_config = |
14116 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14117 | dev_priv->display.crtc_compute_clock = |
14118 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14119 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14120 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
df8ad70c | 14121 | dev_priv->display.off = ironlake_crtc_off; |
bc8d7dff DL |
14122 | dev_priv->display.update_primary_plane = |
14123 | ironlake_update_primary_plane; | |
09b4ddf9 | 14124 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14125 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14126 | dev_priv->display.get_initial_plane_config = |
14127 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14128 | dev_priv->display.crtc_compute_clock = |
14129 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14130 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14131 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
ee7b9f93 | 14132 | dev_priv->display.off = ironlake_crtc_off; |
262ca2b0 MR |
14133 | dev_priv->display.update_primary_plane = |
14134 | ironlake_update_primary_plane; | |
89b667f8 JB |
14135 | } else if (IS_VALLEYVIEW(dev)) { |
14136 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14137 | dev_priv->display.get_initial_plane_config = |
14138 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14139 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14140 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14141 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
14142 | dev_priv->display.off = i9xx_crtc_off; | |
262ca2b0 MR |
14143 | dev_priv->display.update_primary_plane = |
14144 | i9xx_update_primary_plane; | |
f564048e | 14145 | } else { |
0e8ffe1b | 14146 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14147 | dev_priv->display.get_initial_plane_config = |
14148 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14149 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14150 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14151 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
ee7b9f93 | 14152 | dev_priv->display.off = i9xx_crtc_off; |
262ca2b0 MR |
14153 | dev_priv->display.update_primary_plane = |
14154 | i9xx_update_primary_plane; | |
f564048e | 14155 | } |
e70236a8 | 14156 | |
e70236a8 | 14157 | /* Returns the core display clock speed */ |
1652d19e VS |
14158 | if (IS_SKYLAKE(dev)) |
14159 | dev_priv->display.get_display_clock_speed = | |
14160 | skylake_get_display_clock_speed; | |
14161 | else if (IS_BROADWELL(dev)) | |
14162 | dev_priv->display.get_display_clock_speed = | |
14163 | broadwell_get_display_clock_speed; | |
14164 | else if (IS_HASWELL(dev)) | |
14165 | dev_priv->display.get_display_clock_speed = | |
14166 | haswell_get_display_clock_speed; | |
14167 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14168 | dev_priv->display.get_display_clock_speed = |
14169 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14170 | else if (IS_GEN5(dev)) |
14171 | dev_priv->display.get_display_clock_speed = | |
14172 | ilk_get_display_clock_speed; | |
a7c66cd8 VS |
14173 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
14174 | IS_GEN6(dev) || IS_IVYBRIDGE(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) | |
e70236a8 JB |
14175 | dev_priv->display.get_display_clock_speed = |
14176 | i945_get_display_clock_speed; | |
14177 | else if (IS_I915G(dev)) | |
14178 | dev_priv->display.get_display_clock_speed = | |
14179 | i915_get_display_clock_speed; | |
257a7ffc | 14180 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14181 | dev_priv->display.get_display_clock_speed = |
14182 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14183 | else if (IS_PINEVIEW(dev)) |
14184 | dev_priv->display.get_display_clock_speed = | |
14185 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14186 | else if (IS_I915GM(dev)) |
14187 | dev_priv->display.get_display_clock_speed = | |
14188 | i915gm_get_display_clock_speed; | |
14189 | else if (IS_I865G(dev)) | |
14190 | dev_priv->display.get_display_clock_speed = | |
14191 | i865_get_display_clock_speed; | |
f0f8a9ce | 14192 | else if (IS_I85X(dev)) |
e70236a8 JB |
14193 | dev_priv->display.get_display_clock_speed = |
14194 | i855_get_display_clock_speed; | |
14195 | else /* 852, 830 */ | |
14196 | dev_priv->display.get_display_clock_speed = | |
14197 | i830_get_display_clock_speed; | |
14198 | ||
7c10a2b5 | 14199 | if (IS_GEN5(dev)) { |
3bb11b53 | 14200 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14201 | } else if (IS_GEN6(dev)) { |
14202 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14203 | } else if (IS_IVYBRIDGE(dev)) { |
14204 | /* FIXME: detect B0+ stepping and use auto training */ | |
14205 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14206 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14207 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
30a970c6 JB |
14208 | } else if (IS_VALLEYVIEW(dev)) { |
14209 | dev_priv->display.modeset_global_resources = | |
14210 | valleyview_modeset_global_resources; | |
f8437dd1 VK |
14211 | } else if (IS_BROXTON(dev)) { |
14212 | dev_priv->display.modeset_global_resources = | |
14213 | broxton_modeset_global_resources; | |
e70236a8 | 14214 | } |
8c9f3aaf | 14215 | |
8c9f3aaf JB |
14216 | switch (INTEL_INFO(dev)->gen) { |
14217 | case 2: | |
14218 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14219 | break; | |
14220 | ||
14221 | case 3: | |
14222 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14223 | break; | |
14224 | ||
14225 | case 4: | |
14226 | case 5: | |
14227 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14228 | break; | |
14229 | ||
14230 | case 6: | |
14231 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14232 | break; | |
7c9017e5 | 14233 | case 7: |
4e0bbc31 | 14234 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14235 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14236 | break; | |
830c81db | 14237 | case 9: |
ba343e02 TU |
14238 | /* Drop through - unsupported since execlist only. */ |
14239 | default: | |
14240 | /* Default just returns -ENODEV to indicate unsupported */ | |
14241 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14242 | } |
7bd688cd JN |
14243 | |
14244 | intel_panel_init_backlight_funcs(dev); | |
e39b999a VS |
14245 | |
14246 | mutex_init(&dev_priv->pps_mutex); | |
e70236a8 JB |
14247 | } |
14248 | ||
b690e96c JB |
14249 | /* |
14250 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14251 | * resume, or other times. This quirk makes sure that's the case for | |
14252 | * affected systems. | |
14253 | */ | |
0206e353 | 14254 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14255 | { |
14256 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14257 | ||
14258 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14259 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14260 | } |
14261 | ||
b6b5d049 VS |
14262 | static void quirk_pipeb_force(struct drm_device *dev) |
14263 | { | |
14264 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14265 | ||
14266 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14267 | DRM_INFO("applying pipe b force quirk\n"); | |
14268 | } | |
14269 | ||
435793df KP |
14270 | /* |
14271 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14272 | */ | |
14273 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14274 | { | |
14275 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14276 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14277 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14278 | } |
14279 | ||
4dca20ef | 14280 | /* |
5a15ab5b CE |
14281 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14282 | * brightness value | |
4dca20ef CE |
14283 | */ |
14284 | static void quirk_invert_brightness(struct drm_device *dev) | |
14285 | { | |
14286 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14287 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14288 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14289 | } |
14290 | ||
9c72cc6f SD |
14291 | /* Some VBT's incorrectly indicate no backlight is present */ |
14292 | static void quirk_backlight_present(struct drm_device *dev) | |
14293 | { | |
14294 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14295 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14296 | DRM_INFO("applying backlight present quirk\n"); | |
14297 | } | |
14298 | ||
b690e96c JB |
14299 | struct intel_quirk { |
14300 | int device; | |
14301 | int subsystem_vendor; | |
14302 | int subsystem_device; | |
14303 | void (*hook)(struct drm_device *dev); | |
14304 | }; | |
14305 | ||
5f85f176 EE |
14306 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14307 | struct intel_dmi_quirk { | |
14308 | void (*hook)(struct drm_device *dev); | |
14309 | const struct dmi_system_id (*dmi_id_list)[]; | |
14310 | }; | |
14311 | ||
14312 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14313 | { | |
14314 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14315 | return 1; | |
14316 | } | |
14317 | ||
14318 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14319 | { | |
14320 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14321 | { | |
14322 | .callback = intel_dmi_reverse_brightness, | |
14323 | .ident = "NCR Corporation", | |
14324 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14325 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14326 | }, | |
14327 | }, | |
14328 | { } /* terminating entry */ | |
14329 | }, | |
14330 | .hook = quirk_invert_brightness, | |
14331 | }, | |
14332 | }; | |
14333 | ||
c43b5634 | 14334 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14335 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14336 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14337 | ||
b690e96c JB |
14338 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14339 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14340 | ||
5f080c0f VS |
14341 | /* 830 needs to leave pipe A & dpll A up */ |
14342 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14343 | ||
b6b5d049 VS |
14344 | /* 830 needs to leave pipe B & dpll B up */ |
14345 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14346 | ||
435793df KP |
14347 | /* Lenovo U160 cannot use SSC on LVDS */ |
14348 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14349 | |
14350 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14351 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14352 | |
be505f64 AH |
14353 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14354 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14355 | ||
14356 | /* Acer/eMachines G725 */ | |
14357 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14358 | ||
14359 | /* Acer/eMachines e725 */ | |
14360 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14361 | ||
14362 | /* Acer/Packard Bell NCL20 */ | |
14363 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14364 | ||
14365 | /* Acer Aspire 4736Z */ | |
14366 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14367 | |
14368 | /* Acer Aspire 5336 */ | |
14369 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14370 | |
14371 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14372 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14373 | |
dfb3d47b SD |
14374 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14375 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14376 | ||
b2a9601c | 14377 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14378 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14379 | ||
d4967d8c SD |
14380 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14381 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14382 | |
14383 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14384 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14385 | |
14386 | /* Dell Chromebook 11 */ | |
14387 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
14388 | }; |
14389 | ||
14390 | static void intel_init_quirks(struct drm_device *dev) | |
14391 | { | |
14392 | struct pci_dev *d = dev->pdev; | |
14393 | int i; | |
14394 | ||
14395 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14396 | struct intel_quirk *q = &intel_quirks[i]; | |
14397 | ||
14398 | if (d->device == q->device && | |
14399 | (d->subsystem_vendor == q->subsystem_vendor || | |
14400 | q->subsystem_vendor == PCI_ANY_ID) && | |
14401 | (d->subsystem_device == q->subsystem_device || | |
14402 | q->subsystem_device == PCI_ANY_ID)) | |
14403 | q->hook(dev); | |
14404 | } | |
5f85f176 EE |
14405 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14406 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14407 | intel_dmi_quirks[i].hook(dev); | |
14408 | } | |
b690e96c JB |
14409 | } |
14410 | ||
9cce37f4 JB |
14411 | /* Disable the VGA plane that we never use */ |
14412 | static void i915_disable_vga(struct drm_device *dev) | |
14413 | { | |
14414 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14415 | u8 sr1; | |
766aa1c4 | 14416 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 14417 | |
2b37c616 | 14418 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 14419 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 14420 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
14421 | sr1 = inb(VGA_SR_DATA); |
14422 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
14423 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
14424 | udelay(300); | |
14425 | ||
01f5a626 | 14426 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
14427 | POSTING_READ(vga_reg); |
14428 | } | |
14429 | ||
f817586c DV |
14430 | void intel_modeset_init_hw(struct drm_device *dev) |
14431 | { | |
a8f78b58 ED |
14432 | intel_prepare_ddi(dev); |
14433 | ||
f8bf63fd VS |
14434 | if (IS_VALLEYVIEW(dev)) |
14435 | vlv_update_cdclk(dev); | |
14436 | ||
f817586c DV |
14437 | intel_init_clock_gating(dev); |
14438 | ||
8090c6b9 | 14439 | intel_enable_gt_powersave(dev); |
f817586c DV |
14440 | } |
14441 | ||
79e53945 JB |
14442 | void intel_modeset_init(struct drm_device *dev) |
14443 | { | |
652c393a | 14444 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 14445 | int sprite, ret; |
8cc87b75 | 14446 | enum pipe pipe; |
46f297fb | 14447 | struct intel_crtc *crtc; |
79e53945 JB |
14448 | |
14449 | drm_mode_config_init(dev); | |
14450 | ||
14451 | dev->mode_config.min_width = 0; | |
14452 | dev->mode_config.min_height = 0; | |
14453 | ||
019d96cb DA |
14454 | dev->mode_config.preferred_depth = 24; |
14455 | dev->mode_config.prefer_shadow = 1; | |
14456 | ||
25bab385 TU |
14457 | dev->mode_config.allow_fb_modifiers = true; |
14458 | ||
e6ecefaa | 14459 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 14460 | |
b690e96c JB |
14461 | intel_init_quirks(dev); |
14462 | ||
1fa61106 ED |
14463 | intel_init_pm(dev); |
14464 | ||
e3c74757 BW |
14465 | if (INTEL_INFO(dev)->num_pipes == 0) |
14466 | return; | |
14467 | ||
e70236a8 | 14468 | intel_init_display(dev); |
7c10a2b5 | 14469 | intel_init_audio(dev); |
e70236a8 | 14470 | |
a6c45cf0 CW |
14471 | if (IS_GEN2(dev)) { |
14472 | dev->mode_config.max_width = 2048; | |
14473 | dev->mode_config.max_height = 2048; | |
14474 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
14475 | dev->mode_config.max_width = 4096; |
14476 | dev->mode_config.max_height = 4096; | |
79e53945 | 14477 | } else { |
a6c45cf0 CW |
14478 | dev->mode_config.max_width = 8192; |
14479 | dev->mode_config.max_height = 8192; | |
79e53945 | 14480 | } |
068be561 | 14481 | |
dc41c154 VS |
14482 | if (IS_845G(dev) || IS_I865G(dev)) { |
14483 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
14484 | dev->mode_config.cursor_height = 1023; | |
14485 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
14486 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
14487 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
14488 | } else { | |
14489 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
14490 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
14491 | } | |
14492 | ||
5d4545ae | 14493 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 14494 | |
28c97730 | 14495 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
14496 | INTEL_INFO(dev)->num_pipes, |
14497 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 14498 | |
055e393f | 14499 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 14500 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 14501 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 14502 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 14503 | if (ret) |
06da8da2 | 14504 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 14505 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 14506 | } |
79e53945 JB |
14507 | } |
14508 | ||
f42bb70d JB |
14509 | intel_init_dpio(dev); |
14510 | ||
e72f9fbf | 14511 | intel_shared_dpll_init(dev); |
ee7b9f93 | 14512 | |
9cce37f4 JB |
14513 | /* Just disable it once at startup */ |
14514 | i915_disable_vga(dev); | |
79e53945 | 14515 | intel_setup_outputs(dev); |
11be49eb CW |
14516 | |
14517 | /* Just in case the BIOS is doing something questionable. */ | |
7ff0ebcc | 14518 | intel_fbc_disable(dev); |
fa9fa083 | 14519 | |
6e9f798d | 14520 | drm_modeset_lock_all(dev); |
fa9fa083 | 14521 | intel_modeset_setup_hw_state(dev, false); |
6e9f798d | 14522 | drm_modeset_unlock_all(dev); |
46f297fb | 14523 | |
d3fcc808 | 14524 | for_each_intel_crtc(dev, crtc) { |
46f297fb JB |
14525 | if (!crtc->active) |
14526 | continue; | |
14527 | ||
46f297fb | 14528 | /* |
46f297fb JB |
14529 | * Note that reserving the BIOS fb up front prevents us |
14530 | * from stuffing other stolen allocations like the ring | |
14531 | * on top. This prevents some ugliness at boot time, and | |
14532 | * can even allow for smooth boot transitions if the BIOS | |
14533 | * fb is large enough for the active pipe configuration. | |
14534 | */ | |
5724dbd1 DL |
14535 | if (dev_priv->display.get_initial_plane_config) { |
14536 | dev_priv->display.get_initial_plane_config(crtc, | |
46f297fb JB |
14537 | &crtc->plane_config); |
14538 | /* | |
14539 | * If the fb is shared between multiple heads, we'll | |
14540 | * just get the first one. | |
14541 | */ | |
f6936e29 | 14542 | intel_find_initial_plane_obj(crtc, &crtc->plane_config); |
46f297fb | 14543 | } |
46f297fb | 14544 | } |
2c7111db CW |
14545 | } |
14546 | ||
7fad798e DV |
14547 | static void intel_enable_pipe_a(struct drm_device *dev) |
14548 | { | |
14549 | struct intel_connector *connector; | |
14550 | struct drm_connector *crt = NULL; | |
14551 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 14552 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
14553 | |
14554 | /* We can't just switch on the pipe A, we need to set things up with a | |
14555 | * proper mode and output configuration. As a gross hack, enable pipe A | |
14556 | * by enabling the load detect pipe once. */ | |
3a3371ff | 14557 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
14558 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
14559 | crt = &connector->base; | |
14560 | break; | |
14561 | } | |
14562 | } | |
14563 | ||
14564 | if (!crt) | |
14565 | return; | |
14566 | ||
208bf9fd | 14567 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 14568 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
14569 | } |
14570 | ||
fa555837 DV |
14571 | static bool |
14572 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
14573 | { | |
7eb552ae BW |
14574 | struct drm_device *dev = crtc->base.dev; |
14575 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 DV |
14576 | u32 reg, val; |
14577 | ||
7eb552ae | 14578 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
14579 | return true; |
14580 | ||
14581 | reg = DSPCNTR(!crtc->plane); | |
14582 | val = I915_READ(reg); | |
14583 | ||
14584 | if ((val & DISPLAY_PLANE_ENABLE) && | |
14585 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
14586 | return false; | |
14587 | ||
14588 | return true; | |
14589 | } | |
14590 | ||
24929352 DV |
14591 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
14592 | { | |
14593 | struct drm_device *dev = crtc->base.dev; | |
14594 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 | 14595 | u32 reg; |
24929352 | 14596 | |
24929352 | 14597 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 14598 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
14599 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
14600 | ||
d3eaf884 | 14601 | /* restore vblank interrupts to correct state */ |
9625604c | 14602 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 VS |
14603 | if (crtc->active) { |
14604 | update_scanline_offset(crtc); | |
9625604c DV |
14605 | drm_crtc_vblank_on(&crtc->base); |
14606 | } | |
d3eaf884 | 14607 | |
24929352 | 14608 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
14609 | * disable the crtc (and hence change the state) if it is wrong. Note |
14610 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
14611 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
14612 | struct intel_connector *connector; |
14613 | bool plane; | |
14614 | ||
24929352 DV |
14615 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
14616 | crtc->base.base.id); | |
14617 | ||
14618 | /* Pipe has the wrong plane attached and the plane is active. | |
14619 | * Temporarily change the plane mapping and disable everything | |
14620 | * ... */ | |
14621 | plane = crtc->plane; | |
b70709a6 | 14622 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 14623 | crtc->plane = !plane; |
ce22dba9 | 14624 | intel_crtc_disable_planes(&crtc->base); |
24929352 DV |
14625 | dev_priv->display.crtc_disable(&crtc->base); |
14626 | crtc->plane = plane; | |
14627 | ||
14628 | /* ... and break all links. */ | |
3a3371ff | 14629 | for_each_intel_connector(dev, connector) { |
24929352 DV |
14630 | if (connector->encoder->base.crtc != &crtc->base) |
14631 | continue; | |
14632 | ||
7f1950fb EE |
14633 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
14634 | connector->base.encoder = NULL; | |
24929352 | 14635 | } |
7f1950fb EE |
14636 | /* multiple connectors may have the same encoder: |
14637 | * handle them and break crtc link separately */ | |
3a3371ff | 14638 | for_each_intel_connector(dev, connector) |
7f1950fb EE |
14639 | if (connector->encoder->base.crtc == &crtc->base) { |
14640 | connector->encoder->base.crtc = NULL; | |
14641 | connector->encoder->connectors_active = false; | |
14642 | } | |
24929352 DV |
14643 | |
14644 | WARN_ON(crtc->active); | |
83d65738 | 14645 | crtc->base.state->enable = false; |
49d6fa21 | 14646 | crtc->base.state->active = false; |
24929352 DV |
14647 | crtc->base.enabled = false; |
14648 | } | |
24929352 | 14649 | |
7fad798e DV |
14650 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
14651 | crtc->pipe == PIPE_A && !crtc->active) { | |
14652 | /* BIOS forgot to enable pipe A, this mostly happens after | |
14653 | * resume. Force-enable the pipe to fix this, the update_dpms | |
14654 | * call below we restore the pipe to the right state, but leave | |
14655 | * the required bits on. */ | |
14656 | intel_enable_pipe_a(dev); | |
14657 | } | |
14658 | ||
24929352 DV |
14659 | /* Adjust the state of the output pipe according to whether we |
14660 | * have active connectors/encoders. */ | |
14661 | intel_crtc_update_dpms(&crtc->base); | |
14662 | ||
83d65738 | 14663 | if (crtc->active != crtc->base.state->enable) { |
24929352 DV |
14664 | struct intel_encoder *encoder; |
14665 | ||
14666 | /* This can happen either due to bugs in the get_hw_state | |
14667 | * functions or because the pipe is force-enabled due to the | |
14668 | * pipe A quirk. */ | |
14669 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
14670 | crtc->base.base.id, | |
83d65738 | 14671 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
14672 | crtc->active ? "enabled" : "disabled"); |
14673 | ||
83d65738 | 14674 | crtc->base.state->enable = crtc->active; |
49d6fa21 | 14675 | crtc->base.state->active = crtc->active; |
24929352 DV |
14676 | crtc->base.enabled = crtc->active; |
14677 | ||
14678 | /* Because we only establish the connector -> encoder -> | |
14679 | * crtc links if something is active, this means the | |
14680 | * crtc is now deactivated. Break the links. connector | |
14681 | * -> encoder links are only establish when things are | |
14682 | * actually up, hence no need to break them. */ | |
14683 | WARN_ON(crtc->active); | |
14684 | ||
14685 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { | |
14686 | WARN_ON(encoder->connectors_active); | |
14687 | encoder->base.crtc = NULL; | |
14688 | } | |
14689 | } | |
c5ab3bc0 | 14690 | |
a3ed6aad | 14691 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
14692 | /* |
14693 | * We start out with underrun reporting disabled to avoid races. | |
14694 | * For correct bookkeeping mark this on active crtcs. | |
14695 | * | |
c5ab3bc0 DV |
14696 | * Also on gmch platforms we dont have any hardware bits to |
14697 | * disable the underrun reporting. Which means we need to start | |
14698 | * out with underrun reporting disabled also on inactive pipes, | |
14699 | * since otherwise we'll complain about the garbage we read when | |
14700 | * e.g. coming up after runtime pm. | |
14701 | * | |
4cc31489 DV |
14702 | * No protection against concurrent access is required - at |
14703 | * worst a fifo underrun happens which also sets this to false. | |
14704 | */ | |
14705 | crtc->cpu_fifo_underrun_disabled = true; | |
14706 | crtc->pch_fifo_underrun_disabled = true; | |
14707 | } | |
24929352 DV |
14708 | } |
14709 | ||
14710 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
14711 | { | |
14712 | struct intel_connector *connector; | |
14713 | struct drm_device *dev = encoder->base.dev; | |
14714 | ||
14715 | /* We need to check both for a crtc link (meaning that the | |
14716 | * encoder is active and trying to read from a pipe) and the | |
14717 | * pipe itself being active. */ | |
14718 | bool has_active_crtc = encoder->base.crtc && | |
14719 | to_intel_crtc(encoder->base.crtc)->active; | |
14720 | ||
14721 | if (encoder->connectors_active && !has_active_crtc) { | |
14722 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", | |
14723 | encoder->base.base.id, | |
8e329a03 | 14724 | encoder->base.name); |
24929352 DV |
14725 | |
14726 | /* Connector is active, but has no active pipe. This is | |
14727 | * fallout from our resume register restoring. Disable | |
14728 | * the encoder manually again. */ | |
14729 | if (encoder->base.crtc) { | |
14730 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
14731 | encoder->base.base.id, | |
8e329a03 | 14732 | encoder->base.name); |
24929352 | 14733 | encoder->disable(encoder); |
a62d1497 VS |
14734 | if (encoder->post_disable) |
14735 | encoder->post_disable(encoder); | |
24929352 | 14736 | } |
7f1950fb EE |
14737 | encoder->base.crtc = NULL; |
14738 | encoder->connectors_active = false; | |
24929352 DV |
14739 | |
14740 | /* Inconsistent output/port/pipe state happens presumably due to | |
14741 | * a bug in one of the get_hw_state functions. Or someplace else | |
14742 | * in our code, like the register restore mess on resume. Clamp | |
14743 | * things to off as a safer default. */ | |
3a3371ff | 14744 | for_each_intel_connector(dev, connector) { |
24929352 DV |
14745 | if (connector->encoder != encoder) |
14746 | continue; | |
7f1950fb EE |
14747 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
14748 | connector->base.encoder = NULL; | |
24929352 DV |
14749 | } |
14750 | } | |
14751 | /* Enabled encoders without active connectors will be fixed in | |
14752 | * the crtc fixup. */ | |
14753 | } | |
14754 | ||
04098753 | 14755 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
14756 | { |
14757 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 14758 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 14759 | |
04098753 ID |
14760 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
14761 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
14762 | i915_disable_vga(dev); | |
14763 | } | |
14764 | } | |
14765 | ||
14766 | void i915_redisable_vga(struct drm_device *dev) | |
14767 | { | |
14768 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14769 | ||
8dc8a27c PZ |
14770 | /* This function can be called both from intel_modeset_setup_hw_state or |
14771 | * at a very early point in our resume sequence, where the power well | |
14772 | * structures are not yet restored. Since this function is at a very | |
14773 | * paranoid "someone might have enabled VGA while we were not looking" | |
14774 | * level, just check if the power well is enabled instead of trying to | |
14775 | * follow the "don't touch the power well if we don't need it" policy | |
14776 | * the rest of the driver uses. */ | |
f458ebbc | 14777 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
14778 | return; |
14779 | ||
04098753 | 14780 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
14781 | } |
14782 | ||
98ec7739 VS |
14783 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
14784 | { | |
14785 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
14786 | ||
14787 | if (!crtc->active) | |
14788 | return false; | |
14789 | ||
14790 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; | |
14791 | } | |
14792 | ||
30e984df | 14793 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
14794 | { |
14795 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14796 | enum pipe pipe; | |
24929352 DV |
14797 | struct intel_crtc *crtc; |
14798 | struct intel_encoder *encoder; | |
14799 | struct intel_connector *connector; | |
5358901f | 14800 | int i; |
24929352 | 14801 | |
d3fcc808 | 14802 | for_each_intel_crtc(dev, crtc) { |
b70709a6 ML |
14803 | struct drm_plane *primary = crtc->base.primary; |
14804 | struct intel_plane_state *plane_state; | |
14805 | ||
6e3c9717 | 14806 | memset(crtc->config, 0, sizeof(*crtc->config)); |
3b117c8f | 14807 | |
6e3c9717 | 14808 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
9953599b | 14809 | |
0e8ffe1b | 14810 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 14811 | crtc->config); |
24929352 | 14812 | |
83d65738 | 14813 | crtc->base.state->enable = crtc->active; |
49d6fa21 | 14814 | crtc->base.state->active = crtc->active; |
24929352 | 14815 | crtc->base.enabled = crtc->active; |
b70709a6 ML |
14816 | |
14817 | plane_state = to_intel_plane_state(primary->state); | |
14818 | plane_state->visible = primary_get_hw_state(crtc); | |
24929352 DV |
14819 | |
14820 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
14821 | crtc->base.base.id, | |
14822 | crtc->active ? "enabled" : "disabled"); | |
14823 | } | |
14824 | ||
5358901f DV |
14825 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
14826 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
14827 | ||
3e369b76 ACO |
14828 | pll->on = pll->get_hw_state(dev_priv, pll, |
14829 | &pll->config.hw_state); | |
5358901f | 14830 | pll->active = 0; |
3e369b76 | 14831 | pll->config.crtc_mask = 0; |
d3fcc808 | 14832 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 14833 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 14834 | pll->active++; |
3e369b76 | 14835 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 14836 | } |
5358901f | 14837 | } |
5358901f | 14838 | |
1e6f2ddc | 14839 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 14840 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 14841 | |
3e369b76 | 14842 | if (pll->config.crtc_mask) |
bd2bb1b9 | 14843 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
14844 | } |
14845 | ||
b2784e15 | 14846 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
14847 | pipe = 0; |
14848 | ||
14849 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
14850 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
14851 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 14852 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
14853 | } else { |
14854 | encoder->base.crtc = NULL; | |
14855 | } | |
14856 | ||
14857 | encoder->connectors_active = false; | |
6f2bcceb | 14858 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 14859 | encoder->base.base.id, |
8e329a03 | 14860 | encoder->base.name, |
24929352 | 14861 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 14862 | pipe_name(pipe)); |
24929352 DV |
14863 | } |
14864 | ||
3a3371ff | 14865 | for_each_intel_connector(dev, connector) { |
24929352 DV |
14866 | if (connector->get_hw_state(connector)) { |
14867 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
14868 | connector->encoder->connectors_active = true; | |
14869 | connector->base.encoder = &connector->encoder->base; | |
14870 | } else { | |
14871 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
14872 | connector->base.encoder = NULL; | |
14873 | } | |
14874 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
14875 | connector->base.base.id, | |
c23cc417 | 14876 | connector->base.name, |
24929352 DV |
14877 | connector->base.encoder ? "enabled" : "disabled"); |
14878 | } | |
30e984df DV |
14879 | } |
14880 | ||
14881 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm | |
14882 | * and i915 state tracking structures. */ | |
14883 | void intel_modeset_setup_hw_state(struct drm_device *dev, | |
14884 | bool force_restore) | |
14885 | { | |
14886 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14887 | enum pipe pipe; | |
30e984df DV |
14888 | struct intel_crtc *crtc; |
14889 | struct intel_encoder *encoder; | |
35c95375 | 14890 | int i; |
30e984df DV |
14891 | |
14892 | intel_modeset_readout_hw_state(dev); | |
24929352 | 14893 | |
babea61d JB |
14894 | /* |
14895 | * Now that we have the config, copy it to each CRTC struct | |
14896 | * Note that this could go away if we move to using crtc_config | |
14897 | * checking everywhere. | |
14898 | */ | |
d3fcc808 | 14899 | for_each_intel_crtc(dev, crtc) { |
d330a953 | 14900 | if (crtc->active && i915.fastboot) { |
6e3c9717 ACO |
14901 | intel_mode_from_pipe_config(&crtc->base.mode, |
14902 | crtc->config); | |
babea61d JB |
14903 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
14904 | crtc->base.base.id); | |
14905 | drm_mode_debug_printmodeline(&crtc->base.mode); | |
14906 | } | |
14907 | } | |
14908 | ||
24929352 | 14909 | /* HW state is read out, now we need to sanitize this mess. */ |
b2784e15 | 14910 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
14911 | intel_sanitize_encoder(encoder); |
14912 | } | |
14913 | ||
055e393f | 14914 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
14915 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
14916 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
14917 | intel_dump_pipe_config(crtc, crtc->config, |
14918 | "[setup_hw_state]"); | |
24929352 | 14919 | } |
9a935856 | 14920 | |
d29b2f9d ACO |
14921 | intel_modeset_update_connector_atomic_state(dev); |
14922 | ||
35c95375 DV |
14923 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
14924 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
14925 | ||
14926 | if (!pll->on || pll->active) | |
14927 | continue; | |
14928 | ||
14929 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
14930 | ||
14931 | pll->disable(dev_priv, pll); | |
14932 | pll->on = false; | |
14933 | } | |
14934 | ||
3078999f PB |
14935 | if (IS_GEN9(dev)) |
14936 | skl_wm_get_hw_state(dev); | |
14937 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 VS |
14938 | ilk_wm_get_hw_state(dev); |
14939 | ||
45e2b5f6 | 14940 | if (force_restore) { |
7d0bc1ea VS |
14941 | i915_redisable_vga(dev); |
14942 | ||
f30da187 DV |
14943 | /* |
14944 | * We need to use raw interfaces for restoring state to avoid | |
14945 | * checking (bogus) intermediate states. | |
14946 | */ | |
055e393f | 14947 | for_each_pipe(dev_priv, pipe) { |
b5644d05 JB |
14948 | struct drm_crtc *crtc = |
14949 | dev_priv->pipe_to_crtc_mapping[pipe]; | |
f30da187 | 14950 | |
83a57153 | 14951 | intel_crtc_restore_mode(crtc); |
45e2b5f6 DV |
14952 | } |
14953 | } else { | |
14954 | intel_modeset_update_staged_output_state(dev); | |
14955 | } | |
8af6cf88 DV |
14956 | |
14957 | intel_modeset_check_state(dev); | |
2c7111db CW |
14958 | } |
14959 | ||
14960 | void intel_modeset_gem_init(struct drm_device *dev) | |
14961 | { | |
92122789 | 14962 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd | 14963 | struct drm_crtc *c; |
2ff8fde1 | 14964 | struct drm_i915_gem_object *obj; |
e0d6149b | 14965 | int ret; |
484b41dd | 14966 | |
ae48434c ID |
14967 | mutex_lock(&dev->struct_mutex); |
14968 | intel_init_gt_powersave(dev); | |
14969 | mutex_unlock(&dev->struct_mutex); | |
14970 | ||
92122789 JB |
14971 | /* |
14972 | * There may be no VBT; and if the BIOS enabled SSC we can | |
14973 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
14974 | * BIOS isn't using it, don't assume it will work even if the VBT | |
14975 | * indicates as much. | |
14976 | */ | |
14977 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
14978 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
14979 | DREF_SSC1_ENABLE); | |
14980 | ||
1833b134 | 14981 | intel_modeset_init_hw(dev); |
02e792fb DV |
14982 | |
14983 | intel_setup_overlay(dev); | |
484b41dd JB |
14984 | |
14985 | /* | |
14986 | * Make sure any fbs we allocated at startup are properly | |
14987 | * pinned & fenced. When we do the allocation it's too early | |
14988 | * for this. | |
14989 | */ | |
70e1e0ec | 14990 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
14991 | obj = intel_fb_obj(c->primary->fb); |
14992 | if (obj == NULL) | |
484b41dd JB |
14993 | continue; |
14994 | ||
e0d6149b TU |
14995 | mutex_lock(&dev->struct_mutex); |
14996 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
14997 | c->primary->fb, | |
14998 | c->primary->state, | |
14999 | NULL); | |
15000 | mutex_unlock(&dev->struct_mutex); | |
15001 | if (ret) { | |
484b41dd JB |
15002 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15003 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15004 | drm_framebuffer_unreference(c->primary->fb); |
15005 | c->primary->fb = NULL; | |
afd65eb4 | 15006 | update_state_fb(c->primary); |
484b41dd JB |
15007 | } |
15008 | } | |
0962c3c9 VS |
15009 | |
15010 | intel_backlight_register(dev); | |
79e53945 JB |
15011 | } |
15012 | ||
4932e2c3 ID |
15013 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15014 | { | |
15015 | struct drm_connector *connector = &intel_connector->base; | |
15016 | ||
15017 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15018 | drm_connector_unregister(connector); |
4932e2c3 ID |
15019 | } |
15020 | ||
79e53945 JB |
15021 | void intel_modeset_cleanup(struct drm_device *dev) |
15022 | { | |
652c393a | 15023 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15024 | struct drm_connector *connector; |
652c393a | 15025 | |
2eb5252e ID |
15026 | intel_disable_gt_powersave(dev); |
15027 | ||
0962c3c9 VS |
15028 | intel_backlight_unregister(dev); |
15029 | ||
fd0c0642 DV |
15030 | /* |
15031 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15032 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15033 | * experience fancy races otherwise. |
15034 | */ | |
2aeb7d3a | 15035 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15036 | |
fd0c0642 DV |
15037 | /* |
15038 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15039 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15040 | */ | |
f87ea761 | 15041 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15042 | |
652c393a JB |
15043 | mutex_lock(&dev->struct_mutex); |
15044 | ||
723bfd70 JB |
15045 | intel_unregister_dsm_handler(); |
15046 | ||
7ff0ebcc | 15047 | intel_fbc_disable(dev); |
e70236a8 | 15048 | |
69341a5e KH |
15049 | mutex_unlock(&dev->struct_mutex); |
15050 | ||
1630fe75 CW |
15051 | /* flush any delayed tasks or pending work */ |
15052 | flush_scheduled_work(); | |
15053 | ||
db31af1d JN |
15054 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15055 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15056 | struct intel_connector *intel_connector; |
15057 | ||
15058 | intel_connector = to_intel_connector(connector); | |
15059 | intel_connector->unregister(intel_connector); | |
db31af1d | 15060 | } |
d9255d57 | 15061 | |
79e53945 | 15062 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15063 | |
15064 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15065 | |
15066 | mutex_lock(&dev->struct_mutex); | |
15067 | intel_cleanup_gt_powersave(dev); | |
15068 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15069 | } |
15070 | ||
f1c79df3 ZW |
15071 | /* |
15072 | * Return which encoder is currently attached for connector. | |
15073 | */ | |
df0e9248 | 15074 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15075 | { |
df0e9248 CW |
15076 | return &intel_attached_encoder(connector)->base; |
15077 | } | |
f1c79df3 | 15078 | |
df0e9248 CW |
15079 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15080 | struct intel_encoder *encoder) | |
15081 | { | |
15082 | connector->encoder = encoder; | |
15083 | drm_mode_connector_attach_encoder(&connector->base, | |
15084 | &encoder->base); | |
79e53945 | 15085 | } |
28d52043 DA |
15086 | |
15087 | /* | |
15088 | * set vga decode state - true == enable VGA decode | |
15089 | */ | |
15090 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15091 | { | |
15092 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15093 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15094 | u16 gmch_ctrl; |
15095 | ||
75fa041d CW |
15096 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15097 | DRM_ERROR("failed to read control word\n"); | |
15098 | return -EIO; | |
15099 | } | |
15100 | ||
c0cc8a55 CW |
15101 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15102 | return 0; | |
15103 | ||
28d52043 DA |
15104 | if (state) |
15105 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15106 | else | |
15107 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15108 | |
15109 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15110 | DRM_ERROR("failed to write control word\n"); | |
15111 | return -EIO; | |
15112 | } | |
15113 | ||
28d52043 DA |
15114 | return 0; |
15115 | } | |
c4a1d9e4 | 15116 | |
c4a1d9e4 | 15117 | struct intel_display_error_state { |
ff57f1b0 PZ |
15118 | |
15119 | u32 power_well_driver; | |
15120 | ||
63b66e5b CW |
15121 | int num_transcoders; |
15122 | ||
c4a1d9e4 CW |
15123 | struct intel_cursor_error_state { |
15124 | u32 control; | |
15125 | u32 position; | |
15126 | u32 base; | |
15127 | u32 size; | |
52331309 | 15128 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15129 | |
15130 | struct intel_pipe_error_state { | |
ddf9c536 | 15131 | bool power_domain_on; |
c4a1d9e4 | 15132 | u32 source; |
f301b1e1 | 15133 | u32 stat; |
52331309 | 15134 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15135 | |
15136 | struct intel_plane_error_state { | |
15137 | u32 control; | |
15138 | u32 stride; | |
15139 | u32 size; | |
15140 | u32 pos; | |
15141 | u32 addr; | |
15142 | u32 surface; | |
15143 | u32 tile_offset; | |
52331309 | 15144 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15145 | |
15146 | struct intel_transcoder_error_state { | |
ddf9c536 | 15147 | bool power_domain_on; |
63b66e5b CW |
15148 | enum transcoder cpu_transcoder; |
15149 | ||
15150 | u32 conf; | |
15151 | ||
15152 | u32 htotal; | |
15153 | u32 hblank; | |
15154 | u32 hsync; | |
15155 | u32 vtotal; | |
15156 | u32 vblank; | |
15157 | u32 vsync; | |
15158 | } transcoder[4]; | |
c4a1d9e4 CW |
15159 | }; |
15160 | ||
15161 | struct intel_display_error_state * | |
15162 | intel_display_capture_error_state(struct drm_device *dev) | |
15163 | { | |
fbee40df | 15164 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15165 | struct intel_display_error_state *error; |
63b66e5b CW |
15166 | int transcoders[] = { |
15167 | TRANSCODER_A, | |
15168 | TRANSCODER_B, | |
15169 | TRANSCODER_C, | |
15170 | TRANSCODER_EDP, | |
15171 | }; | |
c4a1d9e4 CW |
15172 | int i; |
15173 | ||
63b66e5b CW |
15174 | if (INTEL_INFO(dev)->num_pipes == 0) |
15175 | return NULL; | |
15176 | ||
9d1cb914 | 15177 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15178 | if (error == NULL) |
15179 | return NULL; | |
15180 | ||
190be112 | 15181 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15182 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15183 | ||
055e393f | 15184 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15185 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15186 | __intel_display_power_is_enabled(dev_priv, |
15187 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15188 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15189 | continue; |
15190 | ||
5efb3e28 VS |
15191 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15192 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15193 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15194 | |
15195 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15196 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15197 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15198 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15199 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15200 | } | |
ca291363 PZ |
15201 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15202 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15203 | if (INTEL_INFO(dev)->gen >= 4) { |
15204 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15205 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15206 | } | |
15207 | ||
c4a1d9e4 | 15208 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15209 | |
3abfce77 | 15210 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15211 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15212 | } |
15213 | ||
15214 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15215 | if (HAS_DDI(dev_priv->dev)) | |
15216 | error->num_transcoders++; /* Account for eDP. */ | |
15217 | ||
15218 | for (i = 0; i < error->num_transcoders; i++) { | |
15219 | enum transcoder cpu_transcoder = transcoders[i]; | |
15220 | ||
ddf9c536 | 15221 | error->transcoder[i].power_domain_on = |
f458ebbc | 15222 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15223 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15224 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15225 | continue; |
15226 | ||
63b66e5b CW |
15227 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15228 | ||
15229 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15230 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15231 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15232 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15233 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15234 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15235 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15236 | } |
15237 | ||
15238 | return error; | |
15239 | } | |
15240 | ||
edc3d884 MK |
15241 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15242 | ||
c4a1d9e4 | 15243 | void |
edc3d884 | 15244 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15245 | struct drm_device *dev, |
15246 | struct intel_display_error_state *error) | |
15247 | { | |
055e393f | 15248 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15249 | int i; |
15250 | ||
63b66e5b CW |
15251 | if (!error) |
15252 | return; | |
15253 | ||
edc3d884 | 15254 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15255 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15256 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15257 | error->power_well_driver); |
055e393f | 15258 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15259 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15260 | err_printf(m, " Power: %s\n", |
15261 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15262 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15263 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15264 | |
15265 | err_printf(m, "Plane [%d]:\n", i); | |
15266 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15267 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15268 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15269 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15270 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15271 | } |
4b71a570 | 15272 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15273 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15274 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15275 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15276 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15277 | } |
15278 | ||
edc3d884 MK |
15279 | err_printf(m, "Cursor [%d]:\n", i); |
15280 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15281 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15282 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15283 | } |
63b66e5b CW |
15284 | |
15285 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15286 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15287 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15288 | err_printf(m, " Power: %s\n", |
15289 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15290 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15291 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15292 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15293 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15294 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15295 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15296 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15297 | } | |
c4a1d9e4 | 15298 | } |
e2fcdaa9 VS |
15299 | |
15300 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
15301 | { | |
15302 | struct intel_crtc *crtc; | |
15303 | ||
15304 | for_each_intel_crtc(dev, crtc) { | |
15305 | struct intel_unpin_work *work; | |
e2fcdaa9 | 15306 | |
5e2d7afc | 15307 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15308 | |
15309 | work = crtc->unpin_work; | |
15310 | ||
15311 | if (work && work->event && | |
15312 | work->event->base.file_priv == file) { | |
15313 | kfree(work->event); | |
15314 | work->event = NULL; | |
15315 | } | |
15316 | ||
5e2d7afc | 15317 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15318 | } |
15319 | } |