Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jul-02-2019' into...
[qemu/ar7.git] / hw / riscv / sifive_prci.c
blobfa136b5a9fe98ad8495042ea2baad1d433edd515
1 /*
2 * QEMU SiFive PRCI (Power, Reset, Clock, Interrupt)
4 * Copyright (c) 2017 SiFive, Inc.
6 * Simple model of the PRCI to emulate register reads made by the SDK BSP
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2 or later, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "hw/sysbus.h"
23 #include "qemu/module.h"
24 #include "target/riscv/cpu.h"
25 #include "hw/riscv/sifive_prci.h"
27 /* currently implements enough to mock freedom-e-sdk BSP clock programming */
29 static uint64_t sifive_prci_read(void *opaque, hwaddr addr, unsigned int size)
31 if (addr == 0 /* PRCI_HFROSCCFG */) {
32 return 1 << 31; /* ROSC_RDY */
34 if (addr == 8 /* PRCI_PLLCFG */) {
35 return 1 << 31; /* PLL_LOCK */
37 hw_error("%s: read: addr=0x%x\n", __func__, (int)addr);
38 return 0;
41 static void sifive_prci_write(void *opaque, hwaddr addr,
42 uint64_t val64, unsigned int size)
44 /* discard writes */
47 static const MemoryRegionOps sifive_prci_ops = {
48 .read = sifive_prci_read,
49 .write = sifive_prci_write,
50 .endianness = DEVICE_NATIVE_ENDIAN,
51 .valid = {
52 .min_access_size = 4,
53 .max_access_size = 4
57 static void sifive_prci_init(Object *obj)
59 SiFivePRCIState *s = SIFIVE_PRCI(obj);
61 memory_region_init_io(&s->mmio, obj, &sifive_prci_ops, s,
62 TYPE_SIFIVE_PRCI, 0x8000);
63 sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
66 static const TypeInfo sifive_prci_info = {
67 .name = TYPE_SIFIVE_PRCI,
68 .parent = TYPE_SYS_BUS_DEVICE,
69 .instance_size = sizeof(SiFivePRCIState),
70 .instance_init = sifive_prci_init,
73 static void sifive_prci_register_types(void)
75 type_register_static(&sifive_prci_info);
78 type_init(sifive_prci_register_types)
82 * Create PRCI device.
84 DeviceState *sifive_prci_create(hwaddr addr)
86 DeviceState *dev = qdev_create(NULL, TYPE_SIFIVE_PRCI);
87 qdev_init_nofail(dev);
88 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
89 return dev;