[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper |
Date: |
Thu, 9 Feb 2023 22:23:00 +0100 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 |
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>
- [PATCH v3 00/15] pci hotplug tracking, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 05/15] pci/shpc: pass PCIDevice pointer to shpc_slot_command(), Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 04/15] pci/shpc: more generic handle hot-unplug in shpc_slot_command(), Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 02/15] pci/shpc: change shpc_get_status() return type to uint8_t, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 06/15] pcie: pcie_cap_slot_write_config(): use correct macro, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 08/15] pcie: drop unused PCIExpressIndicator, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper, Vladimir Sementsov-Ogievskiy, 2023/02/09
- Re: [PATCH v3 10/15] pcie: introduce pcie_sltctl_powered_off() helper,
Philippe Mathieu-Daudé <=
- [PATCH v3 03/15] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 07/15] pcie_regs: drop duplicated indicator value macros, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 01/15] pci/shpc: set attention led to OFF on reset, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 09/15] pcie: pcie_cap_slot_enable_power() use correct helper, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 11/15] pcie: set power indicator to off on reset by default, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 15/15] qapi: introduce query-hotplug command, Vladimir Sementsov-Ogievskiy, 2023/02/09
- [PATCH v3 13/15] qapi: add HOTPLUG_STATE event, Vladimir Sementsov-Ogievskiy, 2023/02/09