Skip to content

Commit

Permalink
plat/qemu: trigger reboot with secure pl061
Browse files Browse the repository at this point in the history
Secure pl061 qemu driver allows to rize the GPIO pin
from the secure world to reboot and power down
virtual machine.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
  • Loading branch information
muvarov committed Dec 17, 2020
1 parent 00ad74c commit dd4401d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions plat/qemu/common/qemu_bl31_setup.c
Expand Up @@ -8,6 +8,7 @@

#include <common/bl_common.h>
#include <plat/common/platform.h>
#include <drivers/arm/pl061_gpio.h>

#include "qemu_private.h"

Expand Down Expand Up @@ -69,9 +70,16 @@ void bl31_plat_arch_setup(void)
BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
}

static void qemu_gpio_init(void)
{
pl061_gpio_init();
pl061_gpio_register(SECURE_GPIO_BASE, 0);
}

void bl31_platform_setup(void)
{
plat_qemu_gic_init();
qemu_gpio_init();
}

unsigned int plat_get_syscnt_freq2(void)
Expand Down
14 changes: 12 additions & 2 deletions plat/qemu/common/qemu_pm.c
Expand Up @@ -12,6 +12,7 @@
#include <lib/psci/psci.h>
#include <lib/semihosting.h>
#include <plat/common/platform.h>
#include <drivers/gpio.h>

#include "qemu_private.h"

Expand Down Expand Up @@ -201,16 +202,25 @@ void qemu_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
/*******************************************************************************
* Platform handlers to shutdown/reboot the system
******************************************************************************/
#define GPIO_POWEROFF 3
#define GPIO_REBOOT 4

static void __dead2 qemu_system_off(void)
{
semihosting_exit(ADP_STOPPED_APPLICATION_EXIT, 0);
ERROR("QEMU System Off: semihosting call unexpectedly returned.\n");
ERROR("QEMU System Power off: with gpio.\n");
gpio_set_direction(GPIO_POWEROFF, GPIO_DIR_OUT);
gpio_set_value(GPIO_POWEROFF, GPIO_LEVEL_HIGH);
gpio_set_value(GPIO_POWEROFF, GPIO_LEVEL_LOW);
panic();
}

static void __dead2 qemu_system_reset(void)
{
ERROR("QEMU System Reset: operation not handled.\n");
ERROR("QEMU System Reset: with gpio.\n");
gpio_set_direction(GPIO_REBOOT, GPIO_DIR_OUT);
gpio_set_value(GPIO_REBOOT, GPIO_LEVEL_HIGH);
gpio_set_value(GPIO_REBOOT, GPIO_LEVEL_LOW);
panic();
}

Expand Down
2 changes: 2 additions & 0 deletions plat/qemu/qemu/include/platform_def.h
Expand Up @@ -81,6 +81,8 @@
#define SEC_DRAM_BASE 0x0e100000
#define SEC_DRAM_SIZE 0x00f00000

#define SECURE_GPIO_BASE 0x09031000

/* Load pageable part of OP-TEE 2MB above secure DRAM base */
#define QEMU_OPTEE_PAGEABLE_LOAD_BASE (SEC_DRAM_BASE + 0x00200000)
#define QEMU_OPTEE_PAGEABLE_LOAD_SIZE 0x00400000
Expand Down
2 changes: 2 additions & 0 deletions plat/qemu/qemu/platform.mk
Expand Up @@ -163,6 +163,8 @@ BL31_SOURCES += lib/cpus/aarch64/aem_generic.S \
lib/semihosting/semihosting.c \
lib/semihosting/${ARCH}/semihosting_call.S \
plat/common/plat_psci_common.c \
drivers/arm/pl061/pl061_gpio.c \
drivers/gpio/gpio.c \
${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \
${PLAT_QEMU_COMMON_PATH}/topology.c \
${PLAT_QEMU_COMMON_PATH}/aarch64/plat_helpers.S \
Expand Down

0 comments on commit dd4401d

Please sign in to comment.