[PATCH v3 1/4] PCI: Add pci_power_t helper functions

From: Habil Eren Türker

Date: Sat Nov 21 2026 - 07:59:29 EST


Add helper functions to extract, set and compare PCI power
states in the Power Management Control/Status register.

Functions added:
- pci_power_t_get()
- pci_power_t_set()
- pci_power_t_eq()

Signed-off-by: Habil Eren Türker <habilerenturker@xxxxxxxxxxx>
---
include/linux/pci.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index aa3765a20a96..bfaff0ea6c2d 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -40,6 +40,7 @@
#include <linux/io.h>
#include <linux/resource_ext.h>
#include <linux/msi_api.h>
+#include <linux/bitfield.h>
#include <uapi/linux/pci.h>

#include <linux/pci_ids.h>
@@ -200,6 +201,22 @@ static inline const char *pci_power_name(pci_power_t state)
return pci_power_names[1 + (__force int) state];
}

+/* Helper functions for PCI power management */
+static inline pci_power_t pci_power_t_get(u16 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)
+{
+ FIELD_MODIFY(PCI_PM_CTRL_STATE_MASK, csr, (__force u16)state);
+}
+
+static inline bool pci_power_t_eq(pci_power_t state_a, pci_power_t state_b)
+{
+ return state_a == state_b;
+}
+
/**
* typedef pci_channel_state_t
*
--
2.47.3