xref: /openbmc/linux/arch/x86/kernel/apic/apic_noop.c (revision b2441318)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
29844ab11SCyrill Gorcunov /*
39844ab11SCyrill Gorcunov  * NOOP APIC driver.
49844ab11SCyrill Gorcunov  *
59844ab11SCyrill Gorcunov  * Does almost nothing and should be substituted by a real apic driver via
69844ab11SCyrill Gorcunov  * probe routine.
79844ab11SCyrill Gorcunov  *
89844ab11SCyrill Gorcunov  * Though in case if apic is disabled (for some reason) we try
99844ab11SCyrill Gorcunov  * to not uglify the caller's code and allow to call (some) apic routines
10f88f2b4fSCyrill Gorcunov  * like self-ipi, etc...
119844ab11SCyrill Gorcunov  */
129844ab11SCyrill Gorcunov 
139844ab11SCyrill Gorcunov #include <linux/threads.h>
149844ab11SCyrill Gorcunov #include <linux/cpumask.h>
159844ab11SCyrill Gorcunov #include <linux/string.h>
169844ab11SCyrill Gorcunov #include <linux/kernel.h>
179844ab11SCyrill Gorcunov #include <linux/ctype.h>
189844ab11SCyrill Gorcunov #include <linux/errno.h>
199844ab11SCyrill Gorcunov #include <asm/fixmap.h>
209844ab11SCyrill Gorcunov #include <asm/mpspec.h>
219844ab11SCyrill Gorcunov #include <asm/apicdef.h>
229844ab11SCyrill Gorcunov #include <asm/apic.h>
239844ab11SCyrill Gorcunov #include <asm/setup.h>
249844ab11SCyrill Gorcunov 
259844ab11SCyrill Gorcunov #include <linux/smp.h>
269844ab11SCyrill Gorcunov #include <asm/ipi.h>
279844ab11SCyrill Gorcunov 
289844ab11SCyrill Gorcunov #include <linux/interrupt.h>
299844ab11SCyrill Gorcunov #include <asm/acpi.h>
3066441bd3SIngo Molnar #include <asm/e820/api.h>
319844ab11SCyrill Gorcunov 
32f88f2b4fSCyrill Gorcunov static void noop_init_apic_ldr(void) { }
334727da2eSThomas Gleixner static void noop_send_IPI(int cpu, int vector) { }
34f88f2b4fSCyrill Gorcunov static void noop_send_IPI_mask(const struct cpumask *cpumask, int vector) { }
35f88f2b4fSCyrill Gorcunov static void noop_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector) { }
36f88f2b4fSCyrill Gorcunov static void noop_send_IPI_allbutself(int vector) { }
37f88f2b4fSCyrill Gorcunov static void noop_send_IPI_all(int vector) { }
38f88f2b4fSCyrill Gorcunov static void noop_send_IPI_self(int vector) { }
39f88f2b4fSCyrill Gorcunov static void noop_apic_wait_icr_idle(void) { }
40f88f2b4fSCyrill Gorcunov static void noop_apic_icr_write(u32 low, u32 id) { }
41f88f2b4fSCyrill Gorcunov 
42f88f2b4fSCyrill Gorcunov static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip)
439844ab11SCyrill Gorcunov {
44f88f2b4fSCyrill Gorcunov 	return -1;
459844ab11SCyrill Gorcunov }
469844ab11SCyrill Gorcunov 
47f88f2b4fSCyrill Gorcunov static u32 noop_safe_apic_wait_icr_idle(void)
48f88f2b4fSCyrill Gorcunov {
49f88f2b4fSCyrill Gorcunov 	return 0;
50f88f2b4fSCyrill Gorcunov }
519844ab11SCyrill Gorcunov 
52f88f2b4fSCyrill Gorcunov static u64 noop_apic_icr_read(void)
53f88f2b4fSCyrill Gorcunov {
54f88f2b4fSCyrill Gorcunov 	return 0;
55f88f2b4fSCyrill Gorcunov }
56f88f2b4fSCyrill Gorcunov 
57f88f2b4fSCyrill Gorcunov static int noop_phys_pkg_id(int cpuid_apic, int index_msb)
58f88f2b4fSCyrill Gorcunov {
59f88f2b4fSCyrill Gorcunov 	return 0;
60f88f2b4fSCyrill Gorcunov }
61f88f2b4fSCyrill Gorcunov 
62f88f2b4fSCyrill Gorcunov static unsigned int noop_get_apic_id(unsigned long x)
63f88f2b4fSCyrill Gorcunov {
64f88f2b4fSCyrill Gorcunov 	return 0;
65f88f2b4fSCyrill Gorcunov }
669844ab11SCyrill Gorcunov 
679844ab11SCyrill Gorcunov static int noop_probe(void)
689844ab11SCyrill Gorcunov {
69f88f2b4fSCyrill Gorcunov 	/*
70f88f2b4fSCyrill Gorcunov 	 * NOOP apic should not ever be
71f88f2b4fSCyrill Gorcunov 	 * enabled via probe routine
72f88f2b4fSCyrill Gorcunov 	 */
739844ab11SCyrill Gorcunov 	return 0;
749844ab11SCyrill Gorcunov }
759844ab11SCyrill Gorcunov 
769844ab11SCyrill Gorcunov static int noop_apic_id_registered(void)
779844ab11SCyrill Gorcunov {
78f88f2b4fSCyrill Gorcunov 	/*
79f88f2b4fSCyrill Gorcunov 	 * if we would be really "pedantic"
80f88f2b4fSCyrill Gorcunov 	 * we should pass read_apic_id() here
81f88f2b4fSCyrill Gorcunov 	 * but since NOOP suppose APIC ID = 0
82f88f2b4fSCyrill Gorcunov 	 * lets save a few cycles
83f88f2b4fSCyrill Gorcunov 	 */
84f88f2b4fSCyrill Gorcunov 	return physid_isset(0, phys_cpu_present_map);
859844ab11SCyrill Gorcunov }
869844ab11SCyrill Gorcunov 
879844ab11SCyrill Gorcunov static const struct cpumask *noop_target_cpus(void)
889844ab11SCyrill Gorcunov {
899844ab11SCyrill Gorcunov 	/* only BSP here */
909844ab11SCyrill Gorcunov 	return cpumask_of(0);
919844ab11SCyrill Gorcunov }
929844ab11SCyrill Gorcunov 
931ac322d0SSuresh Siddha static void noop_vector_allocation_domain(int cpu, struct cpumask *retmask,
941ac322d0SSuresh Siddha 					  const struct cpumask *mask)
959844ab11SCyrill Gorcunov {
969844ab11SCyrill Gorcunov 	if (cpu != 0)
979844ab11SCyrill Gorcunov 		pr_warning("APIC: Vector allocated for non-BSP cpu\n");
989d8e1066SAlexander Gordeev 	cpumask_copy(retmask, cpumask_of(cpu));
999844ab11SCyrill Gorcunov }
1009844ab11SCyrill Gorcunov 
1019844ab11SCyrill Gorcunov static u32 noop_apic_read(u32 reg)
1029844ab11SCyrill Gorcunov {
10393984fbdSBorislav Petkov 	WARN_ON_ONCE(boot_cpu_has(X86_FEATURE_APIC) && !disable_apic);
1049844ab11SCyrill Gorcunov 	return 0;
1059844ab11SCyrill Gorcunov }
1069844ab11SCyrill Gorcunov 
107f88f2b4fSCyrill Gorcunov static void noop_apic_write(u32 reg, u32 v)
108f88f2b4fSCyrill Gorcunov {
10993984fbdSBorislav Petkov 	WARN_ON_ONCE(boot_cpu_has(X86_FEATURE_APIC) && !disable_apic);
110f88f2b4fSCyrill Gorcunov }
111f88f2b4fSCyrill Gorcunov 
112404f6aacSKees Cook struct apic apic_noop __ro_after_init = {
1139844ab11SCyrill Gorcunov 	.name				= "noop",
1149844ab11SCyrill Gorcunov 	.probe				= noop_probe,
1159844ab11SCyrill Gorcunov 	.acpi_madt_oem_check		= NULL,
1169844ab11SCyrill Gorcunov 
117fa63030eSDaniel J Blueman 	.apic_id_valid			= default_apic_id_valid,
1189844ab11SCyrill Gorcunov 	.apic_id_registered		= noop_apic_id_registered,
1199844ab11SCyrill Gorcunov 
1209844ab11SCyrill Gorcunov 	.irq_delivery_mode		= dest_LowestPrio,
1219844ab11SCyrill Gorcunov 	/* logical delivery broadcast to all CPUs: */
1229844ab11SCyrill Gorcunov 	.irq_dest_mode			= 1,
1239844ab11SCyrill Gorcunov 
1249844ab11SCyrill Gorcunov 	.target_cpus			= noop_target_cpus,
1259844ab11SCyrill Gorcunov 	.disable_esr			= 0,
1269844ab11SCyrill Gorcunov 	.dest_logical			= APIC_DEST_LOGICAL,
1274c59f3e6SDavid Rientjes 	.check_apicid_used		= default_check_apicid_used,
1289844ab11SCyrill Gorcunov 
1299844ab11SCyrill Gorcunov 	.vector_allocation_domain	= noop_vector_allocation_domain,
1309844ab11SCyrill Gorcunov 	.init_apic_ldr			= noop_init_apic_ldr,
1319844ab11SCyrill Gorcunov 
1327abc0753SCyrill Gorcunov 	.ioapic_phys_id_map		= default_ioapic_phys_id_map,
1339844ab11SCyrill Gorcunov 	.setup_apic_routing		= NULL,
1349844ab11SCyrill Gorcunov 
1359844ab11SCyrill Gorcunov 	.cpu_present_to_apicid		= default_cpu_present_to_apicid,
1367abc0753SCyrill Gorcunov 	.apicid_to_cpu_present		= physid_set_mask_of_physid,
1379844ab11SCyrill Gorcunov 
1389844ab11SCyrill Gorcunov 	.check_phys_apicid_present	= default_check_phys_apicid_present,
1399844ab11SCyrill Gorcunov 
140f88f2b4fSCyrill Gorcunov 	.phys_pkg_id			= noop_phys_pkg_id,
1419844ab11SCyrill Gorcunov 
1429844ab11SCyrill Gorcunov 	.get_apic_id			= noop_get_apic_id,
1439844ab11SCyrill Gorcunov 	.set_apic_id			= NULL,
1449844ab11SCyrill Gorcunov 
14591cd9cb7SThomas Gleixner 	.cpu_mask_to_apicid		= flat_cpu_mask_to_apicid,
1469844ab11SCyrill Gorcunov 
1474727da2eSThomas Gleixner 	.send_IPI			= noop_send_IPI,
1489844ab11SCyrill Gorcunov 	.send_IPI_mask			= noop_send_IPI_mask,
1499844ab11SCyrill Gorcunov 	.send_IPI_mask_allbutself	= noop_send_IPI_mask_allbutself,
1509844ab11SCyrill Gorcunov 	.send_IPI_allbutself		= noop_send_IPI_allbutself,
1519844ab11SCyrill Gorcunov 	.send_IPI_all			= noop_send_IPI_all,
1529844ab11SCyrill Gorcunov 	.send_IPI_self			= noop_send_IPI_self,
1539844ab11SCyrill Gorcunov 
1549844ab11SCyrill Gorcunov 	.wakeup_secondary_cpu		= noop_wakeup_secondary_cpu,
1559844ab11SCyrill Gorcunov 
1569844ab11SCyrill Gorcunov 	.inquire_remote_apic		= NULL,
1579844ab11SCyrill Gorcunov 
1589844ab11SCyrill Gorcunov 	.read				= noop_apic_read,
1599844ab11SCyrill Gorcunov 	.write				= noop_apic_write,
1602a43195dSMichael S. Tsirkin 	.eoi_write			= noop_apic_write,
1619844ab11SCyrill Gorcunov 	.icr_read			= noop_apic_icr_read,
1629844ab11SCyrill Gorcunov 	.icr_write			= noop_apic_icr_write,
1639844ab11SCyrill Gorcunov 	.wait_icr_idle			= noop_apic_wait_icr_idle,
1649844ab11SCyrill Gorcunov 	.safe_wait_icr_idle		= noop_safe_apic_wait_icr_idle,
165acb8bc09STejun Heo 
166acb8bc09STejun Heo #ifdef CONFIG_X86_32
167acb8bc09STejun Heo 	.x86_32_early_logical_apicid	= noop_x86_32_early_logical_apicid,
168acb8bc09STejun Heo #endif
1699844ab11SCyrill Gorcunov };
170