/******************************************************************************* * 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; }
/******************************************************************************* * 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; }