diff mbox

PPC: E500: Implement reboot controller

Message ID 1307015870-22191-1-git-send-email-agraf@suse.de
State New
Headers show

Commit Message

Alexander Graf June 2, 2011, 11:57 a.m. UTC
When Linux reboots an e500 VM, it writes to a magic register in the
"global-utilities" device indicated by the device tree. We were not
emulating that device so far, renedering the VM reboot-less.

This patch implements that device with only the reboot functionality
implemented and adds it to the device tree. With this patch applied,
I can successfully reboot a -M mpc8544ds VM.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 Makefile.target        |    2 +-
 hw/ppce500_mpc8544ds.c |    4 ++
 hw/ppce500_util.c      |   94 ++++++++++++++++++++++++++++++++++++++++++++++++
 pc-bios/mpc8544ds.dtb  |  Bin 12288 -> 2257 bytes
 pc-bios/mpc8544ds.dts  |    6 +++
 5 files changed, 105 insertions(+), 1 deletions(-)
 create mode 100644 hw/ppce500_util.c

Comments

Alexander Graf June 3, 2011, 5:35 p.m. UTC | #1
On 03.06.2011, at 19:00, Scott Wood wrote:

> On Thu, 2 Jun 2011 13:57:50 +0200
> Alexander Graf <agraf@suse.de> wrote:
> 
>> diff --git a/pc-bios/mpc8544ds.dts b/pc-bios/mpc8544ds.dts
>> index 872152d..9b95bfd 100644
>> --- a/pc-bios/mpc8544ds.dts
>> +++ b/pc-bios/mpc8544ds.dts
>> @@ -82,6 +82,12 @@
>> 			compatible = "chrp,open-pic";
>> 			device_type = "open-pic";
>> 		};
>> +
>> +                global-utilities@e0000 {        //global utilities block
>> +                        compatible = "fsl,mpc8548-guts";
>> +                        reg = <0xe0000 0x1000>;
>> +                        fsl,has-rstcr;
>> +                };
>> 	};
> 
> We're not providing a full mpc8548 (or mpc8544) guts, only the rstcr
> register.
> 
> Currently Linux looks for a node with the name "global-utilities" and a
> property "fsl,has-rstcr", so there's no compatibility reason for a
> misleading compatible, either.
> 
> I'd go with compatible = "fsl,guts-rstcr" (what we've been using
> internally, and would be a nicer thing to bind against than what the
> kernel currently does).  Or if the goal is to provide more guts registers
> later, use "fsl,mpc8544-guts" and have qemu log a warning if other accesses
> are made.

Ugh - 8544 is the SoC we're emulating - sorry, it's evening already :). So yes, implementing an mpc8544-guts is certainly what we want!


Alex
diff mbox

Patch

diff --git a/Makefile.target b/Makefile.target
index 602d50d..3c99bf8 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -258,7 +258,7 @@  endif
 obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
 obj-ppc-y += ppc440.o ppc440_bamboo.o
 # PowerPC E500 boards
-obj-ppc-y += ppce500_mpc8544ds.o
+obj-ppc-y += ppce500_mpc8544ds.o ppce500_util.o
 # PowerPC 440 Xilinx ML507 reference board.
 obj-ppc-y += virtex_ml507.o
 obj-ppc-$(CONFIG_KVM) += kvm_ppc.o
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index 6b57fbf..8bcce15 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -50,6 +50,7 @@ 
 #define MPC8544_PCI_REGS_SIZE      0x1000
 #define MPC8544_PCI_IO             0xE1000000
 #define MPC8544_PCI_IOLEN          0x10000
+#define MPC8544_UTIL_BASE          (MPC8544_CCSRBAR_BASE + 0xe0000)
 
 struct boot_info
 {
@@ -270,6 +271,9 @@  static void mpc8544ds_init(ram_addr_t ram_size,
                        serial_hds[0], 1, 1);
     }
 
