Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 9 | #pragma once |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 10 | |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 11 | #include <stdarg.h> |
Andrew Walbran | 7f904bf | 2019-07-12 16:38:38 +0100 | [diff] [blame] | 12 | #include <stddef.h> |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 13 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 14 | #include "hf/ffa.h" |
Andrew Walbran | c1ad4ce | 2019-05-09 11:41:39 +0100 | [diff] [blame] | 15 | |
Andrew Walbran | f3ac84d | 2019-07-26 16:10:02 +0100 | [diff] [blame] | 16 | #define DLOG_BUFFER_SIZE 8192 |
| 17 | |
Karl Meakin | e8fdaed | 2024-05-22 10:02:21 +0100 | [diff] [blame] | 18 | enum log_level { |
| 19 | LOG_LEVEL_NONE = 0, |
| 20 | LOG_LEVEL_ERROR = 1, |
| 21 | LOG_LEVEL_NOTICE = 2, |
| 22 | LOG_LEVEL_WARNING = 3, |
| 23 | LOG_LEVEL_INFO = 4, |
| 24 | LOG_LEVEL_VERBOSE = 5, |
| 25 | }; |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 26 | |
Andrew Walbran | f3ac84d | 2019-07-26 16:10:02 +0100 | [diff] [blame] | 27 | extern size_t dlog_buffer_offset; |
| 28 | extern char dlog_buffer[]; |
| 29 | |
Andrew Scull | fdd716e | 2018-12-20 05:37:31 +0000 | [diff] [blame] | 30 | void dlog_enable_lock(void); |
Karl Meakin | 5445490 | 2024-04-02 16:27:06 +0100 | [diff] [blame^] | 31 | __attribute__((format(printf, 1, 2))) size_t dlog(const char *fmt, ...); |
Karl Meakin | d2ef618 | 2024-05-22 11:23:12 +0100 | [diff] [blame] | 32 | size_t vdlog(const char *fmt, va_list args); |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 33 | |
Demi Marie Obenour | 33f8a16 | 2023-02-14 12:21:41 -0500 | [diff] [blame] | 34 | /* |
| 35 | * The do { ... } while (0) syntax is used to ensure that callers of |
| 36 | * these macros follow them with a semicolon. |
| 37 | * |
| 38 | * Run-time conditionals are preferred over preprocessor conditionals to ensure |
| 39 | * that the code is type-checked and linted unconditionally, even if it will not |
| 40 | * be executed at run-time. Logging statements that are disabled at |
| 41 | * compile-time are unreachable code and will be eliminated by compiler |
| 42 | * optimizations. |
| 43 | */ |
| 44 | #define dlog_error(...) \ |
| 45 | do { \ |
| 46 | if (LOG_LEVEL >= LOG_LEVEL_ERROR) { \ |
| 47 | dlog("ERROR: " __VA_ARGS__); \ |
| 48 | } \ |
| 49 | } while (0) |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 50 | |
Demi Marie Obenour | 33f8a16 | 2023-02-14 12:21:41 -0500 | [diff] [blame] | 51 | #define dlog_notice(...) \ |
| 52 | do { \ |
| 53 | if (LOG_LEVEL >= LOG_LEVEL_NOTICE) { \ |
| 54 | dlog("NOTICE: " __VA_ARGS__); \ |
| 55 | } \ |
| 56 | } while (0) |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 57 | |
Demi Marie Obenour | 33f8a16 | 2023-02-14 12:21:41 -0500 | [diff] [blame] | 58 | #define dlog_warning(...) \ |
| 59 | do { \ |
| 60 | if (LOG_LEVEL >= LOG_LEVEL_WARNING) { \ |
| 61 | dlog("WARNING: " __VA_ARGS__); \ |
| 62 | } \ |
| 63 | } while (0) |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 64 | |
Demi Marie Obenour | 33f8a16 | 2023-02-14 12:21:41 -0500 | [diff] [blame] | 65 | #define dlog_info(...) \ |
| 66 | do { \ |
| 67 | if (LOG_LEVEL >= LOG_LEVEL_WARNING) { \ |
| 68 | dlog("INFO: " __VA_ARGS__); \ |
| 69 | } \ |
| 70 | } while (0) |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 71 | |
Demi Marie Obenour | 33f8a16 | 2023-02-14 12:21:41 -0500 | [diff] [blame] | 72 | #define dlog_verbose(...) \ |
| 73 | do { \ |
| 74 | if (LOG_LEVEL >= LOG_LEVEL_VERBOSE) { \ |
| 75 | dlog("VERBOSE: " __VA_ARGS__); \ |
| 76 | } \ |
| 77 | } while (0) |