]> git.proxmox.com Git - mirror_qemu.git/blob - hw/riscv/sifive_prci.c
Include qemu/module.h where needed, drop it from qemu-common.h
[mirror_qemu.git] / hw / riscv / sifive_prci.c
1 /*
2 * QEMU SiFive PRCI (Power, Reset, Clock, Interrupt)
3 *
4 * Copyright (c) 2017 SiFive, Inc.
5 *
6 * Simple model of the PRCI to emulate register reads made by the SDK BSP
7 *
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.
11 *
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.
16 *
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/>.
19 */
20
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"
26
27 /* currently implements enough to mock freedom-e-sdk BSP clock programming */
28
29 static uint64_t sifive_prci_read(void *opaque, hwaddr addr, unsigned int size)
30 {
31 if (addr == 0 /* PRCI_HFROSCCFG */) {
32 return 1 << 31; /* ROSC_RDY */
33 }
34 if (addr == 8 /* PRCI_PLLCFG */) {
35 return 1 << 31; /* PLL_LOCK */
36 }
37 hw_error("%s: read: addr=0x%x\n", __func__, (int)addr);
38 return 0;
39 }
40
41 static void sifive_prci_write(void *opaque, hwaddr addr,
42 uint64_t val64, unsigned int size)
43 {
44 /* discard writes */
45 }
46
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
54 }
55 };
56
57 static void sifive_prci_init(Object *obj)
58 {
59 SiFivePRCIState *s = SIFIVE_PRCI(obj);
60
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);
64 }
65
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,
71 };
72
73 static void sifive_prci_register_types(void)
74 {
75 type_register_static(&sifive_prci_info);
76 }
77
78 type_init(sifive_prci_register_types)
79
80
81 /*
82 * Create PRCI device.
83 */
84 DeviceState *sifive_prci_create(hwaddr addr)
85 {
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;
90 }