^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __ASM_ARC_SMP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __ASM_ARC_SMP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define raw_smp_processor_id() (current_thread_info()->cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* including cpumask.h leads to cyclic deps hence this Forward declaration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct cpumask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * APIs provided by arch SMP code to generic code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) extern void arch_send_call_function_single_ipi(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * APIs provided by arch SMP code to rest of arch code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) extern void __init smp_init_cpus(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) extern void first_lines_of_secondary(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) extern const char *arc_platform_smp_cpuinfo(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * API expected BY platform smp code (FROM arch smp code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * smp_ipi_irq_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Takes @cpu and @hwirq to which the arch-common ISR is hooked up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) extern int smp_ipi_irq_setup(int cpu, irq_hw_number_t hwirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * struct plat_smp_ops - SMP callbacks provided by platform to ARC SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @info: SoC SMP specific info for /proc/cpuinfo etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @init_early_smp: A SMP specific h/w block can init itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Could be common across platforms so not covered by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * mach_desc->init_early()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @init_per_cpu: Called for each core so SMP h/w block driver can do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * any needed setup per cpu (e.g. IPI request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @cpu_kick: For Master to kickstart a cpu (optionally at a PC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @ipi_send: To send IPI to a @cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @ips_clear: To clear IPI received at @irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct plat_smp_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) const char *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) void (*init_early_smp)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void (*init_per_cpu)(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void (*cpu_kick)(int cpu, unsigned long pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void (*ipi_send)(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void (*ipi_clear)(int irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* TBD: stop exporting it for direct population by platform */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) extern struct plat_smp_ops plat_smp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #else /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static inline void smp_init_cpus(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline const char *arc_platform_smp_cpuinfo(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return "";
^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) #endif /* !CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * ARC700 doesn't support atomic Read-Modify-Write ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Originally Interrupts had to be disabled around code to gaurantee atomicity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * The LLOCK/SCOND insns allow writing interrupt-hassle-free based atomic ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * based on retry-if-irq-in-atomic (with hardware assist).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * However despite these, we provide the IRQ disabling variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * (1) These insn were introduced only in 4.10 release. So for older released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * support needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * (2) In a SMP setup, the LLOCK/SCOND atomicity across CPUs needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * gaurantted by the platform (not something which core handles).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Assuming a platform won't, SMP Linux needs to use spinlocks + local IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * disabling for atomicity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * However exported spinlock API is not usable due to cyclic hdr deps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * (even after system.h disintegration upstream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * asm/bitops.h -> linux/spinlock.h -> linux/preempt.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * -> linux/thread_info.h -> linux/bitops.h -> asm/bitops.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * So the workaround is to use the lowest level arch spinlock API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * The exported spinlock API is smart enough to be NOP for !CONFIG_SMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * but same is not true for ARCH backend, hence the need for 2 variants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #ifndef CONFIG_ARC_HAS_LLSC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #include <linux/irqflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #include <asm/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern arch_spinlock_t smp_atomic_ops_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) extern arch_spinlock_t smp_bitops_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define atomic_ops_lock(flags) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) local_irq_save(flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) arch_spin_lock(&smp_atomic_ops_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define atomic_ops_unlock(flags) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) arch_spin_unlock(&smp_atomic_ops_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) local_irq_restore(flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define bitops_lock(flags) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) local_irq_save(flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) arch_spin_lock(&smp_bitops_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define bitops_unlock(flags) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) arch_spin_unlock(&smp_bitops_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) local_irq_restore(flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #else /* !CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define atomic_ops_lock(flags) local_irq_save(flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define atomic_ops_unlock(flags) local_irq_restore(flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define bitops_lock(flags) local_irq_save(flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define bitops_unlock(flags) local_irq_restore(flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #endif /* !CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #endif /* !CONFIG_ARC_HAS_LLSC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #endif