Skip to contentSkip to conversation

powerpc: adding MSI/MSIX support

PATCH New Alexey Kardashevskiy 1 participant 4 messages Jul 10, 2012

lore
Share & tools
lore
#0 lore raw

cover powerpc: adding MSI/MSIX support

While some of my colleagues are overloaded or in vacations, I will give it another try here :)

The patch I posted earlier is split to three to make it easier to review/comment. Each patch compiles but does not make sense without others.

Alexey Kardashevskiy (3):
pseries pci: preparing for MSI/MSIX support pseries pci: added memory window for MSI/MSIX vectors pseries pci: added actual MSI/MSIX support

 hw/spapr.c     |    7 +-
 hw/spapr_pci.c |  279 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 hw/spapr_pci.h |   10 +-
 trace-events   |    9 ++
 4 files changed, 292 insertions(+), 13 deletions(-)
Signature · 1 line
1.7.10
#1 lore raw

PATCH 1/3 pseries pci: preparing for MSI/MSIX support

Added find_phb() function and find_dev() has been changed to use find_phb().

Also, INTx and MSI traces added and INTx trace is used.

---
 hw/spapr_pci.c |   34 ++++++++++++++++++++++++----------
 trace-events   |    9 +++++++++
 2 files changed, 33 insertions(+), 10 deletions(-)
hw/spapr_pci.c +24 -10
index f98cd7e..ff742ef 100644
@@ -29,27 +29,39 @@
 #include "hw/spapr_pci.h"
 #include "exec-memory.h"
 #include <libfdt.h>
+#include "trace.h"
 
 #include "hw/pci_internals.h"
 
-static PCIDevice *find_dev(sPAPREnvironment *spapr,
-                           uint64_t buid, uint32_t config_addr)
+static sPAPRPHBState *find_phb(sPAPREnvironment *spapr, uint64_t buid)
 {
-    int devfn = (config_addr >> 8) & 0xFF;
     sPAPRPHBState *phb;
 
     QLIST_FOREACH(phb, &spapr->phbs, list) {
-        BusChild *kid;
-
         if (phb->buid != buid) {
             continue;
         }
+        return phb;
+    }
+
+    return NULL;
+}
+
+static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid,
+                           uint32_t config_addr)
+{
+    sPAPRPHBState *phb = find_phb(spapr, buid);
+    BusChild *kid;
+    int devfn = (config_addr >> 8) & 0xFF;
+
+    if (!phb) {
+        return NULL;
+    }
 
-        QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) {
-            PCIDevice *dev = (PCIDevice *)kid->child;
-            if (dev->devfn == devfn) {
-                return dev;
-            }
+    QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) {
+        PCIDevice *dev = (PCIDevice *)kid->child;
+        if (dev->devfn == devfn) {
+            return dev;
         }
     }
 
@@ -223,6 +235,8 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)
      */
     sPAPRPHBState *phb = opaque;
 
+    trace_spapr_pci_lsi_set(phb->busname, irq_num,
+                            phb->lsi_table[irq_num].dt_irq);
     qemu_set_irq(xics_assign_irq(spapr->icp,
                                  phb->lsi_table[irq_num].dt_irq, XICS_LSI),
                  level);
trace-events +9 -0
index 5c82b3a..e548f86 100644
@@ -846,3 +846,12 @@ qxl_render_blit_guest_primary_initialized(void) ""
 qxl_render_blit(int32_t stride, int32_t left, int32_t right, int32_t top, int32_t bottom) "stride=%d [%d, %d, %d, %d]"
 qxl_render_guest_primary_resized(int32_t width, int32_t height, int32_t stride, int32_t bytes_pp, int32_t bits_pp) "%dx%d, stride %d, bpp %d, depth %d"
 qxl_render_update_area_done(void *cookie) "%p"
+
+# hw/spapr_pci.c
+spapr_pci_msi(const char *msg, uint32_t n, uint32_t ca) "%s (device#%d, cfg=%x)"
+spapr_pci_msi_setup(const char *name, unsigned vector, uint64_t addr) "dev\"%s\" vector %u, addr=%"PRIx64
+spapr_pci_rtas_ibm_change_msi(unsigned func, unsigned req) "func %u, requested %u"
+spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned ioa, unsigned intr) "queries for #%u, IRQ%u"
+spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) "@%"PRIx64"<=%"PRIx64" IRQ %u"
+spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) "%s PIN%d IRQ %u"
+
Signature · 1 line
1.7.10
#2 lore raw

PATCH 2/3 pseries pci: added memory window for MSI/MSIX vectors

In reply to Alexey Kardashevskiy

