ide: collapse parameters to ide_init_drive

All calls to ide_init_drive comes from ide_dev_initfn.  Just pass down the
IDEDevice (IDEState is kinda obsolete and should be merged into IDEDevice).

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2024-02-20 17:05:20 +01:00
parent b5a9de3259
commit dcaff46101
3 changed files with 20 additions and 31 deletions

View File

@ -2589,24 +2589,20 @@ static const BlockDevOps ide_hd_block_ops = {
.resize_cb = ide_resize_cb,
};
int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
const char *version, const char *serial, const char *model,
uint64_t wwn,
uint32_t cylinders, uint32_t heads, uint32_t secs,
int chs_trans, Error **errp)
int ide_init_drive(IDEState *s, IDEDevice *dev, IDEDriveKind kind, Error **errp)
{
uint64_t nb_sectors;
s->blk = blk;
s->blk = dev->conf.blk;
s->drive_kind = kind;
blk_get_geometry(blk, &nb_sectors);
s->cylinders = cylinders;
s->heads = s->drive_heads = heads;
s->sectors = s->drive_sectors = secs;
s->chs_trans = chs_trans;
blk_get_geometry(s->blk, &nb_sectors);
s->cylinders = dev->conf.cyls;
s->heads = s->drive_heads = dev->conf.heads;
s->sectors = s->drive_sectors = dev->conf.secs;
s->chs_trans = dev->chs_trans;
s->nb_sectors = nb_sectors;
s->wwn = wwn;
s->wwn = dev->wwn;
/* The SMART values should be preserved across power cycles
but they aren't. */
s->smart_enabled = 1;
@ -2614,26 +2610,26 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
s->smart_errors = 0;
s->smart_selftest_count = 0;
if (kind == IDE_CD) {
blk_set_dev_ops(blk, &ide_cd_block_ops, s);
blk_set_dev_ops(s->blk, &ide_cd_block_ops, s);
} else {
if (!blk_is_inserted(s->blk)) {
error_setg(errp, "Device needs media, but drive is empty");
return -1;
}
if (!blk_is_writable(blk)) {
if (!blk_is_writable(s->blk)) {
error_setg(errp, "Can't use a read-only drive");
return -1;
}
blk_set_dev_ops(blk, &ide_hd_block_ops, s);
blk_set_dev_ops(s->blk, &ide_hd_block_ops, s);
}
if (serial) {
pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial);
if (dev->serial) {
pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), dev->serial);
} else {
snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
"QM%05d", s->drive_serial);
}
if (model) {
pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), model);
if (dev->model) {
pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), dev->model);
} else {
switch (kind) {
case IDE_CD:
@ -2648,14 +2644,14 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
}
}
if (version) {
pstrcpy(s->version, sizeof(s->version), version);
if (dev->version) {
pstrcpy(s->version, sizeof(s->version), dev->version);
} else {
pstrcpy(s->version, sizeof(s->version), qemu_hw_version());
}
ide_reset(s);
blk_iostatus_enable(blk);
blk_iostatus_enable(s->blk);
return 0;
}

View File

@ -118,10 +118,7 @@ void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
return;
}
if (ide_init_drive(s, dev->conf.blk, kind,
dev->version, dev->serial, dev->model, dev->wwn,
dev->conf.cyls, dev->conf.heads, dev->conf.secs,
dev->chs_trans, errp) < 0) {
if (ide_init_drive(s, dev, kind, errp) < 0) {
return;
}

View File

@ -416,11 +416,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
uint32_t ide_data_readl(void *opaque, uint32_t addr);
int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
const char *version, const char *serial, const char *model,
uint64_t wwn,
uint32_t cylinders, uint32_t heads, uint32_t secs,
int chs_trans, Error **errp);
int ide_init_drive(IDEState *s, IDEDevice *dev, IDEDriveKind kind, Error **errp);
void ide_exit(IDEState *s);
void ide_bus_init_output_irq(IDEBus *bus, qemu_irq irq_out);
int ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);