xref: /openbmc/qemu/include/hw/boards.h (revision 7c88e65d9e9ff7df7fa9cff1869d64a0eaac63a1)
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 void machine_register_compat_props(MachineState *machine);
44 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
45 void machine_set_cpu_numa_node(MachineState *machine,
46                                const CpuInstanceProperties *props,
47                                Error **errp);
48 
49 /**
50  * CPUArchId:
51  * @arch_id - architecture-dependent CPU ID of present or possible CPU
52  * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
53  * @props - CPU object properties, initialized by board
54  * #vcpus_count - number of threads provided by @cpu object
55  */
56 typedef struct {
57     uint64_t arch_id;
58     int64_t vcpus_count;
59     CpuInstanceProperties props;
60     Object *cpu;
61 } CPUArchId;
62 
63 /**
64  * CPUArchIdList:
65  * @len - number of @CPUArchId items in @cpus array
66  * @cpus - array of present or possible CPUs for current machine configuration
67  */
68 typedef struct {
69     int len;
70     CPUArchId cpus[0];
71 } CPUArchIdList;
72 
73 /**
74  * MachineClass:
75  * @get_hotplug_handler: this function is called during bus-less
76  *    device hotplug. If defined it returns pointer to an instance
77  *    of HotplugHandler object, which handles hotplug operation
78  *    for a given @dev. It may return NULL if @dev doesn't require
79  *    any actions to be performed by hotplug handler.
80  * @cpu_index_to_instance_props:
81  *    used to provide @cpu_index to socket/core/thread number mapping, allowing
82  *    legacy code to perform maping from cpu_index to topology properties
83  *    Returns: tuple of socket/core/thread ids given cpu_index belongs to.
84  *    used to provide @cpu_index to socket number mapping, allowing
85  *    a machine to group CPU threads belonging to the same socket/package
86  *    Returns: socket number given cpu_index belongs to.
87  * @hw_version:
88  *    Value of QEMU_VERSION when the machine was added to QEMU.
89  *    Set only by old machines because they need to keep
90  *    compatibility on code that exposed QEMU_VERSION to guests in
91  *    the past (and now use qemu_hw_version()).
92  * @possible_cpu_arch_ids:
93  *    Returns an array of @CPUArchId architecture-dependent CPU IDs
94  *    which includes CPU IDs for present and possible to hotplug CPUs.
95  *    Caller is responsible for freeing returned list.
96  * @has_hotpluggable_cpus:
97  *    If true, board supports CPUs creation with -device/device_add.
98  * @minimum_page_bits:
99  *    If non-zero, the board promises never to create a CPU with a page size
100  *    smaller than this, so QEMU can use a more efficient larger page
101  *    size than the target architecture's minimum. (Attempting to create
102  *    such a CPU will fail.) Note that changing this is a migration
103  *    compatibility break for the machine.
104  */
105 struct MachineClass {
106     /*< private >*/
107     ObjectClass parent_class;
108     /*< public >*/
109 
110     const char *family; /* NULL iff @name identifies a standalone machtype */
111     char *name;
112     const char *alias;
113     const char *desc;
114 
115     void (*init)(MachineState *state);
116     void (*reset)(void);
117     void (*hot_add_cpu)(const int64_t id, Error **errp);
118     int (*kvm_type)(const char *arg);
119 
120     BlockInterfaceType block_default_type;
121     int units_per_default_bus;
122     int max_cpus;
123     unsigned int no_serial:1,
124         no_parallel:1,
125         use_virtcon:1,
126         use_sclp:1,
127         no_floppy:1,
128         no_cdrom:1,
129         no_sdcard:1,
130         has_dynamic_sysbus:1,
131         pci_allow_0_address:1,
132         legacy_fw_cfg_order:1;
133     int is_default;
134     const char *default_machine_opts;
135     const char *default_boot_order;
136     const char *default_display;
137     GArray *compat_props;
138     const char *hw_version;
139     ram_addr_t default_ram_size;
140     bool option_rom_has_mr;
141     bool rom_file_has_mr;
142     int minimum_page_bits;
143     bool has_hotpluggable_cpus;
144     int numa_mem_align_shift;
145     void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes,
146                                  int nb_nodes, ram_addr_t size);
147 
148     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
149                                            DeviceState *dev);
150     CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
151                                                          unsigned cpu_index);
152     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
153 };
154 
155 /**
156  * MachineState:
157  */
158 struct MachineState {
159     /*< private >*/
160     Object parent_obj;
161     Notifier sysbus_notifier;
162 
163     /*< public >*/
164 
165     char *accel;
166     bool kernel_irqchip_allowed;
167     bool kernel_irqchip_required;
168     bool kernel_irqchip_split;
169     int kvm_shadow_mem;
170     char *dtb;
171     char *dumpdtb;
172     int phandle_start;
173     char *dt_compatible;
174     bool dump_guest_core;
175     bool mem_merge;
176     bool usb;
177     bool usb_disabled;
178     bool igd_gfx_passthru;
179     char *firmware;
180     bool iommu;
181     bool suppress_vmdesc;
182     bool enforce_config_section;
183     bool enable_graphics;
184 
185     ram_addr_t ram_size;
186     ram_addr_t maxram_size;
187     uint64_t   ram_slots;
188     const char *boot_order;
189     char *kernel_filename;
190     char *kernel_cmdline;
191     char *initrd_filename;
192     const char *cpu_model;
193     AccelState *accelerator;
194     CPUArchIdList *possible_cpus;
195 };
196 
197 #define DEFINE_MACHINE(namestr, machine_initfn) \
198     static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
199     { \
200         MachineClass *mc = MACHINE_CLASS(oc); \
201         machine_initfn(mc); \
202     } \
203     static const TypeInfo machine_initfn##_typeinfo = { \
204         .name       = MACHINE_TYPE_NAME(namestr), \
205         .parent     = TYPE_MACHINE, \
206         .class_init = machine_initfn##_class_init, \
207     }; \
208     static void machine_initfn##_register_types(void) \
209     { \
210         type_register_static(&machine_initfn##_typeinfo); \
211     } \
212     type_init(machine_initfn##_register_types)
213 
214 #define SET_MACHINE_COMPAT(m, COMPAT) \
215     do {                              \
216         int i;                        \
217         static GlobalProperty props[] = {       \
218             COMPAT                              \
219             { /* end of list */ }               \
220         };                                      \
221         if (!m->compat_props) { \
222             m->compat_props = g_array_new(false, false, sizeof(void *)); \
223         } \
224         for (i = 0; props[i].driver != NULL; i++) {    \
225             GlobalProperty *prop = &props[i];          \
226             g_array_append_val(m->compat_props, prop); \
227         }                                              \
228     } while (0)
229 
230 #endif
231