exec: always call qemu_get_ram_ptr within rcu_read_lock
[qemu.git] / hw / misc / milkymist-hpdmc.c
blobf5f4c1b343d25dc75f9849133c83c60873fd528a
1 /*
2 * QEMU model of the Milkymist High Performance Dynamic Memory Controller.
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
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://www.milkymist.org/socdoc/hpdmc.pdf
24 #include "hw/hw.h"
25 #include "hw/sysbus.h"
26 #include "trace.h"
27 #include "qemu/error-report.h"
29 enum {
30 R_SYSTEM = 0,
31 R_BYPASS,
32 R_TIMING,
33 R_IODELAY,
34 R_MAX
37 enum {
38 IODELAY_DQSDELAY_RDY = (1<<5),
39 IODELAY_PLL1_LOCKED = (1<<6),
40 IODELAY_PLL2_LOCKED = (1<<7),
43 #define TYPE_MILKYMIST_HPDMC "milkymist-hpdmc"
44 #define MILKYMIST_HPDMC(obj) \
45 OBJECT_CHECK(MilkymistHpdmcState, (obj), TYPE_MILKYMIST_HPDMC)
47 struct MilkymistHpdmcState {
48 SysBusDevice parent_obj;
50 MemoryRegion regs_region;
52 uint32_t regs[R_MAX];
54 typedef struct MilkymistHpdmcState MilkymistHpdmcState;
56 static uint64_t hpdmc_read(void *opaque, hwaddr addr,
57 unsigned size)
59 MilkymistHpdmcState *s = opaque;
60 uint32_t r = 0;
62 addr >>= 2;
63 switch (addr) {
64 case R_SYSTEM:
65 case R_BYPASS:
66 case R_TIMING:
67 case R_IODELAY:
68 r = s->regs[addr];
69 break;
71 default:
72 error_report("milkymist_hpdmc: read access to unknown register 0x"
73 TARGET_FMT_plx, addr << 2);
74 break;
77 trace_milkymist_hpdmc_memory_read(addr << 2, r);
79 return r;
82 static void hpdmc_write(void *opaque, hwaddr addr, uint64_t value,
83 unsigned size)
85 MilkymistHpdmcState *s = opaque;
87 trace_milkymist_hpdmc_memory_write(addr, value);
89 addr >>= 2;
90 switch (addr) {
91 case R_SYSTEM:
92 case R_BYPASS:
93 case R_TIMING:
94 s->regs[addr] = value;
95 break;
96 case R_IODELAY:
97 /* ignore writes */
98 break;
100 default:
101 error_report("milkymist_hpdmc: write access to unknown register 0x"
102 TARGET_FMT_plx, addr << 2);
103 break;
107 static const MemoryRegionOps hpdmc_mmio_ops = {
108 .read = hpdmc_read,
109 .write = hpdmc_write,
110 .valid = {
111 .min_access_size = 4,
112 .max_access_size = 4,
114 .endianness = DEVICE_NATIVE_ENDIAN,
117 static void milkymist_hpdmc_reset(DeviceState *d)
119 MilkymistHpdmcState *s = MILKYMIST_HPDMC(d);
120 int i;
122 for (i = 0; i < R_MAX; i++) {
123 s->regs[i] = 0;
126 /* defaults */
127 s->regs[R_IODELAY] = IODELAY_DQSDELAY_RDY | IODELAY_PLL1_LOCKED
128 | IODELAY_PLL2_LOCKED;
131 static int milkymist_hpdmc_init(SysBusDevice *dev)
133 MilkymistHpdmcState *s = MILKYMIST_HPDMC(dev);
135 memory_region_init_io(&s->regs_region, OBJECT(dev), &hpdmc_mmio_ops, s,
136 "milkymist-hpdmc", R_MAX * 4);
137 sysbus_init_mmio(dev, &s->regs_region);
139 return 0;
142 static const VMStateDescription vmstate_milkymist_hpdmc = {
143 .name = "milkymist-hpdmc",
144 .version_id = 1,
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);
155 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
157 k->init = milkymist_hpdmc_init;
158 dc->reset = milkymist_hpdmc_reset;
159 dc->vmsd = &vmstate_milkymist_hpdmc;
162 static const TypeInfo milkymist_hpdmc_info = {
163 .name = TYPE_MILKYMIST_HPDMC,
164 .parent = TYPE_SYS_BUS_DEVICE,
165 .instance_size = sizeof(MilkymistHpdmcState),
166 .class_init = milkymist_hpdmc_class_init,
169 static void milkymist_hpdmc_register_types(void)
171 type_register_static(&milkymist_hpdmc_info);
174 type_init(milkymist_hpdmc_register_types)