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 "mvSysCesa.h"
67 #if (MV_CESA_VERSION >= 2)
68 MV_TARGET tdmaAddrDecPrioTable[] =
70 #if defined(MV_INCLUDE_SDRAM_CS0)
73 #if defined(MV_INCLUDE_SDRAM_CS1)
76 #if defined(MV_INCLUDE_SDRAM_CS2)
79 #if defined(MV_INCLUDE_SDRAM_CS3)
82 #if defined(MV_INCLUDE_PEX)
89 /*******************************************************************************
90 * mvCesaWinGet - Get TDMA target address window.
93 * Get TDMA target address window.
96 * winNum - TDMA target address decode window number.
99 * pDecWin - TDMA target window data structure.
102 * MV_ERROR if register parameters are invalid.
104 *******************************************************************************/
105 static MV_STATUS mvCesaWinGet(MV_U32 winNum, MV_DEC_WIN *pDecWin)
107 MV_DEC_WIN_PARAMS winParam;
108 MV_U32 sizeReg, baseReg;
110 /* Parameter checking */
111 if (winNum >= MV_CESA_TDMA_ADDR_DEC_WIN)
113 mvOsPrintf("%s : ERR. Invalid winNum %d\n",
114 __FUNCTION__, winNum);
115 return MV_NOT_SUPPORTED;
118 baseReg = MV_REG_READ( MV_CESA_TDMA_BASE_ADDR_REG(winNum) );
119 sizeReg = MV_REG_READ( MV_CESA_TDMA_WIN_CTRL_REG(winNum) );
121 /* Check if window is enabled */
122 if(sizeReg & MV_CESA_TDMA_WIN_ENABLE_MASK)
124 pDecWin->enable = MV_TRUE;
126 /* Extract window parameters from registers */
127 winParam.targetId = (sizeReg & MV_CESA_TDMA_WIN_TARGET_MASK) >> MV_CESA_TDMA_WIN_TARGET_OFFSET;
128 winParam.attrib = (sizeReg & MV_CESA_TDMA_WIN_ATTR_MASK) >> MV_CESA_TDMA_WIN_ATTR_OFFSET;
129 winParam.size = (sizeReg & MV_CESA_TDMA_WIN_SIZE_MASK) >> MV_CESA_TDMA_WIN_SIZE_OFFSET;
130 winParam.baseAddr = (baseReg & MV_CESA_TDMA_WIN_BASE_MASK);
132 /* Translate the decode window parameters to address decode struct */
133 if (MV_OK != mvCtrlParamsToAddrDec(&winParam, pDecWin))
135 mvOsPrintf("Failed to translate register parameters to CESA address" \
136 " decode window structure\n");
142 pDecWin->enable = MV_FALSE;
147 /*******************************************************************************
148 * cesaWinOverlapDetect - Detect CESA TDMA address windows overlapping
151 * An unpredicted behaviur is expected in case TDMA address decode
153 * This function detects TDMA address decode windows overlapping of a
154 * specified window. The function does not check the window itself for
155 * overlapping. The function also skipps disabled address decode windows.
158 * winNum - address decode window number.
159 * pAddrDecWin - An address decode window struct.
165 * MV_TRUE - if the given address window overlap current address
167 * MV_FALSE - otherwise, MV_ERROR if reading invalid data
170 *******************************************************************************/
171 static MV_STATUS cesaWinOverlapDetect(MV_U32 winNum, MV_ADDR_WIN *pAddrWin)
174 MV_DEC_WIN addrDecWin;
176 for(winNumIndex=0; winNumIndex<MV_CESA_TDMA_ADDR_DEC_WIN; winNumIndex++)
178 /* Do not check window itself */
179 if (winNumIndex == winNum)
184 /* Get window parameters */
185 if (MV_OK != mvCesaWinGet(winNumIndex, &addrDecWin))
187 mvOsPrintf("%s: ERR. TargetWinGet failed\n", __FUNCTION__);
191 /* Do not check disabled windows */
192 if(addrDecWin.enable == MV_FALSE)
197 if (MV_TRUE == ctrlWinOverlapTest(pAddrWin, &(addrDecWin.addrWin)))
205 /*******************************************************************************
206 * mvCesaTdmaWinSet - Set CESA TDMA target address window
209 * This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
210 * address window, also known as address decode window.
211 * After setting this target window, the CESA TDMA will be able to access the
212 * target within the address window.
215 * winNum - CESA TDMA target address decode window number.
216 * pAddrDecWin - CESA TDMA target window data structure.
222 * MV_ERROR - if address window overlapps with other address decode windows.
223 * MV_BAD_PARAM - if base address is invalid parameter or target is
226 *******************************************************************************/
227 static MV_STATUS mvCesaTdmaWinSet(MV_U32 winNum, MV_DEC_WIN *pDecWin)
229 MV_DEC_WIN_PARAMS winParams;
230 MV_U32 sizeReg, baseReg;
232 /* Parameter checking */
233 if (winNum >= MV_CESA_TDMA_ADDR_DEC_WIN)
235 mvOsPrintf("mvCesaTdmaWinSet: ERR. Invalid win num %d\n",winNum);
239 /* Check if the requested window overlapps with current windows */
240 if (MV_TRUE == cesaWinOverlapDetect(winNum, &pDecWin->addrWin))
242 mvOsPrintf("%s: ERR. Window %d overlap\n", __FUNCTION__, winNum);
246 /* check if address is aligned to the size */
247 if(MV_IS_NOT_ALIGN(pDecWin->addrWin.baseLow, pDecWin->addrWin.size))
249 mvOsPrintf("mvCesaTdmaWinSet: Error setting CESA TDMA window %d to "\
250 "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
252 mvCtrlTargetNameGet(pDecWin->target),
253 pDecWin->addrWin.baseLow,
254 pDecWin->addrWin.size);
258 if(MV_OK != mvCtrlAddrDecToParams(pDecWin, &winParams))
260 mvOsPrintf("%s: mvCtrlAddrDecToParams Failed\n", __FUNCTION__);
264 /* set Size, Attributes and TargetID */
265 sizeReg = (((winParams.targetId << MV_CESA_TDMA_WIN_TARGET_OFFSET) & MV_CESA_TDMA_WIN_TARGET_MASK) |
266 ((winParams.attrib << MV_CESA_TDMA_WIN_ATTR_OFFSET) & MV_CESA_TDMA_WIN_ATTR_MASK) |
267 ((winParams.size << MV_CESA_TDMA_WIN_SIZE_OFFSET) & MV_CESA_TDMA_WIN_SIZE_MASK));
269 if (pDecWin->enable == MV_TRUE)
271 sizeReg |= MV_CESA_TDMA_WIN_ENABLE_MASK;
275 sizeReg &= ~MV_CESA_TDMA_WIN_ENABLE_MASK;
278 /* Update Base value */
279 baseReg = (winParams.baseAddr & MV_CESA_TDMA_WIN_BASE_MASK);
281 MV_REG_WRITE( MV_CESA_TDMA_WIN_CTRL_REG(winNum), sizeReg);
282 MV_REG_WRITE( MV_CESA_TDMA_BASE_ADDR_REG(winNum), baseReg);
288 static MV_STATUS mvCesaTdmaAddrDecInit (void)
292 MV_CPU_DEC_WIN cpuAddrDecWin;
294 MV_U32 winPrioIndex = 0;
296 /* First disable all address decode windows */
297 for(winNum=0; winNum<MV_CESA_TDMA_ADDR_DEC_WIN; winNum++)
299 MV_REG_BIT_RESET(MV_CESA_TDMA_WIN_CTRL_REG(winNum), MV_CESA_TDMA_WIN_ENABLE_MASK);
302 /* Go through all windows in user table until table terminator */
304 while( (tdmaAddrDecPrioTable[winPrioIndex] != TBL_TERM) &&
305 (winNum < MV_CESA_TDMA_ADDR_DEC_WIN) ) {
307 /* first get attributes from CPU If */
308 status = mvCpuIfTargetWinGet(tdmaAddrDecPrioTable[winPrioIndex],
310 if(MV_NO_SUCH == status){
317 mvOsPrintf("cesaInit: TargetWinGet failed. winNum=%d, winIdx=%d, target=%d, status=0x%x\n",
318 winNum, winPrioIndex, tdmaAddrDecPrioTable[winPrioIndex], status);
321 if (cpuAddrDecWin.enable == MV_TRUE)
323 cesaWin.addrWin.baseHigh = cpuAddrDecWin.addrWin.baseHigh;
324 cesaWin.addrWin.baseLow = cpuAddrDecWin.addrWin.baseLow;
325 cesaWin.addrWin.size = cpuAddrDecWin.addrWin.size;
326 cesaWin.enable = MV_TRUE;
327 cesaWin.target = tdmaAddrDecPrioTable[winPrioIndex];
330 /* Get the default attributes for that target window */
331 mvCtrlDefAttribGet(cesaWin.target, &cesaWin.addrWinAttr);
334 if(MV_OK != mvCesaTdmaWinSet(winNum, &cesaWin))
336 mvOsPrintf("mvCesaTdmaWinSet FAILED: winNum=%d\n",
346 #endif /* MV_CESA_VERSION >= 2 */
351 MV_STATUS mvCesaInit (int numOfSession, int queueDepth, char* pSramBase, void *osHandle)
353 MV_U32 cesaCryptEngBase;
354 MV_CPU_DEC_WIN addrDecWin;
356 if(sizeof(MV_CESA_SRAM_MAP) > MV_CESA_SRAM_SIZE)
358 mvOsPrintf("mvCesaInit: Wrong SRAM map - %ld > %d\n",
359 sizeof(MV_CESA_SRAM_MAP), MV_CESA_SRAM_SIZE);
363 if (mvCpuIfTargetWinGet(CRYPT_ENG, &addrDecWin) == MV_OK)
364 cesaCryptEngBase = addrDecWin.addrWin.baseLow;
367 mvOsPrintf("mvCesaInit: ERR. mvCpuIfTargetWinGet failed\n");
371 cesaCryptEngBase = (MV_U32)pSramBase;
374 #if 0 /* Already done in the platform init */
375 #if (MV_CESA_VERSION >= 2)
376 mvCesaTdmaAddrDecInit();
377 #endif /* MV_CESA_VERSION >= 2 */
379 return mvCesaHalInit(numOfSession, queueDepth, pSramBase, cesaCryptEngBase,