2 * QEMU RISC-V VirtIO Board
4 * Copyright (c) 2017 SiFive, Inc.
6 * RISC-V machine with 16550a UART and VirtIO MMIO
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
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 "qemu/units.h"
23 #include "qemu/error-report.h"
24 #include "qapi/error.h"
25 #include "hw/boards.h"
26 #include "hw/loader.h"
27 #include "hw/sysbus.h"
28 #include "hw/qdev-properties.h"
29 #include "hw/char/serial.h"
30 #include "target/riscv/cpu.h"
31 #include "hw/riscv/riscv_hart.h"
32 #include "hw/riscv/virt.h"
33 #include "hw/riscv/boot.h"
34 #include "hw/riscv/numa.h"
35 #include "hw/intc/riscv_aclint.h"
36 #include "hw/intc/sifive_plic.h"
37 #include "hw/misc/sifive_test.h"
38 #include "chardev/char.h"
39 #include "sysemu/device_tree.h"
40 #include "sysemu/sysemu.h"
41 #include "hw/pci/pci.h"
42 #include "hw/pci-host/gpex.h"
43 #include "hw/display/ramfb.h"
45 static const MemMapEntry virt_memmap
[] = {
46 [VIRT_DEBUG
] = { 0x0, 0x100 },
47 [VIRT_MROM
] = { 0x1000, 0xf000 },
48 [VIRT_TEST
] = { 0x100000, 0x1000 },
49 [VIRT_RTC
] = { 0x101000, 0x1000 },
50 [VIRT_CLINT
] = { 0x2000000, 0x10000 },
51 [VIRT_ACLINT_SSWI
] = { 0x2F00000, 0x4000 },
52 [VIRT_PCIE_PIO
] = { 0x3000000, 0x10000 },
53 [VIRT_PLIC
] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX
* 2) },
54 [VIRT_UART0
] = { 0x10000000, 0x100 },
55 [VIRT_VIRTIO
] = { 0x10001000, 0x1000 },
56 [VIRT_FW_CFG
] = { 0x10100000, 0x18 },
57 [VIRT_FLASH
] = { 0x20000000, 0x4000000 },
58 [VIRT_PCIE_ECAM
] = { 0x30000000, 0x10000000 },
59 [VIRT_PCIE_MMIO
] = { 0x40000000, 0x40000000 },
60 [VIRT_DRAM
] = { 0x80000000, 0x0 },
63 /* PCIe high mmio is fixed for RV32 */
64 #define VIRT32_HIGH_PCIE_MMIO_BASE 0x300000000ULL
65 #define VIRT32_HIGH_PCIE_MMIO_SIZE (4 * GiB)
67 /* PCIe high mmio for RV64, size is fixed but base depends on top of RAM */
68 #define VIRT64_HIGH_PCIE_MMIO_SIZE (16 * GiB)
70 static MemMapEntry virt_high_pcie_memmap
;
72 #define VIRT_FLASH_SECTOR_SIZE (256 * KiB)
74 static PFlashCFI01
*virt_flash_create1(RISCVVirtState
*s
,
76 const char *alias_prop_name
)
79 * Create a single flash device. We use the same parameters as
80 * the flash devices on the ARM virt board.
82 DeviceState
*dev
= qdev_new(TYPE_PFLASH_CFI01
);
84 qdev_prop_set_uint64(dev
, "sector-length", VIRT_FLASH_SECTOR_SIZE
);
85 qdev_prop_set_uint8(dev
, "width", 4);
86 qdev_prop_set_uint8(dev
, "device-width", 2);
87 qdev_prop_set_bit(dev
, "big-endian", false);
88 qdev_prop_set_uint16(dev
, "id0", 0x89);
89 qdev_prop_set_uint16(dev
, "id1", 0x18);
90 qdev_prop_set_uint16(dev
, "id2", 0x00);
91 qdev_prop_set_uint16(dev
, "id3", 0x00);
92 qdev_prop_set_string(dev
, "name", name
);
94 object_property_add_child(OBJECT(s
), name
, OBJECT(dev
));
95 object_property_add_alias(OBJECT(s
), alias_prop_name
,
96 OBJECT(dev
), "drive");
98 return PFLASH_CFI01(dev
);
101 static void virt_flash_create(RISCVVirtState
*s
)
103 s
->flash
[0] = virt_flash_create1(s
, "virt.flash0", "pflash0");
104 s
->flash
[1] = virt_flash_create1(s
, "virt.flash1", "pflash1");
107 static void virt_flash_map1(PFlashCFI01
*flash
,
108 hwaddr base
, hwaddr size
,
109 MemoryRegion
*sysmem
)
111 DeviceState
*dev
= DEVICE(flash
);
113 assert(QEMU_IS_ALIGNED(size
, VIRT_FLASH_SECTOR_SIZE
));
114 assert(size
/ VIRT_FLASH_SECTOR_SIZE
<= UINT32_MAX
);
115 qdev_prop_set_uint32(dev
, "num-blocks", size
/ VIRT_FLASH_SECTOR_SIZE
);
116 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
118 memory_region_add_subregion(sysmem
, base
,
119 sysbus_mmio_get_region(SYS_BUS_DEVICE(dev
),
123 static void virt_flash_map(RISCVVirtState
*s
,
124 MemoryRegion
*sysmem
)
126 hwaddr flashsize
= virt_memmap
[VIRT_FLASH
].size
/ 2;
127 hwaddr flashbase
= virt_memmap
[VIRT_FLASH
].base
;
129 virt_flash_map1(s
->flash
[0], flashbase
, flashsize
,
131 virt_flash_map1(s
->flash
[1], flashbase
+ flashsize
, flashsize
,
135 static void create_pcie_irq_map(void *fdt
, char *nodename
,
136 uint32_t plic_phandle
)
140 full_irq_map
[GPEX_NUM_IRQS
* GPEX_NUM_IRQS
* FDT_INT_MAP_WIDTH
] = {};
141 uint32_t *irq_map
= full_irq_map
;
143 /* This code creates a standard swizzle of interrupts such that
144 * each device's first interrupt is based on it's PCI_SLOT number.
145 * (See pci_swizzle_map_irq_fn())
147 * We only need one entry per interrupt in the table (not one per
148 * possible slot) seeing the interrupt-map-mask will allow the table
149 * to wrap to any number of devices.
151 for (dev
= 0; dev
< GPEX_NUM_IRQS
; dev
++) {
152 int devfn
= dev
* 0x8;
154 for (pin
= 0; pin
< GPEX_NUM_IRQS
; pin
++) {
155 int irq_nr
= PCIE_IRQ
+ ((pin
+ PCI_SLOT(devfn
)) % GPEX_NUM_IRQS
);
158 irq_map
[i
] = cpu_to_be32(devfn
<< 8);
160 i
+= FDT_PCI_ADDR_CELLS
;
161 irq_map
[i
] = cpu_to_be32(pin
+ 1);
163 i
+= FDT_PCI_INT_CELLS
;
164 irq_map
[i
++] = cpu_to_be32(plic_phandle
);
166 i
+= FDT_PLIC_ADDR_CELLS
;
167 irq_map
[i
] = cpu_to_be32(irq_nr
);
169 irq_map
+= FDT_INT_MAP_WIDTH
;
173 qemu_fdt_setprop(fdt
, nodename
, "interrupt-map",
174 full_irq_map
, sizeof(full_irq_map
));
176 qemu_fdt_setprop_cells(fdt
, nodename
, "interrupt-map-mask",
180 static void create_fdt_socket_cpus(RISCVVirtState
*s
, int socket
,
181 char *clust_name
, uint32_t *phandle
,
182 bool is_32_bit
, uint32_t *intc_phandles
)
185 uint32_t cpu_phandle
;
186 MachineState
*mc
= MACHINE(s
);
187 char *name
, *cpu_name
, *core_name
, *intc_name
;
189 for (cpu
= s
->soc
[socket
].num_harts
- 1; cpu
>= 0; cpu
--) {
190 cpu_phandle
= (*phandle
)++;
192 cpu_name
= g_strdup_printf("/cpus/cpu@%d",
193 s
->soc
[socket
].hartid_base
+ cpu
);
194 qemu_fdt_add_subnode(mc
->fdt
, cpu_name
);
195 qemu_fdt_setprop_string(mc
->fdt
, cpu_name
, "mmu-type",
196 (is_32_bit
) ? "riscv,sv32" : "riscv,sv48");
197 name
= riscv_isa_string(&s
->soc
[socket
].harts
[cpu
]);
198 qemu_fdt_setprop_string(mc
->fdt
, cpu_name
, "riscv,isa", name
);
200 qemu_fdt_setprop_string(mc
->fdt
, cpu_name
, "compatible", "riscv");
201 qemu_fdt_setprop_string(mc
->fdt
, cpu_name
, "status", "okay");
202 qemu_fdt_setprop_cell(mc
->fdt
, cpu_name
, "reg",
203 s
->soc
[socket
].hartid_base
+ cpu
);
204 qemu_fdt_setprop_string(mc
->fdt
, cpu_name
, "device_type", "cpu");
205 riscv_socket_fdt_write_id(mc
, mc
->fdt
, cpu_name
, socket
);
206 qemu_fdt_setprop_cell(mc
->fdt
, cpu_name
, "phandle", cpu_phandle
);
208 intc_phandles
[cpu
] = (*phandle
)++;
210 intc_name
= g_strdup_printf("%s/interrupt-controller", cpu_name
);
211 qemu_fdt_add_subnode(mc
->fdt
, intc_name
);
212 qemu_fdt_setprop_cell(mc
->fdt
, intc_name
, "phandle",
214 qemu_fdt_setprop_string(mc
->fdt
, intc_name
, "compatible",
216 qemu_fdt_setprop(mc
->fdt
, intc_name
, "interrupt-controller", NULL
, 0);
217 qemu_fdt_setprop_cell(mc
->fdt
, intc_name
, "#interrupt-cells", 1);
219 core_name
= g_strdup_printf("%s/core%d", clust_name
, cpu
);
220 qemu_fdt_add_subnode(mc
->fdt
, core_name
);
221 qemu_fdt_setprop_cell(mc
->fdt
, core_name
, "cpu", cpu_phandle
);
229 static void create_fdt_socket_memory(RISCVVirtState
*s
,
230 const MemMapEntry
*memmap
, int socket
)
234 MachineState
*mc
= MACHINE(s
);
236 addr
= memmap
[VIRT_DRAM
].base
+ riscv_socket_mem_offset(mc
, socket
);
237 size
= riscv_socket_mem_size(mc
, socket
);
238 mem_name
= g_strdup_printf("/memory@%lx", (long)addr
);
239 qemu_fdt_add_subnode(mc
->fdt
, mem_name
);
240 qemu_fdt_setprop_cells(mc
->fdt
, mem_name
, "reg",
241 addr
>> 32, addr
, size
>> 32, size
);
242 qemu_fdt_setprop_string(mc
->fdt
, mem_name
, "device_type", "memory");
243 riscv_socket_fdt_write_id(mc
, mc
->fdt
, mem_name
, socket
);
247 static void create_fdt_socket_clint(RISCVVirtState
*s
,
248 const MemMapEntry
*memmap
, int socket
,
249 uint32_t *intc_phandles
)
253 uint32_t *clint_cells
;
254 unsigned long clint_addr
;
255 MachineState
*mc
= MACHINE(s
);
256 static const char * const clint_compat
[2] = {
257 "sifive,clint0", "riscv,clint0"
260 clint_cells
= g_new0(uint32_t, s
->soc
[socket
].num_harts
* 4);
262 for (cpu
= 0; cpu
< s
->soc
[socket
].num_harts
; cpu
++) {
263 clint_cells
[cpu
* 4 + 0] = cpu_to_be32(intc_phandles
[cpu
]);
264 clint_cells
[cpu
* 4 + 1] = cpu_to_be32(IRQ_M_SOFT
);
265 clint_cells
[cpu
* 4 + 2] = cpu_to_be32(intc_phandles
[cpu
]);
266 clint_cells
[cpu
* 4 + 3] = cpu_to_be32(IRQ_M_TIMER
);
269 clint_addr
= memmap
[VIRT_CLINT
].base
+ (memmap
[VIRT_CLINT
].size
* socket
);
270 clint_name
= g_strdup_printf("/soc/clint@%lx", clint_addr
);
271 qemu_fdt_add_subnode(mc
->fdt
, clint_name
);
272 qemu_fdt_setprop_string_array(mc
->fdt
, clint_name
, "compatible",
273 (char **)&clint_compat
,
274 ARRAY_SIZE(clint_compat
));
275 qemu_fdt_setprop_cells(mc
->fdt
, clint_name
, "reg",
276 0x0, clint_addr
, 0x0, memmap
[VIRT_CLINT
].size
);
277 qemu_fdt_setprop(mc
->fdt
, clint_name
, "interrupts-extended",
278 clint_cells
, s
->soc
[socket
].num_harts
* sizeof(uint32_t) * 4);
279 riscv_socket_fdt_write_id(mc
, mc
->fdt
, clint_name
, socket
);
285 static void create_fdt_socket_aclint(RISCVVirtState
*s
,
286 const MemMapEntry
*memmap
, int socket
,
287 uint32_t *intc_phandles
)
292 uint32_t aclint_cells_size
;
293 uint32_t *aclint_mswi_cells
;
294 uint32_t *aclint_sswi_cells
;
295 uint32_t *aclint_mtimer_cells
;
296 MachineState
*mc
= MACHINE(s
);
298 aclint_mswi_cells
= g_new0(uint32_t, s
->soc
[socket
].num_harts
* 2);
299 aclint_mtimer_cells
= g_new0(uint32_t, s
->soc
[socket
].num_harts
* 2);
300 aclint_sswi_cells
= g_new0(uint32_t, s
->soc
[socket
].num_harts
* 2);
302 for (cpu
= 0; cpu
< s
->soc
[socket
].num_harts
; cpu
++) {
303 aclint_mswi_cells
[cpu
* 2 + 0] = cpu_to_be32(intc_phandles
[cpu
]);
304 aclint_mswi_cells
[cpu
* 2 + 1] = cpu_to_be32(IRQ_M_SOFT
);
305 aclint_mtimer_cells
[cpu
* 2 + 0] = cpu_to_be32(intc_phandles
[cpu
]);
306 aclint_mtimer_cells
[cpu
* 2 + 1] = cpu_to_be32(IRQ_M_TIMER
);
307 aclint_sswi_cells
[cpu
* 2 + 0] = cpu_to_be32(intc_phandles
[cpu
]);
308 aclint_sswi_cells
[cpu
* 2 + 1] = cpu_to_be32(IRQ_S_SOFT
);
310 aclint_cells_size
= s
->soc
[socket
].num_harts
* sizeof(uint32_t) * 2;
312 addr
= memmap
[VIRT_CLINT
].base
+ (memmap
[VIRT_CLINT
].size
* socket
);
313 name
= g_strdup_printf("/soc/mswi@%lx", addr
);
314 qemu_fdt_add_subnode(mc
->fdt
, name
);
315 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "riscv,aclint-mswi");
316 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
317 0x0, addr
, 0x0, RISCV_ACLINT_SWI_SIZE
);
318 qemu_fdt_setprop(mc
->fdt
, name
, "interrupts-extended",
319 aclint_mswi_cells
, aclint_cells_size
);
320 qemu_fdt_setprop(mc
->fdt
, name
, "interrupt-controller", NULL
, 0);
321 qemu_fdt_setprop_cell(mc
->fdt
, name
, "#interrupt-cells", 0);
322 riscv_socket_fdt_write_id(mc
, mc
->fdt
, name
, socket
);
325 addr
= memmap
[VIRT_CLINT
].base
+ RISCV_ACLINT_SWI_SIZE
+
326 (memmap
[VIRT_CLINT
].size
* socket
);
327 name
= g_strdup_printf("/soc/mtimer@%lx", addr
);
328 qemu_fdt_add_subnode(mc
->fdt
, name
);
329 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible",
330 "riscv,aclint-mtimer");
331 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
332 0x0, addr
+ RISCV_ACLINT_DEFAULT_MTIME
,
333 0x0, memmap
[VIRT_CLINT
].size
- RISCV_ACLINT_SWI_SIZE
-
334 RISCV_ACLINT_DEFAULT_MTIME
,
335 0x0, addr
+ RISCV_ACLINT_DEFAULT_MTIMECMP
,
336 0x0, RISCV_ACLINT_DEFAULT_MTIME
);
337 qemu_fdt_setprop(mc
->fdt
, name
, "interrupts-extended",
338 aclint_mtimer_cells
, aclint_cells_size
);
339 riscv_socket_fdt_write_id(mc
, mc
->fdt
, name
, socket
);
342 addr
= memmap
[VIRT_ACLINT_SSWI
].base
+
343 (memmap
[VIRT_ACLINT_SSWI
].size
* socket
);
344 name
= g_strdup_printf("/soc/sswi@%lx", addr
);
345 qemu_fdt_add_subnode(mc
->fdt
, name
);
346 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "riscv,aclint-sswi");
347 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
348 0x0, addr
, 0x0, memmap
[VIRT_ACLINT_SSWI
].size
);
349 qemu_fdt_setprop(mc
->fdt
, name
, "interrupts-extended",
350 aclint_sswi_cells
, aclint_cells_size
);
351 qemu_fdt_setprop(mc
->fdt
, name
, "interrupt-controller", NULL
, 0);
352 qemu_fdt_setprop_cell(mc
->fdt
, name
, "#interrupt-cells", 0);
353 riscv_socket_fdt_write_id(mc
, mc
->fdt
, name
, socket
);
356 g_free(aclint_mswi_cells
);
357 g_free(aclint_mtimer_cells
);
358 g_free(aclint_sswi_cells
);
361 static void create_fdt_socket_plic(RISCVVirtState
*s
,
362 const MemMapEntry
*memmap
, int socket
,
363 uint32_t *phandle
, uint32_t *intc_phandles
,
364 uint32_t *plic_phandles
)
368 uint32_t *plic_cells
;
369 unsigned long plic_addr
;
370 MachineState
*mc
= MACHINE(s
);
371 static const char * const plic_compat
[2] = {
372 "sifive,plic-1.0.0", "riscv,plic0"
375 plic_cells
= g_new0(uint32_t, s
->soc
[socket
].num_harts
* 4);
377 for (cpu
= 0; cpu
< s
->soc
[socket
].num_harts
; cpu
++) {
378 plic_cells
[cpu
* 4 + 0] = cpu_to_be32(intc_phandles
[cpu
]);
379 plic_cells
[cpu
* 4 + 1] = cpu_to_be32(IRQ_M_EXT
);
380 plic_cells
[cpu
* 4 + 2] = cpu_to_be32(intc_phandles
[cpu
]);
381 plic_cells
[cpu
* 4 + 3] = cpu_to_be32(IRQ_S_EXT
);
384 plic_phandles
[socket
] = (*phandle
)++;
385 plic_addr
= memmap
[VIRT_PLIC
].base
+ (memmap
[VIRT_PLIC
].size
* socket
);
386 plic_name
= g_strdup_printf("/soc/plic@%lx", plic_addr
);
387 qemu_fdt_add_subnode(mc
->fdt
, plic_name
);
388 qemu_fdt_setprop_cell(mc
->fdt
, plic_name
,
389 "#address-cells", FDT_PLIC_ADDR_CELLS
);
390 qemu_fdt_setprop_cell(mc
->fdt
, plic_name
,
391 "#interrupt-cells", FDT_PLIC_INT_CELLS
);
392 qemu_fdt_setprop_string_array(mc
->fdt
, plic_name
, "compatible",
393 (char **)&plic_compat
,
394 ARRAY_SIZE(plic_compat
));
395 qemu_fdt_setprop(mc
->fdt
, plic_name
, "interrupt-controller", NULL
, 0);
396 qemu_fdt_setprop(mc
->fdt
, plic_name
, "interrupts-extended",
397 plic_cells
, s
->soc
[socket
].num_harts
* sizeof(uint32_t) * 4);
398 qemu_fdt_setprop_cells(mc
->fdt
, plic_name
, "reg",
399 0x0, plic_addr
, 0x0, memmap
[VIRT_PLIC
].size
);
400 qemu_fdt_setprop_cell(mc
->fdt
, plic_name
, "riscv,ndev", VIRTIO_NDEV
);
401 riscv_socket_fdt_write_id(mc
, mc
->fdt
, plic_name
, socket
);
402 qemu_fdt_setprop_cell(mc
->fdt
, plic_name
, "phandle",
403 plic_phandles
[socket
]);
409 static void create_fdt_sockets(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
410 bool is_32_bit
, uint32_t *phandle
,
411 uint32_t *irq_mmio_phandle
,
412 uint32_t *irq_pcie_phandle
,
413 uint32_t *irq_virtio_phandle
)
417 uint32_t *intc_phandles
;
418 MachineState
*mc
= MACHINE(s
);
419 uint32_t xplic_phandles
[MAX_NODES
];
421 qemu_fdt_add_subnode(mc
->fdt
, "/cpus");
422 qemu_fdt_setprop_cell(mc
->fdt
, "/cpus", "timebase-frequency",
423 RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ
);
424 qemu_fdt_setprop_cell(mc
->fdt
, "/cpus", "#size-cells", 0x0);
425 qemu_fdt_setprop_cell(mc
->fdt
, "/cpus", "#address-cells", 0x1);
426 qemu_fdt_add_subnode(mc
->fdt
, "/cpus/cpu-map");
428 for (socket
= (riscv_socket_count(mc
) - 1); socket
>= 0; socket
--) {
429 clust_name
= g_strdup_printf("/cpus/cpu-map/cluster%d", socket
);
430 qemu_fdt_add_subnode(mc
->fdt
, clust_name
);
432 intc_phandles
= g_new0(uint32_t, s
->soc
[socket
].num_harts
);
434 create_fdt_socket_cpus(s
, socket
, clust_name
, phandle
,
435 is_32_bit
, intc_phandles
);
437 create_fdt_socket_memory(s
, memmap
, socket
);
439 if (s
->have_aclint
) {
440 create_fdt_socket_aclint(s
, memmap
, socket
, intc_phandles
);
442 create_fdt_socket_clint(s
, memmap
, socket
, intc_phandles
);
445 create_fdt_socket_plic(s
, memmap
, socket
, phandle
,
446 intc_phandles
, xplic_phandles
);
448 g_free(intc_phandles
);
452 for (socket
= 0; socket
< riscv_socket_count(mc
); socket
++) {
454 *irq_mmio_phandle
= xplic_phandles
[socket
];
455 *irq_virtio_phandle
= xplic_phandles
[socket
];
456 *irq_pcie_phandle
= xplic_phandles
[socket
];
459 *irq_virtio_phandle
= xplic_phandles
[socket
];
460 *irq_pcie_phandle
= xplic_phandles
[socket
];
463 *irq_pcie_phandle
= xplic_phandles
[socket
];
467 riscv_socket_fdt_write_distance_matrix(mc
, mc
->fdt
);
470 static void create_fdt_virtio(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
471 uint32_t irq_virtio_phandle
)
475 MachineState
*mc
= MACHINE(s
);
477 for (i
= 0; i
< VIRTIO_COUNT
; i
++) {
478 name
= g_strdup_printf("/soc/virtio_mmio@%lx",
479 (long)(memmap
[VIRT_VIRTIO
].base
+ i
* memmap
[VIRT_VIRTIO
].size
));
480 qemu_fdt_add_subnode(mc
->fdt
, name
);
481 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "virtio,mmio");
482 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
483 0x0, memmap
[VIRT_VIRTIO
].base
+ i
* memmap
[VIRT_VIRTIO
].size
,
484 0x0, memmap
[VIRT_VIRTIO
].size
);
485 qemu_fdt_setprop_cell(mc
->fdt
, name
, "interrupt-parent",
487 qemu_fdt_setprop_cell(mc
->fdt
, name
, "interrupts", VIRTIO_IRQ
+ i
);
492 static void create_fdt_pcie(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
493 uint32_t irq_pcie_phandle
)
496 MachineState
*mc
= MACHINE(s
);
498 name
= g_strdup_printf("/soc/pci@%lx",
499 (long) memmap
[VIRT_PCIE_ECAM
].base
);
500 qemu_fdt_add_subnode(mc
->fdt
, name
);
501 qemu_fdt_setprop_cell(mc
->fdt
, name
, "#address-cells",
503 qemu_fdt_setprop_cell(mc
->fdt
, name
, "#interrupt-cells",
505 qemu_fdt_setprop_cell(mc
->fdt
, name
, "#size-cells", 0x2);
506 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible",
507 "pci-host-ecam-generic");
508 qemu_fdt_setprop_string(mc
->fdt
, name
, "device_type", "pci");
509 qemu_fdt_setprop_cell(mc
->fdt
, name
, "linux,pci-domain", 0);
510 qemu_fdt_setprop_cells(mc
->fdt
, name
, "bus-range", 0,
511 memmap
[VIRT_PCIE_ECAM
].size
/ PCIE_MMCFG_SIZE_MIN
- 1);
512 qemu_fdt_setprop(mc
->fdt
, name
, "dma-coherent", NULL
, 0);
513 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg", 0,
514 memmap
[VIRT_PCIE_ECAM
].base
, 0, memmap
[VIRT_PCIE_ECAM
].size
);
515 qemu_fdt_setprop_sized_cells(mc
->fdt
, name
, "ranges",
516 1, FDT_PCI_RANGE_IOPORT
, 2, 0,
517 2, memmap
[VIRT_PCIE_PIO
].base
, 2, memmap
[VIRT_PCIE_PIO
].size
,
518 1, FDT_PCI_RANGE_MMIO
,
519 2, memmap
[VIRT_PCIE_MMIO
].base
,
520 2, memmap
[VIRT_PCIE_MMIO
].base
, 2, memmap
[VIRT_PCIE_MMIO
].size
,
521 1, FDT_PCI_RANGE_MMIO_64BIT
,
522 2, virt_high_pcie_memmap
.base
,
523 2, virt_high_pcie_memmap
.base
, 2, virt_high_pcie_memmap
.size
);
525 create_pcie_irq_map(mc
->fdt
, name
, irq_pcie_phandle
);
529 static void create_fdt_reset(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
533 uint32_t test_phandle
;
534 MachineState
*mc
= MACHINE(s
);
536 test_phandle
= (*phandle
)++;
537 name
= g_strdup_printf("/soc/test@%lx",
538 (long)memmap
[VIRT_TEST
].base
);
539 qemu_fdt_add_subnode(mc
->fdt
, name
);
541 static const char * const compat
[3] = {
542 "sifive,test1", "sifive,test0", "syscon"
544 qemu_fdt_setprop_string_array(mc
->fdt
, name
, "compatible",
545 (char **)&compat
, ARRAY_SIZE(compat
));
547 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
548 0x0, memmap
[VIRT_TEST
].base
, 0x0, memmap
[VIRT_TEST
].size
);
549 qemu_fdt_setprop_cell(mc
->fdt
, name
, "phandle", test_phandle
);
550 test_phandle
= qemu_fdt_get_phandle(mc
->fdt
, name
);
553 name
= g_strdup_printf("/soc/reboot");
554 qemu_fdt_add_subnode(mc
->fdt
, name
);
555 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "syscon-reboot");
556 qemu_fdt_setprop_cell(mc
->fdt
, name
, "regmap", test_phandle
);
557 qemu_fdt_setprop_cell(mc
->fdt
, name
, "offset", 0x0);
558 qemu_fdt_setprop_cell(mc
->fdt
, name
, "value", FINISHER_RESET
);
561 name
= g_strdup_printf("/soc/poweroff");
562 qemu_fdt_add_subnode(mc
->fdt
, name
);
563 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "syscon-poweroff");
564 qemu_fdt_setprop_cell(mc
->fdt
, name
, "regmap", test_phandle
);
565 qemu_fdt_setprop_cell(mc
->fdt
, name
, "offset", 0x0);
566 qemu_fdt_setprop_cell(mc
->fdt
, name
, "value", FINISHER_PASS
);
570 static void create_fdt_uart(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
571 uint32_t irq_mmio_phandle
)
574 MachineState
*mc
= MACHINE(s
);
576 name
= g_strdup_printf("/soc/uart@%lx", (long)memmap
[VIRT_UART0
].base
);
577 qemu_fdt_add_subnode(mc
->fdt
, name
);
578 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "ns16550a");
579 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
580 0x0, memmap
[VIRT_UART0
].base
,
581 0x0, memmap
[VIRT_UART0
].size
);
582 qemu_fdt_setprop_cell(mc
->fdt
, name
, "clock-frequency", 3686400);
583 qemu_fdt_setprop_cell(mc
->fdt
, name
, "interrupt-parent", irq_mmio_phandle
);
584 qemu_fdt_setprop_cell(mc
->fdt
, name
, "interrupts", UART0_IRQ
);
586 qemu_fdt_add_subnode(mc
->fdt
, "/chosen");
587 qemu_fdt_setprop_string(mc
->fdt
, "/chosen", "stdout-path", name
);
591 static void create_fdt_rtc(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
592 uint32_t irq_mmio_phandle
)
595 MachineState
*mc
= MACHINE(s
);
597 name
= g_strdup_printf("/soc/rtc@%lx", (long)memmap
[VIRT_RTC
].base
);
598 qemu_fdt_add_subnode(mc
->fdt
, name
);
599 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible",
600 "google,goldfish-rtc");
601 qemu_fdt_setprop_cells(mc
->fdt
, name
, "reg",
602 0x0, memmap
[VIRT_RTC
].base
, 0x0, memmap
[VIRT_RTC
].size
);
603 qemu_fdt_setprop_cell(mc
->fdt
, name
, "interrupt-parent",
605 qemu_fdt_setprop_cell(mc
->fdt
, name
, "interrupts", RTC_IRQ
);
609 static void create_fdt_flash(RISCVVirtState
*s
, const MemMapEntry
*memmap
)
612 MachineState
*mc
= MACHINE(s
);
613 hwaddr flashsize
= virt_memmap
[VIRT_FLASH
].size
/ 2;
614 hwaddr flashbase
= virt_memmap
[VIRT_FLASH
].base
;
616 name
= g_strdup_printf("/flash@%" PRIx64
, flashbase
);
617 qemu_fdt_add_subnode(mc
->fdt
, name
);
618 qemu_fdt_setprop_string(mc
->fdt
, name
, "compatible", "cfi-flash");
619 qemu_fdt_setprop_sized_cells(mc
->fdt
, name
, "reg",
620 2, flashbase
, 2, flashsize
,
621 2, flashbase
+ flashsize
, 2, flashsize
);
622 qemu_fdt_setprop_cell(mc
->fdt
, name
, "bank-width", 4);
626 static void create_fdt(RISCVVirtState
*s
, const MemMapEntry
*memmap
,
627 uint64_t mem_size
, const char *cmdline
, bool is_32_bit
)
629 MachineState
*mc
= MACHINE(s
);
630 uint32_t phandle
= 1, irq_mmio_phandle
= 1;
631 uint32_t irq_pcie_phandle
= 1, irq_virtio_phandle
= 1;
634 mc
->fdt
= load_device_tree(mc
->dtb
, &s
->fdt_size
);
636 error_report("load_device_tree() failed");
639 goto update_bootargs
;
641 mc
->fdt
= create_device_tree(&s
->fdt_size
);
643 error_report("create_device_tree() failed");
648 qemu_fdt_setprop_string(mc
->fdt
, "/", "model", "riscv-virtio,qemu");
649 qemu_fdt_setprop_string(mc
->fdt
, "/", "compatible", "riscv-virtio");
650 qemu_fdt_setprop_cell(mc
->fdt
, "/", "#size-cells", 0x2);
651 qemu_fdt_setprop_cell(mc
->fdt
, "/", "#address-cells", 0x2);
653 qemu_fdt_add_subnode(mc
->fdt
, "/soc");
654 qemu_fdt_setprop(mc
->fdt
, "/soc", "ranges", NULL
, 0);
655 qemu_fdt_setprop_string(mc
->fdt
, "/soc", "compatible", "simple-bus");
656 qemu_fdt_setprop_cell(mc
->fdt
, "/soc", "#size-cells", 0x2);
657 qemu_fdt_setprop_cell(mc
->fdt
, "/soc", "#address-cells", 0x2);
659 create_fdt_sockets(s
, memmap
, is_32_bit
, &phandle
,
660 &irq_mmio_phandle
, &irq_pcie_phandle
, &irq_virtio_phandle
);
662 create_fdt_virtio(s
, memmap
, irq_virtio_phandle
);
664 create_fdt_pcie(s
, memmap
, irq_pcie_phandle
);
666 create_fdt_reset(s
, memmap
, &phandle
);
668 create_fdt_uart(s
, memmap
, irq_mmio_phandle
);
670 create_fdt_rtc(s
, memmap
, irq_mmio_phandle
);
672 create_fdt_flash(s
, memmap
);
676 qemu_fdt_setprop_string(mc
->fdt
, "/chosen", "bootargs", cmdline
);
680 static inline DeviceState
*gpex_pcie_init(MemoryRegion
*sys_mem
,
681 hwaddr ecam_base
, hwaddr ecam_size
,
682 hwaddr mmio_base
, hwaddr mmio_size
,
683 hwaddr high_mmio_base
,
684 hwaddr high_mmio_size
,
689 MemoryRegion
*ecam_alias
, *ecam_reg
;
690 MemoryRegion
*mmio_alias
, *high_mmio_alias
, *mmio_reg
;
694 dev
= qdev_new(TYPE_GPEX_HOST
);
696 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
698 ecam_alias
= g_new0(MemoryRegion
, 1);
699 ecam_reg
= sysbus_mmio_get_region(SYS_BUS_DEVICE(dev
), 0);
700 memory_region_init_alias(ecam_alias
, OBJECT(dev
), "pcie-ecam",
701 ecam_reg
, 0, ecam_size
);
702 memory_region_add_subregion(get_system_memory(), ecam_base
, ecam_alias
);
704 mmio_alias
= g_new0(MemoryRegion
, 1);
705 mmio_reg
= sysbus_mmio_get_region(SYS_BUS_DEVICE(dev
), 1);
706 memory_region_init_alias(mmio_alias
, OBJECT(dev
), "pcie-mmio",
707 mmio_reg
, mmio_base
, mmio_size
);
708 memory_region_add_subregion(get_system_memory(), mmio_base
, mmio_alias
);
710 /* Map high MMIO space */
711 high_mmio_alias
= g_new0(MemoryRegion
, 1);
712 memory_region_init_alias(high_mmio_alias
, OBJECT(dev
), "pcie-mmio-high",
713 mmio_reg
, high_mmio_base
, high_mmio_size
);
714 memory_region_add_subregion(get_system_memory(), high_mmio_base
,
717 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 2, pio_base
);
719 for (i
= 0; i
< GPEX_NUM_IRQS
; i
++) {
720 irq
= qdev_get_gpio_in(plic
, PCIE_IRQ
+ i
);
722 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), i
, irq
);
723 gpex_set_irq_num(GPEX_HOST(dev
), i
, PCIE_IRQ
+ i
);
729 static FWCfgState
*create_fw_cfg(const MachineState
*mc
)
731 hwaddr base
= virt_memmap
[VIRT_FW_CFG
].base
;
732 hwaddr size
= virt_memmap
[VIRT_FW_CFG
].size
;
736 fw_cfg
= fw_cfg_init_mem_wide(base
+ 8, base
, 8, base
+ 16,
737 &address_space_memory
);
738 fw_cfg_add_i16(fw_cfg
, FW_CFG_NB_CPUS
, (uint16_t)mc
->smp
.cpus
);
740 nodename
= g_strdup_printf("/fw-cfg@%" PRIx64
, base
);
741 qemu_fdt_add_subnode(mc
->fdt
, nodename
);
742 qemu_fdt_setprop_string(mc
->fdt
, nodename
,
743 "compatible", "qemu,fw-cfg-mmio");
744 qemu_fdt_setprop_sized_cells(mc
->fdt
, nodename
, "reg",
746 qemu_fdt_setprop(mc
->fdt
, nodename
, "dma-coherent", NULL
, 0);
752 * Return the per-socket PLIC hart topology configuration string
753 * (caller must free with g_free())
755 static char *plic_hart_config_string(int hart_count
)
757 g_autofree
const char **vals
= g_new(const char *, hart_count
+ 1);
760 for (i
= 0; i
< hart_count
; i
++) {
761 vals
[i
] = VIRT_PLIC_HART_CONFIG
;
765 /* g_strjoinv() obliges us to cast away const here */
766 return g_strjoinv(",", (char **)vals
);
769 static void virt_machine_init(MachineState
*machine
)
771 const MemMapEntry
*memmap
= virt_memmap
;
772 RISCVVirtState
*s
= RISCV_VIRT_MACHINE(machine
);
773 MemoryRegion
*system_memory
= get_system_memory();
774 MemoryRegion
*main_mem
= g_new(MemoryRegion
, 1);
775 MemoryRegion
*mask_rom
= g_new(MemoryRegion
, 1);
776 char *plic_hart_config
, *soc_name
;
777 target_ulong start_addr
= memmap
[VIRT_DRAM
].base
;
778 target_ulong firmware_end_addr
, kernel_start_addr
;
779 uint32_t fdt_load_addr
;
780 uint64_t kernel_entry
;
781 DeviceState
*mmio_plic
, *virtio_plic
, *pcie_plic
;
782 int i
, base_hartid
, hart_count
;
784 /* Check socket count limit */
785 if (VIRT_SOCKETS_MAX
< riscv_socket_count(machine
)) {
786 error_report("number of sockets/nodes should be less than %d",
791 /* Initialize sockets */
792 mmio_plic
= virtio_plic
= pcie_plic
= NULL
;
793 for (i
= 0; i
< riscv_socket_count(machine
); i
++) {
794 if (!riscv_socket_check_hartids(machine
, i
)) {
795 error_report("discontinuous hartids in socket%d", i
);
799 base_hartid
= riscv_socket_first_hartid(machine
, i
);
800 if (base_hartid
< 0) {
801 error_report("can't find hartid base for socket%d", i
);
805 hart_count
= riscv_socket_hart_count(machine
, i
);
806 if (hart_count
< 0) {
807 error_report("can't find hart count for socket%d", i
);
811 soc_name
= g_strdup_printf("soc%d", i
);
812 object_initialize_child(OBJECT(machine
), soc_name
, &s
->soc
[i
],
813 TYPE_RISCV_HART_ARRAY
);
815 object_property_set_str(OBJECT(&s
->soc
[i
]), "cpu-type",
816 machine
->cpu_type
, &error_abort
);
817 object_property_set_int(OBJECT(&s
->soc
[i
]), "hartid-base",
818 base_hartid
, &error_abort
);
819 object_property_set_int(OBJECT(&s
->soc
[i
]), "num-harts",
820 hart_count
, &error_abort
);
821 sysbus_realize(SYS_BUS_DEVICE(&s
->soc
[i
]), &error_abort
);
823 /* Per-socket CLINT */
824 riscv_aclint_swi_create(
825 memmap
[VIRT_CLINT
].base
+ i
* memmap
[VIRT_CLINT
].size
,
826 base_hartid
, hart_count
, false);
827 riscv_aclint_mtimer_create(
828 memmap
[VIRT_CLINT
].base
+ i
* memmap
[VIRT_CLINT
].size
+
829 RISCV_ACLINT_SWI_SIZE
,
830 RISCV_ACLINT_DEFAULT_MTIMER_SIZE
, base_hartid
, hart_count
,
831 RISCV_ACLINT_DEFAULT_MTIMECMP
, RISCV_ACLINT_DEFAULT_MTIME
,
832 RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ
, true);
834 /* Per-socket ACLINT SSWI */
835 if (s
->have_aclint
) {
836 riscv_aclint_swi_create(
837 memmap
[VIRT_ACLINT_SSWI
].base
+
838 i
* memmap
[VIRT_ACLINT_SSWI
].size
,
839 base_hartid
, hart_count
, true);
842 /* Per-socket PLIC hart topology configuration string */
843 plic_hart_config
= plic_hart_config_string(hart_count
);
845 /* Per-socket PLIC */
846 s
->plic
[i
] = sifive_plic_create(
847 memmap
[VIRT_PLIC
].base
+ i
* memmap
[VIRT_PLIC
].size
,
848 plic_hart_config
, hart_count
, base_hartid
,
849 VIRT_PLIC_NUM_SOURCES
,
850 VIRT_PLIC_NUM_PRIORITIES
,
851 VIRT_PLIC_PRIORITY_BASE
,
852 VIRT_PLIC_PENDING_BASE
,
853 VIRT_PLIC_ENABLE_BASE
,
854 VIRT_PLIC_ENABLE_STRIDE
,
855 VIRT_PLIC_CONTEXT_BASE
,
856 VIRT_PLIC_CONTEXT_STRIDE
,
857 memmap
[VIRT_PLIC
].size
);
858 g_free(plic_hart_config
);
860 /* Try to use different PLIC instance based device type */
862 mmio_plic
= s
->plic
[i
];
863 virtio_plic
= s
->plic
[i
];
864 pcie_plic
= s
->plic
[i
];
867 virtio_plic
= s
->plic
[i
];
868 pcie_plic
= s
->plic
[i
];
871 pcie_plic
= s
->plic
[i
];
875 if (riscv_is_32bit(&s
->soc
[0])) {
876 #if HOST_LONG_BITS == 64
877 /* limit RAM size in a 32-bit system */
878 if (machine
->ram_size
> 10 * GiB
) {
879 machine
->ram_size
= 10 * GiB
;
880 error_report("Limiting RAM size to 10 GiB");
883 virt_high_pcie_memmap
.base
= VIRT32_HIGH_PCIE_MMIO_BASE
;
884 virt_high_pcie_memmap
.size
= VIRT32_HIGH_PCIE_MMIO_SIZE
;
886 virt_high_pcie_memmap
.size
= VIRT64_HIGH_PCIE_MMIO_SIZE
;
887 virt_high_pcie_memmap
.base
= memmap
[VIRT_DRAM
].base
+ machine
->ram_size
;
888 virt_high_pcie_memmap
.base
=
889 ROUND_UP(virt_high_pcie_memmap
.base
, virt_high_pcie_memmap
.size
);
892 /* register system main memory (actual RAM) */
893 memory_region_init_ram(main_mem
, NULL
, "riscv_virt_board.ram",
894 machine
->ram_size
, &error_fatal
);
895 memory_region_add_subregion(system_memory
, memmap
[VIRT_DRAM
].base
,
898 /* create device tree */
899 create_fdt(s
, memmap
, machine
->ram_size
, machine
->kernel_cmdline
,
900 riscv_is_32bit(&s
->soc
[0]));
903 memory_region_init_rom(mask_rom
, NULL
, "riscv_virt_board.mrom",
904 memmap
[VIRT_MROM
].size
, &error_fatal
);
905 memory_region_add_subregion(system_memory
, memmap
[VIRT_MROM
].base
,
908 if (riscv_is_32bit(&s
->soc
[0])) {
909 firmware_end_addr
= riscv_find_and_load_firmware(machine
,
910 RISCV32_BIOS_BIN
, start_addr
, NULL
);
912 firmware_end_addr
= riscv_find_and_load_firmware(machine
,
913 RISCV64_BIOS_BIN
, start_addr
, NULL
);
916 if (machine
->kernel_filename
) {
917 kernel_start_addr
= riscv_calc_kernel_start_addr(&s
->soc
[0],
920 kernel_entry
= riscv_load_kernel(machine
->kernel_filename
,
921 kernel_start_addr
, NULL
);
923 if (machine
->initrd_filename
) {
925 hwaddr end
= riscv_load_initrd(machine
->initrd_filename
,
926 machine
->ram_size
, kernel_entry
,
928 qemu_fdt_setprop_cell(machine
->fdt
, "/chosen",
929 "linux,initrd-start", start
);
930 qemu_fdt_setprop_cell(machine
->fdt
, "/chosen", "linux,initrd-end",
935 * If dynamic firmware is used, it doesn't know where is the next mode
936 * if kernel argument is not set.
941 if (drive_get(IF_PFLASH
, 0, 0)) {
943 * Pflash was supplied, let's overwrite the address we jump to after
944 * reset to the base of the flash.
946 start_addr
= virt_memmap
[VIRT_FLASH
].base
;
950 * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device
951 * tree cannot be altered and we get FDT_ERR_NOSPACE.
953 s
->fw_cfg
= create_fw_cfg(machine
);
954 rom_set_fw(s
->fw_cfg
);
956 /* Compute the fdt load address in dram */
957 fdt_load_addr
= riscv_load_fdt(memmap
[VIRT_DRAM
].base
,
958 machine
->ram_size
, machine
->fdt
);
959 /* load the reset vector */
960 riscv_setup_rom_reset_vec(machine
, &s
->soc
[0], start_addr
,
961 virt_memmap
[VIRT_MROM
].base
,
962 virt_memmap
[VIRT_MROM
].size
, kernel_entry
,
963 fdt_load_addr
, machine
->fdt
);
965 /* SiFive Test MMIO device */
966 sifive_test_create(memmap
[VIRT_TEST
].base
);
968 /* VirtIO MMIO devices */
969 for (i
= 0; i
< VIRTIO_COUNT
; i
++) {
970 sysbus_create_simple("virtio-mmio",
971 memmap
[VIRT_VIRTIO
].base
+ i
* memmap
[VIRT_VIRTIO
].size
,
972 qdev_get_gpio_in(DEVICE(virtio_plic
), VIRTIO_IRQ
+ i
));
975 gpex_pcie_init(system_memory
,
976 memmap
[VIRT_PCIE_ECAM
].base
,
977 memmap
[VIRT_PCIE_ECAM
].size
,
978 memmap
[VIRT_PCIE_MMIO
].base
,
979 memmap
[VIRT_PCIE_MMIO
].size
,
980 virt_high_pcie_memmap
.base
,
981 virt_high_pcie_memmap
.size
,
982 memmap
[VIRT_PCIE_PIO
].base
,
985 serial_mm_init(system_memory
, memmap
[VIRT_UART0
].base
,
986 0, qdev_get_gpio_in(DEVICE(mmio_plic
), UART0_IRQ
), 399193,
987 serial_hd(0), DEVICE_LITTLE_ENDIAN
);
989 sysbus_create_simple("goldfish_rtc", memmap
[VIRT_RTC
].base
,
990 qdev_get_gpio_in(DEVICE(mmio_plic
), RTC_IRQ
));
992 virt_flash_create(s
);
994 for (i
= 0; i
< ARRAY_SIZE(s
->flash
); i
++) {
995 /* Map legacy -drive if=pflash to machine properties */
996 pflash_cfi01_legacy_drive(s
->flash
[i
],
997 drive_get(IF_PFLASH
, 0, i
));
999 virt_flash_map(s
, system_memory
);
1002 static void virt_machine_instance_init(Object
*obj
)
1006 static bool virt_get_aclint(Object
*obj
, Error
**errp
)
1008 MachineState
*ms
= MACHINE(obj
);
1009 RISCVVirtState
*s
= RISCV_VIRT_MACHINE(ms
);
1011 return s
->have_aclint
;
1014 static void virt_set_aclint(Object
*obj
, bool value
, Error
**errp
)
1016 MachineState
*ms
= MACHINE(obj
);
1017 RISCVVirtState
*s
= RISCV_VIRT_MACHINE(ms
);
1019 s
->have_aclint
= value
;
1022 static void virt_machine_class_init(ObjectClass
*oc
, void *data
)
1024 MachineClass
*mc
= MACHINE_CLASS(oc
);
1026 mc
->desc
= "RISC-V VirtIO board";
1027 mc
->init
= virt_machine_init
;
1028 mc
->max_cpus
= VIRT_CPUS_MAX
;
1029 mc
->default_cpu_type
= TYPE_RISCV_CPU_BASE
;
1030 mc
->pci_allow_0_address
= true;
1031 mc
->possible_cpu_arch_ids
= riscv_numa_possible_cpu_arch_ids
;
1032 mc
->cpu_index_to_instance_props
= riscv_numa_cpu_index_to_props
;
1033 mc
->get_default_cpu_node_id
= riscv_numa_get_default_cpu_node_id
;
1034 mc
->numa_mem_supported
= true;
1036 machine_class_allow_dynamic_sysbus_dev(mc
, TYPE_RAMFB_DEVICE
);
1038 object_class_property_add_bool(oc
, "aclint", virt_get_aclint
,
1040 object_class_property_set_description(oc
, "aclint",
1041 "Set on/off to enable/disable "
1042 "emulating ACLINT devices");
1045 static const TypeInfo virt_machine_typeinfo
= {
1046 .name
= MACHINE_TYPE_NAME("virt"),
1047 .parent
= TYPE_MACHINE
,
1048 .class_init
= virt_machine_class_init
,
1049 .instance_init
= virt_machine_instance_init
,
1050 .instance_size
= sizeof(RISCVVirtState
),
1053 static void virt_machine_init_register_types(void)
1055 type_register_static(&virt_machine_typeinfo
);
1058 type_init(virt_machine_init_register_types
)