MAINTAINERS: Add include/hw/xtensa/mx_pic.h to the XTFPGA machine section
[qemu/kevin.git] / hw / misc / armsse-cpu-pwrctrl.c
blob42fc38879f2e53b1978e3dc35df7393e3ad76247
1 /*
2 * Arm SSE CPU PWRCTRL register block
4 * Copyright (c) 2021 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 "CPU<N>_PWRCTRL block" which is part of the
14 * Arm Corstone SSE-300 Example Subsystem and documented in
15 * https://developer.arm.com/documentation/101773/0000
18 #include "qemu/osdep.h"
19 #include "qemu/log.h"
20 #include "qemu/module.h"
21 #include "trace.h"
22 #include "qapi/error.h"
23 #include "migration/vmstate.h"
24 #include "hw/sysbus.h"
25 #include "hw/registerfields.h"
26 #include "hw/misc/armsse-cpu-pwrctrl.h"
28 REG32(CPUPWRCFG, 0x0)
29 REG32(PID4, 0xfd0)
30 REG32(PID5, 0xfd4)
31 REG32(PID6, 0xfd8)
32 REG32(PID7, 0xfdc)
33 REG32(PID0, 0xfe0)
34 REG32(PID1, 0xfe4)
35 REG32(PID2, 0xfe8)
36 REG32(PID3, 0xfec)
37 REG32(CID0, 0xff0)
38 REG32(CID1, 0xff4)
39 REG32(CID2, 0xff8)
40 REG32(CID3, 0xffc)
42 /* PID/CID values */
43 static const int cpu_pwrctrl_id[] = {
44 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
45 0x5a, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
46 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
49 static uint64_t pwrctrl_read(void *opaque, hwaddr offset, unsigned size)
51 ARMSSECPUPwrCtrl *s = ARMSSE_CPU_PWRCTRL(opaque);
52 uint64_t r;
54 switch (offset) {
55 case A_CPUPWRCFG:
56 r = s->cpupwrcfg;
57 break;
58 case A_PID4 ... A_CID3:
59 r = cpu_pwrctrl_id[(offset - A_PID4) / 4];
60 break;
61 default:
62 qemu_log_mask(LOG_GUEST_ERROR,
63 "SSE CPU_PWRCTRL read: bad offset %x\n", (int)offset);
64 r = 0;
65 break;
67 trace_armsse_cpu_pwrctrl_read(offset, r, size);
68 return r;
71 static void pwrctrl_write(void *opaque, hwaddr offset,
72 uint64_t value, unsigned size)
74 ARMSSECPUPwrCtrl *s = ARMSSE_CPU_PWRCTRL(opaque);
76 trace_armsse_cpu_pwrctrl_write(offset, value, size);
78 switch (offset) {
79 case A_CPUPWRCFG:
80 qemu_log_mask(LOG_UNIMP,
81 "SSE CPU_PWRCTRL: CPUPWRCFG unimplemented\n");
82 s->cpupwrcfg = value;
83 break;
84 default:
85 qemu_log_mask(LOG_GUEST_ERROR,
86 "SSE CPU_PWRCTRL write: bad offset 0x%x\n", (int)offset);
87 break;
91 static const MemoryRegionOps pwrctrl_ops = {
92 .read = pwrctrl_read,
93 .write = pwrctrl_write,
94 .endianness = DEVICE_LITTLE_ENDIAN,
95 .impl.min_access_size = 4,
96 .impl.max_access_size = 4,
97 .valid.min_access_size = 4,
98 .valid.max_access_size = 4,
101 static void pwrctrl_reset(DeviceState *dev)
103 ARMSSECPUPwrCtrl *s = ARMSSE_CPU_PWRCTRL(dev);
105 s->cpupwrcfg = 0;
108 static const VMStateDescription pwrctrl_vmstate = {
109 .name = "armsse-cpu-pwrctrl",
110 .version_id = 1,
111 .minimum_version_id = 1,
112 .fields = (VMStateField[]) {
113 VMSTATE_UINT32(cpupwrcfg, ARMSSECPUPwrCtrl),
114 VMSTATE_END_OF_LIST()
118 static void pwrctrl_init(Object *obj)
120 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
121 ARMSSECPUPwrCtrl *s = ARMSSE_CPU_PWRCTRL(obj);
123 memory_region_init_io(&s->iomem, obj, &pwrctrl_ops,
124 s, "armsse-cpu-pwrctrl", 0x1000);
125 sysbus_init_mmio(sbd, &s->iomem);
128 static void pwrctrl_class_init(ObjectClass *klass, void *data)
130 DeviceClass *dc = DEVICE_CLASS(klass);
132 dc->reset = pwrctrl_reset;
133 dc->vmsd = &pwrctrl_vmstate;
136 static const TypeInfo pwrctrl_info = {
137 .name = TYPE_ARMSSE_CPU_PWRCTRL,
138 .parent = TYPE_SYS_BUS_DEVICE,
139 .instance_size = sizeof(ARMSSECPUPwrCtrl),
140 .instance_init = pwrctrl_init,
141 .class_init = pwrctrl_class_init,
144 static void pwrctrl_register_types(void)
146 type_register_static(&pwrctrl_info);
149 type_init(pwrctrl_register_types);