7df38c4c857597d4bd3425b24af69da69566837e
[linux-block.git] / arch / x86 / kernel / genapic_64.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/threads.h>
12 #include <linux/cpumask.h>
13 #include <linux/string.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/ctype.h>
17 #include <linux/init.h>
18 #include <linux/hardirq.h>
19
20 #include <asm/smp.h>
21 #include <asm/ipi.h>
22 #include <asm/genapic.h>
23
24 #ifdef CONFIG_ACPI
25 #include <acpi/acpi_bus.h>
26 #endif
27
28 /* which logical CPU number maps to which CPU (physical APIC ID) */
29 #ifdef CONFIG_SMP
30 u16 x86_cpu_to_apicid_init[NR_CPUS] __initdata
31                                         = { [0 ... NR_CPUS-1] = BAD_APICID };
32 void *x86_cpu_to_apicid_early_ptr;
33 #endif
34 DEFINE_PER_CPU(int, x2apic_extra_bits);
35
36 struct genapic __read_mostly *genapic = &apic_flat;
37
38 static enum uv_system_type uv_system_type;
39
40 /*
41  * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
42  */
43 void __init setup_apic_routing(void)
44 {
45         if (uv_system_type == UV_NON_UNIQUE_APIC)
46                 genapic = &apic_x2apic_uv_x;
47         else
48 #ifdef CONFIG_ACPI
49         /*
50          * Quirk: some x86_64 machines can only use physical APIC mode
51          * regardless of how many processors are present (x86_64 ES7000
52          * is an example).
53          */
54         if (acpi_gbl_FADT.header.revision > FADT2_REVISION_ID &&
55                         (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL))
56                 genapic = &apic_physflat;
57         else
58 #endif
59
60         if (cpus_weight(cpu_possible_map) <= 8)
61                 genapic = &apic_flat;
62         else
63                 genapic = &apic_physflat;
64
65         printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name);
66 }
67
68 /* Same for both flat and physical. */
69
70 void send_IPI_self(int vector)
71 {
72         __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
73 }
74
75 int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
76 {
77         if (!strcmp(oem_id, "SGI")) {
78                 if (!strcmp(oem_table_id, "UVL"))
79                         uv_system_type = UV_LEGACY_APIC;
80                 else if (!strcmp(oem_table_id, "UVX"))
81                         uv_system_type = UV_X2APIC;
82                 else if (!strcmp(oem_table_id, "UVH"))
83                         uv_system_type = UV_NON_UNIQUE_APIC;
84         }
85         return 0;
86 }
87
88 unsigned int read_apic_id(void)
89 {
90         unsigned int id;
91
92         WARN_ON(preemptible());
93         id = apic_read(APIC_ID);
94         if (uv_system_type >= UV_X2APIC)
95                 id  |= __get_cpu_var(x2apic_extra_bits);
96         return id;
97 }
98
99 enum uv_system_type get_uv_system_type(void)
100 {
101         return uv_system_type;
102 }
103
104 int is_uv_system(void)
105 {
106         return uv_system_type != UV_NONE;
107 }