boards.h 30 KB

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