From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB6LY-000898-8n for qemu-devel@nongnu.org; Tue, 04 Oct 2011 10:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RB6LN-0003pL-CL for qemu-devel@nongnu.org; Tue, 04 Oct 2011 10:51:52 -0400 Received: from smtp.citrix.com ([66.165.176.89]:14140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB6LN-0003mp-99 for qemu-devel@nongnu.org; Tue, 04 Oct 2011 10:51:41 -0400 From: Anthony PERARD Date: Tue, 4 Oct 2011 15:51:18 +0100 Message-ID: <1317739882-4809-8-git-send-email-anthony.perard@citrix.com> In-Reply-To: <1317739882-4809-1-git-send-email-anthony.perard@citrix.com> References: <1317739882-4809-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH RFC V1 07/11] host-pci-device: Add host_pci_find_ext_cap_offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU-devel Cc: Anthony PERARD , Alex Williamson , Xen Devel , Stefano Stabellini Signed-off-by: Anthony PERARD --- hw/host-pci-device.c | 31 +++++++++++++++++++++++++++++++ hw/host-pci-device.h | 2 ++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/hw/host-pci-device.c b/hw/host-pci-device.c index b3f2899..2a889d5 100644 --- a/hw/host-pci-device.c +++ b/hw/host-pci-device.c @@ -162,6 +162,37 @@ int host_pci_write_block(HostPCIDevice *d, int pos, uint8_t *buf, int len) return host_pci_config_write(d, pos, buf, len); } +uint32_t host_pci_find_ext_cap_offset(HostPCIDevice *d, uint32_t cap) +{ + uint32_t header = 0; + int max_cap = 480; + int pos = 0x100; + + do { + header = host_pci_read_long(d, pos); + /* + * If we have no capabilities, this is indicated by cap ID, + * cap version and next pointer all being 0. + */ + if (header == 0) { + break; + } + + if (PCI_EXT_CAP_ID(header) == cap) { + return pos; + } + + pos = PCI_EXT_CAP_NEXT(header); + if (pos < 0x100) { + break; + } + + max_cap--; + } while (max_cap > 0); + + return 0; +} + HostPCIDevice *host_pci_device_get(uint8_t bus, uint8_t dev, uint8_t func) { HostPCIDevice *d = NULL; diff --git a/hw/host-pci-device.h b/hw/host-pci-device.h index 0137507..2734eb3 100644 --- a/hw/host-pci-device.h +++ b/hw/host-pci-device.h @@ -33,4 +33,6 @@ int host_pci_write_word(HostPCIDevice *d, int pos, uint16_t data); int host_pci_write_long(HostPCIDevice *d, int pos, uint32_t data); int host_pci_write_block(HostPCIDevice *d, int pos, uint8_t *buf, int len); +uint32_t host_pci_find_ext_cap_offset(HostPCIDevice *s, uint32_t cap); + #endif /* !HW_HOST_PCI_DEVICE */ -- Anthony PERARD From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony PERARD Subject: [PATCH RFC V1 07/11] host-pci-device: Add host_pci_find_ext_cap_offset Date: Tue, 4 Oct 2011 15:51:18 +0100 Message-ID: <1317739882-4809-8-git-send-email-anthony.perard@citrix.com> References: <1317739882-4809-1-git-send-email-anthony.perard@citrix.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1317739882-4809-1-git-send-email-anthony.perard@citrix.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org To: QEMU-devel Cc: Anthony PERARD , Alex Williamson , Xen Devel , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Signed-off-by: Anthony PERARD --- hw/host-pci-device.c | 31 +++++++++++++++++++++++++++++++ hw/host-pci-device.h | 2 ++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/hw/host-pci-device.c b/hw/host-pci-device.c index b3f2899..2a889d5 100644 --- a/hw/host-pci-device.c +++ b/hw/host-pci-device.c @@ -162,6 +162,37 @@ int host_pci_write_block(HostPCIDevice *d, int pos, uint8_t *buf, int len) return host_pci_config_write(d, pos, buf, len); } +uint32_t host_pci_find_ext_cap_offset(HostPCIDevice *d, uint32_t cap) +{ + uint32_t header = 0; + int max_cap = 480; + int pos = 0x100; + + do { + header = host_pci_read_long(d, pos); + /* + * If we have no capabilities, this is indicated by cap ID, + * cap version and next pointer all being 0. + */ + if (header == 0) { + break; + } + + if (PCI_EXT_CAP_ID(header) == cap) { + return pos; + } + + pos = PCI_EXT_CAP_NEXT(header); + if (pos < 0x100) { + break; + } + + max_cap--; + } while (max_cap > 0); + + return 0; +} + HostPCIDevice *host_pci_device_get(uint8_t bus, uint8_t dev, uint8_t func) { HostPCIDevice *d = NULL; diff --git a/hw/host-pci-device.h b/hw/host-pci-device.h index 0137507..2734eb3 100644 --- a/hw/host-pci-device.h +++ b/hw/host-pci-device.h @@ -33,4 +33,6 @@ int host_pci_write_word(HostPCIDevice *d, int pos, uint16_t data); int host_pci_write_long(HostPCIDevice *d, int pos, uint32_t data); int host_pci_write_block(HostPCIDevice *d, int pos, uint8_t *buf, int len); +uint32_t host_pci_find_ext_cap_offset(HostPCIDevice *s, uint32_t cap); + #endif /* !HW_HOST_PCI_DEVICE */ -- Anthony PERARD