xref: /openbmc/qemu/hw/riscv/sifive_u.c (revision 89854803ce3efb16fbc94604e652f152f5102569)
1a7240d1eSMichael Clark /*
2a7240d1eSMichael Clark  * QEMU RISC-V Board Compatible with SiFive Freedom U SDK
3a7240d1eSMichael Clark  *
4a7240d1eSMichael Clark  * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5a7240d1eSMichael Clark  * Copyright (c) 2017 SiFive, Inc.
6a7240d1eSMichael Clark  *
7a7240d1eSMichael Clark  * Provides a board compatible with the SiFive Freedom U SDK:
8a7240d1eSMichael Clark  *
9a7240d1eSMichael Clark  * 0) UART
10a7240d1eSMichael Clark  * 1) CLINT (Core Level Interruptor)
11a7240d1eSMichael Clark  * 2) PLIC (Platform Level Interrupt Controller)
12a7240d1eSMichael Clark  *
13a7240d1eSMichael Clark  * This board currently uses a hardcoded devicetree that indicates one hart.
14a7240d1eSMichael Clark  *
15a7240d1eSMichael Clark  * This program is free software; you can redistribute it and/or modify it
16a7240d1eSMichael Clark  * under the terms and conditions of the GNU General Public License,
17a7240d1eSMichael Clark  * version 2 or later, as published by the Free Software Foundation.
18a7240d1eSMichael Clark  *
19a7240d1eSMichael Clark  * This program is distributed in the hope it will be useful, but WITHOUT
20a7240d1eSMichael Clark  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21a7240d1eSMichael Clark  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
22a7240d1eSMichael Clark  * more details.
23a7240d1eSMichael Clark  *
24a7240d1eSMichael Clark  * You should have received a copy of the GNU General Public License along with
25a7240d1eSMichael Clark  * this program.  If not, see <http://www.gnu.org/licenses/>.
26a7240d1eSMichael Clark  */
27a7240d1eSMichael Clark 
28a7240d1eSMichael Clark #include "qemu/osdep.h"
29a7240d1eSMichael Clark #include "qemu/log.h"
30a7240d1eSMichael Clark #include "qemu/error-report.h"
31a7240d1eSMichael Clark #include "qapi/error.h"
32a7240d1eSMichael Clark #include "hw/hw.h"
33a7240d1eSMichael Clark #include "hw/boards.h"
34a7240d1eSMichael Clark #include "hw/loader.h"
35a7240d1eSMichael Clark #include "hw/sysbus.h"
36a7240d1eSMichael Clark #include "hw/char/serial.h"
37a7240d1eSMichael Clark #include "target/riscv/cpu.h"
38a7240d1eSMichael Clark #include "hw/riscv/riscv_hart.h"
39a7240d1eSMichael Clark #include "hw/riscv/sifive_plic.h"
40a7240d1eSMichael Clark #include "hw/riscv/sifive_clint.h"
41a7240d1eSMichael Clark #include "hw/riscv/sifive_uart.h"
42a7240d1eSMichael Clark #include "hw/riscv/sifive_prci.h"
43a7240d1eSMichael Clark #include "hw/riscv/sifive_u.h"
44a7240d1eSMichael Clark #include "chardev/char.h"
45a7240d1eSMichael Clark #include "sysemu/arch_init.h"
46a7240d1eSMichael Clark #include "sysemu/device_tree.h"
47a7240d1eSMichael Clark #include "exec/address-spaces.h"
48a7240d1eSMichael Clark #include "elf.h"
49a7240d1eSMichael Clark 
50a7240d1eSMichael Clark static const struct MemmapEntry {
51a7240d1eSMichael Clark     hwaddr base;
52a7240d1eSMichael Clark     hwaddr size;
53a7240d1eSMichael Clark } sifive_u_memmap[] = {
54a7240d1eSMichael Clark     [SIFIVE_U_DEBUG] =    {        0x0,      0x100 },
55a7240d1eSMichael Clark     [SIFIVE_U_MROM] =     {     0x1000,     0x2000 },
56a7240d1eSMichael Clark     [SIFIVE_U_CLINT] =    {  0x2000000,    0x10000 },
57a7240d1eSMichael Clark     [SIFIVE_U_PLIC] =     {  0xc000000,  0x4000000 },
58a7240d1eSMichael Clark     [SIFIVE_U_UART0] =    { 0x10013000,     0x1000 },
59a7240d1eSMichael Clark     [SIFIVE_U_UART1] =    { 0x10023000,     0x1000 },
60a7240d1eSMichael Clark     [SIFIVE_U_DRAM] =     { 0x80000000,        0x0 },
61a7240d1eSMichael Clark };
62a7240d1eSMichael Clark 
63a7240d1eSMichael Clark static void copy_le32_to_phys(hwaddr pa, uint32_t *rom, size_t len)
64a7240d1eSMichael Clark {
65a7240d1eSMichael Clark     int i;
66a7240d1eSMichael Clark     for (i = 0; i < (len >> 2); i++) {
67a7240d1eSMichael Clark         stl_phys(&address_space_memory, pa + (i << 2), rom[i]);
68a7240d1eSMichael Clark     }
69a7240d1eSMichael Clark }
70a7240d1eSMichael Clark 
71a7240d1eSMichael Clark static uint64_t load_kernel(const char *kernel_filename)
72a7240d1eSMichael Clark {
73a7240d1eSMichael Clark     uint64_t kernel_entry, kernel_high;
74a7240d1eSMichael Clark 
75b7938980SMichael Clark     if (load_elf(kernel_filename, NULL, NULL,
76a7240d1eSMichael Clark                  &kernel_entry, NULL, &kernel_high,
77*89854803SMichael Clark                  0, EM_RISCV, 1, 0) < 0) {
78a7240d1eSMichael Clark         error_report("qemu: could not load kernel '%s'", kernel_filename);
79a7240d1eSMichael Clark         exit(1);
80a7240d1eSMichael Clark     }
81a7240d1eSMichael Clark     return kernel_entry;
82a7240d1eSMichael Clark }
83a7240d1eSMichael Clark 
84a7240d1eSMichael Clark static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
85a7240d1eSMichael Clark     uint64_t mem_size, const char *cmdline)
86a7240d1eSMichael Clark {
87a7240d1eSMichael Clark     void *fdt;
88a7240d1eSMichael Clark     int cpu;
89a7240d1eSMichael Clark     uint32_t *cells;
90a7240d1eSMichael Clark     char *nodename;
91a7240d1eSMichael Clark     uint32_t plic_phandle;
92a7240d1eSMichael Clark 
93a7240d1eSMichael Clark     fdt = s->fdt = create_device_tree(&s->fdt_size);
94a7240d1eSMichael Clark     if (!fdt) {
95a7240d1eSMichael Clark         error_report("create_device_tree() failed");
96a7240d1eSMichael Clark         exit(1);
97a7240d1eSMichael Clark     }
98a7240d1eSMichael Clark 
99a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, "/", "model", "ucbbar,spike-bare,qemu");
100a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, "/", "compatible", "ucbbar,spike-bare-dev");
101a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2);
102a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
103a7240d1eSMichael Clark 
104a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, "/soc");
105a7240d1eSMichael Clark     qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
106a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, "/soc", "compatible", "ucbbar,spike-bare-soc");
107a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
108a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
109a7240d1eSMichael Clark 
110a7240d1eSMichael Clark     nodename = g_strdup_printf("/memory@%lx",
111a7240d1eSMichael Clark         (long)memmap[SIFIVE_U_DRAM].base);
112a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, nodename);
113a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "reg",
114a7240d1eSMichael Clark         memmap[SIFIVE_U_DRAM].base >> 32, memmap[SIFIVE_U_DRAM].base,
115a7240d1eSMichael Clark         mem_size >> 32, mem_size);
116a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
117a7240d1eSMichael Clark     g_free(nodename);
118a7240d1eSMichael Clark 
119a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, "/cpus");
1202a8756edSMichael Clark     qemu_fdt_setprop_cell(fdt, "/cpus", "timebase-frequency",
1212a8756edSMichael Clark         SIFIVE_CLINT_TIMEBASE_FREQ);
122a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0);
123a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1);
124a7240d1eSMichael Clark 
125a7240d1eSMichael Clark     for (cpu = s->soc.num_harts - 1; cpu >= 0; cpu--) {
126a7240d1eSMichael Clark         nodename = g_strdup_printf("/cpus/cpu@%d", cpu);
127a7240d1eSMichael Clark         char *intc = g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu);
128a7240d1eSMichael Clark         char *isa = riscv_isa_string(&s->soc.harts[cpu]);
129a7240d1eSMichael Clark         qemu_fdt_add_subnode(fdt, nodename);
1302a8756edSMichael Clark         qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
1312a8756edSMichael Clark                               SIFIVE_U_CLOCK_FREQ);
132a7240d1eSMichael Clark         qemu_fdt_setprop_string(fdt, nodename, "mmu-type", "riscv,sv48");
133a7240d1eSMichael Clark         qemu_fdt_setprop_string(fdt, nodename, "riscv,isa", isa);
134a7240d1eSMichael Clark         qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv");
135a7240d1eSMichael Clark         qemu_fdt_setprop_string(fdt, nodename, "status", "okay");
136a7240d1eSMichael Clark         qemu_fdt_setprop_cell(fdt, nodename, "reg", cpu);
137a7240d1eSMichael Clark         qemu_fdt_setprop_string(fdt, nodename, "device_type", "cpu");
138a7240d1eSMichael Clark         qemu_fdt_add_subnode(fdt, intc);
139a7240d1eSMichael Clark         qemu_fdt_setprop_cell(fdt, intc, "phandle", 1);
140a7240d1eSMichael Clark         qemu_fdt_setprop_cell(fdt, intc, "linux,phandle", 1);
141a7240d1eSMichael Clark         qemu_fdt_setprop_string(fdt, intc, "compatible", "riscv,cpu-intc");
142a7240d1eSMichael Clark         qemu_fdt_setprop(fdt, intc, "interrupt-controller", NULL, 0);
143a7240d1eSMichael Clark         qemu_fdt_setprop_cell(fdt, intc, "#interrupt-cells", 1);
144a7240d1eSMichael Clark         g_free(isa);
145a7240d1eSMichael Clark         g_free(intc);
146a7240d1eSMichael Clark         g_free(nodename);
147a7240d1eSMichael Clark     }
148a7240d1eSMichael Clark 
149a7240d1eSMichael Clark     cells =  g_new0(uint32_t, s->soc.num_harts * 4);
150a7240d1eSMichael Clark     for (cpu = 0; cpu < s->soc.num_harts; cpu++) {
151a7240d1eSMichael Clark         nodename =
152a7240d1eSMichael Clark             g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu);
153a7240d1eSMichael Clark         uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename);
154a7240d1eSMichael Clark         cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle);
155a7240d1eSMichael Clark         cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_SOFT);
156a7240d1eSMichael Clark         cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle);
157a7240d1eSMichael Clark         cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER);
158a7240d1eSMichael Clark         g_free(nodename);
159a7240d1eSMichael Clark     }
160a7240d1eSMichael Clark     nodename = g_strdup_printf("/soc/clint@%lx",
161a7240d1eSMichael Clark         (long)memmap[SIFIVE_U_CLINT].base);
162a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, nodename);
163a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,clint0");
164a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "reg",
165a7240d1eSMichael Clark         0x0, memmap[SIFIVE_U_CLINT].base,
166a7240d1eSMichael Clark         0x0, memmap[SIFIVE_U_CLINT].size);
167a7240d1eSMichael Clark     qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
168a7240d1eSMichael Clark         cells, s->soc.num_harts * sizeof(uint32_t) * 4);
169a7240d1eSMichael Clark     g_free(cells);
170a7240d1eSMichael Clark     g_free(nodename);
171a7240d1eSMichael Clark 
172a7240d1eSMichael Clark     cells =  g_new0(uint32_t, s->soc.num_harts * 4);
173a7240d1eSMichael Clark     for (cpu = 0; cpu < s->soc.num_harts; cpu++) {
174a7240d1eSMichael Clark         nodename =
175a7240d1eSMichael Clark             g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu);
176a7240d1eSMichael Clark         uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename);
177a7240d1eSMichael Clark         cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle);
178a7240d1eSMichael Clark         cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT);
179a7240d1eSMichael Clark         cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle);
180a7240d1eSMichael Clark         cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT);
181a7240d1eSMichael Clark         g_free(nodename);
182a7240d1eSMichael Clark     }
183a7240d1eSMichael Clark     nodename = g_strdup_printf("/soc/interrupt-controller@%lx",
184a7240d1eSMichael Clark         (long)memmap[SIFIVE_U_PLIC].base);
185a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, nodename);
186a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1);
187a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,plic0");
188a7240d1eSMichael Clark     qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
189a7240d1eSMichael Clark     qemu_fdt_setprop(fdt, nodename, "interrupts-extended",
190a7240d1eSMichael Clark         cells, s->soc.num_harts * sizeof(uint32_t) * 4);
191a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "reg",
192a7240d1eSMichael Clark         0x0, memmap[SIFIVE_U_PLIC].base,
193a7240d1eSMichael Clark         0x0, memmap[SIFIVE_U_PLIC].size);
194a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control");
195a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, nodename, "riscv,max-priority", 7);
196a7240d1eSMichael Clark     qemu_fdt_setprop_cell(fdt, nodename, "riscv,ndev", 4);
197a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "phandle", 2);
198a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "linux,phandle", 2);
199a7240d1eSMichael Clark     plic_phandle = qemu_fdt_get_phandle(fdt, nodename);
200a7240d1eSMichael Clark     g_free(cells);
201a7240d1eSMichael Clark     g_free(nodename);
202a7240d1eSMichael Clark 
203a7240d1eSMichael Clark     nodename = g_strdup_printf("/uart@%lx",
204a7240d1eSMichael Clark         (long)memmap[SIFIVE_U_UART0].base);
205a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, nodename);
206a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, nodename, "compatible", "sifive,uart0");
207a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "reg",
208a7240d1eSMichael Clark         0x0, memmap[SIFIVE_U_UART0].base,
209a7240d1eSMichael Clark         0x0, memmap[SIFIVE_U_UART0].size);
210a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "interrupt-parent", plic_phandle);
211a7240d1eSMichael Clark     qemu_fdt_setprop_cells(fdt, nodename, "interrupts", 1);
212a7240d1eSMichael Clark 
213a7240d1eSMichael Clark     qemu_fdt_add_subnode(fdt, "/chosen");
214a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
215a7240d1eSMichael Clark     qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
216a7240d1eSMichael Clark     g_free(nodename);
217a7240d1eSMichael Clark }
218a7240d1eSMichael Clark 
219a7240d1eSMichael Clark static void riscv_sifive_u_init(MachineState *machine)
220a7240d1eSMichael Clark {
221a7240d1eSMichael Clark     const struct MemmapEntry *memmap = sifive_u_memmap;
222a7240d1eSMichael Clark 
223a7240d1eSMichael Clark     SiFiveUState *s = g_new0(SiFiveUState, 1);
224a7240d1eSMichael Clark     MemoryRegion *sys_memory = get_system_memory();
225a7240d1eSMichael Clark     MemoryRegion *main_mem = g_new(MemoryRegion, 1);
226a7240d1eSMichael Clark     MemoryRegion *boot_rom = g_new(MemoryRegion, 1);
227a7240d1eSMichael Clark 
228a7240d1eSMichael Clark     /* Initialize SOC */
229a7240d1eSMichael Clark     object_initialize(&s->soc, sizeof(s->soc), TYPE_RISCV_HART_ARRAY);
230a7240d1eSMichael Clark     object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc),
231a7240d1eSMichael Clark                               &error_abort);
232a7240d1eSMichael Clark     object_property_set_str(OBJECT(&s->soc), SIFIVE_U_CPU, "cpu-type",
233a7240d1eSMichael Clark                             &error_abort);
234a7240d1eSMichael Clark     object_property_set_int(OBJECT(&s->soc), smp_cpus, "num-harts",
235a7240d1eSMichael Clark                             &error_abort);
236a7240d1eSMichael Clark     object_property_set_bool(OBJECT(&s->soc), true, "realized",
237a7240d1eSMichael Clark                             &error_abort);
238a7240d1eSMichael Clark 
239a7240d1eSMichael Clark     /* register RAM */
240a7240d1eSMichael Clark     memory_region_init_ram(main_mem, NULL, "riscv.sifive.u.ram",
241a7240d1eSMichael Clark                            machine->ram_size, &error_fatal);
242a7240d1eSMichael Clark     memory_region_add_subregion(sys_memory, memmap[SIFIVE_U_DRAM].base,
243a7240d1eSMichael Clark         main_mem);
244a7240d1eSMichael Clark 
245a7240d1eSMichael Clark     /* create device tree */
246a7240d1eSMichael Clark     create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
247a7240d1eSMichael Clark 
248a7240d1eSMichael Clark     /* boot rom */
249a7240d1eSMichael Clark     memory_region_init_ram(boot_rom, NULL, "riscv.sifive.u.mrom",
250a7240d1eSMichael Clark                            memmap[SIFIVE_U_MROM].base, &error_fatal);
251a7240d1eSMichael Clark     memory_region_set_readonly(boot_rom, true);
252a7240d1eSMichael Clark     memory_region_add_subregion(sys_memory, 0x0, boot_rom);
253a7240d1eSMichael Clark 
254a7240d1eSMichael Clark     if (machine->kernel_filename) {
255a7240d1eSMichael Clark         load_kernel(machine->kernel_filename);
256a7240d1eSMichael Clark     }
257a7240d1eSMichael Clark 
258a7240d1eSMichael Clark     /* reset vector */
259a7240d1eSMichael Clark     uint32_t reset_vec[8] = {
260a7240d1eSMichael Clark         0x00000297,                    /* 1:  auipc  t0, %pcrel_hi(dtb) */
261a7240d1eSMichael Clark         0x02028593,                    /*     addi   a1, t0, %pcrel_lo(1b) */
262a7240d1eSMichael Clark         0xf1402573,                    /*     csrr   a0, mhartid  */
263a7240d1eSMichael Clark #if defined(TARGET_RISCV32)
264a7240d1eSMichael Clark         0x0182a283,                    /*     lw     t0, 24(t0) */
265a7240d1eSMichael Clark #elif defined(TARGET_RISCV64)
266a7240d1eSMichael Clark         0x0182b283,                    /*     ld     t0, 24(t0) */
267a7240d1eSMichael Clark #endif
268a7240d1eSMichael Clark         0x00028067,                    /*     jr     t0 */
269a7240d1eSMichael Clark         0x00000000,
270a7240d1eSMichael Clark         memmap[SIFIVE_U_DRAM].base, /* start: .dword DRAM_BASE */
271a7240d1eSMichael Clark         0x00000000,
272a7240d1eSMichael Clark                                        /* dtb: */
273a7240d1eSMichael Clark     };
274a7240d1eSMichael Clark 
275a7240d1eSMichael Clark     /* copy in the reset vector */
276a7240d1eSMichael Clark     copy_le32_to_phys(memmap[SIFIVE_U_MROM].base, reset_vec, sizeof(reset_vec));
277a7240d1eSMichael Clark 
278a7240d1eSMichael Clark     /* copy in the device tree */
279a7240d1eSMichael Clark     qemu_fdt_dumpdtb(s->fdt, s->fdt_size);
280a7240d1eSMichael Clark     cpu_physical_memory_write(memmap[SIFIVE_U_MROM].base +
281a7240d1eSMichael Clark         sizeof(reset_vec), s->fdt, s->fdt_size);
282a7240d1eSMichael Clark 
283a7240d1eSMichael Clark     /* MMIO */
284a7240d1eSMichael Clark     s->plic = sifive_plic_create(memmap[SIFIVE_U_PLIC].base,
285a7240d1eSMichael Clark         (char *)SIFIVE_U_PLIC_HART_CONFIG,
286a7240d1eSMichael Clark         SIFIVE_U_PLIC_NUM_SOURCES,
287a7240d1eSMichael Clark         SIFIVE_U_PLIC_NUM_PRIORITIES,
288a7240d1eSMichael Clark         SIFIVE_U_PLIC_PRIORITY_BASE,
289a7240d1eSMichael Clark         SIFIVE_U_PLIC_PENDING_BASE,
290a7240d1eSMichael Clark         SIFIVE_U_PLIC_ENABLE_BASE,
291a7240d1eSMichael Clark         SIFIVE_U_PLIC_ENABLE_STRIDE,
292a7240d1eSMichael Clark         SIFIVE_U_PLIC_CONTEXT_BASE,
293a7240d1eSMichael Clark         SIFIVE_U_PLIC_CONTEXT_STRIDE,
294a7240d1eSMichael Clark         memmap[SIFIVE_U_PLIC].size);
295a7240d1eSMichael Clark     sifive_uart_create(sys_memory, memmap[SIFIVE_U_UART0].base,
2969bca0edbSPeter Maydell         serial_hd(0), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART0_IRQ]);
297a7240d1eSMichael Clark     /* sifive_uart_create(sys_memory, memmap[SIFIVE_U_UART1].base,
2989bca0edbSPeter Maydell         serial_hd(1), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART1_IRQ]); */
299a7240d1eSMichael Clark     sifive_clint_create(memmap[SIFIVE_U_CLINT].base,
300a7240d1eSMichael Clark         memmap[SIFIVE_U_CLINT].size, smp_cpus,
301a7240d1eSMichael Clark         SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
302a7240d1eSMichael Clark }
303a7240d1eSMichael Clark 
304a7240d1eSMichael Clark static void riscv_sifive_u_machine_init(MachineClass *mc)
305a7240d1eSMichael Clark {
306a7240d1eSMichael Clark     mc->desc = "RISC-V Board compatible with SiFive U SDK";
307a7240d1eSMichael Clark     mc->init = riscv_sifive_u_init;
308a7240d1eSMichael Clark     mc->max_cpus = 1;
309a7240d1eSMichael Clark }
310a7240d1eSMichael Clark 
311a7240d1eSMichael Clark DEFINE_MACHINE("sifive_u", riscv_sifive_u_machine_init)
312