| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2007-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: bhsm.c $ |
|---|
| 39 | * $brcm_Revision: Hydra_Software_Devel/2 $ |
|---|
| 40 | * $brcm_Date: 2/15/12 3:33p $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /magnum/portinginterface/hsm/7425/b0/common/bhsm.c $ |
|---|
| 47 | * |
|---|
| 48 | * Hydra_Software_Devel/2 2/15/12 3:33p atruong |
|---|
| 49 | * SWSECURITY-109: HMAC-SHA command support for 40-nm platforms |
|---|
| 50 | * |
|---|
| 51 | * Hydra_Software_Devel/1 10/12/11 5:31p atruong |
|---|
| 52 | * SW7425-1251: HSM PI Support For BCM7425B0 |
|---|
| 53 | * |
|---|
| 54 | * Hydra_Software_Devel/5 9/15/11 4:59p atruong |
|---|
| 55 | * SW7346-381: Coverity Defect 32704 fix: Possible NULL pointer |
|---|
| 56 | * dereferencing |
|---|
| 57 | * |
|---|
| 58 | * Hydra_Software_Devel/4 6/29/11 8:23p atruong |
|---|
| 59 | * SW7425-812:HSM PI API modification for new HMAC-SHA support |
|---|
| 60 | * |
|---|
| 61 | * Hydra_Software_Devel/2 1/24/11 10:49a atruong |
|---|
| 62 | * SW7422-26: Add HSM PI Support For 7422A0 - CC header format |
|---|
| 63 | * |
|---|
| 64 | ******************************************************************************/ |
|---|
| 65 | |
|---|
| 66 | #include "bstd.h" |
|---|
| 67 | #include "bkni.h" |
|---|
| 68 | #include "bint.h" |
|---|
| 69 | #include "bchp_int_id_bsp.h" |
|---|
| 70 | #include "bchp_bsp_cmdbuf.h" |
|---|
| 71 | #include "bchp_bsp_glb_control.h" |
|---|
| 72 | |
|---|
| 73 | #include "bhsm.h" |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | BDBG_MODULE(BHSM); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | /******************************************************************************* |
|---|
| 82 | * Default Module and Channel Settings. Note that we could only modify |
|---|
| 83 | * Module settings during BHSM_Open. |
|---|
| 84 | *******************************************************************************/ |
|---|
| 85 | static const BHSM_Settings BHSM_defHsmSettings = |
|---|
| 86 | { |
|---|
| 87 | 2, /* max channels */ |
|---|
| 88 | 2000, /* 2000 milli seconds timeout */ |
|---|
| 89 | NULL, /* exception Callback function */ |
|---|
| 90 | /* default to ISR; TODO: default to polling needs a BHSM_SetSettings() function call first*/ |
|---|
| 91 | 0, |
|---|
| 92 | NULL |
|---|
| 93 | |
|---|
| 94 | }; |
|---|
| 95 | |
|---|
| 96 | static const BHSM_ChannelSettings BHSM_defHsmChannelSettings = |
|---|
| 97 | { |
|---|
| 98 | 2 |
|---|
| 99 | }; |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | /******************************************************************************* |
|---|
| 103 | * Public Module Functions |
|---|
| 104 | *******************************************************************************/ |
|---|
| 105 | BERR_Code BHSM_GetDefaultSettings( |
|---|
| 106 | BHSM_Settings *outp_sSettings, |
|---|
| 107 | BCHP_Handle in_chipHandle |
|---|
| 108 | ) |
|---|
| 109 | { |
|---|
| 110 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 111 | |
|---|
| 112 | BDBG_ENTER(BHSM_GetDefaultSettings); |
|---|
| 113 | BDBG_ASSERT( in_chipHandle ); |
|---|
| 114 | BSTD_UNUSED(in_chipHandle); /* Removed this when we start using this variable */ |
|---|
| 115 | |
|---|
| 116 | *outp_sSettings = BHSM_defHsmSettings; |
|---|
| 117 | |
|---|
| 118 | BDBG_LEAVE(BHSM_GetDefaultSettings); |
|---|
| 119 | return( errCode ); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | BERR_Code BHSM_SetSettings( |
|---|
| 124 | BHSM_Handle hHsm, |
|---|
| 125 | BHSM_NewSettings_t * newSettings |
|---|
| 126 | |
|---|
| 127 | ) |
|---|
| 128 | { |
|---|
| 129 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 130 | BDBG_MSG(("Inside BHSM_SetSettings\n")); |
|---|
| 131 | BDBG_ENTER(BHSM_SetSettings); |
|---|
| 132 | |
|---|
| 133 | if (hHsm == NULL) { return (BHSM_STATUS_INPUT_PARM_ERR); } |
|---|
| 134 | |
|---|
| 135 | /* |
|---|
| 136 | BHSM_defHsmSettings.uSpecialControl = ((BHSM_defHsmSettings.uSpecialControl >> leftPartShift) << leftPartShift)| |
|---|
| 137 | ((BHSM_defHsmSettings.uSpecialControl << rightPartShift) >> rightPartShift)| |
|---|
| 138 | (ctrlValue << whichControl); |
|---|
| 139 | */ |
|---|
| 140 | |
|---|
| 141 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_INPUT_PARM_ERR, |
|---|
| 142 | (newSettings->whichControl & (~BHSM_SPECIALCTROL_FLAGS)) != 0); |
|---|
| 143 | |
|---|
| 144 | if (((newSettings->whichControl & BHSM_CTRLS_TIMEOUT) == BHSM_CTRLS_TIMEOUT) && |
|---|
| 145 | (newSettings->timeoutMs > BHSM_SPECIALCTROL_TIMEOUT_MAX) ) |
|---|
| 146 | { |
|---|
| 147 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_INPUT_PARM_ERR, 1); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | /* legal setting here */ |
|---|
| 151 | |
|---|
| 152 | if ((newSettings->whichControl & BHSM_CTRLS_POLLINGORISR) == BHSM_CTRLS_POLLINGORISR) |
|---|
| 153 | { |
|---|
| 154 | hHsm->currentSettings.uSpecialControl = (newSettings->ctrlValue & 0x1) | (hHsm->currentSettings.uSpecialControl & (~0x1)); |
|---|
| 155 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.uSpecialControl = hHsm->currentSettings.uSpecialControl; |
|---|
| 156 | BDBG_MSG(("BHSM_CTRLS_POLLINGORISR is %x\n",hHsm->currentSettings.uSpecialControl )); |
|---|
| 157 | |
|---|
| 158 | if ( (newSettings->ctrlValue & 0x1) ==1 ) |
|---|
| 159 | { |
|---|
| 160 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_DisableCallback(hHsm->IntCallback2) ); |
|---|
| 161 | |
|---|
| 162 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_DisableCallback(hHsm->IntCallback) ); |
|---|
| 163 | |
|---|
| 164 | BREG_Write32(hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN, |
|---|
| 165 | BREG_Read32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, |
|---|
| 166 | BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN) & |
|---|
| 167 | (~BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_STATUS_OLOAD2_INT_MASK)); |
|---|
| 168 | |
|---|
| 169 | /* this clear may be optional, just to be safer*/ |
|---|
| 170 | BREG_Write32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, |
|---|
| 171 | BCHP_BSP_GLB_CONTROL_GLB_OLOAD2, |
|---|
| 172 | BREG_Read32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, |
|---|
| 173 | BCHP_BSP_GLB_CONTROL_GLB_OLOAD2) & |
|---|
| 174 | (~BCHP_BSP_GLB_CONTROL_GLB_OLOAD2_CMD_OLOAD2_MASK)); |
|---|
| 175 | |
|---|
| 176 | BDBG_MSG(("//////////BHSM_CTRLS_POLLING to disable ISR2, %x, channel num=%d\n", |
|---|
| 177 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.uSpecialControl, |
|---|
| 178 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->ucChannelNumber)); |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | }else |
|---|
| 182 | { |
|---|
| 183 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_EnableCallback(hHsm->IntCallback2) ); |
|---|
| 184 | |
|---|
| 185 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_EnableCallback(hHsm->IntCallback) ); |
|---|
| 186 | |
|---|
| 187 | BREG_Write32(hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN, |
|---|
| 188 | BREG_Read32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN) | |
|---|
| 189 | BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_STATUS_OLOAD2_INT_MASK); |
|---|
| 190 | BDBG_MSG(("//////////BHSM_CTRLS_POLLING to enable ISR2, %x, channel num=%d\n", |
|---|
| 191 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.uSpecialControl, |
|---|
| 192 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->ucChannelNumber)); |
|---|
| 193 | |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | if ((newSettings->whichControl & BHSM_CTRLS_TIMEOUT) == BHSM_CTRLS_TIMEOUT) |
|---|
| 200 | { |
|---|
| 201 | hHsm->currentSettings.ulTimeOutInMilSecs = newSettings->timeoutMs; |
|---|
| 202 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.ulTimeOutInMilSecs =hHsm->currentSettings.ulTimeOutInMilSecs; |
|---|
| 203 | BDBG_MSG(("BHSM_CTRLS_TIMEOUT is %x\n",hHsm->currentSettings.ulTimeOutInMilSecs )); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | /* for 3563, this is not really used |
|---|
| 207 | if ((newSettings->whichControl & BHSM_CTRLS_CHANNELNUM) == BHSM_CTRLS_CHANNELNUM) |
|---|
| 208 | { |
|---|
| 209 | hHsm->currentSettings.ucMaxChannels = newSettings->maxChannelNum; |
|---|
| 210 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.ulTimeOutInMilSecs =hHsm->currentSettings.ucMaxChannels ; |
|---|
| 211 | BDBG_MSG(("BHSM_CTRLS_CHANNELNUM is %x\n",hHsm->currentSettings.ucMaxChannels )); |
|---|
| 212 | } */ |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | BHSM_P_DONE_LABEL: |
|---|
| 216 | |
|---|
| 217 | BDBG_LEAVE(BHSM_SetSettings); |
|---|
| 218 | BDBG_MSG(("Exit BHSM_SetSettings\n")); |
|---|
| 219 | return( errCode ); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | BERR_Code BHSM_SetSettings_isr( |
|---|
| 224 | BHSM_Handle hHsm, |
|---|
| 225 | BHSM_NewSettings_t * newSettings |
|---|
| 226 | |
|---|
| 227 | ) |
|---|
| 228 | { |
|---|
| 229 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 230 | BDBG_MSG(("Inside BHSM_SetSettings\n")); |
|---|
| 231 | BDBG_ENTER(BHSM_SetSettings_isr); |
|---|
| 232 | |
|---|
| 233 | if (hHsm == NULL) { return (BHSM_STATUS_INPUT_PARM_ERR); } |
|---|
| 234 | |
|---|
| 235 | /* |
|---|
| 236 | BHSM_defHsmSettings.uSpecialControl = ((BHSM_defHsmSettings.uSpecialControl >> leftPartShift) << leftPartShift)| |
|---|
| 237 | ((BHSM_defHsmSettings.uSpecialControl << rightPartShift) >> rightPartShift)| |
|---|
| 238 | (ctrlValue << whichControl); |
|---|
| 239 | */ |
|---|
| 240 | |
|---|
| 241 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_INPUT_PARM_ERR, |
|---|
| 242 | (newSettings->whichControl & (~BHSM_SPECIALCTROL_FLAGS)) != 0); |
|---|
| 243 | |
|---|
| 244 | if (((newSettings->whichControl & BHSM_CTRLS_TIMEOUT) == BHSM_CTRLS_TIMEOUT) && |
|---|
| 245 | ( newSettings->timeoutMs > BHSM_SPECIALCTROL_TIMEOUT_MAX ||newSettings->timeoutMs < BHSM_SPECIALCTROL_TIMEOUT_MIN ) ) |
|---|
| 246 | { |
|---|
| 247 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_INPUT_PARM_ERR, 1); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | /* legal setting here */ |
|---|
| 251 | |
|---|
| 252 | if ((newSettings->whichControl & BHSM_CTRLS_POLLINGORISR) == BHSM_CTRLS_POLLINGORISR) |
|---|
| 253 | { |
|---|
| 254 | hHsm->currentSettings.uSpecialControl = (newSettings->ctrlValue & 0x1) | (hHsm->currentSettings.uSpecialControl & (~0x1)); |
|---|
| 255 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.uSpecialControl = hHsm->currentSettings.uSpecialControl; |
|---|
| 256 | BDBG_MSG(("BHSM_CTRLS_POLLINGORISR is %x\n",hHsm->currentSettings.uSpecialControl )); |
|---|
| 257 | |
|---|
| 258 | if ( (newSettings->ctrlValue & 0x1) ==1 ) |
|---|
| 259 | { |
|---|
| 260 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_DisableCallback_isr(hHsm->IntCallback2) ); |
|---|
| 261 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_DisableCallback(hHsm->IntCallback) ); |
|---|
| 262 | |
|---|
| 263 | BREG_Write32(hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN, |
|---|
| 264 | BREG_Read32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, |
|---|
| 265 | BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN) & |
|---|
| 266 | (~BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_STATUS_OLOAD2_INT_MASK)); |
|---|
| 267 | |
|---|
| 268 | /* this clear may be optional, just to be safer*/ |
|---|
| 269 | BREG_Write32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, |
|---|
| 270 | BCHP_BSP_GLB_CONTROL_GLB_OLOAD2, |
|---|
| 271 | BREG_Read32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, |
|---|
| 272 | BCHP_BSP_GLB_CONTROL_GLB_OLOAD2) & |
|---|
| 273 | (~BCHP_BSP_GLB_CONTROL_GLB_OLOAD2_CMD_OLOAD2_MASK)); |
|---|
| 274 | |
|---|
| 275 | BDBG_MSG(("//////////BHSM_CTRLS_POLLING to disable ISR2, %x, channel num=%d\n", |
|---|
| 276 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.uSpecialControl, |
|---|
| 277 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->ucChannelNumber)); |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | }else |
|---|
| 281 | { |
|---|
| 282 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_EnableCallback_isr(hHsm->IntCallback2) ); |
|---|
| 283 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_EnableCallback(hHsm->IntCallback) ); |
|---|
| 284 | |
|---|
| 285 | BREG_Write32(hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN, |
|---|
| 286 | BREG_Read32( hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN) | |
|---|
| 287 | BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_STATUS_OLOAD2_INT_MASK); |
|---|
| 288 | BDBG_MSG(("//////////BHSM_CTRLS_POLLING to enable ISR2, %x, channel num=%d\n", |
|---|
| 289 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.uSpecialControl, |
|---|
| 290 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->ucChannelNumber)); |
|---|
| 291 | |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | if ((newSettings->whichControl & BHSM_CTRLS_TIMEOUT) == BHSM_CTRLS_TIMEOUT) |
|---|
| 298 | { |
|---|
| 299 | hHsm->currentSettings.ulTimeOutInMilSecs = newSettings->timeoutMs; |
|---|
| 300 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.ulTimeOutInMilSecs =hHsm->currentSettings.ulTimeOutInMilSecs; |
|---|
| 301 | BDBG_MSG(("BHSM_CTRLS_TIMEOUT is %x\n",hHsm->currentSettings.ulTimeOutInMilSecs )); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | /* for 3563, this is not really used |
|---|
| 305 | if ((newSettings->whichControl & BHSM_CTRLS_CHANNELNUM) == BHSM_CTRLS_CHANNELNUM) |
|---|
| 306 | { |
|---|
| 307 | hHsm->currentSettings.ucMaxChannels = newSettings->maxChannelNum; |
|---|
| 308 | hHsm->channelHandles[BHSM_HwModule_eCmdInterface2]->moduleHandle->currentSettings.ulTimeOutInMilSecs =hHsm->currentSettings.ucMaxChannels ; |
|---|
| 309 | BDBG_MSG(("BHSM_CTRLS_CHANNELNUM is %x\n",hHsm->currentSettings.ucMaxChannels )); |
|---|
| 310 | } */ |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | BHSM_P_DONE_LABEL: |
|---|
| 314 | |
|---|
| 315 | BDBG_LEAVE(BHSM_SetSettings_isr); |
|---|
| 316 | BDBG_MSG(("Exit BHSM_SetSettings_isr\n")); |
|---|
| 317 | return( errCode ); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | BERR_Code BHSM_Open( |
|---|
| 322 | BHSM_Handle *outp_handle, |
|---|
| 323 | BREG_Handle in_regHandle, |
|---|
| 324 | BCHP_Handle in_chipHandle, |
|---|
| 325 | BINT_Handle in_interruptHandle, |
|---|
| 326 | const BHSM_Settings *inp_sSettings |
|---|
| 327 | ) |
|---|
| 328 | { |
|---|
| 329 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 330 | BHSM_Handle moduleHandle; |
|---|
| 331 | unsigned int channelNum, i, j; |
|---|
| 332 | |
|---|
| 333 | BDBG_ENTER(BHSM_Open); |
|---|
| 334 | BDBG_ASSERT( in_chipHandle ); |
|---|
| 335 | BDBG_ASSERT( in_regHandle ); |
|---|
| 336 | BDBG_ASSERT( in_interruptHandle ); |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | *outp_handle = NULL; |
|---|
| 340 | |
|---|
| 341 | /* Alloc memory from the system heap */ |
|---|
| 342 | if ((moduleHandle = |
|---|
| 343 | (BHSM_Handle) BKNI_Malloc( sizeof( BHSM_P_Handle))) |
|---|
| 344 | == NULL) { |
|---|
| 345 | /* wrap initially detected error code */ |
|---|
| 346 | errCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 347 | goto BHSM_P_DONE_LABEL; |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | BKNI_Memset(moduleHandle, 0, sizeof( BHSM_P_Handle )); |
|---|
| 351 | |
|---|
| 352 | moduleHandle->ulMagicNumber = BHSM_P_HANDLE_MAGIC_NUMBER; |
|---|
| 353 | moduleHandle->chipHandle = in_chipHandle; |
|---|
| 354 | moduleHandle->regHandle = in_regHandle; |
|---|
| 355 | moduleHandle->interruptHandle = in_interruptHandle; |
|---|
| 356 | if (inp_sSettings == NULL) |
|---|
| 357 | moduleHandle->currentSettings = BHSM_defHsmSettings; |
|---|
| 358 | else { |
|---|
| 359 | moduleHandle->currentSettings = *inp_sSettings; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | if ( moduleHandle->currentSettings.hHeap != NULL ) |
|---|
| 364 | { |
|---|
| 365 | moduleHandle->hHeap = moduleHandle->currentSettings.hHeap; |
|---|
| 366 | moduleHandle->pContiguousMem= BMEM_AllocAligned( moduleHandle->currentSettings.hHeap, BHSM_CONTIGUOUS_MEMORY_SIZE, 6,0 ); /* 64 bytes allignement*/ |
|---|
| 367 | BDBG_MSG(("(%08X bytes continuous memeory inside HSM) pContiguousMem = %p\n", BHSM_CONTIGUOUS_MEMORY_SIZE, moduleHandle->pContiguousMem)); |
|---|
| 368 | BDBG_ASSERT( moduleHandle->pContiguousMem != NULL ); |
|---|
| 369 | |
|---|
| 370 | moduleHandle->shaContext.bufferSizeMax = BHSM_SHA_BUFFER_SIZE; |
|---|
| 371 | moduleHandle->shaContext.pBuffer = BMEM_AllocAligned( moduleHandle->currentSettings.hHeap, BHSM_SHA_BUFFER_SIZE, 6,0 ); |
|---|
| 372 | BDBG_ASSERT( moduleHandle->shaContext.pBuffer != NULL ); |
|---|
| 373 | BHSM_P_CHECK_ERR_CODE_CONDITION(errCode, BHSM_STATUS_MEMORY_PHYCOVERTING_ERR, |
|---|
| 374 | BMEM_ConvertAddressToOffset( moduleHandle->hHeap, |
|---|
| 375 | moduleHandle->shaContext.pBuffer, |
|---|
| 376 | &moduleHandle->shaContext.shaBufferOffset)); |
|---|
| 377 | moduleHandle->shaContext.bufferSize = 0; |
|---|
| 378 | moduleHandle->shaContext.bMultiple = false; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | BKNI_CreateMutex( &(moduleHandle->caKeySlotMutexLock)); |
|---|
| 383 | BKNI_CreateMutex( &(moduleHandle->m2mKeySlotMutexLock)); |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | BHSM_SetIntrCallback( moduleHandle, BHSM_IntrType_eException, BHSM_P_ExceptionInterruptCB_isr); |
|---|
| 388 | |
|---|
| 389 | BDBG_MSG(("Inside BHSM_Open: Before BINT_CreateCallback \n")); |
|---|
| 390 | /* Enable interrupt */ |
|---|
| 391 | |
|---|
| 392 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_CreateCallback( |
|---|
| 393 | &(moduleHandle->IntCallback), moduleHandle->interruptHandle, |
|---|
| 394 | BCHP_INT_ID_BSP_OLOAD1_INTR, |
|---|
| 395 | BHSM_P_IntHandler_isr, (void *) moduleHandle, 0x00 ) ); |
|---|
| 396 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_EnableCallback(moduleHandle->IntCallback) ); |
|---|
| 397 | |
|---|
| 398 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_CreateCallback( |
|---|
| 399 | &(moduleHandle->IntCallback2), moduleHandle->interruptHandle, |
|---|
| 400 | BCHP_INT_ID_BSP_OLOAD2_INTR, |
|---|
| 401 | BHSM_P_IntHandler_isr, (void *) moduleHandle, 0x01 ) ); |
|---|
| 402 | |
|---|
| 403 | BDBG_MSG(("Inside BHSM_Open: Before BINT_EnableCallback2 \n")); |
|---|
| 404 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_EnableCallback(moduleHandle->IntCallback2) ); |
|---|
| 405 | |
|---|
| 406 | BREG_Write32( moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_EN, |
|---|
| 407 | 0); |
|---|
| 408 | /* BCHP_BSP_GLB_NONSECURE_GLB_HOST_INTR_EN_HOST_INTR_STATUS_EN_MASK); */ |
|---|
| 409 | |
|---|
| 410 | BREG_Write32( moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_HOST_INTR_STATUS, 0); |
|---|
| 411 | BREG_Write32( moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_OLOAD2, 0); |
|---|
| 412 | BREG_Write32( moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_ILOAD2, 0); |
|---|
| 413 | BREG_Write32( moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_OLOAD1, 0); |
|---|
| 414 | BREG_Write32( moduleHandle->regHandle, BCHP_BSP_GLB_CONTROL_GLB_ILOAD1, 0); |
|---|
| 415 | |
|---|
| 416 | /* Get the chip information */ |
|---|
| 417 | BCHP_GetChipInfo( moduleHandle->chipHandle, &moduleHandle->chipId, &moduleHandle->chipRev ); |
|---|
| 418 | BDBG_MSG(( "Chip Information \n" )); |
|---|
| 419 | BDBG_MSG(( "chipId=0x%x, chipRev=0x%x\n", moduleHandle->chipId, moduleHandle->chipRev )); |
|---|
| 420 | |
|---|
| 421 | /* |
|---|
| 422 | If inp_sSettings->maxChannels == 0, set it to |
|---|
| 423 | BHSM_MAX_SUPPOTED_CHANNELS |
|---|
| 424 | */ |
|---|
| 425 | if (moduleHandle->currentSettings.ucMaxChannels == 0) |
|---|
| 426 | moduleHandle->currentSettings.ucMaxChannels = |
|---|
| 427 | BHSM_MAX_SUPPOTED_CHANNELS; |
|---|
| 428 | |
|---|
| 429 | for( channelNum = 0; |
|---|
| 430 | channelNum < moduleHandle->currentSettings.ucMaxChannels; |
|---|
| 431 | channelNum++ ) { |
|---|
| 432 | |
|---|
| 433 | moduleHandle->channelHandles[channelNum] = NULL; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | /* Initialize members */ |
|---|
| 438 | for (i=0; i<BCMD_TOTAL_PIDCHANNELS*2; i++) { |
|---|
| 439 | |
|---|
| 440 | moduleHandle->aunCAKeySlotInfo[i].keySlotType = |
|---|
| 441 | BCMD_XptSecKeySlot_eTypeMax; |
|---|
| 442 | moduleHandle->aunCAKeySlotInfo[i].bIsUsed = |
|---|
| 443 | false; |
|---|
| 444 | |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | /* Initialize PidChannelToKeySlotNum matrices */ |
|---|
| 448 | for (i=0; i<BCMD_TOTAL_PIDCHANNELS; i++) { |
|---|
| 449 | for (j=0; j < 2; j++) { |
|---|
| 450 | moduleHandle->aPidChannelToCAKeySlotNum[i][j].keySlotType = |
|---|
| 451 | BCMD_XptSecKeySlot_eTypeMax; |
|---|
| 452 | moduleHandle->aPidChannelToCAKeySlotNum[i][j].unKeySlotNum = |
|---|
| 453 | BHSM_SLOT_NUM_INIT_VAL; |
|---|
| 454 | } |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | /* Initialize M2M Key Slot info matrices */ |
|---|
| 459 | for (i=0; i<BCMD_MAX_M2M_KEY_SLOT; i++) { |
|---|
| 460 | |
|---|
| 461 | moduleHandle->aunM2MKeySlotInfo[i].bIsUsed = false; |
|---|
| 462 | |
|---|
| 463 | } |
|---|
| 464 | |
|---|
| 465 | /* End of Initialize members */ |
|---|
| 466 | |
|---|
| 467 | *outp_handle = moduleHandle; |
|---|
| 468 | |
|---|
| 469 | moduleHandle->bIsOpen = true; |
|---|
| 470 | |
|---|
| 471 | BHSM_P_DONE_LABEL: |
|---|
| 472 | |
|---|
| 473 | if( errCode != BERR_SUCCESS ) |
|---|
| 474 | { |
|---|
| 475 | if( moduleHandle != NULL ) |
|---|
| 476 | { |
|---|
| 477 | BKNI_Free( moduleHandle ); |
|---|
| 478 | |
|---|
| 479 | } |
|---|
| 480 | } |
|---|
| 481 | BDBG_LEAVE(BHSM_Open); |
|---|
| 482 | BDBG_MSG(("Exit BHSM_Open\n")); |
|---|
| 483 | return( errCode ); |
|---|
| 484 | |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | BERR_Code BHSM_Close( |
|---|
| 488 | BHSM_Handle inout_handle |
|---|
| 489 | ) |
|---|
| 490 | { |
|---|
| 491 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | BDBG_ENTER(BHSM_Close); |
|---|
| 495 | BDBG_ASSERT( inout_handle ); |
|---|
| 496 | |
|---|
| 497 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, (inout_handle == NULL) ); |
|---|
| 498 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 499 | (inout_handle->ulMagicNumber != BHSM_P_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 500 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 501 | (inout_handle->bIsOpen == false) ); |
|---|
| 502 | |
|---|
| 503 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_DisableCallback( inout_handle->IntCallback)); |
|---|
| 504 | |
|---|
| 505 | BHSM_P_CHECK_ERR_CODE_FUNC( errCode, BINT_DestroyCallback( inout_handle->IntCallback2 ) ); |
|---|
| 506 | |
|---|
| 507 | if (inout_handle->shaContext.pBuffer) |
|---|
| 508 | { |
|---|
| 509 | BMEM_Free (inout_handle->hHeap, (void*)inout_handle->shaContext.pBuffer); |
|---|
| 510 | } |
|---|
| 511 | if (inout_handle->pContiguousMem) |
|---|
| 512 | { |
|---|
| 513 | BMEM_Free (inout_handle->hHeap, (void*)inout_handle->pContiguousMem); |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | BHSM_P_DONE_LABEL: |
|---|
| 517 | BKNI_DestroyMutex( inout_handle->caKeySlotMutexLock); |
|---|
| 518 | BKNI_DestroyMutex( inout_handle->m2mKeySlotMutexLock); |
|---|
| 519 | |
|---|
| 520 | inout_handle->bIsOpen = false; |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | BKNI_Free( inout_handle ); |
|---|
| 525 | inout_handle = NULL; |
|---|
| 526 | |
|---|
| 527 | BDBG_LEAVE(BHSM_Close); |
|---|
| 528 | return( errCode ); |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | BERR_Code BHSM_GetTotalChannels( |
|---|
| 532 | BHSM_Handle in_handle, |
|---|
| 533 | unsigned char *outp_ucTotalChannels |
|---|
| 534 | ) |
|---|
| 535 | { |
|---|
| 536 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 537 | |
|---|
| 538 | BDBG_ENTER(BHSM_GetTotalChannels); |
|---|
| 539 | BDBG_ASSERT( in_handle ); |
|---|
| 540 | |
|---|
| 541 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 542 | (in_handle->ulMagicNumber != BHSM_P_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 543 | |
|---|
| 544 | *outp_ucTotalChannels = in_handle->currentSettings.ucMaxChannels; |
|---|
| 545 | |
|---|
| 546 | BHSM_P_DONE_LABEL: |
|---|
| 547 | |
|---|
| 548 | BDBG_LEAVE(BHSM_GetTotalChannels); |
|---|
| 549 | return( errCode ); |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | BERR_Code BHSM_GetChannelDefaultSettings( |
|---|
| 554 | BHSM_Handle in_handle, |
|---|
| 555 | BHSM_HwModule in_channelNo, |
|---|
| 556 | BHSM_ChannelSettings *outp_sSettings |
|---|
| 557 | ) |
|---|
| 558 | { |
|---|
| 559 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | BDBG_ENTER(BHSM_GetChannelDefaultSettings); |
|---|
| 563 | BDBG_ASSERT( in_handle ); |
|---|
| 564 | |
|---|
| 565 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 566 | (in_handle->ulMagicNumber != BHSM_P_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 567 | |
|---|
| 568 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BERR_INVALID_PARAMETER, |
|---|
| 569 | (in_channelNo >= in_handle->currentSettings.ucMaxChannels) ); |
|---|
| 570 | |
|---|
| 571 | *outp_sSettings = BHSM_defHsmChannelSettings; |
|---|
| 572 | |
|---|
| 573 | BHSM_P_DONE_LABEL: |
|---|
| 574 | |
|---|
| 575 | BDBG_LEAVE(BHSM_GetChannelDefaultSettings); |
|---|
| 576 | return( errCode ); |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | BERR_Code BHSM_Channel_Open( |
|---|
| 580 | BHSM_Handle in_handle, |
|---|
| 581 | BHSM_ChannelHandle *outp_channelHandle, |
|---|
| 582 | BHSM_HwModule in_channelNo, |
|---|
| 583 | const BHSM_ChannelSettings *inp_channelDefSettings |
|---|
| 584 | ) |
|---|
| 585 | { |
|---|
| 586 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 587 | BHSM_ChannelHandle channelHandle = NULL; |
|---|
| 588 | |
|---|
| 589 | BDBG_MSG(("Inside BHSM_Channel_Open\n")); |
|---|
| 590 | BDBG_ENTER(BHSM_Channel_Open); |
|---|
| 591 | BDBG_ASSERT( in_handle ); |
|---|
| 592 | |
|---|
| 593 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 594 | (in_handle->ulMagicNumber != BHSM_P_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 595 | |
|---|
| 596 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BERR_INVALID_PARAMETER, |
|---|
| 597 | (in_channelNo >= in_handle->currentSettings.ucMaxChannels) ); |
|---|
| 598 | |
|---|
| 599 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 600 | (in_handle->bIsOpen == false) ); |
|---|
| 601 | |
|---|
| 602 | /* channel handle must be NULL. */ |
|---|
| 603 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 604 | (in_handle->channelHandles[in_channelNo] != NULL) ); |
|---|
| 605 | |
|---|
| 606 | *outp_channelHandle = NULL; |
|---|
| 607 | |
|---|
| 608 | /* Alloc memory from the system heap */ |
|---|
| 609 | if ((channelHandle = |
|---|
| 610 | (BHSM_ChannelHandle) BKNI_Malloc(sizeof(BHSM_P_ChannelHandle))) |
|---|
| 611 | == NULL) { |
|---|
| 612 | /* wrap initially detected error code */ |
|---|
| 613 | errCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 614 | goto BHSM_P_DONE_LABEL; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | BKNI_Memset(channelHandle, 0, sizeof( BHSM_P_ChannelHandle )); |
|---|
| 618 | |
|---|
| 619 | channelHandle->ulMagicNumber = BHSM_P_CHANNEL_HANDLE_MAGIC_NUMBER; |
|---|
| 620 | channelHandle->moduleHandle = in_handle; |
|---|
| 621 | |
|---|
| 622 | if (inp_channelDefSettings == NULL) |
|---|
| 623 | channelHandle->currentChannelSettings.ucUnknown = |
|---|
| 624 | BHSM_defHsmChannelSettings.ucUnknown; |
|---|
| 625 | else { |
|---|
| 626 | channelHandle->currentChannelSettings.ucUnknown = |
|---|
| 627 | inp_channelDefSettings->ucUnknown; |
|---|
| 628 | } |
|---|
| 629 | |
|---|
| 630 | BHSM_P_CHECK_ERR_CODE_FUNC(errCode, BKNI_CreateMutex( &(channelHandle->mutexLock))); |
|---|
| 631 | |
|---|
| 632 | BHSM_P_CHECK_ERR_CODE_FUNC(errCode, BKNI_CreateEvent( &(channelHandle->oLoadWait))); |
|---|
| 633 | |
|---|
| 634 | channelHandle->oLoadSet = 0; |
|---|
| 635 | |
|---|
| 636 | BDBG_MSG(("in_channelNo = %d\n", in_channelNo)); |
|---|
| 637 | |
|---|
| 638 | switch(in_channelNo) { |
|---|
| 639 | case BHSM_HwModule_eCmdInterface1: |
|---|
| 640 | channelHandle->ulInCmdBufAddr = BHSM_IN_BUF1_ADDR; |
|---|
| 641 | channelHandle->ulOutCmdBufAddr = BHSM_OUT_BUF1_ADDR; |
|---|
| 642 | channelHandle->ulILoadRegAddr = BCHP_BSP_GLB_CONTROL_GLB_ILOAD1; |
|---|
| 643 | channelHandle->ulILoadVal = BCHP_BSP_GLB_CONTROL_GLB_ILOAD1_CMD_ILOAD1_MASK; |
|---|
| 644 | channelHandle->ulIReadyRegAddr = BCHP_BSP_GLB_CONTROL_GLB_IRDY; |
|---|
| 645 | channelHandle->ulIReadyVal= BCHP_BSP_GLB_CONTROL_GLB_IRDY_CMD_IDRY1_MASK; |
|---|
| 646 | |
|---|
| 647 | break; |
|---|
| 648 | |
|---|
| 649 | case BHSM_HwModule_eCmdInterface2: |
|---|
| 650 | channelHandle->ulInCmdBufAddr = BHSM_IN_BUF2_ADDR; |
|---|
| 651 | channelHandle->ulOutCmdBufAddr = BHSM_OUT_BUF2_ADDR; |
|---|
| 652 | channelHandle->ulILoadRegAddr = BCHP_BSP_GLB_CONTROL_GLB_ILOAD2; |
|---|
| 653 | channelHandle->ulILoadVal = BCHP_BSP_GLB_CONTROL_GLB_ILOAD2_CMD_ILOAD2_MASK; |
|---|
| 654 | channelHandle->ulIReadyRegAddr = BCHP_BSP_GLB_CONTROL_GLB_IRDY; |
|---|
| 655 | channelHandle->ulIReadyVal= BCHP_BSP_GLB_CONTROL_GLB_IRDY_CMD_IDRY2_MASK; |
|---|
| 656 | |
|---|
| 657 | break; |
|---|
| 658 | |
|---|
| 659 | default: |
|---|
| 660 | errCode = BERR_INVALID_PARAMETER; |
|---|
| 661 | goto BHSM_P_DONE_LABEL; |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | BDBG_MSG(("ulInCmdBufAddr = 0x%lx, ulOutCmdBufAddr = 0x%lx \n", |
|---|
| 665 | channelHandle->ulInCmdBufAddr, channelHandle->ulOutCmdBufAddr)); |
|---|
| 666 | |
|---|
| 667 | channelHandle->ucChannelNumber = in_channelNo; |
|---|
| 668 | in_handle->channelHandles[in_channelNo] = channelHandle; |
|---|
| 669 | |
|---|
| 670 | *outp_channelHandle = channelHandle; |
|---|
| 671 | channelHandle->bIsOpen = true; |
|---|
| 672 | |
|---|
| 673 | BHSM_P_DONE_LABEL: |
|---|
| 674 | if( errCode != BERR_SUCCESS ) |
|---|
| 675 | { |
|---|
| 676 | if( channelHandle != NULL ) |
|---|
| 677 | { |
|---|
| 678 | BKNI_Free( channelHandle ); |
|---|
| 679 | } |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | BDBG_LEAVE(BHSM_Channel_Open); |
|---|
| 683 | BDBG_MSG(("Exit BHSM_Channel_Open\n")); |
|---|
| 684 | return( errCode ); |
|---|
| 685 | } |
|---|
| 686 | |
|---|
| 687 | BERR_Code BHSM_Channel_Close( |
|---|
| 688 | BHSM_ChannelHandle inout_channelHandle |
|---|
| 689 | ) |
|---|
| 690 | { |
|---|
| 691 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 692 | BHSM_Handle moduleHandle; |
|---|
| 693 | |
|---|
| 694 | BDBG_ENTER(BHSM_Channel_Close); |
|---|
| 695 | BDBG_MSG(("Enter BHSM_Channel_Close\n")); |
|---|
| 696 | BDBG_ASSERT( inout_channelHandle ); |
|---|
| 697 | |
|---|
| 698 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 699 | (inout_channelHandle->ulMagicNumber != BHSM_P_CHANNEL_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 700 | |
|---|
| 701 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 702 | (inout_channelHandle->bIsOpen == false) ); |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | BHSM_P_DONE_LABEL: |
|---|
| 706 | |
|---|
| 707 | BKNI_DestroyMutex( inout_channelHandle->mutexLock); |
|---|
| 708 | |
|---|
| 709 | BKNI_DestroyEvent( inout_channelHandle->oLoadWait); |
|---|
| 710 | |
|---|
| 711 | inout_channelHandle->bIsOpen = false; |
|---|
| 712 | |
|---|
| 713 | moduleHandle = inout_channelHandle->moduleHandle; |
|---|
| 714 | moduleHandle->channelHandles[inout_channelHandle->ucChannelNumber] = NULL; |
|---|
| 715 | |
|---|
| 716 | BKNI_Free( inout_channelHandle ); |
|---|
| 717 | inout_channelHandle = NULL; |
|---|
| 718 | |
|---|
| 719 | BDBG_MSG(("Leave BHSM_Channel_Close\n")); |
|---|
| 720 | BDBG_LEAVE(BHSM_Channel_Close); |
|---|
| 721 | return( errCode ); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | BERR_Code BHSM_Channel_GetDevice( |
|---|
| 725 | BHSM_ChannelHandle in_channelHandle, |
|---|
| 726 | BHSM_Handle *outp_handle |
|---|
| 727 | ) |
|---|
| 728 | { |
|---|
| 729 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 730 | |
|---|
| 731 | BDBG_ENTER(BHSM_Channel_GetDevice); |
|---|
| 732 | BDBG_ASSERT( in_channelHandle ); |
|---|
| 733 | |
|---|
| 734 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 735 | (in_channelHandle->moduleHandle->bIsOpen == false) ); |
|---|
| 736 | |
|---|
| 737 | *outp_handle = NULL; |
|---|
| 738 | |
|---|
| 739 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 740 | (in_channelHandle->ulMagicNumber != BHSM_P_CHANNEL_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 741 | |
|---|
| 742 | *outp_handle = in_channelHandle->moduleHandle; |
|---|
| 743 | |
|---|
| 744 | BHSM_P_DONE_LABEL: |
|---|
| 745 | BDBG_LEAVE(BHSM_Channel_GetDevice); |
|---|
| 746 | return( errCode ); |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | BERR_Code BHSM_GetChannel( |
|---|
| 751 | BHSM_Handle in_handle, |
|---|
| 752 | BHSM_HwModule in_channelNo, |
|---|
| 753 | BHSM_ChannelHandle *outp_channelHandle |
|---|
| 754 | ) |
|---|
| 755 | { |
|---|
| 756 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 757 | BHSM_ChannelHandle channelHandle = NULL; |
|---|
| 758 | |
|---|
| 759 | BDBG_ENTER(BHSM_GetChannel); |
|---|
| 760 | BDBG_ASSERT( in_handle ); |
|---|
| 761 | |
|---|
| 762 | *outp_channelHandle = NULL; |
|---|
| 763 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 764 | (in_handle->ulMagicNumber != BHSM_P_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 765 | |
|---|
| 766 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BERR_INVALID_PARAMETER, |
|---|
| 767 | (in_channelNo >= in_handle->currentSettings.ucMaxChannels) ); |
|---|
| 768 | |
|---|
| 769 | channelHandle = in_handle->channelHandles[in_channelNo]; |
|---|
| 770 | |
|---|
| 771 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 772 | (channelHandle == NULL ) ); |
|---|
| 773 | |
|---|
| 774 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 775 | (channelHandle->ulMagicNumber != BHSM_P_CHANNEL_HANDLE_MAGIC_NUMBER ) ); |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BHSM_STATUS_FAILED, |
|---|
| 779 | (channelHandle->bIsOpen == false) ); |
|---|
| 780 | |
|---|
| 781 | *outp_channelHandle = channelHandle; |
|---|
| 782 | |
|---|
| 783 | BHSM_P_DONE_LABEL: |
|---|
| 784 | |
|---|
| 785 | BDBG_LEAVE(BHSM_GetChannel); |
|---|
| 786 | return( errCode ); |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | BERR_Code BHSM_SetIntrCallback( |
|---|
| 791 | BHSM_Handle in_handle, |
|---|
| 792 | BHSM_IntrType in_eIntType, |
|---|
| 793 | BHSM_IsrCallbackFunc in_callback |
|---|
| 794 | ) |
|---|
| 795 | { |
|---|
| 796 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 797 | |
|---|
| 798 | BDBG_ASSERT( in_handle ); |
|---|
| 799 | BDBG_ASSERT( in_callback ); |
|---|
| 800 | |
|---|
| 801 | BHSM_P_CHECK_ERR_CODE_CONDITION( errCode, BERR_INVALID_PARAMETER, |
|---|
| 802 | (in_eIntType >= BHSM_IntrType_eMax ) ); |
|---|
| 803 | |
|---|
| 804 | switch (in_eIntType) { |
|---|
| 805 | |
|---|
| 806 | case BHSM_IntrType_eException: |
|---|
| 807 | BKNI_EnterCriticalSection(); |
|---|
| 808 | /* Assign the callback into the interrupt table. */ |
|---|
| 809 | in_handle->currentSettings.exceptionCBfunc = in_callback; |
|---|
| 810 | BKNI_LeaveCriticalSection(); |
|---|
| 811 | break; |
|---|
| 812 | |
|---|
| 813 | default: |
|---|
| 814 | BDBG_ERR(( "callback for in_eIntType %lu is not supported!", in_eIntType )); |
|---|
| 815 | errCode = BERR_TRACE( BERR_INVALID_PARAMETER ); |
|---|
| 816 | |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | /*BDBG_MSG((", final ulVal = 0x%x\n ", ulVal)); */ |
|---|
| 821 | |
|---|
| 822 | BHSM_P_DONE_LABEL: |
|---|
| 823 | |
|---|
| 824 | BDBG_LEAVE(BHSM_Channel_EnableIntrCallback); |
|---|
| 825 | return( errCode ); |
|---|
| 826 | |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | #ifdef BHSM_AUTO_TEST |
|---|
| 832 | |
|---|
| 833 | BERR_Code BHSM_SubmitRawCommand ( |
|---|
| 834 | BHSM_Handle in_handle, |
|---|
| 835 | BHSM_HwModule in_interface, |
|---|
| 836 | uint32_t in_unInputParamLenInWord, /* length in words, including header sections words*/ |
|---|
| 837 | uint32_t *inp_unInputParamsBuf, /* entire cmd, incluidng header section words*/ |
|---|
| 838 | uint32_t *outp_unOutputParamLenInWord, /* length in words, including header sections words*/ |
|---|
| 839 | uint32_t *outp_unOutputParamsBuf /* entire cmd, incluidng header section words*/ |
|---|
| 840 | ) |
|---|
| 841 | { |
|---|
| 842 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 843 | BHSM_P_CommandData_t commandData; |
|---|
| 844 | unsigned int i; |
|---|
| 845 | BHSM_ChannelHandle channelHandle = in_handle->channelHandles[in_interface]; |
|---|
| 846 | |
|---|
| 847 | BDBG_MSG(("Inside BHSM_SubmitRawCommand\n")); |
|---|
| 848 | |
|---|
| 849 | BKNI_Memset(&commandData, 0, sizeof( BHSM_P_CommandData_t )); |
|---|
| 850 | |
|---|
| 851 | commandData.unInputParamLen = in_unInputParamLenInWord*4; /* passed-in param in words*/ |
|---|
| 852 | |
|---|
| 853 | for (i=0; i<commandData.unInputParamLen/4; i++) { |
|---|
| 854 | commandData.unInputParamsBuf[i] = inp_unInputParamsBuf[i]; /* including header section words*/ |
|---|
| 855 | } |
|---|
| 856 | |
|---|
| 857 | BHSM_P_CHECK_ERR_CODE_FUNC(errCode, |
|---|
| 858 | BHSM_P_CommonSubmitRawCommand(channelHandle, &commandData)); |
|---|
| 859 | |
|---|
| 860 | *outp_unOutputParamLenInWord = (commandData.unOutputParamLen+3)/4; /* to soapApp, translated in words*/ |
|---|
| 861 | |
|---|
| 862 | for(i = 0; i<(commandData.unOutputParamLen+3)/4; i++) { |
|---|
| 863 | outp_unOutputParamsBuf[i] = commandData.unOutputParamsBuf[i]; |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | BHSM_P_DONE_LABEL: |
|---|
| 867 | BDBG_MSG(("Exit BHSM_SubmitRawCommand\n")); |
|---|
| 868 | return errCode; |
|---|
| 869 | |
|---|
| 870 | } |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | #endif |
|---|
| 874 | |
|---|
| 875 | uint32_t BHSM_P_HDMIEnumToSerializerAddress ( |
|---|
| 876 | uint32_t portEnum |
|---|
| 877 | ) |
|---|
| 878 | { |
|---|
| 879 | |
|---|
| 880 | return (portEnum); |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | |
|---|