Skip to contentSkip to conversation

ppc patch queue 2012-03-15

GIT PULL New Alexander Graf 2 participants 18 messages Mar 15, 2012 – Mar 17, 2012

lore
Share & tools
lore
#0 lore raw

Hi Blue / Aurelien,

This is my current patch queue for ppc. Please pull.

Alex

The following changes since commit ae7d54d489540b49b7c13a7df7ddc220588a2ced:
Andreas Färber (1):
target-lm32/microblaze: Drop second CPU{LM32, MB}State typedef

are available in the git repository at:

git://repo.or.cz/qemu/agraf.git ppc-for-upstream

Alex Barcelo (1):
Bad zero comparison for sas_ss_flags on powerpc

Alexander Graf (3):
PPC: 405: Fix ppc405ep initialization
PPC: KVM: Synchronize regs on CPU dump
PPC: Fix openpic with relative memregions

Alexey Kardashevskiy (1):
pseries: Remove PCI device from PCI host bridge code

David Gibson (6):
pseries: Don't try to munmap() a malloc()ed TCE table
pseries: Update SLOF firmware image
pseries: Remove unused constant from PCI code
pseries: Add support for level interrupts to XICS
kvm: Comparison with ioctl number macros needs to be unsigned
pseries: Configure PCI bridge using properties

Meador Inge (1):
ppc: Correctly define POWERPC_INSNS2_DEFAULT

Nathan Whitehorn (2):
PPC: Add PIR register to POWER7 CPU
PPC: Fix large page support in TCG

Stefan Weil (1):
ppc: Add missing 'static' to spin_rw_ops

Thomas Huth (1):
PPC64: Add support for ldbrx and stdbrx instructions

 hw/openpic.c                |   12 +--
 hw/ppc405_uc.c              |    2 +
 hw/ppce500_spin.c           |    2 +-
 hw/spapr.c                  |    5 +-
 hw/spapr.h                  |   13 +++-
 hw/spapr_pci.c              |  193 ++++++++++++++++++++-----------------------
 hw/spapr_pci.h              |    4 +-
 hw/spapr_vio.c              |    2 +-
 hw/xics.c                   |  125 +++++++++++++++++++++-------
 hw/xics.h                   |    8 ++-
 kvm-all.c                   |    5 +-
 linux-user/signal.c         |    2 +-
 pc-bios/README              |    2 +-
 pc-bios/slof.bin            |  Bin 869584 -> 880496 bytes
 roms/SLOF                   |    2 +-
 target-ppc/cpu.h            |    4 +-
 target-ppc/helper.c         |   12 ++--
 target-ppc/kvm.c            |   12 ++-
 target-ppc/translate.c      |   54 ++++++++++--
 target-ppc/translate_init.c |   11 ++-
 20 files changed, 294 insertions(+), 176 deletions(-)
#1 lore raw

PATCH 1/16 Bad zero comparison for sas_ss_flags on powerpc

From: Alex Barcelo <[email protected]>

All architectures work the same way, and all check for sas_ss_flags ==
0. The powerpc lines are wrong, and do the check the other way round (it's a qemu internal check, which is done wrong only for this architecture, it's more a typo than a bug). It's NOT ppc specific, it's POSIX standard (sigaltstack) and qemu internal.

I have a test source that I will send in a follow-up (it's longer than I would have wished, I'm sure that a better test case can be written if needed)

---
 linux-user/signal.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/signal.c +1 -1
index fca51e2..b1e139d 100644
@@ -4118,7 +4118,7 @@ static target_ulong get_sigframe(struct target_sigaction *ka,
     oldsp = env->gpr[1];
 
     if ((ka->sa_flags & TARGET_SA_ONSTACK) &&
-        (sas_ss_flags(oldsp))) {
+        (sas_ss_flags(oldsp) == 0)) {
         oldsp = (target_sigaltstack_used.ss_sp
                  + target_sigaltstack_used.ss_size);
     }
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/16 PPC: 405: Fix ppc405ep initialization

In reply to Alexander Graf

When trying to run a ppc405 guest, it segfaults quite quickly, trying to access timers that weren't initialized. Initialize them properly instead.

---
 hw/ppc405_uc.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/ppc405_uc.c +2 -0
index 6f8342e..89e5013 100644
@@ -2471,6 +2471,8 @@ CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,
     ppc4xx_pob_init(env);
     /* OBP arbitrer */
     ppc4xx_opba_init(0xef600600);
+    /* Initialize timers */
+    ppc_booke_timers_init(env, sysclk, 0);
     /* Universal interrupt controller */
     irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] =
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/16 ppc: Add missing 'static' to spin_rw_ops

In reply to Alexander Graf

From: Stefan Weil <[email protected]>

spin_rw_ops is only used in hw/ppce500_spin.c.

---
 hw/ppce500_spin.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/ppce500_spin.c +1 -1
index 268f5fd..960b7b0 100644
@@ -182,7 +182,7 @@ static uint64_t spin_read(void *opaque, target_phys_addr_t addr, unsigned len)
     }
 }
 
