From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568277; cv=none; d=zohomail.com; s=zohoarc; b=BrK3FOY9Xfmwy9QWeflcyjYRFgxRpl9Z69WEMHpuTFQTZ7O0reMrhViv/cfyCGKhykh3oI7TVhAE3i+a4EPRetI/Yxt5W7YHR2O67FUILhj5NNnDk9OYWOOlov0bms8gRYMCeKwgVa8ktwfDTAwrG6iQO3oV1pIqH1N/XkKjp2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568277; h=Content-Type: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=YmtE+YKrz0ZTsj6UkrwfFA8+s6YpXYdAIZoV7wnLLdc=; b=BOBRds75RjEDJbygZCBUXriIz2cMmSx7UDDg8X2DgARNVYt/g5UMAnVZrmeU6Xp96LZhxkelJ1dV8l9TuzUP57MkqdeD4VQIKV4IYoGMBGBcBJle2MgLLrlxDGw9OKRMp2iqGWmeQD9wNxeS0MdJcX+VTD9S9sgT/SNtr9DUV2U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595568277085160.74322411882702; Thu, 23 Jul 2020 22:24:37 -0700 (PDT) Received: from localhost ([::1]:45488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqCB-0002w6-FC for importer@patchew.org; Fri, 24 Jul 2020 01:24:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAp-0000yS-6j for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:11 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:24619 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAl-0007R9-Dw for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-95-Nq8HSymBNz6dJNKvFC954g-1; Fri, 24 Jul 2020 01:23:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A434AC7465; Fri, 24 Jul 2020 05:23:02 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED09E7AC80; Fri, 24 Jul 2020 05:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YmtE+YKrz0ZTsj6UkrwfFA8+s6YpXYdAIZoV7wnLLdc=; b=Y+EL2nrA8Z0LHC363xwqHXVp+6DyWPVnd13UE5mcR2V4+Q6DDYL3zRBRMrwI/3eNbH+VXO YI1x7fHsMNTljl5CLXJiOgJ264NdKU7nMrdBOnKP+JX8AL2hKN8bJA3+aj+7syST3KA/4o 0qyQvPQ6klA1/WdJcNjZBD7YQ3Qg6l0= X-MC-Unique: Nq8HSymBNz6dJNKvFC954g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 1/7] ide: rename cmd_write to ctrl_write Date: Fri, 24 Jul 2020 01:22:54 -0400 Message-Id: <20200724052300.1163728-2-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 00:00:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It's the Control register, part of the Control block -- Command is misleading here. Rename all related functions and constants. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/ide/internal.h | 9 +++++---- hw/ide/core.c | 12 ++++++------ hw/ide/ioport.c | 2 +- hw/ide/macio.c | 2 +- hw/ide/mmio.c | 8 ++++---- hw/ide/pci.c | 12 ++++++------ hw/ide/trace-events | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 1a7869e85d..10ea6e1e23 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -57,8 +57,9 @@ typedef struct IDEDMAOps IDEDMAOps; #define REL 0x04 #define TAG_MASK 0xf8 =20 -#define IDE_CMD_RESET 0x04 -#define IDE_CMD_DISABLE_IRQ 0x02 +/* Bits of Device Control register */ +#define IDE_CTRL_RESET 0x04 +#define IDE_CTRL_DISABLE_IRQ 0x02 =20 /* ACS-2 T13/2015-D Table B.2 Command codes */ #define WIN_NOP 0x00 @@ -564,7 +565,7 @@ static inline IDEState *idebus_active_if(IDEBus *bus) =20 static inline void ide_set_irq(IDEBus *bus) { - if (!(bus->cmd & IDE_CMD_DISABLE_IRQ)) { + if (!(bus->cmd & IDE_CTRL_DISABLE_IRQ)) { qemu_irq_raise(bus->irq); } } @@ -603,7 +604,7 @@ void ide_atapi_io_error(IDEState *s, int ret); void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val); uint32_t ide_ioport_read(void *opaque, uint32_t addr1); uint32_t ide_status_read(void *opaque, uint32_t addr); -void ide_cmd_write(void *opaque, uint32_t addr, uint32_t val); +void ide_ctrl_write(void *opaque, uint32_t addr, uint32_t val); void ide_data_writew(void *opaque, uint32_t addr, uint32_t val); uint32_t ide_data_readw(void *opaque, uint32_t addr); void ide_data_writel(void *opaque, uint32_t addr, uint32_t val); diff --git a/hw/ide/core.c b/hw/ide/core.c index d997a78e47..b472220d65 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2235,25 +2235,25 @@ uint32_t ide_status_read(void *opaque, uint32_t add= r) return ret; } =20 -void ide_cmd_write(void *opaque, uint32_t addr, uint32_t val) +void ide_ctrl_write(void *opaque, uint32_t addr, uint32_t val) { IDEBus *bus =3D opaque; IDEState *s; int i; =20 - trace_ide_cmd_write(addr, val, bus); + trace_ide_ctrl_write(addr, val, bus); =20 /* common for both drives */ - if (!(bus->cmd & IDE_CMD_RESET) && - (val & IDE_CMD_RESET)) { + if (!(bus->cmd & IDE_CTRL_RESET) && + (val & IDE_CTRL_RESET)) { /* reset low to high */ for(i =3D 0;i < 2; i++) { s =3D &bus->ifs[i]; s->status =3D BUSY_STAT | SEEK_STAT; s->error =3D 0x01; } - } else if ((bus->cmd & IDE_CMD_RESET) && - !(val & IDE_CMD_RESET)) { + } else if ((bus->cmd & IDE_CTRL_RESET) && + !(val & IDE_CTRL_RESET)) { /* high to low */ for(i =3D 0;i < 2; i++) { s =3D &bus->ifs[i]; diff --git a/hw/ide/ioport.c b/hw/ide/ioport.c index ab1f4e5d9c..b613ff3bba 100644 --- a/hw/ide/ioport.c +++ b/hw/ide/ioport.c @@ -46,7 +46,7 @@ static const MemoryRegionPortio ide_portio_list[] =3D { }; =20 static const MemoryRegionPortio ide_portio2_list[] =3D { - { 0, 1, 1, .read =3D ide_status_read, .write =3D ide_cmd_write }, + { 0, 1, 1, .read =3D ide_status_read, .write =3D ide_ctrl_write }, PORTIO_END_OF_LIST(), }; =20 diff --git a/hw/ide/macio.c b/hw/ide/macio.c index 62a599a075..b270a10163 100644 --- a/hw/ide/macio.c +++ b/hw/ide/macio.c @@ -329,7 +329,7 @@ static void pmac_ide_write(void *opaque, hwaddr addr, u= int64_t val, case 0x8: case 0x16: if (size =3D=3D 1) { - ide_cmd_write(&d->bus, 0, val); + ide_ctrl_write(&d->bus, 0, val); } break; case 0x20: diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c index d233bd8c01..80b8a9eb09 100644 --- a/hw/ide/mmio.c +++ b/hw/ide/mmio.c @@ -95,16 +95,16 @@ static uint64_t mmio_ide_status_read(void *opaque, hwad= dr addr, return ide_status_read(&s->bus, 0); } =20 -static void mmio_ide_cmd_write(void *opaque, hwaddr addr, - uint64_t val, unsigned size) +static void mmio_ide_ctrl_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) { MMIOState *s =3D opaque; - ide_cmd_write(&s->bus, 0, val); + ide_ctrl_write(&s->bus, 0, val); } =20 static const MemoryRegionOps mmio_ide_cs_ops =3D { .read =3D mmio_ide_status_read, - .write =3D mmio_ide_cmd_write, + .write =3D mmio_ide_ctrl_write, .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 diff --git a/hw/ide/pci.c b/hw/ide/pci.c index 5e85c4ad17..59726ae453 100644 --- a/hw/ide/pci.c +++ b/hw/ide/pci.c @@ -38,7 +38,7 @@ (IDE_RETRY_DMA | IDE_RETRY_PIO | \ IDE_RETRY_READ | IDE_RETRY_FLUSH) =20 -static uint64_t pci_ide_cmd_read(void *opaque, hwaddr addr, unsigned size) +static uint64_t pci_ide_status_read(void *opaque, hwaddr addr, unsigned si= ze) { IDEBus *bus =3D opaque; =20 @@ -48,20 +48,20 @@ static uint64_t pci_ide_cmd_read(void *opaque, hwaddr a= ddr, unsigned size) return ide_status_read(bus, addr + 2); } =20 -static void pci_ide_cmd_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) +static void pci_ide_ctrl_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) { IDEBus *bus =3D opaque; =20 if (addr !=3D 2 || size !=3D 1) { return; } - ide_cmd_write(bus, addr + 2, data); + ide_ctrl_write(bus, addr + 2, data); } =20 const MemoryRegionOps pci_ide_cmd_le_ops =3D { - .read =3D pci_ide_cmd_read, - .write =3D pci_ide_cmd_write, + .read =3D pci_ide_status_read, + .write =3D pci_ide_ctrl_write, .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 diff --git a/hw/ide/trace-events b/hw/ide/trace-events index 2e4162629f..6e357685f9 100644 --- a/hw/ide/trace-events +++ b/hw/ide/trace-events @@ -5,7 +5,7 @@ ide_ioport_read(uint32_t addr, const char *reg, uint32_t val, void *bus, v= oid *s) "IDE PIO rd @ 0x%"PRIx32" (%s); val 0x%02"PRIx32"; bus %p IDEState= %p" ide_ioport_write(uint32_t addr, const char *reg, uint32_t val, void *bus, = void *s) "IDE PIO wr @ 0x%"PRIx32" (%s); val 0x%02"PRIx32"; bus %p IDEState= %p" ide_status_read(uint32_t addr, uint32_t val, void *bus, void *s) = "IDE PIO rd @ 0x%"PRIx32" (Alt Status); val 0x%02"PRIx32"; bus %p;= IDEState %p" -ide_cmd_write(uint32_t addr, uint32_t val, void *bus) = "IDE PIO wr @ 0x%"PRIx32" (Device Control); val 0x%02"PRIx32"; bus= %p" +ide_ctrl_write(uint32_t addr, uint32_t val, void *bus) = "IDE PIO wr @ 0x%"PRIx32" (Device Control); val 0x%02"PRIx32"; bus= %p" # Warning: verbose ide_data_readw(uint32_t addr, uint32_t val, void *bus, void *s) = "IDE PIO rd @ 0x%"PRIx32" (Data: Word); val 0x%04"PRIx32"; bus %p;= IDEState %p" ide_data_writew(uint32_t addr, uint32_t val, void *bus, void *s) = "IDE PIO wr @ 0x%"PRIx32" (Data: Word); val 0x%04"PRIx32"; bus %p;= IDEState %p" --=20 2.26.2 From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568272; cv=none; d=zohomail.com; s=zohoarc; b=UBR87e+7QmiTu90m8wTF/No73qYyk3e9cNEiphTiGa9W5wQiWLl4MdSvUCK/nTpHoEAKZpAaRYhRjYqR9kksEhQi2zztXuIthlR4Kwn/m4e3WGgp/dlBFIQ252GJ7kOIM8btyjnYB2yPpBh1YY2sQBDdZhwigoe5WPTZPE/6Wps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568272; h=Content-Type: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=pJaSzHh7R1iq6j8TrR1VP0OL6+heBIH8mfbdTfjw5zs=; b=FPPZpb8xQh5kOX5DkLCtVmVzNaQxmPeILIBygUBJuTLV+5U612TtDvuc46A9tzaodK3XZeNiFYkqpcDNsLh5pRbh/9PcUodQcmpF9zYKwm5AgiOpTVR9FJ0Cv7d/L3S1AYv+hZBW160+VrKtWwZnPmbMwt4PmKYepN59DIVQYsY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159556827222436.1878492933422; Thu, 23 Jul 2020 22:24:32 -0700 (PDT) Received: from localhost ([::1]:45060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqC6-0002lD-KK for importer@patchew.org; Fri, 24 Jul 2020 01:24:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAq-0000z2-En for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:12 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:57325 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAm-0007Rk-Va for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-301-7a_Gk-qdOMuemeB78uuv5g-1; Fri, 24 Jul 2020 01:23:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70CCF100A8E8; Fri, 24 Jul 2020 05:23:03 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7C797AC80; Fri, 24 Jul 2020 05:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pJaSzHh7R1iq6j8TrR1VP0OL6+heBIH8mfbdTfjw5zs=; b=KSiG9l1o2GYUHyDv6Tp08OoHf22Tjw/s4JIpgAfYnRei50mqoYCxbzJ31BxN7Q++AqfDZU MFnZ628ArWzRNg3vwBVPAzHHk4MRBQoPj4sbPpU8UYMsSoKeiq912MfDpwHvX5AVWAnjuc lEwXFyEzFFgikAvv7eu6fuJfbFcoEXw= X-MC-Unique: 7a_Gk-qdOMuemeB78uuv5g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 2/7] ide: don't tamper with the device register Date: Fri, 24 Jul 2020 01:22:55 -0400 Message-Id: <20200724052300.1163728-3-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 00:00:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In real ISA operation, register writes go out to an entire bus channel and all listening devices receive the write. The devices do not toggle the DEV bit based on their own configuration, nor does the HBA intermediate or tamper with that value. The reality of the matter is that DEV0/DEV1 accordingly will react to command register writes based on whether or not the device was selected. This does not fix a known bug, but it makes the code slightly simpler and more obvious. Signed-off-by: John Snow --- hw/ide/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index b472220d65..5cedebc408 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1297,8 +1297,8 @@ void ide_ioport_write(void *opaque, uint32_t addr, ui= nt32_t val) break; case ATA_IOPORT_WR_DEVICE_HEAD: /* FIXME: HOB readback uses bit 7 */ - bus->ifs[0].select =3D (val & ~0x10) | 0xa0; - bus->ifs[1].select =3D (val | 0x10) | 0xa0; + bus->ifs[0].select =3D val | 0xa0; + bus->ifs[1].select =3D val | 0xa0; /* select drive */ bus->unit =3D (val >> 4) & 1; break; --=20 2.26.2 From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568377; cv=none; d=zohomail.com; s=zohoarc; b=hjSl1Mq80d7lPhIP7VoLf6fB51lZjdHisPjphOa5o6P3q3Lm3DO/kXrn5H7eH7GksbyUdo89JX8994OXk1kabvjCJwvckmu/u2iAO8isV4HuU6zT6j0rFyFYxAwVkJVNkydMDZ2UF6uiojjVRIyRNifsz9IMBVgd+TL/68jtw48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568377; h=Content-Type: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=zhGJpZGOCRF1db9wHuts2huHwM/xClDsqI5d+Pu/uiM=; b=n9d1aZkvWY1BhsZxJ5/0CHRGip28Mkkl9NLj5GcwfpOSiUQR9fjzjtAvw3tWmfLp9EHWVwx0EuE2mLWq8799z5R6ZkjCeCSGwmgQpvdRQGBUmAKciD5HsP3fGDpP4Gztjeq6rxUk1G/QYSsL8idlzDS4Fh19hZpCN5zw8AnaW3o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595568377376888.9976077768515; Thu, 23 Jul 2020 22:26:17 -0700 (PDT) Received: from localhost ([::1]:52200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqDo-0005pO-3P for importer@patchew.org; Fri, 24 Jul 2020 01:26:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAq-0000yw-Bq for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:12 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:47379 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAm-0007RW-02 for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:11 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-yovbNaBNM7KeG_6B3rtXOg-1; Fri, 24 Jul 2020 01:23:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3719A8005B0; Fri, 24 Jul 2020 05:23:04 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 932F57AC80; Fri, 24 Jul 2020 05:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zhGJpZGOCRF1db9wHuts2huHwM/xClDsqI5d+Pu/uiM=; b=ZP5S5GNNVRsMd47hgsmsX8Kdr70rIIETuu5UuSmaDAu1JsCi5+j/iutqP9DSWMpNQyE9KO ewZ9QCHjjnW1Jl/edaqOS90hMHK1zlSo0Szv6sqkDpOGeT9ZZAL9CaEO19ZtY4XlaFdJ1j JthduXC3jD4GJ5PlXGgD5LeixW0i/G0= X-MC-Unique: yovbNaBNM7KeG_6B3rtXOg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 3/7] ide: model HOB correctly Date: Fri, 24 Jul 2020 01:22:56 -0400 Message-Id: <20200724052300.1163728-4-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 00:00:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" I have been staring at this FIXME for years and I never knew what it meant. I finally stumbled across it! When writing to the command registers, the old value is shifted into a HOB copy of the register and the new value is written into the primary register. When reading registers, the value retrieved is dependent on the HOB bit in the CONTROL register. By setting bit 7 (0x80) in CONTROL, any register read will, if it has one, yield the HOB value for that register instead. Our code has a problem: We were using bit 7 of the DEVICE register to model this. We use bus->cmd roughly as the control register already, as it stores the value from ide_ctrl_write. Lastly, all command register writes reset the HOB, so fix that, too. Signed-off-by: John Snow --- include/hw/ide/internal.h | 1 + hw/ide/core.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 10ea6e1e23..16d806e0cf 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -58,6 +58,7 @@ typedef struct IDEDMAOps IDEDMAOps; #define TAG_MASK 0xf8 =20 /* Bits of Device Control register */ +#define IDE_CTRL_HOB 0x80 #define IDE_CTRL_RESET 0x04 #define IDE_CTRL_DISABLE_IRQ 0x02 =20 diff --git a/hw/ide/core.c b/hw/ide/core.c index 5cedebc408..a880b91b47 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1215,8 +1215,7 @@ static void ide_cmd_lba48_transform(IDEState *s, int = lba48) static void ide_clear_hob(IDEBus *bus) { /* any write clears HOB high bit of device control register */ - bus->ifs[0].select &=3D ~(1 << 7); - bus->ifs[1].select &=3D ~(1 << 7); + bus->cmd &=3D ~(IDE_CTRL_HOB); } =20 /* IOport [W]rite [R]egisters */ @@ -1256,12 +1255,14 @@ void ide_ioport_write(void *opaque, uint32_t addr, = uint32_t val) return; } =20 + /* NOTE: Device0 and Device1 both receive incoming register writes. + * (They're on the same bus! They have to!) */ + switch (reg_num) { case 0: break; case ATA_IOPORT_WR_FEATURES: ide_clear_hob(bus); - /* NOTE: data is written to the two drives */ bus->ifs[0].hob_feature =3D bus->ifs[0].feature; bus->ifs[1].hob_feature =3D bus->ifs[1].feature; bus->ifs[0].feature =3D val; @@ -1296,7 +1297,7 @@ void ide_ioport_write(void *opaque, uint32_t addr, ui= nt32_t val) bus->ifs[1].hcyl =3D val; break; case ATA_IOPORT_WR_DEVICE_HEAD: - /* FIXME: HOB readback uses bit 7 */ + ide_clear_hob(bus); bus->ifs[0].select =3D val | 0xa0; bus->ifs[1].select =3D val | 0xa0; /* select drive */ @@ -1304,7 +1305,7 @@ void ide_ioport_write(void *opaque, uint32_t addr, ui= nt32_t val) break; default: case ATA_IOPORT_WR_COMMAND: - /* command */ + ide_clear_hob(bus); ide_exec_cmd(bus, val); break; } @@ -2142,9 +2143,7 @@ uint32_t ide_ioport_read(void *opaque, uint32_t addr) int ret, hob; =20 reg_num =3D addr & 7; - /* FIXME: HOB readback uses bit 7, but it's always set right now */ - //hob =3D s->select & (1 << 7); - hob =3D 0; + hob =3D bus->cmd & (IDE_CTRL_HOB); switch (reg_num) { case ATA_IOPORT_RR_DATA: ret =3D 0xff; --=20 2.26.2 From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568285; cv=none; d=zohomail.com; s=zohoarc; b=TaoiyRHXBNG0Im09KowlkHYpB3R9aP4J3VrepIne5VybsXip6WeelXntn1mTUKw4vXwBVh4oKCs7lTCbf8WVjEfjkYaeWMF7xqtcSFmDg7xFxehzNz1m30fhKrt6yGboTcA/cscBRii/cI5i8Pe0R/wjM5Dq9LLfH6FtQQ+CU9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568285; h=Content-Type: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=1PIIZ0rWR7fbA3h+dJxS8bPAnBQjFmR4OXt+O8WSIe4=; b=bRWJVBTNnCPeITB6BcJ4/wkeXee+4DxLB4CU+tpEyenSVSZTQRIj8Li58lSc57SXffnN0M6dWBXVKxDKpNFuwEESJUpN2imv3JWh5FLTAWCoYUF7r0d4I2/du4q8eRqR4YIMqbsOK/ExFsNiLixSZpi5lCpm5zF9jk28ngF/gYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595568285783396.70107936959766; Thu, 23 Jul 2020 22:24:45 -0700 (PDT) Received: from localhost ([::1]:46124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqCK-0003Df-H5 for importer@patchew.org; Fri, 24 Jul 2020 01:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAr-000114-CV for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:13 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:58658 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAn-0007Ro-99 for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-8ZudlPRyPCafl_ZxXyD4gQ-1; Fri, 24 Jul 2020 01:23:06 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D4B980183C; Fri, 24 Jul 2020 05:23:05 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 816B17F4D6; Fri, 24 Jul 2020 05:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1PIIZ0rWR7fbA3h+dJxS8bPAnBQjFmR4OXt+O8WSIe4=; b=cPxTE+vnoOwmG0gdVqFKQTC6ZGm0JhvNqe4jyK194FKbrJWLgnMLwfWx/kV2/1KNCotrly 3v4IqlCK+8IIN3cW2/CTYn0lT9muEFU3SJ9/+2jzFBMLXSfcTp3MnX8Q/eVbrT61izhMf/ 9KfM808qjvSy599Hu3j2Bu5hgISm0uY= X-MC-Unique: 8ZudlPRyPCafl_ZxXyD4gQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 4/7] ide: reorder set/get sector functions Date: Fri, 24 Jul 2020 01:22:57 -0400 Message-Id: <20200724052300.1163728-5-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 00:00:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reorder these just a pinch to make them more obvious at a glance what the addressing mode is. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/ide/core.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index a880b91b47..f35864070b 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -587,21 +587,23 @@ int64_t ide_get_sector(IDEState *s) { int64_t sector_num; if (s->select & 0x40) { - /* lba */ - if (!s->lba48) { - sector_num =3D ((s->select & 0x0f) << 24) | (s->hcyl << 16) | - (s->lcyl << 8) | s->sector; - } else { + if (s->lba48) { sector_num =3D ((int64_t)s->hob_hcyl << 40) | ((int64_t) s->hob_lcyl << 32) | ((int64_t) s->hob_sector << 24) | ((int64_t) s->hcyl << 16) | ((int64_t) s->lcyl << 8) | s->sector; + } else { + /* LBA28 */ + sector_num =3D ((s->select & 0x0f) << 24) | (s->hcyl << 16) | + (s->lcyl << 8) | s->sector; } } else { + /* CHS */ sector_num =3D ((s->hcyl << 8) | s->lcyl) * s->heads * s->sectors + (s->select & 0x0f) * s->sectors + (s->sector - 1); } + return sector_num; } =20 @@ -609,20 +611,22 @@ void ide_set_sector(IDEState *s, int64_t sector_num) { unsigned int cyl, r; if (s->select & 0x40) { - if (!s->lba48) { - s->select =3D (s->select & 0xf0) | (sector_num >> 24); - s->hcyl =3D (sector_num >> 16); - s->lcyl =3D (sector_num >> 8); - s->sector =3D (sector_num); - } else { + if (s->lba48) { s->sector =3D sector_num; s->lcyl =3D sector_num >> 8; s->hcyl =3D sector_num >> 16; s->hob_sector =3D sector_num >> 24; s->hob_lcyl =3D sector_num >> 32; s->hob_hcyl =3D sector_num >> 40; + } else { + /* LBA28 */ + s->select =3D (s->select & 0xf0) | (sector_num >> 24); + s->hcyl =3D (sector_num >> 16); + s->lcyl =3D (sector_num >> 8); + s->sector =3D (sector_num); } } else { + /* CHS */ cyl =3D sector_num / (s->heads * s->sectors); r =3D sector_num % (s->heads * s->sectors); s->hcyl =3D cyl >> 8; --=20 2.26.2 From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568386; cv=none; d=zohomail.com; s=zohoarc; b=j+hzZmNhijMQOARUhW1MC7wH3M74t4bvNid2HsOVaBYUVcVnT4YcJw1Jv1KNbAK6mBe7CRtewWF5lqrzyShqP7X7SAs4TZbka6b0ciYHDuH0FS5ozP6k+c8JCPg7stj0lyuu+3mMO7zrpvZVILBsYMfqYD+bX6CFMK1hL66z9t8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568386; h=Content-Type: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=5Co9wodFwNQgOYcGNEqwkwsaqy/+vDOfCIdf+CIoN+U=; b=YxoGjrJbx0wsoPjL+Oiqu+dJA9+UQFXZhKfX9EFE295dpQQKRci9/cp/q4u8i2fm90z6ftbL7jq7LedKuk9tLlw2XV1LXzH0jHNc130nvmxl9TmIYVFKalKLL1tu9oYNANESVh2OXEsoHGz6SBIVsfDM6EvAWRAePfgb6zavXPQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595568386479434.9248907737352; Thu, 23 Jul 2020 22:26:26 -0700 (PDT) Received: from localhost ([::1]:52442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqDx-0005vU-8p for importer@patchew.org; Fri, 24 Jul 2020 01:26:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAt-00015s-Gt for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:15 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:23542 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAq-0007SZ-8L for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-DRW_1XZvPIKMJaWiS0yUcQ-1; Fri, 24 Jul 2020 01:23:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD6A6189CEE0; Fri, 24 Jul 2020 05:23:06 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0F4D7AC80; Fri, 24 Jul 2020 05:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Co9wodFwNQgOYcGNEqwkwsaqy/+vDOfCIdf+CIoN+U=; b=ixLGYziUpodw5w9IXI8jY/ZSsHdAfMA+D2dt45RznOGn25Um7yd7tO1MH+ZJTxSHXJvXiZ 1lJln4IHsFTGF9ZoJk4lvfzZbNNTXX6bVmU4o16LbyWvhBHY3kVcMohrFXtxHurAx18lsX z2JPhba2BfXXY8JOPWJGffp78Vx9Eh0= X-MC-Unique: DRW_1XZvPIKMJaWiS0yUcQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 5/7] ide: remove magic constants from the device register Date: Fri, 24 Jul 2020 01:22:58 -0400 Message-Id: <20200724052300.1163728-6-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 01:23:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" (In QEMU, we call this the "select" register.) My memory isn't good enough to memorize what these magic runes do. Label them to prevent mixups from happening in the future. Side note: I assume it's safe to always set 0xA0 even though ATA2 claims these bits are reserved, because ATA3 immediately reinstated that these bits should be always on. ATA4 and subsequent specs only claim that the fields are obsolete, so I assume it's safe to leave these set and that it should work with the widest array of guests. Signed-off-by: John Snow --- include/hw/ide/internal.h | 11 +++++++++++ hw/ide/core.c | 26 ++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 16d806e0cf..d5a6ba1056 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -29,6 +29,17 @@ typedef struct IDEDMAOps IDEDMAOps; =20 #define MAX_IDE_DEVS 2 =20 +/* Device/Head ("select") Register */ +#define ATA_DEV_SELECT 0x10 +/* ATA1,3: Defined as '1'. + * ATA2: Reserved. + * ATA3-7: obsolete. */ +#define ATA_DEV_ALWAYS_ON 0xA0 +#define ATA_DEV_LBA 0x40 +#define ATA_DEV_LBA_MSB 0x0F /* LBA 24:27 */ +#define ATA_DEV_HS 0x0F /* HS 3:0 */ + + /* Bits of HD_STATUS */ #define ERR_STAT 0x01 #define INDEX_STAT 0x02 diff --git a/hw/ide/core.c b/hw/ide/core.c index f35864070b..5f4f004312 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -367,7 +367,7 @@ fill_buffer: =20 static void ide_set_signature(IDEState *s) { - s->select &=3D 0xf0; /* clear head */ + s->select &=3D ~(ATA_DEV_HS); /* clear head */ /* put signature */ s->nsector =3D 1; s->sector =3D 1; @@ -586,7 +586,7 @@ void ide_transfer_stop(IDEState *s) int64_t ide_get_sector(IDEState *s) { int64_t sector_num; - if (s->select & 0x40) { + if (s->select & (ATA_DEV_LBA)) { if (s->lba48) { sector_num =3D ((int64_t)s->hob_hcyl << 40) | ((int64_t) s->hob_lcyl << 32) | @@ -595,13 +595,13 @@ int64_t ide_get_sector(IDEState *s) ((int64_t) s->lcyl << 8) | s->sector; } else { /* LBA28 */ - sector_num =3D ((s->select & 0x0f) << 24) | (s->hcyl << 16) | - (s->lcyl << 8) | s->sector; + sector_num =3D ((s->select & (ATA_DEV_LBA_MSB)) << 24) | + (s->hcyl << 16) | (s->lcyl << 8) | s->sector; } } else { /* CHS */ sector_num =3D ((s->hcyl << 8) | s->lcyl) * s->heads * s->sectors + - (s->select & 0x0f) * s->sectors + (s->sector - 1); + (s->select & (ATA_DEV_HS)) * s->sectors + (s->sector - 1); } =20 return sector_num; @@ -610,7 +610,7 @@ int64_t ide_get_sector(IDEState *s) void ide_set_sector(IDEState *s, int64_t sector_num) { unsigned int cyl, r; - if (s->select & 0x40) { + if (s->select & (ATA_DEV_LBA)) { if (s->lba48) { s->sector =3D sector_num; s->lcyl =3D sector_num >> 8; @@ -620,7 +620,8 @@ void ide_set_sector(IDEState *s, int64_t sector_num) s->hob_hcyl =3D sector_num >> 40; } else { /* LBA28 */ - s->select =3D (s->select & 0xf0) | (sector_num >> 24); + s->select =3D (s->select & ~(ATA_DEV_LBA_MSB)) | + ((sector_num >> 24) & (ATA_DEV_LBA_MSB)); s->hcyl =3D (sector_num >> 16); s->lcyl =3D (sector_num >> 8); s->sector =3D (sector_num); @@ -631,7 +632,8 @@ void ide_set_sector(IDEState *s, int64_t sector_num) r =3D sector_num % (s->heads * s->sectors); s->hcyl =3D cyl >> 8; s->lcyl =3D cyl; - s->select =3D (s->select & 0xf0) | ((r / s->sectors) & 0x0f); + s->select =3D (s->select & ~(ATA_DEV_HS)) | + ((r / s->sectors) & (ATA_DEV_HS)); s->sector =3D (r % s->sectors) + 1; } } @@ -1302,10 +1304,10 @@ void ide_ioport_write(void *opaque, uint32_t addr, = uint32_t val) break; case ATA_IOPORT_WR_DEVICE_HEAD: ide_clear_hob(bus); - bus->ifs[0].select =3D val | 0xa0; - bus->ifs[1].select =3D val | 0xa0; + bus->ifs[0].select =3D val | (ATA_DEV_ALWAYS_ON); + bus->ifs[1].select =3D val | (ATA_DEV_ALWAYS_ON); /* select drive */ - bus->unit =3D (val >> 4) & 1; + bus->unit =3D (val & (ATA_DEV_SELECT)) ? 1 : 0; break; default: case ATA_IOPORT_WR_COMMAND: @@ -1343,7 +1345,7 @@ static void ide_reset(IDEState *s) s->hob_lcyl =3D 0; s->hob_hcyl =3D 0; =20 - s->select =3D 0xa0; + s->select =3D (ATA_DEV_ALWAYS_ON); s->status =3D READY_STAT | SEEK_STAT; =20 s->lba48 =3D 0; --=20 2.26.2 From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568285; cv=none; d=zohomail.com; s=zohoarc; b=N8MyNE4kgOvPD4jV/eMe/gq6gOKRFaFSm/NAv2dXH2g8YiXnFGWnxwVbd/xVmG8FkGD8m8rG3UG9/1TWUmTQPoUHigXGtarX1ateji4QzkhnJcr/CeZ6O8FwHt0CKxHA1W6Z+sGOELakZ3cw+yH84FQU/ZoU7MF+FWFJ157mtuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568285; h=Content-Type: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=/s3X8YqjASZjM7L/p0xkJEgVoB+Q5trhJzSdGsKpBWg=; b=KGu1Y2WYNXbGX5aT/MS+JdwR8tcq7Ok7+yGsWwlpOh1KMVzdvCM1z5SxOkp0KmF/myHkICQ0nKaIZYOf9gpn0flfXpGpAjNKfub1hvwZjsttg+DdtPUFoWUkcAoolQG5m8F4mIDZPtIxLq4f63d3dGKcCffxt66Thsu/CwHAdNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159556828564332.65567183239182; Thu, 23 Jul 2020 22:24:45 -0700 (PDT) Received: from localhost ([::1]:46166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqCK-0003Ed-DV for importer@patchew.org; Fri, 24 Jul 2020 01:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAs-00013Y-LD for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:14 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24378 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAp-0007S6-6g for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-122-WFvfen2UO2iiIJx-wqp7rQ-1; Fri, 24 Jul 2020 01:23:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CC4458; Fri, 24 Jul 2020 05:23:07 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE7B27AC80; Fri, 24 Jul 2020 05:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/s3X8YqjASZjM7L/p0xkJEgVoB+Q5trhJzSdGsKpBWg=; b=WUCpTzKpFBtPr6jSQ+6kfBt7p7+ISPTlUbEVOv6A2Bdlp9I/EDmIbXW73nhT2KVWgcsGjz 3czlMcuf/q+j5nuG6u5Iy0Wzc0Z8RFl7OpHHRCZCxY8UsajDNKY2uytM3KOqrJRmtCkByH FoNX9VtyocYlf+NcUPqUgqXXXSsy7p8= X-MC-Unique: WFvfen2UO2iiIJx-wqp7rQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 6/7] ide: clear interrupt on command write Date: Fri, 24 Jul 2020 01:22:59 -0400 Message-Id: <20200724052300.1163728-7-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 01:23:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Not known to fix any bug, but I couldn't help but notice that ATA specifies that writing to this register should clear an interrupt. ATA7: Section 5.3.3 (Command register - Effect) ATA6: Section 7.4.4 (Command register - Effect) ATA5: Section 7.4.4 (Command register - Effect) ATA4: Section 7.4.4 (Command register - Effect) ATA3: Section 5.2.2 (Command register) Other editions: try searching for the phrase "Writing this register". Signed-off-by: John Snow --- hw/ide/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index 5f4f004312..e4c69a7fde 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1312,6 +1312,7 @@ void ide_ioport_write(void *opaque, uint32_t addr, ui= nt32_t val) default: case ATA_IOPORT_WR_COMMAND: ide_clear_hob(bus); + qemu_irq_lower(bus->irq); ide_exec_cmd(bus, val); break; } --=20 2.26.2 From nobody Sun May 19 04:05:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595568501; cv=none; d=zohomail.com; s=zohoarc; b=D57W5LUfKcr3aoATcYgBwqpkkPT3+08XpL+83TlRDe6vG+M26UZkcZIIAVrZoE+aIzmCQLhym8YTA13bPwdtOyrx6ax33ywA1/cO5oZ/PtWBckB5rTrDZOnQFd+UtePWckqyjmjHyWYv58n+ngbfTPbf/ZKO0GGYn9PvrC7lrjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595568501; h=Content-Type: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=lw3sIMw7bwLzLn8HrEwoFK0CDMSMemR+m8VLVz6kxxc=; b=C7xQrsJs9WexX4NqrLYd/U9ooOhoOMgvvf54Y57HwXVr3vavYZtvRFK2Yb+9y7XJVnXJ8VOsO2IULXxHO7zlDzV2mLyHKtQnSFluyB5uCMgsTs3CpQuhYVHHEF1oJteZ51Qx4TisV4FMtjJnxqTtC8BsN94y6rpjAtV250E24oc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595568501374691.2715362935068; Thu, 23 Jul 2020 22:28:21 -0700 (PDT) Received: from localhost ([::1]:57156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyqFo-0007yH-63 for importer@patchew.org; Fri, 24 Jul 2020 01:28:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyqAv-0001B2-Cd for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:17 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55685 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyqAt-0007Ta-Cb for qemu-devel@nongnu.org; Fri, 24 Jul 2020 01:23:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-SYtFfmeTPdikeFqDmzCSbg-1; Fri, 24 Jul 2020 01:23:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04CAD189CEE0; Fri, 24 Jul 2020 05:23:09 +0000 (UTC) Received: from ibm-p8-OVS-01-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FFA7AC94; Fri, 24 Jul 2020 05:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595568194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lw3sIMw7bwLzLn8HrEwoFK0CDMSMemR+m8VLVz6kxxc=; b=WB1ys1+RjykSH6d1gLjC+M8XgntkIZiQGsvrFhnjh9XDMUL+bVqsMdlqBfqEp6ELxahoO0 2jiZ+gGbvjB5f8UbRQ19Ot3zA0pL3iNSOJBfRLyYOroN6gi3hLDS9R0hUo0nMLwo0hCzYD eoZRTTef4S8jV43cTRIqk7aBe71olaI= X-MC-Unique: SYtFfmeTPdikeFqDmzCSbg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 7/7] ide: cancel pending callbacks on SRST Date: Fri, 24 Jul 2020 01:23:00 -0400 Message-Id: <20200724052300.1163728-8-jsnow@redhat.com> In-Reply-To: <20200724052300.1163728-1-jsnow@redhat.com> References: <20200724052300.1163728-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 00:01:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Alexander Bulekov , John Snow , qemu-block@nongnu.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The SRST implementation did not keep up with the rest of IDE; it is possible to perform a weak reset on an IDE device to remove the BSY/DRQ bits, and then issue writes to the control/device registers which can cause chaos with the state machine. Fix that by actually performing a real reset. Reported-by: Alexander Bulekov Fixes: https://bugs.launchpad.net/qemu/+bug/1878253 Fixes: https://bugs.launchpad.net/qemu/+bug/1887303 Fixes: https://bugs.launchpad.net/qemu/+bug/1887309 Signed-off-by: John Snow --- hw/ide/core.c | 58 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index e4c69a7fde..4da689abdf 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2241,6 +2241,37 @@ uint32_t ide_status_read(void *opaque, uint32_t addr) return ret; } =20 +static void ide_perform_srst(IDEState *s) +{ + s->status |=3D BUSY_STAT; + + /* Halt PIO (Via register state); PIO BH remains scheduled. */ + ide_transfer_halt(s); + + /* Cancel DMA -- may drain block device and invoke callbacks */ + ide_cancel_dma_sync(s); + + /* Cancel PIO callback, reset registers/signature, etc */ + ide_reset(s); + + if (s->drive_kind =3D=3D IDE_CD) { + /* ATAPI drives do not set READY or SEEK */ + s->status =3D 0x00; + } +} + +static void ide_bus_perform_srst(void *opaque) +{ + IDEBus *bus =3D opaque; + IDEState *s; + int i; + + for (i =3D 0; i < 2; i++) { + s =3D &bus->ifs[i]; + ide_perform_srst(s); + } +} + void ide_ctrl_write(void *opaque, uint32_t addr, uint32_t val) { IDEBus *bus =3D opaque; @@ -2249,26 +2280,17 @@ void ide_ctrl_write(void *opaque, uint32_t addr, ui= nt32_t val) =20 trace_ide_ctrl_write(addr, val, bus); =20 - /* common for both drives */ - if (!(bus->cmd & IDE_CTRL_RESET) && - (val & IDE_CTRL_RESET)) { - /* reset low to high */ - for(i =3D 0;i < 2; i++) { + /* Device0 and Device1 each have their own control register, + * but QEMU models it as just one register in the controller. */ + if ((bus->cmd & IDE_CTRL_RESET) && + !(val & IDE_CTRL_RESET)) { + /* SRST triggers on falling edge */ + for (i =3D 0; i < 2; i++) { s =3D &bus->ifs[i]; - s->status =3D BUSY_STAT | SEEK_STAT; - s->error =3D 0x01; - } - } else if ((bus->cmd & IDE_CTRL_RESET) && - !(val & IDE_CTRL_RESET)) { - /* high to low */ - for(i =3D 0;i < 2; i++) { - s =3D &bus->ifs[i]; - if (s->drive_kind =3D=3D IDE_CD) - s->status =3D 0x00; /* NOTE: READY is _not_ set */ - else - s->status =3D READY_STAT | SEEK_STAT; - ide_set_signature(s); + s->status |=3D BUSY_STAT; } + aio_bh_schedule_oneshot(qemu_get_aio_context(), + ide_bus_perform_srst, bus); } =20 bus->cmd =3D val; --=20 2.26.2