]> git.proxmox.com Git - mirror_qemu.git/blob - hw/misc/iotkit-sysinfo.c
Include hw/qdev-properties.h less
[mirror_qemu.git] / hw / misc / iotkit-sysinfo.c
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 * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
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 "sysemu/sysemu.h"
26 #include "hw/sysbus.h"
27 #include "hw/registerfields.h"
28 #include "hw/misc/iotkit-sysinfo.h"
29 #include "hw/qdev-properties.h"
30
31 REG32(SYS_VERSION, 0x0)
32 REG32(SYS_CONFIG, 0x4)
33 REG32(PID4, 0xfd0)
34 REG32(PID5, 0xfd4)
35 REG32(PID6, 0xfd8)
36 REG32(PID7, 0xfdc)
37 REG32(PID0, 0xfe0)
38 REG32(PID1, 0xfe4)
39 REG32(PID2, 0xfe8)
40 REG32(PID3, 0xfec)
41 REG32(CID0, 0xff0)
42 REG32(CID1, 0xff4)
43 REG32(CID2, 0xff8)
44 REG32(CID3, 0xffc)
45
46 /* PID/CID values */
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 */
51 };
52
53 static uint64_t iotkit_sysinfo_read(void *opaque, hwaddr offset,
54 unsigned size)
55 {
56 IoTKitSysInfo *s = IOTKIT_SYSINFO(opaque);
57 uint64_t r;
58
59 switch (offset) {
60 case A_SYS_VERSION:
61 r = s->sys_version;
62 break;
63
64 case A_SYS_CONFIG:
65 r = s->sys_config;
66 break;
67 case A_PID4 ... A_CID3:
68 r = sysinfo_id[(offset - A_PID4) / 4];
69 break;
70 default:
71 qemu_log_mask(LOG_GUEST_ERROR,
72 "IoTKit SysInfo read: bad offset %x\n", (int)offset);
73 r = 0;
74 break;
75 }
76 trace_iotkit_sysinfo_read(offset, r, size);
77 return r;
78 }
79
80 static void iotkit_sysinfo_write(void *opaque, hwaddr offset,
81 uint64_t value, unsigned size)
82 {
83 trace_iotkit_sysinfo_write(offset, value, size);
84
85 qemu_log_mask(LOG_GUEST_ERROR,
86 "IoTKit SysInfo: write to RO offset 0x%x\n", (int)offset);
87 }
88
89 static const MemoryRegionOps iotkit_sysinfo_ops = {
90 .read = iotkit_sysinfo_read,
91 .write = iotkit_sysinfo_write,
92 .endianness = DEVICE_LITTLE_ENDIAN,
93 /* byte/halfword accesses are just zero-padded on reads and writes */
94 .impl.min_access_size = 4,
95 .impl.max_access_size = 4,
96 .valid.min_access_size = 1,
97 .valid.max_access_size = 4,
98 };
99
100 static Property iotkit_sysinfo_props[] = {
101 DEFINE_PROP_UINT32("SYS_VERSION", IoTKitSysInfo, sys_version, 0),
102 DEFINE_PROP_UINT32("SYS_CONFIG", IoTKitSysInfo, sys_config, 0),
103 DEFINE_PROP_END_OF_LIST()
104 };
105
106 static void iotkit_sysinfo_init(Object *obj)
107 {
108 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
109 IoTKitSysInfo *s = IOTKIT_SYSINFO(obj);
110
111 memory_region_init_io(&s->iomem, obj, &iotkit_sysinfo_ops,
112 s, "iotkit-sysinfo", 0x1000);
113 sysbus_init_mmio(sbd, &s->iomem);
114 }
115
116 static void iotkit_sysinfo_class_init(ObjectClass *klass, void *data)
117 {
118 DeviceClass *dc = DEVICE_CLASS(klass);
119
120 /*
121 * This device has no guest-modifiable state and so it
122 * does not need a reset function or VMState.
123 */
124
125 dc->props = iotkit_sysinfo_props;
126 }
127
128 static const TypeInfo iotkit_sysinfo_info = {
129 .name = TYPE_IOTKIT_SYSINFO,
130 .parent = TYPE_SYS_BUS_DEVICE,
131 .instance_size = sizeof(IoTKitSysInfo),
132 .instance_init = iotkit_sysinfo_init,
133 .class_init = iotkit_sysinfo_class_init,
134 };
135
136 static void iotkit_sysinfo_register_types(void)
137 {
138 type_register_static(&iotkit_sysinfo_info);
139 }
140
141 type_init(iotkit_sysinfo_register_types);