summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2020-09-30 09:07:06 -0400
committerTom Rini <[email protected]>2020-09-30 09:07:06 -0400
commit527fad0b2484bf1dd4c443c4c8f4384aa256938f (patch)
treee50b2e3551ce9ac05713b1204e63faea793e94f7 /include
parent0ac83d080a0044cd0d8f782ba12f02cf969d3004 (diff)
parentceb70bb870ac0761992d3e38e9287a338e3b846a (diff)
Merge branch '2020-09-29-dev_xxx-print-improvement' into next
- Improve our dev_xxx(..) wrappers to be generally used and available rather than discarded at link/compile time.
Diffstat (limited to 'include')
-rw-r--r--include/dm/device_compat.h127
-rw-r--r--include/linux/compat.h19
-rw-r--r--include/mmc.h2
-rw-r--r--include/remoteproc.h13
4 files changed, 93 insertions, 68 deletions
diff --git a/include/dm/device_compat.h b/include/dm/device_compat.h
index 3d8cd09f4c0..8f26053b450 100644
--- a/include/dm/device_compat.h
+++ b/include/dm/device_compat.h
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
+ * Copyright (C) 2020 Sean Anderson <[email protected]>
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
@@ -10,6 +11,8 @@
#ifndef _DM_DEVICE_COMPAT_H
#define _DM_DEVICE_COMPAT_H
+#include <log.h>
+#include <linux/build_bug.h>
#include <linux/compat.h>
/*
@@ -33,54 +36,106 @@
#endif
/*
- * REVISIT:
- * print device name like Linux
+ * Define a new identifier which can be tested on by C code. A similar
+ * definition is made for DEBUG in <log.h>.
*/
-#define dev_printk(dev, fmt, ...) \
-({ \
- printk(fmt, ##__VA_ARGS__); \
+#ifdef VERBOSE_DEBUG
+#define _VERBOSE_DEBUG 1
+#else
+#define _VERBOSE_DEBUG 0
+#endif
+
+/**
+ * dev_printk_emit() - Emit a formatted log message
+ * @cat: Category of the message
+ * @level: Log level of the message
+ * @fmt: Format string
+ * @...: Arguments for @fmt
+ *
+ * This macro logs a message through the appropriate channel. It is a macro so
+ * the if statements can be optimized out (as @level should be a constant known
+ * at compile-time).
+ *
+ * If DEBUG or VERBOSE_DEBUG is defined, then some messages are always printed
+ * (through printf()). This is to match the historical behavior of the dev_xxx
+ * functions.
+ *
+ * If LOG is enabled, use log() to emit the message, otherwise print it based on
+ * the console loglevel.
+ */
+#define dev_printk_emit(cat, level, fmt, ...) \
+({ \
+ if ((_DEBUG && level == LOGL_DEBUG) || \
+ (_VERBOSE_DEBUG && level == LOGL_DEBUG_CONTENT)) \
+ printf(fmt, ##__VA_ARGS__); \
+ else if (CONFIG_IS_ENABLED(LOG)) \
+ log(cat, level, fmt, ##__VA_ARGS__); \
+ else if (level < CONFIG_VAL(LOGLEVEL)) \
+ printf(fmt, ##__VA_ARGS__); \
})
-#define __dev_printk(level, dev, fmt, ...) \
-({ \
- if (level < CONFIG_VAL(LOGLEVEL)) \
- dev_printk(dev, fmt, ##__VA_ARGS__); \
+/**
+ * __dev_printk() - Log a message for a device
+ * @level: Log level of the message
+ * @dev: A &struct udevice or &struct device
+ * @fmt: Format string
+ * @...: Arguments for @fmt
+ *
+ * This macro formats and prints dev_xxx log messages. It is done as a macro
+ * because working with variadic argument is much easier this way, we can
+ * interrogate the type of device we are passed (and whether it *is* a &struct
+ * udevice or &struct device), and dev_printk_emit() can optimize out unused if
+ * branches.
+ *
+ * Because this is a macro, we must enforce type checks ourselves. Ideally, we
+ * would only accept udevices, but there is a significant amount of code (mostly
+ * USB) which calls dev_xxx with &struct device. When assigning ``__dev``, we
+ * must first cast ``dev`` to ``void *`` so we don't get warned when ``dev`` is
+ * a &struct device. Even though the latter branch is not taken, it will still
+ * get compiled and type-checked.
+ *
+ * The format strings in case of a ``NULL`` ``dev`` MUST be kept the same.
+ * Otherwise, @fmt will be duplicated in the data section (with slightly
+ * different prefixes). This is why ``(NULL udevice *)`` is printed as two
+ * string arguments, and not by string pasting.
+ */
+#define __dev_printk(level, dev, fmt, ...) \
+({ \
+ if (__same_type(dev, struct device *)) { \
+ dev_printk_emit(LOG_CATEGORY, level, fmt, ##__VA_ARGS__); \
+ } else { \
+ BUILD_BUG_ON(!__same_type(dev, struct udevice *)); \
+ struct udevice *__dev = (void *)dev; \
+ if (__dev) \
+ dev_printk_emit(__dev->driver->id, level, \
+ "%s %s: " fmt, \
+ __dev->driver->name, __dev->name, \
+ ##__VA_ARGS__); \
+ else \
+ dev_printk_emit(LOG_CATEGORY, level, \
+ "%s %s: " fmt, \
+ "(NULL", "udevice *)", \
+ ##__VA_ARGS__); \
+ } \
})
#define dev_emerg(dev, fmt, ...) \
- __dev_printk(0, dev, fmt, ##__VA_ARGS__)
+ __dev_printk(LOGL_EMERG, dev, fmt, ##__VA_ARGS__)
#define dev_alert(dev, fmt, ...) \
- __dev_printk(1, dev, fmt, ##__VA_ARGS__)
+ __dev_printk(LOGL_ALERT, dev, fmt, ##__VA_ARGS__)
#define dev_crit(dev, fmt, ...) \
- __dev_printk(2, dev, fmt, ##__VA_ARGS__)
+ __dev_printk(LOGL_CRIT, dev, fmt, ##__VA_ARGS__)
#define dev_err(dev, fmt, ...) \
- __dev_printk(3, dev, fmt, ##__VA_ARGS__)
+ __dev_printk(LOGL_ERR, dev, fmt, ##__VA_ARGS__)
#define dev_warn(dev, fmt, ...) \
- __dev_printk(4, dev, fmt, ##__VA_ARGS__)
+ __dev_printk(LOGL_WARNING, dev, fmt, ##__VA_ARGS__)
#define dev_notice(dev, fmt, ...) \
- __dev_printk(5, dev, fmt, ##__VA_ARGS__)
+ __dev_printk(LOGL_NOTICE, dev, fmt, ##__VA_ARGS__)
#define dev_info(dev, fmt, ...) \
- __dev_printk(6, dev, fmt, ##__VA_ARGS__)
-
-#ifdef DEBUG
+ __dev_printk(LOGL_INFO, dev, fmt, ##__VA_ARGS__)
#define dev_dbg(dev, fmt, ...) \
- __dev_printk(7, dev, fmt, ##__VA_ARGS__)
-#else
-#define dev_dbg(dev, fmt, ...) \
-({ \
- if (0) \
- __dev_printk(7, dev, fmt, ##__VA_ARGS__); \
-})
-#endif
-
-#ifdef VERBOSE_DEBUG
-#define dev_vdbg dev_dbg
-#else
-#define dev_vdbg(dev, fmt, ...) \
-({ \
- if (0) \
- __dev_printk(7, dev, fmt, ##__VA_ARGS__); \
-})
-#endif
+ __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__)
+#define dev_vdbg(dev, fmt, ...) \
+ __dev_printk(LOGL_DEBUG_CONTENT, dev, fmt, ##__VA_ARGS__)
#endif
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 363b2b94255..d1297803122 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -52,25 +52,6 @@ extern struct p_current *current;
#define dev_warn(dev, fmt, args...) \
printf(fmt, ##args)
-#define netdev_emerg(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_alert(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_crit(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_err(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_warn(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_notice(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_info(dev, fmt, args...) \
- printf(fmt, ##args)
-#define netdev_dbg(dev, fmt, args...) \
- debug(fmt, ##args)
-#define netdev_vdbg(dev, fmt, args...) \
- debug(fmt, ##args)
-
#define GFP_ATOMIC ((gfp_t) 0)
#define GFP_KERNEL ((gfp_t) 0)
#define GFP_NOFS ((gfp_t) 0)
diff --git a/include/mmc.h b/include/mmc.h
index 82562193cc4..75bcaaf6b35 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -888,6 +888,8 @@ void mmc_set_preinit(struct mmc *mmc, int preinit);
#define mmc_host_is_spi(mmc) 0
#endif
+#define mmc_dev(x) ((x)->dev)
+
void board_mmc_power_init(void);
int board_mmc_init(struct bd_info *bis);
int cpu_mmc_init(struct bd_info *bis);
diff --git a/include/remoteproc.h b/include/remoteproc.h
index a903acb9b24..74d01723f6a 100644
--- a/include/remoteproc.h
+++ b/include/remoteproc.h
@@ -227,19 +227,6 @@ int rproc_elf32_sanity_check(ulong addr, ulong size);
int rproc_elf64_sanity_check(ulong addr, ulong size);
/**
- * rproc_elf_sanity_check() - Verify if an image is a valid ELF one
- *
- * Check if a valid ELF image exists at the given memory location. Auto
- * detects ELF32/ELF64 and verifies basic ELF64/ELF32 format requirements
- * like magic number and sections size.
- *
- * @addr: address of the image to verify
- * @size: size of the image
- * @return 0 if the image looks good, else appropriate error value.
- */
-int rproc_elf_sanity_check(ulong addr, ulong size);
-
-/**
* rproc_elf32_load_image() - load an ELF32 image
* @dev: device loading the ELF32 image
* @addr: valid ELF32 image address