Skip to contentSkip to conversation

ppc: Automatically set vga framebuffer endianness based on guest

PATCH Applied David Gibson 4 participants 7 messages Feb 10, 2015 – Feb 20, 2015

lore
Share & tools
lore
#0 lore raw

cover ppc: Automatically set vga framebuffer endianness based on guest

This is a reworked version of BenH's patch to set VGA framebuffer endianess based on the endianness of the guest (as determined by the H_SET_MODE hypercall).

I've split the patch into two parts the first adding the object property to the VGA device allowing control of the endianness, and the second manipulating it from the pseries code.

David Gibson (2):
vga: Expose framebuffer byteorder as a QOM property
pseries: Switch VGA endian on H_SET_MODE

 hw/display/vga-pci.c   | 22 ++++++++++++++++++++++
 hw/ppc/spapr_hcall.c   |  2 ++
 hw/ppc/spapr_pci.c     | 28 ++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h |  1 +
 4 files changed, 53 insertions(+)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/2 vga: Expose framebuffer byteorder as a QOM property

The VGA device model now supports having the framebuffer in either endian, and can be switched between these by the guest via a register in the qext region.

However, in some cases (e.g. LE OS on the pseries machine) we have existing guest that don't know about the endian switch register, but other parts of the qemu code have better information to set a default endianness than the VGA code does of itself.

In order to allow them to set a correct default endianness in these cases, without breaking abstraction walls, this patch exposes the VGA framebuffer endianness via a writable QOM property.

prop fixup

---
 hw/display/vga-pci.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/display/vga-pci.c +22 -0
index 53739e4..8bd6ff7 100644
@@ -181,6 +181,20 @@ static void pci_vga_qext_write(void *ptr, hwaddr addr,
     }
 }
 
+static bool vga_get_big_endian_fb(Object *obj, Error **errp)
+{
+    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, PCI_DEVICE(obj));
+
+    return d->vga.big_endian_fb;
+}
+
+static void vga_set_big_endian_fb(Object *obj, bool value, Error **errp)
+{
+    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, PCI_DEVICE(obj));
+
+    d->vga.big_endian_fb = value;
+}
+
 static const MemoryRegionOps pci_vga_qext_ops = {
     .read = pci_vga_qext_read,
     .write = pci_vga_qext_write,
@@ -233,6 +247,10 @@ static int pci_std_vga_initfn(PCIDevice *dev)
         vga_init_vbe(s, OBJECT(dev), pci_address_space(dev));
     }
 
+    /* Expose framebuffer byteorder via QOM */
+    object_property_add_bool(OBJECT(dev), "big-endian-framebuffer",
+                             vga_get_big_endian_fb, vga_set_big_endian_fb, NULL);
+
     return 0;
 }
 
@@ -268,6 +286,10 @@ static int pci_secondary_vga_initfn(PCIDevice *dev)
     pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
     pci_register_bar(&d->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio);
 
+    /* Expose framebuffer byteorder via QOM */
+    object_property_add_bool(OBJECT(dev), "big-endian-framebuffer",
+                             vga_get_big_endian_fb, vga_set_big_endian_fb, NULL);
+
     return 0;
 }
 
Signature · 1 line
2.1.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] vga: Expose framebuffer byteorder as a QOM property

Quoted 9 lines · David Gibson

The VGA device model now supports having the framebuffer in either endian, and can be switched between these by the guest via a register in the qext region.

However, in some cases (e.g. LE OS on the pseries machine) we have existing guest that don't know about the endian switch register, but other parts of the qemu code have better information to set a default endianness than the VGA code does of itself.

Quoted 7 lines

In order to allow them to set a correct default endianness in these cases, without breaking abstraction walls, this patch exposes the VGA framebuffer endianness via a writable QOM property.

prop fixup

squash leftover?

Otherwise:

(assuming this little series gets in via ppc tree).

cheers,
Gerd

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] vga: Expose framebuffer byteorder as a QOM property

Quoted 14 lines · Gerd Hoffmann
Quoted 13 lines · David Gibson

The VGA device model now supports having the framebuffer in either endian, and can be switched between these by the guest via a register in the qext region.

However, in some cases (e.g. LE OS on the pseries machine) we have existing guest that don't know about the endian switch register, but other parts of the qemu code have better information to set a default endianness than the VGA code does of itself.

In order to allow them to set a correct default endianness in these cases, without breaking abstraction walls, this patch exposes the VGA framebuffer endianness via a writable QOM property.

Quoted 5 lines
Quoted 3 lines

prop fixup

squash leftover?

Oops, yes.

Quoted 10 lines

Otherwise:

(assuming this little series gets in via ppc tree).

cheers,
Gerd

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw

PATCH 2/2 pseries: Switch VGA endian on H_SET_MODE

In reply to David Gibson

When the guest switches the interrupt endian mode, which essentially means a global machine endian switch, we want to change the VGA framebuffer endian mode as well in order to be backward compatible with existing guests who don't know about the new endian control register.

---
 hw/ppc/spapr_hcall.c   |  2 ++
 hw/ppc/spapr_pci.c     | 28 ++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h |  1 +
 3 files changed, 31 insertions(+)
hw/ppc/spapr_hcall.c +2 -0
index 8651447..4f76f1c 100644
@@ -731,12 +731,14 @@ static target_ulong h_set_mode_resource_le(PowerPCCPU *cpu,
         CPU_FOREACH(cs) {
             set_spr(cs, SPR_LPCR, 0, LPCR_ILE);
         }
+        spapr_pci_switch_vga(true);
         return H_SUCCESS;
 
     case H_SET_MODE_ENDIAN_LITTLE:
         CPU_FOREACH(cs) {
             set_spr(cs, SPR_LPCR, LPCR_ILE, LPCR_ILE);
         }
+        spapr_pci_switch_vga(false);
         return H_SUCCESS;
     }
 
