block: pass block dev not num to read/write/erase()

This will allow the implementation to make use of data in the block_dev
structure beyond the base device number. This will be useful so that eMMC
block devices can encompass the HW partition ID rather than treating this
out-of-band. Equally, the existence of the priv field is crying out for
this patch to exist.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 73f4c4a..170f0fa 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -22,9 +22,11 @@
 	return NULL;
 }
 
-static unsigned long host_block_read(int dev, unsigned long start,
-				     lbaint_t blkcnt, void *buffer)
+static unsigned long host_block_read(block_dev_desc_t *block_dev,
+				     unsigned long start, lbaint_t blkcnt,
+				     void *buffer)
 {
+	int dev = block_dev->dev;
 	struct host_block_dev *host_dev = find_host_device(dev);
 
 	if (!host_dev)
@@ -42,9 +44,11 @@
 	return -1;
 }
 
-static unsigned long host_block_write(int dev, unsigned long start,
-				      lbaint_t blkcnt, const void *buffer)
+static unsigned long host_block_write(block_dev_desc_t *block_dev,
+				      unsigned long start, lbaint_t blkcnt,
+				      const void *buffer)
 {
+	int dev = block_dev->dev;
 	struct host_block_dev *host_dev = find_host_device(dev);
 	if (os_lseek(host_dev->fd,
 		     start * host_dev->blk_dev.blksz,
diff --git a/drivers/block/systemace.c b/drivers/block/systemace.c
index fdf75b5..b974e80 100644
--- a/drivers/block/systemace.c
+++ b/drivers/block/systemace.c
@@ -69,8 +69,9 @@
 	return in16(base + off);
 }
 
-static unsigned long systemace_read(int dev, unsigned long start,
-					lbaint_t blkcnt, void *buffer);
+static unsigned long systemace_read(block_dev_desc_t *block_dev,
+				    unsigned long start, lbaint_t blkcnt,
+				    void *buffer);
 
 static block_dev_desc_t systemace_dev = { 0 };
 
@@ -136,8 +137,9 @@
  * the dev_desc) to read blocks of data. The return value is the
  * number of blocks read. A zero return indicates an error.
  */
-static unsigned long systemace_read(int dev, unsigned long start,
-					lbaint_t blkcnt, void *buffer)
+static unsigned long systemace_read(block_dev_desc_t *block_dev,
+				    unsigned long start, lbaint_t blkcnt,
+				    void *buffer)
 {
 	int retry;
 	unsigned blk_countdown;
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 5a9fb4a..7ff2a81 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -77,11 +77,11 @@
 	      dfu->data.mmc.dev_num, blk_start, blk_count, buf);
 	switch (op) {
 	case DFU_OP_READ:
-		n = mmc->block_dev.block_read(dfu->data.mmc.dev_num, blk_start,
+		n = mmc->block_dev.block_read(&mmc->block_dev, blk_start,
 					      blk_count, buf);
 		break;
 	case DFU_OP_WRITE:
-		n = mmc->block_dev.block_write(dfu->data.mmc.dev_num, blk_start,
+		n = mmc->block_dev.block_write(&mmc->block_dev, blk_start,
 					       blk_count, buf);
 		break;
 	default:
diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c
index b1cb4b3..301d9b3 100644
--- a/drivers/mmc/fsl_esdhc_spl.c
+++ b/drivers/mmc/fsl_esdhc_spl.c
@@ -38,7 +38,8 @@
 	blk_start = ALIGN(offs, mmc->read_bl_len) / mmc->read_bl_len;
 	blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len;
 
-	err = mmc->block_dev.block_read(0, blk_start, blk_cnt, vdst);
+	err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt,
+					vdst);
 	if (err != blk_cnt) {
 		puts("spl: mmc read failed!!\n");
 		hang();
@@ -85,7 +86,8 @@
 	/*
 	* Read source addr from sd card
 	*/
-	err = mmc->block_dev.block_read(0, CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
+	err = mmc->block_dev.block_read(&mmc->block_dev,
+					CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
 	if (err != 1) {
 		puts("spl: mmc read failed!!\n");
 		free(tmp_buf);
@@ -126,7 +128,7 @@
 #endif
 	blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len;
 	blk_cnt = ALIGN(code_len, mmc->read_bl_len) / mmc->read_bl_len;
-	err = mmc->block_dev.block_read(0, blk_start, blk_cnt,
+	err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt,
 					(uchar *)CONFIG_SYS_MMC_U_BOOT_DST);
 	if (err != blk_cnt) {
 		puts("spl: mmc read failed!!\n");
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 3a34028..6d88db4 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -234,8 +234,10 @@
 	return blkcnt;
 }
 
-static ulong mmc_bread(int dev_num, lbaint_t start, lbaint_t blkcnt, void *dst)
+static ulong mmc_bread(block_dev_desc_t *block_dev, lbaint_t start,
+		       lbaint_t blkcnt, void *dst)
 {
+	int dev_num = block_dev->dev;
 	lbaint_t cur, blocks_todo = blkcnt;
 
 	if (blkcnt == 0)
diff --git a/drivers/mmc/mmc_private.h b/drivers/mmc/mmc_private.h
index 447a700..6a70639 100644
--- a/drivers/mmc/mmc_private.h
+++ b/drivers/mmc/mmc_private.h
@@ -22,23 +22,24 @@
 
 #ifndef CONFIG_SPL_BUILD
 
-extern unsigned long mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt);
+unsigned long mmc_berase(block_dev_desc_t *block_dev, lbaint_t start,
+			 lbaint_t blkcnt);
 
-extern ulong mmc_bwrite(int dev_num, lbaint_t start, lbaint_t blkcnt,
-		const void *src);
+unsigned long mmc_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+			 lbaint_t blkcnt, const void *src);
 
 #else /* CONFIG_SPL_BUILD */
 
 /* SPL will never write or erase, declare dummies to reduce code size. */
 
-static inline unsigned long mmc_berase(int dev_num, lbaint_t start,
-		lbaint_t blkcnt)
+static inline unsigned long mmc_berase(block_dev_desc_t *block_dev,
+				       lbaint_t start, lbaint_t blkcnt)
 {
 	return 0;
 }
 
-static inline ulong mmc_bwrite(int dev_num, lbaint_t start, lbaint_t blkcnt,
-		const void *src)
+static inline ulong mmc_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+			       lbaint_t blkcnt, const void *src)
 {
 	return 0;
 }
diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index 221bf30..6733314 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -65,8 +65,10 @@
 	return err;
 }
 
-unsigned long mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt)
+unsigned long mmc_berase(block_dev_desc_t *block_dev, lbaint_t start,
+			 lbaint_t blkcnt)
 {
+	int dev_num = block_dev->dev;
 	int err = 0;
 	u32 start_rem, blkcnt_rem;
 	struct mmc *mmc = find_mmc_device(dev_num);
@@ -165,8 +167,10 @@
 	return blkcnt;
 }
 
-ulong mmc_bwrite(int dev_num, lbaint_t start, lbaint_t blkcnt, const void *src)
+ulong mmc_bwrite(block_dev_desc_t *block_dev, lbaint_t start, lbaint_t blkcnt,
+		 const void *src)
 {
+	int dev_num = block_dev->dev;
 	lbaint_t cur, blocks_todo = blkcnt;
 
 	struct mmc *mmc = find_mmc_device(dev_num);
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index e717c44..7b33094 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -454,7 +454,7 @@
 		panic("Failed to allocate memory\n");
 
 	if (mmc_getcd(mmc) && mmc_init(mmc) == 0 &&
-	    mmc->block_dev.block_read(mmc->block_dev.dev, 16, 1, buf) == 1 &&
+	    mmc->block_dev.block_read(&mmc->block_dev, 16, 1, buf) == 1 &&
 	    strncmp(&buf[4], "eGON.BT0", 8) == 0)
 		valid_signature = 1;
 
diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c
index df5db72..40fbf19 100644
--- a/drivers/net/fm/fm.c
+++ b/drivers/net/fm/fm.c
@@ -395,7 +395,8 @@
 		printf("\nMMC read: dev # %u, block # %u, count %u ...\n",
 				dev, blk, cnt);
 		mmc_init(mmc);
-		(void)mmc->block_dev.block_read(dev, blk, cnt, addr);
+		(void)mmc->block_dev.block_read(&mmc->block_dev, blk, cnt,
+						addr);
 		/* flush cache after read */
 		flush_cache((ulong)addr, cnt * 512);
 	}
diff --git a/drivers/net/phy/cortina.c b/drivers/net/phy/cortina.c
index 3a2b3bb..447ecfb 100644
--- a/drivers/net/phy/cortina.c
+++ b/drivers/net/phy/cortina.c
@@ -174,7 +174,8 @@
 		printf("MMC read: dev # %u, block # %u, count %u ...\n",
 		       dev, blk, cnt);
 		mmc_init(mmc);
-		(void)mmc->block_dev.block_read(dev, blk, cnt, addr);
+		(void)mmc->block_dev.block_read(&mmc->block_dev, blk, cnt,
+						addr);
 		/* flush cache after read */
 		flush_cache((ulong)addr, cnt * 512);
 	}