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