As any other PHB, the one in sPAPR has to implement addresses which to be used as MSI/MSIX vectors. It also needs to provide a mechanism to retrieve IRQs number for subsequent qemu_irq_pulse().

This patch includes:

1. A "config_space_address to msi_table" map to provide IRQ resolving from config-address as MSI RTAS calls take a PCI config space address as an identifier.

2. A MSIX memory region is added to catch msi_notify()/msix_notiry() from virtio-pci and pass them to the guest via qemu_irq_pulse().

---
 hw/spapr.c     |    4 +++-
 hw/spapr_pci.c |   43 ++++++++++++++++++++++++++++++++++++++++++-
 hw/spapr_pci.h |   10 +++++++++-
 3 files changed, 54 insertions(+), 3 deletions(-)
hw/spapr.c +3 -1
index af3f479..37f6026 100644
@@ -80,6 +80,7 @@
 #define SPAPR_PCI_MEM_WIN_ADDR  (0x10000000000ULL + 0xA0000000)
 #define SPAPR_PCI_MEM_WIN_SIZE  0x20000000
 #define SPAPR_PCI_IO_WIN_ADDR   (0x10000000000ULL + 0x80000000)
+#define SPAPR_PCI_MSI_WIN_ADDR  (0x10000000000ULL + 0x90000000)
 
 #define PHANDLE_XICP            0x00001111
 
@@ -768,7 +769,8 @@ static void ppc_spapr_init(ram_addr_t ram_size,
     spapr_create_phb(spapr, "pci", SPAPR_PCI_BUID,
                      SPAPR_PCI_MEM_WIN_ADDR,
                      SPAPR_PCI_MEM_WIN_SIZE,
-                     SPAPR_PCI_IO_WIN_ADDR);
+                     SPAPR_PCI_IO_WIN_ADDR,
+                     SPAPR_PCI_MSI_WIN_ADDR);
 
     for (i = 0; i < nb_nics; i++) {
         NICInfo *nd = &nd_table[i];
hw/spapr_pci.c +42 -1

79 lines not on this page · raw message

hw/spapr_pci.h +9 -1
index e54809a..145071c 100644
@@ -27,6 +27,8 @@
 #include "hw/pci_host.h"
 #include "hw/xics.h"
 
+#define SPAPR_MSIX_MAX_DEVS 32
+
 typedef struct sPAPRPHBState {
     PCIHostState host_state;
 
@@ -49,6 +51,12 @@ typedef struct sPAPRPHBState {
         uint32_t dt_irq;
     } lsi_table[PCI_NUM_PINS];
 
+    struct {
+        uint32_t config_addr;
+        uint32_t dt_irq;
+        int nvec;
+    } msi_table[SPAPR_MSIX_MAX_DEVS];
+
     QLIST_ENTRY(sPAPRPHBState) list;
 } sPAPRPHBState;
 
@@ -58,7 +66,7 @@ typedef struct sPAPRPHBState {
 void spapr_create_phb(sPAPREnvironment *spapr,
                       const char *busname, uint64_t buid,
                       uint64_t mem_win_addr, uint64_t mem_win_size,
-                      uint64_t io_win_addr);
+                      uint64_t io_win_addr, uint64_t msi_win_addr);
 
 int spapr_populate_pci_dt(sPAPRPHBState *phb,
                           uint32_t xics_phandle,
Signature · 1 line
1.7.10
#3 lore raw

PATCH 3/3 pseries pci: added actual MSI/MSIX support

In reply to Alexey Kardashevskiy

The first type of MSI/MSIX capable devices to support is virtio-pci.

This patch includes:

1. RTAS call "ibm,change-msi" which sets up number of MSI vectors per a device. Note that this call may configure and return lesser number of vectors than requested.

2. RTAS call "ibm,query-interrupt-source-number" which translates MSI vector to interrupt controller (XICS) IRQ number.

This patch depends on the "msi/msix: added functions to API to set up message address and data" patch.

---
 hw/spapr.c     |    3 +
 hw/spapr_pci.c |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 205 insertions(+)
hw/spapr.c +3 -0
index 37f6026..b83f83b 100644
@@ -41,6 +41,7 @@
 #include "hw/spapr_vio.h"
 #include "hw/spapr_pci.h"
 #include "hw/xics.h"
+#include "hw/msi.h"
 
 #include "kvm.h"
 #include "kvm_ppc.h"
@@ -661,6 +662,8 @@ static void ppc_spapr_init(ram_addr_t ram_size,
     long load_limit, rtas_limit, fw_size;
     char *filename;
 
+    msi_supported = true;
+
     spapr = g_malloc0(sizeof(*spapr));
     QLIST_INIT(&spapr->phbs);
 
hw/spapr_pci.c +202 -0

226 lines not on this page · raw message

Signature · 1 line
1.7.10