10aeed3e9SJustin Hibbits /******************************************************************************
20aeed3e9SJustin Hibbits
30aeed3e9SJustin Hibbits � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc.
40aeed3e9SJustin Hibbits All rights reserved.
50aeed3e9SJustin Hibbits
60aeed3e9SJustin Hibbits This is proprietary source code of Freescale Semiconductor Inc.,
70aeed3e9SJustin Hibbits and its use is subject to the NetComm Device Drivers EULA.
80aeed3e9SJustin Hibbits The copyright notice above does not evidence any actual or intended
90aeed3e9SJustin Hibbits publication of such source code.
100aeed3e9SJustin Hibbits
110aeed3e9SJustin Hibbits ALTERNATIVELY, redistribution and use in source and binary forms, with
120aeed3e9SJustin Hibbits or without modification, are permitted provided that the following
130aeed3e9SJustin Hibbits conditions are met:
140aeed3e9SJustin Hibbits * Redistributions of source code must retain the above copyright
150aeed3e9SJustin Hibbits notice, this list of conditions and the following disclaimer.
160aeed3e9SJustin Hibbits * Redistributions in binary form must reproduce the above copyright
170aeed3e9SJustin Hibbits notice, this list of conditions and the following disclaimer in the
180aeed3e9SJustin Hibbits documentation and/or other materials provided with the distribution.
190aeed3e9SJustin Hibbits * Neither the name of Freescale Semiconductor nor the
200aeed3e9SJustin Hibbits names of its contributors may be used to endorse or promote products
210aeed3e9SJustin Hibbits derived from this software without specific prior written permission.
220aeed3e9SJustin Hibbits
230aeed3e9SJustin Hibbits THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
240aeed3e9SJustin Hibbits EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
250aeed3e9SJustin Hibbits WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
260aeed3e9SJustin Hibbits DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
270aeed3e9SJustin Hibbits DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
280aeed3e9SJustin Hibbits (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
290aeed3e9SJustin Hibbits LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
300aeed3e9SJustin Hibbits ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
310aeed3e9SJustin Hibbits (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
320aeed3e9SJustin Hibbits SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330aeed3e9SJustin Hibbits *
340aeed3e9SJustin Hibbits
350aeed3e9SJustin Hibbits
360aeed3e9SJustin Hibbits **************************************************************************/
370aeed3e9SJustin Hibbits /******************************************************************************
380aeed3e9SJustin Hibbits @File bm.c
390aeed3e9SJustin Hibbits
400aeed3e9SJustin Hibbits @Description BM
410aeed3e9SJustin Hibbits *//***************************************************************************/
420aeed3e9SJustin Hibbits #include "error_ext.h"
430aeed3e9SJustin Hibbits #include "std_ext.h"
440aeed3e9SJustin Hibbits #include "string_ext.h"
450aeed3e9SJustin Hibbits #include "sprint_ext.h"
460aeed3e9SJustin Hibbits #include "debug_ext.h"
470aeed3e9SJustin Hibbits #include "mm_ext.h"
480aeed3e9SJustin Hibbits
490aeed3e9SJustin Hibbits #include "bm.h"
500aeed3e9SJustin Hibbits
510aeed3e9SJustin Hibbits
520aeed3e9SJustin Hibbits t_Error BM_ConfigException(t_Handle h_Bm, e_BmExceptions exception, bool enable);
530aeed3e9SJustin Hibbits
540aeed3e9SJustin Hibbits
550aeed3e9SJustin Hibbits /****************************************/
560aeed3e9SJustin Hibbits /* static functions */
570aeed3e9SJustin Hibbits /****************************************/
580aeed3e9SJustin Hibbits
590aeed3e9SJustin Hibbits static volatile bool blockingFlag = FALSE;
BmIpcMsgCompletionCB(t_Handle h_Module,uint8_t * p_Msg,uint8_t * p_Reply,uint32_t replyLength,t_Error status)600aeed3e9SJustin Hibbits static void BmIpcMsgCompletionCB(t_Handle h_Module,
610aeed3e9SJustin Hibbits uint8_t *p_Msg,
620aeed3e9SJustin Hibbits uint8_t *p_Reply,
630aeed3e9SJustin Hibbits uint32_t replyLength,
640aeed3e9SJustin Hibbits t_Error status)
650aeed3e9SJustin Hibbits {
660aeed3e9SJustin Hibbits SANITY_CHECK_RETURN(h_Module, E_INVALID_HANDLE);
670aeed3e9SJustin Hibbits
680aeed3e9SJustin Hibbits #ifdef DISABLE_SANITY_CHECKS
690aeed3e9SJustin Hibbits UNUSED(h_Module);
700aeed3e9SJustin Hibbits #endif /* DISABLE_SANITY_CHECKS */
710aeed3e9SJustin Hibbits UNUSED(p_Msg);UNUSED(p_Reply);UNUSED(replyLength);UNUSED(status);
720aeed3e9SJustin Hibbits
730aeed3e9SJustin Hibbits blockingFlag = FALSE;
740aeed3e9SJustin Hibbits }
750aeed3e9SJustin Hibbits
BmHandleIpcMsgCB(t_Handle h_Bm,uint8_t * p_Msg,uint32_t msgLength,uint8_t * p_Reply,uint32_t * p_ReplyLength)760aeed3e9SJustin Hibbits static t_Error BmHandleIpcMsgCB(t_Handle h_Bm,
770aeed3e9SJustin Hibbits uint8_t *p_Msg,
780aeed3e9SJustin Hibbits uint32_t msgLength,
790aeed3e9SJustin Hibbits uint8_t *p_Reply,
800aeed3e9SJustin Hibbits uint32_t *p_ReplyLength)
810aeed3e9SJustin Hibbits {
820aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
830aeed3e9SJustin Hibbits t_BmIpcMsg *p_IpcMsg = (t_BmIpcMsg*)p_Msg;
840aeed3e9SJustin Hibbits t_BmIpcReply *p_IpcReply = (t_BmIpcReply *)p_Reply;
850aeed3e9SJustin Hibbits
860aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
870aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR((msgLength >= sizeof(uint32_t)), E_INVALID_VALUE);
880aeed3e9SJustin Hibbits
890aeed3e9SJustin Hibbits #ifdef DISABLE_SANITY_CHECKS
900aeed3e9SJustin Hibbits UNUSED(msgLength);
910aeed3e9SJustin Hibbits #endif /* DISABLE_SANITY_CHECKS */
920aeed3e9SJustin Hibbits
930aeed3e9SJustin Hibbits ASSERT_COND(p_IpcMsg);
940aeed3e9SJustin Hibbits
950aeed3e9SJustin Hibbits memset(p_IpcReply, 0, (sizeof(uint8_t) * BM_IPC_MAX_REPLY_SIZE));
960aeed3e9SJustin Hibbits *p_ReplyLength = 0;
970aeed3e9SJustin Hibbits
980aeed3e9SJustin Hibbits switch(p_IpcMsg->msgId)
990aeed3e9SJustin Hibbits {
1000aeed3e9SJustin Hibbits case (BM_MASTER_IS_ALIVE):
1010aeed3e9SJustin Hibbits *(uint8_t*)p_IpcReply->replyBody = 1;
1020aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(uint8_t);
1030aeed3e9SJustin Hibbits break;
1040aeed3e9SJustin Hibbits case (BM_SET_POOL_THRESH):
1050aeed3e9SJustin Hibbits {
1060aeed3e9SJustin Hibbits t_Error err;
1070aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh;
1080aeed3e9SJustin Hibbits
1090aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcPoolThresh, p_IpcMsg->msgBody, sizeof(t_BmIpcPoolThreshParams));
1100aeed3e9SJustin Hibbits if ((err = BmSetPoolThresholds(p_Bm,
1110aeed3e9SJustin Hibbits ipcPoolThresh.bpid,
1120aeed3e9SJustin Hibbits ipcPoolThresh.thresholds)) != E_OK)
1130aeed3e9SJustin Hibbits REPORT_ERROR(MINOR, err, NO_MSG);
1140aeed3e9SJustin Hibbits break;
1150aeed3e9SJustin Hibbits }
1160aeed3e9SJustin Hibbits case (BM_UNSET_POOL_THRESH):
1170aeed3e9SJustin Hibbits {
1180aeed3e9SJustin Hibbits t_Error err;
1190aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh;
1200aeed3e9SJustin Hibbits
1210aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcPoolThresh, p_IpcMsg->msgBody, sizeof(t_BmIpcPoolThreshParams));
1220aeed3e9SJustin Hibbits if ((err = BmUnSetPoolThresholds(p_Bm,
1230aeed3e9SJustin Hibbits ipcPoolThresh.bpid)) != E_OK)
1240aeed3e9SJustin Hibbits REPORT_ERROR(MINOR, err, NO_MSG);
1250aeed3e9SJustin Hibbits break;
1260aeed3e9SJustin Hibbits }
1270aeed3e9SJustin Hibbits case (BM_GET_COUNTER):
1280aeed3e9SJustin Hibbits {
1290aeed3e9SJustin Hibbits t_BmIpcGetCounter ipcCounter;
1300aeed3e9SJustin Hibbits uint32_t count;
1310aeed3e9SJustin Hibbits
1320aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcCounter, p_IpcMsg->msgBody, sizeof(t_BmIpcGetCounter));
1330aeed3e9SJustin Hibbits count = BmGetCounter(p_Bm,
1340aeed3e9SJustin Hibbits (e_BmInterModuleCounters)ipcCounter.enumId,
1350aeed3e9SJustin Hibbits ipcCounter.bpid);
1360aeed3e9SJustin Hibbits memcpy(p_IpcReply->replyBody, (uint8_t*)&count, sizeof(uint32_t));
1370aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t);
1380aeed3e9SJustin Hibbits break;
1390aeed3e9SJustin Hibbits }
1400aeed3e9SJustin Hibbits case (BM_GET_REVISION):
1410aeed3e9SJustin Hibbits {
1420aeed3e9SJustin Hibbits t_BmRevisionInfo revInfo;
1430aeed3e9SJustin Hibbits t_BmIpcRevisionInfo ipcRevInfo;
1440aeed3e9SJustin Hibbits
1450aeed3e9SJustin Hibbits p_IpcReply->error = (uint32_t)BmGetRevision(h_Bm, &revInfo);
1460aeed3e9SJustin Hibbits ipcRevInfo.majorRev = revInfo.majorRev;
1470aeed3e9SJustin Hibbits ipcRevInfo.minorRev = revInfo.minorRev;
1480aeed3e9SJustin Hibbits memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcRevInfo, sizeof(t_BmIpcRevisionInfo));
1490aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(t_BmIpcRevisionInfo);
1500aeed3e9SJustin Hibbits break;
1510aeed3e9SJustin Hibbits }
1520aeed3e9SJustin Hibbits case (BM_FORCE_BPID):
1530aeed3e9SJustin Hibbits {
1540aeed3e9SJustin Hibbits t_BmIpcBpidParams ipcBpid;
1550aeed3e9SJustin Hibbits uint32_t tmp;
1560aeed3e9SJustin Hibbits
1570aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcBpid, p_IpcMsg->msgBody, sizeof(t_BmIpcBpidParams));
1580aeed3e9SJustin Hibbits tmp = BmBpidGet(p_Bm, TRUE, ipcBpid.bpid);
1590aeed3e9SJustin Hibbits memcpy(p_IpcReply->replyBody, (uint8_t*)&tmp, sizeof(uint32_t));
1600aeed3e9SJustin Hibbits *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t);
1610aeed3e9SJustin Hibbits break;
1620aeed3e9SJustin Hibbits }
1630aeed3e9SJustin Hibbits case (BM_PUT_BPID):
1640aeed3e9SJustin Hibbits {
1650aeed3e9SJustin Hibbits t_Error err;
1660aeed3e9SJustin Hibbits t_BmIpcBpidParams ipcBpid;
1670aeed3e9SJustin Hibbits
1680aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcBpid, p_IpcMsg->msgBody, sizeof(t_BmIpcBpidParams));
1690aeed3e9SJustin Hibbits if ((err = BmBpidPut(p_Bm, ipcBpid.bpid)) != E_OK)
1700aeed3e9SJustin Hibbits REPORT_ERROR(MINOR, err, NO_MSG);
1710aeed3e9SJustin Hibbits break;
1720aeed3e9SJustin Hibbits }
1730aeed3e9SJustin Hibbits default:
1740aeed3e9SJustin Hibbits *p_ReplyLength = 0;
1750aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_SELECTION, ("command not found!!!"));
1760aeed3e9SJustin Hibbits }
1770aeed3e9SJustin Hibbits
1780aeed3e9SJustin Hibbits return E_OK;
1790aeed3e9SJustin Hibbits }
1800aeed3e9SJustin Hibbits
CheckBmParameters(t_Bm * p_Bm)1810aeed3e9SJustin Hibbits static t_Error CheckBmParameters(t_Bm *p_Bm)
1820aeed3e9SJustin Hibbits {
1830aeed3e9SJustin Hibbits if ((p_Bm->p_BmDriverParams->partBpidBase + p_Bm->p_BmDriverParams->partNumOfPools) > BM_MAX_NUM_OF_POOLS)
1840aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("partBpidBase+partNumOfPools out of range!!!"));
1850aeed3e9SJustin Hibbits
1860aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID)
1870aeed3e9SJustin Hibbits {
1880aeed3e9SJustin Hibbits if (!p_Bm->p_BmDriverParams->totalNumOfBuffers)
1890aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("totalNumOfBuffers must be larger than '0'!!!"));
1900aeed3e9SJustin Hibbits if (p_Bm->p_BmDriverParams->totalNumOfBuffers > (128*MEGABYTE))
1910aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("totalNumOfBuffers must be equal or smaller than 128M!!!"));
1920aeed3e9SJustin Hibbits if(!p_Bm->f_Exception)
1930aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exceptions callback not provided"));
1940aeed3e9SJustin Hibbits }
1950aeed3e9SJustin Hibbits
1960aeed3e9SJustin Hibbits return E_OK;
1970aeed3e9SJustin Hibbits }
1980aeed3e9SJustin Hibbits
GenerateThresh(uint32_t val,int roundup)1990aeed3e9SJustin Hibbits static __inline__ uint32_t GenerateThresh(uint32_t val, int roundup)
2000aeed3e9SJustin Hibbits {
2010aeed3e9SJustin Hibbits uint32_t e = 0; /* co-efficient, exponent */
2020aeed3e9SJustin Hibbits uint32_t oddbit = 0;
2030aeed3e9SJustin Hibbits while(val > 0xff) {
2040aeed3e9SJustin Hibbits oddbit = val & 1;
2050aeed3e9SJustin Hibbits val >>= 1;
2060aeed3e9SJustin Hibbits e++;
2070aeed3e9SJustin Hibbits if(roundup && oddbit)
2080aeed3e9SJustin Hibbits val++;
2090aeed3e9SJustin Hibbits }
2100aeed3e9SJustin Hibbits return (val | (e << 8));
2110aeed3e9SJustin Hibbits }
2120aeed3e9SJustin Hibbits
BmSetPool(t_Handle h_Bm,uint8_t bpid,uint32_t swdet,uint32_t swdxt,uint32_t hwdet,uint32_t hwdxt)2130aeed3e9SJustin Hibbits static t_Error BmSetPool(t_Handle h_Bm,
2140aeed3e9SJustin Hibbits uint8_t bpid,
2150aeed3e9SJustin Hibbits uint32_t swdet,
2160aeed3e9SJustin Hibbits uint32_t swdxt,
2170aeed3e9SJustin Hibbits uint32_t hwdet,
2180aeed3e9SJustin Hibbits uint32_t hwdxt)
2190aeed3e9SJustin Hibbits {
2200aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
2210aeed3e9SJustin Hibbits
2220aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
2230aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE);
2240aeed3e9SJustin Hibbits
2250aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->swdet[bpid], GenerateThresh(swdet, 0));
2260aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->swdxt[bpid], GenerateThresh(swdxt, 1));
2270aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->hwdet[bpid], GenerateThresh(hwdet, 0));
2280aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->hwdxt[bpid], GenerateThresh(hwdxt, 1));
2290aeed3e9SJustin Hibbits
2300aeed3e9SJustin Hibbits return E_OK;
2310aeed3e9SJustin Hibbits }
2320aeed3e9SJustin Hibbits
2330aeed3e9SJustin Hibbits /****************************************/
2340aeed3e9SJustin Hibbits /* Inter-Module functions */
2350aeed3e9SJustin Hibbits /****************************************/
2360aeed3e9SJustin Hibbits
BmSetPoolThresholds(t_Handle h_Bm,uint8_t bpid,const uint32_t * thresholds)2370aeed3e9SJustin Hibbits t_Error BmSetPoolThresholds(t_Handle h_Bm, uint8_t bpid, const uint32_t *thresholds)
2380aeed3e9SJustin Hibbits {
2390aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
2400aeed3e9SJustin Hibbits
2410aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
2420aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE);
2430aeed3e9SJustin Hibbits
2440aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID)
2450aeed3e9SJustin Hibbits {
2460aeed3e9SJustin Hibbits return BmSetPool(h_Bm,
2470aeed3e9SJustin Hibbits bpid,
2480aeed3e9SJustin Hibbits thresholds[0],
2490aeed3e9SJustin Hibbits thresholds[1],
2500aeed3e9SJustin Hibbits thresholds[2],
2510aeed3e9SJustin Hibbits thresholds[3]);
2520aeed3e9SJustin Hibbits }
2530aeed3e9SJustin Hibbits else if (p_Bm->h_Session)
2540aeed3e9SJustin Hibbits {
2550aeed3e9SJustin Hibbits t_BmIpcMsg msg;
2560aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh;
2570aeed3e9SJustin Hibbits t_Error errCode = E_OK;
2580aeed3e9SJustin Hibbits
2590aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg));
2600aeed3e9SJustin Hibbits ipcPoolThresh.bpid = bpid;
261*4f0796edSJustin Hibbits memcpy(ipcPoolThresh.thresholds, thresholds, sizeof(uint32_t) * MAX_DEPLETION_THRESHOLDS);
2620aeed3e9SJustin Hibbits msg.msgId = BM_SET_POOL_THRESH;
2630aeed3e9SJustin Hibbits memcpy(msg.msgBody, &ipcPoolThresh, sizeof(t_BmIpcPoolThreshParams));
2640aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
2650aeed3e9SJustin Hibbits (uint8_t*)&msg,
2660aeed3e9SJustin Hibbits sizeof(msg.msgId) + sizeof(t_BmIpcPoolThreshParams),
2670aeed3e9SJustin Hibbits NULL,
2680aeed3e9SJustin Hibbits NULL,
2690aeed3e9SJustin Hibbits NULL,
2700aeed3e9SJustin Hibbits NULL)) != E_OK)
2710aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, errCode, NO_MSG);
2720aeed3e9SJustin Hibbits return E_OK;
2730aeed3e9SJustin Hibbits }
2740aeed3e9SJustin Hibbits else
2750aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_NOT_SUPPORTED, ("IPC"));
2760aeed3e9SJustin Hibbits }
2770aeed3e9SJustin Hibbits
BmUnSetPoolThresholds(t_Handle h_Bm,uint8_t bpid)2780aeed3e9SJustin Hibbits t_Error BmUnSetPoolThresholds(t_Handle h_Bm, uint8_t bpid)
2790aeed3e9SJustin Hibbits {
2800aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
2810aeed3e9SJustin Hibbits
2820aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
2830aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE);
2840aeed3e9SJustin Hibbits
2850aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID)
2860aeed3e9SJustin Hibbits {
2870aeed3e9SJustin Hibbits return BmSetPool(h_Bm,
2880aeed3e9SJustin Hibbits bpid,
2890aeed3e9SJustin Hibbits 0,
2900aeed3e9SJustin Hibbits 0,
2910aeed3e9SJustin Hibbits 0,
2920aeed3e9SJustin Hibbits 0);
2930aeed3e9SJustin Hibbits }
2940aeed3e9SJustin Hibbits else if (p_Bm->h_Session)
2950aeed3e9SJustin Hibbits {
2960aeed3e9SJustin Hibbits t_BmIpcMsg msg;
2970aeed3e9SJustin Hibbits t_BmIpcPoolThreshParams ipcPoolThresh;
2980aeed3e9SJustin Hibbits t_Error errCode = E_OK;
2990aeed3e9SJustin Hibbits
3000aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg));
3010aeed3e9SJustin Hibbits memset(&ipcPoolThresh, 0, sizeof(t_BmIpcPoolThreshParams));
3020aeed3e9SJustin Hibbits ipcPoolThresh.bpid = bpid;
3030aeed3e9SJustin Hibbits msg.msgId = BM_UNSET_POOL_THRESH;
3040aeed3e9SJustin Hibbits memcpy(msg.msgBody, &ipcPoolThresh, sizeof(t_BmIpcPoolThreshParams));
3050aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
3060aeed3e9SJustin Hibbits (uint8_t*)&msg,
3070aeed3e9SJustin Hibbits sizeof(msg.msgId) + sizeof(t_BmIpcPoolThreshParams),
3080aeed3e9SJustin Hibbits NULL,
3090aeed3e9SJustin Hibbits NULL,
3100aeed3e9SJustin Hibbits NULL,
3110aeed3e9SJustin Hibbits NULL)) != E_OK)
3120aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, errCode, NO_MSG);
3130aeed3e9SJustin Hibbits return E_OK;
3140aeed3e9SJustin Hibbits }
3150aeed3e9SJustin Hibbits else
3160aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_NOT_SUPPORTED, ("IPC"));
3170aeed3e9SJustin Hibbits }
3180aeed3e9SJustin Hibbits
BmGetCounter(t_Handle h_Bm,e_BmInterModuleCounters counter,uint8_t bpid)3190aeed3e9SJustin Hibbits uint32_t BmGetCounter(t_Handle h_Bm, e_BmInterModuleCounters counter, uint8_t bpid)
3200aeed3e9SJustin Hibbits {
3210aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
3220aeed3e9SJustin Hibbits
3230aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Bm, E_INVALID_HANDLE, 0);
3240aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE, 0);
3250aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE((((p_Bm->guestId == NCSW_MASTER_ID) && p_Bm->p_BmRegs) ||
3260aeed3e9SJustin Hibbits (p_Bm->guestId != NCSW_MASTER_ID)), E_INVALID_STATE, 0);
3270aeed3e9SJustin Hibbits
3280aeed3e9SJustin Hibbits if ((p_Bm->guestId == NCSW_MASTER_ID) ||
3290aeed3e9SJustin Hibbits (!p_Bm->h_Session && p_Bm->p_BmRegs))
3300aeed3e9SJustin Hibbits {
3310aeed3e9SJustin Hibbits switch(counter)
3320aeed3e9SJustin Hibbits {
3330aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_POOL_CONTENT):
3340aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->content[bpid]);
3350aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_POOL_SW_DEPLETION):
3360aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->sdcnt[bpid]);
3370aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_POOL_HW_DEPLETION):
3380aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->hdcnt[bpid]);
3390aeed3e9SJustin Hibbits case(e_BM_IM_COUNTERS_FBPR):
3400aeed3e9SJustin Hibbits return GET_UINT32(p_Bm->p_BmRegs->fbpr_fpc);
3410aeed3e9SJustin Hibbits default:
3420aeed3e9SJustin Hibbits break;
3430aeed3e9SJustin Hibbits }
3440aeed3e9SJustin Hibbits /* should never get here */
3450aeed3e9SJustin Hibbits ASSERT_COND(FALSE);
3460aeed3e9SJustin Hibbits }
3470aeed3e9SJustin Hibbits else if (p_Bm->h_Session)
3480aeed3e9SJustin Hibbits {
3490aeed3e9SJustin Hibbits t_BmIpcMsg msg;
3500aeed3e9SJustin Hibbits t_BmIpcReply reply;
3510aeed3e9SJustin Hibbits t_BmIpcGetCounter ipcCounter;
3520aeed3e9SJustin Hibbits uint32_t replyLength;
3530aeed3e9SJustin Hibbits uint32_t count;
3540aeed3e9SJustin Hibbits t_Error errCode = E_OK;
3550aeed3e9SJustin Hibbits
3560aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg));
3570aeed3e9SJustin Hibbits memset(&reply, 0, sizeof(t_BmIpcReply));
3580aeed3e9SJustin Hibbits ipcCounter.bpid = bpid;
3590aeed3e9SJustin Hibbits ipcCounter.enumId = (uint32_t)counter;
3600aeed3e9SJustin Hibbits msg.msgId = BM_GET_COUNTER;
3610aeed3e9SJustin Hibbits memcpy(msg.msgBody, &ipcCounter, sizeof(t_BmIpcGetCounter));
3620aeed3e9SJustin Hibbits replyLength = sizeof(uint32_t) + sizeof(uint32_t);
3630aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
3640aeed3e9SJustin Hibbits (uint8_t*)&msg,
3650aeed3e9SJustin Hibbits sizeof(msg.msgId) + sizeof(t_BmIpcGetCounter),
3660aeed3e9SJustin Hibbits (uint8_t*)&reply,
3670aeed3e9SJustin Hibbits &replyLength,
3680aeed3e9SJustin Hibbits NULL,
3690aeed3e9SJustin Hibbits NULL)) != E_OK)
3700aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, errCode, NO_MSG);
3710aeed3e9SJustin Hibbits if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t)))
3720aeed3e9SJustin Hibbits {
3730aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
3740aeed3e9SJustin Hibbits errCode = E_INVALID_VALUE;
3750aeed3e9SJustin Hibbits }
3760aeed3e9SJustin Hibbits if (errCode == E_OK)
3770aeed3e9SJustin Hibbits {
3780aeed3e9SJustin Hibbits memcpy((uint8_t*)&count, reply.replyBody, sizeof(uint32_t));
3790aeed3e9SJustin Hibbits return count;
3800aeed3e9SJustin Hibbits }
3810aeed3e9SJustin Hibbits }
3820aeed3e9SJustin Hibbits else
3830aeed3e9SJustin Hibbits REPORT_ERROR(WARNING, E_NOT_SUPPORTED,
3840aeed3e9SJustin Hibbits ("In 'guest', either IPC or 'baseAddress' is required!"));
3850aeed3e9SJustin Hibbits
3860aeed3e9SJustin Hibbits return 0;
3870aeed3e9SJustin Hibbits }
3880aeed3e9SJustin Hibbits
BmGetRevision(t_Handle h_Bm,t_BmRevisionInfo * p_BmRevisionInfo)3890aeed3e9SJustin Hibbits t_Error BmGetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo)
3900aeed3e9SJustin Hibbits {
3910aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
3920aeed3e9SJustin Hibbits uint32_t tmpReg;
3930aeed3e9SJustin Hibbits
3940aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
3950aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmRevisionInfo, E_NULL_POINTER);
3960aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR((((p_Bm->guestId == NCSW_MASTER_ID) && p_Bm->p_BmRegs) ||
3970aeed3e9SJustin Hibbits (p_Bm->guestId != NCSW_MASTER_ID)), E_INVALID_STATE);
3980aeed3e9SJustin Hibbits
3990aeed3e9SJustin Hibbits if ((p_Bm->guestId == NCSW_MASTER_ID) ||
4000aeed3e9SJustin Hibbits (!p_Bm->h_Session && p_Bm->p_BmRegs))
4010aeed3e9SJustin Hibbits {
4020aeed3e9SJustin Hibbits /* read revision register 1 */
4030aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_Bm->p_BmRegs->ip_rev_1);
4040aeed3e9SJustin Hibbits p_BmRevisionInfo->majorRev = (uint8_t)((tmpReg & REV1_MAJOR_MASK) >> REV1_MAJOR_SHIFT);
4050aeed3e9SJustin Hibbits p_BmRevisionInfo->minorRev = (uint8_t)((tmpReg & REV1_MINOR_MASK) >> REV1_MINOR_SHIFT);
4060aeed3e9SJustin Hibbits }
4070aeed3e9SJustin Hibbits else if (p_Bm->h_Session)
4080aeed3e9SJustin Hibbits {
4090aeed3e9SJustin Hibbits t_BmIpcMsg msg;
4100aeed3e9SJustin Hibbits t_BmIpcReply reply;
4110aeed3e9SJustin Hibbits t_BmIpcRevisionInfo ipcRevInfo;
4120aeed3e9SJustin Hibbits uint32_t replyLength;
4130aeed3e9SJustin Hibbits t_Error errCode = E_OK;
4140aeed3e9SJustin Hibbits
4150aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg));
4160aeed3e9SJustin Hibbits memset(&reply, 0, sizeof(t_BmIpcReply));
4170aeed3e9SJustin Hibbits msg.msgId = BM_GET_REVISION;
4180aeed3e9SJustin Hibbits replyLength = sizeof(uint32_t) + sizeof(t_BmIpcRevisionInfo);
4190aeed3e9SJustin Hibbits if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
4200aeed3e9SJustin Hibbits (uint8_t*)&msg,
4210aeed3e9SJustin Hibbits sizeof(msg.msgId),
4220aeed3e9SJustin Hibbits (uint8_t*)&reply,
4230aeed3e9SJustin Hibbits &replyLength,
4240aeed3e9SJustin Hibbits NULL,
4250aeed3e9SJustin Hibbits NULL)) != E_OK)
4260aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, errCode, NO_MSG);
4270aeed3e9SJustin Hibbits if (replyLength != (sizeof(uint32_t) + sizeof(t_BmIpcRevisionInfo)))
4280aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
4290aeed3e9SJustin Hibbits
4300aeed3e9SJustin Hibbits memcpy((uint8_t*)&ipcRevInfo, reply.replyBody, sizeof(t_BmIpcRevisionInfo));
4310aeed3e9SJustin Hibbits p_BmRevisionInfo->majorRev = ipcRevInfo.majorRev;
4320aeed3e9SJustin Hibbits p_BmRevisionInfo->minorRev = ipcRevInfo.minorRev;
4330aeed3e9SJustin Hibbits return (t_Error)(reply.error);
4340aeed3e9SJustin Hibbits }
4350aeed3e9SJustin Hibbits else
4360aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_NOT_SUPPORTED,
4370aeed3e9SJustin Hibbits ("In 'guest', either IPC or 'baseAddress' is required!"));
4380aeed3e9SJustin Hibbits
4390aeed3e9SJustin Hibbits return E_OK;
4400aeed3e9SJustin Hibbits }
4410aeed3e9SJustin Hibbits
FreeInitResources(t_Bm * p_Bm)4420aeed3e9SJustin Hibbits static void FreeInitResources(t_Bm *p_Bm)
4430aeed3e9SJustin Hibbits {
4440aeed3e9SJustin Hibbits if (p_Bm->p_FbprBase)
4450aeed3e9SJustin Hibbits XX_FreeSmart(p_Bm->p_FbprBase);
4460aeed3e9SJustin Hibbits if (p_Bm->h_Session)
4470aeed3e9SJustin Hibbits XX_IpcFreeSession(p_Bm->h_Session);
4480aeed3e9SJustin Hibbits if (p_Bm->h_BpidMm)
4490aeed3e9SJustin Hibbits MM_Free(p_Bm->h_BpidMm);
4500aeed3e9SJustin Hibbits }
4510aeed3e9SJustin Hibbits
4520aeed3e9SJustin Hibbits /****************************************/
4530aeed3e9SJustin Hibbits /* API Init unit functions */
4540aeed3e9SJustin Hibbits /****************************************/
4550aeed3e9SJustin Hibbits
BM_Config(t_BmParam * p_BmParam)4560aeed3e9SJustin Hibbits t_Handle BM_Config(t_BmParam *p_BmParam)
4570aeed3e9SJustin Hibbits {
4580aeed3e9SJustin Hibbits t_Bm *p_Bm;
4590aeed3e9SJustin Hibbits
4600aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_BmParam, E_INVALID_HANDLE, NULL);
4610aeed3e9SJustin Hibbits
4620aeed3e9SJustin Hibbits p_Bm = (t_Bm *)XX_Malloc(sizeof(t_Bm));
4630aeed3e9SJustin Hibbits if (!p_Bm)
4640aeed3e9SJustin Hibbits {
4650aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("BM obj!!!"));
4660aeed3e9SJustin Hibbits return NULL;
4670aeed3e9SJustin Hibbits }
4680aeed3e9SJustin Hibbits memset(p_Bm, 0, sizeof(t_Bm));
4690aeed3e9SJustin Hibbits
4700aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams = (t_BmDriverParams *)XX_Malloc(sizeof(t_BmDriverParams));
4710aeed3e9SJustin Hibbits if (!p_Bm->p_BmDriverParams)
4720aeed3e9SJustin Hibbits {
4730aeed3e9SJustin Hibbits XX_Free(p_Bm);
4740aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Bm driver parameters"));
4750aeed3e9SJustin Hibbits return NULL;
4760aeed3e9SJustin Hibbits }
4770aeed3e9SJustin Hibbits memset(p_Bm->p_BmDriverParams, 0, sizeof(t_BmDriverParams));
4780aeed3e9SJustin Hibbits
4790aeed3e9SJustin Hibbits p_Bm->guestId = p_BmParam->guestId;
4800aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->partNumOfPools = p_BmParam->partNumOfPools;
4810aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->partBpidBase = p_BmParam->partBpidBase;
4820aeed3e9SJustin Hibbits p_Bm->p_BmRegs = (t_BmRegs *)UINT_TO_PTR(p_BmParam->baseAddress);
4830aeed3e9SJustin Hibbits
4840aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID)
4850aeed3e9SJustin Hibbits {
4860aeed3e9SJustin Hibbits p_Bm->exceptions = DEFAULT_exceptions;
4870aeed3e9SJustin Hibbits p_Bm->f_Exception = p_BmParam->f_Exception;
4880aeed3e9SJustin Hibbits p_Bm->h_App = p_BmParam->h_App;
4890aeed3e9SJustin Hibbits p_Bm->errIrq = p_BmParam->errIrq;
4900aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->totalNumOfBuffers = p_BmParam->totalNumOfBuffers;
4910aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->fbprMemPartitionId = p_BmParam->fbprMemPartitionId;
4920aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->fbprThreshold = DEFAULT_fbprThreshold;
4930aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->liodn = p_BmParam->liodn;
4940aeed3e9SJustin Hibbits
4950aeed3e9SJustin Hibbits }
4960aeed3e9SJustin Hibbits /* build the BM partition IPC address */
4970aeed3e9SJustin Hibbits memset(p_Bm->moduleName, 0, MODULE_NAME_SIZE);
4980aeed3e9SJustin Hibbits if(Sprint (p_Bm->moduleName, "BM_0_%d",p_Bm->guestId) != (p_Bm->guestId<10 ? 6:7))
4990aeed3e9SJustin Hibbits {
5000aeed3e9SJustin Hibbits XX_Free(p_Bm->p_BmDriverParams);
5010aeed3e9SJustin Hibbits XX_Free(p_Bm);
5020aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed"));
5030aeed3e9SJustin Hibbits return NULL;
5040aeed3e9SJustin Hibbits }
5050aeed3e9SJustin Hibbits return p_Bm;
5060aeed3e9SJustin Hibbits }
5070aeed3e9SJustin Hibbits
BM_Init(t_Handle h_Bm)5080aeed3e9SJustin Hibbits t_Error BM_Init(t_Handle h_Bm)
5090aeed3e9SJustin Hibbits {
5100aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm;
5110aeed3e9SJustin Hibbits t_Error err;
5120aeed3e9SJustin Hibbits
5130aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
5140aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm->p_BmDriverParams, E_INVALID_HANDLE);
5150aeed3e9SJustin Hibbits
5160aeed3e9SJustin Hibbits CHECK_INIT_PARAMETERS(p_Bm, CheckBmParameters);
5170aeed3e9SJustin Hibbits
5180aeed3e9SJustin Hibbits if (p_Bm->p_BmDriverParams->partNumOfPools)
5190aeed3e9SJustin Hibbits if (MM_Init(&p_Bm->h_BpidMm, p_Bm->p_BmDriverParams->partBpidBase, p_Bm->p_BmDriverParams->partNumOfPools) != E_OK)
5200aeed3e9SJustin Hibbits {
5210aeed3e9SJustin Hibbits FreeInitResources(p_Bm);
5220aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_HANDLE, ("BM-BPIDS-MEM partition!!!"));
5230aeed3e9SJustin Hibbits }
5240aeed3e9SJustin Hibbits
5250aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID)
5260aeed3e9SJustin Hibbits {
5270aeed3e9SJustin Hibbits uint64_t phyAddr;
5280aeed3e9SJustin Hibbits t_BmRevisionInfo revInfo;
5290aeed3e9SJustin Hibbits uint32_t dsSize, exp;
5300aeed3e9SJustin Hibbits
5310aeed3e9SJustin Hibbits BmGetRevision(p_Bm, &revInfo);
5320aeed3e9SJustin Hibbits DBG(TRACE, ("Bman ver:%02x,%02x", revInfo.majorRev, revInfo.minorRev));
5330aeed3e9SJustin Hibbits
5340aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->liodnr, (uint16_t)p_Bm->p_BmDriverParams->liodn);
5350aeed3e9SJustin Hibbits
5360aeed3e9SJustin Hibbits /* FBPR memory */
5370aeed3e9SJustin Hibbits dsSize = (uint32_t)(p_Bm->p_BmDriverParams->totalNumOfBuffers * (FBPR_ENTRY_SIZE / 8));
5380aeed3e9SJustin Hibbits LOG2(dsSize, exp);
5390aeed3e9SJustin Hibbits if (!POWER_OF_2(dsSize)) (exp++);
5400aeed3e9SJustin Hibbits dsSize = (uint32_t)(1 << exp);
5410aeed3e9SJustin Hibbits if (dsSize < (4*KILOBYTE))
5420aeed3e9SJustin Hibbits {
5430aeed3e9SJustin Hibbits dsSize = (4*KILOBYTE);
5440aeed3e9SJustin Hibbits LOG2(dsSize, exp);
5450aeed3e9SJustin Hibbits }
5460aeed3e9SJustin Hibbits p_Bm->p_FbprBase = XX_MallocSmart(dsSize, (int)p_Bm->p_BmDriverParams->fbprMemPartitionId, dsSize);
5470aeed3e9SJustin Hibbits if (!p_Bm->p_FbprBase)
5480aeed3e9SJustin Hibbits {
5490aeed3e9SJustin Hibbits FreeInitResources(p_Bm);
5500aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FBPR obj!!!"));
5510aeed3e9SJustin Hibbits }
5520aeed3e9SJustin Hibbits phyAddr = XX_VirtToPhys(p_Bm->p_FbprBase);
5530aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_bare, ((uint32_t)(phyAddr >> 32) & 0xffff));
5540aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_bar, (uint32_t)phyAddr);
5550aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_ar, (exp - 1));
5560aeed3e9SJustin Hibbits
5570aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->fbpr_fp_lwit, p_Bm->p_BmDriverParams->fbprThreshold);
5580aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_isr, p_Bm->exceptions);
5590aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_ier, p_Bm->exceptions);
5600aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_isdr, 0x0);
5610aeed3e9SJustin Hibbits if (p_Bm->errIrq != NO_IRQ)
5620aeed3e9SJustin Hibbits {
5630aeed3e9SJustin Hibbits XX_SetIntr(p_Bm->errIrq, BM_ErrorIsr, p_Bm);
5640aeed3e9SJustin Hibbits XX_EnableIntr(p_Bm->errIrq);
5650aeed3e9SJustin Hibbits }
5660aeed3e9SJustin Hibbits
5670aeed3e9SJustin Hibbits if ((err = XX_IpcRegisterMsgHandler(p_Bm->moduleName, BmHandleIpcMsgCB, p_Bm, BM_IPC_MAX_REPLY_SIZE)) != E_OK)
5680aeed3e9SJustin Hibbits {
5690aeed3e9SJustin Hibbits FreeInitResources(p_Bm);
5700aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, err, NO_MSG);
5710aeed3e9SJustin Hibbits }
5720aeed3e9SJustin Hibbits }
5730aeed3e9SJustin Hibbits else /* guest mode */
5740aeed3e9SJustin Hibbits {
5750aeed3e9SJustin Hibbits char masterModuleName[MODULE_NAME_SIZE];
5760aeed3e9SJustin Hibbits
5770aeed3e9SJustin Hibbits memset(masterModuleName, 0, MODULE_NAME_SIZE);
5780aeed3e9SJustin Hibbits if(Sprint (masterModuleName, "BM_0_%d", NCSW_MASTER_ID) != (NCSW_MASTER_ID<10 ? 6:7))
5790aeed3e9SJustin Hibbits {
5800aeed3e9SJustin Hibbits FreeInitResources(p_Bm);
5810aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed"));
5820aeed3e9SJustin Hibbits }
5830aeed3e9SJustin Hibbits
5840aeed3e9SJustin Hibbits p_Bm->h_Session = XX_IpcInitSession(masterModuleName, p_Bm->moduleName);
5850aeed3e9SJustin Hibbits if (p_Bm->h_Session)
5860aeed3e9SJustin Hibbits {
5870aeed3e9SJustin Hibbits t_BmIpcMsg msg;
5880aeed3e9SJustin Hibbits uint8_t isMasterAlive = 0;
5890aeed3e9SJustin Hibbits t_BmIpcReply reply;
5900aeed3e9SJustin Hibbits uint32_t replyLength;
5910aeed3e9SJustin Hibbits
5920aeed3e9SJustin Hibbits memset(&msg, 0, sizeof(t_BmIpcMsg));
5930aeed3e9SJustin Hibbits memset(&reply, 0, sizeof(t_BmIpcReply));
5940aeed3e9SJustin Hibbits msg.msgId = BM_MASTER_IS_ALIVE;
5950aeed3e9SJustin Hibbits replyLength = sizeof(uint32_t) + sizeof(uint8_t);
5960aeed3e9SJustin Hibbits do
5970aeed3e9SJustin Hibbits {
5980aeed3e9SJustin Hibbits blockingFlag = TRUE;
5990aeed3e9SJustin Hibbits if ((err = XX_IpcSendMessage(p_Bm->h_Session,
6000aeed3e9SJustin Hibbits (uint8_t*)&msg,
6010aeed3e9SJustin Hibbits sizeof(msg.msgId),
6020aeed3e9SJustin Hibbits (uint8_t*)&reply,
6030aeed3e9SJustin Hibbits &replyLength,
6040aeed3e9SJustin Hibbits BmIpcMsgCompletionCB,
6050aeed3e9SJustin Hibbits p_Bm)) != E_OK)
6060aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, err, NO_MSG);
6070aeed3e9SJustin Hibbits while(blockingFlag) ;
6080aeed3e9SJustin Hibbits if(replyLength != (sizeof(uint32_t) + sizeof(uint8_t)))
6090aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
6100aeed3e9SJustin Hibbits isMasterAlive = *(uint8_t*)(reply.replyBody);
6110aeed3e9SJustin Hibbits } while (!isMasterAlive);
6120aeed3e9SJustin Hibbits }
6130aeed3e9SJustin Hibbits }
6140aeed3e9SJustin Hibbits
6150aeed3e9SJustin Hibbits XX_Free(p_Bm->p_BmDriverParams);
6160aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams = NULL;
6170aeed3e9SJustin Hibbits
6180aeed3e9SJustin Hibbits return E_OK;
6190aeed3e9SJustin Hibbits }
6200aeed3e9SJustin Hibbits
BM_Free(t_Handle h_Bm)6210aeed3e9SJustin Hibbits t_Error BM_Free(t_Handle h_Bm)
6220aeed3e9SJustin Hibbits {
6230aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm;
6240aeed3e9SJustin Hibbits
6250aeed3e9SJustin Hibbits if (!p_Bm)
6260aeed3e9SJustin Hibbits return ERROR_CODE(E_INVALID_HANDLE);
6270aeed3e9SJustin Hibbits
6280aeed3e9SJustin Hibbits if (p_Bm->guestId == NCSW_MASTER_ID)
6290aeed3e9SJustin Hibbits {
6300aeed3e9SJustin Hibbits XX_IpcUnregisterMsgHandler(p_Bm->moduleName);
6310aeed3e9SJustin Hibbits if (p_Bm->errIrq != NO_IRQ)
6320aeed3e9SJustin Hibbits {
6330aeed3e9SJustin Hibbits XX_DisableIntr(p_Bm->errIrq);
6340aeed3e9SJustin Hibbits XX_FreeIntr(p_Bm->errIrq);
6350aeed3e9SJustin Hibbits }
6360aeed3e9SJustin Hibbits }
6370aeed3e9SJustin Hibbits FreeInitResources(p_Bm);
6380aeed3e9SJustin Hibbits
6390aeed3e9SJustin Hibbits if(p_Bm->p_BmDriverParams)
6400aeed3e9SJustin Hibbits XX_Free(p_Bm->p_BmDriverParams);
6410aeed3e9SJustin Hibbits
6420aeed3e9SJustin Hibbits XX_Free(p_Bm);
6430aeed3e9SJustin Hibbits return E_OK;
6440aeed3e9SJustin Hibbits }
6450aeed3e9SJustin Hibbits
BM_ConfigException(t_Handle h_Bm,e_BmExceptions exception,bool enable)6460aeed3e9SJustin Hibbits t_Error BM_ConfigException(t_Handle h_Bm, e_BmExceptions exception, bool enable)
6470aeed3e9SJustin Hibbits {
6480aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
6490aeed3e9SJustin Hibbits uint32_t bitMask = 0;
6500aeed3e9SJustin Hibbits
6510aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
6520aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm->p_BmDriverParams, E_INVALID_HANDLE);
6530aeed3e9SJustin Hibbits
6540aeed3e9SJustin Hibbits GET_EXCEPTION_FLAG(bitMask, exception);
6550aeed3e9SJustin Hibbits if(bitMask)
6560aeed3e9SJustin Hibbits {
6570aeed3e9SJustin Hibbits if (enable)
6580aeed3e9SJustin Hibbits p_Bm->exceptions |= bitMask;
6590aeed3e9SJustin Hibbits else
6600aeed3e9SJustin Hibbits p_Bm->exceptions &= ~bitMask;
6610aeed3e9SJustin Hibbits }
6620aeed3e9SJustin Hibbits else
6630aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
6640aeed3e9SJustin Hibbits
6650aeed3e9SJustin Hibbits return E_OK;
6660aeed3e9SJustin Hibbits }
6670aeed3e9SJustin Hibbits
BM_ConfigFbprThreshold(t_Handle h_Bm,uint32_t threshold)6680aeed3e9SJustin Hibbits t_Error BM_ConfigFbprThreshold(t_Handle h_Bm, uint32_t threshold)
6690aeed3e9SJustin Hibbits {
6700aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm;
6710aeed3e9SJustin Hibbits
6720aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
6730aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm->p_BmDriverParams, E_INVALID_HANDLE);
6740aeed3e9SJustin Hibbits
6750aeed3e9SJustin Hibbits p_Bm->p_BmDriverParams->fbprThreshold = threshold;
6760aeed3e9SJustin Hibbits
6770aeed3e9SJustin Hibbits return E_OK;
6780aeed3e9SJustin Hibbits }
6790aeed3e9SJustin Hibbits
BM_ErrorIsr(t_Handle h_Bm)6800aeed3e9SJustin Hibbits void BM_ErrorIsr(t_Handle h_Bm)
6810aeed3e9SJustin Hibbits {
6820aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm;
6830aeed3e9SJustin Hibbits uint32_t tmpReg;
6840aeed3e9SJustin Hibbits
6850aeed3e9SJustin Hibbits SANITY_CHECK_RETURN(p_Bm, E_INVALID_HANDLE);
6860aeed3e9SJustin Hibbits
6870aeed3e9SJustin Hibbits if (p_Bm->guestId != NCSW_MASTER_ID)
6880aeed3e9SJustin Hibbits {
6890aeed3e9SJustin Hibbits REPORT_ERROR(WARNING, E_INVALID_OPERATION, ("Master Only"));
6900aeed3e9SJustin Hibbits return;
6910aeed3e9SJustin Hibbits }
6920aeed3e9SJustin Hibbits
6930aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_Bm->p_BmRegs->err_isr);
6940aeed3e9SJustin Hibbits tmpReg &= GET_UINT32(p_Bm->p_BmRegs->err_ier);
6950aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_isr, tmpReg);
6960aeed3e9SJustin Hibbits
6970aeed3e9SJustin Hibbits if (tmpReg & BM_EX_INVALID_COMMAND)
6980aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_INVALID_COMMAND);
6990aeed3e9SJustin Hibbits if (tmpReg & BM_EX_FBPR_THRESHOLD)
7000aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_FBPR_THRESHOLD);
7010aeed3e9SJustin Hibbits if (tmpReg & BM_EX_MULTI_ECC)
7020aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_MULTI_ECC);
7030aeed3e9SJustin Hibbits if (tmpReg & BM_EX_SINGLE_ECC)
7040aeed3e9SJustin Hibbits p_Bm->f_Exception(p_Bm->h_App, e_BM_EX_SINGLE_ECC);
7050aeed3e9SJustin Hibbits }
7060aeed3e9SJustin Hibbits
BM_GetCounter(t_Handle h_Bm,e_BmCounters counter)7070aeed3e9SJustin Hibbits uint32_t BM_GetCounter(t_Handle h_Bm, e_BmCounters counter)
7080aeed3e9SJustin Hibbits {
7090aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
7100aeed3e9SJustin Hibbits
7110aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Bm, E_INVALID_HANDLE, 0);
7120aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_Bm->p_BmDriverParams, E_INVALID_STATE, 0);
7130aeed3e9SJustin Hibbits
7140aeed3e9SJustin Hibbits switch(counter)
7150aeed3e9SJustin Hibbits {
7160aeed3e9SJustin Hibbits case(e_BM_COUNTERS_FBPR):
7170aeed3e9SJustin Hibbits return BmGetCounter(p_Bm, e_BM_IM_COUNTERS_FBPR, 0);
7180aeed3e9SJustin Hibbits default:
7190aeed3e9SJustin Hibbits break;
7200aeed3e9SJustin Hibbits }
7210aeed3e9SJustin Hibbits /* should never get here */
7220aeed3e9SJustin Hibbits ASSERT_COND(FALSE);
7230aeed3e9SJustin Hibbits
7240aeed3e9SJustin Hibbits return 0;
7250aeed3e9SJustin Hibbits }
7260aeed3e9SJustin Hibbits
BM_SetException(t_Handle h_Bm,e_BmExceptions exception,bool enable)7270aeed3e9SJustin Hibbits t_Error BM_SetException(t_Handle h_Bm, e_BmExceptions exception, bool enable)
7280aeed3e9SJustin Hibbits {
7290aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
7300aeed3e9SJustin Hibbits uint32_t tmpReg, bitMask = 0;
7310aeed3e9SJustin Hibbits
7320aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
7330aeed3e9SJustin Hibbits
7340aeed3e9SJustin Hibbits if (p_Bm->guestId != NCSW_MASTER_ID)
7350aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_INVALID_OPERATION, ("Master Only"));
7360aeed3e9SJustin Hibbits
7370aeed3e9SJustin Hibbits BM_ConfigException(p_Bm, exception, enable);
7380aeed3e9SJustin Hibbits
7390aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_Bm->p_BmRegs->err_ier);
7400aeed3e9SJustin Hibbits
7410aeed3e9SJustin Hibbits if(enable)
7420aeed3e9SJustin Hibbits tmpReg |= bitMask;
7430aeed3e9SJustin Hibbits else
7440aeed3e9SJustin Hibbits tmpReg &= ~bitMask;
7450aeed3e9SJustin Hibbits WRITE_UINT32(p_Bm->p_BmRegs->err_ier, tmpReg);
7460aeed3e9SJustin Hibbits
7470aeed3e9SJustin Hibbits return E_OK;
7480aeed3e9SJustin Hibbits }
7490aeed3e9SJustin Hibbits
BM_GetRevision(t_Handle h_Bm,t_BmRevisionInfo * p_BmRevisionInfo)7500aeed3e9SJustin Hibbits t_Error BM_GetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo)
7510aeed3e9SJustin Hibbits {
7520aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm*)h_Bm;
7530aeed3e9SJustin Hibbits
7540aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
7550aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_BmRevisionInfo, E_NULL_POINTER);
7560aeed3e9SJustin Hibbits
7570aeed3e9SJustin Hibbits return BmGetRevision(p_Bm, p_BmRevisionInfo);
7580aeed3e9SJustin Hibbits }
7590aeed3e9SJustin Hibbits
7600aeed3e9SJustin Hibbits #if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0))
BM_DumpRegs(t_Handle h_Bm)7610aeed3e9SJustin Hibbits t_Error BM_DumpRegs(t_Handle h_Bm)
7620aeed3e9SJustin Hibbits {
7630aeed3e9SJustin Hibbits t_Bm *p_Bm = (t_Bm *)h_Bm;
7640aeed3e9SJustin Hibbits
7650aeed3e9SJustin Hibbits DECLARE_DUMP;
7660aeed3e9SJustin Hibbits
7670aeed3e9SJustin Hibbits if (p_Bm->guestId != NCSW_MASTER_ID)
7680aeed3e9SJustin Hibbits RETURN_ERROR(WARNING, E_INVALID_OPERATION, ("Master Only"));
7690aeed3e9SJustin Hibbits
7700aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Bm, E_INVALID_HANDLE);
7710aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Bm->p_BmDriverParams, E_INVALID_STATE);
7720aeed3e9SJustin Hibbits
7730aeed3e9SJustin Hibbits DUMP_SUBTITLE(("\n"));
7740aeed3e9SJustin Hibbits
7750aeed3e9SJustin Hibbits DUMP_TITLE(p_Bm->p_BmRegs, ("BmRegs Regs"));
7760aeed3e9SJustin Hibbits
7770aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, swdet);
7780aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hwdet);
7790aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, swdxt);
7800aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hwdxt);
7810aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, sdcnt);
7820aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hdcnt);
7830aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, content);
7840aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, hdptr);
7850aeed3e9SJustin Hibbits
7860aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_fpc);
7870aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_fp_lwit);
7880aeed3e9SJustin Hibbits
7890aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, cmd_pm_cfg);
7900aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, fl_pm_cfg);
7910aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs, ecsr);
7920aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs, ecir);
7930aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs, eadr);
7940aeed3e9SJustin Hibbits DUMP_ARR(p_Bm->p_BmRegs, edata);
7950aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,sbet);
7960aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,efcr);
7970aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,efar);
7980aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,sbec0);
7990aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,sbec1);
8000aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,ip_rev_1);
8010aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,ip_rev_2);
8020aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_bare);
8030aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_bar);
8040aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,fbpr_ar);
8050aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,srcidr);
8060aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,liodnr);
8070aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_isr);
8080aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_ier);
8090aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_isdr);
8100aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_iir);
8110aeed3e9SJustin Hibbits DUMP_VAR(p_Bm->p_BmRegs,err_ifr);
8120aeed3e9SJustin Hibbits
8130aeed3e9SJustin Hibbits return E_OK;
8140aeed3e9SJustin Hibbits }
8150aeed3e9SJustin Hibbits #endif /* (defined(DEBUG_ERRORS) && ... */
816