xref: /openbmc/linux/arch/x86/kernel/apic/apic_common.c (revision d8666cf7)
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 
apic_default_calc_apicid(unsigned int cpu)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 
apic_flat_calc_apicid(unsigned int cpu)169f9e3bb1SThomas Gleixner u32 apic_flat_calc_apicid(unsigned int cpu)
179f9e3bb1SThomas Gleixner {
189f9e3bb1SThomas Gleixner 	return 1U << cpu;
199f9e3bb1SThomas Gleixner }
209f9e3bb1SThomas Gleixner 
default_check_apicid_used(physid_mask_t * map,int apicid)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 
default_ioapic_phys_id_map(physid_mask_t * phys_map,physid_mask_t * retmap)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 
default_cpu_present_to_apicid(int mps_cpu)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 
default_apic_id_registered(void)40*5a3a46bdSThomas Gleixner bool default_apic_id_registered(void)
41*5a3a46bdSThomas Gleixner {
42*5a3a46bdSThomas Gleixner 	return physid_isset(read_apic_id(), phys_cpu_present_map);
43*5a3a46bdSThomas Gleixner }
44*5a3a46bdSThomas Gleixner 
452f6df03fSThomas Gleixner /*
462f6df03fSThomas Gleixner  * Set up the logical destination ID when the APIC operates in logical
472f6df03fSThomas Gleixner  * destination mode.
482f6df03fSThomas Gleixner  */
default_init_apic_ldr(void)492f6df03fSThomas Gleixner void default_init_apic_ldr(void)
502f6df03fSThomas Gleixner {
512f6df03fSThomas Gleixner 	unsigned long val;
522f6df03fSThomas Gleixner 
532f6df03fSThomas Gleixner 	apic_write(APIC_DFR, APIC_DFR_FLAT);
542f6df03fSThomas Gleixner 	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
552f6df03fSThomas Gleixner 	val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
562f6df03fSThomas Gleixner 	apic_write(APIC_LDR, val);
572f6df03fSThomas Gleixner }
58