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