1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
4 This software file (the "File") is owned and distributed by Marvell
5 International Ltd. and/or its affiliates ("Marvell") under the following
6 alternative licensing terms. Once you have made an election to distribute the
7 File under one of the following license alternatives, please (i) delete this
8 introductory statement regarding license alternatives, (ii) delete the two
9 license alternatives that you have not elected to use and (iii) preserve the
10 Marvell copyright notice above.
12 ********************************************************************************
13 Marvell Commercial License Option
15 If you received this File from Marvell and you have entered into a commercial
16 license agreement (a "Commercial License") with Marvell, the File is licensed
17 to you under the terms of the applicable Commercial License.
19 ********************************************************************************
20 Marvell GPL License Option
22 If you received this File from Marvell, you may opt to use, redistribute and/or
23 modify this File in accordance with the terms and conditions of the General
24 Public License Version 2, June 1991 (the "GPL License"), a copy of which is
25 available along with the File in the license.txt file or by writing to the Free
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
27 on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
29 THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
31 DISCLAIMED. The GPL License provides additional details about this warranty
33 ********************************************************************************
34 Marvell BSD License Option
36 If you received this File from Marvell, you may opt to use, redistribute and/or
37 modify this File under the following licensing terms.
38 Redistribution and use in source and binary forms, with or without modification,
39 are permitted provided that the following conditions are met:
41 * Redistributions of source code must retain the above copyright notice,
42 this list of conditions and the following disclaimer.
44 * Redistributions in binary form must reproduce the above copyright
45 notice, this list of conditions and the following disclaimer in the
46 documentation and/or other materials provided with the distribution.
48 * Neither the name of Marvell nor the names of its contributors may be
49 used to endorse or promote products derived from this software without
50 specific prior written permission.
52 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
56 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *******************************************************************************/
75 static MV_TARGET tdmAddrDecPrioTap[] =
90 static MV_STATUS tdmWinOverlapDetect(MV_U32 winNum, MV_ADDR_WIN *pAddrWin);
92 /*******************************************************************************
93 * mvTdmWinInit - Initialize TDM address decode windows
96 * This function initialize TDM window decode unit. It set the
97 * default address decode
98 * windows of the unit.
107 * MV_ERROR if setting fail.
108 *******************************************************************************/
110 MV_STATUS mvTdmWinInit(void)
113 MV_U32 winPrioIndex = 0;
114 MV_CPU_DEC_WIN cpuAddrDecWin;
115 MV_TDM_DEC_WIN tdmWin;
118 /*Disable all windows*/
119 for (winNum = 0; winNum < TDM_MBUS_MAX_WIN; winNum++)
121 mvTdmWinEnable(winNum, MV_FALSE);
124 for (winNum = 0; ((tdmAddrDecPrioTap[winPrioIndex] != TBL_TERM) &&
125 (winNum < TDM_MBUS_MAX_WIN)); )
127 status = mvCpuIfTargetWinGet(tdmAddrDecPrioTap[winPrioIndex],
129 if (MV_NO_SUCH == status)
136 mvOsPrintf("mvTdmInit: ERR. mvCpuIfTargetWinGet failed\n");
140 if (cpuAddrDecWin.enable == MV_TRUE)
142 tdmWin.addrWin.baseHigh = cpuAddrDecWin.addrWin.baseHigh;
143 tdmWin.addrWin.baseLow = cpuAddrDecWin.addrWin.baseLow;
144 tdmWin.addrWin.size = cpuAddrDecWin.addrWin.size;
145 tdmWin.enable = MV_TRUE;
146 tdmWin.target = tdmAddrDecPrioTap[winPrioIndex];
147 if (MV_OK != mvTdmWinSet(winNum, &tdmWin))
158 /*******************************************************************************
159 * mvTdmWinSet - Set TDM target address window
162 * This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
163 * address window, also known as address decode window.
164 * After setting this target window, the TDM will be able to access the
165 * target within the address window.
168 * winNum - TDM to target address decode window number.
169 * pAddrDecWin - TDM target window data structure.
175 * MV_ERROR if address window overlapps with other address decode windows.
176 * MV_BAD_PARAM if base address is invalid parameter or target is
179 *******************************************************************************/
181 MV_STATUS mvTdmWinSet(MV_U32 winNum, MV_TDM_DEC_WIN *pAddrDecWin)
183 MV_TARGET_ATTRIB targetAttribs;
187 /* Parameter checking */
188 if (winNum >= TDM_MBUS_MAX_WIN)
190 mvOsPrintf("mvTdmWinSet: ERR. Invalid win num %d\n",winNum);
194 /* Check if the requested window overlapps with current windows */
195 if (MV_TRUE == tdmWinOverlapDetect(winNum, &pAddrDecWin->addrWin))
197 mvOsPrintf("mvTdmWinSet: ERR. Window %d overlap\n", winNum);
201 /* check if address is aligned to the size */
202 if (MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size))
204 mvOsPrintf("mvTdmWinSet: Error setting TDM window %d to "\
205 "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
207 mvCtrlTargetNameGet(pAddrDecWin->target),
208 pAddrDecWin->addrWin.baseLow,
209 pAddrDecWin->addrWin.size);
213 decRegs.baseReg = MV_REG_READ(TDM_WIN_BASE_REG(winNum));
214 decRegs.sizeReg = (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_SIZE_MASK) >> TDM_WIN_SIZE_OFFS;
216 if (MV_OK != mvCtrlAddrDecToReg(&(pAddrDecWin->addrWin),&decRegs))
218 mvOsPrintf("mvTdmWinSet: mvCtrlAddrDecToReg Failed\n");
222 mvCtrlAttribGet(pAddrDecWin->target, &targetAttribs);
224 /* for the safe side we disable the window before writing the new
226 mvTdmWinEnable(winNum, MV_FALSE);
228 ctrlReg |= (targetAttribs.attrib << TDM_WIN_ATTRIB_OFFS);
229 ctrlReg |= (targetAttribs.targetId << TDM_WIN_TARGET_OFFS);
230 ctrlReg |= (decRegs.sizeReg & TDM_WIN_SIZE_MASK);
232 /* Write to address base and control registers */
233 MV_REG_WRITE(TDM_WIN_BASE_REG(winNum), decRegs.baseReg);
234 MV_REG_WRITE(TDM_WIN_CTRL_REG(winNum), ctrlReg);
235 /* Enable address decode target window */
236 if (pAddrDecWin->enable == MV_TRUE)
238 mvTdmWinEnable(winNum, MV_TRUE);
243 /*******************************************************************************
244 * mvTdmWinGet - Get peripheral target address window.
247 * Get TDM peripheral target address window.
250 * winNum - TDM to target address decode window number.
253 * pAddrDecWin - TDM target window data structure.
256 * MV_ERROR if register parameters are invalid.
258 *******************************************************************************/
260 MV_STATUS mvTdmWinGet(MV_U32 winNum, MV_TDM_DEC_WIN *pAddrDecWin)
264 MV_TARGET_ATTRIB targetAttrib;
266 /* Parameter checking */
267 if (winNum >= TDM_MBUS_MAX_WIN)
269 mvOsPrintf("mvTdmWinGet: ERR. Invalid winNum %d\n", winNum);
270 return MV_NOT_SUPPORTED;
273 decRegs.baseReg = MV_REG_READ(TDM_WIN_BASE_REG(winNum));
274 decRegs.sizeReg = (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_SIZE_MASK) >> TDM_WIN_SIZE_OFFS;
276 if (MV_OK != mvCtrlRegToAddrDec(&decRegs,&(pAddrDecWin->addrWin)))
278 mvOsPrintf("mvTdmWinGet: mvCtrlRegToAddrDec Failed \n");
282 /* attrib and targetId */
283 targetAttrib.attrib =
284 (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_ATTRIB_MASK) >> TDM_WIN_ATTRIB_OFFS;
285 targetAttrib.targetId =
286 (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_TARGET_MASK) >> TDM_WIN_TARGET_OFFS;
288 pAddrDecWin->target = mvCtrlTargetGet(&targetAttrib);
290 /* Check if window is enabled */
291 if (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_ENABLE_MASK)
293 pAddrDecWin->enable = MV_TRUE;
297 pAddrDecWin->enable = MV_FALSE;
303 /*******************************************************************************
304 * mvTdmWinEnable - Enable/disable a TDM to target address window
307 * This function enable/disable a TDM to target address window.
308 * According to parameter 'enable' the routine will enable the
309 * window, thus enabling TDM accesses (before enabling the window it is
310 * tested for overlapping). Otherwise, the window will be disabled.
313 * winNum - TDM to target address decode window number.
314 * enable - Enable/disable parameter.
320 * MV_ERROR if decode window number was wrong or enabled window overlapps.
322 *******************************************************************************/
323 MV_STATUS mvTdmWinEnable(int winNum, MV_BOOL enable)
325 MV_TDM_DEC_WIN addrDecWin;
327 if (MV_TRUE == enable)
329 if (winNum >= TDM_MBUS_MAX_WIN)
331 mvOsPrintf("mvTdmWinEnable:ERR. Invalid winNum%d\n",winNum);
335 /* First check for overlap with other enabled windows */
336 /* Get current window */
337 if (MV_OK != mvTdmWinGet(winNum, &addrDecWin))
339 mvOsPrintf("mvTdmWinEnable:ERR. targetWinGet fail\n");
342 /* Check for overlapping */
343 if (MV_FALSE == tdmWinOverlapDetect(winNum, &(addrDecWin.addrWin)))
345 /* No Overlap. Enable address decode target window */
346 MV_REG_BIT_SET(TDM_WIN_CTRL_REG(winNum), TDM_WIN_ENABLE_MASK);
349 { /* Overlap detected */
350 mvOsPrintf("mvTdmWinEnable:ERR. Overlap detected\n");
356 MV_REG_BIT_RESET(TDM_WIN_CTRL_REG(winNum), TDM_WIN_ENABLE_MASK);
362 /*******************************************************************************
363 * tdmWinOverlapDetect - Detect TDM address windows overlapping
366 * An unpredicted behaviour is expected in case TDM address decode
368 * This function detects TDM address decode windows overlapping of a
369 * specified window. The function does not check the window itself for
370 * overlapping. The function also skipps disabled address decode windows.
373 * winNum - address decode window number.
374 * pAddrDecWin - An address decode window struct.
380 * MV_TRUE if the given address window overlap current address
381 * decode map, MV_FALSE otherwise, MV_ERROR if reading invalid data
384 *******************************************************************************/
385 static MV_STATUS tdmWinOverlapDetect(MV_U32 winNum, MV_ADDR_WIN *pAddrWin)
388 MV_TDM_DEC_WIN addrDecWin;
390 for (winNumIndex = 0; winNumIndex < TDM_MBUS_MAX_WIN; winNumIndex++)
392 /* Do not check window itself */
393 if (winNumIndex == winNum)
397 /* Do not check disabled windows */
398 if (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_ENABLE_MASK)
400 /* Get window parameters */
401 if (MV_OK != mvTdmWinGet(winNumIndex, &addrDecWin))
403 DB(mvOsPrintf("dmaWinOverlapDetect: ERR. TargetWinGet failed\n"));
407 if (MV_TRUE == ctrlWinOverlapTest(pAddrWin, &(addrDecWin.addrWin)))
416 /*******************************************************************************
417 * mvTdmAddrDecShow - Print the TDM address decode map.
420 * This function print the TDM address decode map.
431 *******************************************************************************/
432 MV_VOID mvTdmAddrDecShow(MV_VOID)
438 mvOsOutput( "TDM:\n" );
439 mvOsOutput( "----\n" );
441 for( i = 0; i < TDM_MBUS_MAX_WIN; i++ )
443 memset( &win, 0, sizeof(MV_TDM_DEC_WIN) );
445 mvOsOutput( "win%d - ", i );
447 if (mvTdmWinGet(i, &win ) == MV_OK )
451 mvOsOutput( "%s base %08x, ",
452 mvCtrlTargetNameGet(win.target), win.addrWin.baseLow);
453 mvOsOutput( "...." );
454 mvSizePrint( win.addrWin.size );
458 mvOsOutput( "disable\n" );