boards.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* Declarations for use by board files for creating devices. */
  2. #ifndef HW_BOARDS_H
  3. #define HW_BOARDS_H
  4. #include "sysemu/blockdev.h"
  5. #include "sysemu/accel.h"
  6. #include "hw/qdev.h"
  7. #include "qom/object.h"
  8. #include "qom/cpu.h"
  9. /**
  10. * memory_region_allocate_system_memory - Allocate a board's main memory
  11. * @mr: the #MemoryRegion to be initialized
  12. * @owner: the object that tracks the region's reference count
  13. * @name: name of the memory region
  14. * @ram_size: size of the region in bytes
  15. *
  16. * This function allocates the main memory for a board model, and
  17. * initializes @mr appropriately. It also arranges for the memory
  18. * to be migrated (by calling vmstate_register_ram_global()).
  19. *
  20. * Memory allocated via this function will be backed with the memory
  21. * backend the user provided using "-mem-path" or "-numa node,memdev=..."
  22. * if appropriate; this is typically used to cause host huge pages to be
  23. * used. This function should therefore be called by a board exactly once,
  24. * for the primary or largest RAM area it implements.
  25. *
  26. * For boards where the major RAM is split into two parts in the memory
  27. * map, you can deal with this by calling memory_region_allocate_system_memory()
  28. * once to get a MemoryRegion with enough RAM for both parts, and then
  29. * creating alias MemoryRegions via memory_region_init_alias() which
  30. * alias into different parts of the RAM MemoryRegion and can be mapped
  31. * into the memory map in the appropriate places.
  32. *
  33. * Smaller pieces of memory (display RAM, static RAMs, etc) don't need
  34. * to be backed via the -mem-path memory backend and can simply
  35. * be created via memory_region_allocate_aux_memory() or
  36. * memory_region_init_ram().
  37. */
  38. void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
  39. const char *name,
  40. uint64_t ram_size);
  41. #define TYPE_MACHINE_SUFFIX "-machine"
  42. /* Machine class name that needs to be used for class-name-based machine
  43. * type lookup to work.
  44. */
  45. #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)
  46. #define TYPE_MACHINE "machine"
  47. #undef MACHINE /* BSD defines it and QEMU does not use it */
  48. #define MACHINE(obj) \
  49. OBJECT_CHECK(MachineState, (obj), TYPE_MACHINE)
  50. #define MACHINE_GET_CLASS(obj) \
  51. OBJECT_GET_CLASS(MachineClass, (obj), TYPE_MACHINE)
  52. #define MACHINE_CLASS(klass) \
  53. OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE)
  54. MachineClass *find_default_machine(void);
  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. void machine_register_compat_props(MachineState *machine);
  66. HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
  67. void machine_set_cpu_numa_node(MachineState *machine,
  68. const CpuInstanceProperties *props,
  69. Error **errp);
  70. void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
  71. /**
  72. * CPUArchId:
  73. * @arch_id - architecture-dependent CPU ID of present or possible CPU
  74. * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
  75. * @type - QOM class name of possible @cpu object
  76. * @props - CPU object properties, initialized by board
  77. * #vcpus_count - number of threads provided by @cpu object
  78. */
  79. typedef struct {
  80. uint64_t arch_id;
  81. int64_t vcpus_count;
  82. CpuInstanceProperties props;
  83. Object *cpu;
  84. const char *type;
  85. } CPUArchId;
  86. /**
  87. * CPUArchIdList:
  88. * @len - number of @CPUArchId items in @cpus array
  89. * @cpus - array of present or possible CPUs for current machine configuration
  90. */
  91. typedef struct {
  92. int len;
  93. CPUArchId cpus[0];
  94. } CPUArchIdList;
  95. /**
  96. * MachineClass:
  97. * @max_cpus: maximum number of CPUs supported. Default: 1
  98. * @min_cpus: minimum number of CPUs supported. Default: 1
  99. * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
  100. * @get_hotplug_handler: this function is called during bus-less
  101. * device hotplug. If defined it returns pointer to an instance
  102. * of HotplugHandler object, which handles hotplug operation
  103. * for a given @dev. It may return NULL if @dev doesn't require
  104. * any actions to be performed by hotplug handler.
  105. * @cpu_index_to_instance_props:
  106. * used to provide @cpu_index to socket/core/thread number mapping, allowing
  107. * legacy code to perform maping from cpu_index to topology properties
  108. * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
  109. * used to provide @cpu_index to socket number mapping, allowing
  110. * a machine to group CPU threads belonging to the same socket/package
  111. * Returns: socket number given cpu_index belongs to.
  112. * @hw_version:
  113. * Value of QEMU_VERSION when the machine was added to QEMU.
  114. * Set only by old machines because they need to keep
  115. * compatibility on code that exposed QEMU_VERSION to guests in
  116. * the past (and now use qemu_hw_version()).
  117. * @possible_cpu_arch_ids:
  118. * Returns an array of @CPUArchId architecture-dependent CPU IDs
  119. * which includes CPU IDs for present and possible to hotplug CPUs.
  120. * Caller is responsible for freeing returned list.
  121. * @get_default_cpu_node_id:
  122. * returns default board specific node_id value for CPU slot specified by
  123. * index @idx in @ms->possible_cpus[]
  124. * @has_hotpluggable_cpus:
  125. * If true, board supports CPUs creation with -device/device_add.
  126. * @default_cpu_type:
  127. * specifies default CPU_TYPE, which will be used for parsing target
  128. * specific features and for creating CPUs if CPU name wasn't provided
  129. * explicitly at CLI
  130. * @minimum_page_bits:
  131. * If non-zero, the board promises never to create a CPU with a page size
  132. * smaller than this, so QEMU can use a more efficient larger page
  133. * size than the target architecture's minimum. (Attempting to create
  134. * such a CPU will fail.) Note that changing this is a migration
  135. * compatibility break for the machine.
  136. * @ignore_memory_transaction_failures:
  137. * If this is flag is true then the CPU will ignore memory transaction
  138. * failures which should cause the CPU to take an exception due to an
  139. * access to an unassigned physical address; the transaction will instead
  140. * return zero (for a read) or be ignored (for a write). This should be
  141. * set only by legacy board models which rely on the old RAZ/WI behaviour
  142. * for handling devices that QEMU does not yet model. New board models
  143. * should instead use "unimplemented-device" for all memory ranges where
  144. * the guest will attempt to probe for a device that QEMU doesn't
  145. * implement and a stub device is required.
  146. */
  147. struct MachineClass {
  148. /*< private >*/
  149. ObjectClass parent_class;
  150. /*< public >*/
  151. const char *family; /* NULL iff @name identifies a standalone machtype */
  152. char *name;
  153. const char *alias;
  154. const char *desc;
  155. void (*init)(MachineState *state);
  156. void (*reset)(void);
  157. void (*hot_add_cpu)(const int64_t id, Error **errp);
  158. int (*kvm_type)(const char *arg);
  159. BlockInterfaceType block_default_type;
  160. int units_per_default_bus;
  161. int max_cpus;
  162. int min_cpus;
  163. int default_cpus;
  164. unsigned int no_serial:1,
  165. no_parallel:1,
  166. use_virtcon:1,
  167. use_sclp:1,
  168. no_floppy:1,
  169. no_cdrom:1,
  170. no_sdcard:1,
  171. pci_allow_0_address:1,
  172. legacy_fw_cfg_order:1;
  173. int is_default;
  174. const char *default_machine_opts;
  175. const char *default_boot_order;
  176. const char *default_display;
  177. GArray *compat_props;
  178. const char *hw_version;
  179. ram_addr_t default_ram_size;
  180. const char *default_cpu_type;
  181. bool option_rom_has_mr;
  182. bool rom_file_has_mr;
  183. int minimum_page_bits;
  184. bool has_hotpluggable_cpus;
  185. bool ignore_memory_transaction_failures;
  186. int numa_mem_align_shift;
  187. const char **valid_cpu_types;
  188. strList *allowed_dynamic_sysbus_devices;
  189. bool auto_enable_numa_with_memhp;
  190. void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes,
  191. int nb_nodes, ram_addr_t size);
  192. HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
  193. DeviceState *dev);
  194. CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
  195. unsigned cpu_index);
  196. const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
  197. int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
  198. };
  199. /**
  200. * MachineState:
  201. */
  202. struct MachineState {
  203. /*< private >*/
  204. Object parent_obj;
  205. Notifier sysbus_notifier;
  206. /*< public >*/
  207. char *accel;
  208. bool kernel_irqchip_allowed;
  209. bool kernel_irqchip_required;
  210. bool kernel_irqchip_split;
  211. int kvm_shadow_mem;
  212. char *dtb;
  213. char *dumpdtb;
  214. int phandle_start;
  215. char *dt_compatible;
  216. bool dump_guest_core;
  217. bool mem_merge;
  218. bool usb;
  219. bool usb_disabled;
  220. bool igd_gfx_passthru;
  221. char *firmware;
  222. bool iommu;
  223. bool suppress_vmdesc;
  224. bool enforce_config_section;
  225. bool enable_graphics;
  226. ram_addr_t ram_size;
  227. ram_addr_t maxram_size;
  228. uint64_t ram_slots;
  229. const char *boot_order;
  230. char *kernel_filename;
  231. char *kernel_cmdline;
  232. char *initrd_filename;
  233. const char *cpu_model;
  234. const char *cpu_type;
  235. AccelState *accelerator;
  236. CPUArchIdList *possible_cpus;
  237. };
  238. #define DEFINE_MACHINE(namestr, machine_initfn) \
  239. static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
  240. { \
  241. MachineClass *mc = MACHINE_CLASS(oc); \
  242. machine_initfn(mc); \
  243. } \
  244. static const TypeInfo machine_initfn##_typeinfo = { \
  245. .name = MACHINE_TYPE_NAME(namestr), \
  246. .parent = TYPE_MACHINE, \
  247. .class_init = machine_initfn##_class_init, \
  248. }; \
  249. static void machine_initfn##_register_types(void) \
  250. { \
  251. type_register_static(&machine_initfn##_typeinfo); \
  252. } \
  253. type_init(machine_initfn##_register_types)
  254. #define SET_MACHINE_COMPAT(m, COMPAT) \
  255. do { \
  256. int i; \
  257. static GlobalProperty props[] = { \
  258. COMPAT \
  259. { /* end of list */ } \
  260. }; \
  261. if (!m->compat_props) { \
  262. m->compat_props = g_array_new(false, false, sizeof(void *)); \
  263. } \
  264. for (i = 0; props[i].driver != NULL; i++) { \
  265. GlobalProperty *prop = &props[i]; \
  266. g_array_append_val(m->compat_props, prop); \
  267. } \
  268. } while (0)
  269. #endif