linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] PCI: Use FIELD_PREP() and remove *_SHIFT defines
@ 2023-10-27  8:38 Ilpo Järvinen
  2023-10-31 20:03 ` Bjorn Helgaas
  0 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2023-10-27  8:38 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, linux-kernel; +Cc: Ilpo Järvinen

Instead of open-coded masking and shifting with PCI_CONF1_* bitfields,
use GENMASK() and FIELD_PREP(), and then remove the *_SHIFT defines
that are no longer needed.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---

 drivers/pci/pci.h | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 39a8932dc340..31da9fde8aca 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -2,6 +2,8 @@
 #ifndef DRIVERS_PCI_H
 #define DRIVERS_PCI_H
 
+#include <linux/bitfield.h>
+#include <linux/bits.h>
 #include <linux/pci.h>
 
 /* Number of possible devfns: 0.0 to 1f.7 inclusive */
@@ -797,19 +799,15 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
  * Section 3.2.2.3.2, Figure 3-2, p. 50.
  */
 
-#define PCI_CONF1_BUS_SHIFT	16 /* Bus number */
-#define PCI_CONF1_DEV_SHIFT	11 /* Device number */
-#define PCI_CONF1_FUNC_SHIFT	8  /* Function number */
-
-#define PCI_CONF1_BUS_MASK	0xff
-#define PCI_CONF1_DEV_MASK	0x1f
-#define PCI_CONF1_FUNC_MASK	0x7
+#define PCI_CONF1_BUS_MASK	GENMASK(23, 16)
+#define PCI_CONF1_DEV_MASK	GENMASK(15, 11)
+#define PCI_CONF1_FUNC_MASK	GENMASK(10, 8)
 #define PCI_CONF1_REG_MASK	0xfc /* Limit aligned offset to a maximum of 256B */
 
 #define PCI_CONF1_ENABLE	BIT(31)
-#define PCI_CONF1_BUS(x)	(((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT)
-#define PCI_CONF1_DEV(x)	(((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT)
-#define PCI_CONF1_FUNC(x)	(((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT)
+#define PCI_CONF1_BUS(x)	FIELD_PREP(PCI_CONF1_BUS_MASK, (x))
+#define PCI_CONF1_DEV(x)	FIELD_PREP(PCI_CONF1_DEV_MASK, (x))
+#define PCI_CONF1_FUNC(x)	FIELD_PREP(PCI_CONF1_FUNC_MASK, (x))
 #define PCI_CONF1_REG(x)	((x) & PCI_CONF1_REG_MASK)
 
 #define PCI_CONF1_ADDRESS(bus, dev, func, reg) \
@@ -827,9 +825,8 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
  * are used for specifying additional 4 high bits of PCI Express register.
  */
 
-#define PCI_CONF1_EXT_REG_SHIFT	16
-#define PCI_CONF1_EXT_REG_MASK	0xf00
-#define PCI_CONF1_EXT_REG(x)	(((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT)
+#define PCI_CONF1_EXT_REG_MASK	GENMASK(27, 24)
+#define PCI_CONF1_EXT_REG(x)	FIELD_PREP(PCI_CONF1_EXT_REG_MASK, (x) >> 8)
 
 #define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \
 	(PCI_CONF1_ADDRESS(bus, dev, func, reg) | \
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-03 15:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27  8:38 [PATCH 1/1] PCI: Use FIELD_PREP() and remove *_SHIFT defines Ilpo Järvinen
2023-10-31 20:03 ` Bjorn Helgaas
2023-11-03 13:10   ` Ilpo Järvinen
2023-11-03 14:07     ` Ilpo Järvinen
2023-11-03 15:51       ` Bjorn Helgaas

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).