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
This commit is contained in:
Warner Losh 2022-04-04 23:06:21 -06:00
parent 1cdb25340f
commit 36b5c44002
2 changed files with 38 additions and 36 deletions

View File

@ -317,6 +317,8 @@ struct pcim_iomap_devres {
};
int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name);
int pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv,
unsigned int flags);
/* Internal helper function(s). */
struct pci_dev *lkpinew_pci_dev(device_t);
@ -860,42 +862,6 @@ pci_enable_msi(struct pci_dev *pdev)
return (0);
}
static inline 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);
}
static inline int
pci_channel_offline(struct pci_dev *pdev)
{

View File

@ -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 {