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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #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 Brown | 76f5858 | 2005-08-24 12:10:49 -0400 | [diff] [blame] | 22 | #if defined(CONFIG_ACPI) |
Jason Davis | 90660ec | 2005-04-16 15:24:53 -0700 | [diff] [blame] | 23 | #include <acpi/acpi_bus.h> |
| 24 | #endif |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* which logical CPU number maps to which CPU (physical APIC ID) */ |
Ravikiran G Thirumalai | 6c231b7 | 2005-09-06 15:17:45 -0700 | [diff] [blame] | 27 | u8 x86_cpu_to_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | EXPORT_SYMBOL(x86_cpu_to_apicid); |
| 29 | u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID }; |
| 30 | |
| 31 | extern struct genapic apic_cluster; |
| 32 | extern struct genapic apic_flat; |
Andi Kleen | f8d3119 | 2005-07-28 21:15:42 -0700 | [diff] [blame] | 33 | extern struct genapic apic_physflat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 35 | struct genapic __read_mostly *genapic = &apic_flat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode. |
| 39 | */ |
| 40 | void __init clustered_apic_check(void) |
| 41 | { |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 42 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | u8 clusters, max_cluster; |
| 44 | u8 id; |
| 45 | u8 cluster_cnt[NUM_APIC_CLUSTERS]; |
Andi Kleen | 7055646 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 46 | int max_apic = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 48 | #ifdef CONFIG_ACPI |
Jason Davis | 90660ec | 2005-04-16 15:24:53 -0700 | [diff] [blame] | 49 | /* |
| 50 | * Some x86_64 machines use physical APIC mode regardless of how many |
| 51 | * procs/clusters are present (x86_64 ES7000 is an example). |
| 52 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 53 | if (acpi_gbl_FADT.header.revision > FADT2_REVISION_ID) |
| 54 | if (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL) { |
Jason Davis | 90660ec | 2005-04-16 15:24:53 -0700 | [diff] [blame] | 55 | genapic = &apic_cluster; |
| 56 | goto print; |
| 57 | } |
| 58 | #endif |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | memset(cluster_cnt, 0, sizeof(cluster_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | for (i = 0; i < NR_CPUS; i++) { |
| 62 | id = bios_cpu_apicid[i]; |
Andi Kleen | f8d3119 | 2005-07-28 21:15:42 -0700 | [diff] [blame] | 63 | if (id == BAD_APICID) |
| 64 | continue; |
Andi Kleen | 7055646 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 65 | if (id > max_apic) |
| 66 | max_apic = id; |
Andi Kleen | f8d3119 | 2005-07-28 21:15:42 -0700 | [diff] [blame] | 67 | cluster_cnt[APIC_CLUSTERID(id)]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 70 | /* |
| 71 | * Don't use clustered mode on AMD platforms, default |
| 72 | * to flat logical mode. |
| 73 | */ |
Andi Kleen | f8d3119 | 2005-07-28 21:15:42 -0700 | [diff] [blame] | 74 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 75 | /* |
| 76 | * Switch to physical flat mode if more than 8 APICs |
| 77 | * (In the case of 8 CPUs APIC ID goes from 0 to 7): |
| 78 | */ |
| 79 | if (max_apic >= 8) |
| 80 | genapic = &apic_physflat; |
Andi Kleen | f8d3119 | 2005-07-28 21:15:42 -0700 | [diff] [blame] | 81 | goto print; |
| 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | clusters = 0; |
| 85 | max_cluster = 0; |
Andi Kleen | f8d3119 | 2005-07-28 21:15:42 -0700 | [diff] [blame] | 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | for (i = 0; i < NUM_APIC_CLUSTERS; i++) { |
| 88 | if (cluster_cnt[i] > 0) { |
| 89 | ++clusters; |
| 90 | if (cluster_cnt[i] > max_cluster) |
| 91 | max_cluster = cluster_cnt[i]; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * If we have clusters <= 1 and CPUs <= 8 in cluster 0, then flat mode, |
| 97 | * else if max_cluster <= 4 and cluster_cnt[15] == 0, clustered logical |
| 98 | * else physical mode. |
| 99 | * (We don't use lowest priority delivery + HW APIC IRQ steering, so |
| 100 | * can ignore the clustered logical case and go straight to physical.) |
| 101 | */ |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 102 | if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | genapic = &apic_flat; |
Ingo Molnar | f18d397 | 2007-05-02 19:27:04 +0200 | [diff] [blame^] | 104 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | genapic = &apic_cluster; |
| 106 | |
| 107 | print: |
| 108 | printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name); |
| 109 | } |
| 110 | |
| 111 | /* Same for both flat and clustered. */ |
| 112 | |
| 113 | void send_IPI_self(int vector) |
| 114 | { |
| 115 | __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL); |
| 116 | } |