diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-04-04 13:59:21 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-05-31 09:34:48 +0200 |
commit | e82e40523f8df1c10b6646798065115119aea9a8 (patch) | |
tree | 2fa821d7e68a6ff78233277ae5980ab7c7ce7381 | |
parent | b5c4e238d38adf76c4648494ae6eeb62345bd086 (diff) | |
download | barebox-e82e40523f8df1c10b6646798065115119aea9a8.tar.gz barebox-e82e40523f8df1c10b6646798065115119aea9a8.tar.xz |
block: implement block_read/block_write functions
Some drivers use blk->ops->read/write. This bypasses the caching block
layer and was never intended like this. The upper API to the block layer
is the cdev layer. This patch adds block_read and block_write functions
and uses them where appropriate.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/block.c | 22 | ||||
-rw-r--r-- | common/partitions.c | 2 | ||||
-rw-r--r-- | common/partitions/efi.c | 4 | ||||
-rw-r--r-- | include/block.h | 8 |
4 files changed, 33 insertions, 3 deletions
diff --git a/common/block.c b/common/block.c index 2cf85ae987..ad07f8b2e2 100644 --- a/common/block.c +++ b/common/block.c @@ -387,3 +387,25 @@ int blockdevice_unregister(struct block_device *blk) return 0; } + +int block_read(struct block_device *blk, void *buf, int block, int num_blocks) +{ + int ret; + + ret = cdev_read(&blk->cdev, buf, + num_blocks << blk->blockbits, + (loff_t)block << blk->blockbits, 0); + + return ret < 0 ? ret : 0; +} + +int block_write(struct block_device *blk, void *buf, int block, int num_blocks) +{ + int ret; + + ret = cdev_write(&blk->cdev, buf, + num_blocks << blk->blockbits, + (loff_t)block << blk->blockbits, 0); + + return ret < 0 ? ret : 0; +} diff --git a/common/partitions.c b/common/partitions.c index 683b2586e4..35a604c35f 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -128,7 +128,7 @@ int parse_partition_table(struct block_device *blk) pdesc = xzalloc(sizeof(*pdesc)); buf = dma_alloc(SECTOR_SIZE * 2); - rc = blk->ops->read(blk, buf, 0, 2); + rc = block_read(blk, buf, 0, 2); if (rc != 0) { dev_err(blk->dev, "Cannot read MBR/partition table\n"); goto on_error; diff --git a/common/partitions/efi.c b/common/partitions/efi.c index e450eebf77..ee1326e622 100644 --- a/common/partitions/efi.c +++ b/common/partitions/efi.c @@ -86,7 +86,7 @@ static gpt_entry *alloc_read_gpt_entries(struct block_device *blk, from = le64_to_cpu(pgpt_head->partition_entry_lba); size = count / GPT_BLOCK_SIZE; - ret = blk->ops->read(blk, pte, from, size); + ret = block_read(blk, pte, from, size); if (ret) { kfree(pte); pte=NULL; @@ -121,7 +121,7 @@ static gpt_header *alloc_read_gpt_header(struct block_device *blk, if (!gpt) return NULL; - ret = blk->ops->read(blk, gpt, lba, 1); + ret = block_read(blk, gpt, lba, 1); if (ret) { kfree(gpt); gpt=NULL; diff --git a/include/block.h b/include/block.h index ef36f585f1..eb31aca4db 100644 --- a/include/block.h +++ b/include/block.h @@ -29,4 +29,12 @@ struct block_device { int blockdevice_register(struct block_device *blk); int blockdevice_unregister(struct block_device *blk); +int block_read(struct block_device *blk, void *buf, int block, int num_blocks); +int block_write(struct block_device *blk, void *buf, int block, int num_blocks); + +static inline int block_flush(struct block_device *blk) +{ + return cdev_flush(&blk->cdev); +} + #endif /* __BLOCK_H */ |