ssi_regs.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**************************************************************************************
  2. * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
  3. * *
  4. * This file and the related binary are licensed under the following license: *
  5. * *
  6. * ARM Object Code and Header Files License, v1.0 Redistribution. *
  7. * *
  8. * Redistribution and use of object code, header files, and documentation, without *
  9. * modification, are permitted provided that the following conditions are met: *
  10. * *
  11. * 1) Redistributions must reproduce the above copyright notice and the *
  12. * following disclaimer in the documentation and/or other materials *
  13. * provided with the distribution. *
  14. * *
  15. * 2) Unless to the extent explicitly permitted by law, no reverse *
  16. * engineering, decompilation, or disassembly of is permitted. *
  17. * *
  18. * 3) Redistribution and use is permitted solely for the purpose of *
  19. * developing or executing applications that are targeted for use *
  20. * on an ARM-based product. *
  21. * *
  22. * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  23. * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
  24. * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
  25. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
  26. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
  33. **************************************************************************************/
  34. /*!
  35. * @file
  36. * @brief Macro definitions for accessing ARM TrustZone CryptoCell register space.
  37. */
  38. #ifndef _SSI_REGS_H_
  39. #define _SSI_REGS_H_
  40. #include "ssi_bitops.h"
  41. /* Register Offset macro */
  42. #define SASI_REG_OFFSET(unit_name, reg_name) \
  43. (DX_BASE_ ## unit_name + DX_ ## reg_name ## _REG_OFFSET)
  44. #define SASI_REG_BIT_SHIFT(reg_name, field_name) \
  45. (DX_ ## reg_name ## _ ## field_name ## _BIT_SHIFT)
  46. /* Register Offset macros (from registers base address in host) */
  47. #if defined(DX_CC_REE) || defined(DX_CC_TEE) || defined(DX_CONFIG_IOT_SUPPORTED)
  48. #include "dx_reg_base_host.h"
  49. /* Indexed GPR offset macros - note the (not original) preprocessor tricks...*/
  50. /* (Using the macro without the "_" prefix is allowed with another macro *
  51. * as the gpr_idx) */
  52. #define _SEP_HOST_GPR_REG_OFFSET(gpr_idx) \
  53. SASI_REG_OFFSET(HOST_RGF, HOST_SEP_HOST_GPR ## gpr_idx)
  54. #define SEP_HOST_GPR_REG_OFFSET(gpr_idx) _SEP_HOST_GPR_REG_OFFSET(gpr_idx)
  55. #define _HOST_SEP_GPR_REG_OFFSET(gpr_idx) \
  56. SASI_REG_OFFSET(HOST_RGF, HOST_HOST_SEP_GPR ## gpr_idx)
  57. #define HOST_SEP_GPR_REG_OFFSET(gpr_idx) _HOST_SEP_GPR_REG_OFFSET(gpr_idx)
  58. /* GPR IRQ bit shift/mask by GPR index */
  59. #define _SEP_HOST_GPR_IRQ_SHIFT(gpr_idx) \
  60. DX_HOST_IRR_SEP_HOST_GPR ## gpr_idx ## _INT_BIT_SHIFT
  61. #define SEP_HOST_GPR_IRQ_SHIFT(gpr_idx) \
  62. _SEP_HOST_GPR_IRQ_SHIFT(gpr_idx)
  63. #define SEP_HOST_GPR_IRQ_MASK(gpr_idx) \
  64. (1 << SEP_HOST_GPR_IRQ_CAUSE_SHIFT(gpr_idx))
  65. /* Read-Modify-Write a field of a register */
  66. #define MODIFY_REGISTER_FLD(unitName, regName, fldName, fldVal) \
  67. do { \
  68. uint32_t regVal; \
  69. regVal = READ_REGISTER(SASI_REG_ADDR(unitName, regName)); \
  70. SASI_REG_FLD_SET(unitName, regName, fldName, regVal, fldVal); \
  71. WRITE_REGISTER(SASI_REG_ADDR(unitName, regName), regVal); \
  72. } while (0)
  73. #elif defined(DX_CC_SEP)
  74. #include "dx_reg_base_sep.h"
  75. /* We only provide this macro for SEP code because other platforms require usage
  76. of (mapping base + offset), i.e., use of SASI_REG_OFFSET */
  77. /* PLEASE AVOID USING THIS MACRO FOR NEW SEP CODE. USE THE OFFSET MACROS. */
  78. #define SASI_REG_ADDR(unit_name, reg_name) \
  79. (DX_BASE_CC_PERIF + DX_BASE_ ## unit_name + \
  80. DX_ ## reg_name ## _REG_OFFSET)
  81. /* Indexed GPR address macros - note the (not original) preprocessor tricks...*/
  82. /* (Using the macro without the "_" prefix is allowed with another macro *
  83. * as the gpr_idx) */
  84. #define _SEP_HOST_GPR_REG_ADDR(gpr_idx) \
  85. SASI_REG_ADDR(SEP_RGF, SEP_SEP_HOST_GPR ## gpr_idx)
  86. #define SEP_HOST_GPR_REG_ADDR(gpr_idx) _SEP_HOST_GPR_REG_ADDR(gpr_idx)
  87. #define _HOST_SEP_GPR_REG_ADDR(gpr_idx) \
  88. SASI_REG_ADDR(SEP_RGF, SEP_HOST_SEP_GPR ## gpr_idx)
  89. #define HOST_SEP_GPR_REG_ADDR(gpr_idx) _HOST_SEP_GPR_REG_ADDR(gpr_idx)
  90. #else
  91. #error Execution domain is not DX_CC_SEP/DX_CC_REE/DX_CC_TEE/DX_CONFIG_IOT_SUPPORTED
  92. #endif
  93. /* Registers address macros for ENV registers (development FPGA only) */
  94. #ifdef DX_BASE_ENV_REGS
  95. #ifndef DX_CC_SEP /* Irrelevant for SeP code */
  96. /* This offset should be added to mapping address of DX_BASE_ENV_REGS */
  97. #define SASI_ENV_REG_OFFSET(reg_name) (DX_ENV_ ## reg_name ## _REG_OFFSET)
  98. #endif
  99. #endif /*DX_BASE_ENV_REGS*/
  100. /* Bit fields access */
  101. #define SASI_REG_FLD_GET(unit_name, reg_name, fld_name, reg_val) \
  102. (DX_ ## reg_name ## _ ## fld_name ## _BIT_SIZE == 0x20 ? \
  103. reg_val /*!< \internal Optimization for 32b fields */ : \
  104. BITFIELD_GET(reg_val, DX_ ## reg_name ## _ ## fld_name ## _BIT_SHIFT, \
  105. DX_ ## reg_name ## _ ## fld_name ## _BIT_SIZE))
  106. /* Bit fields access */
  107. #define SASI2_REG_FLD_GET(unit_name, reg_name, fld_name, reg_val) \
  108. (SASI_ ## reg_name ## _ ## fld_name ## _BIT_SIZE == 0x20 ? \
  109. reg_val /*!< \internal Optimization for 32b fields */ : \
  110. BITFIELD_GET(reg_val, SASI_ ## reg_name ## _ ## fld_name ## _BIT_SHIFT, \
  111. SASI_ ## reg_name ## _ ## fld_name ## _BIT_SIZE))
  112. #define SASI_REG_FLD_SET( \
  113. unit_name, reg_name, fld_name, reg_shadow_var, new_fld_val) \
  114. do { \
  115. if (DX_ ## reg_name ## _ ## fld_name ## _BIT_SIZE == 0x20) \
  116. reg_shadow_var = new_fld_val; /*!< \internal Optimization for 32b fields */\
  117. else \
  118. BITFIELD_SET(reg_shadow_var, \
  119. DX_ ## reg_name ## _ ## fld_name ## _BIT_SHIFT, \
  120. DX_ ## reg_name ## _ ## fld_name ## _BIT_SIZE, \
  121. new_fld_val); \
  122. } while (0)
  123. #define SASI2_REG_FLD_SET( \
  124. unit_name, reg_name, fld_name, reg_shadow_var, new_fld_val) \
  125. do { \
  126. if (SASI_ ## reg_name ## _ ## fld_name ## _BIT_SIZE == 0x20) \
  127. reg_shadow_var = new_fld_val; /*!< \internal Optimization for 32b fields */\
  128. else \
  129. BITFIELD_SET(reg_shadow_var, \
  130. SASI_ ## reg_name ## _ ## fld_name ## _BIT_SHIFT, \
  131. SASI_ ## reg_name ## _ ## fld_name ## _BIT_SIZE, \
  132. new_fld_val); \
  133. } while (0)
  134. /* Usage example:
  135. uint32_t reg_shadow = READ_REGISTER(SASI_REG_ADDR(CRY_KERNEL,AES_CONTROL));
  136. SASI_REG_FLD_SET(CRY_KERNEL,AES_CONTROL,NK_KEY0,reg_shadow, 3);
  137. SASI_REG_FLD_SET(CRY_KERNEL,AES_CONTROL,NK_KEY1,reg_shadow, 1);
  138. WRITE_REGISTER(SASI_REG_ADDR(CRY_KERNEL,AES_CONTROL), reg_shadow);
  139. */
  140. #endif /*_SSI_REGS_H_*/