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 *******************************************************************************/
65 #include "xor/mvXor.h"
76 static MV_STATUS
xorWinOverlapDetect(MV_U32 unit
,MV_U32 winNum
, MV_ADDR_WIN
*pAddrWin
);
78 MV_TARGET xorAddrDecPrioTap
[] =
80 #if defined(MV_INCLUDE_DEVICE_CS0)
83 #if defined(MV_INCLUDE_PEX)
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_CS1)
101 #if defined(MV_INCLUDE_CESA)
106 static MV_STATUS
mvXorInitWinsUnit (MV_U32 unit
)
109 MV_XOR_DEC_WIN addrDecWin
;
110 MV_CPU_DEC_WIN cpuAddrDecWin
;
112 MV_U32 winPrioIndex
=0;
114 /* Initiate XOR address decode */
116 /* First disable all address decode windows */
117 for(winNum
= 0; winNum
< XOR_MAX_ADDR_DEC_WIN
; winNum
++)
119 mvXorTargetWinEnable(unit
,winNum
, MV_FALSE
);
122 /* Go through all windows in user table until table terminator */
123 for (winNum
= 0; ((xorAddrDecPrioTap
[winPrioIndex
] != TBL_TERM
) &&
124 (winNum
< XOR_MAX_ADDR_DEC_WIN
));)
126 /* first get attributes from CPU If */
127 status
= mvCpuIfTargetWinGet(xorAddrDecPrioTap
[winPrioIndex
],
130 if(MV_NO_SUCH
== status
)
137 mvOsPrintf("%s: ERR. mvCpuIfTargetWinGet failed\n", __FUNCTION__
);
142 if (cpuAddrDecWin
.enable
== MV_TRUE
)
145 addrDecWin
.target
= xorAddrDecPrioTap
[winPrioIndex
];
146 addrDecWin
.addrWin
.baseLow
= cpuAddrDecWin
.addrWin
.baseLow
;
147 addrDecWin
.addrWin
.baseHigh
= cpuAddrDecWin
.addrWin
.baseHigh
;
148 addrDecWin
.addrWin
.size
= cpuAddrDecWin
.addrWin
.size
;
149 addrDecWin
.enable
= MV_TRUE
;
151 if (MV_OK
!= mvXorTargetWinSet(unit
,winNum
, &addrDecWin
))
153 DB(mvOsPrintf("mvXorInit: ERR. mvDmaTargetWinSet failed\n"));
166 /*******************************************************************************
167 * mvXorInit - Initialize XOR engine
170 * This function initialize XOR unit. It set the default address decode
171 * windows of the unit.
172 * Note that if the address window is disabled in xorAddrDecMap, the
173 * window parameters will be set but the window will remain disabled.
182 * MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
183 *******************************************************************************/
184 MV_STATUS
mvXorInit (MV_VOID
)
188 /* Initiate XOR address decode */
189 for(i
= 0; i
< MV_XOR_MAX_UNIT
; i
++)
190 mvXorInitWinsUnit(i
);
192 mvXorHalInit(MV_XOR_MAX_CHAN
);
197 /*******************************************************************************
198 * mvXorTargetWinSet - Set XOR target address window
201 * This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
202 * address window. After setting this target window, the XOR will be
203 * able to access the target within the address window.
206 * winNum - One of the possible XOR memory decode windows.
207 * target - Peripheral target enumerator.
208 * base - Window base address.
209 * size - Window size.
210 * enable - Window enable/disable.
216 * MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
218 *******************************************************************************/
219 MV_STATUS
mvXorTargetWinSet(MV_U32 unit
, MV_U32 winNum
, MV_XOR_DEC_WIN
*pAddrDecWin
)
221 MV_DEC_REGS xorDecRegs
;
222 MV_TARGET_ATTRIB targetAttribs
;
225 /* Parameter checking */
226 if (winNum
>= XOR_MAX_ADDR_DEC_WIN
)
228 DB(mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__
, winNum
));
231 if (pAddrDecWin
== NULL
)
233 DB(mvOsPrintf("%s: ERR. pAddrDecWin is NULL pointer\n", __FUNCTION__
));
236 /* Check if the requested window overlaps with current windows */
237 if (MV_TRUE
== xorWinOverlapDetect(unit
, winNum
, &pAddrDecWin
->addrWin
))
239 DB(mvOsPrintf("%s: ERR. Window %d overlap\n",__FUNCTION__
,winNum
));
243 xorDecRegs
.baseReg
= MV_REG_READ(XOR_BASE_ADDR_REG(unit
,winNum
));
244 xorDecRegs
.sizeReg
= MV_REG_READ(XOR_SIZE_MASK_REG(unit
,winNum
));
246 /* Get Base Address and size registers values */
247 if(MV_OK
!= mvCtrlAddrDecToReg(&pAddrDecWin
->addrWin
, &xorDecRegs
))
249 DB(mvOsPrintf("%s: ERR. Invalid addr dec window\n",__FUNCTION__
));
254 mvCtrlAttribGet(pAddrDecWin
->target
,&targetAttribs
);
257 xorDecRegs
.baseReg
&= ~XEBARX_ATTR_MASK
;
258 xorDecRegs
.baseReg
|= targetAttribs
.attrib
<< XEBARX_ATTR_OFFS
;
260 xorDecRegs
.baseReg
&= ~XEBARX_TARGET_MASK
;
261 xorDecRegs
.baseReg
|= targetAttribs
.targetId
<< XEBARX_TARGET_OFFS
;
264 /* Write to address decode Base Address Register */
265 MV_REG_WRITE(XOR_BASE_ADDR_REG(unit
,winNum
), xorDecRegs
.baseReg
);
267 /* Write to Size Register */
268 MV_REG_WRITE(XOR_SIZE_MASK_REG(unit
,winNum
), xorDecRegs
.sizeReg
);
270 for (chan
= 0; chan
< MV_XOR_MAX_CHAN_PER_UNIT
; chan
++)
272 if (pAddrDecWin
->enable
)
274 MV_REG_BIT_SET(XOR_WINDOW_CTRL_REG(unit
,chan
),
275 XEXWCR_WIN_EN_MASK(winNum
));
279 MV_REG_BIT_RESET(XOR_WINDOW_CTRL_REG(unit
,chan
),
280 XEXWCR_WIN_EN_MASK(winNum
));
286 /*******************************************************************************
287 * mvXorTargetWinGet - Get xor peripheral target address window.
290 * Get xor peripheral target address window.
293 * winNum - One of the possible XOR memory decode windows.
296 * base - Window base address.
297 * size - Window size.
298 * enable - window enable/disable.
301 * MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
303 *******************************************************************************/
304 MV_STATUS
mvXorTargetWinGet(MV_U32 unit
,MV_U32 winNum
, MV_XOR_DEC_WIN
*pAddrDecWin
)
306 MV_DEC_REGS xorDecRegs
;
307 MV_TARGET_ATTRIB targetAttrib
;
308 MV_U32 chan
=0,chanWinEn
;
310 /* Parameter checking */
311 if (winNum
>= XOR_MAX_ADDR_DEC_WIN
)
313 DB(mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__
, winNum
));
317 if (NULL
== pAddrDecWin
)
319 DB(mvOsPrintf("%s: ERR. pAddrDecWin is NULL pointer\n", __FUNCTION__
));
323 chanWinEn
= MV_REG_READ(XOR_WINDOW_CTRL_REG(unit
,0)) & XEXWCR_WIN_EN_MASK(winNum
);
325 for (chan
= 0; chan
< MV_XOR_MAX_CHAN_PER_UNIT
; chan
++) /* we should scan here all channels per unit */
327 /* Check if enable bit is equal for all channels */
328 if ((MV_REG_READ(XOR_WINDOW_CTRL_REG(unit
,chan
)) &
329 XEXWCR_WIN_EN_MASK(winNum
)) != chanWinEn
)
331 mvOsPrintf("%s: ERR. Window enable field must be equal in "
332 "all channels(chan=%d)\n",__FUNCTION__
, chan
);
339 xorDecRegs
.baseReg
= MV_REG_READ(XOR_BASE_ADDR_REG(unit
,winNum
));
340 xorDecRegs
.sizeReg
= MV_REG_READ(XOR_SIZE_MASK_REG(unit
,winNum
));
342 if (MV_OK
!= mvCtrlRegToAddrDec(&xorDecRegs
, &pAddrDecWin
->addrWin
))
344 mvOsPrintf("%s: ERR. mvCtrlRegToAddrDec failed\n", __FUNCTION__
);
348 /* attrib and targetId */
349 targetAttrib
.attrib
=
350 (xorDecRegs
.baseReg
& XEBARX_ATTR_MASK
) >> XEBARX_ATTR_OFFS
;
351 targetAttrib
.targetId
=
352 (xorDecRegs
.baseReg
& XEBARX_TARGET_MASK
) >> XEBARX_TARGET_OFFS
;
355 pAddrDecWin
->target
= mvCtrlTargetGet(&targetAttrib
);
359 pAddrDecWin
->enable
= MV_TRUE
;
361 else pAddrDecWin
->enable
= MV_FALSE
;
366 /*******************************************************************************
367 * mvXorTargetWinEnable - Enable/disable a Xor address decode window
370 * This function enable/disable a XOR address decode window.
371 * if parameter 'enable' == MV_TRUE the routine will enable the
372 * window, thus enabling XOR accesses (before enabling the window it is
373 * tested for overlapping). Otherwise, the window will be disabled.
376 * winNum - Decode window number.
377 * enable - Enable/disable parameter.
383 * MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
385 *******************************************************************************/
386 MV_STATUS
mvXorTargetWinEnable(MV_U32 unit
,MV_U32 winNum
, MV_BOOL enable
)
388 MV_XOR_DEC_WIN addrDecWin
;
391 /* Parameter checking */
392 if (winNum
>= XOR_MAX_ADDR_DEC_WIN
)
394 DB(mvOsPrintf("%s: ERR. Invalid winNum%d\n", __FUNCTION__
, winNum
));
398 if (enable
== MV_TRUE
)
400 /* Get current window */
401 if (MV_OK
!= mvXorTargetWinGet(unit
,winNum
, &addrDecWin
))
403 DB(mvOsPrintf("%s: ERR. targetWinGet fail\n", __FUNCTION__
));
407 /* Check for overlapping */
408 if (MV_TRUE
== xorWinOverlapDetect(unit
,winNum
, &(addrDecWin
.addrWin
)))
410 /* Overlap detected */
411 DB(mvOsPrintf("%s: ERR. Overlap detected\n", __FUNCTION__
));
415 /* No Overlap. Enable address decode target window */
416 for (chan
= 0; chan
< MV_XOR_MAX_CHAN_PER_UNIT
; chan
++)
418 MV_REG_BIT_SET(XOR_WINDOW_CTRL_REG(unit
,chan
),
419 XEXWCR_WIN_EN_MASK(winNum
));
425 /* Disable address decode target window */
427 for (chan
= 0; chan
< MV_XOR_MAX_CHAN_PER_UNIT
; chan
++)
429 MV_REG_BIT_RESET(XOR_WINDOW_CTRL_REG(unit
,chan
),
430 XEXWCR_WIN_EN_MASK(winNum
));
438 /*******************************************************************************
439 * mvXorSetProtWinSet - Configure access attributes of a XOR engine
440 * to one of the XOR memory windows.
443 * Each engine can be configured with access attributes for each of the
444 * memory spaces. This function sets access attributes
445 * to a given window for the given engine
448 * chan - One of the possible engines.
449 * winNum - One of the possible XOR memory spaces.
450 * access - Protection access rights.
451 * write - Write rights.
457 * MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
459 *******************************************************************************/
460 MV_STATUS
mvXorProtWinSet (MV_U32 unit
,MV_U32 chan
, MV_U32 winNum
, MV_BOOL access
,
465 /* Parameter checking */
466 if (chan
>= MV_XOR_MAX_CHAN_PER_UNIT
)
468 DB(mvOsPrintf("%s: ERR. Invalid chan num %d\n", __FUNCTION__
, chan
));
471 if (winNum
>= XOR_MAX_ADDR_DEC_WIN
)
473 DB(mvOsPrintf("%s: ERR. Invalid win num %d\n", __FUNCTION__
, winNum
));
477 temp
= MV_REG_READ(XOR_WINDOW_CTRL_REG(unit
,chan
)) &
478 (~XEXWCR_WIN_ACC_MASK(winNum
));
480 /* if access is disable */
484 temp
|= XEXWCR_WIN_ACC_NO_ACC(winNum
);
486 /* if access is enable */
489 /* if write is enable */
493 temp
|= XEXWCR_WIN_ACC_RW(winNum
);
495 /* if write is disable */
499 temp
|= XEXWCR_WIN_ACC_RO(winNum
);
502 MV_REG_WRITE(XOR_WINDOW_CTRL_REG(unit
,chan
),temp
);
506 /*******************************************************************************
507 * mvXorPciRemap - Set XOR remap register for PCI address windows.
510 * only Windows 0-3 can be remapped.
513 * winNum - window number
514 * pAddrDecWin - pointer to address space window structure
519 * MV_BAD_PARAM if parameters to function invalid, MV_OK otherwise.
521 *******************************************************************************/
522 MV_STATUS
mvXorPciRemap(MV_U32 unit
,MV_U32 winNum
, MV_U32 addrHigh
)
524 /* Parameter checking */
525 if (winNum
>= XOR_MAX_REMAP_WIN
)
527 DB(mvOsPrintf("%s: ERR. Invalid win num %d\n", __FUNCTION__
, winNum
));
531 MV_REG_WRITE(XOR_HIGH_ADDR_REMAP_REG(unit
,winNum
), addrHigh
);
536 /*******************************************************************************
537 * xorWinOverlapDetect - Detect XOR address windows overlaping
540 * An unpredicted behaviour is expected in case XOR address decode
542 * This function detects XOR address decode windows overlaping of a
543 * specified window. The function does not check the window itself for
544 * overlaping. The function also skipps disabled address decode windows.
547 * winNum - address decode window number.
548 * pAddrDecWin - An address decode window struct.
554 * MV_TRUE if the given address window overlap current address
555 * decode map, MV_FALSE otherwise, MV_ERROR if reading invalid data
558 *******************************************************************************/
559 static MV_STATUS
xorWinOverlapDetect(MV_U32 unit
,MV_U32 winNum
, MV_ADDR_WIN
*pAddrWin
)
561 MV_U32 baseAddrEnableReg
;
562 MV_U32 winNumIndex
,chan
;
563 MV_XOR_DEC_WIN addrDecWin
;
565 if (pAddrWin
== NULL
)
567 DB(mvOsPrintf("%s: ERR. pAddrWin is NULL pointer\n", __FUNCTION__
));
571 for (chan
= 0; chan
< MV_XOR_MAX_CHAN_PER_UNIT
; chan
++)
573 /* Read base address enable register. Do not check disabled windows */
574 baseAddrEnableReg
= MV_REG_READ(XOR_WINDOW_CTRL_REG(unit
,chan
));
576 for (winNumIndex
= 0; winNumIndex
< XOR_MAX_ADDR_DEC_WIN
; winNumIndex
++)
578 /* Do not check window itself */
579 if (winNumIndex
== winNum
)
584 /* Do not check disabled windows */
585 if ((baseAddrEnableReg
& XEXWCR_WIN_EN_MASK(winNumIndex
)) == 0)
590 /* Get window parameters */
591 if (MV_OK
!= mvXorTargetWinGet(unit
,winNumIndex
, &addrDecWin
))
593 DB(mvOsPrintf("%s: ERR. TargetWinGet failed\n", __FUNCTION__
));
597 if (MV_TRUE
== ctrlWinOverlapTest(pAddrWin
, &(addrDecWin
.addrWin
)))
607 static MV_VOID
mvXorAddrDecShowUnit(MV_U32 unit
)
613 mvOsOutput( "XOR %d:\n", unit
);
614 mvOsOutput( "----\n" );
616 for( i
= 0; i
< XOR_MAX_ADDR_DEC_WIN
; i
++ )
618 memset( &win
, 0, sizeof(MV_XOR_DEC_WIN
) );
620 mvOsOutput( "win%d - ", i
);
622 if( mvXorTargetWinGet(unit
, i
, &win
) == MV_OK
)
626 mvOsOutput( "%s base %x, ",
627 mvCtrlTargetNameGet(win
.target
), win
.addrWin
.baseLow
);
629 mvSizePrint( win
.addrWin
.size
);
634 mvOsOutput( "disable\n" );
639 /*******************************************************************************
640 * mvXorAddrDecShow - Print the XOR address decode map.
643 * This function print the XOR address decode map.
654 *******************************************************************************/
655 MV_VOID
mvXorAddrDecShow(MV_VOID
)
659 for( i
= 0; i
< MV_XOR_MAX_UNIT
; i
++ )
660 mvXorAddrDecShowUnit(i
);