From: "Michael S. Tsirkin" <mst@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
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
Date: Wed, 1 Mar 2023 16:07:54 -0500 [thread overview]
Message-ID: <20230301160635-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230216180356.156832-19-vsementsov@yandex-team.ru>
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 <vsementsov@yandex-team.ru>
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
next prev parent reply other threads:[~2023-03-01 21:08 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 18:03 [PATCH v5 00/18] pci hotplug tracking Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 01/18] pci/shpc: set attention led to OFF on reset Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 02/18] pci/shpc: change shpc_get_status() return type to uint8_t Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 03/18] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 04/18] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 05/18] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 06/18] pci/shpc: refactor shpc_device_plug_common() Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 07/18] pcie: pcie_cap_slot_write_config(): use correct macro Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 08/18] pcie_regs: drop duplicated indicator value macros Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 09/18] pcie: drop unused PCIExpressIndicator Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 10/18] pcie: pcie_cap_slot_enable_power() use correct helper Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 11/18] pcie: introduce pcie_sltctl_powered_off() helper Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 12/18] pcie: set power indicator to off on reset by default Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 13/18] pci: introduce pci_find_the_only_child() Vladimir Sementsov-Ogievskiy
2023-03-01 21:09 ` Michael S. Tsirkin
2023-03-02 8:28 ` Vladimir Sementsov-Ogievskiy
2023-03-02 8:37 ` Michael S. Tsirkin
2023-03-02 8:45 ` Vladimir Sementsov-Ogievskiy
2023-03-02 8:53 ` Michael S. Tsirkin
2023-03-02 9:35 ` Vladimir Sementsov-Ogievskiy
2023-03-02 9:39 ` Michael S. Tsirkin
2023-02-16 18:03 ` [PATCH v5 14/18] qapi/qdev.json: unite DEVICE_* event data into single structure Vladimir Sementsov-Ogievskiy
2023-03-01 21:08 ` Michael S. Tsirkin
2023-02-16 18:03 ` [PATCH v5 15/18] qapi: add HOTPLUG_STATE infrastructure Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 16/18] shpc: implement HOTPLUG_STATE event and query-hotplug Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 17/18] pcie: " Vladimir Sementsov-Ogievskiy
2023-02-16 18:03 ` [PATCH v5 18/18] qapi: introduce DEVICE_ON event Vladimir Sementsov-Ogievskiy
2023-03-01 21:07 ` Michael S. Tsirkin [this message]
2023-03-02 8:39 ` Vladimir Sementsov-Ogievskiy
2023-03-02 8:50 ` Michael S. Tsirkin
2023-03-02 9:16 ` Vladimir Sementsov-Ogievskiy
2023-03-02 9:38 ` Michael S. Tsirkin
2023-03-02 8:44 ` Michael S. Tsirkin
2023-03-02 10:03 ` Vladimir Sementsov-Ogievskiy
2023-03-02 10:05 ` Michael S. Tsirkin
2023-03-01 21:16 ` [PATCH v5 00/18] pci hotplug tracking Michael S. Tsirkin
2023-03-02 8:51 ` Vladimir Sementsov-Ogievskiy
2023-03-01 21:17 ` Michael S. Tsirkin
2023-03-02 9:36 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230301160635-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=antonkuchin@yandex-team.ru \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=den-plotnikov@yandex-team.ru \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).