1 /* 2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef SAMPLE_COMM_SVP_H 16 #define SAMPLE_COMM_SVP_H 17 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <string.h> 21 #include <errno.h> 22 #include <fcntl.h> 23 #include <sys/mman.h> 24 #include <sys/stat.h> 25 #include <sys/types.h> 26 #include <unistd.h> 27 #include <signal.h> 28 #include "hi_common.h" 29 #include "hi_debug.h" 30 31 #ifdef __cplusplus 32 #if __cplusplus 33 extern "C" { 34 #endif 35 #endif /* __cplusplus */ 36 37 typedef enum hiSAMPLE_SVP_ERR_LEVEL_E { 38 SAMPLE_SVP_ERR_LEVEL_DEBUG, /* debug-level */ 39 SAMPLE_SVP_ERR_LEVEL_INFO, /* informational */ 40 SAMPLE_SVP_ERR_LEVEL_NOTICE, /* normal but significant condition */ 41 SAMPLE_SVP_ERR_LEVEL_WARNING, /* warning conditions */ 42 SAMPLE_SVP_ERR_LEVEL_ERROR, /* error conditions */ 43 SAMPLE_SVP_ERR_LEVEL_CRIT, /* critical conditions */ 44 SAMPLE_SVP_ERR_LEVEL_ALERT, /* action must be taken immediately */ 45 SAMPLE_SVP_ERR_LEVEL_FATAL, /* just for compatibility with previous version */ 46 SAMPLE_SVP_ERR_LEVEL_BUTT 47 } SAMPLE_SVP_ERR_LEVEL_E; 48 49 #define SAMPLE_SVP_PRINTF(LevelStr, Msg, ...) \ 50 do { \ 51 fprintf(stderr, "[Level]:%s,[Func]:%s [Line]:%d [Info]:" Msg, LevelStr, __FUNCTION__, __LINE__, \ 52 ##__VA_ARGS__); \ 53 } while (0) 54 #define SAMPLE_SVP_PRINTF_RED(LevelStr, Msg, ...) \ 55 do { \ 56 fprintf(stderr, "\033[0;31m [Level]:%s,[Func]:%s [Line]:%d [Info]:" Msg "\033[0;39m\n", LevelStr, \ 57 __FUNCTION__, __LINE__, ##__VA_ARGS__); \ 58 } while (0) 59 60 #define SAMPLE_SVP_TRACE_FATAL(Msg, ...) SAMPLE_SVP_PRINTF_RED("Fatal", Msg, ##__VA_ARGS__) 61 #define SAMPLE_SVP_TRACE_ALERT(Msg, ...) SAMPLE_SVP_PRINTF_RED("Alert", Msg, ##__VA_ARGS__) 62 #define SAMPLE_SVP_TRACE_CRIT(Msg, ...) SAMPLE_SVP_PRINTF_RED("Critical", Msg, ##__VA_ARGS__) 63 #define SAMPLE_SVP_TRACE_ERR(Msg, ...) SAMPLE_SVP_PRINTF_RED("Error", Msg, ##__VA_ARGS__) 64 #define SAMPLE_SVP_TRACE_WARN(Msg, ...) SAMPLE_SVP_PRINTF("Warning", Msg, ##__VA_ARGS__) 65 #define SAMPLE_SVP_TRACE_NOTICE(Msg, ...) SAMPLE_SVP_PRINTF("Notice", Msg, ##__VA_ARGS__) 66 #define SAMPLE_SVP_TRACE_INFO(Msg, ...) SAMPLE_SVP_PRINTF("Info", Msg, ##__VA_ARGS__) 67 #define SAMPLE_SVP_TRACE_DEBUG(Msg, ...) SAMPLE_SVP_PRINTF("Debug", Msg, ##__VA_ARGS__) 68 69 #define SAMPLE_SVP_TRACE(Level, Msg, ...) \ 70 do { \ 71 switch (Level) { \ 72 case SAMPLE_SVP_ERR_LEVEL_DEBUG: \ 73 SAMPLE_SVP_TRACE_DEBUG(Msg, ##__VA_ARGS__); \ 74 break; \ 75 case SAMPLE_SVP_ERR_LEVEL_INFO: \ 76 SAMPLE_SVP_TRACE_INFO(Msg, ##__VA_ARGS__); \ 77 break; \ 78 case SAMPLE_SVP_ERR_LEVEL_NOTICE: \ 79 SAMPLE_SVP_TRACE_NOTICE(Msg, ##__VA_ARGS__); \ 80 break; \ 81 case SAMPLE_SVP_ERR_LEVEL_WARNING: \ 82 SAMPLE_SVP_TRACE_WARN(Msg, ##__VA_ARGS__); \ 83 break; \ 84 case SAMPLE_SVP_ERR_LEVEL_ERROR: \ 85 SAMPLE_SVP_TRACE_ERR(Msg, ##__VA_ARGS__); \ 86 break; \ 87 case SAMPLE_SVP_ERR_LEVEL_CRIT: \ 88 SAMPLE_SVP_TRACE_CRIT(Msg, ##__VA_ARGS__); \ 89 break; \ 90 case SAMPLE_SVP_ERR_LEVEL_ALERT: \ 91 SAMPLE_SVP_TRACE_ALERT(Msg, ##__VA_ARGS__); \ 92 break; \ 93 case SAMPLE_SVP_ERR_LEVEL_FATAL: \ 94 SAMPLE_SVP_TRACE_FATAL(Msg, ##__VA_ARGS__); \ 95 break; \ 96 default: \ 97 break; \ 98 } \ 99 } while (0) 100 101 #define SAMPLE_SVP_CHECK_EXPR_GOTO(Expr, Label, Level, Msg, ...) \ 102 do { \ 103 if (Expr) { \ 104 SAMPLE_SVP_TRACE(Level, Msg, ##__VA_ARGS__); \ 105 goto Label; \ 106 } \ 107 } while (0) 108 109 #define SAMPLE_SVP_CHECK_EXPR_RET_VOID(Expr, Level, Msg, ...) \ 110 do { \ 111 if (Expr) { \ 112 SAMPLE_SVP_TRACE(Level, Msg, ##__VA_ARGS__); \ 113 return; \ 114 } \ 115 } while (0) 116 117 #define SAMPLE_SVP_CHECK_EXPR_RET(Expr, Ret, Level, Msg, ...) \ 118 do { \ 119 if (Expr) { \ 120 SAMPLE_SVP_TRACE(Level, Msg, ##__VA_ARGS__); \ 121 return Ret; \ 122 } \ 123 } while (0) 124 125 #define SAMPLE_SVP_CHECK_EXPR_TRACE(Expr, Level, Msg, ...) \ 126 do { \ 127 if (Expr) { \ 128 SAMPLE_SVP_TRACE(Level, Msg, ##__VA_ARGS__); \ 129 } \ 130 } while (0) 131 132 #define SAMPLE_SVP_ALIGN_16 16 133 #define SAMPLE_SVP_ALIGN_32 32 134 #define SAMPLE_SVP_D1_PAL_HEIGHT 576 135 #define SAMPLE_SVP_D1_PAL_WIDTH 704 136 137 #define SAMPLE_SVP_MMZ_FREE(phy, vir) \ 138 do { \ 139 if (((phy) != 0) && ((vir) != 0)) { \ 140 HI_MPI_SYS_MmzFree((phy), (HI_VOID *)(HI_UINTPTR_T)(vir)); \ 141 (phy) = 0; \ 142 (vir) = 0; \ 143 } \ 144 } while (0) 145 146 147 #define SAMPLE_SVP_CLOSE_FILE(fp) \ 148 do { \ 149 if ((fp) != NULL) { \ 150 (void)fclose((fp)); \ 151 (fp) = NULL; \ 152 } \ 153 } while (0) 154 155 HI_S32 SAMPLE_COMM_SVP_CheckSysInit(void); 156 157 HI_VOID SAMPLE_COMM_SVP_CheckSysExit(void); 158 159 HI_U32 SAMPLE_COMM_SVP_Align(HI_U32 u32Size, HI_U16 u16Align); 160 161 HI_S32 SAMPLE_COMM_SVP_CreateImage(SVP_IMAGE_S *pstImg, SVP_IMAGE_TYPE_E enType, HI_U32 u32Width, HI_U32 u32Height, 162 HI_U32 u32AddrOffset); 163 164 HI_VOID SAMPLE_COMM_SVP_DestroyImage(SVP_IMAGE_S *pstImg, HI_U32 u32AddrOffset); 165 166 HI_S32 SAMPLE_COMM_SVP_CreateMemInfo(SVP_MEM_INFO_S *pstMemInfo, HI_U32 u32Size, HI_U32 u32AddrOffset); 167 168 HI_VOID SAMPLE_COMM_SVP_DestroyMemInfo(SVP_MEM_INFO_S *pstMemInfo, HI_U32 u32AddrOffset); 169 170 HI_S32 SAMPLE_COMM_SVP_MallocMem(HI_CHAR *pszMmb, HI_CHAR *pszZone, HI_U64 *pu64PhyAddr, HI_VOID **ppvVirAddr, 171 HI_U32 u32Size); 172 173 HI_S32 SAMPLE_COMM_SVP_MallocCached(HI_CHAR *pszMmb, HI_CHAR *pszZone, HI_U64 *pu64PhyAddr, HI_VOID **ppvVirAddr, 174 HI_U32 u32Size); 175 176 HI_S32 SAMPLE_COMM_SVP_FlushCache(HI_U64 u64PhyAddr, HI_VOID *pvVirAddr, HI_U32 u32Size); 177 178 #ifdef __cplusplus 179 #if __cplusplus 180 } 181 #endif 182 #endif /* __cplusplus */ 183 184 #endif /* SAMPLE_COMM_SVP_H */ 185