diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-09-08 20:13:53 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-09-08 20:13:53 +0000 |
commit | d075eab76001a27094f942528416eaa3e621c525 (patch) | |
tree | 840b852e62454f401444f948b7cbeaca1cbc43d1 /sys | |
parent | 67d97a0d2372fcab7f532c49e4a46be2b9aeb9d8 (diff) |
Add a function to scan for PCI Express extended capabilities.
From jordan@, with a few more tweaks by myself.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/pci/pci.c | 34 | ||||
-rw-r--r-- | sys/dev/pci/pcivar.h | 4 |
2 files changed, 36 insertions, 2 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index bf75f875ed2..bc20739e57c 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.c,v 1.118 2020/06/26 10:16:00 dlg Exp $ */ +/* $OpenBSD: pci.c,v 1.119 2020/09/08 20:13:52 kettenis Exp $ */ /* $NetBSD: pci.c,v 1.31 1997/06/06 23:48:04 thorpej Exp $ */ /* @@ -677,6 +677,38 @@ pci_get_ht_capability(pci_chipset_tag_t pc, pcitag_t tag, int capid, return (0); } +int +pci_get_ext_capability(pci_chipset_tag_t pc, pcitag_t tag, int capid, + int *offset, pcireg_t *value) +{ + pcireg_t reg; + unsigned int ofs; + + /* Make sure this is a PCI Express device. */ + if (pci_get_capability(pc, tag, PCI_CAP_PCIEXPRESS, NULL, NULL) == 0) + return (0); + + /* Scan PCI Express extended capabilities. */ + ofs = PCI_PCIE_ECAP; + while (ofs != 0) { +#ifdef DIAGNOSTIC + if ((ofs & 3) || (ofs < PCI_PCIE_ECAP)) + panic("pci_get_ext_capability"); +#endif + reg = pci_conf_read(pc, tag, ofs); + if (PCI_PCIE_ECAP_ID(reg) == capid) { + if (offset) + *offset = ofs; + if (value) + *value = reg; + return (1); + } + ofs = PCI_PCIE_ECAP_NEXT(reg); + } + + return (0); +} + uint16_t pci_requester_id(pci_chipset_tag_t pc, pcitag_t tag) { diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index bdfe0404f04..e85f6fe8150 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcivar.h,v 1.73 2020/06/17 01:43:04 dlg Exp $ */ +/* $OpenBSD: pcivar.h,v 1.74 2020/09/08 20:13:52 kettenis Exp $ */ /* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */ /* @@ -237,6 +237,8 @@ int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *); int pci_get_ht_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *); +int pci_get_ext_capability(pci_chipset_tag_t, pcitag_t, int, + int *, pcireg_t *); struct msix_vector; |