Root/target/linux/generic/files/crypto/ocf/kirkwood/mvHal/kw_family/ctrlEnv/sys/mvSysCesa.c

1/*******************************************************************************
2Copyright (C) Marvell International Ltd. and its affiliates
3
4This software file (the "File") is owned and distributed by Marvell
5International Ltd. and/or its affiliates ("Marvell") under the following
6alternative licensing terms. Once you have made an election to distribute the
7File under one of the following license alternatives, please (i) delete this
8introductory statement regarding license alternatives, (ii) delete the two
9license alternatives that you have not elected to use and (iii) preserve the
10Marvell copyright notice above.
11
12********************************************************************************
13Marvell Commercial License Option
14
15If you received this File from Marvell and you have entered into a commercial
16license agreement (a "Commercial License") with Marvell, the File is licensed
17to you under the terms of the applicable Commercial License.
18
19********************************************************************************
20Marvell GPL License Option
21
22If you received this File from Marvell, you may opt to use, redistribute and/or
23modify this File in accordance with the terms and conditions of the General
24Public License Version 2, June 1991 (the "GPL License"), a copy of which is
25available along with the File in the license.txt file or by writing to the Free
26Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
27on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
28
29THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
30WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
31DISCLAIMED. The GPL License provides additional details about this warranty
32disclaimer.
33********************************************************************************
34Marvell BSD License Option
35
36If you received this File from Marvell, you may opt to use, redistribute and/or
37modify this File under the following licensing terms.
38Redistribution and use in source and binary forms, with or without modification,
39are permitted provided that the following conditions are met:
40
41    * Redistributions of source code must retain the above copyright notice,
42        this list of conditions and the following disclaimer.
43
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.
47
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.
51
52THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
56ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59ANY 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
61SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
63*******************************************************************************/
64
65#include "mvSysCesa.h"
66
67#if (MV_CESA_VERSION >= 2)
68MV_TARGET tdmaAddrDecPrioTable[] =
69{
70#if defined(MV_INCLUDE_SDRAM_CS0)
71    SDRAM_CS0,
72#endif
73#if defined(MV_INCLUDE_SDRAM_CS1)
74    SDRAM_CS1,
75#endif
76#if defined(MV_INCLUDE_SDRAM_CS2)
77    SDRAM_CS2,
78#endif
79#if defined(MV_INCLUDE_SDRAM_CS3)
80    SDRAM_CS3,
81#endif
82#if defined(MV_INCLUDE_PEX)
83    PEX0_MEM,
84#endif
85
86    TBL_TERM
87};
88
89/*******************************************************************************
90* mvCesaWinGet - Get TDMA target address window.
91*
92* DESCRIPTION:
93* Get TDMA target address window.
94*
95* INPUT:
96* winNum - TDMA target address decode window number.
97*
98* OUTPUT:
99* pDecWin - TDMA target window data structure.
100*
101* RETURN:
102* MV_ERROR if register parameters are invalid.
103*
104*******************************************************************************/
105static MV_STATUS mvCesaWinGet(MV_U32 winNum, MV_DEC_WIN *pDecWin)
106{
107    MV_DEC_WIN_PARAMS winParam;
108    MV_U32 sizeReg, baseReg;
109
110    /* Parameter checking */
111    if (winNum >= MV_CESA_TDMA_ADDR_DEC_WIN)
112    {
113        mvOsPrintf("%s : ERR. Invalid winNum %d\n",
114                    __FUNCTION__, winNum);
115        return MV_NOT_SUPPORTED;
116    }
117
118    baseReg = MV_REG_READ( MV_CESA_TDMA_BASE_ADDR_REG(winNum) );
119    sizeReg = MV_REG_READ( MV_CESA_TDMA_WIN_CTRL_REG(winNum) );
120 
121   /* Check if window is enabled */
122    if(sizeReg & MV_CESA_TDMA_WIN_ENABLE_MASK)
123    {
124        pDecWin->enable = MV_TRUE;
125
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);
131
132        /* Translate the decode window parameters to address decode struct */
133        if (MV_OK != mvCtrlParamsToAddrDec(&winParam, pDecWin))
134        {
135            mvOsPrintf("Failed to translate register parameters to CESA address" \
136                       " decode window structure\n");
137            return MV_ERROR;
138        }
139    }
140    else
141    {
142        pDecWin->enable = MV_FALSE;
143    }
144    return MV_OK;
145}
146
147/*******************************************************************************
148* cesaWinOverlapDetect - Detect CESA TDMA address windows overlapping
149*
150* DESCRIPTION:
151* An unpredicted behaviur is expected in case TDMA address decode
152* windows overlapps.
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.
156*
157* INPUT:
158* winNum - address decode window number.
159* pAddrDecWin - An address decode window struct.
160*
161* OUTPUT:
162* None.
163*
164* RETURN:
165* MV_TRUE - if the given address window overlap current address
166* decode map,
167* MV_FALSE - otherwise, MV_ERROR if reading invalid data
168* from registers.
169*
170*******************************************************************************/
171static MV_STATUS cesaWinOverlapDetect(MV_U32 winNum, MV_ADDR_WIN *pAddrWin)
172{
173    MV_U32 winNumIndex;
174    MV_DEC_WIN addrDecWin;
175    
176    for(winNumIndex=0; winNumIndex<MV_CESA_TDMA_ADDR_DEC_WIN; winNumIndex++)
177    {
178        /* Do not check window itself */
179        if (winNumIndex == winNum)
180        {
181            continue;
182        }
183
184        /* Get window parameters */
185        if (MV_OK != mvCesaWinGet(winNumIndex, &addrDecWin))
186        {
187            mvOsPrintf("%s: ERR. TargetWinGet failed\n", __FUNCTION__);
188            return MV_ERROR;
189        }
190
191        /* Do not check disabled windows */
192        if(addrDecWin.enable == MV_FALSE)
193        {
194            continue;
195        }
196
197        if (MV_TRUE == ctrlWinOverlapTest(pAddrWin, &(addrDecWin.addrWin)))
198        {
199            return MV_TRUE;
200        }
201    }
202    return MV_FALSE;
203}
204
205/*******************************************************************************
206* mvCesaTdmaWinSet - Set CESA TDMA target address window
207*
208* DESCRIPTION:
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.
213*
214* INPUT:
215* winNum - CESA TDMA target address decode window number.
216* pAddrDecWin - CESA TDMA target window data structure.
217*
218* OUTPUT:
219* None.
220*
221* RETURN:
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
224* unknown.
225*
226*******************************************************************************/
227static MV_STATUS mvCesaTdmaWinSet(MV_U32 winNum, MV_DEC_WIN *pDecWin)
228{
229    MV_DEC_WIN_PARAMS winParams;
230    MV_U32 sizeReg, baseReg;
231    
232    /* Parameter checking */
233    if (winNum >= MV_CESA_TDMA_ADDR_DEC_WIN)
234    {
235        mvOsPrintf("mvCesaTdmaWinSet: ERR. Invalid win num %d\n",winNum);
236        return MV_BAD_PARAM;
237    }
238
239    /* Check if the requested window overlapps with current windows */
240    if (MV_TRUE == cesaWinOverlapDetect(winNum, &pDecWin->addrWin))
241    {
242        mvOsPrintf("%s: ERR. Window %d overlap\n", __FUNCTION__, winNum);
243        return MV_ERROR;
244    }
245
246    /* check if address is aligned to the size */
247    if(MV_IS_NOT_ALIGN(pDecWin->addrWin.baseLow, pDecWin->addrWin.size))
248    {
249        mvOsPrintf("mvCesaTdmaWinSet: Error setting CESA TDMA window %d to "\
250                   "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
251                   winNum,
252                   mvCtrlTargetNameGet(pDecWin->target),
253                   pDecWin->addrWin.baseLow,
254                   pDecWin->addrWin.size);
255        return MV_ERROR;
256    }
257
258    if(MV_OK != mvCtrlAddrDecToParams(pDecWin, &winParams))
259    {
260        mvOsPrintf("%s: mvCtrlAddrDecToParams Failed\n", __FUNCTION__);
261        return MV_ERROR;
262    }
263
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));
268
269    if (pDecWin->enable == MV_TRUE)
270    {
271        sizeReg |= MV_CESA_TDMA_WIN_ENABLE_MASK;
272    }
273    else
274    {
275        sizeReg &= ~MV_CESA_TDMA_WIN_ENABLE_MASK;
276    }
277
278    /* Update Base value */
279    baseReg = (winParams.baseAddr & MV_CESA_TDMA_WIN_BASE_MASK);
280
281    MV_REG_WRITE( MV_CESA_TDMA_WIN_CTRL_REG(winNum), sizeReg);
282    MV_REG_WRITE( MV_CESA_TDMA_BASE_ADDR_REG(winNum), baseReg);
283        
284    return MV_OK;
285}
286
287
288static MV_STATUS mvCesaTdmaAddrDecInit (void)
289{
290    MV_U32 winNum;
291    MV_STATUS status;
292    MV_CPU_DEC_WIN cpuAddrDecWin;
293    MV_DEC_WIN cesaWin;
294    MV_U32 winPrioIndex = 0;
295
296    /* First disable all address decode windows */
297    for(winNum=0; winNum<MV_CESA_TDMA_ADDR_DEC_WIN; winNum++)
298    {
299        MV_REG_BIT_RESET(MV_CESA_TDMA_WIN_CTRL_REG(winNum), MV_CESA_TDMA_WIN_ENABLE_MASK);
300    }
301
302    /* Go through all windows in user table until table terminator */
303    winNum = 0;
304    while( (tdmaAddrDecPrioTable[winPrioIndex] != TBL_TERM) &&
305           (winNum < MV_CESA_TDMA_ADDR_DEC_WIN) ) {
306
307        /* first get attributes from CPU If */
308        status = mvCpuIfTargetWinGet(tdmaAddrDecPrioTable[winPrioIndex],
309                                     &cpuAddrDecWin);
310        if(MV_NO_SUCH == status){
311        winPrioIndex++;
312            continue;
313    }
314
315        if (MV_OK != status)
316        {
317            mvOsPrintf("cesaInit: TargetWinGet failed. winNum=%d, winIdx=%d, target=%d, status=0x%x\n",
318                        winNum, winPrioIndex, tdmaAddrDecPrioTable[winPrioIndex], status);
319            return MV_ERROR;
320        }
321        if (cpuAddrDecWin.enable == MV_TRUE)
322        {
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];
328
329#if defined(MV646xx)
330            /* Get the default attributes for that target window */
331            mvCtrlDefAttribGet(cesaWin.target, &cesaWin.addrWinAttr);
332#endif /* MV646xx */
333
334            if(MV_OK != mvCesaTdmaWinSet(winNum, &cesaWin))
335            {
336                mvOsPrintf("mvCesaTdmaWinSet FAILED: winNum=%d\n",
337                           winNum);
338                return MV_ERROR;
339            }
340            winNum++;
341        }
342        winPrioIndex++;
343    }
344    return MV_OK;
345}
346#endif /* MV_CESA_VERSION >= 2 */
347
348
349
350
351MV_STATUS mvCesaInit (int numOfSession, int queueDepth, char* pSramBase, void *osHandle)
352{
353    MV_U32 cesaCryptEngBase;
354    MV_CPU_DEC_WIN addrDecWin;
355
356    if(sizeof(MV_CESA_SRAM_MAP) > MV_CESA_SRAM_SIZE)
357    {
358        mvOsPrintf("mvCesaInit: Wrong SRAM map - %ld > %d\n",
359                sizeof(MV_CESA_SRAM_MAP), MV_CESA_SRAM_SIZE);
360        return MV_FAIL;
361    }
362#if 0
363    if (mvCpuIfTargetWinGet(CRYPT_ENG, &addrDecWin) == MV_OK)
364        cesaCryptEngBase = addrDecWin.addrWin.baseLow;
365    else
366    {
367        mvOsPrintf("mvCesaInit: ERR. mvCpuIfTargetWinGet failed\n");
368        return MV_ERROR;
369    }
370#else
371        cesaCryptEngBase = (MV_U32)pSramBase;
372#endif
373
374#if 0 /* Already done in the platform init */
375#if (MV_CESA_VERSION >= 2)
376    mvCesaTdmaAddrDecInit();
377#endif /* MV_CESA_VERSION >= 2 */
378#endif
379    return mvCesaHalInit(numOfSession, queueDepth, pSramBase, cesaCryptEngBase,
380                 osHandle);
381
382}
383

Archive Download this file



interactive