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