[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/46] hw: gpio: implement gpio-pwr driver for qemu reset/poweroff
From: |
Peter Maydell |
Subject: |
[PULL 04/46] hw: gpio: implement gpio-pwr driver for qemu reset/poweroff |
Date: |
Fri, 29 Jan 2021 10:59:30 +0000 |
From: Maxim Uvarov <maxim.uvarov@linaro.org>
Implement gpio-pwr driver to allow reboot and poweroff machine.
This is simple driver with just 2 gpios lines. Current use case
is to reboot and poweroff virt machine in secure mode. Secure
pl066 gpio chip is needed for that.
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/gpio/gpio_pwr.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
hw/gpio/Kconfig | 3 ++
hw/gpio/meson.build | 1 +
3 files changed, 74 insertions(+)
create mode 100644 hw/gpio/gpio_pwr.c
diff --git a/hw/gpio/gpio_pwr.c b/hw/gpio/gpio_pwr.c
new file mode 100644
index 00000000000..7714fa0dc4d
--- /dev/null
+++ b/hw/gpio/gpio_pwr.c
@@ -0,0 +1,70 @@
+/*
+ * GPIO qemu power controller
+ *
+ * Copyright (c) 2020 Linaro Limited
+ *
+ * Author: Maxim Uvarov <maxim.uvarov@linaro.org>
+ *
+ * Virtual gpio driver which can be used on top of pl061
+ * to reboot and shutdown qemu virtual machine. One of use
+ * case is gpio driver for secure world application (ARM
+ * Trusted Firmware.).
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/*
+ * QEMU interface:
+ * two named input GPIO lines:
+ * 'reset' : when asserted, trigger system reset
+ * 'shutdown' : when asserted, trigger system shutdown
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "sysemu/runstate.h"
+
+#define TYPE_GPIOPWR "gpio-pwr"
+OBJECT_DECLARE_SIMPLE_TYPE(GPIO_PWR_State, GPIOPWR)
+
+struct GPIO_PWR_State {
+ SysBusDevice parent_obj;
+};
+
+static void gpio_pwr_reset(void *opaque, int n, int level)
+{
+ if (level) {
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
+ }
+}
+
+static void gpio_pwr_shutdown(void *opaque, int n, int level)
+{
+ if (level) {
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+ }
+}
+
+static void gpio_pwr_init(Object *obj)
+{
+ DeviceState *dev = DEVICE(obj);
+
+ qdev_init_gpio_in_named(dev, gpio_pwr_reset, "reset", 1);
+ qdev_init_gpio_in_named(dev, gpio_pwr_shutdown, "shutdown", 1);
+}
+
+static const TypeInfo gpio_pwr_info = {
+ .name = TYPE_GPIOPWR,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(GPIO_PWR_State),
+ .instance_init = gpio_pwr_init,
+};
+
+static void gpio_pwr_register_types(void)
+{
+ type_register_static(&gpio_pwr_info);
+}
+
+type_init(gpio_pwr_register_types)
diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig
index b6fdaa2586d..f0e7405f6e6 100644
--- a/hw/gpio/Kconfig
+++ b/hw/gpio/Kconfig
@@ -8,5 +8,8 @@ config PL061
config GPIO_KEY
bool
+config GPIO_PWR
+ bool
+
config SIFIVE_GPIO
bool
diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build
index 5c0a7d7b95a..79568f00ce3 100644
--- a/hw/gpio/meson.build
+++ b/hw/gpio/meson.build
@@ -1,5 +1,6 @@
softmmu_ss.add(when: 'CONFIG_E500', if_true: files('mpc8xxx.c'))
softmmu_ss.add(when: 'CONFIG_GPIO_KEY', if_true: files('gpio_key.c'))
+softmmu_ss.add(when: 'CONFIG_GPIO_PWR', if_true: files('gpio_pwr.c'))
softmmu_ss.add(when: 'CONFIG_MAX7310', if_true: files('max7310.c'))
softmmu_ss.add(when: 'CONFIG_PL061', if_true: files('pl061.c'))
softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c'))
--
2.20.1
- [PULL 00/46] target-arm queue, Peter Maydell, 2021/01/29
- [PULL 05/46] arm-virt: refactor gpios creation, Peter Maydell, 2021/01/29
- [PULL 01/46] target/arm: Implement ID_PFR2, Peter Maydell, 2021/01/29
- [PULL 03/46] arm: rename xlnx-zcu102.canbusN properties, Peter Maydell, 2021/01/29
- [PULL 06/46] arm-virt: add secure pl061 for reset/power down, Peter Maydell, 2021/01/29
- [PULL 02/46] target/arm: Conditionalize DBGDIDR, Peter Maydell, 2021/01/29
- [PULL 09/46] configure: Move preadv check to meson.build, Peter Maydell, 2021/01/29
- [PULL 11/46] osdep: build with non-working system() function, Peter Maydell, 2021/01/29
- [PULL 07/46] hw/misc: Fix arith overflow in NPCM7XX PWM module, Peter Maydell, 2021/01/29
- [PULL 08/46] target/arm: Replace magic value by MMU_DATA_LOAD definition, Peter Maydell, 2021/01/29
- [PULL 04/46] hw: gpio: implement gpio-pwr driver for qemu reset/poweroff,
Peter Maydell <=
- [PULL 13/46] darwin: fix cross-compiling for Darwin, Peter Maydell, 2021/01/29
- [PULL 10/46] configure: cross-compiling with empty cross_prefix, Peter Maydell, 2021/01/29
- [PULL 12/46] darwin: remove redundant dependency declaration, Peter Maydell, 2021/01/29
- [PULL 14/46] configure: cross compile should use x86_64 cpu_family, Peter Maydell, 2021/01/29
- [PULL 16/46] darwin: remove 64-bit build detection on 32-bit OS, Peter Maydell, 2021/01/29
- [PULL 19/46] hw/misc/pvpanic: add PCI interface support, Peter Maydell, 2021/01/29
- [PULL 18/46] hw/misc/pvpanic: split-out generic and bus dependent code, Peter Maydell, 2021/01/29
- [PULL 15/46] darwin: detect CoreAudio for build, Peter Maydell, 2021/01/29
- [PULL 17/46] hvf: Add hypervisor entitlement to output binaries, Peter Maydell, 2021/01/29
- [PULL 21/46] tests/qtest: add a test case for pvpanic-pci, Peter Maydell, 2021/01/29