blob: a83451d73a4e2e88e6c64fde600511a48d1b78c5 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2012 Regents of the University of California
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5
6#ifndef _ASM_RISCV_SMP_H
7#define _ASM_RISCV_SMP_H
8
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009#include <linux/cpumask.h>
10#include <linux/irqreturn.h>
David Brazdil0f672f62019-12-10 10:32:29 +000011#include <linux/thread_info.h>
12
13#define INVALID_HARTID ULONG_MAX
14
15struct seq_file;
16extern unsigned long boot_cpu_hartid;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017
18#ifdef CONFIG_SMP
David Brazdil0f672f62019-12-10 10:32:29 +000019/*
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);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027
28/* SMP initialization hook for setup_arch */
29void __init setup_smp(void);
30
31/* Hook for the generic smp_call_function_many() routine. */
32void arch_send_call_function_ipi_mask(struct cpumask *mask);
33
34/* Hook for the generic smp_call_function_single() routine. */
35void arch_send_call_function_single_ipi(int cpu);
36
David Brazdil0f672f62019-12-10 10:32:29 +000037int riscv_hartid_to_cpuid(int hartid);
38void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
39
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000040/*
David Brazdil0f672f62019-12-10 10:32:29 +000041 * Obtains the hart ID of the currently executing task. This relies on
42 * THREAD_INFO_IN_TASK, but we define that unconditionally.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000043 */
David Brazdil0f672f62019-12-10 10:32:29 +000044#define raw_smp_processor_id() (current_thread_info()->cpu)
45
46#else
47
48static inline void show_ipi_stats(struct seq_file *p, int prec)
49{
50}
51
52static inline int riscv_hartid_to_cpuid(int hartid)
53{
54 if (hartid == boot_cpu_hartid)
55 return 0;
56
57 return -1;
58}
59static inline unsigned long cpuid_to_hartid_map(int cpu)
60{
61 return boot_cpu_hartid;
62}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000063
64#endif /* CONFIG_SMP */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000065#endif /* _ASM_RISCV_SMP_H */