]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/boards.h
hw/core/machine: Constify MachineClass::valid_cpu_types[]
[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
5de1aff2
PM
138 * @books_supported - whether books are supported by the machine
139 * @drawers_supported - whether drawers are supported by the machine
e4a97a89
YW
140 */
141typedef struct {
2b526199 142 bool prefer_sockets;
e4a97a89 143 bool dies_supported;
864c3b5c 144 bool clusters_supported;
97f4effe 145 bool has_clusters;
5de1aff2
PM
146 bool books_supported;
147 bool drawers_supported;
e4a97a89
YW
148} SMPCompatProps;
149
36d20cb2
MA
150/**
151 * MachineClass:
08fe6824
TH
152 * @deprecation_reason: If set, the machine is marked as deprecated. The
153 * string should provide some clear information about what to use instead.
72649619
EC
154 * @max_cpus: maximum number of CPUs supported. Default: 1
155 * @min_cpus: minimum number of CPUs supported. Default: 1
156 * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
ea0ac7f6
PMD
157 * @is_default:
158 * If true QEMU will use this machine by default if no '-M' option is given.
b7454548
IM
159 * @get_hotplug_handler: this function is called during bus-less
160 * device hotplug. If defined it returns pointer to an instance
161 * of HotplugHandler object, which handles hotplug operation
162 * for a given @dev. It may return NULL if @dev doesn't require
163 * any actions to be performed by hotplug handler.
ea089eeb
IM
164 * @cpu_index_to_instance_props:
165 * used to provide @cpu_index to socket/core/thread number mapping, allowing
a1a62ced 166 * legacy code to perform mapping from cpu_index to topology properties
ea089eeb 167 * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
57924bcd
IM
168 * used to provide @cpu_index to socket number mapping, allowing
169 * a machine to group CPU threads belonging to the same socket/package
170 * Returns: socket number given cpu_index belongs to.
fac862ff
EH
171 * @hw_version:
172 * Value of QEMU_VERSION when the machine was added to QEMU.
173 * Set only by old machines because they need to keep
174 * compatibility on code that exposed QEMU_VERSION to guests in
175 * the past (and now use qemu_hw_version()).
3811ef14
IM
176 * @possible_cpu_arch_ids:
177 * Returns an array of @CPUArchId architecture-dependent CPU IDs
178 * which includes CPU IDs for present and possible to hotplug CPUs.
179 * Caller is responsible for freeing returned list.
79e07936
IM
180 * @get_default_cpu_node_id:
181 * returns default board specific node_id value for CPU slot specified by
182 * index @idx in @ms->possible_cpus[]
c5514d0e
IM
183 * @has_hotpluggable_cpus:
184 * If true, board supports CPUs creation with -device/device_add.
6063d4c0
IM
185 * @default_cpu_type:
186 * specifies default CPU_TYPE, which will be used for parsing target
187 * specific features and for creating CPUs if CPU name wasn't provided
188 * explicitly at CLI
20bccb82
PM
189 * @minimum_page_bits:
190 * If non-zero, the board promises never to create a CPU with a page size
191 * smaller than this, so QEMU can use a more efficient larger page
192 * size than the target architecture's minimum. (Attempting to create
193 * such a CPU will fail.) Note that changing this is a migration
194 * compatibility break for the machine.
ed860129
PM
195 * @ignore_memory_transaction_failures:
196 * If this is flag is true then the CPU will ignore memory transaction
197 * failures which should cause the CPU to take an exception due to an
198 * access to an unassigned physical address; the transaction will instead
199 * return zero (for a read) or be ignored (for a write). This should be
200 * set only by legacy board models which rely on the old RAZ/WI behaviour
201 * for handling devices that QEMU does not yet model. New board models
202 * should instead use "unimplemented-device" for all memory ranges where
203 * the guest will attempt to probe for a device that QEMU doesn't
204 * implement and a stub device is required.
dc0ca80e
EA
205 * @kvm_type:
206 * Return the type of KVM corresponding to the kvm-type string option or
207 * computed based on other criteria such as the host kernel capabilities.
516fc0a0 208 * kvm-type may be NULL if it is not needed.
cd5ff833
IM
209 * @numa_mem_supported:
210 * true if '--numa node.mem' option is supported and false otherwise
d2321d31
PX
211 * @hotplug_allowed:
212 * If the hook is provided, then it'll be called for each device
213 * hotplug to check whether the device hotplug is allowed. Return
214 * true to grant allowance or false to reject the hotplug. When
215 * false is returned, an error must be set to show the reason of
216 * the rejection. If the hook is not provided, all hotplug will be
217 * allowed.
900c0ba3 218 * @default_ram_id:
a1a62ced 219 * Specifies initial RAM MemoryRegion name to be used for default backend
900c0ba3
IM
220 * creation if user explicitly hasn't specified backend with "memory-backend"
221 * property.
a1a62ced 222 * It also will be used as a way to option into "-m" option support.
900c0ba3
IM
223 * If it's not set by board, '-m' will be ignored and generic code will
224 * not create default RAM MemoryRegion.
5c30ef93
CB
225 * @fixup_ram_size:
226 * Amends user provided ram size (with -m option) using machine
227 * specific algorithm. To be used by old machine types for compat
228 * purposes only.
229 * Applies only to default memory backend, i.e., explicit memory backend
230 * wasn't used.
36d20cb2
MA
231 */
232struct MachineClass {
233 /*< private >*/
234 ObjectClass parent_class;
235 /*< public >*/
236
2709f263 237 const char *family; /* NULL iff @name identifies a standalone machtype */
8ea75371 238 char *name;
00b4fbe2
MA
239 const char *alias;
240 const char *desc;
08fe6824 241 const char *deprecation_reason;
00b4fbe2 242
3ef96221 243 void (*init)(MachineState *state);
7966d70f 244 void (*reset)(MachineState *state, ShutdownCause reason);
4b5e06c9 245 void (*wakeup)(MachineState *state);
dc0ca80e 246 int (*kvm_type)(MachineState *machine, const char *arg);
00b4fbe2
MA
247
248 BlockInterfaceType block_default_type;
16026518 249 int units_per_default_bus;
00b4fbe2 250 int max_cpus;
72649619
EC
251 int min_cpus;
252 int default_cpus;
00b4fbe2
MA
253 unsigned int no_serial:1,
254 no_parallel:1,
00b4fbe2
MA
255 no_floppy:1,
256 no_cdrom:1,
33cd52b5 257 no_sdcard:1,
bab47d9a
GH
258 pci_allow_0_address:1,
259 legacy_fw_cfg_order:1;
ea0ac7f6 260 bool is_default;
00b4fbe2
MA
261 const char *default_machine_opts;
262 const char *default_boot_order;
6f00494a 263 const char *default_display;
01ecdaa4 264 const char *default_nic;
b66bbee3 265 GPtrArray *compat_props;
00b4fbe2 266 const char *hw_version;
076b35b5 267 ram_addr_t default_ram_size;
6063d4c0 268 const char *default_cpu_type;
b2fc91db 269 bool default_kernel_irqchip_split;
71ae9e94
EH
270 bool option_rom_has_mr;
271 bool rom_file_has_mr;
20bccb82 272 int minimum_page_bits;
c5514d0e 273 bool has_hotpluggable_cpus;
ed860129 274 bool ignore_memory_transaction_failures;
55641213 275 int numa_mem_align_shift;
790a4428 276 const char * const *valid_cpu_types;
0bd1909d 277 strList *allowed_dynamic_sysbus_devices;
7b8be49d 278 bool auto_enable_numa_with_memhp;
195784a0 279 bool auto_enable_numa_with_memdev;
907aac2f 280 bool ignore_boot_device_suffixes;
7fccf2a0 281 bool smbus_no_migration_support;
f6a0d06b 282 bool nvdimm_supported;
cd5ff833 283 bool numa_mem_supported;
0533ef5f 284 bool auto_enable_numa;
a494fdb7 285 bool cpu_cluster_has_numa_boundary;
e4a97a89 286 SMPCompatProps smp_props;
900c0ba3 287 const char *default_ram_id;
b7454548
IM
288
289 HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
290 DeviceState *dev);
d2321d31
PX
291 bool (*hotplug_allowed)(MachineState *state, DeviceState *dev,
292 Error **errp);
ea089eeb
IM
293 CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
294 unsigned cpu_index);
80e5db30 295 const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
79e07936 296 int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
5c30ef93 297 ram_addr_t (*fixup_ram_size)(ram_addr_t size);
36d20cb2
MA
298};
299
b0c14ec4 300/**
e017da37 301 * DeviceMemoryState:
b0c14ec4
DH
302 * @base: address in guest physical address space where the memory
303 * address space for memory devices starts
f9716f4b
DH
304 * @mr: memory region container for memory devices
305 * @as: address space for memory devices
306 * @listener: memory listener used to track used memslots in the address space
e919402b 307 * @dimm_size: the sum of plugged DIMMs' sizes
ac23dd2f 308 * @used_region_size: the part of @mr already used by memory devices
f9716f4b
DH
309 * @required_memslots: the number of memslots required by memory devices
310 * @used_memslots: the number of memslots currently used by memory devices
a2335113
DH
311 * @memslot_auto_decision_active: whether any plugged memory device
312 * automatically decided to use more than
313 * one memslot
b0c14ec4 314 */
e017da37 315typedef struct DeviceMemoryState {
b0c14ec4
DH
316 hwaddr base;
317 MemoryRegion mr;
f9716f4b
DH
318 AddressSpace as;
319 MemoryListener listener;
e919402b 320 uint64_t dimm_size;
ac23dd2f 321 uint64_t used_region_size;
f9716f4b
DH
322 unsigned int required_memslots;
323 unsigned int used_memslots;
a2335113 324 unsigned int memslot_auto_decision_active;
e017da37 325} DeviceMemoryState;
b0c14ec4 326
edeeec91
LX
327/**
328 * CpuTopology:
329 * @cpus: the number of present logical processors on the machine
5de1aff2
PM
330 * @drawers: the number of drawers on the machine
331 * @books: the number of books in one drawer
332 * @sockets: the number of sockets in one book
003f230e 333 * @dies: the number of dies in one socket
864c3b5c
YW
334 * @clusters: the number of clusters in one die
335 * @cores: the number of cores in one cluster
003f230e 336 * @threads: the number of threads in one core
edeeec91
LX
337 * @max_cpus: the maximum number of logical processors on the machine
338 */
339typedef struct CpuTopology {
340 unsigned int cpus;
5de1aff2
PM
341 unsigned int drawers;
342 unsigned int books;
003f230e 343 unsigned int sockets;
67872eb8 344 unsigned int dies;
864c3b5c 345 unsigned int clusters;
edeeec91
LX
346 unsigned int cores;
347 unsigned int threads;
348 unsigned int max_cpus;
349} CpuTopology;
350
36d20cb2
MA
351/**
352 * MachineState:
353 */
354struct MachineState {
355 /*< private >*/
356 Object parent_obj;
33cd52b5 357
36d20cb2
MA
358 /*< public >*/
359
a6487d37 360 void *fdt;
36d20cb2
MA
361 char *dtb;
362 char *dumpdtb;
363 int phandle_start;
364 char *dt_compatible;
365 bool dump_guest_core;
366 bool mem_merge;
367 bool usb;
c6e76503 368 bool usb_disabled;
36d20cb2 369 char *firmware;
a52a7fdf 370 bool iommu;
9850c604 371 bool suppress_vmdesc;
cfc58cf3 372 bool enable_graphics;
e0292d7c 373 ConfidentialGuestSupport *cgs;
26f88d84 374 HostMemoryBackend *memdev;
82b911aa
IM
375 /*
376 * convenience alias to ram_memdev_id backend memory region
377 * or to numa container memory region
378 */
379 MemoryRegion *ram;
e017da37 380 DeviceMemoryState *device_memory;
36d20cb2 381
7a2c7da6
MK
382 /*
383 * Included in MachineState for simplicity, but not supported
384 * unless machine_add_audiodev_property is called. Boards
385 * that have embedded audio devices can call it from the
386 * machine init function and forward the property to the device.
387 */
388 char *audiodev;
389
3ef96221 390 ram_addr_t ram_size;
c270fb9e
IM
391 ram_addr_t maxram_size;
392 uint64_t ram_slots;
97ec4d21 393 BootConfiguration boot_config;
6b1b1440
MA
394 char *kernel_filename;
395 char *kernel_cmdline;
396 char *initrd_filename;
6063d4c0 397 const char *cpu_type;
ac2da55e 398 AccelState *accelerator;
38690a1c 399 CPUArchIdList *possible_cpus;
edeeec91 400 CpuTopology smp;
f6a0d06b 401 struct NVDIMMState *nvdimms_state;
aa570207 402 struct NumaState *numa_state;
36d20cb2
MA
403};
404
ed0b6de3
EH
405#define DEFINE_MACHINE(namestr, machine_initfn) \
406 static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
407 { \
408 MachineClass *mc = MACHINE_CLASS(oc); \
409 machine_initfn(mc); \
410 } \
411 static const TypeInfo machine_initfn##_typeinfo = { \
412 .name = MACHINE_TYPE_NAME(namestr), \
413 .parent = TYPE_MACHINE, \
414 .class_init = machine_initfn##_class_init, \
415 }; \
416 static void machine_initfn##_register_types(void) \
417 { \
418 type_register_static(&machine_initfn##_typeinfo); \
419 } \
0e6aac87 420 type_init(machine_initfn##_register_types)
ed0b6de3 421
95f5c89e
CH
422extern GlobalProperty hw_compat_8_1[];
423extern const size_t hw_compat_8_1_len;
424
0259dd3e
CH
425extern GlobalProperty hw_compat_8_0[];
426extern const size_t hw_compat_8_0_len;
427
db723c80
CH
428extern GlobalProperty hw_compat_7_2[];
429extern const size_t hw_compat_7_2_len;
430
f514e147
CH
431extern GlobalProperty hw_compat_7_1[];
432extern const size_t hw_compat_7_1_len;
433
0ca70366
CH
434extern GlobalProperty hw_compat_7_0[];
435extern const size_t hw_compat_7_0_len;
436
01854af2
CH
437extern GlobalProperty hw_compat_6_2[];
438extern const size_t hw_compat_6_2_len;
439
52e64f5b
YW
440extern GlobalProperty hw_compat_6_1[];
441extern const size_t hw_compat_6_1_len;
442
da7e13c0
CH
443extern GlobalProperty hw_compat_6_0[];
444extern const size_t hw_compat_6_0_len;
445
576a00bd
CH
446extern GlobalProperty hw_compat_5_2[];
447extern const size_t hw_compat_5_2_len;
448
3ff3c5d3
CH
449extern GlobalProperty hw_compat_5_1[];
450extern const size_t hw_compat_5_1_len;
451
541aaa1d
CH
452extern GlobalProperty hw_compat_5_0[];
453extern const size_t hw_compat_5_0_len;
454
5f258577
EY
455extern GlobalProperty hw_compat_4_2[];
456extern const size_t hw_compat_4_2_len;
457
9aec2e52
CH
458extern GlobalProperty hw_compat_4_1[];
459extern const size_t hw_compat_4_1_len;
460
9bf2650b
CH
461extern GlobalProperty hw_compat_4_0[];
462extern const size_t hw_compat_4_0_len;
463
abd93cc7
MAL
464extern GlobalProperty hw_compat_3_1[];
465extern const size_t hw_compat_3_1_len;
466
ddb3235d
MAL
467extern GlobalProperty hw_compat_3_0[];
468extern const size_t hw_compat_3_0_len;
469
0d47310b
MAL
470extern GlobalProperty hw_compat_2_12[];
471extern const size_t hw_compat_2_12_len;
472
43df70a9
MAL
473extern GlobalProperty hw_compat_2_11[];
474extern const size_t hw_compat_2_11_len;
475
503224f4
MAL
476extern GlobalProperty hw_compat_2_10[];
477extern const size_t hw_compat_2_10_len;
478
3e803152
MAL
479extern GlobalProperty hw_compat_2_9[];
480extern const size_t hw_compat_2_9_len;
481
edc24ccd
MAL
482extern GlobalProperty hw_compat_2_8[];
483extern const size_t hw_compat_2_8_len;
484
5a995064
MAL
485extern GlobalProperty hw_compat_2_7[];
486extern const size_t hw_compat_2_7_len;
487
ff8f261f
MAL
488extern GlobalProperty hw_compat_2_6[];
489extern const size_t hw_compat_2_6_len;
490
fe759610
MAL
491extern GlobalProperty hw_compat_2_5[];
492extern const size_t hw_compat_2_5_len;
493
2f99b9c2
MAL
494extern GlobalProperty hw_compat_2_4[];
495extern const size_t hw_compat_2_4_len;
496
8995dd90
MAL
497extern GlobalProperty hw_compat_2_3[];
498extern const size_t hw_compat_2_3_len;
499
1c30044e
MAL
500extern GlobalProperty hw_compat_2_2[];
501extern const size_t hw_compat_2_2_len;
502
c4fc5695
MAL
503extern GlobalProperty hw_compat_2_1[];
504extern const size_t hw_compat_2_1_len;
505
87ecb68b 506#endif