split away drive init from ide_init2()
This allows the ide bus being initialized without drives attached and the drives being attached and initialization later on as separate step. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
parent
c219331eb0
commit
88804180fd
|
@ -2518,51 +2518,58 @@ void ide_reset(IDEState *s)
|
||||||
s->media_changed = 0;
|
s->media_changed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ide_init_drive(IDEState *s, DriveInfo *dinfo)
|
||||||
|
{
|
||||||
|
int cylinders, heads, secs;
|
||||||
|
uint64_t nb_sectors;
|
||||||
|
|
||||||
|
if (dinfo && dinfo->bdrv) {
|
||||||
|
s->bs = dinfo->bdrv;
|
||||||
|
bdrv_get_geometry(s->bs, &nb_sectors);
|
||||||
|
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
|
||||||
|
s->cylinders = cylinders;
|
||||||
|
s->heads = heads;
|
||||||
|
s->sectors = secs;
|
||||||
|
s->nb_sectors = nb_sectors;
|
||||||
|
/* 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 (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
|
||||||
|
s->is_cdrom = 1;
|
||||||
|
bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
|
||||||
|
}
|
||||||
|
strncpy(s->drive_serial_str, drive_get_serial(s->bs),
|
||||||
|
sizeof(s->drive_serial_str));
|
||||||
|
}
|
||||||
|
if (strlen(s->drive_serial_str) == 0)
|
||||||
|
snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
|
||||||
|
"QM%05d", s->drive_serial);
|
||||||
|
ide_reset(s);
|
||||||
|
}
|
||||||
|
|
||||||
void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
|
void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
|
||||||
qemu_irq irq)
|
qemu_irq irq)
|
||||||
{
|
{
|
||||||
IDEState *s;
|
IDEState *s;
|
||||||
static int drive_serial = 1;
|
static int drive_serial = 1;
|
||||||
int i, cylinders, heads, secs;
|
int i;
|
||||||
uint64_t nb_sectors;
|
|
||||||
|
|
||||||
for(i = 0; i < 2; i++) {
|
for(i = 0; i < 2; i++) {
|
||||||
s = bus->ifs + i;
|
s = bus->ifs + i;
|
||||||
s->bus = bus;
|
s->bus = bus;
|
||||||
s->unit = i;
|
s->unit = i;
|
||||||
if (i == 0 && hd0)
|
|
||||||
s->bs = hd0->bdrv;
|
|
||||||
if (i == 1 && hd1)
|
|
||||||
s->bs = hd1->bdrv;
|
|
||||||
s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
|
|
||||||
if (s->bs) {
|
|
||||||
bdrv_get_geometry(s->bs, &nb_sectors);
|
|
||||||
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
|
|
||||||
s->cylinders = cylinders;
|
|
||||||
s->heads = heads;
|
|
||||||
s->sectors = secs;
|
|
||||||
s->nb_sectors = nb_sectors;
|
|
||||||
/* 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;
|
|
||||||
s->smart_selftest_data = qemu_blockalign(s->bs, 512);
|
|
||||||
if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
|
|
||||||
s->is_cdrom = 1;
|
|
||||||
bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s->drive_serial = drive_serial++;
|
s->drive_serial = drive_serial++;
|
||||||
strncpy(s->drive_serial_str, drive_get_serial(s->bs),
|
s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
|
||||||
sizeof(s->drive_serial_str));
|
s->smart_selftest_data = qemu_blockalign(s->bs, 512);
|
||||||
if (strlen(s->drive_serial_str) == 0)
|
|
||||||
snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
|
|
||||||
"QM%05d", s->drive_serial);
|
|
||||||
s->sector_write_timer = qemu_new_timer(vm_clock,
|
s->sector_write_timer = qemu_new_timer(vm_clock,
|
||||||
ide_sector_write_timer_cb, s);
|
ide_sector_write_timer_cb, s);
|
||||||
ide_reset(s);
|
if (i == 0)
|
||||||
|
ide_init_drive(s, hd0);
|
||||||
|
if (i == 1)
|
||||||
|
ide_init_drive(s, hd1);
|
||||||
}
|
}
|
||||||
bus->irq = irq;
|
bus->irq = irq;
|
||||||
}
|
}
|
||||||
|
|
|
@ -527,6 +527,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
|
||||||
void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
|
void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
|
||||||
uint32_t ide_data_readl(void *opaque, uint32_t addr);
|
uint32_t ide_data_readl(void *opaque, uint32_t addr);
|
||||||
|
|
||||||
|
void ide_init_drive(IDEState *s, DriveInfo *dinfo);
|
||||||
void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
|
void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
|
||||||
qemu_irq irq);
|
qemu_irq irq);
|
||||||
void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
|
void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
|
||||||
|
|
Loading…
Reference in a new issue