]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
part/dev_desc: Add log2 of blocksize to block_dev_desc data struct
authorEgbert Eich <eich@suse.com>
Tue, 9 Apr 2013 21:11:56 +0000 (21:11 +0000)
committerTom Rini <trini@ti.com>
Wed, 1 May 2013 20:24:02 +0000 (16:24 -0400)
log2 of the device block size serves as the shift value used to calculate
the block number to read in file systems when implementing avaiable block
sizes.
It is needed quite often in file systems thus it is pre-calculated and
stored in the block device descriptor.

Signed-off-by: Egbert Eich <eich@suse.com>
common/cmd_ide.c
common/cmd_sata.c
common/cmd_scsi.c
common/usb_storage.c
drivers/block/ata_piix.c
drivers/block/pata_bfin.c
drivers/block/systemace.c
drivers/mmc/mmc.c
include/part.h

index 0105bdbb7f98cd48bcdd6d8973027bc75b125311..78b4aa70ba7d05da59b0b1f14381a3102d6f4cf1 100644 (file)
@@ -455,6 +455,8 @@ void ide_init(void)
                ide_dev_desc[i].dev = i;
                ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
                ide_dev_desc[i].blksz = 0;
+               ide_dev_desc[i].log2blksz =
+                       LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
                ide_dev_desc[i].lba = 0;
                ide_dev_desc[i].block_read = ide_read;
                ide_dev_desc[i].block_write = ide_write;
@@ -806,6 +808,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
        /* assuming HD */
        dev_desc->type = DEV_TYPE_HARDDISK;
        dev_desc->blksz = ATA_BLOCKSIZE;
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
        dev_desc->lun = 0;      /* just to fill something in... */
 
 #if 0                          /* only used to test the powersaving mode,
@@ -1448,6 +1451,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
        dev_desc->lun = 0;
        dev_desc->lba = 0;
        dev_desc->blksz = 0;
+       dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
        dev_desc->type = iobuf[0] & 0x1f;
 
        if ((iobuf[1] & 0x80) == 0x80)
@@ -1492,6 +1496,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
        dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
                ((unsigned long) iobuf[5] << 16) +
                ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
 #ifdef CONFIG_LBA48
        /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
        dev_desc->lba48 = 0;
index 8d57285d053d27489080f4e7c4e74f659d92f26a..5a57a379443b42829f8d83295bc1a321f33263b1 100644 (file)
@@ -44,6 +44,7 @@ int __sata_initialize(void)
                sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
                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;
 
index 13b3d996f649b2b443fddcf6b5c531527d2e5ed2..294d9f577e3e6bd3cc7c3212273c6e83a5ec1b68 100644 (file)
@@ -106,6 +106,8 @@ void scsi_scan(int mode)
                scsi_dev_desc[i].lun=0xff;
                scsi_dev_desc[i].lba=0;
                scsi_dev_desc[i].blksz=0;
+               scsi_dev_desc[i].log2blksz =
+                       LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz));
                scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN;
                scsi_dev_desc[i].vendor[0]=0;
                scsi_dev_desc[i].product[0]=0;
@@ -166,6 +168,8 @@ void scsi_scan(int mode)
                        }
                        scsi_dev_desc[scsi_max_devs].lba=capacity;
                        scsi_dev_desc[scsi_max_devs].blksz=blksz;
+                       scsi_dev_desc[scsi_max_devs].log2blksz =
+                               LOG2(scsi_dev_desc[scsi_max_devs].blksz);
                        scsi_dev_desc[scsi_max_devs].type=perq;
                        init_part(&scsi_dev_desc[scsi_max_devs]);
 removable:
index fb322b4015fe0ba2ea72d82a1f7171ae7bfee2e3..c5db044165c0a452f62245e9a0fd644a1f1ea631 100644 (file)
@@ -1430,6 +1430,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
                        *capacity, *blksz);
        dev_desc->lba = *capacity;
        dev_desc->blksz = *blksz;
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
        dev_desc->type = perq;
        USB_STOR_PRINTF(" address %d\n", dev_desc->target);
        USB_STOR_PRINTF("partype: %d\n", dev_desc->part_type);
index 1e33a66c45078acc66640346d17323babd2e2579..fcae44850837b0e9a2c3a65f860a862ea0605bee 100644 (file)
@@ -406,6 +406,7 @@ void sata_identify(int num, int dev)
        /* assuming HD */
        sata_dev_desc[devno].type = DEV_TYPE_HARDDISK;
        sata_dev_desc[devno].blksz = ATA_BLOCKSIZE;
+       sata_dev_desc[devno].log2blksz = LOG2(sata_dev_desc[devno].blksz);
        sata_dev_desc[devno].lun = 0;   /* just to fill something in... */
 }
 
index b847dd91e73b474d65f428cc0763c8a1939eb287..27ecaf4f9edad9b87b69e2ad990e2ef2cf014592 100644 (file)
@@ -897,6 +897,8 @@ static void bfin_ata_identify(struct ata_port *ap, int dev)
        /* assuming HD */
        sata_dev_desc[ap->port_no].type = DEV_TYPE_HARDDISK;
        sata_dev_desc[ap->port_no].blksz = ATA_SECT_SIZE;
+       sata_dev_desc[ap->port_no].log2blksz =
+               LOG2(sata_dev_desc[ap->port_no].blksz);
        sata_dev_desc[ap->port_no].lun = 0;     /* just to fill something in... */
 
        printf("PATA device#%d %s is found on ata port#%d.\n",
index bf29cbbb7a838b4db49b323a9db06942a07fc1ea..b08715f7c47efa8e91b44a1a33eddfe5bd36e46d 100644 (file)
@@ -127,6 +127,7 @@ block_dev_desc_t *systemace_get_dev(int dev)
                systemace_dev.part_type = PART_TYPE_UNKNOWN;
                systemace_dev.type = DEV_TYPE_HARDDISK;
                systemace_dev.blksz = 512;
+               systemace_dev.log2blksz = LOG2(systemace_dev.blksz);
                systemace_dev.removable = 1;
                systemace_dev.block_read = systemace_read;
 
index 23aeec19239052e835fa1535b22de50693308e61..2590f1bcce5e1fa223732e15c33cdd980ff0e725 100644 (file)
@@ -1203,6 +1203,7 @@ static int mmc_startup(struct mmc *mmc)
        mmc->block_dev.lun = 0;
        mmc->block_dev.type = 0;
        mmc->block_dev.blksz = mmc->read_bl_len;
+       mmc->block_dev.log2blksz = LOG2(mmc->block_dev.blksz);
        mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
        sprintf(mmc->block_dev.vendor, "Man %06x Snr %04x%04x",
                mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff),
index 12e9b056e46eec20c86e4b50f3e093f6657b029f..f7c7cc59fca2dccb41635e1f28666aed60234449 100644 (file)
@@ -38,6 +38,7 @@ typedef struct block_dev_desc {
 #endif
        lbaint_t        lba;            /* number of blocks */
        unsigned long   blksz;          /* block size */
+       int             log2blksz;      /* for convenience: log2(blksz) */
        char            vendor [40+1];  /* IDE model, SCSI Vendor */
        char            product[20+1];  /* IDE Serial no, SCSI product */
        char            revision[8+1];  /* firmware revision */
@@ -58,6 +59,10 @@ typedef struct block_dev_desc {
 #define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
 #define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
        (PAD_SIZE(size, block_dev_desc->blksz))
+#define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
+                ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
+                ((x & 0xffff0000) ? 16 : 0))
+#define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
 
 /* Interface types: */
 #define IF_TYPE_UNKNOWN                0