ssi_pal_dma.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #ifndef _SSI_PAL_DMA_H
  35. #define _SSI_PAL_DMA_H
  36. /*!
  37. @file
  38. @brief This file contains definitions that are used for the DMA related APIs. The implementation of these functions
  39. need to be replaced according to Platform and OS.
  40. @defgroup ssi_pal_dma CryptoCell PAL DMA related APIs
  41. @{
  42. @ingroup ssi_pal
  43. */
  44. #ifdef __cplusplus
  45. extern "C"
  46. {
  47. #endif
  48. #include "ssi_pal_types.h"
  49. #include "ssi_pal_dma_plat.h"
  50. #include "ssi_pal_dma_defs.h"
  51. /*! User buffer scatter information. */
  52. typedef struct {
  53. SaSiDmaAddr_t blockPhysAddr; /*!< Physical address.*/
  54. uint32_t blockSize; /*!< Block size.*/
  55. }SaSi_PalDmaBlockInfo_t;
  56. #ifdef BIG__ENDIAN
  57. /*! Defintion for big to little endian. */
  58. #define SET_WORD_LE(val) cpu_to_le32(val)
  59. #else
  60. /*! Defintion for big to little endian. */
  61. #define SET_WORD_LE
  62. #endif
  63. /**
  64. * @brief This function is called by the ARM TrustZone CryptoCell TEE runtime library before the HW is used.
  65. * It maps a given data buffer (virtual address) for ARM TrustZone CryptoCell TEE HW DMA use (physical address), and returns the list of
  66. * one or more DMA-able (physical) blocks. It may lock the buffer for ARM TrustZone CryptoCell TEE HW use. Once it is called,
  67. * only ARM TrustZone CryptoCell TEE HW access to the buffer is allowed, until it is unmapped.
  68. * If the data buffer was already mapped by the Secure OS prior to calling the ARM TrustZone CryptoCell TEE runtime library,
  69. * this API does not have to perform any actual mapping operation, but only return the list of DMA-able blocks.
  70. *
  71. * @return A non-zero value in case of failure.
  72. */
  73. uint32_t SaSi_PalDmaBufferMap(uint8_t *pDataBuffer, /*!< [in] Address of the buffer to map. */
  74. uint32_t buffSize, /*!< [in] Buffer size in bytes. */
  75. SaSi_PalDmaBufferDirection_t copyDirection, /*!< [in] Copy direction of the buffer, according to ::SaSi_PalDmaBufferDirection_t,
  76. <ul><li>TO_DEVICE - the original buffer is the input to the operation,
  77. and this function should copy it to the temp buffer,
  78. prior to the activating the HW on the temp buffer.</li>
  79. <li>FROM_DEVICE - not relevant for this API.</li>
  80. <li>BI_DIRECTION - used when the crypto operation is "in-place", meaning
  81. the result of encryption or decryption is written over the original data
  82. at the same address. Should be treated by this API same as
  83. TO_DEVICE. </li></ul> */
  84. uint32_t *pNumOfBlocks, /*!< [in/out] Maximum numOfBlocks to fill, as output the actual number. */
  85. SaSi_PalDmaBlockInfo_t *pDmaBlockList, /*!< [out] List of DMA-able blocks that the buffer maps to. */
  86. SaSi_PalDmaBufferHandle *dmaBuffHandle /*!< [out] A handle to the mapped buffer private resources.*/ );
  87. /**
  88. * @brief This function is called by the ARM TrustZone CryptoCell TEE runtime library after the HW is used.
  89. * It unmaps a given buffer, and frees its associated resources, if needed. It may unlock the buffer and flush it for CPU use.
  90. * Once it is called, ARM TrustZone CryptoCell TEE HW does not require access to this buffer anymore.
  91. * If the data buffer was already mapped by the Secure OS prior to calling the ARM TrustZone CryptoCell TEE runtime library, this API does
  92. * not have to perform any un-mapping operation, and the actual un-mapping can be done by the Secure OS outside the context
  93. * of the ARM TrustZone CryptoCell TEE runtime library.
  94. * @return A non-zero value in case of failure.
  95. */
  96. uint32_t SaSi_PalDmaBufferUnmap(uint8_t *pDataBuffer, /*!< [in] Address of the buffer to unmap. */
  97. uint32_t buffSize, /*!< [in] Buffer size in bytes. */
  98. SaSi_PalDmaBufferDirection_t copyDirection, /*!< [in] Copy direction of the buffer, according to ::SaSi_PalDmaBufferDirection_t
  99. <ul><li>TO_DEVICE - not relevant for this API. </li>
  100. <li>FROM_DEVICE - the temp buffer holds the output of the HW, and this
  101. API should copy it to the actual output buffer.</li>
  102. <li>BI_DIRECTION - used when the crypto operation is "in-place", meaning
  103. the result of encryption or decryption is written over the original data
  104. at the same address. Should be treated by this API same as
  105. FROM_DEVICE.</li></ul> */
  106. uint32_t numOfBlocks, /*!< [in] Number of DMA-able blocks that the buffer maps to. */
  107. SaSi_PalDmaBlockInfo_t *pDmaBlockList, /*!< [in] List of DMA-able blocks that the buffer maps to. */
  108. SaSi_PalDmaBufferHandle dmaBuffHandle /*!< [in] A handle to the mapped buffer private resources. */);
  109. /**
  110. * @brief Allocates a DMA-contiguous buffer for CPU use, and returns its virtual address.
  111. * Before passing the buffer to the ARM TrustZone CryptoCell TEE HW, ::SaSi_PalDmaBufferMap should be called.
  112. * \note The returned address must be aligned to 32 bits.
  113. *
  114. *
  115. * @return A non-zero value in case of failure.
  116. */
  117. uint32_t SaSi_PalDmaContigBufferAllocate(uint32_t buffSize, /*!< [in] Buffer size in bytes.*/
  118. uint8_t **ppVirtBuffAddr /*!< [out] Virtual address of the allocated buffer.*/);
  119. /**
  120. * @brief Frees resources previously allocated by ::SaSi_PalDmaContigBufferAllocate.
  121. *
  122. *
  123. * @return A non-zero value in case of failure.
  124. */
  125. uint32_t SaSi_PalDmaContigBufferFree(uint32_t buffSize, /*!< [in] Buffer size in Bytes. */
  126. uint8_t *pVirtBuffAddr /*!< [in] Virtual address of the buffer to free. */);
  127. /**
  128. * @brief Checks whether the buffer is guaranteed to be a single contiguous DMA block.
  129. *
  130. *
  131. * @return Returns TRUE if the buffer is guaranteed to be a single contiguous DMA block, and FALSE otherwise.
  132. */
  133. uint32_t SaSi_PalIsDmaBufferContiguous(uint8_t *pDataBuffer, /*!< [in] User buffer address. */
  134. uint32_t buffSize /*!< [in] User buffer size. */);
  135. /**
  136. * @brief Maps virtual address to physical address.
  137. *
  138. *
  139. * @return Physical address.
  140. */
  141. SaSiDmaAddr_t SaSi_PalMapVirtualToPhysical(uint8_t *pVirtualAddr /*!< [in] Pointer to virtual address. */);
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. /**
  146. @}
  147. */
  148. #endif