hw/ppc/spapr_pci.c +28 -0
index 21b95b3..acf9e82 100644
@@ -966,3 +966,31 @@ static void spapr_pci_register_types(void)
 }
 
 type_init(spapr_pci_register_types)
+
+static int spapr_switch_one_vga(DeviceState *dev, void *opaque)
+{
+    bool be = *(bool *)opaque;
+
+    if (object_dynamic_cast(OBJECT(dev), "VGA")
+        || object_dynamic_cast(OBJECT(dev), "secondary-vga")) {
+        object_property_set_bool(OBJECT(dev), be, "big-endian-framebuffer",
+                                 &error_abort);
+    }
+    return 0;
+}
+
+void spapr_pci_switch_vga(bool big_endian)
+{
+    sPAPRPHBState *sphb;
+
+    /*
+     * For backward compatibility with existing guests, we switch
+     * the endianness of the VGA controller when changing the guest
+     * interrupt mode
+     */
+    QLIST_FOREACH(sphb, &spapr->phbs, list) {
+        BusState *bus = &PCI_HOST_BRIDGE(sphb)->bus->qbus;
+        qbus_walk_children(bus, spapr_switch_one_vga, NULL, NULL, NULL,
+                           &big_endian);
+    }
+}
include/hw/ppc/spapr.h +1 -0
index 716bff4..6aadc94 100644
@@ -480,5 +480,6 @@ int spapr_dma_dt(void *fdt, int node_off, const char *propname,
                  uint32_t liobn, uint64_t window, uint32_t size);
 int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
                       sPAPRTCETable *tcet);
+void spapr_pci_switch_vga(bool big_endian);
 
 #endif /* !defined (__HW_SPAPR_H__) */
Signature · 1 line
2.1.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] pseries: Switch VGA endian on H_SET_MODE

Quoting David Gibson (2015-02-09 22:36:16)

Quoted 8 lines

When the guest switches the interrupt endian mode, which essentially means a global machine endian switch, we want to change the VGA framebuffer endian mode as well in order to be backward compatible with existing guests who don't know about the new endian control register.

I think maybe Gerd's review applied to the whole series, but:

Quoted 74 lines
---
 hw/ppc/spapr_hcall.c   |  2 ++
 hw/ppc/spapr_pci.c     | 28 ++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h |  1 +
 3 files changed, 31 insertions(+)
hw/ppc/spapr_hcall.c +2 -0
index 8651447..4f76f1c 100644
@@ -731,12 +731,14 @@ static target_ulong h_set_mode_resource_le(PowerPCCPU *cpu,
         CPU_FOREACH(cs) {
             set_spr(cs, SPR_LPCR, 0, LPCR_ILE);
         }
+        spapr_pci_switch_vga(true);
         return H_SUCCESS;
 
     case H_SET_MODE_ENDIAN_LITTLE:
         CPU_FOREACH(cs) {
             set_spr(cs, SPR_LPCR, LPCR_ILE, LPCR_ILE);
         }
+        spapr_pci_switch_vga(false);
         return H_SUCCESS;
     }
 
hw/ppc/spapr_pci.c +28 -0
index 21b95b3..acf9e82 100644
@@ -966,3 +966,31 @@ static void spapr_pci_register_types(void)
 }
 
 type_init(spapr_pci_register_types)
+
+static int spapr_switch_one_vga(DeviceState *dev, void *opaque)
+{
+    bool be = *(bool *)opaque;
+
+    if (object_dynamic_cast(OBJECT(dev), "VGA")
+        || object_dynamic_cast(OBJECT(dev), "secondary-vga")) {
+        object_property_set_bool(OBJECT(dev), be, "big-endian-framebuffer",
+                                 &error_abort);
+    }
+    return 0;
+}
+
+void spapr_pci_switch_vga(bool big_endian)
+{
+    sPAPRPHBState *sphb;
+
+    /*
+     * For backward compatibility with existing guests, we switch
+     * the endianness of the VGA controller when changing the guest
+     * interrupt mode
+     */
+    QLIST_FOREACH(sphb, &spapr->phbs, list) {
+        BusState *bus = &PCI_HOST_BRIDGE(sphb)->bus->qbus;
+        qbus_walk_children(bus, spapr_switch_one_vga, NULL, NULL, NULL,
+                           &big_endian);
+    }
+}
include/hw/ppc/spapr.h +1 -0
index 716bff4..6aadc94 100644
@@ -480,5 +480,6 @@ int spapr_dma_dt(void *fdt, int node_off, const char *propname,
                  uint32_t liobn, uint64_t window, uint32_t size);
 int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
                       sPAPRTCETable *tcet);
+void spapr_pci_switch_vga(bool big_endian);
 
 #endif /* !defined (__HW_SPAPR_H__) */
Signature · 1 line
2.1.0
#6 lore raw
In reply to David Gibson
Quoted 11 lines · David Gibson

This is a reworked version of BenH's patch to set VGA framebuffer endianess based on the endianness of the guest (as determined by the H_SET_MODE hypercall).

I've split the patch into two parts the first adding the object property to the VGA device allowing control of the endianness, and the second manipulating it from the pseries code.

David Gibson (2):
vga: Expose framebuffer byteorder as a QOM property
pseries: Switch VGA endian on H_SET_MODE

Thanks, applied all to ppc-next.

Alex