From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297185; cv=none; d=zohomail.com; s=zohoarc; b=ZgS/PD4g8eQgYncl4dWCQ2KhpWGuitimhBVLGT40O2Jj6RoIEQu96BHds6JgHtH0X4t+gOqeonhyoTYKAgwdwMz/8xdoLRFg5CXgey4ThyLhVfH1pDMDdKx2KAF3fleoDN+CzxwtLXMCNnlAFu5zB20nPYzpNyKnJV696ulWcXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297185; 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=vFYjc7YVo0itqqG99xSbqJsZWQQt3LKzCURmx3+uSc4=; b=b5MFhNy66XkDd/kj++/3lteswnrUmu7RJlFnAN0rKdeSolPsBpeBk6DH4C7DyzAQSxfWrxnTRvjZ1kUZYGfNOGh/L8rG52ZrnCwyy0Nl3kXg6KNiH95SLLi4XwqcdrFBvOCe296OrUwStVLoIy2KugYCaq2l+Kcy9G36MWzyG8o= 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 1676297185255102.65489769505484; Mon, 13 Feb 2023 06:06:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZOy-0006gs-4z; Mon, 13 Feb 2023 09:01:52 -0500 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 1pRZOT-0006ap-H1 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:21 -0500 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOQ-0005s7-Rj for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:21 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id D761F5EC2E; Mon, 13 Feb 2023 17:01:12 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-8qvll5zk; Mon, 13 Feb 2023 17:01:12 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296872; bh=vFYjc7YVo0itqqG99xSbqJsZWQQt3LKzCURmx3+uSc4=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=1m1EbienoBxPlvc/Tn4q67SrnuqsbUn0l1Zu/Xn1R1aapl53i1NgUhtKw++ieCKRe Ono91m/ikRsrIvjeRsOJO17R4oFUaXgbrg1/nx+u6rSBd4tLz45sQ5Enm2dtJ44ggO T1nmDzCqRZYyt0hLZSA4VlFSP481R9j+r9VlFTm8= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 01/16] pci/shpc: set attention led to OFF on reset Date: Mon, 13 Feb 2023 17:00:48 +0300 Message-Id: <20230213140103.1518173-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297186826100003 Content-Type: text/plain; charset="utf-8" 0 is not a valid state for the led. Let's start with OFF. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/shpc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index fca7f6691a..1b3f619dc9 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -223,6 +223,7 @@ void shpc_reset(PCIDevice *d) SHPC_SLOT_STATUS_PRSNT_MASK); shpc_set_status(shpc, i, SHPC_LED_OFF, SHPC_SLOT_PWR_LED_MASK); } + shpc_set_status(shpc, i, SHPC_LED_OFF, SHPC_SLOT_ATTN_LED_MASK); shpc_set_status(shpc, i, 0, SHPC_SLOT_STATUS_66); } shpc_set_sec_bus_speed(shpc, SHPC_SEC_BUS_33); --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297059; cv=none; d=zohomail.com; s=zohoarc; b=IBQBoVa5OEjrO/R0jzra6m3bKMwuI7KQrkk+u+5Ol3i1QIyRezj8qCkEDe/6afu0yie3bqi9CCdGaI6BnEPg9CW85rB7aIP3bssKklkR4cT18pQiEBXk7yKu8RmFxJTDKRXQNCDn9aDWRxjntjlTD73/54f9hhMVGNM2fdm8GSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297059; 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=g9E6WR0ER8a6iXcBVUsc2UOZl2HDibzW91Aa8C7mtlI=; b=eOLamLlq3SCNtL7wl0dVOTjv8tiNa4J5Pu0DpHsnkZg+mt/4GWIeeLSUMJ5hXfEqd2coCP0ZGX6D2X0NzUVBcVzmYUnYNw2fPkundhzT4ex8LyydGPfGl8ZQ7CtMn1GDK6bgF90/n92THlIiGiqLmUR3cgUmjLBS3BdaD2tR4Mk= 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 1676297059299596.4961854026019; Mon, 13 Feb 2023 06:04:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZOm-0006d1-JJ; Mon, 13 Feb 2023 09:01:42 -0500 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 1pRZOT-0006an-Bg for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:21 -0500 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOQ-0005sJ-PC for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:21 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id D6E595ED6F; Mon, 13 Feb 2023 17:01:13 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-mBo3N82L; Mon, 13 Feb 2023 17:01:13 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296873; bh=g9E6WR0ER8a6iXcBVUsc2UOZl2HDibzW91Aa8C7mtlI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=aVMeaDfl2MoPSXpBAtE8k2HV50a2mjqxgkn6pjz/90BhnzUVpPYImQWeVSinhg1mA gbV3TyaQDYnL221FgQSFUr6erzGklDjs7ZLaRzsmBptHu8lUWqPWmrr55D8SP+laO9 GXim9irVZWkTkXFXEplCdcXqtOBKlo4xaAZkZnoY= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 02/16] pci/shpc: change shpc_get_status() return type to uint8_t Date: Mon, 13 Feb 2023 17:00:49 +0300 Message-Id: <20230213140103.1518173-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297061122100001 Content-Type: text/plain; charset="utf-8" The result of the function is always one byte. The result is always assigned to uint8_t variable. Also, shpc_get_status() should be symmetric to shpc_set_status() which has uint8_t value argument. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/shpc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 1b3f619dc9..5d71569b13 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -123,10 +123,13 @@ #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1) #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1) =20 -static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk) +static uint8_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk) { uint8_t *status =3D shpc->config + SHPC_SLOT_STATUS(slot); - return (pci_get_word(status) & msk) >> ctz32(msk); + uint16_t result =3D (pci_get_word(status) & msk) >> ctz32(msk); + + assert(result <=3D UINT8_MAX); + return result; } =20 static void shpc_set_status(SHPCDevice *shpc, --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676296968; cv=none; d=zohomail.com; s=zohoarc; b=NEE8prw9wBm6d37jCNb0NxxuvikfY5XwGKE1Bx56+y0GB25MtWl2sl7WvQby2omE4PYnyAZ9dKx4i1St7gP2lSn45O7qFYlrVdK8vTRhoeXjEvhcH18/WN59f+e3beWGmsz9Co58WP1l8EOWAiS64ultrrXL/zL0KtARTce+w50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676296968; 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=MMa6nDioTx3cGuqWVQFeRTH8JsSLdlX2olYFCTFUFVU=; b=X3RY4tpmRzmhrc+iXk1cXudAHKbCLWU6WG+e/GwfGEg1pX+mfgr+x0zHONWepLdie4ISeu/Nb0Fs5XC3ZiUdZE0OHKge8Ul3h3HA8AEeC1qxB0zsR6QAgKkH2Xcqkn7FBCKy7esZYMjp5JUBYwNUnBXJ7cGofD1YhGxWuA2CGkY= 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 1676296968339483.4726134936817; Mon, 13 Feb 2023 06:02:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZP0-0006iP-0E; Mon, 13 Feb 2023 09:01:54 -0500 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 1pRZOa-0006bh-CN for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:37 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOS-0005sc-Op for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:22 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id E6AA061FE4; Mon, 13 Feb 2023 17:01:14 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-Pk3iS5Sf; Mon, 13 Feb 2023 17:01:14 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296874; bh=MMa6nDioTx3cGuqWVQFeRTH8JsSLdlX2olYFCTFUFVU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ar4JmQqCNaPSNzGu8uszabpp0+w+3M+tHqQZ3VGDaDS+R3wxQmhpyu3XGyHcQ+ZpV WJb6KGJoNmEc2bKAVbaBqX1A5vp3UcxxMmxTS4uiM7iujwfo5ZluoSDnQqPytJxdbz efmfXFMhPyYBJ5/GysPI7Xm/Cs+UtHXHbDyPfYH0= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 03/16] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Date: Mon, 13 Feb 2023 17:00:50 +0300 Message-Id: <20230213140103.1518173-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676296994161100001 Content-Type: text/plain; charset="utf-8" ENABLED -> PWRONLY transition is not allowed and we handle it by shpc_invalid_command(). But PWRONLY -> ENABLED transition is silently ignored, which seems wrong. Let's handle it as correct. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/shpc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 5d71569b13..25e4172382 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -273,28 +273,22 @@ static void shpc_slot_command(SHPCDevice *shpc, uint8= _t target, return; } =20 - switch (power) { - case SHPC_LED_NO: - break; - default: + if (power !=3D SHPC_LED_NO) { /* TODO: send event to monitor */ shpc_set_status(shpc, slot, power, SHPC_SLOT_PWR_LED_MASK); } - switch (attn) { - case SHPC_LED_NO: - break; - default: + if (attn !=3D SHPC_LED_NO) { /* TODO: send event to monitor */ shpc_set_status(shpc, slot, attn, SHPC_SLOT_ATTN_LED_MASK); } - - if ((current_state =3D=3D SHPC_STATE_DISABLED && state =3D=3D SHPC_STA= TE_PWRONLY) || - (current_state =3D=3D SHPC_STATE_DISABLED && state =3D=3D SHPC_STA= TE_ENABLED)) { - shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK); - } else if ((current_state =3D=3D SHPC_STATE_ENABLED || - current_state =3D=3D SHPC_STATE_PWRONLY) && - state =3D=3D SHPC_STATE_DISABLED) { + if (state !=3D SHPC_STATE_NO) { shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK); + } + + if ((current_state =3D=3D SHPC_STATE_ENABLED || + current_state =3D=3D SHPC_STATE_PWRONLY) && + state =3D=3D SHPC_STATE_DISABLED) + { power =3D shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK); /* TODO: track what monitor requested. */ /* Look at LED to figure out whether it's ok to remove the device.= */ --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676296929; cv=none; d=zohomail.com; s=zohoarc; b=i8y2Gk49bL83kTfBA/qdYETTfhU8ZVd2beF3iyt0z7WZ+AXzeTXbji4mrAEBWzMe+N+wM5LSWUsH/YgVw+pqVo+TG7TFFIz/+tiDUEHQeLVehAMD2fiDvvq7y3QoVZW+sz3anLOTKij+9RpzMfMCIUupvoYTmB8JO8XV2KZ2blQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676296929; 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=Ofg0z5A6EVb25euaqITm+xboRrJRtcaO1cNMbngTL1Q=; b=EhoctuYsnef55cLZ0q89WzYaW/cbbMjRnNBgX1d/aHGqrwLKm6hfcUU+LFI6HMwYhMdyRJFwWpnkBtCVkoXSlhOVu/yMXOVcTNSPjUYJZ6695fF5buLcH7pbGVnsvezHOuLACAE4t3AUEoeYf7+EynbBsMeLrs4/hz7ZQ+M7t00= 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 1676296929063158.02327312304737; Mon, 13 Feb 2023 06:02:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZP1-0006iR-Fx; Mon, 13 Feb 2023 09:01:55 -0500 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 1pRZOa-0006bg-CX for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:37 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOS-0005sj-VO for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:22 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 015BC6149F; Mon, 13 Feb 2023 17:01:16 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-wmpjGa0s; Mon, 13 Feb 2023 17:01:15 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296875; bh=Ofg0z5A6EVb25euaqITm+xboRrJRtcaO1cNMbngTL1Q=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=l4YnlTJZJGc19dfNB9XfWYVgf1veDeUNWl8f9eHK+CnharkEyNF3KZhHP4L4KgFTJ srizNQ5FfmbO9YRBHR62DrOFVW6XEfPXjcpvgfOwAPsLtamNEijf8aaK1pyFtZ3god vauZiGXDfpagfR6yKEHBlLhqaU9z4NM4RuHCSUmU= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 04/16] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Date: Mon, 13 Feb 2023 17:00:51 +0300 Message-Id: <20230213140103.1518173-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676296956140100001 Content-Type: text/plain; charset="utf-8" Free slot if both conditions (power-led =3D OFF and state =3D DISABLED) becomes true regardless of the sequence. It is similar to how PCIe hotplug works. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/shpc.c | 52 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 25e4172382..959dc470f3 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -258,49 +258,59 @@ static void shpc_free_devices_in_slot(SHPCDevice *shp= c, int slot) } } =20 +static bool shpc_slot_is_off(uint8_t state, uint8_t power, uint8_t attn) +{ + return state =3D=3D SHPC_STATE_DISABLED && power =3D=3D SHPC_LED_OFF; +} + static void shpc_slot_command(SHPCDevice *shpc, uint8_t target, uint8_t state, uint8_t power, uint8_t attn) { - uint8_t current_state; int slot =3D SHPC_LOGICAL_TO_IDX(target); + uint8_t old_state =3D shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK= ); + uint8_t old_power =3D shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MA= SK); + uint8_t old_attn =3D shpc_get_status(shpc, slot, SHPC_SLOT_ATTN_LED_MA= SK); + if (target < SHPC_CMD_TRGT_MIN || slot >=3D shpc->nslots) { shpc_invalid_command(shpc); return; } - current_state =3D shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK); - if (current_state =3D=3D SHPC_STATE_ENABLED && state =3D=3D SHPC_STATE= _PWRONLY) { + + if (old_state =3D=3D SHPC_STATE_ENABLED && state =3D=3D SHPC_STATE_PWR= ONLY) { shpc_invalid_command(shpc); return; } =20 - if (power !=3D SHPC_LED_NO) { + if (power =3D=3D SHPC_LED_NO) { + power =3D old_power; + } else { /* TODO: send event to monitor */ shpc_set_status(shpc, slot, power, SHPC_SLOT_PWR_LED_MASK); } - if (attn !=3D SHPC_LED_NO) { + + if (attn =3D=3D SHPC_LED_NO) { + attn =3D old_attn; + } else { /* TODO: send event to monitor */ shpc_set_status(shpc, slot, attn, SHPC_SLOT_ATTN_LED_MASK); } - if (state !=3D SHPC_STATE_NO) { + + if (state =3D=3D SHPC_STATE_NO) { + state =3D old_state; + } else { shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK); } =20 - if ((current_state =3D=3D SHPC_STATE_ENABLED || - current_state =3D=3D SHPC_STATE_PWRONLY) && - state =3D=3D SHPC_STATE_DISABLED) + if (!shpc_slot_is_off(old_state, old_power, old_attn) && + shpc_slot_is_off(state, power, attn)) { - power =3D shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK); - /* TODO: track what monitor requested. */ - /* Look at LED to figure out whether it's ok to remove the device.= */ - if (power =3D=3D SHPC_LED_OFF) { - shpc_free_devices_in_slot(shpc, slot); - shpc_set_status(shpc, slot, 1, SHPC_SLOT_STATUS_MRL_OPEN); - shpc_set_status(shpc, slot, SHPC_SLOT_STATUS_PRSNT_EMPTY, - SHPC_SLOT_STATUS_PRSNT_MASK); - shpc->config[SHPC_SLOT_EVENT_LATCH(slot)] |=3D - SHPC_SLOT_EVENT_MRL | - SHPC_SLOT_EVENT_PRESENCE; - } + shpc_free_devices_in_slot(shpc, slot); + shpc_set_status(shpc, slot, 1, SHPC_SLOT_STATUS_MRL_OPEN); + shpc_set_status(shpc, slot, SHPC_SLOT_STATUS_PRSNT_EMPTY, + SHPC_SLOT_STATUS_PRSNT_MASK); + shpc->config[SHPC_SLOT_EVENT_LATCH(slot)] |=3D + SHPC_SLOT_EVENT_MRL | + SHPC_SLOT_EVENT_PRESENCE; } } =20 --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297052; cv=none; d=zohomail.com; s=zohoarc; b=JdazKgoyiBugIQpwZMXjuOPVi9nuIo6Q/2zV33bmfiZOpO5fG4N9nNJSz2/N3E1KYvAqn7kjnye1KD0RM868zOLmPGHRkhCzVIm4O2ks7j4Cpra8e7+1WtpBgNimtKKjYtXtKeeu1SBXTVgJ819DUBjbgTtj78hA9Rnf/JdujHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297052; 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=WCjwcGMUVI5gHbUTYAnMwvGBnHHLWrdxrFw5oKOIvEM=; b=aF9pjibQ2+EWFt7EeQj7DDXbAiE3Wu2+ue4sE2/2JgqwmHRtz3TvbjJdXj0UCu/QGOLP46GyYDfPir7GrhoAG8aoitkkopO7/pl4qbryM3hiUnuz/swMBsI4MMoQuP784zu2zF2UX75An0YImi6JCS1XYxwxb0JLJG/SaUDXYn4= 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 1676297052023579.3155647561133; Mon, 13 Feb 2023 06:04:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZOx-0006eW-S8; Mon, 13 Feb 2023 09:01:51 -0500 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 1pRZOk-0006cP-Ha for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:38 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOa-0005t4-1H for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:29 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 224DA62287; Mon, 13 Feb 2023 17:01:17 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-EpK6jA2n; Mon, 13 Feb 2023 17:01:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296876; bh=WCjwcGMUVI5gHbUTYAnMwvGBnHHLWrdxrFw5oKOIvEM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=HflVsyqJRBTiqyBv6GNnvMb7RpxRgGSdil62165p8W08VYTmzTnFApq5jB6HvxhmV tccLZEtFVdu7s45y/gBOCzTL8eptsoYjgfFldlwBjKco+WdOJNYTlWMRdaS4Eq1As/ DU1qWOKNmwFRKcsHtQtDJVC0tVc+bOqjT64xwjuE= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 05/16] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Date: Mon, 13 Feb 2023 17:00:52 +0300 Message-Id: <20230213140103.1518173-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297053351100002 Content-Type: text/plain; charset="utf-8" We'll need it in further patch to report bridge in QAPI event. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/shpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 959dc470f3..9f964b1d70 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -263,9 +263,10 @@ static bool shpc_slot_is_off(uint8_t state, uint8_t po= wer, uint8_t attn) return state =3D=3D SHPC_STATE_DISABLED && power =3D=3D SHPC_LED_OFF; } =20 -static void shpc_slot_command(SHPCDevice *shpc, uint8_t target, +static void shpc_slot_command(PCIDevice *d, uint8_t target, uint8_t state, uint8_t power, uint8_t attn) { + SHPCDevice *shpc =3D d->shpc; int slot =3D SHPC_LOGICAL_TO_IDX(target); uint8_t old_state =3D shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK= ); uint8_t old_power =3D shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MA= SK); @@ -314,8 +315,9 @@ static void shpc_slot_command(SHPCDevice *shpc, uint8_t= target, } } =20 -static void shpc_command(SHPCDevice *shpc) +static void shpc_command(PCIDevice *d) { + SHPCDevice *shpc =3D d->shpc; uint8_t code =3D pci_get_byte(shpc->config + SHPC_CMD_CODE); uint8_t speed; uint8_t target; @@ -336,7 +338,7 @@ static void shpc_command(SHPCDevice *shpc) state =3D (code & SHPC_SLOT_STATE_MASK) >> SHPC_SLOT_STATE_SHIFT; power =3D (code & SHPC_SLOT_PWR_LED_MASK) >> SHPC_SLOT_PWR_LED_SHI= FT; attn =3D (code & SHPC_SLOT_ATTN_LED_MASK) >> SHPC_SLOT_ATTN_LED_SH= IFT; - shpc_slot_command(shpc, target, state, power, attn); + shpc_slot_command(d, target, state, power, attn); break; case 0x40 ... 0x47: speed =3D code & SHPC_SEC_BUS_MASK; @@ -354,10 +356,10 @@ static void shpc_command(SHPCDevice *shpc) } for (i =3D 0; i < shpc->nslots; ++i) { if (!(shpc_get_status(shpc, i, SHPC_SLOT_STATUS_MRL_OPEN))) { - shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN, + shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN, SHPC_STATE_PWRONLY, SHPC_LED_ON, SHPC_LE= D_NO); } else { - shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN, + shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN, SHPC_STATE_NO, SHPC_LED_OFF, SHPC_LED_NO= ); } } @@ -375,10 +377,10 @@ static void shpc_command(SHPCDevice *shpc) } for (i =3D 0; i < shpc->nslots; ++i) { if (!(shpc_get_status(shpc, i, SHPC_SLOT_STATUS_MRL_OPEN))) { - shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN, + shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN, SHPC_STATE_ENABLED, SHPC_LED_ON, SHPC_LE= D_NO); } else { - shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN, + shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN, SHPC_STATE_NO, SHPC_LED_OFF, SHPC_LED_NO= ); } } @@ -410,7 +412,7 @@ static void shpc_write(PCIDevice *d, unsigned addr, uin= t64_t val, int l) shpc->config[a] &=3D ~(val & w1cmask); /* W1C: Write 1 to Clear */ } if (ranges_overlap(addr, l, SHPC_CMD_CODE, 2)) { - shpc_command(shpc); + shpc_command(d); } shpc_interrupt_update(d); } --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676296937; cv=none; d=zohomail.com; s=zohoarc; b=efSbtRM+JhDE/KUMNcA5kjstISTiSVqY4mCnUuQGT9aw3snZ/Zo9uxroqgqXVRBEAmbpEQy5Tg/5pt2EUZ+a1O7qRaGn5QrAi+OtVS2MolhpEXm0R61vx/ZCM/BrfD5Eg+elA+D78ttay8RPQIEsgLxH2/6jmOxlPyePrEZFu2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676296937; 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=RgEs658D23/SZfEQrmRss/oFP2frhSVbYX7RUY+UhHQ=; b=XySlRoyVWHCHtn5SsRJpf04gqa2XL1H0nuupsqh4IuebM3TrmYVV6tkZToH5bnrqchayQ1VItb95+CIMdpKF8zqWugoADydTJtlsJvNLlhliD3MKhi32wTKQg2sF1Cixu7p4DeDcja9SXIx1F3mxTmotATnlkScBP8jd2Fr+oo0= 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 1676296937394395.32567675571; Mon, 13 Feb 2023 06:02:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZOz-0006iQ-W5; Mon, 13 Feb 2023 09:01:54 -0500 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 1pRZOl-0006d3-C6 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:40 -0500 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOa-0005t6-9Y for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:30 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 2A5C25ED7D; Mon, 13 Feb 2023 17:01:18 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-Ayo7CwWJ; Mon, 13 Feb 2023 17:01:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296877; bh=RgEs658D23/SZfEQrmRss/oFP2frhSVbYX7RUY+UhHQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=k3RPeim3JIe6CSLhRiYO6xEgHK+htbqCKNRgp8aKcg1ey5dJVGshroOyV152nCVOy JYFZdFiUdGDA7XBJyLpUsfKeMTaPzibe2E8CXDJBJMvlFNI6RUDPJ9dOsXXniCqRJ7 rrpAty5P8ZF/JrkNQO3V3JlK5wbRsP4WcunS5q6o= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 06/16] pci/shpc: refactor shpc_device_plug_common() Date: Mon, 13 Feb 2023 17:00:53 +0300 Message-Id: <20230213140103.1518173-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676296978792100001 Content-Type: text/plain; charset="utf-8" Rename it to shpc_device_get_slot(), to mention what it does rather than how it is used. It also helps to reuse it in further commit. Also, add a return value and get rid of local_err. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/shpc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 9f964b1d70..e7bc7192f1 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -496,8 +496,9 @@ static const MemoryRegionOps shpc_mmio_ops =3D { .max_access_size =3D 4, }, }; -static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot, - SHPCDevice *shpc, Error **errp) + +static bool shpc_device_get_slot(PCIDevice *affected_dev, int *slot, + SHPCDevice *shpc, Error **errp) { int pci_slot =3D PCI_SLOT(affected_dev->devfn); *slot =3D SHPC_PCI_TO_IDX(pci_slot); @@ -507,21 +508,20 @@ static void shpc_device_plug_common(PCIDevice *affect= ed_dev, int *slot, "controller. Valid slots are between %d and %d.", pci_slot, SHPC_IDX_TO_PCI(0), SHPC_IDX_TO_PCI(shpc->nslots) - 1); - return; + return false; } + + return true; } =20 void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { - Error *local_err =3D NULL; PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); SHPCDevice *shpc =3D pci_hotplug_dev->shpc; int slot; =20 - shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err); - if (local_err) { - error_propagate(errp, local_err); + if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) { return; } =20 @@ -563,16 +563,13 @@ void shpc_device_unplug_cb(HotplugHandler *hotplug_de= v, DeviceState *dev, void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { - Error *local_err =3D NULL; PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); SHPCDevice *shpc =3D pci_hotplug_dev->shpc; uint8_t state; uint8_t led; int slot; =20 - shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err); - if (local_err) { - error_propagate(errp, local_err); + if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) { return; } =20 --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676296994; cv=none; d=zohomail.com; s=zohoarc; b=Uk2JjuwXhq3ms5uc+ZcdVBTuqTsOqKxvjeWIZ40QrVLPDwE05qzoknXS0I6TzIs7tSmKje3mlv3bGXsMzGtUt01X2rjr35N6OoSzaPjEvw2PfVRC9tq7zsf5k8oxZffamr4tM1ZC+SGW22PNqMP5Er+Ewl0I+tWZjIbzs/M1bnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676296994; 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=tBuAo+qSIh9zdCZ4HuXxxfZJD/NOd0omPSnUx98c5so=; b=meHgWBrI7ICyxDqLzGRTs49GWLCdZePnll0+XwvGKAIX/DgFZTvRBh4PaGt0Obmho4gfQmlcG5InB+4wdCKeGPSwBwCgN0fXYu8jLTIGxy6cRLzquEftnooIcoplihKhYWStk3QjbABD/HkXRC7xRB6OivTQVFiQ7pptsad93/0= 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 1676296994134903.1530789204041; Mon, 13 Feb 2023 06:03:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZOx-0006eX-Ub; Mon, 13 Feb 2023 09:01:52 -0500 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 1pRZOk-0006cS-S3 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:40 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOa-0005ts-1M for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:29 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 3BF2362305; Mon, 13 Feb 2023 17:01:19 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-PEdhi0Ot; Mon, 13 Feb 2023 17:01:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296878; bh=tBuAo+qSIh9zdCZ4HuXxxfZJD/NOd0omPSnUx98c5so=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=bMEsVN7akVdFGynrXa1ieAjP8Tkkgblq/gvCxGC43tp8IQt5nfcDBi+QzZgd+uQcW JbqTkK1xmksgYTydL4R2vz5weYzmgOxYqXg7jMbyYCbXpSV+BlM076cG2PLcWFoEza mz0UxM/uIjFhaWM+VcRc0RtxnBB+vegOv/gAxjkU= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 07/16] pcie: pcie_cap_slot_write_config(): use correct macro Date: Mon, 13 Feb 2023 17:00:54 +0300 Message-Id: <20230213140103.1518173-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297004247100001 PCI_EXP_SLTCTL_PIC_OFF is a value, and PCI_EXP_SLTCTL_PIC is a mask. Happily PCI_EXP_SLTCTL_PIC_OFF is a maximum value for this mask and is equal to the mask itself. Still the code looks like a bug. Let's make it more reader-friendly. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Anton Kuchin --- hw/pci/pcie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 924fdabd15..82ef723983 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -770,9 +770,9 @@ void pcie_cap_slot_write_config(PCIDevice *dev, * control of powered off slots before powering them on. */ if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) && - (val & PCI_EXP_SLTCTL_PIC_OFF) =3D=3D PCI_EXP_SLTCTL_PIC_OFF && + (val & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PIC_OFF && (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || - (old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) !=3D PCI_EXP_SLTCTL_PIC_OFF= )) { + (old_slt_ctl & PCI_EXP_SLTCTL_PIC) !=3D PCI_EXP_SLTCTL_PIC_OFF)) { pcie_cap_slot_do_unplug(dev); } pcie_cap_update_power(dev); --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297157; cv=none; d=zohomail.com; s=zohoarc; b=lsBlzKl64SlYw2HrlnNk+fw9G3bgNmVNr62C61RMuDergt+pyO5d3Vh3q68SMaAGtqo6BQupvnN5DToMvSS0etZNiqcK7P0CZTkH+ptXfaCqgYv5GKVvQ5cOsQ5RBj3S0m0nnU/8K1ie6SFVMwaCdhzca5SQ8AZYB02tzD55SFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297157; 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=ILI8wH9hIiUXO+Dnts0zYZzk4CTd1H6GYtA2wQgWkS4=; b=GqebHqDuPwf1K594Ywh+sToKrDA8guBAffELaQQd5MB9Lpyb6nvSCNRL7LaVSoKDFxh6kMN1Duyo563HoqHvk6K4h1e8xGLIlk3A7fpdURMAhBDqN8H3f+1zQJup9QYPnk2jxTSSq8fb5Mq+qjdxxCVSnwqc+jr5QglEzYbrprY= 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 1676297157167525.6748560843283; Mon, 13 Feb 2023 06:05:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZPL-00074C-4D; Mon, 13 Feb 2023 09:02:15 -0500 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 1pRZOq-0006ea-IM for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:48 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOm-0005uT-A6 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:43 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 54D7061F92; Mon, 13 Feb 2023 17:01:20 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-GmjQxeA6; Mon, 13 Feb 2023 17:01:19 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296879; bh=ILI8wH9hIiUXO+Dnts0zYZzk4CTd1H6GYtA2wQgWkS4=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=BcLPOjFfDMRQqHVCjOPZbLS5icMM52jX7CmnFZe0eNxlmPiL8rNo78b1TwlvX3Bhl JQGxelAv9YuvJoGtuHTUqLMERWY7hp6y7YVfwuO+in9zt38B1NXNEzoJahVxiZkCJF re25zn9qX86f91xoKOOKfb+0bG9EXq9cYlHwfkgw= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 08/16] pcie_regs: drop duplicated indicator value macros Date: Mon, 13 Feb 2023 17:00:55 +0300 Message-Id: <20230213140103.1518173-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297158270100002 We already have indicator values in include/standard-headers/linux/pci_regs.h , no reason to reinvent them in include/hw/pci/pcie_regs.h. (and we already have usage of PCI_EXP_SLTCTL_PWR_IND_BLINK and PCI_EXP_SLTCTL_PWR_IND_OFF in hw/pci/pcie.c, so let's be consistent) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Anton Kuchin --- include/hw/pci/pcie_regs.h | 9 --------- hw/pci/pcie.c | 13 +++++++------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h index 963dc2e170..00b595a82e 100644 --- a/include/hw/pci/pcie_regs.h +++ b/include/hw/pci/pcie_regs.h @@ -70,15 +70,6 @@ typedef enum PCIExpLinkWidth { #define PCI_EXP_SLTCTL_IND_ON 0x1 #define PCI_EXP_SLTCTL_IND_BLINK 0x2 #define PCI_EXP_SLTCTL_IND_OFF 0x3 -#define PCI_EXP_SLTCTL_AIC_SHIFT ctz32(PCI_EXP_SLTCTL_AIC) -#define PCI_EXP_SLTCTL_AIC_OFF \ - (PCI_EXP_SLTCTL_IND_OFF << PCI_EXP_SLTCTL_AIC_SHIFT) - -#define PCI_EXP_SLTCTL_PIC_SHIFT ctz32(PCI_EXP_SLTCTL_PIC) -#define PCI_EXP_SLTCTL_PIC_OFF \ - (PCI_EXP_SLTCTL_IND_OFF << PCI_EXP_SLTCTL_PIC_SHIFT) -#define PCI_EXP_SLTCTL_PIC_ON \ - (PCI_EXP_SLTCTL_IND_ON << PCI_EXP_SLTCTL_PIC_SHIFT) =20 #define PCI_EXP_SLTCTL_SUPPORTED \ (PCI_EXP_SLTCTL_ABPE | \ diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 82ef723983..ccdb2377e1 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -634,8 +634,8 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_PIC | PCI_EXP_SLTCTL_AIC); pci_word_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCTL, - PCI_EXP_SLTCTL_PIC_OFF | - PCI_EXP_SLTCTL_AIC_OFF); + PCI_EXP_SLTCTL_PWR_IND_OFF | + PCI_EXP_SLTCTL_ATTN_IND_OFF); pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL, PCI_EXP_SLTCTL_PIC | PCI_EXP_SLTCTL_AIC | @@ -679,7 +679,7 @@ void pcie_cap_slot_reset(PCIDevice *dev) PCI_EXP_SLTCTL_PDCE | PCI_EXP_SLTCTL_ABPE); pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL, - PCI_EXP_SLTCTL_AIC_OFF); + PCI_EXP_SLTCTL_ATTN_IND_OFF); =20 if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) { /* Downstream ports enforce device number 0. */ @@ -694,7 +694,8 @@ void pcie_cap_slot_reset(PCIDevice *dev) PCI_EXP_SLTCTL_PCC); } =20 - pic =3D populated ? PCI_EXP_SLTCTL_PIC_ON : PCI_EXP_SLTCTL_PIC_OFF; + pic =3D populated ? + PCI_EXP_SLTCTL_PWR_IND_ON : PCI_EXP_SLTCTL_PWR_IND_OFF; pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL, pic); } =20 @@ -770,9 +771,9 @@ void pcie_cap_slot_write_config(PCIDevice *dev, * control of powered off slots before powering them on. */ if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) && - (val & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PIC_OFF && + (val & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF && (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || - (old_slt_ctl & PCI_EXP_SLTCTL_PIC) !=3D PCI_EXP_SLTCTL_PIC_OFF)) { + (old_slt_ctl & PCI_EXP_SLTCTL_PIC) !=3D PCI_EXP_SLTCTL_PWR_IND_OFF= )) { pcie_cap_slot_do_unplug(dev); } pcie_cap_update_power(dev); --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297188; cv=none; d=zohomail.com; s=zohoarc; b=OgMFjiCudSHer6nYPgfK17BAkS0/seQAeh4qV06lcT4r0VBFCADiesu9X7ufgvSK8y3qIZpn41mDNpPr6YJXFn5wbRuUCarr47VsBSsXwkW66tEKRR34Xx0A9/BJSFh4xpdG4UUXFMKpuGb+nopDb72DYc9C/XoSkuBIeSLlBuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297188; 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=9UQZIC26gd9V5xSKa0q+eOT+DoRF3Hp4776K835oCfM=; b=UTesjSRiwYZUzjWVCuTNsCT0Buog8We4gnujSLbD61tqculWWxxP38zy7GXHfMZkqsW3OJnuXETsBJFapr4Lk/ZmnDKizGuTj0QwXxMr6Wsogd0WcAUdbBEPx7frJtiFe0jsENQXkcCODRaRdxRV00rboP3Js0rGfqpjzUpSMKk= 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 1676297188627442.6597512028411; Mon, 13 Feb 2023 06:06:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZP3-0006id-8F; Mon, 13 Feb 2023 09:01:57 -0500 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 1pRZOq-0006eb-IT for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:48 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOm-0005up-AD for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:44 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 613106227B; Mon, 13 Feb 2023 17:01:21 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-6DWuIz1c; Mon, 13 Feb 2023 17:01:20 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296880; bh=9UQZIC26gd9V5xSKa0q+eOT+DoRF3Hp4776K835oCfM=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=JDZBwTIar4fy1Zo4wH/kGVY+KPoRW9a27iD6bxs6ixRvDUOhAFlKAykcR/4yuIJHi MVKhVdvhzyFiPNozWmXRrXYQ7wKVkQxSDhLaS6NiXYEX9D3WlsxbJPuUAItHi4s4GJ 5efWAv97wPmqPbzJeQOKib+8CpZOJte+wX8hULOU= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 09/16] pcie: drop unused PCIExpressIndicator Date: Mon, 13 Feb 2023 17:00:56 +0300 Message-Id: <20230213140103.1518173-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297190511100003 The structure type is unused. Also, it's the only user of corresponding macros, so drop them too. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Anton Kuchin --- include/hw/pci/pcie.h | 8 -------- include/hw/pci/pcie_regs.h | 5 ----- 2 files changed, 13 deletions(-) diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h index 798a262a0a..3cc2b15957 100644 --- a/include/hw/pci/pcie.h +++ b/include/hw/pci/pcie.h @@ -27,14 +27,6 @@ #include "hw/pci/pcie_sriov.h" #include "hw/hotplug.h" =20 -typedef enum { - /* for attention and power indicator */ - PCI_EXP_HP_IND_RESERVED =3D PCI_EXP_SLTCTL_IND_RESERVED, - PCI_EXP_HP_IND_ON =3D PCI_EXP_SLTCTL_IND_ON, - PCI_EXP_HP_IND_BLINK =3D PCI_EXP_SLTCTL_IND_BLINK, - PCI_EXP_HP_IND_OFF =3D PCI_EXP_SLTCTL_IND_OFF, -} PCIExpressIndicator; - typedef enum { /* these bits must match the bits in Slot Control/Status registers. * PCI_EXP_HP_EV_xxx =3D PCI_EXP_SLTCTL_xxxE =3D PCI_EXP_SLTSTA_xxx diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h index 00b595a82e..1fe0bdd25b 100644 --- a/include/hw/pci/pcie_regs.h +++ b/include/hw/pci/pcie_regs.h @@ -66,11 +66,6 @@ typedef enum PCIExpLinkWidth { =20 #define PCI_EXP_SLTCAP_PSN_SHIFT ctz32(PCI_EXP_SLTCAP_PSN) =20 -#define PCI_EXP_SLTCTL_IND_RESERVED 0x0 -#define PCI_EXP_SLTCTL_IND_ON 0x1 -#define PCI_EXP_SLTCTL_IND_BLINK 0x2 -#define PCI_EXP_SLTCTL_IND_OFF 0x3 - #define PCI_EXP_SLTCTL_SUPPORTED \ (PCI_EXP_SLTCTL_ABPE | \ PCI_EXP_SLTCTL_PDCE | \ --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297157; cv=none; d=zohomail.com; s=zohoarc; b=ehFl2l1teUdAozuAvMQsQ4Sx/vO/T2Fib9MhNMCJWTYNbMHKOhP8IbmMHsbyLfpKlMwQLjOsn0HfFnLY4K8bSTW+oLUoMiRBAhDJFmXm4jBKKlySUVqn3y5rReve7G/USrZq8HT/oLHeM3SOJOFJHjomUMxZqjLs/XrmKAkImGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297157; 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=4idUn3gQVhg47qMVrKAPhRCtyv+mFieIGtY3jF5wbTE=; b=Zl4hRI0vG5iR4dp7Fqbg8KBm1ycFZmXyEmgJNTHdec1wiwj4x5U6SiDdVZjbgG23HeI5wCkK8IBBJ1PphsjfE+I1XqgK91loSendbrI1ec5koFFtVke0q7MeAmPwBYhU75rzjqmQASjH+ePgauFVUjEC1HWbF0jeHNrqlZLSqRU= 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 1676297157946875.4384117763946; Mon, 13 Feb 2023 06:05:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZP3-0006ic-7t; Mon, 13 Feb 2023 09:01:57 -0500 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 1pRZOo-0006eB-HT for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:43 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOk-0005v5-Bx for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:41 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 7943062208; Mon, 13 Feb 2023 17:01:22 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-a8zMwdbt; Mon, 13 Feb 2023 17:01:21 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296881; bh=4idUn3gQVhg47qMVrKAPhRCtyv+mFieIGtY3jF5wbTE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=V5o4jeFOzaI4XQnF7PMOa6kFB7Vu73ahaxN3vRhralebnvhZ2mcPwTU+ga9O8poDr vcPFj5xiH7jHHA1fwedJHvJNvjU0f4JKCHMDD9vVFPr39x4MjeMSditSD1tROCd4wa pMRPii1GtG6eei+MipuxpfO+beix6IwTMB4Y9VlM= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 10/16] pcie: pcie_cap_slot_enable_power() use correct helper Date: Mon, 13 Feb 2023 17:00:57 +0300 Message-Id: <20230213140103.1518173-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297158258100001 Content-Type: text/plain; charset="utf-8" *_by_mask() helpers shouldn't be used here (and that's the only one). *_by_mask() helpers do shift their value argument, but in pcie.c code we use values that are already shifted appropriately. Happily, PCI_EXP_SLTCTL_PWR_ON is zero, so shift doesn't matter. But if we apply same helper for PCI_EXP_SLTCTL_PWR_OFF constant it will do wrong thing. So, let's use instead pci_word_test_and_clear_mask() which is already used in the file to clear PCI_EXP_SLTCTL_PWR_OFF bit in pcie_cap_slot_init() and pcie_cap_slot_reset(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/pcie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index ccdb2377e1..db8360226f 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -373,8 +373,8 @@ void pcie_cap_slot_enable_power(PCIDevice *dev) uint32_t sltcap =3D pci_get_long(exp_cap + PCI_EXP_SLTCAP); =20 if (sltcap & PCI_EXP_SLTCAP_PCP) { - pci_set_word_by_mask(exp_cap + PCI_EXP_SLTCTL, - PCI_EXP_SLTCTL_PCC, PCI_EXP_SLTCTL_PWR_ON); + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTCTL, + PCI_EXP_SLTCTL_PCC); } } =20 --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297014; cv=none; d=zohomail.com; s=zohoarc; b=AKuq0hhOPKrVeGQCbcbQAOYmWZfhsrPyF6Ypsz3weyoj2Y1Zmy8pHUqyWFRXU/wQO/GUVmCEnkr5UkXEPT0rMNA1D5hBWCpqi3KgIqyJ+zm4PeR/iMM+V5hhmXSmWThLJER6FvnlOa2v/qe9Gab73RpCK/s7nZvjuRnaosy4WEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297014; 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=4ZbW4RpSqGfFzZpxIfamXG25Rh3hjzaFCEpiZHUI4Ww=; b=RQd7lUPy15YD0MqpiO+vYU1wfyfDYjdQEcXDHN1qiK0g3i2CGTU1urr4sulleGSxYkBOUYL+qcuy7RaIP4zy9bxo8gc+DVxOV94NmhIi59rtH7X2vpInW0d5wiB5Oxq6IFz32xwxVKEx/Na5TBuyqqRsmLBn1YmPyho7rwebPNE= 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 1676297014694203.11697447078893; Mon, 13 Feb 2023 06:03:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZP8-0006jH-W0; Mon, 13 Feb 2023 09:02:03 -0500 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 1pRZOq-0006eZ-Hf for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:48 -0500 Received: from forwardcorp1c.mail.yandex.net ([2a02:6b8:c03:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOm-0005vP-A7 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:43 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 9558F5ED4F; Mon, 13 Feb 2023 17:01:23 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-aR7Fd5EY; Mon, 13 Feb 2023 17:01:22 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296882; bh=4ZbW4RpSqGfFzZpxIfamXG25Rh3hjzaFCEpiZHUI4Ww=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=UcJpbs+6Tc+u38rNo4W+ZBBg9TV+EZzCV6W5vppkcS+y5J2uVNqdWY6knbss08OdT u3Eng6tuR4GuE02iWsEwssqnr0ffdow2w/5fyjMnmu3I7dmTYst4P8xckV235e9r50 aOG1+ombxjnK1YJ3f32EyTN6se5NoG27Lu8E3zCE= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 11/16] pcie: introduce pcie_sltctl_powered_off() helper Date: Mon, 13 Feb 2023 17:00:58 +0300 Message-Id: <20230213140103.1518173-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c03:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297021023100001 In pcie_cap_slot_write_config() we check for PCI_EXP_SLTCTL_PWR_OFF in a bad form. We should distinguish PCI_EXP_SLTCTL_PWR which is a "mask" and PCI_EXP_SLTCTL_PWR_OFF which is value for that mask. Better code is in pcie_cap_slot_unplug_request_cb() and in pcie_cap_update_power(). Let's use same pattern everywhere. To simplify things add also a helper. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Anton Kuchin --- hw/pci/pcie.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index db8360226f..90faf0710a 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -39,6 +39,11 @@ #define PCIE_DEV_PRINTF(dev, fmt, ...) \ PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__) =20 +static bool pcie_sltctl_powered_off(uint16_t sltctl) +{ + return (sltctl & PCI_EXP_SLTCTL_PCC) =3D=3D PCI_EXP_SLTCTL_PWR_OFF + && (sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF; +} =20 /*************************************************************************= ** * pci express capability helper functions @@ -395,6 +400,7 @@ static void pcie_cap_update_power(PCIDevice *hotplug_de= v) =20 if (sltcap & PCI_EXP_SLTCAP_PCP) { power =3D (sltctl & PCI_EXP_SLTCTL_PCC) =3D=3D PCI_EXP_SLTCTL_PWR_= ON; + /* Don't we need to check also (sltctl & PCI_EXP_SLTCTL_PIC) ? */ } =20 pci_for_each_device(sec_bus, pci_bus_num(sec_bus), @@ -579,8 +585,7 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *ho= tplug_dev, return; } =20 - if (((sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF) = && - ((sltctl & PCI_EXP_SLTCTL_PCC) =3D=3D PCI_EXP_SLTCTL_PWR_OFF)) { + if (pcie_sltctl_powered_off(sltctl)) { /* slot is powered off -> unplug without round-trip to the guest */ pcie_cap_slot_do_unplug(hotplug_pdev); hotplug_event_notify(hotplug_pdev); @@ -770,10 +775,9 @@ void pcie_cap_slot_write_config(PCIDevice *dev, * this is a work around for guests that overwrite * control of powered off slots before powering them on. */ - if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) && - (val & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF && - (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || - (old_slt_ctl & PCI_EXP_SLTCTL_PIC) !=3D PCI_EXP_SLTCTL_PWR_IND_OFF= )) { + if ((sltsta & PCI_EXP_SLTSTA_PDS) && pcie_sltctl_powered_off(val) && + !pcie_sltctl_powered_off(old_slt_ctl)) + { pcie_cap_slot_do_unplug(dev); } pcie_cap_update_power(dev); --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297051; cv=none; d=zohomail.com; s=zohoarc; b=S2RTYNTW7CzaXvyR1NAOAmuxGygj3UkAp6vI4q+nyxRBx34aISAhNVJ+QjEiPUEeErNlnk1MQ9IC5bYd1ENb53MbQuowcvoDYde2LWMwPGVSye1/ltyVhayAWIz8YUqfZ7pA5OiEVN+MzzVKqfAheSnH8/8Y6uY1gJw1UWOyE9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297051; 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=d2w9yI4wyK/24WYBV5v4zhNMbzf1YnIzg+Fn4Qp/qyk=; b=iSYRU/R8H1IAV3MReZgCPIqo2klFJTbFeT1ACLMGsBXQbeU8Uu7HHhc5J3XgCWwu4qUKHFKmDHxGvUzr+3OJVTispCQ0RjYlu1DY9BIUBuJZnxFuuR+DL0QCE/f63vgPNoaBtzqaOM60Xtwhqzqlz7+1uAj0YaWXuNqgxSUTDsA= 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 1676297051627775.7928523391683; Mon, 13 Feb 2023 06:04:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZPT-0007Pz-Ue; Mon, 13 Feb 2023 09:02:24 -0500 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 1pRZOq-0006ec-J2 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:48 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOm-0005vR-AI for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:43 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id A12E862258; Mon, 13 Feb 2023 17:01:24 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-cZOTECaD; Mon, 13 Feb 2023 17:01:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296883; bh=d2w9yI4wyK/24WYBV5v4zhNMbzf1YnIzg+Fn4Qp/qyk=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=xizzyvozGOg0Re/ujYK7YHq2iAl1ZQdqPaCo2BSY4n9LhQtX5gSvJ4m151olLRfEB PZtKVyayoR84/g4Yh5Nih6Ln7r4O4YnfvK0i2ctadnSMDh6kEMqtUUqzcm2G8fuzru v+ZBAmqCeHILsGGwgm0YOF49aO9ToA3QTgUXkpBM= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 12/16] pcie: set power indicator to off on reset by default Date: Mon, 13 Feb 2023 17:00:59 +0300 Message-Id: <20230213140103.1518173-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297053342100001 Content-Type: text/plain; charset="utf-8" It should be zero, the only valid values are ON, OFF and BLINK. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- hw/pci/pcie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 90faf0710a..b8c24cf45f 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -684,6 +684,7 @@ void pcie_cap_slot_reset(PCIDevice *dev) PCI_EXP_SLTCTL_PDCE | PCI_EXP_SLTCTL_ABPE); pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL, + PCI_EXP_SLTCTL_PWR_IND_OFF | PCI_EXP_SLTCTL_ATTN_IND_OFF); =20 if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) { --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297110; cv=none; d=zohomail.com; s=zohoarc; b=A/w1ah4lDMNe+SpKNGF5pYYSCiMFrbSJgUoyRz3js9Q+oEInNYJa06BCf9G3Kyei2arixJjFTx510dAPTkWNz/uNIRt1wkMJHXBZhL3UXKuOLqO6HKAj77qW1vRZbuh5RTY6Lt7G13C/yzjDOC+IetJHPk8HKkDysK6DMcTb+g0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297110; 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=wtLpRKD+34nSNrWfdyB3ApaJ12n1OZ5huD/Mn1RffKM=; b=Al0g+BhzOmpJ8rZm8q6u7XFS9hlQtOdBKIULCKrNhOmblJmE6cjYKCLm9Ul7M0+8/EBo9H9eXFVIBAIjPlQsVEO2T4fjqAlZylJZ8YDNOrsh1t8nu7XKmyY1yYgL/JdTMb0TTUARw6v9BEEWeuou/WblssSl2wdYNpGXbj/U5Cg= 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 1676297110935291.7988239807337; Mon, 13 Feb 2023 06:05:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZPL-00073d-2p; Mon, 13 Feb 2023 09:02:15 -0500 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 1pRZOr-0006ee-6p for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:50 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOm-0005vb-A7 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:44 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id AF0AD618B1; Mon, 13 Feb 2023 17:01:25 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-sWblxHjh; Mon, 13 Feb 2023 17:01:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296884; bh=wtLpRKD+34nSNrWfdyB3ApaJ12n1OZ5huD/Mn1RffKM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=b6wW/RDjTQjOtmH50xaiQ32boSMYcSto6/Z1Ftj2WXLOgc+uyRqc26MAOMY1Ifqpa 461Jb5ckcbyI5NrQrZ3dVnY5ElJC9EW8eHrYY7HpmEKy2k0IpsMIOhirEEeP2C/toD y5UaNhK1qPBlFXaDDs86AkOuZ/KOPXx2y4ETnaJg= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 13/16] pci: introduce pci_find_the_only_child() Date: Mon, 13 Feb 2023 17:01:00 +0300 Message-Id: <20230213140103.1518173-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297112262100003 Content-Type: text/plain; charset="utf-8" To be used in further patch to identify the device hot-plugged into pcie-root-port. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Anton Kuchin --- include/hw/pci/pci.h | 1 + hw/pci/pci.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index d5a40cd058..b6c9c44527 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -341,6 +341,7 @@ void pci_for_each_device_under_bus_reverse(PCIBus *bus, void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin, pci_bus_fn end, void *parent_state); PCIDevice *pci_get_function_0(PCIDevice *pci_dev); +PCIDevice *pci_find_the_only_child(PCIBus *bus, int bus_num, Error **errp); =20 /* Use this wrapper when specific scan order is not required. */ static inline diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 208c16f450..34fd1fb5b8 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1771,6 +1771,39 @@ void pci_for_each_device(PCIBus *bus, int bus_num, } } =20 +typedef struct TheOnlyChild { + PCIDevice *dev; + int count; +} TheOnlyChild; + +static void the_only_child_fn(PCIBus *bus, PCIDevice *dev, void *opaque) +{ + TheOnlyChild *s =3D opaque; + + s->dev =3D dev; + s->count++; +} + +PCIDevice *pci_find_the_only_child(PCIBus *bus, int bus_num, Error **errp) +{ + TheOnlyChild res =3D {0}; + + pci_for_each_device(bus, bus_num, the_only_child_fn, &res); + + if (!res.dev) { + assert(res.count =3D=3D 0); + error_setg(errp, "No child devices found"); + return NULL; + } + + if (res.count > 1) { + error_setg(errp, "Several child devices found"); + return NULL; + } + + return res.dev; +} + const pci_class_desc *get_class_desc(int class) { const pci_class_desc *desc; --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676296937; cv=none; d=zohomail.com; s=zohoarc; b=lgBxxngUrkDV8SOOoh135OlnezLHaMVmUPSdEbG2HCSFKBCy4eN1dpj3+PuWYMNh4sAeh3mHmoeabudsSli5/TqHiu3cj+XLCeGm7qxaCJfjajc+H5pxoc1C2m+/90KLdu7XDQdXIFjWiUUkYGFPJIlaXh0/1Mz20gz1jTpb6W0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676296937; 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=37xbgqgW/+R2nNL48ilUQ7NpTPizc85TuRqHPxwlIN4=; b=BWwbXEfdmy6xbAFhuEj4vM/I3yvYQY8AOiRPyVj8G3rDlLYrR8mWx2EcpK8NEs2nhT15i+ztuJv7NU+iIZ/5p05AX/OdEVMLGPupzF879lCc4DV0Ii4lApwk8ijhEM0SzeUirNwXIxiMlaSDRrCS+/ZbiiKTMHLJ2Of8r7MxF1w= 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 1676296937394700.9908521233516; Mon, 13 Feb 2023 06:02:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZPJ-0006kK-VM; Mon, 13 Feb 2023 09:02:14 -0500 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 1pRZOq-0006eY-I0 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:48 -0500 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOm-0005vj-9i for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:42 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id AA4B65E636; Mon, 13 Feb 2023 17:01:26 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-4G9UTDW8; Mon, 13 Feb 2023 17:01:25 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296885; bh=37xbgqgW/+R2nNL48ilUQ7NpTPizc85TuRqHPxwlIN4=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=OHyGtT268MP4pcha6QmL9hUrlTsv8tPm1xol6eB/bhpdMRbBdkg4hOYf3oQaMcqti Mm8+BsSLt0IJ1a2ITDGdcK2QNhDuM44xbttnYOYDCAfCAvb/d9P+tLJAFUQprDrifp 7WQjdXb+EY4xDQRG3eMrRmTx/gnjk4g8v9P9J3zs= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru, libvir-list@redhat.com (reviewer:Incompatible changes) Subject: [PATCH v4 14/16] qapi: deprecate "device" field of DEVICE_* events Date: Mon, 13 Feb 2023 17:01:01 +0300 Message-Id: <20230213140103.1518173-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676296986536100001 Content-Type: text/plain; charset="utf-8" The device field is redundant, because QOM path always include device ID when this ID exist. Signed-off-by: Vladimir Sementsov-Ogievskiy --- docs/about/deprecated.rst | 9 +++++++++ qapi/qdev.json | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index da2e6fe63d..b389934691 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -171,6 +171,15 @@ accepted incorrect commands will return an error. User= s should make sure that all arguments passed to ``device_add`` are consistent with the documented property types. =20 +QEMU Machine Protocol (QMP) events +---------------------------------- + +``DEVICE_DELETED`` & ``DEVICE_UNPLUG_GUEST_ERROR`` field ``device`` (since= 8.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''= ''''' + +Devices that has ``ID`` always has QOM path `/machine/peripheral/ID`. So, = the +``device`` field is redundant and deprecated. Use the ``path`` field inste= ad. + Host Architectures ------------------ =20 diff --git a/qapi/qdev.json b/qapi/qdev.json index 2708fb4e99..325ef554f9 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -124,6 +124,9 @@ # # @path: the device's QOM path # +# Features: +# @deprecated: Member @device is deprecated as redundant. Use @path instea= d. +# # Since: 1.5 # # Example: @@ -135,7 +138,8 @@ # ## { 'event': 'DEVICE_DELETED', - 'data': { '*device': 'str', 'path': 'str' } } + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, + 'path': 'str' } } =20 ## # @DEVICE_UNPLUG_GUEST_ERROR: @@ -146,6 +150,9 @@ # # @path: the device's QOM path # +# Features: +# @deprecated: Member @device is deprecated as redundant. Use @path instea= d. +# # Since: 6.2 # # Example: @@ -157,4 +164,5 @@ # ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', - 'data': { '*device': 'str', 'path': 'str' } } + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, + 'path': 'str' } } --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297200; cv=none; d=zohomail.com; s=zohoarc; b=WvmTEHQrvvioNSz5RftRxVMCtHGJd+EgKsuUk4+vMRu0wwO80EzVEwiifgWdE5UemhNFR+xMkpLNdYt1h5BoVkBSB1bAbYzl+myuC450dDd/CYlDuNlY8+lVeJfjz06FHWIL/IdxiQelTF/yjb31586uzyPHpPVvOqrI92xvaYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297200; 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=Bo13gVGwgbNxJks2SVli/0VXWctB3CE+vVVtbZSoObU=; b=QM6byNf23g2OG3rvLt0rRHgZ8ogVp+WX6vsTCKb3abyMWAZU3uaGiE4DJXwxDUi+fhTQIxvZ7Bg0dcVAAtjQfln5EW7GBxIWNBgYCi4CteO8QuoShjZRTaSgKMpzLzdqmkRgHA2MjA48CFmp+KtSz1uvOLHd7be42wfnXvPPeXM= 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 1676297200124648.7418143448266; Mon, 13 Feb 2023 06:06:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZP3-0006if-Dr; Mon, 13 Feb 2023 09:01:59 -0500 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 1pRZOu-0006gZ-OT for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:51 -0500 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOo-0005w2-8H for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:46 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 4D9105E639; Mon, 13 Feb 2023 17:01:28 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-oy9BMlTC; Mon, 13 Feb 2023 17:01:27 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296887; bh=Bo13gVGwgbNxJks2SVli/0VXWctB3CE+vVVtbZSoObU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=NInyvLt/24HGj8Dq/ktcZ3biadOqH7ME45rgjFqMDX3QGTduWWjCSwROsiOo8gB43 y0gVZnM+s8YofHvnpNordIJq4BGXYRKgkj0+PWzOr/hcCk4a6KpE0fEyn0T8BUy4tx C8YV6JNYss5+ATiolgYBpxhhPfS94Ehg/WJaXp68= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 15/16] qapi: add HOTPLUG_STATE event Date: Mon, 13 Feb 2023 17:01:02 +0300 Message-Id: <20230213140103.1518173-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297200557100001 Content-Type: text/plain; charset="utf-8" For PCIe and SHPC hotplug it's important to track led indicators, especially the power led. Add an event that helps. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/qdev.json | 175 ++++++++++++++++++++++++++++++++ include/hw/hotplug.h | 12 +++ include/hw/pci/pci.h | 3 + include/hw/pci/pci_bridge.h | 2 + include/hw/pci/pcie.h | 2 + include/hw/pci/shpc.h | 2 + include/monitor/qdev.h | 5 + hw/core/hotplug.c | 13 +++ hw/pci-bridge/pci_bridge_dev.c | 14 +++ hw/pci-bridge/pcie_pci_bridge.c | 1 + hw/pci/pcie.c | 79 ++++++++++++++ hw/pci/pcie_port.c | 1 + hw/pci/shpc.c | 102 ++++++++++++++++++- softmmu/qdev-monitor.c | 39 +++++++ 14 files changed, 445 insertions(+), 5 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index 325ef554f9..b6ad311dd4 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -166,3 +166,178 @@ { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, 'path': 'str' } } + +## +# @LedActivity: +# +# Three-state led indicator state. +# +# @on: Indicator is on. +# +# @blink: Indicator is blinking. +# +# @off: Indicator is off. +# +# Since: 8.0 +## +{ 'enum': 'LedActivity', + 'data': [ 'on', 'blink', 'off' ] } + +## +# @HotplugSHPCSlotState: +# +# Standard Hot-Plug Controller slot state. +# +# @power-only: Slot is powered on but neither clock nor bus are connected. +# +# @enabled: Slot is powered on, clock and bus are connected, the card is +# fully functional from a hardware standpoint. +# +# @disabled: Slot is disabled, card us safe to be removed. +# +# Since: 8.0 +## +{ 'enum': 'HotplugSHPCSlotState', + 'data': [ 'power-only', 'enabled', 'disabled' ] } + +## +# @HotplugBaseState: +# +# Base structure for SHPC and PCIe-native hotplug. +# +# @power-led: Power indicator. When power indicator is on the device is +# ready and accepted by guest. Off status means that device +# is safe to remove and blinking is an intermediate state of +# hot-plug or hot-unplug. +# +# @attention-led: Attention indicator. Off status means normal operation, +# On signals about operational problem, Blinking is for +# locating the slot. +# +# Since: 8.0 +## +{ 'struct': 'HotplugBaseState', + 'data': { '*power-led': 'LedActivity', + '*attention-led': 'LedActivity' } } + +## +# @HotplugSHPCState: +# +# Standard Hot Plug Controller state. +# +# @slot-state: The slot state field of Slot Status. +# +# Since: 8.0 +## +{ 'struct': 'HotplugSHPCState', + 'base': 'HotplugBaseState', + 'data': { '*slot-state': 'HotplugSHPCSlotState' } } + +## +# @HotplugPCIeNativeState: +# +# PCIe Native hotplug slot state. +# +# @power-on: PCIe Power Controller Control of Slot Control Register. +# True means Power On (Power Controller Control bit is 0), +# False means Power Off (Power Controller Control bit is 1). +# +# Since: 8.0 +## +{ 'struct': 'HotplugPCIeNativeState', + 'base': 'HotplugBaseState', + 'data': { '*power-on': 'bool' } } + +## +# @HotplugType: +# +# Type of hotplug controller / provider. +# +# @shpc: Standard Hot Plug Controller +# +# @pcie-native: PCIe Native hotplug +# +# Since: 8.0 +## +{ 'enum': 'HotplugType', + 'data': ['shpc', 'pcie-native'] } + +## +# @HotplugState: +# +# Generic hotplug slot state. +# +# @type: type of the hotplug (shpc or pcie-native) +# +# Single: 8.0 +## +{ 'union': 'HotplugState', + 'base': { 'type': 'HotplugType' }, + 'discriminator': 'type', + 'data': { 'shpc': 'HotplugSHPCState', + 'pcie-native': 'HotplugPCIeNativeState' } } + +## +# @HotplugBase: +# +# @bus: The QOM path of the parent bus where device is hotplugged. +# +# @addr: The bus address for hotplugged device if applicable. +# +# @child: the hotplugged device's QOM path. The field absent if +# there is no device at the moment. +# +# Since: 8.0 +## +{ 'struct': 'HotplugBase', + 'data': { 'bus': 'str', + '*addr': 'str', + '*child': 'str' } } + +## +# @HotplugEvent: +# +# @changed: The hotplug controller states being changed. The state +# fields that are not changed are not included into @changed. +# +# Since: 8.0 +## +{ 'struct': 'HotplugEvent', + 'base': 'HotplugBase', + 'data': { 'changed': 'HotplugState' } } + +## +# @HotplugInfo: +# +# @state: Current hotplug controller state. All applicable fields are +# included into @state. +# +# Since: 8.0 +## +{ 'struct': 'HotplugInfo', + 'base': 'HotplugBase', + 'data': { 'state': 'HotplugState' } } + +## +# @HOTPLUG_STATE: +# +# Emitted whenever the state of hotplug controller changes. +# Only changed values are included into event. Any change of any field +# of the state trigger the event. Several fields are included into one +# event if they are changed simultaneously. +# +# Since: 8.0 +## +{ 'event': 'HOTPLUG_STATE', + 'data': 'HotplugEvent' } + +## +# @query-hotplug: +# +# Query the state of hotplug controller. +# +# Since: 8.0 +## +{ 'command': 'query-hotplug', + 'data': { 'id': 'str' }, + 'returns': 'HotplugInfo' } diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index e15f59c8b3..b82261d91e 100644 --- a/include/hw/hotplug.h +++ b/include/hw/hotplug.h @@ -13,6 +13,7 @@ #define HOTPLUG_H =20 #include "qom/object.h" +#include "qapi/qapi-types-qdev.h" =20 #define TYPE_HOTPLUG_HANDLER "hotplug-handler" =20 @@ -58,6 +59,8 @@ struct HotplugHandlerClass { hotplug_fn plug; hotplug_fn unplug_request; hotplug_fn unplug; + HotplugInfo *(*get_hotplug_state)(HotplugHandler *plug_handler, + DeviceState *plugged_dev, Error **er= rp); }; =20 /** @@ -94,4 +97,13 @@ void hotplug_handler_unplug_request(HotplugHandler *plug= _handler, void hotplug_handler_unplug(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp); + +/** + * hotplug_handler_get_hotplug_state: + * + * Calls #HotplugHandlerClass.get_hotplug_state callback of @plug_handler. + */ +HotplugInfo *hotplug_handler_get_hotplug_state(HotplugHandler *plug_handle= r, + DeviceState *plugged_dev, + Error **errp); #endif diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index b6c9c44527..8ebd0ad51e 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -7,6 +7,9 @@ /* PCI includes legacy ISA access. */ #include "hw/isa/isa.h" =20 +#include "qapi/qapi-types-qdev.h" +#include "qapi/qapi-events-qdev.h" + extern bool pci_available; =20 /* PCI bus */ diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h index 63a7521567..b8cb86a6f7 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -126,6 +126,8 @@ void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_d= ev, DeviceState *dev, Error **errp); void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); +HotplugInfo *pci_bridge_dev_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **er= rp); =20 /* * before qdev initialization(qdev_init()), this function sets bus_name and diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h index 3cc2b15957..f755a7cacb 100644 --- a/include/hw/pci/pcie.h +++ b/include/hw/pci/pcie.h @@ -146,4 +146,6 @@ void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_de= v, DeviceState *dev, Error **errp); void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); +HotplugInfo *pcie_cap_slot_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **err= p); #endif /* QEMU_PCIE_H */ diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h index 89c7a3b7fa..bf722ce65d 100644 --- a/include/hw/pci/shpc.h +++ b/include/hw/pci/shpc.h @@ -51,6 +51,8 @@ void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, D= eviceState *dev, Error **errp); void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); +HotplugInfo *shpc_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp); =20 extern VMStateInfo shpc_vmstate_info; #define SHPC_VMSTATE(_field, _type, _test) \ diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 1d57bf6577..a61d5f8f1f 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -1,6 +1,8 @@ #ifndef MONITOR_QDEV_H #define MONITOR_QDEV_H =20 +#include "qapi/qapi-types-qdev.h" + /*** monitor commands ***/ =20 void hmp_info_qtree(Monitor *mon, const QDict *qdict); @@ -36,4 +38,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, */ const char *qdev_set_id(DeviceState *dev, char *id, Error **errp); =20 +void qdev_hotplug_state_event(DeviceState *bus, const char *addr, + DeviceState *child, HotplugState *changed_st= ate); + #endif diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c index 17ac986685..08d6d03760 100644 --- a/hw/core/hotplug.c +++ b/hw/core/hotplug.c @@ -57,6 +57,19 @@ void hotplug_handler_unplug(HotplugHandler *plug_handler, } } =20 +HotplugInfo *hotplug_handler_get_hotplug_state(HotplugHandler *plug_handle= r, + DeviceState *plugged_dev, + Error **errp) +{ + HotplugHandlerClass *hdc =3D HOTPLUG_HANDLER_GET_CLASS(plug_handler); + + if (hdc->get_hotplug_state) { + return hdc->get_hotplug_state(plug_handler, plugged_dev, errp); + } + + return NULL; +} + static const TypeInfo hotplug_handler_info =3D { .name =3D TYPE_HOTPLUG_HANDLER, .parent =3D TYPE_INTERFACE, diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c index 4b2696ea7f..69ffe93e2a 100644 --- a/hw/pci-bridge/pci_bridge_dev.c +++ b/hw/pci-bridge/pci_bridge_dev.c @@ -241,6 +241,19 @@ void pci_bridge_dev_unplug_request_cb(HotplugHandler *= hotplug_dev, shpc_device_unplug_request_cb(hotplug_dev, dev, errp); } =20 +HotplugInfo *pci_bridge_dev_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **er= rp) +{ + PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); + + if (!shpc_present(pci_hotplug_dev)) { + error_setg(errp, "standard hotplug controller has been disabled fo= r " + "this %s", object_get_typename(OBJECT(hotplug_dev))); + return NULL; + } + return shpc_get_hotplug_state(hotplug_dev, dev, errp); +} + static void pci_bridge_dev_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -261,6 +274,7 @@ static void pci_bridge_dev_class_init(ObjectClass *klas= s, void *data) hc->plug =3D pci_bridge_dev_plug_cb; hc->unplug =3D pci_bridge_dev_unplug_cb; hc->unplug_request =3D pci_bridge_dev_unplug_request_cb; + hc->get_hotplug_state =3D pci_bridge_dev_get_hotplug_state; } =20 static const TypeInfo pci_bridge_dev_info =3D { diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridg= e.c index 2301b2ca0b..959b536303 100644 --- a/hw/pci-bridge/pcie_pci_bridge.c +++ b/hw/pci-bridge/pcie_pci_bridge.c @@ -157,6 +157,7 @@ static void pcie_pci_bridge_class_init(ObjectClass *kla= ss, void *data) hc->plug =3D pci_bridge_dev_plug_cb; hc->unplug =3D pci_bridge_dev_unplug_cb; hc->unplug_request =3D pci_bridge_dev_unplug_request_cb; + hc->get_hotplug_state =3D pci_bridge_dev_get_hotplug_state; } =20 static const TypeInfo pcie_pci_bridge_info =3D { diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index b8c24cf45f..08ac37581e 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -19,6 +19,8 @@ */ =20 #include "qemu/osdep.h" + +#include "monitor/qdev.h" #include "qapi/error.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pcie.h" @@ -45,6 +47,23 @@ static bool pcie_sltctl_powered_off(uint16_t sltctl) && (sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF; } =20 +static LedActivity pcie_led_state_to_qapi(uint16_t value) +{ + switch (value) { + case PCI_EXP_SLTCTL_PWR_IND_ON: + case PCI_EXP_SLTCTL_ATTN_IND_ON: + return LED_ACTIVITY_ON; + case PCI_EXP_SLTCTL_PWR_IND_BLINK: + case PCI_EXP_SLTCTL_ATTN_IND_BLINK: + return LED_ACTIVITY_BLINK; + case PCI_EXP_SLTCTL_PWR_IND_OFF: + case PCI_EXP_SLTCTL_ATTN_IND_OFF: + return LED_ACTIVITY_OFF; + default: + abort(); + } +} + /*************************************************************************= ** * pci express capability helper functions */ @@ -728,9 +747,17 @@ void pcie_cap_slot_write_config(PCIDevice *dev, uint16_t old_slt_ctl, uint16_t old_slt_sta, uint32_t addr, uint32_t val, int len) { + PCIBus *sec_bus =3D pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); uint32_t pos =3D dev->exp.exp_cap; uint8_t *exp_cap =3D dev->config + pos; uint16_t sltsta =3D pci_get_word(exp_cap + PCI_EXP_SLTSTA); + uint16_t power_led, attn_led, pcc, old_power_led, old_attn_led, old_pc= c; + DeviceState *child_dev =3D + DEVICE(pci_find_the_only_child(sec_bus, pci_bus_num(sec_bus), NULL= )); + HotplugState changed_state =3D { + .type =3D HOTPLUG_TYPE_PCIE_NATIVE, + }; + HotplugPCIeNativeState *cs =3D &changed_state.u.pcie_native; =20 if (ranges_overlap(addr, len, pos + PCI_EXP_SLTSTA, 2)) { /* @@ -768,6 +795,27 @@ void pcie_cap_slot_write_config(PCIDevice *dev, sltsta); } =20 + power_led =3D val & PCI_EXP_SLTCTL_PIC; + old_power_led =3D old_slt_ctl & PCI_EXP_SLTCTL_PIC; + cs->has_power_led =3D power_led !=3D old_power_led; + cs->power_led =3D cs->has_power_led ? pcie_led_state_to_qapi(power_led= ) : 0; + + attn_led =3D val & PCI_EXP_SLTCTL_AIC; + old_attn_led =3D old_slt_ctl & PCI_EXP_SLTCTL_AIC; + cs->has_attention_led =3D attn_led !=3D old_attn_led; + cs->attention_led =3D + cs->has_attention_led ? pcie_led_state_to_qapi(attn_led) : 0; + + pcc =3D val & PCI_EXP_SLTCTL_PCC; + old_pcc =3D old_slt_ctl & PCI_EXP_SLTCTL_PCC; + cs->has_power_on =3D pcc !=3D old_pcc; + cs->power_on =3D cs->has_power_on ? pcc =3D=3D PCI_EXP_SLTCTL_PWR_ON := false; + + + if (cs->has_power_led || cs->has_attention_led || cs->has_power_on) { + qdev_hotplug_state_event(DEVICE(dev), NULL, child_dev, &changed_st= ate); + } + /* * If the slot is populated, power indicator is off and power * controller is off, it is safe to detach the devices. @@ -1100,3 +1148,34 @@ void pcie_acs_reset(PCIDevice *dev) pci_set_word(dev->config + dev->exp.acs_cap + PCI_ACS_CTRL, 0); } } + +HotplugInfo *pcie_cap_slot_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **err= p) +{ + PCIDevice *hotplug_pdev =3D PCI_DEVICE(hotplug_dev); + DeviceState *hotplug_ds =3D DEVICE(hotplug_pdev); + uint8_t *exp_cap =3D hotplug_pdev->config + hotplug_pdev->exp.exp_cap; + uint16_t sltctl =3D pci_get_word(exp_cap + PCI_EXP_SLTCTL); + uint16_t power_led =3D sltctl & PCI_EXP_SLTCTL_PIC; + uint16_t attn_led =3D sltctl & PCI_EXP_SLTCTL_AIC; + uint16_t pcc =3D sltctl & PCI_EXP_SLTCTL_PCC; + HotplugInfo *res =3D g_new(HotplugInfo, 1); + + *res =3D (HotplugInfo) { + .bus =3D g_strdup(hotplug_ds->canonical_path), + .child =3D g_strdup(dev->canonical_path), + .state =3D g_new(HotplugState, 1), + }; + + *res->state =3D (HotplugState) { + .type =3D HOTPLUG_TYPE_PCIE_NATIVE, + .u.pcie_native.has_power_led =3D true, + .u.pcie_native.power_led =3D pcie_led_state_to_qapi(power_led), + .u.pcie_native.has_attention_led =3D true, + .u.pcie_native.attention_led =3D pcie_led_state_to_qapi(attn_led), + .u.pcie_native.has_power_on =3D true, + .u.pcie_native.power_on =3D pcc =3D=3D PCI_EXP_SLTCTL_PWR_ON, + }; + + return res; +} diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c index 65a397ad23..8b28efc52d 100644 --- a/hw/pci/pcie_port.c +++ b/hw/pci/pcie_port.c @@ -188,6 +188,7 @@ static void pcie_slot_class_init(ObjectClass *oc, void = *data) hc->plug =3D pcie_cap_slot_plug_cb; hc->unplug =3D pcie_cap_slot_unplug_cb; hc->unplug_request =3D pcie_cap_slot_unplug_request_cb; + hc->get_hotplug_state =3D pcie_cap_slot_get_hotplug_state; } =20 static const TypeInfo pcie_slot_type_info =3D { diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index e7bc7192f1..70447bba08 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -8,6 +8,9 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" #include "hw/pci/msi.h" +#include "qapi/qapi-types-qdev.h" +#include "qapi/qapi-events-qdev.h" +#include "monitor/qdev.h" =20 /* TODO: model power only and disabled slot states. */ /* TODO: handle SERR and wakeups */ @@ -123,6 +126,39 @@ #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1) #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1) =20 +static char *shpc_idx_to_pci_addr(int slot) +{ + return g_strdup_printf("%d", SHPC_IDX_TO_PCI(slot)); +} + +static LedActivity shpc_led_state_to_qapi(uint8_t value) +{ + switch (value) { + case SHPC_LED_ON: + return LED_ACTIVITY_ON; + case SHPC_LED_BLINK: + return LED_ACTIVITY_BLINK; + case SHPC_LED_OFF: + return LED_ACTIVITY_OFF; + default: + abort(); + } +} + +static HotplugSHPCSlotState shpc_slot_state_to_qapi(uint8_t value) +{ + switch (value) { + case SHPC_STATE_PWRONLY: + return HOTPLUGSHPC_SLOT_STATE_POWER_ONLY; + case SHPC_STATE_ENABLED: + return HOTPLUGSHPC_SLOT_STATE_ENABLED; + case SHPC_STATE_DISABLED: + return HOTPLUGSHPC_SLOT_STATE_DISABLED; + default: + abort(); + } +} + static uint8_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk) { uint8_t *status =3D shpc->config + SHPC_SLOT_STATUS(slot); @@ -268,9 +304,16 @@ static void shpc_slot_command(PCIDevice *d, uint8_t ta= rget, { SHPCDevice *shpc =3D d->shpc; int slot =3D SHPC_LOGICAL_TO_IDX(target); + int pci_slot =3D SHPC_IDX_TO_PCI(slot); uint8_t old_state =3D shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK= ); uint8_t old_power =3D shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MA= SK); uint8_t old_attn =3D shpc_get_status(shpc, slot, SHPC_SLOT_ATTN_LED_MA= SK); + HotplugState changed_state =3D { + .type =3D HOTPLUG_TYPE_SHPC, + }; + HotplugSHPCState *cs =3D &changed_state.u.shpc; + DeviceState *child_dev =3D + DEVICE(shpc->sec_bus->devices[PCI_DEVFN(pci_slot, 0)]); =20 if (target < SHPC_CMD_TRGT_MIN || slot >=3D shpc->nslots) { shpc_invalid_command(shpc); @@ -284,24 +327,34 @@ static void shpc_slot_command(PCIDevice *d, uint8_t t= arget, =20 if (power =3D=3D SHPC_LED_NO) { power =3D old_power; - } else { - /* TODO: send event to monitor */ + } else if (power !=3D old_power) { + cs->has_power_led =3D true; + cs->power_led =3D shpc_led_state_to_qapi(power); shpc_set_status(shpc, slot, power, SHPC_SLOT_PWR_LED_MASK); } =20 if (attn =3D=3D SHPC_LED_NO) { attn =3D old_attn; - } else { - /* TODO: send event to monitor */ + } else if (attn !=3D old_attn) { + cs->has_attention_led =3D true; + cs->attention_led =3D shpc_led_state_to_qapi(attn); shpc_set_status(shpc, slot, attn, SHPC_SLOT_ATTN_LED_MASK); } =20 if (state =3D=3D SHPC_STATE_NO) { state =3D old_state; - } else { + } else if (state !=3D old_state) { + cs->has_slot_state =3D true; + cs->slot_state =3D shpc_slot_state_to_qapi(state); shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK); } =20 + if (cs->has_power_led || cs->has_attention_led || cs->has_slot_state) { + g_autofree char *addr =3D shpc_idx_to_pci_addr(slot); + + qdev_hotplug_state_event(DEVICE(d), addr, child_dev, &changed_stat= e); + } + if (!shpc_slot_is_off(old_state, old_power, old_attn) && shpc_slot_is_off(state, power, attn)) { @@ -713,6 +766,45 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr= , uint32_t val, int l) shpc_cap_update_dword(d); } =20 +HotplugInfo *shpc_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); + DeviceState *hotplug_ds =3D DEVICE(pci_hotplug_dev); + SHPCDevice *shpc =3D pci_hotplug_dev->shpc; + int slot; + uint8_t state, power, attn; + HotplugInfo *res; + + if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) { + return NULL; + } + + state =3D shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK); + power =3D shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK); + attn =3D shpc_get_status(shpc, slot, SHPC_SLOT_ATTN_LED_MASK); + + res =3D g_new(HotplugInfo, 1); + *res =3D (HotplugInfo) { + .bus =3D g_strdup(hotplug_ds->canonical_path), + .addr =3D shpc_idx_to_pci_addr(slot), + .child =3D g_strdup(dev->canonical_path), + .state =3D g_new(HotplugState, 1), + }; + + *res->state =3D (HotplugState) { + .type =3D HOTPLUG_TYPE_SHPC, + .u.shpc.has_power_led =3D true, + .u.shpc.power_led =3D shpc_led_state_to_qapi(power), + .u.shpc.has_attention_led =3D true, + .u.shpc.attention_led =3D shpc_led_state_to_qapi(attn), + .u.shpc.has_slot_state =3D true, + .u.shpc.slot_state =3D shpc_slot_state_to_qapi(state), + }; + + return res; +} + static int shpc_save(QEMUFile *f, void *pv, size_t size, const VMStateField *field, JSONWriter *vmdesc) { diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b8d2c4dadd..95b7d34700 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -25,6 +25,7 @@ #include "sysemu/arch_init.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" +#include "qapi/qapi-events-qdev.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" @@ -956,6 +957,36 @@ void qmp_device_del(const char *id, Error **errp) } } =20 +HotplugInfo *qmp_query_hotplug(const char *id, Error **errp) +{ + DeviceState *dev =3D find_device_state(id, errp); + HotplugHandler *hotplug_ctrl; + + if (!dev) { + return NULL; + } + + if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) { + error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); + return NULL; + } + + if (!DEVICE_GET_CLASS(dev)->hotpluggable) { + error_setg(errp, QERR_DEVICE_NO_HOTPLUG, + object_get_typename(OBJECT(dev))); + return NULL; + } + + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + /* + * hotpluggable device MUST have HotplugHandler, if it doesn't + * then something is very wrong with it. + */ + g_assert(hotplug_ctrl); + + return hotplug_handler_get_hotplug_state(hotplug_ctrl, dev, errp); +} + void hmp_device_add(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; @@ -1146,3 +1177,11 @@ bool qmp_command_available(const QmpCommand *cmd, Er= ror **errp) } return true; } + +void qdev_hotplug_state_event(DeviceState *bus, const char *addr, + DeviceState *child, HotplugState *changed_st= ate) +{ + qapi_event_send_hotplug_state(bus->canonical_path, + addr, child ? child->canonical_path : NU= LL, + changed_state); +} --=20 2.34.1 From nobody Fri May 17 21:26:22 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1676297016; cv=none; d=zohomail.com; s=zohoarc; b=MJF9mHzODqQZnZ6a4hVywfe/s7il62qUUURguhQ0620EENTVLmaMDNZCgYapo8qyGiWqmm7nCPv+3lGn67haTpPQgNE9GjX0LtB5tGnJoxpNlcyPuAv2QCAQ1m9st1KSnBIo1pPmjpOp0ToYX55lUWc0fUKRuT4j0Nc+sUdjv8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676297016; 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=yzDhgcNkqICMbL34gOlg3udb8Nz2rfVgiYTAETF4QKU=; b=I6DOJcGHXNE5oCFCDLclpq/xa3I7Qs4yMlYPITrlzdnR/8SoZGqF/GdhI+YD520JqFIr0/NuvmiTKMrNNKh3UB6uynhIBw+tgzthGPn/aQn9dfcGVKZXWXnNoJPtFRJh6dgDxiwCFMVl8mvAoQOgv7VwCOxWHFX0JQq4u5ZJAlw= 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 1676297016824975.4763926511303; Mon, 13 Feb 2023 06:03:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRZPK-000705-OU; Mon, 13 Feb 2023 09:02:14 -0500 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 1pRZOu-0006gb-P3 for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:51 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRZOo-0005wA-8p for qemu-devel@nongnu.org; Mon, 13 Feb 2023 09:01:45 -0500 Received: from myt6-23a5e62c0090.qloud-c.yandex.net (myt6-23a5e62c0090.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1da3:0:640:23a5:e62c]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 489606149F; Mon, 13 Feb 2023 17:01:29 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6527::1:3a]) by myt6-23a5e62c0090.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 51j9w00QYCg1-a0CJMT1s; Mon, 13 Feb 2023 17:01:28 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676296888; bh=yzDhgcNkqICMbL34gOlg3udb8Nz2rfVgiYTAETF4QKU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=bRYzP2hRWf1udenLnacfFbiKEbdKRztPW77kcjS+/ojvQPqobkeGUnwgTN9yhUbyQ 1N0SU4u5VNPr8V0ESgt/xz9V+Fs6MGwH3PfrfToZtrWKmVlQiSjXwsVVvvucRuzp2V 586/4VoQEfgtjCAkH0zrsXFa7Y18MT57mnLVaOfE= Authentication-Results: myt6-23a5e62c0090.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, philmd@linaro.org, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: [PATCH v4 16/16] qapi: introduce DEVICE_ON event Date: Mon, 13 Feb 2023 17:01:03 +0300 Message-Id: <20230213140103.1518173-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213140103.1518173-1-vsementsov@yandex-team.ru> References: <20230213140103.1518173-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1676297023968100001 Content-Type: text/plain; charset="utf-8" We have DEVICE_DELETED event, that signals that device_del command is actually completed. But we don't have a counter-part for device_add. Still it's sensible for SHPC and PCIe-native hotplug, as there are time when the device in some intermediate state. Let's add an event that say that the device is finally powered on, power indicator is on and everything is OK for next manipulation on that device. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/qdev.json | 13 +++++++++++++ hw/pci/pcie.c | 13 +++++++++++++ hw/pci/shpc.c | 12 ++++++++++++ 3 files changed, 38 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index b6ad311dd4..2143bb2792 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -341,3 +341,16 @@ { 'command': 'query-hotplug', 'data': { 'id': 'str' }, 'returns': 'HotplugInfo' } + +## +# @DEVICE_ON: +# +# Emitted whenever the device insertion completion is acknowledged by the = guest. +# For now only emitted for SHPC and PCIe-native hotplug. +# +# @path: the hotplugged device's QOM path +# +# Since: 8.0 +## +{ 'event': 'DEVICE_ON', + 'data': { 'path': 'str' } } diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 08ac37581e..efa90e9e6e 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -47,6 +47,13 @@ static bool pcie_sltctl_powered_off(uint16_t sltctl) && (sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF; } =20 +static bool pcie_sltctl_powered_on(uint16_t sltctl) +{ + return (sltctl & PCI_EXP_SLTCTL_PCC) =3D=3D PCI_EXP_SLTCTL_PWR_ON && + (sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_ON && + (sltctl & PCI_EXP_SLTCTL_AIC) =3D=3D PCI_EXP_SLTCTL_ATTN_IND_OFF; +} + static LedActivity pcie_led_state_to_qapi(uint16_t value) { switch (value) { @@ -816,6 +823,12 @@ void pcie_cap_slot_write_config(PCIDevice *dev, qdev_hotplug_state_event(DEVICE(dev), NULL, child_dev, &changed_st= ate); } =20 + if ((sltsta & PCI_EXP_SLTSTA_PDS) && pcie_sltctl_powered_on(val) && + !pcie_sltctl_powered_on(old_slt_ctl) && child_dev) + { + qapi_event_send_device_on(child_dev->canonical_path); + } + /* * If the slot is populated, power indicator is off and power * controller is off, it is safe to detach the devices. diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 70447bba08..105be8f1c1 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -299,6 +299,12 @@ static bool shpc_slot_is_off(uint8_t state, uint8_t po= wer, uint8_t attn) return state =3D=3D SHPC_STATE_DISABLED && power =3D=3D SHPC_LED_OFF; } =20 +static bool shpc_slot_is_on(uint8_t state, uint8_t power, uint8_t attn) +{ + return state =3D=3D SHPC_STATE_ENABLED && power =3D=3D SHPC_LED_ON && + attn =3D=3D SHPC_LED_OFF; +} + static void shpc_slot_command(PCIDevice *d, uint8_t target, uint8_t state, uint8_t power, uint8_t attn) { @@ -366,6 +372,12 @@ static void shpc_slot_command(PCIDevice *d, uint8_t ta= rget, SHPC_SLOT_EVENT_MRL | SHPC_SLOT_EVENT_PRESENCE; } + + if (!shpc_slot_is_on(old_state, old_power, old_attn) && + shpc_slot_is_on(state, power, attn) && child_dev) + { + qapi_event_send_device_on(child_dev->canonical_path); + } } =20 static void shpc_command(PCIDevice *d) --=20 2.34.1