1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Copyright (C) 2012 Regents of the University of California 4 */ 5 6#ifndef _ASM_RISCV_SMP_H 7#define _ASM_RISCV_SMP_H 8 9#include <linux/cpumask.h> 10#include <linux/irqreturn.h> 11#include <linux/thread_info.h> 12 13#define INVALID_HARTID ULONG_MAX 14 15struct seq_file; 16extern unsigned long boot_cpu_hartid; 17 18#ifdef CONFIG_SMP 19/* 20 * Mapping between linux logical cpu index and hartid. 21 */ 22extern unsigned long __cpuid_to_hartid_map[NR_CPUS]; 23#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu] 24 25/* print IPI stats */ 26void show_ipi_stats(struct seq_file *p, int prec); 27 28/* SMP initialization hook for setup_arch */ 29void __init setup_smp(void); 30 31/* Called from C code, this handles an IPI. */ 32void handle_IPI(struct pt_regs *regs); 33 34/* Hook for the generic smp_call_function_many() routine. */ 35void arch_send_call_function_ipi_mask(struct cpumask *mask); 36 37/* Hook for the generic smp_call_function_single() routine. */ 38void arch_send_call_function_single_ipi(int cpu); 39 40int riscv_hartid_to_cpuid(int hartid); 41void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out); 42 43/* 44 * Obtains the hart ID of the currently executing task. This relies on 45 * THREAD_INFO_IN_TASK, but we define that unconditionally. 46 */ 47#define raw_smp_processor_id() (current_thread_info()->cpu) 48 49#if defined CONFIG_HOTPLUG_CPU 50int __cpu_disable(void); 51void __cpu_die(unsigned int cpu); 52void cpu_stop(void); 53#else 54#endif /* CONFIG_HOTPLUG_CPU */ 55 56#else 57 58static inline void show_ipi_stats(struct seq_file *p, int prec) 59{ 60} 61 62static inline int riscv_hartid_to_cpuid(int hartid) 63{ 64 if (hartid == boot_cpu_hartid) 65 return 0; 66 67 return -1; 68} 69static inline unsigned long cpuid_to_hartid_map(int cpu) 70{ 71 return boot_cpu_hartid; 72} 73 74static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in, 75 struct cpumask *out) 76{ 77 cpumask_clear(out); 78 cpumask_set_cpu(boot_cpu_hartid, out); 79} 80 81#endif /* CONFIG_SMP */ 82 83#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP) 84bool cpu_has_hotplug(unsigned int cpu); 85#else 86static inline bool cpu_has_hotplug(unsigned int cpu) 87{ 88 return false; 89} 90#endif 91 92#endif /* _ASM_RISCV_SMP_H */ 93