1 /* 2 * SPDX-FileCopyrightText: Copyright (c) 2016-2017,2020-2020 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 * SPDX-License-Identifier: MIT 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 /** 25 * Internal macro definitions for NVLOG_PRINTF 26 * 27 * Macro magic example: (Assuming nothing gets compiled out) 28 * 0) NV_PRINTF(LEVEL_ERROR, "Bla %d %d", arg0, arg1) 29 * 1) NVLOG_PRINTF(GLOBAL, LEVEL_ERROR, "Bla %d %d", arg0, arg1)) 30 * - This gets picked up by the parser 31 * 2) _NVLOG_GET_PRINT 32 * 3) _NVLOG_GET_PRINT1(NVLOG_, NVLOG_FILEID, __LINE__, PRINT_REL, ___please_include_noprecomp_h___) 33 * 4) _NVLOG_GET_PRINT2(NVLOG_, 0xaaaaaa, 1024, PRINT_REL, ___please_include_noprecomp_h___) 34 * 5) NVLOG_0xaaaaaa_1024_PRINT_REL 35 * 6) NVLOG_PRINT(LEVEL_ERROR, 0xaaaaaa, 0x04001100, arg0, arg1) 36 * 7) NVLOG_PRINT2(LEVEL_ERROR) (0xaaaaaa, 0x04001100, arg0, arg1) 37 * 8) NVLOG_PRINT_LEVEL_0x4 (0xaaaaaa, 0x04001100, arg0, arg1) 38 * 9) nvLog_Printf4 (0xaaaaaa, 0x04001100, arg0, arg1) 39 * 40 */ 41 42 // Compile time stubbing out output below NVLOG_LEVEL level 43 #define _NVLOG_NOTHING(...) ((void)0) 44 45 // 46 // Use __COUNTER__ if available. If not, we can use __LINE__ since it is also 47 // monotonically rising. If __COUNTER__ is unavailable, we can't have inline 48 // functions using NvLog. 49 // 50 #if PORT_COMPILER_HAS_COUNTER 51 #define _NVLOG_COUNTER __COUNTER__ 52 #else 53 #define _NVLOG_COUNTER __LINE__ 54 #endif 55 56 // 57 // NVLOG_PARSING is defined if the file is being compiled for the parser run 58 // 59 #if defined(NVLOG_PARSING) 60 61 // 62 // Since the '@' symbol is not found in C code, using it here makes it trivial 63 // for the parser code to extract the needed info from preprocessed source. 64 // 65 #define _NVLOG_PRINTF2(count, file, line, tag, route, level, format, ...) \ 66 NVLOG@@@count@@@file@@@line@@@level@@@tag@@@route@@@format@@@__VA_ARGS__@@@ 67 68 #define _NVLOG_PRINTF(tag, route, level, format, ...) \ 69 _NVLOG_PRINTF2(_NVLOG_COUNTER, __FILE__, __LINE__, tag, route, level, format, __VA_ARGS__) 70 71 #elif !NVLOG_ENABLED 72 73 #define _NVLOG_PRINTF _NVLOG_NOTHING 74 75 #else // NVLOG_ENABLED && !defined(NVLOG_PARSING) 76 77 #include "nvlog_inc.h" 78 79 #ifdef NVLOG_STRINGS_ALLOWED 80 #define NVLOG_STRING(...) __VA_ARGS__ 81 #else 82 #define NVLOG_STRING(...) 83 #endif 84 85 // 86 // One for every debug level, needed for compile time filtering. 87 // 88 typedef NV_STATUS NVLOG_PRINTF_PROTO(NvU32, NvU32, ...); 89 NVLOG_PRINTF_PROTO nvlogPrint_printf0; 90 NVLOG_PRINTF_PROTO nvlogPrint_printf1; 91 NVLOG_PRINTF_PROTO nvlogPrint_printf2; 92 NVLOG_PRINTF_PROTO nvlogPrint_printf3; 93 NVLOG_PRINTF_PROTO nvlogPrint_printf4; 94 NVLOG_PRINTF_PROTO nvlogPrint_printf5; 95 NVLOG_PRINTF_PROTO nvlogPrint_printf6; 96 97 // This one is used for unknown debug level - It has an extra argument 98 NV_STATUS nvlogPrint_printf(NvU32 dbgLevel, NvU32 file, NvU32 line, ...); 99 100 101 #if NVLOG_LEVEL <= LEVEL_SILENT 102 #define NVLOG_PRINT_LEVEL_0x0 nvlogPrint_printf0 103 #else 104 #define NVLOG_PRINT_LEVEL_0x0 _NVLOG_NOTHING 105 #endif 106 #if NVLOG_LEVEL <= LEVEL_INFO 107 #define NVLOG_PRINT_LEVEL_0x1 nvlogPrint_printf1 108 #else 109 #define NVLOG_PRINT_LEVEL_0x1 _NVLOG_NOTHING 110 #endif 111 #if NVLOG_LEVEL <= LEVEL_NOTICE 112 #define NVLOG_PRINT_LEVEL_0x2 nvlogPrint_printf2 113 #else 114 #define NVLOG_PRINT_LEVEL_0x2 _NVLOG_NOTHING 115 #endif 116 #if NVLOG_LEVEL <= LEVEL_WARNING 117 #define NVLOG_PRINT_LEVEL_0x3 nvlogPrint_printf3 118 #else 119 #define NVLOG_PRINT_LEVEL_0x3 _NVLOG_NOTHING 120 #endif 121 #if NVLOG_LEVEL <= LEVEL_ERROR 122 #define NVLOG_PRINT_LEVEL_0x4 nvlogPrint_printf4 123 #else 124 #define NVLOG_PRINT_LEVEL_0x4 _NVLOG_NOTHING 125 #endif 126 #if NVLOG_LEVEL <= LEVEL_HW_ERROR 127 #define NVLOG_PRINT_LEVEL_0x5 nvlogPrint_printf5 128 #else 129 #define NVLOG_PRINT_LEVEL_0x5 _NVLOG_NOTHING 130 #endif 131 #if NVLOG_LEVEL <= LEVEL_FATAL 132 #define NVLOG_PRINT_LEVEL_0x6 nvlogPrint_printf6 133 #else 134 #define NVLOG_PRINT_LEVEL_0x6 _NVLOG_NOTHING 135 #endif 136 // For when the level isn't known at compile time 137 #define NVLOG_PRINT_LEVEL_ NVLOG_PRINT_LEVEL_UNKNOWN 138 #define NVLOG_PRINT_LEVEL_UNKNOWN nvlogPrint_printf 139 140 141 #define NVLOG_PRINT2(dbglvl) NVLOG_PRINT_LEVEL_ ## dbglvl 142 #define NVLOG_PRINT(level, ...) NVLOG_PRINT2(level)(__VA_ARGS__) 143 144 #define _NVLOG_GET_PRINT2(prefix, x) prefix ##x 145 #define _NVLOG_GET_PRINT1(prefix, id) _NVLOG_GET_PRINT2(prefix, id) 146 #define _NVLOG_GET_PRINT _NVLOG_GET_PRINT1(NVLOG_PRINT_ID_, _NVLOG_COUNTER) 147 148 #define _NVLOG_PRINTF(tag, route, level, format, ...) _NVLOG_GET_PRINT 149 150 #endif // NVLOG_ENABLED && !defined(NVLOG_PARSING) 151