From nobody Sat May 18 05:53:00 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=1675975131; cv=none; d=zohomail.com; s=zohoarc; b=beQ+UhPdGtMtv6LHc7TEPbwQ5C7UAl9EzsF/bW3dTk+suK1d9IAWs/GqqMARuCb0DZFg40fQYxKsQ6pwOYE7dmvbwEkgsvcgEOTwRxelDC+ec1w11nv6hIKj7mrqIz2F9KDPUJZAKp9Pudqr0YA4vTc0iFhel55EQOJiQ9CyB9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675975131; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vFYjc7YVo0itqqG99xSbqJsZWQQt3LKzCURmx3+uSc4=; b=S8/qHeI+kbg75Dy+DhTaRQELzAkaD4fC/WnxjKSPWjYi6rlyachb1dCBqlI6EJdg8MiZBhz+xCVXOzDLkYuJuoh09c3/IBkJhnHx9cxYLiejvo7AXF2IPBKnqdK21RKgFO/2jVMnRWKAovq+fAHqy6ZDI36q6DI1Wvx/VlrDzz4= 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 1675975131314593.039258770259; Thu, 9 Feb 2023 12:38:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDu-0001dA-SZ; Thu, 09 Feb 2023 15:08:50 -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 1pQDDk-0001Zu-Rm for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDd-0002fv-KX for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:36 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id A040E61ADA; Thu, 9 Feb 2023 23:08:23 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-YdOeNInn; Thu, 09 Feb 2023 23:08:22 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973303; bh=vFYjc7YVo0itqqG99xSbqJsZWQQt3LKzCURmx3+uSc4=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=FU/BAtwECVZVbl4ZLtKCvdFEgzw1DbVtBBsvZg4ekvUwzw8DmUVw3WwaKTayQR6e5 Nk2uIh24LvihMDdSTkkV6RDKtf3G1JadtxF4nfzK9Jr/yaFNBehy+Y6yiCSx77EaNn CTZQmzZIXTXb4IOpEvTHoPdMY+iioRoUA3MduO9E= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 01/15] pci/shpc: set attention led to OFF on reset Date: Thu, 9 Feb 2023 23:07:54 +0300 Message-Id: <20230209200808.869275-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675975135103100001 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 --- 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 05:53:00 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=1675973443; cv=none; d=zohomail.com; s=zohoarc; b=QGJh4SeUspQEBCspbYpG7V1yNS6AyDABqw09otVDcTBxAmdtuA6uvdyFnt7LkMXPwio9BGkue8sYalvj7S+XbMHVeaXfk1x/bqJc8uNq2BuILYpA1GYQzmSdvL7W7rktYwtWpHuQFLSX1GtbuXbyngHbTfluDN5pOUHmFnJyxFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973443; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g9E6WR0ER8a6iXcBVUsc2UOZl2HDibzW91Aa8C7mtlI=; b=mKkY/2w8fC/0cc6hOYfVfEbMbATbKs3+UUoETUuRrhlk0DDiFnFkRC6jHOkkQlygo52PEd+l5WN4N1CU06NYQnuBskhVA5PQLuum9c0DPc0xdCarurTjtmn9WrhEAzY8wWblrOYjClbgInuVkHyis4uhP+NtG4hvTK8zMrj1Pe8= 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 1675973443771969.9786232444969; Thu, 9 Feb 2023 12:10:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDq-0001cR-9D; Thu, 09 Feb 2023 15:08:46 -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 1pQDDk-0001Zx-SV for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDd-0002g4-BK for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:34 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 9EDAC606CA; Thu, 9 Feb 2023 23:08:24 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-Zf8vxM2b; Thu, 09 Feb 2023 23:08:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973303; bh=g9E6WR0ER8a6iXcBVUsc2UOZl2HDibzW91Aa8C7mtlI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=iNz+vlMBe3FJOv3FvqT1aeG2UHdE6mrqzo9BXJGmwbkkU7bRZB2FbfuWyOs080OOn M4CB6ipBTPARrLzDSmDNRabG0DZEh4mKGMgGG12v4cIwkaR2OR38laBiMvT5VqnuJt m46FaZTqBsTcMO8LSp5QKyVca/p90rNxAg0ON+sE= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 02/15] pci/shpc: change shpc_get_status() return type to uint8_t Date: Thu, 9 Feb 2023 23:07:55 +0300 Message-Id: <20230209200808.869275-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973446788100001 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 --- 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 05:53:00 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=1675973570; cv=none; d=zohomail.com; s=zohoarc; b=YvztQ6BkRNLLn1J6eFXDhkNtcit+sizKOerH3dWuTxHFbqSwK/IPWedr6ZS16DBX/CcaXmq3x6d5h5jZveB5X0Exfnkl2B5CDYWpfFT132SG3TT82jAvhJIMbPxCZg3jUQRaUASY831YFI0/6nUOmMXfnFAr7+LyUGIQ/Alvlyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973570; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MMa6nDioTx3cGuqWVQFeRTH8JsSLdlX2olYFCTFUFVU=; b=Lu/h7rrWcc0SYLzOWQQvLro0Q9tZgLD5gwveZDj+5y4dITabFIpAx/I6MicBqjulKYW5FxV/BYxoUnUuR5R4x8zZAY0bfmOUNzMZi6tsdlv6S9xlAo0ii3Vf4eHEirw82mq9lzg2GuzafkbPGJt0W+kHK4PfiXlQooVV3s9qnhk= 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 167597357050764.09334506681262; Thu, 9 Feb 2023 12:12:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDq-0001cp-Gt; Thu, 09 Feb 2023 15:08:46 -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 1pQDDk-0001Zw-Ro for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDd-0002g7-KS for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:35 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 91EB661C4F; Thu, 9 Feb 2023 23:08:25 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-Fct6rbxj; Thu, 09 Feb 2023 23:08:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973304; bh=MMa6nDioTx3cGuqWVQFeRTH8JsSLdlX2olYFCTFUFVU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=XX71IDrSEkkgaDmfpktkEG9LxbuNgGtl5iBqTmKX4VCOF6LB7aUUFld4ttzBJdIr3 lCHBnauHP5ji6jDbDFzVGVOXyUmFDlK1NQmRuSFaMtCoveNi1+HxpGXqzAsUVM9+Qo lMfcKcIJ1iUgPa5Dw76EamMTBlWrCsAjjFzNR5zk= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 03/15] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Date: Thu, 9 Feb 2023 23:07:56 +0300 Message-Id: <20230209200808.869275-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973570875100001 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 --- 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 05:53:00 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=1675973584; cv=none; d=zohomail.com; s=zohoarc; b=aOiESwpkv0OEW6oATx6mTnFWB0PdSNViT6gsmin0N81CjlkKFRrOqiDAiYZq4N/gOb2Van9g3tM5WWf8hilpngEmv2bdavNpSs53CBuLvt410MWbLFJXg67I10rS/TDHlGVoIqV8ywOLqYdPUWwgKkvwmg7CseQ1IztfgmTok48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973584; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ofg0z5A6EVb25euaqITm+xboRrJRtcaO1cNMbngTL1Q=; b=nKZvfVWy1/Pug1RSRVLrAfCvFqjvv/mEnCVto0NXnTfZA8aNu0nO/aIf/TMQvHPlw6DrVjaH/wgHr93jsU2KKqQ4hDWY7bUrN9sUGENsrsv8Gdacbcag9ubUPmNxNc48nGJlGGtYvKS5DKSTVctl4fT+nBFjEbvQ5bltojy6yjM= 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 1675973584660401.9425070236948; Thu, 9 Feb 2023 12:13:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDv-0001dO-2l; Thu, 09 Feb 2023 15:08:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDk-0001Zr-Qj for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDd-0002gN-Kh for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:36 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 8117F60703; Thu, 9 Feb 2023 23:08:26 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-sKqpUN53; Thu, 09 Feb 2023 23:08:25 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973305; bh=Ofg0z5A6EVb25euaqITm+xboRrJRtcaO1cNMbngTL1Q=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=gT7O0znDoumer5ph5wkF8+vTB9g3BdXB7wKhnUU6KO5prN3GOa3bGqWijTiDavK96 4+fhJ3NDvqCc3c0i2D/nLr2cIPakbtChbKN6ld6XiKOMQN2hcwTEZslHjGP2rw7wPg eZIRJX5Q/HP075XKoKWvrRrAl1VFh5m0fR/dZHcw= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 04/15] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Date: Thu, 9 Feb 2023 23:07:57 +0300 Message-Id: <20230209200808.869275-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973586944100006 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 --- 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 05:53:00 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=1675973560; cv=none; d=zohomail.com; s=zohoarc; b=NKqdLRx6r5kHH0tsmb/ZnBqlXj0qLm312MVmPQYGmrhAMZ0L6qtG2lBAV4qWZv2o2Af3kJQ1eRa9UqIVx8Z/sUu3RqFp47TRYRFsvDcWUYNg/tp9pyhoSCol6syBdQvplxIJN7Fzet0HMLbRAuWMD1a/s2jW1qvh0t2NrMoeDUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973560; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WCjwcGMUVI5gHbUTYAnMwvGBnHHLWrdxrFw5oKOIvEM=; b=ThFmJhDDK00bsnNknTda25EU1/+ppd2/fcA5LCGV1kkaz1GsfXRdiFV4UEDrVeW5NGkJqihCDddJVbzHdjh1GsBdFaiJL8ra5Da4uz4pU6fTm25D4YO6xhYUGW9zYpYRQHW3YzRQTIAcpGQdc4eSDNio8BNqUndRf2QjvRpP4Zg= 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 1675973560369968.9542825093604; Thu, 9 Feb 2023 12:12:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDo-0001bM-56; Thu, 09 Feb 2023 15:08:44 -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 1pQDDk-0001Zt-Qv for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDd-0002gb-KR for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:36 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 77E9F60712; Thu, 9 Feb 2023 23:08:27 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-wDEYrMRD; Thu, 09 Feb 2023 23:08:26 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973306; bh=WCjwcGMUVI5gHbUTYAnMwvGBnHHLWrdxrFw5oKOIvEM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=M786MWxc0gTR7v2BtseCvJbe7C56uls6xn2yzvyMHNcQWwnMVpZmETeRhP0qP3+rM CiqYKQA5jv0guUKBCjkMRsbCOAgU+AcN+LWD5olNp1iCUeMOEr5k0Uc7NMsvulmd9Z sfPeFUacCRZeszlpw3CalH7Yo512jrE07FcMsF6g= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 05/15] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Date: Thu, 9 Feb 2023 23:07:58 +0300 Message-Id: <20230209200808.869275-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973560865100001 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 --- 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 05:53:00 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=1675973584; cv=none; d=zohomail.com; s=zohoarc; b=Ud7HA7rxCicDco8Si1PGxk3mwpO9B1X+VkIAOCnJIO7ForCidi98+qx/tvXn198EIQAbrTgoVBSLyvfJ0zaq80+NPKFV4WO+ApkM9ml+rp4o9jb2VHPd1tWydCe5WrJc9wVm7cqVAMXVtbk7KPB37L4aADzKCs3IotMfdbIDnko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973584; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tBuAo+qSIh9zdCZ4HuXxxfZJD/NOd0omPSnUx98c5so=; b=mo7zri/O4DfQAbxhGhar72hZvsLW+kmvyHoxSpSe8lyFswMVgnqXYTSwQjc1TUeGAAVGumPgUhx/Wmyu7EYSX5GzKYJTZVdsPqXnY6oRtdJGdrreVHgoZ/iOqU7S6d+IsqsnhGlfdXXwesgIOZjzafF0AQNrte7NCBbo1t+L73c= 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 16759735847261006.6600250001367; Thu, 9 Feb 2023 12:13:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDv-0001dN-30; Thu, 09 Feb 2023 15:08:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDk-0001Zs-S8 for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDd-0002gf-M0 for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:36 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 5E53461C55; Thu, 9 Feb 2023 23:08:28 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-PKwnSYdy; Thu, 09 Feb 2023 23:08:27 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973307; bh=tBuAo+qSIh9zdCZ4HuXxxfZJD/NOd0omPSnUx98c5so=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=X1jnPTjaVAey56WJqfnqNyUZpI/A+rVReDfIAVbSPFjSiZqVUE5U9eymIDtIawqs4 ppeBVmvsUy003gAWJU0s2MyH6f/FcvVvMbanT9AXKGCzXk+FBy7w5zEqSOuqrowoME XExJMvmq0aaAQG6aFfokQoANwYLZcFnmz7W52Obs= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 06/15] pcie: pcie_cap_slot_write_config(): use correct macro Date: Thu, 9 Feb 2023 23:07:59 +0300 Message-Id: <20230209200808.869275-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1675973586940100005 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 --- 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 05:53:00 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=1675973414; cv=none; d=zohomail.com; s=zohoarc; b=WidJpdR40T9rW7aA4z59usFlRB5kLEgC7eONG0qS+eWFcBsc9K5NwU1aYcWuh1WtNiAU0EvlALBmf48aFLAyy37hR757hy3mIsVMD+fKBnf+uopPYN/wYSrF6r2x4n7dO8aDL6oT23sTeaa4TYu3a4hRtMXfdCQa8zn8DxCMAb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973414; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ILI8wH9hIiUXO+Dnts0zYZzk4CTd1H6GYtA2wQgWkS4=; b=NHvpf1HDurYD5Oa6ws/sv6NZ8gcZtOueB27pkQNqrflvM/6fO0x8v5MQxGDrKSADMKeb+QaTPiV78xrpqoQvJIdn8REUYqIW9lJlyMTL/awr12d8hd4CQ77Mz27wDa3Mwp7aqqblqEWzEkZP6EnnI4iXcEYnuHzl7Gg8fWKDAs0= 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 1675973414290474.65696661843265; Thu, 9 Feb 2023 12:10:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDq-0001co-GQ; Thu, 09 Feb 2023 15:08:46 -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 1pQDDk-0001Zv-S6 for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -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 1pQDDe-0002gx-7G for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:37 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 4D68860717; Thu, 9 Feb 2023 23:08:29 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-gS6ziU7Z; Thu, 09 Feb 2023 23:08:28 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973308; bh=ILI8wH9hIiUXO+Dnts0zYZzk4CTd1H6GYtA2wQgWkS4=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=Y4u7XWBVaCgOKTcaDIJQf/HxbH8z27uAQQ+jaqU9Xnd6hqVBV4dcZntMvLbuyAUGy AsFxc+e5I5Q1YG6D+5/hY4DGFjL+NmkW7DMZBSt0kGtnieOzrBq/CrfbcvCrQvVUJj H/GxTxWJvjsw2vdYVrwKJ/6iSknQjSrAoi9XK2nA= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 07/15] pcie_regs: drop duplicated indicator value macros Date: Thu, 9 Feb 2023 23:08:00 +0300 Message-Id: <20230209200808.869275-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973416477100003 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 --- 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 05:53:00 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=1675973584; cv=none; d=zohomail.com; s=zohoarc; b=FAx07bR7Jt3vBZ7HGT9NcsdAlxRh3IfwwVoRosigGWFLDX+dvMRoimYoP9+IwT+fVa6dwwKLedvZODd5zX1Z4AzETN0BSGV1Di67puw9aNIP2HbOk7GN/kJak3kX7HmY5t1RfJ8VlnIvLPsuZWzn3IzD/Wv6nfkMurVANUCSO4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973584; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9UQZIC26gd9V5xSKa0q+eOT+DoRF3Hp4776K835oCfM=; b=JXCKmA7V1c+VNIQEYFQwUXeRnuVCMbNPdEH8BivxArXWa72oxMB1UoYiC+wqP+RGpNyp4InuzVt2ksd4PGrPgqXKATcEVWbkR7itmkZWVnKFg9q+z/v5xVXAmT++TQRFIwjcre8nXEOlhHmNoTS1ReAJ5LapIw2pYCrlgKK1eDQ= 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 167597358447437.91928291442366; Thu, 9 Feb 2023 12:13:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDv-0001dh-J8; Thu, 09 Feb 2023 15:08:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDl-0001Zz-VX for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:42 -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 1pQDDf-0002hk-Bn for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:41 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 450926071B; Thu, 9 Feb 2023 23:08:30 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-jWPcge1g; Thu, 09 Feb 2023 23:08:29 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973309; bh=9UQZIC26gd9V5xSKa0q+eOT+DoRF3Hp4776K835oCfM=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=Zxf+x27Lf/ZVJGAZP4/reNCo0c7r+zgWriO3wsudAEsNzlWPVdOhOCzp2FVqH4ru+ dt9fUI2ELzi28S+wjJ5Ic6Cw8LUxDOKHfXcDFiuZmT+wVp81yLC0qivLlfC8UNUEC1 dDGcxfn8jyBzAESr/lY+QRTbkKjk88R5xXZXqkKk= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 08/15] pcie: drop unused PCIExpressIndicator Date: Thu, 9 Feb 2023 23:08:01 +0300 Message-Id: <20230209200808.869275-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973584916100001 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 --- 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 05:53:00 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=1675973607; cv=none; d=zohomail.com; s=zohoarc; b=C+LQ2NDjG3mCHoq2SFR79uF4nmHAe6u17vT6ZIqLGawpw88lu9Fl/7oPRnCwCFCfLO5ryl08gTTV+eNnpnI/e+2LLGX/yysKLwnpZi/qwVTUbvLjYjx3BECLi9hoobIQW3rSeUn/g3LL12gcQgoezZ0C9mUelF8kUJpsCydh+BA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973607; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4idUn3gQVhg47qMVrKAPhRCtyv+mFieIGtY3jF5wbTE=; b=BwLdoU2gAc1dJ4gTRAck7Mo3L6MhfppkoU1B756HWouzyS5aF26iXOCtyh3yDifuQsFFeoF2hE5Px2JpEzdkbANEYk+mAzJcX+yBl4btwgWmrKNhoXpejltrd5r6D3/A1OyXTel8ERUgDPdr7IoXkjaqSUhCevhYiYJ/U+tSaNY= 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 167597360728263.21162524829174; Thu, 9 Feb 2023 12:13:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDv-0001e0-QR; Thu, 09 Feb 2023 15:08:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDn-0001bD-Ai for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:43 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDk-0002hp-Hm for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:43 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 42C3B61AE7; Thu, 9 Feb 2023 23:08:31 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-TjfqXSKC; Thu, 09 Feb 2023 23:08:30 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973310; bh=4idUn3gQVhg47qMVrKAPhRCtyv+mFieIGtY3jF5wbTE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=ZuKhLRH0kel4N79jCo7kjcCUNnvHSR37lQh0Litzc1tjjhPCJgoJgJqF9v7+czPUI tDntw6QktZx4qhAqA7M/mz6cpl0jy1lZsNlv85O8ac+UK6Dv4/oWAuElyPPCpDa3X/ Nkq8tlmDerYA8bgeuyDTgY2Gww7M3Jrgt4jAVPJo= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 09/15] pcie: pcie_cap_slot_enable_power() use correct helper Date: Thu, 9 Feb 2023 23:08:02 +0300 Message-Id: <20230209200808.869275-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973609071100001 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 --- 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 05:53:00 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=1675973574; cv=none; d=zohomail.com; s=zohoarc; b=eWySk6gmqSaukr1qCXHYRE9hAHDX1hXhgiAIbbuFNyeSRiKING4ytRwqrN9/5AJd7JuLS+/Ml6p2QAiXndS9ivqPKu9pxP+MXN53yZUyHAsu5eizo1O02HwNM0NjjLde1av51mSyR9jPGuef4ws8hjOSEthTiuUG1J0ulLNprdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973574; 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=m7OdM0Jpngd25o5DV8X3PGHHUSoJZJ2L+p23rGOTXgI=; b=NSSPHKvUJDu0l/lnvL61OFZrSH1Y4vrZv8R+sHxJLAPKy4USlxgxTKyk7MzBDLquB4d5ad7TqunA+p0W3rnjz6bCt+IYCLjaV8epLXbzvv87CBRQFJssR1hdTyUNUzh/PDiBxI4+U+p/WZ4j7S/ELRBJCcZ3f9BIywdIzu2Heuk= 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 1675973574891881.8380313944159; Thu, 9 Feb 2023 12:12:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDv-0001eD-Tn; Thu, 09 Feb 2023 15:08:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDn-0001bE-GF for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:43 -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 1pQDDk-0002i4-IA for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:43 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 36084606F2; Thu, 9 Feb 2023 23:08:32 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-Y5AExD34; Thu, 09 Feb 2023 23:08:31 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973311; bh=m7OdM0Jpngd25o5DV8X3PGHHUSoJZJ2L+p23rGOTXgI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=XB3X2llAwvxvASo0JrXHwfyxmUxxmMXZ4wQizCqRI6cB2bSnTOTq0flMRlNTwBsu0 NMeR6nrEQ4MUDhzIwveLE5gQ8q46ZwsssHqxCwlUQVCas+BxfArYF+PVIPMgn0vHvS a5j0k7SgDGWwqAWZx1DLuKzbOfIBTn9RtbHqZ3VE= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper Date: Thu, 9 Feb 2023 23:08:03 +0300 Message-Id: <20230209200808.869275-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973576925100011 Content-Type: text/plain; charset="utf-8" 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 --- 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..e2da00742c 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 05:53:00 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=1675973573; cv=none; d=zohomail.com; s=zohoarc; b=N5tlKnRfoH8fUIgg5xC15zyjQFj6+qz7l11LN+VxNlhYUbTW5Tkq0TvSWS9HDnFxBZFCFNGp7gCqqY7bJ/8I5sCCKjS7kNwfgSOrx0J64z9sUVYnPy98KKLdzqKDi17ho95xXrwPjqd5DFrWLlv7B7Yl+aSVvWKKGvU/n0/+ByM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973573; 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=WVgSKgGG36n1TOJJrrRuMGWVoKX83pTHkt6Jw3wTYMU=; b=ThR6brsFjnJxhbnb/aum7nG1d1mnrpHX5IemN/v9z/wLEFqbCQcX+9gWgZdhyPKTXT3Q6JSRUUC9XVRdTed4Y/CLbjKrnjh/iEdk+ml8C2RhB4QB+sE8M2qUL22dJSROaQGSXlutu4keimhFzCQ+smkiFS8SxYUSU8vEUlz+dw4= 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 1675973573784639.6276335469488; Thu, 9 Feb 2023 12:12:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDw-0001eg-D7; Thu, 09 Feb 2023 15:08:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDp-0001cG-2E for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:45 -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 1pQDDn-0002iO-EW for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:44 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 1A54C61B11; Thu, 9 Feb 2023 23:08:33 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-OTmHMsOM; Thu, 09 Feb 2023 23:08:32 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973312; bh=WVgSKgGG36n1TOJJrrRuMGWVoKX83pTHkt6Jw3wTYMU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=YvKAK985xcOo2K1duddZYHuVZqNGkHHYGcBGkeVJ9cnY6I8KGblg4vpMqoSBLciwx 1I3Zzs4iRnhd3b9RtnRTOjg5t1J9Afy2nxT3SrZmi7dCtY3bgPB8B9BR5pCAhfUN71 KkQvXJw8P4+u/VlyVdELOLRbXb+1hu287zkvCg4I= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 11/15] pcie: set power indicator to off on reset by default Date: Thu, 9 Feb 2023 23:08:04 +0300 Message-Id: <20230209200808.869275-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973574871100004 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 --- hw/pci/pcie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index e2da00742c..774ce85619 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 05:53:00 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=1675973574; cv=none; d=zohomail.com; s=zohoarc; b=E6HVT718x20gMxNuZJKUI7G3uBaPB5O6pHvKTpCLr+0m1S7Q2cymRmihQ7qGDr+2APLFXX+6Pxi1RB1I9uDtmlMQC4gjMxlwQ+HSy1UIu1QYNHO0Iwwo2inggLHUHPlX8GZsKDs99g5SdzzyeuLU8czOiXdwPlYWgfhfSea5r4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973574; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wtLpRKD+34nSNrWfdyB3ApaJ12n1OZ5huD/Mn1RffKM=; b=I7QLrz5rrk+xB4S2q9A1yz9Xmv/KSeMBDVhkmvWBrvklFnDuz7pVlVDv5ok77+haUtH0enpGo1G2peZr73soxLQE7qxTIEiTQQw2qikkfXFbaPOor+KP6rqkTEH93bRLW6yNGXm17PXLaHmK7TuCi5MK5Z9DSsreCeN/BIPzXfs= 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 1675973574381678.5900802949878; Thu, 9 Feb 2023 12:12:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDy-0001g7-0o; Thu, 09 Feb 2023 15:08:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDq-0001cq-Fd for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:46 -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 1pQDDn-0002iT-QK for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:46 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id E482060724; Thu, 9 Feb 2023 23:08:33 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-1zmbNGSD; Thu, 09 Feb 2023 23:08:33 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973313; bh=wtLpRKD+34nSNrWfdyB3ApaJ12n1OZ5huD/Mn1RffKM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=kaWlqgJCshHNavJYPEaTCHDy95F0mN6GY9KXRMO//FU8nE4Q9sqjEyeTQHkkiMtOW QgKeGPzeeDx68jTyODP7rLodNcT1H6FqY9FarT/h9U1w/PzFFQ6TbdPmjAVMQaGINm hH1ZxPTMhVprjh7vqeShjqbFEm4oVtqUEn3V9+R0= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 12/15] pci: introduce pci_find_the_only_child() Date: Thu, 9 Feb 2023 23:08:05 +0300 Message-Id: <20230209200808.869275-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973574870100003 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 --- 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 05:53:00 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=1675973436; cv=none; d=zohomail.com; s=zohoarc; b=oAsJtXeLzEDvR3iIRQFrJBOGkU7AaK3PgHr0LTfHChnycxZzg0U+QdXCY+m4nwHwtUSjb1ydjIpd09jUI8GDxTTZ+c4Ayg5YIf+papxMEwCWT95SL83p3YTuoq0D4ApTWQEfl51a/SzUvJbVxBqw/Eulg3yiy42azEgnAmdCiqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973436; 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=iyn4nbke5GIAljYsZK/MS0nRcNZ7kRP3DJVSY/W+SVw=; b=KycnASfPnFP9XfnVpckFUhN2O8sz92K84PpDdCFkSlx0flg+Zc2UNkZ/vSzASZ57HVN92myKuOCnIFq/dVO4mwBw5RURi5EM9TsLHUFRebTPCYjzGi3BMvYBeGEF3A1fcY80Nfuq96pah2mvPt7FTpX12h8iH+hxU9NigetHEHk= 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 167597343623515.971975461517786; Thu, 9 Feb 2023 12:10:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDw-0001el-W0; Thu, 09 Feb 2023 15:08:53 -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 1pQDDp-0001cQ-Ps for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:45 -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 1pQDDn-0002ip-Ed for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:45 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id F399F61C2D; Thu, 9 Feb 2023 23:08:34 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-lPO6Ujrb; Thu, 09 Feb 2023 23:08:34 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973314; bh=iyn4nbke5GIAljYsZK/MS0nRcNZ7kRP3DJVSY/W+SVw=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=R6gXbSMaWjKfp90U7iR5XWQjSLgsX+e0PPhVgk4QskqUbPpuff7eiRPZO40vA5mJe 9QUhBRRZbMKMg2LmQs/cS0yOPnzzVPzJOEjyH2pt0JMvCUIaERY51gZXiHhz1fBGQb 98OMqt1TjT3h1ad7bUZv8GmarGPN2FYzRf/lFB08= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 13/15] qapi: add HOTPLUG_STATE event Date: Thu, 9 Feb 2023 23:08:06 +0300 Message-Id: <20230209200808.869275-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973438023100003 Content-Type: text/plain; charset="utf-8" For PCIe and SHPC hotplug it's important to track led indicators, especially the power led. Add an event that helps. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/qdev.json | 62 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 15 +++++++++++ hw/pci/pci.c | 33 +++++++++++++++++++++++ hw/pci/pcie.c | 49 ++++++++++++++++++++++++++++++++++ hw/pci/shpc.c | 42 ++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index 2708fb4e99..40dc34f091 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -158,3 +158,65 @@ ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @HotplugLedState: +# +# Since: 8.0 +## +{ 'enum': 'HotplugLedState', + 'data': [ 'on', 'blink', 'off' ] } + +## +# @HotplugPowerState: +# +# Since: 8.0 +## +{ 'enum': 'HotplugPowerState', + 'data': [ 'on', 'off' ] } + +## +# @HotplugSlotState: +# +# Since: 8.0 +## +{ 'enum': 'HotplugSlotState', + 'data': [ 'power-only', 'enabled', 'disabled' ] } + +## +# @HotplugState: +# +# @hotplug-device: hotplug device id +# @hotplug-path: hotplug device path +# @hotplug-slot: hotplug device slot (only for SHPC) +# @device: device name +# @path: device path +# @power-led: Power Indicator +# @attention-led: Attention Indicator +# @state: slot state, only for SHPC hotplug controller +# @power: Power Controller state, only for PCIe hotplug +# +# Since: 8.0 +## +{ 'struct': 'HotplugState', + 'data': { '*hotplug-device': 'str', + 'hotplug-path': 'str', + '*hotplug-slot': 'int', + '*device': 'str', + 'path': 'str', + '*power-led': 'HotplugLedState', + '*attention-led': 'HotplugLedState', + '*state': 'HotplugSlotState', + '*power': 'HotplugPowerState' } } + +## +# @HOTPLUG_STATE: +# +# Emitted whenever the state of hotplug controller is changed. +# Only changed values are included into event. +# Only SHPC and PCIe-native hotplug are supported. +# +# Since: 8.0 +## +{ 'event': 'HOTPLUG_STATE', + 'data': 'HotplugState' } diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index b6c9c44527..900e22a7d3 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -7,6 +7,9 @@ /* PCI includes legacy ISA access. */ #include "hw/isa/isa.h" =20 +#include "qapi/qapi-types-qdev.h" +#include "qapi/qapi-events-qdev.h" + extern bool pci_available; =20 /* PCI bus */ @@ -611,4 +614,16 @@ static inline void pci_irq_pulse(PCIDevice *pci_dev) MSIMessage pci_get_msi_message(PCIDevice *dev, int vector); void pci_set_power(PCIDevice *pci_dev, bool state); =20 +void pci_hotplug_state_event(DeviceState *hotplug_dev, + bool has_slot, int64_t slot, + DeviceState *dev, + HotplugLedState power_led_old, + HotplugLedState power_led_new, + HotplugLedState attention_led_old, + HotplugLedState attention_led_new, + HotplugSlotState state_old, + HotplugSlotState state_new, + HotplugPowerState power_old, + HotplugPowerState power_new); + #endif diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 34fd1fb5b8..b7374d3d66 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2772,6 +2772,39 @@ void pci_set_power(PCIDevice *d, bool state) } } =20 +void pci_hotplug_state_event(DeviceState *hotplug_dev, + bool has_slot, int64_t slot, + DeviceState *dev, + HotplugLedState power_led_old, + HotplugLedState power_led_new, + HotplugLedState attention_led_old, + HotplugLedState attention_led_new, + HotplugSlotState state_old, + HotplugSlotState state_new, + HotplugPowerState power_old, + HotplugPowerState power_new) +{ + bool pwr_led =3D power_led_new !=3D power_led_old; + bool attn_led =3D attention_led_new !=3D attention_led_old; + bool state =3D state_new !=3D state_old; + bool pwr =3D power_new !=3D power_old; + + if (!(pwr_led || attn_led || state || pwr)) { + /* No changes - no event */ + return; + } + + qapi_event_send_hotplug_state(hotplug_dev->id, + hotplug_dev->canonical_path, + has_slot, slot, + dev ? dev->id : NULL, + dev ? dev->canonical_path : NULL, + pwr_led, power_led_new, + attn_led, attention_led_new, + state, state_new, + pwr, power_new); +} + static const TypeInfo pci_device_type_info =3D { .name =3D TYPE_PCI_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 774ce85619..37e2979b3c 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -45,6 +45,35 @@ static bool pcie_sltctl_powered_off(uint16_t sltctl) (sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF; } =20 +static HotplugLedState 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 HOTPLUG_LED_STATE_ON; + case PCI_EXP_SLTCTL_PWR_IND_BLINK: + case PCI_EXP_SLTCTL_ATTN_IND_BLINK: + return HOTPLUG_LED_STATE_BLINK; + case PCI_EXP_SLTCTL_PWR_IND_OFF: + case PCI_EXP_SLTCTL_ATTN_IND_OFF: + return HOTPLUG_LED_STATE_OFF; + default: + abort(); + } +} + +static HotplugPowerState pcie_power_state_to_qapi(uint16_t value) +{ + switch (value) { + case PCI_EXP_SLTCTL_PWR_ON: + return HOTPLUG_POWER_STATE_ON; + case PCI_EXP_SLTCTL_PWR_OFF: + return HOTPLUG_POWER_STATE_OFF; + default: + abort(); + } +} + /*************************************************************************= ** * pci express capability helper functions */ @@ -728,9 +757,13 @@ 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= )); =20 if (ranges_overlap(addr, len, pos + PCI_EXP_SLTSTA, 2)) { /* @@ -768,6 +801,22 @@ void pcie_cap_slot_write_config(PCIDevice *dev, sltsta); } =20 + power_led =3D val & PCI_EXP_SLTCTL_PIC; + attn_led =3D val & PCI_EXP_SLTCTL_AIC; + pcc =3D val & PCI_EXP_SLTCTL_PCC; + old_power_led =3D old_slt_ctl & PCI_EXP_SLTCTL_PIC; + old_attn_led =3D old_slt_ctl & PCI_EXP_SLTCTL_AIC; + old_pcc =3D old_slt_ctl & PCI_EXP_SLTCTL_PCC; + + pci_hotplug_state_event(DEVICE(dev), false, 0, child_dev, + pcie_led_state_to_qapi(old_power_led), + pcie_led_state_to_qapi(power_led), + pcie_led_state_to_qapi(old_attn_led), + pcie_led_state_to_qapi(attn_led), + 0, 0, /* no state */ + pcie_power_state_to_qapi(old_pcc), + pcie_power_state_to_qapi(pcc)); + /* * 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 9f964b1d70..3c62d6b054 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -8,6 +8,8 @@ #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" =20 /* TODO: model power only and disabled slot states. */ /* TODO: handle SERR and wakeups */ @@ -123,6 +125,34 @@ #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1) #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1) =20 +static HotplugLedState shpc_led_state_to_qapi(uint8_t value) +{ + switch (value) { + case SHPC_LED_ON: + return HOTPLUG_LED_STATE_ON; + case SHPC_LED_BLINK: + return HOTPLUG_LED_STATE_BLINK; + case SHPC_LED_OFF: + return HOTPLUG_LED_STATE_OFF; + default: + abort(); + } +} + +static HotplugSlotState shpc_slot_state_to_qapi(uint8_t value) +{ + switch (value) { + case SHPC_STATE_PWRONLY: + return HOTPLUG_SLOT_STATE_POWER_ONLY; + case SHPC_STATE_ENABLED: + return HOTPLUG_SLOT_STATE_ENABLED; + case SHPC_STATE_DISABLED: + return HOTPLUG_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 +298,12 @@ 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); + 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); @@ -302,6 +335,15 @@ static void shpc_slot_command(PCIDevice *d, uint8_t ta= rget, shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK); } =20 + pci_hotplug_state_event(DEVICE(d), true, SHPC_IDX_TO_PCI(slot), child_= dev, + shpc_led_state_to_qapi(old_power), + shpc_led_state_to_qapi(power ?: old_power), + shpc_led_state_to_qapi(old_attn), + shpc_led_state_to_qapi(attn ?: old_attn), + shpc_slot_state_to_qapi(old_state), + shpc_slot_state_to_qapi(state ?: old_state), + 0, 0 /* no PCC */); + if (!shpc_slot_is_off(old_state, old_power, old_attn) && shpc_slot_is_off(state, power, attn)) { --=20 2.34.1 From nobody Sat May 18 05:53:00 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=1675975139; cv=none; d=zohomail.com; s=zohoarc; b=GUqyzfqAzMjFKvTok4r8qKlMHmUJ0z4EpasQ26Yp3bucU8uWVXtpUcs4fCeTfyMtdxuvughLUmhWGN1vNVDc+p9Vu1SzMEH7s9XUmEScns3Vvsvui5l/H0FwrF5X4gTdv7O1Syi5LlFI+LdBdw0mkIY7gEcy3obJSkokxhpPfhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675975139; 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=wuxw4m3aS/CxFzYuJG41QbEdShNl70VxWIdILZrdVFI=; b=jLGlAXwmJODNAphSe9G39FXNfE5R4BhuGcdJJypXg8fP8JdXwfTcJKtokxG2xKq9jm71eI7JfrbvHPOELPUnECbPjdlrCFzY9Nu7rGdIgVK1VC3zC1I/8X7GkXYJt3idZax6VntZmfMP8ZjPZlBXlYLVrIEYAAESrarWEKoqIgA= 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 1675975139280457.1000097738141; Thu, 9 Feb 2023 12:38:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDy-0001gc-KI; Thu, 09 Feb 2023 15:08:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQDDq-0001cr-GO for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:46 -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 1pQDDn-0002j9-GS for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:46 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id EAC6461C5D; Thu, 9 Feb 2023 23:08:35 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-LTuA0rbT; Thu, 09 Feb 2023 23:08:35 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973315; bh=wuxw4m3aS/CxFzYuJG41QbEdShNl70VxWIdILZrdVFI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=lNOtVYLM/AXwPW0InSzpBS9a2WD5cZ+FcZWxKzkY3EUhJv1w72RPeJiIBCOl4JVdx KsguZEnU9ULWC5a3o80HcCb5moRAcNltBIeX5H0ryP2BPUYWSJfoxObdI6nJWUpHAO 7SiInpt5oE55qP/J8mp1fD4XKvUYGG+LW0Mp1YQ4= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 14/15] qapi: introduce DEVICE_ON event Date: Thu, 9 Feb 2023 23:08:07 +0300 Message-Id: <20230209200808.869275-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675975141660100001 Content-Type: text/plain; charset="utf-8" We have DEVICE_DELETED event, that signals that device_del command is actually complited. 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 | 24 ++++++++++++++++++++++++ hw/pci/pcie.c | 12 ++++++++++++ hw/pci/shpc.c | 12 ++++++++++++ 3 files changed, 48 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index 40dc34f091..94da7ca228 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -220,3 +220,27 @@ ## { 'event': 'HOTPLUG_STATE', 'data': 'HotplugState' } + + +## +# @DEVICE_ON: +# +# Emitted whenever the device insertion completion is acknowledged by the = guest. +# For now only emitted for SHPC and PCIe-native hotplug. +# +# @device: device name +# +# @path: device path +# +# Since: 8.0 +# +# Example: +# +# <- { "event": "DEVICE_ON", +# "data": { "device": "virtio-net-pci-0", +# "path": "/machine/peripheral/virtio-net-pci-0" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'DEVICE_ON', + 'data': { '*device': 'str', 'path': 'str' } } diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 37e2979b3c..bc7e60ff9d 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -45,6 +45,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 HotplugLedState pcie_led_state_to_qapi(uint16_t value) { switch (value) { @@ -816,6 +823,11 @@ void pcie_cap_slot_write_config(PCIDevice *dev, 0, 0, /* no state */ pcie_power_state_to_qapi(old_pcc), pcie_power_state_to_qapi(pcc)); + 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= ); + } =20 /* * If the slot is populated, power indicator is off and power diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 3c62d6b054..cce9cf19b5 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -293,6 +293,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) { @@ -355,6 +361,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 From nobody Sat May 18 05:53:00 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=1675973419; cv=none; d=zohomail.com; s=zohoarc; b=HcThxPzwYhoOMu3o1MWKQMklIqUIsRuJksAB+M+uEnYkIiHFwRfZ00gQxyXaLUaR9WvriabGiawXCKKAWTTF/TMHOFe/E1LZU8ZHZPvbw+2oQ6PQSWRN/DV4FAMqkfkSThvMwVP95DQnFgxOE8oEdxPiM0o5yepl5zwOUqgnEYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675973419; 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=8iV6c/j2vC5DlLdSxlYdvYM4RehP8AYMRSU4gVE43JA=; b=UNUy0ddm6Kp17U8k5zymAKuDIfjjvOa7Ql1BvxeQ79lzxcXZbkse/qEOpUn6fvFLOp/b4WmMGRYCOSq/0HeuzJmnjzjGdACddoIwHx38i0DJdc5W0lJQPm/uYlETLxOYu2/ogOmqazeoECipec9RSxgb7d+mGm1ip2UGdCYLgek= 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 1675973419423160.09109060095864; Thu, 9 Feb 2023 12:10:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQDDx-0001f9-B3; Thu, 09 Feb 2023 15:08:53 -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 1pQDDp-0001cL-Mh for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:45 -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 1pQDDn-0002jM-8F for qemu-devel@nongnu.org; Thu, 09 Feb 2023 15:08:45 -0500 Received: from myt5-8800bd68420f.qloud-c.yandex.net (myt5-8800bd68420f.qloud-c.yandex.net [IPv6:2a02:6b8:c12:4615:0:640:8800:bd68]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 184985E6B9; Thu, 9 Feb 2023 23:08:37 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:6518::1:1]) by myt5-8800bd68420f.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A8lCI60OTGk1-bdPQi8fz; Thu, 09 Feb 2023 23:08:36 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1675973316; bh=8iV6c/j2vC5DlLdSxlYdvYM4RehP8AYMRSU4gVE43JA=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=g+UQ/8hpzRmIaDldt69qrlFGq6ve+Rt/qni25QUHMwIPK3TuBvZc4IkyKzDLsxpF5 ldT/Rh7iSSE+K7JRFW1hxEeyKXw4ps+nu320Q97aAHIK414jiRh0flls1VvZsbaYpp q61L3OpkXNB3rDsu6XXKHg6U6V4MlkXTdApd8B7M= Authentication-Results: myt5-8800bd68420f.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, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru Subject: [PATCH v3 15/15] qapi: introduce query-hotplug command Date: Thu, 9 Feb 2023 23:08:08 +0300 Message-Id: <20230209200808.869275-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209200808.869275-1-vsementsov@yandex-team.ru> References: <20230209200808.869275-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: 1675973421843100003 Content-Type: text/plain; charset="utf-8" Add a command that returns same information like HOTPLUG_STATE event. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/qdev.json | 11 +++++++ include/hw/hotplug.h | 12 ++++++++ include/hw/pci/pci_bridge.h | 2 ++ include/hw/pci/pcie.h | 2 ++ include/hw/pci/shpc.h | 2 ++ hw/core/hotplug.c | 13 ++++++++ hw/pci-bridge/pci_bridge_dev.c | 14 +++++++++ hw/pci-bridge/pcie_pci_bridge.c | 1 + hw/pci/pcie.c | 28 +++++++++++++++++ hw/pci/pcie_port.c | 1 + hw/pci/shpc.c | 54 ++++++++++++++++++++++++++------- softmmu/qdev-monitor.c | 30 ++++++++++++++++++ 12 files changed, 159 insertions(+), 11 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index 94da7ca228..c3c2dfc388 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -244,3 +244,14 @@ ## { 'event': 'DEVICE_ON', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @query-hotplug: +# +# Query the state of hotplug controller. +# +# Since: 8.0 +## +{ 'command': 'query-hotplug', + 'data': { 'id': 'str' }, + 'returns': 'HotplugState' } diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index e15f59c8b3..a6ed7aa382 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; + HotplugState *(*get_hotplug_state)(HotplugHandler *plug_handler, + DeviceState *plugged_dev, Error **e= rrp); }; =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. + */ +HotplugState *hotplug_handler_get_hotplug_state(HotplugHandler *plug_handl= er, + DeviceState *plugged_dev, + Error **errp); #endif diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h index 63a7521567..566cf8df7b 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); +HotplugState *pci_bridge_dev_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **e= rrp); =20 /* * before qdev initialization(qdev_init()), this function sets bus_name and diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h index 3cc2b15957..2379227a70 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); +HotplugState *pcie_cap_slot_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **er= rp); #endif /* QEMU_PCIE_H */ diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h index 89c7a3b7fa..b68ec30a87 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); +HotplugState *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/hw/core/hotplug.c b/hw/core/hotplug.c index 17ac986685..c60ab86ce2 100644 --- a/hw/core/hotplug.c +++ b/hw/core/hotplug.c @@ -57,6 +57,19 @@ void hotplug_handler_unplug(HotplugHandler *plug_handler, } } =20 +HotplugState *hotplug_handler_get_hotplug_state(HotplugHandler *plug_handl= er, + DeviceState *plugged_dev, + Error **errp) +{ + HotplugHandlerClass *hdc =3D HOTPLUG_HANDLER_GET_CLASS(plug_handler); + + if (hdc->get_hotplug_state) { + return hdc->get_hotplug_state(plug_handler, plugged_dev, errp); + } + + return NULL; +} + static const TypeInfo hotplug_handler_info =3D { .name =3D TYPE_HOTPLUG_HANDLER, .parent =3D TYPE_INTERFACE, diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c index 4b2696ea7f..21bb3551f0 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 +HotplugState *pci_bridge_dev_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **e= rrp) +{ + PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); + + if (!shpc_present(pci_hotplug_dev)) { + error_setg(errp, "standard hotplug controller has been disabled fo= r " + "this %s", object_get_typename(OBJECT(hotplug_dev))); + return NULL; + } + return shpc_get_hotplug_state(hotplug_dev, dev, errp); +} + static void pci_bridge_dev_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -261,6 +274,7 @@ static void pci_bridge_dev_class_init(ObjectClass *klas= s, void *data) hc->plug =3D pci_bridge_dev_plug_cb; hc->unplug =3D pci_bridge_dev_unplug_cb; hc->unplug_request =3D pci_bridge_dev_unplug_request_cb; + hc->get_hotplug_state =3D pci_bridge_dev_get_hotplug_state; } =20 static const TypeInfo pci_bridge_dev_info =3D { diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridg= e.c index 2301b2ca0b..959b536303 100644 --- a/hw/pci-bridge/pcie_pci_bridge.c +++ b/hw/pci-bridge/pcie_pci_bridge.c @@ -157,6 +157,7 @@ static void pcie_pci_bridge_class_init(ObjectClass *kla= ss, void *data) hc->plug =3D pci_bridge_dev_plug_cb; hc->unplug =3D pci_bridge_dev_unplug_cb; hc->unplug_request =3D pci_bridge_dev_unplug_request_cb; + hc->get_hotplug_state =3D pci_bridge_dev_get_hotplug_state; } =20 static const TypeInfo pcie_pci_bridge_info =3D { diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index bc7e60ff9d..67427c0cf2 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -1161,3 +1161,31 @@ void pcie_acs_reset(PCIDevice *dev) pci_set_word(dev->config + dev->exp.acs_cap + PCI_ACS_CTRL, 0); } } + +HotplugState *pcie_cap_slot_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **er= rp) +{ + PCIDevice *hotplug_pdev =3D PCI_DEVICE(hotplug_dev); + DeviceState *hotplug_ds =3D DEVICE(hotplug_pdev); + uint8_t *exp_cap =3D hotplug_pdev->config + hotplug_pdev->exp.exp_cap; + uint16_t sltctl =3D pci_get_word(exp_cap + PCI_EXP_SLTCTL); + uint16_t power_led =3D sltctl & PCI_EXP_SLTCTL_PIC; + uint16_t attn_led =3D sltctl & PCI_EXP_SLTCTL_AIC; + uint16_t pcc =3D sltctl & PCI_EXP_SLTCTL_PCC; + HotplugState *res =3D g_new(HotplugState, 1); + + *res =3D (HotplugState) { + .hotplug_device =3D g_strdup(hotplug_ds->id), + .hotplug_path =3D g_strdup(hotplug_ds->canonical_path), + .device =3D g_strdup(dev->id), + .path =3D g_strdup(dev->canonical_path), + .has_power_led =3D true, + .power_led =3D pcie_led_state_to_qapi(power_led), + .has_attention_led =3D true, + .attention_led =3D pcie_led_state_to_qapi(attn_led), + .has_power =3D true, + .power =3D pcie_power_state_to_qapi(pcc), + }; + + return res; +} diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c index 65a397ad23..8b28efc52d 100644 --- a/hw/pci/pcie_port.c +++ b/hw/pci/pcie_port.c @@ -188,6 +188,7 @@ static void pcie_slot_class_init(ObjectClass *oc, void = *data) hc->plug =3D pcie_cap_slot_plug_cb; hc->unplug =3D pcie_cap_slot_unplug_cb; hc->unplug_request =3D pcie_cap_slot_unplug_request_cb; + hc->get_hotplug_state =3D pcie_cap_slot_get_hotplug_state; } =20 static const TypeInfo pcie_slot_type_info =3D { diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index cce9cf19b5..4fb37a2436 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -550,8 +550,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); @@ -561,21 +562,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 @@ -617,16 +617,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 @@ -770,6 +767,41 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr= , uint32_t val, int l) shpc_cap_update_dword(d); } =20 +HotplugState *shpc_get_hotplug_state(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); + DeviceState *hotplug_ds =3D DEVICE(pci_hotplug_dev); + SHPCDevice *shpc =3D pci_hotplug_dev->shpc; + int slot; + uint8_t state, power, attn; + HotplugState *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(HotplugState, 1); + *res =3D (HotplugState) { + .hotplug_device =3D g_strdup(hotplug_ds->id), + .hotplug_path =3D g_strdup(hotplug_ds->canonical_path), + .device =3D g_strdup(dev->id), + .path =3D g_strdup(dev->canonical_path), + .has_power_led =3D true, + .power_led =3D shpc_led_state_to_qapi(power), + .has_attention_led =3D true, + .attention_led =3D shpc_led_state_to_qapi(attn), + .has_state =3D true, + .state =3D shpc_slot_state_to_qapi(state), + }; + + return res; +} + static int shpc_save(QEMUFile *f, void *pv, size_t size, const VMStateField *field, JSONWriter *vmdesc) { diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b8d2c4dadd..bd47c117dc 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -956,6 +956,36 @@ void qmp_device_del(const char *id, Error **errp) } } =20 +HotplugState *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; --=20 2.34.1