Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Jan 2023 16:25:06 GMT
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 0b0eb6b1e6a3 - stable/13 - LinuxKPI: pci: add [linuxkpi_]pci_get_device()
Message-ID:  <202301181625.30IGP6qb038329@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by bz:

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

commit 0b0eb6b1e6a30495e9bc5991e56ca0221a9730c8
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-12-02 22:14:09 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-01-18 13:26:51 +0000

    LinuxKPI: pci: add [linuxkpi_]pci_get_device()
    
    Add a version of pci_get_device() as linuxkpi_pci_get_device()
    not (yet) supporting the last argument.
    Due to conflicts we cannot redefine it as we would normally do
    in LinuxKPI so drivers have to be adjusted.
    
    Differential Revision: https://reviews.freebsd.org/D37593
    
    (cherry picked from commit 8f61992d7cc1108cebc1337451a15a0af420984c)
---
 sys/compat/linuxkpi/common/include/linux/pci.h | 14 ++++++++++++++
 sys/compat/linuxkpi/common/src/linux_pci.c     | 17 +++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index f870b039254c..de041fa966ea 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -358,6 +358,7 @@ void lkpi_pci_devres_release(struct device *, void *);
 struct resource *_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size);
 struct pcim_iomap_devres *lkpi_pcim_iomap_devres_find(struct pci_dev *pdev);
 void lkpi_pcim_iomap_table_release(struct device *, void *);
+struct pci_dev *lkpi_pci_get_device(uint16_t, uint16_t, struct pci_dev *);
 
 static inline bool
 dev_is_pci(struct device *dev)
@@ -1579,6 +1580,19 @@ err:
 	return (-EINVAL);
 }
 
+/*
+ * We cannot simply re-define pci_get_device() as we would normally do
+ * and then hide it in linux_pci.c as too many semi-native drivers still
+ * inlucde linux/pci.h and run into the conflict with native PCI. Linux drivers
+ * using pci_get_device() need to be changed to call linuxkpi_pci_get_device().
+ */
+static inline struct pci_dev *
+linuxkpi_pci_get_device(uint16_t vendor, uint16_t device, struct pci_dev *odev)
+{
+
+	return (lkpi_pci_get_device(vendor, device, odev));
+}
+
 /* This is a FreeBSD extension so we can use bus_*(). */
 static inline void
 linuxkpi_pcim_want_to_use_bus_functions(struct pci_dev *pdev)
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index a9c859d29623..54780adfda14 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -273,6 +273,23 @@ linux_pci_find(device_t dev, const struct pci_device_id **idp)
 	return (NULL);
 }
 
+struct pci_dev *
+lkpi_pci_get_device(uint16_t vendor, uint16_t device, struct pci_dev *odev)
+{
+	struct pci_dev *pdev;
+
+	KASSERT(odev == NULL, ("%s: odev argument not yet supported\n", __func__));
+
+	spin_lock(&pci_lock);
+	list_for_each_entry(pdev, &pci_devices, links) {
+		if (pdev->vendor == vendor && pdev->device == device)
+			break;
+	}
+	spin_unlock(&pci_lock);
+
+	return (pdev);
+}
+
 static void
 lkpi_pci_dev_release(struct device *dev)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202301181625.30IGP6qb038329>