Re: [PATCH v2 1/4] PCI: Add pci_power_t helper functions
From: Bjorn Helgaas
Date: Thu Nov 19 2026 - 12:25:26 EST
On Thu, Nov 19, 2026 at 02:35:46PM +0000, Habil Eren Türker wrote:
> Add helper functions to extract, set and compare PCI power
> states in the Power Management Control/Status register.
>
> This follows the discussion with Andy Shevchenko and
> Bjorn Helgaas in response to:
>
> "[PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()"
> https://lore.kernel.org/lkml/20261118161559.63617-1-habilerenturker@xxxxxxxxxxx/
Andy had good comments about the style of references like this, but
IMO if your cover letter includes links to previous versions of the
series, that's enough of a breadcrumb, and previous review comments
and suggestions don't need to be explicitly called out.
https://lore.kernel.org/all/20261112-vfct-regression-v7-0-69b1e0cf45c2@xxxxxxx
is a good example of the previous version link documentation in the
cover letter.
> @@ -2953,4 +2954,31 @@ void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type);
> WARN_ONCE(condition, "%s %s: " fmt, \
> dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
>
> +/* Helper functions for PCI power management */
I think these should go right next to the pci_power_t definitions,
e.g., right after pci_power_name(), so they are easy to find when
using PCI_D0 etc.
> +static inline pci_power_t pci_power_t_get(u32 csr)
> +{
> + return (pci_power_t __force)FIELD_GET(PCI_PM_CTRL_STATE_MASK, csr);
> +}
> +
> +static inline void pci_power_t_set(u16 *csr, pci_power_t state)
> +{
> + *csr &= ~PCI_PM_CTRL_STATE_MASK;
> + *csr |= FIELD_PREP(PCI_PM_CTRL_STATE_MASK, (__force u32)state);
FIELD_MODIFY().
> +}
> +
> +static inline bool pci_power_eq(u32 csr, pci_power_t state)
> +{
> + return pci_power_t_get(csr) == state;
> +}
> +
> +static inline bool pci_power_gt(u32 csr, pci_power_t state)
> +{
> + return pci_power_t_get(csr) > state;
I'm not a __bitwise expert, but I'm surprised this works. I expected
that __bitwise values would not be ordered, so only testing for
equality would be legit.
I do think these should take two pci_power_t values instead of a PMCSR
value and a pci_power_t. The extra internal conversion on one
argument feels a little bit non-intuitive.
> +}
> +
> +static inline bool pci_power_lt(u32 csr, pci_power_t state)
> +{
> + return pci_power_t_get(csr) < state;
> +}
> +
> #endif /* LINUX_PCI_H */
> --
> 2.47.3
>