Skip to content

Commit dcd32b6

Browse files
yhluIngo Molnar
authored andcommitted
x86: make 64-bit identify_cpu use cpu_dev
we may need to move some functions to common.c later Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 3a27dd1 commit dcd32b6

5 files changed

Lines changed: 95 additions & 55 deletions

File tree

‎arch/x86/kernel/cpu/amd_64.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
#include <mach_apic.h>
99

10-
extern int __cpuinit get_model_name(struct cpuinfo_x86 *c);
11-
extern void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c);
10+
#include "cpu.h"
1211

1312
int force_mwait __cpuinitdata;
1413

@@ -109,7 +108,7 @@ static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
109108
#endif
110109
}
111110

112-
void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
111+
static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
113112
{
114113
early_init_amd_mc(c);
115114

@@ -118,7 +117,7 @@ void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
118117
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
119118
}
120119

121-
void __cpuinit init_amd(struct cpuinfo_x86 *c)
120+
static void __cpuinit init_amd(struct cpuinfo_x86 *c)
122121
{
123122
unsigned level;
124123

@@ -200,3 +199,13 @@ void __cpuinit init_amd(struct cpuinfo_x86 *c)
200199
set_memory_4k((unsigned long)__va(tseg), 1);
201200
}
202201
}
202+
203+
static struct cpu_dev amd_cpu_dev __cpuinitdata = {
204+
.c_vendor = "AMD",
205+
.c_ident = { "AuthenticAMD" },
206+
.c_early_init = early_init_amd,
207+
.c_init = init_amd,
208+
};
209+
210+
cpu_vendor_dev_register(X86_VENDOR_AMD, &amd_cpu_dev);
211+

‎arch/x86/kernel/cpu/centaur_64.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#include <asm/cpufeature.h>
55
#include <asm/processor.h>
66

7-
void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
7+
#include "cpu.h"
8+
9+
static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
810
{
911
if (c->x86 == 0x6 && c->x86_model >= 0xf)
1012
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
1113
}
1214

13-
void __cpuinit init_centaur(struct cpuinfo_x86 *c)
15+
static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
1416
{
1517
/* Cache sizes */
1618
unsigned n;
@@ -29,3 +31,13 @@ void __cpuinit init_centaur(struct cpuinfo_x86 *c)
2931
}
3032
set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
3133
}
34+
35+
static struct cpu_dev centaur_cpu_dev __cpuinitdata = {
36+
.c_vendor = "Centaur",
37+
.c_ident = { "CentaurHauls" },
38+
.c_early_init = early_init_centaur,
39+
.c_init = init_centaur,
40+
};
41+
42+
cpu_vendor_dev_register(X86_VENDOR_CENTAUR, &centaur_cpu_dev);
43+

‎arch/x86/kernel/cpu/cpu.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#ifdef CONFIG_X86_32
1+
#ifndef ARCH_X86_CPU_H
2+
3+
#define ARCH_X86_CPU_H
24

35
struct cpu_model_info {
46
int vendor;
@@ -38,4 +40,4 @@ extern struct cpu_vendor_dev __x86cpuvendor_start[], __x86cpuvendor_end[];
3840
extern int get_model_name(struct cpuinfo_x86 *c);
3941
extern void display_cacheinfo(struct cpuinfo_x86 *c);
4042

41-
#endif /* CONFIG_X86_32 */
43+
#endif

‎arch/x86/kernel/cpu/intel_64.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <asm/topology.h>
66
#include <asm/numa_64.h>
77

8-
void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
8+
#include "cpu.h"
9+
10+
static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
911
{
1012
if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
1113
(c->x86 == 0x6 && c->x86_model >= 0x0e))
@@ -48,7 +50,7 @@ static void __cpuinit srat_detect_node(void)
4850
#endif
4951
}
5052

51-
void __cpuinit init_intel(struct cpuinfo_x86 *c)
53+
static void __cpuinit init_intel(struct cpuinfo_x86 *c)
5254
{
5355
/* Cache sizes */
5456
unsigned n;
@@ -90,3 +92,12 @@ void __cpuinit init_intel(struct cpuinfo_x86 *c)
9092

9193
srat_detect_node();
9294
}
95+
96+
static struct cpu_dev intel_cpu_dev __cpuinitdata = {
97+
.c_vendor = "Intel",
98+
.c_ident = { "GenuineIntel" },
99+
.c_early_init = early_init_intel,
100+
.c_init = init_intel,
101+
};
102+
cpu_vendor_dev_register(X86_VENDOR_INTEL, &intel_cpu_dev);
103+

‎arch/x86/kernel/setup_64.c‎

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
#define ARCH_SETUP
8181
#endif
8282

83+
#include "cpu/cpu.h"
84+
8385
/*
8486
* Machine setup..
8587
*/
@@ -163,6 +165,7 @@ static struct resource bss_resource = {
163165
.flags = IORESOURCE_RAM,
164166
};
165167

168+
static void __init early_cpu_init(void);
166169
static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
167170

