From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 331AEC7EE23 for ; Wed, 1 Mar 2023 21:08:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXTgE-0003tU-Vf; Wed, 01 Mar 2023 16:08:06 -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 1pXTgD-0003tK-Of for qemu-devel@nongnu.org; Wed, 01 Mar 2023 16:08:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXTgB-0007JJ-O8 for qemu-devel@nongnu.org; Wed, 01 Mar 2023 16:08:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677704882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RAggOQHsrgTTrxGAn50qC31Nkm/K+Q8AxEy3yqbTA3Y=; b=MLT7LSXqFby9/OeDiGoNptL+Rgs+PCGVMkNDDS/jb2/o2bEwwhIo9eCIznDKauQd69au+I /8obdLALp6aom+rpRwEzNiHNm+/28ucyhBJG6IKPLLCii+FfW0gGE3b1WDDxjXZK9BbyNv nh6xG9kJNrjGv6Qaelg/AWWg3VoL/LQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-654-FisExeRvNw2Z2L6eYufCrw-1; Wed, 01 Mar 2023 16:08:01 -0500 X-MC-Unique: FisExeRvNw2Z2L6eYufCrw-1 Received: by mail-wm1-f72.google.com with SMTP id n27-20020a05600c3b9b00b003e9ca0f4677so199210wms.8 for ; Wed, 01 Mar 2023 13:08:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677704880; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RAggOQHsrgTTrxGAn50qC31Nkm/K+Q8AxEy3yqbTA3Y=; b=AtV+4DZjUmENHprv2LgP1Dp0nftC3iqfgc2If9UnsPOK0P3hRyKz0US/najNspEV5b 8n88sOUCK8kFmhu1s5iKZgVJwGO+RvkkXn72DxhLa9dvCwvs/eyNWDztp86LKewZ4qZy cg4N8TaTnbAwCy27dC0GVmP2+RiFgyImza4DtE21akp4rI0ZCiFChBLfDIPwKMwa1zHA FonEYchXmdLEB2jzp0FEXLzbZraIH8bLWq+qqL18Nz3PvXcKZiPwnhdVVdMoIED33szd hcTKcVH1nz7KZxqCtAEg8MLcrSaB3DAS9vYCdDrTVKw+REv/pEv7jUJ6/XHk8SLjJD60 JAXA== X-Gm-Message-State: AO0yUKWoMxwmuV9FZGLdE2qQGMWrwCC2Spq+7MRz02FIx52vV478w3JK KZmmC4L0FNf6TT8jYaCKNeFv6z5sRUuPuiXeEcgW/2Yf3akYVzoGCY0/vUc4q/jJ7giAkUqBtHz PrROTWKGoDDp+5+4= X-Received: by 2002:adf:f405:0:b0:2c7:2cf4:baff with SMTP id g5-20020adff405000000b002c72cf4baffmr6610054wro.70.1677704880121; Wed, 01 Mar 2023 13:08:00 -0800 (PST) X-Google-Smtp-Source: AK7set9PlvA74njpit57scCWH6hRBnecJokoJfkC1wYdUTdOjnjya/qHDAV8HM0csS64Brdj2UO2Xw== X-Received: by 2002:adf:f405:0:b0:2c7:2cf4:baff with SMTP id g5-20020adff405000000b002c72cf4baffmr6610040wro.70.1677704879783; Wed, 01 Mar 2023 13:07:59 -0800 (PST) Received: from redhat.com ([2.52.141.194]) by smtp.gmail.com with ESMTPSA id y18-20020adffa52000000b002c55efa9cbesm13267555wrr.39.2023.03.01.13.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 13:07:59 -0800 (PST) Date: Wed, 1 Mar 2023 16:07:54 -0500 From: "Michael S. Tsirkin" To: Vladimir Sementsov-Ogievskiy Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, marcel.apfelbaum@gmail.com, philmd@linaro.org, den-plotnikov@yandex-team.ru, antonkuchin@yandex-team.ru Subject: Re: [PATCH v5 18/18] qapi: introduce DEVICE_ON event Message-ID: <20230301160635-mutt-send-email-mst@kernel.org> References: <20230216180356.156832-1-vsementsov@yandex-team.ru> <20230216180356.156832-19-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230216180356.156832-19-vsementsov@yandex-team.ru> Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Thu, Feb 16, 2023 at 09:03:56PM +0300, Vladimir Sementsov-Ogievskiy wrote: > We have DEVICE_DELETED event, that signals that device_del command is > actually completed. But we don't have a counter-part for device_add. > Still it's sensible for SHPC and PCIe-native hotplug, as there are time > when the device in some intermediate state. Let's add an event that say > that the device is finally powered on, power indicator is on and > everything is OK for next manipulation on that device. > > Signed-off-by: Vladimir Sementsov-Ogievskiy I don't much mind though a bit more motivation would be nice. How is this going to be used? When does management care? Meanwhile, for the schema - can this one get ACKs from QAPI maintainers please? > --- > qapi/qdev.json | 10 ++++++++++ > hw/pci/pcie.c | 14 ++++++++++++++ > hw/pci/shpc.c | 12 ++++++++++++ > 3 files changed, 36 insertions(+) > > diff --git a/qapi/qdev.json b/qapi/qdev.json > index 6f2d8d6647..116a8a7de8 100644 > --- a/qapi/qdev.json > +++ b/qapi/qdev.json > @@ -348,3 +348,13 @@ > { 'command': 'query-hotplug', > 'data': { 'id': 'str' }, > 'returns': 'HotplugInfo' } > + > +## > +# @DEVICE_ON: > +# > +# Emitted whenever the device insertion completion is acknowledged by the guest. > +# For now only emitted for SHPC and PCIe-native hotplug. > +# > +# Since: 8.0 > +## > +{ 'event': 'DEVICE_ON', 'data': 'DeviceAndPath' } > diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c > index 636f962a23..4297e4e8dc 100644 > --- a/hw/pci/pcie.c > +++ b/hw/pci/pcie.c > @@ -22,6 +22,7 @@ > > #include "monitor/qdev.h" > #include "qapi/error.h" > +#include "qapi/qapi-events-qdev.h" > #include "hw/pci/pci_bridge.h" > #include "hw/pci/pcie.h" > #include "hw/pci/msix.h" > @@ -47,6 +48,13 @@ static bool pcie_sltctl_powered_off(uint16_t sltctl) > && (sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF; > } > > +static bool pcie_sltctl_powered_on(uint16_t sltctl) > +{ > + return (sltctl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_ON && > + (sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_ON && > + (sltctl & PCI_EXP_SLTCTL_AIC) == PCI_EXP_SLTCTL_ATTN_IND_OFF; > +} > + > static LedActivity pcie_led_state_to_qapi(uint16_t value) > { > switch (value) { > @@ -816,6 +824,12 @@ void pcie_cap_slot_write_config(PCIDevice *dev, > qdev_hotplug_state_event(DEVICE(dev), NULL, child_dev, &changed_state); > } > > + if ((sltsta & PCI_EXP_SLTSTA_PDS) && pcie_sltctl_powered_on(val) && > + !pcie_sltctl_powered_on(old_slt_ctl) && child_dev) > + { > + qapi_event_send_device_on(child_dev->id, child_dev->canonical_path); > + } > + > /* > * If the slot is populated, power indicator is off and power > * controller is off, it is safe to detach the devices. > diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c > index 6a4f93949d..380b2b83b3 100644 > --- a/hw/pci/shpc.c > +++ b/hw/pci/shpc.c > @@ -299,6 +299,12 @@ static bool shpc_slot_is_off(uint8_t state, uint8_t power, uint8_t attn) > return state == SHPC_STATE_DISABLED && power == SHPC_LED_OFF; > } > > +static bool shpc_slot_is_on(uint8_t state, uint8_t power, uint8_t attn) > +{ > + return state == SHPC_STATE_ENABLED && power == SHPC_LED_ON && > + attn == SHPC_LED_OFF; > +} > + > static void shpc_slot_command(PCIDevice *d, uint8_t target, > uint8_t state, uint8_t power, uint8_t attn) > { > @@ -366,6 +372,12 @@ static void shpc_slot_command(PCIDevice *d, uint8_t target, > 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); > + } > } > > static void shpc_command(PCIDevice *d) > -- > 2.34.1