Skip to content

Commit

Permalink
ide: collapse parameters to ide_init_drive
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bonzini committed Feb 27, 2024
1 parent b5a9de3 commit dcaff46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
40 changes: 18 additions & 22 deletions hw/ide/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2589,51 +2589,47 @@ 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;
s->smart_autosave = 1;
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:
Expand All @@ -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;
}

Expand Down
5 changes: 1 addition & 4 deletions hw/ide/ide-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions hw/ide/ide-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dcaff46

Please sign in to comment.