xref: /openbmc/qemu/hw/mem/npcm7xx_mc.c (revision f8e1d8852e393b3fd524fb005e38590063d99bc0)
11351f892SHavard Skinnemoen /*
21351f892SHavard Skinnemoen  * Nuvoton NPCM7xx Memory Controller stub
31351f892SHavard Skinnemoen  *
41351f892SHavard Skinnemoen  * Copyright 2020 Google LLC
51351f892SHavard Skinnemoen  *
61351f892SHavard Skinnemoen  * This program is free software; you can redistribute it and/or modify it
71351f892SHavard Skinnemoen  * under the terms of the GNU General Public License as published by the
81351f892SHavard Skinnemoen  * Free Software Foundation; either version 2 of the License, or
91351f892SHavard Skinnemoen  * (at your option) any later version.
101351f892SHavard Skinnemoen  *
111351f892SHavard Skinnemoen  * This program is distributed in the hope that it will be useful, but WITHOUT
121351f892SHavard Skinnemoen  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131351f892SHavard Skinnemoen  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
141351f892SHavard Skinnemoen  * for more details.
151351f892SHavard Skinnemoen  */
161351f892SHavard Skinnemoen 
171351f892SHavard Skinnemoen #include "qemu/osdep.h"
181351f892SHavard Skinnemoen 
191351f892SHavard Skinnemoen #include "hw/mem/npcm7xx_mc.h"
201351f892SHavard Skinnemoen #include "qapi/error.h"
211351f892SHavard Skinnemoen #include "qemu/log.h"
221351f892SHavard Skinnemoen #include "qemu/module.h"
231351f892SHavard Skinnemoen #include "qemu/units.h"
241351f892SHavard Skinnemoen 
251351f892SHavard Skinnemoen #define NPCM7XX_MC_REGS_SIZE (4 * KiB)
261351f892SHavard Skinnemoen 
npcm7xx_mc_read(void * opaque,hwaddr addr,unsigned int size)271351f892SHavard Skinnemoen static uint64_t npcm7xx_mc_read(void *opaque, hwaddr addr, unsigned int size)
281351f892SHavard Skinnemoen {
291351f892SHavard Skinnemoen     /*
301351f892SHavard Skinnemoen      * If bits 8..11 @ offset 0 are not zero, the boot block thinks the memory
311351f892SHavard Skinnemoen      * controller has already been initialized and will skip DDR training.
321351f892SHavard Skinnemoen      */
331351f892SHavard Skinnemoen     if (addr == 0) {
341351f892SHavard Skinnemoen         return 0x100;
351351f892SHavard Skinnemoen     }
361351f892SHavard Skinnemoen 
371351f892SHavard Skinnemoen     qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
381351f892SHavard Skinnemoen 
391351f892SHavard Skinnemoen     return 0;
401351f892SHavard Skinnemoen }
411351f892SHavard Skinnemoen 
npcm7xx_mc_write(void * opaque,hwaddr addr,uint64_t v,unsigned int size)421351f892SHavard Skinnemoen static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v,
431351f892SHavard Skinnemoen                              unsigned int size)
441351f892SHavard Skinnemoen {
451351f892SHavard Skinnemoen     qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
461351f892SHavard Skinnemoen }
471351f892SHavard Skinnemoen 
481351f892SHavard Skinnemoen static const MemoryRegionOps npcm7xx_mc_ops = {
491351f892SHavard Skinnemoen     .read = npcm7xx_mc_read,
501351f892SHavard Skinnemoen     .write = npcm7xx_mc_write,
511351f892SHavard Skinnemoen     .endianness = DEVICE_LITTLE_ENDIAN,
521351f892SHavard Skinnemoen     .valid = {
531351f892SHavard Skinnemoen         .min_access_size = 4,
541351f892SHavard Skinnemoen         .max_access_size = 4,
551351f892SHavard Skinnemoen         .unaligned = false,
561351f892SHavard Skinnemoen     },
571351f892SHavard Skinnemoen };
581351f892SHavard Skinnemoen 
npcm7xx_mc_realize(DeviceState * dev,Error ** errp)591351f892SHavard Skinnemoen static void npcm7xx_mc_realize(DeviceState *dev, Error **errp)
601351f892SHavard Skinnemoen {
611351f892SHavard Skinnemoen     NPCM7xxMCState *s = NPCM7XX_MC(dev);
621351f892SHavard Skinnemoen 
631351f892SHavard Skinnemoen     memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs",
641351f892SHavard Skinnemoen                           NPCM7XX_MC_REGS_SIZE);
65*828d651cSHao Wu     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);
661351f892SHavard Skinnemoen }
671351f892SHavard Skinnemoen 
npcm7xx_mc_class_init(ObjectClass * klass,void * data)681351f892SHavard Skinnemoen static void npcm7xx_mc_class_init(ObjectClass *klass, void *data)
691351f892SHavard Skinnemoen {
701351f892SHavard Skinnemoen     DeviceClass *dc = DEVICE_CLASS(klass);
711351f892SHavard Skinnemoen 
721351f892SHavard Skinnemoen     dc->desc = "NPCM7xx Memory Controller stub";
731351f892SHavard Skinnemoen     dc->realize = npcm7xx_mc_realize;
741351f892SHavard Skinnemoen }
751351f892SHavard Skinnemoen 
761351f892SHavard Skinnemoen static const TypeInfo npcm7xx_mc_types[] = {
771351f892SHavard Skinnemoen     {
781351f892SHavard Skinnemoen         .name = TYPE_NPCM7XX_MC,
791351f892SHavard Skinnemoen         .parent = TYPE_SYS_BUS_DEVICE,
801351f892SHavard Skinnemoen         .instance_size = sizeof(NPCM7xxMCState),
811351f892SHavard Skinnemoen         .class_init = npcm7xx_mc_class_init,
821351f892SHavard Skinnemoen     },
831351f892SHavard Skinnemoen };
841351f892SHavard Skinnemoen DEFINE_TYPES(npcm7xx_mc_types);
85