1
2 //<MStar Software>
3 //******************************************************************************
4 // MStar Software
5 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
6 // All software, firmware and related documentation herein ("MStar Software") are
7 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
8 // law, including, but not limited to, copyright law and international treaties.
9 // Any use, modification, reproduction, retransmission, or republication of all
10 // or part of MStar Software is expressly prohibited, unless prior written
11 // permission has been granted by MStar.
12 //
13 // By accessing, browsing and/or using MStar Software, you acknowledge that you
14 // have read, understood, and agree, to be bound by below terms ("Terms") and to
15 // comply with all applicable laws and regulations:
16 //
17 // 1. MStar shall retain any and all right, ownership and interest to MStar
18 // Software and any modification/derivatives thereof.
19 // No right, ownership, or interest to MStar Software and any
20 // modification/derivatives thereof is transferred to you under Terms.
21 //
22 // 2. You understand that MStar Software might include, incorporate or be
23 // supplied together with third party`s software and the use of MStar
24 // Software may require additional licenses from third parties.
25 // Therefore, you hereby agree it is your sole responsibility to separately
26 // obtain any and all third party right and license necessary for your use of
27 // such third party`s software.
28 //
29 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
30 // MStar`s confidential information and you agree to keep MStar`s
31 // confidential information in strictest confidence and not disclose to any
32 // third party.
33 //
34 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
35 // kind. Any warranties are hereby expressly disclaimed by MStar, including
36 // without limitation, any warranties of merchantability, non-infringement of
37 // intellectual property rights, fitness for a particular purpose, error free
38 // and in conformity with any international standard. You agree to waive any
39 // claim against MStar for any loss, damage, cost or expense that you may
40 // incur related to your use of MStar Software.
41 // In no event shall MStar be liable for any direct, indirect, incidental or
42 // consequential damages, including without limitation, lost of profit or
43 // revenues, lost or damage of data, and unauthorized system use.
44 // You agree that this Section 4 shall still apply without being affected
45 // even if MStar Software has been modified by MStar in accordance with your
46 // request or instruction for your use, except otherwise agreed by both
47 // parties in writing.
48 //
49 // 5. If requested, MStar may from time to time provide technical supports or
50 // services in relation with MStar Software to you for your use of
51 // MStar Software in conjunction with your or your customer`s product
52 // ("Services").
53 // You understand and agree that, except otherwise agreed by both parties in
54 // writing, Services are provided on an "AS IS" basis and the warranty
55 // disclaimer set forth in Section 4 above shall apply.
56 //
57 // 6. Nothing contained herein shall be construed as by implication, estoppels
58 // or otherwise:
59 // (a) conferring any license or right to use MStar name, trademark, service
60 // mark, symbol or any other identification;
61 // (b) obligating MStar or any of its affiliates to furnish any person,
62 // including without limitation, you and your customers, any assistance
63 // of any kind whatsoever, or any information; or
64 // (c) conferring any license or right under any intellectual property right.
65 //
66 // 7. These terms shall be governed by and construed in accordance with the laws
67 // of Taiwan, R.O.C., excluding its conflict of law rules.
68 // Any and all dispute arising out hereof or related hereto shall be finally
69 // settled by arbitration referred to the Chinese Arbitration Association,
70 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
71 // Rules of the Association by three (3) arbitrators appointed in accordance
72 // with the said Rules.
73 // The place of arbitration shall be in Taipei, Taiwan and the language shall
74 // be English.
75 // The arbitration award shall be final and binding to both parties.
76 //
77 //******************************************************************************
78 //<MStar Software>
79 ////////////////////////////////////////////////////////////////////////////////
80 //
81 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
82 // All rights reserved.
83 //
84 // Unless otherwise stipulated in writing, any and all information contained
85 // herein regardless in any format shall remain the sole proprietary of
86 // MStar Semiconductor Inc. and be kept in strict confidence
87 // ("MStar Confidential Information") by the recipient.
88 // Any unauthorized act including without limitation unauthorized disclosure,
89 // copying, use, reproduction, sale, distribution, modification, disassembling,
90 // reverse engineering and compiling of the contents of MStar Confidential
91 // Information is unlawful and strictly prohibited. MStar hereby reserves the
92 // rights to any and all damages, losses, costs and expenses resulting therefrom.
93 //
94 ////////////////////////////////////////////////////////////////////////////////
95
96 #include "MsCommon.h"
97 #include "halMPool.h"
98 #include "halCHIP.h"
99
100 #if (defined(MCU_AEON))
101 #define RIU_MAP 0xA0000000
102 #define R2_MAU_BASE (RIU_MAP+(0x122B00<<1))
103
104 typedef enum
105 {
106 SECR2_MAU_2Gx2G = 0, //will not be applied in real projects
107 SECR2_MAU_1Gx1G,
108 SECR2_MAU_512Mx512M,
109 SECR2_MAU_256Mx256M,
110 } SECR2_MAU_TYPE;
111 #endif
112
113
HAL_MsOS_MPool_PA2BA(MS_U32 u32PhyAddr)114 MS_U32 HAL_MsOS_MPool_PA2BA(MS_U32 u32PhyAddr)
115 {
116 MS_U32 u32BusAddr = 0x0;
117
118 // ba = pa + offset
119 if( (u32PhyAddr >= HAL_MIU0_BASE) && (u32PhyAddr < HAL_MIU1_BASE) ) // MIU0
120 u32BusAddr = u32PhyAddr - HAL_MIU0_BASE + HAL_MIU0_BUS_BASE;
121 else if( (u32PhyAddr >= HAL_MIU1_BASE) && (u32PhyAddr < HAL_MIU2_BASE) ) // MIU1
122 u32BusAddr = u32PhyAddr - HAL_MIU1_BASE + HAL_MIU1_BUS_BASE;
123 else
124 u32BusAddr = u32PhyAddr - HAL_MIU2_BASE + HAL_MIU2_BUS_BASE; // MIU2
125
126 return u32BusAddr;
127 }
HAL_MsOS_MPool_VA2PA(MS_U32 u32Virt)128 MS_U32 HAL_MsOS_MPool_VA2PA(MS_U32 u32Virt)
129 {
130 //for aeon
131 #if (defined(MCU_AEON))
132 SECR2_MAU_TYPE eSecR2MauType=SECR2_MAU_1Gx1G;
133 MS_U8 u8MauVal=0;
134 u8MauVal =(MS_U8)((*((volatile MS_U32 *) (R2_MAU_BASE +(0x01 << 2)) ))>>8);
135 switch(u8MauVal)
136 {
137 case 0x87 : eSecR2MauType=SECR2_MAU_2Gx2G; break;
138 case 0x85 : eSecR2MauType=SECR2_MAU_1Gx1G; break;
139 case 0x83 : eSecR2MauType=SECR2_MAU_512Mx512M; break;
140 case 0x81 : eSecR2MauType=SECR2_MAU_256Mx256M; break;
141 default: eSecR2MauType=SECR2_MAU_1Gx1G; break;
142 }
143
144 if((eSecR2MauType==SECR2_MAU_1Gx1G)||(eSecR2MauType==SECR2_MAU_2Gx2G))
145 {
146 return ((MS_U32)(u32Virt) & ~(0x80000000));
147 }
148 else
149 {
150 return ((MS_U32)(u32Virt) & ~(0xC0000000));
151 }
152 //for arm
153 #elif (defined(__arm__))
154
155 //for mboot
156 #if (defined(CONFIG_MBOOT))
157 //===========================================
158 // MIU0 (0 ~ 1024MB) (VA) 0x2000:0000 ~ 0x5fff:ffff -> (PA) 0x0000:0000 ~ 0x3fff:ffff (cached)
159 if ((HAL_MIU0_BUS_BASE <= u32Virt) && ((HAL_MIU0_BUS_BASE + 0x3fffffff) >= u32Virt))
160 {
161 return (MS_U32)(u32Virt - HAL_MIU0_BUS_BASE);
162 }
163
164 //===========================================
165 // MIU0 (0 ~ 1024MB) (VA) 0x6000:0000 ~ 0x9fff:ffff -> (PA) 0x0000:0000 ~ 0x3fff:ffff (uncached)
166 if (((HAL_MIU0_BUS_BASE + 0x40000000UL) <= u32Virt) && ((HAL_MIU0_BUS_BASE + 0x7fffffffUL) >= u32Virt))
167 {
168 return (MS_U32)(u32Virt - (HAL_MIU0_BUS_BASE+0x40000000UL));
169 }
170
171 //===========================================
172 // MIU1 (low 512MB) (VA) 0xa000:0000 ~ 0xbfff:ffff -> (PA) 0x8000:0000 ~ 0x9fff:ffff (cached)
173 if ((HAL_MIU1_BUS_BASE <= u32Virt) && ((HAL_MIU1_BUS_BASE + 0x1fffffffUL) >= u32Virt))
174 {
175 return (MS_U32)((u32Virt & 0x1fffffffUL) + HAL_MIU1_BASE);
176 }
177
178 //===========================================
179 // MIU1 (0 ~ 1024MB) (VA) 0xc000:0000 ~ 0xffff:ffff -> (PA) 0x8000:0000 ~ 0xbfff:ffff (uncached)
180 if (((HAL_MIU1_BUS_BASE + 0x20000000UL) <= u32Virt) && ((HAL_MIU1_BUS_BASE + 0x5fffffff) >= u32Virt))
181 {
182 return (MS_U32)((u32Virt & 0x3fffffffUL) + HAL_MIU1_BASE);
183 }
184
185 //for chakra2
186 #else
187 //===========================================
188 // MIU0 (low 512MB) (VA) 0x0000:0000 ~ 0x1fff:ffff -> (PA) 0x0000:0000 ~ 0x1fff:ffff (cached)
189 if ((0x00000000 <= u32Virt) && (0x1fffffff >= u32Virt))
190 {
191 return (u32Virt & 0x1fffffff);
192 }
193
194 //===========================================
195 // MIU0 (low 512MB) (VA) 0x2000:0000 ~ 0x3fff:fffff -> (PA) 0x0000:0000 ~ 0x1fff:ffff (uncached)
196 if ((0x20000000 <= u32Virt) && (0x3fffffff > u32Virt))
197 {
198 return (u32Virt & 0x1fffffff);
199 }
200
201 //===========================================
202 // MIU1 (low 512MB) (VA) 0x4000:0000 ~ 0x5fff:ffff -> (PA) 0x8000:0000 ~ 0x9fff:ffff (cached)
203 if ((0x40000000 <= u32Virt) && (0x5fffffff >= u32Virt))
204 {
205 return ((u32Virt & 0x1fffffff) + HAL_MIU1_BASE);
206 }
207
208 //===========================================
209 // MIU1 (low 512MB) (VA) 0x6000:0000 ~ 0x7fff:ffff -> (PA) 0x8000:0000 ~ 0x9fff:ffff (uncached)
210 if ((0x60000000 <= u32Virt) && (0x7fffffff > u32Virt))
211 {
212 return ((u32Virt & 0x1fffffff) + HAL_MIU1_BASE);
213 }
214 #endif
215
216 // for mips
217 #else
218 #endif
219
220 return 0xffffffff;
221 }
222
HAL_MsOS_MPool_PA2KSEG0(MS_U32 u32Phys)223 MS_U32 HAL_MsOS_MPool_PA2KSEG0(MS_U32 u32Phys)
224 {
225 //for aeon
226 #if (defined(MCU_AEON))
227 SECR2_MAU_TYPE eSecR2MauType=SECR2_MAU_1Gx1G;
228 MS_U8 u8MauVal=0;
229 u8MauVal =(MS_U8)((*((volatile MS_U32 *) (R2_MAU_BASE +(0x01 << 2)) ))>>8);
230 switch(u8MauVal)
231 {
232 case 0x87 : eSecR2MauType=SECR2_MAU_2Gx2G; break;
233 case 0x85 : eSecR2MauType=SECR2_MAU_1Gx1G; break;
234 case 0x83 : eSecR2MauType=SECR2_MAU_512Mx512M; break;
235 case 0x81 : eSecR2MauType=SECR2_MAU_256Mx256M; break;
236 default: eSecR2MauType=SECR2_MAU_1Gx1G; break;
237 }
238
239 if(eSecR2MauType==SECR2_MAU_1Gx1G)
240 {
241 // MIU0 (1GB) - PA 0x0000:0000~0x4000:0000 -> (VA) 0x0000:0000~0x4000:0000 cached
242 // MIU1 (1GB) - PA 0x4000:0000~0x8000:0000 -> (VA) 0x4000:0000~0x8000:0000 cached
243 return (u32Phys + 0x00000000);
244 }
245 else if(eSecR2MauType==SECR2_MAU_512Mx512M)
246 {
247 // MIU0 (512MB) - PA 0x0000:0000~0x2000:0000 -> (VA) 0x4000:0000~0x6000:0000 cached
248 if((u32Phys>=0x00000000)&&(u32Phys<0x20000000))
249 {
250 return (u32Phys + 0x40000000);
251 }
252
253 // MIU1 (512MB) - PA 0x2000:0000~0x4000:0000 -> (VA) 0x6000:0000~0x8000:0000 cached
254 if((u32Phys>=0x20000000)&&(u32Phys<0x40000000))
255 {
256 return (u32Phys + 0x40000000);
257 }
258 }
259 else if(eSecR2MauType==SECR2_MAU_256Mx256M)
260 {
261 // MIU0 (256MB) - PA 0x0000:0000~0x1000:0000 -> (VA) 0x4000:0000~0x5000:0000 cached
262 if((u32Phys>=0x00000000)&&(u32Phys<0x10000000))
263 {
264 return (u32Phys + 0x40000000);
265 }
266
267 // MIU1 (256MB) - PA 0x1000:0000~0x2000:0000 -> (VA) 0x5000:0000~0x6000:0000 cached
268 if((u32Phys>=0x10000000)&&(u32Phys<0x20000000))
269 {
270 return (u32Phys + 0x40000000);
271 }
272 }
273 else //SECR2_MAU_2Gx2G
274 {
275 return 0xffffffff;
276 }
277 //for arm
278 #elif (defined(__arm__))
279
280 #if (defined(CONFIG_MBOOT))
281 //===========================================
282 // MIU0 (0~1024MB) - (PA) 0x0000:0000 ~ 0x3fff:ffff -> (VA) 0x2000:0000 ~ 0x5fff:ffff (cached)
283 if ((0x00000000UL <= u32Phys) && (0x3fffffffUL >= u32Phys))
284 {
285 return (MS_U32)((u32Phys & 0x3fffffffUL) + HAL_MIU0_BUS_BASE);
286 }
287
288 //===========================================
289 // MIU1 (low 512MB) - (PA) 0x8000:0000 ~ 0x9fff:ffff -> (VA) 0xA000:0000 ~ 0xbfff:ffff (cached)
290 if ((HAL_MIU1_BASE <= u32Phys) && ((HAL_MIU1_BASE + 0x1fffffffUL) >= u32Phys))
291 {
292 return (MS_U32)((u32Phys - HAL_MIU1_BASE) + HAL_MIU1_BUS_BASE);
293 }
294
295 //for chakra2
296 #else
297 //===========================================
298 // MIU0 (low 512MB) - (PA) 0x0000:0000 ~ 0x1fff:ffff -> (VA) 0x0000:0000 ~ 0x1fff:ffff (cached)
299 if ((0x00000000 <= u32Phys) && (0x1fffffff >= u32Phys))
300 {
301 return u32Phys;
302 }
303
304 //===========================================
305 // MIU1 (low 512MB) - (PA) 0x8000:0000 ~ 0x9fff:ffff -> (VA) 0x4000:0000 ~ 0x5fff:ffff (cached)
306 if ((HAL_MIU1_BASE <= u32Phys) && ((HAL_MIU1_BASE + 0x1fffffff) >= u32Phys))
307 {
308 return ((u32Phys - HAL_MIU1_BASE) + 0x40000000);
309 }
310 #endif
311
312 //for mips
313 #else
314 #endif
315 return 0xffffffff;
316 }
317
HAL_MsOS_MPool_PA2KSEG1(MS_U32 u32Phys)318 MS_U32 HAL_MsOS_MPool_PA2KSEG1(MS_U32 u32Phys)
319 {
320 //for aeon
321 #if (defined(MCU_AEON))
322 SECR2_MAU_TYPE eSecR2MauType=SECR2_MAU_1Gx1G;
323 MS_U8 u8MauVal=0;
324 u8MauVal =(MS_U8)((*((volatile MS_U32 *) (R2_MAU_BASE +(0x01 << 2)) ))>>8);
325 switch(u8MauVal)
326 {
327 case 0x87 : eSecR2MauType=SECR2_MAU_2Gx2G; break;
328 case 0x85 : eSecR2MauType=SECR2_MAU_1Gx1G; break;
329 case 0x83 : eSecR2MauType=SECR2_MAU_512Mx512M; break;
330 case 0x81 : eSecR2MauType=SECR2_MAU_256Mx256M; break;
331 default: eSecR2MauType=SECR2_MAU_1Gx1G; break;
332 }
333
334 if(eSecR2MauType==SECR2_MAU_1Gx1G)
335 {
336 // MIU0 (1GB) - PA 0x0000:0000~0x4000:0000 -> (VA) 0x8000:0000~0xC000:0000 non-cached
337 // MIU1 (1GB) - PA 0x4000:0000~0x8000:0000 -> (VA) 0xC000:0000~0x10000:0000 non-cached
338 return (u32Phys + 0x80000000);
339 }
340 else if(eSecR2MauType==SECR2_MAU_512Mx512M)
341 {
342 //512Mx512M
343 // MIU0 (512MB) - PA 0x0000:0000~0x2000:0000 -> (VA) 0xC000:0000~0xE000:0000 non-cached
344 if((u32Phys>=0x00000000)&&(u32Phys<0x20000000))
345 {
346 return (u32Phys + 0xC0000000);
347 }
348
349 // MIU1 (512MB) - PA 0x2000:0000~0x4000:0000 -> (VA) 0xE000:0000~0x10000:0000 non-cached
350 if((u32Phys>=0x20000000)&&(u32Phys<0x40000000))
351 {
352 return (u32Phys + 0xC0000000);
353 }
354 }
355 else if(eSecR2MauType==SECR2_MAU_256Mx256M)
356 {
357 // MIU0 (256MB) - PA 0x0000:0000~0x1000:0000 -> (VA) 0xC000:0000~0xD000:0000 non-cached
358 if((u32Phys>=0x00000000)&&(u32Phys<0x10000000))
359 {
360 return (u32Phys + 0xC0000000);
361 }
362
363 // MIU1 (256MB) - PA 0x1000:0000~0x2000:0000 -> (VA) 0xD000:0000~0xE000:0000 non-cached
364 if((u32Phys>=0x10000000)&&(u32Phys<0x20000000))
365 {
366 return (u32Phys + 0xC0000000);
367 }
368 }
369 else //SECR2_MAU_2Gx2G
370 {
371 return 0xffffffff;
372 }
373 //for arm
374 #elif (defined(__arm__))
375
376 #if (defined(CONFIG_MBOOT))
377 //===========================================
378 // MIU0 (0~1024MB) - (PA) 0x0000:0000 ~ 0x3fff:ffff -> (VA) 0x6000:0000 ~ 0x9fff:ffff (uncached)
379 if ((0x00000000UL <= u32Phys) && (0x3fffffffUL >= u32Phys))
380 {
381 return (MS_U32)((u32Phys & 0x3fffffffUL) + HAL_MIU0_BUS_BASE + 0x40000000UL);
382 }
383
384 //===========================================
385 // MIU1 (0~1024MB) - (PA) 0x8000:0000 ~ 0xBfff:ffff -> (VA) 0xc000:0000 ~ 0xFfff:ffff (uncached)
386 if ((HAL_MIU1_BASE <= u32Phys) && ((HAL_MIU1_BASE + 0x3fffffffUL) >= u32Phys))
387 {
388 return (MS_U32)((u32Phys - HAL_MIU1_BASE) + HAL_MIU1_BUS_BASE + 0x20000000UL);
389 }
390
391 //for chakra2
392 #else
393 //===========================================
394 // MIU0 (low 512MB) - (PA) 0x0000:0000 ~ 0x1fff:ffff -> (VA) 0x2000:0000 ~ 0x3fff:ffff (uncached)
395 if ((0x00000000 <= u32Phys) && (0x1fffffff >= u32Phys))
396 {
397 return (u32Phys + 0x20000000);
398 }
399
400 //===========================================
401 // MIU1 (low 512MB) - (PA) 0x8000:0000 ~ 0x9fff:ffff -> (VA) 0x6000:0000 ~ 0x7fff:ffff (uncached)
402 if ((HAL_MIU1_BASE <= u32Phys) && ((HAL_MIU1_BASE + 0x1fffffff) >= u32Phys))
403 {
404 return ((u32Phys - HAL_MIU1_BASE) + 0x60000000);
405 }
406 #endif
407
408 //for mips
409 #else
410 #endif
411 return 0xffffffff;
412 }
413