1 /*
2  * Copyright 2018 The Hafnium Authors.
3  *
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.
7  */
8 
9 #pragma once
10 
11 #include <stdarg.h>
12 #include <stddef.h>
13 
14 #include "hf/ffa.h"
15 
16 #define DLOG_BUFFER_SIZE 8192
17 
18 #define LOG_LEVEL_NONE UINT32_C(0)
19 #define LOG_LEVEL_ERROR UINT32_C(1)
20 #define LOG_LEVEL_NOTICE UINT32_C(2)
21 #define LOG_LEVEL_WARNING UINT32_C(3)
22 #define LOG_LEVEL_INFO UINT32_C(4)
23 #define LOG_LEVEL_VERBOSE UINT32_C(5)
24 
25 extern size_t dlog_buffer_offset;
26 extern char dlog_buffer[];
27 
28 void dlog_enable_lock(void);
29 void dlog(const char *fmt, ...);
30 void vdlog(const char *fmt, va_list args);
31 
32 #if LOG_LEVEL >= LOG_LEVEL_ERROR
33 #define dlog_error(...) dlog("ERROR: " __VA_ARGS__)
34 #else
35 #define dlog_error(...)
36 #endif
37 
38 #if LOG_LEVEL >= LOG_LEVEL_NOTICE
39 #define dlog_notice(...) dlog("NOTICE: " __VA_ARGS__)
40 #else
41 #define dlog_notice(...)
42 #endif
43 
44 #if LOG_LEVEL >= LOG_LEVEL_WARNING
45 #define dlog_warning(...) dlog("WARNING: " __VA_ARGS__)
46 #else
47 #define dlog_warning(...)
48 #endif
49 
50 #if LOG_LEVEL >= LOG_LEVEL_INFO
51 #define dlog_info(...) dlog("INFO: " __VA_ARGS__)
52 #else
53 #define dlog_info(...)
54 #endif
55 
56 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
57 #define dlog_verbose(...) dlog("VERBOSE: " __VA_ARGS__)
58 #else
59 #define dlog_verbose(...)
60 #endif
61 
62 void dlog_flush_vm_buffer(ffa_vm_id_t id, char buffer[], size_t length);
63