1 /*
2  * NOOP APIC driver.
3  *
4  * Does almost nothing and should be substituted by a real apic driver via
5  * probe routine.
6  *
7  * Though in case if apic is disabled (for some reason) we try
8  * to not uglify the caller's code and allow to call (some) apic routines
9  * like self-ipi, etc...
10  */
11 
12 #include <linux/threads.h>
13 #include <linux/cpumask.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
16 #include <linux/kernel.h>
17 #include <linux/ctype.h>
18 #include <linux/init.h>
19 #include <linux/errno.h>
20 #include <asm/fixmap.h>
21 #include <asm/mpspec.h>
22 #include <asm/apicdef.h>
23 #include <asm/apic.h>
24 #include <asm/setup.h>
25 
26 #include <linux/smp.h>
27 #include <asm/ipi.h>
28 
29 #include <linux/interrupt.h>
30 #include <asm/acpi.h>
31 #include <asm/e820.h>
32 
noop_init_apic_ldr(void)33 static void noop_init_apic_ldr(void) { }
noop_send_IPI_mask(const struct cpumask * cpumask,int vector)34 static void noop_send_IPI_mask(const struct cpumask *cpumask, int vector) { }
noop_send_IPI_mask_allbutself(const struct cpumask * cpumask,int vector)35 static void noop_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector) { }
noop_send_IPI_allbutself(int vector)36 static void noop_send_IPI_allbutself(int vector) { }
noop_send_IPI_all(int vector)37 static void noop_send_IPI_all(int vector) { }
noop_send_IPI_self(int vector)38 static void noop_send_IPI_self(int vector) { }
noop_apic_wait_icr_idle(void)39 static void noop_apic_wait_icr_idle(void) { }
noop_apic_icr_write(u32 low,u32 id)40 static void noop_apic_icr_write(u32 low, u32 id) { }
41 
noop_wakeup_secondary_cpu(int apicid,unsigned long start_eip)42 static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip)
43 {
44 	return -1;
45 }
46 
noop_safe_apic_wait_icr_idle(void)47 static u32 noop_safe_apic_wait_icr_idle(void)
48 {
49 	return 0;
50 }
51 
noop_apic_icr_read(void)52 static u64 noop_apic_icr_read(void)
53 {
54 	return 0;
55 }
56 
noop_phys_pkg_id(int cpuid_apic,int index_msb)57 static int noop_phys_pkg_id(int cpuid_apic, int index_msb)
58 {
59 	return 0;
60 }
61 
noop_get_apic_id(unsigned long x)62 static unsigned int noop_get_apic_id(unsigned long x)
63 {
64 	return 0;
65 }
66 
noop_probe(void)67 static int noop_probe(void)
68 {
69 	/*
70 	 * NOOP apic should not ever be
71 	 * enabled via probe routine
72 	 */
73 	return 0;
74 }
75 
noop_apic_id_registered(void)76 static int noop_apic_id_registered(void)
77 {
78 	/*
79 	 * if we would be really "pedantic"
80 	 * we should pass read_apic_id() here
81 	 * but since NOOP suppose APIC ID = 0
82 	 * lets save a few cycles
83 	 */
84 	return physid_isset(0, phys_cpu_present_map);
85 }
86 
noop_target_cpus(void)87 static const struct cpumask *noop_target_cpus(void)
88 {
89 	/* only BSP here */
90 	return cpumask_of(0);
91 }
92 
noop_check_apicid_used(physid_mask_t * map,int apicid)93 static unsigned long noop_check_apicid_used(physid_mask_t *map, int apicid)
94 {
95 	return physid_isset(apicid, *map);
96 }
97 
noop_check_apicid_present(int bit)98 static unsigned long noop_check_apicid_present(int bit)
99 {
100 	return physid_isset(bit, phys_cpu_present_map);
101 }
102 
noop_vector_allocation_domain(int cpu,struct cpumask * retmask)103 static void noop_vector_allocation_domain(int cpu, struct cpumask *retmask)
104 {
105 	if (cpu != 0)
106 		pr_warning("APIC: Vector allocated for non-BSP cpu\n");
107 	cpumask_clear(retmask);
108 	cpumask_set_cpu(cpu, retmask);
109 }
110 
noop_apic_read(u32 reg)111 static u32 noop_apic_read(u32 reg)
112 {
113 	WARN_ON_ONCE((cpu_has_apic && !disable_apic));
114 	return 0;
115 }
116 
noop_apic_write(u32 reg,u32 v)117 static void noop_apic_write(u32 reg, u32 v)
118 {
119 	WARN_ON_ONCE(cpu_has_apic && !disable_apic);
120 }
121 
122 struct apic apic_noop = {
123 	.name				= "noop",
124 	.probe				= noop_probe,
125 	.acpi_madt_oem_check		= NULL,
126 
127 	.apic_id_valid			= default_apic_id_valid,
128 	.apic_id_registered		= noop_apic_id_registered,
129 
130 	.irq_delivery_mode		= dest_LowestPrio,
131 	/* logical delivery broadcast to all CPUs: */
132 	.irq_dest_mode			= 1,
133 
134 	.target_cpus			= noop_target_cpus,
135 	.disable_esr			= 0,
136 	.dest_logical			= APIC_DEST_LOGICAL,
137 	.check_apicid_used		= noop_check_apicid_used,
138 	.check_apicid_present		= noop_check_apicid_present,
139 
140 	.vector_allocation_domain	= noop_vector_allocation_domain,
141 	.init_apic_ldr			= noop_init_apic_ldr,
142 
143 	.ioapic_phys_id_map		= default_ioapic_phys_id_map,
144 	.setup_apic_routing		= NULL,
145 	.multi_timer_check		= NULL,
146 
147 	.cpu_present_to_apicid		= default_cpu_present_to_apicid,
148 	.apicid_to_cpu_present		= physid_set_mask_of_physid,
149 
150 	.setup_portio_remap		= NULL,
151 	.check_phys_apicid_present	= default_check_phys_apicid_present,
152 	.enable_apic_mode		= NULL,
153 
154 	.phys_pkg_id			= noop_phys_pkg_id,
155 
156 	.mps_oem_check			= NULL,
157 
158 	.get_apic_id			= noop_get_apic_id,
159 	.set_apic_id			= NULL,
160 	.apic_id_mask			= 0x0F << 24,
161 
162 	.cpu_mask_to_apicid		= default_cpu_mask_to_apicid,
163 	.cpu_mask_to_apicid_and		= default_cpu_mask_to_apicid_and,
164 
165 	.send_IPI_mask			= noop_send_IPI_mask,
166 	.send_IPI_mask_allbutself	= noop_send_IPI_mask_allbutself,
167 	.send_IPI_allbutself		= noop_send_IPI_allbutself,
168 	.send_IPI_all			= noop_send_IPI_all,
169 	.send_IPI_self			= noop_send_IPI_self,
170 
171 	.wakeup_secondary_cpu		= noop_wakeup_secondary_cpu,
172 
173 	/* should be safe */
174 	.trampoline_phys_low		= DEFAULT_TRAMPOLINE_PHYS_LOW,
175 	.trampoline_phys_high		= DEFAULT_TRAMPOLINE_PHYS_HIGH,
176 
177 	.wait_for_init_deassert		= NULL,
178 
179 	.smp_callin_clear_local_apic	= NULL,
180 	.inquire_remote_apic		= NULL,
181 
182 	.read				= noop_apic_read,
183 	.write				= noop_apic_write,
184 	.icr_read			= noop_apic_icr_read,
185 	.icr_write			= noop_apic_icr_write,
186 	.wait_icr_idle			= noop_apic_wait_icr_idle,
187 	.safe_wait_icr_idle		= noop_safe_apic_wait_icr_idle,
188 
189 #ifdef CONFIG_X86_32
190 	.x86_32_early_logical_apicid	= noop_x86_32_early_logical_apicid,
191 #endif
192 };
193