xref: /openbmc/linux/arch/x86/kernel/apic/apic_common.c (revision 5a3a46bd)
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 
92f6df03fSThomas Gleixner #include "local.h"
102f6df03fSThomas 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 }
442f6df03fSThomas Gleixner 
45*5a3a46bdSThomas Gleixner bool default_apic_id_registered(void)
46*5a3a46bdSThomas Gleixner {
47*5a3a46bdSThomas Gleixner 	return physid_isset(read_apic_id(), phys_cpu_present_map);
48*5a3a46bdSThomas Gleixner }
49*5a3a46bdSThomas Gleixner 
502f6df03fSThomas Gleixner /*
512f6df03fSThomas Gleixner  * Set up the logical destination ID when the APIC operates in logical
522f6df03fSThomas Gleixner  * destination mode.
532f6df03fSThomas Gleixner  */
542f6df03fSThomas Gleixner void default_init_apic_ldr(void)
552f6df03fSThomas Gleixner {
562f6df03fSThomas Gleixner 	unsigned long val;
572f6df03fSThomas Gleixner 
582f6df03fSThomas Gleixner 	apic_write(APIC_DFR, APIC_DFR_FLAT);
592f6df03fSThomas Gleixner 	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
602f6df03fSThomas Gleixner 	val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
612f6df03fSThomas Gleixner 	apic_write(APIC_LDR, val);
622f6df03fSThomas Gleixner }
63