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 <arm...@redhat.com> --- blockdev.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/blockdev.h b/blockdev.h index b1a4bca..f5f103b 100644 --- a/blockdev.h +++ b/blockdev.h @@ -75,5 +75,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); 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 0e28527..1a9783d 100644 --- a/hw/hd-geometry.c +++ b/hw/hd-geometry.c @@ -116,7 +116,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 @@ -139,3 +139,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 80d453b..87cd26e 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2090,6 +2090,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 077ba87..67f9f16 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -170,6 +170,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 5fc64f7..c265113 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -289,7 +289,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, @@ -312,20 +312,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); -- 1.7.6.5