blob: 8e78a75d1866ffc433cb2eb4d28dc7047a0e9a64 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/threads.h>
12#include <linux/cpumask.h>
13#include <linux/string.h>
14#include <linux/kernel.h>
15#include <linux/ctype.h>
16#include <linux/init.h>
17#include <linux/module.h>
18
19#include <asm/smp.h>
20#include <asm/ipi.h>
21
Len Brown76f58582005-08-24 12:10:49 -040022#if defined(CONFIG_ACPI)
Jason Davis90660ec2005-04-16 15:24:53 -070023#include <acpi/acpi_bus.h>
24#endif
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/* which logical CPU number maps to which CPU (physical APIC ID) */
Ravikiran G Thirumalai6c231b72005-09-06 15:17:45 -070027u8 x86_cpu_to_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
Linus Torvalds1da177e2005-04-16 15:20:36 -070028EXPORT_SYMBOL(x86_cpu_to_apicid);
29u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
30
31extern struct genapic apic_cluster;
32extern struct genapic apic_flat;
Andi Kleenf8d31192005-07-28 21:15:42 -070033extern struct genapic apic_physflat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35struct genapic *genapic = &apic_flat;
36
37
38/*
39 * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
40 */
41void __init clustered_apic_check(void)
42{
43 long i;
44 u8 clusters, max_cluster;
45 u8 id;
46 u8 cluster_cnt[NUM_APIC_CLUSTERS];
Andi Kleen70556462005-09-12 18:49:24 +020047 int max_apic = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Len Brown76f58582005-08-24 12:10:49 -040049#if defined(CONFIG_ACPI)
Jason Davis90660ec2005-04-16 15:24:53 -070050 /*
51 * Some x86_64 machines use physical APIC mode regardless of how many
52 * procs/clusters are present (x86_64 ES7000 is an example).
53 */
54 if (acpi_fadt.revision > FADT2_REVISION_ID)
55 if (acpi_fadt.force_apic_physical_destination_mode) {
56 genapic = &apic_cluster;
57 goto print;
58 }
59#endif
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 memset(cluster_cnt, 0, sizeof(cluster_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 for (i = 0; i < NR_CPUS; i++) {
63 id = bios_cpu_apicid[i];
Andi Kleenf8d31192005-07-28 21:15:42 -070064 if (id == BAD_APICID)
65 continue;
Andi Kleen70556462005-09-12 18:49:24 +020066 if (id > max_apic)
67 max_apic = id;
Andi Kleenf8d31192005-07-28 21:15:42 -070068 cluster_cnt[APIC_CLUSTERID(id)]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
Andi Kleenf8d31192005-07-28 21:15:42 -070071 /* Don't use clustered mode on AMD platforms. */
72 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
73 genapic = &apic_physflat;
Andi Kleen016102d2005-09-12 18:49:24 +020074#ifndef CONFIG_HOTPLUG_CPU
Andi Kleenf8d31192005-07-28 21:15:42 -070075 /* In the CPU hotplug case we cannot use broadcast mode
76 because that opens a race when a CPU is removed.
77 Stay at physflat mode in this case.
78 It is bad to do this unconditionally though. Once
79 we have ACPI platform support for CPU hotplug
80 we should detect hotplug capablity from ACPI tables and
81 only do this when really needed. -AK */
Andi Kleen70556462005-09-12 18:49:24 +020082 if (max_apic <= 8)
Andi Kleenf8d31192005-07-28 21:15:42 -070083 genapic = &apic_flat;
84#endif
85 goto print;
86 }
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 clusters = 0;
89 max_cluster = 0;
Andi Kleenf8d31192005-07-28 21:15:42 -070090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
92 if (cluster_cnt[i] > 0) {
93 ++clusters;
94 if (cluster_cnt[i] > max_cluster)
95 max_cluster = cluster_cnt[i];
96 }
97 }
98
99 /*
100 * If we have clusters <= 1 and CPUs <= 8 in cluster 0, then flat mode,
101 * else if max_cluster <= 4 and cluster_cnt[15] == 0, clustered logical
102 * else physical mode.
103 * (We don't use lowest priority delivery + HW APIC IRQ steering, so
104 * can ignore the clustered logical case and go straight to physical.)
105 */
Andi Kleen5bf97e02005-09-12 18:49:24 +0200106 if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster) {
107#ifdef CONFIG_HOTPLUG_CPU
108 /* Don't use APIC shortcuts in CPU hotplug to avoid races */
109 genapic = &apic_physflat;
110#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 genapic = &apic_flat;
Andi Kleen5bf97e02005-09-12 18:49:24 +0200112#endif
113 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 genapic = &apic_cluster;
115
116print:
117 printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name);
118}
119
120/* Same for both flat and clustered. */
121
122void send_IPI_self(int vector)
123{
124 __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
125}