diff options
author | Simon Glass | 2022-02-28 12:08:35 -0700 |
---|---|---|
committer | Tom Rini | 2022-04-06 14:03:17 -0400 |
commit | 49e8668181df501f263751b2e9bbb5ff737819d1 (patch) | |
tree | 50ba086e7342efbdb50046c69326f25fb9687d09 /include/blk.h | |
parent | e86b6f71002e5892c28acd206e68d13adc76c4b7 (diff) |
dm: blk: Expand iteration and add tests
Add some functions which support iteration before probing. Also add tests
for the functions.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/blk.h')
-rw-r--r-- | include/blk.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/include/blk.h b/include/blk.h index d06098bc13e..dbe9ae219da 100644 --- a/include/blk.h +++ b/include/blk.h @@ -732,6 +732,51 @@ int blk_first_device_err(enum blk_flag_t flags, struct udevice **devp); int blk_next_device_err(enum blk_flag_t flags, struct udevice **devp); /** + * blk_find_first() - Return the first matching block device + * @flags: Indicates type of device to return + * @devp: Returns pointer to device, or NULL on error + * + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. + * + * Note that some devices are considered removable until they have been probed + * + * @return 0 if found, -ENODEV if not found + */ +int blk_find_first(enum blk_flag_t flags, struct udevice **devp); + +/** + * blk_find_next() - Return the next matching block device + * @flags: Indicates type of device to return + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next device in the same uclass, or NULL if none + * + * The device is not prepared for use - this is an internal function. + * The function uclass_get_device_tail() can be used to probe the device. + * + * Note that some devices are considered removable until they have been probed + * + * @return 0 if found, -ENODEV if not found + */ +int blk_find_next(enum blk_flag_t flags, struct udevice **devp); + +/** + * blk_foreach() - iterate through block devices + * + * This creates a for() loop which works through the available block devices in + * order from start to end. + * + * If for some reason the uclass cannot be found, this does nothing. + * + * @_flags: Indicates type of device to return + * @_pos: struct udevice * to hold the current device. Set to NULL when there + * are no more devices. + */ +#define blk_foreach(_flags, _pos) \ + for (int _ret = blk_find_first(_flags, &_pos); !_ret && _pos; \ + _ret = blk_find_next(_flags, &_pos)) + +/** * blk_foreach_probe() - Helper function to iteration through block devices * * This creates a for() loop which works through the available devices in |