Skip to contentSkip to conversation

x86/cpu: Add supports for zhaoxin x86 platform

PATCH Superseded Davidwang 2 participants 4 messages Apr 25, 2018 – May 2, 2018

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Davidwang

author
#0 lore raw

PATCH v2 1/1 x86/cpu: Add supports for zhaoxin x86 platform

From: DavidWang <[email protected]>

Zhaoxin is a x86 IC designer. Its SOC products support both CPU virtualization and I/O virtualization, which are compatible with Intel VMX and VT-d respectively. Zhaoxin has 'Shanghai' CPU vendor ID.

---
 xen/arch/x86/cpu/Makefile          |  1 +
 xen/arch/x86/cpu/common.c          |  1 +
 xen/arch/x86/cpu/intel_cacheinfo.c |  2 +-
 xen/arch/x86/cpu/shanghai.c        | 90 ++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/cpufeature.h   |  1 +
 xen/include/asm-x86/iommu.h        |  2 +
 xen/include/asm-x86/setup.h        |  1 +
 xen/include/asm-x86/x86-vendors.h  |  3 +-
 8 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/x86/cpu/shanghai.c
xen/arch/x86/cpu/Makefile +1 -0
index 74f23ae..34a01ca 100644
@@ -7,4 +7,5 @@ obj-y += common.o
 obj-y += intel.o
 obj-y += intel_cacheinfo.o
 obj-y += mwait-idle.o
+obj-y += shanghai.o
 obj-y += vpmu.o vpmu_amd.o vpmu_intel.o
xen/arch/x86/cpu/common.c +1 -0
index 0a452ae..02863c9 100644
@@ -709,6 +709,7 @@ void __init early_cpu_init(void)
 	intel_cpu_init();
 	amd_init_cpu();
 	centaur_init_cpu();
+	shanghai_init_cpu();
 	early_cpu_detect();
 }
 
xen/arch/x86/cpu/intel_cacheinfo.c +1 -1
index 101e297..a3aec13 100644
@@ -103,7 +103,7 @@ int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf)
 	return 0;
 }
 
-static int find_num_cache_leaves(void)
+int find_num_cache_leaves(void)
 {
 	unsigned int		eax, ebx, ecx, edx;
 	union _cpuid4_leaf_eax	cache_eax;
xen/arch/x86/cpu/shanghai.c new file +90 -0

90 lines not on this page · raw message

xen/include/asm-x86/cpufeature.h +1 -0
index 4c62597..2175bd0 100644
@@ -157,6 +157,7 @@ struct cpuid4_info {
 };
 
 int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf);
+int find_num_cache_leaves(void);
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_I386_CPUFEATURE_H */
xen/include/asm-x86/iommu.h +2 -0
index 14ad048..6a6d3bf 100644
@@ -54,6 +54,7 @@ static inline const struct iommu_ops *iommu_get_ops(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return &intel_iommu_ops;
     case X86_VENDOR_AMD:
         return &amd_iommu_ops;
@@ -69,6 +70,7 @@ static inline int iommu_hardware_setup(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return intel_vtd_setup();
     case X86_VENDOR_AMD:
         return amd_iov_detect();
xen/include/asm-x86/setup.h +1 -0
index 19232af..2c2d9fd 100644
@@ -23,6 +23,7 @@ int cyrix_init_cpu(void);
 int nsc_init_cpu(void);
 int centaur_init_cpu(void);
 int transmeta_init_cpu(void);
+int shanghai_init_cpu(void);
 
 void set_nr_cpu_ids(unsigned int max_cpus);
 
xen/include/asm-x86/x86-vendors.h +2 -1
index cae5507..c53d0b9 100644
@@ -7,7 +7,8 @@
 #define X86_VENDOR_INTEL 0
 #define X86_VENDOR_AMD 1
 #define X86_VENDOR_CENTAUR 2
-#define X86_VENDOR_NUM 3
+#define X86_VENDOR_SHANGHAI 3
+#define X86_VENDOR_NUM 4
 #define X86_VENDOR_UNKNOWN 0xff
 
 #endif	/* __XEN_X86_VENDORS_H__ */
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

xen/arch/x86/cpu/intel_cacheinfo.c int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf) · line 106

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 25.04.18 at 11:51, <[email protected]> wrote:
xen/arch/x86/cpu/intel_cacheinfo.c +1 -1
@@ -103,7 +103,7 @@ int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf)
 	return 0;
 }
 
