2011-03-08 01:32:33 +03:00
|
|
|
/*
|
|
|
|
* QEMU model of the Milkymist High Performance Dynamic Memory Controller.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Specification available at:
|
2016-06-20 19:08:41 +03:00
|
|
|
* http://milkymist.walle.cc/socdoc/hpdmc.pdf
|
2011-03-08 01:32:33 +03:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:16:57 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2011-03-08 01:32:33 +03:00
|
|
|
#include "trace.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2011-03-08 01:32:33 +03:00
|
|
|
|
|
|
|
enum {
|
|
|
|
R_SYSTEM = 0,
|
|
|
|
R_BYPASS,
|
|
|
|
R_TIMING,
|
|
|
|
R_IODELAY,
|
|
|
|
R_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
IODELAY_DQSDELAY_RDY = (1<<5),
|
|
|
|
IODELAY_PLL1_LOCKED = (1<<6),
|
|
|
|
IODELAY_PLL2_LOCKED = (1<<7),
|
|
|
|
};
|
|
|
|
|
2013-07-27 00:24:22 +04:00
|
|
|
#define TYPE_MILKYMIST_HPDMC "milkymist-hpdmc"
|
|
|
|
#define MILKYMIST_HPDMC(obj) \
|
|
|
|
OBJECT_CHECK(MilkymistHpdmcState, (obj), TYPE_MILKYMIST_HPDMC)
|
|
|
|
|
2011-03-08 01:32:33 +03:00
|
|
|
struct MilkymistHpdmcState {
|
2013-07-27 00:24:22 +04:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-08-31 18:48:40 +04:00
|
|
|
MemoryRegion regs_region;
|
2011-03-08 01:32:33 +03:00
|
|
|
|
|
|
|
uint32_t regs[R_MAX];
|
|
|
|
};
|
|
|
|
typedef struct MilkymistHpdmcState MilkymistHpdmcState;
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t hpdmc_read(void *opaque, hwaddr addr,
|
2011-08-31 18:48:40 +04:00
|
|
|
unsigned size)
|
2011-03-08 01:32:33 +03:00
|
|
|
{
|
|
|
|
MilkymistHpdmcState *s = opaque;
|
|
|
|
uint32_t r = 0;
|
|
|
|
|
|
|
|
addr >>= 2;
|
|
|
|
switch (addr) {
|
|
|
|
case R_SYSTEM:
|
|
|
|
case R_BYPASS:
|
|
|
|
case R_TIMING:
|
|
|
|
case R_IODELAY:
|
|
|
|
r = s->regs[addr];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error_report("milkymist_hpdmc: read access to unknown register 0x"
|
|
|
|
TARGET_FMT_plx, addr << 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_milkymist_hpdmc_memory_read(addr << 2, r);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void hpdmc_write(void *opaque, hwaddr addr, uint64_t value,
|
2011-08-31 18:48:40 +04:00
|
|
|
unsigned size)
|
2011-03-08 01:32:33 +03:00
|
|
|
{
|
|
|
|
MilkymistHpdmcState *s = opaque;
|
|
|
|
|
|
|
|
trace_milkymist_hpdmc_memory_write(addr, value);
|
|
|
|
|
|
|
|
addr >>= 2;
|
|
|
|
switch (addr) {
|
|
|
|
case R_SYSTEM:
|
|
|
|
case R_BYPASS:
|
|
|
|
case R_TIMING:
|
|
|
|
s->regs[addr] = value;
|
|
|
|
break;
|
|
|
|
case R_IODELAY:
|
|
|
|
/* ignore writes */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error_report("milkymist_hpdmc: write access to unknown register 0x"
|
|
|
|
TARGET_FMT_plx, addr << 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 18:48:40 +04:00
|
|
|
static const MemoryRegionOps hpdmc_mmio_ops = {
|
|
|
|
.read = hpdmc_read,
|
|
|
|
.write = hpdmc_write,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-03-08 01:32:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void milkymist_hpdmc_reset(DeviceState *d)
|
|
|
|
{
|
2013-07-27 00:24:22 +04:00
|
|
|
MilkymistHpdmcState *s = MILKYMIST_HPDMC(d);
|
2011-03-08 01:32:33 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < R_MAX; i++) {
|
|
|
|
s->regs[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* defaults */
|
|
|
|
s->regs[R_IODELAY] = IODELAY_DQSDELAY_RDY | IODELAY_PLL1_LOCKED
|
|
|
|
| IODELAY_PLL2_LOCKED;
|
|
|
|
}
|
|
|
|
|
2018-12-13 16:47:59 +03:00
|
|
|
static void milkymist_hpdmc_realize(DeviceState *dev, Error **errp)
|
2011-03-08 01:32:33 +03:00
|
|
|
{
|
2013-07-27 00:24:22 +04:00
|
|
|
MilkymistHpdmcState *s = MILKYMIST_HPDMC(dev);
|
2011-03-08 01:32:33 +03:00
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&s->regs_region, OBJECT(dev), &hpdmc_mmio_ops, s,
|
2011-08-31 18:48:40 +04:00
|
|
|
"milkymist-hpdmc", R_MAX * 4);
|
2018-12-13 16:47:59 +03:00
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->regs_region);
|
2011-03-08 01:32:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_milkymist_hpdmc = {
|
|
|
|
.name = "milkymist-hpdmc",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 18:01:33 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2011-03-08 01:32:33 +03:00
|
|
|
VMSTATE_UINT32_ARRAY(regs, MilkymistHpdmcState, R_MAX),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
static void milkymist_hpdmc_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 23:12:29 +04:00
|
|
|
|
2018-12-13 16:47:59 +03:00
|
|
|
dc->realize = milkymist_hpdmc_realize;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->reset = milkymist_hpdmc_reset;
|
|
|
|
dc->vmsd = &vmstate_milkymist_hpdmc;
|
2012-01-24 23:12:29 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo milkymist_hpdmc_info = {
|
2013-07-27 00:24:22 +04:00
|
|
|
.name = TYPE_MILKYMIST_HPDMC,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(MilkymistHpdmcState),
|
|
|
|
.class_init = milkymist_hpdmc_class_init,
|
2011-03-08 01:32:33 +03:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void milkymist_hpdmc_register_types(void)
|
2011-03-08 01:32:33 +03:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&milkymist_hpdmc_info);
|
2011-03-08 01:32:33 +03:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(milkymist_hpdmc_register_types)
|