diff mbox

[RFC,14/14] ppc/spapr/vga: Switch VGA endian on H_SET_MODE

Message ID 1403565068-15229-15-git-send-email-benh@kernel.crashing.org
State New
Headers show

Commit Message

Benjamin Herrenschmidt June 23, 2014, 11:11 p.m. UTC
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.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 hw/display/vga-pci.c   |  8 ++++++++
 hw/ppc/spapr_hcall.c   |  2 ++
 hw/ppc/spapr_pci.c     | 26 ++++++++++++++++++++++++++
 include/hw/pci/pci.h   |  1 +
 include/hw/ppc/spapr.h |  1 +
 5 files changed, 38 insertions(+)

Comments

Gerd Hoffmann June 30, 2014, 11:49 a.m. UTC | #1
On Di, 2014-06-24 at 09:11 +1000, Benjamin Herrenschmidt wrote:
> 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'd tend to add a notifier (see include/qemu/notify.h) for endian
switches instead, so anybody interested could register himself.

cheers,
  Gerd
Benjamin Herrenschmidt June 30, 2014, 12:34 p.m. UTC | #2
On Mon, 2014-06-30 at 13:49 +0200, Gerd Hoffmann wrote:
> On Di, 2014-06-24 at 09:11 +1000, Benjamin Herrenschmidt wrote:
> > 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'd tend to add a notifier (see include/qemu/notify.h) for endian
> switches instead, so anybody interested could register himself.

Ok thanks, I'll have a look.

Cheers,
Ben.
diff mbox

Patch

diff --git a/hw/display/vga-pci.c b/hw/display/vga-pci.c
index 0351d94..e2abc8c 100644
--- a/hw/display/vga-pci.c
+++ b/hw/display/vga-pci.c
@@ -212,6 +212,14 @@  static void pci_secondary_vga_reset(DeviceState *dev)
     vga_common_reset(&d->vga);
 }
 
+void pci_vga_switch_fb_endian(DeviceState *dev, bool big_endian)
+{
+    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev.qdev, dev);
+    VGACommonState *s = &d->vga;
+
+    s->big_endian_fb = big_endian;
+}
+
 static Property vga_pci_properties[] = {
     DEFINE_PROP_UINT32("vgamem_mb", PCIVGAState, vga.vram_size_mb, 16),
     DEFINE_PROP_BIT("mmio", PCIVGAState, flags, PCI_VGA_FLAG_ENABLE_MMIO, true),
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 7952077..e52f22d 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -731,12 +731,14 @@  static target_ulong h_set_mode_resouce_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;
     }
 
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 988f8cb..99ae3cd 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -926,3 +926,29 @@  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 (!strcmp(object_get_typename(OBJECT(dev)), "VGA")) {
+        pci_vga_switch_fb_endian(dev, be);
+    }
+    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);
+    }
+}
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 8c25ae5..bea4aff 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -373,6 +373,7 @@  PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
                                const char *default_devaddr);
 
 PCIDevice *pci_vga_init(PCIBus *bus);
+void pci_vga_switch_fb_endian(DeviceState *dev, bool big_endian);
 
 int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num,
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 08c301f..e3e7aff 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -425,5 +425,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__) */