MAINTAINERS: add tracing subsystem
[qemu/ar7.git] / hw / milkymist-hpdmc.c
blobc0962fb528334f7055b9d8e9ce2536e18380dc58
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.h"
25 #include "sysbus.h"
26 #include "trace.h"
27 #include "qemu-error.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 struct MilkymistHpdmcState {
44 SysBusDevice busdev;
46 uint32_t regs[R_MAX];
48 typedef struct MilkymistHpdmcState MilkymistHpdmcState;
50 static uint32_t hpdmc_read(void *opaque, target_phys_addr_t addr)
52 MilkymistHpdmcState *s = opaque;
53 uint32_t r = 0;
55 addr >>= 2;
56 switch (addr) {
57 case R_SYSTEM:
58 case R_BYPASS:
59 case R_TIMING:
60 case R_IODELAY:
61 r = s->regs[addr];
62 break;
64 default:
65 error_report("milkymist_hpdmc: read access to unknown register 0x"
66 TARGET_FMT_plx, addr << 2);
67 break;
70 trace_milkymist_hpdmc_memory_read(addr << 2, r);
72 return r;
75 static void hpdmc_write(void *opaque, target_phys_addr_t addr, uint32_t value)
77 MilkymistHpdmcState *s = opaque;
79 trace_milkymist_hpdmc_memory_write(addr, value);
81 addr >>= 2;
82 switch (addr) {
83 case R_SYSTEM:
84 case R_BYPASS:
85 case R_TIMING:
86 s->regs[addr] = value;
87 break;
88 case R_IODELAY:
89 /* ignore writes */
90 break;
92 default:
93 error_report("milkymist_hpdmc: write access to unknown register 0x"
94 TARGET_FMT_plx, addr << 2);
95 break;
99 static CPUReadMemoryFunc * const hpdmc_read_fn[] = {
100 NULL,
101 NULL,
102 &hpdmc_read,
105 static CPUWriteMemoryFunc * const hpdmc_write_fn[] = {
106 NULL,
107 NULL,
108 &hpdmc_write,
111 static void milkymist_hpdmc_reset(DeviceState *d)
113 MilkymistHpdmcState *s = container_of(d, MilkymistHpdmcState, busdev.qdev);
114 int i;
116 for (i = 0; i < R_MAX; i++) {
117 s->regs[i] = 0;
120 /* defaults */
121 s->regs[R_IODELAY] = IODELAY_DQSDELAY_RDY | IODELAY_PLL1_LOCKED
122 | IODELAY_PLL2_LOCKED;
125 static int milkymist_hpdmc_init(SysBusDevice *dev)
127 MilkymistHpdmcState *s = FROM_SYSBUS(typeof(*s), dev);
128 int hpdmc_regs;
130 hpdmc_regs = cpu_register_io_memory(hpdmc_read_fn, hpdmc_write_fn, s,
131 DEVICE_NATIVE_ENDIAN);
132 sysbus_init_mmio(dev, R_MAX * 4, hpdmc_regs);
134 return 0;
137 static const VMStateDescription vmstate_milkymist_hpdmc = {
138 .name = "milkymist-hpdmc",
139 .version_id = 1,
140 .minimum_version_id = 1,
141 .minimum_version_id_old = 1,
142 .fields = (VMStateField[]) {
143 VMSTATE_UINT32_ARRAY(regs, MilkymistHpdmcState, R_MAX),
144 VMSTATE_END_OF_LIST()
148 static SysBusDeviceInfo milkymist_hpdmc_info = {
149 .init = milkymist_hpdmc_init,
150 .qdev.name = "milkymist-hpdmc",
151 .qdev.size = sizeof(MilkymistHpdmcState),
152 .qdev.vmsd = &vmstate_milkymist_hpdmc,
153 .qdev.reset = milkymist_hpdmc_reset,
156 static void milkymist_hpdmc_register(void)
158 sysbus_register_withprop(&milkymist_hpdmc_info);
161 device_init(milkymist_hpdmc_register)