From patchwork Tue Jul 17 16:00:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 171506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 607F82C008E for ; Wed, 18 Jul 2012 03:26:33 +1000 (EST) Received: from localhost ([::1]:52157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrAED-00087F-CT for incoming@patchwork.ozlabs.org; Tue, 17 Jul 2012 12:02:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrAD2-0007Gj-Ax for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrACw-0005ov-1F for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrACv-0005ob-QG for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:05 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6HG14bB022953 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Jul 2012 12:01:04 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-6-35.ams2.redhat.com [10.36.6.35]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6HG0dqh007516; Tue, 17 Jul 2012 12:01:03 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 17 Jul 2012 18:00:11 +0200 Message-Id: <1342540838-9027-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1342540838-9027-1-git-send-email-kwolf@redhat.com> References: <1342540838-9027-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 14/41] ide pc: Cut out the block layer geometry middleman X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster PC BIOS setup needs IDE geometry information. Get it directly from the device model rather than through the block layer. In preparation of purging geometry from the block layer, which will happen later in this series. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/ide.h | 4 +++- hw/ide/core.c | 2 +- hw/ide/internal.h | 2 +- hw/ide/qdev.c | 21 +++++++++++++++++---- hw/pc.c | 51 +++++++++++++++++++++++++++------------------------ 5 files changed, 49 insertions(+), 31 deletions(-) diff --git a/hw/ide.h b/hw/ide.h index 0b18c90..2db4079 100644 --- a/hw/ide.h +++ b/hw/ide.h @@ -29,7 +29,9 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2, qemu_irq irq, int shift, DriveInfo *hd0, DriveInfo *hd1); -void ide_get_bs(BlockDriverState *bs[], BusState *qbus); +int ide_get_geometry(BusState *bus, int unit, + int16_t *cyls, int8_t *heads, int8_t *secs); +int ide_get_bios_chs_trans(BusState *bus, int unit); /* ide/core.c */ void ide_drive_get(DriveInfo **hd, int max_bus); diff --git a/hw/ide/core.c b/hw/ide/core.c index 28f04ad..7f5ad07 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1934,7 +1934,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, s->drive_kind = kind; bdrv_get_geometry(bs, &nb_sectors); - hd_geometry_guess(bs, &cylinders, &heads, &secs, NULL); + hd_geometry_guess(bs, &cylinders, &heads, &secs, &s->chs_trans); if (cylinders < 1 || cylinders > 16383) { error_report("cyls must be between 1 and 16383"); return -1; diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 1a02f57..56c718e 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -344,7 +344,7 @@ struct IDEState { uint8_t unit; /* ide config */ IDEDriveKind drive_kind; - int cylinders, heads, sectors; + int cylinders, heads, sectors, chs_trans; int64_t nb_sectors; int mult_sectors; int identify_set; diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index c122395..87e0b75 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -111,11 +111,24 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) return DO_UPCAST(IDEDevice, qdev, dev); } -void ide_get_bs(BlockDriverState *bs[], BusState *qbus) +int ide_get_geometry(BusState *bus, int unit, + int16_t *cyls, int8_t *heads, int8_t *secs) { - IDEBus *bus = DO_UPCAST(IDEBus, qbus, qbus); - bs[0] = bus->master ? bus->master->conf.bs : NULL; - bs[1] = bus->slave ? bus->slave->conf.bs : NULL; + IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit]; + + if (!s->bs) { + return -1; + } + + *cyls = s->cylinders; + *heads = s->heads; + *secs = s->sectors; + return 0; +} + +int ide_get_bios_chs_trans(BusState *bus, int unit) +{ + return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans; } /* --------------------------------- */ diff --git a/hw/pc.c b/hw/pc.c index 91cf77d..89a0c66 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -216,11 +216,9 @@ static int cmos_get_fd_drive_type(FDriveType fd0) return val; } -static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd, - ISADevice *s) +static void cmos_init_hd(ISADevice *s, int type_ofs, int info_ofs, + int16_t cylinders, int8_t heads, int8_t sectors) { - int cylinders, heads, sectors; - bdrv_get_geometry_hint(hd, &cylinders, &heads, §ors); rtc_set_memory(s, type_ofs, 47); rtc_set_memory(s, info_ofs, cylinders); rtc_set_memory(s, info_ofs + 1, cylinders >> 8); @@ -281,37 +279,42 @@ static int pc_boot_set(void *opaque, const char *boot_device) typedef struct pc_cmos_init_late_arg { ISADevice *rtc_state; - BusState *idebus0, *idebus1; + BusState *idebus[2]; } pc_cmos_init_late_arg; static void pc_cmos_init_late(void *opaque) { pc_cmos_init_late_arg *arg = opaque; ISADevice *s = arg->rtc_state; + int16_t cylinders; + int8_t heads, sectors; int val; - BlockDriverState *hd_table[4]; int i; - ide_get_bs(hd_table, arg->idebus0); - ide_get_bs(hd_table + 2, arg->idebus1); - - rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0)); - if (hd_table[0]) - cmos_init_hd(0x19, 0x1b, hd_table[0], s); - if (hd_table[1]) - cmos_init_hd(0x1a, 0x24, hd_table[1], s); + val = 0; + if (ide_get_geometry(arg->idebus[0], 0, + &cylinders, &heads, §ors) >= 0) { + cmos_init_hd(s, 0x19, 0x1b, cylinders, heads, sectors); + val |= 0xf0; + } + if (ide_get_geometry(arg->idebus[0], 1, + &cylinders, &heads, §ors) >= 0) { + cmos_init_hd(s, 0x1a, 0x24, cylinders, heads, sectors); + val |= 0x0f; + } + rtc_set_memory(s, 0x12, val); val = 0; for (i = 0; i < 4; i++) { - if (hd_table[i]) { - int cylinders, heads, sectors, translation; - /* NOTE: bdrv_get_geometry_hint() returns the physical - geometry. It is always such that: 1 <= sects <= 63, 1 - <= heads <= 16, 1 <= cylinders <= 16383. The BIOS - geometry can be different if a translation is done. */ - translation = bdrv_get_translation_hint(hd_table[i]); + /* NOTE: ide_get_geometry() returns the physical + geometry. It is always such that: 1 <= sects <= 63, 1 + <= heads <= 16, 1 <= cylinders <= 16383. The BIOS + geometry can be different if a translation is done. */ + if (ide_get_geometry(arg->idebus[i / 2], i % 2, + &cylinders, &heads, §ors) >= 0) { + int translation = ide_get_bios_chs_trans(arg->idebus[i / 2], + i % 2); if (translation == BIOS_ATA_TRANSLATION_AUTO) { - bdrv_get_geometry_hint(hd_table[i], &cylinders, &heads, §ors); if (cylinders <= 1024 && heads <= 16 && sectors <= 63) { /* No translation. */ translation = 0; @@ -411,8 +414,8 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, /* hard drives */ arg.rtc_state = s; - arg.idebus0 = idebus0; - arg.idebus1 = idebus1; + arg.idebus[0] = idebus0; + arg.idebus[1] = idebus1; qemu_register_reset(pc_cmos_init_late, &arg); }