2 * QEMU PC System Emulator
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu/units.h"
27 #include "hw/i386/x86.h"
28 #include "hw/i386/pc.h"
29 #include "hw/char/serial.h"
30 #include "hw/char/parallel.h"
31 #include "hw/i386/apic.h"
32 #include "hw/i386/topology.h"
33 #include "hw/i386/fw_cfg.h"
34 #include "hw/i386/vmport.h"
35 #include "sysemu/cpus.h"
36 #include "hw/block/fdc.h"
38 #include "hw/pci/pci.h"
39 #include "hw/pci/pci_bus.h"
40 #include "hw/nvram/fw_cfg.h"
41 #include "hw/timer/hpet.h"
42 #include "hw/firmware/smbios.h"
43 #include "hw/loader.h"
45 #include "migration/vmstate.h"
46 #include "multiboot.h"
47 #include "hw/rtc/mc146818rtc.h"
48 #include "hw/intc/i8259.h"
49 #include "hw/dma/i8257.h"
50 #include "hw/timer/i8254.h"
51 #include "hw/input/i8042.h"
53 #include "hw/audio/pcspk.h"
54 #include "hw/pci/msi.h"
55 #include "hw/sysbus.h"
56 #include "sysemu/sysemu.h"
57 #include "sysemu/tcg.h"
58 #include "sysemu/numa.h"
59 #include "sysemu/kvm.h"
60 #include "sysemu/xen.h"
61 #include "sysemu/qtest.h"
62 #include "sysemu/reset.h"
63 #include "sysemu/runstate.h"
64 #include "kvm/kvm_i386.h"
65 #include "hw/xen/xen.h"
66 #include "hw/xen/start_info.h"
67 #include "ui/qemu-spice.h"
68 #include "exec/memory.h"
69 #include "exec/address-spaces.h"
70 #include "sysemu/arch_init.h"
71 #include "qemu/bitmap.h"
72 #include "qemu/config-file.h"
73 #include "qemu/error-report.h"
74 #include "qemu/option.h"
75 #include "qemu/cutils.h"
76 #include "hw/acpi/acpi.h"
77 #include "hw/acpi/cpu_hotplug.h"
78 #include "hw/boards.h"
79 #include "acpi-build.h"
80 #include "hw/mem/pc-dimm.h"
81 #include "hw/mem/nvdimm.h"
82 #include "qapi/error.h"
83 #include "qapi/qapi-visit-common.h"
84 #include "qapi/visitor.h"
85 #include "hw/core/cpu.h"
87 #include "hw/i386/intel_iommu.h"
88 #include "hw/net/ne2000-isa.h"
89 #include "standard-headers/asm-x86/bootparam.h"
90 #include "hw/virtio/virtio-pmem-pci.h"
91 #include "hw/virtio/virtio-mem-pci.h"
92 #include "hw/mem/memory-device.h"
93 #include "sysemu/replay.h"
94 #include "qapi/qmp/qerror.h"
95 #include "e820_memory_layout.h"
98 #include CONFIG_DEVICES
100 GlobalProperty pc_compat_5_2
[] = {
101 { "ICH9-LPC", "x-smi-cpu-hotunplug", "off" },
103 const size_t pc_compat_5_2_len
= G_N_ELEMENTS(pc_compat_5_2
);
105 GlobalProperty pc_compat_5_1
[] = {
106 { "ICH9-LPC", "x-smi-cpu-hotplug", "off" },
107 { TYPE_X86_CPU
, "kvm-msi-ext-dest-id", "off" },
109 const size_t pc_compat_5_1_len
= G_N_ELEMENTS(pc_compat_5_1
);
111 GlobalProperty pc_compat_5_0
[] = {
113 const size_t pc_compat_5_0_len
= G_N_ELEMENTS(pc_compat_5_0
);
115 GlobalProperty pc_compat_4_2
[] = {
116 { "mch", "smbase-smram", "off" },
118 const size_t pc_compat_4_2_len
= G_N_ELEMENTS(pc_compat_4_2
);
120 GlobalProperty pc_compat_4_1
[] = {};
121 const size_t pc_compat_4_1_len
= G_N_ELEMENTS(pc_compat_4_1
);
123 GlobalProperty pc_compat_4_0
[] = {};
124 const size_t pc_compat_4_0_len
= G_N_ELEMENTS(pc_compat_4_0
);
126 GlobalProperty pc_compat_3_1
[] = {
127 { "intel-iommu", "dma-drain", "off" },
128 { "Opteron_G3" "-" TYPE_X86_CPU
, "rdtscp", "off" },
129 { "Opteron_G4" "-" TYPE_X86_CPU
, "rdtscp", "off" },
130 { "Opteron_G4" "-" TYPE_X86_CPU
, "npt", "off" },
131 { "Opteron_G4" "-" TYPE_X86_CPU
, "nrip-save", "off" },
132 { "Opteron_G5" "-" TYPE_X86_CPU
, "rdtscp", "off" },
133 { "Opteron_G5" "-" TYPE_X86_CPU
, "npt", "off" },
134 { "Opteron_G5" "-" TYPE_X86_CPU
, "nrip-save", "off" },
135 { "EPYC" "-" TYPE_X86_CPU
, "npt", "off" },
136 { "EPYC" "-" TYPE_X86_CPU
, "nrip-save", "off" },
137 { "EPYC-IBPB" "-" TYPE_X86_CPU
, "npt", "off" },
138 { "EPYC-IBPB" "-" TYPE_X86_CPU
, "nrip-save", "off" },
139 { "Skylake-Client" "-" TYPE_X86_CPU
, "mpx", "on" },
140 { "Skylake-Client-IBRS" "-" TYPE_X86_CPU
, "mpx", "on" },
141 { "Skylake-Server" "-" TYPE_X86_CPU
, "mpx", "on" },
142 { "Skylake-Server-IBRS" "-" TYPE_X86_CPU
, "mpx", "on" },
143 { "Cascadelake-Server" "-" TYPE_X86_CPU
, "mpx", "on" },
144 { "Icelake-Client" "-" TYPE_X86_CPU
, "mpx", "on" },
145 { "Icelake-Server" "-" TYPE_X86_CPU
, "mpx", "on" },
146 { "Cascadelake-Server" "-" TYPE_X86_CPU
, "stepping", "5" },
147 { TYPE_X86_CPU
, "x-intel-pt-auto-level", "off" },
149 const size_t pc_compat_3_1_len
= G_N_ELEMENTS(pc_compat_3_1
);
151 GlobalProperty pc_compat_3_0
[] = {
152 { TYPE_X86_CPU
, "x-hv-synic-kvm-only", "on" },
153 { "Skylake-Server" "-" TYPE_X86_CPU
, "pku", "off" },
154 { "Skylake-Server-IBRS" "-" TYPE_X86_CPU
, "pku", "off" },
156 const size_t pc_compat_3_0_len
= G_N_ELEMENTS(pc_compat_3_0
);
158 GlobalProperty pc_compat_2_12
[] = {
159 { TYPE_X86_CPU
, "legacy-cache", "on" },
160 { TYPE_X86_CPU
, "topoext", "off" },
161 { "EPYC-" TYPE_X86_CPU
, "xlevel", "0x8000000a" },
162 { "EPYC-IBPB-" TYPE_X86_CPU
, "xlevel", "0x8000000a" },
164 const size_t pc_compat_2_12_len
= G_N_ELEMENTS(pc_compat_2_12
);
166 GlobalProperty pc_compat_2_11
[] = {
167 { TYPE_X86_CPU
, "x-migrate-smi-count", "off" },
168 { "Skylake-Server" "-" TYPE_X86_CPU
, "clflushopt", "off" },
170 const size_t pc_compat_2_11_len
= G_N_ELEMENTS(pc_compat_2_11
);
172 GlobalProperty pc_compat_2_10
[] = {
173 { TYPE_X86_CPU
, "x-hv-max-vps", "0x40" },
174 { "i440FX-pcihost", "x-pci-hole64-fix", "off" },
175 { "q35-pcihost", "x-pci-hole64-fix", "off" },
177 const size_t pc_compat_2_10_len
= G_N_ELEMENTS(pc_compat_2_10
);
179 GlobalProperty pc_compat_2_9
[] = {
180 { "mch", "extended-tseg-mbytes", "0" },
182 const size_t pc_compat_2_9_len
= G_N_ELEMENTS(pc_compat_2_9
);
184 GlobalProperty pc_compat_2_8
[] = {
185 { TYPE_X86_CPU
, "tcg-cpuid", "off" },
186 { "kvmclock", "x-mach-use-reliable-get-clock", "off" },
187 { "ICH9-LPC", "x-smi-broadcast", "off" },
188 { TYPE_X86_CPU
, "vmware-cpuid-freq", "off" },
189 { "Haswell-" TYPE_X86_CPU
, "stepping", "1" },
191 const size_t pc_compat_2_8_len
= G_N_ELEMENTS(pc_compat_2_8
);
193 GlobalProperty pc_compat_2_7
[] = {
194 { TYPE_X86_CPU
, "l3-cache", "off" },
195 { TYPE_X86_CPU
, "full-cpuid-auto-level", "off" },
196 { "Opteron_G3" "-" TYPE_X86_CPU
, "family", "15" },
197 { "Opteron_G3" "-" TYPE_X86_CPU
, "model", "6" },
198 { "Opteron_G3" "-" TYPE_X86_CPU
, "stepping", "1" },
199 { "isa-pcspk", "migrate", "off" },
201 const size_t pc_compat_2_7_len
= G_N_ELEMENTS(pc_compat_2_7
);
203 GlobalProperty pc_compat_2_6
[] = {
204 { TYPE_X86_CPU
, "cpuid-0xb", "off" },
205 { "vmxnet3", "romfile", "" },
206 { TYPE_X86_CPU
, "fill-mtrr-mask", "off" },
207 { "apic-common", "legacy-instance-id", "on", }
209 const size_t pc_compat_2_6_len
= G_N_ELEMENTS(pc_compat_2_6
);
211 GlobalProperty pc_compat_2_5
[] = {};
212 const size_t pc_compat_2_5_len
= G_N_ELEMENTS(pc_compat_2_5
);
214 GlobalProperty pc_compat_2_4
[] = {
215 PC_CPU_MODEL_IDS("2.4.0")
216 { "Haswell-" TYPE_X86_CPU
, "abm", "off" },
217 { "Haswell-noTSX-" TYPE_X86_CPU
, "abm", "off" },
218 { "Broadwell-" TYPE_X86_CPU
, "abm", "off" },
219 { "Broadwell-noTSX-" TYPE_X86_CPU
, "abm", "off" },
220 { "host" "-" TYPE_X86_CPU
, "host-cache-info", "on" },
221 { TYPE_X86_CPU
, "check", "off" },
222 { "qemu64" "-" TYPE_X86_CPU
, "sse4a", "on" },
223 { "qemu64" "-" TYPE_X86_CPU
, "abm", "on" },
224 { "qemu64" "-" TYPE_X86_CPU
, "popcnt", "on" },
225 { "qemu32" "-" TYPE_X86_CPU
, "popcnt", "on" },
226 { "Opteron_G2" "-" TYPE_X86_CPU
, "rdtscp", "on" },
227 { "Opteron_G3" "-" TYPE_X86_CPU
, "rdtscp", "on" },
228 { "Opteron_G4" "-" TYPE_X86_CPU
, "rdtscp", "on" },
229 { "Opteron_G5" "-" TYPE_X86_CPU
, "rdtscp", "on", }
231 const size_t pc_compat_2_4_len
= G_N_ELEMENTS(pc_compat_2_4
);
233 GlobalProperty pc_compat_2_3
[] = {
234 PC_CPU_MODEL_IDS("2.3.0")
235 { TYPE_X86_CPU
, "arat", "off" },
236 { "qemu64" "-" TYPE_X86_CPU
, "min-level", "4" },
237 { "kvm64" "-" TYPE_X86_CPU
, "min-level", "5" },
238 { "pentium3" "-" TYPE_X86_CPU
, "min-level", "2" },
239 { "n270" "-" TYPE_X86_CPU
, "min-level", "5" },
240 { "Conroe" "-" TYPE_X86_CPU
, "min-level", "4" },
241 { "Penryn" "-" TYPE_X86_CPU
, "min-level", "4" },
242 { "Nehalem" "-" TYPE_X86_CPU
, "min-level", "4" },
243 { "n270" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
244 { "Penryn" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
245 { "Conroe" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
246 { "Nehalem" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
247 { "Westmere" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
248 { "SandyBridge" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
249 { "IvyBridge" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
250 { "Haswell" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
251 { "Haswell-noTSX" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
252 { "Broadwell" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
253 { "Broadwell-noTSX" "-" TYPE_X86_CPU
, "min-xlevel", "0x8000000a" },
254 { TYPE_X86_CPU
, "kvm-no-smi-migration", "on" },
256 const size_t pc_compat_2_3_len
= G_N_ELEMENTS(pc_compat_2_3
);
258 GlobalProperty pc_compat_2_2
[] = {
259 PC_CPU_MODEL_IDS("2.2.0")
260 { "kvm64" "-" TYPE_X86_CPU
, "vme", "off" },
261 { "kvm32" "-" TYPE_X86_CPU
, "vme", "off" },
262 { "Conroe" "-" TYPE_X86_CPU
, "vme", "off" },
263 { "Penryn" "-" TYPE_X86_CPU
, "vme", "off" },
264 { "Nehalem" "-" TYPE_X86_CPU
, "vme", "off" },
265 { "Westmere" "-" TYPE_X86_CPU
, "vme", "off" },
266 { "SandyBridge" "-" TYPE_X86_CPU
, "vme", "off" },
267 { "Haswell" "-" TYPE_X86_CPU
, "vme", "off" },
268 { "Broadwell" "-" TYPE_X86_CPU
, "vme", "off" },
269 { "Opteron_G1" "-" TYPE_X86_CPU
, "vme", "off" },
270 { "Opteron_G2" "-" TYPE_X86_CPU
, "vme", "off" },
271 { "Opteron_G3" "-" TYPE_X86_CPU
, "vme", "off" },
272 { "Opteron_G4" "-" TYPE_X86_CPU
, "vme", "off" },
273 { "Opteron_G5" "-" TYPE_X86_CPU
, "vme", "off" },
274 { "Haswell" "-" TYPE_X86_CPU
, "f16c", "off" },
275 { "Haswell" "-" TYPE_X86_CPU
, "rdrand", "off" },
276 { "Broadwell" "-" TYPE_X86_CPU
, "f16c", "off" },
277 { "Broadwell" "-" TYPE_X86_CPU
, "rdrand", "off" },
279 const size_t pc_compat_2_2_len
= G_N_ELEMENTS(pc_compat_2_2
);
281 GlobalProperty pc_compat_2_1
[] = {
282 PC_CPU_MODEL_IDS("2.1.0")
283 { "coreduo" "-" TYPE_X86_CPU
, "vmx", "on" },
284 { "core2duo" "-" TYPE_X86_CPU
, "vmx", "on" },
286 const size_t pc_compat_2_1_len
= G_N_ELEMENTS(pc_compat_2_1
);
288 GlobalProperty pc_compat_2_0
[] = {
289 PC_CPU_MODEL_IDS("2.0.0")
290 { "virtio-scsi-pci", "any_layout", "off" },
291 { "PIIX4_PM", "memory-hotplug-support", "off" },
292 { "apic", "version", "0x11" },
293 { "nec-usb-xhci", "superspeed-ports-first", "off" },
294 { "nec-usb-xhci", "force-pcie-endcap", "on" },
295 { "pci-serial", "prog_if", "0" },
296 { "pci-serial-2x", "prog_if", "0" },
297 { "pci-serial-4x", "prog_if", "0" },
298 { "virtio-net-pci", "guest_announce", "off" },
299 { "ICH9-LPC", "memory-hotplug-support", "off" },
300 { "xio3130-downstream", COMPAT_PROP_PCP
, "off" },
301 { "ioh3420", COMPAT_PROP_PCP
, "off" },
303 const size_t pc_compat_2_0_len
= G_N_ELEMENTS(pc_compat_2_0
);
305 GlobalProperty pc_compat_1_7
[] = {
306 PC_CPU_MODEL_IDS("1.7.0")
307 { TYPE_USB_DEVICE
, "msos-desc", "no" },
308 { "PIIX4_PM", "acpi-pci-hotplug-with-bridge-support", "off" },
309 { "hpet", HPET_INTCAP
, "4" },
311 const size_t pc_compat_1_7_len
= G_N_ELEMENTS(pc_compat_1_7
);
313 GlobalProperty pc_compat_1_6
[] = {
314 PC_CPU_MODEL_IDS("1.6.0")
315 { "e1000", "mitigation", "off" },
316 { "qemu64-" TYPE_X86_CPU
, "model", "2" },
317 { "qemu32-" TYPE_X86_CPU
, "model", "3" },
318 { "i440FX-pcihost", "short_root_bus", "1" },
319 { "q35-pcihost", "short_root_bus", "1" },
321 const size_t pc_compat_1_6_len
= G_N_ELEMENTS(pc_compat_1_6
);
323 GlobalProperty pc_compat_1_5
[] = {
324 PC_CPU_MODEL_IDS("1.5.0")
325 { "Conroe-" TYPE_X86_CPU
, "model", "2" },
326 { "Conroe-" TYPE_X86_CPU
, "min-level", "2" },
327 { "Penryn-" TYPE_X86_CPU
, "model", "2" },
328 { "Penryn-" TYPE_X86_CPU
, "min-level", "2" },
329 { "Nehalem-" TYPE_X86_CPU
, "model", "2" },
330 { "Nehalem-" TYPE_X86_CPU
, "min-level", "2" },
331 { "virtio-net-pci", "any_layout", "off" },
332 { TYPE_X86_CPU
, "pmu", "on" },
333 { "i440FX-pcihost", "short_root_bus", "0" },
334 { "q35-pcihost", "short_root_bus", "0" },
336 const size_t pc_compat_1_5_len
= G_N_ELEMENTS(pc_compat_1_5
);
338 GlobalProperty pc_compat_1_4
[] = {
339 PC_CPU_MODEL_IDS("1.4.0")
340 { "scsi-hd", "discard_granularity", "0" },
341 { "scsi-cd", "discard_granularity", "0" },
342 { "scsi-disk", "discard_granularity", "0" },
343 { "ide-hd", "discard_granularity", "0" },
344 { "ide-cd", "discard_granularity", "0" },
345 { "ide-drive", "discard_granularity", "0" },
346 { "virtio-blk-pci", "discard_granularity", "0" },
347 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string: */
348 { "virtio-serial-pci", "vectors", "0xFFFFFFFF" },
349 { "virtio-net-pci", "ctrl_guest_offloads", "off" },
350 { "e1000", "romfile", "pxe-e1000.rom" },
351 { "ne2k_pci", "romfile", "pxe-ne2k_pci.rom" },
352 { "pcnet", "romfile", "pxe-pcnet.rom" },
353 { "rtl8139", "romfile", "pxe-rtl8139.rom" },
354 { "virtio-net-pci", "romfile", "pxe-virtio.rom" },
355 { "486-" TYPE_X86_CPU
, "model", "0" },
356 { "n270" "-" TYPE_X86_CPU
, "movbe", "off" },
357 { "Westmere" "-" TYPE_X86_CPU
, "pclmulqdq", "off" },
359 const size_t pc_compat_1_4_len
= G_N_ELEMENTS(pc_compat_1_4
);
361 GSIState
*pc_gsi_create(qemu_irq
**irqs
, bool pci_enabled
)
365 s
= g_new0(GSIState
, 1);
366 if (kvm_ioapic_in_kernel()) {
367 kvm_pc_setup_irq_routing(pci_enabled
);
369 *irqs
= qemu_allocate_irqs(gsi_handler
, s
, GSI_NUM_PINS
);
374 static void ioport80_write(void *opaque
, hwaddr addr
, uint64_t data
,
379 static uint64_t ioport80_read(void *opaque
, hwaddr addr
, unsigned size
)
381 return 0xffffffffffffffffULL
;
384 /* MSDOS compatibility mode FPU exception support */
385 static void ioportF0_write(void *opaque
, hwaddr addr
, uint64_t data
,
393 static uint64_t ioportF0_read(void *opaque
, hwaddr addr
, unsigned size
)
395 return 0xffffffffffffffffULL
;
398 /* PC cmos mappings */
400 #define REG_EQUIPMENT_BYTE 0x14
402 static void cmos_init_hd(ISADevice
*s
, int type_ofs
, int info_ofs
,
403 int16_t cylinders
, int8_t heads
, int8_t sectors
)
405 rtc_set_memory(s
, type_ofs
, 47);
406 rtc_set_memory(s
, info_ofs
, cylinders
);
407 rtc_set_memory(s
, info_ofs
+ 1, cylinders
>> 8);
408 rtc_set_memory(s
, info_ofs
+ 2, heads
);
409 rtc_set_memory(s
, info_ofs
+ 3, 0xff);
410 rtc_set_memory(s
, info_ofs
+ 4, 0xff);
411 rtc_set_memory(s
, info_ofs
+ 5, 0xc0 | ((heads
> 8) << 3));
412 rtc_set_memory(s
, info_ofs
+ 6, cylinders
);
413 rtc_set_memory(s
, info_ofs
+ 7, cylinders
>> 8);
414 rtc_set_memory(s
, info_ofs
+ 8, sectors
);
417 /* convert boot_device letter to something recognizable by the bios */
418 static int boot_device2nibble(char boot_device
)
420 switch(boot_device
) {
423 return 0x01; /* floppy boot */
425 return 0x02; /* hard drive boot */
427 return 0x03; /* CD-ROM boot */
429 return 0x04; /* Network boot */
434 static void set_boot_dev(ISADevice
*s
, const char *boot_device
, Error
**errp
)
436 #define PC_MAX_BOOT_DEVICES 3
437 int nbds
, bds
[3] = { 0, };
440 nbds
= strlen(boot_device
);
441 if (nbds
> PC_MAX_BOOT_DEVICES
) {
442 error_setg(errp
, "Too many boot devices for PC");
445 for (i
= 0; i
< nbds
; i
++) {
446 bds
[i
] = boot_device2nibble(boot_device
[i
]);
448 error_setg(errp
, "Invalid boot device for PC: '%c'",
453 rtc_set_memory(s
, 0x3d, (bds
[1] << 4) | bds
[0]);
454 rtc_set_memory(s
, 0x38, (bds
[2] << 4) | (fd_bootchk
? 0x0 : 0x1));
457 static void pc_boot_set(void *opaque
, const char *boot_device
, Error
**errp
)
459 set_boot_dev(opaque
, boot_device
, errp
);
462 static void pc_cmos_init_floppy(ISADevice
*rtc_state
, ISADevice
*floppy
)
465 FloppyDriveType fd_type
[2] = { FLOPPY_DRIVE_TYPE_NONE
,
466 FLOPPY_DRIVE_TYPE_NONE
};
470 for (i
= 0; i
< 2; i
++) {
471 fd_type
[i
] = isa_fdc_get_drive_type(floppy
, i
);
474 val
= (cmos_get_fd_drive_type(fd_type
[0]) << 4) |
475 cmos_get_fd_drive_type(fd_type
[1]);
476 rtc_set_memory(rtc_state
, 0x10, val
);
478 val
= rtc_get_memory(rtc_state
, REG_EQUIPMENT_BYTE
);
480 if (fd_type
[0] != FLOPPY_DRIVE_TYPE_NONE
) {
483 if (fd_type
[1] != FLOPPY_DRIVE_TYPE_NONE
) {
490 val
|= 0x01; /* 1 drive, ready for boot */
493 val
|= 0x41; /* 2 drives, ready for boot */
496 rtc_set_memory(rtc_state
, REG_EQUIPMENT_BYTE
, val
);
499 typedef struct pc_cmos_init_late_arg
{
500 ISADevice
*rtc_state
;
502 } pc_cmos_init_late_arg
;
504 typedef struct check_fdc_state
{
509 static int check_fdc(Object
*obj
, void *opaque
)
511 CheckFdcState
*state
= opaque
;
514 Error
*local_err
= NULL
;
516 fdc
= object_dynamic_cast(obj
, TYPE_ISA_FDC
);
521 iobase
= object_property_get_uint(obj
, "iobase", &local_err
);
522 if (local_err
|| iobase
!= 0x3f0) {
523 error_free(local_err
);
528 state
->multiple
= true;
530 state
->floppy
= ISA_DEVICE(obj
);
535 static const char * const fdc_container_path
[] = {
536 "/unattached", "/peripheral", "/peripheral-anon"
540 * Locate the FDC at IO address 0x3f0, in order to configure the CMOS registers
543 ISADevice
*pc_find_fdc0(void)
547 CheckFdcState state
= { 0 };
549 for (i
= 0; i
< ARRAY_SIZE(fdc_container_path
); i
++) {
550 container
= container_get(qdev_get_machine(), fdc_container_path
[i
]);
551 object_child_foreach(container
, check_fdc
, &state
);
554 if (state
.multiple
) {
555 warn_report("multiple floppy disk controllers with "
556 "iobase=0x3f0 have been found");
557 error_printf("the one being picked for CMOS setup might not reflect "
564 static void pc_cmos_init_late(void *opaque
)
566 pc_cmos_init_late_arg
*arg
= opaque
;
567 ISADevice
*s
= arg
->rtc_state
;
569 int8_t heads
, sectors
;
574 if (arg
->idebus
[0] && ide_get_geometry(arg
->idebus
[0], 0,
575 &cylinders
, &heads
, §ors
) >= 0) {
576 cmos_init_hd(s
, 0x19, 0x1b, cylinders
, heads
, sectors
);
579 if (arg
->idebus
[0] && ide_get_geometry(arg
->idebus
[0], 1,
580 &cylinders
, &heads
, §ors
) >= 0) {
581 cmos_init_hd(s
, 0x1a, 0x24, cylinders
, heads
, sectors
);
584 rtc_set_memory(s
, 0x12, val
);
587 for (i
= 0; i
< 4; i
++) {
588 /* NOTE: ide_get_geometry() returns the physical
589 geometry. It is always such that: 1 <= sects <= 63, 1
590 <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
591 geometry can be different if a translation is done. */
592 if (arg
->idebus
[i
/ 2] &&
593 ide_get_geometry(arg
->idebus
[i
/ 2], i
% 2,
594 &cylinders
, &heads
, §ors
) >= 0) {
595 trans
= ide_get_bios_chs_trans(arg
->idebus
[i
/ 2], i
% 2) - 1;
596 assert((trans
& ~3) == 0);
597 val
|= trans
<< (i
* 2);
600 rtc_set_memory(s
, 0x39, val
);
602 pc_cmos_init_floppy(s
, pc_find_fdc0());
604 qemu_unregister_reset(pc_cmos_init_late
, opaque
);
607 void pc_cmos_init(PCMachineState
*pcms
,
608 BusState
*idebus0
, BusState
*idebus1
,
612 static pc_cmos_init_late_arg arg
;
613 X86MachineState
*x86ms
= X86_MACHINE(pcms
);
615 /* various important CMOS locations needed by PC/Bochs bios */
618 /* base memory (first MiB) */
619 val
= MIN(x86ms
->below_4g_mem_size
/ KiB
, 640);
620 rtc_set_memory(s
, 0x15, val
);
621 rtc_set_memory(s
, 0x16, val
>> 8);
622 /* extended memory (next 64MiB) */
623 if (x86ms
->below_4g_mem_size
> 1 * MiB
) {
624 val
= (x86ms
->below_4g_mem_size
- 1 * MiB
) / KiB
;
630 rtc_set_memory(s
, 0x17, val
);
631 rtc_set_memory(s
, 0x18, val
>> 8);
632 rtc_set_memory(s
, 0x30, val
);
633 rtc_set_memory(s
, 0x31, val
>> 8);
634 /* memory between 16MiB and 4GiB */
635 if (x86ms
->below_4g_mem_size
> 16 * MiB
) {
636 val
= (x86ms
->below_4g_mem_size
- 16 * MiB
) / (64 * KiB
);
642 rtc_set_memory(s
, 0x34, val
);
643 rtc_set_memory(s
, 0x35, val
>> 8);
644 /* memory above 4GiB */
645 val
= x86ms
->above_4g_mem_size
/ 65536;
646 rtc_set_memory(s
, 0x5b, val
);
647 rtc_set_memory(s
, 0x5c, val
>> 8);
648 rtc_set_memory(s
, 0x5d, val
>> 16);
650 object_property_add_link(OBJECT(pcms
), "rtc_state",
652 (Object
**)&x86ms
->rtc
,
653 object_property_allow_set_link
,
654 OBJ_PROP_LINK_STRONG
);
655 object_property_set_link(OBJECT(pcms
), "rtc_state", OBJECT(s
),
658 set_boot_dev(s
, MACHINE(pcms
)->boot_order
, &error_fatal
);
661 val
|= 0x02; /* FPU is there */
662 val
|= 0x04; /* PS/2 mouse installed */
663 rtc_set_memory(s
, REG_EQUIPMENT_BYTE
, val
);
665 /* hard drives and FDC */
667 arg
.idebus
[0] = idebus0
;
668 arg
.idebus
[1] = idebus1
;
669 qemu_register_reset(pc_cmos_init_late
, &arg
);
672 static void handle_a20_line_change(void *opaque
, int irq
, int level
)
674 X86CPU
*cpu
= opaque
;
676 /* XXX: send to all CPUs ? */
677 /* XXX: add logic to handle multiple A20 line sources */
678 x86_cpu_set_a20(cpu
, level
);
681 #define NE2000_NB_MAX 6
683 static const int ne2000_io
[NE2000_NB_MAX
] = { 0x300, 0x320, 0x340, 0x360,
685 static const int ne2000_irq
[NE2000_NB_MAX
] = { 9, 10, 11, 3, 4, 5 };
687 void pc_init_ne2k_isa(ISABus
*bus
, NICInfo
*nd
)
689 static int nb_ne2k
= 0;
691 if (nb_ne2k
== NE2000_NB_MAX
)
693 isa_ne2000_init(bus
, ne2000_io
[nb_ne2k
],
694 ne2000_irq
[nb_ne2k
], nd
);
698 void pc_acpi_smi_interrupt(void *opaque
, int irq
, int level
)
700 X86CPU
*cpu
= opaque
;
703 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_SMI
);
708 * This function is very similar to smp_parse()
709 * in hw/core/machine.c but includes CPU die support.
711 void pc_smp_parse(MachineState
*ms
, QemuOpts
*opts
)
713 X86MachineState
*x86ms
= X86_MACHINE(ms
);
716 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
717 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
718 unsigned dies
= qemu_opt_get_number(opts
, "dies", 1);
719 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
720 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
722 /* compute missing values, prefer sockets over cores over threads */
723 if (cpus
== 0 || sockets
== 0) {
724 cores
= cores
> 0 ? cores
: 1;
725 threads
= threads
> 0 ? threads
: 1;
727 sockets
= sockets
> 0 ? sockets
: 1;
728 cpus
= cores
* threads
* dies
* sockets
;
731 qemu_opt_get_number(opts
, "maxcpus", cpus
);
732 sockets
= ms
->smp
.max_cpus
/ (cores
* threads
* dies
);
734 } else if (cores
== 0) {
735 threads
= threads
> 0 ? threads
: 1;
736 cores
= cpus
/ (sockets
* dies
* threads
);
737 cores
= cores
> 0 ? cores
: 1;
738 } else if (threads
== 0) {
739 threads
= cpus
/ (cores
* dies
* sockets
);
740 threads
= threads
> 0 ? threads
: 1;
741 } else if (sockets
* dies
* cores
* threads
< cpus
) {
742 error_report("cpu topology: "
743 "sockets (%u) * dies (%u) * cores (%u) * threads (%u) < "
745 sockets
, dies
, cores
, threads
, cpus
);
750 qemu_opt_get_number(opts
, "maxcpus", cpus
);
752 if (ms
->smp
.max_cpus
< cpus
) {
753 error_report("maxcpus must be equal to or greater than smp");
757 if (sockets
* dies
* cores
* threads
!= ms
->smp
.max_cpus
) {
758 error_report("Invalid CPU topology deprecated: "
759 "sockets (%u) * dies (%u) * cores (%u) * threads (%u) "
761 sockets
, dies
, cores
, threads
,
767 ms
->smp
.cores
= cores
;
768 ms
->smp
.threads
= threads
;
769 ms
->smp
.sockets
= sockets
;
770 x86ms
->smp_dies
= dies
;
773 if (ms
->smp
.cpus
> 1) {
774 Error
*blocker
= NULL
;
775 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
776 replay_add_blocker(blocker
);
781 void pc_machine_done(Notifier
*notifier
, void *data
)
783 PCMachineState
*pcms
= container_of(notifier
,
784 PCMachineState
, machine_done
);
785 X86MachineState
*x86ms
= X86_MACHINE(pcms
);
787 /* set the number of CPUs */
788 x86_rtc_set_cpus_count(x86ms
->rtc
, x86ms
->boot_cpus
);
790 fw_cfg_add_extra_pci_roots(pcms
->bus
, x86ms
->fw_cfg
);
794 fw_cfg_build_smbios(MACHINE(pcms
), x86ms
->fw_cfg
);
795 fw_cfg_build_feature_control(MACHINE(pcms
), x86ms
->fw_cfg
);
796 /* update FW_CFG_NB_CPUS to account for -device added CPUs */
797 fw_cfg_modify_i16(x86ms
->fw_cfg
, FW_CFG_NB_CPUS
, x86ms
->boot_cpus
);
801 if (x86ms
->apic_id_limit
> 255 && !xen_enabled() &&
802 !kvm_irqchip_in_kernel()) {
803 error_report("current -smp configuration requires kernel "
809 void pc_guest_info_init(PCMachineState
*pcms
)
812 MachineState
*ms
= MACHINE(pcms
);
813 X86MachineState
*x86ms
= X86_MACHINE(pcms
);
815 x86ms
->apic_xrupt_override
= true;
816 pcms
->numa_nodes
= ms
->numa_state
->num_nodes
;
817 pcms
->node_mem
= g_malloc0(pcms
->numa_nodes
*
818 sizeof *pcms
->node_mem
);
819 for (i
= 0; i
< ms
->numa_state
->num_nodes
; i
++) {
820 pcms
->node_mem
[i
] = ms
->numa_state
->nodes
[i
].node_mem
;
823 pcms
->machine_done
.notify
= pc_machine_done
;
824 qemu_add_machine_init_done_notifier(&pcms
->machine_done
);
827 /* setup pci memory address space mapping into system address space */
828 void pc_pci_as_mapping_init(Object
*owner
, MemoryRegion
*system_memory
,
829 MemoryRegion
*pci_address_space
)
831 /* Set to lower priority than RAM */
832 memory_region_add_subregion_overlap(system_memory
, 0x0,
833 pci_address_space
, -1);
836 void xen_load_linux(PCMachineState
*pcms
)
840 PCMachineClass
*pcmc
= PC_MACHINE_GET_CLASS(pcms
);
841 X86MachineState
*x86ms
= X86_MACHINE(pcms
);
843 assert(MACHINE(pcms
)->kernel_filename
!= NULL
);
845 fw_cfg
= fw_cfg_init_io(FW_CFG_IO_BASE
);
846 fw_cfg_add_i16(fw_cfg
, FW_CFG_NB_CPUS
, x86ms
->boot_cpus
);
849 x86_load_linux(x86ms
, fw_cfg
, pcmc
->acpi_data_size
,
850 pcmc
->pvh_enabled
, pcmc
->linuxboot_dma_enabled
);
851 for (i
= 0; i
< nb_option_roms
; i
++) {
852 assert(!strcmp(option_rom
[i
].name
, "linuxboot.bin") ||
853 !strcmp(option_rom
[i
].name
, "linuxboot_dma.bin") ||
854 !strcmp(option_rom
[i
].name
, "pvh.bin") ||
855 !strcmp(option_rom
[i
].name
, "multiboot.bin"));
856 rom_add_option(option_rom
[i
].name
, option_rom
[i
].bootindex
);
858 x86ms
->fw_cfg
= fw_cfg
;
861 void pc_memory_init(PCMachineState
*pcms
,
862 MemoryRegion
*system_memory
,
863 MemoryRegion
*rom_memory
,
864 MemoryRegion
**ram_memory
)
867 MemoryRegion
*option_rom_mr
;
868 MemoryRegion
*ram_below_4g
, *ram_above_4g
;
870 MachineState
*machine
= MACHINE(pcms
);
871 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
872 PCMachineClass
*pcmc
= PC_MACHINE_GET_CLASS(pcms
);
873 X86MachineState
*x86ms
= X86_MACHINE(pcms
);
875 assert(machine
->ram_size
== x86ms
->below_4g_mem_size
+
876 x86ms
->above_4g_mem_size
);
878 linux_boot
= (machine
->kernel_filename
!= NULL
);
881 * Split single memory region and use aliases to address portions of it,
882 * done for backwards compatibility with older qemus.
884 *ram_memory
= machine
->ram
;
885 ram_below_4g
= g_malloc(sizeof(*ram_below_4g
));
886 memory_region_init_alias(ram_below_4g
, NULL
, "ram-below-4g", machine
->ram
,
887 0, x86ms
->below_4g_mem_size
);
888 memory_region_add_subregion(system_memory
, 0, ram_below_4g
);
889 e820_add_entry(0, x86ms
->below_4g_mem_size
, E820_RAM
);
890 if (x86ms
->above_4g_mem_size
> 0) {
891 ram_above_4g
= g_malloc(sizeof(*ram_above_4g
));
892 memory_region_init_alias(ram_above_4g
, NULL
, "ram-above-4g",
894 x86ms
->below_4g_mem_size
,
895 x86ms
->above_4g_mem_size
);
896 memory_region_add_subregion(system_memory
, 0x100000000ULL
,
898 e820_add_entry(0x100000000ULL
, x86ms
->above_4g_mem_size
, E820_RAM
);
901 if (!pcmc
->has_reserved_memory
&&
902 (machine
->ram_slots
||
903 (machine
->maxram_size
> machine
->ram_size
))) {
905 error_report("\"-memory 'slots|maxmem'\" is not supported by: %s",
910 /* always allocate the device memory information */
911 machine
->device_memory
= g_malloc0(sizeof(*machine
->device_memory
));
913 /* initialize device memory address space */
914 if (pcmc
->has_reserved_memory
&&
915 (machine
->ram_size
< machine
->maxram_size
)) {
916 ram_addr_t device_mem_size
= machine
->maxram_size
- machine
->ram_size
;
918 if (machine
->ram_slots
> ACPI_MAX_RAM_SLOTS
) {
919 error_report("unsupported amount of memory slots: %"PRIu64
,
924 if (QEMU_ALIGN_UP(machine
->maxram_size
,
925 TARGET_PAGE_SIZE
) != machine
->maxram_size
) {
926 error_report("maximum memory size must by aligned to multiple of "
927 "%d bytes", TARGET_PAGE_SIZE
);
931 machine
->device_memory
->base
=
932 ROUND_UP(0x100000000ULL
+ x86ms
->above_4g_mem_size
, 1 * GiB
);
934 if (pcmc
->enforce_aligned_dimm
) {
935 /* size device region assuming 1G page max alignment per slot */
936 device_mem_size
+= (1 * GiB
) * machine
->ram_slots
;
939 if ((machine
->device_memory
->base
+ device_mem_size
) <
941 error_report("unsupported amount of maximum memory: " RAM_ADDR_FMT
,
942 machine
->maxram_size
);
946 memory_region_init(&machine
->device_memory
->mr
, OBJECT(pcms
),
947 "device-memory", device_mem_size
);
948 memory_region_add_subregion(system_memory
, machine
->device_memory
->base
,
949 &machine
->device_memory
->mr
);
952 /* Initialize PC system firmware */
953 pc_system_firmware_init(pcms
, rom_memory
);
955 option_rom_mr
= g_malloc(sizeof(*option_rom_mr
));
956 memory_region_init_ram(option_rom_mr
, NULL
, "pc.rom", PC_ROM_SIZE
,
958 if (pcmc
->pci_enabled
) {
959 memory_region_set_readonly(option_rom_mr
, true);
961 memory_region_add_subregion_overlap(rom_memory
,
966 fw_cfg
= fw_cfg_arch_create(machine
,
967 x86ms
->boot_cpus
, x86ms
->apic_id_limit
);
971 if (pcmc
->has_reserved_memory
&& machine
->device_memory
->base
) {
972 uint64_t *val
= g_malloc(sizeof(*val
));
973 PCMachineClass
*pcmc
= PC_MACHINE_GET_CLASS(pcms
);
974 uint64_t res_mem_end
= machine
->device_memory
->base
;
976 if (!pcmc
->broken_reserved_end
) {
977 res_mem_end
+= memory_region_size(&machine
->device_memory
->mr
);
979 *val
= cpu_to_le64(ROUND_UP(res_mem_end
, 1 * GiB
));
980 fw_cfg_add_file(fw_cfg
, "etc/reserved-memory-end", val
, sizeof(*val
));
984 x86_load_linux(x86ms
, fw_cfg
, pcmc
->acpi_data_size
,
985 pcmc
->pvh_enabled
, pcmc
->linuxboot_dma_enabled
);
988 for (i
= 0; i
< nb_option_roms
; i
++) {
989 rom_add_option(option_rom
[i
].name
, option_rom
[i
].bootindex
);
991 x86ms
->fw_cfg
= fw_cfg
;
993 /* Init default IOAPIC address space */
994 x86ms
->ioapic_as
= &address_space_memory
;
996 /* Init ACPI memory hotplug IO base address */
997 pcms
->memhp_io_base
= ACPI_MEMORY_HOTPLUG_BASE
;
1001 * The 64bit pci hole starts after "above 4G RAM" and
1002 * potentially the space reserved for memory hotplug.
1004 uint64_t pc_pci_hole64_start(void)
1006 PCMachineState
*pcms
= PC_MACHINE(qdev_get_machine());
1007 PCMachineClass
*pcmc
= PC_MACHINE_GET_CLASS(pcms
);
1008 MachineState
*ms
= MACHINE(pcms
);
1009 X86MachineState
*x86ms
= X86_MACHINE(pcms
);
1010 uint64_t hole64_start
= 0;
1012 if (pcmc
->has_reserved_memory
&& ms
->device_memory
->base
) {
1013 hole64_start
= ms
->device_memory
->base
;
1014 if (!pcmc
->broken_reserved_end
) {
1015 hole64_start
+= memory_region_size(&ms
->device_memory
->mr
);
1018 hole64_start
= 0x100000000ULL
+ x86ms
->above_4g_mem_size
;
1021 return ROUND_UP(hole64_start
, 1 * GiB
);
1024 DeviceState
*pc_vga_init(ISABus
*isa_bus
, PCIBus
*pci_bus
)
1026 DeviceState
*dev
= NULL
;
1028 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_VGA
);
1030 PCIDevice
*pcidev
= pci_vga_init(pci_bus
);
1031 dev
= pcidev
? &pcidev
->qdev
: NULL
;
1032 } else if (isa_bus
) {
1033 ISADevice
*isadev
= isa_vga_init(isa_bus
);
1034 dev
= isadev
? DEVICE(isadev
) : NULL
;
1036 rom_reset_order_override();
1040 static const MemoryRegionOps ioport80_io_ops
= {
1041 .write
= ioport80_write
,
1042 .read
= ioport80_read
,
1043 .endianness
= DEVICE_NATIVE_ENDIAN
,
1045 .min_access_size
= 1,
1046 .max_access_size
= 1,
1050 static const MemoryRegionOps ioportF0_io_ops
= {
1051 .write
= ioportF0_write
,
1052 .read
= ioportF0_read
,
1053 .endianness
= DEVICE_NATIVE_ENDIAN
,
1055 .min_access_size
= 1,
1056 .max_access_size
= 1,
1060 static void pc_superio_init(ISABus
*isa_bus
, bool create_fdctrl
, bool no_vmport
)
1063 DriveInfo
*fd
[MAX_FD
];
1065 ISADevice
*fdc
, *i8042
, *port92
, *vmmouse
;
1067 serial_hds_isa_init(isa_bus
, 0, MAX_ISA_SERIAL_PORTS
);
1068 parallel_hds_isa_init(isa_bus
, MAX_PARALLEL_PORTS
);
1070 for (i
= 0; i
< MAX_FD
; i
++) {
1071 fd
[i
] = drive_get(IF_FLOPPY
, 0, i
);
1072 create_fdctrl
|= !!fd
[i
];
1074 if (create_fdctrl
) {
1075 fdc
= isa_new(TYPE_ISA_FDC
);
1077 isa_realize_and_unref(fdc
, isa_bus
, &error_fatal
);
1078 isa_fdc_init_drives(fdc
, fd
);
1082 i8042
= isa_create_simple(isa_bus
, "i8042");
1084 isa_create_simple(isa_bus
, TYPE_VMPORT
);
1085 vmmouse
= isa_try_new("vmmouse");
1090 object_property_set_link(OBJECT(vmmouse
), "i8042", OBJECT(i8042
),
1092 isa_realize_and_unref(vmmouse
, isa_bus
, &error_fatal
);
1094 port92
= isa_create_simple(isa_bus
, TYPE_PORT92
);
1096 a20_line
= qemu_allocate_irqs(handle_a20_line_change
, first_cpu
, 2);
1097 i8042_setup_a20_line(i8042
, a20_line
[0]);
1098 qdev_connect_gpio_out_named(DEVICE(port92
),
1099 PORT92_A20_LINE
, 0, a20_line
[1]);
1103 void pc_basic_device_init(struct PCMachineState
*pcms
,
1104 ISABus
*isa_bus
, qemu_irq
*gsi
,
1105 ISADevice
**rtc_state
,
1110 DeviceState
*hpet
= NULL
;
1111 int pit_isa_irq
= 0;
1112 qemu_irq pit_alt_irq
= NULL
;
1113 qemu_irq rtc_irq
= NULL
;
1114 ISADevice
*pit
= NULL
;
1115 MemoryRegion
*ioport80_io
= g_new(MemoryRegion
, 1);
1116 MemoryRegion
*ioportF0_io
= g_new(MemoryRegion
, 1);
1118 memory_region_init_io(ioport80_io
, NULL
, &ioport80_io_ops
, NULL
, "ioport80", 1);
1119 memory_region_add_subregion(isa_bus
->address_space_io
, 0x80, ioport80_io
);
1121 memory_region_init_io(ioportF0_io
, NULL
, &ioportF0_io_ops
, NULL
, "ioportF0", 1);
1122 memory_region_add_subregion(isa_bus
->address_space_io
, 0xf0, ioportF0_io
);
1125 * Check if an HPET shall be created.
1127 * Without KVM_CAP_PIT_STATE2, we cannot switch off the in-kernel PIT
1128 * when the HPET wants to take over. Thus we have to disable the latter.
1130 if (pcms
->hpet_enabled
&& (!kvm_irqchip_in_kernel() ||
1131 kvm_has_pit_state2())) {
1132 hpet
= qdev_try_new(TYPE_HPET
);
1134 error_report("couldn't create HPET device");
1138 * For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 and
1139 * earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, IRQ8 and
1142 uint8_t compat
= object_property_get_uint(OBJECT(hpet
),
1145 qdev_prop_set_uint32(hpet
, HPET_INTCAP
, hpet_irqs
);
1147 sysbus_realize_and_unref(SYS_BUS_DEVICE(hpet
), &error_fatal
);
1148 sysbus_mmio_map(SYS_BUS_DEVICE(hpet
), 0, HPET_BASE
);
1150 for (i
= 0; i
< GSI_NUM_PINS
; i
++) {
1151 sysbus_connect_irq(SYS_BUS_DEVICE(hpet
), i
, gsi
[i
]);
1154 pit_alt_irq
= qdev_get_gpio_in(hpet
, HPET_LEGACY_PIT_INT
);
1155 rtc_irq
= qdev_get_gpio_in(hpet
, HPET_LEGACY_RTC_INT
);
1157 *rtc_state
= mc146818_rtc_init(isa_bus
, 2000, rtc_irq
);
1159 qemu_register_boot_set(pc_boot_set
, *rtc_state
);
1161 if (!xen_enabled() && pcms
->pit_enabled
) {
1162 if (kvm_pit_in_kernel()) {
1163 pit
= kvm_pit_init(isa_bus
, 0x40);
1165 pit
= i8254_pit_init(isa_bus
, 0x40, pit_isa_irq
, pit_alt_irq
);
1168 /* connect PIT to output control line of the HPET */
1169 qdev_connect_gpio_out(hpet
, 0, qdev_get_gpio_in(DEVICE(pit
), 0));
1171 pcspk_init(pcms
->pcspk
, isa_bus
, pit
);
1174 i8257_dma_init(isa_bus
, 0);
1177 pc_superio_init(isa_bus
, create_fdctrl
, pcms
->vmport
!= ON_OFF_AUTO_ON
);
1180 void pc_nic_init(PCMachineClass
*pcmc
, ISABus
*isa_bus
, PCIBus
*pci_bus
)
1184 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_NIC
);
1185 for (i
= 0; i
< nb_nics
; i
++) {
1186 NICInfo
*nd
= &nd_table
[i
];
1187 const char *model
= nd
->model
? nd
->model
: pcmc
->default_nic_model
;
1189 if (g_str_equal(model
, "ne2k_isa")) {
1190 pc_init_ne2k_isa(isa_bus
, nd
);
1192 pci_nic_init_nofail(nd
, pci_bus
, model
, NULL
);
1195 rom_reset_order_override();
1198 void pc_i8259_create(ISABus
*isa_bus
, qemu_irq
*i8259_irqs
)
1202 if (kvm_pic_in_kernel()) {
1203 i8259
= kvm_i8259_init(isa_bus
);
1204 } else if (xen_enabled()) {
1205 i8259
= xen_interrupt_controller_init();
1207 i8259
= i8259_init(isa_bus
, x86_allocate_cpu_irq());
1210 for (size_t i
= 0; i
< ISA_NUM_IRQS
; i
++) {
1211 i8259_irqs
[i
] = i8259
[i
];
1217 static void pc_memory_pre_plug(HotplugHandler
*hotplug_dev
, DeviceState
*dev
,
1220 const PCMachineState
*pcms
= PC_MACHINE(hotplug_dev
);
1221 const X86MachineState
*x86ms
= X86_MACHINE(hotplug_dev
);
1222 const PCMachineClass
*pcmc
= PC_MACHINE_GET_CLASS(pcms
);
1223 const MachineState
*ms
= MACHINE(hotplug_dev
);
1224 const bool is_nvdimm
= object_dynamic_cast(OBJECT(dev
), TYPE_NVDIMM
);
1225 const uint64_t legacy_align
= TARGET_PAGE_SIZE
;
1226 Error
*local_err
= NULL
;
1229 * When -no-acpi is used with Q35 machine type, no ACPI is built,
1230 * but pcms->acpi_dev is still created. Check !acpi_enabled in
1231 * addition to cover this case.
1233 if (!x86ms
->acpi_dev
|| !x86_machine_is_acpi_enabled(x86ms
)) {
1235 "memory hotplug is not enabled: missing acpi device or acpi disabled");
1239 if (is_nvdimm
&& !ms
->nvdimms_state
->is_enabled
) {
1240 error_setg(errp
, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
1244 hotplug_handler_pre_plug(x86ms
->acpi_dev
, dev
, &local_err
);
1246 error_propagate(errp
, local_err
);
1250 pc_dimm_pre_plug(PC_DIMM(dev
), MACHINE(hotplug_dev
),
1251 pcmc
->enforce_aligned_dimm
? NULL
: &legacy_align
, errp
);
1254 static void pc_memory_plug(HotplugHandler
*hotplug_dev
,
1255 DeviceState
*dev
, Error
**errp
)
1257 PCMachineState
*pcms
= PC_MACHINE(hotplug_dev
);
1258 X86MachineState
*x86ms
= X86_MACHINE(hotplug_dev
);
1259 MachineState
*ms
= MACHINE(hotplug_dev
);
1260 bool is_nvdimm
= object_dynamic_cast(OBJECT(dev
), TYPE_NVDIMM
);
1262 pc_dimm_plug(PC_DIMM(dev
), MACHINE(pcms
));
1265 nvdimm_plug(ms
->nvdimms_state
);
1268 hotplug_handler_plug(x86ms
->acpi_dev
, dev
, &error_abort
);
1271 static void pc_memory_unplug_request(HotplugHandler
*hotplug_dev
,
1272 DeviceState
*dev
, Error
**errp
)
1274 X86MachineState
*x86ms
= X86_MACHINE(hotplug_dev
);
1277 * When -no-acpi is used with Q35 machine type, no ACPI is built,
1278 * but pcms->acpi_dev is still created. Check !acpi_enabled in
1279 * addition to cover this case.
1281 if (!x86ms
->acpi_dev
|| !x86_machine_is_acpi_enabled(x86ms
)) {
1283 "memory hotplug is not enabled: missing acpi device or acpi disabled");
1287 if (object_dynamic_cast(OBJECT(dev
), TYPE_NVDIMM
)) {
1288 error_setg(errp
, "nvdimm device hot unplug is not supported yet.");
1292 hotplug_handler_unplug_request(x86ms
->acpi_dev
, dev
,
1296 static void pc_memory_unplug(HotplugHandler
*hotplug_dev
,
1297 DeviceState
*dev
, Error
**errp
)
1299 PCMachineState
*pcms
= PC_MACHINE(hotplug_dev
);
1300 X86MachineState
*x86ms
= X86_MACHINE(hotplug_dev
);
1301 Error
*local_err
= NULL
;
1303 hotplug_handler_unplug(x86ms
->acpi_dev
, dev
, &local_err
);
1308 pc_dimm_unplug(PC_DIMM(dev
), MACHINE(pcms
));
1309 qdev_unrealize(dev
);
1311 error_propagate(errp
, local_err
);
1314 static void pc_virtio_md_pci_pre_plug(HotplugHandler
*hotplug_dev
,
1315 DeviceState
*dev
, Error
**errp
)
1317 HotplugHandler
*hotplug_dev2
= qdev_get_bus_hotplug_handler(dev
);
1318 Error
*local_err
= NULL
;
1320 if (!hotplug_dev2
&& dev
->hotplugged
) {
1322 * Without a bus hotplug handler, we cannot control the plug/unplug
1323 * order. We should never reach this point when hotplugging on x86,
1324 * however, better add a safety net.
1326 error_setg(errp
, "hotplug of virtio based memory devices not supported"
1331 * First, see if we can plug this memory device at all. If that
1332 * succeeds, branch of to the actual hotplug handler.
1334 memory_device_pre_plug(MEMORY_DEVICE(dev
), MACHINE(hotplug_dev
), NULL
,
1336 if (!local_err
&& hotplug_dev2
) {
1337 hotplug_handler_pre_plug(hotplug_dev2
, dev
, &local_err
);
1339 error_propagate(errp
, local_err
);
1342 static void pc_virtio_md_pci_plug(HotplugHandler
*hotplug_dev
,
1343 DeviceState
*dev
, Error
**errp
)
1345 HotplugHandler
*hotplug_dev2
= qdev_get_bus_hotplug_handler(dev
);
1346 Error
*local_err
= NULL
;
1349 * Plug the memory device first and then branch off to the actual
1350 * hotplug handler. If that one fails, we can easily undo the memory
1353 memory_device_plug(MEMORY_DEVICE(dev
), MACHINE(hotplug_dev
));
1355 hotplug_handler_plug(hotplug_dev2
, dev
, &local_err
);
1357 memory_device_unplug(MEMORY_DEVICE(dev
), MACHINE(hotplug_dev
));
1360 error_propagate(errp
, local_err
);
1363 static void pc_virtio_md_pci_unplug_request(HotplugHandler
*hotplug_dev
,
1364 DeviceState
*dev
, Error
**errp
)
1366 /* We don't support hot unplug of virtio based memory devices */
1367 error_setg(errp
, "virtio based memory devices cannot be unplugged.");
1370 static void pc_virtio_md_pci_unplug(HotplugHandler
*hotplug_dev
,
1371 DeviceState
*dev
, Error
**errp
)
1373 /* We don't support hot unplug of virtio based memory devices */
1376 static void pc_machine_device_pre_plug_cb(HotplugHandler
*hotplug_dev
,
1377 DeviceState
*dev
, Error
**errp
)
1379 if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
1380 pc_memory_pre_plug(hotplug_dev
, dev
, errp
);
1381 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
1382 x86_cpu_pre_plug(hotplug_dev
, dev
, errp
);
1383 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_PMEM_PCI
) ||
1384 object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_MEM_PCI
)) {
1385 pc_virtio_md_pci_pre_plug(hotplug_dev
, dev
, errp
);
1389 static void pc_machine_device_plug_cb(HotplugHandler
*hotplug_dev
,
1390 DeviceState
*dev
, Error
**errp
)
1392 if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
1393 pc_memory_plug(hotplug_dev
, dev
, errp
);
1394 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
1395 x86_cpu_plug(hotplug_dev
, dev
, errp
);
1396 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_PMEM_PCI
) ||
1397 object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_MEM_PCI
)) {
1398 pc_virtio_md_pci_plug(hotplug_dev
, dev
, errp
);
1402 static void pc_machine_device_unplug_request_cb(HotplugHandler
*hotplug_dev
,
1403 DeviceState
*dev
, Error
**errp
)
1405 if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
1406 pc_memory_unplug_request(hotplug_dev
, dev
, errp
);
1407 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
1408 x86_cpu_unplug_request_cb(hotplug_dev
, dev
, errp
);
1409 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_PMEM_PCI
) ||
1410 object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_MEM_PCI
)) {
1411 pc_virtio_md_pci_unplug_request(hotplug_dev
, dev
, errp
);
1413 error_setg(errp
, "acpi: device unplug request for not supported device"
1414 " type: %s", object_get_typename(OBJECT(dev
)));
1418 static void pc_machine_device_unplug_cb(HotplugHandler
*hotplug_dev
,
1419 DeviceState
*dev
, Error
**errp
)
1421 if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
1422 pc_memory_unplug(hotplug_dev
, dev
, errp
);
1423 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
1424 x86_cpu_unplug_cb(hotplug_dev
, dev
, errp
);
1425 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_PMEM_PCI
) ||
1426 object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_MEM_PCI
)) {
1427 pc_virtio_md_pci_unplug(hotplug_dev
, dev
, errp
);
1429 error_setg(errp
, "acpi: device unplug for not supported device"
1430 " type: %s", object_get_typename(OBJECT(dev
)));
1434 static HotplugHandler
*pc_get_hotplug_handler(MachineState
*machine
,
1437 if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
) ||
1438 object_dynamic_cast(OBJECT(dev
), TYPE_CPU
) ||
1439 object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_PMEM_PCI
) ||
1440 object_dynamic_cast(OBJECT(dev
), TYPE_VIRTIO_MEM_PCI
)) {
1441 return HOTPLUG_HANDLER(machine
);
1448 pc_machine_get_device_memory_region_size(Object
*obj
, Visitor
*v
,
1449 const char *name
, void *opaque
,
1452 MachineState
*ms
= MACHINE(obj
);
1455 if (ms
->device_memory
) {
1456 value
= memory_region_size(&ms
->device_memory
->mr
);
1459 visit_type_int(v
, name
, &value
, errp
);
1462 static void pc_machine_get_vmport(Object
*obj
, Visitor
*v
, const char *name
,
1463 void *opaque
, Error
**errp
)
1465 PCMachineState
*pcms
= PC_MACHINE(obj
);
1466 OnOffAuto vmport
= pcms
->vmport
;
1468 visit_type_OnOffAuto(v
, name
, &vmport
, errp
);
1471 static void pc_machine_set_vmport(Object
*obj
, Visitor
*v
, const char *name
,
1472 void *opaque
, Error
**errp
)
1474 PCMachineState
*pcms
= PC_MACHINE(obj
);
1476 visit_type_OnOffAuto(v
, name
, &pcms
->vmport
, errp
);
1479 static bool pc_machine_get_smbus(Object
*obj
, Error
**errp
)
1481 PCMachineState
*pcms
= PC_MACHINE(obj
);
1483 return pcms
->smbus_enabled
;
1486 static void pc_machine_set_smbus(Object
*obj
, bool value
, Error
**errp
)
1488 PCMachineState
*pcms
= PC_MACHINE(obj
);
1490 pcms
->smbus_enabled
= value
;
1493 static bool pc_machine_get_sata(Object
*obj
, Error
**errp
)
1495 PCMachineState
*pcms
= PC_MACHINE(obj
);
1497 return pcms
->sata_enabled
;
1500 static void pc_machine_set_sata(Object
*obj
, bool value
, Error
**errp
)
1502 PCMachineState
*pcms
= PC_MACHINE(obj
);
1504 pcms
->sata_enabled
= value
;
1507 static bool pc_machine_get_pit(Object
*obj
, Error
**errp
)
1509 PCMachineState
*pcms
= PC_MACHINE(obj
);
1511 return pcms
->pit_enabled
;
1514 static void pc_machine_set_pit(Object
*obj
, bool value
, Error
**errp
)
1516 PCMachineState
*pcms
= PC_MACHINE(obj
);
1518 pcms
->pit_enabled
= value
;
1521 static bool pc_machine_get_hpet(Object
*obj
, Error
**errp
)
1523 PCMachineState
*pcms
= PC_MACHINE(obj
);
1525 return pcms
->hpet_enabled
;
1528 static void pc_machine_set_hpet(Object
*obj
, bool value
, Error
**errp
)
1530 PCMachineState
*pcms
= PC_MACHINE(obj
);
1532 pcms
->hpet_enabled
= value
;
1535 static void pc_machine_get_max_ram_below_4g(Object
*obj
, Visitor
*v
,
1536 const char *name
, void *opaque
,
1539 PCMachineState
*pcms
= PC_MACHINE(obj
);
1540 uint64_t value
= pcms
->max_ram_below_4g
;
1542 visit_type_size(v
, name
, &value
, errp
);
1545 static void pc_machine_set_max_ram_below_4g(Object
*obj
, Visitor
*v
,
1546 const char *name
, void *opaque
,
1549 PCMachineState
*pcms
= PC_MACHINE(obj
);
1552 if (!visit_type_size(v
, name
, &value
, errp
)) {
1555 if (value
> 4 * GiB
) {
1557 "Machine option 'max-ram-below-4g=%"PRIu64
1558 "' expects size less than or equal to 4G", value
);
1562 if (value
< 1 * MiB
) {
1563 warn_report("Only %" PRIu64
" bytes of RAM below the 4GiB boundary,"
1564 "BIOS may not work with less than 1MiB", value
);
1567 pcms
->max_ram_below_4g
= value
;
1570 static void pc_machine_get_max_fw_size(Object
*obj
, Visitor
*v
,
1571 const char *name
, void *opaque
,
1574 PCMachineState
*pcms
= PC_MACHINE(obj
);
1575 uint64_t value
= pcms
->max_fw_size
;
1577 visit_type_size(v
, name
, &value
, errp
);
1580 static void pc_machine_set_max_fw_size(Object
*obj
, Visitor
*v
,
1581 const char *name
, void *opaque
,
1584 PCMachineState
*pcms
= PC_MACHINE(obj
);
1585 Error
*error
= NULL
;
1588 visit_type_size(v
, name
, &value
, &error
);
1590 error_propagate(errp
, error
);
1595 * We don't have a theoretically justifiable exact lower bound on the base
1596 * address of any flash mapping. In practice, the IO-APIC MMIO range is
1597 * [0xFEE00000..0xFEE01000] -- see IO_APIC_DEFAULT_ADDRESS --, leaving free
1598 * only 18MB-4KB below 4G. For now, restrict the cumulative mapping to 8MB in
1601 if (value
> 16 * MiB
) {
1603 "User specified max allowed firmware size %" PRIu64
" is "
1604 "greater than 16MiB. If combined firwmare size exceeds "
1605 "16MiB the system may not boot, or experience intermittent"
1606 "stability issues.",
1611 pcms
->max_fw_size
= value
;
1614 static char *pc_machine_get_oem_id(Object
*obj
, Error
**errp
)
1616 PCMachineState
*pcms
= PC_MACHINE(obj
);
1618 return g_strdup(pcms
->oem_id
);
1621 static void pc_machine_set_oem_id(Object
*obj
, const char *value
, Error
**errp
)
1623 PCMachineState
*pcms
= PC_MACHINE(obj
);
1624 size_t len
= strlen(value
);
1628 "User specified "PC_MACHINE_OEM_ID
" value is bigger than "
1633 strncpy(pcms
->oem_id
, value
, 6);
1636 static char *pc_machine_get_oem_table_id(Object
*obj
, Error
**errp
)
1638 PCMachineState
*pcms
= PC_MACHINE(obj
);
1640 return g_strdup(pcms
->oem_table_id
);
1643 static void pc_machine_set_oem_table_id(Object
*obj
, const char *value
,
1646 PCMachineState
*pcms
= PC_MACHINE(obj
);
1647 size_t len
= strlen(value
);
1651 "User specified "PC_MACHINE_OEM_TABLE_ID
" value is bigger than "
1655 strncpy(pcms
->oem_table_id
, value
, 8);
1658 static void pc_machine_initfn(Object
*obj
)
1660 PCMachineState
*pcms
= PC_MACHINE(obj
);
1662 #ifdef CONFIG_VMPORT
1663 pcms
->vmport
= ON_OFF_AUTO_AUTO
;
1665 pcms
->vmport
= ON_OFF_AUTO_OFF
;
1666 #endif /* CONFIG_VMPORT */
1667 pcms
->max_ram_below_4g
= 0; /* use default */
1668 /* acpi build is enabled by default if machine supports it */
1669 pcms
->acpi_build_enabled
= PC_MACHINE_GET_CLASS(pcms
)->has_acpi_build
;
1670 pcms
->oem_id
= g_strndup(ACPI_BUILD_APPNAME6
, 6);
1671 pcms
->oem_table_id
= g_strndup(ACPI_BUILD_APPNAME8
, 8);
1672 pcms
->smbus_enabled
= true;
1673 pcms
->sata_enabled
= true;
1674 pcms
->pit_enabled
= true;
1675 pcms
->max_fw_size
= 8 * MiB
;
1677 pcms
->hpet_enabled
= true;
1680 pc_system_flash_create(pcms
);
1681 pcms
->pcspk
= isa_new(TYPE_PC_SPEAKER
);
1682 object_property_add_alias(OBJECT(pcms
), "pcspk-audiodev",
1683 OBJECT(pcms
->pcspk
), "audiodev");
1686 static void pc_machine_reset(MachineState
*machine
)
1691 qemu_devices_reset();
1693 /* Reset APIC after devices have been reset to cancel
1694 * any changes that qemu_devices_reset() might have done.
1699 if (cpu
->apic_state
) {
1700 device_legacy_reset(cpu
->apic_state
);
1705 static void pc_machine_wakeup(MachineState
*machine
)
1707 cpu_synchronize_all_states();
1708 pc_machine_reset(machine
);
1709 cpu_synchronize_all_post_reset();
1712 static bool pc_hotplug_allowed(MachineState
*ms
, DeviceState
*dev
, Error
**errp
)
1714 X86IOMMUState
*iommu
= x86_iommu_get_default();
1715 IntelIOMMUState
*intel_iommu
;
1718 object_dynamic_cast((Object
*)iommu
, TYPE_INTEL_IOMMU_DEVICE
) &&
1719 object_dynamic_cast((Object
*)dev
, "vfio-pci")) {
1720 intel_iommu
= INTEL_IOMMU_DEVICE(iommu
);
1721 if (!intel_iommu
->caching_mode
) {
1722 error_setg(errp
, "Device assignment is not allowed without "
1723 "enabling caching-mode=on for Intel IOMMU.");
1731 static void pc_machine_class_init(ObjectClass
*oc
, void *data
)
1733 MachineClass
*mc
= MACHINE_CLASS(oc
);
1734 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(oc
);
1735 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
1737 pcmc
->pci_enabled
= true;
1738 pcmc
->has_acpi_build
= true;
1739 pcmc
->rsdp_in_ram
= true;
1740 pcmc
->smbios_defaults
= true;
1741 pcmc
->smbios_uuid_encoded
= true;
1742 pcmc
->gigabyte_align
= true;
1743 pcmc
->has_reserved_memory
= true;
1744 pcmc
->kvmclock_enabled
= true;
1745 pcmc
->enforce_aligned_dimm
= true;
1746 /* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported
1747 * to be used at the moment, 32K should be enough for a while. */
1748 pcmc
->acpi_data_size
= 0x20000 + 0x8000;
1749 pcmc
->linuxboot_dma_enabled
= true;
1750 pcmc
->pvh_enabled
= true;
1751 pcmc
->kvmclock_create_always
= true;
1752 assert(!mc
->get_hotplug_handler
);
1753 mc
->get_hotplug_handler
= pc_get_hotplug_handler
;
1754 mc
->hotplug_allowed
= pc_hotplug_allowed
;
1755 mc
->cpu_index_to_instance_props
= x86_cpu_index_to_props
;
1756 mc
->get_default_cpu_node_id
= x86_get_default_cpu_node_id
;
1757 mc
->possible_cpu_arch_ids
= x86_possible_cpu_arch_ids
;
1758 mc
->auto_enable_numa_with_memhp
= true;
1759 mc
->auto_enable_numa_with_memdev
= true;
1760 mc
->has_hotpluggable_cpus
= true;
1761 mc
->default_boot_order
= "cad";
1762 mc
->smp_parse
= pc_smp_parse
;
1763 mc
->block_default_type
= IF_IDE
;
1765 mc
->reset
= pc_machine_reset
;
1766 mc
->wakeup
= pc_machine_wakeup
;
1767 hc
->pre_plug
= pc_machine_device_pre_plug_cb
;
1768 hc
->plug
= pc_machine_device_plug_cb
;
1769 hc
->unplug_request
= pc_machine_device_unplug_request_cb
;
1770 hc
->unplug
= pc_machine_device_unplug_cb
;
1771 mc
->default_cpu_type
= TARGET_DEFAULT_CPU_TYPE
;
1772 mc
->nvdimm_supported
= true;
1773 mc
->default_ram_id
= "pc.ram";
1775 object_class_property_add(oc
, PC_MACHINE_MAX_RAM_BELOW_4G
, "size",
1776 pc_machine_get_max_ram_below_4g
, pc_machine_set_max_ram_below_4g
,
1778 object_class_property_set_description(oc
, PC_MACHINE_MAX_RAM_BELOW_4G
,
1779 "Maximum ram below the 4G boundary (32bit boundary)");
1781 object_class_property_add(oc
, PC_MACHINE_DEVMEM_REGION_SIZE
, "int",
1782 pc_machine_get_device_memory_region_size
, NULL
,
1785 object_class_property_add(oc
, PC_MACHINE_VMPORT
, "OnOffAuto",
1786 pc_machine_get_vmport
, pc_machine_set_vmport
,
1788 object_class_property_set_description(oc
, PC_MACHINE_VMPORT
,
1789 "Enable vmport (pc & q35)");
1791 object_class_property_add_bool(oc
, PC_MACHINE_SMBUS
,
1792 pc_machine_get_smbus
, pc_machine_set_smbus
);
1794 object_class_property_add_bool(oc
, PC_MACHINE_SATA
,
1795 pc_machine_get_sata
, pc_machine_set_sata
);
1797 object_class_property_add_bool(oc
, PC_MACHINE_PIT
,
1798 pc_machine_get_pit
, pc_machine_set_pit
);
1800 object_class_property_add_bool(oc
, "hpet",
1801 pc_machine_get_hpet
, pc_machine_set_hpet
);
1803 object_class_property_add(oc
, PC_MACHINE_MAX_FW_SIZE
, "size",
1804 pc_machine_get_max_fw_size
, pc_machine_set_max_fw_size
,
1806 object_class_property_set_description(oc
, PC_MACHINE_MAX_FW_SIZE
,
1807 "Maximum combined firmware size");
1809 object_class_property_add_str(oc
, PC_MACHINE_OEM_ID
,
1810 pc_machine_get_oem_id
,
1811 pc_machine_set_oem_id
);
1812 object_class_property_set_description(oc
, PC_MACHINE_OEM_ID
,
1813 "Override the default value of field OEMID "
1814 "in ACPI table header."
1815 "The string may be up to 6 bytes in size");
1818 object_class_property_add_str(oc
, PC_MACHINE_OEM_TABLE_ID
,
1819 pc_machine_get_oem_table_id
,
1820 pc_machine_set_oem_table_id
);
1821 object_class_property_set_description(oc
, PC_MACHINE_OEM_TABLE_ID
,
1822 "Override the default value of field OEM Table ID "
1823 "in ACPI table header."
1824 "The string may be up to 8 bytes in size");
1828 static const TypeInfo pc_machine_info
= {
1829 .name
= TYPE_PC_MACHINE
,
1830 .parent
= TYPE_X86_MACHINE
,
1832 .instance_size
= sizeof(PCMachineState
),
1833 .instance_init
= pc_machine_initfn
,
1834 .class_size
= sizeof(PCMachineClass
),
1835 .class_init
= pc_machine_class_init
,
1836 .interfaces
= (InterfaceInfo
[]) {
1837 { TYPE_HOTPLUG_HANDLER
},
1842 static void pc_machine_register_types(void)
1844 type_register_static(&pc_machine_info
);
1847 type_init(pc_machine_register_types
)