]> git.proxmox.com Git - mirror_qemu.git/blame - hw/riscv/sifive_u.c
riscv: sifive_u: Add support for loading initrd
[mirror_qemu.git] / hw / riscv / sifive_u.c
CommitLineData
a7240d1e
MC
1/*
2 * QEMU RISC-V Board Compatible with SiFive Freedom U SDK
3 *
4 * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5 * Copyright (c) 2017 SiFive, Inc.
6 *
7 * Provides a board compatible with the SiFive Freedom U SDK:
8 *
9 * 0) UART
10 * 1) CLINT (Core Level Interruptor)
11 * 2) PLIC (Platform Level Interrupt Controller)
12 *
13 * This board currently uses a hardcoded devicetree that indicates one hart.
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms and conditions of the GNU General Public License,
17 * version 2 or later, as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 *
24 * You should have received a copy of the GNU General Public License along with
25 * this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#include "qemu/osdep.h"
29#include "qemu/log.h"
30#include "qemu/error-report.h"
31#include "qapi/error.h"
a7240d1e
MC
32#include "hw/boards.h"
33#include "hw/loader.h"
34#include "hw/sysbus.h"
35#include "hw/char/serial.h"
36#include "target/riscv/cpu.h"
37#include "hw/riscv/riscv_hart.h"
38#include "hw/riscv/sifive_plic.h"
39#include "hw/riscv/sifive_clint.h"
40#include "hw/riscv/sifive_uart.h"
41#include "hw/riscv/sifive_prci.h"
42#include "hw/riscv/sifive_u.h"
0ac24d56 43#include "hw/riscv/boot.h"
a7240d1e
MC
44#include "chardev/char.h"
45#include "sysemu/arch_init.h"
46#include "sysemu/device_tree.h"
46517dd4 47#include "sysemu/sysemu.h"
a7240d1e 48#include "exec/address-spaces.h"
a7240d1e 49
5aec3247
MC
50#include <libfdt.h>
51
fdd1bda4
AF
52#define BIOS_FILENAME "opensbi-riscv64-sifive_u-fw_jump.bin"
53
a7240d1e
MC
54static const struct MemmapEntry {
55 hwaddr base;
56 hwaddr size;
57} sifive_u_memmap[] = {
58 [SIFIVE_U_DEBUG] = { 0x0, 0x100 },
5aec3247 59 [SIFIVE_U_MROM] = { 0x1000, 0x11000 },
a7240d1e
MC
60 [SIFIVE_U_CLINT] = { 0x2000000, 0x10000 },
61 [SIFIVE_U_PLIC] = { 0xc000000, 0x4000000 },
62 [SIFIVE_U_UART0] = { 0x10013000, 0x1000 },
63 [SIFIVE_U_UART1] = { 0x10023000, 0x1000 },
64 [SIFIVE_U_DRAM] = { 0x80000000, 0x0 },
5a7f76a3 65 [SIFIVE_U_GEM] = { 0x100900FC, 0x2000 },
a7240d1e
MC
66};
67
5a7f76a3
AF
68#define GEM_REVISION 0x10070109
69
0f8d4462 70static void *create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
a7240d1e
MC
71 uint64_t mem_size, const char *cmdline)
72{
73 void *fdt;
74 int cpu;
75 uint32_t *cells;
76 char *nodename;
fe93582c 77 char ethclk_names[] = "pclk\0hclk\0tx_clk";
382cb439 78 uint32_t plic_phandle, ethclk_phandle, phandle = 1;
a7240d1e
MC
79
80 fdt = s->fdt = create_device_tree(&s->fdt_size);
81 if (!fdt) {
82 error_report("create_device_tree() failed");
83 exit(1);
84 }
85
86 qemu_fdt_setprop_string(fdt, "/", "model", "ucbbar,spike-bare,qemu");
87 qemu_fdt_setprop_string(fdt, "/", "compatible", "ucbbar,spike-bare-dev");
88 qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2);
89 qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
90
91 qemu_fdt_add_subnode(fdt, "/soc");
92 qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
2a1a6f6d 93 qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus");
a7240d1e
MC
94 qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
95 qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
96
97 nodename = g_strdup_printf("/memory@%lx",
98 (long)memmap[SIFIVE_U_DRAM].base);
99 qemu_fdt_add_subnode(fdt, nodename);
100 qemu_fdt_setprop_cells(fdt, nodename, "reg",
101 memmap[SIFIVE_U_DRAM].base >> 32, memmap[SIFIVE_U_DRAM].base,
102 mem_size >> 32, mem_size);
103 qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
104 g_free(nodename);
105
106 qemu_fdt_add_subnode(fdt, "/cpus");
2a8756ed
MC
107 qemu_fdt_setprop_cell(fdt, "/cpus", "timebase-frequency",
108 SIFIVE_CLINT_TIMEBASE_FREQ);
a7240d1e
MC
109 qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0);
110 qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1);
111
2308092b 112 for (cpu = s->soc.cpus.num_harts - 1; cpu >= 0; cpu--) {
382cb439 113 int cpu_phandle = phandle++;
a7240d1e
MC
114 nodename = g_strdup_printf("/cpus/cpu@%d", cpu);
115 char *intc = g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu);
2308092b 116 char *isa = riscv_isa_string(&s->soc.cpus.harts[cpu]);
a7240d1e 117 qemu_fdt_add_subnode(fdt, nodename);
2a8756ed
MC
118 qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
119 SIFIVE_U_CLOCK_FREQ);
a7240d1e
MC
120 qemu_fdt_setprop_string(fdt, nodename, "mmu-type", "riscv,sv48");
121 qemu_fdt_setprop_string(fdt, nodename, "riscv,isa", isa);
122 qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv");
123 qemu_fdt_setprop_string(fdt, nodename, "status", "okay");
124 qemu_fdt_setprop_cell(fdt, nodename, "reg", cpu);
125 qemu_fdt_setprop_string(fdt, nodename, "device_type", "cpu");
126 qemu_fdt_add_subnode(fdt, intc);
382cb439
BM
127 qemu_fdt_setprop_cell(fdt, intc, "phandle", cpu_phandle);
128 qemu_fdt_setprop_cell(fdt, intc, "linux,phandle", cpu_phandle);
a7240d1e
MC
129 qemu_fdt_setprop_string(fdt, intc, "compatible", "riscv,cpu-intc");
130 qemu_fdt_setprop(fdt, intc, "interrupt-controller", NULL, 0);
131 qemu_fdt_setprop_cell(fdt, intc, "#interrupt-cells", 1);
132 g_free(isa);
133 g_free(intc);
134 g_free(nodename);
135 }
136
2308092b
AF
137 cells = g_new0(uint32_t, s->soc.cpus.num_harts * 4);
138 for (cpu = 0; cpu < s->soc.cpus.num_harts; cpu++) {
a7240d1e
MC
139 nodename =
140 g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu);
141 uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename);
142 cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle);
143 cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_SOFT);
144 cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle);
145 cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER);
146 g_free(nodename);
147 }
148 nodename = g_strdup_printf("/soc/clint@%lx",
149 (long)memmap[SIFIVE_U_CLINT].base);
150 qemu_fdt_add_subnode(fdt, nodename);
151 qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,clint0");
152 qemu_fdt_setprop_cells(fdt, nodename, "reg",
153 0x0, memmap[SIFIVE_U_CLINT].base,
154 0x0, memmap[SIFIVE_U_CLINT].size);
155 qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
2308092b 156 cells, s->soc.cpus.num_harts * sizeof(uint32_t) * 4);
a7240d1e
MC
157 g_free(cells);
158 g_free(nodename);
159
382cb439 160 plic_phandle = phandle++;
2308092b
AF
161 cells = g_new0(uint32_t, s->soc.cpus.num_harts * 4);
162 for (cpu = 0; cpu < s->soc.cpus.num_harts; cpu++) {
a7240d1e
MC
163 nodename =
164 g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu);
165 uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename);
166 cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle);
167 cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT);
168 cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle);
169 cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT);
170 g_free(nodename);
171 }
172 nodename = g_strdup_printf("/soc/interrupt-controller@%lx",
173 (long)memmap[SIFIVE_U_PLIC].base);
174 qemu_fdt_add_subnode(fdt, nodename);
175 qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1);
176 qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,plic0");
177 qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
178 qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
2308092b 179 cells, s->soc.cpus.num_harts * sizeof(uint32_t) * 4);
a7240d1e
MC
180 qemu_fdt_setprop_cells(fdt, nodename, "reg",
181 0x0, memmap[SIFIVE_U_PLIC].base,
182 0x0, memmap[SIFIVE_U_PLIC].size);
183 qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control");
184 qemu_fdt_setprop_cell(fdt, nodename, "riscv,max-priority", 7);
98ceee7f 185 qemu_fdt_setprop_cell(fdt, nodename, "riscv,ndev", 0x35);
382cb439
BM
186 qemu_fdt_setprop_cells(fdt, nodename, "phandle", plic_phandle);
187 qemu_fdt_setprop_cells(fdt, nodename, "linux,phandle", plic_phandle);
a7240d1e
MC
188 plic_phandle = qemu_fdt_get_phandle(fdt, nodename);
189 g_free(cells);
190 g_free(nodename);
191
382cb439 192 ethclk_phandle = phandle++;
fe93582c
AP
193 nodename = g_strdup_printf("/soc/ethclk");
194 qemu_fdt_add_subnode(fdt, nodename);
195 qemu_fdt_setprop_string(fdt, nodename, "compatible", "fixed-clock");
196 qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x0);
197 qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
198 SIFIVE_U_GEM_CLOCK_FREQ);
382cb439
BM
199 qemu_fdt_setprop_cell(fdt, nodename, "phandle", ethclk_phandle);
200 qemu_fdt_setprop_cell(fdt, nodename, "linux,phandle", ethclk_phandle);
fe93582c
AP
201 ethclk_phandle = qemu_fdt_get_phandle(fdt, nodename);
202 g_free(nodename);
203
5a7f76a3
AF
204 nodename = g_strdup_printf("/soc/ethernet@%lx",
205 (long)memmap[SIFIVE_U_GEM].base);
206 qemu_fdt_add_subnode(fdt, nodename);
207 qemu_fdt_setprop_string(fdt, nodename, "compatible", "cdns,macb");
208 qemu_fdt_setprop_cells(fdt, nodename, "reg",
209 0x0, memmap[SIFIVE_U_GEM].base,
210 0x0, memmap[SIFIVE_U_GEM].size);
211 qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control");
212 qemu_fdt_setprop_string(fdt, nodename, "phy-mode", "gmii");
213 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-parent", plic_phandle);
214 qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_GEM_IRQ);
fe93582c
AP
215 qemu_fdt_setprop_cells(fdt, nodename, "clocks",
216 ethclk_phandle, ethclk_phandle, ethclk_phandle);
217 qemu_fdt_setprop(fdt, nodename, "clocks-names", ethclk_names,
218 sizeof(ethclk_names));
5a7f76a3
AF
219 qemu_fdt_setprop_cells(fdt, nodename, "#address-cells", 1);
220 qemu_fdt_setprop_cells(fdt, nodename, "#size-cells", 0);
221 g_free(nodename);
222
223 nodename = g_strdup_printf("/soc/ethernet@%lx/ethernet-phy@0",
224 (long)memmap[SIFIVE_U_GEM].base);
225 qemu_fdt_add_subnode(fdt, nodename);
226 qemu_fdt_setprop_cells(fdt, nodename, "reg", 0x0);
227 g_free(nodename);
228
bde3ab9a 229 nodename = g_strdup_printf("/soc/uart@%lx",
a7240d1e
MC
230 (long)memmap[SIFIVE_U_UART0].base);
231 qemu_fdt_add_subnode(fdt, nodename);
232 qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,uart0");
233 qemu_fdt_setprop_cells(fdt, nodename, "reg",
234 0x0, memmap[SIFIVE_U_UART0].base,
235 0x0, memmap[SIFIVE_U_UART0].size);
6c60757e
AP
236 qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
237 SIFIVE_U_CLOCK_FREQ / 2);
a7240d1e 238 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-parent", plic_phandle);
a9ec1c76 239 qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_UART0_IRQ);
a7240d1e
MC
240
241 qemu_fdt_add_subnode(fdt, "/chosen");
242 qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
7c28f4da
MC
243 if (cmdline) {
244 qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
245 }
a7240d1e 246 g_free(nodename);
0f8d4462
GR
247
248 return fdt;
a7240d1e
MC
249}
250
251static void riscv_sifive_u_init(MachineState *machine)
252{
253 const struct MemmapEntry *memmap = sifive_u_memmap;
0f8d4462 254 void *fdt;
a7240d1e
MC
255
256 SiFiveUState *s = g_new0(SiFiveUState, 1);
5aec3247 257 MemoryRegion *system_memory = get_system_memory();
a7240d1e 258 MemoryRegion *main_mem = g_new(MemoryRegion, 1);
5aec3247 259 int i;
a7240d1e 260
2308092b 261 /* Initialize SoC */
4eea9d7d
AF
262 object_initialize_child(OBJECT(machine), "soc", &s->soc,
263 sizeof(s->soc), TYPE_RISCV_U_SOC,
264 &error_abort, NULL);
a7240d1e
MC
265 object_property_set_bool(OBJECT(&s->soc), true, "realized",
266 &error_abort);
267
268 /* register RAM */
269 memory_region_init_ram(main_mem, NULL, "riscv.sifive.u.ram",
270 machine->ram_size, &error_fatal);
5aec3247 271 memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DRAM].base,
2308092b 272 main_mem);
a7240d1e
MC
273
274 /* create device tree */
0f8d4462 275 fdt = create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
a7240d1e 276
fdd1bda4
AF
277 riscv_find_and_load_firmware(machine, BIOS_FILENAME,
278 memmap[SIFIVE_U_DRAM].base);
b3042223 279
a7240d1e 280 if (machine->kernel_filename) {
0f8d4462
GR
281 uint64_t kernel_entry = riscv_load_kernel(machine->kernel_filename);
282
283 if (machine->initrd_filename) {
284 hwaddr start;
285 hwaddr end = riscv_load_initrd(machine->initrd_filename,
286 machine->ram_size, kernel_entry,
287 &start);
288 qemu_fdt_setprop_cell(fdt, "/chosen",
289 "linux,initrd-start", start);
290 qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
291 end);
292 }
a7240d1e
MC
293 }
294
295 /* reset vector */
296 uint32_t reset_vec[8] = {
297 0x00000297, /* 1: auipc t0, %pcrel_hi(dtb) */
298 0x02028593, /* addi a1, t0, %pcrel_lo(1b) */
299 0xf1402573, /* csrr a0, mhartid */
300#if defined(TARGET_RISCV32)
301 0x0182a283, /* lw t0, 24(t0) */
302#elif defined(TARGET_RISCV64)
303 0x0182b283, /* ld t0, 24(t0) */
304#endif
305 0x00028067, /* jr t0 */
306 0x00000000,
307 memmap[SIFIVE_U_DRAM].base, /* start: .dword DRAM_BASE */
308 0x00000000,
309 /* dtb: */
310 };
311
5aec3247
MC
312 /* copy in the reset vector in little_endian byte order */
313 for (i = 0; i < sizeof(reset_vec) >> 2; i++) {
314 reset_vec[i] = cpu_to_le32(reset_vec[i]);
315 }
316 rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec),
317 memmap[SIFIVE_U_MROM].base, &address_space_memory);
a7240d1e
MC
318
319 /* copy in the device tree */
5aec3247
MC
320 if (fdt_pack(s->fdt) || fdt_totalsize(s->fdt) >
321 memmap[SIFIVE_U_MROM].size - sizeof(reset_vec)) {
322 error_report("not enough space to store device-tree");
323 exit(1);
324 }
325 qemu_fdt_dumpdtb(s->fdt, fdt_totalsize(s->fdt));
326 rom_add_blob_fixed_as("mrom.fdt", s->fdt, fdt_totalsize(s->fdt),
327 memmap[SIFIVE_U_MROM].base + sizeof(reset_vec),
328 &address_space_memory);
2308092b
AF
329}
330
331static void riscv_sifive_u_soc_init(Object *obj)
332{
c4473127 333 MachineState *ms = MACHINE(qdev_get_machine());
2308092b
AF
334 SiFiveUSoCState *s = RISCV_U_SOC(obj);
335
4eea9d7d
AF
336 object_initialize_child(obj, "cpus", &s->cpus, sizeof(s->cpus),
337 TYPE_RISCV_HART_ARRAY, &error_abort, NULL);
2308092b
AF
338 object_property_set_str(OBJECT(&s->cpus), SIFIVE_U_CPU, "cpu-type",
339 &error_abort);
c4473127 340 object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
2308092b 341 &error_abort);
5a7f76a3 342
4eea9d7d
AF
343 sysbus_init_child_obj(obj, "gem", &s->gem, sizeof(s->gem),
344 TYPE_CADENCE_GEM);
2308092b
AF
345}
346
347static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
348{
c4473127 349 MachineState *ms = MACHINE(qdev_get_machine());
2308092b
AF
350 SiFiveUSoCState *s = RISCV_U_SOC(dev);
351 const struct MemmapEntry *memmap = sifive_u_memmap;
352 MemoryRegion *system_memory = get_system_memory();
353 MemoryRegion *mask_rom = g_new(MemoryRegion, 1);
5a7f76a3 354 qemu_irq plic_gpios[SIFIVE_U_PLIC_NUM_SOURCES];
05446f41
BM
355 char *plic_hart_config;
356 size_t plic_hart_config_len;
5a7f76a3
AF
357 int i;
358 Error *err = NULL;
359 NICInfo *nd = &nd_table[0];
2308092b
AF
360
361 object_property_set_bool(OBJECT(&s->cpus), true, "realized",
362 &error_abort);
363
364 /* boot rom */
365 memory_region_init_rom(mask_rom, NULL, "riscv.sifive.u.mrom",
366 memmap[SIFIVE_U_MROM].size, &error_fatal);
367 memory_region_add_subregion(system_memory, memmap[SIFIVE_U_MROM].base,
368 mask_rom);
a7240d1e 369
05446f41 370 /* create PLIC hart topology configuration string */
c4473127
LX
371 plic_hart_config_len = (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1) *
372 ms->smp.cpus;
05446f41 373 plic_hart_config = g_malloc0(plic_hart_config_len);
c4473127 374 for (i = 0; i < ms->smp.cpus; i++) {
05446f41
BM
375 if (i != 0) {
376 strncat(plic_hart_config, ",", plic_hart_config_len);
377 }
378 strncat(plic_hart_config, SIFIVE_U_PLIC_HART_CONFIG,
379 plic_hart_config_len);
380 plic_hart_config_len -= (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1);
381 }
382
a7240d1e
MC
383 /* MMIO */
384 s->plic = sifive_plic_create(memmap[SIFIVE_U_PLIC].base,
05446f41 385 plic_hart_config,
a7240d1e
MC
386 SIFIVE_U_PLIC_NUM_SOURCES,
387 SIFIVE_U_PLIC_NUM_PRIORITIES,
388 SIFIVE_U_PLIC_PRIORITY_BASE,
389 SIFIVE_U_PLIC_PENDING_BASE,
390 SIFIVE_U_PLIC_ENABLE_BASE,
391 SIFIVE_U_PLIC_ENABLE_STRIDE,
392 SIFIVE_U_PLIC_CONTEXT_BASE,
393 SIFIVE_U_PLIC_CONTEXT_STRIDE,
394 memmap[SIFIVE_U_PLIC].size);
5aec3247 395 sifive_uart_create(system_memory, memmap[SIFIVE_U_UART0].base,
647a70a1 396 serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ));
194eef09
MC
397 sifive_uart_create(system_memory, memmap[SIFIVE_U_UART1].base,
398 serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART1_IRQ));
a7240d1e 399 sifive_clint_create(memmap[SIFIVE_U_CLINT].base,
c4473127 400 memmap[SIFIVE_U_CLINT].size, ms->smp.cpus,
a7240d1e 401 SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
5a7f76a3
AF
402
403 for (i = 0; i < SIFIVE_U_PLIC_NUM_SOURCES; i++) {
404 plic_gpios[i] = qdev_get_gpio_in(DEVICE(s->plic), i);
405 }
406
407 if (nd->used) {
408 qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
409 qdev_set_nic_properties(DEVICE(&s->gem), nd);
410 }
411 object_property_set_int(OBJECT(&s->gem), GEM_REVISION, "revision",
412 &error_abort);
413 object_property_set_bool(OBJECT(&s->gem), true, "realized", &err);
414 if (err) {
415 error_propagate(errp, err);
416 return;
417 }
418 sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem), 0, memmap[SIFIVE_U_GEM].base);
419 sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem), 0,
420 plic_gpios[SIFIVE_U_GEM_IRQ]);
a7240d1e
MC
421}
422
a7240d1e
MC
423static void riscv_sifive_u_machine_init(MachineClass *mc)
424{
425 mc->desc = "RISC-V Board compatible with SiFive U SDK";
426 mc->init = riscv_sifive_u_init;
8b1d0714
AF
427 /* The real hardware has 5 CPUs, but one of them is a small embedded power
428 * management CPU.
429 */
430 mc->max_cpus = 4;
a7240d1e
MC
431}
432
433DEFINE_MACHINE("sifive_u", riscv_sifive_u_machine_init)
2308092b
AF
434
435static void riscv_sifive_u_soc_class_init(ObjectClass *oc, void *data)
436{
437 DeviceClass *dc = DEVICE_CLASS(oc);
438
439 dc->realize = riscv_sifive_u_soc_realize;
440 /* Reason: Uses serial_hds in realize function, thus can't be used twice */
441 dc->user_creatable = false;
442}
443
444static const TypeInfo riscv_sifive_u_soc_type_info = {
445 .name = TYPE_RISCV_U_SOC,
446 .parent = TYPE_DEVICE,
447 .instance_size = sizeof(SiFiveUSoCState),
448 .instance_init = riscv_sifive_u_soc_init,
449 .class_init = riscv_sifive_u_soc_class_init,
450};
451
452static void riscv_sifive_u_soc_register_types(void)
453{
454 type_register_static(&riscv_sifive_u_soc_type_info);
455}
456
457type_init(riscv_sifive_u_soc_register_types)