root / hw / milkymist-hpdmc.c @ e6eaabeb
History | View | Annotate | Download (4.2 kB)
1 | e4dc6d2c | Michael Walle | /*
|
---|---|---|---|
2 | e4dc6d2c | Michael Walle | * QEMU model of the Milkymist High Performance Dynamic Memory Controller.
|
3 | e4dc6d2c | Michael Walle | *
|
4 | e4dc6d2c | Michael Walle | * Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
5 | e4dc6d2c | Michael Walle | *
|
6 | e4dc6d2c | Michael Walle | * This library is free software; you can redistribute it and/or
|
7 | e4dc6d2c | Michael Walle | * modify it under the terms of the GNU Lesser General Public
|
8 | e4dc6d2c | Michael Walle | * License as published by the Free Software Foundation; either
|
9 | e4dc6d2c | Michael Walle | * version 2 of the License, or (at your option) any later version.
|
10 | e4dc6d2c | Michael Walle | *
|
11 | e4dc6d2c | Michael Walle | * This library is distributed in the hope that it will be useful,
|
12 | e4dc6d2c | Michael Walle | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | e4dc6d2c | Michael Walle | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | e4dc6d2c | Michael Walle | * Lesser General Public License for more details.
|
15 | e4dc6d2c | Michael Walle | *
|
16 | e4dc6d2c | Michael Walle | * You should have received a copy of the GNU Lesser General Public
|
17 | e4dc6d2c | Michael Walle | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | e4dc6d2c | Michael Walle | *
|
19 | e4dc6d2c | Michael Walle | *
|
20 | e4dc6d2c | Michael Walle | * Specification available at:
|
21 | e4dc6d2c | Michael Walle | * http://www.milkymist.org/socdoc/hpdmc.pdf
|
22 | e4dc6d2c | Michael Walle | */
|
23 | e4dc6d2c | Michael Walle | |
24 | e4dc6d2c | Michael Walle | #include "hw.h" |
25 | e4dc6d2c | Michael Walle | #include "sysbus.h" |
26 | e4dc6d2c | Michael Walle | #include "trace.h" |
27 | e4dc6d2c | Michael Walle | #include "qemu-error.h" |
28 | e4dc6d2c | Michael Walle | |
29 | e4dc6d2c | Michael Walle | enum {
|
30 | e4dc6d2c | Michael Walle | R_SYSTEM = 0,
|
31 | e4dc6d2c | Michael Walle | R_BYPASS, |
32 | e4dc6d2c | Michael Walle | R_TIMING, |
33 | e4dc6d2c | Michael Walle | R_IODELAY, |
34 | e4dc6d2c | Michael Walle | R_MAX |
35 | e4dc6d2c | Michael Walle | }; |
36 | e4dc6d2c | Michael Walle | |
37 | e4dc6d2c | Michael Walle | enum {
|
38 | e4dc6d2c | Michael Walle | IODELAY_DQSDELAY_RDY = (1<<5), |
39 | e4dc6d2c | Michael Walle | IODELAY_PLL1_LOCKED = (1<<6), |
40 | e4dc6d2c | Michael Walle | IODELAY_PLL2_LOCKED = (1<<7), |
41 | e4dc6d2c | Michael Walle | }; |
42 | e4dc6d2c | Michael Walle | |
43 | e4dc6d2c | Michael Walle | struct MilkymistHpdmcState {
|
44 | e4dc6d2c | Michael Walle | SysBusDevice busdev; |
45 | 321c17ae | Michael Walle | MemoryRegion regs_region; |
46 | e4dc6d2c | Michael Walle | |
47 | e4dc6d2c | Michael Walle | uint32_t regs[R_MAX]; |
48 | e4dc6d2c | Michael Walle | }; |
49 | e4dc6d2c | Michael Walle | typedef struct MilkymistHpdmcState MilkymistHpdmcState; |
50 | e4dc6d2c | Michael Walle | |
51 | 321c17ae | Michael Walle | static uint64_t hpdmc_read(void *opaque, target_phys_addr_t addr, |
52 | 321c17ae | Michael Walle | unsigned size)
|
53 | e4dc6d2c | Michael Walle | { |
54 | e4dc6d2c | Michael Walle | MilkymistHpdmcState *s = opaque; |
55 | e4dc6d2c | Michael Walle | uint32_t r = 0;
|
56 | e4dc6d2c | Michael Walle | |
57 | e4dc6d2c | Michael Walle | addr >>= 2;
|
58 | e4dc6d2c | Michael Walle | switch (addr) {
|
59 | e4dc6d2c | Michael Walle | case R_SYSTEM:
|
60 | e4dc6d2c | Michael Walle | case R_BYPASS:
|
61 | e4dc6d2c | Michael Walle | case R_TIMING:
|
62 | e4dc6d2c | Michael Walle | case R_IODELAY:
|
63 | e4dc6d2c | Michael Walle | r = s->regs[addr]; |
64 | e4dc6d2c | Michael Walle | break;
|
65 | e4dc6d2c | Michael Walle | |
66 | e4dc6d2c | Michael Walle | default:
|
67 | e4dc6d2c | Michael Walle | error_report("milkymist_hpdmc: read access to unknown register 0x"
|
68 | e4dc6d2c | Michael Walle | TARGET_FMT_plx, addr << 2);
|
69 | e4dc6d2c | Michael Walle | break;
|
70 | e4dc6d2c | Michael Walle | } |
71 | e4dc6d2c | Michael Walle | |
72 | e4dc6d2c | Michael Walle | trace_milkymist_hpdmc_memory_read(addr << 2, r);
|
73 | e4dc6d2c | Michael Walle | |
74 | e4dc6d2c | Michael Walle | return r;
|
75 | e4dc6d2c | Michael Walle | } |
76 | e4dc6d2c | Michael Walle | |
77 | 321c17ae | Michael Walle | static void hpdmc_write(void *opaque, target_phys_addr_t addr, uint64_t value, |
78 | 321c17ae | Michael Walle | unsigned size)
|
79 | e4dc6d2c | Michael Walle | { |
80 | e4dc6d2c | Michael Walle | MilkymistHpdmcState *s = opaque; |
81 | e4dc6d2c | Michael Walle | |
82 | e4dc6d2c | Michael Walle | trace_milkymist_hpdmc_memory_write(addr, value); |
83 | e4dc6d2c | Michael Walle | |
84 | e4dc6d2c | Michael Walle | addr >>= 2;
|
85 | e4dc6d2c | Michael Walle | switch (addr) {
|
86 | e4dc6d2c | Michael Walle | case R_SYSTEM:
|
87 | e4dc6d2c | Michael Walle | case R_BYPASS:
|
88 | e4dc6d2c | Michael Walle | case R_TIMING:
|
89 | e4dc6d2c | Michael Walle | s->regs[addr] = value; |
90 | e4dc6d2c | Michael Walle | break;
|
91 | e4dc6d2c | Michael Walle | case R_IODELAY:
|
92 | e4dc6d2c | Michael Walle | /* ignore writes */
|
93 | e4dc6d2c | Michael Walle | break;
|
94 | e4dc6d2c | Michael Walle | |
95 | e4dc6d2c | Michael Walle | default:
|
96 | e4dc6d2c | Michael Walle | error_report("milkymist_hpdmc: write access to unknown register 0x"
|
97 | e4dc6d2c | Michael Walle | TARGET_FMT_plx, addr << 2);
|
98 | e4dc6d2c | Michael Walle | break;
|
99 | e4dc6d2c | Michael Walle | } |
100 | e4dc6d2c | Michael Walle | } |
101 | e4dc6d2c | Michael Walle | |
102 | 321c17ae | Michael Walle | static const MemoryRegionOps hpdmc_mmio_ops = { |
103 | 321c17ae | Michael Walle | .read = hpdmc_read, |
104 | 321c17ae | Michael Walle | .write = hpdmc_write, |
105 | 321c17ae | Michael Walle | .valid = { |
106 | 321c17ae | Michael Walle | .min_access_size = 4,
|
107 | 321c17ae | Michael Walle | .max_access_size = 4,
|
108 | 321c17ae | Michael Walle | }, |
109 | 321c17ae | Michael Walle | .endianness = DEVICE_NATIVE_ENDIAN, |
110 | e4dc6d2c | Michael Walle | }; |
111 | e4dc6d2c | Michael Walle | |
112 | e4dc6d2c | Michael Walle | static void milkymist_hpdmc_reset(DeviceState *d) |
113 | e4dc6d2c | Michael Walle | { |
114 | e4dc6d2c | Michael Walle | MilkymistHpdmcState *s = container_of(d, MilkymistHpdmcState, busdev.qdev); |
115 | e4dc6d2c | Michael Walle | int i;
|
116 | e4dc6d2c | Michael Walle | |
117 | e4dc6d2c | Michael Walle | for (i = 0; i < R_MAX; i++) { |
118 | e4dc6d2c | Michael Walle | s->regs[i] = 0;
|
119 | e4dc6d2c | Michael Walle | } |
120 | e4dc6d2c | Michael Walle | |
121 | e4dc6d2c | Michael Walle | /* defaults */
|
122 | e4dc6d2c | Michael Walle | s->regs[R_IODELAY] = IODELAY_DQSDELAY_RDY | IODELAY_PLL1_LOCKED |
123 | e4dc6d2c | Michael Walle | | IODELAY_PLL2_LOCKED; |
124 | e4dc6d2c | Michael Walle | } |
125 | e4dc6d2c | Michael Walle | |
126 | e4dc6d2c | Michael Walle | static int milkymist_hpdmc_init(SysBusDevice *dev) |
127 | e4dc6d2c | Michael Walle | { |
128 | e4dc6d2c | Michael Walle | MilkymistHpdmcState *s = FROM_SYSBUS(typeof(*s), dev); |
129 | e4dc6d2c | Michael Walle | |
130 | 321c17ae | Michael Walle | memory_region_init_io(&s->regs_region, &hpdmc_mmio_ops, s, |
131 | 321c17ae | Michael Walle | "milkymist-hpdmc", R_MAX * 4); |
132 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->regs_region); |
133 | e4dc6d2c | Michael Walle | |
134 | e4dc6d2c | Michael Walle | return 0; |
135 | e4dc6d2c | Michael Walle | } |
136 | e4dc6d2c | Michael Walle | |
137 | e4dc6d2c | Michael Walle | static const VMStateDescription vmstate_milkymist_hpdmc = { |
138 | e4dc6d2c | Michael Walle | .name = "milkymist-hpdmc",
|
139 | e4dc6d2c | Michael Walle | .version_id = 1,
|
140 | e4dc6d2c | Michael Walle | .minimum_version_id = 1,
|
141 | e4dc6d2c | Michael Walle | .minimum_version_id_old = 1,
|
142 | e4dc6d2c | Michael Walle | .fields = (VMStateField[]) { |
143 | e4dc6d2c | Michael Walle | VMSTATE_UINT32_ARRAY(regs, MilkymistHpdmcState, R_MAX), |
144 | e4dc6d2c | Michael Walle | VMSTATE_END_OF_LIST() |
145 | e4dc6d2c | Michael Walle | } |
146 | e4dc6d2c | Michael Walle | }; |
147 | e4dc6d2c | Michael Walle | |
148 | 999e12bb | Anthony Liguori | static void milkymist_hpdmc_class_init(ObjectClass *klass, void *data) |
149 | 999e12bb | Anthony Liguori | { |
150 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
151 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
152 | 999e12bb | Anthony Liguori | |
153 | 999e12bb | Anthony Liguori | k->init = milkymist_hpdmc_init; |
154 | 39bffca2 | Anthony Liguori | dc->reset = milkymist_hpdmc_reset; |
155 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_milkymist_hpdmc; |
156 | 999e12bb | Anthony Liguori | } |
157 | 999e12bb | Anthony Liguori | |
158 | 39bffca2 | Anthony Liguori | static TypeInfo milkymist_hpdmc_info = {
|
159 | 39bffca2 | Anthony Liguori | .name = "milkymist-hpdmc",
|
160 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
161 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(MilkymistHpdmcState),
|
162 | 39bffca2 | Anthony Liguori | .class_init = milkymist_hpdmc_class_init, |
163 | e4dc6d2c | Michael Walle | }; |
164 | e4dc6d2c | Michael Walle | |
165 | 83f7d43a | Andreas Färber | static void milkymist_hpdmc_register_types(void) |
166 | e4dc6d2c | Michael Walle | { |
167 | 39bffca2 | Anthony Liguori | type_register_static(&milkymist_hpdmc_info); |
168 | e4dc6d2c | Michael Walle | } |
169 | e4dc6d2c | Michael Walle | |
170 | 83f7d43a | Andreas Färber | type_init(milkymist_hpdmc_register_types) |