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
27 #include "qemu-error.h"
38 IODELAY_DQSDELAY_RDY
= (1<<5),
39 IODELAY_PLL1_LOCKED
= (1<<6),
40 IODELAY_PLL2_LOCKED
= (1<<7),
43 struct MilkymistHpdmcState
{
45 MemoryRegion regs_region
;
49 typedef struct MilkymistHpdmcState MilkymistHpdmcState
;
51 static uint64_t hpdmc_read(void *opaque
, target_phys_addr_t addr
,
54 MilkymistHpdmcState
*s
= opaque
;
67 error_report("milkymist_hpdmc: read access to unknown register 0x"
68 TARGET_FMT_plx
, addr
<< 2);
72 trace_milkymist_hpdmc_memory_read(addr
<< 2, r
);
77 static void hpdmc_write(void *opaque
, target_phys_addr_t addr
, uint64_t value
,
80 MilkymistHpdmcState
*s
= opaque
;
82 trace_milkymist_hpdmc_memory_write(addr
, value
);
89 s
->regs
[addr
] = value
;
96 error_report("milkymist_hpdmc: write access to unknown register 0x"
97 TARGET_FMT_plx
, addr
<< 2);
102 static const MemoryRegionOps hpdmc_mmio_ops
= {
104 .write
= hpdmc_write
,
106 .min_access_size
= 4,
107 .max_access_size
= 4,
109 .endianness
= DEVICE_NATIVE_ENDIAN
,
112 static void milkymist_hpdmc_reset(DeviceState
*d
)
114 MilkymistHpdmcState
*s
= container_of(d
, MilkymistHpdmcState
, busdev
.qdev
);
117 for (i
= 0; i
< R_MAX
; i
++) {
122 s
->regs
[R_IODELAY
] = IODELAY_DQSDELAY_RDY
| IODELAY_PLL1_LOCKED
123 | IODELAY_PLL2_LOCKED
;
126 static int milkymist_hpdmc_init(SysBusDevice
*dev
)
128 MilkymistHpdmcState
*s
= FROM_SYSBUS(typeof(*s
), dev
);
130 memory_region_init_io(&s
->regs_region
, &hpdmc_mmio_ops
, s
,
131 "milkymist-hpdmc", R_MAX
* 4);
132 sysbus_init_mmio(dev
, &s
->regs_region
);
137 static const VMStateDescription vmstate_milkymist_hpdmc
= {
138 .name
= "milkymist-hpdmc",
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 void milkymist_hpdmc_class_init(ObjectClass
*klass
, void *data
)
150 DeviceClass
*dc
= DEVICE_CLASS(klass
);
151 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
153 k
->init
= milkymist_hpdmc_init
;
154 dc
->reset
= milkymist_hpdmc_reset
;
155 dc
->vmsd
= &vmstate_milkymist_hpdmc
;
158 static TypeInfo milkymist_hpdmc_info
= {
159 .name
= "milkymist-hpdmc",
160 .parent
= TYPE_SYS_BUS_DEVICE
,
161 .instance_size
= sizeof(MilkymistHpdmcState
),
162 .class_init
= milkymist_hpdmc_class_init
,
165 static void milkymist_hpdmc_register_types(void)
167 type_register_static(&milkymist_hpdmc_info
);
170 type_init(milkymist_hpdmc_register_types
)