cvmx-asm.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: [email protected]
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /*
  28. *
  29. * This is file defines ASM primitives for the executive.
  30. */
  31. #ifndef __CVMX_ASM_H__
  32. #define __CVMX_ASM_H__
  33. #include <asm/octeon/octeon-model.h>
  34. /* other useful stuff */
  35. #define CVMX_SYNC asm volatile ("sync" : : : "memory")
  36. /* String version of SYNCW macro for using in inline asm constructs */
  37. #define CVMX_SYNCW_STR "syncw\nsyncw\n"
  38. #ifdef __OCTEON__
  39. /* Deprecated, will be removed in future release */
  40. #define CVMX_SYNCIO asm volatile ("nop")
  41. #define CVMX_SYNCIOBDMA asm volatile ("synciobdma" : : : "memory")
  42. /* Deprecated, will be removed in future release */
  43. #define CVMX_SYNCIOALL asm volatile ("nop")
  44. /*
  45. * We actually use two syncw instructions in a row when we need a write
  46. * memory barrier. This is because the CN3XXX series of Octeons have
  47. * errata Core-401. This can cause a single syncw to not enforce
  48. * ordering under very rare conditions. Even if it is rare, better safe
  49. * than sorry.
  50. */
  51. #define CVMX_SYNCW asm volatile ("syncw\n\tsyncw" : : : "memory")
  52. /*
  53. * Define new sync instructions to be normal SYNC instructions for
  54. * operating systems that use threads.
  55. */
  56. #define CVMX_SYNCWS CVMX_SYNCW
  57. #define CVMX_SYNCS CVMX_SYNC
  58. #define CVMX_SYNCWS_STR CVMX_SYNCW_STR
  59. #else
  60. /*
  61. * Not using a Cavium compiler, always use the slower sync so the
  62. * assembler stays happy.
  63. */
  64. /* Deprecated, will be removed in future release */
  65. #define CVMX_SYNCIO asm volatile ("nop")
  66. #define CVMX_SYNCIOBDMA asm volatile ("sync" : : : "memory")
  67. /* Deprecated, will be removed in future release */
  68. #define CVMX_SYNCIOALL asm volatile ("nop")
  69. #define CVMX_SYNCW asm volatile ("sync" : : : "memory")
  70. #define CVMX_SYNCWS CVMX_SYNCW
  71. #define CVMX_SYNCS CVMX_SYNC
  72. #define CVMX_SYNCWS_STR CVMX_SYNCW_STR
  73. #endif
  74. /*
  75. * CVMX_PREPARE_FOR_STORE makes each byte of the block unpredictable
  76. * (actually old value or zero) until that byte is stored to (by this or
  77. * another processor. Note that the value of each byte is not only
  78. * unpredictable, but may also change again - up until the point when one
  79. * of the cores stores to the byte.
  80. */
  81. #define CVMX_PREPARE_FOR_STORE(address, offset) \
  82. asm volatile ("pref 30, " CVMX_TMP_STR(offset) "(%[rbase])" : : \
  83. [rbase] "d" (address))
  84. /*
  85. * This is a command headed to the L2 controller to tell it to clear
  86. * its dirty bit for a block. Basically, SW is telling HW that the
  87. * current version of the block will not be used.
  88. */
  89. #define CVMX_DONT_WRITE_BACK(address, offset) \
  90. asm volatile ("pref 29, " CVMX_TMP_STR(offset) "(%[rbase])" : : \
  91. [rbase] "d" (address))
  92. /* flush stores, invalidate entire icache */
  93. #define CVMX_ICACHE_INVALIDATE \
  94. { CVMX_SYNC; asm volatile ("synci 0($0)" : : ); }
  95. /* flush stores, invalidate entire icache */
  96. #define CVMX_ICACHE_INVALIDATE2 \
  97. { CVMX_SYNC; asm volatile ("cache 0, 0($0)" : : ); }
  98. /* complete prefetches, invalidate entire dcache */
  99. #define CVMX_DCACHE_INVALIDATE \
  100. { CVMX_SYNC; asm volatile ("cache 9, 0($0)" : : ); }
  101. #define CVMX_CACHE(op, address, offset) \
  102. asm volatile ("cache " CVMX_TMP_STR(op) ", " CVMX_TMP_STR(offset) "(%[rbase])" \
  103. : : [rbase] "d" (address) )
  104. /* fetch and lock the state. */
  105. #define CVMX_CACHE_LCKL2(address, offset) CVMX_CACHE(31, address, offset)
  106. /* unlock the state. */
  107. #define CVMX_CACHE_WBIL2(address, offset) CVMX_CACHE(23, address, offset)
  108. /* invalidate the cache block and clear the USED bits for the block */
  109. #define CVMX_CACHE_WBIL2I(address, offset) CVMX_CACHE(3, address, offset)
  110. /* load virtual tag and data for the L2 cache block into L2C_TAD0_TAG register */
  111. #define CVMX_CACHE_LTGL2I(address, offset) CVMX_CACHE(7, address, offset)
  112. #define CVMX_POP(result, input) \
  113. asm ("pop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
  114. #define CVMX_DPOP(result, input) \
  115. asm ("dpop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
  116. /* some new cop0-like stuff */
  117. #define CVMX_RDHWR(result, regstr) \
  118. asm volatile ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result))
  119. #define CVMX_RDHWRNV(result, regstr) \
  120. asm ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result))
  121. #endif /* __CVMX_ASM_H__ */