xref: /openbmc/linux/arch/x86/kernel/apic/x2apic_phys.c (revision 79deb8e511bd6fc8e40add4da75b19df085d9453)
1f62bae50SIngo Molnar #include <linux/threads.h>
2f62bae50SIngo Molnar #include <linux/cpumask.h>
3f62bae50SIngo Molnar #include <linux/string.h>
4f62bae50SIngo Molnar #include <linux/kernel.h>
5f62bae50SIngo Molnar #include <linux/ctype.h>
6f62bae50SIngo Molnar #include <linux/init.h>
7f62bae50SIngo Molnar #include <linux/dmar.h>
8f62bae50SIngo Molnar 
9f62bae50SIngo Molnar #include <asm/smp.h>
10*79deb8e5SCyrill Gorcunov #include <asm/x2apic.h>
11f62bae50SIngo Molnar 
12ef1f87aaSSuresh Siddha int x2apic_phys;
13f62bae50SIngo Molnar 
14f62bae50SIngo Molnar static int set_x2apic_phys_mode(char *arg)
15f62bae50SIngo Molnar {
16f62bae50SIngo Molnar 	x2apic_phys = 1;
17f62bae50SIngo Molnar 	return 0;
18f62bae50SIngo Molnar }
19f62bae50SIngo Molnar early_param("x2apic_phys", set_x2apic_phys_mode);
20f62bae50SIngo Molnar 
21f62bae50SIngo Molnar static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
22f62bae50SIngo Molnar {
23ef1f87aaSSuresh Siddha 	if (x2apic_phys)
24ef1f87aaSSuresh Siddha 		return x2apic_enabled();
25ef1f87aaSSuresh Siddha 	else
26f62bae50SIngo Molnar 		return 0;
27f62bae50SIngo Molnar }
28f62bae50SIngo Molnar 
29f62bae50SIngo Molnar static void
30a27d0b5eSSuresh Siddha __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
31f62bae50SIngo Molnar {
32f62bae50SIngo Molnar 	unsigned long query_cpu;
33a27d0b5eSSuresh Siddha 	unsigned long this_cpu;
34f62bae50SIngo Molnar 	unsigned long flags;
35f62bae50SIngo Molnar 
36ce4e240cSSuresh Siddha 	x2apic_wrmsr_fence();
37ce4e240cSSuresh Siddha 
38f62bae50SIngo Molnar 	local_irq_save(flags);
39a27d0b5eSSuresh Siddha 
40a27d0b5eSSuresh Siddha 	this_cpu = smp_processor_id();
41f62bae50SIngo Molnar 	for_each_cpu(query_cpu, mask) {
42a27d0b5eSSuresh Siddha 		if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
43f62bae50SIngo Molnar 			continue;
44f62bae50SIngo Molnar 		__x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
45f62bae50SIngo Molnar 				       vector, APIC_DEST_PHYSICAL);
46f62bae50SIngo Molnar 	}
47f62bae50SIngo Molnar 	local_irq_restore(flags);
48f62bae50SIngo Molnar }
49f62bae50SIngo Molnar 
50a27d0b5eSSuresh Siddha static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
51a27d0b5eSSuresh Siddha {
52a27d0b5eSSuresh Siddha 	__x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
53a27d0b5eSSuresh Siddha }
54a27d0b5eSSuresh Siddha 
55a27d0b5eSSuresh Siddha static void
56a27d0b5eSSuresh Siddha  x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
57a27d0b5eSSuresh Siddha {
58a27d0b5eSSuresh Siddha 	__x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
59a27d0b5eSSuresh Siddha }
60a27d0b5eSSuresh Siddha 
61a27d0b5eSSuresh Siddha static void x2apic_send_IPI_allbutself(int vector)
62a27d0b5eSSuresh Siddha {
63a27d0b5eSSuresh Siddha 	__x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT);
64a27d0b5eSSuresh Siddha }
65a27d0b5eSSuresh Siddha 
66f62bae50SIngo Molnar static void x2apic_send_IPI_all(int vector)
67f62bae50SIngo Molnar {
68a27d0b5eSSuresh Siddha 	__x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC);
69f62bae50SIngo Molnar }
70f62bae50SIngo Molnar 
71f62bae50SIngo Molnar static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
72f62bae50SIngo Molnar {
73f62bae50SIngo Molnar 	/*
74f62bae50SIngo Molnar 	 * We're using fixed IRQ delivery, can only return one phys APIC ID.
75f62bae50SIngo Molnar 	 * May as well be the first.
76f62bae50SIngo Molnar 	 */
77f62bae50SIngo Molnar 	int cpu = cpumask_first(cpumask);
78f62bae50SIngo Molnar 
79f62bae50SIngo Molnar 	if ((unsigned)cpu < nr_cpu_ids)
80f62bae50SIngo Molnar 		return per_cpu(x86_cpu_to_apicid, cpu);
81f62bae50SIngo Molnar 	else
82f62bae50SIngo Molnar 		return BAD_APICID;
83f62bae50SIngo Molnar }
84f62bae50SIngo Molnar 
85f62bae50SIngo Molnar static unsigned int
86f62bae50SIngo Molnar x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
87f62bae50SIngo Molnar 			      const struct cpumask *andmask)
88f62bae50SIngo Molnar {
89f62bae50SIngo Molnar 	int cpu;
90f62bae50SIngo Molnar 
91f62bae50SIngo Molnar 	/*
92f62bae50SIngo Molnar 	 * We're using fixed IRQ delivery, can only return one phys APIC ID.
93f62bae50SIngo Molnar 	 * May as well be the first.
94f62bae50SIngo Molnar 	 */
95f62bae50SIngo Molnar 	for_each_cpu_and(cpu, cpumask, andmask) {
96f62bae50SIngo Molnar 		if (cpumask_test_cpu(cpu, cpu_online_mask))
97f62bae50SIngo Molnar 			break;
98f62bae50SIngo Molnar 	}
99f62bae50SIngo Molnar 
100f62bae50SIngo Molnar 	return per_cpu(x86_cpu_to_apicid, cpu);
101f62bae50SIngo Molnar }
102f62bae50SIngo Molnar 
103f62bae50SIngo Molnar static void init_x2apic_ldr(void)
104f62bae50SIngo Molnar {
105f62bae50SIngo Molnar }
106f62bae50SIngo Molnar 
1079ebd680bSSuresh Siddha static int x2apic_phys_probe(void)
1089ebd680bSSuresh Siddha {
1099ebd680bSSuresh Siddha 	if (x2apic_mode && x2apic_phys)
1109ebd680bSSuresh Siddha 		return 1;
1119ebd680bSSuresh Siddha 
1129ebd680bSSuresh Siddha 	return apic == &apic_x2apic_phys;
1139ebd680bSSuresh Siddha }
1149ebd680bSSuresh Siddha 
115f62bae50SIngo Molnar struct apic apic_x2apic_phys = {
116f62bae50SIngo Molnar 
117f62bae50SIngo Molnar 	.name				= "physical x2apic",
1189ebd680bSSuresh Siddha 	.probe				= x2apic_phys_probe,
119f62bae50SIngo Molnar 	.acpi_madt_oem_check		= x2apic_acpi_madt_oem_check,
120f62bae50SIngo Molnar 	.apic_id_registered		= x2apic_apic_id_registered,
121f62bae50SIngo Molnar 
122f62bae50SIngo Molnar 	.irq_delivery_mode		= dest_Fixed,
123f62bae50SIngo Molnar 	.irq_dest_mode			= 0, /* physical */
124f62bae50SIngo Molnar 
125f62bae50SIngo Molnar 	.target_cpus			= x2apic_target_cpus,
126f62bae50SIngo Molnar 	.disable_esr			= 0,
127f62bae50SIngo Molnar 	.dest_logical			= 0,
128f62bae50SIngo Molnar 	.check_apicid_used		= NULL,
129f62bae50SIngo Molnar 	.check_apicid_present		= NULL,
130f62bae50SIngo Molnar 
131f62bae50SIngo Molnar 	.vector_allocation_domain	= x2apic_vector_allocation_domain,
132f62bae50SIngo Molnar 	.init_apic_ldr			= init_x2apic_ldr,
133f62bae50SIngo Molnar 
134f62bae50SIngo Molnar 	.ioapic_phys_id_map		= NULL,
135f62bae50SIngo Molnar 	.setup_apic_routing		= NULL,
136f62bae50SIngo Molnar 	.multi_timer_check		= NULL,
137f62bae50SIngo Molnar 	.cpu_present_to_apicid		= default_cpu_present_to_apicid,
138f62bae50SIngo Molnar 	.apicid_to_cpu_present		= NULL,
139f62bae50SIngo Molnar 	.setup_portio_remap		= NULL,
140f62bae50SIngo Molnar 	.check_phys_apicid_present	= default_check_phys_apicid_present,
141f62bae50SIngo Molnar 	.enable_apic_mode		= NULL,
142f62bae50SIngo Molnar 	.phys_pkg_id			= x2apic_phys_pkg_id,
143f62bae50SIngo Molnar 	.mps_oem_check			= NULL,
144f62bae50SIngo Molnar 
145*79deb8e5SCyrill Gorcunov 	.get_apic_id			= x2apic_get_apic_id,
146*79deb8e5SCyrill Gorcunov 	.set_apic_id			= x2apic_set_apic_id,
147f62bae50SIngo Molnar 	.apic_id_mask			= 0xFFFFFFFFu,
148f62bae50SIngo Molnar 
149f62bae50SIngo Molnar 	.cpu_mask_to_apicid		= x2apic_cpu_mask_to_apicid,
150f62bae50SIngo Molnar 	.cpu_mask_to_apicid_and		= x2apic_cpu_mask_to_apicid_and,
151f62bae50SIngo Molnar 
152f62bae50SIngo Molnar 	.send_IPI_mask			= x2apic_send_IPI_mask,
153f62bae50SIngo Molnar 	.send_IPI_mask_allbutself	= x2apic_send_IPI_mask_allbutself,
154f62bae50SIngo Molnar 	.send_IPI_allbutself		= x2apic_send_IPI_allbutself,
155f62bae50SIngo Molnar 	.send_IPI_all			= x2apic_send_IPI_all,
156f62bae50SIngo Molnar 	.send_IPI_self			= x2apic_send_IPI_self,
157f62bae50SIngo Molnar 
158f62bae50SIngo Molnar 	.trampoline_phys_low		= DEFAULT_TRAMPOLINE_PHYS_LOW,
159f62bae50SIngo Molnar 	.trampoline_phys_high		= DEFAULT_TRAMPOLINE_PHYS_HIGH,
160f62bae50SIngo Molnar 	.wait_for_init_deassert		= NULL,
161f62bae50SIngo Molnar 	.smp_callin_clear_local_apic	= NULL,
162f62bae50SIngo Molnar 	.inquire_remote_apic		= NULL,
163f62bae50SIngo Molnar 
164f62bae50SIngo Molnar 	.read				= native_apic_msr_read,
165f62bae50SIngo Molnar 	.write				= native_apic_msr_write,
166f62bae50SIngo Molnar 	.icr_read			= native_x2apic_icr_read,
167f62bae50SIngo Molnar 	.icr_write			= native_x2apic_icr_write,
168f62bae50SIngo Molnar 	.wait_icr_idle			= native_x2apic_wait_icr_idle,
169f62bae50SIngo Molnar 	.safe_wait_icr_idle		= native_safe_x2apic_wait_icr_idle,
170f62bae50SIngo Molnar };
171