* [PATCH v2 0/4] PCI: Add pci_power_t helper functions
@ 2026-11-19 14:35 Habil Eren Türker
2026-11-19 14:35 ` [PATCH v2 1/4] " Habil Eren Türker
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Habil Eren Türker @ 2026-11-19 14:35 UTC (permalink / raw)
To: bhelgaas
Cc: andriy.shevchenko, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86, Habil Eren Türker
This series introduces helper functions for accessing PCI power
states in the Power Management Control/Status register and
converts existing PMCSR accesses to use these helpers.
The helpers provide typed access to the PCI power state field,
including extraction, setting, and comparison operations.
The series also updates the Apple Airport reset quirk to use
the new comparison helper.
**Scope**
This series focuses on operations involving raw PCI PMCSR
values. Comparisons between values already typed as
`pci_power_t` are intentionally left unchanged, as they do
not involve raw register values.
If there is interest in introducing a separate set of
helpers for comparisons between `pci_power_t` values, I can
prepare that as a follow-up series.
The changes follow the discussion with Andy Shevchenko and
Bjorn Helgaas in response to the original Apple Airport quirk
patch.
Changes in v2:
- Add helpers for comparing PCI power states.
- Convert PCI core and quirk code to use the new helpers.
- Address review feedback.
This series is based on the discussion following the original
Apple Airport quirk patch:
https://lore.kernel.org/lkml/20261118161559.63617-1-habilerenturker@hotmail.com/
LLM assistance was used for editing the cover letter and commit
descriptions. All changes were reviewed by the submitter.
Habil Eren Türker (4):
PCI: Add pci_power_t helper functions
PCI: Convert pci.c to pci_power_t helpers
PCI: Convert quirks.c to pci_power_t helpers
x86/quirks: Use pci_power_eq() in apple_airport_reset()
arch/x86/kernel/early-quirks.c | 6 +++---
drivers/pci/pci.c | 26 +++++++++++---------------
drivers/pci/quirks.c | 2 +-
include/linux/pci.h | 28 ++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 19 deletions(-)
base-commit: c054fccfff7ba1ad9d8913921f5a952bb32513cd
--
2.47.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/4] PCI: Add pci_power_t helper functions
2026-11-19 14:35 [PATCH v2 0/4] PCI: Add pci_power_t helper functions Habil Eren Türker
@ 2026-11-19 14:35 ` Habil Eren Türker
2026-11-19 16:51 ` andriy.shevchenko
2026-11-19 17:23 ` Bjorn Helgaas
2026-11-19 14:35 ` [PATCH v2 2/4] PCI: Convert pci.c to pci_power_t helpers Habil Eren Türker
` (2 subsequent siblings)
3 siblings, 2 replies; 12+ messages in thread
From: Habil Eren Türker @ 2026-11-19 14:35 UTC (permalink / raw)
To: bhelgaas
Cc: andriy.shevchenko, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86, Habil Eren Türker
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@hotmail.com/
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
include/linux/pci.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aa3765a20a96..6efd13e760d7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -43,6 +43,7 @@
#include <uapi/linux/pci.h>
#include <linux/pci_ids.h>
+#include <linux/bitfield.h>
#define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \
PCI_STATUS_SIG_SYSTEM_ERROR | \
@@ -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 */
+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);
+}
+
+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;
+}
+
+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
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 2/4] PCI: Convert pci.c to pci_power_t helpers
2026-11-19 14:35 [PATCH v2 0/4] PCI: Add pci_power_t helper functions Habil Eren Türker
2026-11-19 14:35 ` [PATCH v2 1/4] " Habil Eren Türker
@ 2026-11-19 14:35 ` Habil Eren Türker
2026-11-19 17:09 ` andriy.shevchenko
2026-11-19 14:35 ` [PATCH v2 3/4] PCI: Convert quirks.c " Habil Eren Türker
2026-11-19 14:35 ` [PATCH v2 4/4] x86/quirks: Use pci_power_eq() in apple_airport_reset() Habil Eren Türker
3 siblings, 1 reply; 12+ messages in thread
From: Habil Eren Türker @ 2026-11-19 14:35 UTC (permalink / raw)
To: bhelgaas
Cc: andriy.shevchenko, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86, Habil Eren Türker
Convert PCI core code to use the pci_power_t helper functions
when accessing the Power Management Control/Status register.
Keep comparisons between values already typed as pci_power_t
as direct typed comparisons.
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
drivers/pci/pci.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..1902b7c858fd 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1171,7 +1171,7 @@ void pci_update_current_state(struct pci_dev *dev, pci_power_t state)
dev->current_state = PCI_D3cold;
return;
}
- dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
+ dev->current_state = pci_power_t_get(pmcsr);
} else {
dev->current_state = state;
}
@@ -1368,12 +1368,11 @@ int pci_power_up(struct pci_dev *dev)
return -EIO;
}
- state = pmcsr & PCI_PM_CTRL_STATE_MASK;
-
- need_restore = (state == PCI_D3hot || dev->current_state >= PCI_D3hot) &&
+ need_restore = (pci_power_eq(pmcsr, PCI_D3hot) ||
+ dev->current_state >= PCI_D3hot) &&
!(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET);
- if (state == PCI_D0)
+ if (pci_power_eq(pmcsr, PCI_D0))
goto end;
/*
@@ -1383,7 +1382,7 @@ int pci_power_up(struct pci_dev *dev)
pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, 0);
/* Mandatory transition delays; see PCI PM 1.2. */
- if (state == PCI_D3hot) {
+ if (pci_power_eq(pmcsr, PCI_D3hot)) {
pci_dev_d3_sleep(dev);
if (!(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) {
ret = pci_dev_wait(dev, "power up D3hot->D0uninitialized",
@@ -1393,7 +1392,7 @@ int pci_power_up(struct pci_dev *dev)
return -EIO;
}
}
- } else if (state == PCI_D2) {
+ } else if (pci_power_eq(pmcsr, PCI_D2)) {
udelay(PCI_PM_D2_DELAY);
}
@@ -1432,7 +1431,7 @@ static int pci_set_full_power_state(struct pci_dev *dev, bool locked)
}
pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
- dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
+ dev->current_state = pci_power_t_get(pmcsr);
if (dev->current_state != PCI_D0) {
pci_info_ratelimited(dev, "Refused to change power state from %s to D0\n",
pci_power_name(dev->current_state));
@@ -1546,8 +1545,7 @@ static int pci_set_low_power_state(struct pci_dev *dev, pci_power_t state, bool
return -EIO;
}
- pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
- pmcsr |= state;
+ pci_power_t_set(&pmcsr, state);
/* Enter specified state */
pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
@@ -1559,7 +1557,7 @@ static int pci_set_low_power_state(struct pci_dev *dev, pci_power_t state, bool
udelay(PCI_PM_D2_DELAY);
pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
- dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
+ dev->current_state = pci_power_t_get(pmcsr);
if (dev->current_state != state)
pci_info_ratelimited(dev, "Refused to change power state from %s to %s\n",
pci_power_name(dev->current_state),
@@ -4590,13 +4588,11 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
return ret;
}
- csr &= ~PCI_PM_CTRL_STATE_MASK;
- csr |= PCI_D3hot;
+ pci_power_t_set(&csr, PCI_D3hot);
pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr);
pci_dev_d3_sleep(dev);
- csr &= ~PCI_PM_CTRL_STATE_MASK;
- csr |= PCI_D0;
+ pci_power_t_set(&csr, PCI_D0);
pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr);
pci_dev_d3_sleep(dev);
--
2.47.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 3/4] PCI: Convert quirks.c to pci_power_t helpers
2026-11-19 14:35 [PATCH v2 0/4] PCI: Add pci_power_t helper functions Habil Eren Türker
2026-11-19 14:35 ` [PATCH v2 1/4] " Habil Eren Türker
2026-11-19 14:35 ` [PATCH v2 2/4] PCI: Convert pci.c to pci_power_t helpers Habil Eren Türker
@ 2026-11-19 14:35 ` Habil Eren Türker
2026-11-19 17:11 ` andriy.shevchenko
2026-11-19 14:35 ` [PATCH v2 4/4] x86/quirks: Use pci_power_eq() in apple_airport_reset() Habil Eren Türker
3 siblings, 1 reply; 12+ messages in thread
From: Habil Eren Türker @ 2026-11-19 14:35 UTC (permalink / raw)
To: bhelgaas
Cc: andriy.shevchenko, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86, Habil Eren Türker
Use pci_power_t helper functions when accessing PCI power
states in PCI quirks.
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
drivers/pci/quirks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 7f1f47ea2ee4..de413a0fdb0e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2487,7 +2487,7 @@ static void quirk_e100_interrupt(struct pci_dev *dev)
*/
if (dev->pm_cap) {
pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
- if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0)
+ if (pci_power_t_get(pmcsr) != PCI_D0)
return;
}
--
2.47.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 4/4] x86/quirks: Use pci_power_eq() in apple_airport_reset()
2026-11-19 14:35 [PATCH v2 0/4] PCI: Add pci_power_t helper functions Habil Eren Türker
` (2 preceding siblings ...)
2026-11-19 14:35 ` [PATCH v2 3/4] PCI: Convert quirks.c " Habil Eren Türker
@ 2026-11-19 14:35 ` Habil Eren Türker
2026-11-19 17:14 ` andriy.shevchenko
3 siblings, 1 reply; 12+ messages in thread
From: Habil Eren Türker @ 2026-11-19 14:35 UTC (permalink / raw)
To: bhelgaas
Cc: andriy.shevchenko, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86, Habil Eren Türker
Use pci_power_eq() to check the PCI power state in the
Apple Airport reset quirk.
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
arch/x86/kernel/early-quirks.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 7459a073c74d..82a3c7f72d33 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -644,13 +644,13 @@ static void __init apple_airport_reset(int bus, int slot, int func)
/* Card may have been put into PCI_D3hot by grub quirk */
pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
- if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
- pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
+ if (!pci_power_eq(pmcsr, PCI_D0)) {
+ pci_power_t_set(&pmcsr, PCI_D0);
write_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL, pmcsr);
mdelay(10);
pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
- if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
+ if (!pci_power_eq(pmcsr, PCI_D0)) {
pr_err("pci 0000:%02x:%02x.%d: Cannot power up Apple AirPort card\n",
bus, slot, func);
return;
--
2.47.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] PCI: Add pci_power_t helper functions
2026-11-19 14:35 ` [PATCH v2 1/4] " Habil Eren Türker
@ 2026-11-19 16:51 ` andriy.shevchenko
2026-11-19 17:07 ` Bjorn Helgaas
2026-11-19 17:23 ` Bjorn Helgaas
1 sibling, 1 reply; 12+ messages in thread
From: andriy.shevchenko @ 2026-11-19 16:51 UTC (permalink / raw)
To: Habil Eren Türker
Cc: bhelgaas, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86
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@hotmail.com/
Make it a Link tag with reference
This follows the discussion with Andy Shevchenko and Bjorn Helgaas in
response to "x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()" [1].
Link: $URL [1]
> Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
...
> +++ b/include/linux/pci.h
> #include <uapi/linux/pci.h>
>
> #include <linux/pci_ids.h>
> +#include <linux/bitfield.h>
Put it upper to the proper group of headers (they are grouped from the generic
to custom).
...
> +/* Helper functions for PCI power management */
> +static inline pci_power_t pci_power_t_get(u32 csr)
Why u32 as it seems the value is 16-bit?
> +{
> + 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);
Why u32 and not u16?
> +}
> +
> +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;
> +}
> +
> +static inline bool pci_power_lt(u32 csr, pci_power_t state)
> +{
> + return pci_power_t_get(csr) < state;
> +}
Same questions.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] PCI: Add pci_power_t helper functions
2026-11-19 16:51 ` andriy.shevchenko
@ 2026-11-19 17:07 ` Bjorn Helgaas
2026-11-19 17:18 ` andriy.shevchenko
0 siblings, 1 reply; 12+ messages in thread
From: Bjorn Helgaas @ 2026-11-19 17:07 UTC (permalink / raw)
To: andriy.shevchenko
Cc: Habil Eren Türker, bhelgaas, bp, dave.hansen, hpa, mingo,
tglx, linux-pci, linux-kernel, x86
On Thu, Nov 19, 2026 at 06:51:06PM +0200, andriy.shevchenko@intel.com wrote:
> 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.
> ...
> > +/* Helper functions for PCI power management */
> > +static inline pci_power_t pci_power_t_get(u32 csr)
>
> Why u32 as it seems the value is 16-bit?
I think there's one reader of PCI_PM_CTRL that does a 32-bit read, and
I figured a u16->u32 promotion would be better than a u32->u16
truncation. But maybe that reader should be changed to a 16-bit read.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/4] PCI: Convert pci.c to pci_power_t helpers
2026-11-19 14:35 ` [PATCH v2 2/4] PCI: Convert pci.c to pci_power_t helpers Habil Eren Türker
@ 2026-11-19 17:09 ` andriy.shevchenko
0 siblings, 0 replies; 12+ messages in thread
From: andriy.shevchenko @ 2026-11-19 17:09 UTC (permalink / raw)
To: Habil Eren Türker
Cc: bhelgaas, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86
On Thu, Nov 19, 2026 at 02:35:48PM +0000, Habil Eren Türker wrote:
> Convert PCI core code to use the pci_power_t helper functions
> when accessing the Power Management Control/Status register.
>
> Keep comparisons between values already typed as pci_power_t
> as direct typed comparisons.
Please, add a couple of examples of the sparse warnings.
...
> - state = pmcsr & PCI_PM_CTRL_STATE_MASK;
> -
> - need_restore = (state == PCI_D3hot || dev->current_state >= PCI_D3hot) &&
> + need_restore = (pci_power_eq(pmcsr, PCI_D3hot) ||
> + dev->current_state >= PCI_D3hot) &&
> !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET);
Please, fix indentation.
need_restore = !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET) &&
(pci_power_eq(pmcsr, PCI_D3hot) || dev->current_state >= PCI_D3hot);
Or create an additional temporary variable.
in_d3 = pci_power_eq(pmcsr, PCI_D3hot) || dev->current_state >= PCI_D3hot;
need_restore = in_d3 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET);
> - if (state == PCI_D0)
> + if (pci_power_eq(pmcsr, PCI_D0))
> goto end;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] PCI: Convert quirks.c to pci_power_t helpers
2026-11-19 14:35 ` [PATCH v2 3/4] PCI: Convert quirks.c " Habil Eren Türker
@ 2026-11-19 17:11 ` andriy.shevchenko
0 siblings, 0 replies; 12+ messages in thread
From: andriy.shevchenko @ 2026-11-19 17:11 UTC (permalink / raw)
To: Habil Eren Türker
Cc: bhelgaas, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86
On Thu, Nov 19, 2026 at 02:35:49PM +0000, Habil Eren Türker wrote:
> Use pci_power_t helper functions when accessing PCI power
> states in PCI quirks.
It's a single case, so you may put a oneline sparse warning here.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] x86/quirks: Use pci_power_eq() in apple_airport_reset()
2026-11-19 14:35 ` [PATCH v2 4/4] x86/quirks: Use pci_power_eq() in apple_airport_reset() Habil Eren Türker
@ 2026-11-19 17:14 ` andriy.shevchenko
0 siblings, 0 replies; 12+ messages in thread
From: andriy.shevchenko @ 2026-11-19 17:14 UTC (permalink / raw)
To: Habil Eren Türker
Cc: bhelgaas, bp, dave.hansen, hpa, mingo, tglx, linux-pci,
linux-kernel, x86
On Thu, Nov 19, 2026 at 02:35:50PM +0000, Habil Eren Türker wrote:
> Use pci_power_eq() to check the PCI power state in the
> Apple Airport reset quirk.
...
> - if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
> - pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
> + if (!pci_power_eq(pmcsr, PCI_D0)) {
> + pci_power_t_set(&pmcsr, PCI_D0);
Haven't checked the code, but consider (if enough users) also have
// update state if it wasn't equal to the required
static inline bool pci_power_t_update(...)
{
if (pci_power_eq(pmcsr, state))
return false;
pci_power_t_set(&pmcsr, state);
return true;
}
if (pci_power_t_update(&pmcsr, PCI_D0)) {
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] PCI: Add pci_power_t helper functions
2026-11-19 17:07 ` Bjorn Helgaas
@ 2026-11-19 17:18 ` andriy.shevchenko
0 siblings, 0 replies; 12+ messages in thread
From: andriy.shevchenko @ 2026-11-19 17:18 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Habil Eren Türker, bhelgaas, bp, dave.hansen, hpa, mingo,
tglx, linux-pci, linux-kernel, x86
On Thu, Nov 19, 2026 at 11:07:13AM -0600, Bjorn Helgaas wrote:
> On Thu, Nov 19, 2026 at 06:51:06PM +0200, andriy.shevchenko@intel.com wrote:
> > 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.
...
> > > +/* Helper functions for PCI power management */
> > > +static inline pci_power_t pci_power_t_get(u32 csr)
> >
> > Why u32 as it seems the value is 16-bit?
>
> I think there's one reader of PCI_PM_CTRL that does a 32-bit read, and
> I figured a u16->u32 promotion would be better than a u32->u16
> truncation. But maybe that reader should be changed to a 16-bit read.
Is it specific read on the specific HW that is always done as 32-bit?
(Personally I do not believe there is such a requirement to even weirdest
PCI HW. This register is way too standard.)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] PCI: Add pci_power_t helper functions
2026-11-19 14:35 ` [PATCH v2 1/4] " Habil Eren Türker
2026-11-19 16:51 ` andriy.shevchenko
@ 2026-11-19 17:23 ` Bjorn Helgaas
1 sibling, 0 replies; 12+ messages in thread
From: Bjorn Helgaas @ 2026-11-19 17:23 UTC (permalink / raw)
To: Habil Eren Türker
Cc: bhelgaas, andriy.shevchenko, bp, dave.hansen, hpa, mingo, tglx,
linux-pci, linux-kernel, x86
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@hotmail.com/
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@amd.com
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
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-19 17:23 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 14:35 [PATCH v2 0/4] PCI: Add pci_power_t helper functions Habil Eren Türker
2026-11-19 14:35 ` [PATCH v2 1/4] " Habil Eren Türker
2026-11-19 16:51 ` andriy.shevchenko
2026-11-19 17:07 ` Bjorn Helgaas
2026-11-19 17:18 ` andriy.shevchenko
2026-11-19 17:23 ` Bjorn Helgaas
2026-11-19 14:35 ` [PATCH v2 2/4] PCI: Convert pci.c to pci_power_t helpers Habil Eren Türker
2026-11-19 17:09 ` andriy.shevchenko
2026-11-19 14:35 ` [PATCH v2 3/4] PCI: Convert quirks.c " Habil Eren Türker
2026-11-19 17:11 ` andriy.shevchenko
2026-11-19 14:35 ` [PATCH v2 4/4] x86/quirks: Use pci_power_eq() in apple_airport_reset() Habil Eren Türker
2026-11-19 17:14 ` andriy.shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®