xref: /openbmc/qemu/include/hw/boards.h (revision 646b5378)
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     bool (*create_default_memdev)(MachineState *ms, const char *path,
318                                   Error **errp);
319 };
320 
321 /**
322  * DeviceMemoryState:
323  * @base: address in guest physical address space where the memory
324  * address space for memory devices starts
325  * @mr: memory region container for memory devices
326  * @as: address space for memory devices
327  * @listener: memory listener used to track used memslots in the address space
328  * @dimm_size: the sum of plugged DIMMs' sizes
329  * @used_region_size: the part of @mr already used by memory devices
330  * @required_memslots: the number of memslots required by memory devices
331  * @used_memslots: the number of memslots currently used by memory devices
332  * @memslot_auto_decision_active: whether any plugged memory device
333  *                                automatically decided to use more than
334  *                                one memslot
335  */
336 typedef struct DeviceMemoryState {
337     hwaddr base;
338     MemoryRegion mr;
339     AddressSpace as;
340     MemoryListener listener;
341     uint64_t dimm_size;
342     uint64_t used_region_size;
343     unsigned int required_memslots;
344     unsigned int used_memslots;
345     unsigned int memslot_auto_decision_active;
346 } DeviceMemoryState;
347 
348 /**
349  * CpuTopology:
350  * @cpus: the number of present logical processors on the machine
351  * @drawers: the number of drawers on the machine
352  * @books: the number of books in one drawer
353  * @sockets: the number of sockets in one book
354  * @dies: the number of dies in one socket
355  * @clusters: the number of clusters in one die
356  * @modules: the number of modules in one cluster
357  * @cores: the number of cores in one cluster
358  * @threads: the number of threads in one core
359  * @max_cpus: the maximum number of logical processors on the machine
360  */
361 typedef struct CpuTopology {
362     unsigned int cpus;
363     unsigned int drawers;
364     unsigned int books;
365     unsigned int sockets;
366     unsigned int dies;
367     unsigned int clusters;
368     unsigned int modules;
369     unsigned int cores;
370     unsigned int threads;
371     unsigned int max_cpus;
372 } CpuTopology;
373 
374 /**
375  * MachineState:
376  */
377 struct MachineState {
378     /*< private >*/
379     Object parent_obj;
380 
381     /*< public >*/
382 
383     void *fdt;
384     char *dtb;
385     char *dumpdtb;
386     int phandle_start;
387     char *dt_compatible;
388     bool dump_guest_core;
389     bool mem_merge;
390     bool usb;
391     bool usb_disabled;
392     char *firmware;
393     bool iommu;
394     bool suppress_vmdesc;
395     bool enable_graphics;
396     ConfidentialGuestSupport *cgs;
397     HostMemoryBackend *memdev;
398     /*
399      * convenience alias to ram_memdev_id backend memory region
400      * or to numa container memory region
401      */
402     MemoryRegion *ram;
403     DeviceMemoryState *device_memory;
404 
405     /*
406      * Included in MachineState for simplicity, but not supported
407      * unless machine_add_audiodev_property is called.  Boards
408      * that have embedded audio devices can call it from the
409      * machine init function and forward the property to the device.
410      */
411     char *audiodev;
412 
413     ram_addr_t ram_size;
414     ram_addr_t maxram_size;
415     uint64_t   ram_slots;
416     BootConfiguration boot_config;
417     char *kernel_filename;
418     char *kernel_cmdline;
419     char *initrd_filename;
420     const char *cpu_type;
421     AccelState *accelerator;
422     CPUArchIdList *possible_cpus;
423     CpuTopology smp;
424     struct NVDIMMState *nvdimms_state;
425     struct NumaState *numa_state;
426 };
427 
428 /*
429  * The macros which follow are intended to facilitate the
430  * definition of versioned machine types, using a somewhat
431  * similar pattern across targets.
432  *
433  * For example, a macro that can be used to define versioned
434  * 'virt' machine types would look like:
435  *
436  *  #define DEFINE_VIRT_MACHINE_IMPL(latest, ...) \
437  *      static void MACHINE_VER_SYM(class_init, virt, __VA_ARGS__)( \
438  *          ObjectClass *oc, \
439  *          void *data) \
440  *      { \
441  *          MachineClass *mc = MACHINE_CLASS(oc); \
442  *          MACHINE_VER_SYM(options, virt, __VA_ARGS__)(mc); \
443  *          mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " Virtual Machine"; \
444  *          MACHINE_VER_DEPRECATION(__VA_ARGS__); \
445  *          if (latest) { \
446  *              mc->alias = "virt"; \
447  *          } \
448  *      } \
449  *      static const TypeInfo MACHINE_VER_SYM(info, virt, __VA_ARGS__) = { \
450  *          .name = MACHINE_VER_TYPE_NAME("virt", __VA_ARGS__), \
451  *          .parent = TYPE_VIRT_MACHINE, \
452  *          .class_init = MACHINE_VER_SYM(class_init, virt, __VA_ARGS__), \
453  *      }; \
454  *      static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \
455  *      { \
456  *          MACHINE_VER_DELETION(__VA_ARGS__); \
457  *          type_register_static(&MACHINE_VER_SYM(info, virt, __VA_ARGS__)); \
458  *      } \
459  *      type_init(MACHINE_VER_SYM(register, virt, __VA_ARGS__));
460  *
461  * Following this, one (or more) helpers can be added for
462  * whichever scenarios need to be catered for with a machine:
463  *
464  *  // Normal 2 digit, marked as latest e.g. 'virt-9.0'
465  *  #define DEFINE_VIRT_MACHINE_LATEST(major, minor) \
466  *      DEFINE_VIRT_MACHINE_IMPL(true, major, minor)
467  *
468  *  // Normal 2 digit e.g. 'virt-9.0'
469  *  #define DEFINE_VIRT_MACHINE(major, minor) \
470  *      DEFINE_VIRT_MACHINE_IMPL(false, major, minor)
471  *
472  *  // Bugfix 3 digit e.g. 'virt-9.0.1'
473  *  #define DEFINE_VIRT_MACHINE_BUGFIX(major, minor, micro) \
474  *      DEFINE_VIRT_MACHINE_IMPL(false, major, minor, micro)
475  *
476  *  // Tagged 2 digit e.g. 'virt-9.0-extra'
477  *  #define DEFINE_VIRT_MACHINE_TAGGED(major, minor, tag) \
478  *      DEFINE_VIRT_MACHINE_IMPL(false, major, minor, _, tag)
479  *
480  *  // Tagged bugfix 2 digit e.g. 'virt-9.0.1-extra'
481  *  #define DEFINE_VIRT_MACHINE_TAGGED(major, minor, micro, tag) \
482  *      DEFINE_VIRT_MACHINE_IMPL(false, major, minor, micro, _, tag)
483  */
484 
485 /*
486  * Helper for dispatching different macros based on how
487  * many __VA_ARGS__ are passed. Supports 1 to 5 variadic
488  * arguments, with the called target able to be prefixed
489  * with 0 or more fixed arguments too. To be called thus:
490  *
491  *  _MACHINE_VER_PICK(__VA_ARGS,
492  *                    MACRO_MATCHING_5_ARGS,
493  *                    MACRO_MATCHING_4_ARGS,
494  *                    MACRO_MATCHING_3_ARGS,
495  *                    MACRO_MATCHING_2_ARGS,
496  *                    MACRO_MATCHING_1_ARG) (FIXED-ARG-1,
497  *                                           ...,
498  *                                           FIXED-ARG-N,
499  *                                           __VA_ARGS__)
500  */
501 #define _MACHINE_VER_PICK(x1, x2, x3, x4, x5, x6, ...) x6
502 
503 /*
504  * Construct a human targeted machine version string.
505  *
506  * Can be invoked with various signatures
507  *
508  *  MACHINE_VER_STR(sym, prefix, major, minor)
509  *  MACHINE_VER_STR(sym, prefix, major, minor, micro)
510  *  MACHINE_VER_STR(sym, prefix, major, minor, _, tag)
511  *  MACHINE_VER_STR(sym, prefix, major, minor, micro, _, tag)
512  *
513  * Respectively emitting symbols with the format
514  *
515  *   "{major}.{minor}"
516  *   "{major}.{minor}-{tag}"
517  *   "{major}.{minor}.{micro}"
518  *   "{major}.{minor}.{micro}-{tag}"
519  */
520 #define _MACHINE_VER_STR2(major, minor) \
521     #major "." #minor
522 
523 #define _MACHINE_VER_STR3(major, minor, micro) \
524     #major "." #minor "." #micro
525 
526 #define _MACHINE_VER_STR4(major, minor, _unused_, tag) \
527     #major "." #minor "-" #tag
528 
529 #define _MACHINE_VER_STR5(major, minor, micro, _unused_, tag) \
530     #major "." #minor "." #micro "-" #tag
531 
532 #define MACHINE_VER_STR(...) \
533     _MACHINE_VER_PICK(__VA_ARGS__, \
534                       _MACHINE_VER_STR5, \
535                       _MACHINE_VER_STR4, \
536                       _MACHINE_VER_STR3, \
537                       _MACHINE_VER_STR2) (__VA_ARGS__)
538 
539 
540 /*
541  * Construct a QAPI type name for a versioned machine
542  * type
543  *
544  * Can be invoked with various signatures
545  *
546  *  MACHINE_VER_TYPE_NAME(prefix, major, minor)
547  *  MACHINE_VER_TYPE_NAME(prefix, major, minor, micro)
548  *  MACHINE_VER_TYPE_NAME(prefix, major, minor, _, tag)
549  *  MACHINE_VER_TYPE_NAME(prefix, major, minor, micro, _, tag)
550  *
551  * Respectively emitting symbols with the format
552  *
553  *   "{prefix}-{major}.{minor}"
554  *   "{prefix}-{major}.{minor}.{micro}"
555  *   "{prefix}-{major}.{minor}-{tag}"
556  *   "{prefix}-{major}.{minor}.{micro}-{tag}"
557  */
558 #define _MACHINE_VER_TYPE_NAME2(prefix, major, minor)   \
559     prefix "-" #major "." #minor TYPE_MACHINE_SUFFIX
560 
561 #define _MACHINE_VER_TYPE_NAME3(prefix, major, minor, micro) \
562     prefix "-" #major "." #minor "." #micro TYPE_MACHINE_SUFFIX
563 
564 #define _MACHINE_VER_TYPE_NAME4(prefix, major, minor, _unused_, tag) \
565     prefix "-" #major "." #minor "-" #tag TYPE_MACHINE_SUFFIX
566 
567 #define _MACHINE_VER_TYPE_NAME5(prefix, major, minor, micro, _unused_, tag) \
568     prefix "-" #major "." #minor "." #micro "-" #tag TYPE_MACHINE_SUFFIX
569 
570 #define MACHINE_VER_TYPE_NAME(prefix, ...) \
571     _MACHINE_VER_PICK(__VA_ARGS__, \
572                       _MACHINE_VER_TYPE_NAME5, \
573                       _MACHINE_VER_TYPE_NAME4, \
574                       _MACHINE_VER_TYPE_NAME3, \
575                       _MACHINE_VER_TYPE_NAME2) (prefix, __VA_ARGS__)
576 
577 /*
578  * Construct a name for a versioned machine type that is
579  * suitable for use as a C symbol (function/variable/etc).
580  *
581  * Can be invoked with various signatures
582  *
583  *  MACHINE_VER_SYM(sym, prefix, major, minor)
584  *  MACHINE_VER_SYM(sym, prefix, major, minor, micro)
585  *  MACHINE_VER_SYM(sym, prefix, major, minor, _, tag)
586  *  MACHINE_VER_SYM(sym, prefix, major, minor, micro, _, tag)
587  *
588  * Respectively emitting symbols with the format
589  *
590  *   {prefix}_machine_{major}_{minor}_{sym}
591  *   {prefix}_machine_{major}_{minor}_{micro}_{sym}
592  *   {prefix}_machine_{major}_{minor}_{tag}_{sym}
593  *   {prefix}_machine_{major}_{minor}_{micro}_{tag}_{sym}
594  */
595 #define _MACHINE_VER_SYM2(sym, prefix, major, minor) \
596     prefix ## _machine_ ## major ## _ ## minor ## _ ## sym
597 
598 #define _MACHINE_VER_SYM3(sym, prefix, major, minor, micro) \
599     prefix ## _machine_ ## major ## _ ## minor ## _ ## micro ## _ ## sym
600 
601 #define _MACHINE_VER_SYM4(sym, prefix, major, minor, _unused_, tag) \
602     prefix ## _machine_ ## major ## _ ## minor ## _ ## tag ## _ ## sym
603 
604 #define _MACHINE_VER_SYM5(sym, prefix, major, minor, micro, _unused_, tag) \
605     prefix ## _machine_ ## major ## _ ## minor ## _ ## micro ## _ ## tag ## _ ## sym
606 
607 #define MACHINE_VER_SYM(sym, prefix, ...) \
608     _MACHINE_VER_PICK(__VA_ARGS__, \
609                       _MACHINE_VER_SYM5, \
610                       _MACHINE_VER_SYM4, \
611                       _MACHINE_VER_SYM3, \
612                       _MACHINE_VER_SYM2) (sym, prefix, __VA_ARGS__)
613 
614 
615 /*
616  * How many years/major releases for each phase
617  * of the life cycle. Assumes use of versioning
618  * scheme where major is bumped each year
619  */
620 #define MACHINE_VER_DELETION_MAJOR 6
621 #define MACHINE_VER_DEPRECATION_MAJOR 3
622 
623 /*
624  * Expands to a static string containing a deprecation
625  * message for a versioned machine type
626  */
627 #define MACHINE_VER_DEPRECATION_MSG \
628     "machines more than " stringify(MACHINE_VER_DEPRECATION_MAJOR) \
629     " years old are subject to deletion after " \
630     stringify(MACHINE_VER_DELETION_MAJOR) " years"
631 
632 #define _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor) \
633     (((QEMU_VERSION_MAJOR - major) > cutoff) || \
634      (((QEMU_VERSION_MAJOR - major) == cutoff) && \
635       (QEMU_VERSION_MINOR - minor) >= 0))
636 
637 #define _MACHINE_VER_IS_EXPIRED2(cutoff, major, minor) \
638     _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
639 #define _MACHINE_VER_IS_EXPIRED3(cutoff, major, minor, micro) \
640     _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
641 #define _MACHINE_VER_IS_EXPIRED4(cutoff, major, minor, _unused, tag) \
642     _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
643 #define _MACHINE_VER_IS_EXPIRED5(cutoff, major, minor, micro, _unused, tag)   \
644     _MACHINE_VER_IS_EXPIRED_IMPL(cutoff, major, minor)
645 
646 #define _MACHINE_IS_EXPIRED(cutoff, ...) \
647     _MACHINE_VER_PICK(__VA_ARGS__, \
648                       _MACHINE_VER_IS_EXPIRED5, \
649                       _MACHINE_VER_IS_EXPIRED4, \
650                       _MACHINE_VER_IS_EXPIRED3, \
651                       _MACHINE_VER_IS_EXPIRED2) (cutoff, __VA_ARGS__)
652 
653 /*
654  * Evaluates true when a machine type with (major, minor)
655  * or (major, minor, micro) version should be considered
656  * deprecated based on the current versioned machine type
657  * lifecycle rules
658  */
659 #define MACHINE_VER_IS_DEPRECATED(...) \
660     _MACHINE_IS_EXPIRED(MACHINE_VER_DEPRECATION_MAJOR, __VA_ARGS__)
661 
662 /*
663  * Evaluates true when a machine type with (major, minor)
664  * or (major, minor, micro) version should be considered
665  * for deletion based on the current versioned machine type
666  * lifecycle rules
667  */
668 #define MACHINE_VER_SHOULD_DELETE(...) \
669     _MACHINE_IS_EXPIRED(MACHINE_VER_DELETION_MAJOR, __VA_ARGS__)
670 
671 /*
672  * Sets the deprecation reason for a versioned machine based
673  * on its age
674  *
675  * This must be unconditionally used in the _class_init
676  * function for all machine types which support versioning.
677  *
678  * Initially it will effectively be a no-op, but after a
679  * suitable period of time has passed, it will set the
680  * 'deprecation_reason' field on the machine, to warn users
681  * about forthcoming removal.
682  */
683 #define MACHINE_VER_DEPRECATION(...) \
684     do { \
685         if (MACHINE_VER_IS_DEPRECATED(__VA_ARGS__)) { \
686             mc->deprecation_reason = MACHINE_VER_DEPRECATION_MSG; \
687         } \
688     } while (0)
689 
690 /*
691  * Prevents registration of a versioned machined based on
692  * its age
693  *
694  * This must be unconditionally used in the register
695  * method for all machine types which support versioning.
696  *
697  * Inijtially it will effectively be a no-op, but after a
698  * suitable period of time has passed, it will cause
699  * execution of the method to return, avoiding registration
700  * of the machine
701  *
702  * The new deprecation and deletion policy for versioned
703  * machine types was introduced in QEMU 9.1.0.
704  *
705  * Under the new policy a number of old machine types (any
706  * prior to 2.12) would be liable for immediate deletion
707  * which would be a violation of our historical deprecation
708  * and removal policy
709  *
710  * Thus deletions are temporarily gated on existance of
711  * the env variable "QEMU_DELETE_MACHINES" / QEMU version
712  * number >= 10.1.0. This gate can be deleted in the 10.1.0
713  * dev cycle
714  */
715 #define MACHINE_VER_DELETION(...) \
716     do { \
717         if (MACHINE_VER_SHOULD_DELETE(__VA_ARGS__)) { \
718             if (getenv("QEMU_DELETE_MACHINES") || \
719                 QEMU_VERSION_MAJOR > 10 || (QEMU_VERSION_MAJOR == 10 && \
720                                             QEMU_VERSION_MINOR >= 1)) { \
721                 return; \
722             } \
723         } \
724     } while (0)
725 
726 #define DEFINE_MACHINE(namestr, machine_initfn) \
727     static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
728     { \
729         MachineClass *mc = MACHINE_CLASS(oc); \
730         machine_initfn(mc); \
731     } \
732     static const TypeInfo machine_initfn##_typeinfo = { \
733         .name       = MACHINE_TYPE_NAME(namestr), \
734         .parent     = TYPE_MACHINE, \
735         .class_init = machine_initfn##_class_init, \
736     }; \
737     static void machine_initfn##_register_types(void) \
738     { \
739         type_register_static(&machine_initfn##_typeinfo); \
740     } \
741     type_init(machine_initfn##_register_types)
742 
743 extern GlobalProperty hw_compat_9_1[];
744 extern const size_t hw_compat_9_1_len;
745 
746 extern GlobalProperty hw_compat_9_0[];
747 extern const size_t hw_compat_9_0_len;
748 
749 extern GlobalProperty hw_compat_8_2[];
750 extern const size_t hw_compat_8_2_len;
751 
752 extern GlobalProperty hw_compat_8_1[];
753 extern const size_t hw_compat_8_1_len;
754 
755 extern GlobalProperty hw_compat_8_0[];
756 extern const size_t hw_compat_8_0_len;
757 
758 extern GlobalProperty hw_compat_7_2[];
759 extern const size_t hw_compat_7_2_len;
760 
761 extern GlobalProperty hw_compat_7_1[];
762 extern const size_t hw_compat_7_1_len;
763 
764 extern GlobalProperty hw_compat_7_0[];
765 extern const size_t hw_compat_7_0_len;
766 
767 extern GlobalProperty hw_compat_6_2[];
768 extern const size_t hw_compat_6_2_len;
769 
770 extern GlobalProperty hw_compat_6_1[];
771 extern const size_t hw_compat_6_1_len;
772 
773 extern GlobalProperty hw_compat_6_0[];
774 extern const size_t hw_compat_6_0_len;
775 
776 extern GlobalProperty hw_compat_5_2[];
777 extern const size_t hw_compat_5_2_len;
778 
779 extern GlobalProperty hw_compat_5_1[];
780 extern const size_t hw_compat_5_1_len;
781 
782 extern GlobalProperty hw_compat_5_0[];
783 extern const size_t hw_compat_5_0_len;
784 
785 extern GlobalProperty hw_compat_4_2[];
786 extern const size_t hw_compat_4_2_len;
787 
788 extern GlobalProperty hw_compat_4_1[];
789 extern const size_t hw_compat_4_1_len;
790 
791 extern GlobalProperty hw_compat_4_0[];
792 extern const size_t hw_compat_4_0_len;
793 
794 extern GlobalProperty hw_compat_3_1[];
795 extern const size_t hw_compat_3_1_len;
796 
797 extern GlobalProperty hw_compat_3_0[];
798 extern const size_t hw_compat_3_0_len;
799 
800 extern GlobalProperty hw_compat_2_12[];
801 extern const size_t hw_compat_2_12_len;
802 
803 extern GlobalProperty hw_compat_2_11[];
804 extern const size_t hw_compat_2_11_len;
805 
806 extern GlobalProperty hw_compat_2_10[];
807 extern const size_t hw_compat_2_10_len;
808 
809 extern GlobalProperty hw_compat_2_9[];
810 extern const size_t hw_compat_2_9_len;
811 
812 extern GlobalProperty hw_compat_2_8[];
813 extern const size_t hw_compat_2_8_len;
814 
815 extern GlobalProperty hw_compat_2_7[];
816 extern const size_t hw_compat_2_7_len;
817 
818 extern GlobalProperty hw_compat_2_6[];
819 extern const size_t hw_compat_2_6_len;
820 
821 extern GlobalProperty hw_compat_2_5[];
822 extern const size_t hw_compat_2_5_len;
823 
824 extern GlobalProperty hw_compat_2_4[];
825 extern const size_t hw_compat_2_4_len;
826 
827 extern GlobalProperty hw_compat_2_3[];
828 extern const size_t hw_compat_2_3_len;
829 
830 extern GlobalProperty hw_compat_2_2[];
831 extern const size_t hw_compat_2_2_len;
832 
833 extern GlobalProperty hw_compat_2_1[];
834 extern const size_t hw_compat_2_1_len;
835 
836 #endif
837