From nobody Sat Nov 15 17:47:13 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1748282846; cv=none; d=zohomail.com; s=zohoarc; b=gjU0XQ0mpjR8vhzMPE0eeUc9196VY7WGZkCTLey++4o1AeJq7yKpt/ABcfoeAnyaJb78BQyU2Q+8qjMFlmS7+QCTiDLZQyqLxkvcF2zt+Wtnge3JPOBFLZ0a/ErEgxV4Nr4rNLAK3joWT9gjXwD9v/cRA3NpEFguph8tJw2lfeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748282846; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NhBBZquPEa6qQqozAiO207w2d4gpZ5Cgam5MtutTPKg=; b=bSyzOCuHp0DAgk7Sj+KzXksznqBPBoDXOxlVQOEOeCGkAPbjAP1SPXeu6ujVGjqDmEeJMHk9TLn2CGz2jidek9gP+RTVUm8v682ifSR24OlNtkhGmZTOiofsi+goSEamj7Bsj3Nq3MLRVIApCyPiU+GGyGA4w+2eeCFZF/a9QNs= 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 1748282846232705.5530179830461; Mon, 26 May 2025 11:07:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJcDn-0003QW-Bx; Mon, 26 May 2025 14:06:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uJcDB-00035v-B2 for qemu-devel@nongnu.org; Mon, 26 May 2025 14:06:12 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uJcD8-0004p2-SZ for qemu-devel@nongnu.org; Mon, 26 May 2025 14:06:08 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-43cf257158fso21645195e9.2 for ; Mon, 26 May 2025 11:06:06 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4cfbf2644sm7294056f8f.59.2025.05.26.11.06.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 May 2025 11:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1748282765; x=1748887565; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NhBBZquPEa6qQqozAiO207w2d4gpZ5Cgam5MtutTPKg=; b=qyxctcRiDPUZgc5HL8+M4RLu9f0ddjKLxiQx5nkBSnBK/i1b/MU+owDadwfc6+hFTV wIYunoeDxge5BoVPfsDKo97RhF/X0pqbs8rovI32mnuCtEE4PTjIS0PVeZ0hfenPWOAW unZmPj8NJPPcXxcl/c4MoBcV8CPU07l/X0JgXoodf700COYczbVUal6eVsEQVQzAsuCD DAo6oxJjac35OqcMhszwdD5F4YjSIlXkp5p7bZ/65bMkyRTGGp75lBfVkr90R9Ium6xV LdttSo7613/0UuMWlU5nFA0nnHD3ADhjNNI9wqHD6Oi1W8Pv6RORMX04FLR0ezN9xBn4 NMOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748282765; x=1748887565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NhBBZquPEa6qQqozAiO207w2d4gpZ5Cgam5MtutTPKg=; b=hqOllDvvS4oqPo4v3HZzGu2fzUzmkuAGEp5tCTzYYq9DF9M9CWSM4CXJc3pONA6oyZ FEL1aXoPG/JB8mhyuURsa46IPt9WumBp16GyF+JJIASPdS0zwJEwpj9iRMDUMn7AewWm ff728LGg+7HUogLdbL881snG8ROJpRwrAR511oqK02LptFnx+WTzxHlUNimI35pbqM1X 4axwHKxLzXe6Fvcn6ZHfUQ4aF7f9kE7cHnB931Z84IFMh34s1FNPr9G6eDlHxOWtc1cH rIFX+gBEDU2JRHUYzJc+Ty9sb7Q5KS16Bes34UVgJJ9MPhZkN3ov72gpRr8mktB0+ZiG 8BVw== X-Gm-Message-State: AOJu0Yxk3WiqWfLTsjyrQokklhTdM9v9u07dHZ2jafCanOCYWEUt7V6N 2/d+UXS8MpL031nOgsVN6YEA4Q+y7mmz6i6KLIlGCMoK6ifkrJ81k/w6fywCMRR3GqCy/+Ltj5D /0jQfydY= X-Gm-Gg: ASbGncvJ4/siS1DwjY/um66PO6IwdIk4BS8qCCv6uXslAbacpafCP6sbFJ8xNAuQ82l 6sD80EAkMlzmqgiHfP6j1RMw4iXrr0jO5RUnuzesruGC1HsvkgDYxtaRwV60NZiChsXSw2ikyol QTnAqh7T/c2PLCGwsuClVXUCnInKiLJeRU5CRb44/ZnbouPPiL49MntzTCDw6QGluxMvg4yFRB6 oAYn4Kx3iMIgsbGhi3cYWQAP3pRIUqRnb2Iq3nIsfGpvrqOfa90rUFIpeSoHZsUZ/FIl950lxRM mEDt2M6sZIICLSvP++O9gFo+LG3YYxQnwUvqYt0gYMbhXwtQyItL+YioBJJcRF0LyXG8bYx2Eca R8XtUpbcNvr6kuGuuwboguHgRZcpvsZI= X-Google-Smtp-Source: AGHT+IG3/bXEOeWaouYhu1+H8iDVpJgTeEJK125Fkr72MMn8pa2fC+Va1h7OyrcGZjk0j/4YBwE5fQ== X-Received: by 2002:a05:600c:1f91:b0:43c:ea1a:720a with SMTP id 5b1f17b1804b1-44c9301659dmr75581475e9.1.1748282765013; Mon, 26 May 2025 11:06:05 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: John Snow , Gerd Hoffmann , Jiaxun Yang , Laurent Vivier , qemu-block@nongnu.org, Fabiano Rosas , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 1/2] hw/ide/ahci: Introduce ahci_reset_delayed() and ahci_reset_complete() Date: Mon, 26 May 2025 20:05:57 +0200 Message-ID: <20250526180558.65613-2-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250526180558.65613-1-philmd@linaro.org> References: <20250526180558.65613-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1748282848044116600 AHCI reset is not instantaneous in physical world, and software might poll the reset bits of port and host control registers to detect completion (see chapter 14 of AHCI spec). In preparation of adding a timed reset, split ahci_reset() as ahci_reset_delayed() which keeps the reset bits and ahci_reset_complete() which resets them. No logical changes so far. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/ide/ahci.c | 31 ++++++++++++++++++++++++++++--- hw/ide/trace-events | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 1303c21cb70..7e586c7a0a4 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -46,6 +46,7 @@ static bool ahci_map_clb_address(AHCIDevice *ad); static bool ahci_map_fis_address(AHCIDevice *ad); static void ahci_unmap_clb_address(AHCIDevice *ad); static void ahci_unmap_fis_address(AHCIDevice *ad); +static void ahci_reset_delayed(AHCIState *s, bool immediate); =20 static const char *AHCIHostReg_lookup[AHCI_HOST_REG__COUNT] =3D { [AHCI_HOST_REG_CAP] =3D "CAP", @@ -1623,7 +1624,22 @@ void ahci_uninit(AHCIState *s) g_free(s->dev); } =20 -void ahci_reset(AHCIState *s) +static void ahci_reset_complete(void *opaque) +{ + AHCIState *s =3D opaque; + + trace_ahci_reset_done(s); + + for (unsigned i =3D 0; i < s->ports; i++) { + AHCIPortRegs *pr; + + pr =3D &s->dev[i].port_regs; + pr->cmd &=3D ~PORT_CMD_LIST_ON; + } + s->control_regs.ghc &=3D ~HOST_CTL_RESET; +} + +static void ahci_reset_delayed(AHCIState *s, bool immediate) { AHCIPortRegs *pr; int i; @@ -1639,16 +1655,25 @@ void ahci_reset(AHCIState *s) * * We set HOST_CAP_AHCI so we must enable AHCI at reset. */ - s->control_regs.ghc =3D HOST_CTL_AHCI_EN; + s->control_regs.ghc =3D HOST_CTL_RESET | HOST_CTL_AHCI_EN; =20 for (i =3D 0; i < s->ports; i++) { pr =3D &s->dev[i].port_regs; pr->irq_stat =3D 0; pr->irq_mask =3D 0; pr->scr_ctl =3D 0; - pr->cmd =3D PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON; + pr->cmd =3D PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON | PORT_CMD_LIST_O= N; ahci_reset_port(s, i); } + + if (immediate) { + ahci_reset_complete(s); + } +} + +void ahci_reset(AHCIState *s) +{ + ahci_reset_delayed(s, false); } =20 static const VMStateDescription vmstate_ncq_tfs =3D { diff --git a/hw/ide/trace-events b/hw/ide/trace-events index 57042cafddc..979145c58b8 100644 --- a/hw/ide/trace-events +++ b/hw/ide/trace-events @@ -82,6 +82,7 @@ ahci_mem_write_host(void *s, unsigned size, const char *r= eg, uint64_t addr, uint ahci_mem_write_unimpl(void *s, unsigned size, uint64_t addr, uint64_t val)= "ahci(%p): write%u to unknown register 0x%"PRIx64": 0x%016"PRIx64 ahci_set_signature(void *s, int port, uint8_t nsector, uint8_t sector, uin= t8_t lcyl, uint8_t hcyl, uint32_t sig) "ahci(%p)[%d]: set signature sector:= 0x%02x nsector:0x%02x lcyl:0x%02x hcyl:0x%02x (cumulatively: 0x%08x)" ahci_reset_port(void *s, int port) "ahci(%p)[%d]: reset port" +ahci_reset_done(void *s) "ahci(%p): reset done" ahci_unmap_fis_address_null(void *s, int port) "ahci(%p)[%d]: Attempt to u= nmap NULL FIS address" ahci_unmap_clb_address_null(void *s, int port) "ahci(%p)[%d]: Attempt to u= nmap NULL CLB address" ahci_populate_sglist(void *s, int port) "ahci(%p)[%d]" --=20 2.47.1 From nobody Sat Nov 15 17:47:13 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1748282834; cv=none; d=zohomail.com; s=zohoarc; b=FfVppqANzFCdNx9Y8vYLOLTz7hNv3+N1pG/hMB/lhmWZ5elYZnnCQWuENrpfDRnUIWxGy5uTL74oQ73oIr0z1I/1hq+IQNyvZRlbb+QLm9wb+/lvsk3UKy8RZrRRZKN5q8M+qV3nFLYGD2RJ4YZH5o4jERPvewpDLYaxpeMCAkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748282834; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PK/3BMMw+rPIcEuLbLBqAtKj1UfFQt8uO08FuIUDDYU=; b=eLiZH7ZftyX/FKW5OGme9gyuAl8X6X1DeDyuRT1AUS9iPeu9YTjZD5mA7VwvuziZzkVHBFO1JZfu6gMzr/s1YrlWVoTxOHKWoWQxgWLcOdHtrVI6DsO52JM3fCXPWUOFRrhcVrOxuVeGm6Ta8NxdfXTeC7VKSX6bStdPyNDfb30= 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 1748282834629706.9808136352435; Mon, 26 May 2025 11:07:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uJcDd-0003H1-9F; Mon, 26 May 2025 14:06:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uJcDF-00036e-Eg for qemu-devel@nongnu.org; Mon, 26 May 2025 14:06:14 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uJcDD-0004pq-I6 for qemu-devel@nongnu.org; Mon, 26 May 2025 14:06:13 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so33095665e9.3 for ; Mon, 26 May 2025 11:06:11 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4dc1172ecsm2684499f8f.48.2025.05.26.11.06.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 May 2025 11:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1748282770; x=1748887570; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PK/3BMMw+rPIcEuLbLBqAtKj1UfFQt8uO08FuIUDDYU=; b=WX5uySL2yP1hyPrlTDYUz2KpXgw21GQ4jBsaaxabLmSsZOvAFzqNZvL9AemyKnuiIg rLrR39zpaFma5+pq93atf6qZPOTc4G/5hSm2LqW9timAoZ2WBPafNz12w20/i4QGJeg1 LWLNyPBnFfPtHoM6h+vo2GsMLDffqho3Qj5Tbe79tIeK9PWB/BIw0dK40YDirhs4WBOu DiicblP6t0h+1DxGyWOVBr7TTPU9gZFVohO2Huv5sqrgCn9KHDcYIxGd0rX8/9AVBPAV Ldc+ioinmZ4IMrA5XXHX7fLbWGebH3+wY6O9M9kPJEJ4VK5Z2i3uI8pvouPicEHOaO3V NJ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748282770; x=1748887570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PK/3BMMw+rPIcEuLbLBqAtKj1UfFQt8uO08FuIUDDYU=; b=aBZWL1GkGr3VD/4IbrMCCIn1iVv57ev7RQ9HlmekAgk9cse7FW4fw4x3GXC7H2X+xt C/Ys7UxBgS1HmAqt3shZLYJMn8XphIphWSnYFEyeyoQdJxo2XRliyvcHfUaUYSUg27CW k9sAYQJnluRfaExSOlJVMBkwX1NC0LhpxZXQJTRgVNdAYSHNCbcLF0TDN6sNmee7ijEt +6c3B8YlP8WHIWHi1UCVxI6tcSqKhohnHuSTDnErqEujYOQ0IzaOlYJ7BCiAYfnXzHlB uaFPeWF0EcttzMy56e1ISfHbwN09cZ5N4hoFJcCGLB/OHZV6WBmGB92CP3q5g2uEUabA N2FA== X-Gm-Message-State: AOJu0Yy17OSIbQq1UXB/7zqH0Y6W76c50DPho4HelDSeWgqMFSGHnx6x Eej2sr0m4MM8g8qfmpNXX6Y6CopjLLHOm1f7rnKKaUoxFqi1ncdEWje4shi5Vkl1XRXgqGpAVYM UzgHwdxQ= X-Gm-Gg: ASbGnctdJhd0zv67JQ+2WPkWFnLRo8jwTVEEFF+Fy3EqhF0Rj9JL+O7iSbKoFOFISf5 XyrnIxaX+/9zDGa51KIZjbXLXBCMcyjFhmqw5KsXkCa7sNNwWTYeylDhFdFn09EY4WOAUO90CiZ xnJwadgYiLGuOBOs+U2eRM6W7WulZ61h5R73IHGOF/6cy8obt+EfjBRYjC0aYJXSmdMhpGeFBMM z5xD1DCG5mAuQKMjyiSArxkoVcjBfuiOTsnuX89wCAG5irPyaDIey1fIPIvhhYxXp5QchMmkfFN 23jY6MfHcbszcLDTUjbS/AQiWeD5KI4xYjlNy46Risms5Xz2Ygy0aM1YHXLcgI8jFgEQcHSKIeL XvBPWe93zHAA1QDeIWkjk5aJs1RGGZWc= X-Google-Smtp-Source: AGHT+IEct3U0VqUxCmKQNa7qLZzBiVK1+v0jtdEL0TFxPrlTrutfbCQicw8/ql0Dt31GE8hxRz2aig== X-Received: by 2002:a05:600c:4fd6:b0:43d:b85:1831 with SMTP id 5b1f17b1804b1-44c91bce747mr94158155e9.0.1748282769815; Mon, 26 May 2025 11:06:09 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: John Snow , Gerd Hoffmann , Jiaxun Yang , Laurent Vivier , qemu-block@nongnu.org, Fabiano Rosas , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 2/2] hw/ide/ahci: Delay a bit before completing reset Date: Mon, 26 May 2025 20:05:58 +0200 Message-ID: <20250526180558.65613-3-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250526180558.65613-1-philmd@linaro.org> References: <20250526180558.65613-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1748282835967116600 Give few milliseconds to (emulated) hardware to complete its reset sequence. The intent is to have this model better match hardware, reducing firmware bugs "works in QEMU but not in real world" such https://github.com/FlyGoat/csmwrap/issues/14. Reported-by: Jiaxun Yang Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/ide/ahci.h | 1 + hw/ide/ahci.c | 39 +++++++++++++++++++++++++++++++++++++-- tests/qtest/ahci-test.c | 4 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/hw/ide/ahci.h b/include/hw/ide/ahci.h index cd07b87811b..82617835195 100644 --- a/include/hw/ide/ahci.h +++ b/include/hw/ide/ahci.h @@ -46,6 +46,7 @@ typedef struct AHCIState { uint32_t ports; qemu_irq irq; AddressSpace *as; + QEMUTimer *reset_timer; } AHCIState; =20 =20 diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 7e586c7a0a4..cf1c5d3f3db 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -28,6 +28,7 @@ #include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/main-loop.h" +#include "qemu/timer.h" #include "system/block-backend.h" #include "system/dma.h" #include "ahci-internal.h" @@ -47,6 +48,7 @@ static bool ahci_map_fis_address(AHCIDevice *ad); static void ahci_unmap_clb_address(AHCIDevice *ad); static void ahci_unmap_fis_address(AHCIDevice *ad); static void ahci_reset_delayed(AHCIState *s, bool immediate); +static void ahci_reset_complete(void *opaque); =20 static const char *AHCIHostReg_lookup[AHCI_HOST_REG__COUNT] =3D { [AHCI_HOST_REG_CAP] =3D "CAP", @@ -459,7 +461,7 @@ static void ahci_mem_write(void *opaque, hwaddr addr, break; case AHCI_HOST_REG_CTL: /* R/W */ if (val & HOST_CTL_RESET) { - ahci_reset(s); + ahci_reset_delayed(s, true); } else { s->control_regs.ghc =3D (val & 0x3) | HOST_CTL_AHCI_EN; ahci_check_irq(s); @@ -1591,6 +1593,7 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, Ad= dressSpace *as) s->as =3D as; assert(s->ports > 0); s->dev =3D g_new0(AHCIDevice, s->ports); + s->reset_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, ahci_reset_complet= e, s); ahci_reg_init(s); irqs =3D qemu_allocate_irqs(ahci_irq_set, s, s->ports); for (i =3D 0; i < s->ports; i++) { @@ -1622,8 +1625,12 @@ void ahci_uninit(AHCIState *s) } =20 g_free(s->dev); + + timer_free(s->reset_timer); } =20 +#define AHCI_RESET_DELAY_MS 69 /* Arbitrary value less than 500 ms */ + static void ahci_reset_complete(void *opaque) { AHCIState *s =3D opaque; @@ -1667,7 +1674,11 @@ static void ahci_reset_delayed(AHCIState *s, bool im= mediate) } =20 if (immediate) { + timer_del(s->reset_timer); ahci_reset_complete(s); + } else if (!timer_pending(s->reset_timer)) { + timer_mod(s->reset_timer, + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + AHCI_RESET_DELAY= _MS); } } =20 @@ -1676,6 +1687,24 @@ void ahci_reset(AHCIState *s) ahci_reset_delayed(s, false); } =20 +static bool ahci_timer_needed(void *opaque) +{ + AHCIState *s =3D opaque; + + return timer_pending(s->reset_timer); +} + +static const VMStateDescription vmstate_ahci_timer =3D { + .name =3D "ahci/reset_timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D ahci_timer_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_TIMER_PTR(reset_timer, AHCIState), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_ncq_tfs =3D { .name =3D "ncq state", .version_id =3D 1, @@ -1734,7 +1763,9 @@ static int ahci_state_post_load(void *opaque, int ver= sion_id) ad =3D &s->dev[i]; pr =3D &ad->port_regs; =20 - if (!(pr->cmd & PORT_CMD_START) && (pr->cmd & PORT_CMD_LIST_ON)) { + if (timer_pending(s->reset_timer)) { + /* Reset in progress */ + } else if (!(pr->cmd & PORT_CMD_START) && (pr->cmd & PORT_CMD_LIST= _ON)) { error_report("AHCI: DMA engine should be off, but status bit " "indicates it is still running."); return -1; @@ -1823,6 +1854,10 @@ const VMStateDescription vmstate_ahci =3D { VMSTATE_UINT32_EQUAL(ports, AHCIState, NULL), VMSTATE_END_OF_LIST() }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_ahci_timer, + NULL + } }; =20 void ahci_ide_create_devs(AHCIState *ahci, DriveInfo **hd) diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index e8aabfc13f5..4389aaa7f70 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -40,6 +40,8 @@ #define TEST_IMAGE_SIZE_MB_LARGE (200 * 1024) #define TEST_IMAGE_SIZE_MB_SMALL 64 =20 +#define AHCI_RESET_TIMEOUT_NS (500 * 1000 * 1000) + /*** Globals ***/ static char *tmp_path; static char *debug_path; @@ -483,6 +485,8 @@ static void ahci_test_hba_spec(AHCIQState *ahci) =20 g_assert(ahci !=3D NULL); =20 + qtest_clock_step(ahci->parent->qts, AHCI_RESET_TIMEOUT_NS); + /* * Note that the AHCI spec does expect the BIOS to set up a few things: * CAP.SSS - Support for staggered spin-up (t/f) --=20 2.47.1