From 0c32ab03a41251ebef066bfa6354daab2885551f Mon Sep 17 00:00:00 2001 From: Henning Schild Date: Fri, 7 Nov 2014 14:46:02 +0100 Subject: [PATCH] inmates: pci: include feature check in capability lookup Do not look for pci capabilites in devices that do not support them. Signed-off-by: Henning Schild Signed-off-by: Jan Kiszka --- inmates/lib/pci.c | 3 +++ inmates/lib/x86/inmate.h | 1 + 2 files changed, 4 insertions(+) diff --git a/inmates/lib/pci.c b/inmates/lib/pci.c index 180062d..38120e6 100644 --- a/inmates/lib/pci.c +++ b/inmates/lib/pci.c @@ -30,6 +30,9 @@ int pci_find_cap(u16 bdf, u16 cap) { u8 pos = PCI_CFG_CAP_PTR - 1; + if (!(pci_read_config(bdf, PCI_CFG_STATUS, 2) & PCI_STS_CAPS)) + return -1; + while (1) { pos = pci_read_config(bdf, pos + 1, 1); if (pos == 0) diff --git a/inmates/lib/x86/inmate.h b/inmates/lib/x86/inmate.h index 33d7cb4..45fd049 100644 --- a/inmates/lib/x86/inmate.h +++ b/inmates/lib/x86/inmate.h @@ -44,6 +44,7 @@ # define PCI_CMD_INTX_OFF (1 << 10) #define PCI_CFG_STATUS 0x006 # define PCI_STS_INT (1 << 3) +# define PCI_STS_CAPS (1 << 4) #define PCI_CFG_BAR 0x010 # define PCI_BAR_64BIT 0x4 #define PCI_CFG_CAP_PTR 0x034 -- 2.39.2