1 From: Suresh Siddha <suresh.b.siddha@intel.com>
2 Subject: x64, x2apic/intr-remap: support for x2apic physical mode support
3 References: fate #303948 and fate #303984
4 Patch-Mainline: queued for .28
5 Commit-ID: 2d9579a124d746a3e0e0ba45e57d80800ee80807
7 Signed-off-by: Thomas Renninger <trenn@suse.de>
9 x2apic Physical mode support. By default we will use x2apic cluster mode.
10 x2apic physical mode can be selected using "x2apic_phys" boot parameter.
12 Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
13 Cc: akpm@linux-foundation.org
14 Cc: arjan@linux.intel.com
15 Cc: andi@firstfloor.org
16 Cc: ebiederm@xmission.com
17 Cc: jbarnes@virtuousgeek.org
19 Signed-off-by: Ingo Molnar <mingo@elte.hu>
22 Documentation/kernel-parameters.txt | 4 +
23 arch/x86/kernel/Makefile | 1
24 arch/x86/kernel/genapic_64.c | 18 ++++-
25 arch/x86/kernel/genx2apic_phys.c | 122 ++++++++++++++++++++++++++++++++++++
26 include/asm-x86/genapic_64.h | 1
27 5 files changed, 143 insertions(+), 3 deletions(-)
29 --- a/arch/x86/kernel/genapic_64.c
30 +++ b/arch/x86/kernel/genapic_64.c
31 @@ -30,6 +30,15 @@ DEFINE_PER_CPU(int, x2apic_extra_bits);
33 struct genapic __read_mostly *genapic = &apic_flat;
35 +static int x2apic_phys = 0;
37 +static int set_x2apic_phys_mode(char *arg)
42 +early_param("x2apic_phys", set_x2apic_phys_mode);
44 static enum uv_system_type uv_system_type;
47 @@ -39,9 +48,12 @@ void __init setup_apic_routing(void)
49 if (uv_system_type == UV_NON_UNIQUE_APIC)
50 genapic = &apic_x2apic_uv_x;
51 - else if (cpu_has_x2apic && intr_remapping_enabled)
52 - genapic = &apic_x2apic_cluster;
54 + else if (cpu_has_x2apic && intr_remapping_enabled) {
56 + genapic = &apic_x2apic_phys;
58 + genapic = &apic_x2apic_cluster;
62 * Quirk: some x86_64 machines can only use physical APIC mode
64 +++ b/arch/x86/kernel/genx2apic_phys.c
66 +#include <linux/threads.h>
67 +#include <linux/cpumask.h>
68 +#include <linux/string.h>
69 +#include <linux/kernel.h>
70 +#include <linux/ctype.h>
71 +#include <linux/init.h>
74 +#include <asm/genapic.h>
77 +/* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
79 +static cpumask_t x2apic_target_cpus(void)
81 + return cpumask_of_cpu(0);
84 +static cpumask_t x2apic_vector_allocation_domain(int cpu)
86 + cpumask_t domain = CPU_MASK_NONE;
87 + cpu_set(cpu, domain);
91 +static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
96 + cfg = __prepare_ICR(0, vector, dest);
101 + x2apic_icr_write(cfg, apicid);
104 +static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
106 + unsigned long flags;
107 + unsigned long query_cpu;
109 + local_irq_save(flags);
110 + for_each_cpu_mask(query_cpu, mask) {
111 + __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
112 + vector, APIC_DEST_PHYSICAL);
114 + local_irq_restore(flags);
117 +static void x2apic_send_IPI_allbutself(int vector)
119 + cpumask_t mask = cpu_online_map;
121 + cpu_clear(smp_processor_id(), mask);
123 + if (!cpus_empty(mask))
124 + x2apic_send_IPI_mask(mask, vector);
127 +static void x2apic_send_IPI_all(int vector)
129 + x2apic_send_IPI_mask(cpu_online_map, vector);
132 +static int x2apic_apic_id_registered(void)
137 +static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
142 + * We're using fixed IRQ delivery, can only return one phys APIC ID.
143 + * May as well be the first.
145 + cpu = first_cpu(cpumask);
146 + if ((unsigned)cpu < NR_CPUS)
147 + return per_cpu(x86_cpu_to_apicid, cpu);
152 +static unsigned int x2apic_read_id(void)
154 + return apic_read(APIC_ID);
157 +static unsigned int phys_pkg_id(int index_msb)
159 + return x2apic_read_id() >> index_msb;
162 +void x2apic_send_IPI_self(int vector)
164 + apic_write(APIC_SELF_IPI, vector);
167 +void init_x2apic_ldr(void)
172 +struct genapic apic_x2apic_phys = {
173 + .name = "physical x2apic",
174 + .int_delivery_mode = dest_Fixed,
175 + .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
176 + .target_cpus = x2apic_target_cpus,
177 + .vector_allocation_domain = x2apic_vector_allocation_domain,
178 + .apic_id_registered = x2apic_apic_id_registered,
179 + .init_apic_ldr = init_x2apic_ldr,
180 + .send_IPI_all = x2apic_send_IPI_all,
181 + .send_IPI_allbutself = x2apic_send_IPI_allbutself,
182 + .send_IPI_mask = x2apic_send_IPI_mask,
183 + .send_IPI_self = x2apic_send_IPI_self,
184 + .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
185 + .phys_pkg_id = phys_pkg_id,
186 + .read_apic_id = x2apic_read_id,
188 --- a/arch/x86/kernel/Makefile
189 +++ b/arch/x86/kernel/Makefile
190 @@ -104,6 +104,7 @@ obj-$(CONFIG_OLPC) += olpc.o
191 ifeq ($(CONFIG_X86_64),y)
192 obj-y += genapic_64.o genapic_flat_64.o genx2apic_uv_x.o tlb_uv.o
193 obj-y += genx2apic_cluster.o
194 + obj-y += genx2apic_phys.o
196 obj-$(CONFIG_X86_PM_TIMER) += pmtimer_64.o
197 obj-$(CONFIG_AUDIT) += audit_64.o
198 --- a/Documentation/kernel-parameters.txt
199 +++ b/Documentation/kernel-parameters.txt
200 @@ -1430,6 +1430,10 @@ and is between 256 and 4096 characters.
202 nox2apic [X86-64,APIC] Do not enable x2APIC mode.
204 + x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
205 + default x2apic cluster mode on platforms
208 noltlbs [PPC] Do not use large page/tlb entries for kernel
209 lowmem mapping on PPC40x.
211 --- a/include/asm-x86/genapic_64.h
212 +++ b/include/asm-x86/genapic_64.h
213 @@ -36,6 +36,7 @@ extern struct genapic *genapic;
214 extern struct genapic apic_flat;
215 extern struct genapic apic_physflat;
216 extern struct genapic apic_x2apic_cluster;
217 +extern struct genapic apic_x2apic_phys;
218 extern int acpi_madt_oem_check(char *, char *);
220 extern void apic_send_IPI_self(int vector);