1*0aeed3e9SJustin Hibbits /****************************************************************************** 2*0aeed3e9SJustin Hibbits 3*0aeed3e9SJustin Hibbits � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc. 4*0aeed3e9SJustin Hibbits All rights reserved. 5*0aeed3e9SJustin Hibbits 6*0aeed3e9SJustin Hibbits This is proprietary source code of Freescale Semiconductor Inc., 7*0aeed3e9SJustin Hibbits and its use is subject to the NetComm Device Drivers EULA. 8*0aeed3e9SJustin Hibbits The copyright notice above does not evidence any actual or intended 9*0aeed3e9SJustin Hibbits publication of such source code. 10*0aeed3e9SJustin Hibbits 11*0aeed3e9SJustin Hibbits ALTERNATIVELY, redistribution and use in source and binary forms, with 12*0aeed3e9SJustin Hibbits or without modification, are permitted provided that the following 13*0aeed3e9SJustin Hibbits conditions are met: 14*0aeed3e9SJustin Hibbits * Redistributions of source code must retain the above copyright 15*0aeed3e9SJustin Hibbits notice, this list of conditions and the following disclaimer. 16*0aeed3e9SJustin Hibbits * Redistributions in binary form must reproduce the above copyright 17*0aeed3e9SJustin Hibbits notice, this list of conditions and the following disclaimer in the 18*0aeed3e9SJustin Hibbits documentation and/or other materials provided with the distribution. 19*0aeed3e9SJustin Hibbits * Neither the name of Freescale Semiconductor nor the 20*0aeed3e9SJustin Hibbits names of its contributors may be used to endorse or promote products 21*0aeed3e9SJustin Hibbits derived from this software without specific prior written permission. 22*0aeed3e9SJustin Hibbits 23*0aeed3e9SJustin Hibbits THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 24*0aeed3e9SJustin Hibbits EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25*0aeed3e9SJustin Hibbits WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26*0aeed3e9SJustin Hibbits DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 27*0aeed3e9SJustin Hibbits DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28*0aeed3e9SJustin Hibbits (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29*0aeed3e9SJustin Hibbits LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30*0aeed3e9SJustin Hibbits ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31*0aeed3e9SJustin Hibbits (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32*0aeed3e9SJustin Hibbits SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33*0aeed3e9SJustin Hibbits * 34*0aeed3e9SJustin Hibbits 35*0aeed3e9SJustin Hibbits 36*0aeed3e9SJustin Hibbits **************************************************************************/ 37*0aeed3e9SJustin Hibbits /****************************************************************************** 38*0aeed3e9SJustin Hibbits @File bm.c 39*0aeed3e9SJustin Hibbits 40*0aeed3e9SJustin Hibbits @Description BM 41*0aeed3e9SJustin Hibbits *//***************************************************************************/ 42*0aeed3e9SJustin Hibbits #include "error_ext.h" 43*0aeed3e9SJustin Hibbits #include "std_ext.h" 44*0aeed3e9SJustin Hibbits #include "string_ext.h" 45*0aeed3e9SJustin Hibbits #include "sprint_ext.h" 46*0aeed3e9SJustin Hibbits #include "debug_ext.h" 47*0aeed3e9SJustin Hibbits #include "mm_ext.h" 48*0aeed3e9SJustin Hibbits 49*0aeed3e9SJustin Hibbits #include "bm.h" 50*0aeed3e9SJustin Hibbits 51*0aeed3e9SJustin Hibbits 52*0aeed3e9SJustin Hibbits t_Error BM_ConfigException(t_Handle h_Bm, e_BmExceptions exception, bool enable); 53*0aeed3e9SJustin Hibbits 54*0aeed3e9SJustin Hibbits 55*0aeed3e9SJustin Hibbits /****************************************/ 56*0aeed3e9SJustin Hibbits /* static functions */ 57*0aeed3e9SJustin Hibbits /****************************************/ 58*0aeed3e9SJustin Hibbits 59*0aeed3e9SJustin Hibbits static volatile bool blockingFlag = FALSE; 60*0aeed3e9SJustin Hibbits static void BmIpcMsgCompletionCB(t_Handle h_Module, 61*0aeed3e9SJustin Hibbits uint8_t *p_Msg, 62*0aeed3e9SJustin Hibbits uint8_t *p_Reply, 63*0aeed3e9SJustin Hibbits uint32_t replyLength, 64*0aeed3e9SJustin Hibbits t_Error status) 65*0aeed3e9SJustin Hibbits { 66*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN(h_Module, E_INVALID_HANDLE); 67*0aeed3e9SJustin Hibbits 68*0aeed3e9SJustin Hibbits #ifdef DISABLE_SANITY_CHECKS 69*0aeed3e9SJustin Hibbits UNUSED(h_Module); 70*0aeed3e9SJustin Hibbits #endif /* DISABLE_SANITY_CHECKS */ 71*0aeed3e9SJustin Hibbits UNUSED(p_Msg);UNUSED(p_Reply);UNUSED(replyLength);UNUSED(status); 72*0aeed3e9SJustin Hibbits 73*0aeed3e9SJustin Hibbits blockingFlag = FALSE; 74*0aeed3e9SJustin Hibbits } 75*0aeed3e9SJustin Hibbits 76*0aeed3e9SJustin Hibbits static t_Error BmHandleIpcMsgCB(t_Handle h_Bm, 77*0aeed3e9SJustin Hibbits uint8_t *p_Msg, 78*0aeed3e9SJustin Hibbits uint32_t msgLength, 79*0aeed3e9SJustin Hibbits uint8_t *p_Reply, 80*0aeed3e9SJustin Hibbits uint32_t *p_ReplyLength) 81*0aeed3e9SJustin Hibbits { 82*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 83*0aeed3e9SJustin Hibbits t_BmIpcMsg *p_IpcMsg = (t_BmIpcMsg*)p_Msg; 84*0aeed3e9SJustin Hibbits t_BmIpcReply *p_IpcReply = (t_BmIpcReply *)p_Reply; 85*0aeed3e9SJustin Hibbits 86*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 87*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR((msgLength >= sizeof(uint32_t)), E_INVALID_VALUE); 88*0aeed3e9SJustin Hibbits 89*0aeed3e9SJustin Hibbits #ifdef DISABLE_SANITY_CHECKS 90*0aeed3e9SJustin Hibbits UNUSED(msgLength); 91*0aeed3e9SJustin Hibbits #endif /* DISABLE_SANITY_CHECKS */ 92*0aeed3e9SJustin Hibbits 93*0aeed3e9SJustin Hibbits ASSERT_COND(p_IpcMsg); 94*0aeed3e9SJustin Hibbits 95*0aeed3e9SJustin Hibbits memset(p_IpcReply, 0, (sizeof(uint8_t) * BM_IPC_MAX_REPLY_SIZE)); 96*0aeed3e9SJustin Hibbits *p_ReplyLength = 0; 97*0aeed3e9SJustin Hibbits 98*0aeed3e9SJustin Hibbits switch(p_IpcMsg->msgId) 99*0aeed3e9SJustin Hibbits { 100*0aeed3e9SJustin Hibbits case (BM_MASTER_IS_ALIVE): 101*0aeed3e9SJustin Hibbits *(uint8_t*)p_IpcReply->replyBody = 1; 102*0aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(uint8_t); 103*0aeed3e9SJustin Hibbits break; 104*0aeed3e9SJustin Hibbits case (BM_SET_POOL_THRESH): 105*0aeed3e9SJustin Hibbits { 106*0aeed3e9SJustin Hibbits t_Error err; 107*0aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh; 108*0aeed3e9SJustin Hibbits 109*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcPoolThresh, p_IpcMsg->msgBody, sizeof(t_BmIpcPoolThreshParams)); 110*0aeed3e9SJustin Hibbits if ((err = BmSetPoolThresholds(p_Bm, 111*0aeed3e9SJustin Hibbits ipcPoolThresh.bpid, 112*0aeed3e9SJustin Hibbits ipcPoolThresh.thresholds)) != E_OK) 113*0aeed3e9SJustin Hibbits REPORT_ERROR(MINOR, err, NO_MSG); 114*0aeed3e9SJustin Hibbits break; 115*0aeed3e9SJustin Hibbits } 116*0aeed3e9SJustin Hibbits case (BM_UNSET_POOL_THRESH): 117*0aeed3e9SJustin Hibbits { 118*0aeed3e9SJustin Hibbits t_Error err; 119*0aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh; 120*0aeed3e9SJustin Hibbits 121*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcPoolThresh, p_IpcMsg->msgBody, sizeof(t_BmIpcPoolThreshParams)); 122*0aeed3e9SJustin Hibbits if ((err = BmUnSetPoolThresholds(p_Bm, 123*0aeed3e9SJustin Hibbits ipcPoolThresh.bpid)) != E_OK) 124*0aeed3e9SJustin Hibbits REPORT_ERROR(MINOR, err, NO_MSG); 125*0aeed3e9SJustin Hibbits break; 126*0aeed3e9SJustin Hibbits } 127*0aeed3e9SJustin Hibbits case (BM_GET_COUNTER): 128*0aeed3e9SJustin Hibbits { 129*0aeed3e9SJustin Hibbits t_BmIpcGetCounter ipcCounter; 130*0aeed3e9SJustin Hibbits uint32_t count; 131*0aeed3e9SJustin Hibbits 132*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcCounter, p_IpcMsg->msgBody, sizeof(t_BmIpcGetCounter)); 133*0aeed3e9SJustin Hibbits count = BmGetCounter(p_Bm, 134*0aeed3e9SJustin Hibbits (e_BmInterModuleCounters)ipcCounter.enumId, 135*0aeed3e9SJustin Hibbits ipcCounter.bpid); 136*0aeed3e9SJustin Hibbits memcpy(p_IpcReply->replyBody, (uint8_t*)&count, sizeof(uint32_t)); 137*0aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t); 138*0aeed3e9SJustin Hibbits break; 139*0aeed3e9SJustin Hibbits } 140*0aeed3e9SJustin Hibbits case (BM_GET_REVISION): 141*0aeed3e9SJustin Hibbits { 142*0aeed3e9SJustin Hibbits t_BmRevisionInfo revInfo; 143*0aeed3e9SJustin Hibbits t_BmIpcRevisionInfo ipcRevInfo; 144*0aeed3e9SJustin Hibbits 145*0aeed3e9SJustin Hibbits p_IpcReply->error = (uint32_t)BmGetRevision(h_Bm, &revInfo); 146*0aeed3e9SJustin Hibbits ipcRevInfo.majorRev = revInfo.majorRev; 147*0aeed3e9SJustin Hibbits ipcRevInfo.minorRev = revInfo.minorRev; 148*0aeed3e9SJustin Hibbits memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcRevInfo, sizeof(t_BmIpcRevisionInfo)); 149*0aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(t_BmIpcRevisionInfo); 150*0aeed3e9SJustin Hibbits break; 151*0aeed3e9SJustin Hibbits } 152*0aeed3e9SJustin Hibbits case (BM_FORCE_BPID): 153*0aeed3e9SJustin Hibbits { 154*0aeed3e9SJustin Hibbits t_BmIpcBpidParams ipcBpid; 155*0aeed3e9SJustin Hibbits uint32_t tmp; 156*0aeed3e9SJustin Hibbits 157*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcBpid, p_IpcMsg->msgBody, sizeof(t_BmIpcBpidParams)); 158*0aeed3e9SJustin Hibbits tmp = BmBpidGet(p_Bm, TRUE, ipcBpid.bpid); 159*0aeed3e9SJustin Hibbits memcpy(p_IpcReply->replyBody, (uint8_t*)&tmp, sizeof(uint32_t)); 160*0aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t); 161*0aeed3e9SJustin Hibbits break; 162*0aeed3e9SJustin Hibbits } 163*0aeed3e9SJustin Hibbits case (BM_PUT_BPID): 164*0aeed3e9SJustin Hibbits { 165*0aeed3e9SJustin Hibbits t_Error err; 166*0aeed3e9SJustin Hibbits t_BmIpcBpidParams ipcBpid; 167*0aeed3e9SJustin Hibbits 168*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcBpid, p_IpcMsg->msgBody, sizeof(t_BmIpcBpidParams)); 169*0aeed3e9SJustin Hibbits if ((err = BmBpidPut(p_Bm, ipcBpid.bpid)) != E_OK) 170*0aeed3e9SJustin Hibbits REPORT_ERROR(MINOR, err, NO_MSG); 171*0aeed3e9SJustin Hibbits break; 172*0aeed3e9SJustin Hibbits } 173*0aeed3e9SJustin Hibbits default: 174*0aeed3e9SJustin Hibbits *p_ReplyLength = 0; 175*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_SELECTION, ("command not found!!!")); 176*0aeed3e9SJustin Hibbits } 177*0aeed3e9SJustin Hibbits 178*0aeed3e9SJustin Hibbits return E_OK; 179*0aeed3e9SJustin Hibbits } 180*0aeed3e9SJustin Hibbits 181*0aeed3e9SJustin Hibbits static t_Error CheckBmParameters(t_Bm *p_Bm) 182*0aeed3e9SJustin Hibbits { 183*0aeed3e9SJustin Hibbits if ((p_Bm->p_BmDriverParams->partBpidBase + p_Bm->p_BmDriverParams->partNumOfPools) > BM_MAX_NUM_OF_POOLS) 184*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("partBpidBase+partNumOfPools out of range!!!")); 185*0aeed3e9SJustin Hibbits 186*0aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID) 187*0aeed3e9SJustin Hibbits { 188*0aeed3e9SJustin Hibbits if (!p_Bm->p_BmDriverParams->totalNumOfBuffers) 189*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("totalNumOfBuffers must be larger than '0'!!!")); 190*0aeed3e9SJustin Hibbits if (p_Bm->p_BmDriverParams->totalNumOfBuffers > (128*MEGABYTE)) 191*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("totalNumOfBuffers must be equal or smaller than 128M!!!")); 192*0aeed3e9SJustin Hibbits if(!p_Bm->f_Exception) 193*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exceptions callback not provided")); 194*0aeed3e9SJustin Hibbits } 195*0aeed3e9SJustin Hibbits 196*0aeed3e9SJustin Hibbits return E_OK; 197*0aeed3e9SJustin Hibbits } 198*0aeed3e9SJustin Hibbits 199*0aeed3e9SJustin Hibbits static __inline__ uint32_t GenerateThresh(uint32_t val, int roundup) 200*0aeed3e9SJustin Hibbits { 201*0aeed3e9SJustin Hibbits uint32_t e = 0; /* co-efficient, exponent */ 202*0aeed3e9SJustin Hibbits uint32_t oddbit = 0; 203*0aeed3e9SJustin Hibbits while(val > 0xff) { 204*0aeed3e9SJustin Hibbits oddbit = val & 1; 205*0aeed3e9SJustin Hibbits val >>= 1; 206*0aeed3e9SJustin Hibbits e++; 207*0aeed3e9SJustin Hibbits if(roundup && oddbit) 208*0aeed3e9SJustin Hibbits val++; 209*0aeed3e9SJustin Hibbits } 210*0aeed3e9SJustin Hibbits return (val | (e << 8)); 211*0aeed3e9SJustin Hibbits } 212*0aeed3e9SJustin Hibbits 213*0aeed3e9SJustin Hibbits static t_Error BmSetPool(t_Handle h_Bm, 214*0aeed3e9SJustin Hibbits uint8_t bpid, 215*0aeed3e9SJustin Hibbits uint32_t swdet, 216*0aeed3e9SJustin Hibbits uint32_t swdxt, 217*0aeed3e9SJustin Hibbits uint32_t hwdet, 218*0aeed3e9SJustin Hibbits uint32_t hwdxt) 219*0aeed3e9SJustin Hibbits { 220*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 221*0aeed3e9SJustin Hibbits 222*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 223*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE); 224*0aeed3e9SJustin Hibbits 225*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->swdet[bpid], GenerateThresh(swdet, 0)); 226*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->swdxt[bpid], GenerateThresh(swdxt, 1)); 227*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->hwdet[bpid], GenerateThresh(hwdet, 0)); 228*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->hwdxt[bpid], GenerateThresh(hwdxt, 1)); 229*0aeed3e9SJustin Hibbits 230*0aeed3e9SJustin Hibbits return E_OK; 231*0aeed3e9SJustin Hibbits } 232*0aeed3e9SJustin Hibbits 233*0aeed3e9SJustin Hibbits /****************************************/ 234*0aeed3e9SJustin Hibbits /* Inter-Module functions */ 235*0aeed3e9SJustin Hibbits /****************************************/ 236*0aeed3e9SJustin Hibbits 237*0aeed3e9SJustin Hibbits t_Error BmSetPoolThresholds(t_Handle h_Bm, uint8_t bpid, const uint32_t *thresholds) 238*0aeed3e9SJustin Hibbits { 239*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 240*0aeed3e9SJustin Hibbits 241*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 242*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE); 243*0aeed3e9SJustin Hibbits 244*0aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID) 245*0aeed3e9SJustin Hibbits { 246*0aeed3e9SJustin Hibbits return BmSetPool(h_Bm, 247*0aeed3e9SJustin Hibbits bpid, 248*0aeed3e9SJustin Hibbits thresholds[0], 249*0aeed3e9SJustin Hibbits thresholds[1], 250*0aeed3e9SJustin Hibbits thresholds[2], 251*0aeed3e9SJustin Hibbits thresholds[3]); 252*0aeed3e9SJustin Hibbits } 253*0aeed3e9SJustin Hibbits else if (p_Bm->h_Session) 254*0aeed3e9SJustin Hibbits { 255*0aeed3e9SJustin Hibbits t_BmIpcMsg msg; 256*0aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh; 257*0aeed3e9SJustin Hibbits t_Error errCode = E_OK; 258*0aeed3e9SJustin Hibbits 259*0aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg)); 260*0aeed3e9SJustin Hibbits ipcPoolThresh.bpid = bpid; 261*0aeed3e9SJustin Hibbits memcpy(ipcPoolThresh.thresholds, thresholds, sizeof(uintptr_t) * MAX_DEPLETION_THRESHOLDS); 262*0aeed3e9SJustin Hibbits msg.msgId = BM_SET_POOL_THRESH; 263*0aeed3e9SJustin Hibbits memcpy(msg.msgBody, &ipcPoolThresh, sizeof(t_BmIpcPoolThreshParams)); 264*0aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session, 265*0aeed3e9SJustin Hibbits (uint8_t*)&msg, 266*0aeed3e9SJustin Hibbits sizeof(msg.msgId) + sizeof(t_BmIpcPoolThreshParams), 267*0aeed3e9SJustin Hibbits NULL, 268*0aeed3e9SJustin Hibbits NULL, 269*0aeed3e9SJustin Hibbits NULL, 270*0aeed3e9SJustin Hibbits NULL)) != E_OK) 271*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, errCode, NO_MSG); 272*0aeed3e9SJustin Hibbits return E_OK; 273*0aeed3e9SJustin Hibbits } 274*0aeed3e9SJustin Hibbits else 275*0aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_NOT_SUPPORTED, ("IPC")); 276*0aeed3e9SJustin Hibbits } 277*0aeed3e9SJustin Hibbits 278*0aeed3e9SJustin Hibbits t_Error BmUnSetPoolThresholds(t_Handle h_Bm, uint8_t bpid) 279*0aeed3e9SJustin Hibbits { 280*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 281*0aeed3e9SJustin Hibbits 282*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 283*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE); 284*0aeed3e9SJustin Hibbits 285*0aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID) 286*0aeed3e9SJustin Hibbits { 287*0aeed3e9SJustin Hibbits return BmSetPool(h_Bm, 288*0aeed3e9SJustin Hibbits bpid, 289*0aeed3e9SJustin Hibbits 0, 290*0aeed3e9SJustin Hibbits 0, 291*0aeed3e9SJustin Hibbits 0, 292*0aeed3e9SJustin Hibbits 0); 293*0aeed3e9SJustin Hibbits } 294*0aeed3e9SJustin Hibbits else if (p_Bm->h_Session) 295*0aeed3e9SJustin Hibbits { 296*0aeed3e9SJustin Hibbits t_BmIpcMsg msg; 297*0aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh; 298*0aeed3e9SJustin Hibbits t_Error errCode = E_OK; 299*0aeed3e9SJustin Hibbits 300*0aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg)); 301*0aeed3e9SJustin Hibbits memset(&ipcPoolThresh, 0, sizeof(t_BmIpcPoolThreshParams)); 302*0aeed3e9SJustin Hibbits ipcPoolThresh.bpid = bpid; 303*0aeed3e9SJustin Hibbits msg.msgId = BM_UNSET_POOL_THRESH; 304*0aeed3e9SJustin Hibbits memcpy(msg.msgBody, &ipcPoolThresh, sizeof(t_BmIpcPoolThreshParams)); 305*0aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session, 306*0aeed3e9SJustin Hibbits (uint8_t*)&msg, 307*0aeed3e9SJustin Hibbits sizeof(msg.msgId) + sizeof(t_BmIpcPoolThreshParams), 308*0aeed3e9SJustin Hibbits NULL, 309*0aeed3e9SJustin Hibbits NULL, 310*0aeed3e9SJustin Hibbits NULL, 311*0aeed3e9SJustin Hibbits NULL)) != E_OK) 312*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, errCode, NO_MSG); 313*0aeed3e9SJustin Hibbits return E_OK; 314*0aeed3e9SJustin Hibbits } 315*0aeed3e9SJustin Hibbits else 316*0aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_NOT_SUPPORTED, ("IPC")); 317*0aeed3e9SJustin Hibbits } 318*0aeed3e9SJustin Hibbits 319*0aeed3e9SJustin Hibbits uint32_t BmGetCounter(t_Handle h_Bm, e_BmInterModuleCounters counter, uint8_t bpid) 320*0aeed3e9SJustin Hibbits { 321*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 322*0aeed3e9SJustin Hibbits 323*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Bm, E_INVALID_HANDLE, 0); 324*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE, 0); 325*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE((((p_Bm->guestId == NCSW_MASTER_ID) && p_Bm->p_BmRegs) || 326*0aeed3e9SJustin Hibbits (p_Bm->guestId != NCSW_MASTER_ID)), E_INVALID_STATE, 0); 327*0aeed3e9SJustin Hibbits 328*0aeed3e9SJustin Hibbits if ((p_Bm->guestId == NCSW_MASTER_ID) || 329*0aeed3e9SJustin Hibbits (!p_Bm->h_Session && p_Bm->p_BmRegs)) 330*0aeed3e9SJustin Hibbits { 331*0aeed3e9SJustin Hibbits switch(counter) 332*0aeed3e9SJustin Hibbits { 333*0aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_POOL_CONTENT): 334*0aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->content[bpid]); 335*0aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_POOL_SW_DEPLETION): 336*0aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->sdcnt[bpid]); 337*0aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_POOL_HW_DEPLETION): 338*0aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->hdcnt[bpid]); 339*0aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_FBPR): 340*0aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->fbpr_fpc); 341*0aeed3e9SJustin Hibbits default: 342*0aeed3e9SJustin Hibbits break; 343*0aeed3e9SJustin Hibbits } 344*0aeed3e9SJustin Hibbits /* should never get here */ 345*0aeed3e9SJustin Hibbits ASSERT_COND(FALSE); 346*0aeed3e9SJustin Hibbits } 347*0aeed3e9SJustin Hibbits else if (p_Bm->h_Session) 348*0aeed3e9SJustin Hibbits { 349*0aeed3e9SJustin Hibbits t_BmIpcMsg msg; 350*0aeed3e9SJustin Hibbits t_BmIpcReply reply; 351*0aeed3e9SJustin Hibbits t_BmIpcGetCounter ipcCounter; 352*0aeed3e9SJustin Hibbits uint32_t replyLength; 353*0aeed3e9SJustin Hibbits uint32_t count; 354*0aeed3e9SJustin Hibbits t_Error errCode = E_OK; 355*0aeed3e9SJustin Hibbits 356*0aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg)); 357*0aeed3e9SJustin Hibbits memset(&reply, 0, sizeof(t_BmIpcReply)); 358*0aeed3e9SJustin Hibbits ipcCounter.bpid = bpid; 359*0aeed3e9SJustin Hibbits ipcCounter.enumId = (uint32_t)counter; 360*0aeed3e9SJustin Hibbits msg.msgId = BM_GET_COUNTER; 361*0aeed3e9SJustin Hibbits memcpy(msg.msgBody, &ipcCounter, sizeof(t_BmIpcGetCounter)); 362*0aeed3e9SJustin Hibbits replyLength = sizeof(uint32_t) + sizeof(uint32_t); 363*0aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session, 364*0aeed3e9SJustin Hibbits (uint8_t*)&msg, 365*0aeed3e9SJustin Hibbits sizeof(msg.msgId) + sizeof(t_BmIpcGetCounter), 366*0aeed3e9SJustin Hibbits (uint8_t*)&reply, 367*0aeed3e9SJustin Hibbits &replyLength, 368*0aeed3e9SJustin Hibbits NULL, 369*0aeed3e9SJustin Hibbits NULL)) != E_OK) 370*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, errCode, NO_MSG); 371*0aeed3e9SJustin Hibbits if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t))) 372*0aeed3e9SJustin Hibbits { 373*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch")); 374*0aeed3e9SJustin Hibbits errCode = E_INVALID_VALUE; 375*0aeed3e9SJustin Hibbits } 376*0aeed3e9SJustin Hibbits if (errCode == E_OK) 377*0aeed3e9SJustin Hibbits { 378*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&count, reply.replyBody, sizeof(uint32_t)); 379*0aeed3e9SJustin Hibbits return count; 380*0aeed3e9SJustin Hibbits } 381*0aeed3e9SJustin Hibbits } 382*0aeed3e9SJustin Hibbits else 383*0aeed3e9SJustin Hibbits REPORT_ERROR(WARNING, E_NOT_SUPPORTED, 384*0aeed3e9SJustin Hibbits ("In 'guest', either IPC or 'baseAddress' is required!")); 385*0aeed3e9SJustin Hibbits 386*0aeed3e9SJustin Hibbits return 0; 387*0aeed3e9SJustin Hibbits } 388*0aeed3e9SJustin Hibbits 389*0aeed3e9SJustin Hibbits t_Error BmGetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo) 390*0aeed3e9SJustin Hibbits { 391*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 392*0aeed3e9SJustin Hibbits uint32_t tmpReg; 393*0aeed3e9SJustin Hibbits 394*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 395*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmRevisionInfo, E_NULL_POINTER); 396*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR((((p_Bm->guestId == NCSW_MASTER_ID) && p_Bm->p_BmRegs) || 397*0aeed3e9SJustin Hibbits (p_Bm->guestId != NCSW_MASTER_ID)), E_INVALID_STATE); 398*0aeed3e9SJustin Hibbits 399*0aeed3e9SJustin Hibbits if ((p_Bm->guestId == NCSW_MASTER_ID) || 400*0aeed3e9SJustin Hibbits (!p_Bm->h_Session && p_Bm->p_BmRegs)) 401*0aeed3e9SJustin Hibbits { 402*0aeed3e9SJustin Hibbits /* read revision register 1 */ 403*0aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_Bm->p_BmRegs->ip_rev_1); 404*0aeed3e9SJustin Hibbits p_BmRevisionInfo->majorRev = (uint8_t)((tmpReg & REV1_MAJOR_MASK) >> REV1_MAJOR_SHIFT); 405*0aeed3e9SJustin Hibbits p_BmRevisionInfo->minorRev = (uint8_t)((tmpReg & REV1_MINOR_MASK) >> REV1_MINOR_SHIFT); 406*0aeed3e9SJustin Hibbits } 407*0aeed3e9SJustin Hibbits else if (p_Bm->h_Session) 408*0aeed3e9SJustin Hibbits { 409*0aeed3e9SJustin Hibbits t_BmIpcMsg msg; 410*0aeed3e9SJustin Hibbits t_BmIpcReply reply; 411*0aeed3e9SJustin Hibbits t_BmIpcRevisionInfo ipcRevInfo; 412*0aeed3e9SJustin Hibbits uint32_t replyLength; 413*0aeed3e9SJustin Hibbits t_Error errCode = E_OK; 414*0aeed3e9SJustin Hibbits 415*0aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg)); 416*0aeed3e9SJustin Hibbits memset(&reply, 0, sizeof(t_BmIpcReply)); 417*0aeed3e9SJustin Hibbits msg.msgId = BM_GET_REVISION; 418*0aeed3e9SJustin Hibbits replyLength = sizeof(uint32_t) + sizeof(t_BmIpcRevisionInfo); 419*0aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session, 420*0aeed3e9SJustin Hibbits (uint8_t*)&msg, 421*0aeed3e9SJustin Hibbits sizeof(msg.msgId), 422*0aeed3e9SJustin Hibbits (uint8_t*)&reply, 423*0aeed3e9SJustin Hibbits &replyLength, 424*0aeed3e9SJustin Hibbits NULL, 425*0aeed3e9SJustin Hibbits NULL)) != E_OK) 426*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, errCode, NO_MSG); 427*0aeed3e9SJustin Hibbits if (replyLength != (sizeof(uint32_t) + sizeof(t_BmIpcRevisionInfo))) 428*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch")); 429*0aeed3e9SJustin Hibbits 430*0aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcRevInfo, reply.replyBody, sizeof(t_BmIpcRevisionInfo)); 431*0aeed3e9SJustin Hibbits p_BmRevisionInfo->majorRev = ipcRevInfo.majorRev; 432*0aeed3e9SJustin Hibbits p_BmRevisionInfo->minorRev = ipcRevInfo.minorRev; 433*0aeed3e9SJustin Hibbits return (t_Error)(reply.error); 434*0aeed3e9SJustin Hibbits } 435*0aeed3e9SJustin Hibbits else 436*0aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_NOT_SUPPORTED, 437*0aeed3e9SJustin Hibbits ("In 'guest', either IPC or 'baseAddress' is required!")); 438*0aeed3e9SJustin Hibbits 439*0aeed3e9SJustin Hibbits return E_OK; 440*0aeed3e9SJustin Hibbits } 441*0aeed3e9SJustin Hibbits 442*0aeed3e9SJustin Hibbits static void FreeInitResources(t_Bm *p_Bm) 443*0aeed3e9SJustin Hibbits { 444*0aeed3e9SJustin Hibbits if (p_Bm->p_FbprBase) 445*0aeed3e9SJustin Hibbits XX_FreeSmart(p_Bm->p_FbprBase); 446*0aeed3e9SJustin Hibbits if (p_Bm->h_Session) 447*0aeed3e9SJustin Hibbits XX_IpcFreeSession(p_Bm->h_Session); 448*0aeed3e9SJustin Hibbits if (p_Bm->h_BpidMm) 449*0aeed3e9SJustin Hibbits MM_Free(p_Bm->h_BpidMm); 450*0aeed3e9SJustin Hibbits } 451*0aeed3e9SJustin Hibbits 452*0aeed3e9SJustin Hibbits /****************************************/ 453*0aeed3e9SJustin Hibbits /* API Init unit functions */ 454*0aeed3e9SJustin Hibbits /****************************************/ 455*0aeed3e9SJustin Hibbits 456*0aeed3e9SJustin Hibbits t_Handle BM_Config(t_BmParam *p_BmParam) 457*0aeed3e9SJustin Hibbits { 458*0aeed3e9SJustin Hibbits t_Bm *p_Bm; 459*0aeed3e9SJustin Hibbits 460*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmParam, E_INVALID_HANDLE, NULL); 461*0aeed3e9SJustin Hibbits 462*0aeed3e9SJustin Hibbits p_Bm = (t_Bm *)XX_Malloc(sizeof(t_Bm)); 463*0aeed3e9SJustin Hibbits if (!p_Bm) 464*0aeed3e9SJustin Hibbits { 465*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("BM obj!!!")); 466*0aeed3e9SJustin Hibbits return NULL; 467*0aeed3e9SJustin Hibbits } 468*0aeed3e9SJustin Hibbits memset(p_Bm, 0, sizeof(t_Bm)); 469*0aeed3e9SJustin Hibbits 470*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams = (t_BmDriverParams *)XX_Malloc(sizeof(t_BmDriverParams)); 471*0aeed3e9SJustin Hibbits if (!p_Bm->p_BmDriverParams) 472*0aeed3e9SJustin Hibbits { 473*0aeed3e9SJustin Hibbits XX_Free(p_Bm); 474*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Bm driver parameters")); 475*0aeed3e9SJustin Hibbits return NULL; 476*0aeed3e9SJustin Hibbits } 477*0aeed3e9SJustin Hibbits memset(p_Bm->p_BmDriverParams, 0, sizeof(t_BmDriverParams)); 478*0aeed3e9SJustin Hibbits 479*0aeed3e9SJustin Hibbits p_Bm->guestId = p_BmParam->guestId; 480*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->partNumOfPools = p_BmParam->partNumOfPools; 481*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->partBpidBase = p_BmParam->partBpidBase; 482*0aeed3e9SJustin Hibbits p_Bm->p_BmRegs = (t_BmRegs *)UINT_TO_PTR(p_BmParam->baseAddress); 483*0aeed3e9SJustin Hibbits 484*0aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID) 485*0aeed3e9SJustin Hibbits { 486*0aeed3e9SJustin Hibbits p_Bm->exceptions = DEFAULT_exceptions; 487*0aeed3e9SJustin Hibbits p_Bm->f_Exception = p_BmParam->f_Exception; 488*0aeed3e9SJustin Hibbits p_Bm->h_App = p_BmParam->h_App; 489*0aeed3e9SJustin Hibbits p_Bm->errIrq = p_BmParam->errIrq; 490*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->totalNumOfBuffers = p_BmParam->totalNumOfBuffers; 491*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->fbprMemPartitionId = p_BmParam->fbprMemPartitionId; 492*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->fbprThreshold = DEFAULT_fbprThreshold; 493*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->liodn = p_BmParam->liodn; 494*0aeed3e9SJustin Hibbits 495*0aeed3e9SJustin Hibbits } 496*0aeed3e9SJustin Hibbits /* build the BM partition IPC address */ 497*0aeed3e9SJustin Hibbits memset(p_Bm->moduleName, 0, MODULE_NAME_SIZE); 498*0aeed3e9SJustin Hibbits if(Sprint (p_Bm->moduleName, "BM_0_%d",p_Bm->guestId) != (p_Bm->guestId<10 ? 6:7)) 499*0aeed3e9SJustin Hibbits { 500*0aeed3e9SJustin Hibbits XX_Free(p_Bm->p_BmDriverParams); 501*0aeed3e9SJustin Hibbits XX_Free(p_Bm); 502*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed")); 503*0aeed3e9SJustin Hibbits return NULL; 504*0aeed3e9SJustin Hibbits } 505*0aeed3e9SJustin Hibbits return p_Bm; 506*0aeed3e9SJustin Hibbits } 507*0aeed3e9SJustin Hibbits 508*0aeed3e9SJustin Hibbits t_Error BM_Init(t_Handle h_Bm) 509*0aeed3e9SJustin Hibbits { 510*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm; 511*0aeed3e9SJustin Hibbits t_Error err; 512*0aeed3e9SJustin Hibbits 513*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 514*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm->p_BmDriverParams, E_INVALID_HANDLE); 515*0aeed3e9SJustin Hibbits 516*0aeed3e9SJustin Hibbits CHECK_INIT_PARAMETERS(p_Bm, CheckBmParameters); 517*0aeed3e9SJustin Hibbits 518*0aeed3e9SJustin Hibbits if (p_Bm->p_BmDriverParams->partNumOfPools) 519*0aeed3e9SJustin Hibbits if (MM_Init(&p_Bm->h_BpidMm, p_Bm->p_BmDriverParams->partBpidBase, p_Bm->p_BmDriverParams->partNumOfPools) != E_OK) 520*0aeed3e9SJustin Hibbits { 521*0aeed3e9SJustin Hibbits FreeInitResources(p_Bm); 522*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_HANDLE, ("BM-BPIDS-MEM partition!!!")); 523*0aeed3e9SJustin Hibbits } 524*0aeed3e9SJustin Hibbits 525*0aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID) 526*0aeed3e9SJustin Hibbits { 527*0aeed3e9SJustin Hibbits uint64_t phyAddr; 528*0aeed3e9SJustin Hibbits t_BmRevisionInfo revInfo; 529*0aeed3e9SJustin Hibbits uint32_t dsSize, exp; 530*0aeed3e9SJustin Hibbits 531*0aeed3e9SJustin Hibbits BmGetRevision(p_Bm, &revInfo); 532*0aeed3e9SJustin Hibbits DBG(TRACE, ("Bman ver:%02x,%02x", revInfo.majorRev, revInfo.minorRev)); 533*0aeed3e9SJustin Hibbits 534*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->liodnr, (uint16_t)p_Bm->p_BmDriverParams->liodn); 535*0aeed3e9SJustin Hibbits 536*0aeed3e9SJustin Hibbits /* FBPR memory */ 537*0aeed3e9SJustin Hibbits dsSize = (uint32_t)(p_Bm->p_BmDriverParams->totalNumOfBuffers * (FBPR_ENTRY_SIZE / 8)); 538*0aeed3e9SJustin Hibbits LOG2(dsSize, exp); 539*0aeed3e9SJustin Hibbits if (!POWER_OF_2(dsSize)) (exp++); 540*0aeed3e9SJustin Hibbits dsSize = (uint32_t)(1 << exp); 541*0aeed3e9SJustin Hibbits if (dsSize < (4*KILOBYTE)) 542*0aeed3e9SJustin Hibbits { 543*0aeed3e9SJustin Hibbits dsSize = (4*KILOBYTE); 544*0aeed3e9SJustin Hibbits LOG2(dsSize, exp); 545*0aeed3e9SJustin Hibbits } 546*0aeed3e9SJustin Hibbits p_Bm->p_FbprBase = XX_MallocSmart(dsSize, (int)p_Bm->p_BmDriverParams->fbprMemPartitionId, dsSize); 547*0aeed3e9SJustin Hibbits if (!p_Bm->p_FbprBase) 548*0aeed3e9SJustin Hibbits { 549*0aeed3e9SJustin Hibbits FreeInitResources(p_Bm); 550*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FBPR obj!!!")); 551*0aeed3e9SJustin Hibbits } 552*0aeed3e9SJustin Hibbits phyAddr = XX_VirtToPhys(p_Bm->p_FbprBase); 553*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_bare, ((uint32_t)(phyAddr >> 32) & 0xffff)); 554*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_bar, (uint32_t)phyAddr); 555*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_ar, (exp - 1)); 556*0aeed3e9SJustin Hibbits 557*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_fp_lwit, p_Bm->p_BmDriverParams->fbprThreshold); 558*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_isr, p_Bm->exceptions); 559*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_ier, p_Bm->exceptions); 560*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_isdr, 0x0); 561*0aeed3e9SJustin Hibbits if (p_Bm->errIrq != NO_IRQ) 562*0aeed3e9SJustin Hibbits { 563*0aeed3e9SJustin Hibbits XX_SetIntr(p_Bm->errIrq, BM_ErrorIsr, p_Bm); 564*0aeed3e9SJustin Hibbits XX_EnableIntr(p_Bm->errIrq); 565*0aeed3e9SJustin Hibbits } 566*0aeed3e9SJustin Hibbits 567*0aeed3e9SJustin Hibbits if ((err = XX_IpcRegisterMsgHandler(p_Bm->moduleName, BmHandleIpcMsgCB, p_Bm, BM_IPC_MAX_REPLY_SIZE)) != E_OK) 568*0aeed3e9SJustin Hibbits { 569*0aeed3e9SJustin Hibbits FreeInitResources(p_Bm); 570*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, err, NO_MSG); 571*0aeed3e9SJustin Hibbits } 572*0aeed3e9SJustin Hibbits } 573*0aeed3e9SJustin Hibbits else /* guest mode */ 574*0aeed3e9SJustin Hibbits { 575*0aeed3e9SJustin Hibbits char masterModuleName[MODULE_NAME_SIZE]; 576*0aeed3e9SJustin Hibbits 577*0aeed3e9SJustin Hibbits memset(masterModuleName, 0, MODULE_NAME_SIZE); 578*0aeed3e9SJustin Hibbits if(Sprint (masterModuleName, "BM_0_%d", NCSW_MASTER_ID) != (NCSW_MASTER_ID<10 ? 6:7)) 579*0aeed3e9SJustin Hibbits { 580*0aeed3e9SJustin Hibbits FreeInitResources(p_Bm); 581*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed")); 582*0aeed3e9SJustin Hibbits } 583*0aeed3e9SJustin Hibbits 584*0aeed3e9SJustin Hibbits p_Bm->h_Session = XX_IpcInitSession(masterModuleName, p_Bm->moduleName); 585*0aeed3e9SJustin Hibbits if (p_Bm->h_Session) 586*0aeed3e9SJustin Hibbits { 587*0aeed3e9SJustin Hibbits t_BmIpcMsg msg; 588*0aeed3e9SJustin Hibbits uint8_t isMasterAlive = 0; 589*0aeed3e9SJustin Hibbits t_BmIpcReply reply; 590*0aeed3e9SJustin Hibbits uint32_t replyLength; 591*0aeed3e9SJustin Hibbits 592*0aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg)); 593*0aeed3e9SJustin Hibbits memset(&reply, 0, sizeof(t_BmIpcReply)); 594*0aeed3e9SJustin Hibbits msg.msgId = BM_MASTER_IS_ALIVE; 595*0aeed3e9SJustin Hibbits replyLength = sizeof(uint32_t) + sizeof(uint8_t); 596*0aeed3e9SJustin Hibbits do 597*0aeed3e9SJustin Hibbits { 598*0aeed3e9SJustin Hibbits blockingFlag = TRUE; 599*0aeed3e9SJustin Hibbits if ((err = XX_IpcSendMessage(p_Bm->h_Session, 600*0aeed3e9SJustin Hibbits (uint8_t*)&msg, 601*0aeed3e9SJustin Hibbits sizeof(msg.msgId), 602*0aeed3e9SJustin Hibbits (uint8_t*)&reply, 603*0aeed3e9SJustin Hibbits &replyLength, 604*0aeed3e9SJustin Hibbits BmIpcMsgCompletionCB, 605*0aeed3e9SJustin Hibbits p_Bm)) != E_OK) 606*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, err, NO_MSG); 607*0aeed3e9SJustin Hibbits while(blockingFlag) ; 608*0aeed3e9SJustin Hibbits if(replyLength != (sizeof(uint32_t) + sizeof(uint8_t))) 609*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch")); 610*0aeed3e9SJustin Hibbits isMasterAlive = *(uint8_t*)(reply.replyBody); 611*0aeed3e9SJustin Hibbits } while (!isMasterAlive); 612*0aeed3e9SJustin Hibbits } 613*0aeed3e9SJustin Hibbits } 614*0aeed3e9SJustin Hibbits 615*0aeed3e9SJustin Hibbits XX_Free(p_Bm->p_BmDriverParams); 616*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams = NULL; 617*0aeed3e9SJustin Hibbits 618*0aeed3e9SJustin Hibbits return E_OK; 619*0aeed3e9SJustin Hibbits } 620*0aeed3e9SJustin Hibbits 621*0aeed3e9SJustin Hibbits t_Error BM_Free(t_Handle h_Bm) 622*0aeed3e9SJustin Hibbits { 623*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm; 624*0aeed3e9SJustin Hibbits 625*0aeed3e9SJustin Hibbits if (!p_Bm) 626*0aeed3e9SJustin Hibbits return ERROR_CODE(E_INVALID_HANDLE); 627*0aeed3e9SJustin Hibbits 628*0aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID) 629*0aeed3e9SJustin Hibbits { 630*0aeed3e9SJustin Hibbits XX_IpcUnregisterMsgHandler(p_Bm->moduleName); 631*0aeed3e9SJustin Hibbits if (p_Bm->errIrq != NO_IRQ) 632*0aeed3e9SJustin Hibbits { 633*0aeed3e9SJustin Hibbits XX_DisableIntr(p_Bm->errIrq); 634*0aeed3e9SJustin Hibbits XX_FreeIntr(p_Bm->errIrq); 635*0aeed3e9SJustin Hibbits } 636*0aeed3e9SJustin Hibbits } 637*0aeed3e9SJustin Hibbits FreeInitResources(p_Bm); 638*0aeed3e9SJustin Hibbits 639*0aeed3e9SJustin Hibbits if(p_Bm->p_BmDriverParams) 640*0aeed3e9SJustin Hibbits XX_Free(p_Bm->p_BmDriverParams); 641*0aeed3e9SJustin Hibbits 642*0aeed3e9SJustin Hibbits XX_Free(p_Bm); 643*0aeed3e9SJustin Hibbits return E_OK; 644*0aeed3e9SJustin Hibbits } 645*0aeed3e9SJustin Hibbits 646*0aeed3e9SJustin Hibbits t_Error BM_ConfigException(t_Handle h_Bm, e_BmExceptions exception, bool enable) 647*0aeed3e9SJustin Hibbits { 648*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 649*0aeed3e9SJustin Hibbits uint32_t bitMask = 0; 650*0aeed3e9SJustin Hibbits 651*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 652*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm->p_BmDriverParams, E_INVALID_HANDLE); 653*0aeed3e9SJustin Hibbits 654*0aeed3e9SJustin Hibbits GET_EXCEPTION_FLAG(bitMask, exception); 655*0aeed3e9SJustin Hibbits if(bitMask) 656*0aeed3e9SJustin Hibbits { 657*0aeed3e9SJustin Hibbits if (enable) 658*0aeed3e9SJustin Hibbits p_Bm->exceptions |= bitMask; 659*0aeed3e9SJustin Hibbits else 660*0aeed3e9SJustin Hibbits p_Bm->exceptions &= ~bitMask; 661*0aeed3e9SJustin Hibbits } 662*0aeed3e9SJustin Hibbits else 663*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception")); 664*0aeed3e9SJustin Hibbits 665*0aeed3e9SJustin Hibbits return E_OK; 666*0aeed3e9SJustin Hibbits } 667*0aeed3e9SJustin Hibbits 668*0aeed3e9SJustin Hibbits t_Error BM_ConfigFbprThreshold(t_Handle h_Bm, uint32_t threshold) 669*0aeed3e9SJustin Hibbits { 670*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm; 671*0aeed3e9SJustin Hibbits 672*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 673*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm->p_BmDriverParams, E_INVALID_HANDLE); 674*0aeed3e9SJustin Hibbits 675*0aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->fbprThreshold = threshold; 676*0aeed3e9SJustin Hibbits 677*0aeed3e9SJustin Hibbits return E_OK; 678*0aeed3e9SJustin Hibbits } 679*0aeed3e9SJustin Hibbits 680*0aeed3e9SJustin Hibbits void BM_ErrorIsr(t_Handle h_Bm) 681*0aeed3e9SJustin Hibbits { 682*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm; 683*0aeed3e9SJustin Hibbits uint32_t tmpReg; 684*0aeed3e9SJustin Hibbits 685*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN(p_Bm, E_INVALID_HANDLE); 686*0aeed3e9SJustin Hibbits 687*0aeed3e9SJustin Hibbits if (p_Bm->guestId != NCSW_MASTER_ID) 688*0aeed3e9SJustin Hibbits { 689*0aeed3e9SJustin Hibbits REPORT_ERROR(WARNING, E_INVALID_OPERATION, ("Master Only")); 690*0aeed3e9SJustin Hibbits return; 691*0aeed3e9SJustin Hibbits } 692*0aeed3e9SJustin Hibbits 693*0aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_Bm->p_BmRegs->err_isr); 694*0aeed3e9SJustin Hibbits tmpReg &= GET_UINT32(p_Bm->p_BmRegs->err_ier); 695*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_isr, tmpReg); 696*0aeed3e9SJustin Hibbits 697*0aeed3e9SJustin Hibbits if (tmpReg & BM_EX_INVALID_COMMAND) 698*0aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_INVALID_COMMAND); 699*0aeed3e9SJustin Hibbits if (tmpReg & BM_EX_FBPR_THRESHOLD) 700*0aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_FBPR_THRESHOLD); 701*0aeed3e9SJustin Hibbits if (tmpReg & BM_EX_MULTI_ECC) 702*0aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_MULTI_ECC); 703*0aeed3e9SJustin Hibbits if (tmpReg & BM_EX_SINGLE_ECC) 704*0aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_SINGLE_ECC); 705*0aeed3e9SJustin Hibbits } 706*0aeed3e9SJustin Hibbits 707*0aeed3e9SJustin Hibbits uint32_t BM_GetCounter(t_Handle h_Bm, e_BmCounters counter) 708*0aeed3e9SJustin Hibbits { 709*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 710*0aeed3e9SJustin Hibbits 711*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Bm, E_INVALID_HANDLE, 0); 712*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_Bm->p_BmDriverParams, E_INVALID_STATE, 0); 713*0aeed3e9SJustin Hibbits 714*0aeed3e9SJustin Hibbits switch(counter) 715*0aeed3e9SJustin Hibbits { 716*0aeed3e9SJustin Hibbits case(e_BM_COUNTERS_FBPR): 717*0aeed3e9SJustin Hibbits return BmGetCounter(p_Bm, e_BM_IM_COUNTERS_FBPR, 0); 718*0aeed3e9SJustin Hibbits default: 719*0aeed3e9SJustin Hibbits break; 720*0aeed3e9SJustin Hibbits } 721*0aeed3e9SJustin Hibbits /* should never get here */ 722*0aeed3e9SJustin Hibbits ASSERT_COND(FALSE); 723*0aeed3e9SJustin Hibbits 724*0aeed3e9SJustin Hibbits return 0; 725*0aeed3e9SJustin Hibbits } 726*0aeed3e9SJustin Hibbits 727*0aeed3e9SJustin Hibbits t_Error BM_SetException(t_Handle h_Bm, e_BmExceptions exception, bool enable) 728*0aeed3e9SJustin Hibbits { 729*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 730*0aeed3e9SJustin Hibbits uint32_t tmpReg, bitMask = 0; 731*0aeed3e9SJustin Hibbits 732*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 733*0aeed3e9SJustin Hibbits 734*0aeed3e9SJustin Hibbits if (p_Bm->guestId != NCSW_MASTER_ID) 735*0aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_INVALID_OPERATION, ("Master Only")); 736*0aeed3e9SJustin Hibbits 737*0aeed3e9SJustin Hibbits BM_ConfigException(p_Bm, exception, enable); 738*0aeed3e9SJustin Hibbits 739*0aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_Bm->p_BmRegs->err_ier); 740*0aeed3e9SJustin Hibbits 741*0aeed3e9SJustin Hibbits if(enable) 742*0aeed3e9SJustin Hibbits tmpReg |= bitMask; 743*0aeed3e9SJustin Hibbits else 744*0aeed3e9SJustin Hibbits tmpReg &= ~bitMask; 745*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_ier, tmpReg); 746*0aeed3e9SJustin Hibbits 747*0aeed3e9SJustin Hibbits return E_OK; 748*0aeed3e9SJustin Hibbits } 749*0aeed3e9SJustin Hibbits 750*0aeed3e9SJustin Hibbits t_Error BM_GetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo) 751*0aeed3e9SJustin Hibbits { 752*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm; 753*0aeed3e9SJustin Hibbits 754*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 755*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmRevisionInfo, E_NULL_POINTER); 756*0aeed3e9SJustin Hibbits 757*0aeed3e9SJustin Hibbits return BmGetRevision(p_Bm, p_BmRevisionInfo); 758*0aeed3e9SJustin Hibbits } 759*0aeed3e9SJustin Hibbits 760*0aeed3e9SJustin Hibbits #if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)) 761*0aeed3e9SJustin Hibbits t_Error BM_DumpRegs(t_Handle h_Bm) 762*0aeed3e9SJustin Hibbits { 763*0aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm; 764*0aeed3e9SJustin Hibbits 765*0aeed3e9SJustin Hibbits DECLARE_DUMP; 766*0aeed3e9SJustin Hibbits 767*0aeed3e9SJustin Hibbits if (p_Bm->guestId != NCSW_MASTER_ID) 768*0aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_INVALID_OPERATION, ("Master Only")); 769*0aeed3e9SJustin Hibbits 770*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE); 771*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Bm->p_BmDriverParams, E_INVALID_STATE); 772*0aeed3e9SJustin Hibbits 773*0aeed3e9SJustin Hibbits DUMP_SUBTITLE(("\n")); 774*0aeed3e9SJustin Hibbits 775*0aeed3e9SJustin Hibbits DUMP_TITLE(p_Bm->p_BmRegs, ("BmRegs Regs")); 776*0aeed3e9SJustin Hibbits 777*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, swdet); 778*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hwdet); 779*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, swdxt); 780*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hwdxt); 781*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, sdcnt); 782*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hdcnt); 783*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, content); 784*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hdptr); 785*0aeed3e9SJustin Hibbits 786*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_fpc); 787*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_fp_lwit); 788*0aeed3e9SJustin Hibbits 789*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, cmd_pm_cfg); 790*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, fl_pm_cfg); 791*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs, ecsr); 792*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs, ecir); 793*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs, eadr); 794*0aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, edata); 795*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,sbet); 796*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,efcr); 797*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,efar); 798*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,sbec0); 799*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,sbec1); 800*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,ip_rev_1); 801*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,ip_rev_2); 802*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_bare); 803*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_bar); 804*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_ar); 805*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,srcidr); 806*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,liodnr); 807*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_isr); 808*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_ier); 809*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_isdr); 810*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_iir); 811*0aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_ifr); 812*0aeed3e9SJustin Hibbits 813*0aeed3e9SJustin Hibbits return E_OK; 814*0aeed3e9SJustin Hibbits } 815*0aeed3e9SJustin Hibbits #endif /* (defined(DEBUG_ERRORS) && ... */ 816