Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jason Davis | 90660ec | 2005-04-16 15:24:53 -0700 | [diff] [blame] | 23 | #if defined(CONFIG_ACPI_BUS) |
| 24 | #include <acpi/acpi_bus.h> |
| 25 | #endif |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /* which logical CPU number maps to which CPU (physical APIC ID) */ |
| 28 | u8 x86_cpu_to_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID }; |
| 29 | EXPORT_SYMBOL(x86_cpu_to_apicid); |
| 30 | u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID }; |
| 31 | |
| 32 | extern struct genapic apic_cluster; |
| 33 | extern struct genapic apic_flat; |
| 34 | |
| 35 | struct genapic *genapic = &apic_flat; |
| 36 | |
| 37 | |
| 38 | /* |
| 39 | * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode. |
| 40 | */ |
| 41 | void __init clustered_apic_check(void) |
| 42 | { |
| 43 | long i; |
| 44 | u8 clusters, max_cluster; |
| 45 | u8 id; |
| 46 | u8 cluster_cnt[NUM_APIC_CLUSTERS]; |
| 47 | |
| 48 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { |
| 49 | /* AMD always uses flat mode right now */ |
| 50 | genapic = &apic_flat; |
| 51 | goto print; |
| 52 | } |
| 53 | |
Jason Davis | 90660ec | 2005-04-16 15:24:53 -0700 | [diff] [blame] | 54 | #if defined(CONFIG_ACPI_BUS) |
| 55 | /* |
| 56 | * Some x86_64 machines use physical APIC mode regardless of how many |
| 57 | * procs/clusters are present (x86_64 ES7000 is an example). |
| 58 | */ |
| 59 | if (acpi_fadt.revision > FADT2_REVISION_ID) |
| 60 | if (acpi_fadt.force_apic_physical_destination_mode) { |
| 61 | genapic = &apic_cluster; |
| 62 | goto print; |
| 63 | } |
| 64 | #endif |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | memset(cluster_cnt, 0, sizeof(cluster_cnt)); |
| 67 | |
| 68 | for (i = 0; i < NR_CPUS; i++) { |
| 69 | id = bios_cpu_apicid[i]; |
| 70 | if (id != BAD_APICID) |
| 71 | cluster_cnt[APIC_CLUSTERID(id)]++; |
| 72 | } |
| 73 | |
| 74 | clusters = 0; |
| 75 | max_cluster = 0; |
| 76 | for (i = 0; i < NUM_APIC_CLUSTERS; i++) { |
| 77 | if (cluster_cnt[i] > 0) { |
| 78 | ++clusters; |
| 79 | if (cluster_cnt[i] > max_cluster) |
| 80 | max_cluster = cluster_cnt[i]; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * If we have clusters <= 1 and CPUs <= 8 in cluster 0, then flat mode, |
| 86 | * else if max_cluster <= 4 and cluster_cnt[15] == 0, clustered logical |
| 87 | * else physical mode. |
| 88 | * (We don't use lowest priority delivery + HW APIC IRQ steering, so |
| 89 | * can ignore the clustered logical case and go straight to physical.) |
| 90 | */ |
| 91 | if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster) |
| 92 | genapic = &apic_flat; |
| 93 | else |
| 94 | genapic = &apic_cluster; |
| 95 | |
| 96 | print: |
| 97 | printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name); |
| 98 | } |
| 99 | |
| 100 | /* Same for both flat and clustered. */ |
| 101 | |
| 102 | void send_IPI_self(int vector) |
| 103 | { |
| 104 | __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL); |
| 105 | } |