qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	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,
	den-plotnikov@yandex-team.ru
Subject: Re: [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper
Date: Thu, 9 Feb 2023 22:23:00 +0100	[thread overview]
Message-ID: <00d3fa26-5bec-a3ad-f4e9-b6ccf8933d79@linaro.org> (raw)
In-Reply-To: <20230209200808.869275-11-vsementsov@yandex-team.ru>

On 9/2/23 21:08, Vladimir Sementsov-Ogievskiy wrote:
> 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 <vsementsov@yandex-team.ru>
> ---
>   hw/pci/pcie.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)


> +static bool pcie_sltctl_powered_off(uint16_t sltctl)
> +{
> +    return (sltctl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_OFF &&
> +        (sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF;

Matter of taste (it is harder to miss the &&):

    return (sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF
            && (sltctl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_OFF;


> @@ -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) == PCI_EXP_SLTCTL_PWR_IND_OFF &&
> -        (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) ||
> -        (old_slt_ctl & PCI_EXP_SLTCTL_PIC) != PCI_EXP_SLTCTL_PWR_IND_OFF)) {
> +    if ((sltsta & PCI_EXP_SLTSTA_PDS) && pcie_sltctl_powered_off(val) &&
> +        !pcie_sltctl_powered_off(old_slt_ctl))

Certainly simpler!

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



  reply	other threads:[~2023-02-09 21:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-09 20:07 [PATCH v3 00/15] pci hotplug tracking Vladimir Sementsov-Ogievskiy
2023-02-09 20:07 ` [PATCH v3 01/15] pci/shpc: set attention led to OFF on reset Vladimir Sementsov-Ogievskiy
2023-02-09 20:07 ` [PATCH v3 02/15] pci/shpc: change shpc_get_status() return type to uint8_t Vladimir Sementsov-Ogievskiy
2023-02-09 20:07 ` [PATCH v3 03/15] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Vladimir Sementsov-Ogievskiy
2023-02-09 20:07 ` [PATCH v3 04/15] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Vladimir Sementsov-Ogievskiy
2023-02-09 20:07 ` [PATCH v3 05/15] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Vladimir Sementsov-Ogievskiy
2023-02-09 20:07 ` [PATCH v3 06/15] pcie: pcie_cap_slot_write_config(): use correct macro Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 07/15] pcie_regs: drop duplicated indicator value macros Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 08/15] pcie: drop unused PCIExpressIndicator Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 09/15] pcie: pcie_cap_slot_enable_power() use correct helper Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper Vladimir Sementsov-Ogievskiy
2023-02-09 21:23   ` Philippe Mathieu-Daudé [this message]
2023-02-09 20:08 ` [PATCH v3 11/15] pcie: set power indicator to off on reset by default Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 12/15] pci: introduce pci_find_the_only_child() Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 13/15] qapi: add HOTPLUG_STATE event Vladimir Sementsov-Ogievskiy
2023-02-09 21:28   ` Philippe Mathieu-Daudé
2023-02-10 10:47     ` Vladimir Sementsov-Ogievskiy
2023-02-10 11:20       ` Philippe Mathieu-Daudé
2023-02-10 10:23   ` Markus Armbruster
2023-02-10 11:36     ` Vladimir Sementsov-Ogievskiy
2023-02-10 12:01       ` Markus Armbruster
2023-02-10 13:38         ` Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 14/15] qapi: introduce DEVICE_ON event Vladimir Sementsov-Ogievskiy
2023-02-09 21:37   ` Philippe Mathieu-Daudé
2023-02-10 13:49     ` Vladimir Sementsov-Ogievskiy
2023-02-13  9:30       ` Markus Armbruster
2023-02-13 11:43         ` Vladimir Sementsov-Ogievskiy
2023-02-09 20:08 ` [PATCH v3 15/15] qapi: introduce query-hotplug command Vladimir Sementsov-Ogievskiy
2023-02-10 10:09   ` Markus Armbruster
2023-02-10 13:51     ` 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=00d3fa26-5bec-a3ad-f4e9-b6ccf8933d79@linaro.org \
    --to=philmd@linaro.org \
    --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=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --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).