[tip:x86/cpu] x86/acpi/cstate: Add Zhaoxin processors support for cache flush policy in C3

2019-06-22 Thread tip-bot for Tony W Wang-oc
Commit-ID:  f8c0e061cb83bd528ff0843e717bcebc846d4838
Gitweb: https://git.kernel.org/tip/f8c0e061cb83bd528ff0843e717bcebc846d4838
Author: Tony W Wang-oc 
AuthorDate: Tue, 18 Jun 2019 08:37:29 +
Committer:  Thomas Gleixner 
CommitDate: Sat, 22 Jun 2019 11:45:58 +0200

x86/acpi/cstate: Add Zhaoxin processors support for cache flush policy in C3

Same as Intel, Zhaoxin MP CPUs support C3 share cache and on all
recent Zhaoxin platforms ARB_DISABLE is a nop. So set related
flags correctly in the same way as Intel does.

Signed-off-by: Tony W Wang-oc 
Signed-off-by: Thomas Gleixner 
Cc: "h...@zytor.com" 
Cc: "gre...@linuxfoundation.org" 
Cc: "r...@rjwysocki.net" 
Cc: "l...@kernel.org" 
Cc: David Wang 
Cc: "Cooper Yan(BJ-RD)" 
Cc: "Qiyuan Wang(BJ-RD)" 
Cc: "Herry Yang(BJ-RD)" 
Link: https://lkml.kernel.org/r/a370503660994669991a7f7cda7c5...@zhaoxin.com

---
 arch/x86/kernel/acpi/cstate.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c
index a5e5484988fd..caf2edccbad2 100644
--- a/arch/x86/kernel/acpi/cstate.c
+++ b/arch/x86/kernel/acpi/cstate.c
@@ -64,6 +64,21 @@ void acpi_processor_power_init_bm_check(struct 
acpi_processor_flags *flags,
c->x86_stepping >= 0x0e))
flags->bm_check = 1;
}
+
+   if (c->x86_vendor == X86_VENDOR_ZHAOXIN) {
+   /*
+* All Zhaoxin CPUs that support C3 share cache.
+* And caches should not be flushed by software while
+* entering C3 type state.
+*/
+   flags->bm_check = 1;
+   /*
+* On all recent Zhaoxin platforms, ARB_DISABLE is a nop.
+* So, set bm_control to zero to indicate that ARB_DISABLE
+* is not required while entering C3 type state.
+*/
+   flags->bm_control = 0;
+   }
 }
 EXPORT_SYMBOL(acpi_processor_power_init_bm_check);
 


[tip:x86/cpu] ACPI, x86: Add Zhaoxin processors support for NONSTOP TSC

2019-06-22 Thread tip-bot for Tony W Wang-oc
Commit-ID:  773b2f30a3fc026f3ed121a8b945b0ae19b64ec5
Gitweb: https://git.kernel.org/tip/773b2f30a3fc026f3ed121a8b945b0ae19b64ec5
Author: Tony W Wang-oc 
AuthorDate: Tue, 18 Jun 2019 08:37:14 +
Committer:  Thomas Gleixner 
CommitDate: Sat, 22 Jun 2019 11:45:57 +0200

ACPI, x86: Add Zhaoxin processors support for NONSTOP TSC

Zhaoxin CPUs have NONSTOP TSC feature, so enable the ACPI
driver support for it.

Signed-off-by: Tony W Wang-oc 
Signed-off-by: Thomas Gleixner 
Cc: "h...@zytor.com" 
Cc: "gre...@linuxfoundation.org" 
Cc: "r...@rjwysocki.net" 
Cc: "l...@kernel.org" 
Cc: David Wang 
Cc: "Cooper Yan(BJ-RD)" 
Cc: "Qiyuan Wang(BJ-RD)" 
Cc: "Herry Yang(BJ-RD)" 
Link: https://lkml.kernel.org/r/d1cfd937dabc44518d42038b55522...@zhaoxin.com

---
 drivers/acpi/acpi_pad.c   | 1 +
 drivers/acpi/processor_idle.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 6b3f1217a237..e7dc0133f817 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -64,6 +64,7 @@ static void power_saving_mwait_init(void)
