diff options
author | Simon Glass | 2022-10-20 18:22:54 -0600 |
---|---|---|
committer | Tom Rini | 2022-10-31 11:02:44 -0400 |
commit | 606b926f9d76eaab11be2d95cfd7734644e1627c (patch) | |
tree | 513867ec3914aeeee981ac980eec71edb51c47d8 /include/blk.h | |
parent | b55afa0c0e6dcb185ee527a6c37941bfde04ffd1 (diff) |
dm: blk: Add udevice functions
At present we have functions called blk_dread(), etc., which take a
struct blk_desc * to refer to the block device. Add some functions which
use udevice instead, since this is more in keeping with how driver model
is supposed to work.
Update one of the tests to use this.
Note that it would be nice to update the functions in disk-uclass.c to use
these new functions. However they are not quite the same. For example,
disk_blk_read() adds the partition offset to 'start' when calling the
cache read/fill functions, but does not with part_blk_read(), which does
the addition itself. So as designed the code is duplicated.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/blk.h')
-rw-r--r-- | include/blk.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/include/blk.h b/include/blk.h index d3ab9a10b96..e854166edb9 100644 --- a/include/blk.h +++ b/include/blk.h @@ -274,6 +274,43 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); /** + * blk_read() - Read from a block device + * + * @dev: Device to read from + * @start: Start block for the read + * @blkcnt: Number of blocks to read + * @buf: Place to put the data + * @return number of blocks read (which may be less than @blkcnt), + * or -ve on error. This never returns 0 unless @blkcnt is 0 + */ +long blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, + void *buffer); + +/** + * blk_write() - Write to a block device + * + * @dev: Device to write to + * @start: Start block for the write + * @blkcnt: Number of blocks to write + * @buf: Data to write + * @return number of blocks written (which may be less than @blkcnt), + * or -ve on error. This never returns 0 unless @blkcnt is 0 + */ +long blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, + const void *buffer); + +/** + * blk_erase() - Erase part of a block device + * + * @dev: Device to erase + * @start: Start block for the erase + * @blkcnt: Number of blocks to erase + * @return number of blocks erased (which may be less than @blkcnt), + * or -ve on error. This never returns 0 unless @blkcnt is 0 + */ +long blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt); + +/** * blk_find_device() - Find a block device * * This function does not activate the device. The device will be returned @@ -428,7 +465,7 @@ const char *blk_get_devtype(struct udevice *dev); /** * blk_get_by_device() - Get the block device descriptor for the given device - * @dev: Instance of a storage device + * @dev: Instance of a storage device (the parent of the block device) * * Return: With block device descriptor on success , NULL if there is no such * block device. |