From patchwork Fri Jul 6 06:58:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 169374 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 00E5B2C01BB for ; Fri, 6 Jul 2012 18:31:37 +1000 (EST) Received: from localhost ([::1]:42562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2b2-0001qt-GY for incoming@patchwork.ozlabs.org; Fri, 06 Jul 2012 03:04:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2aU-0000Ok-3n for qemu-devel@nongnu.org; Fri, 06 Jul 2012 03:04:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sn2aM-00052g-1N for qemu-devel@nongnu.org; Fri, 06 Jul 2012 03:04:21 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:50656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2aL-000522-OI for qemu-devel@nongnu.org; Fri, 06 Jul 2012 03:04:13 -0400 Received: from blackfin.pond.sub.org (p5B32A0DA.dip.t-dialin.net [91.50.160.218]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 1A838A5A56; Fri, 6 Jul 2012 09:04:12 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 5F49D600BA; Fri, 6 Jul 2012 08:58:12 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2012 08:58:08 +0200 Message-Id: <1341557890-17464-31-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1341557890-17464-1-git-send-email-armbru@redhat.com> References: <1341557890-17464-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, blauwirbel@gmail.com, stefanha@linux.vnet.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 30/32] hd-geometry: Compute BIOS CHS translation in one place 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 Currently, it is split between hd_geometry_guess() and pc_cmos_init_late(). Confusing. info qtree shows the result of the former. Also confusing. Fold the part done in pc_cmos_init_late() into hd_geometry_guess(). Signed-off-by: Markus Armbruster --- hw/block-common.h | 1 + hw/hd-geometry.c | 9 ++++++++- hw/ide/core.c | 2 ++ hw/ide/qdev.c | 3 +++ hw/pc.c | 19 ++++--------------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/hw/block-common.h b/hw/block-common.h index ec7810d..31e12ba 100644 --- a/hw/block-common.h +++ b/hw/block-common.h @@ -24,5 +24,6 @@ void hd_geometry_guess(BlockDriverState *bs, uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, int *ptrans); +int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs); #endif diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c index 74678a6..1cdb9fb 100644 --- a/hw/hd-geometry.c +++ b/hw/hd-geometry.c @@ -125,7 +125,7 @@ void hd_geometry_guess(BlockDriverState *bs, if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) { /* no LCHS guess: use a standard physical disk geometry */ guess_chs_for_size(bs, pcyls, pheads, psecs); - translation = BIOS_ATA_TRANSLATION_AUTO; + translation = hd_bios_chs_auto_trans(*pcyls, *pheads, *psecs); } else if (heads > 16) { /* LCHS guess with heads > 16 means that a BIOS LBA translation was active, so a standard physical disk @@ -148,3 +148,10 @@ void hd_geometry_guess(BlockDriverState *bs, } trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation); } + +int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs) +{ + return cyls <= 1024 && heads <= 16 && secs <= 63 + ? BIOS_ATA_TRANSLATION_NONE + : BIOS_ATA_TRANSLATION_LBA; +} diff --git a/hw/ide/core.c b/hw/ide/core.c index bf1ce89..1ca7cdf 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2091,6 +2091,8 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, trans = dinfo->trans; if (!cyls && !heads && !secs) { hd_geometry_guess(dinfo->bdrv, &cyls, &heads, &secs, &trans); + } else if (trans == BIOS_ATA_TRANSLATION_AUTO) { + trans = hd_bios_chs_auto_trans(cyls, heads, secs); } if (ide_init_drive(&bus->ifs[i], dinfo->bdrv, dinfo->media_cd ? IDE_CD : IDE_HD, NULL, diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 84097fd..de9db3b 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -171,6 +171,9 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) hd_geometry_guess(dev->conf.bs, &dev->conf.cyls, &dev->conf.heads, &dev->conf.secs, &dev->chs_trans); + } else if (dev->chs_trans == BIOS_ATA_TRANSLATION_AUTO) { + dev->chs_trans = hd_bios_chs_auto_trans(dev->conf.cyls, + dev->conf.heads, dev->conf.secs); } if (ide_init_drive(s, dev->conf.bs, kind, diff --git a/hw/pc.c b/hw/pc.c index 968376e..681a9a7 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -290,7 +290,7 @@ static void pc_cmos_init_late(void *opaque) int16_t cylinders; int8_t heads, sectors; int val; - int i; + int i, trans; val = 0; if (ide_get_geometry(arg->idebus[0], 0, @@ -313,20 +313,9 @@ static void pc_cmos_init_late(void *opaque) 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) { - if (cylinders <= 1024 && heads <= 16 && sectors <= 63) { - /* No translation. */ - translation = 0; - } else { - /* LBA translation. */ - translation = 1; - } - } else { - translation--; - } - val |= translation << (i * 2); + trans = ide_get_bios_chs_trans(arg->idebus[i / 2], i % 2) - 1; + assert((trans & ~3) == 0); + val |= trans << (i * 2); } } rtc_set_memory(s, 0x39, val);