summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2020-06-17 01:43:05 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2020-06-17 01:43:05 +0000
commit7fd904b6568f8d75f40db5ea6f1cc71aa7797fc3 (patch)
treee9ababd7ca33fc3863f65ebcec48e6882804ddd4
parentb5c7a4ef7a2d0789ba4fa50126cfda273efd6b77 (diff)
add pci_intr_msix_count(), to get the msi-x table size for a device.
this basically tells us the number of interrupt vectors a pci device is able to support. it relies on the arch having __HAVE_PCI_MSIX defined. without that define it always returns 0. i think this originally came from haesbart via patrick@ as amd64 md code in the middle of a diff from 2018(!), but i've tweaked it to make it MI. tested on sparc64 and amd64 with various drivers.
-rw-r--r--sys/dev/pci/pci.c21
-rw-r--r--sys/dev/pci/pcivar.h4
2 files changed, 22 insertions, 3 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index da7ba535460..68cda5a80a9 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci.c,v 1.115 2020/01/15 14:01:19 cheloha Exp $ */
+/* $OpenBSD: pci.c,v 1.116 2020/06/17 01:43:04 dlg Exp $ */
/* $NetBSD: pci.c,v 1.31 1997/06/06 23:48:04 thorpej Exp $ */
/*
@@ -1625,7 +1625,18 @@ pci_resume_msix(pci_chipset_tag_t pc, pcitag_t tag,
pci_conf_write(pc, tag, off, mc);
}
-#else
+int
+pci_intr_msix_count(pci_chipset_tag_t pc, pcitag_t tag)
+{
+ pcireg_t reg;
+
+ if (pci_get_capability(pc, tag, PCI_CAP_MSIX, NULL, &reg) == 0)
+ return (0);
+
+ return (PCI_MSIX_MC_TBLSZ(reg) + 1);
+}
+
+#else /* __HAVE_PCI_MSIX */
struct msix_vector *
pci_alloc_msix_table(pci_chipset_tag_t pc, pcitag_t tag)
@@ -1651,4 +1662,10 @@ pci_resume_msix(pci_chipset_tag_t pc, pcitag_t tag,
{
}
+int
+pci_intr_msix_count(pci_chipset_tag_t pc, pcitag_t tag)
+{
+ return (0);
+}
+
#endif /* __HAVE_PCI_MSIX */
diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h
index 13d65afadc1..bdfe0404f04 100644
--- a/sys/dev/pci/pcivar.h
+++ b/sys/dev/pci/pcivar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcivar.h,v 1.72 2019/06/25 16:46:33 kettenis Exp $ */
+/* $OpenBSD: pcivar.h,v 1.73 2020/06/17 01:43:04 dlg Exp $ */
/* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */
/*
@@ -247,6 +247,8 @@ void pci_suspend_msix(pci_chipset_tag_t, pcitag_t, bus_space_tag_t,
void pci_resume_msix(pci_chipset_tag_t, pcitag_t, bus_space_tag_t,
pcireg_t, struct msix_vector *);
+int pci_intr_msix_count(pci_chipset_tag_t, pcitag_t);
+
uint16_t pci_requester_id(pci_chipset_tag_t, pcitag_t);
struct pci_matchid {