qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 07/16] pci: add Error-propagating pci_add_capability2()
Date: Thu, 10 Apr 2014 10:24:36 +0200	[thread overview]
Message-ID: <1397118285-11715-8-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1397118285-11715-1-git-send-email-lersek@redhat.com>

... and rebase pci_add_capability() to it.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 include/hw/pci/pci.h |  4 ++++
 hw/pci/pci.c         | 32 ++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 693dd6b..8c25ae5 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -4,10 +4,11 @@
 #include "qemu-common.h"
 
 #include "hw/qdev.h"
 #include "exec/memory.h"
 #include "sysemu/dma.h"
+#include "qapi/error.h"
 
 /* PCI includes legacy ISA access.  */
 #include "hw/isa/isa.h"
 
 #include "hw/pci/pcie.h"
@@ -306,10 +307,13 @@ void pci_register_vga(PCIDevice *pci_dev, MemoryRegion *mem,
 void pci_unregister_vga(PCIDevice *pci_dev);
 pcibus_t pci_get_bar_addr(PCIDevice *pci_dev, int region_num);
 
 int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
                        uint8_t offset, uint8_t size);
+int pci_add_capability2(PCIDevice *pdev, uint8_t cap_id,
+                       uint8_t offset, uint8_t size,
+                       Error **errp);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
 uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
 
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 2a9f08e..64e6f23 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2011,32 +2011,52 @@ static void pci_del_option_rom(PCIDevice *pdev)
  * 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 offset, uint8_t size)
 {
+    int ret;
+    Error *local_err = NULL;
+
+    ret = pci_add_capability2(pdev, cap_id, offset, size, &local_err);
+    if (local_err) {
+        assert(ret < 0);
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
+    } else {
+        /* success implies a positive offset in config space */
+        assert(ret > 0);
+    }
+    return ret;
+}
+
+int pci_add_capability2(PCIDevice *pdev, uint8_t cap_id,
+                       uint8_t offset, uint8_t size,
+                       Error **errp)
+{
     uint8_t *config;
     int i, overlapping_cap;
 
     if (!offset) {
         offset = pci_find_space(pdev, size);
         if (!offset) {
+            error_setg(errp, "out of PCI config space");
             return -ENOSPC;
         }
     } else {
         /* Verify that capabilities don't overlap.  Note: device assignment
          * depends on this check to verify that the device is not broken.
          * Should never trigger for emulated devices, but it's helpful
          * for debugging these. */
         for (i = offset; i < offset + size; i++) {
             overlapping_cap = pci_find_capability_at_offset(pdev, i);
             if (overlapping_cap) {
-                fprintf(stderr, "ERROR: %s:%02x:%02x.%x "
-                        "Attempt to add PCI capability %x at offset "
-                        "%x overlaps existing capability %x at offset %x\n",
-                        pci_root_bus_path(pdev), pci_bus_num(pdev->bus),
-                        PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
-                        cap_id, offset, overlapping_cap, i);
+                error_setg(errp, "%s:%02x:%02x.%x "
+                           "Attempt to add PCI capability %x at offset "
+                           "%x overlaps existing capability %x at offset %x",
+                           pci_root_bus_path(pdev), pci_bus_num(pdev->bus),
+                           PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                           cap_id, offset, overlapping_cap, i);
                 return -EINVAL;
             }
         }
     }
 
-- 
1.8.3.1

  parent reply	other threads:[~2014-04-10  8:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-10  8:24 [Qemu-devel] [PATCH 00/16] PCI device assignment: improve error reporting over QMP Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd() Laszlo Ersek
2014-04-10 11:51   ` Eric Blake
2014-04-10  8:24 ` [Qemu-devel] [PATCH 02/16] monitor: add Error-propagating monitor_handle_fd_param2() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 03/16] pci-assign: accept Error from monitor_handle_fd_param2() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 04/16] pci-assign: make assign_failed_examine() just format the cause Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 05/16] pci-assign: propagate errors from get_real_id() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 06/16] pci-assign: propagate Error from check_irqchip_in_kernel() Laszlo Ersek
2014-04-10  8:24 ` Laszlo Ersek [this message]
2014-04-10  8:24 ` [Qemu-devel] [PATCH 08/16] pci-assign: accept Error from pci_add_capability2() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 09/16] pci-assign: assignment should fail if we can't read config space Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 10/16] pci-assign: propagate errors from get_real_device() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 11/16] pci-assign: propagate errors from assigned_device_pci_cap_init() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 12/16] pci-assign: propagate errors from assigned_dev_register_msix_mmio() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 13/16] pci-assign: propagate errors from assigned_dev_register_regions() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 14/16] pci-assign: propagate errors from assign_device() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 15/16] pci-assign: propagate errors from assign_intx() Laszlo Ersek
2014-04-10  8:24 ` [Qemu-devel] [PATCH 16/16] pci-assign: assigned_initfn(): set monitor error in common error handler Laszlo Ersek
     [not found]   ` <536034EB.5010400@redhat.com>
     [not found]     ` <53604550.1000202@redhat.com>
2014-05-07 13:52       ` Luiz Capitulino
2014-05-07 15:17         ` Laszlo Ersek
     [not found] ` <5360FF1D.6020300@redhat.com>
2014-05-07 13:52   ` [Qemu-devel] [PATCH 00/16] PCI device assignment: improve error reporting over QMP Luiz Capitulino
2014-05-07 15:18     ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397118285-11715-8-git-send-email-lersek@redhat.com \
    --to=lersek@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).