boards.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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/blockdev.h"
  6. #include "sysemu/accel.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. /**
  12. * memory_region_allocate_system_memory - Allocate a board's main memory
  13. * @mr: the #MemoryRegion to be initialized
  14. * @owner: the object that tracks the region's reference count
  15. * @name: name of the memory region
  16. * @ram_size: size of the region in bytes
  17. *
  18. * This function allocates the main memory for a board model, and
  19. * initializes @mr appropriately. It also arranges for the memory
  20. * to be migrated (by calling vmstate_register_ram_global()).
  21. *
  22. * Memory allocated via this function will be backed with the memory
  23. * backend the user provided using "-mem-path" or "-numa node,memdev=..."
  24. * if appropriate; this is typically used to cause host huge pages to be
  25. * used. This function should therefore be called by a board exactly once,
  26. * for the primary or largest RAM area it implements.
  27. *
  28. * For boards where the major RAM is split into two parts in the memory
  29. * map, you can deal with this by calling memory_region_allocate_system_memory()
  30. * once to get a MemoryRegion with enough RAM for both parts, and then
  31. * creating alias MemoryRegions via memory_region_init_alias() which
  32. * alias into different parts of the RAM MemoryRegion and can be mapped
  33. * into the memory map in the appropriate places.
  34. *
  35. * Smaller pieces of memory (display RAM, static RAMs, etc) don't need
  36. * to be backed via the -mem-path memory backend and can simply
  37. * be created via memory_region_init_ram().
  38. */
  39. void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
  40. const char *name,
  41. uint64_t ram_size);
  42. #define TYPE_MACHINE_SUFFIX "-machine"
  43. /* Machine class name that needs to be used for class-name-based machine
  44. * type lookup to work.
  45. */
  46. #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)
  47. #define TYPE_MACHINE "machine"
  48. #undef MACHINE /* BSD defines it and QEMU does not use it */
  49. #define MACHINE(obj) \
  50. OBJECT_CHECK(MachineState, (obj), TYPE_MACHINE)
  51. #define MACHINE_GET_CLASS(obj) \
  52. OBJECT_GET_CLASS(MachineClass, (obj), TYPE_MACHINE)
  53. #define MACHINE_CLASS(klass) \
  54. OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE)
  55. extern MachineState *current_machine;
  56. void machine_run_board_init(MachineState *machine);
  57. bool machine_usb(MachineState *machine);
  58. bool machine_kernel_irqchip_allowed(MachineState *machine);
  59. bool machine_kernel_irqchip_required(MachineState *machine);
  60. bool machine_kernel_irqchip_split(MachineState *machine);
  61. int machine_kvm_shadow_mem(MachineState *machine);
  62. int machine_phandle_start(MachineState *machine);
  63. bool machine_dump_guest_core(MachineState *machine);
  64. bool machine_mem_merge(MachineState *machine);
  65. HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
  66. void machine_set_cpu_numa_node(MachineState *machine,
  67. const CpuInstanceProperties *props,
  68. Error **errp);
  69. void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
  70. /**
  71. * CPUArchId:
  72. * @arch_id - architecture-dependent CPU ID of present or possible CPU
  73. * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
  74. * @type - QOM class name of possible @cpu object
  75. * @props - CPU object properties, initialized by board
  76. * #vcpus_count - number of threads provided by @cpu object
  77. */
  78. typedef struct CPUArchId {
  79. uint64_t arch_id;
  80. int64_t vcpus_count;
  81. CpuInstanceProperties props;
  82. Object *cpu;
  83. const char *type;
  84. } CPUArchId;
  85. /**
  86. * CPUArchIdList:
  87. * @len - number of @CPUArchId items in @cpus array
  88. * @cpus - array of present or possible CPUs for current machine configuration
  89. */
  90. typedef struct {
  91. int len;
  92. CPUArchId cpus[0];
  93. } CPUArchIdList;
  94. /**
  95. * MachineClass:
  96. * @deprecation_reason: If set, the machine is marked as deprecated. The
  97. * string should provide some clear information about what to use instead.
  98. * @max_cpus: maximum number of CPUs supported. Default: 1
  99. * @min_cpus: minimum number of CPUs supported. Default: 1
  100. * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
  101. * @get_hotplug_handler: this function is called during bus-less
  102. * device hotplug. If defined it returns pointer to an instance
  103. * of HotplugHandler object, which handles hotplug operation
  104. * for a given @dev. It may return NULL if @dev doesn't require
  105. * any actions to be performed by hotplug handler.
  106. * @cpu_index_to_instance_props:
  107. * used to provide @cpu_index to socket/core/thread number mapping, allowing
  108. * legacy code to perform maping from cpu_index to topology properties
  109. * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
  110. * used to provide @cpu_index to socket number mapping, allowing
  111. * a machine to group CPU threads belonging to the same socket/package
  112. * Returns: socket number given cpu_index belongs to.
  113. * @hw_version:
  114. * Value of QEMU_VERSION when the machine was added to QEMU.
  115. * Set only by old machines because they need to keep
  116. * compatibility on code that exposed QEMU_VERSION to guests in
  117. * the past (and now use qemu_hw_version()).
  118. * @possible_cpu_arch_ids:
  119. * Returns an array of @CPUArchId architecture-dependent CPU IDs
  120. * which includes CPU IDs for present and possible to hotplug CPUs.
  121. * Caller is responsible for freeing returned list.
  122. * @get_default_cpu_node_id:
  123. * returns default board specific node_id value for CPU slot specified by
  124. * index @idx in @ms->possible_cpus[]
  125. * @has_hotpluggable_cpus:
  126. * If true, board supports CPUs creation with -device/device_add.
  127. * @default_cpu_type:
  128. * specifies default CPU_TYPE, which will be used for parsing target
  129. * specific features and for creating CPUs if CPU name wasn't provided
  130. * explicitly at CLI
  131. * @minimum_page_bits:
  132. * If non-zero, the board promises never to create a CPU with a page size
  133. * smaller than this, so QEMU can use a more efficient larger page
  134. * size than the target architecture's minimum. (Attempting to create
  135. * such a CPU will fail.) Note that changing this is a migration
  136. * compatibility break for the machine.
  137. * @ignore_memory_transaction_failures:
  138. * If this is flag is true then the CPU will ignore memory transaction
  139. * failures which should cause the CPU to take an exception due to an
  140. * access to an unassigned physical address; the transaction will instead
  141. * return zero (for a read) or be ignored (for a write). This should be
  142. * set only by legacy board models which rely on the old RAZ/WI behaviour
  143. * for handling devices that QEMU does not yet model. New board models
  144. * should instead use "unimplemented-device" for all memory ranges where
  145. * the guest will attempt to probe for a device that QEMU doesn't
  146. * implement and a stub device is required.
  147. * @kvm_type:
  148. * Return the type of KVM corresponding to the kvm-type string option or
  149. * computed based on other criteria such as the host kernel capabilities.
  150. * @numa_mem_supported:
  151. * true if '--numa node.mem' option is supported and false otherwise
  152. * @smp_parse:
  153. * The function pointer to hook different machine specific functions for
  154. * parsing "smp-opts" from QemuOpts to MachineState::CpuTopology and more
  155. * machine specific topology fields, such as smp_dies for PCMachine.
  156. */
  157. struct MachineClass {
  158. /*< private >*/
  159. ObjectClass parent_class;
  160. /*< public >*/
  161. const char *family; /* NULL iff @name identifies a standalone machtype */
  162. char *name;
  163. const char *alias;
  164. const char *desc;
  165. const char *deprecation_reason;
  166. void (*init)(MachineState *state);
  167. void (*reset)(MachineState *state);
  168. void (*wakeup)(MachineState *state);
  169. void (*hot_add_cpu)(MachineState *state, const int64_t id, Error **errp);
  170. int (*kvm_type)(MachineState *machine, const char *arg);
  171. void (*smp_parse)(MachineState *ms, QemuOpts *opts);
  172. BlockInterfaceType block_default_type;
  173. int units_per_default_bus;
  174. int max_cpus;
  175. int min_cpus;
  176. int default_cpus;
  177. unsigned int no_serial:1,
  178. no_parallel:1,
  179. no_floppy:1,
  180. no_cdrom:1,
  181. no_sdcard:1,
  182. pci_allow_0_address:1,
  183. legacy_fw_cfg_order:1;
  184. int is_default;
  185. const char *default_machine_opts;
  186. const char *default_boot_order;
  187. const char *default_display;
  188. GPtrArray *compat_props;
  189. const char *hw_version;
  190. ram_addr_t default_ram_size;
  191. const char *default_cpu_type;
  192. bool default_kernel_irqchip_split;
  193. bool option_rom_has_mr;
  194. bool rom_file_has_mr;
  195. int minimum_page_bits;
  196. bool has_hotpluggable_cpus;
  197. bool ignore_memory_transaction_failures;
  198. int numa_mem_align_shift;
  199. const char **valid_cpu_types;
  200. strList *allowed_dynamic_sysbus_devices;
  201. bool auto_enable_numa_with_memhp;
  202. void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes,
  203. int nb_nodes, ram_addr_t size);
  204. bool ignore_boot_device_suffixes;
  205. bool smbus_no_migration_support;
  206. bool nvdimm_supported;
  207. bool numa_mem_supported;
  208. HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
  209. DeviceState *dev);
  210. CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
  211. unsigned cpu_index);
  212. const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
  213. int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
  214. };
  215. /**
  216. * DeviceMemoryState:
  217. * @base: address in guest physical address space where the memory
  218. * address space for memory devices starts
  219. * @mr: address space container for memory devices
  220. */
  221. typedef struct DeviceMemoryState {
  222. hwaddr base;
  223. MemoryRegion mr;
  224. } DeviceMemoryState;
  225. /**
  226. * CpuTopology:
  227. * @cpus: the number of present logical processors on the machine
  228. * @cores: the number of cores in one package
  229. * @threads: the number of threads in one core
  230. * @max_cpus: the maximum number of logical processors on the machine
  231. */
  232. typedef struct CpuTopology {
  233. unsigned int cpus;
  234. unsigned int cores;
  235. unsigned int threads;
  236. unsigned int max_cpus;
  237. } CpuTopology;
  238. /**
  239. * MachineState:
  240. */
  241. struct MachineState {
  242. /*< private >*/
  243. Object parent_obj;
  244. Notifier sysbus_notifier;
  245. /*< public >*/
  246. char *accel;
  247. bool kernel_irqchip_allowed;
  248. bool kernel_irqchip_required;
  249. bool kernel_irqchip_split;
  250. int kvm_shadow_mem;
  251. char *dtb;
  252. char *dumpdtb;
  253. int phandle_start;
  254. char *dt_compatible;
  255. bool dump_guest_core;
  256. bool mem_merge;
  257. bool usb;
  258. bool usb_disabled;
  259. bool igd_gfx_passthru;
  260. char *firmware;
  261. bool iommu;
  262. bool suppress_vmdesc;
  263. bool enforce_config_section;
  264. bool enable_graphics;
  265. char *memory_encryption;
  266. DeviceMemoryState *device_memory;
  267. ram_addr_t ram_size;
  268. ram_addr_t maxram_size;
  269. uint64_t ram_slots;
  270. const char *boot_order;
  271. char *kernel_filename;
  272. char *kernel_cmdline;
  273. char *initrd_filename;
  274. const char *cpu_type;
  275. AccelState *accelerator;
  276. CPUArchIdList *possible_cpus;
  277. CpuTopology smp;
  278. struct NVDIMMState *nvdimms_state;
  279. };
  280. #define DEFINE_MACHINE(namestr, machine_initfn) \
  281. static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
  282. { \
  283. MachineClass *mc = MACHINE_CLASS(oc); \
  284. machine_initfn(mc); \
  285. } \
  286. static const TypeInfo machine_initfn##_typeinfo = { \
  287. .name = MACHINE_TYPE_NAME(namestr), \
  288. .parent = TYPE_MACHINE, \
  289. .class_init = machine_initfn##_class_init, \
  290. }; \
  291. static void machine_initfn##_register_types(void) \
  292. { \
  293. type_register_static(&machine_initfn##_typeinfo); \
  294. } \
  295. type_init(machine_initfn##_register_types)
  296. extern GlobalProperty hw_compat_4_1[];
  297. extern const size_t hw_compat_4_1_len;
  298. extern GlobalProperty hw_compat_4_0[];
  299. extern const size_t hw_compat_4_0_len;
  300. extern GlobalProperty hw_compat_3_1[];
  301. extern const size_t hw_compat_3_1_len;
  302. extern GlobalProperty hw_compat_3_0[];
  303. extern const size_t hw_compat_3_0_len;
  304. extern GlobalProperty hw_compat_2_12[];
  305. extern const size_t hw_compat_2_12_len;
  306. extern GlobalProperty hw_compat_2_11[];
  307. extern const size_t hw_compat_2_11_len;
  308. extern GlobalProperty hw_compat_2_10[];
  309. extern const size_t hw_compat_2_10_len;
  310. extern GlobalProperty hw_compat_2_9[];
  311. extern const size_t hw_compat_2_9_len;
  312. extern GlobalProperty hw_compat_2_8[];
  313. extern const size_t hw_compat_2_8_len;
  314. extern GlobalProperty hw_compat_2_7[];
  315. extern const size_t hw_compat_2_7_len;
  316. extern GlobalProperty hw_compat_2_6[];
  317. extern const size_t hw_compat_2_6_len;
  318. extern GlobalProperty hw_compat_2_5[];
  319. extern const size_t hw_compat_2_5_len;
  320. extern GlobalProperty hw_compat_2_4[];
  321. extern const size_t hw_compat_2_4_len;
  322. extern GlobalProperty hw_compat_2_3[];
  323. extern const size_t hw_compat_2_3_len;
  324. extern GlobalProperty hw_compat_2_2[];
  325. extern const size_t hw_compat_2_2_len;
  326. extern GlobalProperty hw_compat_2_1[];
  327. extern const size_t hw_compat_2_1_len;
  328. #endif