blob: be355cf2976e3bd0c3c024cbea53d166990f1768 [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
Michal Wajdeczkoa8c9b842017-12-19 11:43:44 +000025#include <drm/drm_print.h>
26
Chris Wilson94b4f3b2016-07-05 10:40:20 +010027#include "i915_drv.h"
28
Jani Nikula2e0d26f2016-12-01 14:49:55 +020029#define PLATFORM_NAME(x) [INTEL_##x] = #x
30static const char * const platform_names[] = {
31 PLATFORM_NAME(I830),
32 PLATFORM_NAME(I845G),
33 PLATFORM_NAME(I85X),
34 PLATFORM_NAME(I865G),
35 PLATFORM_NAME(I915G),
36 PLATFORM_NAME(I915GM),
37 PLATFORM_NAME(I945G),
38 PLATFORM_NAME(I945GM),
39 PLATFORM_NAME(G33),
40 PLATFORM_NAME(PINEVIEW),
Jani Nikulac0f86832016-12-07 12:13:04 +020041 PLATFORM_NAME(I965G),
42 PLATFORM_NAME(I965GM),
Jani Nikulaf69c11a2016-11-30 17:43:05 +020043 PLATFORM_NAME(G45),
44 PLATFORM_NAME(GM45),
Jani Nikula2e0d26f2016-12-01 14:49:55 +020045 PLATFORM_NAME(IRONLAKE),
46 PLATFORM_NAME(SANDYBRIDGE),
47 PLATFORM_NAME(IVYBRIDGE),
48 PLATFORM_NAME(VALLEYVIEW),
49 PLATFORM_NAME(HASWELL),
50 PLATFORM_NAME(BROADWELL),
51 PLATFORM_NAME(CHERRYVIEW),
52 PLATFORM_NAME(SKYLAKE),
53 PLATFORM_NAME(BROXTON),
54 PLATFORM_NAME(KABYLAKE),
55 PLATFORM_NAME(GEMINILAKE),
Rodrigo Vivi71851fa2017-06-08 08:49:58 -070056 PLATFORM_NAME(COFFEELAKE),
Rodrigo Vivi413f3c12017-06-06 13:30:30 -070057 PLATFORM_NAME(CANNONLAKE),
Jani Nikula2e0d26f2016-12-01 14:49:55 +020058};
59#undef PLATFORM_NAME
60
61const char *intel_platform_name(enum intel_platform platform)
62{
Jani Nikula91600952017-02-28 13:11:43 +020063 BUILD_BUG_ON(ARRAY_SIZE(platform_names) != INTEL_MAX_PLATFORMS);
64
Jani Nikula2e0d26f2016-12-01 14:49:55 +020065 if (WARN_ON_ONCE(platform >= ARRAY_SIZE(platform_names) ||
66 platform_names[platform] == NULL))
67 return "<unknown>";
68
69 return platform_names[platform];
70}
71
Michal Wajdeczkoa8c9b842017-12-19 11:43:44 +000072void intel_device_info_dump_flags(const struct intel_device_info *info,
73 struct drm_printer *p)
74{
75#define PRINT_FLAG(name) drm_printf(p, "%s: %s\n", #name, yesno(info->name));
76 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
77#undef PRINT_FLAG
78}
79
Michal Wajdeczkoeb10ed92017-12-19 11:43:45 +000080void intel_device_info_dump(const struct intel_device_info *info,
81 struct drm_printer *p)
Chris Wilson94b4f3b2016-07-05 10:40:20 +010082{
Michal Wajdeczkoeb10ed92017-12-19 11:43:45 +000083 struct drm_i915_private *dev_priv =
84 container_of(info, struct drm_i915_private, info);
Chris Wilson94b4f3b2016-07-05 10:40:20 +010085
Michal Wajdeczkoeb10ed92017-12-19 11:43:45 +000086 drm_printf(p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
87 INTEL_DEVID(dev_priv),
88 INTEL_REVID(dev_priv),
89 intel_platform_name(info->platform),
90 info->gen);
Michal Wajdeczkoa8c9b842017-12-19 11:43:44 +000091
Michal Wajdeczkoeb10ed92017-12-19 11:43:45 +000092 intel_device_info_dump_flags(info, p);
Chris Wilson94b4f3b2016-07-05 10:40:20 +010093}
94
Ben Widawsky4e9767b2017-09-20 11:35:24 -070095static void gen10_sseu_info_init(struct drm_i915_private *dev_priv)
96{
97 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu;
98 const u32 fuse2 = I915_READ(GEN8_FUSE2);
99
100 sseu->slice_mask = (fuse2 & GEN10_F2_S_ENA_MASK) >>
101 GEN10_F2_S_ENA_SHIFT;
102 sseu->subslice_mask = (1 << 4) - 1;
103 sseu->subslice_mask &= ~((fuse2 & GEN10_F2_SS_DIS_MASK) >>
104 GEN10_F2_SS_DIS_SHIFT);
105
106 sseu->eu_total = hweight32(~I915_READ(GEN8_EU_DISABLE0));
107 sseu->eu_total += hweight32(~I915_READ(GEN8_EU_DISABLE1));
108 sseu->eu_total += hweight32(~I915_READ(GEN8_EU_DISABLE2));
109 sseu->eu_total += hweight8(~(I915_READ(GEN10_EU_DISABLE3) &
110 GEN10_EU_DIS_SS_MASK));
111
112 /*
113 * CNL is expected to always have a uniform distribution
114 * of EU across subslices with the exception that any one
115 * EU in any one subslice may be fused off for die
116 * recovery.
117 */
118 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
119 DIV_ROUND_UP(sseu->eu_total,
120 sseu_subslice_total(sseu)) : 0;
121
122 /* No restrictions on Power Gating */
123 sseu->has_slice_pg = 1;
124 sseu->has_subslice_pg = 1;
125 sseu->has_eu_pg = 1;
126}
127
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100128static void cherryview_sseu_info_init(struct drm_i915_private *dev_priv)
129{
Imre Deak43b67992016-08-31 19:13:02 +0300130 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100131 u32 fuse, eu_dis;
132
133 fuse = I915_READ(CHV_FUSE_GT);
134
Imre Deakf08a0c92016-08-31 19:13:04 +0300135 sseu->slice_mask = BIT(0);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100136
137 if (!(fuse & CHV_FGT_DISABLE_SS0)) {
Imre Deak57ec1712016-08-31 19:13:05 +0300138 sseu->subslice_mask |= BIT(0);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100139 eu_dis = fuse & (CHV_FGT_EU_DIS_SS0_R0_MASK |
140 CHV_FGT_EU_DIS_SS0_R1_MASK);
Imre Deak43b67992016-08-31 19:13:02 +0300141 sseu->eu_total += 8 - hweight32(eu_dis);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100142 }
143
144 if (!(fuse & CHV_FGT_DISABLE_SS1)) {
Imre Deak57ec1712016-08-31 19:13:05 +0300145 sseu->subslice_mask |= BIT(1);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100146 eu_dis = fuse & (CHV_FGT_EU_DIS_SS1_R0_MASK |
147 CHV_FGT_EU_DIS_SS1_R1_MASK);
Imre Deak43b67992016-08-31 19:13:02 +0300148 sseu->eu_total += 8 - hweight32(eu_dis);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100149 }
150
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100151 /*
152 * CHV expected to always have a uniform distribution of EU
153 * across subslices.
154 */
Imre Deak57ec1712016-08-31 19:13:05 +0300155 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
156 sseu->eu_total / sseu_subslice_total(sseu) :
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100157 0;
158 /*
159 * CHV supports subslice power gating on devices with more than
160 * one subslice, and supports EU power gating on devices with
161 * more than one EU pair per subslice.
162 */
Imre Deak43b67992016-08-31 19:13:02 +0300163 sseu->has_slice_pg = 0;
Imre Deak57ec1712016-08-31 19:13:05 +0300164 sseu->has_subslice_pg = sseu_subslice_total(sseu) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300165 sseu->has_eu_pg = (sseu->eu_per_subslice > 2);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100166}
167
168static void gen9_sseu_info_init(struct drm_i915_private *dev_priv)
169{
170 struct intel_device_info *info = mkwrite_device_info(dev_priv);
Imre Deak43b67992016-08-31 19:13:02 +0300171 struct sseu_dev_info *sseu = &info->sseu;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100172 int s_max = 3, ss_max = 4, eu_max = 8;
173 int s, ss;
Imre Deak57ec1712016-08-31 19:13:05 +0300174 u32 fuse2, eu_disable;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100175 u8 eu_mask = 0xff;
176
177 fuse2 = I915_READ(GEN8_FUSE2);
Imre Deakf08a0c92016-08-31 19:13:04 +0300178 sseu->slice_mask = (fuse2 & GEN8_F2_S_ENA_MASK) >> GEN8_F2_S_ENA_SHIFT;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100179
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100180 /*
181 * The subslice disable field is global, i.e. it applies
182 * to each of the enabled slices.
183 */
Imre Deak57ec1712016-08-31 19:13:05 +0300184 sseu->subslice_mask = (1 << ss_max) - 1;
185 sseu->subslice_mask &= ~((fuse2 & GEN9_F2_SS_DIS_MASK) >>
186 GEN9_F2_SS_DIS_SHIFT);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100187
188 /*
189 * Iterate through enabled slices and subslices to
190 * count the total enabled EU.
191 */
192 for (s = 0; s < s_max; s++) {
Imre Deakf08a0c92016-08-31 19:13:04 +0300193 if (!(sseu->slice_mask & BIT(s)))
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100194 /* skip disabled slice */
195 continue;
196
197 eu_disable = I915_READ(GEN9_EU_DISABLE(s));
198 for (ss = 0; ss < ss_max; ss++) {
199 int eu_per_ss;
200
Imre Deak57ec1712016-08-31 19:13:05 +0300201 if (!(sseu->subslice_mask & BIT(ss)))
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100202 /* skip disabled subslice */
203 continue;
204
205 eu_per_ss = eu_max - hweight8((eu_disable >> (ss*8)) &
206 eu_mask);
207
208 /*
209 * Record which subslice(s) has(have) 7 EUs. we
210 * can tune the hash used to spread work among
211 * subslices if they are unbalanced.
212 */
213 if (eu_per_ss == 7)
Imre Deak43b67992016-08-31 19:13:02 +0300214 sseu->subslice_7eu[s] |= BIT(ss);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100215
Imre Deak43b67992016-08-31 19:13:02 +0300216 sseu->eu_total += eu_per_ss;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100217 }
218 }
219
220 /*
221 * SKL is expected to always have a uniform distribution
222 * of EU across subslices with the exception that any one
223 * EU in any one subslice may be fused off for die
224 * recovery. BXT is expected to be perfectly uniform in EU
225 * distribution.
226 */
Imre Deak57ec1712016-08-31 19:13:05 +0300227 sseu->eu_per_subslice = sseu_subslice_total(sseu) ?
Imre Deak43b67992016-08-31 19:13:02 +0300228 DIV_ROUND_UP(sseu->eu_total,
Imre Deak57ec1712016-08-31 19:13:05 +0300229 sseu_subslice_total(sseu)) : 0;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100230 /*
Rodrigo Vivic7ae7e92017-06-06 13:30:36 -0700231 * SKL+ supports slice power gating on devices with more than
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100232 * one slice, and supports EU power gating on devices with
Rodrigo Vivic7ae7e92017-06-06 13:30:36 -0700233 * more than one EU pair per subslice. BXT+ supports subslice
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100234 * power gating on devices with more than one subslice, and
235 * supports EU power gating on devices with more than one EU
236 * pair per subslice.
237 */
Imre Deak43b67992016-08-31 19:13:02 +0300238 sseu->has_slice_pg =
Rodrigo Vivic7ae7e92017-06-06 13:30:36 -0700239 !IS_GEN9_LP(dev_priv) && hweight8(sseu->slice_mask) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300240 sseu->has_subslice_pg =
Michel Thierry254e0932017-01-09 16:51:35 +0200241 IS_GEN9_LP(dev_priv) && sseu_subslice_total(sseu) > 1;
Imre Deak43b67992016-08-31 19:13:02 +0300242 sseu->has_eu_pg = sseu->eu_per_subslice > 2;
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100243
Ander Conselvan de Oliveira234516a2017-03-17 16:04:36 +0200244 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +0300245#define IS_SS_DISABLED(ss) (!(sseu->subslice_mask & BIT(ss)))
Ander Conselvan de Oliveira234516a2017-03-17 16:04:36 +0200246 info->has_pooled_eu = hweight8(sseu->subslice_mask) == 3;
247
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 Landwerlinf577a032017-11-13 23:34:53 +0000332static u32 read_reference_ts_freq(struct drm_i915_private *dev_priv)
Lionel Landwerlindab91782017-11-10 19:08:44 +0000333{
334 u32 ts_override = I915_READ(GEN9_TIMESTAMP_OVERRIDE);
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000335 u32 base_freq, frac_freq;
Lionel Landwerlindab91782017-11-10 19:08:44 +0000336
337 base_freq = ((ts_override & GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DIVIDER_MASK) >>
338 GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DIVIDER_SHIFT) + 1;
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000339 base_freq *= 1000;
Lionel Landwerlindab91782017-11-10 19:08:44 +0000340
341 frac_freq = ((ts_override &
342 GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DENOMINATOR_MASK) >>
343 GEN9_TIMESTAMP_OVERRIDE_US_COUNTER_DENOMINATOR_SHIFT);
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000344 frac_freq = 1000 / (frac_freq + 1);
Lionel Landwerlindab91782017-11-10 19:08:44 +0000345
346 return base_freq + frac_freq;
347}
348
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000349static u32 read_timestamp_frequency(struct drm_i915_private *dev_priv)
Lionel Landwerlindab91782017-11-10 19:08:44 +0000350{
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000351 u32 f12_5_mhz = 12500;
352 u32 f19_2_mhz = 19200;
353 u32 f24_mhz = 24000;
Lionel Landwerlindab91782017-11-10 19:08:44 +0000354
355 if (INTEL_GEN(dev_priv) <= 4) {
356 /* PRMs say:
357 *
358 * "The value in this register increments once every 16
359 * hclks." (through the “Clocking Configuration”
360 * (“CLKCFG”) MCHBAR register)
361 */
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000362 return dev_priv->rawclk_freq / 16;
Lionel Landwerlindab91782017-11-10 19:08:44 +0000363 } else if (INTEL_GEN(dev_priv) <= 8) {
364 /* PRMs say:
365 *
366 * "The PCU TSC counts 10ns increments; this timestamp
367 * reflects bits 38:3 of the TSC (i.e. 80ns granularity,
368 * rolling over every 1.5 hours).
369 */
370 return f12_5_mhz;
371 } else if (INTEL_GEN(dev_priv) <= 9) {
372 u32 ctc_reg = I915_READ(CTC_MODE);
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000373 u32 freq = 0;
Lionel Landwerlindab91782017-11-10 19:08:44 +0000374
375 if ((ctc_reg & CTC_SOURCE_PARAMETER_MASK) == CTC_SOURCE_DIVIDE_LOGIC) {
376 freq = read_reference_ts_freq(dev_priv);
377 } else {
378 freq = IS_GEN9_LP(dev_priv) ? f19_2_mhz : f24_mhz;
379
380 /* Now figure out how the command stream's timestamp
381 * register increments from this frequency (it might
382 * increment only every few clock cycle).
383 */
384 freq >>= 3 - ((ctc_reg & CTC_SHIFT_PARAMETER_MASK) >>
385 CTC_SHIFT_PARAMETER_SHIFT);
386 }
387
388 return freq;
389 } else if (INTEL_GEN(dev_priv) <= 10) {
390 u32 ctc_reg = I915_READ(CTC_MODE);
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000391 u32 freq = 0;
Lionel Landwerlindab91782017-11-10 19:08:44 +0000392 u32 rpm_config_reg = 0;
393
394 /* First figure out the reference frequency. There are 2 ways
395 * we can compute the frequency, either through the
396 * TIMESTAMP_OVERRIDE register or through RPM_CONFIG. CTC_MODE
397 * tells us which one we should use.
398 */
399 if ((ctc_reg & CTC_SOURCE_PARAMETER_MASK) == CTC_SOURCE_DIVIDE_LOGIC) {
400 freq = read_reference_ts_freq(dev_priv);
401 } else {
402 u32 crystal_clock;
403
404 rpm_config_reg = I915_READ(RPM_CONFIG0);
405 crystal_clock = (rpm_config_reg &
406 GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_MASK) >>
407 GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_SHIFT;
408 switch (crystal_clock) {
409 case GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_19_2_MHZ:
410 freq = f19_2_mhz;
411 break;
412 case GEN9_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_24_MHZ:
413 freq = f24_mhz;
414 break;
415 }
Lionel Landwerlindab91782017-11-10 19:08:44 +0000416
Lionel Landwerlin53ff2642017-11-13 23:34:55 +0000417 /* Now figure out how the command stream's timestamp
418 * register increments from this frequency (it might
419 * increment only every few clock cycle).
420 */
421 freq >>= 3 - ((rpm_config_reg &
422 GEN10_RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK) >>
423 GEN10_RPM_CONFIG0_CTC_SHIFT_PARAMETER_SHIFT);
424 }
Lionel Landwerlindab91782017-11-10 19:08:44 +0000425
426 return freq;
427 }
428
Lionel Landwerlinfe66e922017-12-13 17:11:54 +0000429 MISSING_CASE("Unknown gen, unable to read command streamer timestamp frequency\n");
Lionel Landwerlindab91782017-11-10 19:08:44 +0000430 return 0;
431}
432
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100433/*
434 * Determine various intel_device_info fields at runtime.
435 *
436 * Use it when either:
437 * - it's judged too laborious to fill n static structures with the limit
438 * when a simple if statement does the job,
439 * - run-time checks (eg read fuse/strap registers) are needed.
440 *
441 * This function needs to be called:
442 * - after the MMIO has been setup as we are reading registers,
443 * - after the PCH has been detected,
444 * - before the first usage of the fields it can tweak.
445 */
446void intel_device_info_runtime_init(struct drm_i915_private *dev_priv)
447{
448 struct intel_device_info *info = mkwrite_device_info(dev_priv);
449 enum pipe pipe;
450
Mika Kahola6e7406d2017-11-01 12:08:50 +0200451 if (INTEL_GEN(dev_priv) >= 10) {
452 for_each_pipe(dev_priv, pipe)
453 info->num_scalers[pipe] = 2;
454 } else if (INTEL_GEN(dev_priv) == 9) {
Ander Conselvan de Oliveira0bf02302017-01-02 15:54:41 +0200455 info->num_scalers[PIPE_A] = 2;
456 info->num_scalers[PIPE_B] = 2;
457 info->num_scalers[PIPE_C] = 1;
458 }
459
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100460 /*
461 * Skylake and Broxton currently don't expose the topmost plane as its
462 * use is exclusive with the legacy cursor and we only want to expose
463 * one of those, not both. Until we can safely expose the topmost plane
464 * as a DRM_PLANE_TYPE_CURSOR with all the features exposed/supported,
465 * we don't expose the topmost plane at all to prevent ABI breakage
466 * down the line.
467 */
James Irwin8366be92017-06-06 13:30:35 -0700468 if (IS_GEN10(dev_priv) || IS_GEMINILAKE(dev_priv))
Ander Conselvan de Oliveirae9c98822016-12-02 10:23:57 +0200469 for_each_pipe(dev_priv, pipe)
470 info->num_sprites[pipe] = 3;
471 else if (IS_BROXTON(dev_priv)) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100472 info->num_sprites[PIPE_A] = 2;
473 info->num_sprites[PIPE_B] = 2;
474 info->num_sprites[PIPE_C] = 1;
Ville Syrjälä33edc242016-10-25 18:58:00 +0300475 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100476 for_each_pipe(dev_priv, pipe)
477 info->num_sprites[pipe] = 2;
Ville Syrjäläab330812017-04-21 21:14:32 +0300478 } else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100479 for_each_pipe(dev_priv, pipe)
480 info->num_sprites[pipe] = 1;
Ville Syrjälä33edc242016-10-25 18:58:00 +0300481 }
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100482
Michal Wajdeczko4f044a82017-09-19 19:38:44 +0000483 if (i915_modparams.disable_display) {
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100484 DRM_INFO("Display disabled (module parameter)\n");
485 info->num_pipes = 0;
486 } else if (info->num_pipes > 0 &&
487 (IS_GEN7(dev_priv) || IS_GEN8(dev_priv)) &&
488 HAS_PCH_SPLIT(dev_priv)) {
489 u32 fuse_strap = I915_READ(FUSE_STRAP);
490 u32 sfuse_strap = I915_READ(SFUSE_STRAP);
491
492 /*
493 * SFUSE_STRAP is supposed to have a bit signalling the display
494 * is fused off. Unfortunately it seems that, at least in
495 * certain cases, fused off display means that PCH display
496 * reads don't land anywhere. In that case, we read 0s.
497 *
498 * On CPT/PPT, we can detect this case as SFUSE_STRAP_FUSE_LOCK
499 * should be set when taking over after the firmware.
500 */
501 if (fuse_strap & ILK_INTERNAL_DISPLAY_DISABLE ||
502 sfuse_strap & SFUSE_STRAP_DISPLAY_DISABLED ||
Ville Syrjäläb9eb89b2017-06-20 16:03:06 +0300503 (HAS_PCH_CPT(dev_priv) &&
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100504 !(sfuse_strap & SFUSE_STRAP_FUSE_LOCK))) {
505 DRM_INFO("Display fused off, disabling\n");
506 info->num_pipes = 0;
507 } else if (fuse_strap & IVB_PIPE_C_DISABLE) {
508 DRM_INFO("PipeC fused off\n");
509 info->num_pipes -= 1;
510 }
511 } else if (info->num_pipes > 0 && IS_GEN9(dev_priv)) {
512 u32 dfsm = I915_READ(SKL_DFSM);
513 u8 disabled_mask = 0;
514 bool invalid;
515 int num_bits;
516
517 if (dfsm & SKL_DFSM_PIPE_A_DISABLE)
518 disabled_mask |= BIT(PIPE_A);
519 if (dfsm & SKL_DFSM_PIPE_B_DISABLE)
520 disabled_mask |= BIT(PIPE_B);
521 if (dfsm & SKL_DFSM_PIPE_C_DISABLE)
522 disabled_mask |= BIT(PIPE_C);
523
524 num_bits = hweight8(disabled_mask);
525
526 switch (disabled_mask) {
527 case BIT(PIPE_A):
528 case BIT(PIPE_B):
529 case BIT(PIPE_A) | BIT(PIPE_B):
530 case BIT(PIPE_A) | BIT(PIPE_C):
531 invalid = true;
532 break;
533 default:
534 invalid = false;
535 }
536
537 if (num_bits > info->num_pipes || invalid)
538 DRM_ERROR("invalid pipe fuse configuration: 0x%x\n",
539 disabled_mask);
540 else
541 info->num_pipes -= num_bits;
542 }
543
544 /* Initialize slice/subslice/EU info */
545 if (IS_CHERRYVIEW(dev_priv))
546 cherryview_sseu_info_init(dev_priv);
547 else if (IS_BROADWELL(dev_priv))
548 broadwell_sseu_info_init(dev_priv);
Ben Widawsky4e9767b2017-09-20 11:35:24 -0700549 else if (INTEL_GEN(dev_priv) == 9)
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100550 gen9_sseu_info_init(dev_priv);
Ben Widawsky4e9767b2017-09-20 11:35:24 -0700551 else if (INTEL_GEN(dev_priv) >= 10)
552 gen10_sseu_info_init(dev_priv);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100553
Lionel Landwerlindab91782017-11-10 19:08:44 +0000554 /* Initialize command stream timestamp frequency */
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000555 info->cs_timestamp_frequency_khz = read_timestamp_frequency(dev_priv);
Lionel Landwerlindab91782017-11-10 19:08:44 +0000556
Imre Deakc67ba532016-08-31 19:13:06 +0300557 DRM_DEBUG_DRIVER("slice mask: %04x\n", info->sseu.slice_mask);
Imre Deakf08a0c92016-08-31 19:13:04 +0300558 DRM_DEBUG_DRIVER("slice total: %u\n", hweight8(info->sseu.slice_mask));
Imre Deak57ec1712016-08-31 19:13:05 +0300559 DRM_DEBUG_DRIVER("subslice total: %u\n",
560 sseu_subslice_total(&info->sseu));
Imre Deakc67ba532016-08-31 19:13:06 +0300561 DRM_DEBUG_DRIVER("subslice mask %04x\n", info->sseu.subslice_mask);
Imre Deak43b67992016-08-31 19:13:02 +0300562 DRM_DEBUG_DRIVER("subslice per slice: %u\n",
Imre Deak57ec1712016-08-31 19:13:05 +0300563 hweight8(info->sseu.subslice_mask));
Imre Deak43b67992016-08-31 19:13:02 +0300564 DRM_DEBUG_DRIVER("EU total: %u\n", info->sseu.eu_total);
565 DRM_DEBUG_DRIVER("EU per subslice: %u\n", info->sseu.eu_per_subslice);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100566 DRM_DEBUG_DRIVER("has slice power gating: %s\n",
Imre Deak43b67992016-08-31 19:13:02 +0300567 info->sseu.has_slice_pg ? "y" : "n");
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100568 DRM_DEBUG_DRIVER("has subslice power gating: %s\n",
Imre Deak43b67992016-08-31 19:13:02 +0300569 info->sseu.has_subslice_pg ? "y" : "n");
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100570 DRM_DEBUG_DRIVER("has EU power gating: %s\n",
Imre Deak43b67992016-08-31 19:13:02 +0300571 info->sseu.has_eu_pg ? "y" : "n");
Lionel Landwerlinf577a032017-11-13 23:34:53 +0000572 DRM_DEBUG_DRIVER("CS timestamp frequency: %u kHz\n",
573 info->cs_timestamp_frequency_khz);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100574}