smp.h 4.2 KB

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