Exemplo n.º 1
0
/*******************************************************************************
* mvSataWinInit - Initialize the integrated SATA target address window.
*
* DESCRIPTION:
*       Initialize the SATA peripheral target address window.
*
* INPUT:
*
*
* OUTPUT:
*     
*
* RETURN:
*       MV_ERROR if register parameters are invalid.
*
*******************************************************************************/
MV_STATUS mvSataWinInit(MV_UNIT_WIN_INFO *addrWinMap)
{
    MV_U32		winNum;
    MV_UNIT_WIN_INFO	*addrDecWin;
    MV_U32		winPrioIndex = 0;

    /* Initiate Sata address decode */

    /* First disable all address decode windows */
    for(winNum = 0; winNum < MV_SATA_MAX_ADDR_DECODE_WIN; winNum++)
    {
        MV_U32  regVal = MV_REG_READ(MV_SATA_WIN_CTRL_REG(0, winNum));
        regVal &= ~MV_SATA_WIN_ENABLE_MASK;
        MV_REG_WRITE(MV_SATA_WIN_CTRL_REG(0, winNum), regVal);
    }

    winNum = 0;
    while( (sataAddrDecPrioTab[winPrioIndex] != TBL_TERM) &&
           (winNum < MV_SATA_MAX_ADDR_DECODE_WIN) )
    {
	addrDecWin = &addrWinMap[sataAddrDecPrioTab[winPrioIndex]];
        if (addrDecWin->enable == MV_TRUE)
        {
            if(MV_OK != mvSataWinWrite(0/*dev*/, winNum, addrDecWin))
            {
                return MV_ERROR;
            }
            winNum++;
        }
        winPrioIndex++;
    }
    return MV_OK;
}
Exemplo n.º 2
0
/*******************************************************************************
* mvSataWinInit - Initialize the integrated SATA target address window.
*
* DESCRIPTION:
*       Initialize the SATA peripheral target address window.
*
* INPUT:
*
*
* OUTPUT:
*
*
* RETURN:
*       MV_ERROR if register parameters are invalid.
*
*******************************************************************************/
MV_STATUS mvSataWinInit(MV_VOID)
{
    int             winNum;
    MV_SATA_DEC_WIN  sataWin;
    MV_CPU_DEC_WIN  cpuAddrDecWin;
    MV_U32          status, winPrioIndex = 0;

    /* Initiate Sata address decode */

    /* First disable all address decode windows */
    for(winNum = 0; winNum < MV_SATA_MAX_ADDR_DECODE_WIN; winNum++)
    {
        MV_U32  regVal = MV_REG_READ(MV_SATA_WIN_CTRL_REG(0, winNum));
        regVal &= ~MV_SATA_WIN_ENABLE_MASK;
        MV_REG_WRITE(MV_SATA_WIN_CTRL_REG(0, winNum), regVal);
    }

    winNum = 0;
    while( (sataAddrDecPrioTab[winPrioIndex] != TBL_TERM) &&
            (winNum < MV_SATA_MAX_ADDR_DECODE_WIN) )
    {
        /* first get attributes from CPU If */
        status = mvCpuIfTargetWinGet(sataAddrDecPrioTab[winPrioIndex],
                                     &cpuAddrDecWin);

        if(MV_NO_SUCH == status)
        {
            winPrioIndex++;
            continue;
        }
        if (MV_OK != status)
        {
            mvOsPrintf("%s: ERR. mvCpuIfTargetWinGet failed\n", __FUNCTION__);
            return MV_ERROR;
        }

        if (cpuAddrDecWin.enable == MV_TRUE)
        {
            sataWin.addrWin.baseHigh = cpuAddrDecWin.addrWin.baseHigh;
            sataWin.addrWin.baseLow  = cpuAddrDecWin.addrWin.baseLow;
            sataWin.addrWin.size     = cpuAddrDecWin.addrWin.size;
            sataWin.enable           = MV_TRUE;
            sataWin.target           = sataAddrDecPrioTab[winPrioIndex];

            if(MV_OK != mvSataWinSet(0/*dev*/, winNum, &sataWin))
            {
                return MV_ERROR;
            }
            winNum++;
        }
        winPrioIndex++;
    }
    return MV_OK;
}
Exemplo n.º 3
0
/*******************************************************************************
* mvSataWinRead - Get SATA peripheral target address window.
*
* DESCRIPTION:
*       Get SATA peripheral target address window.
*
* INPUT:
*       winNum - SATA target address decode window number.
*
* OUTPUT:
*       pAddrDecWin - SATA target window data structure.
*
* RETURN:
*       MV_ERROR if register parameters are invalid.
*
*******************************************************************************/
MV_STATUS mvSataWinRead(MV_U32 dev, MV_U32 winNum, MV_UNIT_WIN_INFO *pAddrDecWin)
{
    MV_U32  sizeReg, baseReg;
    MV_U32  sizeRegVal;

    /* Parameter checking   */
    if (winNum >= MV_SATA_MAX_ADDR_DECODE_WIN)
    {
        mvOsPrintf("%s (dev=%d): ERR. Invalid winNum %d\n", 
                    __FUNCTION__, dev, winNum);
        return MV_NOT_SUPPORTED;
    }

    baseReg = MV_REG_READ( MV_SATA_WIN_BASE_REG(dev, winNum) );
    sizeReg = MV_REG_READ( MV_SATA_WIN_CTRL_REG(dev, winNum) );


    /* Extract base address and size	*/
    sizeRegVal = (sizeReg & MV_SATA_WIN_SIZE_MASK) >> MV_SATA_WIN_SIZE_OFFSET;
    pAddrDecWin->addrWin.size = (sizeRegVal + 1) *MV_SATA_WIN_SIZE_ALIGN;
    pAddrDecWin->addrWin.baseLow = baseReg & MV_SATA_WIN_BASE_MASK;
    pAddrDecWin->addrWin.baseHigh =  0;

    /* attrib and targetId		*/
    pAddrDecWin->attrib = (sizeReg & MV_SATA_WIN_ATTR_MASK) >> MV_SATA_WIN_ATTR_OFFSET;
    pAddrDecWin->targetId = (sizeReg & MV_SATA_WIN_TARGET_MASK) >> MV_SATA_WIN_TARGET_OFFSET;

    /* Check if window is enabled	*/
    if(sizeReg & MV_SATA_WIN_ENABLE_MASK) 
        pAddrDecWin->enable = MV_TRUE;
    else
        pAddrDecWin->enable = MV_FALSE;
    return MV_OK;
}
Exemplo n.º 4
0
/*******************************************************************************
* mvSataWinWrite - Set SATA target address window
*
* DESCRIPTION:
*       This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0) 
*       address window, also known as address decode window. 
*       After setting this target window, the SATA will be able to access the 
*       target within the address window. 
*
* INPUT:
*       winNum      - SATA target address decode window number.
*       pAddrDecWin - SATA target window data structure.
*
* OUTPUT:
*       None.
*
* RETURN:
*       MV_ERROR if address window overlapps with other address decode windows.
*       MV_BAD_PARAM if base address is invalid parameter or target is 
*       unknown.
*
*******************************************************************************/
MV_STATUS mvSataWinWrite(MV_U32 dev, MV_U32 winNum, MV_UNIT_WIN_INFO *pAddrDecWin)
{
    MV_U32  sizeReg, baseReg;

    /* Parameter checking   */
    if (winNum >= MV_SATA_MAX_ADDR_DECODE_WIN)
    {
        mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__, winNum);
        return MV_BAD_PARAM;
    }
    
    /* Check if the requested window overlapps with current windows         */
    if (MV_TRUE == sataWinOverlapDetect(dev, winNum, &pAddrDecWin->addrWin))
    {
        mvOsPrintf("%s: ERR. Window %d overlap\n", __FUNCTION__, winNum);
        return MV_ERROR;
    }

    /* check if address is aligned to the size */
    if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size))
    {
	mvOsPrintf("mvSataWinSet:Error setting SATA window %d.\n"\
		   "Address 0x%08x is unaligned to size 0x%x.\n",
		   winNum,
		   pAddrDecWin->addrWin.baseLow,
		   pAddrDecWin->addrWin.size);
	return MV_ERROR;
    }

    baseReg = pAddrDecWin->addrWin.baseLow & MV_SATA_WIN_BASE_MASK;
    sizeReg = (pAddrDecWin->addrWin.size / MV_SATA_WIN_SIZE_ALIGN) - 1;
    sizeReg = sizeReg << MV_SATA_WIN_SIZE_OFFSET;

    /* set attributes */
    sizeReg &= ~MV_SATA_WIN_ATTR_MASK;
    sizeReg |= (pAddrDecWin->attrib << MV_SATA_WIN_ATTR_OFFSET);

    /* set target ID */
    sizeReg &= ~MV_SATA_WIN_TARGET_MASK;
    sizeReg |= (pAddrDecWin->targetId << MV_SATA_WIN_TARGET_OFFSET);

    if (pAddrDecWin->enable == MV_TRUE)
        sizeReg |= MV_SATA_WIN_ENABLE_MASK;
    else
        sizeReg &= ~MV_SATA_WIN_ENABLE_MASK;

    MV_REG_WRITE( MV_SATA_WIN_CTRL_REG(dev, winNum), sizeReg);
    MV_REG_WRITE( MV_SATA_WIN_BASE_REG(dev, winNum), baseReg);
    
    return MV_OK;
}
Exemplo n.º 5
0
/*******************************************************************************
* mvSataWinGet - Get SATA peripheral target address window.
*
* DESCRIPTION:
*       Get SATA peripheral target address window.
*
* INPUT:
*       winNum - SATA target address decode window number.
*
* OUTPUT:
*       pAddrDecWin - SATA target window data structure.
*
* RETURN:
*       MV_ERROR if register parameters are invalid.
*
*******************************************************************************/
MV_STATUS mvSataWinGet(int dev, MV_U32 winNum, MV_SATA_DEC_WIN *pAddrDecWin)
{
    MV_DEC_REGS         decRegs;
    MV_TARGET_ATTRIB    targetAttrib;

    /* Parameter checking   */
    if (winNum >= MV_SATA_MAX_ADDR_DECODE_WIN)
    {
        mvOsPrintf("%s (dev=%d): ERR. Invalid winNum %d\n",
                   __FUNCTION__, dev, winNum);
        return MV_NOT_SUPPORTED;
    }

    decRegs.baseReg = MV_REG_READ( MV_SATA_WIN_BASE_REG(dev, winNum) );
    decRegs.sizeReg = MV_REG_READ( MV_SATA_WIN_CTRL_REG(dev, winNum) );

    if (MV_OK != mvCtrlRegToAddrDec(&decRegs, &pAddrDecWin->addrWin) )
    {
        mvOsPrintf("%s: mvCtrlRegToAddrDec Failed\n", __FUNCTION__);
        return MV_ERROR;
    }

    /* attrib and targetId */
    targetAttrib.attrib = (decRegs.sizeReg & MV_SATA_WIN_ATTR_MASK) >>
                          MV_SATA_WIN_ATTR_OFFSET;
    targetAttrib.targetId = (decRegs.sizeReg & MV_SATA_WIN_TARGET_MASK) >>
                            MV_SATA_WIN_TARGET_OFFSET;

    pAddrDecWin->target = mvCtrlTargetGet(&targetAttrib);

    /* Check if window is enabled   */
    if(decRegs.sizeReg & MV_SATA_WIN_ENABLE_MASK)
    {
        pAddrDecWin->enable = MV_TRUE;
    }
    else
    {
        pAddrDecWin->enable = MV_FALSE;
    }
    return MV_OK;
}
Exemplo n.º 6
0
/*******************************************************************************
* mvSataWinSet - Set SATA target address window
*
* DESCRIPTION:
*       This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
*       address window, also known as address decode window.
*       After setting this target window, the SATA will be able to access the
*       target within the address window.
*
* INPUT:
*       winNum      - SATA target address decode window number.
*       pAddrDecWin - SATA target window data structure.
*
* OUTPUT:
*       None.
*
* RETURN:
*       MV_ERROR if address window overlapps with other address decode windows.
*       MV_BAD_PARAM if base address is invalid parameter or target is
*       unknown.
*
*******************************************************************************/
MV_STATUS mvSataWinSet(int dev, MV_U32 winNum, MV_SATA_DEC_WIN *pAddrDecWin)
{
    MV_TARGET_ATTRIB    targetAttribs;
    MV_DEC_REGS         decRegs;

    /* Parameter checking   */
    if (winNum >= MV_SATA_MAX_ADDR_DECODE_WIN)
    {
        mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__, winNum);
        return MV_BAD_PARAM;
    }

    /* Check if the requested window overlapps with current windows         */
    if (MV_TRUE == sataWinOverlapDetect(dev, winNum, &pAddrDecWin->addrWin))
    {
        mvOsPrintf("%s: ERR. Window %d overlap\n", __FUNCTION__, winNum);
        return MV_ERROR;
    }

    /* check if address is aligned to the size */
    if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size))
    {
        mvOsPrintf("mvSataWinSet:Error setting SATA window %d to "\
                   "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
                   winNum,
                   mvCtrlTargetNameGet(pAddrDecWin->target),
                   pAddrDecWin->addrWin.baseLow,
                   pAddrDecWin->addrWin.size);
        return MV_ERROR;
    }

    decRegs.baseReg = 0;
    decRegs.sizeReg = 0;

    if (MV_OK != mvCtrlAddrDecToReg(&(pAddrDecWin->addrWin),&decRegs))
    {
        mvOsPrintf("%s: mvCtrlAddrDecToReg Failed\n", __FUNCTION__);
        return MV_ERROR;
    }

    mvCtrlAttribGet(pAddrDecWin->target, &targetAttribs);

    /* set attributes */
    decRegs.sizeReg &= ~MV_SATA_WIN_ATTR_MASK;
    decRegs.sizeReg |= (targetAttribs.attrib << MV_SATA_WIN_ATTR_OFFSET);

    /* set target ID */
    decRegs.sizeReg &= ~MV_SATA_WIN_TARGET_MASK;
    decRegs.sizeReg |= (targetAttribs.targetId << MV_SATA_WIN_TARGET_OFFSET);

    if (pAddrDecWin->enable == MV_TRUE)
    {
        decRegs.sizeReg |= MV_SATA_WIN_ENABLE_MASK;
    }
    else
    {
        decRegs.sizeReg &= ~MV_SATA_WIN_ENABLE_MASK;
    }

    MV_REG_WRITE( MV_SATA_WIN_CTRL_REG(dev, winNum), decRegs.sizeReg);
    MV_REG_WRITE( MV_SATA_WIN_BASE_REG(dev, winNum), decRegs.baseReg);

    return MV_OK;
}