@samitouri / QOSamiQemu / commits / 331ef90a25

hw/riscv/numa: make numa_enabled() public

There's FDT logic gated around 'numa_enabled()' in virt.c and spike.c. We want to move the FDT code to a common helper without having to call hw/riscv/numa.c functions from it, but at the same time being aware of the FDT changes if numa is enabled. To do that the boards will inform the FDT helpers if we have numa_enabled in the env or not. And for the boards to be able to do that we need the static 'numa_enabled' function to be public. Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Message-ID: <20260615203734.954428-4-daniel.barboza@oss.qualcomm.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Daniel Henrique Barboza committed Jun 15, 2026 at 17:37 UTC 331ef90a2573fa587d45a7bdfedb1eb32a575399
2 files changed +18 -10
hw/riscv/numa.c
+10 -10
@@ -25,21 +25,21 @@
25 #include "hw/riscv/numa.h"
26 #include "system/device_tree.h"
27
28 -static bool numa_enabled(const MachineState *ms)
28 +bool riscv_numa_enabled(const MachineState *ms)
29 {
30 return (ms->numa_state && ms->numa_state->num_nodes) ? true : false;
31 }
32
33 int riscv_socket_count(const MachineState *ms)
34 {
35 - return (numa_enabled(ms)) ? ms->numa_state->num_nodes : 1;
35 + return (riscv_numa_enabled(ms)) ? ms->numa_state->num_nodes : 1;
36 }
37
38 int riscv_socket_first_hartid(const MachineState *ms, int socket_id)
39 {
40 int i, first_hartid = ms->smp.cpus;
41
42 - if (!numa_enabled(ms)) {
42 + if (!riscv_numa_enabled(ms)) {
43 return (!socket_id) ? 0 : -1;
44 }
45
@@ -59,7 +59,7 @@ int riscv_socket_last_hartid(const MachineState *ms, int socket_id)
59 {
60 int i, last_hartid = -1;
61
62 - if (!numa_enabled(ms)) {
62 + if (!riscv_numa_enabled(ms)) {
63 return (!socket_id) ? ms->smp.cpus - 1 : -1;
64 }
65
@@ -79,7 +79,7 @@ int riscv_socket_hart_count(const MachineState *ms, int socket_id)
79 {
80 int first_hartid, last_hartid;
81
82 - if (!numa_enabled(ms)) {
82 + if (!riscv_numa_enabled(ms)) {
83 return (!socket_id) ? ms->smp.cpus : -1;
84 }
85
@@ -104,7 +104,7 @@ bool riscv_socket_check_hartids(const MachineState *ms, int socket_id)
104 {
105 int i, first_hartid, last_hartid;
106
107 - if (!numa_enabled(ms)) {
107 + if (!riscv_numa_enabled(ms)) {
108 return (!socket_id) ? true : false;
109 }
110
@@ -132,7 +132,7 @@ uint64_t riscv_socket_mem_offset(const MachineState *ms, int socket_id)
132 int i;
133 uint64_t mem_offset = 0;
134
135 - if (!numa_enabled(ms)) {
135 + if (!riscv_numa_enabled(ms)) {
136 return 0;
137 }
138
@@ -148,7 +148,7 @@ uint64_t riscv_socket_mem_offset(const MachineState *ms, int socket_id)
148
149 uint64_t riscv_socket_mem_size(const MachineState *ms, int socket_id)
150 {
151 - if (!numa_enabled(ms)) {
151 + if (!riscv_numa_enabled(ms)) {
152 return (!socket_id) ? ms->ram_size : 0;
153 }
154
@@ -159,7 +159,7 @@ uint64_t riscv_socket_mem_size(const MachineState *ms, int socket_id)
159 void riscv_socket_fdt_write_id(const MachineState *ms, const char *node_name,
160 int socket_id)
161 {
162 - if (numa_enabled(ms)) {
162 + if (riscv_numa_enabled(ms)) {
163 qemu_fdt_setprop_cell(ms->fdt, node_name, "numa-node-id", socket_id);
164 }
165 }
@@ -170,7 +170,7 @@ void riscv_socket_fdt_write_distance_matrix(const MachineState *ms)
170 g_autofree uint32_t *dist_matrix = NULL;
171 uint32_t dist_matrix_size;
172
173 - if (numa_enabled(ms) && ms->numa_state->have_numa_distance) {
173 + if (riscv_numa_enabled(ms) && ms->numa_state->have_numa_distance) {
174 dist_matrix_size = riscv_socket_count(ms) * riscv_socket_count(ms);
175 dist_matrix_size *= (3 * sizeof(uint32_t));
176 dist_matrix = g_malloc0(dist_matrix_size);
include/hw/riscv/numa.h
+8
@@ -23,6 +23,14 @@
23 #include "hw/core/sysbus.h"
24 #include "system/numa.h"
25
26 +/**
27 + * riscv_numa_enabled:
28 + * @ms: pointer to machine state
29 + *
30 + * Returns: true if NUMA is enabled in the machine state.
31 + */
32 +bool riscv_numa_enabled(const MachineState *ms);
33 +
34 /**
35 * riscv_socket_count:
36 * @ms: pointer to machine state