Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
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
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|