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