blob: 1532d59352ab4a3648b78fac795059cb69a20208 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * 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 Scull18834872018-10-12 11:48:09 +01007 */
8
Andrew Scullfbc938a2018-08-20 14:09:28 +01009#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010010
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010011#include <stdarg.h>
Andrew Walbran7f904bf2019-07-12 16:38:38 +010012#include <stddef.h>
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010013
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010014#include "hf/ffa.h"
Andrew Walbranc1ad4ce2019-05-09 11:41:39 +010015
Andrew Walbranf3ac84d2019-07-26 16:10:02 +010016#define DLOG_BUFFER_SIZE 8192
17
Karl Meakine8fdaed2024-05-22 10:02:21 +010018enum 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 Walbran17eebf92020-02-05 16:35:49 +000026
Andrew Walbranf3ac84d2019-07-26 16:10:02 +010027extern size_t dlog_buffer_offset;
28extern char dlog_buffer[];
29
Andrew Scullfdd716e2018-12-20 05:37:31 +000030void dlog_enable_lock(void);
Karl Meakind2ef6182024-05-22 11:23:12 +010031size_t dlog(const char *fmt, ...);
32size_t vdlog(const char *fmt, va_list args);
Andrew Walbran17eebf92020-02-05 16:35:49 +000033
Demi Marie Obenour33f8a162023-02-14 12:21:41 -050034/*
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 Walbran17eebf92020-02-05 16:35:49 +000050
Demi Marie Obenour33f8a162023-02-14 12:21:41 -050051#define dlog_notice(...) \
52 do { \
53 if (LOG_LEVEL >= LOG_LEVEL_NOTICE) { \
54 dlog("NOTICE: " __VA_ARGS__); \
55 } \
56 } while (0)
Andrew Walbran17eebf92020-02-05 16:35:49 +000057
Demi Marie Obenour33f8a162023-02-14 12:21:41 -050058#define dlog_warning(...) \
59 do { \
60 if (LOG_LEVEL >= LOG_LEVEL_WARNING) { \
61 dlog("WARNING: " __VA_ARGS__); \
62 } \
63 } while (0)
Andrew Walbran17eebf92020-02-05 16:35:49 +000064
Demi Marie Obenour33f8a162023-02-14 12:21:41 -050065#define dlog_info(...) \
66 do { \
67 if (LOG_LEVEL >= LOG_LEVEL_WARNING) { \
68 dlog("INFO: " __VA_ARGS__); \
69 } \
70 } while (0)
Andrew Walbran17eebf92020-02-05 16:35:49 +000071
Demi Marie Obenour33f8a162023-02-14 12:21:41 -050072#define dlog_verbose(...) \
73 do { \
74 if (LOG_LEVEL >= LOG_LEVEL_VERBOSE) { \
75 dlog("VERBOSE: " __VA_ARGS__); \
76 } \
77 } while (0)