mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
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 <tero.kristo@linux.intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Link: https://lore.kernel.org/r/20240617060708.892981-5-tero.kristo@linux.intel.com [ij: Removed underscores from variable names] Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
parent
90583374f1
commit
69207a0f17
@ -19,7 +19,7 @@ static int uncore_instance_count;
|
||||
static DEFINE_IDA(intel_uncore_ida);
|
||||
|
||||
/* callbacks for actual HW read/write */
|
||||
static int (*uncore_read)(struct uncore_data *data, unsigned int *min, unsigned int *max);
|
||||
static int (*uncore_read)(struct uncore_data *data, unsigned int *value, enum uncore_index index);
|
||||
static int (*uncore_write)(struct uncore_data *data, unsigned int input, enum uncore_index index);
|
||||
static int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq);
|
||||
|
||||
@ -47,19 +47,16 @@ static ssize_t show_package_id(struct kobject *kobj, struct kobj_attribute *attr
|
||||
static ssize_t show_min_max_freq_khz(struct uncore_data *data,
|
||||
char *buf, enum uncore_index index)
|
||||
{
|
||||
unsigned int min, max;
|
||||
unsigned int value;
|
||||
int ret;
|
||||
|
||||
mutex_lock(&uncore_lock);
|
||||
ret = uncore_read(data, &min, &max);
|
||||
ret = uncore_read(data, &value, index);
|
||||
mutex_unlock(&uncore_lock);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (index == UNCORE_INDEX_MAX_FREQ)
|
||||
return sprintf(buf, "%u\n", max);
|
||||
|
||||
return sprintf(buf, "%u\n", min);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
}
|
||||
|
||||
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)
|
||||
sprintf(data->name, "package_%02d_die_%02d", data->package_id, data->die_id);
|
||||
}
|
||||
|
||||
uncore_read(data, &data->initial_min_freq_khz, &data->initial_max_freq_khz);
|
||||
uncore_read(data, &data->initial_min_freq_khz, UNCORE_INDEX_MIN_FREQ);
|
||||
uncore_read(data, &data->initial_max_freq_khz, UNCORE_INDEX_MAX_FREQ);
|
||||
|
||||
ret = create_attr_group(data, data->name);
|
||||
if (ret) {
|
||||
@ -269,10 +267,11 @@ void uncore_freq_remove_die_entry(struct uncore_data *data)
|
||||
}
|
||||
EXPORT_SYMBOL_NS_GPL(uncore_freq_remove_die_entry, INTEL_UNCORE_FREQUENCY);
|
||||
|
||||
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *min, unsigned int *max),
|
||||
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
|
||||
enum uncore_index index),
|
||||
int (*read_freq)(struct uncore_data *data, unsigned int *freq))
|
||||
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *value,
|
||||
enum uncore_index index),
|
||||
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
|
||||
enum uncore_index index),
|
||||
int (*read_freq)(struct uncore_data *data, unsigned int *freq))
|
||||
{
|
||||
mutex_lock(&uncore_lock);
|
||||
|
||||
|
@ -71,10 +71,11 @@ enum uncore_index {
|
||||
UNCORE_INDEX_MAX_FREQ,
|
||||
};
|
||||
|
||||
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *min, unsigned int *max),
|
||||
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
|
||||
enum uncore_index index),
|
||||
int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq));
|
||||
int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *value,
|
||||
enum uncore_index index),
|
||||
int (*write_control_freq)(struct uncore_data *data, unsigned int input,
|
||||
enum uncore_index index),
|
||||
int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq));
|
||||
void uncore_freq_common_exit(void);
|
||||
int uncore_freq_add_entry(struct uncore_data *data, int cpu);
|
||||
void uncore_freq_remove_die_entry(struct uncore_data *data);
|
||||
|
@ -78,20 +78,22 @@ struct tpmi_uncore_struct {
|
||||
|
||||
/* Helper function to read MMIO offset for max/min control frequency */
|
||||
static void read_control_freq(struct tpmi_uncore_cluster_info *cluster_info,
|
||||
unsigned int *min, unsigned int *max)
|
||||
unsigned int *value, enum uncore_index index)
|
||||
{
|
||||
u64 control;
|
||||
|
||||
control = readq(cluster_info->cluster_base + UNCORE_CONTROL_INDEX);
|
||||
*max = FIELD_GET(UNCORE_MAX_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
*min = FIELD_GET(UNCORE_MIN_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
if (index == UNCORE_INDEX_MAX_FREQ)
|
||||
*value = FIELD_GET(UNCORE_MAX_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
else
|
||||
*value = FIELD_GET(UNCORE_MIN_RATIO_MASK, control) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
}
|
||||
|
||||
#define UNCORE_MAX_RATIO FIELD_MAX(UNCORE_MAX_RATIO_MASK)
|
||||
|
||||
/* Callback for sysfs read for max/min frequencies. Called under mutex locks */
|
||||
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
|
||||
unsigned int *max)
|
||||
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *value,
|
||||
enum uncore_index index)
|
||||
{
|
||||
struct tpmi_uncore_cluster_info *cluster_info;
|
||||
|
||||
@ -99,10 +101,11 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
|
||||
|
||||
if (cluster_info->root_domain) {
|
||||
struct tpmi_uncore_struct *uncore_root = cluster_info->uncore_root;
|
||||
int i, _min = 0, _max = 0;
|
||||
unsigned int min, max, v;
|
||||
int i;
|
||||
|
||||
*min = UNCORE_MAX_RATIO * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
*max = 0;
|
||||
min = UNCORE_MAX_RATIO * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
max = 0;
|
||||
|
||||
/*
|
||||
* 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,
|
||||
|
||||
for (j = 0; j < uncore_root->pd_info[i].cluster_count; ++j) {
|
||||
read_control_freq(&uncore_root->pd_info[i].cluster_infos[j],
|
||||
&_min, &_max);
|
||||
if (*min > _min)
|
||||
*min = _min;
|
||||
if (*max < _max)
|
||||
*max = _max;
|
||||
&v, index);
|
||||
if (v < min)
|
||||
min = v;
|
||||
if (v > max)
|
||||
max = v;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == UNCORE_INDEX_MIN_FREQ)
|
||||
*value = min;
|
||||
else
|
||||
*value = max;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
read_control_freq(cluster_info, min, max);
|
||||
read_control_freq(cluster_info, value, index);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ static enum cpuhp_state uncore_hp_state __read_mostly;
|
||||
|
||||
#define UNCORE_CURRENT_RATIO_MASK GENMASK_ULL(6, 0)
|
||||
|
||||
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
|
||||
unsigned int *max)
|
||||
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *value,
|
||||
enum uncore_index index)
|
||||
{
|
||||
u64 cap;
|
||||
int ret;
|
||||
@ -55,8 +55,10 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*max = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
*min = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
if (index == UNCORE_INDEX_MAX_FREQ)
|
||||
*value = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
else
|
||||
*value = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user