/*******************************************************************************
* mvTsuWinEnable - Enable/disable a TS address decode window
*
* DESCRIPTION:
*       This function enable/disable a TS address decode window.
*
* INPUT:
*       winNum - Decode window number.
*       enable - Enable/disable parameter.
*
* OUTPUT:
*       None.
*
* RETURN:
*       MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
*
*******************************************************************************/
MV_STATUS mvTsuWinEnable(MV_U32 winNum, MV_BOOL enable)
{
    MV_UNIT_WIN_INFO	addrDecWin;

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

    if (enable == MV_TRUE) {
	/* Get current window */
	if (MV_OK != mvTsuWinRead(0, winNum, &addrDecWin)) {
	    DB(mvOsPrintf("%s: ERR. targetWinGet fail\n", __FUNCTION__));
	    return MV_ERROR;
	}

	/* Check for overlapping */
	if (MV_TRUE == tsuWinOverlapDetect(winNum, &(addrDecWin.addrWin))) {
	    /* Overlap detected	*/
	    DB(mvOsPrintf("%s: ERR. Overlap detected\n", __FUNCTION__));
	    return MV_ERROR;
	}

	/* No Overlap. Enable address decode target window */
	MV_REG_BIT_SET(MV_TSU_WIN_CTRL_REG(winNum), TSU_WIN_CTRL_EN_MASK);
    } else {
	/* Disable address decode target window */
	MV_REG_BIT_RESET(MV_TSU_WIN_CTRL_REG(winNum), TSU_WIN_CTRL_EN_MASK);
    }

    return MV_OK;                  
}
/*******************************************************************************
* mvTsuWinWrite
*
* 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 TSU will be able to access the
*       target within the address window.
*
* INPUT:
*	unit	    - The Unit ID.
*       winNum      - TSU to target address decode window number.
*       pAddrDecWin - TSU 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 mvTsuWinWrite(MV_U32 unit, MV_U32 winNum, MV_UNIT_WIN_INFO *pAddrDecWin)
{
	MV_U32  sizeReg, baseReg;

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

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

	/* check if address is aligned to the size */
	if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow,pAddrDecWin->addrWin.size))
	{
		mvOsPrintf("mvTsuWinSet: Error setting TSU 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 & TSU_WIN_BASE_MASK;
	sizeReg = (pAddrDecWin->addrWin.size / TSU_WIN_SIZE_ALIGN) - 1;
	sizeReg = (sizeReg << TSU_WIN_CTRL_SIZE_OFFS) & TSU_WIN_CTRL_SIZE_MASK;

	/* set attributes */
	baseReg &= ~TSU_WIN_CTRL_ATTR_MASK;
	baseReg |= pAddrDecWin->attrib << TSU_WIN_CTRL_ATTR_OFFS;
	/* set target ID */
	baseReg &= ~TSU_WIN_CTRL_TARGET_MASK;
	baseReg |= pAddrDecWin->targetId << TSU_WIN_CTRL_TARGET_OFFS;

	/* for the safe side we disable the window before writing the new */
	/* values */
	mvTsuWinEnable(winNum, MV_FALSE);
	MV_REG_WRITE(MV_TSU_WIN_CTRL_REG(winNum), sizeReg);

	/* Write to address decode Size Register                            */
	MV_REG_WRITE(MV_TSU_WIN_BASE_REG(winNum), baseReg);

	/* Enable address decode target window                              */
	if(pAddrDecWin->enable == MV_TRUE)
	{
		mvTsuWinEnable(winNum,MV_TRUE);
	}

	return MV_OK;
}
Example #3
0
/*******************************************************************************
* mvTsuWinEnable
*
* DESCRIPTION:
*       This function enable/disable a TSU to target address window.
*       According to parameter 'enable' the routine will enable the
*       window, thus enabling TSU accesses (before enabling the window it is
*       tested for overlapping). Otherwise, the window will be disabled.
*
* INPUT:
*       winNum - TSU to target address decode window number.
*       enable - Enable / disable parameter.
*
* OUTPUT:
*       N/A
*
* RETURN:
*       MV_ERROR if decode window number was wrong or enabled window overlapps.
*
*******************************************************************************/
MV_STATUS mvTsuWinEnable(MV_U32 winNum,MV_BOOL enable)
{
	MV_TSU_DEC_WIN addrDecWin;

	/* Parameter checking   */
	if(winNum >= TSU_MAX_DECODE_WIN)
	{
		mvOsPrintf("mvTsuWinEnable: ERR. Invalid winNum%d\n",winNum);
		return MV_ERROR;
	}

	if(enable == MV_TRUE)
	{
		/* First check for overlap with other enabled windows   */
		/* Get current window.					*/
		if(MV_OK != mvTsuWinGet(winNum,&addrDecWin))
		{
			mvOsPrintf("mvTsuWinEnable: ERR. targetWinGet fail\n");
			return MV_ERROR;
		}
		/* Check for overlapping.	*/
		if(MV_FALSE == tsuWinOverlapDetect(winNum,&(addrDecWin.addrWin)))
		{
			/* No Overlap. Enable address decode target window   */
			MV_REG_BIT_SET(MV_TSU_WIN_CTRL_REG(winNum),
				       TSU_WIN_CTRL_EN_MASK);
		}
		else
		{
			/* Overlap detected */
			mvOsPrintf("mvTsuWinEnable: ERR. Overlap detected\n");
			return MV_ERROR;
		}
	}
	else
	{
		/* Disable address decode target window */
		MV_REG_BIT_RESET(MV_TSU_WIN_CTRL_REG(winNum),
				 TSU_WIN_CTRL_EN_MASK);
	}
	return MV_OK;
}
Example #4
0
/*******************************************************************************
* mvTsuWinSet
*
* 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 TSU will be able to access the
*       target within the address window.
*
* INPUT:
*       winNum      - TSU to target address decode window number.
*       pAddrDecWin - TSU 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 mvTsuWinSet(MV_U32 winNum, MV_TSU_DEC_WIN *pAddrDecWin)
{
	MV_TARGET_ATTRIB    targetAttribs;
	MV_DEC_REGS         decRegs;

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

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

	/* check if address is aligned to the size */
	if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow,pAddrDecWin->addrWin.size))
	{
		mvOsPrintf("mvTsuWinSet: Error setting TSU 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 = MV_REG_READ(MV_TSU_WIN_BASE_REG(winNum));
	decRegs.sizeReg = MV_REG_READ(MV_TSU_WIN_CTRL_REG(winNum));

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

	mvCtrlAttribGet(pAddrDecWin->target,&targetAttribs);

	/* set attributes */
	decRegs.sizeReg &= ~TSU_WIN_CTRL_ATTR_MASK;
	decRegs.sizeReg |= targetAttribs.attrib << TSU_WIN_CTRL_ATTR_OFFS;
	/* set target ID */
	decRegs.sizeReg &= ~TSU_WIN_CTRL_TARGET_MASK;
	decRegs.sizeReg |= targetAttribs.targetId << TSU_WIN_CTRL_TARGET_OFFS;

	/* for the safe side we disable the window before writing the new */
	/* values */
	mvTsuWinEnable(winNum, MV_FALSE);
	MV_REG_WRITE(MV_TSU_WIN_CTRL_REG(winNum),decRegs.sizeReg);

	/* Write to address decode Size Register                            */
	MV_REG_WRITE(MV_TSU_WIN_BASE_REG(winNum), decRegs.baseReg);

	/* Enable address decode target window                              */
	if(pAddrDecWin->enable == MV_TRUE)
	{
		mvTsuWinEnable(winNum,MV_TRUE);
	}

	return MV_OK;
}