59
int cpu, socket;
60
MachineState *ms = MACHINE(s);
61
uint32_t *clint_cells;
62
- uint32_t cpu_phandle, intc_phandle, phandle = 1;
62
+ uint32_t cpu_phandle, phandle = 1;
63
char *clint_name, *clust_name;
64
char *core_name, *cpu_name, *intc_name;
65
static const char * const clint_compat[2] = {
84
qemu_fdt_add_subnode(fdt, "/cpus/cpu-map");
85
86
for (socket = (riscv_socket_count(ms) - 1); socket >= 0; socket--) {
87
+ g_autofree uint32_t *intc_phandles = g_new0(uint32_t,
88
+ s->soc[socket].num_harts);
89
hwaddr memaddr = memmap[SPIKE_DRAM].base +
90
riscv_socket_mem_offset(ms, socket);
91
uint64_t memsize = riscv_socket_mem_size(ms, socket);
93
clust_name = g_strdup_printf("/cpus/cpu-map/cluster%d", socket);
94
qemu_fdt_add_subnode(fdt, clust_name);
95
94
- clint_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4);
95
-
96
for (cpu = s->soc[socket].num_harts - 1; cpu >= 0; cpu--) {
97
cpu_phandle = phandle++;
98
113
riscv_socket_fdt_write_id(ms, cpu_name, socket);
114
qemu_fdt_setprop_cell(fdt, cpu_name, "phandle", cpu_phandle);
115
116
+ intc_phandles[cpu] = phandle++;
117
+
118
intc_name = g_strdup_printf("%s/interrupt-controller", cpu_name);
119
qemu_fdt_add_subnode(fdt, intc_name);
118
- intc_phandle = phandle++;
119
- qemu_fdt_setprop_cell(fdt, intc_name, "phandle", intc_phandle);
120
+ qemu_fdt_setprop_cell(fdt, intc_name, "phandle",
121
+ intc_phandles[cpu]);
122
qemu_fdt_setprop_string(fdt, intc_name, "compatible",
123
"riscv,cpu-intc");
124
qemu_fdt_setprop(fdt, intc_name, "interrupt-controller", NULL, 0);
125
qemu_fdt_setprop_cell(fdt, intc_name, "#interrupt-cells", 1);
126
125
- clint_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandle);
126
- clint_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_SOFT);
127
- clint_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandle);
128
- clint_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER);
129
-
127
core_name = g_strdup_printf("%s/core%d", clust_name, cpu);
128
qemu_fdt_add_subnode(fdt, core_name);
129
qemu_fdt_setprop_cell(fdt, core_name, "cpu", cpu_phandle);
136
create_fdt_socket_memory(fdt, memaddr, memsize, socket,
137
riscv_numa_enabled(ms));
138
139
+ clint_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4);
140
+
141
+ for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) {
142
+ clint_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandles[cpu]);
143
+ clint_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_SOFT);
144
+ clint_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandles[cpu]);
145
+ clint_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER);
146
+ }
147
+
148
clint_addr = memmap[SPIKE_CLINT].base +
149
(memmap[SPIKE_CLINT].size * socket);
150
clint_name = g_strdup_printf("/soc/clint@%lx", clint_addr);