From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 3/8] split away drive init from ide_init2()
Date: Fri, 11 Sep 2009 14:32:26 +0200 [thread overview]
Message-ID: <1252672351-12937-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1252672351-12937-1-git-send-email-kraxel@redhat.com>
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>
---
hw/ide/core.c | 71 +++++++++++++++++++++++++++++------------------------
hw/ide/internal.h | 1 +
2 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index fe5bd17..bac2d5e 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2505,51 +2505,58 @@ void ide_reset(IDEState *s)
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,
qemu_irq irq)
{
IDEState *s;
static int drive_serial = 1;
- int i, cylinders, heads, secs;
- uint64_t nb_sectors;
+ int i;
for(i = 0; i < 2; i++) {
s = bus->ifs + i;
s->bus = bus;
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++;
- 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);
+ s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
+ s->smart_selftest_data = qemu_blockalign(s->bs, 512);
s->sector_write_timer = qemu_new_timer(vm_clock,
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;
}
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index b9a7c72..62aef1c 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -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);
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,
qemu_irq irq);
void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
--
1.6.2.5
next prev parent reply other threads:[~2009-09-11 12:33 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-11 12:32 [Qemu-devel] [PATCH 0/8] ide: convert to qdev Gerd Hoffmann
2009-09-11 12:32 ` [Qemu-devel] [PATCH 1/8] qdev/pci: add pci_create_noinit() Gerd Hoffmann
2009-09-11 14:14 ` Markus Armbruster
2009-09-11 14:28 ` Gerd Hoffmann
2009-09-11 14:57 ` Markus Armbruster
2009-09-11 12:32 ` [Qemu-devel] [PATCH 2/8] support media=cdrom for if=none Gerd Hoffmann
2009-09-11 12:32 ` Gerd Hoffmann [this message]
2009-09-11 14:27 ` [Qemu-devel] [PATCH 3/8] split away drive init from ide_init2() Markus Armbruster
2009-09-11 14:36 ` Gerd Hoffmann
2009-09-11 12:32 ` [Qemu-devel] [PATCH 4/8] ide/qdev: add ide bus Gerd Hoffmann
[not found] ` <m3fxat8u80.fsf@neno.mitica>
2009-09-11 14:10 ` [Qemu-devel] " Gerd Hoffmann
2009-09-11 14:54 ` [Qemu-devel] " Markus Armbruster
2009-09-11 15:01 ` Gerd Hoffmann
2009-09-11 12:32 ` [Qemu-devel] [PATCH 5/8] ide/pci: convert to qdev Gerd Hoffmann
[not found] ` <m3bplh8u13.fsf@neno.mitica>
2009-09-11 14:13 ` [Qemu-devel] " Gerd Hoffmann
[not found] ` <m3my517dni.fsf@neno.mitica>
2009-09-11 14:58 ` Gerd Hoffmann
[not found] ` <m3y6ol5x64.fsf@neno.mitica>
2009-09-11 19:16 ` Gerd Hoffmann
[not found] ` <m3bplh2js1.fsf@neno.mitica>
2009-09-14 7:09 ` Gerd Hoffmann
2009-09-11 15:21 ` [Qemu-devel] " Markus Armbruster
2009-09-14 6:44 ` Gerd Hoffmann
2009-09-11 12:32 ` [Qemu-devel] [PATCH 6/8] ide/isa: " Gerd Hoffmann
2009-09-11 12:32 ` [Qemu-devel] [PATCH 7/8] isa: refine irq reservations Gerd Hoffmann
2009-09-11 12:32 ` [Qemu-devel] [PATCH 8/8] unbreak ppc/prep Gerd Hoffmann
2009-09-11 14:31 ` [Qemu-devel] Re: [PATCH 0/8] ide: convert to qdev Juan Quintela
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1252672351-12937-4-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).