Skip to contentSkip to conversation

aspeed: Guest to exit on shutdown

PATCH In review Joel Stanley 2 participants 5 messages Nov 13, 2018 Arm/Aspeed machine support

lore
Share & tools
lore

Joel Stanley

author maintainer
#0 lore raw

cover aspeed: Guest to exit on shutdown

With this change to qemu and CONFIG_POWER_RESET_SYSCON_POWEROFF=y enabled in the kernel, the guest will cause qemu to exit when performing a shutdown. This is useful for detecting the end of a successful CI job.

This is only relevant when passing the device tree to Qemu with the -dtb option.

It only supports the ast2500 so far.

Joel Stanley (2):
aspeed: Add syscon-poweroff to system
aspeed/scu: Implement power off command

 hw/arm/aspeed.c      | 35 +++++++++++++++++++++++++++++++++++
 hw/misc/aspeed_scu.c |  5 +++++
 2 files changed, 40 insertions(+)
Signature · 1 line
2.19.1
author maintainer
#1 lore raw

PATCH 1/2 aspeed: Add syscon-poweroff to system

---
 hw/arm/aspeed.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
hw/arm/aspeed.c +35 -0
index e7b87e355f12..66d6e9ed4551 100644
@@ -21,8 +21,10 @@
 #include "hw/i2c/smbus.h"
 #include "qemu/log.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/device_tree.h"
 #include "hw/loader.h"
 #include "qemu/error-report.h"
+#include <libfdt.h>
 
 static struct arm_boot_info aspeed_board_binfo = {
     .board_id = -1, /* device-tree-only board */
@@ -126,6 +128,38 @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
     g_free(storage);
 }
 
