xref: /openbmc/linux/arch/x86/kernel/apic/apic_common.c (revision 9f9e3bb1)
1 /*
2  * Common functions shared between the various APIC flavours
3  *
4  * SPDX-License-Identifier: GPL-2.0
5  */
6 #include <linux/irq.h>
7 #include <asm/apic.h>
8 
9 u32 apic_default_calc_apicid(unsigned int cpu)
10 {
11 	return per_cpu(x86_cpu_to_apicid, cpu);
12 }
13 
14 int default_cpu_mask_to_apicid(const struct cpumask *msk, struct irq_data *irqd,
15 			       unsigned int *apicid)
16 {
17 	unsigned int cpu = cpumask_first(msk);
18 
19 	if (cpu >= nr_cpu_ids)
20 		return -EINVAL;
21 	*apicid = per_cpu(x86_cpu_to_apicid, cpu);
22 	irq_data_update_effective_affinity(irqd, cpumask_of(cpu));
23 	return 0;
24 }
25 
26 u32 apic_flat_calc_apicid(unsigned int cpu)
27 {
28 	return 1U << cpu;
29 }
30 
31 int flat_cpu_mask_to_apicid(const struct cpumask *mask, struct irq_data *irqd,
32 			    unsigned int *apicid)
33 
34 {
35 	struct cpumask *effmsk = irq_data_get_effective_affinity_mask(irqd);
36 	unsigned long cpu_mask = cpumask_bits(mask)[0] & APIC_ALL_CPUS;
37 
38 	if (!cpu_mask)
39 		return -EINVAL;
40 	*apicid = (unsigned int)cpu_mask;
41 	cpumask_bits(effmsk)[0] = cpu_mask;
42 	return 0;
43 }
44 
45 bool default_check_apicid_used(physid_mask_t *map, int apicid)
46 {
47 	return physid_isset(apicid, *map);
48 }
49 
50 void flat_vector_allocation_domain(int cpu, struct cpumask *retmask,
51 				   const struct cpumask *mask)
52 {
53 	/*
54 	 * Careful. Some cpus do not strictly honor the set of cpus
55 	 * specified in the interrupt destination when using lowest
56 	 * priority interrupt delivery mode.
57 	 *
58 	 * In particular there was a hyperthreading cpu observed to
59 	 * deliver interrupts to the wrong hyperthread when only one
60 	 * hyperthread was specified in the interrupt desitination.
61 	 */
62 	cpumask_clear(retmask);
63 	cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
64 }
65 
66 void default_vector_allocation_domain(int cpu, struct cpumask *retmask,
67 				      const struct cpumask *mask)
68 {
69 	cpumask_copy(retmask, cpumask_of(cpu));
70 }
71 
72 void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
73 {
74 	*retmap = *phys_map;
75 }
76 
77 int default_cpu_present_to_apicid(int mps_cpu)
78 {
79 	if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
80 		return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
81 	else
82 		return BAD_APICID;
83 }
84 EXPORT_SYMBOL_GPL(default_cpu_present_to_apicid);
85 
86 int default_check_phys_apicid_present(int phys_apicid)
87 {
88 	return physid_isset(phys_apicid, phys_cpu_present_map);
89 }
90 
91 int default_apic_id_valid(int apicid)
92 {
93 	return (apicid < 255);
94 }
95