Commit e3ede976 authored by Huang Rui's avatar Huang Rui Committed by Shuah Khan
Browse files

cpupower: Add the function to get the sysfs value from specific table



Expose the helper into cpufreq header, then cpufreq driver can use this
function to get the sysfs value if it has any specific sysfs interfaces.

Reviewed-by: default avatarShuah Khan <skhan@linuxfoundation.org>
Signed-off-by: default avatarHuang Rui <ray.huang@amd.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 083792f3
Loading
Loading
Loading
Loading
+16 −7
Original line number Original line Diff line number Diff line
@@ -83,20 +83,21 @@ static const char *cpufreq_value_files[MAX_CPUFREQ_VALUE_READ_FILES] = {
	[STATS_NUM_TRANSITIONS] = "stats/total_trans"
	[STATS_NUM_TRANSITIONS] = "stats/total_trans"
};
};



unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
						 const char **table,
						 enum cpufreq_value which)
						 unsigned int index,
						 unsigned int size)
{
{
	unsigned long value;
	unsigned long value;
	unsigned int len;
	unsigned int len;
	char linebuf[MAX_LINE_LEN];
	char linebuf[MAX_LINE_LEN];
	char *endp;
	char *endp;


	if (which >= MAX_CPUFREQ_VALUE_READ_FILES)
	if (!table || index >= size || !table[index])
		return 0;
		return 0;


	len = sysfs_cpufreq_read_file(cpu, cpufreq_value_files[which],
	len = sysfs_cpufreq_read_file(cpu, table[index], linebuf,
				linebuf, sizeof(linebuf));
				      sizeof(linebuf));


	if (len == 0)
	if (len == 0)
		return 0;
		return 0;
@@ -109,6 +110,14 @@ static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
	return value;
	return value;
}
}


static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
						 enum cpufreq_value which)
{
	return cpufreq_get_sysfs_value_from_table(cpu, cpufreq_value_files,
						  which,
						  MAX_CPUFREQ_VALUE_READ_FILES);
}

/* read access to files which contain one string */
/* read access to files which contain one string */


enum cpufreq_string {
enum cpufreq_string {
+12 −0
Original line number Original line Diff line number Diff line
@@ -203,6 +203,18 @@ int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
int cpufreq_set_frequency(unsigned int cpu,
int cpufreq_set_frequency(unsigned int cpu,
				unsigned long target_frequency);
				unsigned long target_frequency);


/*
 * get the sysfs value from specific table
 *
 * Read the value with the sysfs file name from specific table. Does
 * only work if the cpufreq driver has the specific sysfs interfaces.
 */

unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
						 const char **table,
						 unsigned int index,
						 unsigned int size);

#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif