2 * ARM IoTKit system information block
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 information block" which is part of the
14 * Arm IoTKit and documented in
15 * https://developer.arm.com/documentation/ecm0601256/latest
16 * It consists of 2 read-only version/config registers, plus the
20 #include "qemu/osdep.h"
22 #include "qemu/module.h"
24 #include "qapi/error.h"
25 #include "hw/sysbus.h"
26 #include "hw/registerfields.h"
27 #include "hw/misc/iotkit-sysinfo.h"
28 #include "hw/qdev-properties.h"
29 #include "hw/arm/armsse-version.h"
31 REG32(SYS_VERSION
, 0x0)
32 REG32(SYS_CONFIG
, 0x4)
47 static const int sysinfo_id
[] = {
48 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
49 0x58, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
50 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
53 static const int sysinfo_sse300_id
[] = {
54 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
55 0x58, 0xb8, 0x1b, 0x00, /* PID0..PID3 */
56 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
59 static uint64_t iotkit_sysinfo_read(void *opaque
, hwaddr offset
,
62 IoTKitSysInfo
*s
= IOTKIT_SYSINFO(opaque
);
73 case A_PID4
... A_CID3
:
74 switch (s
->sse_version
) {
76 r
= sysinfo_sse300_id
[(offset
- A_PID4
) / 4];
79 r
= sysinfo_id
[(offset
- A_PID4
) / 4];
84 qemu_log_mask(LOG_GUEST_ERROR
,
85 "IoTKit SysInfo read: bad offset %x\n", (int)offset
);
89 trace_iotkit_sysinfo_read(offset
, r
, size
);
93 static void iotkit_sysinfo_write(void *opaque
, hwaddr offset
,
94 uint64_t value
, unsigned size
)
96 trace_iotkit_sysinfo_write(offset
, value
, size
);
98 qemu_log_mask(LOG_GUEST_ERROR
,
99 "IoTKit SysInfo: write to RO offset 0x%x\n", (int)offset
);
102 static const MemoryRegionOps iotkit_sysinfo_ops
= {
103 .read
= iotkit_sysinfo_read
,
104 .write
= iotkit_sysinfo_write
,
105 .endianness
= DEVICE_LITTLE_ENDIAN
,
106 /* byte/halfword accesses are just zero-padded on reads and writes */
107 .impl
.min_access_size
= 4,
108 .impl
.max_access_size
= 4,
109 .valid
.min_access_size
= 1,
110 .valid
.max_access_size
= 4,
113 static Property iotkit_sysinfo_props
[] = {
114 DEFINE_PROP_UINT32("SYS_VERSION", IoTKitSysInfo
, sys_version
, 0),
115 DEFINE_PROP_UINT32("SYS_CONFIG", IoTKitSysInfo
, sys_config
, 0),
116 DEFINE_PROP_UINT32("sse-version", IoTKitSysInfo
, sse_version
, 0),
117 DEFINE_PROP_END_OF_LIST()
120 static void iotkit_sysinfo_init(Object
*obj
)
122 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
123 IoTKitSysInfo
*s
= IOTKIT_SYSINFO(obj
);
125 memory_region_init_io(&s
->iomem
, obj
, &iotkit_sysinfo_ops
,
126 s
, "iotkit-sysinfo", 0x1000);
127 sysbus_init_mmio(sbd
, &s
->iomem
);
130 static void iotkit_sysinfo_realize(DeviceState
*dev
, Error
**errp
)
132 IoTKitSysInfo
*s
= IOTKIT_SYSINFO(dev
);
134 if (!armsse_version_valid(s
->sse_version
)) {
135 error_setg(errp
, "invalid sse-version value %d", s
->sse_version
);
140 static void iotkit_sysinfo_class_init(ObjectClass
*klass
, void *data
)
142 DeviceClass
*dc
= DEVICE_CLASS(klass
);
145 * This device has no guest-modifiable state and so it
146 * does not need a reset function or VMState.
148 dc
->realize
= iotkit_sysinfo_realize
;
149 device_class_set_props(dc
, iotkit_sysinfo_props
);
152 static const TypeInfo iotkit_sysinfo_info
= {
153 .name
= TYPE_IOTKIT_SYSINFO
,
154 .parent
= TYPE_SYS_BUS_DEVICE
,
155 .instance_size
= sizeof(IoTKitSysInfo
),
156 .instance_init
= iotkit_sysinfo_init
,
157 .class_init
= iotkit_sysinfo_class_init
,
160 static void iotkit_sysinfo_register_types(void)
162 type_register_static(&iotkit_sysinfo_info
);
165 type_init(iotkit_sysinfo_register_types
);