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