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