From nobody Sat May 18 22:54:13 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=1676570694; cv=none; d=zohomail.com; s=zohoarc; b=HRG1qhuzkUO2aaODmfjhlpp45SMFHgpZlTSXJRFLurPs55ED5ln4Kuior1u/50NztRLChnWnkg+i5Ql2H3gaC7GTwwFHb2V/Axnpa/iS2sAFp6pRrQQUTJliB+fepZs5koofQFocUTUgkEBoPggvwBKeaCic9gy+kqMkdFUNUFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570694; 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=LKk0NsNxWY3QySuOaRiPhRhksY881PykX1pba2KGV9c=; b=DFEiI2PdttmaEXoy1BMTKiaGXtMGl8bRcsx3nu6uYEvdk1Iumbulj/1FmkwimycdQl9qOF7yVODWRbLxmAdPtD0N/Q6gX+z8IukAb+VaVf29d1tFZ8kwEhyC6Mu7DnidtKvsdxyX1xLNvoG2MNaQTgQbKrplXlAuQfcRTV3QiYU= 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 1676570694750525.135072899741; Thu, 16 Feb 2023 10:04:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSic9-0008PF-FR; Thu, 16 Feb 2023 13:04:13 -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 1pSic7-0008NF-O7 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:11 -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 1pSic5-0005lj-O0 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:11 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 2A67A60129; Thu, 16 Feb 2023 21:04:02 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-AgPlymGz; Thu, 16 Feb 2023 21:04:01 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570641; bh=LKk0NsNxWY3QySuOaRiPhRhksY881PykX1pba2KGV9c=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=fqEj5+m3xIbqD6O/DFX1G+pJZDpZO7VVFu6tw89uXbHEaNd+h2OwZsxpx9OkoYRuw jamT7Qw9hhswTHTYlJygeis93TdJfb44kEGEquoNeVbhRmBzRX7BFwopRXbBAuAIIZ lGqALdWQfldtiwlcixVQaFzUYI9fpHdcNx1Ot0i4= Authentication-Results: iva8-99b070b76c56.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 v5 01/18] pci/shpc: set attention led to OFF on reset Date: Thu, 16 Feb 2023 21:03:39 +0300 Message-Id: <20230216180356.156832-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: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: 1676570695929100001 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 Sat May 18 22:54:13 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=1676570716; cv=none; d=zohomail.com; s=zohoarc; b=abU+4H83LBD7UtLPoghedRim9FIV6I3OE4IXilIReBpwCNmwDfVmqQZJyl78MqWCC3WFIZNmFTtC10JU8oLTjD5BXVJlJY6L1GTYoe8+oGH8AcLgkJEdvIXjFs4B5V3x4bFcQh2UbdfRvEzGf36cAr6pC6jOPZtd+S7ohqOnH9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570716; 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=10MHLiZcXhNinnYHAedT2xoeawYGH6LhBzP0neAItZM=; b=a8EyV+I9k39pvxYiT1lITidD1Zas5zLvtWmDEfNUjBdteFB9K358qZCkkDrjybXjZeC1b4v4Zstou9LIFqQuwEqku6Ge6Bd2fU8GHX6lgII0vIr5rQ/XcjH1vFFSa6F9o3BWyQfPTmV+gkN/PuatD1I5DFm5JKT0FQGhL8czz+U= 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 1676570716582626.1944373117657; Thu, 16 Feb 2023 10:05:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicB-00008z-TA; Thu, 16 Feb 2023 13:04: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 1pSic9-0008Pg-Aa for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -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 1pSic5-0005ll-SG for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 07A7162242; Thu, 16 Feb 2023 21:04:03 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-oQhDVm0z; Thu, 16 Feb 2023 21:04:02 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570642; bh=10MHLiZcXhNinnYHAedT2xoeawYGH6LhBzP0neAItZM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=XHMwk/Ap1h7x7ErXP1xjfV85klYwB6Y1jFrCQV97BlvYvEF7JPKLKBVS+BmTtpiaO wckIopFv8G0iOMWOepwYKwphqJfa4ZxUxAUpeMqDuBFfyrjUhibVz750+xX1jfrIGA zqyL7s5p/X3PCNrOgQ+mUhM1dKvYiHHocPugF2kk= Authentication-Results: iva8-99b070b76c56.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 v5 02/18] pci/shpc: change shpc_get_status() return type to uint8_t Date: Thu, 16 Feb 2023 21:03:40 +0300 Message-Id: <20230216180356.156832-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570718021100001 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 Sat May 18 22:54:13 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=1676570795; cv=none; d=zohomail.com; s=zohoarc; b=Htb1x5DZEXj/WTZXvrxOwk2Ep6Rdbnre2dJlib0t/IostvqGJGT6N2vucKEjfMZDctUVEi5tGf4o66UqVsQcBnznWF7duqmnzdlbaa60v1SOyed4Apih2cTm74UWcjKL1FF3oAbOnSkWvXyRsHpaeGcgYLSPkOsBWuyZxkQaoxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570795; 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=NbcCnKazuSUBtSMi8XHtmAMrPNfUeTOAcnzBYThFUXM=; b=MWKu5J9yuV7HMIfUepsS9sJ2BNkJ5y8NcFHH/csgKNUQ7SX2Pw2+qLLxetfnOcmkO8aUR2hi+MXrbZIzIWTLzRXBGo6kMSP+aFH/t7qFLwqGfMJMxMOIrkfewIg8h/6BipM9uxXw9csswBDxwz5ma1OiVFCf99dVNZFhizcP5ZY= 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 1676570795583156.51771621360774; Thu, 16 Feb 2023 10:06:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicA-0008Uw-H8; Thu, 16 Feb 2023 13:04: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 1pSic9-0008P2-7w for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -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 1pSic5-0005lu-Pm for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:12 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id C4A8560153; Thu, 16 Feb 2023 21:04:03 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-K0GSVfcF; Thu, 16 Feb 2023 21:04:03 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570643; bh=NbcCnKazuSUBtSMi8XHtmAMrPNfUeTOAcnzBYThFUXM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=hNqLOYOmqbxBWsCTcGmkE+LfeoOdFwVT1pJ9+t5A4CJ7Gckxya6jdHQ2ukvH5rL8j 2EYAO7ieLbH3cEpn6gJCLhlqcgXQsJ7rRU1Cwh0ctYybGLf0SlKsSAv8tn+zH3VBlQ WHzmuX1KGsThl6vtlrPyLjU2jTDJatMByC/KAdAs= Authentication-Results: iva8-99b070b76c56.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 v5 03/18] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Date: Thu, 16 Feb 2023 21:03:41 +0300 Message-Id: <20230216180356.156832-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570796698100001 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 Sat May 18 22:54:13 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=1676570732; cv=none; d=zohomail.com; s=zohoarc; b=ih6GA5reDOabKRAEuR1OzUDjECmkYSNxpxDEyNxTUBZKSzx/TrVUsnwIrbONo4faJ4GA8LZfPtdwIIXNzgaQ81Ar9sZ1c5IT+Ljf0wwjqhKRUKk/XlqiEhyAvQS2Zt8voOXdQLcPoVNRp0Y7tEvzN3jDGyiOGEbuqrojiT7zdg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570732; 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=ki9tRpMZ+Z7sktrE/CeEecG1mJlJ8kwse5dAT3vJnUk=; b=eKFy5qmj1/rsuKRQS4yd1jrmIZOzzLucU8izIeJ6LGjAQgyPafZgFwTOmDNFcVJKvlqIY04yDelD9AE5MZVUswShR8Snoe1so0OR10dr/7aG7g9jKCBz2kTRvaHEG+GaOdGKQyue8MyGo4VVnEXAbBrSEjY3mprR9cSwei2kGkk= 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 1676570732325781.5622628279419; Thu, 16 Feb 2023 10:05:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicB-000080-95; Thu, 16 Feb 2023 13:04: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 1pSic9-0008Pn-Ba for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -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 1pSic6-0005m8-Cw for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id C3C0261F43; Thu, 16 Feb 2023 21:04:04 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-nd8bRyRi; Thu, 16 Feb 2023 21:04:03 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570643; bh=ki9tRpMZ+Z7sktrE/CeEecG1mJlJ8kwse5dAT3vJnUk=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=D9ht7TYTK+SUN4UZhZx3Qx4NNg4By2nUAgXJykjDT1DKgSQ3NOMFR4NIVtlWZEcA5 WZF7tgqppf8MDTJNxyFt4i+SOtcvluFGvA6hMiabm/ds420nKDUjIwe3wzM32Nyg/d 1ZYwlU2JZFfgJWbuDDHnGXnIWljE6gezsX2P+cDk= Authentication-Results: iva8-99b070b76c56.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 v5 04/18] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Date: Thu, 16 Feb 2023 21:03:42 +0300 Message-Id: <20230216180356.156832-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570734167100005 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 Sat May 18 22:54:13 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=1676570761; cv=none; d=zohomail.com; s=zohoarc; b=FyHU+HXbuwhP5wW0f3EBr6K4/i99r//mkyPppcpWx9VLsqzVvZG66Y+1620eBhRvQxw2fCBR00VWRDMuFF3ng86+X+s7BupmAH8FsbilzfkhkpZ0MQlik+6DIaK8qfHZ2VFMk/tIfXn1K2nxbcEfY1ZNyd2q4G2NYWcfwbkIpL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570761; 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=IC2Wo/P0ieMWwEJZ5bV9dxTh3KiekbzkeMBqLf2d5Oc=; b=nnqJPiwofiqRijsskw2Gr4y08N9jJ6G7fVhYMfkB3OPmNom+EH+jQ4dwibelwxit38cKR01IfD0eMxlN+NrbLYNhoHLT4fx2lzvzSZcxl9BzkwDxQkWOkrm1DNT9eZ4Da+7pQHC0XRarUC3pAbpO0Og7kJveLO2txst5KqATk7M= 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 1676570761149999.5806166337053; Thu, 16 Feb 2023 10:06:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicD-00009W-5w; Thu, 16 Feb 2023 13:04:17 -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 1pSic9-0008Pp-C2 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -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 1pSic7-0005mC-FR for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:12 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id BD3496070B; Thu, 16 Feb 2023 21:04:05 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-usvE3ZcJ; Thu, 16 Feb 2023 21:04:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570644; bh=IC2Wo/P0ieMWwEJZ5bV9dxTh3KiekbzkeMBqLf2d5Oc=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=ImSOul97exmeycnVEoUQ+05acRS0TFWHSfS+EMHLUlkPJbKb+sS3Fm6y8Xa4FhuSl fYxTginEJYStHUXwKUl0ecLSXnTy7XXZF4Zuj+K5+vzuuxfc/jhVEPR0SzG+hdbn00 E9aLGxTZ9r0/aJmcy9xhOUVPFafK4AHrB8G73yjU= Authentication-Results: iva8-99b070b76c56.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 v5 05/18] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Date: Thu, 16 Feb 2023 21:03:43 +0300 Message-Id: <20230216180356.156832-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570762455100004 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 Sat May 18 22:54:13 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=1676570736; cv=none; d=zohomail.com; s=zohoarc; b=gHNzvOKX04nGWTNHp8A5AeTMuZTYfqhAew413Vh3hL4b4/PUnDQWzZAw8fdeulR313XrgAczJkQIkjkcCI3FNfQbGM4hNe+lGW/70+GEJNFdZyVBxbM3NmdwYsIpb5L5Hmi/MFwwAfxsIz50GKMS7gqyIWiDyLYMma28CyjYSFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570736; 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=KDKIxgv6fSaskaR4WEq6WOq+Fsii94FuBg3bG4LBd+I=; b=ehECz2oygvTOIT4G4WwUasXGbpYR/LwklnjKX80NlBggRwqmMNccsCoORaT9cYGhtSlMvy/H+Urq7VgtP5qGhggrRXo9rjPF1r8P33pnUJiTnF7yiJA7tc9arF6gk2GtytIPYerEyTHnVT8dqk6zLHeYlVrq626hNvePU/GvE5o= 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 1676570736555193.24620464953261; Thu, 16 Feb 2023 10:05:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicB-000078-8V; Thu, 16 Feb 2023 13:04: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 1pSic9-0008PU-AD for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:13 -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 1pSic7-0005mG-AQ for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:12 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 993F962326; Thu, 16 Feb 2023 21:04:06 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-D9Cc0vYM; Thu, 16 Feb 2023 21:04:05 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570645; bh=KDKIxgv6fSaskaR4WEq6WOq+Fsii94FuBg3bG4LBd+I=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Jp+OnereqPtEA8XpW8GgTamxZRKOjcyvyR2dqifb7SWND9/pNZURLpoekFEgp7TnW N3fwHs9hsmAbUDnzPxkrg25EmEyGkg6RvuFLG+r73Gbssy/ElbTqEHJFAv3FbKXkiD FOz7tfRuFypvJeKL7Acig4N0dc2xDNiUR6Nhc2uU= Authentication-Results: iva8-99b070b76c56.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 v5 06/18] pci/shpc: refactor shpc_device_plug_common() Date: Thu, 16 Feb 2023 21:03:44 +0300 Message-Id: <20230216180356.156832-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570738178100001 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 Sat May 18 22:54:13 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=1676570731; cv=none; d=zohomail.com; s=zohoarc; b=V6vPrSfZtFheyklMfXwEjjMfcZBiBjOGZA+hrSyZ5eFAYYTA08eBdU1zuIBfbJudaWuZ4Bmwj1lJkR9Tne2Pxub22UJBrroFcaQ9s2Kn91qIRZeiR1qjuFPNy4A+KXxtDu9Fe+Tvyh4226VOFFSd6zbBAt69DsOflV3bjpdqVp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570731; 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=Z2Fy+sU7iSest3Fx8VhTY+hhe0XhQg4WFbN4CIGvAl8=; b=db5nlQ6+kEdRs6ob2KqgZ6rvFDS3Lv8KgahySECiX6fcNZxQfQhpChf891hmwFkv4L5j1SISl7qjzKJjC+BEmEyugR3c3gwMPe4qhEjyetuqJiWA3vIMsLGFXYOWhESkjYJH217yIFd3dSth9h9h/aTdCJuFqfOHWh0RmKRoSt8= 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 1676570731131712.6559026731994; Thu, 16 Feb 2023 10:05:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicD-00009n-SA; Thu, 16 Feb 2023 13:04:17 -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 1pSicA-0008Un-Ds for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:14 -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 1pSic8-0005mP-8D for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:14 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 6F47160143; Thu, 16 Feb 2023 21:04:07 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-KWdsAbFU; Thu, 16 Feb 2023 21:04:06 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570646; bh=Z2Fy+sU7iSest3Fx8VhTY+hhe0XhQg4WFbN4CIGvAl8=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=Gt/7XTiWz4/govPyGDzh+uQDsrRt6aNUXYcBJ2suDZ2wZt4xZKsKetEXzb/Xz0VYL wIAeOuXSI2RVDYzYFVLV6Je4iGIkPKClCEI3keLfXYe/ILs5pQmOuvs17Y/OSGYjMV FxQttMIHGp7AlqckX7z0WJi0uxp4Kg4DpQvapIYE= Authentication-Results: iva8-99b070b76c56.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 v5 07/18] pcie: pcie_cap_slot_write_config(): use correct macro Date: Thu, 16 Feb 2023 21:03:45 +0300 Message-Id: <20230216180356.156832-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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.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: 1676570732382100001 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 Sat May 18 22:54:13 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=1676570784; cv=none; d=zohomail.com; s=zohoarc; b=C6i4B7vKhGkvTeiySCgTY3cEy+j2MR64uy65H9wbTi9hBvVIVEBYK5dcA0Io2EGd1d05Qp7zFPToASUvfYKvCaJM3RSo335Ozwa0F3fZC5vYijI/fe8IGwrQdXFJGsPB8+qm/h2Xr9/OxB5ldJWsVSg6i/ml3RWGOyJXUs6/LmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570784; 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=j7wDaeE19gwYM/8Fi7V3CQ1M8SgBMOegQjvWyQBn0NE=; b=R3bZ/rfws0aE2qnitoPOm4JjYznbFD5h6GLSibdziPqIrZ6CxI7IZ3D+RXFT44YOayYY0fqk71fm8ROSKWdnlXY56LQD9jqYJ5w5y+0+iWH+Kukg79HitwHzpGqd/qHiPCQ5LULnimmd9xUedjzxE7+lT8VpQzRG/FBGxkcirZM= 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 167657078456273.37532263363096; Thu, 16 Feb 2023 10:06:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicE-00009t-Dc; Thu, 16 Feb 2023 13:04:18 -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 1pSicA-0008Vo-Js for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:14 -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 1pSic8-0005mU-O6 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:14 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 6D378628C0; Thu, 16 Feb 2023 21:04:08 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-Hx4g0jFH; Thu, 16 Feb 2023 21:04:07 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570647; bh=j7wDaeE19gwYM/8Fi7V3CQ1M8SgBMOegQjvWyQBn0NE=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=vPRG/l1GlU6VNMuTAO7jafA/hHzmDj9qeogxuVed3VBpiz6V33DjODx61tstgLPge +Bt4eoX3it0wjn63b2iyCBt2Ldhgwr1+nMQXFn+iEkNjJXshCihFJU/paC0tyRmoXG 2yRQ60XnSkb/PlAYPWCGmIAvfWZ2QL4w5Ku4KplA= Authentication-Results: iva8-99b070b76c56.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 v5 08/18] pcie_regs: drop duplicated indicator value macros Date: Thu, 16 Feb 2023 21:03:46 +0300 Message-Id: <20230216180356.156832-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570786454100001 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 Sat May 18 22:54:13 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=1676570753; cv=none; d=zohomail.com; s=zohoarc; b=YUjOgvFQxN8VKlKWKhq3UCv5NCg6U4ZAyk2pTKIBKCdeiPTE57uwXDw3+2UZJRcY2YNSQbDagDH0L4eCylveAEPN5TNQuOwiXFIlzGtZ+jN2r9Es8bp+Z0sFVW6Qgnxzksw2tUXHptgLrWkHM0Ypmk8vGAKMokwze6l+OlcQv3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570753; 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=Sz8Pi4DU5kF9yl/iDFAXH2jVIvTQt6apUWkeiTTZRRA=; b=H3/zs9d/+yyBnRB5ttdUK5M/KOvX258tR7/VFXvCf1qOou/EDWTYUvhg0S6wdAhPK91KZfxjrO7n3evtU2gCAEYbAWrbbFZsEse+xk9NnKrc5m0K5/5GLV6P4t5eB6MCpKrbGy3+4OLNKDFKZ03xpKTcy0gm/MQMBM5WBoH2wJU= 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 1676570751668382.20529910828895; Thu, 16 Feb 2023 10:05:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicE-0000AC-S0; Thu, 16 Feb 2023 13:04:18 -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 1pSicB-00008N-8x for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:15 -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 1pSic9-0005md-Ii for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:14 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 45E616016B; Thu, 16 Feb 2023 21:04:09 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-XooPyPZr; Thu, 16 Feb 2023 21:04:08 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570648; bh=Sz8Pi4DU5kF9yl/iDFAXH2jVIvTQt6apUWkeiTTZRRA=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=OOrK5kIgrIyv3TZtKXbDGX1siX9Y1vvG2eslgd9cXXNIUNuCcbjdzTw6obbcVo/ZK pJm31HpTRT1ItkERvxNLQNo39CXPq9EZlEuVmGS6qfCPmDpkNhMPl8wzAsyAgMU3My 7N4Ba7WFxyVXBMg30JH9jAQ035Z+GbWdFS3VikRI= Authentication-Results: iva8-99b070b76c56.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 v5 09/18] pcie: drop unused PCIExpressIndicator Date: Thu, 16 Feb 2023 21:03:47 +0300 Message-Id: <20230216180356.156832-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570754259100001 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 Sat May 18 22:54:13 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=1676570707; cv=none; d=zohomail.com; s=zohoarc; b=XU5WacQAtogvSihzZ8SD7W9mGB5YoGmvB3+Ft96mER6JKS+XMYTEJHEIOsCJFz0jLXwfCnykTdbuwEpiyEWfdGshklskSLWN6o3NXVrvU0iymAFjsPpTOMPCSp/tEZ0rGPyQt2GWLgCMznuWLY3xudj6BbgMjqfRT4TGZhnr9e0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570707; 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=qTit8O7kmF4p+YxJsfORPr3kXjoW/PDb2WdnZY2B1no=; b=Zwl9ASwC7PjQlyKAaxiraTff3VdeIxYPRYtAeBYgQnjQ6Y4iXuqeUqnyTVceKkmhSFrOJWwn8SpGE8bZRtZHJRWV8IkF+ONYWjA1YFVAqkugP6y4wpryx51p78tV8DHAlZpaqC4avCFuXM/TpE1AVTvG5Y+QGMUccshV1pF6fTo= 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 1676570707175388.537756545752; Thu, 16 Feb 2023 10:05:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicF-0000Ac-Et; Thu, 16 Feb 2023 13:04:19 -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 1pSicD-00009V-2i for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:17 -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 1pSicB-0005o4-6G for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:16 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 2C1B462950; Thu, 16 Feb 2023 21:04:10 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-BsCCl7VZ; Thu, 16 Feb 2023 21:04:09 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570649; bh=qTit8O7kmF4p+YxJsfORPr3kXjoW/PDb2WdnZY2B1no=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=OqRDihjhJeh3EG17sY7erf/OQiyaa5unTcWj7y+bbD2TtQZFbfEq8pQAWivzg99xL EjUHsLDUI6FKwDGJwJEMom9EVp5tCpOHSa+PjEBKA4qfRu7zNZFownGh1s7MrPeHSu ImNm4apyhvHzReKyCEIckYBjJKJjtuBhRYPSofFA= Authentication-Results: iva8-99b070b76c56.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 v5 10/18] pcie: pcie_cap_slot_enable_power() use correct helper Date: Thu, 16 Feb 2023 21:03:48 +0300 Message-Id: <20230216180356.156832-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570707966100005 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 Sat May 18 22:54:13 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=1676570777; cv=none; d=zohomail.com; s=zohoarc; b=G/BOoM4S029hv4egfEVg7mkTeEed8kwxGPyEkQaw8UapSWg2KHaKK23TNBLA+uZpaGW5SrMBRhpwJl0yF+7d4P4wGyxU8YyNnykq515dVf5I0cLCljD8cCvibYTQ4mn2hoWJarpufV10HYS0IbpuyqA1/C3c+OoIv+cujzJJvIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570777; 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=zDJnt062wSWvPVpZGnb+SDFh4AxY4PsZjRb5AnZqg9M=; b=j/AIb4jW+D0S4I6yC6YvZcAV/wSmsuWPgNEq27zP2wxXs5z4ejDnQETvNjtMnLPL0SsCWYMffInlAhccU8AwfFmW6ER79z3mUOVCw3dEK6D3Wg3S1cxVxVVeQFBzmRcV0wtZGBPGgtC6zZnNAEw13o7YfSlfqXurwkGT8wT/UUg= 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 1676570777508615.8406821850386; Thu, 16 Feb 2023 10:06:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicG-0000B6-IV; Thu, 16 Feb 2023 13:04:20 -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 1pSicD-00009e-Ag for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:17 -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 1pSicB-0005oM-Ly for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:17 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 1641960918; Thu, 16 Feb 2023 21:04:11 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-7HClK4KA; Thu, 16 Feb 2023 21:04:10 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570650; bh=zDJnt062wSWvPVpZGnb+SDFh4AxY4PsZjRb5AnZqg9M=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=XqRM0Nq9yE7heBFkGRzE94yzj6KH0wWTc/QGM8Q+FTRIZhagMuLwu9gt5MpiyzTo0 1d5Q3Wt2ZT7DsOV9oeUN3FT57alqXW5HFjH7u4SS1AlReg5lXVcvY4ZD6ArOV0YXrV xDHrd2XnopZik/NYw31nEiFf2vBr+OjtLUuYPKtc= Authentication-Results: iva8-99b070b76c56.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 v5 11/18] pcie: introduce pcie_sltctl_powered_off() helper Date: Thu, 16 Feb 2023 21:03:49 +0300 Message-Id: <20230216180356.156832-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570778428100001 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 Sat May 18 22:54:13 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=1676570703; cv=none; d=zohomail.com; s=zohoarc; b=ao63GyMgQRbbvGGSvFIHoFNoTjrh6jvui52e0uqgzM6Mpv2ZztJ9XpmkAnHsVotqwG0DWg2Kjk8D4nQj/PWYpBjTkEeEt02mRHFK8/tuXlF8j82zbFhEhwBtHiF+4WVBwNKWtcGDLFd9tQGRtlB+xkeEk29vrPJz2Bs8zASypJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570703; 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=rpEBsfck65Xp6MZdZ6eq8uqVcvDqA9fpR1aXcYudBsQ=; b=Cj7vTCAIXrf9/E/qlShIHGq7Qr7v9FYuxeSQ3XJc71q8pvhL9Rmh/10FDTBlcM0htkgFv/I0IcZVaJTV9XAjXYtyodvQZqXP3cS63C/uwExln2a9IhDhpy4XzGVk38BK+0YQC43goNJOwBXvsHs45AJw+0zcahUD4hNd/5HLJTU= 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 1676570703838454.17028142491995; Thu, 16 Feb 2023 10:05:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicF-0000Aj-Vj; Thu, 16 Feb 2023 13:04:19 -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 1pSicE-00009p-6i for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:18 -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 1pSicC-0005oT-BQ for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:17 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id ED079629BC; Thu, 16 Feb 2023 21:04:11 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-p27dZgi2; Thu, 16 Feb 2023 21:04:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570651; bh=rpEBsfck65Xp6MZdZ6eq8uqVcvDqA9fpR1aXcYudBsQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=vm9Cc03TRERG7RF0weveu4yjyTuiAQoH4B1FWySv/Uuun2cvL+lUAREHvqV3PBhDX KduZat45qBuD44qEbCWDVHZH5cH7LJ6l78W3M+G+7SmQMvHFprxD9plwpL6qQ1JC9h nyYuu5OY37pB4z/VDyllkOiYaqu4ys7aj8XdB+zk= Authentication-Results: iva8-99b070b76c56.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 v5 12/18] pcie: set power indicator to off on reset by default Date: Thu, 16 Feb 2023 21:03:50 +0300 Message-Id: <20230216180356.156832-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570706352100001 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 Sat May 18 22:54:13 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=1676570760; cv=none; d=zohomail.com; s=zohoarc; b=RFMrz3cL2fgLyeWDHQn+IJRfXVbk00IwmrjOl1Vd823NFfSMVPYVsicN7YOVd1pAGodirxX08qWsVetMhbSLUmWDpnuxOZbBldt2b2yw6qhtLOxtVOLmomXbLsDgpeIRo8c52LKpqKbZQ0nDAge0MVGUF98xS1m+RwQXLkkFoZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570760; 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=F5Wxv5yHGahm1QgMD4KJ+e7w0s6Rljic/JUMqMdNWmE=; b=ZX4Hms/kSHLCULBeFowcKsBdVV4wIfwCeE/AvU4OT5vZ+2QAjAuZVzUV/hNVVSIhNJSWMaL/SYy1YFyGoqnapq3aUFCZVyF3irvVRc8z8nYfG2WnTXf9Wi6vAUT+03y1Bo4BcslAA+zqYjTwUTKGCn7UyNCxVnivhiqQfGTaazI= 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 167657076017970.04729079396895; Thu, 16 Feb 2023 10:06:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicH-0000CH-Kd; Thu, 16 Feb 2023 13:04:21 -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 1pSicE-0000A1-Me for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:18 -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 1pSicD-0005p0-1x for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:18 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id C37C6600F7; Thu, 16 Feb 2023 21:04:12 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-tow6Dt1V; Thu, 16 Feb 2023 21:04:12 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570652; bh=F5Wxv5yHGahm1QgMD4KJ+e7w0s6Rljic/JUMqMdNWmE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=azieJRY3jCblJrsSQDPDNyJWJtFrWN4QFy5PY69Z9RYPWfv024YK6UsKdf+at3gcN spsGwP//cPreOB2Dc/DVUkGsqwvcRpWNBFW2xJ1+tLD1sOxffRg2X6VNrVont1omp/ yYQDT1pruxY83h4zHvZJO/sBXbBOjvjKqGcqAC+U= Authentication-Results: iva8-99b070b76c56.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 v5 13/18] pci: introduce pci_find_the_only_child() Date: Thu, 16 Feb 2023 21:03:51 +0300 Message-Id: <20230216180356.156832-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570762346100003 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 Sat May 18 22:54:13 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=1676570824; cv=none; d=zohomail.com; s=zohoarc; b=cbJ7zeK+L3p5fe067CQ80DXN///1/sjruQMwci2PQb9AbKuVbINHSTfo4vBACI48phAS0uNzFnD0eFSXV9gpLuF3bUPXQH7f5A35/Q3OPIsXSpQ1lCTgTkuwUr45bQsxqMVEQyiRzNj1L3eDWTTUt9jG1wXu8KRD9Wb5suQ205g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570824; 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=9iQwB6p2IbDsuTo7h2CcmdpXMTGTs8SrDPWPSs9O2Rs=; b=dPrQAPKkU7fJuTchG5YF1r2Bt5Ew5HBEuPnUekvyhs9QWTHQNWU2Jnpv8Sbebspl5QNpkcpQYxmXmmxLRO27xPKujGDROF/H1MXoy7P/QouCRnD2OdSv0XHGWbtX/PlczvmBkElGEuwQd77cWbtq0TlFRYzn6LtwnZ4x4MOwiUI= 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 1676570824543832.6023866774315; Thu, 16 Feb 2023 10:07:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicI-0000CU-6W; Thu, 16 Feb 2023 13:04:22 -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 1pSicF-0000Ai-SI for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:19 -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 1pSicE-0005pB-4i for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:19 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 95F6A62A5F; Thu, 16 Feb 2023 21:04:13 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-RRJ4GSMB; Thu, 16 Feb 2023 21:04:12 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570652; bh=9iQwB6p2IbDsuTo7h2CcmdpXMTGTs8SrDPWPSs9O2Rs=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=rSUxGyLGADDw3+2tSh4QWmYtuNr+iSq71HRpPsnfbZlTVi4fBodVIXJyfZimXT2zW OJImaQiM3Am3LYP36EFXYk5oU7TMpfbIcwZXXwq596jhr2cK/YyELkOl5Qt+ryn/5f vtaqywZNtV7VQ4w4P8asErl3IgjLsRtEQ7LY4Avo= Authentication-Results: iva8-99b070b76c56.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 v5 14/18] qapi/qdev.json: unite DEVICE_* event data into single structure Date: Thu, 16 Feb 2023 21:03:52 +0300 Message-Id: <20230216180356.156832-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570825054100001 Content-Type: text/plain; charset="utf-8" DEVICE_DELETED and DEVICE_UNPLUG_GUEST_ERROR has equal data, let's refactor it to one structure. That also helps to add new events consistently. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/qdev.json | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index 2708fb4e99..135cd81586 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -114,16 +114,37 @@ { 'command': 'device_del', 'data': {'id': 'str'} } =20 ## -# @DEVICE_DELETED: +# @DeviceAndPath: # -# Emitted whenever the device removal completion is acknowledged by the gu= est. -# At this point, it's safe to reuse the specified device ID. Device remova= l can -# be initiated by the guest or by HMP/QMP commands. +# In events we designate devices by both their ID (if the device has one) +# and QOM path. +# +# Why we need ID? User specify ID in device_add command and in command line +# and expects same identifier in the event data. +# +# Why we need QOM path? Some devices don't have ID and we still want to em= it +# events for them. +# +# So, we have a bit of redundancy, as QOM path for device that has ID is +# always /machine/peripheral/ID. But that's hard to change keeping both +# simple interface for most users and universality for the generic case. # # @device: the device's ID if it has one # # @path: the device's QOM path # +# Since: 8.0 +## +{ 'struct': 'DeviceAndPath', + 'data': { '*device': 'str', 'path': 'str' } } + +## +# @DEVICE_DELETED: +# +# Emitted whenever the device removal completion is acknowledged by the gu= est. +# At this point, it's safe to reuse the specified device ID. Device remova= l can +# be initiated by the guest or by HMP/QMP commands. +# # Since: 1.5 # # Example: @@ -134,18 +155,13 @@ # "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } # ## -{ 'event': 'DEVICE_DELETED', - 'data': { '*device': 'str', 'path': 'str' } } +{ 'event': 'DEVICE_DELETED', 'data': 'DeviceAndPath' } =20 ## # @DEVICE_UNPLUG_GUEST_ERROR: # # Emitted when a device hot unplug fails due to a guest reported error. # -# @device: the device's ID if it has one -# -# @path: the device's QOM path -# # Since: 6.2 # # Example: @@ -156,5 +172,4 @@ # "timestamp": { "seconds": 1615570772, "microseconds": 202844 } } # ## -{ 'event': 'DEVICE_UNPLUG_GUEST_ERROR', - 'data': { '*device': 'str', 'path': 'str' } } +{ 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': 'DeviceAndPath' } --=20 2.34.1 From nobody Sat May 18 22:54:13 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=1676570794; cv=none; d=zohomail.com; s=zohoarc; b=fR/oxRp81IfViot+fs/g/c9inwRGVXusXgxBvL9zFzUDpN5pO+yOjrwEkhPX5hoUXa5M0hzbvSjRkfhsxzKdQ2oOYB4VI0/M7d9zWZqztSJ6toIrxYp9VSCK3z6P36wIIpAZO3guhLMlp/X7Lnw8MyGLEhTEMlOwvN6GX/Gz2tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570794; 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=OyvAP+cr+sIZsDK+/VjfcuCfl/E3nXVANIYC8bVM7Gg=; b=N9NFgER/9bMvJG0Gj6ksmuln2iGmApGkzLW5x5wzLYQDEL3SVv3kfVt0CMx6ddvg1cmJiNO6QJIUPJWBv2ihDjeMaWXQDwVfv85rFLta2WDGg58AcDlGN2wlgcq5S19EeuOBi30HmxoKFMQ5CGbgg05fCKaba8x/UuWXS9v9TSE= 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 1676570794868900.6183618213598; Thu, 16 Feb 2023 10:06:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicI-0000DC-HL; Thu, 16 Feb 2023 13:04:22 -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 1pSicG-0000BB-Qn for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:20 -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 1pSicE-0005pm-Oe for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:20 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id A1BAE60118; Thu, 16 Feb 2023 21:04:14 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-QU880Xs5; Thu, 16 Feb 2023 21:04:13 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570653; bh=OyvAP+cr+sIZsDK+/VjfcuCfl/E3nXVANIYC8bVM7Gg=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=N6IHZT5AG4vbqnzcie9zs/wN/F82GSyN/I71ucJILYCkLO2s1Oq0sJmCbKx3d6XdU Wb6DvIR1ZzrUhSuOtWlkEARdjw0Q5lqGQ/QEl0t/Fcqk3D6CL7raVRAfb3nBKB5DrN 9AMsOGSUMKjxXPwAAHuwyNwEu3thNAe9pNwKdWpI= Authentication-Results: iva8-99b070b76c56.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 v5 15/18] qapi: add HOTPLUG_STATE infrastructure Date: Thu, 16 Feb 2023 21:03:53 +0300 Message-Id: <20230216180356.156832-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: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: 1676570796718100002 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. This commits adds infrastructure for HOTPLUG_STATE event and corresponding query command. The implementation for PCIe and SHPC will follow in further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/qdev.json | 175 +++++++++++++++++++++++++++++++++++++++++ include/hw/hotplug.h | 12 +++ include/monitor/qdev.h | 5 ++ hw/core/hotplug.c | 13 +++ softmmu/qdev-monitor.c | 50 ++++++++++++ 5 files changed, 255 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index 135cd81586..6f2d8d6647 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -173,3 +173,178 @@ # ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': 'DeviceAndPath' } + +## +# @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 is 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': 'DeviceAndPath', + '*addr': 'str', + 'child': 'DeviceAndPath' } } + +## +# @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/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/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b8d2c4dadd..d1cc770d11 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,22 @@ 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) +{ + DeviceAndPath child_desc, bus_desc =3D { + .device =3D bus->id, + .path =3D bus->canonical_path, + }; + + if (child) { + child_desc =3D (DeviceAndPath) { + .device =3D child->id, + .path =3D child->canonical_path, + }; + } + + qapi_event_send_hotplug_state(&bus_desc, addr, child ? &child_desc : N= ULL, + changed_state); +} --=20 2.34.1 From nobody Sat May 18 22:54:13 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=1676570745; cv=none; d=zohomail.com; s=zohoarc; b=kDpV7yAO3Y9/Z5kBRMDgh0L1n1qjvPzOVrm2j312K4feZNlSxbfXY+en5FOW8Dl2vAlhhNxvfNQyJve4u55j9kV6bww96vWE6KMOgEKI2CrfYU5nI2P824HBGTMMFyMLohFQoQvdH2Qr6+xbwLHTbCeiN8ITCz5rGJ0dhZUDDZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570745; 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=0Ns0Dm8+dRFEZWzommPVlRJ5i+t3D8sggsA9XHOWcFI=; b=LiG9MLCFFxcbclIme2rhVUhuSDUvq2ae716V9yezAkEnfHLTUq2yaioA8Z2Pgk8erxF2GY3QrKUQK0AgOYIHhEv50xvgMOAFV6MjrgES+knVYOm3QK9OqNxMRC3sYbA/v0CoS4zl5rKxg3q1cJ7h6m+gtyS7Jv/1y/gzaJBf2Jc= 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 1676570745104955.5158659523214; Thu, 16 Feb 2023 10:05:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicK-0000FC-7a; Thu, 16 Feb 2023 13:04: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 1pSicI-0000CV-8g for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:22 -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 1pSicG-0005pw-7J for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:21 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id A2A1C62A6A; Thu, 16 Feb 2023 21:04:15 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-cue6GkBm; Thu, 16 Feb 2023 21:04:14 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570654; bh=0Ns0Dm8+dRFEZWzommPVlRJ5i+t3D8sggsA9XHOWcFI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=HbrtPQttYUgn/b8tRWaIHYUoO8oWElFKg98eK6c3NM/ZCTalR4bx5thScAv2lSrIF mPfkbfqYhj9jWJlsOySsxRQMgTKRLJBZ3g0SGg5V6uAVFK5NdDewFu4+vmhqbJj1IZ Ge7X3H6YhMXG9jsFOQMPiebtn4HQElogvdVHvDNY= Authentication-Results: iva8-99b070b76c56.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 v5 16/18] shpc: implement HOTPLUG_STATE event and query-hotplug Date: Thu, 16 Feb 2023 21:03:54 +0300 Message-Id: <20230216180356.156832-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570746234100003 Content-Type: text/plain; charset="utf-8" For PCIe and SHPC hotplug it's important to track led indicators, especially the power led. At this step, implement the prepared infrastructure in SHPC. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/hw/pci/pci_bridge.h | 2 + include/hw/pci/shpc.h | 2 + include/monitor/qdev.h | 2 + hw/pci-bridge/pci_bridge_dev.c | 14 +++++ hw/pci-bridge/pcie_pci_bridge.c | 1 + hw/pci/shpc.c | 101 ++++++++++++++++++++++++++++++-- softmmu/qdev-monitor.c | 17 ++++++ 7 files changed, 134 insertions(+), 5 deletions(-) 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/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 a61d5f8f1f..780e64bcdc 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -41,4 +41,6 @@ const char *qdev_set_id(DeviceState *dev, char *id, Error= **errp); void qdev_hotplug_state_event(DeviceState *bus, const char *addr, DeviceState *child, HotplugState *changed_st= ate); =20 +DeviceAndPath *qdev_new_device_and_path(DeviceState *dev); + #endif 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/shpc.c b/hw/pci/shpc.c index e7bc7192f1..6a4f93949d 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,44 @@ 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); + 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 qdev_new_device_and_path(DEVICE(pci_hotplug_dev)), + .addr =3D shpc_idx_to_pci_addr(slot), + .child =3D qdev_new_device_and_path(dev), + .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 d1cc770d11..adbba2b8d3 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -1178,6 +1178,23 @@ bool qmp_command_available(const QmpCommand *cmd, Er= ror **errp) return true; } =20 +DeviceAndPath *qdev_new_device_and_path(DeviceState *dev) +{ + DeviceAndPath *res; + + if (!dev) { + return NULL; + } + + res =3D g_new(DeviceAndPath, 1); + *res =3D (DeviceAndPath) { + .device =3D g_strdup(dev->id), + .path =3D g_strdup(dev->canonical_path), + }; + + return res; +} + void qdev_hotplug_state_event(DeviceState *bus, const char *addr, DeviceState *child, HotplugState *changed_st= ate) { --=20 2.34.1 From nobody Sat May 18 22:54:13 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=1676570683; cv=none; d=zohomail.com; s=zohoarc; b=ELdaktCllSPCKt6IY0KFZgRCnfdeUoDXezl+DWu79HBpRfm0nUCVcG4ytnGYXanoZaA7ekxvnmp8tIQKpRvTRLwylDqMYCwyurUUbHDXPEp3EHr3KZGU3KklgLMJjo+1Kje7ylCtCjKad78mYp+wDDiY4U4rv6uly/KRi7ylBk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570683; 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=VH7cB3OHOb41tMa8KzVmevyAQ6J4RBo6JMPZOuTkaSM=; b=UrMDh/QHriX/h+Eb10HXSt5V4HbWcvPYg137Hbf49ii6Alq5BDuQL6jwf4M3pnYbhHoWidP2dxdn1R15cBoYfQioZdXMXu4+jcmrbWT7MvgYYuZmERtlvU6nmKwmZHhVnolfCtCup/JxSijAa8tvfJ4YuFi6j0Qc8UvhYacZNiI= 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 1676570683363687.9273015381376; Thu, 16 Feb 2023 10:04:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicK-0000FA-3X; Thu, 16 Feb 2023 13:04: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 1pSicI-0000EG-M7 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:22 -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 1pSicG-0005q8-Ry for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:22 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id A651560153; Thu, 16 Feb 2023 21:04:16 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-DbdLt7Bv; Thu, 16 Feb 2023 21:04:15 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570655; bh=VH7cB3OHOb41tMa8KzVmevyAQ6J4RBo6JMPZOuTkaSM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=pu4Nz/A6fYG6u6jep9Z0QII1YLW7ok9uYZkx9qumgbM1BvApGALGPlOHY+BIrHWOK LrtORcntTDY69pDICFKfgJpCTR+gbBvHEIA6raUcgKprs7nsZyQW9jDa+AGvbmzpeM CGm5EYRxomQnB2dr3pEWBcw6LMf2r4EhfvcRdNNA= Authentication-Results: iva8-99b070b76c56.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 v5 17/18] pcie: implement HOTPLUG_STATE event and query-hotplug Date: Thu, 16 Feb 2023 21:03:55 +0300 Message-Id: <20230216180356.156832-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570686150100001 Content-Type: text/plain; charset="utf-8" For PCIe and SHPC hotplug it's important to track led indicators, especially the power led. At this step implement the prepared infrastructure in PCIe. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/hw/pci/pcie.h | 2 ++ hw/pci/pcie.c | 78 +++++++++++++++++++++++++++++++++++++++++++ hw/pci/pcie_port.c | 1 + 3 files changed, 81 insertions(+) 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/hw/pci/pcie.c b/hw/pci/pcie.c index b8c24cf45f..636f962a23 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,33 @@ 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); + 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 qdev_new_device_and_path(DEVICE(hotplug_pdev)), + .child =3D qdev_new_device_and_path(dev), + .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 { --=20 2.34.1 From nobody Sat May 18 22:54:13 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=1676570746; cv=none; d=zohomail.com; s=zohoarc; b=ic453J91n9I30FMG58xIQ2j5u4OrucguplKt0IGtEgibose507FGE7k1ZPRJ7MpweBGHl77FJJ3yNAeNX+QjvT2GpNos6q9Wr/3QvbXe3lAHO/adlI4USJq6RKUrpcpEAS+yYJRPsKIgStFoSpHqFMQqNG2Awk3FbbeuDrGcRn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676570746; 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=6LzK5JcKoqQp/AREI8ga/H9CKv30XnA168S3R/9Tv0I=; b=FRsXaFK6l9agJGua0GGYqID3hV8uUtZxu7KDoC7T+TQI42ldl/4E9dmdfOunjw7rRDnEanj58t3I/FzihIWldwMU4aizRik2rufvNo81znsmPcPiSFLqnvw+Ksp+71rqPw2qmeZzJivMguYVcqMl0eQUzbQlj+qlwKWDy0epPz4= 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 167657074655559.63138516323875; Thu, 16 Feb 2023 10:05:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSicM-0000Fq-0P; Thu, 16 Feb 2023 13:04:26 -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 1pSicJ-0000Ew-CF for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:23 -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 1pSicH-0005qS-M9 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 13:04:23 -0500 Received: from iva8-99b070b76c56.qloud-c.yandex.net (iva8-99b070b76c56.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:1099:0:640:99b0:70b7]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id BC44062A6E; Thu, 16 Feb 2023 21:04:17 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8813::1:16]) by iva8-99b070b76c56.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id u3q89J0Qp8c1-peyGi9TG; Thu, 16 Feb 2023 21:04:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1676570656; bh=6LzK5JcKoqQp/AREI8ga/H9CKv30XnA168S3R/9Tv0I=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=HKQHbfXxtwmILHkkBqz/vgvEcVxfwS5v8oR7Wr3793tv8P+lfE2c4P26e0WsPm4US g1gpxAwtftOIyvp2Y4E4/owmPhQq1T6YNROFoGlVPAoCzxKUCdzqGj5eVsXfYfkoeh NDHU1C9oTYZAjw6IaR8U1knkBiNofJqnDazP0D74= Authentication-Results: iva8-99b070b76c56.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 v5 18/18] qapi: introduce DEVICE_ON event Date: Thu, 16 Feb 2023 21:03:56 +0300 Message-Id: <20230216180356.156832-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216180356.156832-1-vsementsov@yandex-team.ru> References: <20230216180356.156832-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: 1676570748246100005 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 | 10 ++++++++++ hw/pci/pcie.c | 14 ++++++++++++++ hw/pci/shpc.c | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index 6f2d8d6647..116a8a7de8 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -348,3 +348,13 @@ { '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. +# +# Since: 8.0 +## +{ 'event': 'DEVICE_ON', 'data': 'DeviceAndPath' } diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 636f962a23..4297e4e8dc 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -22,6 +22,7 @@ =20 #include "monitor/qdev.h" #include "qapi/error.h" +#include "qapi/qapi-events-qdev.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pcie.h" #include "hw/pci/msix.h" @@ -47,6 +48,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 +824,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->id, 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 6a4f93949d..380b2b83b3 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->id, child_dev->canonical_path= ); + } } =20 static void shpc_command(PCIDevice *d) --=20 2.34.1