2 * SPDX-License-Identifer: GPL-2.0-or-later
4 * Virt system Controller
7 #include "qemu/osdep.h"
9 #include "hw/qdev-properties.h"
10 #include "hw/sysbus.h"
11 #include "migration/vmstate.h"
14 #include "sysemu/runstate.h"
15 #include "hw/misc/virt_ctrl.h"
22 #define FEAT_POWER_CTRL 0x00000001
31 static uint64_t virt_ctrl_read(void *opaque
, hwaddr addr
, unsigned size
)
33 VirtCtrlState
*s
= opaque
;
38 value
= FEAT_POWER_CTRL
;
41 qemu_log_mask(LOG_UNIMP
,
42 "%s: unimplemented register read 0x%02"HWADDR_PRIx
"\n",
47 trace_virt_ctrl_write(s
, addr
, size
, value
);
52 static void virt_ctrl_write(void *opaque
, hwaddr addr
, uint64_t value
,
55 VirtCtrlState
*s
= opaque
;
57 trace_virt_ctrl_write(s
, addr
, size
, value
);
65 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
68 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
71 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
76 qemu_log_mask(LOG_UNIMP
,
77 "%s: unimplemented register write 0x%02"HWADDR_PRIx
"\n",
83 static const MemoryRegionOps virt_ctrl_ops
= {
84 .read
= virt_ctrl_read
,
85 .write
= virt_ctrl_write
,
86 .endianness
= DEVICE_NATIVE_ENDIAN
,
87 .valid
.max_access_size
= 4,
88 .impl
.max_access_size
= 4,
91 static void virt_ctrl_reset(DeviceState
*dev
)
93 VirtCtrlState
*s
= VIRT_CTRL(dev
);
95 trace_virt_ctrl_reset(s
);
98 static void virt_ctrl_realize(DeviceState
*dev
, Error
**errp
)
100 VirtCtrlState
*s
= VIRT_CTRL(dev
);
102 trace_virt_ctrl_instance_init(s
);
104 memory_region_init_io(&s
->iomem
, OBJECT(s
), &virt_ctrl_ops
, s
,
108 static const VMStateDescription vmstate_virt_ctrl
= {
111 .minimum_version_id
= 1,
112 .fields
= (VMStateField
[]) {
113 VMSTATE_UINT32(irq_enabled
, VirtCtrlState
),
114 VMSTATE_END_OF_LIST()
118 static void virt_ctrl_instance_init(Object
*obj
)
120 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
121 VirtCtrlState
*s
= VIRT_CTRL(obj
);
123 trace_virt_ctrl_instance_init(s
);
125 sysbus_init_mmio(dev
, &s
->iomem
);
126 sysbus_init_irq(dev
, &s
->irq
);
129 static void virt_ctrl_class_init(ObjectClass
*oc
, void *data
)
131 DeviceClass
*dc
= DEVICE_CLASS(oc
);
133 dc
->reset
= virt_ctrl_reset
;
134 dc
->realize
= virt_ctrl_realize
;
135 dc
->vmsd
= &vmstate_virt_ctrl
;
138 static const TypeInfo virt_ctrl_info
= {
139 .name
= TYPE_VIRT_CTRL
,
140 .parent
= TYPE_SYS_BUS_DEVICE
,
141 .class_init
= virt_ctrl_class_init
,
142 .instance_init
= virt_ctrl_instance_init
,
143 .instance_size
= sizeof(VirtCtrlState
),
146 static void virt_ctrl_register_types(void)
148 type_register_static(&virt_ctrl_info
);
151 type_init(virt_ctrl_register_types
)