smp.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. */
  5. #ifndef __ASM_ARC_SMP_H
  6. #define __ASM_ARC_SMP_H
  7. #ifdef CONFIG_SMP
  8. #include <linux/types.h>
  9. #include <linux/init.h>
  10. #include <linux/threads.h>
  11. #define raw_smp_processor_id() (current_thread_info()->cpu)
  12. /* including cpumask.h leads to cyclic deps hence this Forward declaration */
  13. struct cpumask;
  14. /*
  15. * APIs provided by arch SMP code to generic code
  16. */
  17. extern void arch_send_call_function_single_ipi(int cpu);
  18. extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
  19. /*
  20. * APIs provided by arch SMP code to rest of arch code
  21. */
  22. extern void __init smp_init_cpus(void);
  23. extern void first_lines_of_secondary(void);
  24. extern const char *arc_platform_smp_cpuinfo(void);
  25. extern void arc_platform_smp_wait_to_boot(int);
  26. extern void start_kernel_secondary(void);
  27. /*
  28. * API expected BY platform smp code (FROM arch smp code)
  29. *
  30. * smp_ipi_irq_setup:
  31. * Takes @cpu and @hwirq to which the arch-common ISR is hooked up
  32. */
  33. extern int smp_ipi_irq_setup(int cpu, irq_hw_number_t hwirq);
  34. /*
  35. * struct plat_smp_ops - SMP callbacks provided by platform to ARC SMP
  36. *
  37. * @info: SoC SMP specific info for /proc/cpuinfo etc
  38. * @init_early_smp: A SMP specific h/w block can init itself
  39. * Could be common across platforms so not covered by
  40. * mach_desc->init_early()
  41. * @init_per_cpu: Called for each core so SMP h/w block driver can do
  42. * any needed setup per cpu (e.g. IPI request)
  43. * @cpu_kick: For Master to kickstart a cpu (optionally at a PC)
  44. * @ipi_send: To send IPI to a @cpu
  45. * @ips_clear: To clear IPI received at @irq
  46. */
  47. struct plat_smp_ops {
  48. const char *info;
  49. void (*init_early_smp)(void);
  50. void (*init_per_cpu)(int cpu);
  51. void (*cpu_kick)(int cpu, unsigned long pc);
  52. void (*ipi_send)(int cpu);
  53. void (*ipi_clear)(int irq);
  54. };
  55. /* TBD: stop exporting it for direct population by platform */
  56. extern struct plat_smp_ops plat_smp_ops;
  57. #else /* CONFIG_SMP */
  58. static inline void smp_init_cpus(void) {}
  59. static inline const char *arc_platform_smp_cpuinfo(void)
  60. {
  61. return "";
  62. }
  63. #endif /* !CONFIG_SMP */
  64. /*
  65. * ARC700 doesn't support atomic Read-Modify-Write ops.
  66. * Originally Interrupts had to be disabled around code to guarantee atomicity.
  67. * The LLOCK/SCOND insns allow writing interrupt-hassle-free based atomic ops
  68. * based on retry-if-irq-in-atomic (with hardware assist).
  69. * However despite these, we provide the IRQ disabling variant
  70. *
  71. * (1) These insn were introduced only in 4.10 release. So for older released
  72. * support needed.
  73. *
  74. * (2) In a SMP setup, the LLOCK/SCOND atomicity across CPUs needs to be
  75. * guaranteed by the platform (not something which core handles).
  76. * Assuming a platform won't, SMP Linux needs to use spinlocks + local IRQ
  77. * disabling for atomicity.
  78. *
  79. * However exported spinlock API is not usable due to cyclic hdr deps
  80. * (even after system.h disintegration upstream)
  81. * asm/bitops.h -> linux/spinlock.h -> linux/preempt.h
  82. * -> linux/thread_info.h -> linux/bitops.h -> asm/bitops.h
  83. *
  84. * So the workaround is to use the lowest level arch spinlock API.
  85. * The exported spinlock API is smart enough to be NOP for !CONFIG_SMP,
  86. * but same is not true for ARCH backend, hence the need for 2 variants
  87. */
  88. #ifndef CONFIG_ARC_HAS_LLSC
  89. #include <linux/irqflags.h>
  90. #ifdef CONFIG_SMP
  91. #include <asm/spinlock.h>
  92. extern arch_spinlock_t smp_atomic_ops_lock;
  93. #define atomic_ops_lock(flags) do { \
  94. local_irq_save(flags); \
  95. arch_spin_lock(&smp_atomic_ops_lock); \
  96. } while (0)
  97. #define atomic_ops_unlock(flags) do { \
  98. arch_spin_unlock(&smp_atomic_ops_lock); \
  99. local_irq_restore(flags); \
  100. } while (0)
  101. #else /* !CONFIG_SMP */
  102. #define atomic_ops_lock(flags) local_irq_save(flags)
  103. #define atomic_ops_unlock(flags) local_irq_restore(flags)
  104. #endif /* !CONFIG_SMP */
  105. #endif /* !CONFIG_ARC_HAS_LLSC */
  106. #endif