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 *******************************************************************************/
66 #include "ctrlEnv/sys/mvSysTs.h"
69 typedef struct _mvTsuDecWin
72 MV_ADDR_WIN addrWin
; /* An address window*/
73 MV_BOOL enable
; /* Address decode window is enabled/disabled */
78 MV_TARGET tsuAddrDecPrioTap
[] =
80 #if defined(MV_INCLUDE_PEX)
83 #if defined(MV_INCLUDE_PCI)
86 #if defined(MV_INCLUDE_SDRAM_CS0)
89 #if defined(MV_INCLUDE_SDRAM_CS1)
92 #if defined(MV_INCLUDE_SDRAM_CS2)
95 #if defined(MV_INCLUDE_SDRAM_CS3)
98 #if defined(MV_INCLUDE_DEVICE_CS0)
101 #if defined(MV_INCLUDE_DEVICE_CS1)
104 #if defined(MV_INCLUDE_DEVICE_CS2)
107 #if defined(MV_INCLUDE_DEVICE_CS3)
110 #if defined(MV_INCLUDE_PEX)
113 #if defined(MV_INCLUDE_PCI)
119 static MV_STATUS
tsuWinOverlapDetect(MV_U32 winNum
, MV_ADDR_WIN
*pAddrWin
);
120 static MV_STATUS
mvTsuWinSet(MV_U32 winNum
, MV_TSU_DEC_WIN
*pAddrDecWin
);
121 static MV_STATUS
mvTsuWinGet(MV_U32 winNum
, MV_TSU_DEC_WIN
*pAddrDecWin
);
122 MV_STATUS
mvTsuWinEnable(MV_U32 winNum
,MV_BOOL enable
);
124 /*******************************************************************************
128 * Initialize the TSU unit address decode windows.
135 * MV_OK - on success,
137 *******************************************************************************/
138 MV_STATUS
mvTsuWinInit(void)
140 MV_U32 winNum
, status
, winPrioIndex
=0;
141 MV_TSU_DEC_WIN tsuWin
;
142 MV_CPU_DEC_WIN cpuAddrDecWin
;
144 /* First disable all address decode windows */
145 for(winNum
= 0; winNum
< TSU_MAX_DECODE_WIN
; winNum
++)
147 MV_REG_BIT_RESET(MV_TSU_WIN_CTRL_REG(winNum
),
148 TSU_WIN_CTRL_EN_MASK
);
151 /* Go through all windows in user table until table terminator */
152 for(winNum
= 0; ((tsuAddrDecPrioTap
[winPrioIndex
] != TBL_TERM
) &&
153 (winNum
< TSU_MAX_DECODE_WIN
));)
155 /* first get attributes from CPU If */
156 status
= mvCpuIfTargetWinGet(tsuAddrDecPrioTap
[winPrioIndex
],
159 if(MV_NO_SUCH
== status
)
166 mvOsPrintf("mvTsuWinInit: ERR. mvCpuIfTargetWinGet failed\n");
170 if (cpuAddrDecWin
.enable
== MV_TRUE
)
172 tsuWin
.addrWin
.baseHigh
= cpuAddrDecWin
.addrWin
.baseHigh
;
173 tsuWin
.addrWin
.baseLow
= cpuAddrDecWin
.addrWin
.baseLow
;
174 tsuWin
.addrWin
.size
= cpuAddrDecWin
.addrWin
.size
;
175 tsuWin
.enable
= MV_TRUE
;
176 tsuWin
.target
= tsuAddrDecPrioTap
[winPrioIndex
];
178 if(MV_OK
!= mvTsuWinSet(winNum
, &tsuWin
))
180 mvOsPrintf("mvTsuWinInit: ERR. mvTsuWinSet failed winNum=%d\n",
193 /*******************************************************************************
197 * This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
198 * address window, also known as address decode window.
199 * After setting this target window, the TSU will be able to access the
200 * target within the address window.
203 * winNum - TSU to target address decode window number.
204 * pAddrDecWin - TSU target window data structure.
210 * MV_ERROR - if address window overlapps with other address decode
212 * MV_BAD_PARAM - if base address is invalid parameter or target is
215 *******************************************************************************/
216 MV_STATUS
mvTsuWinSet(MV_U32 winNum
, MV_TSU_DEC_WIN
*pAddrDecWin
)
218 MV_TARGET_ATTRIB targetAttribs
;
221 /* Parameter checking */
222 if(winNum
>= TSU_MAX_DECODE_WIN
)
224 mvOsPrintf("mvTsuWinSet: ERR. Invalid win num %d\n",winNum
);
228 /* Check if the requested window overlapps with current windows */
229 if(MV_TRUE
== tsuWinOverlapDetect(winNum
, &pAddrDecWin
->addrWin
))
231 mvOsPrintf("mvTsuWinSet: ERR. Window %d overlap\n", winNum
);
235 /* check if address is aligned to the size */
236 if(MV_IS_NOT_ALIGN(pAddrDecWin
->addrWin
.baseLow
,pAddrDecWin
->addrWin
.size
))
238 mvOsPrintf("mvTsuWinSet: Error setting TSU window %d to target "
239 "%s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
240 winNum
, mvCtrlTargetNameGet(pAddrDecWin
->target
),
241 pAddrDecWin
->addrWin
.baseLow
,
242 pAddrDecWin
->addrWin
.size
);
246 decRegs
.baseReg
= MV_REG_READ(MV_TSU_WIN_BASE_REG(winNum
));
247 decRegs
.sizeReg
= MV_REG_READ(MV_TSU_WIN_CTRL_REG(winNum
));
249 if(MV_OK
!= mvCtrlAddrDecToReg(&(pAddrDecWin
->addrWin
),&decRegs
))
251 mvOsPrintf("mvTsuWinSet: mvCtrlAddrDecToReg Failed\n");
255 mvCtrlAttribGet(pAddrDecWin
->target
,&targetAttribs
);
258 decRegs
.sizeReg
&= ~TSU_WIN_CTRL_ATTR_MASK
;
259 decRegs
.sizeReg
|= targetAttribs
.attrib
<< TSU_WIN_CTRL_ATTR_OFFS
;
261 decRegs
.sizeReg
&= ~TSU_WIN_CTRL_TARGET_MASK
;
262 decRegs
.sizeReg
|= targetAttribs
.targetId
<< TSU_WIN_CTRL_TARGET_OFFS
;
264 /* for the safe side we disable the window before writing the new */
266 mvTsuWinEnable(winNum
, MV_FALSE
);
267 MV_REG_WRITE(MV_TSU_WIN_CTRL_REG(winNum
),decRegs
.sizeReg
);
269 /* Write to address decode Size Register */
270 MV_REG_WRITE(MV_TSU_WIN_BASE_REG(winNum
), decRegs
.baseReg
);
272 /* Enable address decode target window */
273 if(pAddrDecWin
->enable
== MV_TRUE
)
275 mvTsuWinEnable(winNum
,MV_TRUE
);
282 /*******************************************************************************
286 * Get TSU peripheral target address window.
289 * winNum - TSU to target address decode window number.
292 * pAddrDecWin - TSU target window data structure.
295 * MV_ERROR if register parameters are invalid.
297 *******************************************************************************/
298 MV_STATUS
mvTsuWinGet(MV_U32 winNum
, MV_TSU_DEC_WIN
*pAddrDecWin
)
301 MV_TARGET_ATTRIB targetAttrib
;
303 /* Parameter checking */
304 if(winNum
>= TSU_MAX_DECODE_WIN
)
306 mvOsPrintf("mvTsuWinGet: ERR. Invalid winNum %d\n", winNum
);
307 return MV_NOT_SUPPORTED
;
310 decRegs
.baseReg
= MV_REG_READ(MV_TSU_WIN_BASE_REG(winNum
));
311 decRegs
.sizeReg
= MV_REG_READ(MV_TSU_WIN_CTRL_REG(winNum
));
313 if(MV_OK
!= mvCtrlRegToAddrDec(&decRegs
,&(pAddrDecWin
->addrWin
)))
315 mvOsPrintf("mvTsuWinGet: mvCtrlRegToAddrDec Failed \n");
319 /* attrib and targetId */
320 targetAttrib
.attrib
=
321 (decRegs
.sizeReg
& TSU_WIN_CTRL_ATTR_MASK
) >> TSU_WIN_CTRL_ATTR_OFFS
;
322 targetAttrib
.targetId
=
323 (decRegs
.sizeReg
& TSU_WIN_CTRL_TARGET_MASK
) >> TSU_WIN_CTRL_TARGET_OFFS
;
325 pAddrDecWin
->target
= mvCtrlTargetGet(&targetAttrib
);
327 /* Check if window is enabled */
328 if((MV_REG_READ(MV_TSU_WIN_CTRL_REG(winNum
)) & TSU_WIN_CTRL_EN_MASK
))
330 pAddrDecWin
->enable
= MV_TRUE
;
334 pAddrDecWin
->enable
= MV_FALSE
;
341 /*******************************************************************************
345 * This function enable/disable a TSU to target address window.
346 * According to parameter 'enable' the routine will enable the
347 * window, thus enabling TSU accesses (before enabling the window it is
348 * tested for overlapping). Otherwise, the window will be disabled.
351 * winNum - TSU to target address decode window number.
352 * enable - Enable / disable parameter.
358 * MV_ERROR if decode window number was wrong or enabled window overlapps.
360 *******************************************************************************/
361 MV_STATUS
mvTsuWinEnable(MV_U32 winNum
,MV_BOOL enable
)
363 MV_TSU_DEC_WIN addrDecWin
;
365 /* Parameter checking */
366 if(winNum
>= TSU_MAX_DECODE_WIN
)
368 mvOsPrintf("mvTsuWinEnable: ERR. Invalid winNum%d\n",winNum
);
372 if(enable
== MV_TRUE
)
374 /* First check for overlap with other enabled windows */
375 /* Get current window. */
376 if(MV_OK
!= mvTsuWinGet(winNum
,&addrDecWin
))
378 mvOsPrintf("mvTsuWinEnable: ERR. targetWinGet fail\n");
381 /* Check for overlapping. */
382 if(MV_FALSE
== tsuWinOverlapDetect(winNum
,&(addrDecWin
.addrWin
)))
384 /* No Overlap. Enable address decode target window */
385 MV_REG_BIT_SET(MV_TSU_WIN_CTRL_REG(winNum
),
386 TSU_WIN_CTRL_EN_MASK
);
390 /* Overlap detected */
391 mvOsPrintf("mvTsuWinEnable: ERR. Overlap detected\n");
397 /* Disable address decode target window */
398 MV_REG_BIT_RESET(MV_TSU_WIN_CTRL_REG(winNum
),
399 TSU_WIN_CTRL_EN_MASK
);
404 /*******************************************************************************
408 * Get Window number associated with target
411 * target - Target ID to get the window number for.
415 * window number or 0xFFFFFFFF on error.
417 *******************************************************************************/
418 MV_U32
mvTsuWinTargetGet(MV_TARGET target
)
420 MV_TSU_DEC_WIN decWin
;
423 /* Check parameters */
424 if(target
>= MAX_TARGETS
)
426 mvOsPrintf("mvTsuWinTargetGet: target %d is Illigal\n", target
);
430 for(winNum
= 0; winNum
< TSU_MAX_DECODE_WIN
; winNum
++)
432 if(mvTsuWinGet(winNum
,&decWin
) != MV_OK
)
434 mvOsPrintf("mvTsuWinGet: window returned error\n");
438 if (decWin
.enable
== MV_TRUE
)
440 if(decWin
.target
== target
)
450 /*******************************************************************************
451 * tsuWinOverlapDetect
454 * Detect TSU address windows overlapping
455 * An unpredicted behaviur is expected in case TSU address decode
457 * This function detects TSU address decode windows overlapping of a
458 * specified window. The function does not check the window itself for
459 * overlapping. The function also skipps disabled address decode windows.
462 * winNum - address decode window number.
463 * pAddrDecWin - An address decode window struct.
469 * MV_TRUE if the given address window overlap current address
470 * decode map, MV_FALSE otherwise, MV_ERROR if reading invalid data
473 *******************************************************************************/
474 static MV_STATUS
tsuWinOverlapDetect(MV_U32 winNum
, MV_ADDR_WIN
*pAddrWin
)
478 MV_TSU_DEC_WIN addrDecWin
;
480 for(winNumIndex
= 0; winNumIndex
< TSU_MAX_DECODE_WIN
; winNumIndex
++)
482 /* Do not check window itself */
483 if(winNumIndex
== winNum
)
488 /* Do not check disabled windows */
489 ctrlReg
= MV_REG_READ(MV_TSU_WIN_CTRL_REG(winNumIndex
));
490 if((ctrlReg
& TSU_WIN_CTRL_EN_MASK
) == 0)
495 /* Get window parameters */
496 if (MV_OK
!= mvTsuWinGet(winNumIndex
, &addrDecWin
))
498 mvOsPrintf("tsuWinOverlapDetect: ERR. mvTsuWinGet failed\n");
502 if (MV_TRUE
== ctrlWinOverlapTest(pAddrWin
, &(addrDecWin
.addrWin
)))
511 /*******************************************************************************
515 * Print the TSU address decode map.
526 *******************************************************************************/
527 void mvTsuAddrDecShow(void)
532 if (MV_FALSE
== mvCtrlPwrClckGet(TS_UNIT_ID
, 0))
536 mvOsOutput( "TSU:\n");
537 mvOsOutput( "----\n" );
539 for(i
= 0; i
< TSU_MAX_DECODE_WIN
; i
++)
541 memset(&win
, 0, sizeof(TSU_MAX_DECODE_WIN
));
542 mvOsOutput( "win%d - ", i
);
544 if(mvTsuWinGet(i
, &win
) == MV_OK
)
546 if(win
.enable
== MV_TRUE
)
548 mvOsOutput("%s base %08x, ",
549 mvCtrlTargetNameGet(win
.target
),
550 win
.addrWin
.baseLow
);
551 mvOsOutput( "...." );
552 mvSizePrint(win
.addrWin
.size
);
557 mvOsOutput( "disable\n" );
565 /*******************************************************************************
569 * Initialize the TSU unit, and get unit out of reset.
572 * coreClock - The core clock at which the TSU should operate.
573 * mode - The mode on configure the unit into (serial/parallel).
574 * memHandle - Memory handle used for memory allocations.
578 * MV_OK - on success,
580 *******************************************************************************/
581 MV_STATUS
mvTsuInit(MV_TSU_CORE_CLOCK coreClock
, MV_TSU_PORTS_MODE mode
,
586 status
= mvTsuWinInit();
588 status
= mvTsuHalInit(coreClock
,mode
,osHandle
);