-const MemoryRegionOps spin_rw_ops = {
+static const MemoryRegionOps spin_rw_ops = {
     .read = spin_read,
     .write = spin_write,
     .endianness = DEVICE_BIG_ENDIAN,
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/16 pseries: Don't try to munmap() a malloc()ed TCE table

In reply to Alexander Graf

From: David Gibson <[email protected]>

For the pseries machine, TCE (IOMMU) tables can either be directly malloc()ed in qemu or, when running on a KVM which supports it, mmap()ed from a KVM ioctl. The latter option is used when available, because it allows the (frequent bottlenext) H_PUT_TCE hypercall to be KVM accelerated. However, even when KVM is persent, TCE acceleration is not always possible. Only KVM HV supports this ioctl(), not KVM PR, or the kernel could run out of contiguous memory to allocate the new table. In this case we need to fall back on the malloc()ed table.

When a device is removed, and we need to remove the TCE table, we need to either munmap() or free() the table as appropriate for how it was allocated. The code is supposed to do that, but we buggily fail to initialize the tcet->fd variable in the malloc() case, which is used as a flag to determine which is the right choice.

This patch fixes the bug, and cleans up error messages relating to this path while we're at it.

---
 target-ppc/kvm.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
target-ppc/kvm.c +10 -2
index aeb3de9..724f4c7 100644
@@ -843,12 +843,18 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd)
     int fd;
     void *table;
 
+    /* Must set fd to -1 so we don't try to munmap when called for
+     * destroying the table, which the upper layers -will- do
+     */
+    *pfd = -1;
     if (!cap_spapr_tce) {
         return NULL;
     }
 
     fd = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE, &args);
     if (fd < 0) {
+        fprintf(stderr, "KVM: Failed to create TCE table for liobn 0x%x\n",
+                liobn);
         return NULL;
     }
 
@@ -857,6 +863,8 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd)
 
     table = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
     if (table == MAP_FAILED) {
+        fprintf(stderr, "KVM: Failed to map TCE table for liobn 0x%x\n",
+                liobn);
         close(fd);
         return NULL;
     }
@@ -876,8 +884,8 @@ int kvmppc_remove_spapr_tce(void *table, int fd, uint32_t window_size)
     len = (window_size / SPAPR_VIO_TCE_PAGE_SIZE)*sizeof(VIOsPAPR_RTCE);
     if ((munmap(table, len) < 0) ||
         (close(fd) < 0)) {
-        fprintf(stderr, "KVM: Unexpected error removing KVM SPAPR TCE "
-                "table: %s", strerror(errno));
+        fprintf(stderr, "KVM: Unexpected error removing TCE table: %s",
+                strerror(errno));
         /* Leak the table */
     }
 
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/16 PPC64: Add support for ldbrx and stdbrx instructions

In reply to Alexander Graf

From: Thomas Huth <[email protected]>

These instructions for loading and storing byte-swapped 64-bit values have been introduced in PowerISA 2.06.

---
 target-ppc/cpu.h            |    4 ++-
 target-ppc/translate.c      |   52 +++++++++++++++++++++++++++++++++++-------
 target-ppc/translate_init.c |    2 +-
 3 files changed, 47 insertions(+), 11 deletions(-)
target-ppc/cpu.h +3 -1
index ad09cbe..ca6f1cb 100644
@@ -1918,8 +1918,10 @@ enum {
     PPC2_DFP           = 0x0000000000000004ULL,
     /* Embedded.Processor Control                                            */
     PPC2_PRCNTL        = 0x0000000000000008ULL,
+    /* Byte-reversed, indexed, double-word load and store                    */
+    PPC2_DBRX          = 0x0000000000000010ULL,
 
-#define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_PRCNTL)
+#define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_DBRX)
 };
 
 /*****************************************************************************/
target-ppc/translate.c +43 -9

124 lines not on this page · raw message

target-ppc/translate_init.c +1 -1
index 1ec6f42..c707959 100644
@@ -6571,7 +6571,7 @@ static void init_proc_970MP (CPUPPCState *env)
                               PPC_64B | PPC_ALTIVEC |                         \
                               PPC_SEGMENT_64B | PPC_SLBI |                    \
                               PPC_POPCNTB | PPC_POPCNTWD)
-#define POWERPC_INSNS2_POWER7 (PPC2_VSX | PPC2_DFP)
+#define POWERPC_INSNS2_POWER7 (PPC2_VSX | PPC2_DFP | PPC2_DBRX)
 #define POWERPC_MSRM_POWER7   (0x800000000204FF36ULL)
 #define POWERPC_MMU_POWER7    (POWERPC_MMU_2_06)
 #define POWERPC_EXCP_POWER7   (POWERPC_EXCP_POWER7)
Signature · 1 line
1.6.0.2
#6 lore raw

PATCH 6/16 pseries: Update SLOF firmware image

In reply to Alexander Graf

From: David Gibson <[email protected]>

This patch updates the SLOF firmware image used on the pseries machine. The new version adds support for Cirrus VGA and virtfs, as well as including a number of bugfixes.

---
 pc-bios/README   |    2 +-
 pc-bios/slof.bin |  Bin 869584 -> 880496 bytes
 roms/SLOF        |    2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)