+static void fdt_add_shutdown_node(void *fdt)
+{
+    /* TODO: Support 2400 */
+    const char *scu = "aspeed,ast2500-scu";
+    const char *nodename = "/syscon-poweroff";
+    uint32_t phandle;
+    int offset;
+
+    /* Find the scu phandle */
+    offset = fdt_node_offset_by_compatible(fdt, -1, scu);
+    if (offset < 0) {
+        error_report("%s couldn't find %s, guest shutdown unavailable: %s",
+                     __func__, scu, fdt_strerror(offset));
+        return;
+    }
+    phandle = fdt_get_phandle(fdt, offset);
+
+    /* Add syscon-poweroff node and use 0x1A0, an un-used SCU register */
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-poweroff");
+    qemu_fdt_setprop_cells(fdt, nodename, "regmap", phandle);
+    qemu_fdt_setprop_cells(fdt, nodename, "offset", 0x1A0);
+    qemu_fdt_setprop_cells(fdt, nodename, "value", 1);
+}
+
+static void aspeed_board_modify_dtb(const struct arm_boot_info *binfo,
+                                    void *fdt)
+{
+    fdt_add_shutdown_node(fdt);
+}
+
+
 static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
                                       Error **errp)
 {
@@ -235,6 +269,7 @@ static void aspeed_board_init(MachineState *machine,
     aspeed_board_binfo.kernel_cmdline = machine->kernel_cmdline;
     aspeed_board_binfo.ram_size = ram_size;
     aspeed_board_binfo.loader_start = sc->info->sdram_base;
+    aspeed_board_binfo.modify_dtb = aspeed_board_modify_dtb;
 
     if (cfg->i2c_init) {
         cfg->i2c_init(bmc);
Signature · 1 line
2.19.1
#2 lore raw

Re: [PATCH qemu aspeed-3.1 1/2] aspeed: Add syscon-poweroff to system

Quoted 21 lines · Joel Stanley
---
 hw/arm/aspeed.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
hw/arm/aspeed.c +2 -0
index e7b87e355f12..66d6e9ed4551 100644
@@ -21,8 +21,10 @@
 #include "hw/i2c/smbus.h"
 #include "qemu/log.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/device_tree.h"
 #include "hw/loader.h"
 #include "qemu/error-report.h"
+#include <libfdt.h>
 
 static struct arm_boot_info aspeed_board_binfo = {
     .board_id = -1, /* device-tree-only board */

hw/arm/aspeed.c static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size, · line 133

Quoted 6 lines
hw/arm/aspeed.c +3 -0
@@ -126,6 +128,38 @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
     g_free(storage);
 }
 
+static void fdt_add_shutdown_node(void *fdt)
+{
+    /* TODO: Support 2400 */

You could add a 'const char* property' parameter to fdt_add_shutdown_node() and use a AspeedBoardConfig.modify_dtb() method to call it.

Quoted 41 lines
hw/arm/aspeed.c +30 -0
+    const char *scu = "aspeed,ast2500-scu";
+    const char *nodename = "/syscon-poweroff";
+    uint32_t phandle;
+    int offset;
+
+    /* Find the scu phandle */
+    offset = fdt_node_offset_by_compatible(fdt, -1, scu);
+    if (offset < 0) {
+        error_report("%s couldn't find %s, guest shutdown unavailable: %s",
+                     __func__, scu, fdt_strerror(offset));
+        return;
+    }
+    phandle = fdt_get_phandle(fdt, offset);
+
+    /* Add syscon-poweroff node and use 0x1A0, an un-used SCU register */
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-poweroff");
+    qemu_fdt_setprop_cells(fdt, nodename, "regmap", phandle);
+    qemu_fdt_setprop_cells(fdt, nodename, "offset", 0x1A0);
+    qemu_fdt_setprop_cells(fdt, nodename, "value", 1);
+}
+
+static void aspeed_board_modify_dtb(const struct arm_boot_info *binfo,
+                                    void *fdt)
+{
+    fdt_add_shutdown_node(fdt);
+}
+
+
 static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
                                       Error **errp)
 {
@@ -235,6 +269,7 @@ static void aspeed_board_init(MachineState *machine,
     aspeed_board_binfo.kernel_cmdline = machine->kernel_cmdline;
     aspeed_board_binfo.ram_size = ram_size;
     aspeed_board_binfo.loader_start = sc->info->sdram_base;
+    aspeed_board_binfo.modify_dtb = aspeed_board_modify_dtb;
 
     if (cfg->i2c_init) {
         cfg->i2c_init(bmc);
author maintainer
#3 lore raw

PATCH 2/2 aspeed/scu: Implement power off command

In reply to Joel Stanley
---
 hw/misc/aspeed_scu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/misc/aspeed_scu.c +5 -0
index 51498ce70be6..257f9a6c6b8a 100644
@@ -16,6 +16,7 @@
 #include "qapi/visitor.h"
 #include "qemu/bitops.h"
 #include "qemu/log.h"
+#include "sysemu/sysemu.h"
 #include "crypto/random.h"
 #include "trace.h"
 
@@ -84,6 +85,7 @@
 #define SRAM_DECODE_BASE1    TO_REG(0x194)
 #define SRAM_DECODE_BASE2    TO_REG(0x198)
 #define BMC_REV              TO_REG(0x19C)
+#define POWEROFF             TO_REG(0x1A0)
 #define BMC_DEV_ID           TO_REG(0x1A4)
 
 #define SCU_IO_REGION_SIZE 0x1000
@@ -263,6 +265,9 @@ static void aspeed_scu_write(void *opaque, hwaddr offset, uint64_t data,
         }
         /* Avoid assignment below, we've handled everything */
         return;
+    case POWEROFF:
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+        break;
     case FREQ_CNTR_EVAL:
     case VGA_SCRATCH1 ... VGA_SCRATCH8:
     case RNG_DATA:
Signature · 1 line
2.19.1
#4 lore raw
In reply to Joel Stanley
Quoted 3 lines · Joel Stanley

With this change to qemu and CONFIG_POWER_RESET_SYSCON_POWEROFF=y enabled in the kernel, the guest will cause qemu to exit when performing a shutdown. This is useful for detecting the end of a successful CI job.

Excellent !

Quoted 2 lines

This is only relevant when passing the device tree to Qemu with the -dtb option.

Can't we find a way to inform Linux that it's running on a "virtual" QEMU Aspeed machine ?

Quoted 1 line

It only supports the ast2500 so far.

I pushed the patches in aspeed-3.1

Thanks,

C.

Quoted 9 lines

Joel Stanley (2):
aspeed: Add syscon-poweroff to system
aspeed/scu: Implement power off command

 hw/arm/aspeed.c      | 35 +++++++++++++++++++++++++++++++++++
 hw/misc/aspeed_scu.c |  5 +++++
 2 files changed, 40 insertions(+)