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 12dfabb8b9SPaolo Bonzini void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, 13dfabb8b9SPaolo Bonzini const char *name, 14dfabb8b9SPaolo Bonzini uint64_t ram_size); 15dfabb8b9SPaolo Bonzini 16dfabb8b9SPaolo Bonzini #define TYPE_MACHINE_SUFFIX "-machine" 17c84a8f01SEduardo Habkost 18c84a8f01SEduardo Habkost /* Machine class name that needs to be used for class-name-based machine 19c84a8f01SEduardo Habkost * type lookup to work. 20c84a8f01SEduardo Habkost */ 21c84a8f01SEduardo Habkost #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX) 22c84a8f01SEduardo Habkost 2336d20cb2SMarcel Apfelbaum #define TYPE_MACHINE "machine" 24c8897e8eSMarcel Apfelbaum #undef MACHINE /* BSD defines it and QEMU does not use it */ 2536d20cb2SMarcel Apfelbaum #define MACHINE(obj) \ 2636d20cb2SMarcel Apfelbaum OBJECT_CHECK(MachineState, (obj), TYPE_MACHINE) 2736d20cb2SMarcel Apfelbaum #define MACHINE_GET_CLASS(obj) \ 2836d20cb2SMarcel Apfelbaum OBJECT_GET_CLASS(MachineClass, (obj), TYPE_MACHINE) 2936d20cb2SMarcel Apfelbaum #define MACHINE_CLASS(klass) \ 3036d20cb2SMarcel Apfelbaum OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE) 3136d20cb2SMarcel Apfelbaum 320056ae24SMarcel Apfelbaum MachineClass *find_default_machine(void); 330056ae24SMarcel Apfelbaum extern MachineState *current_machine; 340056ae24SMarcel Apfelbaum 355e97b623SMarcel Apfelbaum bool machine_usb(MachineState *machine); 36d8870d02SMarcel Apfelbaum bool machine_kernel_irqchip_allowed(MachineState *machine); 37d8870d02SMarcel Apfelbaum bool machine_kernel_irqchip_required(MachineState *machine); 3832c18a2dSMatt Gingell bool machine_kernel_irqchip_split(MachineState *machine); 394689b77bSMarcel Apfelbaum int machine_kvm_shadow_mem(MachineState *machine); 406cabe7faSMarcel Apfelbaum int machine_phandle_start(MachineState *machine); 4147c8ca53SMarcel Apfelbaum bool machine_dump_guest_core(MachineState *machine); 4275cc7f01SMarcel Apfelbaum bool machine_mem_merge(MachineState *machine); 4339a3b377SEduardo Habkost void machine_register_compat_props(MachineState *machine); 44f2d672c2SIgor Mammedov HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine); 455e97b623SMarcel Apfelbaum 4636d20cb2SMarcel Apfelbaum /** 473811ef14SIgor Mammedov * CPUArchId: 483811ef14SIgor Mammedov * @arch_id - architecture-dependent CPU ID of present or possible CPU 493811ef14SIgor Mammedov * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise 50c67ae933SIgor Mammedov * @props - CPU object properties, initialized by board 51f2d672c2SIgor Mammedov * #vcpus_count - number of threads provided by @cpu object 523811ef14SIgor Mammedov */ 533811ef14SIgor Mammedov typedef struct { 543811ef14SIgor Mammedov uint64_t arch_id; 55f2d672c2SIgor Mammedov int64_t vcpus_count; 56c67ae933SIgor Mammedov CpuInstanceProperties props; 578aba3842SIgor Mammedov Object *cpu; 583811ef14SIgor Mammedov } CPUArchId; 593811ef14SIgor Mammedov 603811ef14SIgor Mammedov /** 613811ef14SIgor Mammedov * CPUArchIdList: 623811ef14SIgor Mammedov * @len - number of @CPUArchId items in @cpus array 633811ef14SIgor Mammedov * @cpus - array of present or possible CPUs for current machine configuration 643811ef14SIgor Mammedov */ 653811ef14SIgor Mammedov typedef struct { 663811ef14SIgor Mammedov int len; 673811ef14SIgor Mammedov CPUArchId cpus[0]; 683811ef14SIgor Mammedov } CPUArchIdList; 693811ef14SIgor Mammedov 703811ef14SIgor Mammedov /** 7136d20cb2SMarcel Apfelbaum * MachineClass: 72b7454548SIgor Mammedov * @get_hotplug_handler: this function is called during bus-less 73b7454548SIgor Mammedov * device hotplug. If defined it returns pointer to an instance 74b7454548SIgor Mammedov * of HotplugHandler object, which handles hotplug operation 75b7454548SIgor Mammedov * for a given @dev. It may return NULL if @dev doesn't require 76b7454548SIgor Mammedov * any actions to be performed by hotplug handler. 77*ea089eebSIgor Mammedov * @cpu_index_to_instance_props: 78*ea089eebSIgor Mammedov * used to provide @cpu_index to socket/core/thread number mapping, allowing 79*ea089eebSIgor Mammedov * legacy code to perform maping from cpu_index to topology properties 80*ea089eebSIgor Mammedov * Returns: tuple of socket/core/thread ids given cpu_index belongs to. 8157924bcdSIgor Mammedov * used to provide @cpu_index to socket number mapping, allowing 8257924bcdSIgor Mammedov * a machine to group CPU threads belonging to the same socket/package 8357924bcdSIgor Mammedov * Returns: socket number given cpu_index belongs to. 84fac862ffSEduardo Habkost * @hw_version: 85fac862ffSEduardo Habkost * Value of QEMU_VERSION when the machine was added to QEMU. 86fac862ffSEduardo Habkost * Set only by old machines because they need to keep 87fac862ffSEduardo Habkost * compatibility on code that exposed QEMU_VERSION to guests in 88fac862ffSEduardo Habkost * the past (and now use qemu_hw_version()). 893811ef14SIgor Mammedov * @possible_cpu_arch_ids: 903811ef14SIgor Mammedov * Returns an array of @CPUArchId architecture-dependent CPU IDs 913811ef14SIgor Mammedov * which includes CPU IDs for present and possible to hotplug CPUs. 923811ef14SIgor Mammedov * Caller is responsible for freeing returned list. 93c5514d0eSIgor Mammedov * @has_hotpluggable_cpus: 94c5514d0eSIgor Mammedov * If true, board supports CPUs creation with -device/device_add. 9520bccb82SPeter Maydell * @minimum_page_bits: 9620bccb82SPeter Maydell * If non-zero, the board promises never to create a CPU with a page size 9720bccb82SPeter Maydell * smaller than this, so QEMU can use a more efficient larger page 9820bccb82SPeter Maydell * size than the target architecture's minimum. (Attempting to create 9920bccb82SPeter Maydell * such a CPU will fail.) Note that changing this is a migration 10020bccb82SPeter Maydell * compatibility break for the machine. 10136d20cb2SMarcel Apfelbaum */ 10236d20cb2SMarcel Apfelbaum struct MachineClass { 10336d20cb2SMarcel Apfelbaum /*< private >*/ 10436d20cb2SMarcel Apfelbaum ObjectClass parent_class; 10536d20cb2SMarcel Apfelbaum /*< public >*/ 10636d20cb2SMarcel Apfelbaum 1072709f263SLaszlo Ersek const char *family; /* NULL iff @name identifies a standalone machtype */ 1088ea75371SMarc-André Lureau char *name; 10900b4fbe2SMarcel Apfelbaum const char *alias; 11000b4fbe2SMarcel Apfelbaum const char *desc; 11100b4fbe2SMarcel Apfelbaum 1123ef96221SMarcel Apfelbaum void (*init)(MachineState *state); 11300b4fbe2SMarcel Apfelbaum void (*reset)(void); 11400b4fbe2SMarcel Apfelbaum void (*hot_add_cpu)(const int64_t id, Error **errp); 11500b4fbe2SMarcel Apfelbaum int (*kvm_type)(const char *arg); 11600b4fbe2SMarcel Apfelbaum 11700b4fbe2SMarcel Apfelbaum BlockInterfaceType block_default_type; 11816026518SJohn Snow int units_per_default_bus; 11900b4fbe2SMarcel Apfelbaum int max_cpus; 12000b4fbe2SMarcel Apfelbaum unsigned int no_serial:1, 12100b4fbe2SMarcel Apfelbaum no_parallel:1, 12200b4fbe2SMarcel Apfelbaum use_virtcon:1, 12300b4fbe2SMarcel Apfelbaum use_sclp:1, 12400b4fbe2SMarcel Apfelbaum no_floppy:1, 12500b4fbe2SMarcel Apfelbaum no_cdrom:1, 12633cd52b5SAlexander Graf no_sdcard:1, 12792055797SPaulo Alcantara has_dynamic_sysbus:1, 128bab47d9aSGerd Hoffmann pci_allow_0_address:1, 129bab47d9aSGerd Hoffmann legacy_fw_cfg_order:1; 13000b4fbe2SMarcel Apfelbaum int is_default; 13100b4fbe2SMarcel Apfelbaum const char *default_machine_opts; 13200b4fbe2SMarcel Apfelbaum const char *default_boot_order; 1336f00494aSGerd Hoffmann const char *default_display; 134bacc344cSIgor Mammedov GArray *compat_props; 13500b4fbe2SMarcel Apfelbaum const char *hw_version; 136076b35b5SNikunj A Dadhania ram_addr_t default_ram_size; 13771ae9e94SEduardo Habkost bool option_rom_has_mr; 13871ae9e94SEduardo Habkost bool rom_file_has_mr; 13920bccb82SPeter Maydell int minimum_page_bits; 140c5514d0eSIgor Mammedov bool has_hotpluggable_cpus; 14155641213SLaurent Vivier int numa_mem_align_shift; 1423bfe5716SLaurent Vivier void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes, 1433bfe5716SLaurent Vivier int nb_nodes, ram_addr_t size); 144b7454548SIgor Mammedov 145b7454548SIgor Mammedov HotplugHandler *(*get_hotplug_handler)(MachineState *machine, 146b7454548SIgor Mammedov DeviceState *dev); 147*ea089eebSIgor Mammedov CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine, 148*ea089eebSIgor Mammedov unsigned cpu_index); 14980e5db30SIgor Mammedov const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); 15036d20cb2SMarcel Apfelbaum }; 15136d20cb2SMarcel Apfelbaum 15236d20cb2SMarcel Apfelbaum /** 15336d20cb2SMarcel Apfelbaum * MachineState: 15436d20cb2SMarcel Apfelbaum */ 15536d20cb2SMarcel Apfelbaum struct MachineState { 15636d20cb2SMarcel Apfelbaum /*< private >*/ 15736d20cb2SMarcel Apfelbaum Object parent_obj; 15833cd52b5SAlexander Graf Notifier sysbus_notifier; 15933cd52b5SAlexander Graf 16036d20cb2SMarcel Apfelbaum /*< public >*/ 16136d20cb2SMarcel Apfelbaum 16236d20cb2SMarcel Apfelbaum char *accel; 163d8870d02SMarcel Apfelbaum bool kernel_irqchip_allowed; 164d8870d02SMarcel Apfelbaum bool kernel_irqchip_required; 16532c18a2dSMatt Gingell bool kernel_irqchip_split; 16636d20cb2SMarcel Apfelbaum int kvm_shadow_mem; 16736d20cb2SMarcel Apfelbaum char *dtb; 16836d20cb2SMarcel Apfelbaum char *dumpdtb; 16936d20cb2SMarcel Apfelbaum int phandle_start; 17036d20cb2SMarcel Apfelbaum char *dt_compatible; 17136d20cb2SMarcel Apfelbaum bool dump_guest_core; 17236d20cb2SMarcel Apfelbaum bool mem_merge; 17336d20cb2SMarcel Apfelbaum bool usb; 174c6e76503SPaolo Bonzini bool usb_disabled; 17579814179STiejun Chen bool igd_gfx_passthru; 17636d20cb2SMarcel Apfelbaum char *firmware; 177a52a7fdfSLe Tan bool iommu; 1789850c604SAlexander Graf bool suppress_vmdesc; 179902c053dSGreg Kurz bool enforce_config_section; 180cfc58cf3SEduardo Habkost bool enable_graphics; 18136d20cb2SMarcel Apfelbaum 1823ef96221SMarcel Apfelbaum ram_addr_t ram_size; 183c270fb9eSIgor Mammedov ram_addr_t maxram_size; 184c270fb9eSIgor Mammedov uint64_t ram_slots; 1853ef96221SMarcel Apfelbaum const char *boot_order; 1866b1b1440SMarcel Apfelbaum char *kernel_filename; 1876b1b1440SMarcel Apfelbaum char *kernel_cmdline; 1886b1b1440SMarcel Apfelbaum char *initrd_filename; 1893ef96221SMarcel Apfelbaum const char *cpu_model; 190ac2da55eSEduardo Habkost AccelState *accelerator; 19138690a1cSIgor Mammedov CPUArchIdList *possible_cpus; 19236d20cb2SMarcel Apfelbaum }; 19336d20cb2SMarcel Apfelbaum 194ed0b6de3SEduardo Habkost #define DEFINE_MACHINE(namestr, machine_initfn) \ 195ed0b6de3SEduardo Habkost static void machine_initfn##_class_init(ObjectClass *oc, void *data) \ 196ed0b6de3SEduardo Habkost { \ 197ed0b6de3SEduardo Habkost MachineClass *mc = MACHINE_CLASS(oc); \ 198ed0b6de3SEduardo Habkost machine_initfn(mc); \ 199ed0b6de3SEduardo Habkost } \ 200ed0b6de3SEduardo Habkost static const TypeInfo machine_initfn##_typeinfo = { \ 201ed0b6de3SEduardo Habkost .name = MACHINE_TYPE_NAME(namestr), \ 202ed0b6de3SEduardo Habkost .parent = TYPE_MACHINE, \ 203ed0b6de3SEduardo Habkost .class_init = machine_initfn##_class_init, \ 204ed0b6de3SEduardo Habkost }; \ 205ed0b6de3SEduardo Habkost static void machine_initfn##_register_types(void) \ 206ed0b6de3SEduardo Habkost { \ 207ed0b6de3SEduardo Habkost type_register_static(&machine_initfn##_typeinfo); \ 208ed0b6de3SEduardo Habkost } \ 2090e6aac87SEduardo Habkost type_init(machine_initfn##_register_types) 210ed0b6de3SEduardo Habkost 211877f8931SDavid Gibson #define SET_MACHINE_COMPAT(m, COMPAT) \ 212877f8931SDavid Gibson do { \ 213bacc344cSIgor Mammedov int i; \ 214877f8931SDavid Gibson static GlobalProperty props[] = { \ 215877f8931SDavid Gibson COMPAT \ 216877f8931SDavid Gibson { /* end of list */ } \ 217877f8931SDavid Gibson }; \ 218bacc344cSIgor Mammedov if (!m->compat_props) { \ 219bacc344cSIgor Mammedov m->compat_props = g_array_new(false, false, sizeof(void *)); \ 220bacc344cSIgor Mammedov } \ 221bacc344cSIgor Mammedov for (i = 0; props[i].driver != NULL; i++) { \ 222bacc344cSIgor Mammedov GlobalProperty *prop = &props[i]; \ 223bacc344cSIgor Mammedov g_array_append_val(m->compat_props, prop); \ 224bacc344cSIgor Mammedov } \ 225877f8931SDavid Gibson } while (0) 226877f8931SDavid Gibson 2270d09e41aSPaolo Bonzini #endif 228