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