system.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * System level definitions for the Hexagon architecture
  3. *
  4. * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #ifndef _ASM_SYSTEM_H
  21. #define _ASM_SYSTEM_H
  22. #include <linux/linkage.h>
  23. #include <linux/irqflags.h>
  24. #include <asm/atomic.h>
  25. #include <asm/hexagon_vm.h>
  26. struct thread_struct;
  27. extern struct task_struct *__switch_to(struct task_struct *,
  28. struct task_struct *,
  29. struct task_struct *);
  30. #define switch_to(p, n, r) do {\
  31. r = __switch_to((p), (n), (r));\
  32. } while (0)
  33. #define rmb() barrier()
  34. #define read_barrier_depends() barrier()
  35. #define wmb() barrier()
  36. #define mb() barrier()
  37. #define smp_rmb() barrier()
  38. #define smp_read_barrier_depends() barrier()
  39. #define smp_wmb() barrier()
  40. #define smp_mb() barrier()
  41. #define smp_mb__before_atomic_dec() barrier()
  42. #define smp_mb__after_atomic_dec() barrier()
  43. #define smp_mb__before_atomic_inc() barrier()
  44. #define smp_mb__after_atomic_inc() barrier()
  45. /*
  46. * __xchg - atomically exchange a register and a memory location
  47. * @x: value to swap
  48. * @ptr: pointer to memory
  49. * @size: size of the value
  50. *
  51. * Only 4 bytes supported currently.
  52. *
  53. * Note: there was an errata for V2 about .new's and memw_locked.
  54. *
  55. */
  56. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  57. int size)
  58. {
  59. unsigned long retval;
  60. /* Can't seem to use printk or panic here, so just stop */
  61. if (size != 4) do { asm volatile("brkpt;\n"); } while (1);
  62. __asm__ __volatile__ (
  63. "1: %0 = memw_locked(%1);\n" /* load into retval */
  64. " memw_locked(%1,P0) = %2;\n" /* store into memory */
  65. " if !P0 jump 1b;\n"
  66. : "=&r" (retval)
  67. : "r" (ptr), "r" (x)
  68. : "memory", "p0"
  69. );
  70. return retval;
  71. }
  72. /*
  73. * Atomically swap the contents of a register with memory. Should be atomic
  74. * between multiple CPU's and within interrupts on the same CPU.
  75. */
  76. #define xchg(ptr, v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v), (ptr), \
  77. sizeof(*(ptr))))
  78. /* Set a value and use a memory barrier. Used by the scheduler somewhere. */
  79. #define set_mb(var, value) \
  80. do { var = value; mb(); } while (0)
  81. /*
  82. * see rt-mutex-design.txt; cmpxchg supposedly checks if *ptr == A and swaps.
  83. * looks just like atomic_cmpxchg on our arch currently with a bunch of
  84. * variable casting.
  85. */
  86. #define __HAVE_ARCH_CMPXCHG 1
  87. #define cmpxchg(ptr, old, new) \
  88. ({ \
  89. __typeof__(ptr) __ptr = (ptr); \
  90. __typeof__(*(ptr)) __old = (old); \
  91. __typeof__(*(ptr)) __new = (new); \
  92. __typeof__(*(ptr)) __oldval = 0; \
  93. \
  94. asm volatile( \
  95. "1: %0 = memw_locked(%1);\n" \
  96. " { P0 = cmp.eq(%0,%2);\n" \
  97. " if (!P0.new) jump:nt 2f; }\n" \
  98. " memw_locked(%1,p0) = %3;\n" \
  99. " if (!P0) jump 1b;\n" \
  100. "2:\n" \
  101. : "=&r" (__oldval) \
  102. : "r" (__ptr), "r" (__old), "r" (__new) \
  103. : "memory", "p0" \
  104. ); \
  105. __oldval; \
  106. })
  107. /* Should probably shoot for an 8-byte aligned stack pointer */
  108. #define STACK_MASK (~7)
  109. #define arch_align_stack(x) (x & STACK_MASK)
  110. #endif