diff options
author | David Wang <davidwang@zhaoxin.com> | 2018-05-02 22:32:44 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2018-05-13 06:06:12 -0400 |
commit | 2cc61be60e37b1856a97ccbdcca3e86e593bf06a (patch) | |
tree | a4d2eae5b8d11c1b2dd1ca8afb2a4be3c99b4e52 | |
parent | b5cf8707e6c9d85819b4bee3218ec560953149f7 (diff) |
x86/CPU: Make intel_num_cpu_cores() generic
intel_num_cpu_cores() is a static function in intel.c which can't be used
by other files. Define another function called detect_num_cpu_cores() in
common.c to replace this function so it can be reused.
Signed-off-by: David Wang <davidwang@zhaoxin.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: lukelin@viacpu.com
Cc: qiyuanwang@zhaoxin.com
Cc: gregkh@linuxfoundation.org
Cc: brucechang@via-alliance.com
Cc: timguo@zhaoxin.com
Cc: cooperyan@zhaoxin.com
Cc: hpa@zytor.com
Cc: benjaminpan@viatech.com
Link: https://lkml.kernel.org/r/1525314766-18910-2-git-send-email-davidwang@zhaoxin.com
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 14 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/cpu.h | 1 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/intel.c | 20 |
3 files changed, 16 insertions, 19 deletions
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 37c7c8334a00..6993842e788c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -584,6 +584,20 @@ static void get_model_name(struct cpuinfo_x86 *c) | |||
584 | *(s + 1) = '\0'; | 584 | *(s + 1) = '\0'; |
585 | } | 585 | } |
586 | 586 | ||
587 | int detect_num_cpu_cores(struct cpuinfo_x86 *c) | ||
588 | { | ||
589 | unsigned int eax, ebx, ecx, edx; | ||
590 | |||
591 | if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) | ||
592 | return 1; | ||
593 | |||
594 | cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); | ||
595 | if (eax & 0x1f) | ||
596 | return (eax >> 26) + 1; | ||
597 | else | ||
598 | return 1; | ||
599 | } | ||
600 | |||
587 | void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) | 601 | void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) |
588 | { | 602 | { |
589 | unsigned int n, dummy, ebx, ecx, edx, l2size; | 603 | unsigned int n, dummy, ebx, ecx, edx, l2size; |
diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index c415f99e9599..efd6ef8ad14e 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h | |||
@@ -54,6 +54,7 @@ extern u32 get_scattered_cpuid_leaf(unsigned int level, | |||
54 | extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c); | 54 | extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c); |
55 | extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); | 55 | extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); |
56 | 56 | ||
57 | extern int detect_num_cpu_cores(struct cpuinfo_x86 *c); | ||
57 | extern int detect_extended_topology(struct cpuinfo_x86 *c); | 58 | extern int detect_extended_topology(struct cpuinfo_x86 *c); |
58 | extern void detect_ht(struct cpuinfo_x86 *c); | 59 | extern void detect_ht(struct cpuinfo_x86 *c); |
59 | 60 | ||
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index b9693b80fc21..b54535be254a 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c | |||
@@ -453,24 +453,6 @@ static void srat_detect_node(struct cpuinfo_x86 *c) | |||
453 | #endif | 453 | #endif |
454 | } | 454 | } |
455 | 455 | ||
456 | /* | ||
457 | * find out the number of processor cores on the die | ||
458 | */ | ||
459 | static int intel_num_cpu_cores(struct cpuinfo_x86 *c) | ||
460 | { | ||
461 | unsigned int eax, ebx, ecx, edx; | ||
462 | |||
463 | if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) | ||
464 | return 1; | ||
465 | |||
466 | /* Intel has a non-standard dependency on %ecx for this CPUID level. */ | ||
467 | cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); | ||
468 | if (eax & 0x1f) | ||
469 | return (eax >> 26) + 1; | ||
470 | else | ||
471 | return 1; | ||
472 | } | ||
473 | |||
474 | static void detect_vmx_virtcap(struct cpuinfo_x86 *c) | 456 | static void detect_vmx_virtcap(struct cpuinfo_x86 *c) |
475 | { | 457 | { |
476 | /* Intel VMX MSR indicated features */ | 458 | /* Intel VMX MSR indicated features */ |
@@ -671,7 +653,7 @@ static void init_intel(struct cpuinfo_x86 *c) | |||
671 | * let's use the legacy cpuid vector 0x1 and 0x4 for topology | 653 | * let's use the legacy cpuid vector 0x1 and 0x4 for topology |
672 | * detection. | 654 | * detection. |
673 | */ | 655 | */ |
674 | c->x86_max_cores = intel_num_cpu_cores(c); | 656 | c->x86_max_cores = detect_num_cpu_cores(c); |
675 | #ifdef CONFIG_X86_32 | 657 | #ifdef CONFIG_X86_32 |
676 | detect_ht(c); | 658 | detect_ht(c); |
677 | #endif | 659 | #endif |