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