pc-bios/README +1 -1
index 5dce355..71f4871 100644
@@ -17,7 +17,7 @@
 - SLOF (Slimline Open Firmware) is a free IEEE 1275 Open Firmware
   implementation for certain IBM POWER hardware.  The sources are at
   https://github.com/dgibson/SLOF, and the image currently in qemu is
-  built from git tag qemu-slof-20120111.1.
+  built from git tag qemu-slof-20120217.
 
 - sgabios (the Serial Graphics Adapter option ROM) provides a means for
   legacy x86 software to communicate with an attached serial console as
pc-bios/slof.bin binary +0 -0
index 8554f54b5773f0771eec28f6c3bc0dc17e063a47..449a7bb2afaf604f6c089612e99086df0800d7dc 100644
GIT binary patch
roms/SLOF +1 -1
index ab062ff..d153364 160000
@@ -1 +1 @@
-Subproject commit ab062ff3b37c39649f2b0d94ed607adc6f6b3c7d
+Subproject commit d153364253548d6cd91403711f84996e6a7dab31
Signature · 1 line
1.6.0.2
#7 lore raw

PATCH 7/16 pseries: Remove unused constant from PCI code

In reply to Alexander Graf

From: David Gibson <[email protected]>

The 'bars' constant array was used in experimental device allocation code which is no longer necessary now that we always run the SLOF firmware. This patch removes the now redundant variable.

---
 hw/spapr_pci.c |    7 -------
 1 files changed, 0 insertions(+), 7 deletions(-)
hw/spapr_pci.c +0 -7
index 374dcf8..3d5e50a 100644
@@ -32,13 +32,6 @@
 
 #include "hw/pci_internals.h"
 
-static const uint32_t bars[] = {
-    PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1,
-    PCI_BASE_ADDRESS_2, PCI_BASE_ADDRESS_3,
-    PCI_BASE_ADDRESS_4, PCI_BASE_ADDRESS_5
-    /*, PCI_ROM_ADDRESS*/
-};
-
 static PCIDevice *find_dev(sPAPREnvironment *spapr,
                            uint64_t buid, uint32_t config_addr)
 {
Signature · 1 line
1.6.0.2
#8 lore raw

PATCH 8/16 pseries: Remove PCI device from PCI host bridge code

In reply to Alexander Graf

From: Alexey Kardashevskiy <[email protected]>

The sPAPR PCI code defines a PCI device "spapr-pci-host-bridge-pci" which is never used. This came over from the earlier bridge driver we used as a template. Some other bridges appear on their own PCI bus as a device, but that is not true of pSeries bridges, which are pure host to PCI with no visible presence on the PCI side.

---
 hw/spapr_pci.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
hw/spapr_pci.c +0 -20
index 3d5e50a..c06afac 100644
@@ -202,25 +202,6 @@ static int spapr_phb_init(SysBusDevice *s)
     return 0;
 }
 