168171
#ifdef CONFIG_PROC_VMCORE
@@ -339,6 +342,7 @@ void __init setup_arch(char **cmdline_p)
339342
bss_resource.start = virt_to_phys(&__bss_start);
340343
bss_resource.end = virt_to_phys(&__bss_stop)-1;
341344

345+
early_cpu_init();
342346
early_identify_cpu(&boot_cpu_data);
343347

344348
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
@@ -524,6 +528,19 @@ void __init setup_arch(char **cmdline_p)
524528
check_enable_amd_mmconf_dmi();
525529
}
526530

531+
struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
532+
533+
static void __cpuinit default_init(struct cpuinfo_x86 *c)
534+
{
535+
display_cacheinfo(c);
536+
}
537+
538+
static struct cpu_dev __cpuinitdata default_cpu = {
539+
.c_init = default_init,
540+
.c_vendor = "Unknown",
541+
};
542+
static struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
543+
527544
int __cpuinit get_model_name(struct cpuinfo_x86 *c)
528545
{
529546
unsigned int *v;
@@ -625,24 +642,37 @@ void __cpuinit detect_ht(struct cpuinfo_x86 *c)
625642
static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
626643
{
627644
char *v = c->x86_vendor_id;
628-
629-
if (!strcmp(v, "AuthenticAMD"))
630-
c->x86_vendor = X86_VENDOR_AMD;
631-
else if (!strcmp(v, "GenuineIntel"))
632-
c->x86_vendor = X86_VENDOR_INTEL;
633-
else if (!strcmp(v, "CentaurHauls"))
634-
c->x86_vendor = X86_VENDOR_CENTAUR;
635-
else
636-
c->x86_vendor = X86_VENDOR_UNKNOWN;
645+
int i;
646+
static int printed;
647+
648+
for (i = 0; i < X86_VENDOR_NUM; i++) {
649+
if (cpu_devs[i]) {
650+
if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
651+
(cpu_devs[i]->c_ident[1] &&
652+
!strcmp(v, cpu_devs[i]->c_ident[1]))) {
653+
c->x86_vendor = i;
654+
this_cpu = cpu_devs[i];
655+
return;
656+
}
657+
}
658+
}
659+
if (!printed) {
660+
printed++;
661+
printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
662+
printk(KERN_ERR "CPU: Your system may be unstable.\n");
663+
}
664+
c->x86_vendor = X86_VENDOR_UNKNOWN;
637665
}
638666

639-
// FIXME: Needs to use cpu_vendor_dev_register
640-
extern void __cpuinit early_init_amd(struct cpuinfo_x86 *c);
641-
extern void __cpuinit init_amd(struct cpuinfo_x86 *c);
642-
extern void __cpuinit early_init_intel(struct cpuinfo_x86 *c);
643-
extern void __cpuinit init_intel(struct cpuinfo_x86 *c);
644-
extern void __cpuinit early_init_centaur(struct cpuinfo_x86 *c);
645-
extern void __cpuinit init_centaur(struct cpuinfo_x86 *c);
667+
static void __init early_cpu_init(void)
668+
{
669+
struct cpu_vendor_dev *cvdev;
670+
671+
for (cvdev = __x86cpuvendor_start ;
672+
cvdev < __x86cpuvendor_end ;
673+
cvdev++)
674+
cpu_devs[cvdev->vendor] = cvdev->cpu_dev;
675+
}
646676

647677
/* Do some early cpuid on the boot CPU to get some parameter that are
648678
needed before check_bugs. Everything advanced is in identify_cpu
@@ -722,17 +752,9 @@ static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
722752
if (c->extended_cpuid_level >= 0x80000007)
723753
c->x86_power = cpuid_edx(0x80000007);
724754

725-
switch (c->x86_vendor) {
726-
case X86_VENDOR_AMD:
727-
early_init_amd(c);
728-
break;
729-
case X86_VENDOR_INTEL:
730-
early_init_intel(c);
731-
break;
732-
case X86_VENDOR_CENTAUR:
733-
early_init_centaur(c);
734-
break;
735-
}
755+
if (c->x86_vendor != X86_VENDOR_UNKNOWN &&
756+
cpu_devs[c->x86_vendor]->c_early_init)
757+
cpu_devs[c->x86_vendor]->c_early_init(c);
736758

737759
validate_pat_support(c);
738760
}
@@ -760,24 +782,8 @@ void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
760782
* At the end of this section, c->x86_capability better
761783
* indicate the features this CPU genuinely supports!
762784
*/
763-
switch (c->x86_vendor) {
764-
case X86_VENDOR_AMD:
765-
init_amd(c);
766-
break;
767-
768-
case X86_VENDOR_INTEL:
769-
init_intel(c);
770-
break;
771-
772-
case X86_VENDOR_CENTAUR:
773-
init_centaur(c);
774-
break;
775-
776-
case X86_VENDOR_UNKNOWN:
777-
default:
778-
display_cacheinfo(c);
779-
break;
780-
}
785+
if (this_cpu->c_init)
786+
this_cpu->c_init(c);
781787

782788
detect_ht(c);
783789

0 commit comments

Comments
 (0)