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 int default_cpu_mask_to_apicid(const struct cpumask *msk, struct irq_data *irqd, 10 unsigned int *apicid) 11 { 12 unsigned int cpu = cpumask_first(msk); 13 14 if (cpu >= nr_cpu_ids) 15 return -EINVAL; 16 *apicid = per_cpu(x86_cpu_to_apicid, cpu); 17 irq_data_update_effective_affinity(irqd, cpumask_of(cpu)); 18 return 0; 19 } 20 21 int flat_cpu_mask_to_apicid(const struct cpumask *mask, struct irq_data *irqd, 22 unsigned int *apicid) 23 24 { 25 struct cpumask *effmsk = irq_data_get_effective_affinity_mask(irqd); 26 unsigned long cpu_mask = cpumask_bits(mask)[0] & APIC_ALL_CPUS; 27 28 if (!cpu_mask) 29 return -EINVAL; 30 *apicid = (unsigned int)cpu_mask; 31 cpumask_bits(effmsk)[0] = cpu_mask; 32 return 0; 33 } 34 35 bool default_check_apicid_used(physid_mask_t *map, int apicid) 36 { 37 return physid_isset(apicid, *map); 38 } 39 40 void flat_vector_allocation_domain(int cpu, struct cpumask *retmask, 41 const struct cpumask *mask) 42 { 43 /* 44 * Careful. Some cpus do not strictly honor the set of cpus 45 * specified in the interrupt destination when using lowest 46 * priority interrupt delivery mode. 47 * 48 * In particular there was a hyperthreading cpu observed to 49 * deliver interrupts to the wrong hyperthread when only one 50 * hyperthread was specified in the interrupt desitination. 51 */ 52 cpumask_clear(retmask); 53 cpumask_bits(retmask)[0] = APIC_ALL_CPUS; 54 } 55 56 void default_vector_allocation_domain(int cpu, struct cpumask *retmask, 57 const struct cpumask *mask) 58 { 59 cpumask_copy(retmask, cpumask_of(cpu)); 60 } 61 62 void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap) 63 { 64 *retmap = *phys_map; 65 } 66 67 int default_cpu_present_to_apicid(int mps_cpu) 68 { 69 if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) 70 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); 71 else 72 return BAD_APICID; 73 } 74 EXPORT_SYMBOL_GPL(default_cpu_present_to_apicid); 75 76 int default_check_phys_apicid_present(int phys_apicid) 77 { 78 return physid_isset(phys_apicid, phys_cpu_present_map); 79 } 80 81 const struct cpumask *default_target_cpus(void) 82 { 83 #ifdef CONFIG_SMP 84 return cpu_online_mask; 85 #else 86 return cpumask_of(0); 87 #endif 88 } 89 90 const struct cpumask *online_target_cpus(void) 91 { 92 return cpu_online_mask; 93 } 94 95 int default_apic_id_valid(int apicid) 96 { 97 return (apicid < 255); 98 } 99