diff options
author | Simon Glass <sjg@chromium.org> | 2022-10-20 18:22:54 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-10-31 11:02:44 -0400 |
commit | 606b926f9d76eaab11be2d95cfd7734644e1627c (patch) | |
tree | 513867ec3914aeeee981ac980eec71edb51c47d8 /drivers/block | |
parent | b55afa0c0e6dcb185ee527a6c37941bfde04ffd1 (diff) | |
download | u-boot-606b926f9d76eaab11be2d95cfd7734644e1627c.zip u-boot-606b926f9d76eaab11be2d95cfd7734644e1627c.tar.gz u-boot-606b926f9d76eaab11be2d95cfd7734644e1627c.tar.bz2 |
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 'drivers/block')
-rw-r--r-- | drivers/block/blk-uclass.c | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index bcc14a6..e82789f 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -444,53 +444,70 @@ int blk_get_device(int uclass_id, int devnum, struct udevice **devp) return device_probe(*devp); } -unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start, - lbaint_t blkcnt, void *buffer) +long blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *buf) { - struct udevice *dev = block_dev->bdev; + struct blk_desc *desc = dev_get_uclass_plat(dev); const struct blk_ops *ops = blk_get_ops(dev); ulong blks_read; if (!ops->read) return -ENOSYS; - if (blkcache_read(block_dev->uclass_id, block_dev->devnum, - start, blkcnt, block_dev->blksz, buffer)) + if (blkcache_read(desc->uclass_id, desc->devnum, + start, blkcnt, desc->blksz, buf)) return blkcnt; - blks_read = ops->read(dev, start, blkcnt, buffer); + blks_read = ops->read(dev, start, blkcnt, buf); if (blks_read == blkcnt) - blkcache_fill(block_dev->uclass_id, block_dev->devnum, - start, blkcnt, block_dev->blksz, buffer); + blkcache_fill(desc->uclass_id, desc->devnum, start, blkcnt, + desc->blksz, buf); return blks_read; } -unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start, - lbaint_t blkcnt, const void *buffer) +long blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, + const void *buf) { - struct udevice *dev = block_dev->bdev; + struct blk_desc *desc = dev_get_uclass_plat(dev); const struct blk_ops *ops = blk_get_ops(dev); if (!ops->write) return -ENOSYS; - blkcache_invalidate(block_dev->uclass_id, block_dev->devnum); - return ops->write(dev, start, blkcnt, buffer); + blkcache_invalidate(desc->uclass_id, desc->devnum); + + return ops->write(dev, start, blkcnt, buf); } -unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, - lbaint_t blkcnt) +long blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt) { - struct udevice *dev = block_dev->bdev; + struct blk_desc *desc = dev_get_uclass_plat(dev); const struct blk_ops *ops = blk_get_ops(dev); if (!ops->erase) return -ENOSYS; - blkcache_invalidate(block_dev->uclass_id, block_dev->devnum); + blkcache_invalidate(desc->uclass_id, desc->devnum); + return ops->erase(dev, start, blkcnt); } +ulong blk_dread(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt, + void *buffer) +{ + return blk_read(desc->bdev, start, blkcnt, buffer); +} + +ulong blk_dwrite(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt, + const void *buffer) +{ + return blk_write(desc->bdev, start, blkcnt, buffer); +} + +ulong blk_derase(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt) +{ + return blk_erase(desc->bdev, start, blkcnt); +} + int blk_get_from_parent(struct udevice *parent, struct udevice **devp) { struct udevice *dev; |