boards.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. #define TYPE_MACHINE_SUFFIX "-machine"
  12. /* Machine class name that needs to be used for class-name-based machine
  13. * type lookup to work.
  14. */
  15. #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)
  16. #define TYPE_MACHINE "machine"
  17. #undef MACHINE /* BSD defines it and QEMU does not use it */
  18. OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
  19. extern MachineState *current_machine;
  20. void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp);
  21. bool machine_usb(MachineState *machine);
  22. int machine_phandle_start(MachineState *machine);
  23. bool machine_dump_guest_core(MachineState *machine);
  24. bool machine_mem_merge(MachineState *machine);
  25. HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
  26. void machine_set_cpu_numa_node(MachineState *machine,
  27. const CpuInstanceProperties *props,
  28. Error **errp);
  29. void machine_parse_smp_config(MachineState *ms,
  30. const SMPConfiguration *config, Error **errp);
  31. /**
  32. * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
  33. * @mc: Machine class
  34. * @type: type to allow (should be a subtype of TYPE_SYS_BUS_DEVICE)
  35. *
  36. * Add the QOM type @type to the list of devices of which are subtypes
  37. * of TYPE_SYS_BUS_DEVICE but which are still permitted to be dynamically
  38. * created (eg by the user on the command line with -device).
  39. * By default if the user tries to create any devices on the command line
  40. * that are subtypes of TYPE_SYS_BUS_DEVICE they will get an error message;
  41. * for the special cases which are permitted for this machine model, the
  42. * machine model class init code must call this function to add them
  43. * to the list of specifically permitted devices.
  44. */
  45. void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
  46. /**
  47. * device_type_is_dynamic_sysbus: Check if type is an allowed sysbus device
  48. * type for the machine class.
  49. * @mc: Machine class
  50. * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE)
  51. *
  52. * Returns: true if @type is a type in the machine's list of
  53. * dynamically pluggable sysbus devices; otherwise false.
  54. *
  55. * Check if the QOM type @type is in the list of allowed sysbus device
  56. * types (see machine_class_allowed_dynamic_sysbus_dev()).
  57. * Note that if @type has a parent type in the list, it is allowed too.
  58. */
  59. bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type);
  60. /**
  61. * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device
  62. * @mc: Machine class
  63. * @dev: device to check
  64. *
  65. * Returns: true if @dev is a sysbus device on the machine's list
  66. * of dynamically pluggable sysbus devices; otherwise false.
  67. *
  68. * This function checks whether @dev is a valid dynamic sysbus device,
  69. * by first confirming that it is a sysbus device and then checking it
  70. * against the list of permitted dynamic sysbus devices which has been
  71. * set up by the machine using machine_class_allow_dynamic_sysbus_dev().
  72. *
  73. * It is valid to call this with something that is not a subclass of
  74. * TYPE_SYS_BUS_DEVICE; the function will return false in this case.
  75. * This allows hotplug callback functions to be written as:
  76. * if (device_is_dynamic_sysbus(mc, dev)) {
  77. * handle dynamic sysbus case;
  78. * } else if (some other kind of hotplug) {
  79. * handle that;
  80. * }
  81. */
  82. bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev);
  83. /*
  84. * Checks that backend isn't used, preps it for exclusive usage and
  85. * returns migratable MemoryRegion provided by backend.
  86. */
  87. MemoryRegion *machine_consume_memdev(MachineState *machine,
  88. HostMemoryBackend *backend);
  89. /**
  90. * CPUArchId:
  91. * @arch_id - architecture-dependent CPU ID of present or possible CPU
  92. * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
  93. * @type - QOM class name of possible @cpu object
  94. * @props - CPU object properties, initialized by board
  95. * #vcpus_count - number of threads provided by @cpu object
  96. */
  97. typedef struct CPUArchId {
  98. uint64_t arch_id;
  99. int64_t vcpus_count;
  100. CpuInstanceProperties props;
  101. Object *cpu;
  102. const char *type;
  103. } CPUArchId;
  104. /**
  105. * CPUArchIdList:
  106. * @len - number of @CPUArchId items in @cpus array
  107. * @cpus - array of present or possible CPUs for current machine configuration
  108. */
  109. typedef struct {
  110. int len;
  111. CPUArchId cpus[];
  112. } CPUArchIdList;
  113. /**
  114. * SMPCompatProps:
  115. * @prefer_sockets - whether sockets are preferred over cores in smp parsing
  116. * @dies_supported - whether dies are supported by the machine
  117. * @clusters_supported - whether clusters are supported by the machine
  118. * @has_clusters - whether clusters are explicitly specified in the user
  119. * provided SMP configuration
  120. */
  121. typedef struct {
  122. bool prefer_sockets;
  123. bool dies_supported;
  124. bool clusters_supported;
  125. bool has_clusters;
  126. } SMPCompatProps;
  127. /**
  128. * MachineClass:
  129. * @deprecation_reason: If set, the machine is marked as deprecated. The
  130. * string should provide some clear information about what to use instead.
  131. * @max_cpus: maximum number of CPUs supported. Default: 1
  132. * @min_cpus: minimum number of CPUs supported. Default: 1
  133. * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
  134. * @is_default:
  135. * If true QEMU will use this machine by default if no '-M' option is given.
  136. * @get_hotplug_handler: this function is called during bus-less
  137. * device hotplug. If defined it returns pointer to an instance
  138. * of HotplugHandler object, which handles hotplug operation
  139. * for a given @dev. It may return NULL if @dev doesn't require
  140. * any actions to be performed by hotplug handler.
  141. * @cpu_index_to_instance_props:
  142. * used to provide @cpu_index to socket/core/thread number mapping, allowing
  143. * legacy code to perform maping from cpu_index to topology properties
  144. * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
  145. * used to provide @cpu_index to socket number mapping, allowing
  146. * a machine to group CPU threads belonging to the same socket/package
  147. * Returns: socket number given cpu_index belongs to.
  148. * @hw_version:
  149. * Value of QEMU_VERSION when the machine was added to QEMU.
  150. * Set only by old machines because they need to keep
  151. * compatibility on code that exposed QEMU_VERSION to guests in
  152. * the past (and now use qemu_hw_version()).
  153. * @possible_cpu_arch_ids:
  154. * Returns an array of @CPUArchId architecture-dependent CPU IDs
  155. * which includes CPU IDs for present and possible to hotplug CPUs.
  156. * Caller is responsible for freeing returned list.
  157. * @get_default_cpu_node_id:
  158. * returns default board specific node_id value for CPU slot specified by
  159. * index @idx in @ms->possible_cpus[]
  160. * @has_hotpluggable_cpus:
  161. * If true, board supports CPUs creation with -device/device_add.
  162. * @default_cpu_type:
  163. * specifies default CPU_TYPE, which will be used for parsing target
  164. * specific features and for creating CPUs if CPU name wasn't provided
  165. * explicitly at CLI
  166. * @minimum_page_bits:
  167. * If non-zero, the board promises never to create a CPU with a page size
  168. * smaller than this, so QEMU can use a more efficient larger page
  169. * size than the target architecture's minimum. (Attempting to create
  170. * such a CPU will fail.) Note that changing this is a migration
  171. * compatibility break for the machine.
  172. * @ignore_memory_transaction_failures:
  173. * If this is flag is true then the CPU will ignore memory transaction
  174. * failures which should cause the CPU to take an exception due to an
  175. * access to an unassigned physical address; the transaction will instead
  176. * return zero (for a read) or be ignored (for a write). This should be
  177. * set only by legacy board models which rely on the old RAZ/WI behaviour
  178. * for handling devices that QEMU does not yet model. New board models
  179. * should instead use "unimplemented-device" for all memory ranges where
  180. * the guest will attempt to probe for a device that QEMU doesn't
  181. * implement and a stub device is required.
  182. * @kvm_type:
  183. * Return the type of KVM corresponding to the kvm-type string option or
  184. * computed based on other criteria such as the host kernel capabilities.
  185. * kvm-type may be NULL if it is not needed.
  186. * @numa_mem_supported:
  187. * true if '--numa node.mem' option is supported and false otherwise
  188. * @hotplug_allowed:
  189. * If the hook is provided, then it'll be called for each device
  190. * hotplug to check whether the device hotplug is allowed. Return
  191. * true to grant allowance or false to reject the hotplug. When
  192. * false is returned, an error must be set to show the reason of
  193. * the rejection. If the hook is not provided, all hotplug will be
  194. * allowed.
  195. * @default_ram_id:
  196. * Specifies inital RAM MemoryRegion name to be used for default backend
  197. * creation if user explicitly hasn't specified backend with "memory-backend"
  198. * property.
  199. * It also will be used as a way to optin into "-m" option support.
  200. * If it's not set by board, '-m' will be ignored and generic code will
  201. * not create default RAM MemoryRegion.
  202. * @fixup_ram_size:
  203. * Amends user provided ram size (with -m option) using machine
  204. * specific algorithm. To be used by old machine types for compat
  205. * purposes only.
  206. * Applies only to default memory backend, i.e., explicit memory backend
  207. * wasn't used.
  208. */
  209. struct MachineClass {
  210. /*< private >*/
  211. ObjectClass parent_class;
  212. /*< public >*/
  213. const char *family; /* NULL iff @name identifies a standalone machtype */
  214. char *name;
  215. const char *alias;
  216. const char *desc;
  217. const char *deprecation_reason;
  218. void (*init)(MachineState *state);
  219. void (*reset)(MachineState *state, ShutdownCause reason);
  220. void (*wakeup)(MachineState *state);
  221. int (*kvm_type)(MachineState *machine, const char *arg);
  222. BlockInterfaceType block_default_type;
  223. int units_per_default_bus;
  224. int max_cpus;
  225. int min_cpus;
  226. int default_cpus;
  227. unsigned int no_serial:1,
  228. no_parallel:1,
  229. no_floppy:1,
  230. no_cdrom:1,
  231. no_sdcard:1,
  232. pci_allow_0_address:1,
  233. legacy_fw_cfg_order:1;
  234. bool is_default;
  235. const char *default_machine_opts;
  236. const char *default_boot_order;
  237. const char *default_display;
  238. const char *default_nic;
  239. GPtrArray *compat_props;
  240. const char *hw_version;
  241. ram_addr_t default_ram_size;
  242. const char *default_cpu_type;
  243. bool default_kernel_irqchip_split;
  244. bool option_rom_has_mr;
  245. bool rom_file_has_mr;
  246. int minimum_page_bits;
  247. bool has_hotpluggable_cpus;
  248. bool ignore_memory_transaction_failures;
  249. int numa_mem_align_shift;
  250. const char **valid_cpu_types;
  251. strList *allowed_dynamic_sysbus_devices;
  252. bool auto_enable_numa_with_memhp;
  253. bool auto_enable_numa_with_memdev;
  254. bool ignore_boot_device_suffixes;
  255. bool smbus_no_migration_support;
  256. bool nvdimm_supported;
  257. bool numa_mem_supported;
  258. bool auto_enable_numa;
  259. SMPCompatProps smp_props;
  260. const char *default_ram_id;
  261. HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
  262. DeviceState *dev);
  263. bool (*hotplug_allowed)(MachineState *state, DeviceState *dev,
  264. Error **errp);
  265. CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
  266. unsigned cpu_index);
  267. const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
  268. int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
  269. ram_addr_t (*fixup_ram_size)(ram_addr_t size);
  270. };
  271. /**
  272. * DeviceMemoryState:
  273. * @base: address in guest physical address space where the memory
  274. * address space for memory devices starts
  275. * @mr: address space container for memory devices
  276. * @dimm_size: the sum of plugged DIMMs' sizes
  277. */
  278. typedef struct DeviceMemoryState {
  279. hwaddr base;
  280. MemoryRegion mr;
  281. uint64_t dimm_size;
  282. } DeviceMemoryState;
  283. /**
  284. * CpuTopology:
  285. * @cpus: the number of present logical processors on the machine
  286. * @sockets: the number of sockets on the machine
  287. * @dies: the number of dies in one socket
  288. * @clusters: the number of clusters in one die
  289. * @cores: the number of cores in one cluster
  290. * @threads: the number of threads in one core
  291. * @max_cpus: the maximum number of logical processors on the machine
  292. */
  293. typedef struct CpuTopology {
  294. unsigned int cpus;
  295. unsigned int sockets;
  296. unsigned int dies;
  297. unsigned int clusters;
  298. unsigned int cores;
  299. unsigned int threads;
  300. unsigned int max_cpus;
  301. } CpuTopology;
  302. /**
  303. * MachineState:
  304. */
  305. struct MachineState {
  306. /*< private >*/
  307. Object parent_obj;
  308. /*< public >*/
  309. void *fdt;
  310. char *dtb;
  311. char *dumpdtb;
  312. int phandle_start;
  313. char *dt_compatible;
  314. bool dump_guest_core;
  315. bool mem_merge;
  316. bool usb;
  317. bool usb_disabled;
  318. char *firmware;
  319. bool iommu;
  320. bool suppress_vmdesc;
  321. bool enable_graphics;
  322. ConfidentialGuestSupport *cgs;
  323. HostMemoryBackend *memdev;
  324. /*
  325. * convenience alias to ram_memdev_id backend memory region
  326. * or to numa container memory region
  327. */
  328. MemoryRegion *ram;
  329. DeviceMemoryState *device_memory;
  330. ram_addr_t ram_size;
  331. ram_addr_t maxram_size;
  332. uint64_t ram_slots;
  333. BootConfiguration boot_config;
  334. char *kernel_filename;
  335. char *kernel_cmdline;
  336. char *initrd_filename;
  337. const char *cpu_type;
  338. AccelState *accelerator;
  339. CPUArchIdList *possible_cpus;
  340. CpuTopology smp;
  341. struct NVDIMMState *nvdimms_state;
  342. struct NumaState *numa_state;
  343. };
  344. #define DEFINE_MACHINE(namestr, machine_initfn) \
  345. static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
  346. { \
  347. MachineClass *mc = MACHINE_CLASS(oc); \
  348. machine_initfn(mc); \
  349. } \
  350. static const TypeInfo machine_initfn##_typeinfo = { \
  351. .name = MACHINE_TYPE_NAME(namestr), \
  352. .parent = TYPE_MACHINE, \
  353. .class_init = machine_initfn##_class_init, \
  354. }; \
  355. static void machine_initfn##_register_types(void) \
  356. { \
  357. type_register_static(&machine_initfn##_typeinfo); \
  358. } \
  359. type_init(machine_initfn##_register_types)
  360. extern GlobalProperty hw_compat_8_0[];
  361. extern const size_t hw_compat_8_0_len;
  362. extern GlobalProperty hw_compat_7_2[];
  363. extern const size_t hw_compat_7_2_len;
  364. extern GlobalProperty hw_compat_7_1[];
  365. extern const size_t hw_compat_7_1_len;
  366. extern GlobalProperty hw_compat_7_0[];
  367. extern const size_t hw_compat_7_0_len;
  368. extern GlobalProperty hw_compat_6_2[];
  369. extern const size_t hw_compat_6_2_len;
  370. extern GlobalProperty hw_compat_6_1[];
  371. extern const size_t hw_compat_6_1_len;
  372. extern GlobalProperty hw_compat_6_0[];
  373. extern const size_t hw_compat_6_0_len;
  374. extern GlobalProperty hw_compat_5_2[];
  375. extern const size_t hw_compat_5_2_len;
  376. extern GlobalProperty hw_compat_5_1[];
  377. extern const size_t hw_compat_5_1_len;
  378. extern GlobalProperty hw_compat_5_0[];
  379. extern const size_t hw_compat_5_0_len;
  380. extern GlobalProperty hw_compat_4_2[];
  381. extern const size_t hw_compat_4_2_len;
  382. extern GlobalProperty hw_compat_4_1[];
  383. extern const size_t hw_compat_4_1_len;
  384. extern GlobalProperty hw_compat_4_0[];
  385. extern const size_t hw_compat_4_0_len;
  386. extern GlobalProperty hw_compat_3_1[];
  387. extern const size_t hw_compat_3_1_len;
  388. extern GlobalProperty hw_compat_3_0[];
  389. extern const size_t hw_compat_3_0_len;
  390. extern GlobalProperty hw_compat_2_12[];
  391. extern const size_t hw_compat_2_12_len;
  392. extern GlobalProperty hw_compat_2_11[];
  393. extern const size_t hw_compat_2_11_len;
  394. extern GlobalProperty hw_compat_2_10[];
  395. extern const size_t hw_compat_2_10_len;
  396. extern GlobalProperty hw_compat_2_9[];
  397. extern const size_t hw_compat_2_9_len;
  398. extern GlobalProperty hw_compat_2_8[];
  399. extern const size_t hw_compat_2_8_len;
  400. extern GlobalProperty hw_compat_2_7[];
  401. extern const size_t hw_compat_2_7_len;
  402. extern GlobalProperty hw_compat_2_6[];
  403. extern const size_t hw_compat_2_6_len;
  404. extern GlobalProperty hw_compat_2_5[];
  405. extern const size_t hw_compat_2_5_len;
  406. extern GlobalProperty hw_compat_2_4[];
  407. extern const size_t hw_compat_2_4_len;
  408. extern GlobalProperty hw_compat_2_3[];
  409. extern const size_t hw_compat_2_3_len;
  410. extern GlobalProperty hw_compat_2_2[];
  411. extern const size_t hw_compat_2_2_len;
  412. extern GlobalProperty hw_compat_2_1[];
  413. extern const size_t hw_compat_2_1_len;
  414. #endif