case X86_VENDOR_HYGON:
case X86_VENDOR_AMD:
case X86_VENDOR_INTEL:
+   case X86_VENDOR_ZHAOXIN:
/*
 * AMD Fam10h TSC will tick in all
 * C/P/S0/S1 states when this bit is set.
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index e387a258d649..ed56c6d20b08 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -196,6 +196,7 @@ static void tsc_check_state(int state)
case X86_VENDOR_AMD:
case X86_VENDOR_INTEL:
case X86_VENDOR_CENTAUR:
+   case X86_VENDOR_ZHAOXIN:
/*
 * AMD Fam10h TSC will tick in all
 * C/P/S0/S1 states when this bit is set.


[tip:x86/cpu] x86/cpu: Create Zhaoxin processors architecture support file

2019-06-22 Thread tip-bot for Tony W Wang-oc
Commit-ID:  761fdd5e3327db6c646a09bab5ad48cd42680cd2
Gitweb: https://git.kernel.org/tip/761fdd5e3327db6c646a09bab5ad48cd42680cd2
Author: Tony W Wang-oc 
AuthorDate: Tue, 18 Jun 2019 08:37:05 +
Committer:  Thomas Gleixner 
CommitDate: Sat, 22 Jun 2019 11:45:57 +0200

x86/cpu: Create Zhaoxin processors architecture support file

Add x86 architecture support for new Zhaoxin processors.
Carve out initialization code needed by Zhaoxin processors into
a separate compilation unit.

To identify Zhaoxin CPU, add a new vendor type X86_VENDOR_ZHAOXIN
for system recognition.

Signed-off-by: Tony W Wang-oc 
Signed-off-by: Thomas Gleixner 
Cc: "h...@zytor.com" 
Cc: "gre...@linuxfoundation.org" 
Cc: "r...@rjwysocki.net" 
Cc: "l...@kernel.org" 
Cc: David Wang 
Cc: "Cooper Yan(BJ-RD)" 
Cc: "Qiyuan Wang(BJ-RD)" 
Cc: "Herry Yang(BJ-RD)" 
Link: https://lkml.kernel.org/r/01042674b2f741b2aed1f797359bd...@zhaoxin.com

---
 MAINTAINERS  |   6 ++
 arch/x86/Kconfig.cpu |  13 +++
 arch/x86/include/asm/processor.h |   3 +-
 arch/x86/kernel/cpu/Makefile |   1 +
 arch/x86/kernel/cpu/zhaoxin.c| 167 +++
 5 files changed, 189 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 57f496cff999..dfdefc6cb3a2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17477,6 +17477,12 @@ Q: 
https://patchwork.linuxtv.org/project/linux-media/list/
 S: Maintained
 F: drivers/media/dvb-frontends/zd1301_demod*
 
+ZHAOXIN PROCESSOR SUPPORT
+M: Tony W Wang-oc 
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: arch/x86/kernel/cpu/zhaoxin.c
+
 ZPOOL COMPRESSED PAGE STORAGE API
 M: Dan Streetman 
 L: linux...@kvack.org
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 6adce15268bd..8e29c991ba3e 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -480,3 +480,16 @@ config CPU_SUP_UMC_32
  CPU might render the kernel unbootable.
 
  If unsure, say N.
+
+config CPU_SUP_ZHAOXIN
+   default y
+   bool "Support Zhaoxin processors" if PROCESSOR_SELECT
+   help
+ This enables detection, tunings and quirks for Zhaoxin processors
+
+ You need this enabled if you want your kernel to run on a
+ Zhaoxin CPU. Disabling this option on other types of CPUs
+ makes the kernel a tiny bit smaller. Disabling it on a Zhaoxin
+ CPU might render the kernel unbootable.
+
+ If unsure, say N.
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index c34a35c78618..e57d2ca2ed87 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -144,7 +144,8 @@ enum cpuid_regs_idx {
 #define X86_VENDOR_TRANSMETA   7
 #define X86_VENDOR_NSC 8
 #define X86_VENDOR_HYGON   9
-#define X86_VENDOR_NUM 10
+#define X86_VENDOR_ZHAOXIN 10
+#define X86_VENDOR_NUM 11
 
 #define X86_VENDOR_UNKNOWN 0xff
 
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index 5102bf7c8192..a7d9a4cb3ab6 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_CPU_SUP_CYRIX_32)+= cyrix.o
 obj-$(CONFIG_CPU_SUP_CENTAUR)  += centaur.o
 obj-$(CONFIG_CPU_SUP_TRANSMETA_32) += transmeta.o
 obj-$(CONFIG_CPU_SUP_UMC_32)   += umc.o
+obj-$(CONFIG_CPU_SUP_ZHAOXIN)  += zhaoxin.o
 
 obj-$(CONFIG_X86_MCE)  += mce/
 obj-$(CONFIG_MTRR) += mtrr/
diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c
new file mode 100644
index ..8e6f2f4b4afe
--- /dev/null
+++ b/arch/x86/kernel/cpu/zhaoxin.c
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+
+#include 
+
+#include "cpu.h"
+
+#define MSR_ZHAOXIN_FCR57 0x1257
+
+#define ACE_PRESENT(1 << 6)
+#define ACE_ENABLED(1 << 7)
+#define ACE_FCR(1 << 7)/* MSR_ZHAOXIN_FCR */
+
+#define RNG_PRESENT(1 << 2)
+#define RNG_ENABLED(1 << 3)
+#define RNG_ENABLE (1 << 8)/* MSR_ZHAOXIN_RNG */
+
+#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW   0x0020
+#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x0040
+#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x8000
+#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC   0x0001
+#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x0002
+#define X86_VMX_FEATURE_PROC_CTLS2_VPID0x0020
+
+static void init_zhaoxin_cap(struct cpuinfo_x86 *c)
+{
+   u32  lo, hi;
+
+   /* Test for Extended Feature Flags presence */
+   if (cpuid_eax(0xC000) >= 0xC001) {
+   u32 tmp = cpuid_edx(0xC001);
+
+   /* Enable ACE unit, if present and disabled */
+   if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
+   rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+   /* Enable ACE unit */
+