2 * SPDX-License-Identifer: GPL-2.0-or-later
4 * Virt system Controller
7 #include "qemu/osdep.h"
8 #include "hw/qdev-properties.h"
10 #include "migration/vmstate.h"
13 #include "sysemu/runstate.h"
14 #include "hw/misc/virt_ctrl.h"
21 #define FEAT_POWER_CTRL 0x00000001
30 static uint64_t virt_ctrl_read(void *opaque
, hwaddr addr
, unsigned size
)
32 VirtCtrlState
*s
= opaque
;
37 value
= FEAT_POWER_CTRL
;
40 qemu_log_mask(LOG_UNIMP
,
41 "%s: unimplemented register read 0x%02"HWADDR_PRIx
"\n",
46 trace_virt_ctrl_write(s
, addr
, size
, value
);
51 static void virt_ctrl_write(void *opaque
, hwaddr addr
, uint64_t value
,
54 VirtCtrlState
*s
= opaque
;
56 trace_virt_ctrl_write(s
, addr
, size
, value
);
64 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
67 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
70 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
75 qemu_log_mask(LOG_UNIMP
,
76 "%s: unimplemented register write 0x%02"HWADDR_PRIx
"\n",
82 static const MemoryRegionOps virt_ctrl_ops
= {
83 .read
= virt_ctrl_read
,
84 .write
= virt_ctrl_write
,
85 .endianness
= DEVICE_NATIVE_ENDIAN
,
86 .valid
.max_access_size
= 4,
87 .impl
.max_access_size
= 4,
90 static void virt_ctrl_reset(DeviceState
*dev
)
92 VirtCtrlState
*s
= VIRT_CTRL(dev
);
94 trace_virt_ctrl_reset(s
);
97 static void virt_ctrl_realize(DeviceState
*dev
, Error
**errp
)
99 VirtCtrlState
*s
= VIRT_CTRL(dev
);
101 trace_virt_ctrl_instance_init(s
);
103 memory_region_init_io(&s
->iomem
, OBJECT(s
), &virt_ctrl_ops
, s
,
107 static const VMStateDescription vmstate_virt_ctrl
= {
110 .minimum_version_id
= 1,
111 .fields
= (VMStateField
[]) {
112 VMSTATE_UINT32(irq_enabled
, VirtCtrlState
),
113 VMSTATE_END_OF_LIST()
117 static void virt_ctrl_instance_init(Object
*obj
)
119 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
120 VirtCtrlState
*s
= VIRT_CTRL(obj
);
122 trace_virt_ctrl_instance_init(s
);
124 sysbus_init_mmio(dev
, &s
->iomem
);
125 sysbus_init_irq(dev
, &s
->irq
);
128 static void virt_ctrl_class_init(ObjectClass
*oc
, void *data
)
130 DeviceClass
*dc
= DEVICE_CLASS(oc
);
132 dc
->reset
= virt_ctrl_reset
;
133 dc
->realize
= virt_ctrl_realize
;
134 dc
->vmsd
= &vmstate_virt_ctrl
;
137 static const TypeInfo virt_ctrl_info
= {
138 .name
= TYPE_VIRT_CTRL
,
139 .parent
= TYPE_SYS_BUS_DEVICE
,
140 .class_init
= virt_ctrl_class_init
,
141 .instance_init
= virt_ctrl_instance_init
,
142 .instance_size
= sizeof(VirtCtrlState
),
145 static void virt_ctrl_register_types(void)
147 type_register_static(&virt_ctrl_info
);
150 type_init(virt_ctrl_register_types
)