block: pass block dev not num to read/write/erase()
authorStephen Warren <swarren@nvidia.com>
Mon, 7 Dec 2015 18:38:48 +0000 (11:38 -0700)
committerTom Rini <trini@konsulko.com>
Thu, 14 Jan 2016 02:05:18 +0000 (21:05 -0500)
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>
41 files changed:
api/api_storage.c
board/freescale/common/sdhc_boot.c
board/gdsys/p1022/controlcenterd-id.c
board/gdsys/p1022/sdhc_boot.c
common/cmd_disk.c
common/cmd_ide.c
common/cmd_mmc.c
common/cmd_read.c
common/cmd_sata.c
common/cmd_scsi.c
common/cmd_usb.c
common/cmd_usb_mass_storage.c
common/env_mmc.c
common/fb_mmc.c
common/spl/spl_mmc.c
common/usb_storage.c
disk/part_amiga.c
disk/part_dos.c
disk/part_efi.c
disk/part_iso.c
disk/part_mac.c
drivers/block/sandbox.c
drivers/block/systemace.c
drivers/dfu/dfu_mmc.c
drivers/mmc/fsl_esdhc_spl.c
drivers/mmc/mmc.c
drivers/mmc/mmc_private.h
drivers/mmc/mmc_write.c
drivers/mmc/sunxi_mmc.c
drivers/net/fm/fm.c
drivers/net/phy/cortina.c
fs/ext4/dev.c
fs/ext4/ext4_common.c
fs/fat/fat.c
fs/fat/fat_write.c
fs/reiserfs/dev.c
fs/zfs/dev.c
include/ide.h
include/part.h
lib/gunzip.c
test/dm/usb.c

index ec92ae48d1c21fcc5ffae88bc42d9167171fa9ed..bc2b4d6b8cc76de796d98ecb69e1f581212df6b9 100644 (file)
@@ -345,19 +345,6 @@ int dev_close_stor(void *cookie)
 }
 
 
-static int dev_stor_index(block_dev_desc_t *dd)
-{
-       int i, type;
-
-       type = dev_stor_type(dd);
-       for (i = 0; i < specs[type].max_dev; i++)
-               if (dd == get_dev(specs[type].name, i))
-                       return i;
-
-       return (specs[type].max_dev);
-}
-
-
 lbasize_t dev_read_stor(void *cookie, void *buf, lbasize_t len, lbastart_t start)
 {
        int type;
@@ -374,5 +361,5 @@ lbasize_t dev_read_stor(void *cookie, void *buf, lbasize_t len, lbastart_t start
                return 0;
        }
 
-       return (dd->block_read(dev_stor_index(dd), start, len, buf));
+       return dd->block_read(dd, start, len, buf);
 }
index 022f38b117f2c945cb6e5eb7e1cea21612631cce..e55a03090ab86c00b6765d823910755346b45295 100644 (file)
@@ -29,7 +29,7 @@ int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
                return 1;
 
        /* read out the first block, get the config data information */
