git: acfd6cea1f57 - stable/14 - LinuxKPI: Add pci_dev_id to linux/pci.h

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Thu, 01 Aug 2024 22:27:28 UTC
The branch stable/14 has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=acfd6cea1f570baf0ec866b42f9fe56de1ec1ea9

commit acfd6cea1f570baf0ec866b42f9fe56de1ec1ea9
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2024-04-08 06:47:43 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-08-01 21:09:38 +0000

    LinuxKPI: Add pci_dev_id to linux/pci.h
    
    It returns bus/device/function number for given PCI device.
    Also add intermediate PCI_DEVID macro used in some drivers.
    
    Sponsored by:   Serenity Cyber Security, LLC
    Reviewed by:    emaste
    MFC after:      1 week
    
    (cherry picked from commit f1206503e5a0073f56710bfebb6e503dcf612536)
---
 sys/compat/linuxkpi/common/include/linux/pci.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index 98ba160150f7..f8ee6c5600da 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -94,6 +94,7 @@ MODULE_PNP_INFO("U32:vendor;U32:device;V32:subvendor;V32:subdevice",	\
 #define PCI_SLOT(devfn)		(((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn)		((devfn) & 0x07)
 #define	PCI_BUS_NUM(devfn)	(((devfn) >> 8) & 0xff)
+#define	PCI_DEVID(bus, devfn)	((((uint16_t)(bus)) << 8) | (devfn))
 
 #define PCI_VDEVICE(_vendor, _device)					\
 	    .vendor = PCI_VENDOR_ID_##_vendor, .device = (_device),	\
@@ -386,6 +387,12 @@ dev_is_pci(struct device *dev)
 	return (device_get_devclass(dev->bsddev) == devclass_find("pci"));
 }
 
+static inline uint16_t
+pci_dev_id(struct pci_dev *pdev)
+{
+	return (PCI_DEVID(pdev->bus->number, pdev->devfn));
+}
+
 static inline int
 pci_resource_type(struct pci_dev *pdev, int bar)
 {