2 * ARM IoTKit system control element
4 * Copyright (c) 2018 Linaro Limited
5 * Written by Peter Maydell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 or
9 * (at your option) any later version.
13 * This is a model of the "system control element" which is part of the
14 * Arm IoTKit and documented in
15 * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
16 * Specifically, it implements the "system control register" blocks.
19 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "sysemu/sysemu.h"
24 #include "hw/sysbus.h"
25 #include "hw/registerfields.h"
26 #include "hw/misc/iotkit-sysctl.h"
28 REG32(SECDBGSTAT
, 0x0)
31 REG32(RESET_SYNDROME
, 0x100)
32 REG32(RESET_MASK
, 0x104)
34 FIELD(SWRESET
, SWRESETREQ
, 9, 1)
36 REG32(INITSVRTOR0
, 0x110)
54 static const int sysctl_id
[] = {
55 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
56 0x54, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
57 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
60 static uint64_t iotkit_sysctl_read(void *opaque
, hwaddr offset
,
63 IoTKitSysCtl
*s
= IOTKIT_SYSCTL(opaque
);
70 case A_RESET_SYNDROME
:
71 r
= s
->reset_syndrome
;
86 /* In IoTKit BUSWAIT is reserved, R/O, zero */
92 case A_PID4
... A_CID3
:
93 r
= sysctl_id
[(offset
- A_PID4
) / 4];
98 qemu_log_mask(LOG_GUEST_ERROR
,
99 "IoTKit SysCtl read: read of WO offset %x\n",
104 qemu_log_mask(LOG_GUEST_ERROR
,
105 "IoTKit SysCtl read: bad offset %x\n", (int)offset
);
109 trace_iotkit_sysctl_read(offset
, r
, size
);
113 static void iotkit_sysctl_write(void *opaque
, hwaddr offset
,
114 uint64_t value
, unsigned size
)
116 IoTKitSysCtl
*s
= IOTKIT_SYSCTL(opaque
);
118 trace_iotkit_sysctl_write(offset
, value
, size
);
121 * Most of the state here has to do with control of reset and
122 * similar kinds of power up -- for instance the guest can ask
123 * what the reason for the last reset was, or forbid reset for
124 * some causes (like the non-secure watchdog). Most of this is
125 * not relevant to QEMU, which doesn't really model anything other
126 * than a full power-on reset.
127 * We just model the registers as reads-as-written.
131 case A_RESET_SYNDROME
:
132 qemu_log_mask(LOG_UNIMP
,
133 "IoTKit SysCtl RESET_SYNDROME unimplemented\n");
134 s
->reset_syndrome
= value
;
137 qemu_log_mask(LOG_UNIMP
, "IoTKit SysCtl RESET_MASK unimplemented\n");
138 s
->reset_mask
= value
;
142 * General retention register, which is only reset by a power-on
143 * reset. Technically this implementation is complete, since
144 * QEMU only supports power-on resets...
149 qemu_log_mask(LOG_UNIMP
, "IoTKit SysCtl INITSVRTOR0 unimplemented\n");
150 s
->initsvrtor0
= value
;
153 qemu_log_mask(LOG_UNIMP
, "IoTKit SysCtl CPUWAIT unimplemented\n");
157 qemu_log_mask(LOG_UNIMP
, "IoTKit SysCtl WICCTRL unimplemented\n");
162 qemu_log_mask(LOG_UNIMP
, "IoTKit SysCtl SECDBGSET unimplemented\n");
163 s
->secure_debug
|= value
;
166 /* write-1-to-clear */
167 s
->secure_debug
&= ~value
;
170 /* One w/o bit to request a reset; all other bits reserved */
171 if (value
& R_SWRESET_SWRESETREQ_MASK
) {
172 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
175 case A_BUSWAIT
: /* In IoTKit BUSWAIT is reserved, R/O, zero */
177 case A_PID4
... A_CID3
:
178 qemu_log_mask(LOG_GUEST_ERROR
,
179 "IoTKit SysCtl write: write of RO offset %x\n",
183 qemu_log_mask(LOG_GUEST_ERROR
,
184 "IoTKit SysCtl write: bad offset %x\n", (int)offset
);
189 static const MemoryRegionOps iotkit_sysctl_ops
= {
190 .read
= iotkit_sysctl_read
,
191 .write
= iotkit_sysctl_write
,
192 .endianness
= DEVICE_LITTLE_ENDIAN
,
193 /* byte/halfword accesses are just zero-padded on reads and writes */
194 .impl
.min_access_size
= 4,
195 .impl
.max_access_size
= 4,
196 .valid
.min_access_size
= 1,
197 .valid
.max_access_size
= 4,
200 static void iotkit_sysctl_reset(DeviceState
*dev
)
202 IoTKitSysCtl
*s
= IOTKIT_SYSCTL(dev
);
204 trace_iotkit_sysctl_reset();
206 s
->reset_syndrome
= 1;
209 s
->initsvrtor0
= 0x10000000;
214 static void iotkit_sysctl_init(Object
*obj
)
216 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
217 IoTKitSysCtl
*s
= IOTKIT_SYSCTL(obj
);
219 memory_region_init_io(&s
->iomem
, obj
, &iotkit_sysctl_ops
,
220 s
, "iotkit-sysctl", 0x1000);
221 sysbus_init_mmio(sbd
, &s
->iomem
);
224 static const VMStateDescription iotkit_sysctl_vmstate
= {
225 .name
= "iotkit-sysctl",
227 .minimum_version_id
= 1,
228 .fields
= (VMStateField
[]) {
229 VMSTATE_UINT32(secure_debug
, IoTKitSysCtl
),
230 VMSTATE_UINT32(reset_syndrome
, IoTKitSysCtl
),
231 VMSTATE_UINT32(reset_mask
, IoTKitSysCtl
),
232 VMSTATE_UINT32(gretreg
, IoTKitSysCtl
),
233 VMSTATE_UINT32(initsvrtor0
, IoTKitSysCtl
),
234 VMSTATE_UINT32(cpuwait
, IoTKitSysCtl
),
235 VMSTATE_UINT32(wicctrl
, IoTKitSysCtl
),
236 VMSTATE_END_OF_LIST()
240 static void iotkit_sysctl_class_init(ObjectClass
*klass
, void *data
)
242 DeviceClass
*dc
= DEVICE_CLASS(klass
);
244 dc
->vmsd
= &iotkit_sysctl_vmstate
;
245 dc
->reset
= iotkit_sysctl_reset
;
248 static const TypeInfo iotkit_sysctl_info
= {
249 .name
= TYPE_IOTKIT_SYSCTL
,
250 .parent
= TYPE_SYS_BUS_DEVICE
,
251 .instance_size
= sizeof(IoTKitSysCtl
),
252 .instance_init
= iotkit_sysctl_init
,
253 .class_init
= iotkit_sysctl_class_init
,
256 static void iotkit_sysctl_register_types(void)
258 type_register_static(&iotkit_sysctl_info
);
261 type_init(iotkit_sysctl_register_types
);