2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
7 #include <linux/cpufreq.h>
11 #include "intel_llc.h"
12 #include "intel_sideband.h"
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
;
32 policy
= cpufreq_cpu_get(0);
34 max_khz
= policy
->cpuinfo
.max_freq
;
35 cpufreq_cpu_put(policy
);
38 * Default to measured freq if none found, PCU will ensure we
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 (!HAS_LLC(i915
) || IS_DGFX(i915
))
56 if (rps
->max_freq
<= rps
->min_freq
)
59 consts
->max_ia_freq
= cpu_max_MHz();
61 consts
->min_ring_freq
=
62 intel_uncore_read(llc_to_gt(llc
)->uncore
, DCLK
) & 0xf;
63 /* convert DDR frequency from units of 266.6MHz to bandwidth */
64 consts
->min_ring_freq
= mult_frac(consts
->min_ring_freq
, 8, 3);
66 consts
->min_gpu_freq
= rps
->min_freq
;
67 consts
->max_gpu_freq
= rps
->max_freq
;
68 if (INTEL_GEN(i915
) >= 9) {
69 /* Convert GT frequency to 50 HZ units */
70 consts
->min_gpu_freq
/= GEN9_FREQ_SCALER
;
71 consts
->max_gpu_freq
/= GEN9_FREQ_SCALER
;
77 static void calc_ia_freq(struct intel_llc
*llc
,
78 unsigned int gpu_freq
,
79 const struct ia_constants
*consts
,
80 unsigned int *out_ia_freq
,
81 unsigned int *out_ring_freq
)
83 struct drm_i915_private
*i915
= llc_to_gt(llc
)->i915
;
84 const int diff
= consts
->max_gpu_freq
- gpu_freq
;
85 unsigned int ia_freq
= 0, ring_freq
= 0;
87 if (INTEL_GEN(i915
) >= 9) {
89 * ring_freq = 2 * GT. ring_freq is in 100MHz units
90 * No floor required for ring frequency on SKL.
93 } else if (INTEL_GEN(i915
) >= 8) {
94 /* max(2 * GT, DDR). NB: GT is 50MHz units */
95 ring_freq
= max(consts
->min_ring_freq
, gpu_freq
);
96 } else if (IS_HASWELL(i915
)) {
97 ring_freq
= mult_frac(gpu_freq
, 5, 4);
98 ring_freq
= max(consts
->min_ring_freq
, ring_freq
);
99 /* leave ia_freq as the default, chosen by cpufreq */
101 const int min_freq
= 15;
102 const int scale
= 180;
105 * On older processors, there is no separate ring
106 * clock domain, so in order to boost the bandwidth
107 * of the ring, we need to upclock the CPU (ia_freq).
109 * For GPU frequencies less than 750MHz,
110 * just use the lowest ring freq.
112 if (gpu_freq
< min_freq
)
115 ia_freq
= consts
->max_ia_freq
- diff
* scale
/ 2;
116 ia_freq
= DIV_ROUND_CLOSEST(ia_freq
, 100);
119 *out_ia_freq
= ia_freq
;
120 *out_ring_freq
= ring_freq
;
123 static void gen6_update_ring_freq(struct intel_llc
*llc
)
125 struct drm_i915_private
*i915
= llc_to_gt(llc
)->i915
;
126 struct ia_constants consts
;
127 unsigned int gpu_freq
;
129 if (!get_ia_constants(llc
, &consts
))
133 * For each potential GPU frequency, load a ring frequency we'd like
134 * to use for memory access. We do this by specifying the IA frequency
135 * the PCU should use as a reference to determine the ring frequency.
137 for (gpu_freq
= consts
.max_gpu_freq
;
138 gpu_freq
>= consts
.min_gpu_freq
;
140 unsigned int ia_freq
, ring_freq
;
142 calc_ia_freq(llc
, gpu_freq
, &consts
, &ia_freq
, &ring_freq
);
143 sandybridge_pcode_write(i915
,
144 GEN6_PCODE_WRITE_MIN_FREQ_TABLE
,
145 ia_freq
<< GEN6_PCODE_FREQ_IA_RATIO_SHIFT
|
146 ring_freq
<< GEN6_PCODE_FREQ_RING_RATIO_SHIFT
|
151 void intel_llc_enable(struct intel_llc
*llc
)
153 gen6_update_ring_freq(llc
);
156 void intel_llc_disable(struct intel_llc
*llc
)
158 /* Currently there is no HW configuration to be done to disable. */
161 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
162 #include "selftest_llc.c"