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 *******************************************************************************/
69 #include "ctrlEnv/mvCtrlEnvLib.h"
70 #include "cpu/mvCpu.h"
71 #include "ctrlEnv/sys/mvCpuIf.h"
72 #include "sata/CoreDriver/mvRegs.h"
73 #include "ctrlEnv/sys/mvSysSata.h"
75 MV_TARGET sataAddrDecPrioTab
[] =
77 #if defined(MV_INCLUDE_SDRAM_CS0)
80 #if defined(MV_INCLUDE_SDRAM_CS1)
83 #if defined(MV_INCLUDE_SDRAM_CS2)
86 #if defined(MV_INCLUDE_SDRAM_CS3)
89 #if defined(MV_INCLUDE_PEX)
96 /*******************************************************************************
97 * sataWinOverlapDetect - Detect SATA address windows overlapping
100 * An unpredicted behaviur is expected in case SATA address decode
102 * This function detects SATA address decode windows overlapping of a
103 * specified window. The function does not check the window itself for
104 * overlapping. The function also skipps disabled address decode windows.
107 * winNum - address decode window number.
108 * pAddrDecWin - An address decode window struct.
114 * MV_TRUE if the given address window overlap current address
115 * decode map, MV_FALSE otherwise, MV_ERROR if reading invalid data
118 *******************************************************************************/
119 static MV_STATUS
sataWinOverlapDetect(int dev
, MV_U32 winNum
,
120 MV_ADDR_WIN
*pAddrWin
)
123 MV_SATA_DEC_WIN addrDecWin
;
125 for(winNumIndex
=0; winNumIndex
<MV_SATA_MAX_ADDR_DECODE_WIN
; winNumIndex
++)
127 /* Do not check window itself */
128 if (winNumIndex
== winNum
)
133 /* Get window parameters */
134 if (MV_OK
!= mvSataWinGet(dev
, winNumIndex
, &addrDecWin
))
136 mvOsPrintf("%s: ERR. TargetWinGet failed\n", __FUNCTION__
);
140 /* Do not check disabled windows */
141 if(addrDecWin
.enable
== MV_FALSE
)
146 if (MV_TRUE
== ctrlWinOverlapTest(pAddrWin
, &(addrDecWin
.addrWin
)))
155 /*******************************************************************************
156 * mvSataWinSet - Set SATA target address window
159 * This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
160 * address window, also known as address decode window.
161 * After setting this target window, the SATA will be able to access the
162 * target within the address window.
165 * winNum - SATA target address decode window number.
166 * pAddrDecWin - SATA target window data structure.
172 * MV_ERROR if address window overlapps with other address decode windows.
173 * MV_BAD_PARAM if base address is invalid parameter or target is
176 *******************************************************************************/
177 MV_STATUS
mvSataWinSet(int dev
, MV_U32 winNum
, MV_SATA_DEC_WIN
*pAddrDecWin
)
179 MV_TARGET_ATTRIB targetAttribs
;
182 /* Parameter checking */
183 if (winNum
>= MV_SATA_MAX_ADDR_DECODE_WIN
)
185 mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__
, winNum
);
189 /* Check if the requested window overlapps with current windows */
190 if (MV_TRUE
== sataWinOverlapDetect(dev
, winNum
, &pAddrDecWin
->addrWin
))
192 mvOsPrintf("%s: ERR. Window %d overlap\n", __FUNCTION__
, winNum
);
196 /* check if address is aligned to the size */
197 if(MV_IS_NOT_ALIGN(pAddrDecWin
->addrWin
.baseLow
, pAddrDecWin
->addrWin
.size
))
199 mvOsPrintf("mvSataWinSet:Error setting SATA window %d to "\
200 "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
202 mvCtrlTargetNameGet(pAddrDecWin
->target
),
203 pAddrDecWin
->addrWin
.baseLow
,
204 pAddrDecWin
->addrWin
.size
);
211 if (MV_OK
!= mvCtrlAddrDecToReg(&(pAddrDecWin
->addrWin
),&decRegs
))
213 mvOsPrintf("%s: mvCtrlAddrDecToReg Failed\n", __FUNCTION__
);
217 mvCtrlAttribGet(pAddrDecWin
->target
, &targetAttribs
);
220 decRegs
.sizeReg
&= ~MV_SATA_WIN_ATTR_MASK
;
221 decRegs
.sizeReg
|= (targetAttribs
.attrib
<< MV_SATA_WIN_ATTR_OFFSET
);
224 decRegs
.sizeReg
&= ~MV_SATA_WIN_TARGET_MASK
;
225 decRegs
.sizeReg
|= (targetAttribs
.targetId
<< MV_SATA_WIN_TARGET_OFFSET
);
227 if (pAddrDecWin
->enable
== MV_TRUE
)
229 decRegs
.sizeReg
|= MV_SATA_WIN_ENABLE_MASK
;
233 decRegs
.sizeReg
&= ~MV_SATA_WIN_ENABLE_MASK
;
236 MV_REG_WRITE( MV_SATA_WIN_CTRL_REG(dev
, winNum
), decRegs
.sizeReg
);
237 MV_REG_WRITE( MV_SATA_WIN_BASE_REG(dev
, winNum
), decRegs
.baseReg
);
242 /*******************************************************************************
243 * mvSataWinGet - Get SATA peripheral target address window.
246 * Get SATA peripheral target address window.
249 * winNum - SATA target address decode window number.
252 * pAddrDecWin - SATA target window data structure.
255 * MV_ERROR if register parameters are invalid.
257 *******************************************************************************/
258 MV_STATUS
mvSataWinGet(int dev
, MV_U32 winNum
, MV_SATA_DEC_WIN
*pAddrDecWin
)
261 MV_TARGET_ATTRIB targetAttrib
;
263 /* Parameter checking */
264 if (winNum
>= MV_SATA_MAX_ADDR_DECODE_WIN
)
266 mvOsPrintf("%s (dev=%d): ERR. Invalid winNum %d\n",
267 __FUNCTION__
, dev
, winNum
);
268 return MV_NOT_SUPPORTED
;
271 decRegs
.baseReg
= MV_REG_READ( MV_SATA_WIN_BASE_REG(dev
, winNum
) );
272 decRegs
.sizeReg
= MV_REG_READ( MV_SATA_WIN_CTRL_REG(dev
, winNum
) );
274 if (MV_OK
!= mvCtrlRegToAddrDec(&decRegs
, &pAddrDecWin
->addrWin
) )
276 mvOsPrintf("%s: mvCtrlRegToAddrDec Failed\n", __FUNCTION__
);
280 /* attrib and targetId */
281 targetAttrib
.attrib
= (decRegs
.sizeReg
& MV_SATA_WIN_ATTR_MASK
) >>
282 MV_SATA_WIN_ATTR_OFFSET
;
283 targetAttrib
.targetId
= (decRegs
.sizeReg
& MV_SATA_WIN_TARGET_MASK
) >>
284 MV_SATA_WIN_TARGET_OFFSET
;
286 pAddrDecWin
->target
= mvCtrlTargetGet(&targetAttrib
);
288 /* Check if window is enabled */
289 if(decRegs
.sizeReg
& MV_SATA_WIN_ENABLE_MASK
)
291 pAddrDecWin
->enable
= MV_TRUE
;
295 pAddrDecWin
->enable
= MV_FALSE
;
299 /*******************************************************************************
300 * mvSataAddrDecShow - Print the SATA address decode map.
303 * This function print the SATA address decode map.
314 *******************************************************************************/
315 MV_VOID
mvSataAddrDecShow(MV_VOID
)
323 for( j
= 0; j
< MV_SATA_MAX_CHAN
; j
++ )
325 if (MV_FALSE
== mvCtrlPwrClckGet(SATA_UNIT_ID
, j
))
329 mvOsOutput( "SATA %d:\n", j
);
330 mvOsOutput( "----\n" );
332 for( i
= 0; i
< MV_SATA_MAX_ADDR_DECODE_WIN
; i
++ )
334 memset( &win
, 0, sizeof(MV_SATA_DEC_WIN
) );
336 mvOsOutput( "win%d - ", i
);
338 if( mvSataWinGet(j
, i
, &win
) == MV_OK
)
342 mvOsOutput( "%s base %08x, ",
343 mvCtrlTargetNameGet(win
.target
), win
.addrWin
.baseLow
);
344 mvOsOutput( "...." );
346 mvSizePrint( win
.addrWin
.size
);
351 mvOsOutput( "disable\n" );
358 /*******************************************************************************
359 * mvSataWinInit - Initialize the integrated SATA target address window.
362 * Initialize the SATA peripheral target address window.
371 * MV_ERROR if register parameters are invalid.
373 *******************************************************************************/
374 MV_STATUS
mvSataWinInit(MV_VOID
)
377 MV_SATA_DEC_WIN sataWin
;
378 MV_CPU_DEC_WIN cpuAddrDecWin
;
379 MV_U32 status
, winPrioIndex
= 0;
381 /* Initiate Sata address decode */
383 /* First disable all address decode windows */
384 for(winNum
= 0; winNum
< MV_SATA_MAX_ADDR_DECODE_WIN
; winNum
++)
386 MV_U32 regVal
= MV_REG_READ(MV_SATA_WIN_CTRL_REG(0, winNum
));
387 regVal
&= ~MV_SATA_WIN_ENABLE_MASK
;
388 MV_REG_WRITE(MV_SATA_WIN_CTRL_REG(0, winNum
), regVal
);
392 while( (sataAddrDecPrioTab
[winPrioIndex
] != TBL_TERM
) &&
393 (winNum
< MV_SATA_MAX_ADDR_DECODE_WIN
) )
395 /* first get attributes from CPU If */
396 status
= mvCpuIfTargetWinGet(sataAddrDecPrioTab
[winPrioIndex
],
399 if(MV_NO_SUCH
== status
)
406 mvOsPrintf("%s: ERR. mvCpuIfTargetWinGet failed\n", __FUNCTION__
);
410 if (cpuAddrDecWin
.enable
== MV_TRUE
)
412 sataWin
.addrWin
.baseHigh
= cpuAddrDecWin
.addrWin
.baseHigh
;
413 sataWin
.addrWin
.baseLow
= cpuAddrDecWin
.addrWin
.baseLow
;
414 sataWin
.addrWin
.size
= cpuAddrDecWin
.addrWin
.size
;
415 sataWin
.enable
= MV_TRUE
;
416 sataWin
.target
= sataAddrDecPrioTab
[winPrioIndex
];
418 if(MV_OK
!= mvSataWinSet(0/*dev*/, winNum
, &sataWin
))