This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / x86_64 / kernel / genapic.c
1 /*
2  * Copyright 2004 James Cleverdon, IBM.
3  * Subject to the GNU Public License, v.2
4  *
5  * Generic APIC sub-arch probe layer.
6  *
7  * Hacked for x86-64 by James Cleverdon from i386 architecture code by
8  * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
9  * James Cleverdon.
10  */
11 #include <linux/config.h>
12 #include <linux/threads.h>
13 #include <linux/cpumask.h>
14 #include <linux/string.h>
15 #include <linux/kernel.h>
16 #include <linux/ctype.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19
20 #include <asm/smp.h>
21 #include <asm/ipi.h>
22
23 /* which logical CPU number maps to which CPU (physical APIC ID) */
24 u8 x86_cpu_to_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
25 EXPORT_SYMBOL(x86_cpu_to_apicid);
26 u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
27
28 extern struct genapic apic_cluster;
29 extern struct genapic apic_flat;
30
31 struct genapic *genapic = &apic_flat;
32
33
34 /*
35  * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
36  */
37 void __init clustered_apic_check(void)
38 {
39         long i;
40         u8 clusters, max_cluster;
41         u8 id;
42         u8 cluster_cnt[NUM_APIC_CLUSTERS];
43
44         memset(cluster_cnt, 0, sizeof(cluster_cnt));
45
46         for (i = 0; i < NR_CPUS; i++) {
47                 id = bios_cpu_apicid[i];
48                 if (id != BAD_APICID)
49                         cluster_cnt[APIC_CLUSTERID(id)]++;
50         }
51
52         clusters = 0;
53         max_cluster = 0;
54         for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
55                 if (cluster_cnt[i] > 0) {
56                         ++clusters;
57                         if (cluster_cnt[i] > max_cluster)
58                                 max_cluster = cluster_cnt[i];
59                 }
60         }
61
62         /*
63          * If we have clusters <= 1 and CPUs <= 8 in cluster 0, then flat mode,
64          * else if max_cluster <= 4 and cluster_cnt[15] == 0, clustered logical
65          * else physical mode.
66          * (We don't use lowest priority delivery + HW APIC IRQ steering, so
67          * can ignore the clustered logical case and go straight to physical.)
68          */
69         if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster)
70                 genapic = &apic_flat;
71         else
72                 genapic = &apic_cluster;
73
74         printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name);
75 }
76
77 /* Same for both flat and clustered. */
78
79 void send_IPI_self(int vector)
80 {
81         __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
82 }