system.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * U-boot - system.h
  3. *
  4. * Copyright (c) 2005-2007 Analog Devices Inc.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #ifndef _BLACKFIN_SYSTEM_H
  25. #define _BLACKFIN_SYSTEM_H
  26. /*
  27. * Interrupt configuring macros.
  28. */
  29. extern int irq_flags;
  30. #define local_irq_enable() \
  31. __asm__ __volatile__ ( \
  32. "sti %0;" \
  33. : \
  34. : "d" (irq_flags) \
  35. )
  36. #define local_irq_disable() \
  37. do { \
  38. int __tmp_dummy; \
  39. __asm__ __volatile__ ( \
  40. "cli %0;" \
  41. : "=d" (__tmp_dummy) \
  42. ); \
  43. } while (0)
  44. # define local_irq_save(x) \
  45. __asm__ __volatile__ ( \
  46. "cli %0;" \
  47. : "=&d" (x) \
  48. )
  49. #define local_save_flags(x) \
  50. __asm__ __volatile__ ( \
  51. "cli %0;" \
  52. "sti %0;" \
  53. : "=d" (x) \
  54. )
  55. #define irqs_enabled_from_flags(x) ((x) != 0x1f)
  56. #define local_irq_restore(x) \
  57. do { \
  58. if (irqs_enabled_from_flags(x)) \
  59. local_irq_enable(); \
  60. } while (0)
  61. /*
  62. * Force strict CPU ordering.
  63. */
  64. #define nop() asm volatile ("nop;\n\t"::)
  65. #define mb() asm volatile ("" : : :"memory")
  66. #define rmb() asm volatile ("" : : :"memory")
  67. #define wmb() asm volatile ("" : : :"memory")
  68. #define set_rmb(var, value) do { xchg(&var, value); } while (0)
  69. #define set_mb(var, value) set_rmb(var, value)
  70. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  71. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  72. struct __xchg_dummy {
  73. unsigned long a[100];
  74. };
  75. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  76. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  77. int size)
  78. {
  79. unsigned long tmp = 0;
  80. unsigned long flags = 0;
  81. local_irq_save(flags);
  82. switch (size) {
  83. case 1:
  84. __asm__ __volatile__
  85. ("%0 = b%2 (z);\n\t"
  86. "b%2 = %1;\n\t"
  87. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  88. break;
  89. case 2:
  90. __asm__ __volatile__
  91. ("%0 = w%2 (z);\n\t"
  92. "w%2 = %1;\n\t"
  93. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  94. break;
  95. case 4:
  96. __asm__ __volatile__
  97. ("%0 = %2;\n\t"
  98. "%2 = %1;\n\t"
  99. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  100. break;
  101. }
  102. local_irq_restore(flags);
  103. return tmp;
  104. }
  105. #endif /* _BLACKFIN_SYSTEM_H */