master
h 884 lines 32.7 KB
Raw
1 /* Declarations for use by board files for creating devices. */
2
3 #ifndef HW_BOARDS_H
4 #define HW_BOARDS_H
5
6 #include "system/memory.h"
7 #include "system/hostmem.h"
8 #include "system/blockdev.h"
9 #include "qapi/qapi-types-machine.h"
10 #include "qemu/module.h"
11 #include "qom/compat-properties.h"
12 #include "qom/object.h"
13 #include "hw/core/cpu.h"
14 #include "hw/core/resettable.h"
15
16 #define TYPE_MACHINE_SUFFIX "-machine"
17
18 /* Machine class name that needs to be used for class-name-based machine
19 * type lookup to work.
20 */
21 #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)
22
23 #define TYPE_MACHINE "machine"
24 #undef MACHINE /* BSD defines it and QEMU does not use it */
25 OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
26
27 extern MachineState *current_machine;
28
29 /**
30 * machine_default_cpu_type: Return the machine default CPU type.
31 * @ms: Machine state
32 */
33 const char *machine_default_cpu_type(const MachineState *ms);
34 /**
35 * machine_class_default_cpu_type: Return the machine default CPU type.
36 * @mc: Machine class
37 */
38 const char *machine_class_default_cpu_type(MachineClass *mc);
39
40 void machine_add_audiodev_property(MachineClass *mc);
41 void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp);
42 bool machine_usb(MachineState *machine);
43 int machine_phandle_start(MachineState *machine);
44 bool machine_dump_guest_core(MachineState *machine);
45 bool machine_mem_merge(MachineState *machine);
46 bool machine_require_guest_memfd(MachineState *machine);
47 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
48 void machine_set_cpu_numa_node(MachineState *machine,
49 const CpuInstanceProperties *props,
50 Error **errp);
51 void machine_parse_smp_config(MachineState *ms,
52 const SMPConfiguration *config, Error **errp);
53 bool machine_parse_smp_cache(MachineState *ms,
54 const SmpCachePropertiesList *caches,
55 Error **errp);
56 unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
57 unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
58 CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms,
59 CacheLevelAndType cache);
60 void machine_set_cache_topo_level(MachineState *ms, CacheLevelAndType cache,
61 CpuTopologyLevel level);
62 bool machine_check_smp_cache(const MachineState *ms, Error **errp);
63 void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size);
64 bool machine_defines_cache_at_topo_level(const MachineState *ms,
65 CpuTopologyLevel topology);
66 bool machine_find_lowest_level_cache_at_topo_level(const MachineState *ms,
67 int *lowest_cache_level,
68 CpuTopologyLevel topo_level);
69
70 /**
71 * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
72 * @mc: Machine class
73 * @type: type to allow (should be a subtype of TYPE_SYS_BUS_DEVICE)
74 *
75 * Add the QOM type @type to the list of devices of which are subtypes
76 * of TYPE_SYS_BUS_DEVICE but which are still permitted to be dynamically
77 * created (eg by the user on the command line with -device).
78 * By default if the user tries to create any devices on the command line
79 * that are subtypes of TYPE_SYS_BUS_DEVICE they will get an error message;
80 * for the special cases which are permitted for this machine model, the
81 * machine model class init code must call this function to add them
82 * to the list of specifically permitted devices.
83 */
84 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
85
86 /**
87 * device_type_is_dynamic_sysbus: Check if type is an allowed sysbus device
88 * type for the machine class.
89 * @mc: Machine class
90 * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE)
91 *
92 * Returns: true if @type is a type in the machine's list of
93 * dynamically pluggable sysbus devices; otherwise false.
94 *
95 * Check if the QOM type @type is in the list of allowed sysbus device
96 * types (see machine_class_allowed_dynamic_sysbus_dev()).
97 * Note that if @type has a parent type in the list, it is allowed too.
98 */
99 bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type);
100
101 /**
102 * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device
103 * @mc: Machine class
104 * @dev: device to check
105 *
106 * Returns: true if @dev is a sysbus device on the machine's list
107 * of dynamically pluggable sysbus devices; otherwise false.
108 *
109 * This function checks whether @dev is a valid dynamic sysbus device,
110 * by first confirming that it is a sysbus device and then checking it
111 * against the list of permitted dynamic sysbus devices which has been
112 * set up by the machine using machine_class_allow_dynamic_sysbus_dev().
113 *
114 * It is valid to call this with something that is not a subclass of
115 * TYPE_SYS_BUS_DEVICE; the function will return false in this case.
116 * This allows hotplug callback functions to be written as:
117 * if (device_is_dynamic_sysbus(mc, dev)) {
118 * handle dynamic sysbus case;
119 * } else if (some other kind of hotplug) {
120 * handle that;
121 * }
122 */
123 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev);
124
125 /*
126 * Checks that backend isn't used, preps it for exclusive usage and
127 * returns migratable MemoryRegion provided by backend.
128 */
129 MemoryRegion *machine_consume_memdev(MachineState *machine,
130 HostMemoryBackend *backend);
131
132 /**
133 * CPUArchId:
134 * @arch_id - architecture-dependent CPU ID of present or possible CPU
135 * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
136 * @type - QOM class name of possible @cpu object
137 * @props - CPU object properties, initialized by board
138 * #vcpus_count - number of threads provided by @cpu object
139 */
140 typedef struct CPUArchId {
141 uint64_t arch_id;
142 int64_t vcpus_count;
143 CpuInstanceProperties props;
144 CPUState *cpu;
145 const char *type;
146 } CPUArchId;
147
148 /**
149 * CPUArchIdList:
150 * @len - number of @CPUArchId items in @cpus array
151 * @cpus - array of present or possible CPUs for current machine configuration
152 */
153 typedef struct {
154 int len;
155 CPUArchId cpus[];
156 } CPUArchIdList;
157
158 /**
159 * SMPCompatProps:
160 * @prefer_sockets - whether sockets are preferred over cores in smp parsing
161 * @dies_supported - whether dies are supported by the machine
162 * @clusters_supported - whether clusters are supported by the machine
163 * @has_clusters - whether clusters are explicitly specified in the user
164 * provided SMP configuration
165 * @books_supported - whether books are supported by the machine
166 * @drawers_supported - whether drawers are supported by the machine
167 * @modules_supported - whether modules are supported by the machine
168 * @cache_supported - whether cache (l1d, l1i, l2 and l3) configuration are
169 * supported by the machine
170 * @has_caches - whether cache properties are explicitly specified in the
171 * user provided smp-cache configuration
172 */
173 typedef struct {
174 bool prefer_sockets;
175 bool dies_supported;
176 bool clusters_supported;
177 bool has_clusters;
178 bool books_supported;
179 bool drawers_supported;
180 bool modules_supported;
181 bool cache_supported[CACHE_LEVEL_AND_TYPE__MAX];
182 bool has_caches;
183 } SMPCompatProps;
184
185 /**
186 * MachineClass:
187 * @deprecation_reason: If set, the machine is marked as deprecated. The
188 * string should provide some clear information about what to use instead.
189 * @max_cpus: maximum number of CPUs supported. Default: 1
190 * @min_cpus: minimum number of CPUs supported. Default: 1
191 * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
192 * @is_default:
193 * If true QEMU will use this machine by default if no '-M' option is given.
194 * @get_hotplug_handler: this function is called during bus-less
195 * device hotplug. If defined it returns pointer to an instance
196 * of HotplugHandler object, which handles hotplug operation
197 * for a given @dev. It may return NULL if @dev doesn't require
198 * any actions to be performed by hotplug handler.
199 * @cpu_index_to_instance_props:
200 * used to provide @cpu_index to socket/core/thread number mapping, allowing
201 * legacy code to perform mapping from cpu_index to topology properties
202 * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
203 * used to provide @cpu_index to socket number mapping, allowing
204 * a machine to group CPU threads belonging to the same socket/package
205 * Returns: socket number given cpu_index belongs to.
206 * @possible_cpu_arch_ids:
207 * Returns an array of @CPUArchId architecture-dependent CPU IDs
208 * which includes CPU IDs for present and possible to hotplug CPUs.
209 * Caller is responsible for freeing returned list.
210 * @get_default_cpu_node_id:
211 * returns default board specific node_id value for CPU slot specified by
212 * index @idx in @ms->possible_cpus[]
213 * @has_hotpluggable_cpus:
214 * If true, board supports CPUs creation with -device/device_add.
215 * @default_cpu_type:
216 * specifies default CPU_TYPE, which will be used for parsing target
217 * specific features and for creating CPUs if CPU name wasn't provided
218 * explicitly at CLI
219 * @minimum_page_bits:
220 * If non-zero, the board promises never to create a CPU with a page size
221 * smaller than this, so QEMU can use a more efficient larger page
222 * size than the target architecture's minimum. (Attempting to create
223 * such a CPU will fail.) Note that changing this is a migration
224 * compatibility break for the machine.
225 * @ignore_memory_transaction_failures:
226 * If this is flag is true then the CPU will ignore memory transaction
227 * failures which should cause the CPU to take an exception due to an
228 * access to an unassigned physical address; the transaction will instead
229 * return zero (for a read) or be ignored (for a write). This should be
230 * set only by legacy board models which rely on the old RAZ/WI behaviour
231 * for handling devices that QEMU does not yet model. New board models
232 * should instead use "unimplemented-device" for all memory ranges where
233 * the guest will attempt to probe for a device that QEMU doesn't
234 * implement and a stub device is required.
235 * @kvm_type:
236 * Return the type of KVM corresponding to the kvm-type string option or
237 * computed based on other criteria such as the host kernel capabilities.
238 * kvm-type may be NULL if it is not needed.
239 * @hvf_get_physical_address_range:
240 * Returns the physical address range in bits to use for the HVF virtual
241 * machine based on the current boards memory map. This may be NULL if it
242 * is not needed.
243 * @numa_mem_supported:
244 * true if '--numa node.mem' option is supported and false otherwise
245 * @hotplug_allowed:
246 * If the hook is provided, then it'll be called for each device
247 * hotplug to check whether the device hotplug is allowed. Return
248 * true to grant allowance or false to reject the hotplug. When
249 * false is returned, an error must be set to show the reason of
250 * the rejection. If the hook is not provided, all hotplug will be
251 * allowed.
252 * @default_ram_id:
253 * Specifies initial RAM MemoryRegion name to be used for default backend
254 * creation if user explicitly hasn't specified backend with "memory-backend"
255 * property.
256 * It also will be used as a way to option into "-m" option support.
257 * If it's not set by board, '-m' will be ignored and generic code will
258 * not create default RAM MemoryRegion.
259 * @smbios_memory_device_size:
260 * Default size of memory device,
261 * SMBIOS 3.1.0 "7.18 Memory Device (Type 17)"
262 * @get_valid_cpu_types:
263 * Returns a list of valid CPU types for this board. May be NULL
264 * if not needed.
265 */
266 struct MachineClass {
267 /*< private >*/
268 ObjectClass parent_class;
269 /*< public >*/
270
271 const char *family; /* NULL iff @name identifies a standalone machtype */
272 char *name;
273 const char *alias;
274 const char *desc;
275 const char *deprecation_reason;
276
277 void (*init)(MachineState *state);
278 void (*reset)(MachineState *state, ResetType type);
279 void (*wakeup)(MachineState *state);
280 int (*kvm_type)(MachineState *machine, const char *arg);
281 int (*get_physical_address_range)(MachineState *machine,
282 int default_ipa_size, int max_ipa_size);
283 bool (*get_kernel_irqchip_default) (const MachineState *machine);
284
285 BlockInterfaceType block_default_type;
286 int units_per_default_bus;
287 int max_cpus;
288 int min_cpus;
289 int default_cpus;
290 unsigned int no_serial:1,
291 no_parallel:1,
292 no_floppy:1,
293 no_cdrom:1,
294 pci_allow_0_address:1;
295 bool auto_create_sdcard;
296 bool is_default;
297 const char *default_machine_opts;
298 const char *default_boot_order;
299 const char *default_display;
300 const char *default_nic;
301 GPtrArray *compat_props;
302 ram_addr_t default_ram_size;
303 const char *default_cpu_type;
304 bool default_kernel_irqchip_split;
305 bool option_rom_has_mr;
306 bool rom_file_has_mr;
307 int minimum_page_bits;
308 bool has_hotpluggable_cpus;
309 bool ignore_memory_transaction_failures;
310 int numa_mem_align_shift;
311 const char * const *valid_cpu_types;
312 GPtrArray *(*get_valid_cpu_types)(const MachineState *ms);
313 const char *(*get_default_cpu_type)(const MachineState *ms);
314 strList *allowed_dynamic_sysbus_devices;
315 bool auto_enable_numa_with_memhp;
316 bool auto_enable_numa_with_memdev;
317 bool ignore_boot_device_suffixes;
318 bool nvdimm_supported;
319 bool numa_mem_supported;
320 bool auto_enable_numa;
321 bool cpu_cluster_has_numa_boundary;
322 SMPCompatProps smp_props;
323 const char *default_ram_id;
324
325 HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
326 DeviceState *dev);
327 bool (*hotplug_allowed)(MachineState *state, DeviceState *dev,
328 Error **errp);
329 CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
330 unsigned cpu_index);
331 const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
332 int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
333 uint64_t smbios_memory_device_size;
334 bool (*create_default_memdev)(MachineState *ms, const char *path,
335 Error **errp);
336 };
337
338 /**
339 * DeviceMemoryState:
340 * @base: address in guest physical address space where the memory
341 * address space for memory devices starts
342 * @mr: memory region container for memory devices
343 * @as: address space for memory devices
344 * @listener: memory listener used to track used memslots in the address space
345 * @dimm_size: the sum of plugged DIMMs' sizes
346 * @used_region_size: the part of @mr already used by memory devices
347 * @required_memslots: the number of memslots required by memory devices
348 * @used_memslots: the number of memslots currently used by memory devices
349 * @memslot_auto_decision_active: whether any plugged memory device
350 * automatically decided to use more than
351 * one memslot
352 */
353 typedef struct DeviceMemoryState {
354 hwaddr base;
355 MemoryRegion mr;
356 AddressSpace as;
357 MemoryListener listener;
358 uint64_t dimm_size;
359 uint64_t used_region_size;
360 unsigned int required_memslots;
361 unsigned int used_memslots;
362 unsigned int memslot_auto_decision_active;
363 } DeviceMemoryState;
364
365 /**
366 * CpuTopology:
367 * @cpus: the number of present logical processors on the machine
368 * @drawers: the number of drawers on the machine
369 * @books: the number of books in one drawer
370 * @sockets: the number of sockets in one book
371 * @dies: the number of dies in one socket
372 * @clusters: the number of clusters in one die
373 * @modules: the number of modules in one cluster
374 * @cores: the number of cores in one cluster
375 * @threads: the number of threads in one core
376 * @max_cpus: the maximum number of logical processors on the machine
377 */
378 typedef struct CpuTopology {
379 unsigned int cpus;
380 unsigned int drawers;
381 unsigned int books;
382 unsigned int sockets;
383 unsigned int dies;
384 unsigned int clusters;
385 unsigned int modules;
386 unsigned int cores;
387 unsigned int threads;
388 unsigned int max_cpus;
389 } CpuTopology;
390
391 typedef struct SmpCache {
392 SmpCacheProperties props[CACHE_LEVEL_AND_TYPE__MAX];
393 } SmpCache;
394
395 /**
396 * MachineState:
397 */
398 struct MachineState {
399 /*< private >*/
400 Object parent_obj;
401
402 /*< public >*/
403
404 void *fdt;
405 char *dtb;
406 char *dumpdtb;
407 int phandle_start;
408 char *dt_compatible;
409 bool dump_guest_core;
410 bool mem_merge;
411 bool usb;
412 bool usb_disabled;
413 char *firmware;
414 bool iommu;
415 bool suppress_vmdesc;
416 bool enable_graphics;
417 ConfidentialGuestSupport *cgs;
418 HostMemoryBackend *memdev;
419 bool aux_ram_share;
420 /*
421 * convenience alias to ram_memdev_id backend memory region
422 * or to numa container memory region
423 */
424 MemoryRegion *ram;
425 DeviceMemoryState *device_memory;
426
427 /*
428 * Included in MachineState for simplicity, but not supported
429 * unless machine_add_audiodev_property is called. Boards
430 * that have embedded audio devices can call it from the
431 * machine init function and forward the property to the device.
432 */
433 char *audiodev;
434
435 ram_addr_t ram_size;
436 ram_addr_t maxram_size;
437 uint64_t ram_slots;
438 BootConfiguration boot_config;
439 char *kernel_filename;
440 char *kernel_cmdline;
441 char *shim_filename;
442 char *initrd_filename;
443 const char *cpu_type;
444 AccelState *accelerator;
445 CPUArchIdList *possible_cpus;
446 CpuTopology smp;
447 SmpCache smp_cache;
448 struct NVDIMMState *nvdimms_state;
449 struct NumaState *numa_state;
450 bool acpi_spcr_enabled;
451 /*
452 * Whether to change virtual machine accelerator handle upon
453 * reset or not. Used only for debugging and testing purpose.
454 * Set to false by default for all regular use.
455 */
456 bool new_accel_vmfd_on_reset;
457 };
458
459 /*
460 * The macros which follow are intended to facilitate the
461 * definition of versioned machine types, using a somewhat
462 * similar pattern across targets.
463 *
464 * For example, a macro that can be used to define versioned
465 * 'virt' machine types would look like:
466 *
467 * #define DEFINE_VIRT_MACHINE_IMPL(latest, ...) \
468 * static void MACHINE_VER_SYM(class_init, virt, __VA_ARGS__)( \
469 * ObjectClass *oc, \
470 * void *data) \
471 * { \
472 * MachineClass *mc = MACHINE_CLASS(oc); \
473 * MACHINE_VER_SYM(options, virt, __VA_ARGS__)(mc); \
474 * mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " Virtual Machine"; \
475 * MACHINE_VER_DEPRECATION(__VA_ARGS__); \
476 * if (latest) { \
477 * mc->alias = "virt"; \
478 * } \
479 * } \
480 * static const TypeInfo MACHINE_VER_SYM(info, virt, __VA_ARGS__) = { \
481 * .name = MACHINE_VER_TYPE_NAME("virt", __VA_ARGS__), \
482 * .parent = TYPE_VIRT_MACHINE, \
483 * .class_init = MACHINE_VER_SYM(class_init, virt, __VA_ARGS__), \
484 * }; \
485 * static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \
486 * { \
487 * MACHINE_VER_DELETION(__VA_ARGS__); \
488 * type_register_static(&MACHINE_VER_SYM(info, virt, __VA_ARGS__)); \
489 * } \
490 * type_init(MACHINE_VER_SYM(register, virt, __VA_ARGS__));
491 *
492 * Following this, one (or more) helpers can be added for
493 * whichever scenarios need to be catered for with a machine:
494 *
495 * // Normal 2 digit, marked as latest e.g. 'virt-9.0'
496 * #define DEFINE_VIRT_MACHINE_LATEST(major, minor) \
497 * DEFINE_VIRT_MACHINE_IMPL(true, major, minor)
498 *
499 * // Normal 2 digit e.g. 'virt-9.0'
500 * #define DEFINE_VIRT_MACHINE(major, minor) \
501 * DEFINE_VIRT_MACHINE_IMPL(false, major, minor)
502 *
503 * // Bugfix 3 digit e.g. 'virt-9.0.1'
504 * #define DEFINE_VIRT_MACHINE_BUGFIX(major, minor, micro) \
505 * DEFINE_VIRT_MACHINE_IMPL(false, major, minor, micro)
506 *
507 * // Tagged 2 digit e.g. 'virt-9.0-extra'
508 * #define DEFINE_VIRT_MACHINE_TAGGED(major, minor, tag) \
509 * DEFINE_VIRT_MACHINE_IMPL(false, major, minor, _, tag)
510 *
511 * // Tagged bugfix 2 digit e.g. 'virt-9.0.1-extra'
512 * #define DEFINE_VIRT_MACHINE_TAGGED(major, minor, micro, tag) \
513 * DEFINE_VIRT_MACHINE_IMPL(false, major, minor, micro, _, tag)
514 */
515
516 #define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
517 machine_initfn, ABSTRACT, ifaces...) \
518 static void machine_initfn##_class_init(ObjectClass *oc, const void *data) \
519 { \
520 MachineClass *mc = MACHINE_CLASS(oc); \
521 machine_initfn(mc); \
522 } \
523 static const TypeInfo machine_initfn##_typeinfo = { \
524 .name = MACHINE_TYPE_NAME(namestr), \
525 .parent = TYPE_##PARENT_NAME, \
526 .class_init = machine_initfn##_class_init, \
527 .instance_size = sizeof(InstanceName), \
528 .abstract = ABSTRACT, \
529 .interfaces = ifaces, \
530 }; \
531 static void machine_initfn##_register_types(void) \
532 { \
533 type_register_static(&machine_initfn##_typeinfo); \
534 } \
535 type_init(machine_initfn##_register_types)
536
537 #define DEFINE_MACHINE(namestr, machine_initfn) \
538 DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
539 false, NULL)
540
541 #define DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, ifaces...)\
542 DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
543 false, ifaces)
544
545 #define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
546 DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \
547 (const InterfaceInfo[]) { __VA_ARGS__ })
548
549 /*
550 * Helper for dispatching different macros based on how
551 * many __VA_ARGS__ are passed. Supports 1 to 5 variadic
552 * arguments, with the called target able to be prefixed
553 * with 0 or more fixed arguments too. To be called thus:
554 *
555 * _MACHINE_VER_PICK(__VA_ARGS,
556 * MACRO_MATCHING_5_ARGS,
557 * MACRO_MATCHING_4_ARGS,
558 * MACRO_MATCHING_3_ARGS,
559 * MACRO_MATCHING_2_ARGS,
560 * MACRO_MATCHING_1_ARG) (FIXED-ARG-1,
561 * ...,
562 * FIXED-ARG-N,
563 * __VA_ARGS__)
564 */
565 #define _MACHINE_VER_PICK(x1, x2, x3, x4, x5, x6, ...) x6
566
567 /*
568 * Construct a human targeted machine version string.
569 *
570 * Can be invoked with various signatures
571 *
572 * MACHINE_VER_STR(sym, prefix, major, minor)
573 * MACHINE_VER_STR(sym, prefix, major, minor, micro)
574 * MACHINE_VER_STR(sym, prefix, major, minor, _, tag)
575 * MACHINE_VER_STR(sym, prefix, major, minor, micro, _, tag)
576 *
577 * Respectively emitting symbols with the format
578 *
579 * "{major}.{minor}"
580 * "{major}.{minor}-{tag}"
581 * "{major}.{minor}.{micro}"
582 * "{major}.{minor}.{micro}-{tag}"
583 */
584 #define _MACHINE_VER_STR2(major, minor) \
585 #major "." #minor
586
587 #define _MACHINE_VER_STR3(major, minor, micro) \
588 #major "." #minor "." #micro
589
590 #define _MACHINE_VER_STR4(major, minor, _unused_, tag) \
591 #major "." #minor "-" #tag
592
593 #define _MACHINE_VER_STR5(major, minor, micro, _unused_, tag) \
594 #major "." #minor "." #micro "-" #tag
595
596 #define MACHINE_VER_STR(...) \
597 _MACHINE_VER_PICK(__VA_ARGS__, \
598 _MACHINE_VER_STR5, \
599 _MACHINE_VER_STR4, \
600 _MACHINE_VER_STR3, \
601 _MACHINE_VER_STR2) (__VA_ARGS__)
602
603
604 /*
605 * Construct a QAPI type name for a versioned machine
606 * type
607 *
608 * Can be invoked with various signatures
609 *
610 * MACHINE_VER_TYPE_NAME(prefix, major, minor)
611 * MACHINE_VER_TYPE_NAME(prefix, major, minor, micro)
612 * MACHINE_VER_TYPE_NAME(prefix, major, minor, _, tag)
613 * MACHINE_VER_TYPE_NAME(prefix, major, minor, micro, _, tag)
614 *
615 * Respectively emitting symbols with the format
616 *
617 * "{prefix}-{major}.{minor}"
618 * "{prefix}-{major}.{minor}.{micro}"
619 * "{prefix}-{major}.{minor}-{tag}"
620 * "{prefix}-{major}.{minor}.{micro}-{tag}"
621 */
622 #define _MACHINE_VER_TYPE_NAME2(prefix, major, minor) \
623 prefix "-" #major "." #minor TYPE_MACHINE_SUFFIX
624
625 #define _MACHINE_VER_TYPE_NAME3(prefix, major, minor, micro) \
626 prefix "-" #major "." #minor "." #micro TYPE_MACHINE_SUFFIX
627
628 #define _MACHINE_VER_TYPE_NAME4(prefix, major, minor, _unused_, tag) \
629 prefix "-" #major "." #minor "-" #tag TYPE_MACHINE_SUFFIX
630
631 #define _MACHINE_VER_TYPE_NAME5(prefix, major, minor, micro, _unused_, tag) \
632 prefix "-" #major "." #minor "." #micro "-" #tag TYPE_MACHINE_SUFFIX
633
634 #define MACHINE_VER_TYPE_NAME(prefix, ...) \
635 _MACHINE_VER_PICK(__VA_ARGS__, \
636 _MACHINE_VER_TYPE_NAME5, \
637 _MACHINE_VER_TYPE_NAME4, \
638 _MACHINE_VER_TYPE_NAME3, \
639 _MACHINE_VER_TYPE_NAME2) (prefix, __VA_ARGS__)
640
641 /*
642 * Construct a name for a versioned machine type that is
643 * suitable for use as a C symbol (function/variable/etc).
644 *
645 * Can be invoked with various signatures
646 *
647 * MACHINE_VER_SYM(sym, prefix, major, minor)
648 * MACHINE_VER_SYM(sym, prefix, major, minor, micro)
649 * MACHINE_VER_SYM(sym, prefix, major, minor, _, tag)
650 * MACHINE_VER_SYM(sym, prefix, major, minor, micro, _, tag)
651 *
652 * Respectively emitting symbols with the format
653 *
654 * {prefix}_machine_{major}_{minor}_{sym}
655 * {prefix}_machine_{major}_{minor}_{micro}_{sym}
656 * {prefix}_machine_{major}_{minor}_{tag}_{sym}
657 * {prefix}_machine_{major}_{minor}_{micro}_{tag}_{sym}
658 */
659 #define _MACHINE_VER_SYM2(sym, prefix, major, minor) \
660 prefix ## _machine_ ## major ## _ ## minor ## _ ## sym
661
662 #define _MACHINE_VER_SYM3(sym, prefix, major, minor, micro) \
663 prefix ## _machine_ ## major ## _ ## minor ## _ ## micro ## _ ## sym
664
665 #define _MACHINE_VER_SYM4(sym, prefix, major, minor, _unused_, tag) \
666 prefix ## _machine_ ## major ## _ ## minor ## _ ## tag ## _ ## sym
667
668 #define _MACHINE_VER_SYM5(sym, prefix, major, minor, micro, _unused_, tag) \
669 prefix ## _machine_ ## major ## _ ## minor ## _ ## micro ## _ ## tag ## _ ## sym
670
671 #define MACHINE_VER_SYM(sym, prefix, ...) \
672 _MACHINE_VER_PICK(__VA_ARGS__, \
673 _MACHINE_VER_SYM5, \
674 _MACHINE_VER_SYM4, \
675 _MACHINE_VER_SYM3, \
676 _MACHINE_VER_SYM2) (sym, prefix, __VA_ARGS__)
677
678
679 /*
680 * How many years/major releases for each phase
681 * of the life cycle. Assumes use of versioning
682 * scheme where major is bumped each year.
683 *
684 * These values must match the ver_machine_deprecation_version
685 * and ver_machine_deletion_version logic in docs/conf.py and
686 * the text in docs/about/deprecated.rst
687 */
688 #define MACHINE_VER_DELETION_MAJOR 6
689 #define MACHINE_VER_DEPRECATION_MAJOR 3
690
691 /*
692 * Expands to a static string containing a deprecation
693 * message for a versioned machine type
694 */
695 #define MACHINE_VER_DEPRECATION_MSG \
696 "machines more than " stringify(MACHINE_VER_DEPRECATION_MAJOR) \
697 " years old are subject to deletion after " \
698 stringify(MACHINE_VER_DELETION_MAJOR) " years"
699
700 #define _MACHINE_VER_IS_CURRENT_EXPIRED(cutoff, major, minor) \
701 (((QEMU_VERSION_MAJOR - major) > cutoff) || \
702 (((QEMU_VERSION_MAJOR - major) == cutoff) && \
703 (QEMU_VERSION_MINOR - minor) >= 0))
704
705 #define _MACHINE_VER_IS_NEXT_MINOR_EXPIRED(cutoff, major, minor) \
706 (((QEMU_VERSION_MAJOR - major) > cutoff) || \
707 (((QEMU_VERSION_MAJOR - major) == cutoff) && \
708 ((QEMU_VERSION_MINOR + 1) - minor) >= 0))
709
710 #define _MACHINE_VER_IS_NEXT_MAJOR_EXPIRED(cutoff, major, minor) \
711 ((((QEMU_VERSION_MAJOR + 1) - major) > cutoff) || \
712 ((((QEMU_VERSION_MAJOR + 1) - major) == cutoff) && \
713 (0 - minor) >= 0))
714
715 /*
716 * - The first check applies to formal releases
717 * - The second check applies to dev snapshots / release candidates
718 * where the next major version is the same.
719 * e.g. 9.0.50, 9.1.50, 9.0.90, 9.1.90
720 * - The third check applies to dev snapshots / release candidates
721 * where the next major version will change.
722 * e.g. 9.2.50, 9.2.90
723 *
724 * NB: this assumes we do 3 minor releases per year, before bumping major,
725 * and dev snapshots / release candidates are numbered with micro >= 50
726 * If this ever changes the logic below will need modifying....
727 */
728 #define _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor) \
729 ((QEMU_VERSION_MICRO < 50 && \
730 _MACHINE_VER_IS_CURRENT_EXPIRED(cutoff, major, minor)) || \
731 (QEMU_VERSION_MICRO >= 50 && QEMU_VERSION_MINOR < 2 && \
732 _MACHINE_VER_IS_NEXT_MINOR_EXPIRED(cutoff, major, minor)) || \
733 (QEMU_VERSION_MICRO >= 50 && QEMU_VERSION_MINOR == 2 && \
734 _MACHINE_VER_IS_NEXT_MAJOR_EXPIRED(cutoff, major, minor)))
735
736 #define _MACHINE_VER_IS_EXPIRED2(cutoff, major, minor) \
737 _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
738 #define _MACHINE_VER_IS_EXPIRED3(cutoff, major, minor, micro) \
739 _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
740 #define _MACHINE_VER_IS_EXPIRED4(cutoff, major, minor, _unused, tag) \
741 _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
742 #define _MACHINE_VER_IS_EXPIRED5(cutoff, major, minor, micro, _unused, tag) \
743 _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
744
745 #define _MACHINE_IS_EXPIRED(cutoff, ...) \
746 _MACHINE_VER_PICK(__VA_ARGS__, \
747 _MACHINE_VER_IS_EXPIRED5, \
748 _MACHINE_VER_IS_EXPIRED4, \
749 _MACHINE_VER_IS_EXPIRED3, \
750 _MACHINE_VER_IS_EXPIRED2) (cutoff, __VA_ARGS__)
751
752 /*
753 * Evaluates true when a machine type with (major, minor)
754 * or (major, minor, micro) version should be considered
755 * deprecated based on the current versioned machine type
756 * lifecycle rules
757 */
758 #define MACHINE_VER_IS_DEPRECATED(...) \
759 _MACHINE_IS_EXPIRED(MACHINE_VER_DEPRECATION_MAJOR, __VA_ARGS__)
760
761 /*
762 * Evaluates true when a machine type with (major, minor)
763 * or (major, minor, micro) version should be considered
764 * for deletion based on the current versioned machine type
765 * lifecycle rules
766 */
767 #define MACHINE_VER_SHOULD_DELETE(...) \
768 _MACHINE_IS_EXPIRED(MACHINE_VER_DELETION_MAJOR, __VA_ARGS__)
769
770 /*
771 * Sets the deprecation reason for a versioned machine based
772 * on its age
773 *
774 * This must be unconditionally used in the _class_init
775 * function for all machine types which support versioning.
776 *
777 * Initially it will effectively be a no-op, but after a
778 * suitable period of time has passed, it will set the
779 * 'deprecation_reason' field on the machine, to warn users
780 * about forthcoming removal.
781 */
782 #define MACHINE_VER_DEPRECATION(...) \
783 do { \
784 if (MACHINE_VER_IS_DEPRECATED(__VA_ARGS__)) { \
785 mc->deprecation_reason = MACHINE_VER_DEPRECATION_MSG; \
786 } \
787 } while (0)
788
789 /*
790 * Prevents registration of a versioned machined based on
791 * its age
792 *
793 * This must be unconditionally used in the register
794 * method for all machine types which support versioning.
795 *
796 * Inijtially it will effectively be a no-op, but after a
797 * suitable period of time has passed, it will cause
798 * execution of the method to return, avoiding registration
799 * of the machine
800 */
801 #define MACHINE_VER_DELETION(...) \
802 do { \
803 if (MACHINE_VER_SHOULD_DELETE(__VA_ARGS__)) { \
804 return; \
805 } \
806 } while (0)
807
808 static inline void
809 compat_props_add(GPtrArray *arr,
810 GlobalProperty props[], size_t nelem)
811 {
812 int i;
813 for (i = 0; i < nelem; i++) {
814 g_ptr_array_add(arr, (void *)&props[i]);
815 }
816 }
817
818 extern GlobalProperty hw_compat_11_1[];
819 extern const size_t hw_compat_11_1_len;
820
821 extern GlobalProperty hw_compat_11_0[];
822 extern const size_t hw_compat_11_0_len;
823
824 extern GlobalProperty hw_compat_10_2[];
825 extern const size_t hw_compat_10_2_len;
826
827 extern GlobalProperty hw_compat_10_1[];
828 extern const size_t hw_compat_10_1_len;
829
830 extern GlobalProperty hw_compat_10_0[];
831 extern const size_t hw_compat_10_0_len;
832
833 extern GlobalProperty hw_compat_9_2[];
834 extern const size_t hw_compat_9_2_len;
835
836 extern GlobalProperty hw_compat_9_1[];
837 extern const size_t hw_compat_9_1_len;
838
839 extern GlobalProperty hw_compat_9_0[];
840 extern const size_t hw_compat_9_0_len;
841
842 extern GlobalProperty hw_compat_8_2[];
843 extern const size_t hw_compat_8_2_len;
844
845 extern GlobalProperty hw_compat_8_1[];
846 extern const size_t hw_compat_8_1_len;
847
848 extern GlobalProperty hw_compat_8_0[];
849 extern const size_t hw_compat_8_0_len;
850
851 extern GlobalProperty hw_compat_7_2[];
852 extern const size_t hw_compat_7_2_len;
853
854 extern GlobalProperty hw_compat_7_1[];
855 extern const size_t hw_compat_7_1_len;
856
857 extern GlobalProperty hw_compat_7_0[];
858 extern const size_t hw_compat_7_0_len;
859
860 extern GlobalProperty hw_compat_6_2[];
861 extern const size_t hw_compat_6_2_len;
862
863 extern GlobalProperty hw_compat_6_1[];
864 extern const size_t hw_compat_6_1_len;
865
866 extern GlobalProperty hw_compat_6_0[];
867 extern const size_t hw_compat_6_0_len;
868
869 extern GlobalProperty hw_compat_5_2[];
870 extern const size_t hw_compat_5_2_len;
871
872 extern GlobalProperty hw_compat_5_1[];
873 extern const size_t hw_compat_5_1_len;
874
875 extern GlobalProperty hw_compat_5_0[];
876 extern const size_t hw_compat_5_0_len;
877
878 extern GlobalProperty hw_compat_4_2[];
879 extern const size_t hw_compat_4_2_len;
880
881 extern GlobalProperty hw_compat_4_1[];
882 extern const size_t hw_compat_4_1_len;
883
884 #endif