15b4beba1SMichael Clark /*
25b4beba1SMichael Clark * QEMU RISC-V Spike Board
35b4beba1SMichael Clark *
45b4beba1SMichael Clark * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
55b4beba1SMichael Clark * Copyright (c) 2017-2018 SiFive, Inc.
65b4beba1SMichael Clark *
75b4beba1SMichael Clark * This provides a RISC-V Board with the following devices:
85b4beba1SMichael Clark *
95b4beba1SMichael Clark * 0) HTIF Console and Poweroff
105b4beba1SMichael Clark * 1) CLINT (Timer and IPI)
115b4beba1SMichael Clark *
125b4beba1SMichael Clark * This program is free software; you can redistribute it and/or modify it
135b4beba1SMichael Clark * under the terms and conditions of the GNU General Public License,
145b4beba1SMichael Clark * version 2 or later, as published by the Free Software Foundation.
155b4beba1SMichael Clark *
165b4beba1SMichael Clark * This program is distributed in the hope it will be useful, but WITHOUT
175b4beba1SMichael Clark * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
185b4beba1SMichael Clark * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
195b4beba1SMichael Clark * more details.
205b4beba1SMichael Clark *
215b4beba1SMichael Clark * You should have received a copy of the GNU General Public License along with
225b4beba1SMichael Clark * this program. If not, see <http://www.gnu.org/licenses/>.
235b4beba1SMichael Clark */
245b4beba1SMichael Clark
255b4beba1SMichael Clark #include "qemu/osdep.h"
265b4beba1SMichael Clark #include "qemu/error-report.h"
275b4beba1SMichael Clark #include "qapi/error.h"
285b4beba1SMichael Clark #include "hw/boards.h"
295b4beba1SMichael Clark #include "hw/loader.h"
305b4beba1SMichael Clark #include "hw/sysbus.h"
315b4beba1SMichael Clark #include "target/riscv/cpu.h"
325b4beba1SMichael Clark #include "hw/riscv/riscv_hart.h"
335b4beba1SMichael Clark #include "hw/riscv/spike.h"
340ac24d56SAlistair Francis #include "hw/riscv/boot.h"
35a7172791SAnup Patel #include "hw/riscv/numa.h"
3670eb9f9cSBin Meng #include "hw/char/riscv_htif.h"
37cc63a182SAnup Patel #include "hw/intc/riscv_aclint.h"
385b4beba1SMichael Clark #include "chardev/char.h"
395b4beba1SMichael Clark #include "sysemu/device_tree.h"
4046517dd4SMarkus Armbruster #include "sysemu/sysemu.h"
415aec3247SMichael Clark
42719b718cSDaniel Henrique Barboza #include <libfdt.h>
43719b718cSDaniel Henrique Barboza
4473261285SBin Meng static const MemMapEntry spike_memmap[] = {
459eb8b14aSBin Meng [SPIKE_MROM] = { 0x1000, 0xf000 },
468d8897acSAnup Patel [SPIKE_HTIF] = { 0x1000000, 0x1000 },
475b4beba1SMichael Clark [SPIKE_CLINT] = { 0x2000000, 0x10000 },
485b4beba1SMichael Clark [SPIKE_DRAM] = { 0x80000000, 0x0 },
495b4beba1SMichael Clark };
505b4beba1SMichael Clark
create_fdt(SpikeState * s,const MemMapEntry * memmap,bool is_32_bit,bool htif_custom_base)5173261285SBin Meng static void create_fdt(SpikeState *s, const MemMapEntry *memmap,
5271d68c48SBin Meng bool is_32_bit, bool htif_custom_base)
535b4beba1SMichael Clark {
545b4beba1SMichael Clark void *fdt;
553139929dSDaniel Henrique Barboza int fdt_size;
56a7172791SAnup Patel uint64_t addr, size;
57a7172791SAnup Patel unsigned long clint_addr;
58a7172791SAnup Patel int cpu, socket;
59606a2439SDaniel Henrique Barboza MachineState *ms = MACHINE(s);
60a7172791SAnup Patel uint32_t *clint_cells;
61a7172791SAnup Patel uint32_t cpu_phandle, intc_phandle, phandle = 1;
621c8e491cSConor Dooley char *mem_name, *clint_name, *clust_name;
63a7172791SAnup Patel char *core_name, *cpu_name, *intc_name;
647cfbb17fSBin Meng static const char * const clint_compat[2] = {
657cfbb17fSBin Meng "sifive,clint0", "riscv,clint0"
667cfbb17fSBin Meng };
675b4beba1SMichael Clark
68606a2439SDaniel Henrique Barboza fdt = ms->fdt = create_device_tree(&fdt_size);
695b4beba1SMichael Clark if (!fdt) {
705b4beba1SMichael Clark error_report("create_device_tree() failed");
715b4beba1SMichael Clark exit(1);
725b4beba1SMichael Clark }
735b4beba1SMichael Clark
745b4beba1SMichael Clark qemu_fdt_setprop_string(fdt, "/", "model", "ucbbar,spike-bare,qemu");
755b4beba1SMichael Clark qemu_fdt_setprop_string(fdt, "/", "compatible", "ucbbar,spike-bare-dev");
765b4beba1SMichael Clark qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2);
775b4beba1SMichael Clark qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
785b4beba1SMichael Clark
795b4beba1SMichael Clark qemu_fdt_add_subnode(fdt, "/htif");
805b4beba1SMichael Clark qemu_fdt_setprop_string(fdt, "/htif", "compatible", "ucb,htif0");
8171d68c48SBin Meng if (htif_custom_base) {
828d8897acSAnup Patel qemu_fdt_setprop_cells(fdt, "/htif", "reg",
838d8897acSAnup Patel 0x0, memmap[SPIKE_HTIF].base, 0x0, memmap[SPIKE_HTIF].size);
848d8897acSAnup Patel }
855b4beba1SMichael Clark
865b4beba1SMichael Clark qemu_fdt_add_subnode(fdt, "/soc");
875b4beba1SMichael Clark qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
88117caacfSAlistair Francis qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus");
895b4beba1SMichael Clark qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
905b4beba1SMichael Clark qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
915b4beba1SMichael Clark
925b4beba1SMichael Clark qemu_fdt_add_subnode(fdt, "/cpus");
932a8756edSMichael Clark qemu_fdt_setprop_cell(fdt, "/cpus", "timebase-frequency",
94b8fb878aSAnup Patel RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ);
955b4beba1SMichael Clark qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0);
965b4beba1SMichael Clark qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1);
97a7172791SAnup Patel qemu_fdt_add_subnode(fdt, "/cpus/cpu-map");
985b4beba1SMichael Clark
99606a2439SDaniel Henrique Barboza for (socket = (riscv_socket_count(ms) - 1); socket >= 0; socket--) {
100a7172791SAnup Patel clust_name = g_strdup_printf("/cpus/cpu-map/cluster%d", socket);
101a7172791SAnup Patel qemu_fdt_add_subnode(fdt, clust_name);
102a7172791SAnup Patel
103a7172791SAnup Patel clint_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4);
104a7172791SAnup Patel
105a7172791SAnup Patel for (cpu = s->soc[socket].num_harts - 1; cpu >= 0; cpu--) {
106a7172791SAnup Patel cpu_phandle = phandle++;
107a7172791SAnup Patel
108a7172791SAnup Patel cpu_name = g_strdup_printf("/cpus/cpu@%d",
109a7172791SAnup Patel s->soc[socket].hartid_base + cpu);
110a7172791SAnup Patel qemu_fdt_add_subnode(fdt, cpu_name);
111bd62c13eSAlistair Francis if (is_32_bit) {
112a7172791SAnup Patel qemu_fdt_setprop_string(fdt, cpu_name, "mmu-type", "riscv,sv32");
113bd62c13eSAlistair Francis } else {
114a7172791SAnup Patel qemu_fdt_setprop_string(fdt, cpu_name, "mmu-type", "riscv,sv48");
115bd62c13eSAlistair Francis }
1161c8e491cSConor Dooley riscv_isa_write_fdt(&s->soc[socket].harts[cpu], fdt, cpu_name);
117a7172791SAnup Patel qemu_fdt_setprop_string(fdt, cpu_name, "compatible", "riscv");
118a7172791SAnup Patel qemu_fdt_setprop_string(fdt, cpu_name, "status", "okay");
119a7172791SAnup Patel qemu_fdt_setprop_cell(fdt, cpu_name, "reg",
120a7172791SAnup Patel s->soc[socket].hartid_base + cpu);
121a7172791SAnup Patel qemu_fdt_setprop_string(fdt, cpu_name, "device_type", "cpu");
122606a2439SDaniel Henrique Barboza riscv_socket_fdt_write_id(ms, cpu_name, socket);
123a7172791SAnup Patel qemu_fdt_setprop_cell(fdt, cpu_name, "phandle", cpu_phandle);
124a7172791SAnup Patel
125a7172791SAnup Patel intc_name = g_strdup_printf("%s/interrupt-controller", cpu_name);
126a7172791SAnup Patel qemu_fdt_add_subnode(fdt, intc_name);
127a7172791SAnup Patel intc_phandle = phandle++;
128a7172791SAnup Patel qemu_fdt_setprop_cell(fdt, intc_name, "phandle", intc_phandle);
129a7172791SAnup Patel qemu_fdt_setprop_string(fdt, intc_name, "compatible",
130a7172791SAnup Patel "riscv,cpu-intc");
131a7172791SAnup Patel qemu_fdt_setprop(fdt, intc_name, "interrupt-controller", NULL, 0);
132a7172791SAnup Patel qemu_fdt_setprop_cell(fdt, intc_name, "#interrupt-cells", 1);
133a7172791SAnup Patel
134a7172791SAnup Patel clint_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle);
135a7172791SAnup Patel clint_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_SOFT);
136a7172791SAnup Patel clint_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle);
137a7172791SAnup Patel clint_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER);
138a7172791SAnup Patel
139a7172791SAnup Patel core_name = g_strdup_printf("%s/core%d", clust_name, cpu);
140a7172791SAnup Patel qemu_fdt_add_subnode(fdt, core_name);
141a7172791SAnup Patel qemu_fdt_setprop_cell(fdt, core_name, "cpu", cpu_phandle);
142a7172791SAnup Patel
143a7172791SAnup Patel g_free(core_name);
144a7172791SAnup Patel g_free(intc_name);
145a7172791SAnup Patel g_free(cpu_name);
1465b4beba1SMichael Clark }
1475b4beba1SMichael Clark
148606a2439SDaniel Henrique Barboza addr = memmap[SPIKE_DRAM].base + riscv_socket_mem_offset(ms, socket);
149606a2439SDaniel Henrique Barboza size = riscv_socket_mem_size(ms, socket);
150a7172791SAnup Patel mem_name = g_strdup_printf("/memory@%lx", (long)addr);
151a7172791SAnup Patel qemu_fdt_add_subnode(fdt, mem_name);
152a7172791SAnup Patel qemu_fdt_setprop_cells(fdt, mem_name, "reg",
153a7172791SAnup Patel addr >> 32, addr, size >> 32, size);
154a7172791SAnup Patel qemu_fdt_setprop_string(fdt, mem_name, "device_type", "memory");
155606a2439SDaniel Henrique Barboza riscv_socket_fdt_write_id(ms, mem_name, socket);
156a7172791SAnup Patel g_free(mem_name);
157a7172791SAnup Patel
158a7172791SAnup Patel clint_addr = memmap[SPIKE_CLINT].base +
159a7172791SAnup Patel (memmap[SPIKE_CLINT].size * socket);
160a7172791SAnup Patel clint_name = g_strdup_printf("/soc/clint@%lx", clint_addr);
161a7172791SAnup Patel qemu_fdt_add_subnode(fdt, clint_name);
1627cfbb17fSBin Meng qemu_fdt_setprop_string_array(fdt, clint_name, "compatible",
1637cfbb17fSBin Meng (char **)&clint_compat, ARRAY_SIZE(clint_compat));
164a7172791SAnup Patel qemu_fdt_setprop_cells(fdt, clint_name, "reg",
165a7172791SAnup Patel 0x0, clint_addr, 0x0, memmap[SPIKE_CLINT].size);
166a7172791SAnup Patel qemu_fdt_setprop(fdt, clint_name, "interrupts-extended",
167a7172791SAnup Patel clint_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4);
168606a2439SDaniel Henrique Barboza riscv_socket_fdt_write_id(ms, clint_name, socket);
169a7172791SAnup Patel
170a7172791SAnup Patel g_free(clint_name);
171a7172791SAnup Patel g_free(clint_cells);
172a7172791SAnup Patel g_free(clust_name);
1735b4beba1SMichael Clark }
174a7172791SAnup Patel
175606a2439SDaniel Henrique Barboza riscv_socket_fdt_write_distance_matrix(ms);
1765b4beba1SMichael Clark
1775b4beba1SMichael Clark qemu_fdt_add_subnode(fdt, "/chosen");
1788d8897acSAnup Patel qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif");
1797c28f4daSMichael Clark }
1805b4beba1SMichael Clark
spike_test_elf_image(char * filename)18171d68c48SBin Meng static bool spike_test_elf_image(char *filename)
18271d68c48SBin Meng {
18371d68c48SBin Meng Error *err = NULL;
18471d68c48SBin Meng
18571d68c48SBin Meng load_elf_hdr(filename, NULL, NULL, &err);
18671d68c48SBin Meng if (err) {
18771d68c48SBin Meng error_free(err);
18871d68c48SBin Meng return false;
18971d68c48SBin Meng } else {
19071d68c48SBin Meng return true;
19171d68c48SBin Meng }
19271d68c48SBin Meng }
19371d68c48SBin Meng
spike_board_init(MachineState * machine)194cd69e3a6SAlistair Francis static void spike_board_init(MachineState *machine)
195cd69e3a6SAlistair Francis {
19673261285SBin Meng const MemMapEntry *memmap = spike_memmap;
197a7172791SAnup Patel SpikeState *s = SPIKE_MACHINE(machine);
198cd69e3a6SAlistair Francis MemoryRegion *system_memory = get_system_memory();
199cd69e3a6SAlistair Francis MemoryRegion *mask_rom = g_new(MemoryRegion, 1);
20071d68c48SBin Meng target_ulong firmware_end_addr = memmap[SPIKE_DRAM].base;
201*55c13659SSamuel Holland hwaddr firmware_load_addr = memmap[SPIKE_DRAM].base;
20271d68c48SBin Meng target_ulong kernel_start_addr;
20371d68c48SBin Meng char *firmware_name;
20466b1205bSAtish Patra uint32_t fdt_load_addr;
205dc144fe1SAtish Patra uint64_t kernel_entry;
206a7172791SAnup Patel char *soc_name;
207a7172791SAnup Patel int i, base_hartid, hart_count;
20871d68c48SBin Meng bool htif_custom_base = false;
209cd69e3a6SAlistair Francis
210a7172791SAnup Patel /* Check socket count limit */
211a7172791SAnup Patel if (SPIKE_SOCKETS_MAX < riscv_socket_count(machine)) {
212a7172791SAnup Patel error_report("number of sockets/nodes should be less than %d",
213a7172791SAnup Patel SPIKE_SOCKETS_MAX);
214a7172791SAnup Patel exit(1);
215a7172791SAnup Patel }
216a7172791SAnup Patel
217a7172791SAnup Patel /* Initialize sockets */
218a7172791SAnup Patel for (i = 0; i < riscv_socket_count(machine); i++) {
219a7172791SAnup Patel if (!riscv_socket_check_hartids(machine, i)) {
220a7172791SAnup Patel error_report("discontinuous hartids in socket%d", i);
221a7172791SAnup Patel exit(1);
222a7172791SAnup Patel }
223a7172791SAnup Patel
224a7172791SAnup Patel base_hartid = riscv_socket_first_hartid(machine, i);
225a7172791SAnup Patel if (base_hartid < 0) {
226a7172791SAnup Patel error_report("can't find hartid base for socket%d", i);
227a7172791SAnup Patel exit(1);
228a7172791SAnup Patel }
229a7172791SAnup Patel
230a7172791SAnup Patel hart_count = riscv_socket_hart_count(machine, i);
231a7172791SAnup Patel if (hart_count < 0) {
232a7172791SAnup Patel error_report("can't find hart count for socket%d", i);
233a7172791SAnup Patel exit(1);
234a7172791SAnup Patel }
235a7172791SAnup Patel
236a7172791SAnup Patel soc_name = g_strdup_printf("soc%d", i);
237a7172791SAnup Patel object_initialize_child(OBJECT(machine), soc_name, &s->soc[i],
23875a6ed87SMarkus Armbruster TYPE_RISCV_HART_ARRAY);
239a7172791SAnup Patel g_free(soc_name);
240a7172791SAnup Patel object_property_set_str(OBJECT(&s->soc[i]), "cpu-type",
241a7172791SAnup Patel machine->cpu_type, &error_abort);
242a7172791SAnup Patel object_property_set_int(OBJECT(&s->soc[i]), "hartid-base",
243a7172791SAnup Patel base_hartid, &error_abort);
244a7172791SAnup Patel object_property_set_int(OBJECT(&s->soc[i]), "num-harts",
245a7172791SAnup Patel hart_count, &error_abort);
2464bcfc391STsukasa OI sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
247a7172791SAnup Patel
248a7172791SAnup Patel /* Core Local Interruptor (timer and IPI) for each socket */
249b8fb878aSAnup Patel riscv_aclint_swi_create(
250a7172791SAnup Patel memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size,
251b8fb878aSAnup Patel base_hartid, hart_count, false);
252b8fb878aSAnup Patel riscv_aclint_mtimer_create(
253b8fb878aSAnup Patel memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size +
254b8fb878aSAnup Patel RISCV_ACLINT_SWI_SIZE,
255b8fb878aSAnup Patel RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count,
256b8fb878aSAnup Patel RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
257b8fb878aSAnup Patel RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, false);
258a7172791SAnup Patel }
259cd69e3a6SAlistair Francis
260cd69e3a6SAlistair Francis /* register system main memory (actual RAM) */
261cd69e3a6SAlistair Francis memory_region_add_subregion(system_memory, memmap[SPIKE_DRAM].base,
26211ec06f9SBin Meng machine->ram);
263cd69e3a6SAlistair Francis
264cd69e3a6SAlistair Francis /* boot rom */
265cd69e3a6SAlistair Francis memory_region_init_rom(mask_rom, NULL, "riscv.spike.mrom",
266cd69e3a6SAlistair Francis memmap[SPIKE_MROM].size, &error_fatal);
267cd69e3a6SAlistair Francis memory_region_add_subregion(system_memory, memmap[SPIKE_MROM].base,
268cd69e3a6SAlistair Francis mask_rom);
269cd69e3a6SAlistair Francis
27071d68c48SBin Meng /* Find firmware */
27171d68c48SBin Meng firmware_name = riscv_find_firmware(machine->firmware,
27271d68c48SBin Meng riscv_default_firmware_name(&s->soc[0]));
27371d68c48SBin Meng
27471d68c48SBin Meng /*
27571d68c48SBin Meng * Test the given firmware or kernel file to see if it is an ELF image.
27671d68c48SBin Meng * If it is an ELF, we assume it contains the symbols required for
27771d68c48SBin Meng * the HTIF console, otherwise we fall back to use the custom base
27871d68c48SBin Meng * passed from device tree for the HTIF console.
27971d68c48SBin Meng */
28071d68c48SBin Meng if (!firmware_name && !machine->kernel_filename) {
28171d68c48SBin Meng htif_custom_base = true;
28271d68c48SBin Meng } else {
28371d68c48SBin Meng if (firmware_name) {
28471d68c48SBin Meng htif_custom_base = !spike_test_elf_image(firmware_name);
28571d68c48SBin Meng }
28671d68c48SBin Meng if (!htif_custom_base && machine->kernel_filename) {
28771d68c48SBin Meng htif_custom_base = !spike_test_elf_image(machine->kernel_filename);
28871d68c48SBin Meng }
28971d68c48SBin Meng }
29071d68c48SBin Meng
29171d68c48SBin Meng /* Load firmware */
29271d68c48SBin Meng if (firmware_name) {
29371d68c48SBin Meng firmware_end_addr = riscv_load_firmware(firmware_name,
294*55c13659SSamuel Holland &firmware_load_addr,
2955b8a9863SAnup Patel htif_symbol_callback);
29671d68c48SBin Meng g_free(firmware_name);
29771d68c48SBin Meng }
2985b8a9863SAnup Patel
299c44df400SDaniel Henrique Barboza /* Create device tree */
3005dfe2377SDaniel Henrique Barboza create_fdt(s, memmap, riscv_is_32bit(&s->soc[0]), htif_custom_base);
301c44df400SDaniel Henrique Barboza
3028d8897acSAnup Patel /* Load kernel */
303cd69e3a6SAlistair Francis if (machine->kernel_filename) {
304a8259b53SAlistair Francis kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0],
30538bc4e34SAlistair Francis firmware_end_addr);
30638bc4e34SAlistair Francis
30762c5bc34SDaniel Henrique Barboza kernel_entry = riscv_load_kernel(machine, &s->soc[0],
30862c5bc34SDaniel Henrique Barboza kernel_start_addr,
309487d73fcSDaniel Henrique Barboza true, htif_symbol_callback);
310c44df400SDaniel Henrique Barboza } else {
311c44df400SDaniel Henrique Barboza /*
312c44df400SDaniel Henrique Barboza * If dynamic firmware is used, it doesn't know where is the next mode
313c44df400SDaniel Henrique Barboza * if kernel argument is not set.
314c44df400SDaniel Henrique Barboza */
315c44df400SDaniel Henrique Barboza kernel_entry = 0;
316c44df400SDaniel Henrique Barboza }
317cd69e3a6SAlistair Francis
318bc2c0153SDaniel Henrique Barboza fdt_load_addr = riscv_compute_fdt_addr(memmap[SPIKE_DRAM].base,
3194b402886SDaniel Henrique Barboza memmap[SPIKE_DRAM].size,
3204b402886SDaniel Henrique Barboza machine);
321bc2c0153SDaniel Henrique Barboza riscv_load_fdt(fdt_load_addr, machine->fdt);
322719b718cSDaniel Henrique Barboza
32343cf723aSAtish Patra /* load the reset vector */
324*55c13659SSamuel Holland riscv_setup_rom_reset_vec(machine, &s->soc[0], firmware_load_addr,
32578936771SAlistair Francis memmap[SPIKE_MROM].base,
326dc144fe1SAtish Patra memmap[SPIKE_MROM].size, kernel_entry,
3276934f15bSDaniel Henrique Barboza fdt_load_addr);
328cd69e3a6SAlistair Francis
329cd69e3a6SAlistair Francis /* initialize HTIF using symbols found in load_kernel */
33071d68c48SBin Meng htif_mm_init(system_memory, serial_hd(0), memmap[SPIKE_HTIF].base,
33171d68c48SBin Meng htif_custom_base);
332cd69e3a6SAlistair Francis }
333cd69e3a6SAlistair Francis
spike_set_signature(Object * obj,const char * val,Error ** errp)33466247edcSWeiwei Li static void spike_set_signature(Object *obj, const char *val, Error **errp)
33566247edcSWeiwei Li {
33666247edcSWeiwei Li sig_file = g_strdup(val);
33766247edcSWeiwei Li }
33866247edcSWeiwei Li
spike_machine_instance_init(Object * obj)339a7172791SAnup Patel static void spike_machine_instance_init(Object *obj)
340cd69e3a6SAlistair Francis {
341a7172791SAnup Patel }
342a7172791SAnup Patel
spike_machine_class_init(ObjectClass * oc,void * data)343a7172791SAnup Patel static void spike_machine_class_init(ObjectClass *oc, void *data)
344a7172791SAnup Patel {
345a7172791SAnup Patel MachineClass *mc = MACHINE_CLASS(oc);
346a7172791SAnup Patel
347a7172791SAnup Patel mc->desc = "RISC-V Spike board";
348cd69e3a6SAlistair Francis mc->init = spike_board_init;
349a7172791SAnup Patel mc->max_cpus = SPIKE_CPUS_MAX;
350ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true;
351dc4d4aaeSAlistair Francis mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
352a7172791SAnup Patel mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids;
353a7172791SAnup Patel mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
354a7172791SAnup Patel mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
355a7172791SAnup Patel mc->numa_mem_supported = true;
3563d9981cdSGavin Shan /* platform instead of architectural choice */
3573d9981cdSGavin Shan mc->cpu_cluster_has_numa_boundary = true;
35811ec06f9SBin Meng mc->default_ram_id = "riscv.spike.ram";
35966247edcSWeiwei Li object_class_property_add_str(oc, "signature", NULL, spike_set_signature);
36066247edcSWeiwei Li object_class_property_set_description(oc, "signature",
36166247edcSWeiwei Li "File to write ACT test signature");
36266247edcSWeiwei Li object_class_property_add_uint8_ptr(oc, "signature-granularity",
36366247edcSWeiwei Li &line_size, OBJ_PROP_FLAG_WRITE);
36466247edcSWeiwei Li object_class_property_set_description(oc, "signature-granularity",
36566247edcSWeiwei Li "Size of each line in ACT signature "
36666247edcSWeiwei Li "file");
3675b4beba1SMichael Clark }
3685b4beba1SMichael Clark
369a7172791SAnup Patel static const TypeInfo spike_machine_typeinfo = {
370a7172791SAnup Patel .name = MACHINE_TYPE_NAME("spike"),
371a7172791SAnup Patel .parent = TYPE_MACHINE,
372a7172791SAnup Patel .class_init = spike_machine_class_init,
373a7172791SAnup Patel .instance_init = spike_machine_instance_init,
374a7172791SAnup Patel .instance_size = sizeof(SpikeState),
375a7172791SAnup Patel };
376a7172791SAnup Patel
spike_machine_init_register_types(void)377a7172791SAnup Patel static void spike_machine_init_register_types(void)
378a7172791SAnup Patel {
379a7172791SAnup Patel type_register_static(&spike_machine_typeinfo);
380a7172791SAnup Patel }
381a7172791SAnup Patel
382a7172791SAnup Patel type_init(spike_machine_init_register_types)
383