[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/38] pci: add Error-propagating pci_add_capability2
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 12/38] pci: add Error-propagating pci_add_capability2() |
Date: |
Thu, 8 May 2014 14:52:36 -0400 |
From: Laszlo Ersek <address@hidden>
... and rebase pci_add_capability() to it.
Signed-off-by: Laszlo Ersek <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
hw/pci/pci.c | 32 ++++++++++++++++++++++++++------
include/hw/pci/pci.h | 4 ++++
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 517ff2a..22fe5ee 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2013,12 +2013,32 @@ static void pci_del_option_rom(PCIDevice *pdev)
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 {
@@ -2029,12 +2049,12 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
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;
}
}
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
@@ -6,6 +6,7 @@
#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"
@@ -308,6 +309,9 @@ 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);
--
1.9.0
- [Qemu-devel] [PULL 04/38] qapi: Add a primitive to include other files from a QAPI schema file, (continued)
- [Qemu-devel] [PULL 04/38] qapi: Add a primitive to include other files from a QAPI schema file, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 02/38] qapi: [trivial] Do not catch unknown exceptions in "test-qapi.py", Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 01/38] qapi: [trivial] Break long command lines, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 06/38] cutils: tighten qemu_parse_fd(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 07/38] monitor: add Error-propagating monitor_handle_fd_param2(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 08/38] pci-assign: accept Error from monitor_handle_fd_param2(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 05/38] qapi: treat all negative return of strtosz_suffix() as error, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 11/38] pci-assign: propagate Error from check_irqchip_in_kernel(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 10/38] pci-assign: propagate errors from get_real_id(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 14/38] pci-assign: assignment should fail if we can't read config space, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 12/38] pci: add Error-propagating pci_add_capability2(),
Luiz Capitulino <=
- [Qemu-devel] [PULL 13/38] pci-assign: accept Error from pci_add_capability2(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 15/38] pci-assign: propagate errors from get_real_device(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 16/38] pci-assign: propagate errors from assigned_device_pci_cap_init(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 09/38] pci-assign: make assign_failed_examine() just format the cause, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 18/38] pci-assign: propagate errors from assigned_dev_register_regions(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 17/38] pci-assign: propagate errors from assigned_dev_register_msix_mmio(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 19/38] pci-assign: propagate errors from assign_device(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 20/38] pci-assign: propagate errors from assign_intx(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 21/38] pci-assign: assigned_initfn(): set monitor error in common error handler, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 23/38] qga: Consistently name Error ** objects errp, and not err, Luiz Capitulino, 2014/05/08