acrn-hypervisor/hypervisor/include/debug/logmsg.h
Junjun Shan eb8c4fb0d5 hv:Fix Implict conversion:actual to formal param
MISRAC has requirement about implict conversion: actual to formal
param. This patch is used to fix part of these violations.

1.Add a new structure seg_desc_vmcs to hold the VMCS field address of
segment selector to clean up seg_desc structure.

2.Add the definition of maximum MSI entry and the relevant judgement.

3.The violations in shell.c, logmsg.c will be fixed in other series of
patches with modification of function snprintf(), vsnprintf() and other
related usages.

v1->v2:
  *Move the definition of struct seg_desc_vmcs from instr_emul.h to
   instr_emul.c.
  *Modify the formal parameter type in function definition from uint8_t
   to char instead of using cast.
  *Drop the const declaration for char data in formal parameter.

v2->v3:
  *update the data missing conversion.
  *change type of internal parameter len to avoid casting in npklog.c.
  *change the conversion from signed char to unsigned int in
   uart16550_getc() to solve sign-extension.

Tracked-On: #861
Signed-off-by: Junjun Shan <junjun.shan@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-09-18 13:09:39 +08:00

146 lines
3.3 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef LOGMSG_H
#define LOGMSG_H
/* Logging severity levels */
#define LOG_FATAL 1U
/* For msg should be write to console and sbuf meanwhile but not fatal error */
#define LOG_ACRN 2U
#define LOG_ERROR 3U
#define LOG_WARNING 4U
#define LOG_INFO 5U
#define LOG_DEBUG 6U
/* Logging flags */
#define LOG_FLAG_STDOUT 0x00000001U
#define LOG_FLAG_MEMORY 0x00000002U
#define LOG_FLAG_NPK 0x00000004U
#define LOG_ENTRY_SIZE 80U
/* Size of buffer used to store a message being logged,
* should align to LOG_ENTRY_SIZE.
*/
#define LOG_MESSAGE_MAX_SIZE (4U * LOG_ENTRY_SIZE)
#if defined(HV_DEBUG)
extern uint32_t console_loglevel;
extern uint32_t mem_loglevel;
extern uint32_t npk_loglevel;
void init_logmsg(__unused uint32_t mem_size, uint32_t flags);
void print_logmsg_buffer(uint16_t pcpu_id);
void do_logmsg(uint32_t severity, const char *fmt, ...);
void asm_assert(int32_t line, const char *file, const char *txt);
#define ASSERT(x, ...) \
do { \
if (!(x)) {\
asm_assert(__LINE__, __FILE__, "fatal error");\
} \
} while (0)
/** The well known printf() function.
*
* Formats a string and writes it to the console output.
*
* @param fmt A pointer to the NUL terminated format string.
*
* @return The number of characters actually written or a negative
* number if an error occurred.
*/
int printf(const char *fmt, ...);
/** The well known vprintf() function.
*
* Formats a string and writes it to the console output.
*
* @param fmt A pointer to the NUL terminated format string.
* @param args The variable long argument list as va_list.
* @return The number of characters actually written or a negative
* number if an error occurred.
*/
int vprintf(const char *fmt, va_list args);
#else /* HV_DEBUG */
static inline void init_logmsg(__unused uint32_t mem_size,
__unused uint32_t flags)
{
}
static inline void do_logmsg(__unused uint32_t severity,
__unused const char *fmt, ...)
{
}
static inline void print_logmsg_buffer(__unused uint16_t pcpu_id)
{
}
#define ASSERT(x, ...) do { } while (0)
static inline int printf(__unused const char *fmt, ...)
{
return 0;
}
static inline int vprintf(__unused const char *fmt, __unused va_list args)
{
return 0;
}
#endif /* HV_DEBUG */
#ifndef pr_prefix
#define pr_prefix
#endif
#define pr_fatal(...) \
do { \
do_logmsg(LOG_FATAL, pr_prefix __VA_ARGS__); \
} while (0)
#define pr_acrnlog(...) \
do { \
do_logmsg(LOG_ACRN, pr_prefix __VA_ARGS__); \
} while (0)
#define pr_err(...) \
do { \
do_logmsg(LOG_ERROR, pr_prefix __VA_ARGS__); \
} while (0)
#define pr_warn(...) \
do { \
do_logmsg(LOG_WARNING, pr_prefix __VA_ARGS__); \
} while (0)
#define pr_info(...) \
do { \
do_logmsg(LOG_INFO, pr_prefix __VA_ARGS__); \
} while (0)
#define pr_dbg(...) \
do { \
do_logmsg(LOG_DEBUG, pr_prefix __VA_ARGS__); \
} while (0)
#define dev_dbg(lvl, ...) \
do { \
do_logmsg((lvl), pr_prefix __VA_ARGS__); \
} while (0)
#define panic(...) \
do { pr_fatal("PANIC: %s line: %d\n", __func__, __LINE__); \
pr_fatal(__VA_ARGS__); \
while (1) { asm volatile ("pause" ::: "memory"); }; } while (0)
#endif /* LOGMSG_H */