10d09e41aSPaolo Bonzini /* Declarations for use by board files for creating devices. */ 20d09e41aSPaolo Bonzini 30d09e41aSPaolo Bonzini #ifndef HW_BOARDS_H 40d09e41aSPaolo Bonzini #define HW_BOARDS_H 50d09e41aSPaolo Bonzini 60d09e41aSPaolo Bonzini #include "sysemu/blockdev.h" 7ac2da55eSEduardo Habkost #include "sysemu/accel.h" 80d09e41aSPaolo Bonzini #include "hw/qdev.h" 936d20cb2SMarcel Apfelbaum #include "qom/object.h" 103811ef14SIgor Mammedov #include "qom/cpu.h" 110d09e41aSPaolo Bonzini 1209ad6438SPeter Maydell /** 1309ad6438SPeter Maydell * memory_region_allocate_system_memory - Allocate a board's main memory 1409ad6438SPeter Maydell * @mr: the #MemoryRegion to be initialized 1509ad6438SPeter Maydell * @owner: the object that tracks the region's reference count 1609ad6438SPeter Maydell * @name: name of the memory region 1709ad6438SPeter Maydell * @ram_size: size of the region in bytes 1809ad6438SPeter Maydell * 1909ad6438SPeter Maydell * This function allocates the main memory for a board model, and 2009ad6438SPeter Maydell * initializes @mr appropriately. It also arranges for the memory 2109ad6438SPeter Maydell * to be migrated (by calling vmstate_register_ram_global()). 2209ad6438SPeter Maydell * 2309ad6438SPeter Maydell * Memory allocated via this function will be backed with the memory 2409ad6438SPeter Maydell * backend the user provided using "-mem-path" or "-numa node,memdev=..." 2509ad6438SPeter Maydell * if appropriate; this is typically used to cause host huge pages to be 2609ad6438SPeter Maydell * used. This function should therefore be called by a board exactly once, 2709ad6438SPeter Maydell * for the primary or largest RAM area it implements. 2809ad6438SPeter Maydell * 2909ad6438SPeter Maydell * For boards where the major RAM is split into two parts in the memory 3009ad6438SPeter Maydell * map, you can deal with this by calling memory_region_allocate_system_memory() 3109ad6438SPeter Maydell * once to get a MemoryRegion with enough RAM for both parts, and then 3209ad6438SPeter Maydell * creating alias MemoryRegions via memory_region_init_alias() which 3309ad6438SPeter Maydell * alias into different parts of the RAM MemoryRegion and can be mapped 3409ad6438SPeter Maydell * into the memory map in the appropriate places. 3509ad6438SPeter Maydell * 3609ad6438SPeter Maydell * Smaller pieces of memory (display RAM, static RAMs, etc) don't need 3709ad6438SPeter Maydell * to be backed via the -mem-path memory backend and can simply 38b08199c6SPeter Maydell * be created via memory_region_allocate_aux_memory() or 39b08199c6SPeter Maydell * memory_region_init_ram(). 4009ad6438SPeter Maydell */ 41dfabb8b9SPaolo Bonzini void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, 42dfabb8b9SPaolo Bonzini const char *name, 43dfabb8b9SPaolo Bonzini uint64_t ram_size); 44dfabb8b9SPaolo Bonzini 45dfabb8b9SPaolo Bonzini #define TYPE_MACHINE_SUFFIX "-machine" 46c84a8f01SEduardo Habkost 47c84a8f01SEduardo Habkost /* Machine class name that needs to be used for class-name-based machine 48c84a8f01SEduardo Habkost * type lookup to work. 49c84a8f01SEduardo Habkost */ 50c84a8f01SEduardo Habkost #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX) 51c84a8f01SEduardo Habkost 5236d20cb2SMarcel Apfelbaum #define TYPE_MACHINE "machine" 53c8897e8eSMarcel Apfelbaum #undef MACHINE /* BSD defines it and QEMU does not use it */ 5436d20cb2SMarcel Apfelbaum #define MACHINE(obj) \ 5536d20cb2SMarcel Apfelbaum OBJECT_CHECK(MachineState, (obj), TYPE_MACHINE) 5636d20cb2SMarcel Apfelbaum #define MACHINE_GET_CLASS(obj) \ 5736d20cb2SMarcel Apfelbaum OBJECT_GET_CLASS(MachineClass, (obj), TYPE_MACHINE) 5836d20cb2SMarcel Apfelbaum #define MACHINE_CLASS(klass) \ 5936d20cb2SMarcel Apfelbaum OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE) 6036d20cb2SMarcel Apfelbaum 610056ae24SMarcel Apfelbaum MachineClass *find_default_machine(void); 620056ae24SMarcel Apfelbaum extern MachineState *current_machine; 630056ae24SMarcel Apfelbaum 64482dfe9aSIgor Mammedov void machine_run_board_init(MachineState *machine); 655e97b623SMarcel Apfelbaum bool machine_usb(MachineState *machine); 66d8870d02SMarcel Apfelbaum bool machine_kernel_irqchip_allowed(MachineState *machine); 67d8870d02SMarcel Apfelbaum bool machine_kernel_irqchip_required(MachineState *machine); 6832c18a2dSMatt Gingell bool machine_kernel_irqchip_split(MachineState *machine); 694689b77bSMarcel Apfelbaum int machine_kvm_shadow_mem(MachineState *machine); 706cabe7faSMarcel Apfelbaum int machine_phandle_start(MachineState *machine); 7147c8ca53SMarcel Apfelbaum bool machine_dump_guest_core(MachineState *machine); 7275cc7f01SMarcel Apfelbaum bool machine_mem_merge(MachineState *machine); 7339a3b377SEduardo Habkost void machine_register_compat_props(MachineState *machine); 74f2d672c2SIgor Mammedov HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine); 757c88e65dSIgor Mammedov void machine_set_cpu_numa_node(MachineState *machine, 767c88e65dSIgor Mammedov const CpuInstanceProperties *props, 777c88e65dSIgor Mammedov Error **errp); 785e97b623SMarcel Apfelbaum 79*0bd1909dSEduardo Habkost void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type); 80*0bd1909dSEduardo Habkost 81*0bd1909dSEduardo Habkost 8236d20cb2SMarcel Apfelbaum /** 833811ef14SIgor Mammedov * CPUArchId: 843811ef14SIgor Mammedov * @arch_id - architecture-dependent CPU ID of present or possible CPU 853811ef14SIgor Mammedov * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise 86c67ae933SIgor Mammedov * @props - CPU object properties, initialized by board 87f2d672c2SIgor Mammedov * #vcpus_count - number of threads provided by @cpu object 883811ef14SIgor Mammedov */ 893811ef14SIgor Mammedov typedef struct { 903811ef14SIgor Mammedov uint64_t arch_id; 91f2d672c2SIgor Mammedov int64_t vcpus_count; 92c67ae933SIgor Mammedov CpuInstanceProperties props; 938aba3842SIgor Mammedov Object *cpu; 943811ef14SIgor Mammedov } CPUArchId; 953811ef14SIgor Mammedov 963811ef14SIgor Mammedov /** 973811ef14SIgor Mammedov * CPUArchIdList: 983811ef14SIgor Mammedov * @len - number of @CPUArchId items in @cpus array 993811ef14SIgor Mammedov * @cpus - array of present or possible CPUs for current machine configuration 1003811ef14SIgor Mammedov */ 1013811ef14SIgor Mammedov typedef struct { 1023811ef14SIgor Mammedov int len; 1033811ef14SIgor Mammedov CPUArchId cpus[0]; 1043811ef14SIgor Mammedov } CPUArchIdList; 1053811ef14SIgor Mammedov 1063811ef14SIgor Mammedov /** 10736d20cb2SMarcel Apfelbaum * MachineClass: 10872649619SEmilio G. Cota * @max_cpus: maximum number of CPUs supported. Default: 1 10972649619SEmilio G. Cota * @min_cpus: minimum number of CPUs supported. Default: 1 11072649619SEmilio G. Cota * @default_cpus: number of CPUs instantiated if none are specified. Default: 1 111b7454548SIgor Mammedov * @get_hotplug_handler: this function is called during bus-less 112b7454548SIgor Mammedov * device hotplug. If defined it returns pointer to an instance 113b7454548SIgor Mammedov * of HotplugHandler object, which handles hotplug operation 114b7454548SIgor Mammedov * for a given @dev. It may return NULL if @dev doesn't require 115b7454548SIgor Mammedov * any actions to be performed by hotplug handler. 116ea089eebSIgor Mammedov * @cpu_index_to_instance_props: 117ea089eebSIgor Mammedov * used to provide @cpu_index to socket/core/thread number mapping, allowing 118ea089eebSIgor Mammedov * legacy code to perform maping from cpu_index to topology properties 119ea089eebSIgor Mammedov * Returns: tuple of socket/core/thread ids given cpu_index belongs to. 12057924bcdSIgor Mammedov * used to provide @cpu_index to socket number mapping, allowing 12157924bcdSIgor Mammedov * a machine to group CPU threads belonging to the same socket/package 12257924bcdSIgor Mammedov * Returns: socket number given cpu_index belongs to. 123fac862ffSEduardo Habkost * @hw_version: 124fac862ffSEduardo Habkost * Value of QEMU_VERSION when the machine was added to QEMU. 125fac862ffSEduardo Habkost * Set only by old machines because they need to keep 126fac862ffSEduardo Habkost * compatibility on code that exposed QEMU_VERSION to guests in 127fac862ffSEduardo Habkost * the past (and now use qemu_hw_version()). 1283811ef14SIgor Mammedov * @possible_cpu_arch_ids: 1293811ef14SIgor Mammedov * Returns an array of @CPUArchId architecture-dependent CPU IDs 1303811ef14SIgor Mammedov * which includes CPU IDs for present and possible to hotplug CPUs. 1313811ef14SIgor Mammedov * Caller is responsible for freeing returned list. 13279e07936SIgor Mammedov * @get_default_cpu_node_id: 13379e07936SIgor Mammedov * returns default board specific node_id value for CPU slot specified by 13479e07936SIgor Mammedov * index @idx in @ms->possible_cpus[] 135c5514d0eSIgor Mammedov * @has_hotpluggable_cpus: 136c5514d0eSIgor Mammedov * If true, board supports CPUs creation with -device/device_add. 1376063d4c0SIgor Mammedov * @default_cpu_type: 1386063d4c0SIgor Mammedov * specifies default CPU_TYPE, which will be used for parsing target 1396063d4c0SIgor Mammedov * specific features and for creating CPUs if CPU name wasn't provided 1406063d4c0SIgor Mammedov * explicitly at CLI 14120bccb82SPeter Maydell * @minimum_page_bits: 14220bccb82SPeter Maydell * If non-zero, the board promises never to create a CPU with a page size 14320bccb82SPeter Maydell * smaller than this, so QEMU can use a more efficient larger page 14420bccb82SPeter Maydell * size than the target architecture's minimum. (Attempting to create 14520bccb82SPeter Maydell * such a CPU will fail.) Note that changing this is a migration 14620bccb82SPeter Maydell * compatibility break for the machine. 147ed860129SPeter Maydell * @ignore_memory_transaction_failures: 148ed860129SPeter Maydell * If this is flag is true then the CPU will ignore memory transaction 149ed860129SPeter Maydell * failures which should cause the CPU to take an exception due to an 150ed860129SPeter Maydell * access to an unassigned physical address; the transaction will instead 151ed860129SPeter Maydell * return zero (for a read) or be ignored (for a write). This should be 152ed860129SPeter Maydell * set only by legacy board models which rely on the old RAZ/WI behaviour 153ed860129SPeter Maydell * for handling devices that QEMU does not yet model. New board models 154ed860129SPeter Maydell * should instead use "unimplemented-device" for all memory ranges where 155ed860129SPeter Maydell * the guest will attempt to probe for a device that QEMU doesn't 156ed860129SPeter Maydell * implement and a stub device is required. 15736d20cb2SMarcel Apfelbaum */ 15836d20cb2SMarcel Apfelbaum struct MachineClass { 15936d20cb2SMarcel Apfelbaum /*< private >*/ 16036d20cb2SMarcel Apfelbaum ObjectClass parent_class; 16136d20cb2SMarcel Apfelbaum /*< public >*/ 16236d20cb2SMarcel Apfelbaum 1632709f263SLaszlo Ersek const char *family; /* NULL iff @name identifies a standalone machtype */ 1648ea75371SMarc-André Lureau char *name; 16500b4fbe2SMarcel Apfelbaum const char *alias; 16600b4fbe2SMarcel Apfelbaum const char *desc; 16700b4fbe2SMarcel Apfelbaum 1683ef96221SMarcel Apfelbaum void (*init)(MachineState *state); 16900b4fbe2SMarcel Apfelbaum void (*reset)(void); 17000b4fbe2SMarcel Apfelbaum void (*hot_add_cpu)(const int64_t id, Error **errp); 17100b4fbe2SMarcel Apfelbaum int (*kvm_type)(const char *arg); 17200b4fbe2SMarcel Apfelbaum 17300b4fbe2SMarcel Apfelbaum BlockInterfaceType block_default_type; 17416026518SJohn Snow int units_per_default_bus; 17500b4fbe2SMarcel Apfelbaum int max_cpus; 17672649619SEmilio G. Cota int min_cpus; 17772649619SEmilio G. Cota int default_cpus; 17800b4fbe2SMarcel Apfelbaum unsigned int no_serial:1, 17900b4fbe2SMarcel Apfelbaum no_parallel:1, 18000b4fbe2SMarcel Apfelbaum use_virtcon:1, 18100b4fbe2SMarcel Apfelbaum use_sclp:1, 18200b4fbe2SMarcel Apfelbaum no_floppy:1, 18300b4fbe2SMarcel Apfelbaum no_cdrom:1, 18433cd52b5SAlexander Graf no_sdcard:1, 185bab47d9aSGerd Hoffmann pci_allow_0_address:1, 186bab47d9aSGerd Hoffmann legacy_fw_cfg_order:1; 18700b4fbe2SMarcel Apfelbaum int is_default; 18800b4fbe2SMarcel Apfelbaum const char *default_machine_opts; 18900b4fbe2SMarcel Apfelbaum const char *default_boot_order; 1906f00494aSGerd Hoffmann const char *default_display; 191bacc344cSIgor Mammedov GArray *compat_props; 19200b4fbe2SMarcel Apfelbaum const char *hw_version; 193076b35b5SNikunj A Dadhania ram_addr_t default_ram_size; 1946063d4c0SIgor Mammedov const char *default_cpu_type; 19571ae9e94SEduardo Habkost bool option_rom_has_mr; 19671ae9e94SEduardo Habkost bool rom_file_has_mr; 19720bccb82SPeter Maydell int minimum_page_bits; 198c5514d0eSIgor Mammedov bool has_hotpluggable_cpus; 199ed860129SPeter Maydell bool ignore_memory_transaction_failures; 20055641213SLaurent Vivier int numa_mem_align_shift; 201c9cf636dSAlistair Francis const char **valid_cpu_types; 202*0bd1909dSEduardo Habkost strList *allowed_dynamic_sysbus_devices; 2037b8be49dSDou Liyang bool auto_enable_numa_with_memhp; 2043bfe5716SLaurent Vivier void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes, 2053bfe5716SLaurent Vivier int nb_nodes, ram_addr_t size); 206b7454548SIgor Mammedov 207b7454548SIgor Mammedov HotplugHandler *(*get_hotplug_handler)(MachineState *machine, 208b7454548SIgor Mammedov DeviceState *dev); 209ea089eebSIgor Mammedov CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine, 210ea089eebSIgor Mammedov unsigned cpu_index); 21180e5db30SIgor Mammedov const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); 21279e07936SIgor Mammedov int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx); 21336d20cb2SMarcel Apfelbaum }; 21436d20cb2SMarcel Apfelbaum 21536d20cb2SMarcel Apfelbaum /** 21636d20cb2SMarcel Apfelbaum * MachineState: 21736d20cb2SMarcel Apfelbaum */ 21836d20cb2SMarcel Apfelbaum struct MachineState { 21936d20cb2SMarcel Apfelbaum /*< private >*/ 22036d20cb2SMarcel Apfelbaum Object parent_obj; 22133cd52b5SAlexander Graf Notifier sysbus_notifier; 22233cd52b5SAlexander Graf 22336d20cb2SMarcel Apfelbaum /*< public >*/ 22436d20cb2SMarcel Apfelbaum 22536d20cb2SMarcel Apfelbaum char *accel; 226d8870d02SMarcel Apfelbaum bool kernel_irqchip_allowed; 227d8870d02SMarcel Apfelbaum bool kernel_irqchip_required; 22832c18a2dSMatt Gingell bool kernel_irqchip_split; 22936d20cb2SMarcel Apfelbaum int kvm_shadow_mem; 23036d20cb2SMarcel Apfelbaum char *dtb; 23136d20cb2SMarcel Apfelbaum char *dumpdtb; 23236d20cb2SMarcel Apfelbaum int phandle_start; 23336d20cb2SMarcel Apfelbaum char *dt_compatible; 23436d20cb2SMarcel Apfelbaum bool dump_guest_core; 23536d20cb2SMarcel Apfelbaum bool mem_merge; 23636d20cb2SMarcel Apfelbaum bool usb; 237c6e76503SPaolo Bonzini bool usb_disabled; 23879814179STiejun Chen bool igd_gfx_passthru; 23936d20cb2SMarcel Apfelbaum char *firmware; 240a52a7fdfSLe Tan bool iommu; 2419850c604SAlexander Graf bool suppress_vmdesc; 242902c053dSGreg Kurz bool enforce_config_section; 243cfc58cf3SEduardo Habkost bool enable_graphics; 24436d20cb2SMarcel Apfelbaum 2453ef96221SMarcel Apfelbaum ram_addr_t ram_size; 246c270fb9eSIgor Mammedov ram_addr_t maxram_size; 247c270fb9eSIgor Mammedov uint64_t ram_slots; 2483ef96221SMarcel Apfelbaum const char *boot_order; 2496b1b1440SMarcel Apfelbaum char *kernel_filename; 2506b1b1440SMarcel Apfelbaum char *kernel_cmdline; 2516b1b1440SMarcel Apfelbaum char *initrd_filename; 2523ef96221SMarcel Apfelbaum const char *cpu_model; 2536063d4c0SIgor Mammedov const char *cpu_type; 254ac2da55eSEduardo Habkost AccelState *accelerator; 25538690a1cSIgor Mammedov CPUArchIdList *possible_cpus; 25636d20cb2SMarcel Apfelbaum }; 25736d20cb2SMarcel Apfelbaum 258ed0b6de3SEduardo Habkost #define DEFINE_MACHINE(namestr, machine_initfn) \ 259ed0b6de3SEduardo Habkost static void machine_initfn##_class_init(ObjectClass *oc, void *data) \ 260ed0b6de3SEduardo Habkost { \ 261ed0b6de3SEduardo Habkost MachineClass *mc = MACHINE_CLASS(oc); \ 262ed0b6de3SEduardo Habkost machine_initfn(mc); \ 263ed0b6de3SEduardo Habkost } \ 264ed0b6de3SEduardo Habkost static const TypeInfo machine_initfn##_typeinfo = { \ 265ed0b6de3SEduardo Habkost .name = MACHINE_TYPE_NAME(namestr), \ 266ed0b6de3SEduardo Habkost .parent = TYPE_MACHINE, \ 267ed0b6de3SEduardo Habkost .class_init = machine_initfn##_class_init, \ 268ed0b6de3SEduardo Habkost }; \ 269ed0b6de3SEduardo Habkost static void machine_initfn##_register_types(void) \ 270ed0b6de3SEduardo Habkost { \ 271ed0b6de3SEduardo Habkost type_register_static(&machine_initfn##_typeinfo); \ 272ed0b6de3SEduardo Habkost } \ 2730e6aac87SEduardo Habkost type_init(machine_initfn##_register_types) 274ed0b6de3SEduardo Habkost 275877f8931SDavid Gibson #define SET_MACHINE_COMPAT(m, COMPAT) \ 276877f8931SDavid Gibson do { \ 277bacc344cSIgor Mammedov int i; \ 278877f8931SDavid Gibson static GlobalProperty props[] = { \ 279877f8931SDavid Gibson COMPAT \ 280877f8931SDavid Gibson { /* end of list */ } \ 281877f8931SDavid Gibson }; \ 282bacc344cSIgor Mammedov if (!m->compat_props) { \ 283bacc344cSIgor Mammedov m->compat_props = g_array_new(false, false, sizeof(void *)); \ 284bacc344cSIgor Mammedov } \ 285bacc344cSIgor Mammedov for (i = 0; props[i].driver != NULL; i++) { \ 286bacc344cSIgor Mammedov GlobalProperty *prop = &props[i]; \ 287bacc344cSIgor Mammedov g_array_append_val(m->compat_props, prop); \ 288bacc344cSIgor Mammedov } \ 289877f8931SDavid Gibson } while (0) 290877f8931SDavid Gibson 2910d09e41aSPaolo Bonzini #endif 292