blob: 78bf7374fbdde073f96c371125d21190207ed13e [file] [log] [blame]
Chris Wilson94b4f3b2016-07-05 10:40:20 +01001/*
2 * Copyright © 2016 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 DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
25#include "i915_drv.h"
26
Jani Nikula2e0d26f2016-12-01 14:49:55 +020027#define PLATFORM_NAME(x) [INTEL_##x] = #x
28static const char * const platform_names[] = {
29 PLATFORM_NAME(I830),
30 PLATFORM_NAME(I845G),
31 PLATFORM_NAME(I85X),
32 PLATFORM_NAME(I865G),
33 PLATFORM_NAME(I915G),
34 PLATFORM_NAME(I915GM),
35 PLATFORM_NAME(I945G),
36 PLATFORM_NAME(I945GM),
37 PLATFORM_NAME(G33),
38 PLATFORM_NAME(PINEVIEW),
Jani Nikulac0f86832016-12-07 12:13:04 +020039 PLATFORM_NAME(I965G),
40 PLATFORM_NAME(I965GM),
Jani Nikulaf69c11a2016-11-30 17:43:05 +020041 PLATFORM_NAME(G45),
42 PLATFORM_NAME(GM45),
Jani Nikula2e0d26f2016-12-01 14:49:55 +020043 PLATFORM_NAME(IRONLAKE),
44 PLATFORM_NAME(SANDYBRIDGE),
45 PLATFORM_NAME(IVYBRIDGE),
46 PLATFORM_NAME(VALLEYVIEW),
47 PLATFORM_NAME(HASWELL),
48 PLATFORM_NAME(BROADWELL),
49 PLATFORM_NAME(CHERRYVIEW),
50 PLATFORM_NAME(SKYLAKE),
51 PLATFORM_NAME(BROXTON),
52 PLATFORM_NAME(KABYLAKE),
53 PLATFORM_NAME(GEMINILAKE),
Rodrigo Vivi71851fa2017-06-08 08:49:58 -070054 PLATFORM_NAME(COFFEELAKE),
Rodrigo Vivi413f3c12017-06-06 13:30:30 -070055 PLATFORM_NAME(CANNONLAKE),
Jani Nikula2e0d26f2016-12-01 14:49:55 +020056};
57#undef PLATFORM_NAME
58
59const char *intel_platform_name(enum intel_platform platform)
60{
Jani Nikula91600952017-02-28 13:11:43 +020061 BUILD_BUG_ON(ARRAY_SIZE(platform_names) != INTEL_MAX_PLATFORMS);
62
Jani Nikula2e0d26f2016-12-01 14:49:55 +020063 if (WARN_ON_ONCE(platform >= ARRAY_SIZE(platform_names) ||
64 platform_names[platform] == NULL))
65 return "<unknown>";
66
67 return platform_names[platform];
68}
69
Chris Wilson94b4f3b2016-07-05 10:40:20 +010070void intel_device_info_dump(struct drm_i915_private *dev_priv)
71{
72 const struct intel_device_info *info = &dev_priv->info;
73
Jani Nikula2e0d26f2016-12-01 14:49:55 +020074 DRM_DEBUG_DRIVER("i915 device info: platform=%s gen=%i pciid=0x%04x rev=0x%02x",
75 intel_platform_name(info->platform),
Chris Wilson94b4f3b2016-07-05 10:40:20 +010076 info->gen,
77 dev_priv->drm.pdev->device,
Joonas Lahtinen604db652016-10-05 13:50:16 +030078 dev_priv->drm.pdev->revision);
79#define PRINT_FLAG(name) \
80 DRM_DEBUG_DRIVER("i915 device info: " #name ": %s", yesno(info->name))
81 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Chris Wilson94b4f3b2016-07-05 10:40:20 +010082#undef PRINT_FLAG
Chris Wilson94b4f3b2016-07-05 10:40:20 +010083}
84
Ben Widawsky4e9767b2017-09-20 11:35:24 -070085static void gen10_sseu_info_init(struct drm_i915_private *dev_priv)
86{
87 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu;
88 const u32 fuse2 = I915_READ(GEN8_FUSE2);
89
90 sseu->slice_mask = (fuse2 & GEN10_F2_S_ENA_MASK) >>
91 GEN10_F2_S_ENA_SHIFT;
92 sseu->subslice_mask = (1 << 4) - 1;
93 sseu->subslice_mask &= ~((fuse2 & GEN10_F2_SS_DIS_MASK) >>
94 GEN10_F2_SS_DIS_SHIFT);
95
96 sseu->eu_total = hweight32(~I915_READ(GEN8_EU_DISABLE0));
97 sseu->eu_total += hweight32(~I915_READ(GEN8_EU_DISABLE1));
98 sseu->eu_total += hweight32(~I915_READ(GEN8_EU_DISABLE2));
99 sseu->eu_total += hweight8(~(I915_READ(GEN10_EU_DISABLE3) &
100 GEN10_EU_DIS_SS_MASK));
101
102 /*
103 * CNL is expected to always have a uniform distribution
104 * of EU across subslices with the exception that any one
105 * EU in any one subslice may be fused off for die
106 * recovery.
107 */
108 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
109 DIV_ROUND_UP(sseu->eu_total,
110 sseu_subslice_total(sseu)) : 0;
111
112 /* No restrictions on Power Gating */
113 sseu->has_slice_pg = 1;
114 sseu->has_subslice_pg = 1;
115 sseu->has_eu_pg = 1;
116}
117
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100118static void cherryview_sseu_info_init(struct drm_i915_private *dev_priv)
119{
Imre Deak43b67992016-08-31 19:13:02 +0300120 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100121 u32 fuse, eu_dis;
122
123 fuse = I915_READ(CHV_FUSE_GT);
124
Imre Deakf08a0c92016-08-31 19:13:04 +0300125 sseu->slice_mask = BIT(0);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100126
127 if (!(fuse & CHV_FGT_DISABLE_SS0)) {
Imre Deak57ec1712016-08-31 19:13:05 +0300128 sseu->subslice_mask |= BIT(0);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100129 eu_dis = fuse & (CHV_FGT_EU_DIS_SS0_R0_MASK |
130 CHV_FGT_EU_DIS_SS0_R1_MASK);
Imre Deak43b67992016-08-31 19:13:02 +0300131 sseu->eu_total += 8 - hweight32(eu_dis);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100132 }
133
134 if (!(fuse & CHV_FGT_DISABLE_SS1)) {
Imre Deak57ec1712016-08-31 19:13:05 +0300135 sseu->subslice_mask |= BIT(1);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100136 eu_dis = fuse & (CHV_FGT_EU_DIS_SS1_R0_MASK |
137 CHV_FGT_EU_DIS_SS1_R1_MASK);
Imre Deak43b67992016-08-31 19:13:02 +0300138 sseu->eu_total += 8 - hweight32(eu_dis);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100139 }
140
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100141 /*
142 * CHV expected to always have a uniform distribution of EU
143 * across subslices.
144 */
Imre Deak57ec1712016-08-31 19:13:05 +0300145 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
146 sseu->eu_total / sseu_subslice_total(sseu) :
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100147 0;
148 /*
149 * CHV supports subslice power gating on devices with more than
150 * one subslice, and supports EU power gating on devices with
151 * more than one EU pair per subslice.
152 */
Imre Deak43b67992016-08-31 19:13:02 +0300153 sseu->has_slice_pg = 0;
Imre Deak57ec1712016-08-31 19:13:05 +0300154 sseu->has_subslice_pg = sseu_subslice_total(sseu) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300155 sseu->has_eu_pg = (sseu->eu_per_subslice > 2);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100156}
157
158static void gen9_sseu_info_init(struct drm_i915_private *dev_priv)
159{
160 struct intel_device_info *info = mkwrite_device_info(dev_priv);
Imre Deak43b67992016-08-31 19:13:02 +0300161 struct sseu_dev_info *sseu = &info->sseu;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100162 int s_max = 3, ss_max = 4, eu_max = 8;
163 int s, ss;
Imre Deak57ec1712016-08-31 19:13:05 +0300164 u32 fuse2, eu_disable;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100165 u8 eu_mask = 0xff;
166
167 fuse2 = I915_READ(GEN8_FUSE2);
Imre Deakf08a0c92016-08-31 19:13:04 +0300168 sseu->slice_mask = (fuse2 & GEN8_F2_S_ENA_MASK) >> GEN8_F2_S_ENA_SHIFT;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100169
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100170 /*
171 * The subslice disable field is global, i.e. it applies
172 * to each of the enabled slices.
173 */
Imre Deak57ec1712016-08-31 19:13:05 +0300174 sseu->subslice_mask = (1 << ss_max) - 1;
175 sseu->subslice_mask &= ~((fuse2 & GEN9_F2_SS_DIS_MASK) >>
176 GEN9_F2_SS_DIS_SHIFT);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100177
178 /*
179 * Iterate through enabled slices and subslices to
180 * count the total enabled EU.
181 */
182 for (s = 0; s < s_max; s++) {
Imre Deakf08a0c92016-08-31 19:13:04 +0300183 if (!(sseu->slice_mask & BIT(s)))
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100184 /* skip disabled slice */
185 continue;
186
187 eu_disable = I915_READ(GEN9_EU_DISABLE(s));
188 for (ss = 0; ss < ss_max; ss++) {
189 int eu_per_ss;
190
Imre Deak57ec1712016-08-31 19:13:05 +0300191 if (!(sseu->subslice_mask & BIT(ss)))
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100192 /* skip disabled subslice */
193 continue;
194
195 eu_per_ss = eu_max - hweight8((eu_disable >> (ss*8)) &
196 eu_mask);
197
198 /*
199 * Record which subslice(s) has(have) 7 EUs. we
200 * can tune the hash used to spread work among
201 * subslices if they are unbalanced.
202 */
203 if (eu_per_ss == 7)
Imre Deak43b67992016-08-31 19:13:02 +0300204 sseu->subslice_7eu[s] |= BIT(ss);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100205
Imre Deak43b67992016-08-31 19:13:02 +0300206 sseu->eu_total += eu_per_ss;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100207 }
208 }
209
210 /*
211 * SKL is expected to always have a uniform distribution
212 * of EU across subslices with the exception that any one
213 * EU in any one subslice may be fused off for die
214 * recovery. BXT is expected to be perfectly uniform in EU
215 * distribution.
216 */
Imre Deak57ec1712016-08-31 19:13:05 +0300217 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
Imre Deak43b67992016-08-31 19:13:02 +0300218 DIV_ROUND_UP(sseu->eu_total,
Imre Deak57ec1712016-08-31 19:13:05 +0300219 sseu_subslice_total(sseu)) : 0;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100220 /*
Rodrigo Vivic7ae7e92017-06-06 13:30:36 -0700221 * SKL+ supports slice power gating on devices with more than
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100222 * one slice, and supports EU power gating on devices with
Rodrigo Vivic7ae7e92017-06-06 13:30:36 -0700223 * more than one EU pair per subslice. BXT+ supports subslice
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100224 * power gating on devices with more than one subslice, and
225 * supports EU power gating on devices with more than one EU
226 * pair per subslice.
227 */
Imre Deak43b67992016-08-31 19:13:02 +0300228 sseu->has_slice_pg =
Rodrigo Vivic7ae7e92017-06-06 13:30:36 -0700229 !IS_GEN9_LP(dev_priv) && hweight8(sseu->slice_mask) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300230 sseu->has_subslice_pg =
Michel Thierry254e0932017-01-09 16:51:35 +0200231 IS_GEN9_LP(dev_priv) && sseu_subslice_total(sseu) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300232 sseu->has_eu_pg = sseu->eu_per_subslice > 2;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100233
Ander Conselvan de Oliveira234516a2017-03-17 16:04:36 +0200234 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +0300235#define IS_SS_DISABLED(ss) (!(sseu->subslice_mask & BIT(ss)))
Ander Conselvan de Oliveira234516a2017-03-17 16:04:36 +0200236 info->has_pooled_eu = hweight8(sseu->subslice_mask) == 3;
237
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100238 /*
239 * There is a HW issue in 2x6 fused down parts that requires
240 * Pooled EU to be enabled as a WA. The pool configuration
241 * changes depending upon which subslice is fused down. This
242 * doesn't affect if the device has all 3 subslices enabled.
243 */
244 /* WaEnablePooledEuFor2x6:bxt */
Ander Conselvan de Oliveira234516a2017-03-17 16:04:36 +0200245 info->has_pooled_eu |= (hweight8(sseu->subslice_mask) == 2 &&
246 IS_BXT_REVID(dev_priv, 0, BXT_REVID_B_LAST));
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100247
Imre Deak43b67992016-08-31 19:13:02 +0300248 sseu->min_eu_in_pool = 0;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100249 if (info->has_pooled_eu) {
Imre Deak57ec1712016-08-31 19:13:05 +0300250 if (IS_SS_DISABLED(2) || IS_SS_DISABLED(0))
Imre Deak43b67992016-08-31 19:13:02 +0300251 sseu->min_eu_in_pool = 3;
Imre Deak57ec1712016-08-31 19:13:05 +0300252 else if (IS_SS_DISABLED(1))
Imre Deak43b67992016-08-31 19:13:02 +0300253 sseu->min_eu_in_pool = 6;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100254 else
Imre Deak43b67992016-08-31 19:13:02 +0300255 sseu->min_eu_in_pool = 9;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100256 }
257#undef IS_SS_DISABLED
258 }
259}
260
261static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv)
262{
Imre Deak43b67992016-08-31 19:13:02 +0300263 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100264 const int s_max = 3, ss_max = 3, eu_max = 8;
265 int s, ss;
Jani Nikulaff64aa12016-10-04 12:54:12 +0300266 u32 fuse2, eu_disable[3]; /* s_max */
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100267
268 fuse2 = I915_READ(GEN8_FUSE2);
Imre Deakf08a0c92016-08-31 19:13:04 +0300269 sseu->slice_mask = (fuse2 & GEN8_F2_S_ENA_MASK) >> GEN8_F2_S_ENA_SHIFT;
Imre Deak57ec1712016-08-31 19:13:05 +0300270 /*
271 * The subslice disable field is global, i.e. it applies
272 * to each of the enabled slices.
273 */
Joonas Lahtinen3c779a42017-02-08 15:12:09 +0200274 sseu->subslice_mask = GENMASK(ss_max - 1, 0);
Imre Deak57ec1712016-08-31 19:13:05 +0300275 sseu->subslice_mask &= ~((fuse2 & GEN8_F2_SS_DIS_MASK) >>
276 GEN8_F2_SS_DIS_SHIFT);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100277
278 eu_disable[0] = I915_READ(GEN8_EU_DISABLE0) & GEN8_EU_DIS0_S0_MASK;
279 eu_disable[1] = (I915_READ(GEN8_EU_DISABLE0) >> GEN8_EU_DIS0_S1_SHIFT) |
280 ((I915_READ(GEN8_EU_DISABLE1) & GEN8_EU_DIS1_S1_MASK) <<
281 (32 - GEN8_EU_DIS0_S1_SHIFT));
282 eu_disable[2] = (I915_READ(GEN8_EU_DISABLE1) >> GEN8_EU_DIS1_S2_SHIFT) |
283 ((I915_READ(GEN8_EU_DISABLE2) & GEN8_EU_DIS2_S2_MASK) <<
284 (32 - GEN8_EU_DIS1_S2_SHIFT));
285
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100286 /*
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100287 * Iterate through enabled slices and subslices to
288 * count the total enabled EU.
289 */
290 for (s = 0; s < s_max; s++) {
Imre Deakf08a0c92016-08-31 19:13:04 +0300291 if (!(sseu->slice_mask & BIT(s)))
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100292 /* skip disabled slice */
293 continue;
294
295 for (ss = 0; ss < ss_max; ss++) {
296 u32 n_disabled;
297
Imre Deak57ec1712016-08-31 19:13:05 +0300298 if (!(sseu->subslice_mask & BIT(ss)))
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100299 /* skip disabled subslice */
300 continue;
301
302 n_disabled = hweight8(eu_disable[s] >> (ss * eu_max));
303
304 /*
305 * Record which subslices have 7 EUs.
306 */
307 if (eu_max - n_disabled == 7)
Imre Deak43b67992016-08-31 19:13:02 +0300308 sseu->subslice_7eu[s] |= 1 << ss;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100309
Imre Deak43b67992016-08-31 19:13:02 +0300310 sseu->eu_total += eu_max - n_disabled;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100311 }
312 }
313
314 /*
315 * BDW is expected to always have a uniform distribution of EU across
316 * subslices with the exception that any one EU in any one subslice may
317 * be fused off for die recovery.
318 */
Imre Deak57ec1712016-08-31 19:13:05 +0300319 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
320 DIV_ROUND_UP(sseu->eu_total,
321 sseu_subslice_total(sseu)) : 0;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100322
323 /*
324 * BDW supports slice power gating on devices with more than
325 * one slice.
326 */
Imre Deakf08a0c92016-08-31 19:13:04 +0300327 sseu->has_slice_pg = hweight8(sseu->slice_mask) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300328 sseu->has_subslice_pg = 0;
329 sseu->has_eu_pg = 0;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100330}
331
Lionel Landwerlindab91782017-11-10 19:08:44 +0000332static u64 read_reference_ts_freq(struct drm_i915_private *dev_priv)
333{
334 u32 ts_override = I915_READ(GEN9_TIMESTAMP_OVERRIDE);
335 u64 base_freq, frac_freq;
336
337 base_freq = ((ts_override & GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DIVIDER_MASK) >>
338 GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DIVIDER_SHIFT) + 1;
339 base_freq *= 1000000;
340
341 frac_freq = ((ts_override &
342 GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DENOMINATOR_MASK) >>
343 GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DENOMINATOR_SHIFT);
344 if (frac_freq != 0)
345 frac_freq = 1000000 / (frac_freq + 1);
346
347 return base_freq + frac_freq;
348}
349
350static u64 read_timestamp_frequency(struct drm_i915_private *dev_priv)
351{
352 u64 f12_5_mhz = 12500000;
353 u64 f19_2_mhz = 19200000;
354 u64 f24_mhz = 24000000;
355
356 if (INTEL_GEN(dev_priv) <= 4) {
357 /* PRMs say:
358 *
359 * "The value in this register increments once every 16
360 * hclks." (through the “Clocking Configuration”
361 * (“CLKCFG”) MCHBAR register)
362 */
363 return (dev_priv->rawclk_freq * 1000) / 16;
364 } else if (INTEL_GEN(dev_priv) <= 8) {
365 /* PRMs say:
366 *
367 * "The PCU TSC counts 10ns increments; this timestamp
368 * reflects bits 38:3 of the TSC (i.e. 80ns granularity,
369 * rolling over every 1.5 hours).
370 */
371 return f12_5_mhz;
372 } else if (INTEL_GEN(dev_priv) <= 9) {
373 u32 ctc_reg = I915_READ(CTC_MODE);
374 u64 freq = 0;
375
376 if ((ctc_reg & CTC_SOURCE_PARAMETER_MASK) == CTC_SOURCE_DIVIDE_LOGIC) {
377 freq = read_reference_ts_freq(dev_priv);
378 } else {
379 freq = IS_GEN9_LP(dev_priv) ? f19_2_mhz : f24_mhz;
380
381 /* Now figure out how the command stream's timestamp
382 * register increments from this frequency (it might
383 * increment only every few clock cycle).
384 */
385 freq >>= 3 - ((ctc_reg & CTC_SHIFT_PARAMETER_MASK) >>
386 CTC_SHIFT_PARAMETER_SHIFT);
387 }
388
389 return freq;
390 } else if (INTEL_GEN(dev_priv) <= 10) {
391 u32 ctc_reg = I915_READ(CTC_MODE);
392 u64 freq = 0;
393 u32 rpm_config_reg = 0;
394
395 /* First figure out the reference frequency. There are 2 ways
396 * we can compute the frequency, either through the
397 * TIMESTAMP_OVERRIDE register or through RPM_CONFIG. CTC_MODE
398 * tells us which one we should use.
399 */
400 if ((ctc_reg & CTC_SOURCE_PARAMETER_MASK) == CTC_SOURCE_DIVIDE_LOGIC) {
401 freq = read_reference_ts_freq(dev_priv);
402 } else {
403 u32 crystal_clock;
404
405 rpm_config_reg = I915_READ(RPM_CONFIG0);
406 crystal_clock = (rpm_config_reg &
407 GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_MASK) >>
408 GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_SHIFT;
409 switch (crystal_clock) {
410 case GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_19_2_MHZ:
411 freq = f19_2_mhz;
412 break;
413 case GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_24_MHZ:
414 freq = f24_mhz;
415 break;
416 }
417 }
418
419 /* Now figure out how the command stream's timestamp register
420 * increments from this frequency (it might increment only
421 * every few clock cycle).
422 */
423 freq >>= 3 - ((rpm_config_reg &
424 GEN10_RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK) >>
425 GEN10_RPM_CONFIG0_CTC_SHIFT_PARAMETER_SHIFT);
426
427 return freq;
428 }
429
430 DRM_ERROR("Unknown gen, unable to compute command stream timestamp frequency\n");
431 return 0;
432}
433
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100434/*
435 * Determine various intel_device_info fields at runtime.
436 *
437 * Use it when either:
438 * - it's judged too laborious to fill n static structures with the limit
439 * when a simple if statement does the job,
440 * - run-time checks (eg read fuse/strap registers) are needed.
441 *
442 * This function needs to be called:
443 * - after the MMIO has been setup as we are reading registers,
444 * - after the PCH has been detected,
445 * - before the first usage of the fields it can tweak.
446 */
447void intel_device_info_runtime_init(struct drm_i915_private *dev_priv)
448{
449 struct intel_device_info *info = mkwrite_device_info(dev_priv);
450 enum pipe pipe;
451
Mika Kahola6e7406d2017-11-01 12:08:50 +0200452 if (INTEL_GEN(dev_priv) >= 10) {
453 for_each_pipe(dev_priv, pipe)
454 info->num_scalers[pipe] = 2;
455 } else if (INTEL_GEN(dev_priv) == 9) {
Ander Conselvan de Oliveira0bf02302017-01-02 15:54:41 +0200456 info->num_scalers[PIPE_A] = 2;
457 info->num_scalers[PIPE_B] = 2;
458 info->num_scalers[PIPE_C] = 1;
459 }
460
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100461 /*
462 * Skylake and Broxton currently don't expose the topmost plane as its
463 * use is exclusive with the legacy cursor and we only want to expose
464 * one of those, not both. Until we can safely expose the topmost plane
465 * as a DRM_PLANE_TYPE_CURSOR with all the features exposed/supported,
466 * we don't expose the topmost plane at all to prevent ABI breakage
467 * down the line.
468 */
James Irwin8366be92017-06-06 13:30:35 -0700469 if (IS_GEN10(dev_priv) || IS_GEMINILAKE(dev_priv))
Ander Conselvan de Oliveirae9c98822016-12-02 10:23:57 +0200470 for_each_pipe(dev_priv, pipe)
471 info->num_sprites[pipe] = 3;
472 else if (IS_BROXTON(dev_priv)) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100473 info->num_sprites[PIPE_A] = 2;
474 info->num_sprites[PIPE_B] = 2;
475 info->num_sprites[PIPE_C] = 1;
Ville Syrjälä33edc242016-10-25 18:58:00 +0300476 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100477 for_each_pipe(dev_priv, pipe)
478 info->num_sprites[pipe] = 2;
Ville Syrjäläab330812017-04-21 21:14:32 +0300479 } else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100480 for_each_pipe(dev_priv, pipe)
481 info->num_sprites[pipe] = 1;
Ville Syrjälä33edc242016-10-25 18:58:00 +0300482 }
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100483
Michal Wajdeczko4f044a82017-09-19 19:38:44 +0000484 if (i915_modparams.disable_display) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100485 DRM_INFO("Display disabled (module parameter)\n");
486 info->num_pipes = 0;
487 } else if (info->num_pipes > 0 &&
488 (IS_GEN7(dev_priv) || IS_GEN8(dev_priv)) &&
489 HAS_PCH_SPLIT(dev_priv)) {
490 u32 fuse_strap = I915_READ(FUSE_STRAP);
491 u32 sfuse_strap = I915_READ(SFUSE_STRAP);
492
493 /*
494 * SFUSE_STRAP is supposed to have a bit signalling the display
495 * is fused off. Unfortunately it seems that, at least in
496 * certain cases, fused off display means that PCH display
497 * reads don't land anywhere. In that case, we read 0s.
498 *
499 * On CPT/PPT, we can detect this case as SFUSE_STRAP_FUSE_LOCK
500 * should be set when taking over after the firmware.
501 */
502 if (fuse_strap & ILK_INTERNAL_DISPLAY_DISABLE ||
503 sfuse_strap & SFUSE_STRAP_DISPLAY_DISABLED ||
Ville Syrjäläb9eb89b2017-06-20 16:03:06 +0300504 (HAS_PCH_CPT(dev_priv) &&
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100505 !(sfuse_strap & SFUSE_STRAP_FUSE_LOCK))) {
506 DRM_INFO("Display fused off, disabling\n");
507 info->num_pipes = 0;
508 } else if (fuse_strap & IVB_PIPE_C_DISABLE) {
509 DRM_INFO("PipeC fused off\n");
510 info->num_pipes -= 1;
511 }
512 } else if (info->num_pipes > 0 && IS_GEN9(dev_priv)) {
513 u32 dfsm = I915_READ(SKL_DFSM);
514 u8 disabled_mask = 0;
515 bool invalid;
516 int num_bits;
517
518 if (dfsm & SKL_DFSM_PIPE_A_DISABLE)
519 disabled_mask |= BIT(PIPE_A);
520 if (dfsm & SKL_DFSM_PIPE_B_DISABLE)
521 disabled_mask |= BIT(PIPE_B);
522 if (dfsm & SKL_DFSM_PIPE_C_DISABLE)
523 disabled_mask |= BIT(PIPE_C);
524
525 num_bits = hweight8(disabled_mask);
526
527 switch (disabled_mask) {
528 case BIT(PIPE_A):
529 case BIT(PIPE_B):
530 case BIT(PIPE_A) | BIT(PIPE_B):
531 case BIT(PIPE_A) | BIT(PIPE_C):
532 invalid = true;
533 break;
534 default:
535 invalid = false;
536 }
537
538 if (num_bits > info->num_pipes || invalid)
539 DRM_ERROR("invalid pipe fuse configuration: 0x%x\n",
540 disabled_mask);
541 else
542 info->num_pipes -= num_bits;
543 }
544
545 /* Initialize slice/subslice/EU info */
546 if (IS_CHERRYVIEW(dev_priv))
547 cherryview_sseu_info_init(dev_priv);
548 else if (IS_BROADWELL(dev_priv))
549 broadwell_sseu_info_init(dev_priv);
Ben Widawsky4e9767b2017-09-20 11:35:24 -0700550 else if (INTEL_GEN(dev_priv) == 9)
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100551 gen9_sseu_info_init(dev_priv);
Ben Widawsky4e9767b2017-09-20 11:35:24 -0700552 else if (INTEL_GEN(dev_priv) >= 10)
553 gen10_sseu_info_init(dev_priv);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100554
Lionel Landwerlindab91782017-11-10 19:08:44 +0000555 /* Initialize command stream timestamp frequency */
556 info->cs_timestamp_frequency = read_timestamp_frequency(dev_priv);
557
Imre Deakc67ba532016-08-31 19:13:06 +0300558 DRM_DEBUG_DRIVER("slice mask: %04x\n", info->sseu.slice_mask);
Imre Deakf08a0c92016-08-31 19:13:04 +0300559 DRM_DEBUG_DRIVER("slice total: %u\n", hweight8(info->sseu.slice_mask));
Imre Deak57ec1712016-08-31 19:13:05 +0300560 DRM_DEBUG_DRIVER("subslice total: %u\n",
561 sseu_subslice_total(&info->sseu));
Imre Deakc67ba532016-08-31 19:13:06 +0300562 DRM_DEBUG_DRIVER("subslice mask %04x\n", info->sseu.subslice_mask);
Imre Deak43b67992016-08-31 19:13:02 +0300563 DRM_DEBUG_DRIVER("subslice per slice: %u\n",
Imre Deak57ec1712016-08-31 19:13:05 +0300564 hweight8(info->sseu.subslice_mask));
Imre Deak43b67992016-08-31 19:13:02 +0300565 DRM_DEBUG_DRIVER("EU total: %u\n", info->sseu.eu_total);
566 DRM_DEBUG_DRIVER("EU per subslice: %u\n", info->sseu.eu_per_subslice);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100567 DRM_DEBUG_DRIVER("has slice power gating: %s\n",
Imre Deak43b67992016-08-31 19:13:02 +0300568 info->sseu.has_slice_pg ? "y" : "n");
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100569 DRM_DEBUG_DRIVER("has subslice power gating: %s\n",
Imre Deak43b67992016-08-31 19:13:02 +0300570 info->sseu.has_subslice_pg ? "y" : "n");
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100571 DRM_DEBUG_DRIVER("has EU power gating: %s\n",
Imre Deak43b67992016-08-31 19:13:02 +0300572 info->sseu.has_eu_pg ? "y" : "n");
Lionel Landwerlindab91782017-11-10 19:08:44 +0000573 DRM_DEBUG_DRIVER("CS timestamp frequency: %llu\n",
574 info->cs_timestamp_frequency);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100575}