-static int spapr_main_pci_host_init(PCIDevice *d)
-{
-    return 0;
-}
-
-static void spapr_main_pci_host_class_init(ObjectClass *klass, void *data)
-{
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = spapr_main_pci_host_init;
-}
-
-static TypeInfo spapr_main_pci_host_info = {
-    .name          = "spapr-pci-host-bridge-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(PCIDevice),
-    .class_init    = spapr_main_pci_host_class_init,
-};
-
 static void spapr_phb_class_init(ObjectClass *klass, void *data)
 {
     SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
@@ -238,7 +219,6 @@ static TypeInfo spapr_phb_info = {
 static void spapr_register_types(void)
 {
     type_register_static(&spapr_phb_info);
-    type_register_static(&spapr_main_pci_host_info);
 }
 
 type_init(spapr_register_types)
Signature · 1 line
1.6.0.2
#9 lore raw

PATCH 9/16 PPC: Add PIR register to POWER7 CPU

In reply to Alexander Graf

From: Nathan Whitehorn <[email protected]>

The POWER7 emulation is missing the Processor Identification Register, mandatory in recent POWER CPUs, that is required for SMP on at least some operating systems (e.g. FreeBSD) to function properly. This patch copies the existing PIR code from the other CPUs that implement it.

---
 target-ppc/translate_init.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
target-ppc/translate_init.c +5 -0
index c707959..5a958b9 100644
@@ -6588,6 +6588,11 @@ static void init_proc_POWER7 (CPUPPCState *env)
     gen_spr_7xx(env);
     /* Time base */
     gen_tbl(env);
+    /* Processor identification */
+    spr_register(env, SPR_PIR, "PIR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 &spr_read_generic, &spr_write_pir,
+                 0x00000000);
 #if !defined(CONFIG_USER_ONLY)
     /* PURR & SPURR: Hack - treat these as aliases for the TB for now */
     spr_register(env, SPR_PURR,   "PURR",
Signature · 1 line
1.6.0.2
#10 lore raw

PATCH 10/16 PPC: Fix large page support in TCG

In reply to Alexander Graf

From: Nathan Whitehorn <[email protected]>

Fix large page support in TCG. The old code would overwrite the large page table entry with the fake 4 KB one generated here whenever the ref/change bits were updated, causing it to point to the wrong area of memory.

---
 target-ppc/helper.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
target-ppc/helper.c +6 -6
index bd711b6..39dcc27 100644
@@ -591,12 +591,6 @@ static inline int _find_pte(CPUPPCState *env, mmu_ctx_t *ctx, int is_64b, int h,
                 pte1 = ldq_phys(env->htab_base + pteg_off + (i * 16) + 8);
             }
 
-            /* We have a TLB that saves 4K pages, so let's
-             * split a huge page to 4k chunks */
-            if (target_page_bits != TARGET_PAGE_BITS)
-                pte1 |= (ctx->eaddr & (( 1 << target_page_bits ) - 1))
-                        & TARGET_PAGE_MASK;
-
             r = pte64_check(ctx, pte0, pte1, h, rw, type);
             LOG_MMU("Load pte from " TARGET_FMT_lx " => " TARGET_FMT_lx " "
                     TARGET_FMT_lx " %d %d %d " TARGET_FMT_lx "\n",
@@ -672,6 +666,12 @@ static inline int _find_pte(CPUPPCState *env, mmu_ctx_t *ctx, int is_64b, int h,
         }
     }
 
+    /* We have a TLB that saves 4K pages, so let's
+     * split a huge page to 4k chunks */
+    if (target_page_bits != TARGET_PAGE_BITS) {
+        ctx->raddr |= (ctx->eaddr & ((1 << target_page_bits) - 1))
+                      & TARGET_PAGE_MASK;
+    }
     return ret;
 }
 
Signature · 1 line
1.6.0.2
#11 lore raw

PATCH 11/16 pseries: Add support for level interrupts to XICS

In reply to Alexander Graf

From: David Gibson <[email protected]>

The pseries "xics" interrupt controller, like most interrupt controllers can support both message (i.e. edge sensitive) interrupts and level sensitive interrupts, but it needs to know which are which.

When I implemented the xics emulation for qemu, the only devices we supported were the PAPR virtual IO devices. These devices only use message interrupts, so they were the only ones I implemented in xics.

Since then, however, we have added support for PCI devices, which use level sensitive interrupts. It turns out the message interrupt logic still actually works most of the time for these, but there are circumstances where we can lost interrupts due to the incorrect interrupt logic.

This patch, therefore, implements the correct xics level-sensitive interrupt logic. The type of the interrupt is set when a device allocates a new xics interrupt.

---
 hw/spapr.c     |    5 +-
 hw/spapr.h     |   13 +++++-
 hw/spapr_pci.c |    2 +-
 hw/spapr_vio.c |    2 +-
 hw/xics.c      |  125 +++++++++++++++++++++++++++++++++++++++++--------------
 hw/xics.h      |    8 +++-
 6 files changed, 117 insertions(+), 38 deletions(-)
hw/spapr.c +3 -2
index 3719e0e..bfaf260 100644
@@ -83,7 +83,8 @@
 
 sPAPREnvironment *spapr;
 
-qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num)
+qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num,
+                            enum xics_irq_type type)
 {
     uint32_t irq;
     qemu_irq qirq;
@@ -95,7 +96,7 @@ qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num)
         irq = spapr->next_irq++;
     }
 
-    qirq = xics_find_qirq(spapr->icp, irq);
+    qirq = xics_assign_irq(spapr->icp, irq, type);
     if (!qirq) {
         return NULL;
     }
hw/spapr.h +12 -1
index a41641f..11160b0 100644
@@ -286,7 +286,18 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
 target_ulong spapr_hypercall(CPUPPCState *env, target_ulong opcode,
                              target_ulong *args);
 
-qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num);
+qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num,
+                            enum xics_irq_type type);
+
+static inline qemu_irq spapr_allocate_msi(uint32_t hint, uint32_t *irq_num)
+{
+    return spapr_allocate_irq(hint, irq_num, XICS_MSI);
+}
+
+static inline qemu_irq spapr_allocate_lsi(uint32_t hint, uint32_t *irq_num)
+{
+    return spapr_allocate_irq(hint, irq_num, XICS_LSI);
+}
 
 static inline uint32_t rtas_ld(target_ulong phys, int n)
 {
hw/spapr_pci.c +1 -1
index c06afac..233250f 100644
@@ -190,7 +190,7 @@ static int spapr_phb_init(SysBusDevice *s)
         qemu_irq qirq;
         uint32_t num;
 
-        qirq = spapr_allocate_irq(0, &num);
+        qirq = spapr_allocate_lsi(0, &num);
         if (!qirq) {
             return -1;
         }
hw/spapr_vio.c +1 -1
index 2fb3cee..dbf5a90 100644
@@ -670,7 +670,7 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
         dev->qdev.id = id;
     }
 
-    dev->qirq = spapr_allocate_irq(dev->vio_irq_num, &dev->vio_irq_num);
+    dev->qirq = spapr_allocate_msi(dev->vio_irq_num, &dev->vio_irq_num);
     if (!dev->qirq) {
         return -1;
     }
hw/xics.c +93 -32

204 lines not on this page · raw message

