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