boards.h 30 KB

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