-       n = mmc->block_dev.block_read(mmc->block_dev.dev, 0, 1, tmp_buf);
+       n = mmc->block_dev.block_read(&mmc->block_dev, 0, 1, tmp_buf);
        if (!n) {
                free(tmp_buf);
                return 1;
index 11d075c38593c91d0ce588ff7c11ee56796427fd..46a46c0d86834502b2cbf16f3e4a768ee51e2db4 100644 (file)
@@ -232,7 +232,7 @@ static int ccdm_mmc_read(struct mmc *mmc, u64 src, u8 *dst, int size)
        ofs = src % blk_len;
 
        if (ofs) {
-               n = mmc->block_dev.block_read(mmc->block_dev.dev, block_no++, 1,
+               n = mmc->block_dev.block_read(&mmc->block_dev, block_no++, 1,
                        tmp_buf);
                if (!n)
                        goto failure;
@@ -243,7 +243,7 @@ static int ccdm_mmc_read(struct mmc *mmc, u64 src, u8 *dst, int size)
        }
        cnt = size / blk_len;
        if (cnt) {
-               n = mmc->block_dev.block_read(mmc->block_dev.dev, block_no, cnt,
+               n = mmc->block_dev.block_read(&mmc->block_dev, block_no, cnt,
                        dst);
                if (n != cnt)
                        goto failure;
@@ -253,7 +253,7 @@ static int ccdm_mmc_read(struct mmc *mmc, u64 src, u8 *dst, int size)
                block_no += cnt;
        }
        if (size) {
-               n = mmc->block_dev.block_read(mmc->block_dev.dev, block_no++, 1,
+               n = mmc->block_dev.block_read(&mmc->block_dev, block_no++, 1,
                        tmp_buf);
                if (!n)
                        goto failure;
index fd0e910d7ba7cd08a3f9fee88f9ff52e5c9b7c4f..6a4a6ef6af2498cc3475b959eeb608a0d89229f8 100644 (file)
@@ -43,7 +43,7 @@ int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
                return 1;
 
        /* read out the first block, get the config data information */
-       n = mmc->block_dev.block_read(mmc->block_dev.dev, 0, 1, tmp_buf);
+       n = mmc->block_dev.block_read(&mmc->block_dev, 0, 1, tmp_buf);
        if (!n) {
                free(tmp_buf);
                return 1;
index 8a1fda9f68a412a0afa232df5a6e3c0ed7d69890..3025225c764264a899d2ecd40e4081ccbc713228 100644 (file)
@@ -56,7 +56,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
              ", Block Size: %ld\n",
              info.start, info.size, info.blksz);
 
-       if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) {
+       if (dev_desc->block_read(dev_desc, info.start, 1, (ulong *)addr) != 1) {
                printf("** Read error on %d:%d\n", dev, part);
                bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
                return 1;
@@ -100,8 +100,8 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
        cnt /= info.blksz;
        cnt -= 1;
 
-       if (dev_desc->block_read(dev, info.start + 1, cnt,
-                                        (ulong *)(addr + info.blksz)) != cnt) {
+       if (dev_desc->block_read(dev_desc, info.start + 1, cnt,
+                                (ulong *)(addr + info.blksz)) != cnt) {
                printf("** Read error on %d:%d\n", dev, part);
                bootstage_error(BOOTSTAGE_ID_IDE_READ);
                return 1;
index ecd3e9d64f086318578af7579e125dabdf0c381b..f19a7ce42a728895ecb3582bd35d7487c2ef559e 100644 (file)
@@ -79,8 +79,8 @@ static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len
 
 #ifdef CONFIG_ATAPI
 static void    atapi_inquiry(block_dev_desc_t *dev_desc);
-static ulong atapi_read(int device, lbaint_t blknr, lbaint_t blkcnt,
-                       void *buffer);
+static ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                       lbaint_t blkcnt, void *buffer);
 #endif
 
 
@@ -187,6 +187,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                if (strcmp(argv[1], "read") == 0) {
                        ulong addr = simple_strtoul(argv[2], NULL, 16);
                        ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                       block_dev_desc_t *dev_desc;
                        ulong n;
 
 #ifdef CONFIG_SYS_64BIT_LBA
@@ -201,9 +202,9 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                                curr_device, blk, cnt);
 #endif
 
-                       n = ide_dev_desc[curr_device].block_read(curr_device,
-                                                                blk, cnt,
-                                                                (ulong *)addr);
+                       dev_desc = &ide_dev_desc[curr_device];
+                       n = dev_desc->block_read(dev_desc, blk, cnt,
+                                                (ulong *)addr);
                        /* flush cache after read */
                        flush_cache(addr,
                                    cnt * ide_dev_desc[curr_device].blksz);
@@ -230,7 +231,8 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                        printf("\nIDE write: device %d block # %ld, count %ld ... ",
                                curr_device, blk, cnt);
 #endif
-                       n = ide_write(curr_device, blk, cnt, (ulong *) addr);
+                       n = ide_write(&ide_dev_desc[curr_device], blk, cnt,
+                                     (ulong *)addr);
 
                        printf("%ld blocks written: %s\n",
                                n, (n == cnt) ? "OK" : "ERROR");
@@ -711,8 +713,10 @@ static void ide_ident(block_dev_desc_t *dev_desc)
 
 /* ------------------------------------------------------------------------- */
 
-ulong ide_read(int device, lbaint_t blknr, lbaint_t blkcnt, void *buffer)
+ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+              void *buffer)
 {
+       int device = block_dev->dev;
        ulong n = 0;
        unsigned char c;
        unsigned char pwrsave = 0;      /* power save */
@@ -835,8 +839,10 @@ IDE_READ_E:
 /* ------------------------------------------------------------------------- */
 
 
-ulong ide_write(int device, lbaint_t blknr, lbaint_t blkcnt, const void *buffer)
+ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+               const void *buffer)
 {
+       int device = block_dev->dev;
        ulong n = 0;
        unsigned char c;
 
@@ -1388,8 +1394,10 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
 #define ATAPI_READ_BLOCK_SIZE  2048    /* assuming CD part */
 #define ATAPI_READ_MAX_BLOCK   (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
 
-ulong atapi_read(int device, lbaint_t blknr, lbaint_t blkcnt, void *buffer)
+ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+                void *buffer)
 {
+       int device = block_dev->dev;
        ulong n = 0;
        unsigned char ccb[12];  /* Command descriptor block */
        ulong cnt;
index a6b7313e4a44d1f895a6a9e2a55311b85bcf5487..6b5c1ac1109eb6e10c27ad7fb88ddd0e8a8fa2f8 100644 (file)
@@ -351,7 +351,7 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
        printf("\nMMC read: dev # %d, block # %d, count %d ... ",
               curr_device, blk, cnt);
 
-       n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
+       n = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, addr);
        /* flush cache after read */
        flush_cache((ulong)addr, cnt * 512); /* FIXME */
        printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
@@ -383,7 +383,7 @@ static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
                printf("Error: card is write protected!\n");
                return CMD_RET_FAILURE;
        }
-       n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
+       n = mmc->block_dev.block_write(&mmc->block_dev, blk, cnt, addr);
        printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
 
        return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
@@ -411,7 +411,7 @@ static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
                printf("Error: card is write protected!\n");
                return CMD_RET_FAILURE;
        }
-       n = mmc->block_dev.block_erase(curr_device, blk, cnt);
+       n = mmc->block_dev.block_erase(&mmc->block_dev, blk, cnt);
        printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
 
        return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
index f0fc9bfe17adaf01147a4ef32de8d35b72125d95..8710288781747d9f0bc32a4d2ac18a9e61b893e4 100644 (file)
@@ -66,7 +66,7 @@ int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return 1;
        }
 
-       if (dev_desc->block_read(dev, offset + blk, cnt, addr) < 0) {
+       if (dev_desc->block_read(dev_desc, offset + blk, cnt, addr) < 0) {
                printf("Error reading blocks\n");
                return 1;
        }
index 51f67033ae32026d973e8944685839587c855e5e..76baceae8c939eff77fcd45d46c820f3feb8a5d5 100644 (file)
 static int sata_curr_device = -1;
 block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
 
+static unsigned long sata_bread(block_dev_desc_t *block_dev, lbaint_t start,
+                               lbaint_t blkcnt, void *dst)
+{
+       return sata_read(block_dev->dev, start, blkcnt, dst);
+}
+
+static unsigned long sata_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+                                lbaint_t blkcnt, const void *buffer)
+{
+       return sata_write(block_dev->dev, start, blkcnt, buffer);
+}
+
 int __sata_initialize(void)
 {
        int rc;
@@ -32,8 +44,8 @@ int __sata_initialize(void)
                sata_dev_desc[i].lba = 0;
                sata_dev_desc[i].blksz = 512;
                sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
-               sata_dev_desc[i].block_read = sata_read;
-               sata_dev_desc[i].block_write = sata_write;
+               sata_dev_desc[i].block_read = sata_bread;
+               sata_dev_desc[i].block_write = sata_bwrite;
 
                rc = init_sata(i);
                if (!rc) {
index 86954089fe78aa234434306e37aba9bee9ec1d91..bc7d1b6c53007801eb24e298629040aa6c7ed2c5 100644 (file)
@@ -66,9 +66,9 @@ void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
 
 static int scsi_read_capacity(ccb *pccb, lbaint_t *capacity,
                              unsigned long *blksz);
-static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt,
-                      void *buffer);
-static ulong scsi_write(int device, lbaint_t blknr,
+static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                      lbaint_t blkcnt, void *buffer);
+static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
                        lbaint_t blkcnt, const void *buffer);
 
 
@@ -346,7 +346,8 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                                ulong n;
                                printf ("\nSCSI read: device %d block # %ld, count %ld ... ",
                                                scsi_curr_dev, blk, cnt);
-                               n = scsi_read(scsi_curr_dev, blk, cnt, (ulong *)addr);
+                               n = scsi_read(&scsi_dev_desc[scsi_curr_dev],
+                                             blk, cnt, (ulong *)addr);
                                printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR");
                                return 0;
                        } else if (strcmp(argv[1], "write") == 0) {
@@ -357,8 +358,8 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                                printf("\nSCSI write: device %d block # %ld, "
                                       "count %ld ... ",
                                       scsi_curr_dev, blk, cnt);
-                               n = scsi_write(scsi_curr_dev, blk, cnt,
-                                              (ulong *)addr);
+                               n = scsi_write(&scsi_dev_desc[scsi_curr_dev],
+                                              blk, cnt, (ulong *)addr);
                                printf("%ld blocks written: %s\n", n,
                                       (n == cnt) ? "OK" : "ERROR");
                                return 0;
@@ -375,9 +376,10 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #define SCSI_MAX_READ_BLK 0xFFFF
 #define SCSI_LBA48_READ        0xFFFFFFF
 
-static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt,
-                      void *buffer)
+static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                      lbaint_t blkcnt, void *buffer)
 {
+       int device = block_dev->dev;
        lbaint_t start, blks;
        uintptr_t buf_addr;
        unsigned short smallblks = 0;
@@ -441,9 +443,10 @@ static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt,
 /* Almost the maximum amount of the scsi_ext command.. */
 #define SCSI_MAX_WRITE_BLK 0xFFFF
 
-static ulong scsi_write(int device, lbaint_t blknr,
+static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
                        lbaint_t blkcnt, const void *buffer)
 {
+       int device = block_dev->dev;
        lbaint_t start, blks;
        uintptr_t buf_addr;
        unsigned short smallblks;
index a540b422db3abb9c9498f74aa26fbf701bb08f84..c7b642c40af969885d0d782bcf010740e613f16f 100644 (file)
@@ -759,7 +759,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        printf("\nUSB read: device %d block # %ld, count %ld"
                                " ... ", usb_stor_curr_dev, blk, cnt);
                        stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
-                       n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt,
+                       n = stor_dev->block_read(stor_dev, blk, cnt,
                                                 (ulong *)addr);
                        printf("%ld blocks read: %s\n", n,
                                (n == cnt) ? "OK" : "ERROR");
@@ -781,7 +781,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        printf("\nUSB write: device %d block # %ld, count %ld"
                                " ... ", usb_stor_curr_dev, blk, cnt);
                        stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
-                       n = stor_dev->block_write(usb_stor_curr_dev, blk, cnt,
+                       n = stor_dev->block_write(stor_dev, blk, cnt,
                                                (ulong *)addr);
                        printf("%ld blocks write: %s\n", n,
                                (n == cnt) ? "OK" : "ERROR");
index 040738911290c63f86715ba93b8df963424e459f..f4bafecd0d45c5eae13703abce6151eff4b417b1 100644 (file)
@@ -19,9 +19,8 @@ static int ums_read_sector(struct ums *ums_dev,
 {
        block_dev_desc_t *block_dev = ums_dev->block_dev;
        lbaint_t blkstart = start + ums_dev->start_sector;
-       int dev_num = block_dev->dev;
 
-       return block_dev->block_read(dev_num, blkstart, blkcnt, buf);
+       return block_dev->block_read(block_dev, blkstart, blkcnt, buf);
 }
 
 static int ums_write_sector(struct ums *ums_dev,
@@ -29,9 +28,8 @@ static int ums_write_sector(struct ums *ums_dev,
 {
        block_dev_desc_t *block_dev = ums_dev->block_dev;
        lbaint_t blkstart = start + ums_dev->start_sector;
-       int dev_num = block_dev->dev;
 
-       return block_dev->block_write(dev_num, blkstart, blkcnt, buf);
+       return block_dev->block_write(block_dev, blkstart, blkcnt, buf);
 }
 
 static struct ums ums_dev = {
index 96398224cc849577a4150edf281337070e06d94b..f182749e8b88931ec18075e95653e8c2d397340b 100644 (file)
@@ -127,7 +127,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
        blk_start       = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
        blk_cnt         = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
 
-       n = mmc->block_dev.block_write(CONFIG_SYS_MMC_ENV_DEV, blk_start,
+       n = mmc->block_dev.block_write(&mmc->block_dev, blk_start,
                                        blk_cnt, (u_char *)buffer);
 
        return (n == blk_cnt) ? 0 : -1;
@@ -192,16 +192,12 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
                           unsigned long offset, const void *buffer)
 {
        uint blk_start, blk_cnt, n;
-       int dev = CONFIG_SYS_MMC_ENV_DEV;
-
-#ifdef CONFIG_SPL_BUILD
-       dev = 0;
-#endif
 
        blk_start       = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len;
        blk_cnt         = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len;
 
-       n = mmc->block_dev.block_read(dev, blk_start, blk_cnt, (uchar *)buffer);
+       n = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt,
+                                     (uchar *)buffer);
 
        return (n == blk_cnt) ? 0 : -1;
 }
index b480e76554bca8d1debe33103f38249e7401439e..6e742dac56f7884ebd866ab35730412b4e255b15 100644 (file)
@@ -58,7 +58,7 @@ static int fb_mmc_sparse_write(struct sparse_storage *storage,
        block_dev_desc_t *dev_desc = sparse->dev_desc;
        int ret;
 
-       ret = dev_desc->block_write(dev_desc->dev, offset, size, data);
+       ret = dev_desc->block_write(dev_desc, offset, size, data);
        if (!ret)
                return -EIO;
 
@@ -84,8 +84,7 @@ static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
 
        puts("Flashing Raw Image\n");
 
-       blks = dev_desc->block_write(dev_desc->dev, info->start, blkcnt,
-                                    buffer);
+       blks = dev_desc->block_write(dev_desc, info->start, blkcnt, buffer);
        if (blks != blkcnt) {
                error("failed writing to device %d\n", dev_desc->dev);
                fastboot_fail(response_str, "failed writing to device");
@@ -206,7 +205,7 @@ void fb_mmc_erase(const char *cmd, char *response)
        printf("Erasing blocks " LBAFU " to " LBAFU " due to alignment\n",
               blks_start, blks_start + blks_size);
 
-       blks = dev_desc->block_erase(dev_desc->dev, blks_start, blks_size);
+       blks = dev_desc->block_erase(dev_desc, blks_start, blks_size);
        if (blks != blks_size) {
                error("failed erasing from device %d", dev_desc->dev);
                fastboot_fail(response_str, "failed erasing from device");
index c1c29c02d7edec75b5d64a186679e7755f079607..c3931c6c4d7761c598d45312e2b5ffc01a676231 100644 (file)
@@ -23,13 +23,12 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
        unsigned long count;
        u32 image_size_sectors;
        struct image_header *header;
-       int dev_num = mmc->block_dev.dev;
 
        header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
                                         sizeof(struct image_header));
 
        /* read image header to find the image size & load address */
-       count = mmc->block_dev.block_read(dev_num, sector, 1, header);
+       count = mmc->block_dev.block_read(&mmc->block_dev, sector, 1, header);
        debug("read sector %lx, count=%lu\n", sector, count);
        if (count == 0)
                goto end;
@@ -46,7 +45,8 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
                             mmc->read_bl_len;
 
        /* Read the header too to avoid extra memcpy */
-       count = mmc->block_dev.block_read(dev_num, sector, image_size_sectors,
+       count = mmc->block_dev.block_read(&mmc->block_dev, sector,
+                                         image_size_sectors,
                                          (void *)(ulong)spl_image.load_addr);
        debug("read %x sectors to %x\n", image_size_sectors,
              spl_image.load_addr);
@@ -150,8 +150,7 @@ static int mmc_load_image_raw_os(struct mmc *mmc)
 {
        unsigned long count;
 
-       count = mmc->block_dev.block_read(
-               mmc->block_dev.dev,
+       count = mmc->block_dev.block_read(&mmc->block_dev,
                CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
                CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
                (void *) CONFIG_SYS_SPL_ARGS_ADDR);
index e61a8c8adfd02e82c320169dc6da9e28f515d8ef..4fdb55f9faf9061f730abb02710094aed2f5f547 100644 (file)
@@ -119,10 +119,10 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *us,
                      block_dev_desc_t *dev_desc);
 int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
                      struct us_data *ss);
-unsigned long usb_stor_read(int device, lbaint_t blknr,
-                           lbaint_t blkcnt, void *buffer);
-unsigned long usb_stor_write(int device, lbaint_t blknr,
-                            lbaint_t blkcnt, const void *buffer);
+static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                                  lbaint_t blkcnt, void *buffer);
+static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+                                   lbaint_t blkcnt, const void *buffer);
 void uhci_show_temp_int_td(void);
 
 #ifdef CONFIG_PARTITIONS
@@ -1027,9 +1027,10 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor,
 }
 #endif /* CONFIG_USB_BIN_FIXUP */
 
-unsigned long usb_stor_read(int device, lbaint_t blknr,
-                           lbaint_t blkcnt, void *buffer)
+static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                                  lbaint_t blkcnt, void *buffer)
 {
+       int device = block_dev->dev;
        lbaint_t start, blks;
        uintptr_t buf_addr;
        unsigned short smallblks;
@@ -1097,9 +1098,10 @@ retry_it:
        return blkcnt;
 }
 
-unsigned long usb_stor_write(int device, lbaint_t blknr,
-                               lbaint_t blkcnt, const void *buffer)
+static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+                                   lbaint_t blkcnt, const void *buffer)
 {
+       int device = block_dev->dev;
        lbaint_t start, blks;
        uintptr_t buf_addr;
        unsigned short smallblks;
index 260a3d5e87c8eac903403fc904e73e440ed61111..57c1b9d055f0d1d1ca255bc7e9f4dfd1a4542b29 100644 (file)
@@ -140,8 +140,7 @@ struct rigid_disk_block *get_rdisk(block_dev_desc_t *dev_desc)
 
     for (i=0; i<limit; i++)
     {
-       ulong res = dev_desc->block_read(dev_desc->dev, i, 1,
-                                        (ulong *)block_buffer);
+       ulong res = dev_desc->block_read(dev_desc, i, 1, (ulong *)block_buffer);
        if (res == 1)
        {
            struct rigid_disk_block *trdb = (struct rigid_disk_block *)block_buffer;
@@ -183,7 +182,7 @@ struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc)
 
     for (i = 0; i < limit; i++)
     {
-       ulong res = dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)block_buffer);
+       ulong res = dev_desc->block_read(dev_desc, i, 1, (ulong *)block_buffer);
        if (res == 1)
        {
            struct bootcode_block *boot = (struct bootcode_block *)block_buffer;
@@ -258,7 +257,7 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
 
     while (block != 0xFFFFFFFF)
     {
-       ulong res = dev_desc->block_read(dev_desc->dev, block, 1,
+       ulong res = dev_desc->block_read(dev_desc, block, 1,
                                         (ulong *)block_buffer);
        if (res == 1)
        {
@@ -354,8 +353,7 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
 
        PRINTF("Trying to load block #0x%X\n", block);
 
-       res = dev_desc->block_read(dev_desc->dev, block, 1,
-                                  (ulong *)block_buffer);
+       res = dev_desc->block_read(dev_desc, block, 1, (ulong *)block_buffer);
        if (res == 1)
        {
            p = (struct partition_block *)block_buffer;
index 628066041bb4a05930be989539c95f4a77728a64..1e5cb330cd5566f3d638ce2ad1f9a2378f802263 100644 (file)
@@ -91,7 +91,7 @@ int test_part_dos (block_dev_desc_t *dev_desc)
 {
        ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 
-       if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1)
+       if (dev_desc->block_read(dev_desc, 0, 1, (ulong *)buffer) != 1)
                return -1;
 
        if (test_block_type(buffer) != DOS_MBR)
@@ -111,7 +111,8 @@ static void print_partition_extended(block_dev_desc_t *dev_desc,
        dos_partition_t *pt;
        int i;
 
-       if (dev_desc->block_read(dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) {
+       if (dev_desc->block_read(dev_desc, ext_part_sector, 1,
+                                (ulong *)buffer) != 1) {
                printf ("** Can't read partition table on %d:" LBAFU " **\n",
                        dev_desc->dev, ext_part_sector);
                return;
@@ -177,7 +178,8 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc,
        int i;
        int dos_type;
 
-       if (dev_desc->block_read (dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) {
+       if (dev_desc->block_read(dev_desc, ext_part_sector, 1,
+                                (ulong *)buffer) != 1) {
                printf ("** Can't read partition table on %d:" LBAFU " **\n",
                        dev_desc->dev, ext_part_sector);
                return -1;
index b1e01558a69f67a8a16b5bdf9a3fbe7454ba09a9..22dfbb16b56c0ad36932ebfeca431af20498d658 100644 (file)
@@ -324,7 +324,7 @@ int test_part_efi(block_dev_desc_t * dev_desc)
        ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
 
        /* Read legacy MBR from block 0 and validate it */
-       if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)legacymbr) != 1)
+       if ((dev_desc->block_read(dev_desc, 0, 1, (ulong *)legacymbr) != 1)
                || (is_pmbr_valid(legacymbr) != 1)) {
                return -1;
        }
@@ -354,7 +354,7 @@ static int set_protective_mbr(block_dev_desc_t *dev_desc)
        p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1;
 
        /* Write MBR sector to the MMC device */
-       if (dev_desc->block_write(dev_desc->dev, 0, 1, p_mbr) != 1) {
+       if (dev_desc->block_write(dev_desc, 0, 1, p_mbr) != 1) {
                printf("** Can't write to device %d **\n",
                        dev_desc->dev);
                return -1;
@@ -386,22 +386,22 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
        gpt_h->header_crc32 = cpu_to_le32(calc_crc32);
 
        /* Write the First GPT to the block right after the Legacy MBR */
-       if (dev_desc->block_write(dev_desc->dev, 1, 1, gpt_h) != 1)
+       if (dev_desc->block_write(dev_desc, 1, 1, gpt_h) != 1)
                goto err;
 
-       if (dev_desc->block_write(dev_desc->dev, 2, pte_blk_cnt, gpt_e)
+       if (dev_desc->block_write(dev_desc, 2, pte_blk_cnt, gpt_e)
            != pte_blk_cnt)
                goto err;
 
        prepare_backup_gpt_header(gpt_h);
 
-       if (dev_desc->block_write(dev_desc->dev,
+       if (dev_desc->block_write(dev_desc,
                                  (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba)
                                  + 1,
                                  pte_blk_cnt, gpt_e) != pte_blk_cnt)
                goto err;
 
-       if (dev_desc->block_write(dev_desc->dev,
+       if (dev_desc->block_write(dev_desc,
                                  (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1,
                                  gpt_h) != 1)
                goto err;
@@ -737,7 +737,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
        /* write MBR */
        lba = 0;        /* MBR is always at 0 */
        cnt = 1;        /* MBR (1 block) */
-       if (dev_desc->block_write(dev_desc->dev, lba, cnt, buf) != cnt) {
+       if (dev_desc->block_write(dev_desc, lba, cnt, buf) != cnt) {
                printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
                       __func__, "MBR", cnt, lba);
                return 1;
@@ -746,7 +746,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
        /* write Primary GPT */
        lba = GPT_PRIMARY_PARTITION_TABLE_LBA;
        cnt = 1;        /* GPT Header (1 block) */
-       if (dev_desc->block_write(dev_desc->dev, lba, cnt, gpt_h) != cnt) {
+       if (dev_desc->block_write(dev_desc, lba, cnt, gpt_h) != cnt) {
                printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
                       __func__, "Primary GPT Header", cnt, lba);
                return 1;
@@ -754,7 +754,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
 
        lba = le64_to_cpu(gpt_h->partition_entry_lba);
        cnt = gpt_e_blk_cnt;
-       if (dev_desc->block_write(dev_desc->dev, lba, cnt, gpt_e) != cnt) {
+       if (dev_desc->block_write(dev_desc, lba, cnt, gpt_e) != cnt) {
                printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
                       __func__, "Primary GPT Entries", cnt, lba);
                return 1;
@@ -765,7 +765,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
        /* write Backup GPT */
        lba = le64_to_cpu(gpt_h->partition_entry_lba);
        cnt = gpt_e_blk_cnt;
-       if (dev_desc->block_write(dev_desc->dev, lba, cnt, gpt_e) != cnt) {
+       if (dev_desc->block_write(dev_desc, lba, cnt, gpt_e) != cnt) {
                printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
                       __func__, "Backup GPT Entries", cnt, lba);
                return 1;
@@ -773,7 +773,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
 
        lba = le64_to_cpu(gpt_h->my_lba);
        cnt = 1;        /* GPT Header (1 block) */
-       if (dev_desc->block_write(dev_desc->dev, lba, cnt, gpt_h) != cnt) {
+       if (dev_desc->block_write(dev_desc, lba, cnt, gpt_h) != cnt) {
                printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
                       __func__, "Backup GPT Header", cnt, lba);
                return 1;
@@ -843,8 +843,7 @@ static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
        }
 
        /* Read GPT Header from device */
-       if (dev_desc->block_read(dev_desc->dev, (lbaint_t)lba, 1, pgpt_head)
-                       != 1) {
+       if (dev_desc->block_read(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) {
                printf("*** ERROR: Can't read GPT header ***\n");
                return 0;
        }
@@ -881,6 +880,7 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
                                         gpt_header * pgpt_head)
 {
        size_t count = 0, blk_cnt;
+       lbaint_t blk;
        gpt_entry *pte = NULL;
 
        if (!dev_desc || !pgpt_head) {
@@ -909,12 +909,10 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
        }
 
        /* Read GPT Entries from device */
+       blk = le64_to_cpu(pgpt_head->partition_entry_lba);
        blk_cnt = BLOCK_CNT(count, dev_desc);
-       if (dev_desc->block_read (dev_desc->dev,
-               (lbaint_t)le64_to_cpu(pgpt_head->partition_entry_lba),
-               (lbaint_t) (blk_cnt), pte)
-               != blk_cnt) {
-
+       if (dev_desc->block_read(dev_desc, blk, (lbaint_t)blk_cnt, pte)
+           != blk_cnt) {
                printf("*** ERROR: Can't read GPT Entries ***\n");
                free(pte);
                return NULL;
index 2547c703db54d02dd12ae891ec299042b4906e94..0b1ac606374bbbf781e95dbe0ebf886335703bf7 100644 (file)
@@ -62,8 +62,8 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
 
        /* the first sector (sector 0x10) must be a primary volume desc */
        blkaddr=PVD_OFFSET;
-       if (dev_desc->block_read (dev_desc->dev, PVD_OFFSET, 1, (ulong *) tmpbuf) != 1)
-       return (-1);
+       if (dev_desc->block_read(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
+               return -1;
        if(ppr->desctype!=0x01) {
                if(verb)
                        printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
@@ -84,8 +84,8 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
        PRINTF(" Lastsect:%08lx\n",lastsect);
        for(i=blkaddr;i<lastsect;i++) {
                PRINTF("Reading block %d\n", i);
-               if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *) tmpbuf) != 1)
-               return (-1);
+               if (dev_desc->block_read(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
+                       return -1;
                if(ppr->desctype==0x00)
                        break; /* boot entry found */
                if(ppr->desctype==0xff) {
@@ -104,7 +104,7 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
        }
        bootaddr=le32_to_int(pbr->pointer);
        PRINTF(" Boot Entry at: %08lX\n",bootaddr);
-       if (dev_desc->block_read (dev_desc->dev, bootaddr, 1, (ulong *) tmpbuf) != 1) {
+       if (dev_desc->block_read(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
                if(verb)
                        printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
                                bootaddr,dev_desc->dev, part_num);
index 099e0a0035be07303ac6b69a646ab59ba6260819..f3bc8dd55535b843850df201c534456a396a99a8 100644 (file)
@@ -51,7 +51,8 @@ int test_part_mac (block_dev_desc_t *dev_desc)
 
        n = 1;  /* assuming at least one partition */
        for (i=1; i<=n; ++i) {
-               if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)mpart) != 1) ||
+               if ((dev_desc->block_read(dev_desc, i, 1,
+                                         (ulong *)mpart) != 1) ||
                    (mpart->signature != MAC_PARTITION_MAGIC) ) {
                        return (-1);
                }
@@ -104,7 +105,7 @@ void print_part_mac (block_dev_desc_t *dev_desc)
                char c;
 
                printf ("%4ld: ", i);
-               if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *)mpart) != 1) {
+               if (dev_desc->block_read(dev_desc, i, 1, (ulong *)mpart) != 1) {
                        printf ("** Can't read Partition Map on %d:%ld **\n",
                                dev_desc->dev, i);
                        return;
@@ -150,7 +151,7 @@ void print_part_mac (block_dev_desc_t *dev_desc)
  */
 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p)
 {
-       if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)ddb_p) != 1) {
+       if (dev_desc->block_read(dev_desc, 0, 1, (ulong *)ddb_p) != 1) {
                printf ("** Can't read Driver Desriptor Block **\n");
                return (-1);
        }
@@ -178,7 +179,7 @@ static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partitio
                 * partition 1 first since this is the only way to
                 * know how many partitions we have.
                 */
-               if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) {
+               if (dev_desc->block_read(dev_desc, n, 1, (ulong *)pdb_p) != 1) {
                        printf ("** Can't read Partition Map on %d:%d **\n",
                                dev_desc->dev, n);
                        return (-1);
index 73f4c4a9e98c52141118791dbf786c8dbfff70c0..170f0fa5bf20bf3394c08c19f89eb75b4a5fc415 100644 (file)
@@ -22,9 +22,11 @@ static struct host_block_dev *find_host_device(int dev)
        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 @@ static unsigned long host_block_read(int dev, unsigned long start,
        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,
index fdf75b5abfc90ea2b9eb4d6afcc53d880ebd81c1..b974e80167e961dbf6934cdcd74c6a3588dd77c1 100644 (file)
@@ -69,8 +69,9 @@ static u16 ace_readw(unsigned off)
        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 @@ block_dev_desc_t *systemace_get_dev(int dev)
  * 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;
index 5a9fb4a6e24780ed3fda556ca522cd697d5f90dc..7ff2a810f303f9b3551934f3661a537730e30d88 100644 (file)
@@ -77,11 +77,11 @@ static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
              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:
index b1cb4b3534f8e68b2576d30cb5f021fde8a80133..301d9b3ab996b1eb3fd8e284aee5ec14d1c1d8ac 100644 (file)
@@ -38,7 +38,8 @@ void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
        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 @@ void __noreturn mmc_boot(void)
        /*
        * 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 @@ void __noreturn mmc_boot(void)
 #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");
index 3a34028c9177ef1d917910dfd61a7c4b14e12749..6d88db4bb6dd2fd3a29e7d7d78a5fc458d7ab31d 100644 (file)
@@ -234,8 +234,10 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
        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)
index 447a7001dbd986719aca1c39acbf0e5cd58dc80c..6a7063976ceaa01fe32418f50a60861a29b2d52d 100644 (file)
@@ -22,23 +22,24 @@ void mmc_adapter_card_type_ident(void);
 
 #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;
 }
index 221bf306cc5c6ec4d5d6c24d10d06f3a59432ad4..6733314942ea4fd4ad67d2b5643878dece2ba343 100644 (file)
@@ -65,8 +65,10 @@ err_out:
        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 @@ static ulong mmc_write_blocks(struct mmc *mmc, lbaint_t start,
        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);
index e717c44216297fba3583098fad6cb20da8c58d98..7b33094d8486d0650f6328039254eca258d20121 100644 (file)
@@ -454,7 +454,7 @@ int sunxi_mmc_has_egon_boot_signature(struct mmc *mmc)
                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;
 
index df5db723ba23ad47a5820858e7367fff91979c07..40fbf19c75729f9a3d8bd6192d0222c6f200fd3d 100644 (file)
@@ -395,7 +395,8 @@ int fm_init_common(int index, struct ccsr_fman *reg)
                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);
        }
index 3a2b3bba995282ebd8a96fb61d9ad742df5c246b..447ecfbeb6dfe9b378d3c7c5789f33a5518b38f9 100644 (file)
@@ -174,7 +174,8 @@ void cs4340_upload_firmware(struct phy_device *phydev)
                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);
        }
index 20f52566f09c03bfeaa869855aa81649e109dc2c..9fd10de0776b82028c8ccdc547a03e6188eb5812 100644 (file)
@@ -76,10 +76,10 @@ int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
        if (byte_offset != 0) {
                int readlen;
                /* read first part which isn't aligned with start of sector */
-               if (ext4fs_block_dev_desc->
-                   block_read(ext4fs_block_dev_desc->dev,
-                               part_info->start + sector, 1,
-                               (unsigned long *) sec_buf) != 1) {
+               if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
+                                                     part_info->start + sector,
+                                                     1, (void *)sec_buf)
+                   != 1) {
                        printf(" ** ext2fs_devread() read error **\n");
                        return 0;
                }
@@ -101,18 +101,18 @@ int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
                ALLOC_CACHE_ALIGN_BUFFER(u8, p, ext4fs_block_dev_desc->blksz);
 
                block_len = ext4fs_block_dev_desc->blksz;
-               ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
+               ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
                                                  part_info->start + sector,
-                                                 1, (unsigned long *)p);
+                                                 1, (void *)p);
                memcpy(buf, p, byte_len);
                return 1;
        }
 
-       if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
-                                              part_info->start + sector,
-                                              block_len >> log2blksz,
-                                              (unsigned long *) buf) !=
-                                              block_len >> log2blksz) {
+       if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
+                                             part_info->start + sector,
+                                             block_len >> log2blksz,
+                                             (void *)buf) !=
+                                             block_len >> log2blksz) {
                printf(" ** %s read error - block\n", __func__);
                return 0;
        }
@@ -123,10 +123,10 @@ int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
 
        if (byte_len != 0) {
                /* read rest of data which are not in whole sector */
-               if (ext4fs_block_dev_desc->
-                   block_read(ext4fs_block_dev_desc->dev,
-                               part_info->start + sector, 1,
-                               (unsigned long *) sec_buf) != 1) {
+               if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
+                                                     part_info->start + sector,
+                                                     1, (void *)sec_buf)
+                   != 1) {
                        printf("* %s read error - last part\n", __func__);
                        return 0;
                }
index e73223ac22c99a8687d065e5f91732f7f6deab98..55efa4dd761878253be4291c60327b0da0e1f6e0 100644 (file)
@@ -82,26 +82,26 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 
        if (remainder) {
                if (fs->dev_desc->block_read) {
-                       fs->dev_desc->block_read(fs->dev_desc->dev,
+                       fs->dev_desc->block_read(fs->dev_desc,
                                                 startblock, 1, sec_buf);
                        temp_ptr = sec_buf;
                        memcpy((temp_ptr + remainder),
                               (unsigned char *)buf, size);
-                       fs->dev_desc->block_write(fs->dev_desc->dev,
+                       fs->dev_desc->block_write(fs->dev_desc,
                                                  startblock, 1, sec_buf);
                }
        } else {
                if (size >> log2blksz != 0) {
-                       fs->dev_desc->block_write(fs->dev_desc->dev,
+                       fs->dev_desc->block_write(fs->dev_desc,
                                                  startblock,
                                                  size >> log2blksz,
                                                  (unsigned long *)buf);
                } else {
-                       fs->dev_desc->block_read(fs->dev_desc->dev,
+                       fs->dev_desc->block_read(fs->dev_desc,
                                                 startblock, 1, sec_buf);
                        temp_ptr = sec_buf;
                        memcpy(temp_ptr, buf, size);
-                       fs->dev_desc->block_write(fs->dev_desc->dev,
+                       fs->dev_desc->block_write(fs->dev_desc,
                                                  startblock, 1,
                                                  (unsigned long *)sec_buf);
                }
index f939bc5deed2770e84c98dcfd4bc8fe056070655..472a63e8bb0af7fb47f9467b40a781d1744a1ecd 100644 (file)
@@ -51,8 +51,8 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
        if (!cur_dev || !cur_dev->block_read)
                return -1;
 
-       ret = cur_dev->block_read(cur_dev->dev,
-                                 cur_part_info.start + block, nr_blocks, buf);
+       ret = cur_dev->block_read(cur_dev, cur_part_info.start + block,
+                                 nr_blocks, buf);
 
        if (nr_blocks && ret == 0)
                return -1;
index af828d07bd0a7377b3a783550756ff9242e1a08a..5ed324ce1a022241a9a43c1a257f7f6ab11279d3 100644 (file)
@@ -41,8 +41,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
                return -1;
        }
 
-       ret = cur_dev->block_write(cur_dev->dev,
-                                  cur_part_info.start + block,
+       ret = cur_dev->block_write(cur_dev, cur_part_info.start + block,
                                   nr_blocks, buf);
        if (nr_blocks && ret == 0)
                return -1;
index 68255458d5101a9cd302563bd6b97352d8aa2ea2..7b24d6aa715c275b107b2c54eb5318fcd45aa517 100644 (file)
@@ -59,9 +59,11 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
 
        if (byte_offset != 0) {
                /* read first part which isn't aligned with start of sector */
-               if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
-                   part_info->start + sector, 1,
-                   (unsigned long *)sec_buf) != 1) {
+               if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc,
+                                                       part_info->start +
+                                                               sector,
+                                                       1, (void *)sec_buf)
+                   != 1) {
                        printf (" ** reiserfs_devread() read error\n");
                        return 0;
                }
@@ -73,9 +75,11 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
 
        /* read sector aligned part */
        block_len = byte_len & ~(SECTOR_SIZE-1);
-       if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
-           part_info->start + sector, block_len/SECTOR_SIZE,
-           (unsigned long *)buf) != block_len/SECTOR_SIZE) {
+       if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc,
+                                               part_info->start + sector,
+                                               block_len / SECTOR_SIZE,
+                                               (void *)buf)
+           != block_len/SECTOR_SIZE) {
                printf (" ** reiserfs_devread() read error - block\n");
                return 0;
        }
@@ -85,9 +89,11 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
 
        if ( byte_len != 0 ) {
                /* read rest of data which are not in whole sector */
-               if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
-                   part_info->start + sector, 1,
-                   (unsigned long *)sec_buf) != 1) {
+               if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc,
+                                                       part_info->start +
+                                                           sector,
+                                                       1, (void *)sec_buf)
+                   != 1) {
                        printf (" ** reiserfs_devread() read error - last part\n");
                        return 0;
                }
index 3a1fa5685afe0540b9e111971c4285d12389cda1..67d12652b01e27a5f94b3fc4f62a079baf0e61c1 100644 (file)
@@ -55,9 +55,10 @@ int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
 
        if (byte_offset != 0) {
                /* read first part which isn't aligned with start of sector */
-               if (zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
-                       part_info->start + sector, 1,
-                       (unsigned long *)sec_buf) != 1) {
+               if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
+                                                  part_info->start + sector, 1,
+                                                  (void *)sec_buf)
+                   != 1) {
                        printf(" ** zfs_devread() read error **\n");
                        return 1;
                }
@@ -78,16 +79,18 @@ int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
                u8 p[SECTOR_SIZE];
 
                block_len = SECTOR_SIZE;
-               zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
-                       part_info->start + sector,
-                       1, (unsigned long *)p);
+               zfs_block_dev_desc->block_read(zfs_block_dev_desc,
+                                              part_info->start + sector,
+                                              1, (void *)p);
                memcpy(buf, p, byte_len);
                return 0;
        }
 
-       if (zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
-               part_info->start + sector, block_len / SECTOR_SIZE,
-               (unsigned long *) buf) != block_len / SECTOR_SIZE) {
+       if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
+                                          part_info->start + sector,
+                                          block_len / SECTOR_SIZE,
+                                          (void *)buf)
+           != block_len / SECTOR_SIZE) {
                printf(" ** zfs_devread() read error - block\n");
                return 1;
        }
@@ -99,10 +102,9 @@ int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
 
        if (byte_len != 0) {
                /* read rest of data which are not in whole sector */
-               if (zfs_block_dev_desc->
-                       block_read(zfs_block_dev_desc->dev,
-                                          part_info->start + sector, 1,
-                                          (unsigned long *) sec_buf) != 1) {
+               if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
+                                                  part_info->start + sector,
+                                                  1, (void *)sec_buf) != 1) {
                        printf(" ** zfs_devread() read error - last part\n");
                        return 1;
                }
index f9b43cb23a657828e281646e6c09dc5ebc82373a..f9357bee76220d9066ace1f697040e43da810e51 100644 (file)
@@ -41,8 +41,10 @@ typedef ulong lbaint_t;
  */
 
 void ide_init(void);
-ulong ide_read(int device, lbaint_t blknr, lbaint_t blkcnt, void *buffer);
-ulong ide_write(int device, lbaint_t blknr, lbaint_t blkcnt,
+typedef struct block_dev_desc block_dev_desc_t;
+ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+              void *buffer);
+ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
                const void *buffer);
 
 #ifdef CONFIG_IDE_PREINIT
index 720a867783c41f89b9d1fa6d22cdca56ac9d1c1c..8396ed178eead1f367ccfae281d2d015257b2b24 100644 (file)
@@ -10,7 +10,9 @@
 #include <ide.h>
 #include <common.h>
 
-typedef struct block_dev_desc {
+typedef struct block_dev_desc block_dev_desc_t;
+
+struct block_dev_desc {
        int             if_type;        /* type of the interface */
        int             dev;            /* device number */
        unsigned char   part_type;      /* partition type */
@@ -27,19 +29,19 @@ typedef struct block_dev_desc {
        char            vendor [40+1];  /* IDE model, SCSI Vendor */
        char            product[20+1];  /* IDE Serial no, SCSI product */
        char            revision[8+1];  /* firmware revision */
-       unsigned long   (*block_read)(int dev,
+       unsigned long   (*block_read)(block_dev_desc_t *block_dev,
                                      lbaint_t start,
                                      lbaint_t blkcnt,
                                      void *buffer);
-       unsigned long   (*block_write)(int dev,
+       unsigned long   (*block_write)(block_dev_desc_t *block_dev,
                                       lbaint_t start,
                                       lbaint_t blkcnt,
                                       const void *buffer);
-       unsigned long   (*block_erase)(int dev,
+       unsigned long   (*block_erase)(block_dev_desc_t *block_dev,
                                       lbaint_t start,
                                       lbaint_t blkcnt);
        void            *priv;          /* driver private struct pointer */
-}block_dev_desc_t;
+};
 
 #define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
 #define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
index bdd85c4c17526eadc9d8303225f3629779763f4b..d86aa87f688477219a16550f69ba6c3cdb1cebba 100644 (file)
@@ -231,8 +231,7 @@ int gzwrite(unsigned char *src, int len,
                        gzwrite_progress(iteration++,
                                         totalfilled,
                                         szexpected);
-                       blocks_written = dev->block_write(dev->dev,
-                                                         outblock,
+                       blocks_written = dev->block_write(dev, outblock,
                                                          writeblocks,
                                                          writebuf);
                        outblock += blocks_written;
index cbc7899ff971ef78770039a80db62c4ae23cf654..3a2e52b2b57d32f5142f8e261d7f0df83f00bca6 100644 (file)
@@ -50,7 +50,7 @@ static int dm_test_usb_flash(struct unit_test_state *uts)
        /* Read a few blocks and look for the string we expect */
        ut_asserteq(512, dev_desc->blksz);
        memset(cmp, '\0', sizeof(cmp));
-       ut_asserteq(2, dev_desc->block_read(dev_desc->dev, 0, 2, cmp));
+       ut_asserteq(2, dev_desc->block_read(dev_desc, 0, 2, cmp));
        ut_assertok(strcmp(cmp, "this is a test"));
 
        return 0;