Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <asm/io_apic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) DEFINE_STATIC_KEY_FALSE(apic_use_ipi_shorthand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static int apic_ipi_shorthand_off __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static __init int apic_ipi_shorthand(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	get_option(&str, &apic_ipi_shorthand_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) __setup("no_ipi_broadcast=", apic_ipi_shorthand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int __init print_ipi_mode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	pr_info("IPI shorthand broadcast: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		apic_ipi_shorthand_off ? "disabled" : "enabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) late_initcall(print_ipi_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) void apic_smt_update(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 * Do not switch to broadcast mode if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 * - Disabled on the command line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 * - Only a single CPU is online
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 * - Not all present CPUs have been at least booted once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	 * The latter is important as the local APIC might be in some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	 * random state and a broadcast might cause havoc. That's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 * especially true for NMI broadcasting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (apic_ipi_shorthand_off || num_online_cpus() == 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	    !cpumask_equal(cpu_present_mask, &cpus_booted_once_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		static_branch_disable(&apic_use_ipi_shorthand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		static_branch_enable(&apic_use_ipi_shorthand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) void apic_send_IPI_allbutself(unsigned int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (num_online_cpus() < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (static_branch_likely(&apic_use_ipi_shorthand))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		apic->send_IPI_allbutself(vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		apic->send_IPI_mask_allbutself(cpu_online_mask, vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * Send a 'reschedule' IPI to another CPU. It goes straight through and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * wastes no time serializing anything. Worst case is that we lose a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * reschedule ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void native_smp_send_reschedule(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (unlikely(cpu_is_offline(cpu))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	apic->send_IPI(cpu, RESCHEDULE_VECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) void native_send_call_func_single_ipi(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	apic->send_IPI(cpu, CALL_FUNCTION_SINGLE_VECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) void native_send_call_func_ipi(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (static_branch_likely(&apic_use_ipi_shorthand)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (!cpumask_or_equal(mask, cpumask_of(cpu), cpu_online_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			goto sendmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (cpumask_test_cpu(cpu, mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			apic->send_IPI_all(CALL_FUNCTION_VECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		else if (num_online_cpus() > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			apic->send_IPI_allbutself(CALL_FUNCTION_VECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) sendmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline int __prepare_ICR2(unsigned int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return SET_APIC_DEST_FIELD(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline void __xapic_wait_icr_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	while (native_apic_mem_read(APIC_ICR) & APIC_ICR_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void __default_send_IPI_shortcut(unsigned int shortcut, int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * Subtle. In the case of the 'never do double writes' workaround
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * we have to lock out interrupts to be safe.  As we don't care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * of the value read we use an atomic rmw access to avoid costly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * cli/sti.  Otherwise we use an even cheaper single atomic write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * to the APIC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	unsigned int cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * Wait for idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (unlikely(vector == NMI_VECTOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		safe_apic_wait_icr_idle();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		__xapic_wait_icr_idle();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * No need to touch the target chip field. Also the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * mode is ignored when a shorthand is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	cfg = __prepare_ICR(shortcut, vector, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * Send the IPI. The write to APIC_ICR fires this off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	native_apic_mem_write(APIC_ICR, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * This is used to send an IPI with no shorthand notation (the destination is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * specified in bits 56 to 63 of the ICR).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	unsigned long cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * Wait for idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (unlikely(vector == NMI_VECTOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		safe_apic_wait_icr_idle();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		__xapic_wait_icr_idle();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * prepare target chip field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	cfg = __prepare_ICR2(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	native_apic_mem_write(APIC_ICR2, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 * program the ICR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	cfg = __prepare_ICR(0, vector, dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	 * Send the IPI. The write to APIC_ICR fires this off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	native_apic_mem_write(APIC_ICR, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) void default_send_IPI_single_phys(int cpu, int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	__default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				      vector, APIC_DEST_PHYSICAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	unsigned long query_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 * Hack. The clustered APIC addressing mode doesn't allow us to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 * to an arbitrary mask, so I do a unicast to each CPU instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	 * - mbligh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	for_each_cpu(query_cpu, mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		__default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				query_cpu), vector, APIC_DEST_PHYSICAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 						 int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	unsigned int this_cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	unsigned int query_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/* See Hack comment above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	for_each_cpu(query_cpu, mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (query_cpu == this_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		__default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 				 query_cpu), vector, APIC_DEST_PHYSICAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * Helper function for APICs which insist on cpumasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) void default_send_IPI_single(int cpu, int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	apic->send_IPI_mask(cpumask_of(cpu), vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) void default_send_IPI_allbutself(int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	__default_send_IPI_shortcut(APIC_DEST_ALLBUT, vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void default_send_IPI_all(int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	__default_send_IPI_shortcut(APIC_DEST_ALLINC, vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) void default_send_IPI_self(int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	__default_send_IPI_shortcut(APIC_DEST_SELF, vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void default_send_IPI_mask_sequence_logical(const struct cpumask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 						 int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	unsigned int query_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 * Hack. The clustered APIC addressing mode doesn't allow us to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 * should be modified to do 1 message per cluster ID - mbligh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	for_each_cpu(query_cpu, mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		__default_send_IPI_dest_field(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			vector, apic->dest_logical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 						 int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	unsigned int query_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	unsigned int this_cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	/* See Hack comment above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	for_each_cpu(query_cpu, mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		if (query_cpu == this_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		__default_send_IPI_dest_field(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			vector, apic->dest_logical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * This is only used on smaller machines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	unsigned long mask = cpumask_bits(cpumask)[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (!mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	__default_send_IPI_dest_field(mask, vector, apic->dest_logical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* must come after the send_IPI functions above for inlining */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int convert_apicid_to_cpu(int apic_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int safe_smp_processor_id(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	int apicid, cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (!boot_cpu_has(X86_FEATURE_APIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	apicid = hard_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (apicid == BAD_APICID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	cpuid = convert_apicid_to_cpu(apicid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return cpuid >= 0 ? cpuid : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #endif