Blame SOURCES/kvm-hw-pci-introduce-bridge-only-vendor-specific-capabil.patch

9bac43
From 0153864e153e633e3ebfd4d4091971591d098385 Mon Sep 17 00:00:00 2001
9bac43
From: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Date: Mon, 13 Nov 2017 15:59:39 +0100
9bac43
Subject: [PATCH 01/30] hw/pci: introduce bridge-only vendor-specific
9bac43
 capability to provide some hints to firmware
9bac43
9bac43
RH-Author: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Message-id: <20171113155940.50793-2-marcel@redhat.com>
9bac43
Patchwork-id: 77662
9bac43
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 1/2] hw/pci: introduce bridge-only vendor-specific capability to provide some hints to firmware
9bac43
Bugzilla: 1437113
9bac43
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9bac43
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
9bac43
9bac43
From: Aleksandr Bezzubikov <zuban32s@gmail.com>
9bac43
9bac43
On PCI init PCI bridges may need some extra info about bus number,
9bac43
IO, memory and prefetchable memory to reserve. QEMU can provide this
9bac43
with a special vendor-specific PCI capability.
9bac43
9bac43
Signed-off-by: Aleksandr Bezzubikov <zuban32s@gmail.com>
9bac43
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Tested-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
(cherry picked from commit 70e1ee59bb9490d9ac529e96820a03b346086ca1)
9bac43
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 hw/pci/pci_bridge.c         | 46 +++++++++++++++++++++++++++++++++++++++++++++
9bac43
 include/hw/pci/pci_bridge.h | 25 ++++++++++++++++++++++++
9bac43
 2 files changed, 71 insertions(+)
9bac43
9bac43
diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
9bac43
index 720119b..17feae5 100644
9bac43
--- a/hw/pci/pci_bridge.c
9bac43
+++ b/hw/pci/pci_bridge.c
9bac43
@@ -408,6 +408,52 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,
9bac43
     br->bus_name = bus_name;
9bac43
 }
9bac43
 
9bac43
+
9bac43
+int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,
9bac43
+                                     uint32_t bus_reserve, uint64_t io_reserve,
9bac43
+                                     uint32_t mem_non_pref_reserve,
9bac43
+                                     uint32_t mem_pref_32_reserve,
9bac43
+                                     uint64_t mem_pref_64_reserve,
9bac43
+                                     Error **errp)
9bac43
+{
9bac43
+    if (mem_pref_32_reserve != (uint32_t)-1 &&
9bac43
+        mem_pref_64_reserve != (uint64_t)-1) {
9bac43
+        error_setg(errp,
9bac43
+                   "PCI resource reserve cap: PREF32 and PREF64 conflict");
9bac43
+        return -EINVAL;
9bac43
+    }
9bac43
+
9bac43
+    if (bus_reserve == (uint32_t)-1 &&
9bac43
+        io_reserve == (uint64_t)-1 &&
9bac43
+        mem_non_pref_reserve == (uint32_t)-1 &&
9bac43
+        mem_pref_32_reserve == (uint32_t)-1 &&
9bac43
+        mem_pref_64_reserve == (uint64_t)-1) {
9bac43
+        return 0;
9bac43
+    }
9bac43
+
9bac43
+    size_t cap_len = sizeof(PCIBridgeQemuCap);
9bac43
+    PCIBridgeQemuCap cap = {
9bac43
+            .len = cap_len,
9bac43
+            .type = REDHAT_PCI_CAP_RESOURCE_RESERVE,
9bac43
+            .bus_res = bus_reserve,
9bac43
+            .io = io_reserve,
9bac43
+            .mem = mem_non_pref_reserve,
9bac43
+            .mem_pref_32 = mem_pref_32_reserve,
9bac43
+            .mem_pref_64 = mem_pref_64_reserve
9bac43
+    };
9bac43
+
9bac43
+    int offset = pci_add_capability(dev, PCI_CAP_ID_VNDR,
9bac43
+                                    cap_offset, cap_len, errp);
9bac43
+    if (offset < 0) {
9bac43
+        return offset;
9bac43
+    }
9bac43
+
9bac43
+    memcpy(dev->config + offset + PCI_CAP_FLAGS,
9bac43
+           (char *)&cap + PCI_CAP_FLAGS,
9bac43
+           cap_len - PCI_CAP_FLAGS);
9bac43
+    return 0;
9bac43
+}
9bac43
+
9bac43
 static const TypeInfo pci_bridge_type_info = {
9bac43
     .name = TYPE_PCI_BRIDGE,
9bac43
     .parent = TYPE_PCI_DEVICE,
9bac43
diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
9bac43
index ff7cbaa..1acadc2 100644
9bac43
--- a/include/hw/pci/pci_bridge.h
9bac43
+++ b/include/hw/pci/pci_bridge.h
9bac43
@@ -67,4 +67,29 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,
9bac43
 #define  PCI_BRIDGE_CTL_DISCARD_STATUS	0x400	/* Discard timer status */
9bac43
 #define  PCI_BRIDGE_CTL_DISCARD_SERR	0x800	/* Discard timer SERR# enable */
9bac43
 
9bac43
+typedef struct PCIBridgeQemuCap {
9bac43
+    uint8_t id;     /* Standard PCI capability header field */
9bac43
+    uint8_t next;   /* Standard PCI capability header field */
9bac43
+    uint8_t len;    /* Standard PCI vendor-specific capability header field */
9bac43
+    uint8_t type;   /* Red Hat vendor-specific capability type.
9bac43
+                       Types are defined with REDHAT_PCI_CAP_ prefix */
9bac43
+
9bac43
+    uint32_t bus_res;   /* Minimum number of buses to reserve */
9bac43
+    uint64_t io;        /* IO space to reserve */
9bac43
+    uint32_t mem;       /* Non-prefetchable memory to reserve */
9bac43
+    /* At most one of the following two fields may be set to a value
9bac43
+     * different from -1 */
9bac43
+    uint32_t mem_pref_32; /* Prefetchable memory to reserve (32-bit MMIO) */
9bac43
+    uint64_t mem_pref_64; /* Prefetchable memory to reserve (64-bit MMIO) */
9bac43
+} PCIBridgeQemuCap;
9bac43
+
9bac43
+#define REDHAT_PCI_CAP_RESOURCE_RESERVE 1
9bac43
+
9bac43
+int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,
9bac43
+                              uint32_t bus_reserve, uint64_t io_reserve,
9bac43
+                              uint32_t mem_non_pref_reserve,
9bac43
+                              uint32_t mem_pref_32_reserve,
9bac43
+                              uint64_t mem_pref_64_reserve,
9bac43
+                              Error **errp);
9bac43
+
9bac43
 #endif /* QEMU_PCI_BRIDGE_H */
9bac43
-- 
9bac43
1.8.3.1
9bac43