xref: /openbmc/qemu/hw/mem/npcm7xx_mc.c (revision 1351f892467bd8d9655b43b8fbf10a8d08890612)
1*1351f892SHavard Skinnemoen /*
2*1351f892SHavard Skinnemoen  * Nuvoton NPCM7xx Memory Controller stub
3*1351f892SHavard Skinnemoen  *
4*1351f892SHavard Skinnemoen  * Copyright 2020 Google LLC
5*1351f892SHavard Skinnemoen  *
6*1351f892SHavard Skinnemoen  * This program is free software; you can redistribute it and/or modify it
7*1351f892SHavard Skinnemoen  * under the terms of the GNU General Public License as published by the
8*1351f892SHavard Skinnemoen  * Free Software Foundation; either version 2 of the License, or
9*1351f892SHavard Skinnemoen  * (at your option) any later version.
10*1351f892SHavard Skinnemoen  *
11*1351f892SHavard Skinnemoen  * This program is distributed in the hope that it will be useful, but WITHOUT
12*1351f892SHavard Skinnemoen  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*1351f892SHavard Skinnemoen  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14*1351f892SHavard Skinnemoen  * for more details.
15*1351f892SHavard Skinnemoen  */
16*1351f892SHavard Skinnemoen 
17*1351f892SHavard Skinnemoen #include "qemu/osdep.h"
18*1351f892SHavard Skinnemoen 
19*1351f892SHavard Skinnemoen #include "hw/mem/npcm7xx_mc.h"
20*1351f892SHavard Skinnemoen #include "qapi/error.h"
21*1351f892SHavard Skinnemoen #include "qemu/log.h"
22*1351f892SHavard Skinnemoen #include "qemu/module.h"
23*1351f892SHavard Skinnemoen #include "qemu/units.h"
24*1351f892SHavard Skinnemoen 
25*1351f892SHavard Skinnemoen #define NPCM7XX_MC_REGS_SIZE (4 * KiB)
26*1351f892SHavard Skinnemoen 
27*1351f892SHavard Skinnemoen static uint64_t npcm7xx_mc_read(void *opaque, hwaddr addr, unsigned int size)
28*1351f892SHavard Skinnemoen {
29*1351f892SHavard Skinnemoen     /*
30*1351f892SHavard Skinnemoen      * If bits 8..11 @ offset 0 are not zero, the boot block thinks the memory
31*1351f892SHavard Skinnemoen      * controller has already been initialized and will skip DDR training.
32*1351f892SHavard Skinnemoen      */
33*1351f892SHavard Skinnemoen     if (addr == 0) {
34*1351f892SHavard Skinnemoen         return 0x100;
35*1351f892SHavard Skinnemoen     }
36*1351f892SHavard Skinnemoen 
37*1351f892SHavard Skinnemoen     qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
38*1351f892SHavard Skinnemoen 
39*1351f892SHavard Skinnemoen     return 0;
40*1351f892SHavard Skinnemoen }
41*1351f892SHavard Skinnemoen 
42*1351f892SHavard Skinnemoen static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v,
43*1351f892SHavard Skinnemoen                              unsigned int size)
44*1351f892SHavard Skinnemoen {
45*1351f892SHavard Skinnemoen     qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
46*1351f892SHavard Skinnemoen }
47*1351f892SHavard Skinnemoen 
48*1351f892SHavard Skinnemoen static const MemoryRegionOps npcm7xx_mc_ops = {
49*1351f892SHavard Skinnemoen     .read = npcm7xx_mc_read,
50*1351f892SHavard Skinnemoen     .write = npcm7xx_mc_write,
51*1351f892SHavard Skinnemoen     .endianness = DEVICE_LITTLE_ENDIAN,
52*1351f892SHavard Skinnemoen     .valid = {
53*1351f892SHavard Skinnemoen         .min_access_size = 4,
54*1351f892SHavard Skinnemoen         .max_access_size = 4,
55*1351f892SHavard Skinnemoen         .unaligned = false,
56*1351f892SHavard Skinnemoen     },
57*1351f892SHavard Skinnemoen };
58*1351f892SHavard Skinnemoen 
59*1351f892SHavard Skinnemoen static void npcm7xx_mc_realize(DeviceState *dev, Error **errp)
60*1351f892SHavard Skinnemoen {
61*1351f892SHavard Skinnemoen     NPCM7xxMCState *s = NPCM7XX_MC(dev);
62*1351f892SHavard Skinnemoen 
63*1351f892SHavard Skinnemoen     memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs",
64*1351f892SHavard Skinnemoen                           NPCM7XX_MC_REGS_SIZE);
65*1351f892SHavard Skinnemoen     sysbus_init_mmio(&s->parent, &s->mmio);
66*1351f892SHavard Skinnemoen }
67*1351f892SHavard Skinnemoen 
68*1351f892SHavard Skinnemoen static void npcm7xx_mc_class_init(ObjectClass *klass, void *data)
69*1351f892SHavard Skinnemoen {
70*1351f892SHavard Skinnemoen     DeviceClass *dc = DEVICE_CLASS(klass);
71*1351f892SHavard Skinnemoen 
72*1351f892SHavard Skinnemoen     dc->desc = "NPCM7xx Memory Controller stub";
73*1351f892SHavard Skinnemoen     dc->realize = npcm7xx_mc_realize;
74*1351f892SHavard Skinnemoen }
75*1351f892SHavard Skinnemoen 
76*1351f892SHavard Skinnemoen static const TypeInfo npcm7xx_mc_types[] = {
77*1351f892SHavard Skinnemoen     {
78*1351f892SHavard Skinnemoen         .name = TYPE_NPCM7XX_MC,
79*1351f892SHavard Skinnemoen         .parent = TYPE_SYS_BUS_DEVICE,
80*1351f892SHavard Skinnemoen         .instance_size = sizeof(NPCM7xxMCState),
81*1351f892SHavard Skinnemoen         .class_init = npcm7xx_mc_class_init,
82*1351f892SHavard Skinnemoen     },
83*1351f892SHavard Skinnemoen };
84*1351f892SHavard Skinnemoen DEFINE_TYPES(npcm7xx_mc_types);
85