From nobody Fri May 10 02:51:50 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=1668615224; cv=none; d=zohomail.com; s=zohoarc; b=B5o7sdI+oclciLgRuID+SGy3z/3/F+uydQXOlhFX+TEmHNFQD3eOVPkruPANjuK3Yctyg2fUfowt+uWlzAhSizuwPizNx/RW2bXhyw6vbhUN/aezMav/B97ols1OC0OHawQsJ95gIcY4psAaggFzmUSLyJdL9qAhIakUfqZSDPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668615224; 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=pXL2EsPAT+iu0OJdzb46Em8htiMdE0Ui/fug/j2J5HI=; b=LrQbju6RBrNgrp420LG81Q4M9//SqX3RRUFpOT1ZiCaejzo+kOkI4t88XRmYUCVeBjMo6cl6O3AxJslxq8s6dlZ4z72s/WC9y5Y6EJYc6BJi3tTjluCOdtkI3N0hFXTmTl9DPbq6MsnnkSPeGuaVuXaPfmF1T2v7e9xbKSZfD7c= 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 1668615224302510.13505159691977; Wed, 16 Nov 2022 08:13:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovL2D-0007gS-JV; Wed, 16 Nov 2022 11:13:09 -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 1ovL26-0007fn-R5 for qemu-devel@nongnu.org; Wed, 16 Nov 2022 11:13:02 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovL25-0000ey-85 for qemu-devel@nongnu.org; Wed, 16 Nov 2022 11:13:02 -0500 Received: from vla5-b2806cb321eb.qloud-c.yandex.net (vla5-b2806cb321eb.qloud-c.yandex.net [IPv6:2a02:6b8:c18:3e0d:0:640:b280:6cb3]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTP id AC52F600F5; Wed, 16 Nov 2022 19:12:45 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8128::1:3]) by vla5-b2806cb321eb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6qDkL1QYoB-CjO0pUUi; Wed, 16 Nov 2022 19:12:45 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1668615165; bh=pXL2EsPAT+iu0OJdzb46Em8htiMdE0Ui/fug/j2J5HI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Qqi19rsxBMEoDiY/v5LqhDhpO+ultO3rmWxAwY+9m4dJh79dYt6R2S9Fo1eFg7ktN DBc1RBYqsiaf/nYBYpZn4vBBarPrIcasCQH7Z60a/Iiv3TSgyvEhtGw12ePIu7b4JZ O7g+NfZ14qnBQ1rvFl7n7yaPugp24mVhq3Af+2xA= Authentication-Results: vla5-b2806cb321eb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, armbru@redhat.com, eblake@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, imammedo@redhat.com, ani@anisinha.ca, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 1/2] hw/pci/shpc: introduce FOR_EACH_DEVICE_IN_SLOT Date: Wed, 16 Nov 2022 19:12:33 +0300 Message-Id: <20221116161234.44206-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221116161234.44206-1-vsementsov@yandex-team.ru> References: <20221116161234.44206-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1668615306725100001 Content-Type: text/plain; charset="utf-8" Introduce a macro to loop through devices like in shpc_free_devices_in_slot(), as we are going to add one more similar function. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/shpc.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index e71f3a7483..ba241e2818 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -236,22 +236,41 @@ static void shpc_invalid_command(SHPCDevice *shpc) SHPC_CMD_STATUS_INVALID_CMD); } =20 -static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot) +static PCIDevice *shpc_next_device_in_slot(SHPCDevice *shpc, int slot, + int *start_devfn) { - HotplugHandler *hotplug_ctrl; int devfn; int pci_slot =3D SHPC_IDX_TO_PCI(slot); - for (devfn =3D PCI_DEVFN(pci_slot, 0); + + for (devfn =3D *start_devfn ?: PCI_DEVFN(pci_slot, 0); devfn <=3D PCI_DEVFN(pci_slot, PCI_FUNC_MAX - 1); ++devfn) { - PCIDevice *affected_dev =3D shpc->sec_bus->devices[devfn]; - if (affected_dev) { - hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(affected_dev)= ); - hotplug_handler_unplug(hotplug_ctrl, DEVICE(affected_dev), - &error_abort); - object_unparent(OBJECT(affected_dev)); + PCIDevice *dev =3D shpc->sec_bus->devices[devfn]; + if (dev) { + *start_devfn =3D devfn + 1; /* for next iteration */ + return dev; } } + + return NULL; +} + +#define FOR_EACH_DEVICE_IN_SLOT(shpc, slot, dev, devfn) \ + for ((devfn) =3D 0, \ + (dev) =3D shpc_next_device_in_slot((shpc), (slot), &(devfn)); \ + (dev); (dev) =3D shpc_next_device_in_slot((shpc), (slot), &(devfn= ))) + +static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot) +{ + HotplugHandler *hotplug_ctrl; + int devfn; + PCIDevice *dev; + + FOR_EACH_DEVICE_IN_SLOT(shpc, slot, dev, devfn) { + hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(dev)); + hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort); + object_unparent(OBJECT(dev)); + } } =20 static void shpc_slot_command(SHPCDevice *shpc, uint8_t target, --=20 2.34.1 From nobody Fri May 10 02:51:50 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=1668615223; cv=none; d=zohomail.com; s=zohoarc; b=hAtOsdBaNEBZWMkvmVjm8QfMZEuclIih6HcMmByUiNIGxDXvSGCEa5odFBA24pr9mGZZqUiPyeqbVA1cEAHja5KnrSa1LhEYKZxBkLM1xqEX6fT0cGxZEChRBHovY7/eWtcA+n3SKP8s/K5W458d2FNAx0uAn79CC9DuEKbeFEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668615223; 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=pxy8SoZKMYQOtt4zyvcYm1JwSwGd6OKGn9O3dAAlZPQ=; b=I6zwqjGuhbArJmz6K01O5xZBH75mDH24RzlweKAuldOjVu1isP9R4SA0l9jT3YtKcsxLqBLV9S5v8A4TVjUg4bWM3dcHGtVp4VkX3YbBDlCKbUmUa2TXTkds9I/+GUNBwNpMM2x39XBF4z/tW/bU6RF4hZXxvGIkQOOvjNxB6+Q= 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 1668615223597655.6780032476829; Wed, 16 Nov 2022 08:13:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovL23-0007es-MU; Wed, 16 Nov 2022 11:12:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovL22-0007dz-HG for qemu-devel@nongnu.org; Wed, 16 Nov 2022 11:12:58 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovL1z-0000da-7b for qemu-devel@nongnu.org; Wed, 16 Nov 2022 11:12:57 -0500 Received: from vla5-b2806cb321eb.qloud-c.yandex.net (vla5-b2806cb321eb.qloud-c.yandex.net [IPv6:2a02:6b8:c18:3e0d:0:640:b280:6cb3]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTP id 84294600F6; Wed, 16 Nov 2022 19:12:46 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8128::1:3]) by vla5-b2806cb321eb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6qDkL1QYoB-CjO0mh7k; Wed, 16 Nov 2022 19:12:45 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1668615165; bh=pxy8SoZKMYQOtt4zyvcYm1JwSwGd6OKGn9O3dAAlZPQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=oP10KNchVcHLB7r7Dt1hNnBaMtilxD+VgRMqAPnCIS4auk/Uv6bpTgj6YLfKO4GVv gOuvyesUv7DsFqo3pz5XeGBD7rzICYeqn0HrMKNKLVn9u+y+q1BObbawXxGMk2IomZ rglpsMGbHn+W4i04hbfmvyx+IRQ/OLkLmsXY+RWs= Authentication-Results: vla5-b2806cb321eb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, armbru@redhat.com, eblake@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, imammedo@redhat.com, ani@anisinha.ca, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 2/2] qapi: introduce DEVICE_POWER_ON for SHPC hotplug Date: Wed, 16 Nov 2022 19:12:34 +0300 Message-Id: <20221116161234.44206-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221116161234.44206-1-vsementsov@yandex-team.ru> References: <20221116161234.44206-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1668615298178100001 Content-Type: text/plain; charset="utf-8" Hi all! That's an RFC patch. The problem is that SHPC protocol says that power-led is blinking for 5 seconds before actual turning-on the device. If we call device-del during this time the attention button press is ignored and we never get DEVICE_DELETED event, which is unexpected for the user. I suggest add a pair for DEVICE_DELETED: DEVICE_POWER_ON. So user should wait for DEVICE_POWER_ON after device-add before making any other operations with the device (incluing device-del). What I'm unsure is what about other types of hotplug - PCIE and ACPI.. Do they suffer from similar problems? Seems not.. Should we sent for them this event at some moment of should the user be aware of which kind of hotplug is in use to determine to wait for the DEVICE_POWER_ON or not to wait. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/shpc.c | 16 ++++++++++++++++ qapi/qdev.json | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index ba241e2818..7c53971c1c 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -1,5 +1,6 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-events-qdev.h" #include "qemu/host-utils.h" #include "qemu/range.h" #include "qemu/error-report.h" @@ -273,6 +274,18 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc= , int slot) } } =20 +static void shpc_devices_power_on_in_slot(SHPCDevice *shpc, int slot) +{ + int devfn; + PCIDevice *dev; + + FOR_EACH_DEVICE_IN_SLOT(shpc, slot, dev, devfn) { + DeviceState *ds =3D DEVICE(dev); + + qapi_event_send_device_power_on(!!ds->id, ds->id, ds->canonical_pa= th); + } +} + static void shpc_slot_command(SHPCDevice *shpc, uint8_t target, uint8_t state, uint8_t power, uint8_t attn) { @@ -291,6 +304,9 @@ static void shpc_slot_command(SHPCDevice *shpc, uint8_t= target, switch (power) { case SHPC_LED_NO: break; + case SHPC_LED_ON: + shpc_devices_power_on_in_slot(shpc, slot); + __attribute__ ((fallthrough)); default: /* TODO: send event to monitor */ shpc_set_status(shpc, slot, power, SHPC_SLOT_PWR_LED_MASK); diff --git a/qapi/qdev.json b/qapi/qdev.json index 2708fb4e99..360dcf8ba6 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -158,3 +158,26 @@ ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @DEVICE_POWER_ON: +# +# Emitted whenever power is on for the devices plugged into pci slot. +# At this point it's safe to remove the device. +# +# @device: the device's ID if it has one +# +# @path: the device's QOM path +# +# Since: 7.2 +# +# Example: +# +# <- { "event": "DEVICE_POWER_ON", +# "data": { "device": "virtio-disk-0", +# "path": "/machine/peripheral/virtio-disk-0" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'DEVICE_POWER_ON', + 'data': { '*device': 'str', 'path': 'str' } } --=20 2.34.1