diff mbox

[1/2] pci: add API to add capability at a known offset

Message ID 2b600ff5a3d1dd5fc1cb4c35c4403d21674b3377.1270627361.git.mst@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin April 7, 2010, 8:04 a.m. UTC
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>
---
 hw/pci.c |   16 ++++++++++++----
 hw/pci.h |    2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

Stefan Weil April 7, 2010, 8:36 a.m. UTC | #1
Michael S. Tsirkin schrieb:
> 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>
> ---
>  hw/pci.c |   16 ++++++++++++----
>  hw/pci.h |    2 ++
>  2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index 0dbca17..df03149 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,16 @@ 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;
>   

{} Coding style? The rest is ok.

> +    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)
>  {
> diff --git a/hw/pci.h b/hw/pci.h
> index 20c670e..625188c 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -190,6 +190,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
>                              PCIMapIORegionFunc *map_func);
>  
>  int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
> +int pci_add_capability_at_offset(PCIDevice *pci_dev, uint8_t cap_id,
> +                                 uint8_t cap_offset, uint8_t cap_size);
>  
>  void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
>  
>
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 0dbca17..df03149 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,16 @@  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)
 {
diff --git a/hw/pci.h b/hw/pci.h
index 20c670e..625188c 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -190,6 +190,8 @@  void pci_register_bar(PCIDevice *pci_dev, int region_num,
                             PCIMapIORegionFunc *map_func);
 
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+int pci_add_capability_at_offset(PCIDevice *pci_dev, uint8_t cap_id,
+                                 uint8_t cap_offset, uint8_t cap_size);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);