hw/xics.h +7 -1
index 83c1182..2080159 100644
@@ -31,7 +31,13 @@
 
 struct icp_state;
 
-qemu_irq xics_find_qirq(struct icp_state *icp, int irq);
+enum xics_irq_type {
+    XICS_MSI,        /* Message-signalled (edge) interrupt */
+    XICS_LSI,        /* Level-signalled interrupt */
+};
+
+qemu_irq xics_assign_irq(struct icp_state *icp, int irq,
+                         enum xics_irq_type type);
 
 struct icp_state *xics_system_init(int nr_irqs);
 
Signature · 1 line
1.6.0.2
#12 lore raw

PATCH 12/16 ppc: Correctly define POWERPC_INSNS2_DEFAULT

In reply to Alexander Graf

From: Meador Inge <[email protected]>

'POWERPC_INSNS2_DEFAULT' was defined incorrectly which was causing the opcode table creation code to erroneously register 'eieio' and 'mbar' for the "default" processor:

** ERROR: opcode 1a already assigned in opcode table 16 *** ERROR: unable to insert opcode [1f-16-1a] *** ERROR initializing PowerPC instruction 0x1f 0x16 0x1a

---
 target-ppc/translate_init.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
target-ppc/translate_init.c +2 -2
index 5a958b9..367eefa 100644
@@ -6718,7 +6718,7 @@ static void init_proc_620 (CPUPPCState *env)
 #if defined (TARGET_PPC64) && 0 // XXX: TODO
 #define CPU_POWERPC_DEFAULT    CPU_POWERPC_PPC64
 #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC64
-#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC64
+#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC64
 #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC64
 #define POWERPC_MMU_DEFAULT    POWERPC_MMU_PPC64
 #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC64
@@ -6730,7 +6730,7 @@ static void init_proc_620 (CPUPPCState *env)
 #else
 #define CPU_POWERPC_DEFAULT    CPU_POWERPC_PPC32
 #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC32
-#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC32
+#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC32
 #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC32
 #define POWERPC_MMU_DEFAULT    POWERPC_MMU_PPC32
 #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC32
Signature · 1 line
1.6.0.2
#13 lore raw

PATCH 13/16 kvm: Comparison with ioctl number macros needs to be unsigned

In reply to Alexander Graf

From: David Gibson <[email protected]>

In kvm-all.c we store an ioctl cmd number in the irqchip_inject_ioctl field of KVMState, which has type 'int'. This seems to make sense since the ioctl() man page says that the cmd parameter has type int.

However, the kernel treats ioctl numbers as unsigned - sys_ioctl() takes an unsigned int, and the macros which generate ioctl numbers expand to unsigned expressions. Furthermore, some ioctls (IOC_READ ioctls on x86 and IOC_WRITE ioctls on powerpc) have bit 31 set, and so would be negative if interpreted as an int. This has the surprising and compile-breaking consequence that in kvm_irqchip_set_irq() where we do:

    return (s->irqchip_inject_ioctl == KVM_IRQ_LINE) ? 1 : event.status;

We will get a "comparison is always false due to limited range of data type" warning from gcc if KVM_IRQ_LINE is one of the bit-31-set ioctls, which it is on powerpc.

So, despite the fact that the man page and posix say ioctl numbers are signed, they're actually unsigned. The kernel uses unsigned, the glibc header uses unsigned long, and FreeBSD, NetBSD and OSX also use unsigned long ioctl numbers in the code.

Therefore, this patch changes the variable to be unsigned, fixing the compile.

---
 kvm-all.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kvm-all.c +4 -1
index 42e5e23..ba2cee1 100644
@@ -79,7 +79,10 @@ struct KVMState
     int pit_state2;
     int xsave, xcrs;
     int many_ioeventfds;
-    int irqchip_inject_ioctl;
+    /* The man page (and posix) say ioctl numbers are signed int, but
+     * they're not.  Linux, glibc and *BSD all treat ioctl numbers as
+     * unsigned, and treating them as signed here can break things */
+    unsigned irqchip_inject_ioctl;
 #ifdef KVM_CAP_IRQ_ROUTING
     struct kvm_irq_routing *irq_routes;
     int nr_allocated_irq_routes;
Signature · 1 line
1.6.0.2
#14 lore raw

PATCH 14/16 PPC: KVM: Synchronize regs on CPU dump

In reply to Alexander Graf

When we dump the CPU registers, there's a certain chance they haven't been synchronized with KVM yet, so we have to manually trigger that.

This aligns the code with x86 and fixes a bug where the register state was bogus on invalid/unknown kvm exit reasons.

---
 target-ppc/translate.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-ppc/translate.c +2 -0
index 4722a09..c9a503a 100644
@@ -9319,6 +9319,8 @@ void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf,
 
     int i;
 
+    cpu_synchronize_state(env);
+
     cpu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
                 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
                 env->nip, env->lr, env->ctr, env->xer);
Signature · 1 line
1.6.0.2
#15 lore raw

PATCH 15/16 pseries: Configure PCI bridge using properties

In reply to Alexander Graf

From: David Gibson <[email protected]>

