aboutsummaryrefslogtreecommitdiff
path: root/hw/pci.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2010-04-06 16:05:46 +0300
committerMichael S. Tsirkin <mst@redhat.com>2010-04-11 19:37:28 +0300
commit1db5a3aad3c689be1255ed850ef8e3515ab461e8 (patch)
treeceb4251827cbea3c60157205443b8cc1b536574c /hw/pci.c
parentf62719ca6fcdab99d6fbd7a1d6798e0fad4e0b70 (diff)
downloadqemu-1db5a3aad3c689be1255ed850ef8e3515ab461e8.zip
qemu-1db5a3aad3c689be1255ed850ef8e3515ab461e8.tar.gz
qemu-1db5a3aad3c689be1255ed850ef8e3515ab461e8.tar.bz2
pci: add API to add capability at a known offset
Unlike virtio, device emulations need to add pci capabilities at known offsets to match real hardware. Make this possible by adding an appropriate API. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/pci.c')
-rw-r--r--hw/pci.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/hw/pci.c b/hw/pci.c
index 0dbca17..b6abd67 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1789,12 +1789,10 @@ static int pci_add_option_rom(PCIDevice *pdev)
}
/* Reserve space and add capability to the linked list in pci config space */
-int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+int pci_add_capability_at_offset(PCIDevice *pdev, uint8_t cap_id,
+ uint8_t offset, uint8_t size)
{
- uint8_t offset = pci_find_space(pdev, size);
uint8_t *config = pdev->config + offset;
- if (!offset)
- return -ENOSPC;
config[PCI_CAP_LIST_ID] = cap_id;
config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
pdev->config[PCI_CAPABILITY_LIST] = offset;
@@ -1807,6 +1805,17 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
return offset;
}
+/* Find and reserve space and add capability to the linked list
+ * in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+ uint8_t offset = pci_find_space(pdev, size);
+ if (!offset) {
+ return -ENOSPC;
+ }
+ return pci_add_capability_at_offset(pdev, cap_id, offset, size);
+}
+
/* Unlink capability from the pci config space. */
void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
{