aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-02-11 10:58:41 -0500
committerTom Rini <trini@konsulko.com>2020-02-11 10:58:41 -0500
commit9a8942b53d57149754e0dfc975e0d92d1afd4087 (patch)
treede55e5352f3a8a79c413c0b8cb533428e5476841 /include
parentae347120eed8204b1fdf018ddf79131964e57016 (diff)
parent21d651fb29cf268b1a5f64d080e3d352ee32c87f (diff)
downloadu-boot-9a8942b53d57149754e0dfc975e0d92d1afd4087.zip
u-boot-9a8942b53d57149754e0dfc975e0d92d1afd4087.tar.gz
u-boot-9a8942b53d57149754e0dfc975e0d92d1afd4087.tar.bz2
Merge tag 'dm-pull-6feb20' of https://gitlab.denx.de/u-boot/custodians/u-boot-dm
sandbox conversion to SDL2 TPM TEE driver Various minor sandbox video enhancements New driver model core utility functions
Diffstat (limited to 'include')
-rw-r--r--include/asm-generic/gpio.h2
-rw-r--r--include/bloblist.h16
-rw-r--r--include/clk-uclass.h4
-rw-r--r--include/console.h19
-rw-r--r--include/dm/device.h185
-rw-r--r--include/dm/device_compat.h86
-rw-r--r--include/dm/devres.h4
-rw-r--r--include/dm/fdtaddr.h26
-rw-r--r--include/dm/ofnode.h39
-rw-r--r--include/dm/read.h212
-rw-r--r--include/dm/util.h3
-rw-r--r--include/dma-uclass.h4
-rw-r--r--include/fdtdec.h2
-rw-r--r--include/linux/clk-provider.h1
-rw-r--r--include/linux/compat.h3
-rw-r--r--include/linux/mtd/mtd.h4
-rw-r--r--include/linux/string.h7
-rw-r--r--include/mailbox-uclass.h4
-rw-r--r--include/malloc.h24
-rw-r--r--include/os.h22
-rw-r--r--include/pci.h38
-rw-r--r--include/phy.h1
-rw-r--r--include/power-domain-uclass.h4
-rw-r--r--include/reset-uclass.h4
-rw-r--r--include/sound.h12
-rw-r--r--include/test/test.h4
-rw-r--r--include/test/ut.h109
-rw-r--r--include/tpm-common.h3
28 files changed, 556 insertions, 286 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index d6cf187..05777e6 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -248,7 +248,7 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
*/
struct dm_gpio_ops {
int (*request)(struct udevice *dev, unsigned offset, const char *label);
- int (*free)(struct udevice *dev, unsigned offset);
+ int (*rfree)(struct udevice *dev, unsigned int offset);
int (*direction_input)(struct udevice *dev, unsigned offset);
int (*direction_output)(struct udevice *dev, unsigned offset,
int value);
diff --git a/include/bloblist.h b/include/bloblist.h
index 8514401..609ac42 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -152,6 +152,19 @@ int bloblist_ensure_size(uint tag, int size, void **blobp);
void *bloblist_ensure(uint tag, int size);
/**
+ * bloblist_ensure_size_ret() - Find or add a blob
+ *
+ * Find an existing blob, or add a new one if not found
+ *
+ * @tag: Tag to add (enum bloblist_tag_t)
+ * @sizep: Size of the blob to create; returns size of actual blob
+ * @blobp: Returns a pointer to blob on success
+ * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
+ * of space
+ */
+int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp);
+
+/**
* bloblist_new() - Create a new, empty bloblist of a given size
*
* @addr: Address of bloblist
@@ -170,7 +183,8 @@ int bloblist_new(ulong addr, uint size, uint flags);
* @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that
* there problem is no bloblist at the given address), -EPROTONOSUPPORT
* if the version does not match, -EIO if the checksum does not match,
- * -EFBIG if the expected size does not match the detected size
+ * -EFBIG if the expected size does not match the detected size, -ENOSPC
+ * if the size is not large enough to hold the headers
*/
int bloblist_check(ulong addr, uint size);
diff --git a/include/clk-uclass.h b/include/clk-uclass.h
index e76d98e..dac42da 100644
--- a/include/clk-uclass.h
+++ b/include/clk-uclass.h
@@ -53,14 +53,14 @@ struct clk_ops {
*/
int (*request)(struct clk *clock);
/**
- * free - Free a previously requested clock.
+ * rfree - Free a previously requested clock.
*
* This is the implementation of the client clk_free() API.
*
* @clock: The clock to free.
* @return 0 if OK, or a negative error code.
*/
- int (*free)(struct clk *clock);
+ int (*rfree)(struct clk *clock);
/**
* get_rate() - Get current clock rate.
*
diff --git a/include/console.h b/include/console.h
index e935c601..74afe22 100644
--- a/include/console.h
+++ b/include/console.h
@@ -42,6 +42,25 @@ void console_record_reset(void);
void console_record_reset_enable(void);
/**
+ * console_record_readline() - Read a line from the console output
+ *
+ * This reads the next available line from the console output previously
+ * recorded.
+ *
+ * @str: Place to put string
+ * @maxlen: Maximum length of @str including nul terminator
+ * @return length of string returned
+ */
+int console_record_readline(char *str, int maxlen);
+
+/**
+ * console_record_avail() - Get the number of available bytes in console output
+ *
+ * @return available bytes (0 if empty)
+ */
+int console_record_avail(void);
+
+/**
* console_announce_r() - print a U-Boot console on non-serial consoles
*
* When U-Boot starts up with a display it generally does not announce itself
diff --git a/include/dm/device.h b/include/dm/device.h
index 1138a09..ab806d0 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -14,7 +14,6 @@
#include <dm/uclass-id.h>
#include <fdtdec.h>
#include <linker_lists.h>
-#include <linux/compat.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/printk.h>
@@ -409,7 +408,8 @@ const char *dev_get_uclass_name(const struct udevice *dev);
* @return 0 if OK, -ENODEV if no such device, other error if the device fails
* to probe
*/
-int device_get_child(struct udevice *parent, int index, struct udevice **devp);
+int device_get_child(const struct udevice *parent, int index,
+ struct udevice **devp);
/**
* device_get_child_count() - Get the available child count of a device
@@ -418,7 +418,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp);
*
* @parent: Parent device to check
*/
-int device_get_child_count(struct udevice *parent);
+int device_get_child_count(const struct udevice *parent);
/**
* device_find_child_by_seq() - Find a child device based on a sequence
@@ -439,7 +439,7 @@ int device_get_child_count(struct udevice *parent);
* Set to NULL if none is found
* @return 0 if OK, -ve on error
*/
-int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq,
+int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq,
bool find_req_seq, struct udevice **devp);
/**
@@ -457,7 +457,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq,
* Set to NULL if none is found
* @return 0 if OK, -ve on error
*/
-int device_get_child_by_seq(struct udevice *parent, int seq,
+int device_get_child_by_seq(const struct udevice *parent, int seq,
struct udevice **devp);
/**
@@ -470,7 +470,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq,
* @devp: Returns pointer to device if found, otherwise this is set to NULL
* @return 0 if OK, -ve on error
*/
-int device_find_child_by_of_offset(struct udevice *parent, int of_offset,
+int device_find_child_by_of_offset(const struct udevice *parent, int of_offset,
struct udevice **devp);
/**
@@ -485,7 +485,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset,
* @devp: Returns pointer to device if found, otherwise this is set to NULL
* @return 0 if OK, -ve on error
*/
-int device_get_child_by_of_offset(struct udevice *parent, int of_offset,
+int device_get_child_by_of_offset(const struct udevice *parent, int of_offset,
struct udevice **devp);
/**
@@ -524,7 +524,8 @@ int device_get_global_by_ofnode(ofnode node, struct udevice **devp);
* @devp: Returns first child device, or NULL if none
* @return 0
*/
-int device_find_first_child(struct udevice *parent, struct udevice **devp);
+int device_find_first_child(const struct udevice *parent,
+ struct udevice **devp);
/**
* device_find_next_child() - Find the next child of a device
@@ -548,7 +549,7 @@ int device_find_next_child(struct udevice **devp);
* @devp: Returns device found, if any
* @return 0 if found, else -ENODEV
*/
-int device_find_first_inactive_child(struct udevice *parent,
+int device_find_first_inactive_child(const struct udevice *parent,
enum uclass_id uclass_id,
struct udevice **devp);
@@ -560,7 +561,7 @@ int device_find_first_inactive_child(struct udevice *parent,
* @devp: Returns first child device in that uclass, if any
* @return 0 if found, else -ENODEV
*/
-int device_find_first_child_by_uclass(struct udevice *parent,
+int device_find_first_child_by_uclass(const struct udevice *parent,
enum uclass_id uclass_id,
struct udevice **devp);
@@ -572,10 +573,57 @@ int device_find_first_child_by_uclass(struct udevice *parent,
* @devp: Returns device found, if any
* @return 0 if found, else -ENODEV
*/
-int device_find_child_by_name(struct udevice *parent, const char *name,
+int device_find_child_by_name(const struct udevice *parent, const char *name,
struct udevice **devp);
/**
+ * device_first_child_ofdata_err() - Find the first child and reads its platdata
+ *
+ * The ofdata_to_platdata() method is called on the child before it is returned,
+ * but the child is not probed.
+ *
+ * @parent: Parent to check
+ * @devp: Returns child that was found, if any
+ * @return 0 on success, -ENODEV if no children, other -ve on error
+ */
+int device_first_child_ofdata_err(struct udevice *parent,
+ struct udevice **devp);
+
+/*
+ * device_next_child_ofdata_err() - Find the next child and read its platdata
+ *
+ * The ofdata_to_platdata() method is called on the child before it is returned,
+ * but the child is not probed.
+ *
+ * @devp: On entry, points to the previous child; on exit returns the child that
+ * was found, if any
+ * @return 0 on success, -ENODEV if no children, other -ve on error
+ */
+int device_next_child_ofdata_err(struct udevice **devp);
+
+/**
+ * device_first_child_err() - Get the first child of a device
+ *
+ * The device returned is probed if necessary, and ready for use
+ *
+ * @parent: Parent device to search
+ * @devp: Returns device found, if any
+ * @return 0 if found, -ENODEV if not, -ve error if device failed to probe
+ */
+int device_first_child_err(struct udevice *parent, struct udevice **devp);
+
+/**
+ * device_next_child_err() - Get the next child of a parent device
+ *
+ * The device returned is probed if necessary, and ready for use
+ *
+ * @devp: On entry, pointer to device to lookup. On exit, returns pointer
+ * to the next sibling if no error occurred
+ * @return 0 if found, -ENODEV if not, -ve error if device failed to probe
+ */
+int device_next_child_err(struct udevice **devp);
+
+/**
* device_has_children() - check if a device has any children
*
* @dev: Device to check
@@ -590,7 +638,7 @@ bool device_has_children(const struct udevice *dev);
* @return true if the device has one or more children and at least one of
* them is active (probed).
*/
-bool device_has_active_children(struct udevice *dev);
+bool device_has_active_children(const struct udevice *dev);
/**
* device_is_last_sibling() - check if a device is the last sibling
@@ -603,7 +651,7 @@ bool device_has_active_children(struct udevice *dev);
* @return true if there are no more siblings after this one - i.e. is it
* last in the list.
*/
-bool device_is_last_sibling(struct udevice *dev);
+bool device_is_last_sibling(const struct udevice *dev);
/**
* device_set_name() - set the name of a device
@@ -643,7 +691,7 @@ void device_set_name_alloced(struct udevice *dev);
* device
* @return true if OK, false if the compatible is not found
*/
-bool device_is_compatible(struct udevice *dev, const char *compat);
+bool device_is_compatible(const struct udevice *dev, const char *compat);
/**
* of_machine_is_compatible() - check if the machine is compatible with
@@ -678,7 +726,7 @@ int dev_enable_by_path(const char *path);
* @dev: device to test
* @return: true if it is on a PCI bus, false otherwise
*/
-static inline bool device_is_on_pci_bus(struct udevice *dev)
+static inline bool device_is_on_pci_bus(const struct udevice *dev)
{
return device_get_uclass_id(dev->parent) == UCLASS_PCI;
}
@@ -705,6 +753,40 @@ static inline bool device_is_on_pci_bus(struct udevice *dev)
list_for_each_entry(pos, &parent->child_head, sibling_node)
/**
+ * device_foreach_child_ofdata_to_platdata() - iterate through children
+ *
+ * This stops when it gets an error, with @pos set to the device that failed to
+ * read ofdata.
+
+ * This creates a for() loop which works through the available children of
+ * a device in order from start to end. Device ofdata is read by calling
+ * device_ofdata_to_platdata() on each one. The devices are not probed.
+ *
+ * @pos: struct udevice * for the current device
+ * @parent: parent device to scan
+ */
+#define device_foreach_child_ofdata_to_platdata(pos, parent) \
+ for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \
+ _ret = device_next_child_ofdata_err(&dev))
+
+/**
+ * device_foreach_child_probe() - iterate through children, probing them
+ *
+ * This creates a for() loop which works through the available children of
+ * a device in order from start to end. Devices are probed if necessary,
+ * and ready for use.
+ *
+ * This stops when it gets an error, with @pos set to the device that failed to
+ * probe
+ *
+ * @pos: struct udevice * for the current device
+ * @parent: parent device to scan
+ */
+#define device_foreach_child_probe(pos, parent) \
+ for (int _ret = device_first_child_err(parent, &dev); !_ret; \
+ _ret = device_next_child_err(&dev))
+
+/**
* dm_scan_fdt_dev() - Bind child device in a the device tree
*
* This handles device which have sub-nodes in the device tree. It scans all
@@ -720,77 +802,4 @@ static inline bool device_is_on_pci_bus(struct udevice *dev)
*/
int dm_scan_fdt_dev(struct udevice *dev);
-#include <dm/devres.h>
-
-/*
- * REVISIT:
- * remove the following after resolving conflicts with <linux/compat.h>
- */
-#ifdef dev_dbg
-#undef dev_dbg
-#endif
-#ifdef dev_vdbg
-#undef dev_vdbg
-#endif
-#ifdef dev_info
-#undef dev_info
-#endif
-#ifdef dev_err
-#undef dev_err
-#endif
-#ifdef dev_warn
-#undef dev_warn
-#endif
-
-/*
- * REVISIT:
- * print device name like Linux
- */
-#define dev_printk(dev, fmt, ...) \
-({ \
- printk(fmt, ##__VA_ARGS__); \
-})
-
-#define __dev_printk(level, dev, fmt, ...) \
-({ \
- if (level < CONFIG_VAL(LOGLEVEL)) \
- dev_printk(dev, fmt, ##__VA_ARGS__); \
-})
-
-#define dev_emerg(dev, fmt, ...) \
- __dev_printk(0, dev, fmt, ##__VA_ARGS__)
-#define dev_alert(dev, fmt, ...) \
- __dev_printk(1, dev, fmt, ##__VA_ARGS__)
-#define dev_crit(dev, fmt, ...) \
- __dev_printk(2, dev, fmt, ##__VA_ARGS__)
-#define dev_err(dev, fmt, ...) \
- __dev_printk(3, dev, fmt, ##__VA_ARGS__)
-#define dev_warn(dev, fmt, ...) \
- __dev_printk(4, dev, fmt, ##__VA_ARGS__)
-#define dev_notice(dev, fmt, ...) \
- __dev_printk(5, dev, fmt, ##__VA_ARGS__)
-#define dev_info(dev, fmt, ...) \
- __dev_printk(6, dev, fmt, ##__VA_ARGS__)
-
-#ifdef DEBUG
-#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
-
#endif
diff --git a/include/dm/device_compat.h b/include/dm/device_compat.h
new file mode 100644
index 0000000..3d8cd09
--- /dev/null
+++ b/include/dm/device_compat.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis@gmail.com>
+ * Marek Vasut <marex@denx.de>
+ */
+
+#ifndef _DM_DEVICE_COMPAT_H
+#define _DM_DEVICE_COMPAT_H
+
+#include <linux/compat.h>
+
+/*
+ * REVISIT:
+ * remove the following after resolving conflicts with <linux/compat.h>
+ */
+#ifdef dev_dbg
+#undef dev_dbg
+#endif
+#ifdef dev_vdbg
+#undef dev_vdbg
+#endif
+#ifdef dev_info
+#undef dev_info
+#endif
+#ifdef dev_err
+#undef dev_err
+#endif
+#ifdef dev_warn
+#undef dev_warn
+#endif
+
+/*
+ * REVISIT:
+ * print device name like Linux
+ */
+#define dev_printk(dev, fmt, ...) \
+({ \
+ printk(fmt, ##__VA_ARGS__); \
+})
+
+#define __dev_printk(level, dev, fmt, ...) \
+({ \
+ if (level < CONFIG_VAL(LOGLEVEL)) \
+ dev_printk(dev, fmt, ##__VA_ARGS__); \
+})
+
+#define dev_emerg(dev, fmt, ...) \
+ __dev_printk(0, dev, fmt, ##__VA_ARGS__)
+#define dev_alert(dev, fmt, ...) \
+ __dev_printk(1, dev, fmt, ##__VA_ARGS__)
+#define dev_crit(dev, fmt, ...) \
+ __dev_printk(2, dev, fmt, ##__VA_ARGS__)
+#define dev_err(dev, fmt, ...) \
+ __dev_printk(3, dev, fmt, ##__VA_ARGS__)
+#define dev_warn(dev, fmt, ...) \
+ __dev_printk(4, dev, fmt, ##__VA_ARGS__)
+#define dev_notice(dev, fmt, ...) \
+ __dev_printk(5, dev, fmt, ##__VA_ARGS__)
+#define dev_info(dev, fmt, ...) \
+ __dev_printk(6, dev, fmt, ##__VA_ARGS__)
+
+#ifdef DEBUG
+#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
+
+#endif
diff --git a/include/dm/devres.h b/include/dm/devres.h
index 9c69196..17bb1ee 100644
--- a/include/dm/devres.h
+++ b/include/dm/devres.h
@@ -11,6 +11,10 @@
#ifndef _DM_DEVRES_H
#define _DM_DEVRES_H
+#include <linux/compat.h>
+
+struct udevice;
+
/* device resource management */
typedef void (*dr_release_t)(struct udevice *dev, void *res);
typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);
diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h
index 959d3bc..a4fda58 100644
--- a/include/dm/fdtaddr.h
+++ b/include/dm/fdtaddr.h
@@ -21,7 +21,7 @@ struct udevice;
*
* @return addr
*/
-fdt_addr_t devfdt_get_addr(struct udevice *dev);
+fdt_addr_t devfdt_get_addr(const struct udevice *dev);
/**
* devfdt_get_addr_ptr() - Return pointer to the address of the reg property
@@ -31,7 +31,7 @@ fdt_addr_t devfdt_get_addr(struct udevice *dev);
*
* @return Pointer to addr, or NULL if there is no such property
*/
-void *devfdt_get_addr_ptr(struct udevice *dev);
+void *devfdt_get_addr_ptr(const struct udevice *dev);
/**
* devfdt_remap_addr() - Return pointer to the memory-mapped I/O address
@@ -41,7 +41,7 @@ void *devfdt_get_addr_ptr(struct udevice *dev);
*
* @return Pointer to addr, or NULL if there is no such property
*/
-void *devfdt_remap_addr(struct udevice *dev);
+void *devfdt_remap_addr(const struct udevice *dev);
/**
* devfdt_remap_addr_index() - Return indexed pointer to the memory-mapped
@@ -53,7 +53,7 @@ void *devfdt_remap_addr(struct udevice *dev);
*
* @return Pointer to addr, or NULL if there is no such property
*/
-void *devfdt_remap_addr_index(struct udevice *dev, int index);
+void *devfdt_remap_addr_index(const struct udevice *dev, int index);
/**
* devfdt_remap_addr_name() - Get the reg property of a device, indexed by
@@ -66,7 +66,7 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index);
*
* @return Pointer to addr, or NULL if there is no such property
*/
-void *devfdt_remap_addr_name(struct udevice *dev, const char *name);
+void *devfdt_remap_addr_name(const struct udevice *dev, const char *name);
/**
* devfdt_map_physmem() - Read device address from reg property of the
@@ -79,7 +79,7 @@ void *devfdt_remap_addr_name(struct udevice *dev, const char *name);
* @return mapped address, or NULL if the device does not have reg
* property.
*/
-void *devfdt_map_physmem(struct udevice *dev, unsigned long size);
+void *devfdt_map_physmem(const struct udevice *dev, unsigned long size);
/**
* devfdt_get_addr_index() - Get the indexed reg property of a device
@@ -90,7 +90,7 @@ void *devfdt_map_physmem(struct udevice *dev, unsigned long size);
*
* @return addr
*/
-fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index);
+fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index);
/**
* devfdt_get_addr_size_index() - Get the indexed reg property of a device
@@ -105,8 +105,8 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index);
*
* @return addr
*/
-fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index,
- fdt_size_t *size);
+fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index,
+ fdt_size_t *size);
/**
* devfdt_get_addr_name() - Get the reg property of a device, indexed by name
@@ -118,7 +118,7 @@ fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index,
*
* @return addr
*/
-fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name);
+fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name);
/**
* devfdt_get_addr_size_name() - Get the reg property and its size for a device,
@@ -135,8 +135,8 @@ fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name);
*
* @return addr
*/
-fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name,
- fdt_size_t *size);
+fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev,
+ const char *name, fdt_size_t *size);
/**
* devfdt_get_addr_pci() - Read an address and handle PCI address translation
@@ -144,6 +144,6 @@ fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name,
* @dev: Device to read from
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t devfdt_get_addr_pci(struct udevice *dev);
+fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev);
#endif
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 4282169..b5a50e8 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -257,9 +257,20 @@ int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
/**
+ * ofnode_read_prop() - Read a property from a node
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read
+ * @sizep: if non-NULL, returns the size of the property, or an error code
+ if not found
+ * @return property value, or NULL if there is no such property
+ */
+const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
+
+/**
* ofnode_read_string() - Read a string from a property
*
- * @ref: valid node reference to read property from
+ * @node: valid node reference to read property from
* @propname: name of the property to read
* @return string from property value, or NULL if there is no such property
*/
@@ -510,21 +521,37 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
ofnode ofnode_path(const char *path);
/**
- * ofnode_get_chosen_prop() - get the value of a chosen property
+ * ofnode_read_chosen_prop() - get the value of a chosen property
*
* This looks for a property within the /chosen node and returns its value
*
* @propname: Property name to look for
+ * @sizep: Returns size of property, or FDT_ERR_... error code if function
+ * returns NULL
* @return property value if found, else NULL
*/
-const char *ofnode_get_chosen_prop(const char *propname);
+const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
/**
- * ofnode_get_chosen_node() - get the chosen node
+ * ofnode_read_chosen_string() - get the string value of a chosen property
+ *
+ * This looks for a property within the /chosen node and returns its value,
+ * checking that it is a valid nul-terminated string
+ *
+ * @propname: Property name to look for
+ * @return string value if found, else NULL
+ */
+const char *ofnode_read_chosen_string(const char *propname);
+
+/**
+ * ofnode_get_chosen_node() - get a referenced node from the chosen node
+ *
+ * This looks up a named property in the chosen node and uses that as a path to
+ * look up a code.
*
- * @return the chosen node if present, else ofnode_null()
+ * @return the referenced node if present, else ofnode_null()
*/
-ofnode ofnode_get_chosen_node(const char *name);
+ofnode ofnode_get_chosen_node(const char *propname);
struct display_timing;
/**
diff --git a/include/dm/read.h b/include/dm/read.h
index d37fcb5..da8c7f2 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -16,12 +16,12 @@
struct resource;
#if CONFIG_IS_ENABLED(OF_LIVE)
-static inline const struct device_node *dev_np(struct udevice *dev)
+static inline const struct device_node *dev_np(const struct udevice *dev)
{
return ofnode_to_np(dev->node);
}
#else
-static inline const struct device_node *dev_np(struct udevice *dev)
+static inline const struct device_node *dev_np(const struct udevice *dev)
{
return NULL;
}
@@ -33,12 +33,12 @@ static inline const struct device_node *dev_np(struct udevice *dev)
* @dev: device to check
* @return reference of the the device's DT node
*/
-static inline ofnode dev_ofnode(struct udevice *dev)
+static inline ofnode dev_ofnode(const struct udevice *dev)
{
return dev->node;
}
-static inline bool dev_of_valid(struct udevice *dev)
+static inline bool dev_of_valid(const struct udevice *dev)
{
return ofnode_valid(dev_ofnode(dev));
}
@@ -53,7 +53,7 @@ static inline bool dev_of_valid(struct udevice *dev)
* @outp: place to put value (if found)
* @return 0 if OK, -ve on error
*/
-int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp);
+int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
/**
* dev_read_u32_default() - read a 32-bit integer from a device's DT property
@@ -63,7 +63,8 @@ int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp);
* @def: default value to return if the property has no value
* @return property value, or @def if not found
*/
-int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
+int dev_read_u32_default(const struct udevice *dev, const char *propname,
+ int def);
/**
* dev_read_s32() - read a signed 32-bit integer from a device's DT property
@@ -73,7 +74,7 @@ int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
* @outp: place to put value (if found)
* @return 0 if OK, -ve on error
*/
-int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp);
+int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
/**
* dev_read_s32_default() - read a signed 32-bit int from a device's DT property
@@ -83,7 +84,8 @@ int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp);
* @def: default value to return if the property has no value
* @return property value, or @def if not found
*/
-int dev_read_s32_default(struct udevice *dev, const char *propname, int def);
+int dev_read_s32_default(const struct udevice *dev, const char *propname,
+ int def);
/**
* dev_read_u32u() - read a 32-bit integer from a device's DT property
@@ -95,7 +97,7 @@ int dev_read_s32_default(struct udevice *dev, const char *propname, int def);
* @outp: place to put value (if found)
* @return 0 if OK, -ve on error
*/
-int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp);
+int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
/**
* dev_read_u64() - read a 64-bit integer from a device's DT property
@@ -105,7 +107,7 @@ int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp);
* @outp: place to put value (if found)
* @return 0 if OK, -ve on error
*/
-int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp);
+int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
/**
* dev_read_u64_default() - read a 64-bit integer from a device's DT property
@@ -115,7 +117,8 @@ int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp);
* @def: default value to return if the property has no value
* @return property value, or @def if not found
*/
-u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def);
+u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
+ u64 def);
/**
* dev_read_string() - Read a string from a device's DT property
@@ -124,7 +127,7 @@ u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def);
* @propname: name of the property to read
* @return string from property value, or NULL if there is no such property
*/
-const char *dev_read_string(struct udevice *dev, const char *propname);
+const char *dev_read_string(const struct udevice *dev, const char *propname);
/**
* dev_read_bool() - read a boolean value from a device's DT property
@@ -133,7 +136,7 @@ const char *dev_read_string(struct udevice *dev, const char *propname);
* @propname: name of property to read
* @return true if property is present (meaning true), false if not present
*/
-bool dev_read_bool(struct udevice *dev, const char *propname);
+bool dev_read_bool(const struct udevice *dev, const char *propname);
/**
* dev_read_subnode() - find a named subnode of a device
@@ -143,7 +146,7 @@ bool dev_read_bool(struct udevice *dev, const char *propname);
* @return reference to subnode (which can be invalid if there is no such
* subnode)
*/
-ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
+ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
/**
* dev_read_size() - read the size of a property
@@ -152,7 +155,7 @@ ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
* @propname: property to check
* @return size of property if present, or -EINVAL if not
*/
-int dev_read_size(struct udevice *dev, const char *propname);
+int dev_read_size(const struct udevice *dev, const char *propname);
/**
* dev_read_addr_index() - Get the indexed reg property of a device
@@ -163,7 +166,7 @@ int dev_read_size(struct udevice *dev, const char *propname);
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
+fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
/**
* dev_read_addr_size_index() - Get the indexed reg property of a device
@@ -175,7 +178,7 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index,
+fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
fdt_size_t *size);
/**
@@ -188,7 +191,7 @@ fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index,
*
* @return pointer or NULL if not found
*/
-void *dev_remap_addr_index(struct udevice *dev, int index);
+void *dev_remap_addr_index(const struct udevice *dev, int index);
/**
* dev_read_addr_name() - Get the reg property of a device, indexed by name
@@ -200,7 +203,7 @@ void *dev_remap_addr_index(struct udevice *dev, int index);
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name);
+fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
/**
* dev_read_addr_size_name() - Get the reg property of a device, indexed by name
@@ -213,7 +216,7 @@ fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name);
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name,
+fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
fdt_size_t *size);
/**
@@ -227,7 +230,7 @@ fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name,
*
* @return pointer or NULL if not found
*/
-void *dev_remap_addr_name(struct udevice *dev, const char* name);
+void *dev_remap_addr_name(const struct udevice *dev, const char *name);
/**
* dev_read_addr() - Get the reg property of a device
@@ -236,7 +239,7 @@ void *dev_remap_addr_name(struct udevice *dev, const char* name);
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t dev_read_addr(struct udevice *dev);
+fdt_addr_t dev_read_addr(const struct udevice *dev);
/**
* dev_read_addr_ptr() - Get the reg property of a device
@@ -246,7 +249,7 @@ fdt_addr_t dev_read_addr(struct udevice *dev);
*
* @return pointer or NULL if not found
*/
-void *dev_read_addr_ptr(struct udevice *dev);
+void *dev_read_addr_ptr(const struct udevice *dev);
/**
* dev_read_addr_pci() - Read an address and handle PCI address translation
@@ -266,7 +269,7 @@ void *dev_read_addr_ptr(struct udevice *dev);
* @dev: Device to read from
* @return address or FDT_ADDR_T_NONE if not found
*/
-fdt_addr_t dev_read_addr_pci(struct udevice *dev);
+fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
/**
* dev_remap_addr() - Get the reg property of a device as a
@@ -276,7 +279,7 @@ fdt_addr_t dev_read_addr_pci(struct udevice *dev);
*
* @return pointer or NULL if not found
*/
-void *dev_remap_addr(struct udevice *dev);
+void *dev_remap_addr(const struct udevice *dev);
/**
* dev_read_addr_size() - get address and size from a device property
@@ -289,8 +292,8 @@ void *dev_remap_addr(struct udevice *dev);
* @sizep: place to put size value (on success)
* @return address value, or FDT_ADDR_T_NONE on error
*/
-fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
- fdt_size_t *sizep);
+fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
+ fdt_size_t *sizep);
/**
* dev_read_name() - get the name of a device's node
@@ -298,7 +301,7 @@ fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
* @dev: Device to read from
* @return name of node
*/
-const char *dev_read_name(struct udevice *dev);
+const char *dev_read_name(const struct udevice *dev);
/**
* dev_read_stringlist_search() - find string in a string list and return index
@@ -318,8 +321,8 @@ const char *dev_read_name(struct udevice *dev);
* -ENODATA if the property is not found
* -EINVAL on some other error
*/
-int dev_read_stringlist_search(struct udevice *dev, const char *property,
- const char *string);
+int dev_read_stringlist_search(const struct udevice *dev, const char *property,
+ const char *string);
/**
* dev_read_string_index() - obtain an indexed string from a string list
@@ -332,8 +335,8 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property,
* @return:
* length of string, if found or -ve error value if not found
*/
-int dev_read_string_index(struct udevice *dev, const char *propname, int index,
- const char **outp);
+int dev_read_string_index(const struct udevice *dev, const char *propname,
+ int index, const char **outp);
/**
* dev_read_string_count() - find the number of strings in a string list
@@ -343,7 +346,7 @@ int dev_read_string_index(struct udevice *dev, const char *propname, int index,
* @return:
* number of strings in the list, or -ve error value if not found
*/
-int dev_read_string_count(struct udevice *dev, const char *propname);
+int dev_read_string_count(const struct udevice *dev, const char *propname);
/**
* dev_read_phandle_with_args() - Find a node pointed by phandle in a list
*
@@ -382,10 +385,9 @@ int dev_read_string_count(struct udevice *dev, const char *propname);
* @cells_name could not be found, the arguments were truncated or there
* were too many arguments.
*/
-int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
- const char *cells_name, int cell_count,
- int index,
- struct ofnode_phandle_args *out_args);
+int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
+ const char *cells_name, int cell_count,
+ int index, struct ofnode_phandle_args *out_args);
/**
* dev_count_phandle_with_args() - Return phandle number in a list
@@ -402,8 +404,8 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
* errno value.
*/
-int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
- const char *cells_name);
+int dev_count_phandle_with_args(const struct udevice *dev,
+ const char *list_name, const char *cells_name);
/**
* dev_read_addr_cells() - Get the number of address cells for a device's node
@@ -414,7 +416,7 @@ int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
* @dev: device to check
* @return number of address cells this node uses
*/
-int dev_read_addr_cells(struct udevice *dev);
+int dev_read_addr_cells(const struct udevice *dev);
/**
* dev_read_size_cells() - Get the number of size cells for a device's node
@@ -425,7 +427,7 @@ int dev_read_addr_cells(struct udevice *dev);
* @dev: device to check
* @return number of size cells this node uses
*/
-int dev_read_size_cells(struct udevice *dev);
+int dev_read_size_cells(const struct udevice *dev);
/**
* dev_read_addr_cells() - Get the address cells property in a node
@@ -435,7 +437,7 @@ int dev_read_size_cells(struct udevice *dev);
* @dev: device to check
* @return number of address cells this node uses
*/
-int dev_read_simple_addr_cells(struct udevice *dev);
+int dev_read_simple_addr_cells(const struct udevice *dev);
/**
* dev_read_size_cells() - Get the size cells property in a node
@@ -445,7 +447,7 @@ int dev_read_simple_addr_cells(struct udevice *dev);
* @dev: device to check
* @return number of size cells this node uses
*/
-int dev_read_simple_size_cells(struct udevice *dev);
+int dev_read_simple_size_cells(const struct udevice *dev);
/**
* dev_read_phandle() - Get the phandle from a device
@@ -453,7 +455,7 @@ int dev_read_simple_size_cells(struct udevice *dev);
* @dev: device to check
* @return phandle (1 or greater), or 0 if no phandle or other error
*/
-int dev_read_phandle(struct udevice *dev);
+int dev_read_phandle(const struct udevice *dev);
/**
* dev_read_prop()- - read a property from a device's node
@@ -463,7 +465,8 @@ int dev_read_phandle(struct udevice *dev);
* @lenp: place to put length on success
* @return pointer to property, or NULL if not found
*/
-const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
+const void *dev_read_prop(const struct udevice *dev, const char *propname,
+ int *lenp);
/**
* dev_read_alias_seq() - Get the alias sequence number of a node
@@ -476,7 +479,7 @@ const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
* @devnump: set to the sequence number if one is found
* @return 0 if a sequence was found, -ve if not
*/
-int dev_read_alias_seq(struct udevice *dev, int *devnump);
+int dev_read_alias_seq(const struct udevice *dev, int *devnump);
/**
* dev_read_u32_array() - Find and read an array of 32 bit integers
@@ -494,7 +497,7 @@ int dev_read_alias_seq(struct udevice *dev, int *devnump);
* property does not have a value, and -EOVERFLOW if the property data isn't
* large enough.
*/
-int dev_read_u32_array(struct udevice *dev, const char *propname,
+int dev_read_u32_array(const struct udevice *dev, const char *propname,
u32 *out_values, size_t sz);
/**
@@ -504,7 +507,7 @@ int dev_read_u32_array(struct udevice *dev, const char *propname,
* @return reference to the first subnode (which can be invalid if the device's
* node has no subnodes)
*/
-ofnode dev_read_first_subnode(struct udevice *dev);
+ofnode dev_read_first_subnode(const struct udevice *dev);
/**
* ofnode_next_subnode() - find the next sibling of a subnode
@@ -529,8 +532,8 @@ ofnode dev_read_next_subnode(ofnode node);
* @return pointer to byte array if found, or NULL if the property is not
* found or there is not enough data
*/
-const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
- size_t sz);
+const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
+ const char *propname, size_t sz);
/**
* dev_read_enabled() - check whether a node is enabled
@@ -543,7 +546,7 @@ const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
* @dev: device to examine
* @return integer value 0 (not enabled) or 1 (enabled)
*/
-int dev_read_enabled(struct udevice *dev);
+int dev_read_enabled(const struct udevice *dev);
/**
* dev_read_resource() - obtain an indexed resource from a device.
@@ -553,7 +556,8 @@ int dev_read_enabled(struct udevice *dev);
* @res returns the resource
* @return 0 if ok, negative on error
*/
-int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
+int dev_read_resource(const struct udevice *dev, uint index,
+ struct resource *res);
/**
* dev_read_resource_byname() - obtain a named resource from a device.
@@ -563,7 +567,7 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
* @res: returns the resource
* @return 0 if ok, negative on error
*/
-int dev_read_resource_byname(struct udevice *dev, const char *name,
+int dev_read_resource_byname(const struct udevice *dev, const char *name,
struct resource *res);
/**
@@ -577,7 +581,7 @@ int dev_read_resource_byname(struct udevice *dev, const char *name,
* @in_addr: pointer to the address to translate
* @return the translated address; OF_BAD_ADDR on error
*/
-u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
+u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
/**
* dev_translate_dma_address() - Translate a device-tree DMA address
@@ -590,7 +594,8 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
* @in_addr: pointer to the DMA address to translate
* @return the translated DMA address; OF_BAD_ADDR on error
*/
-u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr);
+u64 dev_translate_dma_address(const struct udevice *dev,
+ const fdt32_t *in_addr);
/**
* dev_read_alias_highest_id - Get highest alias id for the given stem
@@ -604,31 +609,31 @@ int dev_read_alias_highest_id(const char *stem);
#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
-static inline int dev_read_u32(struct udevice *dev,
+static inline int dev_read_u32(const struct udevice *dev,
const char *propname, u32 *outp)
{
return ofnode_read_u32(dev_ofnode(dev), propname, outp);
}
-static inline int dev_read_u32_default(struct udevice *dev,
+static inline int dev_read_u32_default(const struct udevice *dev,
const char *propname, int def)
{
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
-static inline int dev_read_s32(struct udevice *dev,
+static inline int dev_read_s32(const struct udevice *dev,
const char *propname, s32 *outp)
{
return ofnode_read_s32(dev_ofnode(dev), propname, outp);
}
-static inline int dev_read_s32_default(struct udevice *dev,
+static inline int dev_read_s32_default(const struct udevice *dev,
const char *propname, int def)
{
return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
}
-static inline int dev_read_u32u(struct udevice *dev,
+static inline int dev_read_u32u(const struct udevice *dev,
const char *propname, uint *outp)
{
u32 val;
@@ -642,128 +647,131 @@ static inline int dev_read_u32u(struct udevice *dev,
return 0;
}
-static inline int dev_read_u64(struct udevice *dev,
+static inline int dev_read_u64(const struct udevice *dev,
const char *propname, u64 *outp)
{
return ofnode_read_u64(dev_ofnode(dev), propname, outp);
}
-static inline u64 dev_read_u64_default(struct udevice *dev,
+static inline u64 dev_read_u64_default(const struct udevice *dev,
const char *propname, u64 def)
{
return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
}
-static inline const char *dev_read_string(struct udevice *dev,
+static inline const char *dev_read_string(const struct udevice *dev,
const char *propname)
{
return ofnode_read_string(dev_ofnode(dev), propname);
}
-static inline bool dev_read_bool(struct udevice *dev, const char *propname)
+static inline bool dev_read_bool(const struct udevice *dev,
+ const char *propname)
{
return ofnode_read_bool(dev_ofnode(dev), propname);
}
-static inline ofnode dev_read_subnode(struct udevice *dev,
+static inline ofnode dev_read_subnode(const struct udevice *dev,
const char *subbnode_name)
{
return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
}
-static inline int dev_read_size(struct udevice *dev, const char *propname)
+static inline int dev_read_size(const struct udevice *dev, const char *propname)
{
return ofnode_read_size(dev_ofnode(dev), propname);
}
-static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
+static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
+ int index)
{
return devfdt_get_addr_index(dev, index);
}
-static inline fdt_addr_t dev_read_addr_size_index(struct udevice *dev,
+static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
int index,
fdt_size_t *size)
{
return devfdt_get_addr_size_index(dev, index, size);
}
-static inline fdt_addr_t dev_read_addr_name(struct udevice *dev,
+static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
const char *name)
{
return devfdt_get_addr_name(dev, name);
}
-static inline fdt_addr_t dev_read_addr_size_name(struct udevice *dev,
+static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
const char *name,
fdt_size_t *size)
{
return devfdt_get_addr_size_name(dev, name, size);
}
-static inline fdt_addr_t dev_read_addr(struct udevice *dev)
+static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
{
return devfdt_get_addr(dev);
}
-static inline void *dev_read_addr_ptr(struct udevice *dev)
+static inline void *dev_read_addr_ptr(const struct udevice *dev)
{
return devfdt_get_addr_ptr(dev);
}
-static inline fdt_addr_t dev_read_addr_pci(struct udevice *dev)
+static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
{
return devfdt_get_addr_pci(dev);
}
-static inline void *dev_remap_addr(struct udevice *dev)
+static inline void *dev_remap_addr(const struct udevice *dev)
{
return devfdt_remap_addr(dev);
}
-static inline void *dev_remap_addr_index(struct udevice *dev, int index)
+static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
{
return devfdt_remap_addr_index(dev, index);
}
-static inline void *dev_remap_addr_name(struct udevice *dev, const char *name)
+static inline void *dev_remap_addr_name(const struct udevice *dev,
+ const char *name)
{
return devfdt_remap_addr_name(dev, name);
}
-static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
+static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
const char *propname,
fdt_size_t *sizep)
{
return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
}
-static inline const char *dev_read_name(struct udevice *dev)
+static inline const char *dev_read_name(const struct udevice *dev)
{
return ofnode_get_name(dev_ofnode(dev));
}
-static inline int dev_read_stringlist_search(struct udevice *dev,
+static inline int dev_read_stringlist_search(const struct udevice *dev,
const char *propname,
const char *string)
{
return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
}
-static inline int dev_read_string_index(struct udevice *dev,
+static inline int dev_read_string_index(const struct udevice *dev,
const char *propname, int index,
const char **outp)
{
return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
}
-static inline int dev_read_string_count(struct udevice *dev,
+static inline int dev_read_string_count(const struct udevice *dev,
const char *propname)
{
return ofnode_read_string_count(dev_ofnode(dev), propname);
}
-static inline int dev_read_phandle_with_args(struct udevice *dev,
+static inline int dev_read_phandle_with_args(const struct udevice *dev,
const char *list_name, const char *cells_name, int cell_count,
int index, struct ofnode_phandle_args *out_args)
{
@@ -772,59 +780,60 @@ static inline int dev_read_phandle_with_args(struct udevice *dev,
out_args);
}
-static inline int dev_count_phandle_with_args(struct udevice *dev,
+static inline int dev_count_phandle_with_args(const struct udevice *dev,
const char *list_name, const char *cells_name)
{
return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
cells_name);
}
-static inline int dev_read_addr_cells(struct udevice *dev)
+static inline int dev_read_addr_cells(const struct udevice *dev)
{
/* NOTE: this call should walk up the parent stack */
return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
}
-static inline int dev_read_size_cells(struct udevice *dev)
+static inline int dev_read_size_cells(const struct udevice *dev)
{
/* NOTE: this call should walk up the parent stack */
return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
}
-static inline int dev_read_simple_addr_cells(struct udevice *dev)
+static inline int dev_read_simple_addr_cells(const struct udevice *dev)
{
return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
}
-static inline int dev_read_simple_size_cells(struct udevice *dev)
+static inline int dev_read_simple_size_cells(const struct udevice *dev)
{
return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
}
-static inline int dev_read_phandle(struct udevice *dev)
+static inline int dev_read_phandle(const struct udevice *dev)
{
return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
}
-static inline const void *dev_read_prop(struct udevice *dev,
+static inline const void *dev_read_prop(const struct udevice *dev,
const char *propname, int *lenp)
{
return ofnode_get_property(dev_ofnode(dev), propname, lenp);
}
-static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
+static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
{
return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
dev_of_offset(dev), devnump);
}
-static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
- u32 *out_values, size_t sz)
+static inline int dev_read_u32_array(const struct udevice *dev,
+ const char *propname, u32 *out_values,
+ size_t sz)
{
return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
}
-static inline ofnode dev_read_first_subnode(struct udevice *dev)
+static inline ofnode dev_read_first_subnode(const struct udevice *dev)
{
return ofnode_first_subnode(dev_ofnode(dev));
}
@@ -834,36 +843,39 @@ static inline ofnode dev_read_next_subnode(ofnode node)
return ofnode_next_subnode(node);
}
-static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
- const char *propname, size_t sz)
+static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
+ const char *propname,
+ size_t sz)
{
return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
}
-static inline int dev_read_enabled(struct udevice *dev)
+static inline int dev_read_enabled(const struct udevice *dev)
{
return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
}
-static inline int dev_read_resource(struct udevice *dev, uint index,
+static inline int dev_read_resource(const struct udevice *dev, uint index,
struct resource *res)
{
return ofnode_read_resource(dev_ofnode(dev), index, res);
}
-static inline int dev_read_resource_byname(struct udevice *dev,
+static inline int dev_read_resource_byname(const struct udevice *dev,
const char *name,
struct resource *res)
{
return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
}
-static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
+static inline u64 dev_translate_address(const struct udevice *dev,
+ const fdt32_t *in_addr)
{
return ofnode_translate_address(dev_ofnode(dev), in_addr);
}
-static inline u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr)
+static inline u64 dev_translate_dma_address(const struct udevice *dev,
+ const fdt32_t *in_addr)
{
return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
}
diff --git a/include/dm/util.h b/include/dm/util.h
index 348c2ac..0ccb3fb 100644
--- a/include/dm/util.h
+++ b/include/dm/util.h
@@ -39,6 +39,9 @@ static inline void dm_dump_devres(void)
}
#endif
+/* Dump out a list of drivers */
+void dm_dump_drivers(void);
+
/**
* Check if an of node should be or was bound before relocation.
*
diff --git a/include/dma-uclass.h b/include/dma-uclass.h
index a1d9d26..340437a 100644
--- a/include/dma-uclass.h
+++ b/include/dma-uclass.h
@@ -58,14 +58,14 @@ struct dma_ops {
*/
int (*request)(struct dma *dma);
/**
- * free - Free a previously requested dma.
+ * rfree - Free a previously requested dma.
*
* This is the implementation of the client dma_free() API.
*
* @dma: The DMA to free.
* @return 0 if OK, or a negative error code.
*/
- int (*free)(struct dma *dma);
+ int (*rfree)(struct dma *dma);
/**
* enable() - Enable a DMA Channel.
*
diff --git a/include/fdtdec.h b/include/fdtdec.h
index c8a143d..166f29c 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -441,7 +441,7 @@ int fdtdec_get_pci_vendev(const void *blob, int node,
* @param bar returns base address of the pci device's registers
* @return 0 if ok, negative on error
*/
-int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
+int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr,
u32 *bar);
/**
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 0ef6e68..8a20743 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -13,6 +13,7 @@
#include <linux/bitops.h>
#include <linux/err.h>
#include <clk-uclass.h>
+#include <linux/err.h>
static inline void clk_dm(ulong id, struct clk *clk)
{
diff --git a/include/linux/compat.h b/include/linux/compat.h
index d0f51ba..171188a 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -123,7 +123,10 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep)
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+/* This is also defined in ARMv8's mmu.h */
+#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
+#endif
/* drivers/char/random.c */
#define get_random_bytes(...)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index ceffd99..1b91517 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -129,8 +129,8 @@ struct mtd_oob_region {
struct mtd_ooblayout_ops {
int (*ecc)(struct mtd_info *mtd, int section,
struct mtd_oob_region *oobecc);
- int (*free)(struct mtd_info *mtd, int section,
- struct mtd_oob_region *oobfree);
+ int (*rfree)(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *oobfree);
};
/*
diff --git a/include/linux/string.h b/include/linux/string.h
index 5d63be4..d67998e 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -91,10 +91,15 @@ extern __kernel_size_t strnlen(const char *,__kernel_size_t);
size_t strcspn(const char *s, const char *reject);
#endif
+#ifdef CONFIG_SANDBOX
+# define strdup sandbox_strdup
+# define strndup sandbox_strndup
+#endif
+
#ifndef __HAVE_ARCH_STRDUP
extern char * strdup(const char *);
-#endif
extern char * strndup(const char *, size_t);
+#endif
#ifndef __HAVE_ARCH_STRSWAB
extern char * strswab(const char *);
#endif
diff --git a/include/mailbox-uclass.h b/include/mailbox-uclass.h
index e0618aa..3c60c76 100644
--- a/include/mailbox-uclass.h
+++ b/include/mailbox-uclass.h
@@ -49,14 +49,14 @@ struct mbox_ops {
*/
int (*request)(struct mbox_chan *chan);
/**
- * free - Free a previously requested channel.
+ * rfree - Free a previously requested channel.
*
* This is the implementation of the client mbox_free() API.
*
* @chan: The channel to free.
* @return 0 if OK, or a negative error code.
*/
- int (*free)(struct mbox_chan *chan);
+ int (*rfree)(struct mbox_chan *chan);
/**
* send - Send a message over a mailbox channel
*
diff --git a/include/malloc.h b/include/malloc.h
index 5efa692..f66c2e8 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -788,8 +788,13 @@ struct mallinfo {
*/
-/* #define USE_DL_PREFIX */
-
+/*
+ * Rename the U-Boot alloc functions so that sandbox can still use the system
+ * ones
+ */
+#ifdef CONFIG_SANDBOX
+#define USE_DL_PREFIX
+#endif
/*
@@ -892,6 +897,21 @@ void malloc_simple_info(void);
# define pvALLOc dlpvalloc
# define mALLINFo dlmallinfo
# define mALLOPt dlmallopt
+
+/* Ensure that U-Boot actually uses these too */
+#define calloc dlcalloc
+#define free(ptr) dlfree(ptr)
+#define malloc(x) dlmalloc(x)
+#define memalign dlmemalign
+#define realloc dlrealloc
+#define valloc dlvalloc
+#define pvalloc dlpvalloc
+#define mallinfo() dlmallinfo()
+#define mallopt dlmallopt
+#define malloc_trim dlmalloc_trim
+#define malloc_usable_size dlmalloc_usable_size
+#define malloc_stats dlmalloc_stats
+
# else /* USE_DL_PREFIX */
# define cALLOc calloc
# define fREe free
diff --git a/include/os.h b/include/os.h
index 7a4f78b..1874ae6 100644
--- a/include/os.h
+++ b/include/os.h
@@ -119,7 +119,7 @@ void os_fd_restore(void);
void *os_malloc(size_t length);
/**
- * Free memory previous allocated with os_malloc()/os_realloc()
+ * Free memory previous allocated with os_malloc()
*
* This returns the memory to the OS.
*
@@ -128,26 +128,6 @@ void *os_malloc(size_t length);
void os_free(void *ptr);
/**
- * Reallocate previously-allocated memory to increase/decrease space
- *
- * This works in a similar way to the C library realloc() function. If
- * length is 0, then ptr is freed. Otherwise the space used by ptr is
- * expanded or reduced depending on whether length is larger or smaller
- * than before.
- *
- * If ptr is NULL, then this is similar to calling os_malloc().
- *
- * This function may need to move the memory block to make room for any
- * extra space, in which case the new pointer is returned.
- *
- * \param ptr Pointer to memory block to reallocate
- * \param length New length for memory block
- * \return pointer to new memory block, or NULL on failure or if length
- * is 0.
- */
-void *os_realloc(void *ptr, size_t length);
-
-/**
* Access to the usleep function of the os
*
* \param usec Time to sleep in micro seconds
diff --git a/include/pci.h b/include/pci.h
index 8c761d8..50ca249 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -899,8 +899,8 @@ struct dm_pci_ops {
* @size: Access size
* @return 0 if OK, -ve on error
*/
- int (*read_config)(struct udevice *bus, pci_dev_t bdf, uint offset,
- ulong *valuep, enum pci_size_t size);
+ int (*read_config)(const struct udevice *bus, pci_dev_t bdf,
+ uint offset, ulong *valuep, enum pci_size_t size);
/**
* write_config() - Write a PCI configuration value
*
@@ -924,7 +924,7 @@ struct dm_pci_ops {
* @dev: Device to check
* @return bus/device/function value (see PCI_BDF())
*/
-pci_dev_t dm_pci_get_bdf(struct udevice *dev);
+pci_dev_t dm_pci_get_bdf(const struct udevice *dev);
/**
* pci_bind_bus_devices() - scan a PCI bus and bind devices
@@ -974,7 +974,7 @@ int dm_pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp);
* @devp: Returns the device for this address, if found
* @return 0 if OK, -ENODEV if not found
*/
-int pci_bus_find_devfn(struct udevice *bus, pci_dev_t find_devfn,
+int pci_bus_find_devfn(const struct udevice *bus, pci_dev_t find_devfn,
struct udevice **devp);
/**
@@ -1067,7 +1067,7 @@ int dm_pci_hose_probe_bus(struct udevice *bus);
* @size: Access size
* @return 0 if OK, -ve on error
*/
-int pci_bus_read_config(struct udevice *bus, pci_dev_t bdf, int offset,
+int pci_bus_read_config(const struct udevice *bus, pci_dev_t bdf, int offset,
unsigned long *valuep, enum pci_size_t size);
/**
@@ -1102,12 +1102,12 @@ int pci_bus_clrset_config32(struct udevice *bus, pci_dev_t bdf, int offset,
* Driver model PCI config access functions. Use these in preference to others
* when you have a valid device
*/
-int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep,
- enum pci_size_t size);
+int dm_pci_read_config(const struct udevice *dev, int offset,
+ unsigned long *valuep, enum pci_size_t size);
-int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep);
-int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep);
-int dm_pci_read_config32(struct udevice *dev, int offset, u32 *valuep);
+int dm_pci_read_config8(const struct udevice *dev, int offset, u8 *valuep);
+int dm_pci_read_config16(const struct udevice *dev, int offset, u16 *valuep);
+int dm_pci_read_config32(const struct udevice *dev, int offset, u32 *valuep);
int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value,
enum pci_size_t size);
@@ -1155,8 +1155,9 @@ int pci_read_config8(pci_dev_t pcidev, int offset, u8 *valuep);
* Return: 0 on success, else -EINVAL
*/
int pci_generic_mmap_write_config(
- struct udevice *bus,
- int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp),
+ const struct udevice *bus,
+ int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset,
+ void **addrp),
pci_dev_t bdf,
uint offset,
ulong value,
@@ -1180,8 +1181,9 @@ int pci_generic_mmap_write_config(
* Return: 0 on success, else -EINVAL
*/
int pci_generic_mmap_read_config(
- struct udevice *bus,
- int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp),
+ const struct udevice *bus,
+ int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset,
+ void **addrp),
pci_dev_t bdf,
uint offset,
ulong *valuep,
@@ -1311,7 +1313,7 @@ void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr);
* @barnum: Bar number to read (numbered from 0)
* @return: value of BAR
*/
-u32 dm_pci_read_bar32(struct udevice *dev, int barnum);
+u32 dm_pci_read_bar32(const struct udevice *dev, int barnum);
/**
* dm_pci_bus_to_phys() - convert a PCI bus address to a physical address
@@ -1523,8 +1525,8 @@ struct dm_pci_emul_ops {
* @size: Access size
* @return 0 if OK, -ve on error
*/
- int (*read_config)(struct udevice *dev, uint offset, ulong *valuep,
- enum pci_size_t size);
+ int (*read_config)(const struct udevice *dev, uint offset,
+ ulong *valuep, enum pci_size_t size);
/**
* write_config() - Write a PCI configuration value
*
@@ -1609,7 +1611,7 @@ struct dm_pci_emul_ops {
* @emulp: Returns emulated device if found
* @return 0 if found, -ENODEV if not found
*/
-int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
+int sandbox_pci_get_emul(const struct udevice *bus, pci_dev_t find_devfn,
struct udevice **containerp, struct udevice **emulp);
/**
diff --git a/include/phy.h b/include/phy.h
index 6ace9b3..42cfc59 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -10,6 +10,7 @@
#define _PHY_H
#include <dm.h>
+#include <linux/errno.h>
#include <linux/list.h>
#include <linux/mii.h>
#include <linux/ethtool.h>
diff --git a/include/power-domain-uclass.h b/include/power-domain-uclass.h
index bd9906b..acf749b 100644
--- a/include/power-domain-uclass.h
+++ b/include/power-domain-uclass.h
@@ -54,14 +54,14 @@ struct power_domain_ops {
*/
int (*request)(struct power_domain *power_domain);
/**
- * free - Free a previously requested power domain.
+ * rfree - Free a previously requested power domain.
*
* This is the implementation of the client power_domain_free() API.
*
* @power_domain: The power domain to free.
* @return 0 if OK, or a negative error code.
*/
- int (*free)(struct power_domain *power_domain);
+ int (*rfree)(struct power_domain *power_domain);
/**
* on - Power on a power domain.
*
diff --git a/include/reset-uclass.h b/include/reset-uclass.h
index 7b5cc3c..9a0696d 100644
--- a/include/reset-uclass.h
+++ b/include/reset-uclass.h
@@ -51,14 +51,14 @@ struct reset_ops {
*/
int (*request)(struct reset_ctl *reset_ctl);
/**
- * free - Free a previously requested reset control.
+ * rfree - Free a previously requested reset control.
*
* This is the implementation of the client reset_free() API.
*
* @reset_ctl: The reset control to free.
* @return 0 if OK, or a negative error code.
*/
- int (*free)(struct reset_ctl *reset_ctl);
+ int (*rfree)(struct reset_ctl *reset_ctl);
/**
* rst_assert - Assert a reset signal.
*
diff --git a/include/sound.h b/include/sound.h
index 47de9fa..71bd850 100644
--- a/include/sound.h
+++ b/include/sound.h
@@ -69,6 +69,18 @@ struct sound_ops {
int (*play)(struct udevice *dev, void *data, uint data_size);
/**
+ * stop_play() - Indicate that there is no more data coming
+ *
+ * This is called once play() has finished sending all the data to the
+ * output device. This may be used to tell the hardware to turn off the
+ * codec, for example.
+ *
+ * @dev: Sound device
+ * @return 0 if OK, -ve on error
+ */
+ int (*stop_play)(struct udevice *dev);
+
+ /**
* start_beep() - Start beeping (optional)
*
* This tells the sound hardware to start a beep. It will continue until
diff --git a/include/test/test.h b/include/test/test.h
index e5bef47..2a75211 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -15,12 +15,16 @@
* @start: Store the starting mallinfo when doing leak test
* @priv: A pointer to some other info some suites want to track
* @of_root: Record of the livetree root node (used for setting up tests)
+ * @expect_str: Temporary string used to hold expected string value
+ * @actual_str: Temporary string used to hold actual string value
*/
struct unit_test_state {
int fail_count;
struct mallinfo start;
void *priv;
struct device_node *of_root;
+ char expect_str[256];
+ char actual_str[256];
};
/**
diff --git a/include/test/ut.h b/include/test/ut.h
index f616c20..04df8ba 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -38,6 +38,43 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
const char *func, const char *cond, const char *fmt, ...)
__attribute__ ((format (__printf__, 6, 7)));
+/**
+ * ut_check_console_line() - Check the next console line against expectations
+ *
+ * This creates a string and then checks it against the next line of console
+ * output obtained with console_record_readline().
+ *
+ * After the function returns, uts->expect_str holds the expected string and
+ * uts->actual_str holds the actual string read from the console.
+ *
+ * @uts: Test state
+ * @fmt: printf() format string for the error, followed by args
+ * @return 0 if OK, other value on error
+ */
+int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
+ __attribute__ ((format (__printf__, 2, 3)));
+
+/**
+ * ut_check_console_end() - Check there is no more console output
+ *
+ * After the function returns, uts->actual_str holds the actual string read
+ * from the console
+ *
+ * @uts: Test state
+ * @return 0 if OK (console has no output), other value on error
+ */
+int ut_check_console_end(struct unit_test_state *uts);
+
+/**
+ * ut_check_console_dump() - Check that next lines have a print_buffer() dump
+ *
+ * This only supports a byte dump.
+ *
+ * @total_bytes: Size of the expected dump in bytes`
+ * @return 0 if OK (looks like a dump and the length matches), other value on
+ * error
+ */
+int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
/* Assert that a condition is non-zero */
#define ut_assert(cond) \
@@ -56,39 +93,39 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
/* Assert that two int expressions are equal */
#define ut_asserteq(expr1, expr2) { \
- unsigned int val1 = (expr1), val2 = (expr2); \
+ unsigned int _val1 = (expr1), _val2 = (expr2); \
\
- if (val1 != val2) { \
+ if (_val1 != _val2) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr1 " == " #expr2, \
- "Expected %#x (%d), got %#x (%d)", val1, val1, \
- val2, val2); \
+ "Expected %#x (%d), got %#x (%d)", \
+ _val1, _val1, _val2, _val2); \
return CMD_RET_FAILURE; \
} \
}
/* Assert that two string expressions are equal */
#define ut_asserteq_str(expr1, expr2) { \
- const char *val1 = (expr1), *val2 = (expr2); \
+ const char *_val1 = (expr1), *_val2 = (expr2); \
\
- if (strcmp(val1, val2)) { \
+ if (strcmp(_val1, _val2)) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr1 " = " #expr2, \
- "Expected \"%s\", got \"%s\"", val1, val2); \
+ "Expected \"%s\", got \"%s\"", _val1, _val2); \
return CMD_RET_FAILURE; \
} \
}
/* Assert that two memory areas are equal */
#define ut_asserteq_mem(expr1, expr2, len) { \
- const u8 *val1 = (u8 *)(expr1), *val2 = (u8 *)(expr2); \
+ const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \
const uint __len = len; \
\
- if (memcmp(val1, val2, __len)) { \
+ if (memcmp(_val1, _val2, __len)) { \
char __buf1[64 + 1] = "\0"; \
char __buf2[64 + 1] = "\0"; \
- bin2hex(__buf1, val1, min(__len, (uint)32)); \
- bin2hex(__buf2, val2, min(__len, (uint)32)); \
+ bin2hex(__buf1, _val1, min(__len, (uint)32)); \
+ bin2hex(__buf2, _val2, min(__len, (uint)32)); \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr1 " = " #expr2, \
"Expected \"%s\", got \"%s\"", \
@@ -99,33 +136,33 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
/* Assert that two pointers are equal */
#define ut_asserteq_ptr(expr1, expr2) { \
- const void *val1 = (expr1), *val2 = (expr2); \
+ const void *_val1 = (expr1), *_val2 = (expr2); \
\
- if (val1 != val2) { \
+ if (_val1 != _val2) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr1 " = " #expr2, \
- "Expected %p, got %p", val1, val2); \
+ "Expected %p, got %p", _val1, _val2); \
return CMD_RET_FAILURE; \
} \
}
/* Assert that a pointer is NULL */
#define ut_assertnull(expr) { \
- const void *val = (expr); \
+ const void *_val = (expr); \
\
- if (val != NULL) { \
+ if (_val) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr " != NULL", \
- "Expected NULL, got %p", val); \
+ "Expected NULL, got %p", _val); \
return CMD_RET_FAILURE; \
} \
}
/* Assert that a pointer is not NULL */
#define ut_assertnonnull(expr) { \
- const void *val = (expr); \
+ const void *_val = (expr); \
\
- if (val == NULL) { \
+ if (!_val) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr " = NULL", \
"Expected non-null, got NULL"); \
@@ -135,13 +172,13 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
/* Assert that a pointer is not an error pointer */
#define ut_assertok_ptr(expr) { \
- const void *val = (expr); \
+ const void *_val = (expr); \
\
- if (IS_ERR(val)) { \
+ if (IS_ERR(_val)) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr " = NULL", \
"Expected pointer, got error %ld", \
- PTR_ERR(val)); \
+ PTR_ERR(_val)); \
return CMD_RET_FAILURE; \
} \
}
@@ -149,6 +186,34 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
/* Assert that an operation succeeds (returns 0) */
#define ut_assertok(cond) ut_asserteq(0, cond)
+/* Assert that the next console output line matches */
+#define ut_assert_nextline(fmt, args...) \
+ if (ut_check_console_line(uts, fmt, ##args)) { \
+ ut_failf(uts, __FILE__, __LINE__, __func__, \
+ "console", "\nExpected '%s',\n got '%s'", \
+ uts->expect_str, uts->actual_str); \
+ return CMD_RET_FAILURE; \
+ } \
+
+/* Assert that there is no more console output */
+#define ut_assert_console_end() \
+ if (ut_check_console_end(uts)) { \
+ ut_failf(uts, __FILE__, __LINE__, __func__, \
+ "console", "Expected no more output, got '%s'",\
+ uts->actual_str); \
+ return CMD_RET_FAILURE; \
+ } \
+
+/* Assert that the next lines are print_buffer() dump at an address */
+#define ut_assert_nextlines_are_dump(total_bytes) \
+ if (ut_check_console_dump(uts, total_bytes)) { \
+ ut_failf(uts, __FILE__, __LINE__, __func__, \
+ "console", \
+ "Expected dump of length %x bytes, got '%s'", \
+ total_bytes, uts->actual_str); \
+ return CMD_RET_FAILURE; \
+ } \
+
/**
* ut_check_free() - Return the number of bytes free in the malloc() pool
*
diff --git a/include/tpm-common.h b/include/tpm-common.h
index f9c2ca2..702cd6e 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -293,4 +293,7 @@ static inline cmd_tbl_t *get_tpm2_commands(unsigned int *size)
*/
enum tpm_version tpm_get_version(struct udevice *dev);
+/* Iterate on all TPM devices */
+#define for_each_tpm_device(dev) uclass_foreach_dev_probe(UCLASS_TPM, (dev))
+
#endif /* __TPM_COMMON_H */