]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/boards.h
hw/fsi: Introduce IBM's FSI Bus
[mirror_qemu.git] / include / hw / boards.h
CommitLineData
87ecb68b
PB
1/* Declarations for use by board files for creating devices. */
2
3#ifndef HW_BOARDS_H
4#define HW_BOARDS_H
5
d4842052 6#include "exec/memory.h"
aa8b1839 7#include "sysemu/hostmem.h"
9c17d615 8#include "sysemu/blockdev.h"
8ac25c84 9#include "qapi/qapi-types-machine.h"
0b8fa32f 10#include "qemu/module.h"
36d20cb2 11#include "qom/object.h"
2e5b09fd 12#include "hw/core/cpu.h"
b6b61144 13
dfabb8b9 14#define TYPE_MACHINE_SUFFIX "-machine"
c84a8f01
EH
15
16/* Machine class name that needs to be used for class-name-based machine
17 * type lookup to work.
18 */
19#define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)
20
36d20cb2 21#define TYPE_MACHINE "machine"
c8897e8e 22#undef MACHINE /* BSD defines it and QEMU does not use it */
a489d195 23OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
36d20cb2 24
0056ae24
MA
25extern MachineState *current_machine;
26
62b4a227
PMD
27/**
28 * machine_class_default_cpu_type: Return the machine default CPU type.
29 * @mc: Machine class
30 */
31const char *machine_class_default_cpu_type(MachineClass *mc);
32
7a2c7da6 33void machine_add_audiodev_property(MachineClass *mc);
26f88d84 34void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp);
5e97b623 35bool machine_usb(MachineState *machine);
6cabe7fa 36int machine_phandle_start(MachineState *machine);
47c8ca53 37bool machine_dump_guest_core(MachineState *machine);
75cc7f01 38bool machine_mem_merge(MachineState *machine);
f2d672c2 39HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
7c88e65d
IM
40void machine_set_cpu_numa_node(MachineState *machine,
41 const CpuInstanceProperties *props,
42 Error **errp);
3e2f1498
PMD
43void machine_parse_smp_config(MachineState *ms,
44 const SMPConfiguration *config, Error **errp);
a1d027be
ZL
45unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
46unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
cc0afd8a 47void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size);
5e97b623 48
387c0e8b
PM
49/**
50 * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
51 * @mc: Machine class
52 * @type: type to allow (should be a subtype of TYPE_SYS_BUS_DEVICE)
53 *
54 * Add the QOM type @type to the list of devices of which are subtypes
55 * of TYPE_SYS_BUS_DEVICE but which are still permitted to be dynamically
56 * created (eg by the user on the command line with -device).
57 * By default if the user tries to create any devices on the command line
58 * that are subtypes of TYPE_SYS_BUS_DEVICE they will get an error message;
59 * for the special cases which are permitted for this machine model, the
60 * machine model class init code must call this function to add them
61 * to the list of specifically permitted devices.
62 */
0bd1909d 63void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
387c0e8b 64
b5fdf410
DH
65/**
66 * device_type_is_dynamic_sysbus: Check if type is an allowed sysbus device
67 * type for the machine class.
68 * @mc: Machine class
69 * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE)
70 *
71 * Returns: true if @type is a type in the machine's list of
72 * dynamically pluggable sysbus devices; otherwise false.
73 *
74 * Check if the QOM type @type is in the list of allowed sysbus device
75 * types (see machine_class_allowed_dynamic_sysbus_dev()).
76 * Note that if @type has a parent type in the list, it is allowed too.
77 */
78bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type);
79
0fb124db
PM
80/**
81 * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device
82 * @mc: Machine class
83 * @dev: device to check
84 *
85 * Returns: true if @dev is a sysbus device on the machine's list
86 * of dynamically pluggable sysbus devices; otherwise false.
87 *
88 * This function checks whether @dev is a valid dynamic sysbus device,
89 * by first confirming that it is a sysbus device and then checking it
90 * against the list of permitted dynamic sysbus devices which has been
91 * set up by the machine using machine_class_allow_dynamic_sysbus_dev().
92 *
93 * It is valid to call this with something that is not a subclass of
94 * TYPE_SYS_BUS_DEVICE; the function will return false in this case.
95 * This allows hotplug callback functions to be written as:
96 * if (device_is_dynamic_sysbus(mc, dev)) {
97 * handle dynamic sysbus case;
98 * } else if (some other kind of hotplug) {
99 * handle that;
100 * }
101 */
102bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev);
103
82b911aa
IM
104/*
105 * Checks that backend isn't used, preps it for exclusive usage and
106 * returns migratable MemoryRegion provided by backend.
107 */
108MemoryRegion *machine_consume_memdev(MachineState *machine,
109 HostMemoryBackend *backend);
0bd1909d 110
3811ef14
IM
111/**
112 * CPUArchId:
113 * @arch_id - architecture-dependent CPU ID of present or possible CPU
114 * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
d342eb76 115 * @type - QOM class name of possible @cpu object
c67ae933 116 * @props - CPU object properties, initialized by board
f2d672c2 117 * #vcpus_count - number of threads provided by @cpu object
3811ef14 118 */
a44432b4 119typedef struct CPUArchId {
3811ef14 120 uint64_t arch_id;
f2d672c2 121 int64_t vcpus_count;
c67ae933 122 CpuInstanceProperties props;
8aba3842 123 Object *cpu;
d342eb76 124 const char *type;
3811ef14
IM
125} CPUArchId;
126
127/**
128 * CPUArchIdList:
129 * @len - number of @CPUArchId items in @cpus array
130 * @cpus - array of present or possible CPUs for current machine configuration
131 */
132typedef struct {
133 int len;
880a7817 134 CPUArchId cpus[];
3811ef14
IM
135} CPUArchIdList;
136
e4a97a89
YW
137/**
138 * SMPCompatProps:
2b526199 139 * @prefer_sockets - whether sockets are preferred over cores in smp parsing
e4a97a89 140 * @dies_supported - whether dies are supported by the machine
864c3b5c 141 * @clusters_supported - whether clusters are supported by the machine
97f4effe
YY
142 * @has_clusters - whether clusters are explicitly specified in the user
143 * provided SMP configuration
5de1aff2
PM
144 * @books_supported - whether books are supported by the machine
145 * @drawers_supported - whether drawers are supported by the machine
e4a97a89
YW
146 */
147typedef struct {
2b526199 148 bool prefer_sockets;
e4a97a89 149 bool dies_supported;
864c3b5c 150 bool clusters_supported;
97f4effe 151 bool has_clusters;
5de1aff2
PM
152 bool books_supported;
153 bool drawers_supported;
e4a97a89
YW
154} SMPCompatProps;
155
36d20cb2
MA
156/**
157 * MachineClass:
08fe6824
TH
158 * @deprecation_reason: If set, the machine is marked as deprecated. The
159 * string should provide some clear information about what to use instead.
72649619
EC
160 * @max_cpus: maximum number of CPUs supported. Default: 1
161 * @min_cpus: minimum number of CPUs supported. Default: 1
162 * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
ea0ac7f6
PMD
163 * @is_default:
164 * If true QEMU will use this machine by default if no '-M' option is given.
b7454548
IM
165 * @get_hotplug_handler: this function is called during bus-less
166 * device hotplug. If defined it returns pointer to an instance
167 * of HotplugHandler object, which handles hotplug operation
168 * for a given @dev. It may return NULL if @dev doesn't require
169 * any actions to be performed by hotplug handler.
ea089eeb
IM
170 * @cpu_index_to_instance_props:
171 * used to provide @cpu_index to socket/core/thread number mapping, allowing
a1a62ced 172 * legacy code to perform mapping from cpu_index to topology properties
ea089eeb 173 * Returns: tuple of socket/core/thread ids given cpu_index belongs to.
57924bcd
IM
174 * used to provide @cpu_index to socket number mapping, allowing
175 * a machine to group CPU threads belonging to the same socket/package
176 * Returns: socket number given cpu_index belongs to.
fac862ff
EH
177 * @hw_version:
178 * Value of QEMU_VERSION when the machine was added to QEMU.
179 * Set only by old machines because they need to keep
180 * compatibility on code that exposed QEMU_VERSION to guests in
181 * the past (and now use qemu_hw_version()).
3811ef14
IM
182 * @possible_cpu_arch_ids:
183 * Returns an array of @CPUArchId architecture-dependent CPU IDs
184 * which includes CPU IDs for present and possible to hotplug CPUs.
185 * Caller is responsible for freeing returned list.
79e07936
IM
186 * @get_default_cpu_node_id:
187 * returns default board specific node_id value for CPU slot specified by
188 * index @idx in @ms->possible_cpus[]
c5514d0e
IM
189 * @has_hotpluggable_cpus:
190 * If true, board supports CPUs creation with -device/device_add.
6063d4c0
IM
191 * @default_cpu_type:
192 * specifies default CPU_TYPE, which will be used for parsing target
193 * specific features and for creating CPUs if CPU name wasn't provided
194 * explicitly at CLI
20bccb82
PM
195 * @minimum_page_bits:
196 * If non-zero, the board promises never to create a CPU with a page size
197 * smaller than this, so QEMU can use a more efficient larger page
198 * size than the target architecture's minimum. (Attempting to create
199 * such a CPU will fail.) Note that changing this is a migration
200 * compatibility break for the machine.
ed860129
PM
201 * @ignore_memory_transaction_failures:
202 * If this is flag is true then the CPU will ignore memory transaction
203 * failures which should cause the CPU to take an exception due to an
204 * access to an unassigned physical address; the transaction will instead
205 * return zero (for a read) or be ignored (for a write). This should be
206 * set only by legacy board models which rely on the old RAZ/WI behaviour
207 * for handling devices that QEMU does not yet model. New board models
208 * should instead use "unimplemented-device" for all memory ranges where
209 * the guest will attempt to probe for a device that QEMU doesn't
210 * implement and a stub device is required.
dc0ca80e
EA
211 * @kvm_type:
212 * Return the type of KVM corresponding to the kvm-type string option or
213 * computed based on other criteria such as the host kernel capabilities.
516fc0a0 214 * kvm-type may be NULL if it is not needed.
cd5ff833
IM
215 * @numa_mem_supported:
216 * true if '--numa node.mem' option is supported and false otherwise
d2321d31
PX
217 * @hotplug_allowed:
218 * If the hook is provided, then it'll be called for each device
219 * hotplug to check whether the device hotplug is allowed. Return
220 * true to grant allowance or false to reject the hotplug. When
221 * false is returned, an error must be set to show the reason of
222 * the rejection. If the hook is not provided, all hotplug will be
223 * allowed.
900c0ba3 224 * @default_ram_id:
a1a62ced 225 * Specifies initial RAM MemoryRegion name to be used for default backend
900c0ba3
IM
226 * creation if user explicitly hasn't specified backend with "memory-backend"
227 * property.
a1a62ced 228 * It also will be used as a way to option into "-m" option support.
900c0ba3
IM
229 * If it's not set by board, '-m' will be ignored and generic code will
230 * not create default RAM MemoryRegion.
5c30ef93
CB
231 * @fixup_ram_size:
232 * Amends user provided ram size (with -m option) using machine
233 * specific algorithm. To be used by old machine types for compat
234 * purposes only.
235 * Applies only to default memory backend, i.e., explicit memory backend
236 * wasn't used.
36d20cb2
MA
237 */
238struct MachineClass {
239 /*< private >*/
240 ObjectClass parent_class;
241 /*< public >*/
242
2709f263 243 const char *family; /* NULL iff @name identifies a standalone machtype */
8ea75371 244 char *name;
00b4fbe2
MA
245 const char *alias;
246 const char *desc;
08fe6824 247 const char *deprecation_reason;
00b4fbe2 248
3ef96221 249 void (*init)(MachineState *state);
7966d70f 250 void (*reset)(MachineState *state, ShutdownCause reason);
4b5e06c9 251 void (*wakeup)(MachineState *state);
dc0ca80e 252 int (*kvm_type)(MachineState *machine, const char *arg);
00b4fbe2
MA
253
254 BlockInterfaceType block_default_type;
16026518 255 int units_per_default_bus;
00b4fbe2 256 int max_cpus;
72649619
EC
257 int min_cpus;
258 int default_cpus;
00b4fbe2
MA
259 unsigned int no_serial:1,
260 no_parallel:1,
00b4fbe2
MA
261 no_floppy:1,
262 no_cdrom:1,
33cd52b5 263 no_sdcard:1,
bab47d9a
GH
264 pci_allow_0_address:1,
265 legacy_fw_cfg_order:1;
ea0ac7f6 266 bool is_default;
00b4fbe2
MA
267 const char *default_machine_opts;
268 const char *default_boot_order;
6f00494a 269 const char *default_display;
01ecdaa4 270 const char *default_nic;
b66bbee3 271 GPtrArray *compat_props;
00b4fbe2 272 const char *hw_version;
076b35b5 273 ram_addr_t default_ram_size;
6063d4c0 274 const char *default_cpu_type;
b2fc91db 275 bool default_kernel_irqchip_split;
71ae9e94
EH
276 bool option_rom_has_mr;
277 bool rom_file_has_mr;
20bccb82 278 int minimum_page_bits;
c5514d0e 279 bool has_hotpluggable_cpus;
ed860129 280 bool ignore_memory_transaction_failures;
55641213 281 int numa_mem_align_shift;
790a4428 282 const char * const *valid_cpu_types;
0bd1909d 283 strList *allowed_dynamic_sysbus_devices;
7b8be49d 284 bool auto_enable_numa_with_memhp;
195784a0 285 bool auto_enable_numa_with_memdev;
907aac2f 286 bool ignore_boot_device_suffixes;
7fccf2a0 287 bool smbus_no_migration_support;
f6a0d06b 288 bool nvdimm_supported;
cd5ff833 289 bool numa_mem_supported;
0533ef5f 290 bool auto_enable_numa;
a494fdb7 291 bool cpu_cluster_has_numa_boundary;
e4a97a89 292 SMPCompatProps smp_props;
900c0ba3 293 const char *default_ram_id;
b7454548
IM
294
295 HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
296 DeviceState *dev);
d2321d31
PX
297 bool (*hotplug_allowed)(MachineState *state, DeviceState *dev,
298 Error **errp);
ea089eeb
IM
299 CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
300 unsigned cpu_index);
80e5db30 301 const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
79e07936 302 int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
5c30ef93 303 ram_addr_t (*fixup_ram_size)(ram_addr_t size);
36d20cb2
MA
304};
305
b0c14ec4 306/**
e017da37 307 * DeviceMemoryState:
b0c14ec4
DH
308 * @base: address in guest physical address space where the memory
309 * address space for memory devices starts
f9716f4b
DH
310 * @mr: memory region container for memory devices
311 * @as: address space for memory devices
312 * @listener: memory listener used to track used memslots in the address space
e919402b 313 * @dimm_size: the sum of plugged DIMMs' sizes
ac23dd2f 314 * @used_region_size: the part of @mr already used by memory devices
f9716f4b
DH
315 * @required_memslots: the number of memslots required by memory devices
316 * @used_memslots: the number of memslots currently used by memory devices
a2335113
DH
317 * @memslot_auto_decision_active: whether any plugged memory device
318 * automatically decided to use more than
319 * one memslot
b0c14ec4 320 */
e017da37 321typedef struct DeviceMemoryState {
b0c14ec4
DH
322 hwaddr base;
323 MemoryRegion mr;
f9716f4b
DH
324 AddressSpace as;
325 MemoryListener listener;
e919402b 326 uint64_t dimm_size;
ac23dd2f 327 uint64_t used_region_size;
f9716f4b
DH
328 unsigned int required_memslots;
329 unsigned int used_memslots;
a2335113 330 unsigned int memslot_auto_decision_active;
e017da37 331} DeviceMemoryState;
b0c14ec4 332
edeeec91
LX
333/**
334 * CpuTopology:
335 * @cpus: the number of present logical processors on the machine
5de1aff2
PM
336 * @drawers: the number of drawers on the machine
337 * @books: the number of books in one drawer
338 * @sockets: the number of sockets in one book
003f230e 339 * @dies: the number of dies in one socket
864c3b5c
YW
340 * @clusters: the number of clusters in one die
341 * @cores: the number of cores in one cluster
003f230e 342 * @threads: the number of threads in one core
edeeec91
LX
343 * @max_cpus: the maximum number of logical processors on the machine
344 */
345typedef struct CpuTopology {
346 unsigned int cpus;
5de1aff2
PM
347 unsigned int drawers;
348 unsigned int books;
003f230e 349 unsigned int sockets;
67872eb8 350 unsigned int dies;
864c3b5c 351 unsigned int clusters;
edeeec91
LX
352 unsigned int cores;
353 unsigned int threads;
354 unsigned int max_cpus;
355} CpuTopology;
356
36d20cb2
MA
357/**
358 * MachineState:
359 */
360struct MachineState {
361 /*< private >*/
362 Object parent_obj;
33cd52b5 363
36d20cb2
MA
364 /*< public >*/
365
a6487d37 366 void *fdt;
36d20cb2
MA
367 char *dtb;
368 char *dumpdtb;
369 int phandle_start;
370 char *dt_compatible;
371 bool dump_guest_core;
372 bool mem_merge;
373 bool usb;
c6e76503 374 bool usb_disabled;
36d20cb2 375 char *firmware;
a52a7fdf 376 bool iommu;
9850c604 377 bool suppress_vmdesc;
cfc58cf3 378 bool enable_graphics;
e0292d7c 379 ConfidentialGuestSupport *cgs;
26f88d84 380 HostMemoryBackend *memdev;
82b911aa
IM
381 /*
382 * convenience alias to ram_memdev_id backend memory region
383 * or to numa container memory region
384 */
385 MemoryRegion *ram;
e017da37 386 DeviceMemoryState *device_memory;
36d20cb2 387
7a2c7da6
MK
388 /*
389 * Included in MachineState for simplicity, but not supported
390 * unless machine_add_audiodev_property is called. Boards
391 * that have embedded audio devices can call it from the
392 * machine init function and forward the property to the device.
393 */
394 char *audiodev;
395
3ef96221 396 ram_addr_t ram_size;
c270fb9e
IM
397 ram_addr_t maxram_size;
398 uint64_t ram_slots;
97ec4d21 399 BootConfiguration boot_config;
6b1b1440
MA
400 char *kernel_filename;
401 char *kernel_cmdline;
402 char *initrd_filename;
6063d4c0 403 const char *cpu_type;
ac2da55e 404 AccelState *accelerator;
38690a1c 405 CPUArchIdList *possible_cpus;
edeeec91 406 CpuTopology smp;
f6a0d06b 407 struct NVDIMMState *nvdimms_state;
aa570207 408 struct NumaState *numa_state;
36d20cb2
MA
409};
410
ed0b6de3
EH
411#define DEFINE_MACHINE(namestr, machine_initfn) \
412 static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
413 { \
414 MachineClass *mc = MACHINE_CLASS(oc); \
415 machine_initfn(mc); \
416 } \
417 static const TypeInfo machine_initfn##_typeinfo = { \
418 .name = MACHINE_TYPE_NAME(namestr), \
419 .parent = TYPE_MACHINE, \
420 .class_init = machine_initfn##_class_init, \
421 }; \
422 static void machine_initfn##_register_types(void) \
423 { \
424 type_register_static(&machine_initfn##_typeinfo); \
425 } \
0e6aac87 426 type_init(machine_initfn##_register_types)
ed0b6de3 427
2b10a676
CH
428extern GlobalProperty hw_compat_8_2[];
429extern const size_t hw_compat_8_2_len;
430
95f5c89e
CH
431extern GlobalProperty hw_compat_8_1[];
432extern const size_t hw_compat_8_1_len;
433
0259dd3e
CH
434extern GlobalProperty hw_compat_8_0[];
435extern const size_t hw_compat_8_0_len;
436
db723c80
CH
437extern GlobalProperty hw_compat_7_2[];
438extern const size_t hw_compat_7_2_len;
439
f514e147
CH
440extern GlobalProperty hw_compat_7_1[];
441extern const size_t hw_compat_7_1_len;
442
0ca70366
CH
443extern GlobalProperty hw_compat_7_0[];
444extern const size_t hw_compat_7_0_len;
445
01854af2
CH
446extern GlobalProperty hw_compat_6_2[];
447extern const size_t hw_compat_6_2_len;
448
52e64f5b
YW
449extern GlobalProperty hw_compat_6_1[];
450extern const size_t hw_compat_6_1_len;
451
da7e13c0
CH
452extern GlobalProperty hw_compat_6_0[];
453extern const size_t hw_compat_6_0_len;
454
576a00bd
CH
455extern GlobalProperty hw_compat_5_2[];
456extern const size_t hw_compat_5_2_len;
457
3ff3c5d3
CH
458extern GlobalProperty hw_compat_5_1[];
459extern const size_t hw_compat_5_1_len;
460
541aaa1d
CH
461extern GlobalProperty hw_compat_5_0[];
462extern const size_t hw_compat_5_0_len;
463
5f258577
EY
464extern GlobalProperty hw_compat_4_2[];
465extern const size_t hw_compat_4_2_len;
466
9aec2e52
CH
467extern GlobalProperty hw_compat_4_1[];
468extern const size_t hw_compat_4_1_len;
469
9bf2650b
CH
470extern GlobalProperty hw_compat_4_0[];
471extern const size_t hw_compat_4_0_len;
472
abd93cc7
MAL
473extern GlobalProperty hw_compat_3_1[];
474extern const size_t hw_compat_3_1_len;
475
ddb3235d
MAL
476extern GlobalProperty hw_compat_3_0[];
477extern const size_t hw_compat_3_0_len;
478
0d47310b
MAL
479extern GlobalProperty hw_compat_2_12[];
480extern const size_t hw_compat_2_12_len;
481
43df70a9
MAL
482extern GlobalProperty hw_compat_2_11[];
483extern const size_t hw_compat_2_11_len;
484
503224f4
MAL
485extern GlobalProperty hw_compat_2_10[];
486extern const size_t hw_compat_2_10_len;
487
3e803152
MAL
488extern GlobalProperty hw_compat_2_9[];
489extern const size_t hw_compat_2_9_len;
490
edc24ccd
MAL
491extern GlobalProperty hw_compat_2_8[];
492extern const size_t hw_compat_2_8_len;
493
5a995064
MAL
494extern GlobalProperty hw_compat_2_7[];
495extern const size_t hw_compat_2_7_len;
496
ff8f261f
MAL
497extern GlobalProperty hw_compat_2_6[];
498extern const size_t hw_compat_2_6_len;
499
fe759610
MAL
500extern GlobalProperty hw_compat_2_5[];
501extern const size_t hw_compat_2_5_len;
502
2f99b9c2
MAL
503extern GlobalProperty hw_compat_2_4[];
504extern const size_t hw_compat_2_4_len;
505
8995dd90
MAL
506extern GlobalProperty hw_compat_2_3[];
507extern const size_t hw_compat_2_3_len;
508
1c30044e
MAL
509extern GlobalProperty hw_compat_2_2[];
510extern const size_t hw_compat_2_2_len;
511
c4fc5695
MAL
512extern GlobalProperty hw_compat_2_1[];
513extern const size_t hw_compat_2_1_len;
514
87ecb68b 515#endif