Commit 322e0add authored by leoliu-oc's avatar leoliu-oc
Browse files

Update zhaoxin cputemp driver with using the same MSR uniformly

zhaoxin inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I914B8


CVE: NA

-----------------

Unify the way of obtaining temperature values for various models of
processors.

Signed-off-by: default avatarleoliu-oc <leoliu-oc@zhaoxin.com>
parent effc5ce5
Loading
Loading
Loading
Loading
+4 −31
Original line number Diff line number Diff line
@@ -15,9 +15,9 @@
#include <linux/mutex.h>
#include <linux/list.h>
#include <linux/platform_device.h>
#include <linux/processor.h>
#include <linux/cpu.h>
#include <asm/msr.h>
#include <asm/processor.h>
#include <asm/cpu_device_id.h>

#define DRVNAME "zhaoxin_cputemp"
@@ -33,7 +33,6 @@ struct zhaoxin_cputemp_data {
	u32 msr_temp;
	u32 msr_crit;
	u32 msr_max;
	u32 msr_index;
};

/* Sysfs stuff */
@@ -51,7 +50,6 @@ static ssize_t name_show(struct device *dev, struct device_attribute *devattr, c
	return ret;
}

static int temperature_access(struct zhaoxin_cputemp_data *data, u32 *l, u32 *h);
static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, char *buf)
{
	struct zhaoxin_cputemp_data *data = dev_get_drvdata(dev);
@@ -110,28 +108,6 @@ static const struct attribute_group zhaoxin_cputemp_group = {
	.attrs = zhaoxin_cputemp_attributes,
};

static int temperature_access(struct zhaoxin_cputemp_data *data, u32 *l, u32 *h)
{
	int err;
	*l = 0x19;

	if (data->msr_index) {
		err = wrmsr_safe_on_cpu(data->id, data->msr_index, *l, *h);
		if (err) {
			pr_info("Unable to write TEMPERATURE INDEX MSR\n");
			return err;
		}
	}

	*l = 0;
	err = rdmsr_safe_on_cpu(data->id, data->msr_temp, l, h);
	if (err) {
		pr_info("Unable to read TEMPERATURE DATA MSR\n");
		return err;
	}
	return 0;
}

static int zhaoxin_cputemp_probe(struct platform_device *pdev)
{
	struct zhaoxin_cputemp_data *data;
@@ -145,20 +121,17 @@ static int zhaoxin_cputemp_probe(struct platform_device *pdev)

	data->id = pdev->id;
	data->name = "zhaoxin_cputemp";
	data->msr_temp = 0x1423;
	if (c->x86_model == 0x6b) {
		data->msr_index = 0x174c;
		data->msr_temp  = 0x174d;
		data->msr_crit  = 0x175b;
		data->msr_max   = 0x175a;
	} else {
		data->msr_index = 0;
		data->msr_temp = 0x1423;
		data->msr_crit = 0x1416;
		data->msr_max = 0x1415;
	}

	/* test if we can access the TEMPERATURE MSR */
	err = temperature_access(data, &eax, &edx);
	err = rdmsr_safe_on_cpu(data->id, data->msr_temp, &eax, &edx);
	if (err) {
		dev_err(&pdev->dev, "Unable to access TEMPERATURE MSR, giving up\n");
		return err;
@@ -269,7 +242,7 @@ static int zhaoxin_cputemp_down_prep(unsigned int cpu)
	return 0;
}

static const struct x86_cpu_id __initconst cputemp_ids[] = {
static const struct x86_cpu_id cputemp_ids[] __initconst = {
	X86_MATCH_VENDOR_FAM_MODEL(CENTAUR, 7, 0x3b, NULL),
	X86_MATCH_VENDOR_FAM_MODEL(ZHAOXIN, 7, 0x3b, NULL),
	X86_MATCH_VENDOR_FAM_MODEL(CENTAUR, 7, 0x5b, NULL),