Currently, the function spapr_create_phb() uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.

Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from spapr_create_phb() to spapr_phb_init().

While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.

---
 hw/spapr_pci.c |  166 +++++++++++++++++++++++++++++++-------------------------
 hw/spapr_pci.h |    4 +-
 2 files changed, 94 insertions(+), 76 deletions(-)
hw/spapr_pci.c +91 -75
index 233250f..e7ef551 100644
@@ -180,49 +180,6 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)
     qemu_set_irq(phb->lsi_table[irq_num].qirq, level);
 }
 
-static int spapr_phb_init(SysBusDevice *s)
-{
-    sPAPRPHBState *phb = FROM_SYSBUS(sPAPRPHBState, s);
-    int i;
-
-    /* Initialize the LSI table */
-    for (i = 0; i < SPAPR_PCI_NUM_LSI; i++) {
-        qemu_irq qirq;
-        uint32_t num;
-
-        qirq = spapr_allocate_lsi(0, &num);
-        if (!qirq) {
-            return -1;
-        }
-
-        phb->lsi_table[i].dt_irq = num;
-        phb->lsi_table[i].qirq = qirq;
-    }
-
-    return 0;
-}
-
-static void spapr_phb_class_init(ObjectClass *klass, void *data)
-{
-    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
-
-    sdc->init = spapr_phb_init;
-}
-
-static TypeInfo spapr_phb_info = {
-    .name          = "spapr-pci-host-bridge",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(sPAPRPHBState),
-    .class_init    = spapr_phb_class_init,
-};
-
-static void spapr_register_types(void)
-{
-    type_register_static(&spapr_phb_info);
-}
-
-type_init(spapr_register_types)
-
 static uint64_t spapr_io_read(void *opaque, target_phys_addr_t addr,
                               unsigned size)
 {
@@ -260,35 +217,29 @@ static const MemoryRegionOps spapr_io_ops = {
     .write = spapr_io_write
 };
 
-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)
+/*
+ * PHB PCI device
+ */
+static int spapr_phb_init(SysBusDevice *s)
 {
-    DeviceState *dev;
-    SysBusDevice *s;
-    sPAPRPHBState *phb;
+    sPAPRPHBState *phb = FROM_SYSBUS(sPAPRPHBState, s);
+    char *namebuf;
+    int i;
     PCIBus *bus;
-    char namebuf[strlen(busname)+11];
 
-    dev = qdev_create(NULL, "spapr-pci-host-bridge");
-    qdev_init_nofail(dev);
-    s = sysbus_from_qdev(dev);
-    phb = FROM_SYSBUS(sPAPRPHBState, s);
+    phb->dtbusname = g_strdup_printf("pci@%" PRIx64, phb->buid);
+    namebuf = alloca(strlen(phb->dtbusname) + 32);
 
-    phb->mem_win_addr = mem_win_addr;
-
-    sprintf(namebuf, "%s-mem", busname);
+    /* Initialize memory regions */
+    sprintf(namebuf, "%s.mmio", phb->dtbusname);
     memory_region_init(&phb->memspace, namebuf, INT64_MAX);
 
-    sprintf(namebuf, "%s-memwindow", busname);
+    sprintf(namebuf, "%s.mmio-alias", phb->dtbusname);
     memory_region_init_alias(&phb->memwindow, namebuf, &phb->memspace,
-                             SPAPR_PCI_MEM_WIN_BUS_OFFSET, mem_win_size);
-    memory_region_add_subregion(get_system_memory(), mem_win_addr,
+                             SPAPR_PCI_MEM_WIN_BUS_OFFSET, phb->mem_win_size);
+    memory_region_add_subregion(get_system_memory(), phb->mem_win_addr,
                                 &phb->memwindow);
 
-    phb->io_win_addr = io_win_addr;
-
     /* On ppc, we only have MMIO no specific IO space from the CPU
      * perspective.  In theory we ought to be able to embed the PCI IO
      * memory region direction in the system memory space.  However,
@@ -297,33 +248,92 @@ void spapr_create_phb(sPAPREnvironment *spapr,
      * system io address space.  This hack to bounce things via
      * system_io works around the problem until all the users of
      * old_portion are updated */
-    sprintf(namebuf, "%s-io", busname);
+    sprintf(namebuf, "%s.io", phb->dtbusname);
     memory_region_init(&phb->iospace, namebuf, SPAPR_PCI_IO_WIN_SIZE);
     /* FIXME: fix to support multiple PHBs */
     memory_region_add_subregion(get_system_io(), 0, &phb->iospace);
 
-    sprintf(namebuf, "%s-iowindow", busname);
+    sprintf(namebuf, "%s.io-alias", phb->dtbusname);
     memory_region_init_io(&phb->iowindow, &spapr_io_ops, phb,
                           namebuf, SPAPR_PCI_IO_WIN_SIZE);
-    memory_region_add_subregion(get_system_memory(), io_win_addr,
+    memory_region_add_subregion(get_system_memory(), phb->io_win_addr,
                                 &phb->iowindow);
 
-    phb->host_state.bus = bus = pci_register_bus(&phb->busdev.qdev, busname,
-                                                 pci_spapr_set_irq,
-                                                 pci_spapr_map_irq,
-                                                 phb,
-                                                 &phb->memspace, &phb->iospace,
-                                                 PCI_DEVFN(0, 0),
-                                                 SPAPR_PCI_NUM_LSI);
+    bus = pci_register_bus(&phb->busdev.qdev,
+                           phb->busname ? phb->busname : phb->dtbusname,
+                           pci_spapr_set_irq, pci_spapr_map_irq, phb,
+                           &phb->memspace, &phb->iospace,
+                           PCI_DEVFN(0, 0), SPAPR_PCI_NUM_LSI);
+    phb->host_state.bus = bus;
+
+    QLIST_INSERT_HEAD(&spapr->phbs, phb, list);
+
+    /* Initialize the LSI table */
+    for (i = 0; i < SPAPR_PCI_NUM_LSI; i++) {
+        qemu_irq qirq;
+        uint32_t num;
+
+        qirq = spapr_allocate_lsi(0, &num);
+        if (!qirq) {
+            return -1;
+        }
+
+        phb->lsi_table[i].dt_irq = num;
+        phb->lsi_table[i].qirq = qirq;
+    }
+
+    return 0;
+}
+
+static Property spapr_phb_properties[] = {
+    DEFINE_PROP_HEX64("buid", sPAPRPHBState, buid, 0),
+    DEFINE_PROP_STRING("busname", sPAPRPHBState, busname),
+    DEFINE_PROP_HEX64("mem_win_addr", sPAPRPHBState, mem_win_addr, 0),
+    DEFINE_PROP_HEX64("mem_win_size", sPAPRPHBState, mem_win_size, 0x20000000),
+    DEFINE_PROP_HEX64("io_win_addr", sPAPRPHBState, io_win_addr, 0),
+    DEFINE_PROP_HEX64("io_win_size", sPAPRPHBState, io_win_size, 0x10000),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_phb_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    sdc->init = spapr_phb_init;
+    dc->props = spapr_phb_properties;
 
     spapr_rtas_register("read-pci-config", rtas_read_pci_config);
     spapr_rtas_register("write-pci-config", rtas_write_pci_config);
     spapr_rtas_register("ibm,read-pci-config", rtas_ibm_read_pci_config);
     spapr_rtas_register("ibm,write-pci-config", rtas_ibm_write_pci_config);
+}
 
-    QLIST_INSERT_HEAD(&spapr->phbs, phb, list);
+static TypeInfo spapr_phb_info = {
+    .name          = "spapr-pci-host-bridge",
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(sPAPRPHBState),
+    .class_init    = spapr_phb_class_init,
+};
+
+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)
+{
+    DeviceState *dev;
+
+    dev = qdev_create(NULL, spapr_phb_info.name);
 
-    /* pci_bus_set_mem_base(bus, mem_va_start - SPAPR_PCI_MEM_BAR_START); */
+    if (busname) {
+        qdev_prop_set_string(dev, "busname", g_strdup(busname));
+    }
+    qdev_prop_set_uint64(dev, "buid", buid);
+    qdev_prop_set_uint64(dev, "mem_win_addr", mem_win_addr);
+    qdev_prop_set_uint64(dev, "mem_win_size", mem_win_size);
+    qdev_prop_set_uint64(dev, "io_win_addr", io_win_addr);
+
+    qdev_init_nofail(dev);
 }
 
 /* Macros to operate with address in OF binding to PCI */
