From 6e43d1b19982b1756b7c607569d1778e556d6577 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 28 Dec 2017 13:14:15 -0700 Subject: dm: core: Add a function to look up a uclass by name Each uclass has a driver name which we can use to look up the uclass. This is useful for logging, where the uclass ID is used as the category. Add a function to handle this, as well as a test. Signed-off-by: Simon Glass --- include/dm/uclass.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 709f661..3a01abc 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -128,6 +128,14 @@ int uclass_get(enum uclass_id key, struct uclass **ucp); const char *uclass_get_name(enum uclass_id id); /** + * uclass_get_by_name() - Look up a uclass by its driver name + * + * @name: Name to look up + * @returns the associated uclass ID, or UCLASS_INVALID if not found + */ +enum uclass_id uclass_get_by_name(const char *name); + +/** * uclass_get_device() - Get a uclass device based on an ID and index * * The device is probed to activate it ready for use. -- cgit v1.1 From f941c8d76c665045e5d645112a309d12523e19c7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 28 Dec 2017 13:14:16 -0700 Subject: log: Add functions to convert IDs to/from names Category and level both use an enum for their ID values. Add functions to convert these IDs to strings and vice versa. This will allow the log to output the strings instead of the (inscrutable) values. At the same time, add a new 'driver-model' category, to cover core driver-model functions and fix an incorrect value for LOGL_MAX. Tests will be added with the new 'log' subcommands. Signed-off-by: Simon Glass (Updated to correct clang warnings) --- include/log.h | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/log.h b/include/log.h index 8083b64..5133213 100644 --- a/include/log.h +++ b/include/log.h @@ -27,8 +27,10 @@ enum log_level_t { LOGL_DEBUG_IO, /* Debug message showing hardware I/O access */ LOGL_COUNT, + LOGL_NONE, + LOGL_FIRST = LOGL_EMERG, - LOGL_MAX = LOGL_DEBUG, + LOGL_MAX = LOGL_DEBUG_IO, }; /** @@ -42,7 +44,8 @@ enum log_category_t { LOGC_ARCH, LOGC_BOARD, LOGC_CORE, - LOGC_DT, + LOGC_DM, /* Core driver-model */ + LOGC_DT, /* Device-tree */ LOGC_COUNT, LOGC_END, @@ -256,6 +259,38 @@ struct log_filter { #define LOG_DRIVER(_name) \ ll_entry_declare(struct log_driver, _name, log_driver) +/** + * log_get_cat_name() - Get the name of a category + * + * @cat: Category to look up + * @return category name (which may be a uclass driver name) + */ +const char *log_get_cat_name(enum log_category_t cat); + +/** + * log_get_cat_by_name() - Look up a category by name + * + * @name: Name to look up + * @return category ID, or LOGC_NONE if not found + */ +enum log_category_t log_get_cat_by_name(const char *name); + +/** + * log_get_level_name() - Get the name of a log level + * + * @level: Log level to look up + * @return log level name (in ALL CAPS) + */ +const char *log_get_level_name(enum log_level_t level); + +/** + * log_get_level_by_name() - Look up a log level by name + * + * @name: Name to look up + * @return log level ID, or LOGL_NONE if not found + */ +enum log_level_t log_get_level_by_name(const char *name); + /* Handle the 'log test' command */ int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]); -- cgit v1.1 From 3b73e8d067fb7cb504bed2018583980a3cd3f4bc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 28 Dec 2017 13:14:17 -0700 Subject: log: Add control over log formatting It is useful to be able to control the output format of log records on the console. As a starting point, add definitions for controlling which elements of the log record are displayed. Use function and message as the default, since these are the most useful fields. Signed-off-by: Simon Glass --- include/asm-generic/global_data.h | 1 + include/log.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index fd8cd45..1de67e8 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -119,6 +119,7 @@ typedef struct global_data { int log_drop_count; /* Number of dropped log messages */ int default_log_level; /* For devices with no filters */ struct list_head log_head; /* List of struct log_device */ + int log_fmt; /* Mask containing log format info */ #endif } gd_t; #endif diff --git a/include/log.h b/include/log.h index 5133213..828919a 100644 --- a/include/log.h +++ b/include/log.h @@ -291,6 +291,20 @@ const char *log_get_level_name(enum log_level_t level); */ enum log_level_t log_get_level_by_name(const char *name); +/* Log format flags (bit numbers) for gd->log_fmt. See log_fmt_chars */ +enum log_fmt { + LOGF_CAT = 0, + LOGF_LEVEL, + LOGF_FILE, + LOGF_LINE, + LOGF_FUNC, + LOGF_MSG, + + LOGF_COUNT, + LOGF_DEFAULT = (1 << LOGF_FUNC) | (1 << LOGF_MSG), + LOGF_ALL = 0x3f, +}; + /* Handle the 'log test' command */ int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]); -- cgit v1.1 From 3707c6ee0d1f939130a62c945b56045d9a83fafc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 28 Dec 2017 13:14:23 -0700 Subject: log: Add a way to log error-return values When functions return an error it propagates up the stack to the point where it is reported. Often the error code provides enough information about the root cause of the error that this is obvious what went wrong. However in some cases the error may be hard to trace. For example if a driver uses several devices to perform an operation, it may not be obvious which one failed. Add a log_ret() macro to help with this. This can be used to wrap any error-return value. The logging system will then output a log record when the original error is generated, making it easy to trace the call stack of the error. This macro can significantly impact code size, so its use is controlled by a Kconfig option, which is enabled for sandbox. Signed-off-by: Simon Glass --- include/log.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/log.h b/include/log.h index 828919a..68368d5 100644 --- a/include/log.h +++ b/include/log.h @@ -159,6 +159,17 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line, ({ if (!(x) && _DEBUG) \ __assert_fail(#x, __FILE__, __LINE__, __func__); }) +#ifdef CONFIG_LOG_ERROR_RETURN +#define log_ret(_ret) ({ \ + int __ret = (_ret); \ + if (__ret < 0) \ + log(LOG_CATEGORY, LOGL_ERR, "returning err=%d\n", __ret); \ + __ret; \ + }) +#else +#define log_ret(_ret) (_ret) +#endif + /** * struct log_rec - a single log record * -- cgit v1.1 From 1973b381a1b3545783c3238080f566746579e923 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 22 Jan 2018 20:10:45 +0100 Subject: log: add category LOGC_EFI The EFI implementation does not fit into any of the existing categories. Provide LOGC_EFI so that EFI related message can be filtered. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- include/log.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/log.h b/include/log.h index 68368d5..20dc528 100644 --- a/include/log.h +++ b/include/log.h @@ -46,6 +46,7 @@ enum log_category_t { LOGC_CORE, LOGC_DM, /* Core driver-model */ LOGC_DT, /* Device-tree */ + LOGL_EFI, /* EFI implementation */ LOGC_COUNT, LOGC_END, -- cgit v1.1