new file mode 100644
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Accessor functions for the MSR_PKG_CST_CONFIG_CONTROL (0xE2) MSR, found on
+ * some Intel processors.
+ */
+
+#ifndef _MSR_PKG_CST_CONFIG_CONTROL_H
+#define _MSR_PKG_CST_CONFIG_CONTROL_H
+
+#include <asm/msr-index.h>
+#include <asm/msr.h>
+
+/**
+ * msr_pkg_cst_config_set_c1_demotion - Enable/disable C1 demotion.
+ * @set: Enable C1 demotion if true, disable it if false.
+ * @other_bits: Additional bits to set or clear in the register.
+ *
+ * Read-modify-write the MSR_PKG_CST_CONFIG_CONTROL register to enable or
+ * disable C1 demotion. The caller should take care of locking if necessary.
+ *
+ * Return: The new value of the MSR_PKG_CST_CONFIG_CONTROL register after
+ * modification.
+ */
+static inline unsigned long long
+msr_pkg_cst_config_set_c1_demotion(bool set, unsigned long long other_bits)
+{
+ unsigned long long val;
+
+ rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, val);
+
+ if (set)
+ val |= NHM_C1_AUTO_DEMOTE | other_bits;
+ else
+ val &= ~(NHM_C1_AUTO_DEMOTE | other_bits);
+
+ wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, val);
+
+ return val;
+}
+
+#endif /* _MSR_PKG_CST_CONFIG_CONTROL_H */
@@ -60,6 +60,7 @@
#include <asm/spec-ctrl.h>
#include <asm/tsc.h>
#include <asm/fpu/api.h>
+#include <asm/msr_pkg_cst_config_control.h>
#define INTEL_IDLE_VERSION "0.5.1"
@@ -2325,18 +2326,11 @@ static void __init intel_idle_cpuidle_devices_uninit(void)
static void intel_c1_demotion_toggle(void *enable)
{
- unsigned long long msr_val;
-
- rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
/*
* Enable/disable C1 undemotion along with C1 demotion, as this is the
* most sensible configuration in general.
*/
- if (enable)
- msr_val |= NHM_C1_AUTO_DEMOTE | SNB_C1_AUTO_UNDEMOTE;
- else
- msr_val &= ~(NHM_C1_AUTO_DEMOTE | SNB_C1_AUTO_UNDEMOTE);
- wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
+ msr_pkg_cst_config_set_c1_demotion(!!enable, SNB_C1_AUTO_UNDEMOTE);
}
static ssize_t intel_c1_demotion_store(struct device *dev,
@@ -10,6 +10,7 @@
#include <linux/smp.h>
#include <linux/suspend.h>
+#include <asm/msr_pkg_cst_config_control.h>
#include "core.h"
/* Cannon Lake: PGD PFET Enable Ack Status Register(s) bitmap */
@@ -227,10 +228,8 @@ static void disable_c1_auto_demote(void *unused)
int cpunum = smp_processor_id();
u64 val;
- rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, val);
- per_cpu(pkg_cst_config, cpunum) = val;
- val &= ~NHM_C1_AUTO_DEMOTE;
- wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, val);
+ val = msr_pkg_cst_config_set_c1_demotion(false, 0)
+ per_cpu(pkg_cst_config, cpunum) = val
pr_debug("%s: cpu:%d cst %llx\n", __func__, cpunum, val);
}