1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include "hw/sysbus.h"
27#include "sysemu/runstate.h"
28
29#define TYPE_GPIOPWR "gpio-pwr"
30OBJECT_DECLARE_SIMPLE_TYPE(GPIO_PWR_State, GPIOPWR)
31
32struct GPIO_PWR_State {
33 SysBusDevice parent_obj;
34};
35
36static void gpio_pwr_reset(void *opaque, int n, int level)
37{
38 if (level) {
39 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
40 }
41}
42
43static void gpio_pwr_shutdown(void *opaque, int n, int level)
44{
45 if (level) {
46 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
47 }
48}
49
50static void gpio_pwr_init(Object *obj)
51{
52 DeviceState *dev = DEVICE(obj);
53
54 qdev_init_gpio_in_named(dev, gpio_pwr_reset, "reset", 1);
55 qdev_init_gpio_in_named(dev, gpio_pwr_shutdown, "shutdown", 1);
56}
57
58static const TypeInfo gpio_pwr_info = {
59 .name = TYPE_GPIOPWR,
60 .parent = TYPE_SYS_BUS_DEVICE,
61 .instance_size = sizeof(GPIO_PWR_State),
62 .instance_init = gpio_pwr_init,
63};
64
65static void gpio_pwr_register_types(void)
66{
67 type_register_static(&gpio_pwr_info);
68}
69
70type_init(gpio_pwr_register_types)
71