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