git: 8f61992d7cc1 - main - LinuxKPI: pci: add [linuxkpi_]pci_get_device()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Jan 2023 00:41:51 UTC
The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=8f61992d7cc1108cebc1337451a15a0af420984c commit 8f61992d7cc1108cebc1337451a15a0af420984c 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-13 00:40:57 +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. MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D37593 --- 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 4b9f02497a59..cc9cb7da0b2a 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -344,6 +344,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) @@ -1584,6 +1585,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 9e79ec80b74f..57e431a7abcd 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -271,6 +271,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) {