smp.h 2.4 KB

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