-static int find_num_cache_leaves(void)
+int find_num_cache_leaves(void)

Instead of making this function non-static, please consider re-using init_intel_cacheinfo(): All you want is skip the CPUID leaf 2 handling, and you'd better to this by altering the single if() controlling it in that function than by effectively introducing a clone. If you're concerned of some other dead code in that function, attached you'll find a patch deleting at least some of that.

Quoted 7 lines
xen/arch/x86/cpu/shanghai.c new file +4 -0
@@ -0,0 +1,90 @@
+#include <xen/bitops.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include "cpu.h"

xen/arch/x86/cpu/shanghai.c line 14

Quoted 10 lines
xen/arch/x86/cpu/shanghai.c new file +10 -0
+
+void init_shanghai_cache(struct cpuinfo_x86 *c)
+{
+	unsigned int i = 0, l1d = 0, l1i = 0, l2 = 0, l3 = 0;
+    struct cpuid4_info leaf;
+	static bool is_initialized = false;
+	static unsigned int cache_leaves = 0;
+
+	if ( (!is_initialized) && (c->cpuid_level > 0x00000003) )
+    {

If there was a convincing argument that this clone of the original function was really needed, then you'd need to go through here and clean up style (various aspects of it are broken, most notably the mix of space and tab indentation).

Quoted 11 lines
xen/include/asm-x86/iommu.h +1 -0
@@ -54,6 +54,7 @@ static inline const struct iommu_ops *iommu_get_ops(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return &intel_iommu_ops;
     case X86_VENDOR_AMD:
         return &amd_iommu_ops;

xen/include/asm-x86/iommu.h static inline int iommu_hardware_setup(void) · line 76

Quoted 7 lines
xen/include/asm-x86/iommu.h +1 -0
@@ -69,6 +70,7 @@ static inline int iommu_hardware_setup(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return intel_vtd_setup();
     case X86_VENDOR_AMD:
         return amd_iov_detect();

There are numerous further occurrences of X86_VENDOR_INTEL throughout the code base - is it really the case that no single one of them needs similar amendment?

Jan

x86: remove read code from cpuid4_cache_lookup()

... and make num_cache_leaves local to the only function using it.

xen/arch/x86/cpu/intel_cacheinfo.c +1 -9
@@ -80,8 +80,6 @@ static const struct _cache_table cache_t
 	{ 0x00, 0, 0}
 };
 
-unsigned short			num_cache_leaves;
-
 int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf)
 {
 	union _cpuid4_leaf_eax 	eax;
@@ -123,7 +121,7 @@ unsigned int init_intel_cacheinfo(struct
 	unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0; /* Cache sizes */
 	unsigned int new_l1d = 0, new_l1i = 0; /* Cache sizes from cpuid(4) */
 	unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */
-	unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb;
+	static unsigned int num_cache_leaves;
 
 	if (c->cpuid_level > 3) {
 		static int is_initialized;
@@ -156,15 +154,9 @@ unsigned int init_intel_cacheinfo(struct
 					break;
 				    case 2:
 					new_l2 = this_leaf.size/1024;
-					num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
-					index_msb = get_count_order(num_threads_sharing);
-					l2_id = c->apicid >> index_msb;
 					break;
 				    case 3:
 					new_l3 = this_leaf.size/1024;
-					num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
-					index_msb = get_count_order(num_threads_sharing);
-					l3_id = c->apicid >> index_msb;
 					break;
 				    default:
 					break;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw

Hi Jan,
Thanks for your reply. Answer as following.
________________________________________
发件人: Jan Beulich <[email protected]>
发送时间: 2018年4月30日 22:15
收件人: David Wang
抄送: xen-devel; Fiona Li(BJ-RD)
主题: Re: [PATCH v2] x86/cpu: Add supports for zhaoxin x86 platform

xen/arch/x86/cpu/intel_cacheinfo.c int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf) · line 106

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 25.04.18 at 11:51, <[email protected]> wrote:
xen/arch/x86/cpu/intel_cacheinfo.c +1 -1
@@ -103,7 +103,7 @@ int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf)
      return 0;
 }
 
-static int find_num_cache_leaves(void)
+int find_num_cache_leaves(void)

Instead of making this function non-static, please consider re-using
init_intel_cacheinfo(): All you want is skip the CPUID leaf 2 handling,
and you'd better to this by altering the single if() controlling it in that
function than by effectively introducing a clone. If you're concerned
of some other dead code in that function, attached you'll find a patch
deleting at least some of that.
[David]: Concerned the dead code in init_intel_cacheinfo(), I rewrite it. Thanks for your patch, i will re-using init_intel_cacheinfo() in next version.

Quoted 7 lines
xen/arch/x86/cpu/shanghai.c new file +4 -0
@@ -0,0 +1,90 @@
+#include <xen/bitops.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include "cpu.h"

xen/arch/x86/cpu/shanghai.c line 14

Quoted 10 lines
xen/arch/x86/cpu/shanghai.c new file +10 -0
+
+void init_shanghai_cache(struct cpuinfo_x86 *c)
+{
+     unsigned int i = 0, l1d = 0, l1i = 0, l2 = 0, l3 = 0;
+    struct cpuid4_info leaf;
+     static bool is_initialized = false;
+     static unsigned int cache_leaves = 0;
+
+     if ( (!is_initialized) && (c->cpuid_level > 0x00000003) )
+    {

If there was a convincing argument that this clone of the original function was really needed, then you'd need to go through here and clean up style (various aspects of it are broken, most notably the mix of space and tab indentation).
[David]: Sorry for my mistake.

Quoted 11 lines
xen/include/asm-x86/iommu.h +1 -0
@@ -54,6 +54,7 @@ static inline const struct iommu_ops *iommu_get_ops(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return &intel_iommu_ops;
     case X86_VENDOR_AMD:
         return &amd_iommu_ops;

xen/include/asm-x86/iommu.h static inline int iommu_hardware_setup(void) · line 76

Quoted 7 lines
xen/include/asm-x86/iommu.h +1 -0
@@ -69,6 +70,7 @@ static inline int iommu_hardware_setup(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return intel_vtd_setup();
     case X86_VENDOR_AMD:
         return amd_iov_detect();

There are numerous further occurrences of X86_VENDOR_INTEL throughout the code base - is it really the case that no single one of them needs similar amendment?
[David]: Yes, there are numerous occurrences of X86_VENDOR_INTEL, such as supporting idle_nops in arch_init_ideal_nops() or vpmu in vpmu_arch_initialise(). Some of them perfect function, others improve performance. Can we perfect those by submitting separate patches? To support the iommu, we need to re-use intel_iommu_ops() and intel_vtd_setup().

David

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 02.05.18 at 09:47, <[email protected]> wrote:

发件人: Jan Beulich <[email protected]>
发送时间: 2018年4月30日 22:15

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 25.04.18 at 11:51, <[email protected]> wrote:
xen/include/asm-x86/iommu.h +1 -0
@@ -54,6 +54,7 @@ static inline const struct iommu_ops *iommu_get_ops(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return &intel_iommu_ops;
     case X86_VENDOR_AMD:
         return &amd_iommu_ops;

xen/include/asm-x86/iommu.h static inline int iommu_hardware_setup(void) · line 76

Quoted 7 lines
xen/include/asm-x86/iommu.h +1 -0
@@ -69,6 +70,7 @@ static inline int iommu_hardware_setup(void)
     switch ( boot_cpu_data.x86_vendor )
     {
     case X86_VENDOR_INTEL:
+    case X86_VENDOR_SHANGHAI:
         return intel_vtd_setup();
     case X86_VENDOR_AMD:
         return amd_iov_detect();

There are numerous further occurrences of X86_VENDOR_INTEL throughout

Quoted 8 lines

the code base - is it really the case that no single one of them needs similar
amendment?
[David]: Yes, there are numerous occurrences of X86_VENDOR_INTEL, such as supporting idle_nops in arch_init_ideal_nops() or vpmu in vpmu_arch_initialise(). Some of them perfect function, others improve
performance. Can we perfect those by submitting separate patches? To
support the iommu, we need to re-use intel_iommu_ops() and intel_vtd_setup().

Yes, and then even the IOMMU adjustment should be split to a separate patch, I think.

Also please adjust your quoting style when replying to mails.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel