2 * QEMU model of the Milkymist High Performance Dynamic Memory Controller.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Specification available at:
21 * http://milkymist.walle.cc/socdoc/hpdmc.pdf
24 #include "qemu/osdep.h"
26 #include "hw/sysbus.h"
28 #include "qemu/error-report.h"
29 #include "qemu/module.h"
40 IODELAY_DQSDELAY_RDY = (1<<5),
41 IODELAY_PLL1_LOCKED = (1<<6),
42 IODELAY_PLL2_LOCKED = (1<<7),
45 #define TYPE_MILKYMIST_HPDMC "milkymist-hpdmc"
46 #define MILKYMIST_HPDMC(obj) \
47 OBJECT_CHECK(MilkymistHpdmcState, (obj), TYPE_MILKYMIST_HPDMC)
49 struct MilkymistHpdmcState {
50 SysBusDevice parent_obj;
52 MemoryRegion regs_region;
56 typedef struct MilkymistHpdmcState MilkymistHpdmcState;
58 static uint64_t hpdmc_read(void *opaque, hwaddr addr,
61 MilkymistHpdmcState *s = opaque;
74 error_report("milkymist_hpdmc: read access to unknown register 0x"
75 TARGET_FMT_plx, addr << 2);
79 trace_milkymist_hpdmc_memory_read(addr << 2, r);
84 static void hpdmc_write(void *opaque, hwaddr addr, uint64_t value,
87 MilkymistHpdmcState *s = opaque;
89 trace_milkymist_hpdmc_memory_write(addr, value);
96 s->regs[addr] = value;
103 error_report("milkymist_hpdmc: write access to unknown register 0x"
104 TARGET_FMT_plx, addr << 2);
109 static const MemoryRegionOps hpdmc_mmio_ops = {
111 .write = hpdmc_write,
113 .min_access_size = 4,
114 .max_access_size = 4,
116 .endianness = DEVICE_NATIVE_ENDIAN,
119 static void milkymist_hpdmc_reset(DeviceState *d)
121 MilkymistHpdmcState *s = MILKYMIST_HPDMC(d);
124 for (i = 0; i < R_MAX; i++) {
129 s->regs[R_IODELAY] = IODELAY_DQSDELAY_RDY | IODELAY_PLL1_LOCKED
130 | IODELAY_PLL2_LOCKED;
133 static void milkymist_hpdmc_realize(DeviceState *dev, Error **errp)
135 MilkymistHpdmcState *s = MILKYMIST_HPDMC(dev);
137 memory_region_init_io(&s->regs_region, OBJECT(dev), &hpdmc_mmio_ops, s,
138 "milkymist-hpdmc", R_MAX * 4);
139 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->regs_region);
142 static const VMStateDescription vmstate_milkymist_hpdmc = {
143 .name = "milkymist-hpdmc",
145 .minimum_version_id = 1,
146 .fields = (VMStateField[]) {
147 VMSTATE_UINT32_ARRAY(regs, MilkymistHpdmcState, R_MAX),
148 VMSTATE_END_OF_LIST()
152 static void milkymist_hpdmc_class_init(ObjectClass *klass, void *data)
154 DeviceClass *dc = DEVICE_CLASS(klass);
156 dc->realize = milkymist_hpdmc_realize;
157 dc->reset = milkymist_hpdmc_reset;
158 dc->vmsd = &vmstate_milkymist_hpdmc;
161 static const TypeInfo milkymist_hpdmc_info = {
162 .name = TYPE_MILKYMIST_HPDMC,
163 .parent = TYPE_SYS_BUS_DEVICE,
164 .instance_size = sizeof(MilkymistHpdmcState),
165 .class_init = milkymist_hpdmc_class_init,
168 static void milkymist_hpdmc_register_types(void)
170 type_register_static(&milkymist_hpdmc_info);
173 type_init(milkymist_hpdmc_register_types)