smp.h (2319B)
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 18struct riscv_ipi_ops { 19 void (*ipi_inject)(const struct cpumask *target); 20 void (*ipi_clear)(void); 21}; 22 23#ifdef CONFIG_SMP 24/* 25 * Mapping between linux logical cpu index and hartid. 26 */ 27extern unsigned long __cpuid_to_hartid_map[NR_CPUS]; 28#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu] 29 30/* print IPI stats */ 31void show_ipi_stats(struct seq_file *p, int prec); 32 33/* SMP initialization hook for setup_arch */ 34void __init setup_smp(void); 35 36/* Called from C code, this handles an IPI. */ 37void handle_IPI(struct pt_regs *regs); 38 39/* Hook for the generic smp_call_function_many() routine. */ 40void arch_send_call_function_ipi_mask(struct cpumask *mask); 41 42/* Hook for the generic smp_call_function_single() routine. */ 43void arch_send_call_function_single_ipi(int cpu); 44 45int riscv_hartid_to_cpuid(int hartid); 46 47/* Set custom IPI operations */ 48void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops); 49 50/* Clear IPI for current CPU */ 51void riscv_clear_ipi(void); 52 53/* Secondary hart entry */ 54asmlinkage void smp_callin(void); 55 56/* 57 * Obtains the hart ID of the currently executing task. This relies on 58 * THREAD_INFO_IN_TASK, but we define that unconditionally. 59 */ 60#define raw_smp_processor_id() (current_thread_info()->cpu) 61 62#if defined CONFIG_HOTPLUG_CPU 63int __cpu_disable(void); 64void __cpu_die(unsigned int cpu); 65#endif /* CONFIG_HOTPLUG_CPU */ 66 67#else 68 69static inline void show_ipi_stats(struct seq_file *p, int prec) 70{ 71} 72 73static inline int riscv_hartid_to_cpuid(int hartid) 74{ 75 if (hartid == boot_cpu_hartid) 76 return 0; 77 78 return -1; 79} 80static inline unsigned long cpuid_to_hartid_map(int cpu) 81{ 82 return boot_cpu_hartid; 83} 84 85static inline void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops) 86{ 87} 88 89static inline void riscv_clear_ipi(void) 90{ 91} 92 93#endif /* CONFIG_SMP */ 94 95#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP) 96bool cpu_has_hotplug(unsigned int cpu); 97#else 98static inline bool cpu_has_hotplug(unsigned int cpu) 99{ 100 return false; 101} 102#endif 103 104#endif /* _ASM_RISCV_SMP_H */