1 /* Declarations for use by board files for creating devices. */ 2 3 #ifndef HW_BOARDS_H 4 #define HW_BOARDS_H 5 6 #include "sysemu/blockdev.h" 7 #include "sysemu/accel.h" 8 #include "hw/qdev.h" 9 #include "qom/object.h" 10 #include "qom/cpu.h" 11 12 void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, 13 const char *name, 14 uint64_t ram_size); 15 16 #define TYPE_MACHINE_SUFFIX "-machine" 17 18 /* Machine class name that needs to be used for class-name-based machine 19 * type lookup to work. 20 */ 21 #define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX) 22 23 #define TYPE_MACHINE "machine" 24 #undef MACHINE /* BSD defines it and QEMU does not use it */ 25 #define MACHINE(obj) \ 26 OBJECT_CHECK(MachineState, (obj), TYPE_MACHINE) 27 #define MACHINE_GET_CLASS(obj) \ 28 OBJECT_GET_CLASS(MachineClass, (obj), TYPE_MACHINE) 29 #define MACHINE_CLASS(klass) \ 30 OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE) 31 32 MachineClass *find_default_machine(void); 33 extern MachineState *current_machine; 34 35 bool machine_usb(MachineState *machine); 36 bool machine_kernel_irqchip_allowed(MachineState *machine); 37 bool machine_kernel_irqchip_required(MachineState *machine); 38 bool machine_kernel_irqchip_split(MachineState *machine); 39 int machine_kvm_shadow_mem(MachineState *machine); 40 int machine_phandle_start(MachineState *machine); 41 bool machine_dump_guest_core(MachineState *machine); 42 bool machine_mem_merge(MachineState *machine); 43 44 /** 45 * CPUArchId: 46 * @arch_id - architecture-dependent CPU ID of present or possible CPU 47 * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise 48 */ 49 typedef struct { 50 uint64_t arch_id; 51 struct CPUState *cpu; 52 } CPUArchId; 53 54 /** 55 * CPUArchIdList: 56 * @len - number of @CPUArchId items in @cpus array 57 * @cpus - array of present or possible CPUs for current machine configuration 58 */ 59 typedef struct { 60 int len; 61 CPUArchId cpus[0]; 62 } CPUArchIdList; 63 64 /** 65 * MachineClass: 66 * @get_hotplug_handler: this function is called during bus-less 67 * device hotplug. If defined it returns pointer to an instance 68 * of HotplugHandler object, which handles hotplug operation 69 * for a given @dev. It may return NULL if @dev doesn't require 70 * any actions to be performed by hotplug handler. 71 * @cpu_index_to_socket_id: 72 * used to provide @cpu_index to socket number mapping, allowing 73 * a machine to group CPU threads belonging to the same socket/package 74 * Returns: socket number given cpu_index belongs to. 75 * @hw_version: 76 * Value of QEMU_VERSION when the machine was added to QEMU. 77 * Set only by old machines because they need to keep 78 * compatibility on code that exposed QEMU_VERSION to guests in 79 * the past (and now use qemu_hw_version()). 80 * @possible_cpu_arch_ids: 81 * Returns an array of @CPUArchId architecture-dependent CPU IDs 82 * which includes CPU IDs for present and possible to hotplug CPUs. 83 * Caller is responsible for freeing returned list. 84 * @query_hotpluggable_cpus: 85 * Returns a @HotpluggableCPUList, which describes CPUs objects which 86 * could be added with -device/device_add. 87 * Caller is responsible for freeing returned list. 88 */ 89 struct MachineClass { 90 /*< private >*/ 91 ObjectClass parent_class; 92 /*< public >*/ 93 94 const char *family; /* NULL iff @name identifies a standalone machtype */ 95 const char *name; 96 const char *alias; 97 const char *desc; 98 99 void (*init)(MachineState *state); 100 void (*reset)(void); 101 void (*hot_add_cpu)(const int64_t id, Error **errp); 102 int (*kvm_type)(const char *arg); 103 104 BlockInterfaceType block_default_type; 105 int units_per_default_bus; 106 int max_cpus; 107 unsigned int no_serial:1, 108 no_parallel:1, 109 use_virtcon:1, 110 use_sclp:1, 111 no_floppy:1, 112 no_cdrom:1, 113 no_sdcard:1, 114 has_dynamic_sysbus:1, 115 pci_allow_0_address:1, 116 legacy_fw_cfg_order:1; 117 int is_default; 118 const char *default_machine_opts; 119 const char *default_boot_order; 120 const char *default_display; 121 GArray *compat_props; 122 const char *hw_version; 123 ram_addr_t default_ram_size; 124 bool option_rom_has_mr; 125 bool rom_file_has_mr; 126 127 HotplugHandler *(*get_hotplug_handler)(MachineState *machine, 128 DeviceState *dev); 129 unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); 130 CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); 131 HotpluggableCPUList *(*query_hotpluggable_cpus)(MachineState *machine); 132 }; 133 134 /** 135 * MachineState: 136 */ 137 struct MachineState { 138 /*< private >*/ 139 Object parent_obj; 140 Notifier sysbus_notifier; 141 142 /*< public >*/ 143 144 char *accel; 145 bool kernel_irqchip_allowed; 146 bool kernel_irqchip_required; 147 bool kernel_irqchip_split; 148 int kvm_shadow_mem; 149 char *dtb; 150 char *dumpdtb; 151 int phandle_start; 152 char *dt_compatible; 153 bool dump_guest_core; 154 bool mem_merge; 155 bool usb; 156 bool usb_disabled; 157 bool igd_gfx_passthru; 158 char *firmware; 159 bool iommu; 160 bool suppress_vmdesc; 161 bool enforce_config_section; 162 bool enable_graphics; 163 164 ram_addr_t ram_size; 165 ram_addr_t maxram_size; 166 uint64_t ram_slots; 167 const char *boot_order; 168 char *kernel_filename; 169 char *kernel_cmdline; 170 char *initrd_filename; 171 const char *cpu_model; 172 AccelState *accelerator; 173 }; 174 175 #define DEFINE_MACHINE(namestr, machine_initfn) \ 176 static void machine_initfn##_class_init(ObjectClass *oc, void *data) \ 177 { \ 178 MachineClass *mc = MACHINE_CLASS(oc); \ 179 machine_initfn(mc); \ 180 } \ 181 static const TypeInfo machine_initfn##_typeinfo = { \ 182 .name = MACHINE_TYPE_NAME(namestr), \ 183 .parent = TYPE_MACHINE, \ 184 .class_init = machine_initfn##_class_init, \ 185 }; \ 186 static void machine_initfn##_register_types(void) \ 187 { \ 188 type_register_static(&machine_initfn##_typeinfo); \ 189 } \ 190 type_init(machine_initfn##_register_types) 191 192 #define SET_MACHINE_COMPAT(m, COMPAT) \ 193 do { \ 194 int i; \ 195 static GlobalProperty props[] = { \ 196 COMPAT \ 197 { /* end of list */ } \ 198 }; \ 199 if (!m->compat_props) { \ 200 m->compat_props = g_array_new(false, false, sizeof(void *)); \ 201 } \ 202 for (i = 0; props[i].driver != NULL; i++) { \ 203 GlobalProperty *prop = &props[i]; \ 204 g_array_append_val(m->compat_props, prop); \ 205 } \ 206 } while (0) 207 208 #endif 209