smp.h 3.9 KB

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