Skip to content

Commit 69207a0

Browse files
Tero Kristoij-intel
authored andcommitted
platform/x86/intel-uncore-freq: Use uncore_index with read_control_freq
Use the enumerated index for selecting the uncore driver parameter to read, instead of reading everything. This is done in preparation to expand the API to access more parameters later. No functional change intended. Signed-off-by: Tero Kristo <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ij: Removed underscores from variable names] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 9058337 commit 69207a0

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int uncore_instance_count;
1919
static DEFINE_IDA(intel_uncore_ida);
2020

2121
/* callbacks for actual HW read/write */
22-
static int (*uncore_read)(struct uncore_data *data, unsigned int *min, unsigned int *max);
22+
static int (*uncore_read)(struct uncore_data *data, unsigned int *value, enum uncore_index index);
2323
static int (*uncore_write)(struct uncore_data *data, unsigned int input, enum uncore_index index);
2424
static int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq);
2525

@@ -47,19 +47,16 @@ static ssize_t show_package_id(struct kobject *kobj, struct kobj_attribute *attr
4747
static ssize_t show_min_max_freq_khz(struct uncore_data *data,
4848
char *buf, enum uncore_index index)
4949
{
50-
unsigned int min, max;
50+
unsigned int value;
5151
int ret;
5252

5353
mutex_lock(&uncore_lock);
54-
ret = uncore_read(data, &min, &max);
54+
ret = uncore_read(data, &value, index);
5555
mutex_unlock(&uncore_lock);
5656
if (ret)
5757
return ret;
5858

59-
if (index == UNCORE_INDEX_MAX_FREQ)
60-
return sprintf(buf, "%u\n", max);
61-
62-
return sprintf(buf, "%u\n", min);
59+
return sprintf(buf, "%u\n", value);
6360
}
6461

6562
static ssize_t store_min_max_freq_khz(struct uncore_data *data,
@@ -238,7 +235,8 @@ int uncore_freq_add_entry(struct uncore_data *data, int cpu)
238235
sprintf(data->name, "package_%02d_die_%02d", data->package_id, data->die_id);
239236
}
240237

241-
uncore_read(data, &data->initial_min_freq_khz, &data->initial_max_freq_khz);
238+
uncore_read(data, &data->initial_min_freq_khz, UNCORE_INDEX_MIN_FREQ);
239+
uncore_read(data, &data->initial_max_freq_khz, UNCORE_INDEX_MAX_FREQ);
242240

243241
ret = create_attr_group(data, data->name);
244242
if (ret) {
@@ -269,10 +267,11 @@ void uncore_freq_remove_die_entry(struct uncore_data *data)
269267
}
270268
EXPORT_SYMBOL_NS_GPL(uncore_freq_remove_die_entry, INTEL_UNCORE_FREQUENCY);
271269

272-
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *min, unsigned int *max),
273-
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
274-
enum uncore_index index),
275-
int (*read_freq)(struct uncore_data *data, unsigned int *freq))
270+
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *value,
271+
enum uncore_index index),
272+
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
273+
enum uncore_index index),
274+
int (*read_freq)(struct uncore_data *data, unsigned int *freq))
276275
{
277276
mutex_lock(&uncore_lock);
278277

drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ enum uncore_index {
7171
UNCORE_INDEX_MAX_FREQ,
7272
};
7373

74-
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *min, unsigned int *max),
75-
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
76-
enum uncore_index index),
77-
int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq));
74+
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *value,
75+
enum uncore_index index),
76+
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
77+
enum uncore_index index),
78+
int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq));
7879
void uncore_freq_common_exit(void);
7980
int uncore_freq_add_entry(struct uncore_data *data, int cpu);
8081
void uncore_freq_remove_die_entry(struct uncore_data *data);

drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,34 @@ struct tpmi_uncore_struct {
7878

7979
/* Helper function to read MMIO offset for max/min control frequency */
8080
static void read_control_freq(struct tpmi_uncore_cluster_info *cluster_info,
81-
unsigned int *min, unsigned int *max)
81+
unsigned int *value, enum uncore_index index)
8282
{
8383
u64 control;
8484

8585
control = readq(cluster_info->cluster_base + UNCORE_CONTROL_INDEX);
86-
*max = FIELD_GET(UNCORE_MAX_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
87-
*min = FIELD_GET(UNCORE_MIN_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
86+
if (index == UNCORE_INDEX_MAX_FREQ)
87+
*value = FIELD_GET(UNCORE_MAX_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
88+
else
89+
*value = FIELD_GET(UNCORE_MIN_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
8890
}
8991

9092
#define UNCORE_MAX_RATIO FIELD_MAX(UNCORE_MAX_RATIO_MASK)
9193

9294
/* Callback for sysfs read for max/min frequencies. Called under mutex locks */
93-
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
94-
unsigned int *max)
95+
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *value,
96+
enum uncore_index index)
9597
{
9698
struct tpmi_uncore_cluster_info *cluster_info;
9799

98100
cluster_info = container_of(data, struct tpmi_uncore_cluster_info, uncore_data);
99101

100102
if (cluster_info->root_domain) {
101103
struct tpmi_uncore_struct *uncore_root = cluster_info->uncore_root;
102-
int i, _min = 0, _max = 0;
104+
unsigned int min, max, v;
105+
int i;
103106

104-
*min = UNCORE_MAX_RATIO * UNCORE_FREQ_KHZ_MULTIPLIER;
105-
*max = 0;
107+
min = UNCORE_MAX_RATIO * UNCORE_FREQ_KHZ_MULTIPLIER;
108+
max = 0;
106109

107110
/*
108111
* Get the max/min by looking at each cluster. Get the lowest
@@ -113,17 +116,23 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
113116

114117
for (j = 0; j < uncore_root->pd_info[i].cluster_count; ++j) {
115118
read_control_freq(&uncore_root->pd_info[i].cluster_infos[j],
116-
&_min, &_max);
117-
if (*min > _min)
118-
*min = _min;
119-
if (*max < _max)
120-
*max = _max;
119+
&v, index);
120+
if (v < min)
121+
min = v;
122+
if (v > max)
123+
max = v;
121124
}
122125
}
126+
127+
if (index == UNCORE_INDEX_MIN_FREQ)
128+
*value = min;
129+
else
130+
*value = max;
131+
123132
return 0;
124133
}
125134

126-
read_control_freq(cluster_info, min, max);
135+
read_control_freq(cluster_info, value, index);
127136

128137
return 0;
129138
}

drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static enum cpuhp_state uncore_hp_state __read_mostly;
4242

4343
#define UNCORE_CURRENT_RATIO_MASK GENMASK_ULL(6, 0)
4444

45-
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
46-
unsigned int *max)
45+
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *value,
46+
enum uncore_index index)
4747
{
4848
u64 cap;
4949
int ret;
@@ -55,8 +55,10 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
5555
if (ret)
5656
return ret;
5757

58-
*max = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
59-
*min = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
58+
if (index == UNCORE_INDEX_MAX_FREQ)
59+
*value = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
60+
else
61+
*value = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
6062

6163
return 0;
6264
}

0 commit comments

Comments
 (0)