1
0

cortex_a.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Copyright (c) 2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #if !defined(__CORTEX_A_H__)
  31. #define __CORTEX_A9H__
  32. #include <stdint.h>
  33. #include <stdbool.h>
  34. #include <stdlib.h>
  35. //! @addtogroup cortexa9
  36. //! @{
  37. ////////////////////////////////////////////////////////////////////////////////
  38. // Definitions
  39. ////////////////////////////////////////////////////////////////////////////////
  40. //! @name Instruction macros
  41. //@{
  42. #define _ARM_NOP() asm volatile ("nop\n\t")
  43. #define _ARM_WFI() asm volatile ("wfi\n\t")
  44. #define _ARM_WFE() asm volatile ("wfe\n\t")
  45. #define _ARM_SEV() asm volatile ("sev\n\t")
  46. #define _ARM_DSB() asm volatile ("dsb\n\t")
  47. #define _ARM_ISB() asm volatile ("isb\n\t")
  48. #define _ARM_MRC(coproc, opcode1, Rt, CRn, CRm, opcode2) \
  49. asm volatile ("mrc p" #coproc ", " #opcode1 ", %[output], c" #CRn ", c" #CRm ", " #opcode2 "\n" : [output] "=r" (Rt))
  50. #define _ARM_MCR(coproc, opcode1, Rt, CRn, CRm, opcode2) \
  51. asm volatile ("mcr p" #coproc ", " #opcode1 ", %[input], c" #CRn ", c" #CRm ", " #opcode2 "\n" :: [input] "r" (Rt))
  52. //@}
  53. ////////////////////////////////////////////////////////////////////////////////
  54. // Code
  55. ////////////////////////////////////////////////////////////////////////////////
  56. #if defined(__cplusplus)
  57. extern "C" {
  58. #endif
  59. //! @name Misc
  60. //@{
  61. //! @brief Enable or disable the IRQ and FIQ state.
  62. bool arm_set_interrupt_state(bool enable);
  63. //! @brief Get current CPU ID.
  64. int cpu_get_current(void);
  65. //! @brief Enable the NEON MPE.
  66. void enable_neon_fpu(void);
  67. //! @brief Disable aborts on unaligned accesses.
  68. void disable_strict_align_check(void);
  69. //! @brief Get base address of private perpherial space.
  70. //!
  71. //! @return The address of the ARM CPU's private peripherals.
  72. uint32_t get_arm_private_peripheral_base(void);
  73. //@}
  74. //! @name Data cache operations
  75. //@{
  76. //! @brief Check if dcache is enabled or disabled.
  77. int arm_dcache_state_query();
  78. //! @brief Enables data cache at any available cache level.
  79. //!
  80. //! Works only if MMU is enabled!
  81. void arm_dcache_enable();
  82. //! @brief Disables the data cache at any available cache level.
  83. void arm_dcache_disable();
  84. //! @brief Invalidates the entire data cache.
  85. void arm_dcache_invalidate();
  86. //! @brief Invalidate a line of data cache.
  87. void arm_dcache_invalidate_line(const void * addr);
  88. //! @brief Invalidate a number of lines of data cache.
  89. //!
  90. //! Number of lines depends on length parameter and size of line.
  91. //! Size of line for A9 L1 cache is 32B.
  92. void arm_dcache_invalidate_mlines(const void * addr, size_t length);
  93. //! @brief Flush (clean) all lines of cache (all sets in all ways).
  94. void arm_dcache_flush();
  95. //! @brief Flush (clean) one line of cache.
  96. void arm_dcache_flush_line(const void * addr);
  97. // @brief Flush (clean) multiple lines of cache.
  98. //!
  99. //! Number of lines depends on length parameter and size of line.
  100. void arm_dcache_flush_mlines(const void * addr, size_t length);
  101. //@}
  102. //! @name Instrution cache operations
  103. //@{
  104. //! @brief Check if icache is enabled or disabled.
  105. int arm_icache_state_query();
  106. //! @brief Enables instruction cache at any available cache level.
  107. //!
  108. //! Works without enabled MMU too!
  109. void arm_icache_enable();
  110. //! @brief Disables the instruction cache at any available cache level.
  111. void arm_icache_disable();
  112. //! @brief Invalidates the entire instruction cache.
  113. void arm_icache_invalidate();
  114. //! @brief Invalidates the entire instruction cache inner shareable.
  115. void arm_icache_invalidate_is();
  116. //! @brief Invalidate a line of the instruction cache.
  117. void arm_icache_invalidate_line(const void * addr);
  118. //! @brief Invalidate a number of lines of instruction cache.
  119. //!
  120. //! Number of lines depends on length parameter and size of line.
  121. void arm_icache_invalidate_mlines(const void * addr, size_t length);
  122. //@}
  123. //! @name TLB operations
  124. //@{
  125. //! @brief Invalidate entire unified TLB.
  126. void arm_unified_tlb_invalidate(void);
  127. //! @brief Invalidate entire unified TLB Inner Shareable.
  128. void arm_unified_tlb_invalidate_is(void);
  129. //@}
  130. //! @name Branch predictor operations
  131. //@{
  132. //! @brief Enable branch prediction.
  133. void arm_branch_prediction_enable(void);
  134. //! @brief Disable branch prediction.
  135. void arm_branch_prediction_disable(void);
  136. //! @brief Invalidate entire branch predictor array.
  137. void arm_branch_target_cache_invalidate(void);
  138. //! @brief Invalidate entire branch predictor array Inner Shareable
  139. void arm_branch_target_cache_invalidate_is(void);
  140. //@}
  141. //! @name SCU
  142. //@{
  143. //! @brief Enables the SCU.
  144. void scu_enable(void);
  145. //! @brief Set this CPU as participating in SMP.
  146. void scu_join_smp(void);
  147. //! @brief Set this CPU as not participating in SMP.
  148. void scu_leave_smp(void);
  149. //! @brief Determine which CPUs are participating in SMP.
  150. //!
  151. //! The return value is 1 bit per core:
  152. //! - bit 0 - CPU 0
  153. //! - bit 1 - CPU 1
  154. //! - etc...
  155. unsigned int scu_get_cpus_in_smp(void);
  156. //! @brief Enable the broadcasting of cache & TLB maintenance operations.
  157. //!
  158. //! When enabled AND in SMP, broadcast all "inner sharable"
  159. //! cache and TLM maintenance operations to other SMP cores
  160. void scu_enable_maintenance_broadcast(void);
  161. //! @brief Disable the broadcasting of cache & TLB maintenance operations.
  162. void scu_disable_maintenance_broadcast(void);
  163. //! @brief Invalidates the SCU copy of the tag rams for the specified core.
  164. //!
  165. //! Typically only done at start-up.
  166. //! Possible flow:
  167. //! - Invalidate L1 caches
  168. //! - Invalidate SCU copy of TAG RAMs
  169. //! - Join SMP
  170. //!
  171. //! @param cpu 0x0=CPU 0, 0x1=CPU 1, etc...
  172. //! @param ways The ways to invalidate. Pass 0xf to invalidate all ways.
  173. void scu_secure_invalidate(unsigned int cpu, unsigned int ways);
  174. //@}
  175. #if defined(__cplusplus)
  176. }
  177. #endif
  178. //! @}
  179. #endif // __CORTEX_A_H__
  180. ////////////////////////////////////////////////////////////////////////////////
  181. // EOF
  182. ////////////////////////////////////////////////////////////////////////////////