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