]>
Commit | Line | Data |
---|---|---|
a8a506c3 XY |
1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | /* | |
3 | * QEMU loongson 3a5000 develop board emulation | |
4 | * | |
5 | * Copyright (c) 2021 Loongson Technology Corporation Limited | |
6 | */ | |
7 | #include "qemu/osdep.h" | |
8 | #include "qemu/units.h" | |
9 | #include "qemu/datadir.h" | |
10 | #include "qapi/error.h" | |
11 | #include "hw/boards.h" | |
12 | #include "sysemu/sysemu.h" | |
13 | #include "sysemu/qtest.h" | |
14 | #include "sysemu/runstate.h" | |
15 | #include "sysemu/reset.h" | |
16 | #include "sysemu/rtc.h" | |
17 | #include "hw/loongarch/virt.h" | |
18 | #include "exec/address-spaces.h" | |
19 | #include "target/loongarch/cpu.h" | |
20 | ||
21 | static void loongarch_init(MachineState *machine) | |
22 | { | |
23 | const char *cpu_model = machine->cpu_type; | |
24 | ram_addr_t offset = 0; | |
25 | ram_addr_t ram_size = machine->ram_size; | |
26 | uint64_t highram_size = 0; | |
27 | MemoryRegion *address_space_mem = get_system_memory(); | |
28 | LoongArchMachineState *lams = LOONGARCH_MACHINE(machine); | |
29 | int i; | |
30 | ||
31 | if (!cpu_model) { | |
32 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); | |
33 | } | |
34 | ||
35 | if (!strstr(cpu_model, "la464")) { | |
36 | error_report("LoongArch/TCG needs cpu type la464"); | |
37 | exit(1); | |
38 | } | |
39 | ||
40 | if (ram_size < 1 * GiB) { | |
41 | error_report("ram_size must be greater than 1G."); | |
42 | exit(1); | |
43 | } | |
44 | ||
45 | /* Init CPUs */ | |
46 | for (i = 0; i < machine->smp.cpus; i++) { | |
47 | cpu_create(machine->cpu_type); | |
48 | } | |
49 | ||
50 | /* Add memory region */ | |
51 | memory_region_init_alias(&lams->lowmem, NULL, "loongarch.lowram", | |
52 | machine->ram, 0, 256 * MiB); | |
53 | memory_region_add_subregion(address_space_mem, offset, &lams->lowmem); | |
54 | offset += 256 * MiB; | |
55 | ||
56 | highram_size = ram_size - 256 * MiB; | |
57 | memory_region_init_alias(&lams->highmem, NULL, "loongarch.highmem", | |
58 | machine->ram, offset, highram_size); | |
59 | memory_region_add_subregion(address_space_mem, 0x90000000, &lams->highmem); | |
60 | ||
61 | /* Add isa io region */ | |
62 | memory_region_init_alias(&lams->isa_io, NULL, "isa-io", | |
63 | get_system_io(), 0, LOONGARCH_ISA_IO_SIZE); | |
64 | memory_region_add_subregion(address_space_mem, LOONGARCH_ISA_IO_BASE, | |
65 | &lams->isa_io); | |
66 | } | |
67 | ||
68 | static void loongarch_class_init(ObjectClass *oc, void *data) | |
69 | { | |
70 | MachineClass *mc = MACHINE_CLASS(oc); | |
71 | ||
72 | mc->desc = "Loongson-3A5000 LS7A1000 machine"; | |
73 | mc->init = loongarch_init; | |
74 | mc->default_ram_size = 1 * GiB; | |
75 | mc->default_cpu_type = LOONGARCH_CPU_TYPE_NAME("la464"); | |
76 | mc->default_ram_id = "loongarch.ram"; | |
77 | mc->max_cpus = LOONGARCH_MAX_VCPUS; | |
78 | mc->is_default = 1; | |
79 | mc->default_kernel_irqchip_split = false; | |
80 | mc->block_default_type = IF_VIRTIO; | |
81 | mc->default_boot_order = "c"; | |
82 | mc->no_cdrom = 1; | |
83 | } | |
84 | ||
85 | static const TypeInfo loongarch_machine_types[] = { | |
86 | { | |
87 | .name = TYPE_LOONGARCH_MACHINE, | |
88 | .parent = TYPE_MACHINE, | |
89 | .instance_size = sizeof(LoongArchMachineState), | |
90 | .class_init = loongarch_class_init, | |
91 | } | |
92 | }; | |
93 | ||
94 | DEFINE_TYPES(loongarch_machine_types) |