ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / i386 / mach-generic / probe.c
1 /* Copyright 2003 Andi Kleen, SuSE Labs. 
2  * Subject to the GNU Public License, v.2 
3  * 
4  * Generic x86 APIC driver probe layer.
5  */  
6 #include <linux/config.h>
7 #include <linux/threads.h>
8 #include <linux/cpumask.h>
9 #include <linux/string.h>
10 #include <linux/kernel.h>
11 #include <linux/ctype.h>
12 #include <linux/init.h>
13 #include <asm/fixmap.h>
14 #include <asm/mpspec.h>
15 #include <asm/apicdef.h>
16 #include <asm/genapic.h>
17
18 extern struct genapic apic_summit;
19 extern struct genapic apic_bigsmp;
20 extern struct genapic apic_default;
21
22 struct genapic *genapic = &apic_default;
23
24 struct genapic *apic_probe[] __initdata = { 
25         &apic_summit,
26         &apic_bigsmp, 
27         &apic_default,  /* must be last */
28         NULL,
29 };
30
31 void __init generic_apic_probe(char *command_line) 
32
33         char *s;
34         int i;
35         int changed = 0;
36
37         s = strstr(command_line, "apic=");
38         if (s && (s == command_line || isspace(s[-1]))) { 
39                 char *p = strchr(s, ' '), old; 
40                 if (!p)
41                         p = strchr(s, '\0'); 
42                 old = *p; 
43                 *p = 0; 
44                 for (i = 0; !changed && apic_probe[i]; i++) {
45                         if (!strcmp(apic_probe[i]->name, s+5)) { 
46                                 changed = 1;
47                                 genapic = apic_probe[i];
48                         }
49                 }
50                 if (!changed)
51                         printk(KERN_ERR "Unknown genapic `%s' specified.\n", s);
52                 *p = old;
53         } 
54         for (i = 0; !changed && apic_probe[i]; i++) { 
55                 if (apic_probe[i]->probe()) {
56                         changed = 1;
57                         genapic = apic_probe[i]; 
58                 } 
59         }
60         /* Not visible without early console */ 
61         if (!changed) 
62                 panic("Didn't find an APIC driver"); 
63
64         printk(KERN_INFO "Using APIC driver %s\n", genapic->name);
65
66
67 /* These functions can switch the APIC even after the initial ->probe() */
68
69 int __init mps_oem_check(struct mp_config_table *mpc, char *oem, char *productid)
70
71         int i;
72         for (i = 0; apic_probe[i]; ++i) { 
73                 if (apic_probe[i]->mps_oem_check(mpc,oem,productid)) { 
74                         genapic = apic_probe[i];
75                         printk(KERN_INFO "Switched to APIC driver `%s'.\n", 
76                                genapic->name);
77                         return 1;
78                 } 
79         } 
80         return 0;
81
82
83 int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
84 {
85         int i;
86         for (i = 0; apic_probe[i]; ++i) { 
87                 if (apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id)) { 
88                         genapic = apic_probe[i];
89                         printk(KERN_INFO "Switched to APIC driver `%s'.\n", 
90                                genapic->name);
91                         return 1;
92                 } 
93         } 
94         return 0;       
95 }
96
97 int hard_smp_processor_id(void)
98 {
99         return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
100 }