Message ID | 20230328080702.10.Ia41ab329f6a5b52b15e58c5f405ce07c5b5545d1@changeid |
---|---|
State | Changes Requested |
Delegated to: | Tom Rini |
Headers | show |
Series | ide: Clean up code and fix a few bugs | expand |
On mar., mars 28, 2023 at 08:06, Simon Glass <sjg@chromium.org> wrote: > The use of atapi_read() was incorrect dropped. Fix this so that it will > be used when needed. Use a udevice for the first argument of atapi_read() > so it is consistent with ide_read(). > > This requires much of the ATAPI code to be brought out from behind the > existing #ifdef. It will still be removed by the compiler if it is not > needed. > > Add an atapi flag to struct blk_desc so the information can be retained. > > Fixes: 145df842b44 ("dm: ide: Add support for driver-model block devices") > Fixes: d0075059e4d ("ide: Drop non-DM code for BLK") > > Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> > --- > > drivers/block/ide.c | 20 +++++++++++++++++--- > include/blk.h | 1 + > 2 files changed, 18 insertions(+), 3 deletions(-) > > diff --git a/drivers/block/ide.c b/drivers/block/ide.c > index fa5f68ffeb01..875192cba163 100644 > --- a/drivers/block/ide.c > +++ b/drivers/block/ide.c > @@ -155,7 +155,6 @@ OUT: > *last = '\0'; > } > > -#ifdef CONFIG_ATAPI > /**************************************************************************** > * ATAPI Support > */ > @@ -422,9 +421,10 @@ error: > #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(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, > +ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, > void *buffer) > { > + struct blk_desc *block_dev = dev_get_uclass_plat(dev); > int device = block_dev->devnum; > ulong n = 0; > unsigned char ccb[12]; /* Command descriptor block */ > @@ -466,6 +466,8 @@ ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, > return n; > } > > +#ifdef CONFIG_ATAPI > + > static void atapi_inquiry(struct blk_desc *dev_desc) > { > unsigned char ccb[12]; /* Command descriptor block */ > @@ -653,6 +655,7 @@ static void ide_ident(struct blk_desc *dev_desc) > > #ifdef CONFIG_ATAPI > if (is_atapi) { > + dev_desc->atapi = true; > atapi_inquiry(dev_desc); > return; > } > @@ -1010,6 +1013,17 @@ WR_OUT: > return n; > } > > +ulong ide_or_atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, > + void *buffer) > +{ > + struct blk_desc *desc = dev_get_uclass_plat(dev); > + > + if (IS_ENABLED(CONFIG_ATAPI) && desc->atapi) > + return atapi_read(dev, blknr, blkcnt, buffer); > + > + return ide_read(dev, blknr, blkcnt, buffer); > +} > + > static int ide_blk_probe(struct udevice *udev) > { > struct blk_desc *desc = dev_get_uclass_plat(udev); > @@ -1029,7 +1043,7 @@ static int ide_blk_probe(struct udevice *udev) > } > > static const struct blk_ops ide_blk_ops = { > - .read = ide_read, > + .read = ide_or_atapi_read, > .write = ide_write, > }; > > diff --git a/include/blk.h b/include/blk.h > index 1db203c1baba..871922dcde07 100644 > --- a/include/blk.h > +++ b/include/blk.h > @@ -66,6 +66,7 @@ struct blk_desc { > /* device can use 48bit addr (ATA/ATAPI v7) */ > unsigned char lba48; > #endif > + unsigned char atapi; /* Use ATAPI protocol */ > lbaint_t lba; /* number of blocks */ > unsigned long blksz; /* block size */ > int log2blksz; /* for convenience: log2(blksz) */ > -- > 2.40.0.348.gf938b09366-goog
diff --git a/drivers/block/ide.c b/drivers/block/ide.c index fa5f68ffeb01..875192cba163 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -155,7 +155,6 @@ OUT: *last = '\0'; } -#ifdef CONFIG_ATAPI /**************************************************************************** * ATAPI Support */ @@ -422,9 +421,10 @@ error: #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(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, +ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer) { + struct blk_desc *block_dev = dev_get_uclass_plat(dev); int device = block_dev->devnum; ulong n = 0; unsigned char ccb[12]; /* Command descriptor block */ @@ -466,6 +466,8 @@ ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, return n; } +#ifdef CONFIG_ATAPI + static void atapi_inquiry(struct blk_desc *dev_desc) { unsigned char ccb[12]; /* Command descriptor block */ @@ -653,6 +655,7 @@ static void ide_ident(struct blk_desc *dev_desc) #ifdef CONFIG_ATAPI if (is_atapi) { + dev_desc->atapi = true; atapi_inquiry(dev_desc); return; } @@ -1010,6 +1013,17 @@ WR_OUT: return n; } +ulong ide_or_atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + void *buffer) +{ + struct blk_desc *desc = dev_get_uclass_plat(dev); + + if (IS_ENABLED(CONFIG_ATAPI) && desc->atapi) + return atapi_read(dev, blknr, blkcnt, buffer); + + return ide_read(dev, blknr, blkcnt, buffer); +} + static int ide_blk_probe(struct udevice *udev) { struct blk_desc *desc = dev_get_uclass_plat(udev); @@ -1029,7 +1043,7 @@ static int ide_blk_probe(struct udevice *udev) } static const struct blk_ops ide_blk_ops = { - .read = ide_read, + .read = ide_or_atapi_read, .write = ide_write, }; diff --git a/include/blk.h b/include/blk.h index 1db203c1baba..871922dcde07 100644 --- a/include/blk.h +++ b/include/blk.h @@ -66,6 +66,7 @@ struct blk_desc { /* device can use 48bit addr (ATA/ATAPI v7) */ unsigned char lba48; #endif + unsigned char atapi; /* Use ATAPI protocol */ lbaint_t lba; /* number of blocks */ unsigned long blksz; /* block size */ int log2blksz; /* for convenience: log2(blksz) */
The use of atapi_read() was incorrect dropped. Fix this so that it will be used when needed. Use a udevice for the first argument of atapi_read() so it is consistent with ide_read(). This requires much of the ATAPI code to be brought out from behind the existing #ifdef. It will still be removed by the compiler if it is not needed. Add an atapi flag to struct blk_desc so the information can be retained. Fixes: 145df842b44 ("dm: ide: Add support for driver-model block devices") Fixes: d0075059e4d ("ide: Drop non-DM code for BLK") Signed-off-by: Simon Glass <sjg@chromium.org> --- drivers/block/ide.c | 20 +++++++++++++++++--- include/blk.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-)