diff mbox

[v3,7/7] qemu-kvm: Resolve PCI upstream diffs

Message ID dc709c3428c36ba9cd7509c9c812043bbdbfa6b9.1314120782.git.jan.kiszka@siemens.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kiszka Aug. 23, 2011, 5:33 p.m. UTC
Device assignment no longer peeks into config_map, so we can drop all
the related changes and sync the PCI core with upstream.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/pci.c |   29 +++++++++++++++--------------
 hw/pci.h |    7 +++++--
 2 files changed, 20 insertions(+), 16 deletions(-)

Comments

Jan Kiszka Aug. 24, 2011, 12:38 p.m. UTC | #1
On 2011-08-23 19:33, Jan Kiszka wrote:
> Device assignment no longer peeks into config_map, so we can drop all
> the related changes and sync the PCI core with upstream.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  hw/pci.c |   29 +++++++++++++++--------------
>  hw/pci.h |    7 +++++--
>  2 files changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 5c87a62..0225888 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -806,7 +806,7 @@ static void pci_config_alloc(PCIDevice *pci_dev)
>      pci_dev->cmask = g_malloc0(config_size);
>      pci_dev->wmask = g_malloc0(config_size);
>      pci_dev->w1cmask = g_malloc0(config_size);
> -    pci_dev->config_map = g_malloc0(config_size);
> +    pci_dev->used = g_malloc0(config_size);
>  }
>  
>  static void pci_config_free(PCIDevice *pci_dev)
> @@ -815,7 +815,7 @@ static void pci_config_free(PCIDevice *pci_dev)
>      g_free(pci_dev->cmask);
>      g_free(pci_dev->wmask);
>      g_free(pci_dev->w1cmask);
> -    g_free(pci_dev->config_map);
> +    g_free(pci_dev->used);
>  }
>  
>  /* -1 for devfn means auto assign */
> @@ -846,8 +846,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
>      pci_dev->irq_state = 0;
>      pci_config_alloc(pci_dev);
>  
> -    memset(pci_dev->config_map, 0xff, PCI_CONFIG_HEADER_SIZE);
> -
>      pci_config_set_vendor_id(pci_dev->config, info->vendor_id);
>      pci_config_set_device_id(pci_dev->config, info->device_id);
>      pci_config_set_revision(pci_dev->config, info->revision);
> @@ -1887,7 +1885,7 @@ static int pci_find_space(PCIDevice *pdev, uint8_t size)
>      int offset = PCI_CONFIG_HEADER_SIZE;
>      int i;
>      for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i)
> -        if (pdev->config_map[i])
> +        if (pdev->used[i])
>              offset = i + 1;
>          else if (i - offset + 1 == size)
>              return offset;
> @@ -2062,13 +2060,13 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
>          int i;
>  
>          for (i = offset; i < offset + size; i++) {
> -            if (pdev->config_map[i]) {
> +            if (pdev->used[i]) {
>                  fprintf(stderr, "ERROR: %04x:%02x:%02x.%x "
>                          "Attempt to add PCI capability %x at offset "
>                          "%x overlaps existing capability %x at offset %x\n",
>                          pci_find_domain(pdev->bus), pci_bus_num(pdev->bus),
>                          PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
> -                        cap_id, offset, pdev->config_map[i], i);
> +                        cap_id, offset, pdev->used[i], i);
>                  return -EINVAL;

This hunk is actually not equivalent. So the whole patch should be
skipped for now. I'll post a new version once upstreaming and merging
back of that error detection is done.

Jan
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 5c87a62..0225888 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -806,7 +806,7 @@  static void pci_config_alloc(PCIDevice *pci_dev)
     pci_dev->cmask = g_malloc0(config_size);
     pci_dev->wmask = g_malloc0(config_size);
     pci_dev->w1cmask = g_malloc0(config_size);
-    pci_dev->config_map = g_malloc0(config_size);
+    pci_dev->used = g_malloc0(config_size);
 }
 
 static void pci_config_free(PCIDevice *pci_dev)
@@ -815,7 +815,7 @@  static void pci_config_free(PCIDevice *pci_dev)
     g_free(pci_dev->cmask);
     g_free(pci_dev->wmask);
     g_free(pci_dev->w1cmask);
-    g_free(pci_dev->config_map);
+    g_free(pci_dev->used);
 }
 
 /* -1 for devfn means auto assign */
@@ -846,8 +846,6 @@  static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     pci_dev->irq_state = 0;
     pci_config_alloc(pci_dev);
 
-    memset(pci_dev->config_map, 0xff, PCI_CONFIG_HEADER_SIZE);
-
     pci_config_set_vendor_id(pci_dev->config, info->vendor_id);
     pci_config_set_device_id(pci_dev->config, info->device_id);
     pci_config_set_revision(pci_dev->config, info->revision);
@@ -1887,7 +1885,7 @@  static int pci_find_space(PCIDevice *pdev, uint8_t size)
     int offset = PCI_CONFIG_HEADER_SIZE;
     int i;
     for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i)
-        if (pdev->config_map[i])
+        if (pdev->used[i])
             offset = i + 1;
         else if (i - offset + 1 == size)
             return offset;
@@ -2062,13 +2060,13 @@  int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
         int i;
 
         for (i = offset; i < offset + size; i++) {
-            if (pdev->config_map[i]) {
+            if (pdev->used[i]) {
                 fprintf(stderr, "ERROR: %04x:%02x:%02x.%x "
                         "Attempt to add PCI capability %x at offset "
                         "%x overlaps existing capability %x at offset %x\n",
                         pci_find_domain(pdev->bus), pci_bus_num(pdev->bus),
                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
-                        cap_id, offset, pdev->config_map[i], i);
+                        cap_id, offset, pdev->used[i], i);
                 return -EINVAL;
             }
         }
@@ -2078,14 +2076,12 @@  int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
     config[PCI_CAP_LIST_ID] = cap_id;
     config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
     pdev->config[PCI_CAPABILITY_LIST] = offset;
-    memset(pdev->config_map + offset, cap_id, size);
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
     /* Make capability read-only by default */
     memset(pdev->wmask + offset, 0, size);
     /* Check capability by default */
     memset(pdev->cmask + offset, 0xFF, size);
-
-    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
-
     return offset;
 }
 
@@ -2101,11 +2097,16 @@  void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
     memset(pdev->w1cmask + offset, 0, size);
     /* Clear cmask as device-specific registers can't be checked */
     memset(pdev->cmask + offset, 0, size);
-    memset(pdev->config_map + offset, 0, size);
+    memset(pdev->used + offset, 0, size);
 
-    if (!pdev->config[PCI_CAPABILITY_LIST]) {
+    if (!pdev->config[PCI_CAPABILITY_LIST])
         pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
-    }
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
 }
 
 uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
diff --git a/hw/pci.h b/hw/pci.h
index 071a044..70fcd9c 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -147,8 +147,8 @@  struct PCIDevice {
     /* Used to implement RW1C(Write 1 to Clear) bytes */
     uint8_t *w1cmask;
 
-    /* Used to allocate config space and track capabilities. */
-    uint8_t *config_map;
+    /* Used to allocate config space for capabilities. */
+    uint8_t *used;
 
     /* the following fields are read only */
     PCIBus *bus;
@@ -230,8 +230,11 @@  int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
 uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
 
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,