mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-22 04:44:46 +00:00
disk: Simplify disk_blk_read() using blk_read()
The disk_blk_read() can be simplified using blk_read(), the only things which needs to be handled are the read offset based on the partition properties, and the block device ops which are coming from the parent udevice, not the partition udevice. The later is currently not implemented correctly as far as I can tell, since the current code extracts block device descriptor from the parent udevice which is OK, but extracts block device operations from the partition udevice, which does not seem OK. Switching to the blk_read() fixes that too. The dev_get_blk() usage is simplified using UCLASS_PARTITION check. Add non-confusing documentation what this really does. Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
This commit is contained in:
parent
5ff4609f85
commit
91d3066c90
1 changed files with 14 additions and 24 deletions
|
@ -168,36 +168,26 @@ static struct blk_desc *dev_get_blk(struct udevice *dev)
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* disk_blk_read() - Read from a block device partition
|
||||||
|
*
|
||||||
|
* @dev: Device to read from (partition udevice)
|
||||||
|
* @start: Start block for the read (from start of partition)
|
||||||
|
* @blkcnt: Number of blocks to read (within the partition)
|
||||||
|
* @buffer: 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
|
||||||
|
*/
|
||||||
unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
|
unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
|
||||||
lbaint_t blkcnt, void *buffer)
|
lbaint_t blkcnt, void *buffer)
|
||||||
{
|
{
|
||||||
struct blk_desc *desc;
|
struct disk_part *part = dev_get_uclass_plat(dev);
|
||||||
const struct blk_ops *ops;
|
|
||||||
struct disk_part *part;
|
|
||||||
lbaint_t start_in_disk;
|
|
||||||
ulong blks_read;
|
|
||||||
|
|
||||||
desc = dev_get_blk(dev);
|
if (device_get_uclass_id(dev) != UCLASS_PARTITION)
|
||||||
if (!desc)
|
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
ops = blk_get_ops(dev);
|
return blk_read(dev_get_parent(dev), start + part->gpt_part_info.start,
|
||||||
if (!ops->read)
|
blkcnt, buffer);
|
||||||
return -ENOSYS;
|
|
||||||
|
|
||||||
start_in_disk = start;
|
|
||||||
part = dev_get_uclass_plat(dev);
|
|
||||||
start_in_disk += part->gpt_part_info.start;
|
|
||||||
|
|
||||||
if (blkcache_read(desc->uclass_id, desc->devnum, start_in_disk, blkcnt,
|
|
||||||
desc->blksz, buffer))
|
|
||||||
return blkcnt;
|
|
||||||
blks_read = ops->read(dev, start, blkcnt, buffer);
|
|
||||||
if (blks_read == blkcnt)
|
|
||||||
blkcache_fill(desc->uclass_id, desc->devnum, start_in_disk,
|
|
||||||
blkcnt, desc->blksz, buffer);
|
|
||||||
|
|
||||||
return blks_read;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
|
unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
|
||||||
|
|
Loading…
Add table
Reference in a new issue