1*53ee8cc1Swenshuai.xi //<MStar Software> 2*53ee8cc1Swenshuai.xi //****************************************************************************** 3*53ee8cc1Swenshuai.xi // MStar Software 4*53ee8cc1Swenshuai.xi // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5*53ee8cc1Swenshuai.xi // All software, firmware and related documentation herein ("MStar Software") are 6*53ee8cc1Swenshuai.xi // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7*53ee8cc1Swenshuai.xi // law, including, but not limited to, copyright law and international treaties. 8*53ee8cc1Swenshuai.xi // Any use, modification, reproduction, retransmission, or republication of all 9*53ee8cc1Swenshuai.xi // or part of MStar Software is expressly prohibited, unless prior written 10*53ee8cc1Swenshuai.xi // permission has been granted by MStar. 11*53ee8cc1Swenshuai.xi // 12*53ee8cc1Swenshuai.xi // By accessing, browsing and/or using MStar Software, you acknowledge that you 13*53ee8cc1Swenshuai.xi // have read, understood, and agree, to be bound by below terms ("Terms") and to 14*53ee8cc1Swenshuai.xi // comply with all applicable laws and regulations: 15*53ee8cc1Swenshuai.xi // 16*53ee8cc1Swenshuai.xi // 1. MStar shall retain any and all right, ownership and interest to MStar 17*53ee8cc1Swenshuai.xi // Software and any modification/derivatives thereof. 18*53ee8cc1Swenshuai.xi // No right, ownership, or interest to MStar Software and any 19*53ee8cc1Swenshuai.xi // modification/derivatives thereof is transferred to you under Terms. 20*53ee8cc1Swenshuai.xi // 21*53ee8cc1Swenshuai.xi // 2. You understand that MStar Software might include, incorporate or be 22*53ee8cc1Swenshuai.xi // supplied together with third party`s software and the use of MStar 23*53ee8cc1Swenshuai.xi // Software may require additional licenses from third parties. 24*53ee8cc1Swenshuai.xi // Therefore, you hereby agree it is your sole responsibility to separately 25*53ee8cc1Swenshuai.xi // obtain any and all third party right and license necessary for your use of 26*53ee8cc1Swenshuai.xi // such third party`s software. 27*53ee8cc1Swenshuai.xi // 28*53ee8cc1Swenshuai.xi // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29*53ee8cc1Swenshuai.xi // MStar`s confidential information and you agree to keep MStar`s 30*53ee8cc1Swenshuai.xi // confidential information in strictest confidence and not disclose to any 31*53ee8cc1Swenshuai.xi // third party. 32*53ee8cc1Swenshuai.xi // 33*53ee8cc1Swenshuai.xi // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34*53ee8cc1Swenshuai.xi // kind. Any warranties are hereby expressly disclaimed by MStar, including 35*53ee8cc1Swenshuai.xi // without limitation, any warranties of merchantability, non-infringement of 36*53ee8cc1Swenshuai.xi // intellectual property rights, fitness for a particular purpose, error free 37*53ee8cc1Swenshuai.xi // and in conformity with any international standard. You agree to waive any 38*53ee8cc1Swenshuai.xi // claim against MStar for any loss, damage, cost or expense that you may 39*53ee8cc1Swenshuai.xi // incur related to your use of MStar Software. 40*53ee8cc1Swenshuai.xi // In no event shall MStar be liable for any direct, indirect, incidental or 41*53ee8cc1Swenshuai.xi // consequential damages, including without limitation, lost of profit or 42*53ee8cc1Swenshuai.xi // revenues, lost or damage of data, and unauthorized system use. 43*53ee8cc1Swenshuai.xi // You agree that this Section 4 shall still apply without being affected 44*53ee8cc1Swenshuai.xi // even if MStar Software has been modified by MStar in accordance with your 45*53ee8cc1Swenshuai.xi // request or instruction for your use, except otherwise agreed by both 46*53ee8cc1Swenshuai.xi // parties in writing. 47*53ee8cc1Swenshuai.xi // 48*53ee8cc1Swenshuai.xi // 5. If requested, MStar may from time to time provide technical supports or 49*53ee8cc1Swenshuai.xi // services in relation with MStar Software to you for your use of 50*53ee8cc1Swenshuai.xi // MStar Software in conjunction with your or your customer`s product 51*53ee8cc1Swenshuai.xi // ("Services"). 52*53ee8cc1Swenshuai.xi // You understand and agree that, except otherwise agreed by both parties in 53*53ee8cc1Swenshuai.xi // writing, Services are provided on an "AS IS" basis and the warranty 54*53ee8cc1Swenshuai.xi // disclaimer set forth in Section 4 above shall apply. 55*53ee8cc1Swenshuai.xi // 56*53ee8cc1Swenshuai.xi // 6. Nothing contained herein shall be construed as by implication, estoppels 57*53ee8cc1Swenshuai.xi // or otherwise: 58*53ee8cc1Swenshuai.xi // (a) conferring any license or right to use MStar name, trademark, service 59*53ee8cc1Swenshuai.xi // mark, symbol or any other identification; 60*53ee8cc1Swenshuai.xi // (b) obligating MStar or any of its affiliates to furnish any person, 61*53ee8cc1Swenshuai.xi // including without limitation, you and your customers, any assistance 62*53ee8cc1Swenshuai.xi // of any kind whatsoever, or any information; or 63*53ee8cc1Swenshuai.xi // (c) conferring any license or right under any intellectual property right. 64*53ee8cc1Swenshuai.xi // 65*53ee8cc1Swenshuai.xi // 7. These terms shall be governed by and construed in accordance with the laws 66*53ee8cc1Swenshuai.xi // of Taiwan, R.O.C., excluding its conflict of law rules. 67*53ee8cc1Swenshuai.xi // Any and all dispute arising out hereof or related hereto shall be finally 68*53ee8cc1Swenshuai.xi // settled by arbitration referred to the Chinese Arbitration Association, 69*53ee8cc1Swenshuai.xi // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70*53ee8cc1Swenshuai.xi // Rules of the Association by three (3) arbitrators appointed in accordance 71*53ee8cc1Swenshuai.xi // with the said Rules. 72*53ee8cc1Swenshuai.xi // The place of arbitration shall be in Taipei, Taiwan and the language shall 73*53ee8cc1Swenshuai.xi // be English. 74*53ee8cc1Swenshuai.xi // The arbitration award shall be final and binding to both parties. 75*53ee8cc1Swenshuai.xi // 76*53ee8cc1Swenshuai.xi //****************************************************************************** 77*53ee8cc1Swenshuai.xi //<MStar Software> 78*53ee8cc1Swenshuai.xi 79*53ee8cc1Swenshuai.xi //////////////////////////////////////////////////////////////////////////////// 80*53ee8cc1Swenshuai.xi // 81*53ee8cc1Swenshuai.xi // Copyright (c) 2008-2009 MStar Semiconductor, Inc. 82*53ee8cc1Swenshuai.xi // All rights reserved. 83*53ee8cc1Swenshuai.xi // 84*53ee8cc1Swenshuai.xi // Unless otherwise stipulated in writing, any and all information contained 85*53ee8cc1Swenshuai.xi // herein regardless in any format shall remain the sole proprietary of 86*53ee8cc1Swenshuai.xi // MStar Semiconductor Inc. and be kept in strict confidence 87*53ee8cc1Swenshuai.xi // ("MStar Confidential Information") by the recipient. 88*53ee8cc1Swenshuai.xi // Any unauthorized act including without limitation unauthorized disclosure, 89*53ee8cc1Swenshuai.xi // copying, use, reproduction, sale, distribution, modification, disassembling, 90*53ee8cc1Swenshuai.xi // reverse engineering and compiling of the contents of MStar Confidential 91*53ee8cc1Swenshuai.xi // Information is unlawful and strictly prohibited. MStar hereby reserves the 92*53ee8cc1Swenshuai.xi // rights to any and all damages, losses, costs and expenses resulting therefrom. 93*53ee8cc1Swenshuai.xi // 94*53ee8cc1Swenshuai.xi //////////////////////////////////////////////////////////////////////////////// 95*53ee8cc1Swenshuai.xi 96*53ee8cc1Swenshuai.xi /////////////////////////////////////////////////////////////////////////////////////////////////// 97*53ee8cc1Swenshuai.xi /// 98*53ee8cc1Swenshuai.xi /// @file MsCommon.h 99*53ee8cc1Swenshuai.xi /// @brief MStar Common Interface Header File 100*53ee8cc1Swenshuai.xi /// @author MStar Semiconductor Inc. 101*53ee8cc1Swenshuai.xi /// @note MsCommon.h includes most command header files including basic data type, macro(MsTypes.h),\n 102*53ee8cc1Swenshuai.xi /// board configuration(MsBoard.h), and OS related API(MsOS.h).\n 103*53ee8cc1Swenshuai.xi /////////////////////////////////////////////////////////////////////////////////////////////////// 104*53ee8cc1Swenshuai.xi 105*53ee8cc1Swenshuai.xi #ifndef _MS_COMMON_H_ 106*53ee8cc1Swenshuai.xi #define _MS_COMMON_H_ 107*53ee8cc1Swenshuai.xi 108*53ee8cc1Swenshuai.xi #ifndef MSOS_TYPE_LINUX_KERNEL 109*53ee8cc1Swenshuai.xi #include <stdio.h> 110*53ee8cc1Swenshuai.xi #include <stdlib.h> 111*53ee8cc1Swenshuai.xi #else 112*53ee8cc1Swenshuai.xi #endif 113*53ee8cc1Swenshuai.xi 114*53ee8cc1Swenshuai.xi #ifdef MSOS_TYPE_ECOS 115*53ee8cc1Swenshuai.xi #include <cyg/infra/diag.h> 116*53ee8cc1Swenshuai.xi #endif 117*53ee8cc1Swenshuai.xi 118*53ee8cc1Swenshuai.xi #include <stdarg.h> 119*53ee8cc1Swenshuai.xi 120*53ee8cc1Swenshuai.xi #ifdef CONFIG_ENABLE_MENUCONFIG 121*53ee8cc1Swenshuai.xi #include "autoconf.h" 122*53ee8cc1Swenshuai.xi #endif 123*53ee8cc1Swenshuai.xi 124*53ee8cc1Swenshuai.xi #ifdef MSOS_TYPE_LINUX 125*53ee8cc1Swenshuai.xi #include <limits.h> 126*53ee8cc1Swenshuai.xi #elif defined(MSOS_TYPE_ECOS) 127*53ee8cc1Swenshuai.xi #include <limits.h> 128*53ee8cc1Swenshuai.xi #elif defined(MSOS_TYPE_OPTEE) 129*53ee8cc1Swenshuai.xi #include <limits.h> 130*53ee8cc1Swenshuai.xi #else 131*53ee8cc1Swenshuai.xi #ifndef MSOS_TYPE_LINUX_KERNEL 132*53ee8cc1Swenshuai.xi #ifndef MSOS_TYPE_OPTEE 133*53ee8cc1Swenshuai.xi #define ULONG_MAX 0xffffffff 134*53ee8cc1Swenshuai.xi #else 135*53ee8cc1Swenshuai.xi //#define ULONG_MAX 0xffffffff 136*53ee8cc1Swenshuai.xi #endif 137*53ee8cc1Swenshuai.xi #endif 138*53ee8cc1Swenshuai.xi #endif 139*53ee8cc1Swenshuai.xi 140*53ee8cc1Swenshuai.xi //#include <setjmp.h> 141*53ee8cc1Swenshuai.xi 142*53ee8cc1Swenshuai.xi #include "MsOS.h" // Plan to be obsoleted in next generation. 143*53ee8cc1Swenshuai.xi #include "MsTypes.h" 144*53ee8cc1Swenshuai.xi #include "MsIRQ.h" 145*53ee8cc1Swenshuai.xi //#include "MsVersion.h" 146*53ee8cc1Swenshuai.xi #include "MsDevice.h" 147*53ee8cc1Swenshuai.xi 148*53ee8cc1Swenshuai.xi #ifdef CONFIG_ENABLE_MENUCONFIG 149*53ee8cc1Swenshuai.xi #include "autoconf.h" 150*53ee8cc1Swenshuai.xi #endif 151*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 152*53ee8cc1Swenshuai.xi // Defines 153*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 154*53ee8cc1Swenshuai.xi #ifndef DLL_PUBLIC 155*53ee8cc1Swenshuai.xi #define DLL_PUBLIC __attribute__ ((visibility ("default"))) 156*53ee8cc1Swenshuai.xi #endif 157*53ee8cc1Swenshuai.xi #ifndef DLL_LOCAL 158*53ee8cc1Swenshuai.xi #define DLL_LOCAL __attribute__ ((visibility ("hidden"))) 159*53ee8cc1Swenshuai.xi #endif 160*53ee8cc1Swenshuai.xi 161*53ee8cc1Swenshuai.xi #ifndef MSOS_TYPE_LINUX_KERNEL 162*53ee8cc1Swenshuai.xi #define SYMBOL_WEAK __attribute__((weak)) 163*53ee8cc1Swenshuai.xi #else 164*53ee8cc1Swenshuai.xi #define SYMBOL_WEAK 165*53ee8cc1Swenshuai.xi #endif 166*53ee8cc1Swenshuai.xi 167*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 168*53ee8cc1Swenshuai.xi // Macros 169*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 170*53ee8cc1Swenshuai.xi #define GEN_EXCEP { while(1); } 171*53ee8cc1Swenshuai.xi 172*53ee8cc1Swenshuai.xi //#define REG(addr) (*(volatile U32 *)(addr)) 173*53ee8cc1Swenshuai.xi #if 0 174*53ee8cc1Swenshuai.xi #ifdef __aeon__ 175*53ee8cc1Swenshuai.xi 176*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 177*53ee8cc1Swenshuai.xi // In order to keep the compatiblity of the source code from Venus, 178*53ee8cc1Swenshuai.xi // keep these memory address translation for a while. 179*53ee8cc1Swenshuai.xi // They will be removed in the future. 180*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 181*53ee8cc1Swenshuai.xi #define CACHED_BASE ((void *)0x00000000) 182*53ee8cc1Swenshuai.xi #define UNCACHED_BASE ((void *)0x80000000) 183*53ee8cc1Swenshuai.xi 184*53ee8cc1Swenshuai.xi #define CACHED_SIZE ((void *)0x20000000) 185*53ee8cc1Swenshuai.xi #define UNCACHED_SIZE ((void *)0x20000000) 186*53ee8cc1Swenshuai.xi // 0xA0000000~0xA000FFFF belongs to RIU 187*53ee8cc1Swenshuai.xi // 0xA1000000~ belongs to SPI 188*53ee8cc1Swenshuai.xi 189*53ee8cc1Swenshuai.xi //cached/unchched segment 190*53ee8cc1Swenshuai.xi #define KSEG0_BASE CACHED_BASE 191*53ee8cc1Swenshuai.xi #define KSEG1_BASE UNCACHED_BASE 192*53ee8cc1Swenshuai.xi #define KSEG0_SIZE CACHED_SIZE 193*53ee8cc1Swenshuai.xi #define KSEG1_SIZE UNCACHED_SIZE 194*53ee8cc1Swenshuai.xi 195*53ee8cc1Swenshuai.xi //cached <-> uncached 196*53ee8cc1Swenshuai.xi #define KSEG02KSEG1(addr) ((void *)((U32)(addr)|0x80000000)) 197*53ee8cc1Swenshuai.xi #define KSEG12KSEG0(addr) ((void *)((U32)(addr)&~0x80000000)) 198*53ee8cc1Swenshuai.xi 199*53ee8cc1Swenshuai.xi //virtual <-> physical 200*53ee8cc1Swenshuai.xi #define VA2PA(addr) ((void *)(((U32)addr) & 0x1fffffff)) 201*53ee8cc1Swenshuai.xi #define PA2KSEG0(addr) ((void *)(((U32)addr) | 0x00000000)) 202*53ee8cc1Swenshuai.xi #define PA2KSEG1(addr) ((void *)(((U32)addr) | 0x80000000)) 203*53ee8cc1Swenshuai.xi #endif 204*53ee8cc1Swenshuai.xi 205*53ee8cc1Swenshuai.xi #if defined(__mips__) 206*53ee8cc1Swenshuai.xi 207*53ee8cc1Swenshuai.xi //cached/unchched segment 208*53ee8cc1Swenshuai.xi #define KSEG0_BASE ((void *)0x80000000) 209*53ee8cc1Swenshuai.xi #define KSEG1_BASE ((void *)0xa0000000) 210*53ee8cc1Swenshuai.xi #define KSEG0_SIZE 0x20000000 211*53ee8cc1Swenshuai.xi #define KSEG1_SIZE 0x20000000 212*53ee8cc1Swenshuai.xi 213*53ee8cc1Swenshuai.xi //cached addr <-> unchched addr 214*53ee8cc1Swenshuai.xi #define KSEG02KSEG1(addr) ((void *)((MS_U32)(addr)|0x20000000)) //cached -> unchched 215*53ee8cc1Swenshuai.xi #define KSEG12KSEG0(addr) ((void *)((MS_U32)(addr)&~0x20000000)) //unchched -> cached 216*53ee8cc1Swenshuai.xi 217*53ee8cc1Swenshuai.xi //virtual addr <-> physical addr 218*53ee8cc1Swenshuai.xi #define VA2PA(addr) ((void *)(((MS_U32)addr) & 0x1fffffff)) //virtual -> physical 219*53ee8cc1Swenshuai.xi #define PA2KSEG0(addr) ((void *)(((MS_U32)addr) | 0x80000000)) //physical -> cached 220*53ee8cc1Swenshuai.xi #define PA2KSEG1(addr) ((void *)(((MS_U32)addr) | 0xa0000000)) //physical -> unchched 221*53ee8cc1Swenshuai.xi #endif 222*53ee8cc1Swenshuai.xi #endif 223*53ee8cc1Swenshuai.xi 224*53ee8cc1Swenshuai.xi #if 0 225*53ee8cc1Swenshuai.xi //cached/unchched segment 226*53ee8cc1Swenshuai.xi #define KSEG0_BASE ((void *)0x80000000) 227*53ee8cc1Swenshuai.xi #define KSEG1_BASE ((void *)0xa0000000) 228*53ee8cc1Swenshuai.xi #define KSEG0_SIZE 0x20000000 229*53ee8cc1Swenshuai.xi #define KSEG1_SIZE 0x20000000 230*53ee8cc1Swenshuai.xi 231*53ee8cc1Swenshuai.xi //cached <-> unchched 232*53ee8cc1Swenshuai.xi #define KSEG02KSEG1(addr) ((void *)((U32)(addr)|0x20000000)) 233*53ee8cc1Swenshuai.xi #define KSEG12KSEG0(addr) ((void *)((U32)(addr)&~0x20000000)) 234*53ee8cc1Swenshuai.xi 235*53ee8cc1Swenshuai.xi //virtual <-> physical 236*53ee8cc1Swenshuai.xi #define VA2PA(addr) ((void *)(((U32)addr) & 0x1fffffff)) 237*53ee8cc1Swenshuai.xi #define PA2KSEG0(addr) ((void *)(((U32)addr) | 0x80000000)) 238*53ee8cc1Swenshuai.xi #define PA2KSEG1(addr) ((void *)(((U32)addr) | 0xa0000000)) 239*53ee8cc1Swenshuai.xi #endif 240*53ee8cc1Swenshuai.xi 241*53ee8cc1Swenshuai.xi //user-defined warning 242*53ee8cc1Swenshuai.xi #ifdef MSOS_TYPE_ECOS 243*53ee8cc1Swenshuai.xi #ifdef BLOCK_ASSERT 244*53ee8cc1Swenshuai.xi #define MS_ASSERT(_bool_) \ 245*53ee8cc1Swenshuai.xi { \ 246*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 247*53ee8cc1Swenshuai.xi { \ 248*53ee8cc1Swenshuai.xi diag_printf("\033[35m UTOPIA ASSERT: %s, %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 249*53ee8cc1Swenshuai.xi *(volatile unsigned int *)(ULONG_MAX) = 0; \ 250*53ee8cc1Swenshuai.xi } \ 251*53ee8cc1Swenshuai.xi } 252*53ee8cc1Swenshuai.xi #else 253*53ee8cc1Swenshuai.xi #define MS_ASSERT(_bool_) \ 254*53ee8cc1Swenshuai.xi { \ 255*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 256*53ee8cc1Swenshuai.xi { \ 257*53ee8cc1Swenshuai.xi diag_printf("\033[35m UTOPIA ASSERT: %s, %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 258*53ee8cc1Swenshuai.xi } \ 259*53ee8cc1Swenshuai.xi } 260*53ee8cc1Swenshuai.xi #endif 261*53ee8cc1Swenshuai.xi #else 262*53ee8cc1Swenshuai.xi #ifdef MSOS_TYPE_LINUX_KERNEL 263*53ee8cc1Swenshuai.xi #ifdef BLOCK_ASSERT 264*53ee8cc1Swenshuai.xi #define MS_ASSERT(_bool_) \ 265*53ee8cc1Swenshuai.xi { \ 266*53ee8cc1Swenshuai.xi if (!(_bool_)) \ 267*53ee8cc1Swenshuai.xi { \ 268*53ee8cc1Swenshuai.xi printk("\033[35m ASSERT FAIL: %s, %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 269*53ee8cc1Swenshuai.xi panic("mstar panic\n"); \ 270*53ee8cc1Swenshuai.xi *(volatile unsigned int *)(ULONG_MAX) = 0; \ 271*53ee8cc1Swenshuai.xi } \ 272*53ee8cc1Swenshuai.xi } 273*53ee8cc1Swenshuai.xi #else 274*53ee8cc1Swenshuai.xi #define MS_ASSERT(_bool_) \ 275*53ee8cc1Swenshuai.xi { \ 276*53ee8cc1Swenshuai.xi if (!(_bool_)) \ 277*53ee8cc1Swenshuai.xi { \ 278*53ee8cc1Swenshuai.xi printk("\033[35m ASSERT FAIL: %s, %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 279*53ee8cc1Swenshuai.xi panic("mstar panic\n"); \ 280*53ee8cc1Swenshuai.xi } \ 281*53ee8cc1Swenshuai.xi } 282*53ee8cc1Swenshuai.xi #endif 283*53ee8cc1Swenshuai.xi #else 284*53ee8cc1Swenshuai.xi #ifdef BLOCK_ASSERT 285*53ee8cc1Swenshuai.xi #define MS_ASSERT(_bool_) \ 286*53ee8cc1Swenshuai.xi { \ 287*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 288*53ee8cc1Swenshuai.xi { \ 289*53ee8cc1Swenshuai.xi printf("\033[35m UTOPIA ASSERT: %s, %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 290*53ee8cc1Swenshuai.xi *(volatile unsigned int *)(ULONG_MAX) = 0; \ 291*53ee8cc1Swenshuai.xi } \ 292*53ee8cc1Swenshuai.xi } 293*53ee8cc1Swenshuai.xi #else 294*53ee8cc1Swenshuai.xi #define MS_ASSERT(_bool_) \ 295*53ee8cc1Swenshuai.xi { \ 296*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 297*53ee8cc1Swenshuai.xi { \ 298*53ee8cc1Swenshuai.xi printf("\033[35m UTOPIA ASSERT: %s, %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 299*53ee8cc1Swenshuai.xi } \ 300*53ee8cc1Swenshuai.xi } 301*53ee8cc1Swenshuai.xi #endif 302*53ee8cc1Swenshuai.xi #endif 303*53ee8cc1Swenshuai.xi #endif 304*53ee8cc1Swenshuai.xi 305*53ee8cc1Swenshuai.xi //user-defined panic 306*53ee8cc1Swenshuai.xi //access null pointer 0xFFFFFFFF to make exception 307*53ee8cc1Swenshuai.xi #ifdef MSOS_TYPE_ECOS 308*53ee8cc1Swenshuai.xi #define MS_PANIC(_bool_) \ 309*53ee8cc1Swenshuai.xi { \ 310*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 311*53ee8cc1Swenshuai.xi { \ 312*53ee8cc1Swenshuai.xi diag_printf("\033[35m UTOPIA ASSERT: %s %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 313*53ee8cc1Swenshuai.xi *(volatile unsigned int *)(ULONG_MAX) = 0; \ 314*53ee8cc1Swenshuai.xi } \ 315*53ee8cc1Swenshuai.xi } 316*53ee8cc1Swenshuai.xi #elif defined(MSOS_TYPE_OPTEE) 317*53ee8cc1Swenshuai.xi #define MS_PANIC(_bool_) \ 318*53ee8cc1Swenshuai.xi { \ 319*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 320*53ee8cc1Swenshuai.xi { \ 321*53ee8cc1Swenshuai.xi printf("\033[35m UTOPIA ASSERT: %s %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 322*53ee8cc1Swenshuai.xi while(1); \ 323*53ee8cc1Swenshuai.xi } \ 324*53ee8cc1Swenshuai.xi } 325*53ee8cc1Swenshuai.xi #else 326*53ee8cc1Swenshuai.xi #define MS_PANIC(_bool_) \ 327*53ee8cc1Swenshuai.xi { \ 328*53ee8cc1Swenshuai.xi if ( ! ( _bool_ ) ) \ 329*53ee8cc1Swenshuai.xi { \ 330*53ee8cc1Swenshuai.xi printf("\033[35m UTOPIA ASSERT: %s %s %s %d\033[35m\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 331*53ee8cc1Swenshuai.xi *(volatile unsigned int *)(ULONG_MAX) = 0; \ 332*53ee8cc1Swenshuai.xi } \ 333*53ee8cc1Swenshuai.xi } 334*53ee8cc1Swenshuai.xi #endif 335*53ee8cc1Swenshuai.xi 336*53ee8cc1Swenshuai.xi 337*53ee8cc1Swenshuai.xi #ifndef MIN 338*53ee8cc1Swenshuai.xi #define MIN(_a_, _b_) ((_a_) < (_b_) ? (_a_) : (_b_)) 339*53ee8cc1Swenshuai.xi #endif 340*53ee8cc1Swenshuai.xi #ifndef MAX 341*53ee8cc1Swenshuai.xi #define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) 342*53ee8cc1Swenshuai.xi #endif 343*53ee8cc1Swenshuai.xi 344*53ee8cc1Swenshuai.xi 345*53ee8cc1Swenshuai.xi #define ALIGN_4(_x_) (((_x_) + 3) & ~3) 346*53ee8cc1Swenshuai.xi #define ALIGN_8(_x_) (((_x_) + 7) & ~7) 347*53ee8cc1Swenshuai.xi #define ALIGN_16(_x_) (((_x_) + 15) & ~15) // No data type specified, optimized by complier 348*53ee8cc1Swenshuai.xi #define ALIGN_32(_x_) (((_x_) + 31) & ~31) // No data type specified, optimized by complier 349*53ee8cc1Swenshuai.xi 350*53ee8cc1Swenshuai.xi #define MASK(x) (((1<<(x##_BITS))-1) << x##_SHIFT) 351*53ee8cc1Swenshuai.xi #ifndef BIT //for Linux_kernel type, BIT redefined in <linux/bitops.h> 352*53ee8cc1Swenshuai.xi #define BIT(_bit_) (1 << (_bit_)) 353*53ee8cc1Swenshuai.xi #endif 354*53ee8cc1Swenshuai.xi #define BIT_(x) BIT(x) //[OBSOLETED] //TODO: remove it later 355*53ee8cc1Swenshuai.xi #define BITS(_bits_, _val_) ((BIT(((1)?_bits_)+1)-BIT(((0)?_bits_))) & (_val_<<((0)?_bits_))) 356*53ee8cc1Swenshuai.xi #define BMASK(_bits_) (BIT(((1)?_bits_)+1)-BIT(((0)?_bits_))) 357*53ee8cc1Swenshuai.xi 358*53ee8cc1Swenshuai.xi 359*53ee8cc1Swenshuai.xi #define READ_BYTE(_reg) (*(volatile MS_U8*)(_reg)) 360*53ee8cc1Swenshuai.xi #define READ_WORD(_reg) (*(volatile MS_U16*)(_reg)) 361*53ee8cc1Swenshuai.xi #define READ_LONG(_reg) (*(volatile MS_U32*)(_reg)) 362*53ee8cc1Swenshuai.xi #define WRITE_BYTE(_reg, _val) { (*((volatile MS_U8*)(_reg))) = (MS_U8)(_val); } 363*53ee8cc1Swenshuai.xi #define WRITE_WORD(_reg, _val) { (*((volatile MS_U16*)(_reg))) = (MS_U16)(_val); } 364*53ee8cc1Swenshuai.xi #define WRITE_LONG(_reg, _val) { (*((volatile MS_U32*)(_reg))) = (MS_U32)(_val); } 365*53ee8cc1Swenshuai.xi 366*53ee8cc1Swenshuai.xi 367*53ee8cc1Swenshuai.xi #if 0 368*53ee8cc1Swenshuai.xi typedef struct _cmd_mload_utopia_interface_s cmd_mload_utopia_interface; 369*53ee8cc1Swenshuai.xi struct _cmd_mload_utopia_interface_s 370*53ee8cc1Swenshuai.xi { 371*53ee8cc1Swenshuai.xi //menuload ring buffer dynamic allocation service 372*53ee8cc1Swenshuai.xi MS_PHY (*get_next_mload_ringbuf_write_ptr)(cmd_mload_utopia_interface *cmdinf); 373*53ee8cc1Swenshuai.xi MS_PHY (*update_mload_ringbuf_read_ptr)(cmd_mload_utopia_interface *cmdinf, MS_PHY next_read_ptr); 374*53ee8cc1Swenshuai.xi MS_S32 (*mload_copy_buf)(cmd_mload_utopia_interface *cmdinf, void *mload_buf, MS_U32 size, 375*53ee8cc1Swenshuai.xi MS_U16 u16Alignment, MS_PHY *phyRetAddr); 376*53ee8cc1Swenshuai.xi MS_U16 (*check_buf_available)(cmd_mload_utopia_interface *cmdinf , MS_U32 cmdq_num); 377*53ee8cc1Swenshuai.xi MS_S32 (*write_dummy_reg_cmdq)(cmd_mload_utopia_interface *cmdinf, MS_U16 value); 378*53ee8cc1Swenshuai.xi MS_U32 (*read_dummy_reg_cmdq)(cmd_mload_utopia_interface *cmdinf); 379*53ee8cc1Swenshuai.xi 380*53ee8cc1Swenshuai.xi MS_S32 (*write_reg_cmdq_mask)(cmd_mload_utopia_interface *cmdinf, MS_U32 reg_addr, MS_U16 value, MS_U16 write_mask); 381*53ee8cc1Swenshuai.xi MS_S32 (*write_reg_cmdq)(cmd_mload_utopia_interface *cmdinf, MS_U32 reg_addr, MS_U16 value); 382*53ee8cc1Swenshuai.xi MS_S32 (*cmdq_poll_reg_bits)(cmd_mload_utopia_interface *cmdinf, MS_U32 reg_addr, MS_U16 value, MS_U16 write_mask); 383*53ee8cc1Swenshuai.xi MS_S32 (*cmdq_add_wait_event_cmd)(cmd_mload_utopia_interface *cmdinf, MS_U16 event); 384*53ee8cc1Swenshuai.xi MS_S32 (*cmdq_abort_command)(cmd_mload_utopia_interface *cmdinf); 385*53ee8cc1Swenshuai.xi 386*53ee8cc1Swenshuai.xi MS_S32 (*kick_off_cmdq)(cmd_mload_utopia_interface *cmdinf); 387*53ee8cc1Swenshuai.xi 388*53ee8cc1Swenshuai.xi MS_S32 (*is_cmdq_empty_idle)(cmd_mload_utopia_interface *cmdinf); 389*53ee8cc1Swenshuai.xi 390*53ee8cc1Swenshuai.xi VOID *ctx; 391*53ee8cc1Swenshuai.xi }; 392*53ee8cc1Swenshuai.xi #endif 393*53ee8cc1Swenshuai.xi 394*53ee8cc1Swenshuai.xi #endif // _MS_COMMON_H_ 395