smp.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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(int hartid);
  34. void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
  35. /* Set custom IPI operations */
  36. void riscv_set_ipi_ops(struct riscv_ipi_ops *ops);
  37. /* Clear IPI for current CPU */
  38. void riscv_clear_ipi(void);
  39. void crash_smp_send_stop(void);
  40. bool smp_crash_stop_failed(void);
  41. /* Secondary hart entry */
  42. asmlinkage void smp_callin(void);
  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. #if defined CONFIG_HOTPLUG_CPU
  49. int __cpu_disable(void);
  50. void __cpu_die(unsigned int cpu);
  51. void cpu_stop(void);
  52. #else
  53. #endif /* CONFIG_HOTPLUG_CPU */
  54. #else
  55. static inline void show_ipi_stats(struct seq_file *p, int prec)
  56. {
  57. }
  58. static inline int riscv_hartid_to_cpuid(int hartid)
  59. {
  60. if (hartid == boot_cpu_hartid)
  61. return 0;
  62. return -1;
  63. }
  64. static inline unsigned long cpuid_to_hartid_map(int cpu)
  65. {
  66. return boot_cpu_hartid;
  67. }
  68. static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
  69. struct cpumask *out)
  70. {
  71. cpumask_clear(out);
  72. cpumask_set_cpu(boot_cpu_hartid, out);
  73. }
  74. static inline void riscv_set_ipi_ops(struct riscv_ipi_ops *ops)
  75. {
  76. }
  77. static inline void riscv_clear_ipi(void)
  78. {
  79. }
  80. #endif /* CONFIG_SMP */
  81. #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
  82. bool cpu_has_hotplug(unsigned int cpu);
  83. #else
  84. static inline bool cpu_has_hotplug(unsigned int cpu)
  85. {
  86. return false;
  87. }
  88. #endif
  89. #endif /* _ASM_RISCV_SMP_H */