master
c 206 lines 5.5 KB
Raw
1 /*
2 * ARM IoTKit system information block
3 *
4 * Copyright (c) 2018 Linaro Limited
5 * Written by Peter Maydell
6 *
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.
10 */
11
12 /*
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
17 * usual ID registers.
18 */
19
20 #include "qemu/osdep.h"
21 #include "qemu/log.h"
22 #include "qemu/module.h"
23 #include "trace.h"
24 #include "qapi/error.h"
25 #include "hw/core/sysbus.h"
26 #include "hw/core/registerfields.h"
27 #include "hw/misc/iotkit-sysinfo.h"
28 #include "hw/core/qdev-properties.h"
29 #include "hw/arm/armsse-version.h"
30
31 REG32(SYS_VERSION, 0x0)
32 REG32(SYS_CONFIG, 0x4)
33 REG32(SYS_CONFIG1, 0x8)
34 REG32(SYS_CONFIG2, 0xc)
35 REG32(IIDR, 0xfc8)
36 REG32(PID4, 0xfd0)
37 REG32(PID5, 0xfd4)
38 REG32(PID6, 0xfd8)
39 REG32(PID7, 0xfdc)
40 REG32(PID0, 0xfe0)
41 REG32(PID1, 0xfe4)
42 REG32(PID2, 0xfe8)
43 REG32(PID3, 0xfec)
44 REG32(CID0, 0xff0)
45 REG32(CID1, 0xff4)
46 REG32(CID2, 0xff8)
47 REG32(CID3, 0xffc)
48
49 /* PID/CID values */
50 static const int sysinfo_id[] = {
51 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
52 0x58, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
53 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
54 };
55
56 static const int sysinfo_sse300_id[] = {
57 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
58 0x58, 0xb8, 0x1b, 0x00, /* PID0..PID3 */
59 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
60 };
61
62 static const int sysinfo_sse310_id[] = {
63 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
64 0x58, 0xb8, 0x2b, 0x00, /* PID0..PID3 */
65 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
66 };
67
68 static uint64_t iotkit_sysinfo_read(void *opaque, hwaddr offset,
69 unsigned size)
70 {
71 IoTKitSysInfo *s = IOTKIT_SYSINFO(opaque);
72 uint64_t r;
73
74 switch (offset) {
75 case A_SYS_VERSION:
76 r = s->sys_version;
77 break;
78 case A_SYS_CONFIG:
79 r = s->sys_config;
80 break;
81 case A_SYS_CONFIG1:
82 switch (s->sse_version) {
83 case ARMSSE_SSE300:
84 case ARMSSE_SSE310:
85 return 0;
86 break;
87 default:
88 goto bad_read;
89 }
90 break;
91 case A_SYS_CONFIG2:
92 switch (s->sse_version) {
93 case ARMSSE_SSE310:
94 return 0;
95 break;
96 default:
97 goto bad_read;
98 }
99 break;
100 case A_IIDR:
101 switch (s->sse_version) {
102 case ARMSSE_SSE300:
103 case ARMSSE_SSE310:
104 return s->iidr;
105 break;
106 default:
107 goto bad_read;
108 }
109 break;
110 case A_PID4 ... A_CID3:
111 switch (s->sse_version) {
112 case ARMSSE_SSE300:
113 r = sysinfo_sse300_id[(offset - A_PID4) / 4];
114 break;
115 case ARMSSE_SSE310:
116 r = sysinfo_sse310_id[(offset - A_PID4) / 4];
117 break;
118 default:
119 r = sysinfo_id[(offset - A_PID4) / 4];
120 break;
121 }
122 break;
123 default:
124 bad_read:
125 qemu_log_mask(LOG_GUEST_ERROR,
126 "IoTKit SysInfo read: bad offset %x\n", (int)offset);
127 r = 0;
128 break;
129 }
130 trace_iotkit_sysinfo_read(offset, r, size);
131 return r;
132 }
133
134 static void iotkit_sysinfo_write(void *opaque, hwaddr offset,
135 uint64_t value, unsigned size)
136 {
137 trace_iotkit_sysinfo_write(offset, value, size);
138
139 qemu_log_mask(LOG_GUEST_ERROR,
140 "IoTKit SysInfo: write to RO offset 0x%x\n", (int)offset);
141 }
142
143 static const MemoryRegionOps iotkit_sysinfo_ops = {
144 .read = iotkit_sysinfo_read,
145 .write = iotkit_sysinfo_write,
146 .endianness = DEVICE_LITTLE_ENDIAN,
147 /* byte/halfword accesses are just zero-padded on reads and writes */
148 .impl.min_access_size = 4,
149 .impl.max_access_size = 4,
150 .valid.min_access_size = 1,
151 .valid.max_access_size = 4,
152 };
153
154 static const Property iotkit_sysinfo_props[] = {
155 DEFINE_PROP_UINT32("SYS_VERSION", IoTKitSysInfo, sys_version, 0),
156 DEFINE_PROP_UINT32("SYS_CONFIG", IoTKitSysInfo, sys_config, 0),
157 DEFINE_PROP_UINT32("sse-version", IoTKitSysInfo, sse_version, 0),
158 DEFINE_PROP_UINT32("IIDR", IoTKitSysInfo, iidr, 0),
159 };
160
161 static void iotkit_sysinfo_init(Object *obj)
162 {
163 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
164 IoTKitSysInfo *s = IOTKIT_SYSINFO(obj);
165
166 memory_region_init_io(&s->iomem, obj, &iotkit_sysinfo_ops,
167 s, "iotkit-sysinfo", 0x1000);
168 sysbus_init_mmio(sbd, &s->iomem);
169 }
170
171 static void iotkit_sysinfo_realize(DeviceState *dev, Error **errp)
172 {
173 IoTKitSysInfo *s = IOTKIT_SYSINFO(dev);
174
175 if (!armsse_version_valid(s->sse_version)) {
176 error_setg(errp, "invalid sse-version value %d", s->sse_version);
177 return;
178 }
179 }
180
181 static void iotkit_sysinfo_class_init(ObjectClass *klass, const void *data)
182 {
183 DeviceClass *dc = DEVICE_CLASS(klass);
184
185 /*
186 * This device has no guest-modifiable state and so it
187 * does not need a reset function or VMState.
188 */
189 dc->realize = iotkit_sysinfo_realize;
190 device_class_set_props(dc, iotkit_sysinfo_props);
191 }
192
193 static const TypeInfo iotkit_sysinfo_info = {
194 .name = TYPE_IOTKIT_SYSINFO,
195 .parent = TYPE_SYS_BUS_DEVICE,
196 .instance_size = sizeof(IoTKitSysInfo),
197 .instance_init = iotkit_sysinfo_init,
198 .class_init = iotkit_sysinfo_class_init,
199 };
200
201 static void iotkit_sysinfo_register_types(void)
202 {
203 type_register_static(&iotkit_sysinfo_info);
204 }
205
206 type_init(iotkit_sysinfo_register_types);