LinuxKPI: implement irq_get_msi_desc()

Add irq_get_msi_desc() as a wrapper around a PCI function which will
allocate a single cached value (see comment on struct) for the
msi_desc requested if it doesn't exist yet and handle freeing it
when the PCI device goes away.  We take the values from the ivars of
the native (FreeBSD) device.

While changing struct pci_dev also add the msi_cap field requested by
a wireless driver.

Bump __FreeBSD_version so these changes can be detected.

MFC after:	3 days
X-MFC: move fields to end of struct (alloc happens in linux_pci.c)
Reviewed by:	hselasky (earlier version)
Differential Revision: https://reviews.freebsd.org/D37523
This commit is contained in:
Bjoern A. Zeeb 2022-11-28 18:27:03 +00:00
parent 8f61992d7c
commit 4b56afaf7b
5 changed files with 61 additions and 1 deletions

View File

@ -27,6 +27,10 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 14.x IS SLOW:
world, or to merely disable the most expensive debugging functionality
at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".)
20230113:
LinuxKPI pci.h changes may require out-of-tree drivers to be recompiled.
Bump _FreeBSD_version to 1400078 to be able to detect this change.
20221212:
llvm-objump is now always installed as objdump. Previously there was
no /usr/bin/objdump unless the WITH_LLVM_BINUTILS knob was used.

View File

@ -131,6 +131,13 @@ irq_set_affinity_hint(int vector, cpumask_t *mask)
return (-error);
}
static inline struct msi_desc *
irq_get_msi_desc(unsigned int irq)
{
return (lkpi_pci_msi_desc_alloc(irq));
}
/*
* LinuxKPI tasklet support
*/

View File

@ -285,6 +285,17 @@ _pci_exit(void) \
module_init(_pci_init); \
module_exit(_pci_exit)
struct msi_msg {
uint32_t data;
};
struct msi_desc {
struct msi_msg msg;
struct {
bool is_64;
} msi_attrib;
};
/*
* If we find drivers accessing this from multiple KPIs we may have to
* refcount objects of this structure.
@ -311,12 +322,18 @@ struct pci_dev {
unsigned int devfn;
uint32_t class;
uint8_t revision;
uint8_t msi_cap;
bool managed; /* devres "pcim_*(). */
bool want_iomap_res;
bool msi_enabled;
bool msix_enabled;
phys_addr_t rom;
size_t romlen;
/*
* msi_desc should be an array one day? For as long as we only support
* 1 MSI vector this is fine.
*/
struct msi_desc *msi_desc;
TAILQ_HEAD(, pci_mmio_region) mmio;
};
@ -345,6 +362,7 @@ 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 *);
struct msi_desc *lkpi_pci_msi_desc_alloc(int);
static inline bool
dev_is_pci(struct device *dev)

View File

@ -339,6 +339,8 @@ lkpinew_pci_dev_release(struct device *dev)
if (pdev->bus->self != pdev)
pci_dev_put(pdev->bus->self);
free(pdev->bus, M_DEVBUF);
if (pdev->msi_desc != NULL)
free(pdev->msi_desc, M_DEVBUF);
free(pdev, M_DEVBUF);
}
@ -965,6 +967,35 @@ out:
return (-EINVAL);
}
struct msi_desc *
lkpi_pci_msi_desc_alloc(int irq)
{
struct device *dev;
struct pci_dev *pdev;
struct msi_desc *desc;
struct pci_devinfo *dinfo;
struct pcicfg_msi *msi;
dev = linux_pci_find_irq_dev(irq);
if (dev == NULL)
return (NULL);
pdev = to_pci_dev(dev);
if (pdev->msi_desc != NULL)
return (pdev->msi_desc);
dinfo = device_get_ivars(dev->bsddev);
msi = &dinfo->cfg.msi;
desc = malloc(sizeof(*desc), M_DEVBUF, M_WAITOK | M_ZERO);
desc->msi_attrib.is_64 =
(msi->msi_ctrl & PCIM_MSICTRL_64BIT) ? true : false;
desc->msg.data = msi->msi_data;
return (desc);
}
CTASSERT(sizeof(dma_addr_t) <= sizeof(uint64_t));
struct linux_dma_obj {

View File

@ -76,7 +76,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1400077
#define __FreeBSD_version 1400078
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,