core_cmSecureAccess.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**************************************************************************//**
  2. * @file core_cmSecureAccess.h
  3. * @brief CMSIS Cortex-M Core Secure Access Header File
  4. * @version XXX
  5. * @date 10. June 2016
  6. *
  7. * @note
  8. *
  9. ******************************************************************************/
  10. /* Copyright (c) 2016 ARM LIMITED
  11. All rights reserved.
  12. Redistribution and use in source and binary forms, with or without
  13. modification, are permitted provided that the following conditions are met:
  14. - Redistributions of source code must retain the above copyright
  15. notice, this list of conditions and the following disclaimer.
  16. - Redistributions in binary form must reproduce the above copyright
  17. notice, this list of conditions and the following disclaimer in the
  18. documentation and/or other materials provided with the distribution.
  19. - Neither the name of ARM nor the names of its contributors may be used
  20. to endorse or promote products derived from this software without
  21. specific prior written permission.
  22. *
  23. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  27. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. POSSIBILITY OF SUCH DAMAGE.
  34. ---------------------------------------------------------------------------*/
  35. #ifndef __CORE_CM_SECURE_ACCESS_H
  36. #define __CORE_CM_SECURE_ACCESS_H
  37. /* ########################### Core Secure Access ########################### */
  38. #ifdef FEATURE_UVISOR
  39. #include "uvisor-lib/uvisor-lib.h"
  40. /* Secure uVisor implementation. */
  41. /** Set the value at the target address.
  42. *
  43. * Equivalent to: `*address = value`.
  44. * @param address[in] Target address
  45. * @param value[in] Value to write at the address location.
  46. */
  47. #define SECURE_WRITE(address, value) \
  48. uvisor_write(public_box, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
  49. /** Get the value at the target address.
  50. *
  51. * @param address[in] Target address
  52. * @returns The value `*address`.
  53. */
  54. #define SECURE_READ(address) \
  55. uvisor_read(public_box, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
  56. /** Get the selected bits at the target address.
  57. *
  58. * @param address[in] Target address
  59. * @param mask[in] Bits to select out of the target address
  60. * @returns The value `*address & mask`.
  61. */
  62. #define SECURE_BITS_GET(address, mask) \
  63. UVISOR_BITS_GET(public_box, UVISOR_RGW_SHARED, address, mask)
  64. /** Check the selected bits at the target address.
  65. *
  66. * @param address[in] Address at which to check the bits
  67. * @param mask[in] Bits to select out of the target address
  68. * @returns The value `((*address & mask) == mask)`.
  69. */
  70. #define SECURE_BITS_CHECK(address, mask) \
  71. UVISOR_BITS_CHECK(public_box, UVISOR_RGW_SHARED, address, mask)
  72. /** Set the selected bits to 1 at the target address.
  73. *
  74. * Equivalent to: `*address |= mask`.
  75. * @param address[in] Target address
  76. * @param mask[in] Bits to select out of the target address
  77. */
  78. #define SECURE_BITS_SET(address, mask) \
  79. UVISOR_BITS_SET(public_box, UVISOR_RGW_SHARED, address, mask)
  80. /** Clear the selected bits at the target address.
  81. *
  82. * Equivalent to: `*address &= ~mask`.
  83. * @param address[in] Target address
  84. * @param mask[in] Bits to select out of the target address
  85. */
  86. #define SECURE_BITS_CLEAR(address, mask) \
  87. UVISOR_BITS_CLEAR(public_box, UVISOR_RGW_SHARED, address, mask)
  88. /** Set the selected bits at the target address to the given value.
  89. *
  90. * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
  91. * @param address[in] Target address
  92. * @param mask[in] Bits to select out of the target address
  93. * @param value[in] Value to write at the address location. Note: The value
  94. * must be already shifted to the correct bit position
  95. */
  96. #define SECURE_BITS_SET_VALUE(address, mask, value) \
  97. UVISOR_BITS_SET_VALUE(public_box, UVISOR_RGW_SHARED, address, mask, value)
  98. /** Toggle the selected bits at the target address.
  99. *
  100. * Equivalent to: `*address ^= mask`.
  101. * @param address[in] Target address
  102. * @param mask[in] Bits to select out of the target address
  103. */
  104. #define SECURE_BITS_TOGGLE(address, mask) \
  105. UVISOR_BITS_TOGGLE(public_box, UVISOR_RGW_SHARED, address, mask)
  106. #else
  107. /* Insecure fallback implementation. */
  108. /** Set the value at the target address.
  109. *
  110. * Equivalent to: `*address = value`.
  111. * @param address[in] Target address
  112. * @param value[in] Value to write at the address location.
  113. */
  114. #define SECURE_WRITE(address, value) \
  115. *(address) = (value)
  116. /** Get the value at the target address.
  117. *
  118. * @param address[in] Target address
  119. * @returns The value `*address`.
  120. */
  121. #define SECURE_READ(address) \
  122. (*(address))
  123. /** Get the selected bits at the target address.
  124. *
  125. * @param address[in] Target address
  126. * @param mask[in] Bits to select out of the target address
  127. * @returns The value `*address & mask`.
  128. */
  129. #define SECURE_BITS_GET(address, mask) \
  130. (*(address) & (mask))
  131. /** Check the selected bits at the target address.
  132. *
  133. * @param address[in] Address at which to check the bits
  134. * @param mask[in] Bits to select out of the target address
  135. * @returns The value `((*address & mask) == mask)`.
  136. */
  137. #define SECURE_BITS_CHECK(address, mask) \
  138. ((*(address) & (mask)) == (mask))
  139. /** Set the selected bits to 1 at the target address.
  140. *
  141. * Equivalent to: `*address |= mask`.
  142. * @param address[in] Target address
  143. * @param mask[in] Bits to select out of the target address
  144. */
  145. #define SECURE_BITS_SET(address, mask) \
  146. *(address) |= (mask)
  147. /** Clear the selected bits at the target address.
  148. *
  149. * Equivalent to: `*address &= ~mask`.
  150. * @param address[in] Target address
  151. * @param mask[in] Bits to select out of the target address
  152. */
  153. #define SECURE_BITS_CLEAR(address, mask) \
  154. *(address) &= ~(mask)
  155. /** Set the selected bits at the target address to the given value.
  156. *
  157. * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
  158. * @param address[in] Target address
  159. * @param mask[in] Bits to select out of the target address
  160. * @param value[in] Value to write at the address location. Note: The value
  161. * must be already shifted to the correct bit position
  162. */
  163. #define SECURE_BITS_SET_VALUE(address, mask, value) \
  164. *(address) = (*(address) & ~(mask)) | ((value) & (mask))
  165. /** Toggle the selected bits at the target address.
  166. *
  167. * Equivalent to: `*address ^= mask`.
  168. * @param address[in] Target address
  169. * @param mask[in] Bits to select out of the target address
  170. */
  171. #define SECURE_BITS_TOGGLE(address, mask) \
  172. *(address) ^= (mask)
  173. #endif
  174. #endif /* __CORE_CM_SECURE_ACCESS_H */