git: ce2d721b9fab - stable/14 - LinuxKPI: Add pci_match_id to linux/pci.h

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

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

commit ce2d721b9fab172a7a3484155461076b026f0179
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2024-07-21 13:09:27 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-08-01 21:15:44 +0000

    LinuxKPI: Add pci_match_id to linux/pci.h
    
    It finds out if a given PCI device matches a given pci_id table.
    
    Sponsored by:   Serenity Cyber Security, LLC
    MFC after:      1 week
    Reviewed by:    manu
    Differential Revision:  https://reviews.freebsd.org/D45846
    
    (cherry picked from commit 5b1171a0b75fc88bffb5a67b0b02d8d59eb8d5c4)
---
 sys/compat/linuxkpi/common/include/linux/pci.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index f8ee6c5600da..027dc0dfca0b 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -1268,6 +1268,29 @@ pci_dev_present(const struct pci_device_id *cur)
 	return (0);
 }
 
+static inline const struct pci_device_id *
+pci_match_id(const struct pci_device_id *ids, struct pci_dev *pdev)
+{
+	if (ids == NULL)
+		return (NULL);
+
+	for (;
+	     ids->vendor != 0 || ids->subvendor != 0 || ids->class_mask != 0;
+	     ids++)
+		if ((ids->vendor == PCI_ANY_ID ||
+		     ids->vendor == pdev->vendor) &&
+		    (ids->device == PCI_ANY_ID ||
+		     ids->device == pdev->device) &&
+		    (ids->subvendor == PCI_ANY_ID ||
+		     ids->subvendor == pdev->subsystem_vendor) &&
+		    (ids->subdevice == PCI_ANY_ID ||
+		     ids->subdevice == pdev->subsystem_device) &&
+		    ((ids->class ^ pdev->class) & ids->class_mask) == 0)
+			return (ids);
+
+	return (NULL);
+}
+
 struct pci_dev *lkpi_pci_get_domain_bus_and_slot(int domain,
     unsigned int bus, unsigned int devfn);
 #define	pci_get_domain_bus_and_slot(domain, bus, devfn)	\