+    /* General Utility device */
+    sysbus_create_simple("e500-util", MPC8544_UTIL_BASE, NULL);
+
     /* PCI */
     dev = sysbus_create_varargs("e500-pcihost", MPC8544_PCI_REGS_BASE,
                                 mpic[pci_irq_nrs[0]], mpic[pci_irq_nrs[1]],
diff --git a/hw/ppce500_util.c b/hw/ppce500_util.c
new file mode 100644
index 0000000..4440c21
--- /dev/null
+++ b/hw/ppce500_util.c
@@ -0,0 +1,94 @@ 
+/*
+ * QEMU PowerPC E500 global util pseudo-device
+ *
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Alexander Graf, <alex@csgraf.de>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of  the GNU General  Public License as published by
+ * the Free Software Foundation;  either version 2 of the  License, or
+ * (at your option) any later version.
+ */
+
+#include "hw.h"
+#include "sysemu.h"
+#include "sysbus.h"
+
+#define E500_UTIL_MMIO_SIZE        0x1000
+#define E500_UTIL_ADDR_RSTCR       0xb0
+#define E500_UTIL_RSTCR_RESET      0x02
+
+struct PPCE500UtilState {
+    SysBusDevice busdev;
+    int mmio_map;
+};
+
+typedef struct PPCE500UtilState PPCE500UtilState;
+
+static uint32_t e500_util_read32(void *opaque, target_phys_addr_t addr)
+{
+    uint32_t value = 0;
+
+    addr &= 0xfff;
+    switch (addr) {
+    default:
+        break;
+    }
+
+    return value;
+}
+
+static CPUReadMemoryFunc * const e500_util_read[] = {
+    NULL,
+    NULL,
+    &e500_util_read32,
+};
+
+static void e500_util_write32(void *opaque, target_phys_addr_t addr,
+                              uint32_t value)
+{
+    addr &= 0xfff;
+
+    switch (addr) {
+    case E500_UTIL_ADDR_RSTCR:
+        if (value & E500_UTIL_RSTCR_RESET) {
+            qemu_system_reset_request();
+        }
+        break;
+    default:
+        break;
+    }
+}
+
+static CPUWriteMemoryFunc * const e500_util_write[] = {
+    NULL,
+    NULL,
+    &e500_util_write32,
+};
+
+static int e500_util_initfn(SysBusDevice *dev)
+{
+    PPCE500UtilState *s;
+    int iomem;
+
+    s = FROM_SYSBUS(PPCE500UtilState, sysbus_from_qdev(dev));
+
+    iomem = cpu_register_io_memory(e500_util_read, e500_util_write, s,
+                                   DEVICE_BIG_ENDIAN);
+    sysbus_init_mmio(dev, E500_UTIL_MMIO_SIZE, iomem);
+
+    return 0;
+}
+
+static SysBusDeviceInfo e500_util_info = {
+    .init         = e500_util_initfn,
+    .qdev.name    = "e500-util",
+    .qdev.size    = sizeof(PPCE500UtilState),
+};
+
+static void e500_pci_register(void)
+{
+    sysbus_register_withprop(&e500_util_info);
+}
+device_init(e500_pci_register);
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6V|z_)KBDDz&Xw|p<Gv~*Br-+
zd3YvT=W=F7%A>ZPvoXU;JqM=H)9PC?E8)1UpUd%nwtg<h`&rCfuC`yr3*SxD;yL2}
z-X=v48*?_uhWsH#tWA0h0OZ&z>?SFOXZglP8AL7SI9mACdrzzN&0PY5^G&jOf8cTV
zkb|1LHc^LUE|D6X;}4Tu$8ZgX{ui9hv%mG#{{r@aE=I{fhssZ))GLCWP^)EcFvxVC
zyS@&?TrKCpOKt7)ThUhKx~k}2wbejB4}85{9Hd%hdQS~p-}8ss4TD&_C|1FV2xI2b
z#wmhG@6aEeyPN4}BOUt(iav)ko*yRu{*0e_@gDsxVpunb2YRf6xX@WPN{f7Ix~Z4x
zxR?p}NnB(}80t(dR~7c0H2P@VN{3!NAVQ|u$V=VG%lGF)W<WEBDhu;skc<l2vKZpA
zhzJA1fG{8o2m``^Fdz&F1HynXAPfit!hkR!3<v|lfG{8o2m``^Fdz&F1HynXAPfit
W!hkR!3<v|lfG{8o2m}8&1AhU`J`#BV

diff --git a/pc-bios/mpc8544ds.dts b/pc-bios/mpc8544ds.dts
index 872152d..9b95bfd 100644
--- a/pc-bios/mpc8544ds.dts
+++ b/pc-bios/mpc8544ds.dts
@@ -82,6 +82,12 @@ 
 			compatible = "chrp,open-pic";
 			device_type = "open-pic";
 		};
+
+                global-utilities@e0000 {        //global utilities block
+                        compatible = "fsl,mpc8548-guts";
+                        reg = <0xe0000 0x1000>;
+                        fsl,has-rstcr;
+                };
 	};
 
 	pci0: pci@e0008000 {