aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/src
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-04-05 05:06:21 +0000
committerWarner Losh <imp@FreeBSD.org>2022-04-05 05:06:21 +0000
commit36b5c440028b44b22cfc0596125f575ca513656f (patch)
tree737f0c7c33a058387579816e1dd94795a6306069 /sys/compat/linuxkpi/common/src
parent1cdb25340f8ee5dd145b0dc370cbab1bd7bdca65 (diff)
downloadsrc-36b5c440028b44b22cfc0596125f575ca513656f.tar.gz
src-36b5c440028b44b22cfc0596125f575ca513656f.zip
linuxkpi: Move pci_alloc_irq_vectors to .c file
pci_alloc_irq_vectors encodes the size of struct msix_entry into its code. Move from .h to .c to move this knowledge from client modules to linuxkpi module. Sponsored by: Netflix Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D34774
Diffstat (limited to 'sys/compat/linuxkpi/common/src')
-rw-r--r--sys/compat/linuxkpi/common/src/linux_pci.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index 43a8cf96d0e3..8b64cbae0e6a 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -883,6 +883,42 @@ linux_pci_unregister_drm_driver(struct pci_driver *pdrv)
bus_topo_unlock();
}
+int
+pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv,
+ unsigned int flags)
+{
+ int error;
+
+ if (flags & PCI_IRQ_MSIX) {
+ struct msix_entry *entries;
+ int i;
+
+ entries = kcalloc(maxv, sizeof(*entries), GFP_KERNEL);
+ if (entries == NULL) {
+ error = -ENOMEM;
+ goto out;
+ }
+ for (i = 0; i < maxv; ++i)
+ entries[i].entry = i;
+ error = pci_enable_msix(pdev, entries, maxv);
+out:
+ kfree(entries);
+ if (error == 0 && pdev->msix_enabled)
+ return (pdev->dev.irq_end - pdev->dev.irq_start);
+ }
+ if (flags & PCI_IRQ_MSI) {
+ error = pci_enable_msi(pdev);
+ if (error == 0 && pdev->msi_enabled)
+ return (pdev->dev.irq_end - pdev->dev.irq_start);
+ }
+ if (flags & PCI_IRQ_LEGACY) {
+ if (pdev->irq)
+ return (1);
+ }
+
+ return (-EINVAL);
+}
+
CTASSERT(sizeof(dma_addr_t) <= sizeof(uint64_t));
struct linux_dma_obj {