1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifdef CC_IOT 8 9 /************* Include Files ****************/ 10 #include "cc_pal_init.h" 11 #include "cc_pal_dma_plat.h" 12 #include "cc_pal_log.h" 13 #include "dx_reg_base_host.h" 14 #include "cc_pal_mutex.h" 15 #include "cc_pal_mem.h" 16 #include "cc_pal_abort.h" 17 #include "cc_pal_pm.h" 18 #include "cc_pal_interrupt_ctrl_plat.h" 19 20 extern CC_PalMutex CCSymCryptoMutex; 21 extern CC_PalMutex CCAsymCryptoMutex; 22 extern CC_PalMutex CCRndCryptoMutex; 23 extern CC_PalMutex *pCCRndCryptoMutex; 24 extern CC_PalMutex CCApbFilteringRegMutex; 25 26 #define PAL_WORKSPACE_MEM_BASE_ADDR 0 27 #define PAL_WORKSPACE_MEM_SIZE 0 28 29 30 /** 31 * @brief PAL layer entry point. 32 * The function initializes customer platform sub components, 33 * such as memory mapping used later by CRYS to get physical contiguous memory. 34 * 35 * 36 * @return Returns a non-zero value in case of failure 37 */ CC_PalInit(void)38int CC_PalInit(void) 39 { 40 41 CCError_t rc = CC_FAIL; 42 43 /* Currently in FreeRtos palDma is not needed - and therefore is implemented as empty. */ 44 rc = CC_PalDmaInit(PAL_WORKSPACE_MEM_SIZE, PAL_WORKSPACE_MEM_BASE_ADDR); 45 if (rc != CC_SUCCESS) 46 { 47 return 1; 48 } 49 50 /* Initialize power management module */ 51 CC_PalPowerSaveModeInit(); 52 53 /* Initialize mutex that protects shared memory and crypto access */ 54 rc = CC_PalMutexCreate(&CCSymCryptoMutex); 55 if (rc != CC_SUCCESS) 56 { 57 CC_PalAbort("Fail to create SYM mutex\n"); 58 } 59 /* Initialize mutex that protects shared memory and crypto access */ 60 rc = CC_PalMutexCreate(&CCAsymCryptoMutex); 61 if (rc != CC_SUCCESS) 62 { 63 CC_PalAbort("Fail to create ASYM mutex\n"); 64 } 65 /* Initialize mutex that protects shared memory and crypto access */ 66 rc = CC_PalMutexCreate(&CCRndCryptoMutex); 67 if (rc != CC_SUCCESS) { 68 CC_PalAbort("Fail to create RND mutex\n"); 69 } 70 pCCRndCryptoMutex = &CCRndCryptoMutex; 71 72 /* Initialize mutex that protects APBC access */ 73 rc = CC_PalMutexCreate(&CCApbFilteringRegMutex); 74 if (rc != 0) { 75 CC_PalAbort("Fail to create APBC mutex\n"); 76 } 77 78 CC_PalInitIrq(); 79 80 return 0; 81 } 82 83 84 /** 85 * @brief PAL layer entry point. 86 * The function initializes customer platform sub components, 87 * such as memory mapping used later by CRYS to get physical contiguous memory. 88 * 89 * 90 * @return None 91 */ CC_PalTerminate(void)92void CC_PalTerminate(void) 93 { 94 CCError_t err = CC_FAIL; 95 96 CC_PalDmaTerminate(); 97 CC_PalFinishIrq(); 98 99 err = CC_PalMutexDestroy(&CCSymCryptoMutex); 100 if (err != CC_SUCCESS) 101 { 102 CC_PAL_LOG_DEBUG("failed to destroy mutex CCSymCryptoMutex\n"); 103 } 104 105 CC_PalMemSetZero(&CCSymCryptoMutex, sizeof(CC_PalMutex)); 106 107 err = CC_PalMutexDestroy(&CCAsymCryptoMutex); 108 if (err != CC_SUCCESS) 109 { 110 CC_PAL_LOG_DEBUG("failed to destroy mutex CCAsymCryptoMutex\n"); 111 } 112 113 CC_PalMemSetZero(&CCAsymCryptoMutex, sizeof(CC_PalMutex)); 114 115 err = CC_PalMutexDestroy(&CCRndCryptoMutex); 116 if (err != CC_SUCCESS) 117 { 118 CC_PAL_LOG_DEBUG("failed to destroy mutex CCRndCryptoMutex\n"); 119 } 120 CC_PalMemSetZero(&CCRndCryptoMutex, sizeof(CC_PalMutex)); 121 122 123 err = CC_PalMutexDestroy(&CCApbFilteringRegMutex); 124 if (err != 0){ 125 CC_PAL_LOG_DEBUG("failed to destroy mutex CCApbFilteringRegMutex\n"); 126 } 127 CC_PalMemSetZero(&CCApbFilteringRegMutex, sizeof(CC_PalMutex)); 128 } 129 130 #endif 131 132