@@ -415,3 +425,9 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,
 
     return 0;
 }
+
+static void register_types(void)
+{
+    type_register_static(&spapr_phb_info);
+}
+type_init(register_types)
hw/spapr_pci.h +3 -1
index 213340c..039f85b 100644
@@ -33,9 +33,11 @@ typedef struct sPAPRPHBState {
     PCIHostState host_state;
 
     uint64_t buid;
+    char *busname;
+    char *dtbusname;
 
     MemoryRegion memspace, iospace;
-    target_phys_addr_t mem_win_addr, io_win_addr;
+    target_phys_addr_t mem_win_addr, mem_win_size, io_win_addr, io_win_size;
     MemoryRegion memwindow, iowindow;
 
     struct {
Signature · 1 line
1.6.0.2
#16 lore raw

PATCH 16/16 PPC: Fix openpic with relative memregions

In reply to Alexander Graf

After commit 5312bd8b3152 we got memory region relative offsets into our mmio callbacks instead of page boundary based offsets.

This broke the OpenPIC emulation which expected offsets to be on page boundary and substracted its region offset manually.

This patch gets rid of that manual substraction and lets the memory api do its magic instead.

---
 hw/openpic.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)
hw/openpic.c +2 -10
index 280b7a9..58ef871 100644
@@ -713,7 +713,7 @@ static void openpic_timer_write (void *opaque, uint32_t addr, uint32_t val)
     DPRINTF("%s: addr %08x <= %08x\n", __func__, addr, val);
     if (addr & 0xF)
         return;
-    addr -= 0x1100;
+    addr -= 0x10;
     addr &= 0xFFFF;
     idx = (addr & 0xFFF0) >> 6;
     addr = addr & 0x30;
@@ -746,7 +746,7 @@ static uint32_t openpic_timer_read (void *opaque, uint32_t addr)
     retval = 0xFFFFFFFF;
     if (addr & 0xF)
         return retval;
-    addr -= 0x1100;
+    addr -= 0x10;
     addr &= 0xFFFF;
     idx = (addr & 0xFFF0) >> 6;
     addr = addr & 0x30;
@@ -1361,7 +1361,6 @@ static void mpic_src_ext_write (void *opaque, target_phys_addr_t addr,
     if (addr & 0xF)
         return;
 
-    addr -= MPIC_EXT_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_EXT_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1385,7 +1384,6 @@ static uint32_t mpic_src_ext_read (void *opaque, target_phys_addr_t addr)
     if (addr & 0xF)
         return retval;
 
-    addr -= MPIC_EXT_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_EXT_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1411,7 +1409,6 @@ static void mpic_src_int_write (void *opaque, target_phys_addr_t addr,
     if (addr & 0xF)
         return;
 
-    addr -= MPIC_INT_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_INT_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1435,7 +1432,6 @@ static uint32_t mpic_src_int_read (void *opaque, target_phys_addr_t addr)
     if (addr & 0xF)
         return retval;
 
-    addr -= MPIC_INT_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_INT_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1461,7 +1457,6 @@ static void mpic_src_msg_write (void *opaque, target_phys_addr_t addr,
     if (addr & 0xF)
         return;
 
-    addr -= MPIC_MSG_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_MSG_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1485,7 +1480,6 @@ static uint32_t mpic_src_msg_read (void *opaque, target_phys_addr_t addr)
     if (addr & 0xF)
         return retval;
 
-    addr -= MPIC_MSG_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_MSG_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1511,7 +1505,6 @@ static void mpic_src_msi_write (void *opaque, target_phys_addr_t addr,
     if (addr & 0xF)
         return;
 
-    addr -= MPIC_MSI_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_MSI_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
@@ -1534,7 +1527,6 @@ static uint32_t mpic_src_msi_read (void *opaque, target_phys_addr_t addr)
     if (addr & 0xF)
         return retval;
 
-    addr -= MPIC_MSI_REG_START & (OPENPIC_PAGE_SIZE - 1);
     if (addr < MPIC_MSI_REG_SIZE) {
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
Signature · 1 line
1.6.0.2
#17 lore raw
In reply to Alexander Graf
Quoted 3 lines · Alexander Graf

Hi Blue / Aurelien,

This is my current patch queue for ppc. Please pull.

Thanks, pulled.

Quoted 64 lines

Alex

The following changes since commit ae7d54d489540b49b7c13a7df7ddc220588a2ced:
 Andreas Färber (1):
       target-lm32/microblaze: Drop second CPU{LM32, MB}State typedef

are available in the git repository at:

 git://repo.or.cz/qemu/agraf.git ppc-for-upstream

Alex Barcelo (1):
     Bad zero comparison for sas_ss_flags on powerpc

Alexander Graf (3):
     PPC: 405: Fix ppc405ep initialization
     PPC: KVM: Synchronize regs on CPU dump
     PPC: Fix openpic with relative memregions

Alexey Kardashevskiy (1):
     pseries: Remove PCI device from PCI host bridge code

David Gibson (6):
     pseries: Don't try to munmap() a malloc()ed TCE table
     pseries: Update SLOF firmware image
     pseries: Remove unused constant from PCI code
     pseries: Add support for level interrupts to XICS
     kvm: Comparison with ioctl number macros needs to be unsigned
     pseries: Configure PCI bridge using properties

Meador Inge (1):
     ppc: Correctly define POWERPC_INSNS2_DEFAULT

Nathan Whitehorn (2):
     PPC: Add PIR register to POWER7 CPU
     PPC: Fix large page support in TCG

Stefan Weil (1):
     ppc: Add missing 'static' to spin_rw_ops

Thomas Huth (1):
     PPC64: Add support for ldbrx and stdbrx instructions

 hw/openpic.c                |   12 +--
 hw/ppc405_uc.c              |    2 +
 hw/ppce500_spin.c           |    2 +-
 hw/spapr.c                  |    5 +-
 hw/spapr.h                  |   13 +++-

 hw/spapr_pci.c              |  193 ++++++++++++++++++++-----------------------
 hw/spapr_pci.h              |    4 +-
 hw/spapr_vio.c              |    2 +-
 hw/xics.c                   |  125 +++++++++++++++++++++-------
 hw/xics.h                   |    8 ++-
 kvm-all.c                   |    5 +-

 linux-user/signal.c         |    2 +- pc-bios/README              |    2 +- pc-bios/slof.bin            |  Bin 869584 -> 880496 bytes roms/SLOF                   |    2 +- target-ppc/cpu.h            |    4 +- target-ppc/helper.c         |   12 ++-- target-ppc/kvm.c            |   12 ++- target-ppc/translate.c      |   54 ++++++++++-- target-ppc/translate_init.c |   11 ++-

 20 files changed, 294 insertions(+), 176 deletions(-)