]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/boards.h
Merge tag 'pull-ufs-20231013' of https://gitlab.com/jeuk20.kim/qemu into staging
[mirror_qemu.git] / include / hw / boards.h
CommitLineData
87ecb68b
PB
1/* Declarations for use by board files for creating devices. */
2
3#ifndef HW_BOARDS_H
4#define HW_BOARDS_H
5
d4842052 6#include "exec/memory.h"
aa8b1839 7#include "sysemu/hostmem.h"
9c17d615 8#include "sysemu/blockdev.h"
8ac25c84 9#include "qapi/qapi-types-machine.h"
0b8fa32f 10#include "qemu/module.h"
36d20cb2 11#include "qom/object.h"
2e5b09fd 12#include "hw/core/cpu.h"
b6b61144 13
dfabb8b9 14#define TYPE_MACHINE_SUFFIX "-machine"
c84a8f01
EH
15
16/* Machine class name that needs to be used for class-name-based machine
17 * type lookup to work.
18 */
19#define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)
20
36d20cb2 21#define TYPE_MACHINE "machine"
c8897e8e 22#undef MACHINE /* BSD defines it and QEMU does not use it */
a489d195 23OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
36d20cb2 24
0056ae24
MA
25extern MachineState *current_machine;
26
7a2c7da6 27void machine_add_audiodev_property(MachineClass *mc);
26f88d84 28void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp);
5e97b623 29bool machine_usb(MachineState *machine);
6cabe7fa 30int machine_phandle_start(MachineState *machine);
47c8ca53 31bool machine_dump_guest_core(MachineState *machine);
75cc7f01 32bool machine_mem_merge(MachineState *machine);
f2d672c2 33HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
7c88e65d
IM
34void machine_set_cpu_numa_node(MachineState *machine,
35 const CpuInstanceProperties *props,
36 Error **errp);
3e2f1498
PMD
37void machine_parse_smp_config(MachineState *ms,
38 const SMPConfiguration *config, Error **errp);
a1d027be
ZL
39unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
40unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
cc0afd8a 41void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size);
5e97b623 42
387c0e8b
PM
43/**
44 * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
45 * @mc: Machine class
46 * @type: type to allow (should be a subtype of TYPE_SYS_BUS_DEVICE)
47 *
48 * Add the QOM type @type to the list of devices of which are subtypes
49 * of TYPE_SYS_BUS_DEVICE but which are still permitted to be dynamically
50 * created (eg by the user on the command line with -device).
51 * By default if the user tries to create any devices on the command line
52 * that are subtypes of TYPE_SYS_BUS_DEVICE they will get an error message;
53 * for the special cases which are permitted for this machine model, the
54 * machine model class init code must call this function to add them
55 * to the list of specifically permitted devices.
56 */
0bd1909d 57void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
387c0e8b 58
b5fdf410
DH
59/**
60 * device_type_is_dynamic_sysbus: Check if type is an allowed sysbus device
61 * type for the machine class.
62 * @mc: Machine class
63 * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE)
64 *
65 * Returns: true if @type is a type in the machine's list of
66 * dynamically pluggable sysbus devices; otherwise false.
67 *
68 * Check if the QOM type @type is in the list of allowed sysbus device
69 * types (see machine_class_allowed_dynamic_sysbus_dev()).
70 * Note that if @type has a parent type in the list, it is allowed too.
71 */
72bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type);
73
0fb124db
PM
74/**
75 * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device
76 * @mc: Machine class
77 * @dev: device to check
78 *
79 * Returns: true if @dev is a sysbus device on the machine's list
80 * of dynamically pluggable sysbus devices; otherwise false.
81 *
82 * This function checks whether @dev is a valid dynamic sysbus device,
83 * by first confirming that it is a sysbus device and then checking it
84 * against the list of permitted dynamic sysbus devices which has been
85 * set up by the machine using machine_class_allow_dynamic_sysbus_dev().
86 *
87 * It is valid to call this with something that is not a subclass of
88 * TYPE_SYS_BUS_DEVICE; the function will return false in this case.
89 * This allows hotplug callback functions to be written as:
90 * if (device_is_dynamic_sysbus(mc, dev)) {
91 * handle dynamic sysbus case;
92 * } else if (some other kind of hotplug) {
93 * handle that;
94 * }
95 */
96bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev);
97
82b911aa
IM
98/*
99 * Checks that backend isn't used, preps it for exclusive usage and
100 * returns migratable MemoryRegion provided by backend.
101 */
102MemoryRegion *machine_consume_memdev(MachineState *machine,
103 HostMemoryBackend *backend);
0bd1909d 104
3811ef14
IM
105/**
106 * CPUArchId:
107 * @arch_id - architecture-dependent CPU ID of present or possible CPU
108 * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
d342eb76 109 * @type - QOM class name of possible @cpu object
c67ae933 110 * @props - CPU object properties, initialized by board
f2d672c2 111 * #vcpus_count - number of threads provided by @cpu object
3811ef14 112 */
a44432b4 113typedef struct CPUArchId {
3811ef14 114 uint64_t arch_id;
f2d672c2 115 int64_t vcpus_count;
c67ae933 116 CpuInstanceProperties props;
8aba3842 117 Object *cpu;
d342eb76 118 const char *type;
3811ef14
IM
119} CPUArchId;
120
121/**
122 * CPUArchIdList:
123 * @len - number of @CPUArchId items in @cpus array
124 * @cpus - array of present or possible CPUs for current machine configuration
125 */
126typedef struct {
127 int len;
880a7817 128 CPUArchId cpus[];
3811ef14
IM
129} CPUArchIdList;
130
e4a97a89
YW
131/**
132 * SMPCompatProps:
2b526199 133 * @prefer_sockets - whether sockets are preferred over cores in smp parsing
e4a97a89 134 * @dies_supported - whether dies are supported by the machine
864c3b5c 135 * @clusters_supported - whether clusters are supported by the machine
97f4effe
YY
136 * @has_clusters - whether clusters are explicitly specified in the user
137 * provided SMP configuration
e4a97a89
YW
138 */
139typedef struct {
2b526199 140 bool prefer_sockets;
e4a97a89 141 bool dies_supported;
864c3b5c 142 bool clusters_supported;
97f4effe 143 bool has_clusters;
e4a97a89
YW
144} SMPCompatProps;
145
36d20cb2
MA
146/**
147 * MachineClass:
08fe6824
TH
148 * @deprecation_reason: If set, the machine is marked as deprecated. The
149 * string should provide some clear information about what to use instead.
72649619
EC
150 * @max_cpus: maximum number of CPUs supported. Default: 1
151 * @min_cpus: minimum number of CPUs supported. Default: 1
152 * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
ea0ac7f6
PMD
153 * @is_default:
154 * If true QEMU will use this machine by default if no '-M' option is given.
b7454548
IM
155 * @get_hotplug_handler: this function is called during bus-less
156 * device hotplug. If defined it returns pointer to an instance
157 * of HotplugHandler object, which handles hotplug operation
158 * for a given @dev. It may return NULL if @dev doesn't require
159 * any actions to be performed by hotplug handler.
ea089eeb
IM
160 * @cpu_index_to_instance_props:
161 * used to provide @cpu_index to socket/core/thread number mapping, allowing
a1a62ced 162 * legacy code to perform mapping from cpu_index to topology properties
ea089eeb 163 * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
57924bcd
IM
164 * used to provide @cpu_index to socket number mapping, allowing
165 * a machine to group CPU threads belonging to the same socket/package
166 * Returns: socket number given cpu_index belongs to.
fac862ff
EH
167 * @hw_version:
168 * Value of QEMU_VERSION when the machine was added to QEMU.
169 * Set only by old machines because they need to keep
170 * compatibility on code that exposed QEMU_VERSION to guests in
171 * the past (and now use qemu_hw_version()).
3811ef14
IM
172 * @possible_cpu_arch_ids:
173 * Returns an array of @CPUArchId architecture-dependent CPU IDs
174 * which includes CPU IDs for present and possible to hotplug CPUs.
175 * Caller is responsible for freeing returned list.
79e07936
IM
176 * @get_default_cpu_node_id:
177 * returns default board specific node_id value for CPU slot specified by
178 * index @idx in @ms->possible_cpus[]
c5514d0e
IM
179 * @has_hotpluggable_cpus:
180 * If true, board supports CPUs creation with -device/device_add.
6063d4c0
IM
181 * @default_cpu_type:
182 * specifies default CPU_TYPE, which will be used for parsing target
183 * specific features and for creating CPUs if CPU name wasn't provided
184 * explicitly at CLI
20bccb82
PM
185 * @minimum_page_bits:
186 * If non-zero, the board promises never to create a CPU with a page size
187 * smaller than this, so QEMU can use a more efficient larger page
188 * size than the target architecture's minimum. (Attempting to create
189 * such a CPU will fail.) Note that changing this is a migration
190 * compatibility break for the machine.
ed860129
PM
191 * @ignore_memory_transaction_failures:
192 * If this is flag is true then the CPU will ignore memory transaction
193 * failures which should cause the CPU to take an exception due to an
194 * access to an unassigned physical address; the transaction will instead
195 * return zero (for a read) or be ignored (for a write). This should be
196 * set only by legacy board models which rely on the old RAZ/WI behaviour
197 * for handling devices that QEMU does not yet model. New board models
198 * should instead use "unimplemented-device" for all memory ranges where
199 * the guest will attempt to probe for a device that QEMU doesn't
200 * implement and a stub device is required.
dc0ca80e
EA
201 * @kvm_type:
202 * Return the type of KVM corresponding to the kvm-type string option or
203 * computed based on other criteria such as the host kernel capabilities.
516fc0a0 204 * kvm-type may be NULL if it is not needed.
cd5ff833
IM
205 * @numa_mem_supported:
206 * true if '--numa node.mem' option is supported and false otherwise
d2321d31
PX
207 * @hotplug_allowed:
208 * If the hook is provided, then it'll be called for each device
209 * hotplug to check whether the device hotplug is allowed. Return
210 * true to grant allowance or false to reject the hotplug. When
211 * false is returned, an error must be set to show the reason of
212 * the rejection. If the hook is not provided, all hotplug will be
213 * allowed.
900c0ba3 214 * @default_ram_id:
a1a62ced 215 * Specifies initial RAM MemoryRegion name to be used for default backend
900c0ba3
IM
216 * creation if user explicitly hasn't specified backend with "memory-backend"
217 * property.
a1a62ced 218 * It also will be used as a way to option into "-m" option support.
900c0ba3
IM
219 * If it's not set by board, '-m' will be ignored and generic code will
220 * not create default RAM MemoryRegion.
5c30ef93
CB
221 * @fixup_ram_size:
222 * Amends user provided ram size (with -m option) using machine
223 * specific algorithm. To be used by old machine types for compat
224 * purposes only.
225 * Applies only to default memory backend, i.e., explicit memory backend
226 * wasn't used.
36d20cb2
MA
227 */
228struct MachineClass {
229 /*< private >*/
230 ObjectClass parent_class;
231 /*< public >*/
232
2709f263 233 const char *family; /* NULL iff @name identifies a standalone machtype */
8ea75371 234 char *name;
00b4fbe2
MA
235 const char *alias;
236 const char *desc;
08fe6824 237 const char *deprecation_reason;
00b4fbe2 238
3ef96221 239 void (*init)(MachineState *state);
7966d70f 240 void (*reset)(MachineState *state, ShutdownCause reason);
4b5e06c9 241 void (*wakeup)(MachineState *state);
dc0ca80e 242 int (*kvm_type)(MachineState *machine, const char *arg);
00b4fbe2
MA
243
244 BlockInterfaceType block_default_type;
16026518 245 int units_per_default_bus;
00b4fbe2 246 int max_cpus;
72649619
EC
247 int min_cpus;
248 int default_cpus;
00b4fbe2
MA
249 unsigned int no_serial:1,
250 no_parallel:1,
00b4fbe2
MA
251 no_floppy:1,
252 no_cdrom:1,
33cd52b5 253 no_sdcard:1,
bab47d9a
GH
254 pci_allow_0_address:1,
255 legacy_fw_cfg_order:1;
ea0ac7f6 256 bool is_default;
00b4fbe2
MA
257 const char *default_machine_opts;
258 const char *default_boot_order;
6f00494a 259 const char *default_display;
01ecdaa4 260 const char *default_nic;
b66bbee3 261 GPtrArray *compat_props;
00b4fbe2 262 const char *hw_version;
076b35b5 263 ram_addr_t default_ram_size;
6063d4c0 264 const char *default_cpu_type;
b2fc91db 265 bool default_kernel_irqchip_split;
71ae9e94
EH
266 bool option_rom_has_mr;
267 bool rom_file_has_mr;
20bccb82 268 int minimum_page_bits;
c5514d0e 269 bool has_hotpluggable_cpus;
ed860129 270 bool ignore_memory_transaction_failures;
55641213 271 int numa_mem_align_shift;
c9cf636d 272 const char **valid_cpu_types;
0bd1909d 273 strList *allowed_dynamic_sysbus_devices;
7b8be49d 274 bool auto_enable_numa_with_memhp;
195784a0 275 bool auto_enable_numa_with_memdev;
907aac2f 276 bool ignore_boot_device_suffixes;
7fccf2a0 277 bool smbus_no_migration_support;
f6a0d06b 278 bool nvdimm_supported;
cd5ff833 279 bool numa_mem_supported;
0533ef5f 280 bool auto_enable_numa;
a494fdb7 281 bool cpu_cluster_has_numa_boundary;
e4a97a89 282 SMPCompatProps smp_props;
900c0ba3 283 const char *default_ram_id;
b7454548
IM
284
285 HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
286 DeviceState *dev);
d2321d31
PX
287 bool (*hotplug_allowed)(MachineState *state, DeviceState *dev,
288 Error **errp);
ea089eeb
IM
289 CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
290 unsigned cpu_index);
80e5db30 291 const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
79e07936 292 int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
5c30ef93 293 ram_addr_t (*fixup_ram_size)(ram_addr_t size);
36d20cb2
MA
294};
295
b0c14ec4 296/**
e017da37 297 * DeviceMemoryState:
b0c14ec4
DH
298 * @base: address in guest physical address space where the memory
299 * address space for memory devices starts
f9716f4b
DH
300 * @mr: memory region container for memory devices
301 * @as: address space for memory devices
302 * @listener: memory listener used to track used memslots in the address space
e919402b 303 * @dimm_size: the sum of plugged DIMMs' sizes
ac23dd2f 304 * @used_region_size: the part of @mr already used by memory devices
f9716f4b
DH
305 * @required_memslots: the number of memslots required by memory devices
306 * @used_memslots: the number of memslots currently used by memory devices
a2335113
DH
307 * @memslot_auto_decision_active: whether any plugged memory device
308 * automatically decided to use more than
309 * one memslot
b0c14ec4 310 */
e017da37 311typedef struct DeviceMemoryState {
b0c14ec4
DH
312 hwaddr base;
313 MemoryRegion mr;
f9716f4b
DH
314 AddressSpace as;
315 MemoryListener listener;
e919402b 316 uint64_t dimm_size;
ac23dd2f 317 uint64_t used_region_size;
f9716f4b
DH
318 unsigned int required_memslots;
319 unsigned int used_memslots;
a2335113 320 unsigned int memslot_auto_decision_active;
e017da37 321} DeviceMemoryState;
b0c14ec4 322
edeeec91
LX
323/**
324 * CpuTopology:
325 * @cpus: the number of present logical processors on the machine
8cb30e3a 326 * @sockets: the number of sockets on the machine
003f230e 327 * @dies: the number of dies in one socket
864c3b5c
YW
328 * @clusters: the number of clusters in one die
329 * @cores: the number of cores in one cluster
003f230e 330 * @threads: the number of threads in one core
edeeec91
LX
331 * @max_cpus: the maximum number of logical processors on the machine
332 */
333typedef struct CpuTopology {
334 unsigned int cpus;
003f230e 335 unsigned int sockets;
67872eb8 336 unsigned int dies;
864c3b5c 337 unsigned int clusters;
edeeec91
LX
338 unsigned int cores;
339 unsigned int threads;
340 unsigned int max_cpus;
341} CpuTopology;
342
36d20cb2
MA
343/**
344 * MachineState:
345 */
346struct MachineState {
347 /*< private >*/
348 Object parent_obj;
33cd52b5 349
36d20cb2
MA
350 /*< public >*/
351
a6487d37 352 void *fdt;
36d20cb2
MA
353 char *dtb;
354 char *dumpdtb;
355 int phandle_start;
356 char *dt_compatible;
357 bool dump_guest_core;
358 bool mem_merge;
359 bool usb;
c6e76503 360 bool usb_disabled;
36d20cb2 361 char *firmware;
a52a7fdf 362 bool iommu;
9850c604 363 bool suppress_vmdesc;
cfc58cf3 364 bool enable_graphics;
e0292d7c 365 ConfidentialGuestSupport *cgs;
26f88d84 366 HostMemoryBackend *memdev;
82b911aa
IM
367 /*
368 * convenience alias to ram_memdev_id backend memory region
369 * or to numa container memory region
370 */
371 MemoryRegion *ram;
e017da37 372 DeviceMemoryState *device_memory;
36d20cb2 373
7a2c7da6
MK
374 /*
375 * Included in MachineState for simplicity, but not supported
376 * unless machine_add_audiodev_property is called. Boards
377 * that have embedded audio devices can call it from the
378 * machine init function and forward the property to the device.
379 */
380 char *audiodev;
381
3ef96221 382 ram_addr_t ram_size;
c270fb9e
IM
383 ram_addr_t maxram_size;
384 uint64_t ram_slots;
97ec4d21 385 BootConfiguration boot_config;
6b1b1440
MA
386 char *kernel_filename;
387 char *kernel_cmdline;
388 char *initrd_filename;
6063d4c0 389 const char *cpu_type;
ac2da55e 390 AccelState *accelerator;
38690a1c 391 CPUArchIdList *possible_cpus;
edeeec91 392 CpuTopology smp;
f6a0d06b 393 struct NVDIMMState *nvdimms_state;
aa570207 394 struct NumaState *numa_state;
36d20cb2
MA
395};
396
ed0b6de3
EH
397#define DEFINE_MACHINE(namestr, machine_initfn) \
398 static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
399 { \
400 MachineClass *mc = MACHINE_CLASS(oc); \
401 machine_initfn(mc); \
402 } \
403 static const TypeInfo machine_initfn##_typeinfo = { \
404 .name = MACHINE_TYPE_NAME(namestr), \
405 .parent = TYPE_MACHINE, \
406 .class_init = machine_initfn##_class_init, \
407 }; \
408 static void machine_initfn##_register_types(void) \
409 { \
410 type_register_static(&machine_initfn##_typeinfo); \
411 } \
0e6aac87 412 type_init(machine_initfn##_register_types)
ed0b6de3 413
95f5c89e
CH
414extern GlobalProperty hw_compat_8_1[];
415extern const size_t hw_compat_8_1_len;
416
0259dd3e
CH
417extern GlobalProperty hw_compat_8_0[];
418extern const size_t hw_compat_8_0_len;
419
db723c80
CH
420extern GlobalProperty hw_compat_7_2[];
421extern const size_t hw_compat_7_2_len;
422
f514e147
CH
423extern GlobalProperty hw_compat_7_1[];
424extern const size_t hw_compat_7_1_len;
425
0ca70366
CH
426extern GlobalProperty hw_compat_7_0[];
427extern const size_t hw_compat_7_0_len;
428
01854af2
CH
429extern GlobalProperty hw_compat_6_2[];
430extern const size_t hw_compat_6_2_len;
431
52e64f5b
YW
432extern GlobalProperty hw_compat_6_1[];
433extern const size_t hw_compat_6_1_len;
434
da7e13c0
CH
435extern GlobalProperty hw_compat_6_0[];
436extern const size_t hw_compat_6_0_len;
437
576a00bd
CH
438extern GlobalProperty hw_compat_5_2[];
439extern const size_t hw_compat_5_2_len;
440
3ff3c5d3
CH
441extern GlobalProperty hw_compat_5_1[];
442extern const size_t hw_compat_5_1_len;
443
541aaa1d
CH
444extern GlobalProperty hw_compat_5_0[];
445extern const size_t hw_compat_5_0_len;
446
5f258577
EY
447extern GlobalProperty hw_compat_4_2[];
448extern const size_t hw_compat_4_2_len;
449
9aec2e52
CH
450extern GlobalProperty hw_compat_4_1[];
451extern const size_t hw_compat_4_1_len;
452
9bf2650b
CH
453extern GlobalProperty hw_compat_4_0[];
454extern const size_t hw_compat_4_0_len;
455
abd93cc7
MAL
456extern GlobalProperty hw_compat_3_1[];
457extern const size_t hw_compat_3_1_len;
458
ddb3235d
MAL
459extern GlobalProperty hw_compat_3_0[];
460extern const size_t hw_compat_3_0_len;
461
0d47310b
MAL
462extern GlobalProperty hw_compat_2_12[];
463extern const size_t hw_compat_2_12_len;
464
43df70a9
MAL
465extern GlobalProperty hw_compat_2_11[];
466extern const size_t hw_compat_2_11_len;
467
503224f4
MAL
468extern GlobalProperty hw_compat_2_10[];
469extern const size_t hw_compat_2_10_len;
470
3e803152
MAL
471extern GlobalProperty hw_compat_2_9[];
472extern const size_t hw_compat_2_9_len;
473
edc24ccd
MAL
474extern GlobalProperty hw_compat_2_8[];
475extern const size_t hw_compat_2_8_len;
476
5a995064
MAL
477extern GlobalProperty hw_compat_2_7[];
478extern const size_t hw_compat_2_7_len;
479
ff8f261f
MAL
480extern GlobalProperty hw_compat_2_6[];
481extern const size_t hw_compat_2_6_len;
482
fe759610
MAL
483extern GlobalProperty hw_compat_2_5[];
484extern const size_t hw_compat_2_5_len;
485
2f99b9c2
MAL
486extern GlobalProperty hw_compat_2_4[];
487extern const size_t hw_compat_2_4_len;
488
8995dd90
MAL
489extern GlobalProperty hw_compat_2_3[];
490extern const size_t hw_compat_2_3_len;
491
1c30044e
MAL
492extern GlobalProperty hw_compat_2_2[];
493extern const size_t hw_compat_2_2_len;
494
c4fc5695
MAL
495extern GlobalProperty hw_compat_2_1[];
496extern const size_t hw_compat_2_1_len;
497
87ecb68b 498#endif