smp.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 __init first_lines_of_secondary(void);
  27. /*
  28. * API expected BY platform smp code (FROM arch smp code)
  29. *
  30. * smp_ipi_irq_setup:
  31. * Takes @cpu and @irq to which the arch-common ISR is hooked up
  32. */
  33. extern int smp_ipi_irq_setup(int cpu, int irq);
  34. /*
  35. * APIs expected FROM platform smp code
  36. *
  37. * arc_platform_smp_cpuinfo:
  38. * returns a string containing info for /proc/cpuinfo
  39. *
  40. * arc_platform_smp_wait_to_boot:
  41. * Called from early bootup code for non-Master CPUs to "park" them
  42. *
  43. * arc_platform_smp_wakeup_cpu:
  44. * Called from __cpu_up (Master CPU) to kick start another one
  45. *
  46. * arc_platform_ipi_send:
  47. * Takes @cpumask to which IPI(s) would be sent.
  48. * The actual msg-id/buffer is manager in arch-common code
  49. *
  50. * arc_platform_ipi_clear:
  51. * Takes @cpu which got IPI at @irq to do any IPI clearing
  52. */
  53. extern const char *arc_platform_smp_cpuinfo(void);
  54. extern void arc_platform_smp_wait_to_boot(int cpu);
  55. extern void arc_platform_smp_wakeup_cpu(int cpu, unsigned long pc);
  56. extern void arc_platform_ipi_send(const struct cpumask *callmap);
  57. extern void arc_platform_ipi_clear(int cpu, int irq);
  58. #endif /* CONFIG_SMP */
  59. /*
  60. * ARC700 doesn't support atomic Read-Modify-Write ops.
  61. * Originally Interrupts had to be disabled around code to gaurantee atomicity.
  62. * The LLOCK/SCOND insns allow writing interrupt-hassle-free based atomic ops
  63. * based on retry-if-irq-in-atomic (with hardware assist).
  64. * However despite these, we provide the IRQ disabling variant
  65. *
  66. * (1) These insn were introduced only in 4.10 release. So for older released
  67. * support needed.
  68. *
  69. * (2) In a SMP setup, the LLOCK/SCOND atomiticity across CPUs needs to be
  70. * gaurantted by the platform (not something which core handles).
  71. * Assuming a platform won't, SMP Linux needs to use spinlocks + local IRQ
  72. * disabling for atomicity.
  73. *
  74. * However exported spinlock API is not usable due to cyclic hdr deps
  75. * (even after system.h disintegration upstream)
  76. * asm/bitops.h -> linux/spinlock.h -> linux/preempt.h
  77. * -> linux/thread_info.h -> linux/bitops.h -> asm/bitops.h
  78. *
  79. * So the workaround is to use the lowest level arch spinlock API.
  80. * The exported spinlock API is smart enough to be NOP for !CONFIG_SMP,
  81. * but same is not true for ARCH backend, hence the need for 2 variants
  82. */
  83. #ifndef CONFIG_ARC_HAS_LLSC
  84. #include <linux/irqflags.h>
  85. #ifdef CONFIG_SMP
  86. #include <asm/spinlock.h>
  87. extern arch_spinlock_t smp_atomic_ops_lock;
  88. extern arch_spinlock_t smp_bitops_lock;
  89. #define atomic_ops_lock(flags) do { \
  90. local_irq_save(flags); \
  91. arch_spin_lock(&smp_atomic_ops_lock); \
  92. } while (0)
  93. #define atomic_ops_unlock(flags) do { \
  94. arch_spin_unlock(&smp_atomic_ops_lock); \
  95. local_irq_restore(flags); \
  96. } while (0)
  97. #define bitops_lock(flags) do { \
  98. local_irq_save(flags); \
  99. arch_spin_lock(&smp_bitops_lock); \
  100. } while (0)
  101. #define bitops_unlock(flags) do { \
  102. arch_spin_unlock(&smp_bitops_lock); \
  103. local_irq_restore(flags); \
  104. } while (0)
  105. #else /* !CONFIG_SMP */
  106. #define atomic_ops_lock(flags) local_irq_save(flags)
  107. #define atomic_ops_unlock(flags) local_irq_restore(flags)
  108. #define bitops_lock(flags) local_irq_save(flags)
  109. #define bitops_unlock(flags) local_irq_restore(flags)
  110. #endif /* !CONFIG_SMP */
  111. #endif /* !CONFIG_ARC_HAS_LLSC */
  112. #endif