treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gt / intel_llc.c
blobceb785b75c25c489a8cc3943727cc962d9ac8f76
1 /*
2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
5 */
7 #include <linux/cpufreq.h>
9 #include "i915_drv.h"
10 #include "intel_gt.h"
11 #include "intel_llc.h"
12 #include "intel_sideband.h"
14 struct ia_constants {
15 unsigned int min_gpu_freq;
16 unsigned int max_gpu_freq;
18 unsigned int min_ring_freq;
19 unsigned int max_ia_freq;
22 static struct intel_gt *llc_to_gt(struct intel_llc *llc)
24 return container_of(llc, struct intel_gt, llc);
27 static unsigned int cpu_max_MHz(void)
29 struct cpufreq_policy *policy;
30 unsigned int max_khz;
32 policy = cpufreq_cpu_get(0);
33 if (policy) {
34 max_khz = policy->cpuinfo.max_freq;
35 cpufreq_cpu_put(policy);
36 } else {
38 * Default to measured freq if none found, PCU will ensure we
39 * don't go over
41 max_khz = tsc_khz;
44 return max_khz / 1000;
47 static bool get_ia_constants(struct intel_llc *llc,
48 struct ia_constants *consts)
50 struct drm_i915_private *i915 = llc_to_gt(llc)->i915;
51 struct intel_rps *rps = &llc_to_gt(llc)->rps;
53 if (rps->max_freq <= rps->min_freq)
54 return false;
56 consts->max_ia_freq = cpu_max_MHz();
58 consts->min_ring_freq =
59 intel_uncore_read(llc_to_gt(llc)->uncore, DCLK) & 0xf;
60 /* convert DDR frequency from units of 266.6MHz to bandwidth */
61 consts->min_ring_freq = mult_frac(consts->min_ring_freq, 8, 3);
63 consts->min_gpu_freq = rps->min_freq;
64 consts->max_gpu_freq = rps->max_freq;
65 if (INTEL_GEN(i915) >= 9) {
66 /* Convert GT frequency to 50 HZ units */
67 consts->min_gpu_freq /= GEN9_FREQ_SCALER;
68 consts->max_gpu_freq /= GEN9_FREQ_SCALER;
71 return true;
74 static void calc_ia_freq(struct intel_llc *llc,
75 unsigned int gpu_freq,
76 const struct ia_constants *consts,
77 unsigned int *out_ia_freq,
78 unsigned int *out_ring_freq)
80 struct drm_i915_private *i915 = llc_to_gt(llc)->i915;
81 const int diff = consts->max_gpu_freq - gpu_freq;
82 unsigned int ia_freq = 0, ring_freq = 0;
84 if (INTEL_GEN(i915) >= 9) {
86 * ring_freq = 2 * GT. ring_freq is in 100MHz units
87 * No floor required for ring frequency on SKL.
89 ring_freq = gpu_freq;
90 } else if (INTEL_GEN(i915) >= 8) {
91 /* max(2 * GT, DDR). NB: GT is 50MHz units */
92 ring_freq = max(consts->min_ring_freq, gpu_freq);
93 } else if (IS_HASWELL(i915)) {
94 ring_freq = mult_frac(gpu_freq, 5, 4);
95 ring_freq = max(consts->min_ring_freq, ring_freq);
96 /* leave ia_freq as the default, chosen by cpufreq */
97 } else {
98 const int min_freq = 15;
99 const int scale = 180;
102 * On older processors, there is no separate ring
103 * clock domain, so in order to boost the bandwidth
104 * of the ring, we need to upclock the CPU (ia_freq).
106 * For GPU frequencies less than 750MHz,
107 * just use the lowest ring freq.
109 if (gpu_freq < min_freq)
110 ia_freq = 800;
111 else
112 ia_freq = consts->max_ia_freq - diff * scale / 2;
113 ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100);
116 *out_ia_freq = ia_freq;
117 *out_ring_freq = ring_freq;
120 static void gen6_update_ring_freq(struct intel_llc *llc)
122 struct drm_i915_private *i915 = llc_to_gt(llc)->i915;
123 struct ia_constants consts;
124 unsigned int gpu_freq;
126 if (!get_ia_constants(llc, &consts))
127 return;
130 * For each potential GPU frequency, load a ring frequency we'd like
131 * to use for memory access. We do this by specifying the IA frequency
132 * the PCU should use as a reference to determine the ring frequency.
134 for (gpu_freq = consts.max_gpu_freq;
135 gpu_freq >= consts.min_gpu_freq;
136 gpu_freq--) {
137 unsigned int ia_freq, ring_freq;
139 calc_ia_freq(llc, gpu_freq, &consts, &ia_freq, &ring_freq);
140 sandybridge_pcode_write(i915,
141 GEN6_PCODE_WRITE_MIN_FREQ_TABLE,
142 ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT |
143 ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT |
144 gpu_freq);
148 void intel_llc_enable(struct intel_llc *llc)
150 if (HAS_LLC(llc_to_gt(llc)->i915))
151 gen6_update_ring_freq(llc);
154 void intel_llc_disable(struct intel_llc *llc)
156 /* Currently there is no HW configuration to be done to disable. */
159 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
160 #include "selftest_llc.c"
161 #endif