From patchwork Fri Sep 11 12:32:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 33458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 510EAB7067 for ; Fri, 11 Sep 2009 23:14:04 +1000 (EST) Received: from localhost ([127.0.0.1]:59410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm5wv-0000ZT-DA for incoming@patchwork.ozlabs.org; Fri, 11 Sep 2009 09:14:01 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mm5JH-0004EQ-Ui for qemu-devel@nongnu.org; Fri, 11 Sep 2009 08:33:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mm5JC-00046o-Bk for qemu-devel@nongnu.org; Fri, 11 Sep 2009 08:33:03 -0400 Received: from [199.232.76.173] (port=49292 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm5JB-00046O-W3 for qemu-devel@nongnu.org; Fri, 11 Sep 2009 08:32:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20704) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mm5JB-00046B-FJ for qemu-devel@nongnu.org; Fri, 11 Sep 2009 08:32:57 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8BCWuLV026292 for ; Fri, 11 Sep 2009 08:32:56 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-42.ams2.redhat.com [10.36.5.42]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n8BCWlGE009982; Fri, 11 Sep 2009 08:32:50 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 67198700DD; Fri, 11 Sep 2009 14:32:32 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 11 Sep 2009 14:32:26 +0200 Message-Id: <1252672351-12937-4-git-send-email-kraxel@redhat.com> In-Reply-To: <1252672351-12937-1-git-send-email-kraxel@redhat.com> References: <1252672351-12937-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 3/8] split away drive init from ide_init2() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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);