xref: /openbmc/linux/arch/x86/kernel/apic/apic_common.c (revision 2f6df03f)
164063505SThomas Gleixner /*
264063505SThomas Gleixner  * Common functions shared between the various APIC flavours
364063505SThomas Gleixner  *
464063505SThomas Gleixner  * SPDX-License-Identifier: GPL-2.0
564063505SThomas Gleixner  */
664063505SThomas Gleixner #include <linux/irq.h>
764063505SThomas Gleixner #include <asm/apic.h>
864063505SThomas Gleixner 
9*2f6df03fSThomas Gleixner #include "local.h"
10*2f6df03fSThomas Gleixner 
119f9e3bb1SThomas Gleixner u32 apic_default_calc_apicid(unsigned int cpu)
129f9e3bb1SThomas Gleixner {
139f9e3bb1SThomas Gleixner 	return per_cpu(x86_cpu_to_apicid, cpu);
149f9e3bb1SThomas Gleixner }
159f9e3bb1SThomas Gleixner 
169f9e3bb1SThomas Gleixner u32 apic_flat_calc_apicid(unsigned int cpu)
179f9e3bb1SThomas Gleixner {
189f9e3bb1SThomas Gleixner 	return 1U << cpu;
199f9e3bb1SThomas Gleixner }
209f9e3bb1SThomas Gleixner 
2183a10522SThomas Gleixner bool default_check_apicid_used(physid_mask_t *map, int apicid)
2283a10522SThomas Gleixner {
2383a10522SThomas Gleixner 	return physid_isset(apicid, *map);
2483a10522SThomas Gleixner }
2583a10522SThomas Gleixner 
2683a10522SThomas Gleixner void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
2783a10522SThomas Gleixner {
2883a10522SThomas Gleixner 	*retmap = *phys_map;
2983a10522SThomas Gleixner }
3083a10522SThomas Gleixner 
3164063505SThomas Gleixner int default_cpu_present_to_apicid(int mps_cpu)
3264063505SThomas Gleixner {
3364063505SThomas Gleixner 	if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
34d23c977fSThomas Gleixner 		return (int)per_cpu(x86_cpu_to_apicid, mps_cpu);
3564063505SThomas Gleixner 	else
3664063505SThomas Gleixner 		return BAD_APICID;
3764063505SThomas Gleixner }
3883a10522SThomas Gleixner EXPORT_SYMBOL_GPL(default_cpu_present_to_apicid);
3964063505SThomas Gleixner 
40a774635dSLi RongQing int default_apic_id_valid(u32 apicid)
4183a10522SThomas Gleixner {
4283a10522SThomas Gleixner 	return (apicid < 255);
4383a10522SThomas Gleixner }
44*2f6df03fSThomas Gleixner 
45*2f6df03fSThomas Gleixner /*
46*2f6df03fSThomas Gleixner  * Set up the logical destination ID when the APIC operates in logical
47*2f6df03fSThomas Gleixner  * destination mode.
48*2f6df03fSThomas Gleixner  */
49*2f6df03fSThomas Gleixner void default_init_apic_ldr(void)
50*2f6df03fSThomas Gleixner {
51*2f6df03fSThomas Gleixner 	unsigned long val;
52*2f6df03fSThomas Gleixner 
53*2f6df03fSThomas Gleixner 	apic_write(APIC_DFR, APIC_DFR_FLAT);
54*2f6df03fSThomas Gleixner 	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
55*2f6df03fSThomas Gleixner 	val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
56*2f6df03fSThomas Gleixner 	apic_write(APIC_LDR, val);
57*2f6df03fSThomas Gleixner }
58