From nobody Fri Dec 19 16:01:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664558106; cv=none; d=zohomail.com; s=zohoarc; b=TcarwzYzIOiYnwXArpOSEP37HfvKvEUh7nozP5Q/JuFbRW2US04ASq38zkBCS71FZEDHDEt1HzEBg9M6x2Y3ifRiL80bbpRyRx+eSG2jHpJRuP9sxEmJ5WLctejFKTXk9FGQZulNJCQVSRob/TM2Ci24qjJHIhIRSey5b7vNDxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664558106; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VRlEUOM1qeE9+nvz4hF5vEgRMiGWQ0qR7RFnjxXiuB8=; b=RVnD64B+KFVagABurQnggYZ0g/6L2Dj9Tw3gMaI937t7+RooO8qRKKvVnv/ser9eb6IWIbE9eZlURvTCV5AYWpFjIUUMmH45fwnzWkWVM3NeBq8G+nwQf1A/Vu4nh/UwTSPQbeTBMIO0aHeDbWnsmBEJG1/BIb0Def+fx8P8sEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664558106380653.047532762936; Fri, 30 Sep 2022 10:15:06 -0700 (PDT) Received: from localhost ([::1]:44998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeJbM-0002Da-Ce for importer@patchew.org; Fri, 30 Sep 2022 13:15:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeJFv-0006lS-TV for qemu-devel@nongnu.org; Fri, 30 Sep 2022 12:52:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeJFt-0006hn-V1 for qemu-devel@nongnu.org; Fri, 30 Sep 2022 12:52:55 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-224-nnhQVtpLNuayQOZLURytvw-1; Fri, 30 Sep 2022 12:52:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D19693C10226; Fri, 30 Sep 2022 16:52:51 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DC0417582; Fri, 30 Sep 2022 16:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664556773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VRlEUOM1qeE9+nvz4hF5vEgRMiGWQ0qR7RFnjxXiuB8=; b=BtaIDZbLWFc3i7rDCHGHR72ED0L8QU7sgP9c99zNpUPSx4XdUoCpXeOUufMFxMrn+xJebc qnPdgmapMwR+bmsblym9fd2i9u89X8Ph4N5586L4zI6rtSQWbBbkM/w0QJA014Sb1QR8Vx oVEGGFeb+UkW0frutxSIl6gPpHASHkY= X-MC-Unique: nnhQVtpLNuayQOZLURytvw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 18/18] hw/ide/core.c: Implement ATA INITIALIZE_DEVICE_PARAMETERS command Date: Fri, 30 Sep 2022 18:52:22 +0200 Message-Id: <20220930165222.249716-19-kwolf@redhat.com> In-Reply-To: <20220930165222.249716-1-kwolf@redhat.com> References: <20220930165222.249716-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664558107148100001 Content-Type: text/plain; charset="utf-8" From: Lev Kujawski CHS-based disk utilities and operating systems may adjust the logical geometry of a hard drive to cope with the expectations or limitations of software using the ATA INITIALIZE_DEVICE_PARAMETERS command. Prior to this patch, INITIALIZE_DEVICE_PARAMETERS was a nop that always returned success, raising the possibility of data loss or corruption if the CHS<->LBA translation redirected a write to the wrong sector. * hw/ide/core.c ide_reset(): Reset the logical CHS geometry of the hard disk when the power-on defaults feature is enabled. cmd_specify(): a) New function implementing INITIALIZE_DEVICE_PARAMETERS. b) Ignore calls for empty or ATAPI devices. cmd_set_features(): Implement the power-on defaults enable and disable features. struct ide_cmd_table: Switch WIN_SPECIFY from cmd_nop() to cmd_specify(). ide_init_drive(): Set new fields 'drive_heads' and 'drive_sectors' based upon the actual disk geometry. * include/hw/ide/internal.h struct IDEState: a) Store the actual drive CHS values within the new fields 'drive_heads' and 'drive_sectors.' b) Track whether a soft IDE reset should also reset the logical CHS geometry of the hard disk within the new field 'reset_reverts'. Signed-off-by: Lev Kujawski Message-Id: <20220707031140.158958-7-lkujaw@member.fsf.org> Signed-off-by: Kevin Wolf --- include/hw/ide/internal.h | 3 +++ hw/ide/core.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 97e7e59dc5..b17f36df95 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -375,6 +375,7 @@ struct IDEState { uint8_t unit; /* ide config */ IDEDriveKind drive_kind; + int drive_heads, drive_sectors; int cylinders, heads, sectors, chs_trans; int64_t nb_sectors; int mult_sectors; @@ -401,6 +402,8 @@ struct IDEState { uint8_t select; uint8_t status; =20 + bool reset_reverts; + /* set for lba48 access */ uint8_t lba48; BlockBackend *blk; diff --git a/hw/ide/core.c b/hw/ide/core.c index b747191ebf..39afdc0006 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1340,6 +1340,11 @@ static void ide_reset(IDEState *s) s->pio_aiocb =3D NULL; } =20 + if (s->reset_reverts) { + s->reset_reverts =3D false; + s->heads =3D s->drive_heads; + s->sectors =3D s->drive_sectors; + } if (s->drive_kind =3D=3D IDE_CFATA) s->mult_sectors =3D 0; else @@ -1618,6 +1623,20 @@ static bool cmd_check_power_mode(IDEState *s, uint8_= t cmd) return true; } =20 +/* INITIALIZE DEVICE PARAMETERS */ +static bool cmd_specify(IDEState *s, uint8_t cmd) +{ + if (s->blk && s->drive_kind !=3D IDE_CD) { + s->heads =3D (s->select & (ATA_DEV_HS)) + 1; + s->sectors =3D s->nsector; + ide_set_irq(s->bus); + } else { + ide_abort_command(s); + } + + return true; +} + static bool cmd_set_features(IDEState *s, uint8_t cmd) { uint16_t *identify_data; @@ -1641,7 +1660,11 @@ static bool cmd_set_features(IDEState *s, uint8_t cm= d) ide_flush_cache(s); return false; case 0xcc: /* reverting to power-on defaults enable */ + s->reset_reverts =3D true; + return true; case 0x66: /* reverting to power-on defaults disable */ + s->reset_reverts =3D false; + return true; case 0xaa: /* read look-ahead enable */ case 0x55: /* read look-ahead disable */ case 0x05: /* set advanced power management mode */ @@ -2051,7 +2074,7 @@ static const struct { [WIN_SEEK] =3D { cmd_seek, HD_CFA_OK | SET_DSC }, [CFA_TRANSLATE_SECTOR] =3D { cmd_cfa_translate_sector, CFA_OK }, [WIN_DIAGNOSE] =3D { cmd_exec_dev_diagnostic, ALL_OK }, - [WIN_SPECIFY] =3D { cmd_nop, HD_CFA_OK | SET_DSC }, + [WIN_SPECIFY] =3D { cmd_specify, HD_CFA_OK | SET_DSC }, [WIN_STANDBYNOW2] =3D { cmd_nop, HD_CFA_OK }, [WIN_IDLEIMMEDIATE2] =3D { cmd_nop, HD_CFA_OK }, [WIN_STANDBY2] =3D { cmd_nop, HD_CFA_OK }, @@ -2541,8 +2564,8 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, ID= EDriveKind kind, =20 blk_get_geometry(blk, &nb_sectors); s->cylinders =3D cylinders; - s->heads =3D heads; - s->sectors =3D secs; + s->heads =3D s->drive_heads =3D heads; + s->sectors =3D s->drive_sectors =3D secs; s->chs_trans =3D chs_trans; s->nb_sectors =3D nb_sectors; s->wwn =3D wwn; --=20 2.37.3