smp.h 3.7 KB

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