blob: a5dd6252fa7da66502e9df8558c0cdc0d050b0a8 [file] [log] [blame]
bellard80cabfa2004-03-14 12:20:30 +00001/*
2 * QEMU PC System Emulator
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard80cabfa2004-03-14 12:20:30 +00004 * Copyright (c) 2003-2004 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellard80cabfa2004-03-14 12:20:30 +00006 * 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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
Markus Armbrustere688df62018-02-01 12:18:31 +010024
Peter Maydellb6a0aa02016-01-26 18:17:03 +000025#include "qemu/osdep.h"
Paolo Bonzinid471bf32018-06-29 16:22:13 +020026#include "qemu/units.h"
Sergio Lopez549e9842019-10-08 11:56:49 +020027#include "hw/i386/x86.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010028#include "hw/i386/pc.h"
29#include "hw/char/serial.h"
Philippe Mathieu-Daudébb3d5ea2018-03-08 23:39:22 +010030#include "hw/char/parallel.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010031#include "hw/i386/apic.h"
Eduardo Habkost54a40292014-12-18 23:43:35 -020032#include "hw/i386/topology.h"
Philippe Mathieu-Daudé87abaa52019-04-22 18:58:21 +020033#include "hw/i386/fw_cfg.h"
Liran Alond8f23d62020-03-12 18:54:22 +020034#include "hw/i386/vmport.h"
Eduardo Habkost54a40292014-12-18 23:43:35 -020035#include "sysemu/cpus.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010036#include "hw/block/fdc.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010037#include "hw/ide.h"
38#include "hw/pci/pci.h"
Marcel Apfelbaum21181962015-06-02 14:23:07 +030039#include "hw/pci/pci_bus.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010040#include "hw/nvram/fw_cfg.h"
41#include "hw/timer/hpet.h"
Philippe Mathieu-Daudéa2eb5c02018-12-11 17:34:06 +010042#include "hw/firmware/smbios.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010043#include "hw/loader.h"
Blue Swirlca20cf32009-09-20 14:58:02 +000044#include "elf.h"
Markus Armbrusterd6454272019-08-12 07:23:45 +020045#include "migration/vmstate.h"
Paolo Bonzini47b43a12013-03-18 17:36:02 +010046#include "multiboot.h"
Philippe Mathieu-Daudébcdb9062019-10-04 01:03:53 +020047#include "hw/rtc/mc146818rtc.h"
Paolo Bonzini852c27e2019-12-12 17:15:43 +010048#include "hw/intc/i8259.h"
Philippe Mathieu-Daudé55f613a2018-03-08 23:39:23 +010049#include "hw/dma/i8257.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010050#include "hw/timer/i8254.h"
Philippe Mathieu-Daudé47973a22018-03-08 23:39:24 +010051#include "hw/input/i8042.h"
Markus Armbruster64552b62019-08-12 07:23:42 +020052#include "hw/irq.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010053#include "hw/audio/pcspk.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010054#include "hw/pci/msi.h"
55#include "hw/sysbus.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010056#include "sysemu/sysemu.h"
Markus Armbruster14a48c12019-05-23 16:35:05 +020057#include "sysemu/tcg.h"
Eduardo Habkoste35704b2015-02-08 16:51:16 -020058#include "sysemu/numa.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010059#include "sysemu/kvm.h"
Philippe Mathieu-Daudéda278d52020-05-08 12:02:22 +020060#include "sysemu/xen.h"
Andreas Färberb1c12022015-03-14 14:24:37 +010061#include "sysemu/qtest.h"
Markus Armbruster71e8a912019-08-12 07:23:38 +020062#include "sysemu/reset.h"
Markus Armbruster54d31232019-08-12 07:23:59 +020063#include "sysemu/runstate.h"
Peter Maydell1d31f662012-07-26 15:35:13 +010064#include "kvm_i386.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010065#include "hw/xen/xen.h"
Liam Merwickab969082019-01-15 12:18:06 +000066#include "hw/xen/start_info.h"
Gerd Hoffmanna19cbfb2010-04-27 11:50:11 +020067#include "ui/qemu-spice.h"
Paolo Bonzini022c62c2012-12-17 18:19:49 +010068#include "exec/memory.h"
69#include "exec/address-spaces.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010070#include "sysemu/arch_init.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010071#include "qemu/bitmap.h"
Laszlo Ersek0c764a92013-03-21 00:23:17 +010072#include "qemu/config-file.h"
Markus Armbrusterd49b6832015-03-17 18:29:20 +010073#include "qemu/error-report.h"
Markus Armbruster922a01a2018-02-01 12:18:46 +010074#include "qemu/option.h"
Sergio Lopez133ef072019-10-10 15:49:39 +020075#include "qemu/cutils.h"
Michael S. Tsirkin04452592013-04-15 09:19:22 +030076#include "hw/acpi/acpi.h"
Eduardo Habkost5ff020b2014-03-14 16:33:51 -030077#include "hw/acpi/cpu_hotplug.h"
Igor Mammedovc6499832013-04-30 18:00:53 +020078#include "hw/boards.h"
Michael S. Tsirkin72c194f2013-07-24 18:56:14 +030079#include "acpi-build.h"
Igor Mammedov95bee272014-06-02 15:25:12 +020080#include "hw/mem/pc-dimm.h"
Philippe Mathieu-Daudé4b997692020-02-28 12:46:47 +010081#include "hw/mem/nvdimm.h"
Markus Armbrustere688df62018-02-01 12:18:31 +010082#include "qapi/error.h"
Markus Armbruster9af23982018-02-11 10:36:01 +010083#include "qapi/qapi-visit-common.h"
Igor Mammedovbf1e8932014-06-02 15:25:27 +020084#include "qapi/visitor.h"
Markus Armbruster2e5b09f2019-07-09 17:20:52 +020085#include "hw/core/cpu.h"
Marc-André Lureaua310e652018-12-12 21:57:53 +040086#include "hw/usb.h"
Igor Mammedov60c5e102016-10-19 14:05:42 +020087#include "hw/i386/intel_iommu.h"
Philippe Mathieu-Daudé489983d2017-10-17 13:44:22 -030088#include "hw/net/ne2000-isa.h"
Li Zhijian06e02592019-01-17 20:49:03 +080089#include "standard-headers/asm-x86/bootparam.h"
David Hildenbranda0a49812019-06-19 15:19:07 +053090#include "hw/virtio/virtio-pmem-pci.h"
91#include "hw/mem/memory-device.h"
Like Xu6f479562019-06-20 13:45:24 +080092#include "sysemu/replay.h"
93#include "qapi/qmp/qerror.h"
Julio Montes97fd1ea2019-07-12 16:02:57 +000094#include "config-devices.h"
Philippe Mathieu-Daudéd6d059c2019-08-19 00:54:01 +020095#include "e820_memory_layout.h"
Philippe Mathieu-Daudé149c50c2019-09-16 12:49:28 +020096#include "fw_cfg.h"
Philippe Mathieu-Daudé4ca8dab2019-12-13 11:50:57 +010097#include "trace.h"
Blue Swirl471fd342010-05-29 20:23:49 +000098
Cornelia Huck541aaa12020-04-29 16:46:05 +020099GlobalProperty pc_compat_5_0[] = {};
100const size_t pc_compat_5_0_len = G_N_ELEMENTS(pc_compat_5_0);
101
Igor Mammedovf4042202019-12-09 14:08:55 +0100102GlobalProperty pc_compat_4_2[] = {
103 { "mch", "smbase-smram", "off" },
104};
Cornelia Huck3eb74d22019-11-12 11:48:11 +0100105const size_t pc_compat_4_2_len = G_N_ELEMENTS(pc_compat_4_2);
106
Cornelia Huck9aec2e52019-07-24 12:35:24 +0200107GlobalProperty pc_compat_4_1[] = {};
108const size_t pc_compat_4_1_len = G_N_ELEMENTS(pc_compat_4_1);
109
Cornelia Huck9bf26502019-04-11 12:20:25 +0200110GlobalProperty pc_compat_4_0[] = {};
111const size_t pc_compat_4_0_len = G_N_ELEMENTS(pc_compat_4_0);
112
Marc-André Lureauabd93cc2018-12-12 19:36:30 +0400113GlobalProperty pc_compat_3_1[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200114 { "intel-iommu", "dma-drain", "off" },
Borislav Petkov483c6ad2018-12-20 10:07:32 -0200115 { "Opteron_G3" "-" TYPE_X86_CPU, "rdtscp", "off" },
116 { "Opteron_G4" "-" TYPE_X86_CPU, "rdtscp", "off" },
Vitaly Kuznetsov9fe8b7b2019-01-21 16:50:51 +0100117 { "Opteron_G4" "-" TYPE_X86_CPU, "npt", "off" },
118 { "Opteron_G4" "-" TYPE_X86_CPU, "nrip-save", "off" },
Borislav Petkov483c6ad2018-12-20 10:07:32 -0200119 { "Opteron_G5" "-" TYPE_X86_CPU, "rdtscp", "off" },
Vitaly Kuznetsov9fe8b7b2019-01-21 16:50:51 +0100120 { "Opteron_G5" "-" TYPE_X86_CPU, "npt", "off" },
121 { "Opteron_G5" "-" TYPE_X86_CPU, "nrip-save", "off" },
122 { "EPYC" "-" TYPE_X86_CPU, "npt", "off" },
123 { "EPYC" "-" TYPE_X86_CPU, "nrip-save", "off" },
124 { "EPYC-IBPB" "-" TYPE_X86_CPU, "npt", "off" },
125 { "EPYC-IBPB" "-" TYPE_X86_CPU, "nrip-save", "off" },
Paolo Bonziniecb85fe2018-12-20 13:11:00 +0100126 { "Skylake-Client" "-" TYPE_X86_CPU, "mpx", "on" },
127 { "Skylake-Client-IBRS" "-" TYPE_X86_CPU, "mpx", "on" },
128 { "Skylake-Server" "-" TYPE_X86_CPU, "mpx", "on" },
129 { "Skylake-Server-IBRS" "-" TYPE_X86_CPU, "mpx", "on" },
130 { "Cascadelake-Server" "-" TYPE_X86_CPU, "mpx", "on" },
131 { "Icelake-Client" "-" TYPE_X86_CPU, "mpx", "on" },
132 { "Icelake-Server" "-" TYPE_X86_CPU, "mpx", "on" },
Tao Xub0a19802018-12-27 10:43:03 +0800133 { "Cascadelake-Server" "-" TYPE_X86_CPU, "stepping", "5" },
Luwei Kangf24c3a72019-01-29 18:52:59 -0500134 { TYPE_X86_CPU, "x-intel-pt-auto-level", "off" },
Marc-André Lureauabd93cc2018-12-12 19:36:30 +0400135};
136const size_t pc_compat_3_1_len = G_N_ELEMENTS(pc_compat_3_1);
137
Marc-André Lureauddb32352018-12-12 19:36:30 +0400138GlobalProperty pc_compat_3_0[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200139 { TYPE_X86_CPU, "x-hv-synic-kvm-only", "on" },
140 { "Skylake-Server" "-" TYPE_X86_CPU, "pku", "off" },
141 { "Skylake-Server-IBRS" "-" TYPE_X86_CPU, "pku", "off" },
Marc-André Lureauddb32352018-12-12 19:36:30 +0400142};
143const size_t pc_compat_3_0_len = G_N_ELEMENTS(pc_compat_3_0);
144
Marc-André Lureau0d473102018-12-12 19:36:30 +0400145GlobalProperty pc_compat_2_12[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200146 { TYPE_X86_CPU, "legacy-cache", "on" },
147 { TYPE_X86_CPU, "topoext", "off" },
148 { "EPYC-" TYPE_X86_CPU, "xlevel", "0x8000000a" },
149 { "EPYC-IBPB-" TYPE_X86_CPU, "xlevel", "0x8000000a" },
Marc-André Lureau0d473102018-12-12 19:36:30 +0400150};
151const size_t pc_compat_2_12_len = G_N_ELEMENTS(pc_compat_2_12);
152
Marc-André Lureau43df70a2018-12-12 19:36:30 +0400153GlobalProperty pc_compat_2_11[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200154 { TYPE_X86_CPU, "x-migrate-smi-count", "off" },
155 { "Skylake-Server" "-" TYPE_X86_CPU, "clflushopt", "off" },
Marc-André Lureau43df70a2018-12-12 19:36:30 +0400156};
157const size_t pc_compat_2_11_len = G_N_ELEMENTS(pc_compat_2_11);
158
Marc-André Lureau503224f2018-12-12 19:36:30 +0400159GlobalProperty pc_compat_2_10[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200160 { TYPE_X86_CPU, "x-hv-max-vps", "0x40" },
161 { "i440FX-pcihost", "x-pci-hole64-fix", "off" },
162 { "q35-pcihost", "x-pci-hole64-fix", "off" },
Marc-André Lureau503224f2018-12-12 19:36:30 +0400163};
164const size_t pc_compat_2_10_len = G_N_ELEMENTS(pc_compat_2_10);
165
Marc-André Lureau3e803152018-12-12 19:36:30 +0400166GlobalProperty pc_compat_2_9[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200167 { "mch", "extended-tseg-mbytes", "0" },
Marc-André Lureau3e803152018-12-12 19:36:30 +0400168};
169const size_t pc_compat_2_9_len = G_N_ELEMENTS(pc_compat_2_9);
170
Marc-André Lureauedc24cc2018-12-12 19:36:30 +0400171GlobalProperty pc_compat_2_8[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200172 { TYPE_X86_CPU, "tcg-cpuid", "off" },
173 { "kvmclock", "x-mach-use-reliable-get-clock", "off" },
174 { "ICH9-LPC", "x-smi-broadcast", "off" },
175 { TYPE_X86_CPU, "vmware-cpuid-freq", "off" },
176 { "Haswell-" TYPE_X86_CPU, "stepping", "1" },
Marc-André Lureauedc24cc2018-12-12 19:36:30 +0400177};
178const size_t pc_compat_2_8_len = G_N_ELEMENTS(pc_compat_2_8);
179
Marc-André Lureau5a995062018-12-12 19:36:30 +0400180GlobalProperty pc_compat_2_7[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200181 { TYPE_X86_CPU, "l3-cache", "off" },
182 { TYPE_X86_CPU, "full-cpuid-auto-level", "off" },
183 { "Opteron_G3" "-" TYPE_X86_CPU, "family", "15" },
184 { "Opteron_G3" "-" TYPE_X86_CPU, "model", "6" },
185 { "Opteron_G3" "-" TYPE_X86_CPU, "stepping", "1" },
186 { "isa-pcspk", "migrate", "off" },
Marc-André Lureau5a995062018-12-12 19:36:30 +0400187};
188const size_t pc_compat_2_7_len = G_N_ELEMENTS(pc_compat_2_7);
189
Marc-André Lureauff8f2612018-12-12 19:36:30 +0400190GlobalProperty pc_compat_2_6[] = {
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200191 { TYPE_X86_CPU, "cpuid-0xb", "off" },
192 { "vmxnet3", "romfile", "" },
193 { TYPE_X86_CPU, "fill-mtrr-mask", "off" },
194 { "apic-common", "legacy-instance-id", "on", }
Marc-André Lureauff8f2612018-12-12 19:36:30 +0400195};
196const size_t pc_compat_2_6_len = G_N_ELEMENTS(pc_compat_2_6);
197
Marc-André Lureaufe759612018-12-12 19:36:30 +0400198GlobalProperty pc_compat_2_5[] = {};
199const size_t pc_compat_2_5_len = G_N_ELEMENTS(pc_compat_2_5);
200
Marc-André Lureau2f99b9c2018-12-12 19:36:30 +0400201GlobalProperty pc_compat_2_4[] = {
202 PC_CPU_MODEL_IDS("2.4.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200203 { "Haswell-" TYPE_X86_CPU, "abm", "off" },
204 { "Haswell-noTSX-" TYPE_X86_CPU, "abm", "off" },
205 { "Broadwell-" TYPE_X86_CPU, "abm", "off" },
206 { "Broadwell-noTSX-" TYPE_X86_CPU, "abm", "off" },
207 { "host" "-" TYPE_X86_CPU, "host-cache-info", "on" },
208 { TYPE_X86_CPU, "check", "off" },
209 { "qemu64" "-" TYPE_X86_CPU, "sse4a", "on" },
210 { "qemu64" "-" TYPE_X86_CPU, "abm", "on" },
211 { "qemu64" "-" TYPE_X86_CPU, "popcnt", "on" },
212 { "qemu32" "-" TYPE_X86_CPU, "popcnt", "on" },
213 { "Opteron_G2" "-" TYPE_X86_CPU, "rdtscp", "on" },
214 { "Opteron_G3" "-" TYPE_X86_CPU, "rdtscp", "on" },
215 { "Opteron_G4" "-" TYPE_X86_CPU, "rdtscp", "on" },
216 { "Opteron_G5" "-" TYPE_X86_CPU, "rdtscp", "on", }
Marc-André Lureau2f99b9c2018-12-12 19:36:30 +0400217};
218const size_t pc_compat_2_4_len = G_N_ELEMENTS(pc_compat_2_4);
219
Marc-André Lureau8995dd92018-12-12 19:36:30 +0400220GlobalProperty pc_compat_2_3[] = {
221 PC_CPU_MODEL_IDS("2.3.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200222 { TYPE_X86_CPU, "arat", "off" },
223 { "qemu64" "-" TYPE_X86_CPU, "min-level", "4" },
224 { "kvm64" "-" TYPE_X86_CPU, "min-level", "5" },
225 { "pentium3" "-" TYPE_X86_CPU, "min-level", "2" },
226 { "n270" "-" TYPE_X86_CPU, "min-level", "5" },
227 { "Conroe" "-" TYPE_X86_CPU, "min-level", "4" },
228 { "Penryn" "-" TYPE_X86_CPU, "min-level", "4" },
229 { "Nehalem" "-" TYPE_X86_CPU, "min-level", "4" },
230 { "n270" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
231 { "Penryn" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
232 { "Conroe" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
233 { "Nehalem" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
234 { "Westmere" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
235 { "SandyBridge" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
236 { "IvyBridge" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
237 { "Haswell" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
238 { "Haswell-noTSX" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
239 { "Broadwell" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
240 { "Broadwell-noTSX" "-" TYPE_X86_CPU, "min-xlevel", "0x8000000a" },
241 { TYPE_X86_CPU, "kvm-no-smi-migration", "on" },
Marc-André Lureau8995dd92018-12-12 19:36:30 +0400242};
243const size_t pc_compat_2_3_len = G_N_ELEMENTS(pc_compat_2_3);
244
Marc-André Lureau1c300442018-12-12 19:36:30 +0400245GlobalProperty pc_compat_2_2[] = {
246 PC_CPU_MODEL_IDS("2.2.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200247 { "kvm64" "-" TYPE_X86_CPU, "vme", "off" },
248 { "kvm32" "-" TYPE_X86_CPU, "vme", "off" },
249 { "Conroe" "-" TYPE_X86_CPU, "vme", "off" },
250 { "Penryn" "-" TYPE_X86_CPU, "vme", "off" },
251 { "Nehalem" "-" TYPE_X86_CPU, "vme", "off" },
252 { "Westmere" "-" TYPE_X86_CPU, "vme", "off" },
253 { "SandyBridge" "-" TYPE_X86_CPU, "vme", "off" },
254 { "Haswell" "-" TYPE_X86_CPU, "vme", "off" },
255 { "Broadwell" "-" TYPE_X86_CPU, "vme", "off" },
256 { "Opteron_G1" "-" TYPE_X86_CPU, "vme", "off" },
257 { "Opteron_G2" "-" TYPE_X86_CPU, "vme", "off" },
258 { "Opteron_G3" "-" TYPE_X86_CPU, "vme", "off" },
259 { "Opteron_G4" "-" TYPE_X86_CPU, "vme", "off" },
260 { "Opteron_G5" "-" TYPE_X86_CPU, "vme", "off" },
261 { "Haswell" "-" TYPE_X86_CPU, "f16c", "off" },
262 { "Haswell" "-" TYPE_X86_CPU, "rdrand", "off" },
263 { "Broadwell" "-" TYPE_X86_CPU, "f16c", "off" },
264 { "Broadwell" "-" TYPE_X86_CPU, "rdrand", "off" },
Marc-André Lureau1c300442018-12-12 19:36:30 +0400265};
266const size_t pc_compat_2_2_len = G_N_ELEMENTS(pc_compat_2_2);
267
Marc-André Lureauc4fc5692018-12-12 19:36:30 +0400268GlobalProperty pc_compat_2_1[] = {
269 PC_CPU_MODEL_IDS("2.1.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200270 { "coreduo" "-" TYPE_X86_CPU, "vmx", "on" },
271 { "core2duo" "-" TYPE_X86_CPU, "vmx", "on" },
Marc-André Lureauc4fc5692018-12-12 19:36:30 +0400272};
273const size_t pc_compat_2_1_len = G_N_ELEMENTS(pc_compat_2_1);
274
Marc-André Lureaua310e652018-12-12 21:57:53 +0400275GlobalProperty pc_compat_2_0[] = {
276 PC_CPU_MODEL_IDS("2.0.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200277 { "virtio-scsi-pci", "any_layout", "off" },
278 { "PIIX4_PM", "memory-hotplug-support", "off" },
279 { "apic", "version", "0x11" },
280 { "nec-usb-xhci", "superspeed-ports-first", "off" },
281 { "nec-usb-xhci", "force-pcie-endcap", "on" },
282 { "pci-serial", "prog_if", "0" },
283 { "pci-serial-2x", "prog_if", "0" },
284 { "pci-serial-4x", "prog_if", "0" },
285 { "virtio-net-pci", "guest_announce", "off" },
286 { "ICH9-LPC", "memory-hotplug-support", "off" },
287 { "xio3130-downstream", COMPAT_PROP_PCP, "off" },
288 { "ioh3420", COMPAT_PROP_PCP, "off" },
Marc-André Lureaua310e652018-12-12 21:57:53 +0400289};
290const size_t pc_compat_2_0_len = G_N_ELEMENTS(pc_compat_2_0);
291
292GlobalProperty pc_compat_1_7[] = {
293 PC_CPU_MODEL_IDS("1.7.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200294 { TYPE_USB_DEVICE, "msos-desc", "no" },
295 { "PIIX4_PM", "acpi-pci-hotplug-with-bridge-support", "off" },
296 { "hpet", HPET_INTCAP, "4" },
Marc-André Lureaua310e652018-12-12 21:57:53 +0400297};
298const size_t pc_compat_1_7_len = G_N_ELEMENTS(pc_compat_1_7);
299
300GlobalProperty pc_compat_1_6[] = {
301 PC_CPU_MODEL_IDS("1.6.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200302 { "e1000", "mitigation", "off" },
303 { "qemu64-" TYPE_X86_CPU, "model", "2" },
304 { "qemu32-" TYPE_X86_CPU, "model", "3" },
305 { "i440FX-pcihost", "short_root_bus", "1" },
306 { "q35-pcihost", "short_root_bus", "1" },
Marc-André Lureaua310e652018-12-12 21:57:53 +0400307};
308const size_t pc_compat_1_6_len = G_N_ELEMENTS(pc_compat_1_6);
309
310GlobalProperty pc_compat_1_5[] = {
311 PC_CPU_MODEL_IDS("1.5.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200312 { "Conroe-" TYPE_X86_CPU, "model", "2" },
313 { "Conroe-" TYPE_X86_CPU, "min-level", "2" },
314 { "Penryn-" TYPE_X86_CPU, "model", "2" },
315 { "Penryn-" TYPE_X86_CPU, "min-level", "2" },
316 { "Nehalem-" TYPE_X86_CPU, "model", "2" },
317 { "Nehalem-" TYPE_X86_CPU, "min-level", "2" },
318 { "virtio-net-pci", "any_layout", "off" },
319 { TYPE_X86_CPU, "pmu", "on" },
320 { "i440FX-pcihost", "short_root_bus", "0" },
321 { "q35-pcihost", "short_root_bus", "0" },
Marc-André Lureaua310e652018-12-12 21:57:53 +0400322};
323const size_t pc_compat_1_5_len = G_N_ELEMENTS(pc_compat_1_5);
324
325GlobalProperty pc_compat_1_4[] = {
326 PC_CPU_MODEL_IDS("1.4.0")
Eduardo Habkost6c36bdd2019-01-07 17:30:20 -0200327 { "scsi-hd", "discard_granularity", "0" },
328 { "scsi-cd", "discard_granularity", "0" },
329 { "scsi-disk", "discard_granularity", "0" },
330 { "ide-hd", "discard_granularity", "0" },
331 { "ide-cd", "discard_granularity", "0" },
332 { "ide-drive", "discard_granularity", "0" },
333 { "virtio-blk-pci", "discard_granularity", "0" },
334 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string: */
335 { "virtio-serial-pci", "vectors", "0xFFFFFFFF" },
336 { "virtio-net-pci", "ctrl_guest_offloads", "off" },
337 { "e1000", "romfile", "pxe-e1000.rom" },
338 { "ne2k_pci", "romfile", "pxe-ne2k_pci.rom" },
339 { "pcnet", "romfile", "pxe-pcnet.rom" },
340 { "rtl8139", "romfile", "pxe-rtl8139.rom" },
341 { "virtio-net-pci", "romfile", "pxe-virtio.rom" },
342 { "486-" TYPE_X86_CPU, "model", "0" },
343 { "n270" "-" TYPE_X86_CPU, "movbe", "off" },
344 { "Westmere" "-" TYPE_X86_CPU, "pclmulqdq", "off" },
Marc-André Lureaua310e652018-12-12 21:57:53 +0400345};
346const size_t pc_compat_1_4_len = G_N_ELEMENTS(pc_compat_1_4);
347
Philippe Mathieu-Daudé417258f2019-10-18 15:59:06 +0200348GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled)
349{
350 GSIState *s;
351
352 s = g_new0(GSIState, 1);
353 if (kvm_ioapic_in_kernel()) {
354 kvm_pc_setup_irq_routing(pci_enabled);
Philippe Mathieu-Daudé417258f2019-10-18 15:59:06 +0200355 }
Philippe Mathieu-Daudé64c033b2019-12-13 12:07:36 +0100356 *irqs = qemu_allocate_irqs(gsi_handler, s, GSI_NUM_PINS);
Philippe Mathieu-Daudé417258f2019-10-18 15:59:06 +0200357
358 return s;
359}
360
Julien Grall258711c2012-09-19 12:50:08 +0100361static void ioport80_write(void *opaque, hwaddr addr, uint64_t data,
362 unsigned size)
bellard80cabfa2004-03-14 12:20:30 +0000363{
364}
365
Julien Grallc02e1ea2013-01-09 18:10:22 +0000366static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size)
367{
Julien Gralla6fc23e2013-01-11 16:41:43 +0000368 return 0xffffffffffffffffULL;
Julien Grallc02e1ea2013-01-09 18:10:22 +0000369}
370
bellardf929aad2004-05-08 21:03:41 +0000371/* MSDOS compatibility mode FPU exception support */
Julien Grall258711c2012-09-19 12:50:08 +0100372static void ioportF0_write(void *opaque, hwaddr addr, uint64_t data,
373 unsigned size)
bellardf929aad2004-05-08 21:03:41 +0000374{
Paolo Bonzini6f529b72019-10-16 10:18:10 +0200375 if (tcg_enabled()) {
Paolo Bonzinibf13bfa2019-10-16 10:34:39 +0200376 cpu_set_ignne();
Paolo Bonzini6f529b72019-10-16 10:18:10 +0200377 }
bellardf929aad2004-05-08 21:03:41 +0000378}
379
Julien Grallc02e1ea2013-01-09 18:10:22 +0000380static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size)
381{
Julien Gralla6fc23e2013-01-11 16:41:43 +0000382 return 0xffffffffffffffffULL;
Julien Grallc02e1ea2013-01-09 18:10:22 +0000383}
384
bellardb0a21b52004-03-31 18:58:38 +0000385/* PC cmos mappings */
386
bellard80cabfa2004-03-14 12:20:30 +0000387#define REG_EQUIPMENT_BYTE 0x14
388
Roman Kaganbda05502016-02-17 21:25:31 +0300389int cmos_get_fd_drive_type(FloppyDriveType fd0)
bellard777428f2004-05-23 16:26:20 +0000390{
391 int val;
392
393 switch (fd0) {
John Snow2da44dd2016-01-22 15:50:56 -0500394 case FLOPPY_DRIVE_TYPE_144:
bellard777428f2004-05-23 16:26:20 +0000395 /* 1.44 Mb 3"5 drive */
396 val = 4;
397 break;
John Snow2da44dd2016-01-22 15:50:56 -0500398 case FLOPPY_DRIVE_TYPE_288:
bellard777428f2004-05-23 16:26:20 +0000399 /* 2.88 Mb 3"5 drive */
400 val = 5;
401 break;
John Snow2da44dd2016-01-22 15:50:56 -0500402 case FLOPPY_DRIVE_TYPE_120:
bellard777428f2004-05-23 16:26:20 +0000403 /* 1.2 Mb 5"5 drive */
404 val = 2;
405 break;
John Snow2da44dd2016-01-22 15:50:56 -0500406 case FLOPPY_DRIVE_TYPE_NONE:
bellard777428f2004-05-23 16:26:20 +0000407 default:
408 val = 0;
409 break;
410 }
411 return val;
412}
413
Markus Armbruster91390462012-07-10 11:12:38 +0200414static void cmos_init_hd(ISADevice *s, int type_ofs, int info_ofs,
415 int16_t cylinders, int8_t heads, int8_t sectors)
bellardba6c2372004-10-09 16:47:59 +0000416{
bellardba6c2372004-10-09 16:47:59 +0000417 rtc_set_memory(s, type_ofs, 47);
418 rtc_set_memory(s, info_ofs, cylinders);
419 rtc_set_memory(s, info_ofs + 1, cylinders >> 8);
420 rtc_set_memory(s, info_ofs + 2, heads);
421 rtc_set_memory(s, info_ofs + 3, 0xff);
422 rtc_set_memory(s, info_ofs + 4, 0xff);
423 rtc_set_memory(s, info_ofs + 5, 0xc0 | ((heads > 8) << 3));
424 rtc_set_memory(s, info_ofs + 6, cylinders);
425 rtc_set_memory(s, info_ofs + 7, cylinders >> 8);
426 rtc_set_memory(s, info_ofs + 8, sectors);
427}
428
balrog6ac0e822007-10-31 01:54:04 +0000429/* convert boot_device letter to something recognizable by the bios */
430static int boot_device2nibble(char boot_device)
431{
432 switch(boot_device) {
433 case 'a':
434 case 'b':
435 return 0x01; /* floppy boot */
436 case 'c':
437 return 0x02; /* hard drive boot */
438 case 'd':
439 return 0x03; /* CD-ROM boot */
440 case 'n':
441 return 0x04; /* Network boot */
442 }
443 return 0;
444}
445
Gongleiddcd5532014-12-03 19:04:02 +0000446static void set_boot_dev(ISADevice *s, const char *boot_device, Error **errp)
aurel320ecdffb2008-05-04 20:11:34 +0000447{
448#define PC_MAX_BOOT_DEVICES 3
aurel320ecdffb2008-05-04 20:11:34 +0000449 int nbds, bds[3] = { 0, };
450 int i;
451
452 nbds = strlen(boot_device);
453 if (nbds > PC_MAX_BOOT_DEVICES) {
Gongleiddcd5532014-12-03 19:04:02 +0000454 error_setg(errp, "Too many boot devices for PC");
455 return;
aurel320ecdffb2008-05-04 20:11:34 +0000456 }
457 for (i = 0; i < nbds; i++) {
458 bds[i] = boot_device2nibble(boot_device[i]);
459 if (bds[i] == 0) {
Gongleiddcd5532014-12-03 19:04:02 +0000460 error_setg(errp, "Invalid boot device for PC: '%c'",
461 boot_device[i]);
462 return;
aurel320ecdffb2008-05-04 20:11:34 +0000463 }
464 }
465 rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]);
Markus Armbrusterd9346e82010-02-17 18:07:48 +0100466 rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1));
aurel320ecdffb2008-05-04 20:11:34 +0000467}
468
Gongleiddcd5532014-12-03 19:04:02 +0000469static void pc_boot_set(void *opaque, const char *boot_device, Error **errp)
Markus Armbrusterd9346e82010-02-17 18:07:48 +0100470{
Gongleiddcd5532014-12-03 19:04:02 +0000471 set_boot_dev(opaque, boot_device, errp);
Markus Armbrusterd9346e82010-02-17 18:07:48 +0100472}
473
Laszlo Ersek7444ca42015-06-25 15:35:05 +0200474static void pc_cmos_init_floppy(ISADevice *rtc_state, ISADevice *floppy)
475{
476 int val, nb, i;
John Snow2da44dd2016-01-22 15:50:56 -0500477 FloppyDriveType fd_type[2] = { FLOPPY_DRIVE_TYPE_NONE,
478 FLOPPY_DRIVE_TYPE_NONE };
Laszlo Ersek7444ca42015-06-25 15:35:05 +0200479
480 /* floppy type */
481 if (floppy) {
482 for (i = 0; i < 2; i++) {
483 fd_type[i] = isa_fdc_get_drive_type(floppy, i);
484 }
485 }
486 val = (cmos_get_fd_drive_type(fd_type[0]) << 4) |
487 cmos_get_fd_drive_type(fd_type[1]);
488 rtc_set_memory(rtc_state, 0x10, val);
489
490 val = rtc_get_memory(rtc_state, REG_EQUIPMENT_BYTE);
491 nb = 0;
John Snow2da44dd2016-01-22 15:50:56 -0500492 if (fd_type[0] != FLOPPY_DRIVE_TYPE_NONE) {
Laszlo Ersek7444ca42015-06-25 15:35:05 +0200493 nb++;
494 }
John Snow2da44dd2016-01-22 15:50:56 -0500495 if (fd_type[1] != FLOPPY_DRIVE_TYPE_NONE) {
Laszlo Ersek7444ca42015-06-25 15:35:05 +0200496 nb++;
497 }
498 switch (nb) {
499 case 0:
500 break;
501 case 1:
502 val |= 0x01; /* 1 drive, ready for boot */
503 break;
504 case 2:
505 val |= 0x41; /* 2 drives, ready for boot */
506 break;
507 }
508 rtc_set_memory(rtc_state, REG_EQUIPMENT_BYTE, val);
509}
510
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200511typedef struct pc_cmos_init_late_arg {
512 ISADevice *rtc_state;
Markus Armbruster91390462012-07-10 11:12:38 +0200513 BusState *idebus[2];
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200514} pc_cmos_init_late_arg;
515
Laszlo Ersekb86f4612015-06-25 15:35:06 +0200516typedef struct check_fdc_state {
517 ISADevice *floppy;
518 bool multiple;
519} CheckFdcState;
520
521static int check_fdc(Object *obj, void *opaque)
522{
523 CheckFdcState *state = opaque;
524 Object *fdc;
525 uint32_t iobase;
526 Error *local_err = NULL;
527
528 fdc = object_dynamic_cast(obj, TYPE_ISA_FDC);
529 if (!fdc) {
530 return 0;
531 }
532
Marc-André Lureau1ea15722017-06-07 20:36:22 +0400533 iobase = object_property_get_uint(obj, "iobase", &local_err);
Laszlo Ersekb86f4612015-06-25 15:35:06 +0200534 if (local_err || iobase != 0x3f0) {
535 error_free(local_err);
536 return 0;
537 }
538
539 if (state->floppy) {
540 state->multiple = true;
541 } else {
542 state->floppy = ISA_DEVICE(obj);
543 }
544 return 0;
545}
546
547static const char * const fdc_container_path[] = {
548 "/unattached", "/peripheral", "/peripheral-anon"
549};
550
Roman Kagan424e4a82015-12-30 23:11:51 +0300551/*
552 * Locate the FDC at IO address 0x3f0, in order to configure the CMOS registers
553 * and ACPI objects.
554 */
555ISADevice *pc_find_fdc0(void)
556{
557 int i;
558 Object *container;
559 CheckFdcState state = { 0 };
560
561 for (i = 0; i < ARRAY_SIZE(fdc_container_path); i++) {
562 container = container_get(qdev_get_machine(), fdc_container_path[i]);
563 object_child_foreach(container, check_fdc, &state);
564 }
565
566 if (state.multiple) {
Alistair Francis3dc6f862017-07-12 06:57:41 -0700567 warn_report("multiple floppy disk controllers with "
568 "iobase=0x3f0 have been found");
Markus Armbruster433672b2015-12-18 16:35:24 +0100569 error_printf("the one being picked for CMOS setup might not reflect "
Alistair Francis9e5d2c52017-09-11 12:52:43 -0700570 "your intent");
Roman Kagan424e4a82015-12-30 23:11:51 +0300571 }
572
573 return state.floppy;
574}
575
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200576static void pc_cmos_init_late(void *opaque)
577{
578 pc_cmos_init_late_arg *arg = opaque;
579 ISADevice *s = arg->rtc_state;
Markus Armbruster91390462012-07-10 11:12:38 +0200580 int16_t cylinders;
581 int8_t heads, sectors;
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200582 int val;
Markus Armbruster2adc99b2012-07-10 11:12:53 +0200583 int i, trans;
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200584
Markus Armbruster91390462012-07-10 11:12:38 +0200585 val = 0;
Chao Peng272f0422016-11-05 03:19:49 -0400586 if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 0,
587 &cylinders, &heads, &sectors) >= 0) {
Markus Armbruster91390462012-07-10 11:12:38 +0200588 cmos_init_hd(s, 0x19, 0x1b, cylinders, heads, sectors);
589 val |= 0xf0;
590 }
Chao Peng272f0422016-11-05 03:19:49 -0400591 if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 1,
592 &cylinders, &heads, &sectors) >= 0) {
Markus Armbruster91390462012-07-10 11:12:38 +0200593 cmos_init_hd(s, 0x1a, 0x24, cylinders, heads, sectors);
594 val |= 0x0f;
595 }
596 rtc_set_memory(s, 0x12, val);
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200597
598 val = 0;
599 for (i = 0; i < 4; i++) {
Markus Armbruster91390462012-07-10 11:12:38 +0200600 /* NOTE: ide_get_geometry() returns the physical
601 geometry. It is always such that: 1 <= sects <= 63, 1
602 <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
603 geometry can be different if a translation is done. */
Chao Peng272f0422016-11-05 03:19:49 -0400604 if (arg->idebus[i / 2] &&
605 ide_get_geometry(arg->idebus[i / 2], i % 2,
Markus Armbruster91390462012-07-10 11:12:38 +0200606 &cylinders, &heads, &sectors) >= 0) {
Markus Armbruster2adc99b2012-07-10 11:12:53 +0200607 trans = ide_get_bios_chs_trans(arg->idebus[i / 2], i % 2) - 1;
608 assert((trans & ~3) == 0);
609 val |= trans << (i * 2);
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200610 }
611 }
612 rtc_set_memory(s, 0x39, val);
613
Roman Kagan424e4a82015-12-30 23:11:51 +0300614 pc_cmos_init_floppy(s, pc_find_fdc0());
Laszlo Ersekb86f4612015-06-25 15:35:06 +0200615
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200616 qemu_unregister_reset(pc_cmos_init_late, opaque);
617}
618
Eduardo Habkost23d30402015-08-07 16:55:49 -0300619void pc_cmos_init(PCMachineState *pcms,
Laszlo Ersek220a8842015-06-25 15:35:07 +0200620 BusState *idebus0, BusState *idebus1,
Blue Swirl63ffb562011-02-05 16:32:23 +0000621 ISADevice *s)
bellard80cabfa2004-03-14 12:20:30 +0000622{
Laszlo Ersek7444ca42015-06-25 15:35:05 +0200623 int val;
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200624 static pc_cmos_init_late_arg arg;
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200625 X86MachineState *x86ms = X86_MACHINE(pcms);
bellard80cabfa2004-03-14 12:20:30 +0000626
bellardb0a21b52004-03-31 18:58:38 +0000627 /* various important CMOS locations needed by PC/Bochs bios */
bellard80cabfa2004-03-14 12:20:30 +0000628
629 /* memory size */
Markus Armbrustere89001f2012-08-15 13:12:20 +0200630 /* base memory (first MiB) */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200631 val = MIN(x86ms->below_4g_mem_size / KiB, 640);
bellard333190e2004-04-07 20:51:30 +0000632 rtc_set_memory(s, 0x15, val);
633 rtc_set_memory(s, 0x16, val >> 8);
Markus Armbrustere89001f2012-08-15 13:12:20 +0200634 /* extended memory (next 64MiB) */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200635 if (x86ms->below_4g_mem_size > 1 * MiB) {
636 val = (x86ms->below_4g_mem_size - 1 * MiB) / KiB;
Markus Armbrustere89001f2012-08-15 13:12:20 +0200637 } else {
638 val = 0;
639 }
bellard80cabfa2004-03-14 12:20:30 +0000640 if (val > 65535)
641 val = 65535;
bellardb0a21b52004-03-31 18:58:38 +0000642 rtc_set_memory(s, 0x17, val);
643 rtc_set_memory(s, 0x18, val >> 8);
644 rtc_set_memory(s, 0x30, val);
645 rtc_set_memory(s, 0x31, val >> 8);
Markus Armbrustere89001f2012-08-15 13:12:20 +0200646 /* memory between 16MiB and 4GiB */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200647 if (x86ms->below_4g_mem_size > 16 * MiB) {
648 val = (x86ms->below_4g_mem_size - 16 * MiB) / (64 * KiB);
Markus Armbrustere89001f2012-08-15 13:12:20 +0200649 } else {
bellard9da98862004-06-26 15:53:17 +0000650 val = 0;
Markus Armbrustere89001f2012-08-15 13:12:20 +0200651 }
bellard80cabfa2004-03-14 12:20:30 +0000652 if (val > 65535)
653 val = 65535;
bellardb0a21b52004-03-31 18:58:38 +0000654 rtc_set_memory(s, 0x34, val);
655 rtc_set_memory(s, 0x35, val >> 8);
Markus Armbrustere89001f2012-08-15 13:12:20 +0200656 /* memory above 4GiB */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200657 val = x86ms->above_4g_mem_size / 65536;
Markus Armbrustere89001f2012-08-15 13:12:20 +0200658 rtc_set_memory(s, 0x5b, val);
659 rtc_set_memory(s, 0x5c, val >> 8);
660 rtc_set_memory(s, 0x5d, val >> 16);
ths3b46e622007-09-17 08:09:54 +0000661
Eduardo Habkost23d30402015-08-07 16:55:49 -0300662 object_property_add_link(OBJECT(pcms), "rtc_state",
Gu Zheng2d996152014-10-22 11:24:29 +0800663 TYPE_ISA_DEVICE,
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200664 (Object **)&x86ms->rtc,
Gu Zheng2d996152014-10-22 11:24:29 +0800665 object_property_allow_set_link,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200666 OBJ_PROP_LINK_STRONG);
Eduardo Habkost23d30402015-08-07 16:55:49 -0300667 object_property_set_link(OBJECT(pcms), OBJECT(s),
Gu Zheng2d996152014-10-22 11:24:29 +0800668 "rtc_state", &error_abort);
aurel32298e01b2008-03-28 22:28:08 +0000669
Markus Armbruster007b0652015-09-11 15:04:45 +0200670 set_boot_dev(s, MACHINE(pcms)->boot_order, &error_fatal);
bellard80cabfa2004-03-14 12:20:30 +0000671
bellardb0a21b52004-03-31 18:58:38 +0000672 val = 0;
bellardb0a21b52004-03-31 18:58:38 +0000673 val |= 0x02; /* FPU is there */
674 val |= 0x04; /* PS/2 mouse installed */
675 rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);
676
Laszlo Ersekb86f4612015-06-25 15:35:06 +0200677 /* hard drives and FDC */
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200678 arg.rtc_state = s;
Markus Armbruster91390462012-07-10 11:12:38 +0200679 arg.idebus[0] = idebus0;
680 arg.idebus[1] = idebus1;
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200681 qemu_register_reset(pc_cmos_init_late, &arg);
bellard80cabfa2004-03-14 12:20:30 +0000682}
683
Blue Swirl956a3e62010-05-22 07:59:01 +0000684static void handle_a20_line_change(void *opaque, int irq, int level)
bellard59b8ad82005-11-21 23:34:32 +0000685{
Andreas Färbercc36a7a2013-01-18 15:19:06 +0100686 X86CPU *cpu = opaque;
Blue Swirl956a3e62010-05-22 07:59:01 +0000687
bellard59b8ad82005-11-21 23:34:32 +0000688 /* XXX: send to all CPUs ? */
Blue Swirl4b78a802011-01-06 18:24:35 +0000689 /* XXX: add logic to handle multiple A20 line sources */
Andreas Färbercc36a7a2013-01-18 15:19:06 +0100690 x86_cpu_set_a20(cpu, level);
bellarde1a23742004-04-05 20:26:03 +0000691}
692
bellardb41a2cd2004-03-14 21:46:48 +0000693#define NE2000_NB_MAX 6
694
Blue Swirl675d6f82009-09-13 08:32:37 +0000695static const int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360,
696 0x280, 0x380 };
697static const int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
bellardb41a2cd2004-03-14 21:46:48 +0000698
Hervé Poussineau48a18b32011-12-15 22:09:51 +0100699void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd)
pbrooka41b2ff2006-02-05 04:14:41 +0000700{
701 static int nb_ne2k = 0;
702
703 if (nb_ne2k == NE2000_NB_MAX)
704 return;
Hervé Poussineau48a18b32011-12-15 22:09:51 +0100705 isa_ne2000_init(bus, ne2000_io[nb_ne2k],
Gerd Hoffmann9453c5b2009-09-10 11:43:33 +0200706 ne2000_irq[nb_ne2k], nd);
pbrooka41b2ff2006-02-05 04:14:41 +0000707 nb_ne2k++;
708}
709
Isaku Yamahata845773a2010-05-14 16:29:15 +0900710void pc_acpi_smi_interrupt(void *opaque, int irq, int level)
Blue Swirl53b67b32010-03-29 19:23:52 +0000711{
Andreas Färberc3affe52013-01-18 15:03:43 +0100712 X86CPU *cpu = opaque;
Blue Swirl53b67b32010-03-29 19:23:52 +0000713
714 if (level) {
Andreas Färberc3affe52013-01-18 15:03:43 +0100715 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_SMI);
Blue Swirl53b67b32010-03-29 19:23:52 +0000716 }
717}
718
Like Xu6f479562019-06-20 13:45:24 +0800719/*
720 * This function is very similar to smp_parse()
721 * in hw/core/machine.c but includes CPU die support.
722 */
723void pc_smp_parse(MachineState *ms, QemuOpts *opts)
724{
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200725 X86MachineState *x86ms = X86_MACHINE(ms);
Like Xu1b458422019-06-20 13:45:25 +0800726
Like Xu6f479562019-06-20 13:45:24 +0800727 if (opts) {
728 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
729 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
Like Xu1b458422019-06-20 13:45:25 +0800730 unsigned dies = qemu_opt_get_number(opts, "dies", 1);
Like Xu6f479562019-06-20 13:45:24 +0800731 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
732 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
733
734 /* compute missing values, prefer sockets over cores over threads */
735 if (cpus == 0 || sockets == 0) {
736 cores = cores > 0 ? cores : 1;
737 threads = threads > 0 ? threads : 1;
738 if (cpus == 0) {
739 sockets = sockets > 0 ? sockets : 1;
Like Xu1b458422019-06-20 13:45:25 +0800740 cpus = cores * threads * dies * sockets;
Like Xu6f479562019-06-20 13:45:24 +0800741 } else {
742 ms->smp.max_cpus =
743 qemu_opt_get_number(opts, "maxcpus", cpus);
Like Xu1b458422019-06-20 13:45:25 +0800744 sockets = ms->smp.max_cpus / (cores * threads * dies);
Like Xu6f479562019-06-20 13:45:24 +0800745 }
746 } else if (cores == 0) {
747 threads = threads > 0 ? threads : 1;
Like Xu1b458422019-06-20 13:45:25 +0800748 cores = cpus / (sockets * dies * threads);
Like Xu6f479562019-06-20 13:45:24 +0800749 cores = cores > 0 ? cores : 1;
750 } else if (threads == 0) {
Like Xu1b458422019-06-20 13:45:25 +0800751 threads = cpus / (cores * dies * sockets);
Like Xu6f479562019-06-20 13:45:24 +0800752 threads = threads > 0 ? threads : 1;
Like Xu1b458422019-06-20 13:45:25 +0800753 } else if (sockets * dies * cores * threads < cpus) {
Like Xu6f479562019-06-20 13:45:24 +0800754 error_report("cpu topology: "
Like Xu1b458422019-06-20 13:45:25 +0800755 "sockets (%u) * dies (%u) * cores (%u) * threads (%u) < "
Like Xu6f479562019-06-20 13:45:24 +0800756 "smp_cpus (%u)",
Like Xu1b458422019-06-20 13:45:25 +0800757 sockets, dies, cores, threads, cpus);
Like Xu6f479562019-06-20 13:45:24 +0800758 exit(1);
759 }
760
761 ms->smp.max_cpus =
762 qemu_opt_get_number(opts, "maxcpus", cpus);
763
764 if (ms->smp.max_cpus < cpus) {
765 error_report("maxcpus must be equal to or greater than smp");
766 exit(1);
767 }
768
Like Xu1b458422019-06-20 13:45:25 +0800769 if (sockets * dies * cores * threads > ms->smp.max_cpus) {
Like Xu6f479562019-06-20 13:45:24 +0800770 error_report("cpu topology: "
Like Xu1b458422019-06-20 13:45:25 +0800771 "sockets (%u) * dies (%u) * cores (%u) * threads (%u) > "
Like Xu6f479562019-06-20 13:45:24 +0800772 "maxcpus (%u)",
Like Xu1b458422019-06-20 13:45:25 +0800773 sockets, dies, cores, threads,
Like Xu6f479562019-06-20 13:45:24 +0800774 ms->smp.max_cpus);
775 exit(1);
776 }
777
Like Xu1b458422019-06-20 13:45:25 +0800778 if (sockets * dies * cores * threads != ms->smp.max_cpus) {
Like Xu6f479562019-06-20 13:45:24 +0800779 warn_report("Invalid CPU topology deprecated: "
Like Xu1b458422019-06-20 13:45:25 +0800780 "sockets (%u) * dies (%u) * cores (%u) * threads (%u) "
Like Xu6f479562019-06-20 13:45:24 +0800781 "!= maxcpus (%u)",
Like Xu1b458422019-06-20 13:45:25 +0800782 sockets, dies, cores, threads,
Like Xu6f479562019-06-20 13:45:24 +0800783 ms->smp.max_cpus);
784 }
785
786 ms->smp.cpus = cpus;
787 ms->smp.cores = cores;
788 ms->smp.threads = threads;
Babu Moger8cb30e32020-03-11 17:53:06 -0500789 ms->smp.sockets = sockets;
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200790 x86ms->smp_dies = dies;
Like Xu6f479562019-06-20 13:45:24 +0800791 }
792
793 if (ms->smp.cpus > 1) {
794 Error *blocker = NULL;
795 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
796 replay_add_blocker(blocker);
797 }
798}
799
Like Xua0628592019-05-19 04:54:20 +0800800void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp)
Igor Mammedovc6499832013-04-30 18:00:53 +0200801{
Sergio Lopez703a5482019-09-30 17:26:29 +0200802 X86MachineState *x86ms = X86_MACHINE(ms);
803 int64_t apic_id = x86_cpu_apic_id_from_index(x86ms, id);
Andreas Färber0e3bd562015-03-17 17:46:36 +0100804 Error *local_err = NULL;
Igor Mammedovc6499832013-04-30 18:00:53 +0200805
Igor Mammedov8de433c2013-05-30 17:09:34 +0200806 if (id < 0) {
807 error_setg(errp, "Invalid CPU id: %" PRIi64, id);
808 return;
809 }
810
Eduardo Habkost5ff020b2014-03-14 16:33:51 -0300811 if (apic_id >= ACPI_CPU_HOTPLUG_ID_LIMIT) {
812 error_setg(errp, "Unable to add CPU: %" PRIi64
813 ", resulting APIC ID (%" PRIi64 ") is too large",
814 id, apic_id);
815 return;
816 }
817
Sergio Lopez703a5482019-09-30 17:26:29 +0200818
819 x86_cpu_new(X86_MACHINE(ms), apic_id, &local_err);
Andreas Färber0e3bd562015-03-17 17:46:36 +0100820 if (local_err) {
821 error_propagate(errp, local_err);
822 return;
823 }
Igor Mammedovc6499832013-04-30 18:00:53 +0200824}
825
Igor Mammedove3cadac2016-11-16 14:04:41 +0100826static void rtc_set_cpus_count(ISADevice *rtc, uint16_t cpus_count)
827{
828 if (cpus_count > 0xff) {
829 /* If the number of CPUs can't be represented in 8 bits, the
830 * BIOS must use "FW_CFG_NB_CPUS". Set RTC field to 0 just
831 * to make old BIOSes fail more predictably.
832 */
833 rtc_set_memory(rtc, 0x5f, 0);
834 } else {
835 rtc_set_memory(rtc, 0x5f, cpus_count - 1);
836 }
837}
838
Michael S. Tsirkin3459a622013-05-30 12:57:26 +0300839static
Eduardo Habkost9ebeed02015-12-11 16:42:23 -0200840void pc_machine_done(Notifier *notifier, void *data)
Michael S. Tsirkin3459a622013-05-30 12:57:26 +0300841{
Eduardo Habkost9ebeed02015-12-11 16:42:23 -0200842 PCMachineState *pcms = container_of(notifier,
843 PCMachineState, machine_done);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200844 X86MachineState *x86ms = X86_MACHINE(pcms);
Eduardo Habkost9ebeed02015-12-11 16:42:23 -0200845 PCIBus *bus = pcms->bus;
Marcel Apfelbaum21181962015-06-02 14:23:07 +0300846
Igor Mammedovba157b62016-07-14 18:54:31 +0200847 /* set the number of CPUs */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200848 rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus);
Igor Mammedovba157b62016-07-14 18:54:31 +0200849
Marcel Apfelbaum21181962015-06-02 14:23:07 +0300850 if (bus) {
851 int extra_hosts = 0;
852
853 QLIST_FOREACH(bus, &bus->child, sibling) {
854 /* look for expander root buses */
855 if (pci_bus_is_root(bus)) {
856 extra_hosts++;
857 }
858 }
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200859 if (extra_hosts && x86ms->fw_cfg) {
Marcel Apfelbaum21181962015-06-02 14:23:07 +0300860 uint64_t *val = g_malloc(sizeof(*val));
861 *val = cpu_to_le64(extra_hosts);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200862 fw_cfg_add_file(x86ms->fw_cfg,
Marcel Apfelbaum21181962015-06-02 14:23:07 +0300863 "etc/extra-pci-roots", val, sizeof(*val));
864 }
865 }
866
Eduardo Habkostbb292f52015-12-11 16:42:28 -0200867 acpi_setup();
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200868 if (x86ms->fw_cfg) {
869 fw_cfg_build_smbios(MACHINE(pcms), x86ms->fw_cfg);
870 fw_cfg_build_feature_control(MACHINE(pcms), x86ms->fw_cfg);
Igor Mammedove3cadac2016-11-16 14:04:41 +0100871 /* update FW_CFG_NB_CPUS to account for -device added CPUs */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200872 fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus);
Corey Minyard6d42eef2016-05-24 12:37:18 -0500873 }
Igor Mammedov60c5e102016-10-19 14:05:42 +0200874
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200875 if (x86ms->apic_id_limit > 255 && !xen_enabled()) {
Igor Mammedov60c5e102016-10-19 14:05:42 +0200876 IntelIOMMUState *iommu = INTEL_IOMMU_DEVICE(x86_iommu_get_default());
877
Peter Xua924b3d2018-12-20 13:40:36 +0800878 if (!iommu || !x86_iommu_ir_supported(X86_IOMMU_DEVICE(iommu)) ||
Igor Mammedov60c5e102016-10-19 14:05:42 +0200879 iommu->intr_eim != ON_OFF_AUTO_ON) {
880 error_report("current -smp configuration requires "
881 "Extended Interrupt Mode enabled. "
882 "You can add an IOMMU using: "
883 "-device intel-iommu,intremap=on,eim=on");
884 exit(EXIT_FAILURE);
885 }
886 }
Michael S. Tsirkin3459a622013-05-30 12:57:26 +0300887}
888
Eduardo Habkoste4e8ba02015-12-11 16:42:33 -0200889void pc_guest_info_init(PCMachineState *pcms)
Michael S. Tsirkin3459a622013-05-30 12:57:26 +0300890{
Igor Mammedov1f3aba32016-06-16 14:23:48 +0200891 int i;
Tao Xuaa570202019-08-09 14:57:22 +0800892 MachineState *ms = MACHINE(pcms);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200893 X86MachineState *x86ms = X86_MACHINE(pcms);
Michael S. Tsirkinb20c9bd2013-07-24 18:56:09 +0300894
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200895 x86ms->apic_xrupt_override = kvm_allows_irq0_override();
Tao Xuaa570202019-08-09 14:57:22 +0800896 pcms->numa_nodes = ms->numa_state->num_nodes;
Eduardo Habkostdd4c2f02015-12-11 16:42:32 -0200897 pcms->node_mem = g_malloc0(pcms->numa_nodes *
898 sizeof *pcms->node_mem);
Tao Xuaa570202019-08-09 14:57:22 +0800899 for (i = 0; i < ms->numa_state->num_nodes; i++) {
Tao Xu7e721e72019-08-09 14:57:24 +0800900 pcms->node_mem[i] = ms->numa_state->nodes[i].node_mem;
Wanlong Gao8c859012014-05-14 17:43:07 +0800901 }
902
Eduardo Habkost9ebeed02015-12-11 16:42:23 -0200903 pcms->machine_done.notify = pc_machine_done;
904 qemu_add_machine_init_done_notifier(&pcms->machine_done);
Michael S. Tsirkin3459a622013-05-30 12:57:26 +0300905}
906
Michael S. Tsirkin83d08f22013-10-29 13:57:34 +0100907/* setup pci memory address space mapping into system address space */
908void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory,
909 MemoryRegion *pci_address_space)
Igor Mammedov39848902013-07-29 16:47:57 +0200910{
Michael S. Tsirkin83d08f22013-10-29 13:57:34 +0100911 /* Set to lower priority than RAM */
912 memory_region_add_subregion_overlap(system_memory, 0x0,
913 pci_address_space, -1);
Igor Mammedov39848902013-07-29 16:47:57 +0200914}
915
Eduardo Habkost7bc35e02015-12-11 16:42:25 -0200916void xen_load_linux(PCMachineState *pcms)
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800917{
918 int i;
919 FWCfgState *fw_cfg;
Sergio Lopez703a5482019-09-30 17:26:29 +0200920 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200921 X86MachineState *x86ms = X86_MACHINE(pcms);
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800922
Eduardo Habkostdf1f79f2015-08-07 16:55:53 -0300923 assert(MACHINE(pcms)->kernel_filename != NULL);
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800924
Gabriel L. Somlo305ae882016-02-19 13:20:26 -0500925 fw_cfg = fw_cfg_init_io(FW_CFG_IO_BASE);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200926 fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus);
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800927 rom_set_fw(fw_cfg);
928
Sergio Lopez703a5482019-09-30 17:26:29 +0200929 x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
930 pcmc->pvh_enabled, pcmc->linuxboot_dma_enabled);
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800931 for (i = 0; i < nb_option_roms; i++) {
932 assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
Marc Maríb2a575a2016-05-23 19:11:33 +0100933 !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
Stefano Garzarella1fb0d702019-01-18 13:01:42 +0100934 !strcmp(option_rom[i].name, "pvh.bin") ||
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800935 !strcmp(option_rom[i].name, "multiboot.bin"));
936 rom_add_option(option_rom[i].name, option_rom[i].bootindex);
937 }
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200938 x86ms->fw_cfg = fw_cfg;
Chunyan Liub33a5bb2014-07-07 14:34:35 +0800939}
940
Eduardo Habkost5934e212015-12-11 16:42:24 -0200941void pc_memory_init(PCMachineState *pcms,
942 MemoryRegion *system_memory,
943 MemoryRegion *rom_memory,
944 MemoryRegion **ram_memory)
bellard80cabfa2004-03-14 12:20:30 +0000945{
Jordan Justencbc5b5f2012-02-21 23:18:51 -0800946 int linux_boot, i;
Igor Mammedovbd457782020-02-19 11:09:17 -0500947 MemoryRegion *option_rom_mr;
Avi Kivity00cb2a92011-07-26 14:26:17 +0300948 MemoryRegion *ram_below_4g, *ram_above_4g;
Laszlo Erseka88b3622013-04-16 02:24:08 +0200949 FWCfgState *fw_cfg;
Eduardo Habkost62b160c2015-08-07 16:55:50 -0300950 MachineState *machine = MACHINE(pcms);
Philippe Mathieu-Daudé264b4852019-08-19 00:54:06 +0200951 MachineClass *mc = MACHINE_GET_CLASS(machine);
Eduardo Habkost16a9e8a2015-12-01 20:58:06 -0200952 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200953 X86MachineState *x86ms = X86_MACHINE(pcms);
bellardd592d302005-07-23 19:05:37 +0000954
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200955 assert(machine->ram_size == x86ms->below_4g_mem_size +
956 x86ms->above_4g_mem_size);
Paolo Bonzini9521d422014-06-10 19:15:17 +0800957
958 linux_boot = (machine->kernel_filename != NULL);
bellard80cabfa2004-03-14 12:20:30 +0000959
Igor Mammedovbd457782020-02-19 11:09:17 -0500960 /*
961 * Split single memory region and use aliases to address portions of it,
962 * done for backwards compatibility with older qemus.
Avi Kivity00cb2a92011-07-26 14:26:17 +0300963 */
Igor Mammedovbd457782020-02-19 11:09:17 -0500964 *ram_memory = machine->ram;
Anthony Liguori7267c092011-08-20 22:09:37 -0500965 ram_below_4g = g_malloc(sizeof(*ram_below_4g));
Igor Mammedovbd457782020-02-19 11:09:17 -0500966 memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram,
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200967 0, x86ms->below_4g_mem_size);
Avi Kivity00cb2a92011-07-26 14:26:17 +0300968 memory_region_add_subregion(system_memory, 0, ram_below_4g);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200969 e820_add_entry(0, x86ms->below_4g_mem_size, E820_RAM);
970 if (x86ms->above_4g_mem_size > 0) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500971 ram_above_4g = g_malloc(sizeof(*ram_above_4g));
Igor Mammedovbd457782020-02-19 11:09:17 -0500972 memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g",
973 machine->ram,
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200974 x86ms->below_4g_mem_size,
975 x86ms->above_4g_mem_size);
Avi Kivity00cb2a92011-07-26 14:26:17 +0300976 memory_region_add_subregion(system_memory, 0x100000000ULL,
977 ram_above_4g);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +0200978 e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM);
Alex Williamsonbbe80ad2010-07-06 10:37:17 -0600979 }
aliguori82b36dc2008-09-15 16:01:01 +0000980
Eduardo Habkostbb292f52015-12-11 16:42:28 -0200981 if (!pcmc->has_reserved_memory &&
Igor Mammedovca8336f2014-06-02 15:25:11 +0200982 (machine->ram_slots ||
Paolo Bonzini9521d422014-06-10 19:15:17 +0800983 (machine->maxram_size > machine->ram_size))) {
Igor Mammedovca8336f2014-06-02 15:25:11 +0200984
985 error_report("\"-memory 'slots|maxmem'\" is not supported by: %s",
986 mc->name);
987 exit(EXIT_FAILURE);
988 }
989
David Hildenbrandb0c14ec2018-04-23 18:51:17 +0200990 /* always allocate the device memory information */
991 machine->device_memory = g_malloc0(sizeof(*machine->device_memory));
992
David Hildenbrandf2ffbe22018-04-23 18:51:24 +0200993 /* initialize device memory address space */
Eduardo Habkostbb292f52015-12-11 16:42:28 -0200994 if (pcmc->has_reserved_memory &&
Paolo Bonzini9521d422014-06-10 19:15:17 +0800995 (machine->ram_size < machine->maxram_size)) {
David Hildenbrandf2ffbe22018-04-23 18:51:24 +0200996 ram_addr_t device_mem_size = machine->maxram_size - machine->ram_size;
Igor Mammedov619d11e2014-06-02 15:25:08 +0200997
Igor Mammedova0cc8852014-06-02 15:25:09 +0200998 if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) {
999 error_report("unsupported amount of memory slots: %"PRIu64,
1000 machine->ram_slots);
1001 exit(EXIT_FAILURE);
1002 }
1003
Peter Krempaf2c38522015-01-29 14:48:41 +01001004 if (QEMU_ALIGN_UP(machine->maxram_size,
1005 TARGET_PAGE_SIZE) != machine->maxram_size) {
1006 error_report("maximum memory size must by aligned to multiple of "
1007 "%d bytes", TARGET_PAGE_SIZE);
1008 exit(EXIT_FAILURE);
1009 }
1010
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001011 machine->device_memory->base =
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001012 ROUND_UP(0x100000000ULL + x86ms->above_4g_mem_size, 1 * GiB);
Igor Mammedov619d11e2014-06-02 15:25:08 +02001013
Eduardo Habkost16a9e8a2015-12-01 20:58:06 -02001014 if (pcmc->enforce_aligned_dimm) {
David Hildenbrandf2ffbe22018-04-23 18:51:24 +02001015 /* size device region assuming 1G page max alignment per slot */
Paolo Bonzinid471bf32018-06-29 16:22:13 +02001016 device_mem_size += (1 * GiB) * machine->ram_slots;
Igor Mammedov085f8e82014-10-31 16:38:42 +00001017 }
1018
David Hildenbrandf2ffbe22018-04-23 18:51:24 +02001019 if ((machine->device_memory->base + device_mem_size) <
1020 device_mem_size) {
Igor Mammedov619d11e2014-06-02 15:25:08 +02001021 error_report("unsupported amount of maximum memory: " RAM_ADDR_FMT,
1022 machine->maxram_size);
1023 exit(EXIT_FAILURE);
1024 }
1025
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001026 memory_region_init(&machine->device_memory->mr, OBJECT(pcms),
David Hildenbrandf2ffbe22018-04-23 18:51:24 +02001027 "device-memory", device_mem_size);
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001028 memory_region_add_subregion(system_memory, machine->device_memory->base,
1029 &machine->device_memory->mr);
Igor Mammedov619d11e2014-06-02 15:25:08 +02001030 }
Jordan Justencbc5b5f2012-02-21 23:18:51 -08001031
1032 /* Initialize PC system firmware */
Philippe Mathieu-Daudé5e640a92019-03-08 14:14:43 +01001033 pc_system_firmware_init(pcms, rom_memory);
ths9ae02552007-01-05 17:39:04 +00001034
Anthony Liguori7267c092011-08-20 22:09:37 -05001035 option_rom_mr = g_malloc(sizeof(*option_rom_mr));
Peter Maydell98a99ce2017-07-07 15:42:53 +01001036 memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
Markus Armbrusterf8ed85a2015-09-11 16:51:43 +02001037 &error_fatal);
Igor Mammedov208fa0e2017-07-28 11:09:05 +02001038 if (pcmc->pci_enabled) {
1039 memory_region_set_readonly(option_rom_mr, true);
1040 }
Jan Kiszka4463aee2011-09-21 20:49:29 +02001041 memory_region_add_subregion_overlap(rom_memory,
Avi Kivity00cb2a92011-07-26 14:26:17 +03001042 PC_ROM_MIN_VGA,
1043 option_rom_mr,
1044 1);
pbrookf753ff12009-04-09 20:59:05 +00001045
Paolo Bonzinibd802bd2019-09-16 12:42:42 +02001046 fw_cfg = fw_cfg_arch_create(machine,
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001047 x86ms->boot_cpus, x86ms->apic_id_limit);
Marc Maríc886fc42015-10-08 17:02:57 +02001048
Gerd Hoffmann8832cb82010-01-08 15:25:40 +01001049 rom_set_fw(fw_cfg);
Alexander Graf1d108d92009-06-29 15:37:37 +02001050
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001051 if (pcmc->has_reserved_memory && machine->device_memory->base) {
Igor Mammedovde268e12014-06-02 15:25:10 +02001052 uint64_t *val = g_malloc(sizeof(*val));
Igor Mammedov2f8b5002015-09-07 13:55:32 +02001053 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001054 uint64_t res_mem_end = machine->device_memory->base;
Igor Mammedov2f8b5002015-09-07 13:55:32 +02001055
1056 if (!pcmc->broken_reserved_end) {
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001057 res_mem_end += memory_region_size(&machine->device_memory->mr);
Igor Mammedov2f8b5002015-09-07 13:55:32 +02001058 }
Paolo Bonzinid471bf32018-06-29 16:22:13 +02001059 *val = cpu_to_le64(ROUND_UP(res_mem_end, 1 * GiB));
Igor Mammedovde268e12014-06-02 15:25:10 +02001060 fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
1061 }
1062
pbrookf753ff12009-04-09 20:59:05 +00001063 if (linux_boot) {
Sergio Lopez703a5482019-09-30 17:26:29 +02001064 x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
1065 pcmc->pvh_enabled, pcmc->linuxboot_dma_enabled);
pbrookf753ff12009-04-09 20:59:05 +00001066 }
1067
1068 for (i = 0; i < nb_option_roms; i++) {
Gleb Natapov2e55e842010-12-08 13:35:07 +02001069 rom_add_option(option_rom[i].name, option_rom[i].bootindex);
Glauber Costa406c8df2009-06-17 09:05:30 -04001070 }
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001071 x86ms->fw_cfg = fw_cfg;
Peter Xucb135f52016-07-14 13:56:23 +08001072
1073 /* Init default IOAPIC address space */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001074 x86ms->ioapic_as = &address_space_memory;
Shameer Kolothum091c4662019-09-18 14:06:23 +01001075
1076 /* Init ACPI memory hotplug IO base address */
1077 pcms->memhp_io_base = ACPI_MEMORY_HOTPLUG_BASE;
Isaku Yamahata3d53f5c2010-05-14 16:29:11 +09001078}
1079
Marcel Apfelbaum9fa99d22017-11-11 17:25:00 +02001080/*
1081 * The 64bit pci hole starts after "above 4G RAM" and
1082 * potentially the space reserved for memory hotplug.
1083 */
1084uint64_t pc_pci_hole64_start(void)
1085{
1086 PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
1087 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001088 MachineState *ms = MACHINE(pcms);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001089 X86MachineState *x86ms = X86_MACHINE(pcms);
Marcel Apfelbaum9fa99d22017-11-11 17:25:00 +02001090 uint64_t hole64_start = 0;
1091
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001092 if (pcmc->has_reserved_memory && ms->device_memory->base) {
1093 hole64_start = ms->device_memory->base;
Marcel Apfelbaum9fa99d22017-11-11 17:25:00 +02001094 if (!pcmc->broken_reserved_end) {
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001095 hole64_start += memory_region_size(&ms->device_memory->mr);
Marcel Apfelbaum9fa99d22017-11-11 17:25:00 +02001096 }
1097 } else {
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001098 hole64_start = 0x100000000ULL + x86ms->above_4g_mem_size;
Marcel Apfelbaum9fa99d22017-11-11 17:25:00 +02001099 }
1100
Paolo Bonzinid471bf32018-06-29 16:22:13 +02001101 return ROUND_UP(hole64_start, 1 * GiB);
Marcel Apfelbaum9fa99d22017-11-11 17:25:00 +02001102}
1103
Hervé Poussineau48a18b32011-12-15 22:09:51 +01001104DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
Isaku Yamahata765d7902010-05-14 16:29:12 +09001105{
Anthony Liguoriad6d45f2011-12-12 14:29:41 -06001106 DeviceState *dev = NULL;
1107
Gerd Hoffmannbab47d92016-04-07 09:12:58 -05001108 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_VGA);
Aurelien Jarno16094b72012-09-08 12:47:45 +02001109 if (pci_bus) {
1110 PCIDevice *pcidev = pci_vga_init(pci_bus);
1111 dev = pcidev ? &pcidev->qdev : NULL;
1112 } else if (isa_bus) {
1113 ISADevice *isadev = isa_vga_init(isa_bus);
Andreas Färber4a17cc42013-06-07 13:49:13 +02001114 dev = isadev ? DEVICE(isadev) : NULL;
Isaku Yamahata765d7902010-05-14 16:29:12 +09001115 }
Gerd Hoffmannbab47d92016-04-07 09:12:58 -05001116 rom_reset_order_override();
Anthony Liguoriad6d45f2011-12-12 14:29:41 -06001117 return dev;
Isaku Yamahata765d7902010-05-14 16:29:12 +09001118}
1119
Julien Grall258711c2012-09-19 12:50:08 +01001120static const MemoryRegionOps ioport80_io_ops = {
1121 .write = ioport80_write,
Julien Grallc02e1ea2013-01-09 18:10:22 +00001122 .read = ioport80_read,
Julien Grall258711c2012-09-19 12:50:08 +01001123 .endianness = DEVICE_NATIVE_ENDIAN,
1124 .impl = {
1125 .min_access_size = 1,
1126 .max_access_size = 1,
1127 },
1128};
1129
1130static const MemoryRegionOps ioportF0_io_ops = {
1131 .write = ioportF0_write,
Julien Grallc02e1ea2013-01-09 18:10:22 +00001132 .read = ioportF0_read,
Julien Grall258711c2012-09-19 12:50:08 +01001133 .endianness = DEVICE_NATIVE_ENDIAN,
1134 .impl = {
1135 .min_access_size = 1,
1136 .max_access_size = 1,
1137 },
1138};
1139
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001140static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport)
1141{
1142 int i;
1143 DriveInfo *fd[MAX_FD];
1144 qemu_irq *a20_line;
1145 ISADevice *i8042, *port92, *vmmouse;
1146
Peter Maydelldef337f2018-04-20 15:52:46 +01001147 serial_hds_isa_init(isa_bus, 0, MAX_ISA_SERIAL_PORTS);
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001148 parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS);
1149
1150 for (i = 0; i < MAX_FD; i++) {
1151 fd[i] = drive_get(IF_FLOPPY, 0, i);
1152 create_fdctrl |= !!fd[i];
1153 }
1154 if (create_fdctrl) {
1155 fdctrl_init_isa(isa_bus, fd);
1156 }
1157
1158 i8042 = isa_create_simple(isa_bus, "i8042");
1159 if (!no_vmport) {
Philippe Mathieu-Daudéb4fa79e2020-05-04 10:33:39 +02001160 isa_create_simple(isa_bus, TYPE_VMPORT);
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001161 vmmouse = isa_try_create(isa_bus, "vmmouse");
1162 } else {
1163 vmmouse = NULL;
1164 }
1165 if (vmmouse) {
Marc-André Lureau0fe4bb32019-10-17 17:06:05 +02001166 object_property_set_link(OBJECT(vmmouse), OBJECT(i8042),
1167 "i8042", &error_abort);
1168 qdev_init_nofail(DEVICE(vmmouse));
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001169 }
Philippe Mathieu-Daudé9e5213c2019-12-13 11:50:58 +01001170 port92 = isa_create_simple(isa_bus, TYPE_PORT92);
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001171
1172 a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2);
1173 i8042_setup_a20_line(i8042, a20_line[0]);
Philippe Mathieu-Daudé1820b702019-12-13 11:50:59 +01001174 qdev_connect_gpio_out_named(DEVICE(port92),
1175 PORT92_A20_LINE, 0, a20_line[1]);
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001176 g_free(a20_line);
1177}
1178
Hervé Poussineau48a18b32011-12-15 22:09:51 +01001179void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
Anthony PERARD16119772011-05-03 17:06:54 +01001180 ISADevice **rtc_state,
Laszlo Ersekfd53c872015-05-28 22:04:08 +02001181 bool create_fdctrl,
Liu Ping Fan7a10ef52013-12-08 17:38:17 +08001182 bool no_vmport,
Chao Pengfeddd2f2016-11-05 03:19:50 -04001183 bool has_pit,
Peter Maydell3a87d002016-01-22 15:09:21 +00001184 uint32_t hpet_irqs)
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001185{
1186 int i;
Jan Kiszkace967e22012-02-01 20:31:41 +01001187 DeviceState *hpet = NULL;
1188 int pit_isa_irq = 0;
1189 qemu_irq pit_alt_irq = NULL;
Jan Kiszka7d932df2010-06-13 14:15:40 +02001190 qemu_irq rtc_irq = NULL;
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001191 ISADevice *pit = NULL;
Julien Grall258711c2012-09-19 12:50:08 +01001192 MemoryRegion *ioport80_io = g_new(MemoryRegion, 1);
1193 MemoryRegion *ioportF0_io = g_new(MemoryRegion, 1);
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001194
Paolo Bonzini2c9b15c2013-06-06 05:41:28 -04001195 memory_region_init_io(ioport80_io, NULL, &ioport80_io_ops, NULL, "ioport80", 1);
Julien Grall258711c2012-09-19 12:50:08 +01001196 memory_region_add_subregion(isa_bus->address_space_io, 0x80, ioport80_io);
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001197
Paolo Bonzini2c9b15c2013-06-06 05:41:28 -04001198 memory_region_init_io(ioportF0_io, NULL, &ioportF0_io_ops, NULL, "ioportF0", 1);
Julien Grall258711c2012-09-19 12:50:08 +01001199 memory_region_add_subregion(isa_bus->address_space_io, 0xf0, ioportF0_io);
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001200
Jan Kiszka5d17c0d2012-03-02 20:28:49 +01001201 /*
1202 * Check if an HPET shall be created.
1203 *
1204 * Without KVM_CAP_PIT_STATE2, we cannot switch off the in-kernel PIT
1205 * when the HPET wants to take over. Thus we have to disable the latter.
1206 */
1207 if (!no_hpet && (!kvm_irqchip_in_kernel() || kvm_has_pit_state2())) {
Michael S. Tsirkin51116102013-12-11 02:48:49 +02001208 hpet = qdev_try_create(NULL, TYPE_HPET);
Blue Swirldd703b92011-02-05 14:35:00 +00001209 if (hpet) {
Liu Ping Fan7a10ef52013-12-08 17:38:17 +08001210 /* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7
1211 * and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23,
1212 * IRQ8 and IRQ2.
1213 */
Marc-André Lureau5d7fb0f2017-06-07 20:36:24 +04001214 uint8_t compat = object_property_get_uint(OBJECT(hpet),
Liu Ping Fan7a10ef52013-12-08 17:38:17 +08001215 HPET_INTCAP, NULL);
1216 if (!compat) {
1217 qdev_prop_set_uint32(hpet, HPET_INTCAP, hpet_irqs);
1218 }
1219 qdev_init_nofail(hpet);
1220 sysbus_mmio_map(SYS_BUS_DEVICE(hpet), 0, HPET_BASE);
1221
Jan Kiszkab881fbe2011-10-07 09:19:35 +02001222 for (i = 0; i < GSI_NUM_PINS; i++) {
Andreas Färber1356b982013-01-20 02:47:33 +01001223 sysbus_connect_irq(SYS_BUS_DEVICE(hpet), i, gsi[i]);
Blue Swirldd703b92011-02-05 14:35:00 +00001224 }
Jan Kiszkace967e22012-02-01 20:31:41 +01001225 pit_isa_irq = -1;
1226 pit_alt_irq = qdev_get_gpio_in(hpet, HPET_LEGACY_PIT_INT);
1227 rtc_irq = qdev_get_gpio_in(hpet, HPET_LEGACY_RTC_INT);
Jan Kiszka822557e2010-06-13 14:15:38 +02001228 }
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001229 }
Philippe Mathieu-Daudé6c646a12017-10-17 13:44:16 -03001230 *rtc_state = mc146818_rtc_init(isa_bus, 2000, rtc_irq);
Jan Kiszka7d932df2010-06-13 14:15:40 +02001231
1232 qemu_register_boot_set(pc_boot_set, *rtc_state);
1233
Chao Pengfeddd2f2016-11-05 03:19:50 -04001234 if (!xen_enabled() && has_pit) {
Paolo Bonzini15eafc22015-12-17 17:16:08 +01001235 if (kvm_pit_in_kernel()) {
Stefano Stabellinic2d8d312011-11-14 15:07:01 +00001236 pit = kvm_pit_init(isa_bus, 0x40);
1237 } else {
Philippe Mathieu-Daudéacf695e2017-10-17 13:44:15 -03001238 pit = i8254_pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq);
Stefano Stabellinic2d8d312011-11-14 15:07:01 +00001239 }
1240 if (hpet) {
1241 /* connect PIT to output control line of the HPET */
Andreas Färber4a17cc42013-06-07 13:49:13 +02001242 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
Stefano Stabellinic2d8d312011-11-14 15:07:01 +00001243 }
1244 pcspk_init(isa_bus, pit);
Jan Kiszka5d17c0d2012-03-02 20:28:49 +01001245 }
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001246
Philippe Mathieu-Daudé55f613a2018-03-08 23:39:23 +01001247 i8257_dma_init(isa_bus, 0);
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001248
Philippe Mathieu-Daudéac642732018-03-08 23:39:46 +01001249 /* Super I/O */
1250 pc_superio_init(isa_bus, create_fdctrl, no_vmport);
Isaku Yamahataffe513d2010-05-14 16:29:13 +09001251}
1252
Paolo Bonzini4b9c2642018-03-02 10:29:06 +01001253void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
Isaku Yamahata9011a1a2012-11-14 15:54:01 -05001254{
1255 int i;
1256
Gerd Hoffmannbab47d92016-04-07 09:12:58 -05001257 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_NIC);
Isaku Yamahata9011a1a2012-11-14 15:54:01 -05001258 for (i = 0; i < nb_nics; i++) {
1259 NICInfo *nd = &nd_table[i];
Paolo Bonzini4b9c2642018-03-02 10:29:06 +01001260 const char *model = nd->model ? nd->model : pcmc->default_nic_model;
Isaku Yamahata9011a1a2012-11-14 15:54:01 -05001261
Paolo Bonzini4b9c2642018-03-02 10:29:06 +01001262 if (g_str_equal(model, "ne2k_isa")) {
Isaku Yamahata9011a1a2012-11-14 15:54:01 -05001263 pc_init_ne2k_isa(isa_bus, nd);
1264 } else {
Paolo Bonzini4b9c2642018-03-02 10:29:06 +01001265 pci_nic_init_nofail(nd, pci_bus, model, NULL);
Isaku Yamahata9011a1a2012-11-14 15:54:01 -05001266 }
1267 }
Gerd Hoffmannbab47d92016-04-07 09:12:58 -05001268 rom_reset_order_override();
Isaku Yamahata9011a1a2012-11-14 15:54:01 -05001269}
1270
Philippe Mathieu-Daudé4501d312019-10-18 15:59:09 +02001271void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs)
1272{
1273 qemu_irq *i8259;
1274
1275 if (kvm_pic_in_kernel()) {
1276 i8259 = kvm_i8259_init(isa_bus);
1277 } else if (xen_enabled()) {
1278 i8259 = xen_interrupt_controller_init();
1279 } else {
Paolo Bonzini89a289c2019-12-12 14:14:40 +01001280 i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq());
Philippe Mathieu-Daudé4501d312019-10-18 15:59:09 +02001281 }
1282
1283 for (size_t i = 0; i < ISA_NUM_IRQS; i++) {
1284 i8259_irqs[i] = i8259[i];
1285 }
1286
1287 g_free(i8259);
1288}
1289
David Hildenbrandd4681152018-06-19 15:41:34 +02001290static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
1291 Error **errp)
1292{
1293 const PCMachineState *pcms = PC_MACHINE(hotplug_dev);
David Hildenbrandb0e62442018-08-01 15:34:44 +02001294 const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
Eric Augerf6a0d062019-03-08 19:20:53 +01001295 const MachineState *ms = MACHINE(hotplug_dev);
David Hildenbrandd4681152018-06-19 15:41:34 +02001296 const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
David Hildenbrandb0e62442018-08-01 15:34:44 +02001297 const uint64_t legacy_align = TARGET_PAGE_SIZE;
Thomas Huthae909492019-04-07 11:23:14 +02001298 Error *local_err = NULL;
David Hildenbrandd4681152018-06-19 15:41:34 +02001299
1300 /*
1301 * When -no-acpi is used with Q35 machine type, no ACPI is built,
1302 * but pcms->acpi_dev is still created. Check !acpi_enabled in
1303 * addition to cover this case.
1304 */
Gerd Hoffmann17e89072020-03-20 11:01:36 +01001305 if (!pcms->acpi_dev || !x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) {
David Hildenbrandd4681152018-06-19 15:41:34 +02001306 error_setg(errp,
1307 "memory hotplug is not enabled: missing acpi device or acpi disabled");
1308 return;
1309 }
1310
Eric Augerf6a0d062019-03-08 19:20:53 +01001311 if (is_nvdimm && !ms->nvdimms_state->is_enabled) {
David Hildenbrandd4681152018-06-19 15:41:34 +02001312 error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
1313 return;
1314 }
David Hildenbrand8f1ffe52018-08-01 15:34:41 +02001315
Thomas Huthae909492019-04-07 11:23:14 +02001316 hotplug_handler_pre_plug(pcms->acpi_dev, dev, &local_err);
1317 if (local_err) {
1318 error_propagate(errp, local_err);
1319 return;
1320 }
1321
David Hildenbrandfd3416f2018-10-05 11:20:12 +02001322 pc_dimm_pre_plug(PC_DIMM(dev), MACHINE(hotplug_dev),
David Hildenbrandb0e62442018-08-01 15:34:44 +02001323 pcmc->enforce_aligned_dimm ? NULL : &legacy_align, errp);
David Hildenbrandd4681152018-06-19 15:41:34 +02001324}
1325
David Hildenbrandbb6e2f72018-06-19 15:41:31 +02001326static void pc_memory_plug(HotplugHandler *hotplug_dev,
1327 DeviceState *dev, Error **errp)
Igor Mammedov95bee272014-06-02 15:25:12 +02001328{
1329 Error *local_err = NULL;
1330 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
Eric Augerf6a0d062019-03-08 19:20:53 +01001331 MachineState *ms = MACHINE(hotplug_dev);
Stefan Hajnoczi7f3cf2d2017-06-09 16:16:15 +01001332 bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
Igor Mammedov95bee272014-06-02 15:25:12 +02001333
David Hildenbrandfd3416f2018-10-05 11:20:12 +02001334 pc_dimm_plug(PC_DIMM(dev), MACHINE(pcms), &local_err);
Bharata B Rao43bbb492015-06-29 13:50:23 +05301335 if (local_err) {
Igor Mammedovb8865592014-10-31 16:38:32 +00001336 goto out;
1337 }
1338
Stefan Hajnoczi7f3cf2d2017-06-09 16:16:15 +01001339 if (is_nvdimm) {
Eric Augerf6a0d062019-03-08 19:20:53 +01001340 nvdimm_plug(ms->nvdimms_state);
Xiao Guangrongc7f8d0f2016-11-07 19:13:36 +08001341 }
1342
David Hildenbrand473ac562018-12-12 10:57:07 +01001343 hotplug_handler_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &error_abort);
Igor Mammedov95bee272014-06-02 15:25:12 +02001344out:
1345 error_propagate(errp, local_err);
1346}
1347
David Hildenbrandbb6e2f72018-06-19 15:41:31 +02001348static void pc_memory_unplug_request(HotplugHandler *hotplug_dev,
1349 DeviceState *dev, Error **errp)
Tang Chen64fec582015-04-27 16:47:17 +08001350{
Tang Chen64fec582015-04-27 16:47:17 +08001351 Error *local_err = NULL;
1352 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
1353
Haozhong Zhang8cd91ac2017-12-22 09:51:20 +08001354 /*
1355 * When -no-acpi is used with Q35 machine type, no ACPI is built,
1356 * but pcms->acpi_dev is still created. Check !acpi_enabled in
1357 * addition to cover this case.
1358 */
Gerd Hoffmann17e89072020-03-20 11:01:36 +01001359 if (!pcms->acpi_dev || !x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) {
Tang Chen64fec582015-04-27 16:47:17 +08001360 error_setg(&local_err,
Haozhong Zhang8cd91ac2017-12-22 09:51:20 +08001361 "memory hotplug is not enabled: missing acpi device or acpi disabled");
Tang Chen64fec582015-04-27 16:47:17 +08001362 goto out;
1363 }
1364
Xiao Guangrongb097cc52016-10-29 00:35:40 +08001365 if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
1366 error_setg(&local_err,
1367 "nvdimm device hot unplug is not supported yet.");
1368 goto out;
1369 }
1370
David Hildenbrand473ac562018-12-12 10:57:07 +01001371 hotplug_handler_unplug_request(HOTPLUG_HANDLER(pcms->acpi_dev), dev,
1372 &local_err);
Tang Chen64fec582015-04-27 16:47:17 +08001373out:
1374 error_propagate(errp, local_err);
1375}
1376
David Hildenbrandbb6e2f72018-06-19 15:41:31 +02001377static void pc_memory_unplug(HotplugHandler *hotplug_dev,
1378 DeviceState *dev, Error **errp)
Tang Chenf7d3e292015-04-27 16:47:18 +08001379{
1380 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
Tang Chenf7d3e292015-04-27 16:47:18 +08001381 Error *local_err = NULL;
1382
David Hildenbrand473ac562018-12-12 10:57:07 +01001383 hotplug_handler_unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err);
Tang Chenf7d3e292015-04-27 16:47:18 +08001384 if (local_err) {
1385 goto out;
1386 }
1387
David Hildenbrandfd3416f2018-10-05 11:20:12 +02001388 pc_dimm_unplug(PC_DIMM(dev), MACHINE(pcms));
Markus Armbruster981c3dc2020-06-10 07:31:56 +02001389 qdev_unrealize(dev);
Tang Chenf7d3e292015-04-27 16:47:18 +08001390 out:
1391 error_propagate(errp, local_err);
1392}
1393
Igor Mammedov3811ef12016-03-03 15:28:56 +01001394static int pc_apic_cmp(const void *a, const void *b)
1395{
1396 CPUArchId *apic_a = (CPUArchId *)a;
1397 CPUArchId *apic_b = (CPUArchId *)b;
1398
1399 return apic_a->arch_id - apic_b->arch_id;
1400}
1401
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001402/* returns pointer to CPUArchId descriptor that matches CPU's apic_id
Igor Mammedov38690a12017-02-09 12:08:32 +01001403 * in ms->possible_cpus->cpus, if ms->possible_cpus->cpus has no
Stefan Weilb12227a2016-11-19 20:29:26 +01001404 * entry corresponding to CPU's apic_id returns NULL.
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001405 */
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001406static CPUArchId *pc_find_cpu_slot(MachineState *ms, uint32_t id, int *idx)
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001407{
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001408 CPUArchId apic_id, *found_cpu;
1409
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001410 apic_id.arch_id = id;
Igor Mammedov38690a12017-02-09 12:08:32 +01001411 found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus,
1412 ms->possible_cpus->len, sizeof(*ms->possible_cpus->cpus),
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001413 pc_apic_cmp);
1414 if (found_cpu && idx) {
Igor Mammedov38690a12017-02-09 12:08:32 +01001415 *idx = found_cpu - ms->possible_cpus->cpus;
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001416 }
1417 return found_cpu;
1418}
1419
Gu Zheng52795692014-10-22 11:24:28 +08001420static void pc_cpu_plug(HotplugHandler *hotplug_dev,
1421 DeviceState *dev, Error **errp)
1422{
Igor Mammedov7baef5c2016-07-06 08:20:39 +02001423 CPUArchId *found_cpu;
Gu Zheng52795692014-10-22 11:24:28 +08001424 Error *local_err = NULL;
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001425 X86CPU *cpu = X86_CPU(dev);
Gu Zheng52795692014-10-22 11:24:28 +08001426 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001427 X86MachineState *x86ms = X86_MACHINE(pcms);
Gu Zheng52795692014-10-22 11:24:28 +08001428
Igor Mammedova44a49d2016-07-14 18:54:32 +02001429 if (pcms->acpi_dev) {
David Hildenbrand473ac562018-12-12 10:57:07 +01001430 hotplug_handler_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err);
Igor Mammedova44a49d2016-07-14 18:54:32 +02001431 if (local_err) {
1432 goto out;
1433 }
Gu Zheng52795692014-10-22 11:24:28 +08001434 }
1435
Igor Mammedove3cadac2016-11-16 14:04:41 +01001436 /* increment the number of CPUs */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001437 x86ms->boot_cpus++;
1438 if (x86ms->rtc) {
1439 rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus);
Igor Mammedov26ef65b2016-12-30 15:33:11 +01001440 }
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001441 if (x86ms->fw_cfg) {
1442 fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus);
Gu Zheng52795692014-10-22 11:24:28 +08001443 }
1444
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001445 found_cpu = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, NULL);
Igor Mammedov8aba3842017-02-09 12:08:36 +01001446 found_cpu->cpu = OBJECT(dev);
Gu Zheng52795692014-10-22 11:24:28 +08001447out:
1448 error_propagate(errp, local_err);
1449}
Igor Mammedov8872c252016-06-14 16:14:02 +02001450static void pc_cpu_unplug_request_cb(HotplugHandler *hotplug_dev,
1451 DeviceState *dev, Error **errp)
1452{
Igor Mammedov73360e22016-07-18 10:31:22 +02001453 int idx = -1;
Igor Mammedov8872c252016-06-14 16:14:02 +02001454 Error *local_err = NULL;
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001455 X86CPU *cpu = X86_CPU(dev);
Igor Mammedov8872c252016-06-14 16:14:02 +02001456 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
1457
Igor Mammedov75ba2dd2017-11-20 18:19:23 +01001458 if (!pcms->acpi_dev) {
1459 error_setg(&local_err, "CPU hot unplug not supported without ACPI");
1460 goto out;
1461 }
1462
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001463 pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx);
Igor Mammedov73360e22016-07-18 10:31:22 +02001464 assert(idx != -1);
1465 if (idx == 0) {
1466 error_setg(&local_err, "Boot CPU is unpluggable");
1467 goto out;
1468 }
1469
David Hildenbrand473ac562018-12-12 10:57:07 +01001470 hotplug_handler_unplug_request(HOTPLUG_HANDLER(pcms->acpi_dev), dev,
1471 &local_err);
Igor Mammedov8872c252016-06-14 16:14:02 +02001472 if (local_err) {
1473 goto out;
1474 }
1475
1476 out:
1477 error_propagate(errp, local_err);
1478
1479}
1480
1481static void pc_cpu_unplug_cb(HotplugHandler *hotplug_dev,
1482 DeviceState *dev, Error **errp)
1483{
Igor Mammedov8fe63742016-06-24 15:36:11 +02001484 CPUArchId *found_cpu;
Igor Mammedov8872c252016-06-14 16:14:02 +02001485 Error *local_err = NULL;
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001486 X86CPU *cpu = X86_CPU(dev);
Igor Mammedov8872c252016-06-14 16:14:02 +02001487 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001488 X86MachineState *x86ms = X86_MACHINE(pcms);
Igor Mammedov8872c252016-06-14 16:14:02 +02001489
David Hildenbrand473ac562018-12-12 10:57:07 +01001490 hotplug_handler_unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err);
Igor Mammedov8872c252016-06-14 16:14:02 +02001491 if (local_err) {
1492 goto out;
1493 }
1494
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001495 found_cpu = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, NULL);
Igor Mammedov8fe63742016-06-24 15:36:11 +02001496 found_cpu->cpu = NULL;
Markus Armbruster981c3dc2020-06-10 07:31:56 +02001497 qdev_unrealize(dev);
Igor Mammedov8872c252016-06-14 16:14:02 +02001498
Igor Mammedove3cadac2016-11-16 14:04:41 +01001499 /* decrement the number of CPUs */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001500 x86ms->boot_cpus--;
Igor Mammedove3cadac2016-11-16 14:04:41 +01001501 /* Update the number of CPUs in CMOS */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001502 rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus);
1503 fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus);
Igor Mammedov8872c252016-06-14 16:14:02 +02001504 out:
1505 error_propagate(errp, local_err);
1506}
Gu Zheng52795692014-10-22 11:24:28 +08001507
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001508static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
1509 DeviceState *dev, Error **errp)
1510{
1511 int idx;
Igor Mammedova15d2722016-07-25 11:59:23 +02001512 CPUState *cs;
Igor Mammedove8f7b832016-07-14 18:54:30 +02001513 CPUArchId *cpu_slot;
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001514 X86CPUTopoIDs topo_ids;
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001515 X86CPU *cpu = X86_CPU(dev);
Like Xucabea7d2019-06-12 16:40:57 +08001516 CPUX86State *env = &cpu->env;
Igor Mammedov6970c5f2017-10-10 14:34:39 +02001517 MachineState *ms = MACHINE(hotplug_dev);
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001518 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001519 X86MachineState *x86ms = X86_MACHINE(pcms);
Like Xu0e11fc62019-05-19 04:54:25 +08001520 unsigned int smp_cores = ms->smp.cores;
1521 unsigned int smp_threads = ms->smp.threads;
Babu Moger53a5e7b2020-03-11 17:52:52 -05001522 X86CPUTopoInfo topo_info;
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001523
Igor Mammedov6970c5f2017-10-10 14:34:39 +02001524 if(!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) {
1525 error_setg(errp, "Invalid CPU type, expected cpu type: '%s'",
1526 ms->cpu_type);
1527 return;
1528 }
1529
Babu Moger53a5e7b2020-03-11 17:52:52 -05001530 init_topo_info(&topo_info, x86ms);
1531
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001532 env->nr_dies = x86ms->smp_dies;
Babu Mogerc24a41b2020-03-11 17:53:20 -05001533 env->nr_nodes = topo_info.nodes_per_pkg;
Babu Moger7b225762020-03-11 17:54:15 -05001534 env->pkg_offset = x86ms->apicid_pkg_offset(&topo_info);
Like Xucabea7d2019-06-12 16:40:57 +08001535
Like Xuc26ae612019-06-12 16:40:56 +08001536 /*
1537 * If APIC ID is not set,
1538 * set it based on socket/die/core/thread properties.
1539 */
Igor Mammedove8f7b832016-07-14 18:54:30 +02001540 if (cpu->apic_id == UNASSIGNED_APIC_ID) {
Like Xuc26ae612019-06-12 16:40:56 +08001541 int max_socket = (ms->smp.max_cpus - 1) /
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001542 smp_threads / smp_cores / x86ms->smp_dies;
Igor Mammedove8f7b832016-07-14 18:54:30 +02001543
Eduardo Habkostfea374e2019-08-16 14:07:50 -03001544 /*
1545 * die-id was optional in QEMU 4.0 and older, so keep it optional
1546 * if there's only one die per socket.
1547 */
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001548 if (cpu->die_id < 0 && x86ms->smp_dies == 1) {
Eduardo Habkostfea374e2019-08-16 14:07:50 -03001549 cpu->die_id = 0;
1550 }
1551
Igor Mammedove8f7b832016-07-14 18:54:30 +02001552 if (cpu->socket_id < 0) {
1553 error_setg(errp, "CPU socket-id is not set");
1554 return;
1555 } else if (cpu->socket_id > max_socket) {
1556 error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u",
1557 cpu->socket_id, max_socket);
1558 return;
Eduardo Habkost23d9cff2019-08-15 15:38:02 -03001559 }
1560 if (cpu->die_id < 0) {
1561 error_setg(errp, "CPU die-id is not set");
1562 return;
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001563 } else if (cpu->die_id > x86ms->smp_dies - 1) {
Like Xu176d2cd2019-06-12 16:40:58 +08001564 error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u",
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001565 cpu->die_id, x86ms->smp_dies - 1);
Like Xu176d2cd2019-06-12 16:40:58 +08001566 return;
Igor Mammedove8f7b832016-07-14 18:54:30 +02001567 }
1568 if (cpu->core_id < 0) {
1569 error_setg(errp, "CPU core-id is not set");
1570 return;
1571 } else if (cpu->core_id > (smp_cores - 1)) {
1572 error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u",
1573 cpu->core_id, smp_cores - 1);
1574 return;
1575 }
1576 if (cpu->thread_id < 0) {
1577 error_setg(errp, "CPU thread-id is not set");
1578 return;
1579 } else if (cpu->thread_id > (smp_threads - 1)) {
1580 error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u",
1581 cpu->thread_id, smp_threads - 1);
1582 return;
1583 }
1584
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001585 topo_ids.pkg_id = cpu->socket_id;
1586 topo_ids.die_id = cpu->die_id;
1587 topo_ids.core_id = cpu->core_id;
1588 topo_ids.smt_id = cpu->thread_id;
Babu Moger2e26f4a2020-03-11 17:54:02 -05001589 cpu->apic_id = x86ms->apicid_from_topo_ids(&topo_info, &topo_ids);
Igor Mammedove8f7b832016-07-14 18:54:30 +02001590 }
1591
Igor Mammedov1ea69c02017-02-09 12:08:35 +01001592 cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx);
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001593 if (!cpu_slot) {
Igor Mammedov38690a12017-02-09 12:08:32 +01001594 MachineState *ms = MACHINE(pcms);
1595
Babu Moger2e26f4a2020-03-11 17:54:02 -05001596 x86ms->topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids);
Like Xud65af282019-06-12 16:40:59 +08001597 error_setg(errp,
1598 "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with"
1599 " APIC ID %" PRIu32 ", valid index range 0:%d",
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001600 topo_ids.pkg_id, topo_ids.die_id, topo_ids.core_id, topo_ids.smt_id,
Like Xud65af282019-06-12 16:40:59 +08001601 cpu->apic_id, ms->possible_cpus->len - 1);
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001602 return;
1603 }
1604
1605 if (cpu_slot->cpu) {
1606 error_setg(errp, "CPU[%d] with APIC ID %" PRIu32 " exists",
1607 idx, cpu->apic_id);
1608 return;
1609 }
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001610
1611 /* if 'address' properties socket-id/core-id/thread-id are not set, set them
Igor Mammedovc5514d02017-02-10 11:20:57 +01001612 * so that machine_query_hotpluggable_cpus would show correct values
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001613 */
1614 /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn()
1615 * once -smp refactoring is complete and there will be CPU private
1616 * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */
Babu Moger2e26f4a2020-03-11 17:54:02 -05001617 x86ms->topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids);
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001618 if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) {
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001619 error_setg(errp, "property socket-id: %u doesn't match set apic-id:"
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001620 " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id,
1621 topo_ids.pkg_id);
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001622 return;
1623 }
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001624 cpu->socket_id = topo_ids.pkg_id;
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001625
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001626 if (cpu->die_id != -1 && cpu->die_id != topo_ids.die_id) {
Like Xu176d2cd2019-06-12 16:40:58 +08001627 error_setg(errp, "property die-id: %u doesn't match set apic-id:"
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001628 " 0x%x (die-id: %u)", cpu->die_id, cpu->apic_id, topo_ids.die_id);
Like Xu176d2cd2019-06-12 16:40:58 +08001629 return;
1630 }
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001631 cpu->die_id = topo_ids.die_id;
Like Xu176d2cd2019-06-12 16:40:58 +08001632
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001633 if (cpu->core_id != -1 && cpu->core_id != topo_ids.core_id) {
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001634 error_setg(errp, "property core-id: %u doesn't match set apic-id:"
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001635 " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id,
1636 topo_ids.core_id);
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001637 return;
1638 }
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001639 cpu->core_id = topo_ids.core_id;
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001640
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001641 if (cpu->thread_id != -1 && cpu->thread_id != topo_ids.smt_id) {
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001642 error_setg(errp, "property thread-id: %u doesn't match set apic-id:"
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001643 " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id,
1644 topo_ids.smt_id);
Igor Mammedovd89c2b82016-07-06 08:20:42 +02001645 return;
1646 }
Babu Mogerdcf08bc2020-03-03 13:56:58 -06001647 cpu->thread_id = topo_ids.smt_id;
Igor Mammedova15d2722016-07-25 11:59:23 +02001648
Vitaly Kuznetsov2d384d72019-05-17 16:19:16 +02001649 if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) &&
1650 !kvm_hv_vpindex_settable()) {
Roman Kagane9688fa2018-07-02 16:41:56 +03001651 error_setg(errp, "kernel doesn't allow setting HyperV VP_INDEX");
1652 return;
1653 }
1654
Igor Mammedova15d2722016-07-25 11:59:23 +02001655 cs = CPU(cpu);
1656 cs->cpu_index = idx;
Igor Mammedov93b2a8c2017-05-10 13:29:47 +02001657
Igor Mammedova0ceb642017-05-30 18:23:56 +02001658 numa_cpu_pre_plug(cpu_slot, dev, errp);
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001659}
1660
David Hildenbranda0a49812019-06-19 15:19:07 +05301661static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev,
1662 DeviceState *dev, Error **errp)
1663{
1664 HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev);
1665 Error *local_err = NULL;
1666
1667 if (!hotplug_dev2) {
1668 /*
1669 * Without a bus hotplug handler, we cannot control the plug/unplug
1670 * order. This should never be the case on x86, however better add
1671 * a safety net.
1672 */
1673 error_setg(errp, "virtio-pmem-pci not supported on this bus.");
1674 return;
1675 }
1676 /*
1677 * First, see if we can plug this memory device at all. If that
1678 * succeeds, branch of to the actual hotplug handler.
1679 */
1680 memory_device_pre_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev), NULL,
1681 &local_err);
1682 if (!local_err) {
1683 hotplug_handler_pre_plug(hotplug_dev2, dev, &local_err);
1684 }
1685 error_propagate(errp, local_err);
1686}
1687
1688static void pc_virtio_pmem_pci_plug(HotplugHandler *hotplug_dev,
1689 DeviceState *dev, Error **errp)
1690{
1691 HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev);
1692 Error *local_err = NULL;
1693
1694 /*
1695 * Plug the memory device first and then branch off to the actual
1696 * hotplug handler. If that one fails, we can easily undo the memory
1697 * device bits.
1698 */
1699 memory_device_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev));
1700 hotplug_handler_plug(hotplug_dev2, dev, &local_err);
1701 if (local_err) {
1702 memory_device_unplug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev));
1703 }
1704 error_propagate(errp, local_err);
1705}
1706
1707static void pc_virtio_pmem_pci_unplug_request(HotplugHandler *hotplug_dev,
1708 DeviceState *dev, Error **errp)
1709{
1710 /* We don't support virtio pmem hot unplug */
1711 error_setg(errp, "virtio pmem device unplug not supported.");
1712}
1713
1714static void pc_virtio_pmem_pci_unplug(HotplugHandler *hotplug_dev,
1715 DeviceState *dev, Error **errp)
1716{
1717 /* We don't support virtio pmem hot unplug */
1718}
1719
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001720static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
1721 DeviceState *dev, Error **errp)
1722{
David Hildenbrandd4681152018-06-19 15:41:34 +02001723 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
1724 pc_memory_pre_plug(hotplug_dev, dev, errp);
1725 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001726 pc_cpu_pre_plug(hotplug_dev, dev, errp);
David Hildenbranda0a49812019-06-19 15:19:07 +05301727 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) {
1728 pc_virtio_pmem_pci_pre_plug(hotplug_dev, dev, errp);
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001729 }
1730}
1731
Igor Mammedov95bee272014-06-02 15:25:12 +02001732static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
1733 DeviceState *dev, Error **errp)
1734{
1735 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
David Hildenbrandbb6e2f72018-06-19 15:41:31 +02001736 pc_memory_plug(hotplug_dev, dev, errp);
Gu Zheng52795692014-10-22 11:24:28 +08001737 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
1738 pc_cpu_plug(hotplug_dev, dev, errp);
David Hildenbranda0a49812019-06-19 15:19:07 +05301739 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) {
1740 pc_virtio_pmem_pci_plug(hotplug_dev, dev, errp);
Igor Mammedov95bee272014-06-02 15:25:12 +02001741 }
1742}
1743
Tang Chend9c5c5b2015-01-28 15:45:37 +08001744static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
1745 DeviceState *dev, Error **errp)
1746{
Tang Chen64fec582015-04-27 16:47:17 +08001747 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
David Hildenbrandbb6e2f72018-06-19 15:41:31 +02001748 pc_memory_unplug_request(hotplug_dev, dev, errp);
Igor Mammedov8872c252016-06-14 16:14:02 +02001749 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
1750 pc_cpu_unplug_request_cb(hotplug_dev, dev, errp);
David Hildenbranda0a49812019-06-19 15:19:07 +05301751 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) {
1752 pc_virtio_pmem_pci_unplug_request(hotplug_dev, dev, errp);
Tang Chen64fec582015-04-27 16:47:17 +08001753 } else {
1754 error_setg(errp, "acpi: device unplug request for not supported device"
1755 " type: %s", object_get_typename(OBJECT(dev)));
1756 }
Tang Chend9c5c5b2015-01-28 15:45:37 +08001757}
1758
Tang Chen232391c2015-01-28 15:45:39 +08001759static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
1760 DeviceState *dev, Error **errp)
1761{
Tang Chenf7d3e292015-04-27 16:47:18 +08001762 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
David Hildenbrandbb6e2f72018-06-19 15:41:31 +02001763 pc_memory_unplug(hotplug_dev, dev, errp);
Igor Mammedov8872c252016-06-14 16:14:02 +02001764 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
1765 pc_cpu_unplug_cb(hotplug_dev, dev, errp);
David Hildenbranda0a49812019-06-19 15:19:07 +05301766 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) {
1767 pc_virtio_pmem_pci_unplug(hotplug_dev, dev, errp);
Tang Chenf7d3e292015-04-27 16:47:18 +08001768 } else {
1769 error_setg(errp, "acpi: device unplug for not supported device"
1770 " type: %s", object_get_typename(OBJECT(dev)));
1771 }
Tang Chen232391c2015-01-28 15:45:39 +08001772}
1773
Wei Yang285816d2019-01-24 15:36:26 +08001774static HotplugHandler *pc_get_hotplug_handler(MachineState *machine,
Igor Mammedov95bee272014-06-02 15:25:12 +02001775 DeviceState *dev)
1776{
Gu Zheng52795692014-10-22 11:24:28 +08001777 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
David Hildenbranda0a49812019-06-19 15:19:07 +05301778 object_dynamic_cast(OBJECT(dev), TYPE_CPU) ||
1779 object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) {
Igor Mammedov95bee272014-06-02 15:25:12 +02001780 return HOTPLUG_HANDLER(machine);
1781 }
1782
Igor Mammedov38aefb52018-05-10 18:10:56 +01001783 return NULL;
Igor Mammedov95bee272014-06-02 15:25:12 +02001784}
1785
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001786static void
David Hildenbrandf2ffbe22018-04-23 18:51:24 +02001787pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
1788 const char *name, void *opaque,
1789 Error **errp)
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001790{
David Hildenbrandb0c14ec2018-04-23 18:51:17 +02001791 MachineState *ms = MACHINE(obj);
Igor Mammedovfc3b77e2019-06-24 05:02:00 -04001792 int64_t value = 0;
1793
1794 if (ms->device_memory) {
1795 value = memory_region_size(&ms->device_memory->mr);
1796 }
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001797
Eric Blake51e72bc2016-01-29 06:48:54 -07001798 visit_type_int(v, name, &value, errp);
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001799}
1800
Eric Blaked7bce992016-01-29 06:48:55 -07001801static void pc_machine_get_vmport(Object *obj, Visitor *v, const char *name,
1802 void *opaque, Error **errp)
Dr. David Alan Gilbert9b23cfb2014-10-03 17:33:37 -04001803{
1804 PCMachineState *pcms = PC_MACHINE(obj);
Don Slutzd1048be2014-11-21 11:18:52 -05001805 OnOffAuto vmport = pcms->vmport;
Dr. David Alan Gilbert9b23cfb2014-10-03 17:33:37 -04001806
Eric Blake51e72bc2016-01-29 06:48:54 -07001807 visit_type_OnOffAuto(v, name, &vmport, errp);
Dr. David Alan Gilbert9b23cfb2014-10-03 17:33:37 -04001808}
1809
Eric Blaked7bce992016-01-29 06:48:55 -07001810static void pc_machine_set_vmport(Object *obj, Visitor *v, const char *name,
1811 void *opaque, Error **errp)
Dr. David Alan Gilbert9b23cfb2014-10-03 17:33:37 -04001812{
1813 PCMachineState *pcms = PC_MACHINE(obj);
1814
Eric Blake51e72bc2016-01-29 06:48:54 -07001815 visit_type_OnOffAuto(v, name, &pcms->vmport, errp);
Dr. David Alan Gilbert9b23cfb2014-10-03 17:33:37 -04001816}
1817
Chao Pengbe232eb2016-11-05 03:19:48 -04001818static bool pc_machine_get_smbus(Object *obj, Error **errp)
1819{
1820 PCMachineState *pcms = PC_MACHINE(obj);
1821
Corey Minyardf5878b02018-11-07 09:24:34 -06001822 return pcms->smbus_enabled;
Chao Pengbe232eb2016-11-05 03:19:48 -04001823}
1824
1825static void pc_machine_set_smbus(Object *obj, bool value, Error **errp)
1826{
1827 PCMachineState *pcms = PC_MACHINE(obj);
1828
Corey Minyardf5878b02018-11-07 09:24:34 -06001829 pcms->smbus_enabled = value;
Chao Pengbe232eb2016-11-05 03:19:48 -04001830}
1831
Chao Peng272f0422016-11-05 03:19:49 -04001832static bool pc_machine_get_sata(Object *obj, Error **errp)
1833{
1834 PCMachineState *pcms = PC_MACHINE(obj);
1835
Corey Minyardf5878b02018-11-07 09:24:34 -06001836 return pcms->sata_enabled;
Chao Peng272f0422016-11-05 03:19:49 -04001837}
1838
1839static void pc_machine_set_sata(Object *obj, bool value, Error **errp)
1840{
1841 PCMachineState *pcms = PC_MACHINE(obj);
1842
Corey Minyardf5878b02018-11-07 09:24:34 -06001843 pcms->sata_enabled = value;
Chao Peng272f0422016-11-05 03:19:49 -04001844}
1845
Chao Pengfeddd2f2016-11-05 03:19:50 -04001846static bool pc_machine_get_pit(Object *obj, Error **errp)
1847{
1848 PCMachineState *pcms = PC_MACHINE(obj);
1849
Corey Minyardf5878b02018-11-07 09:24:34 -06001850 return pcms->pit_enabled;
Chao Pengfeddd2f2016-11-05 03:19:50 -04001851}
1852
1853static void pc_machine_set_pit(Object *obj, bool value, Error **errp)
1854{
1855 PCMachineState *pcms = PC_MACHINE(obj);
1856
Corey Minyardf5878b02018-11-07 09:24:34 -06001857 pcms->pit_enabled = value;
Chao Pengfeddd2f2016-11-05 03:19:50 -04001858}
1859
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001860static void pc_machine_initfn(Object *obj)
1861{
Don Slutzc87b1522014-06-19 21:40:25 -04001862 PCMachineState *pcms = PC_MACHINE(obj);
1863
Julio Montes97fd1ea2019-07-12 16:02:57 +00001864#ifdef CONFIG_VMPORT
Don Slutzd1048be2014-11-21 11:18:52 -05001865 pcms->vmport = ON_OFF_AUTO_AUTO;
Julio Montes97fd1ea2019-07-12 16:02:57 +00001866#else
1867 pcms->vmport = ON_OFF_AUTO_OFF;
1868#endif /* CONFIG_VMPORT */
Wei Liu021746c2016-11-01 17:44:16 +00001869 /* acpi build is enabled by default if machine supports it */
1870 pcms->acpi_build_enabled = PC_MACHINE_GET_CLASS(pcms)->has_acpi_build;
Corey Minyardf5878b02018-11-07 09:24:34 -06001871 pcms->smbus_enabled = true;
1872 pcms->sata_enabled = true;
1873 pcms->pit_enabled = true;
Markus Armbrusterebc29e12019-03-11 18:39:26 +01001874
1875 pc_system_flash_create(pcms);
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001876}
1877
Like Xua0628592019-05-19 04:54:20 +08001878static void pc_machine_reset(MachineState *machine)
Zhu Guihuaae50c552015-09-16 17:19:13 +08001879{
1880 CPUState *cs;
1881 X86CPU *cpu;
1882
1883 qemu_devices_reset();
1884
1885 /* Reset APIC after devices have been reset to cancel
1886 * any changes that qemu_devices_reset() might have done.
1887 */
1888 CPU_FOREACH(cs) {
1889 cpu = X86_CPU(cs);
1890
1891 if (cpu->apic_state) {
Damien Heddef703a042020-01-30 16:02:03 +00001892 device_legacy_reset(cpu->apic_state);
Zhu Guihuaae50c552015-09-16 17:19:13 +08001893 }
1894 }
1895}
1896
Nicholas Pigginc508bd12019-07-22 16:17:51 +10001897static void pc_machine_wakeup(MachineState *machine)
1898{
1899 cpu_synchronize_all_states();
1900 pc_machine_reset(machine);
1901 cpu_synchronize_all_post_reset();
1902}
1903
Peter Xuc6cbc292019-09-16 16:07:17 +08001904static bool pc_hotplug_allowed(MachineState *ms, DeviceState *dev, Error **errp)
1905{
1906 X86IOMMUState *iommu = x86_iommu_get_default();
1907 IntelIOMMUState *intel_iommu;
1908
1909 if (iommu &&
1910 object_dynamic_cast((Object *)iommu, TYPE_INTEL_IOMMU_DEVICE) &&
1911 object_dynamic_cast((Object *)dev, "vfio-pci")) {
1912 intel_iommu = INTEL_IOMMU_DEVICE(iommu);
1913 if (!intel_iommu->caching_mode) {
1914 error_setg(errp, "Device assignment is not allowed without "
1915 "enabling caching-mode=on for Intel IOMMU.");
1916 return false;
1917 }
1918 }
1919
1920 return true;
1921}
1922
Igor Mammedov95bee272014-06-02 15:25:12 +02001923static void pc_machine_class_init(ObjectClass *oc, void *data)
1924{
1925 MachineClass *mc = MACHINE_CLASS(oc);
1926 PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
1927 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
1928
Eduardo Habkost7102fa72015-12-01 20:58:03 -02001929 pcmc->pci_enabled = true;
1930 pcmc->has_acpi_build = true;
1931 pcmc->rsdp_in_ram = true;
1932 pcmc->smbios_defaults = true;
1933 pcmc->smbios_uuid_encoded = true;
1934 pcmc->gigabyte_align = true;
1935 pcmc->has_reserved_memory = true;
1936 pcmc->kvmclock_enabled = true;
Eduardo Habkost16a9e8a2015-12-01 20:58:06 -02001937 pcmc->enforce_aligned_dimm = true;
Eduardo Habkostcd4040e2015-12-01 20:58:05 -02001938 /* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported
1939 * to be used at the moment, 32K should be enough for a while. */
1940 pcmc->acpi_data_size = 0x20000 + 0x8000;
Igor Mammedov98e753a2017-04-25 17:37:50 +02001941 pcmc->linuxboot_dma_enabled = true;
Stefano Garzarellafda672b2019-01-22 13:10:48 +01001942 pcmc->pvh_enabled = true;
Igor Mammedovdebbdc02018-05-10 18:10:56 +01001943 assert(!mc->get_hotplug_handler);
Wei Yang285816d2019-01-24 15:36:26 +08001944 mc->get_hotplug_handler = pc_get_hotplug_handler;
Peter Xuc6cbc292019-09-16 16:07:17 +08001945 mc->hotplug_allowed = pc_hotplug_allowed;
Sergio Lopez81ef68e2019-09-26 15:26:16 +02001946 mc->cpu_index_to_instance_props = x86_cpu_index_to_props;
1947 mc->get_default_cpu_node_id = x86_get_default_cpu_node_id;
1948 mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids;
Dou Liyang7b8be492017-11-14 10:34:01 +08001949 mc->auto_enable_numa_with_memhp = true;
Igor Mammedovc5514d02017-02-10 11:20:57 +01001950 mc->has_hotpluggable_cpus = true;
Eduardo Habkost41742762015-08-07 16:55:47 -03001951 mc->default_boot_order = "cad";
Eduardo Habkost4458fb32015-08-07 16:55:48 -03001952 mc->hot_add_cpu = pc_hot_add_cpu;
Like Xu6f479562019-06-20 13:45:24 +08001953 mc->smp_parse = pc_smp_parse;
Markus Armbruster20598392017-02-15 11:05:40 +01001954 mc->block_default_type = IF_IDE;
Eduardo Habkost4458fb32015-08-07 16:55:48 -03001955 mc->max_cpus = 255;
Zhu Guihuaae50c552015-09-16 17:19:13 +08001956 mc->reset = pc_machine_reset;
Nicholas Pigginc508bd12019-07-22 16:17:51 +10001957 mc->wakeup = pc_machine_wakeup;
Igor Mammedov4ec60c72016-07-06 08:20:40 +02001958 hc->pre_plug = pc_machine_device_pre_plug_cb;
Igor Mammedov95bee272014-06-02 15:25:12 +02001959 hc->plug = pc_machine_device_plug_cb;
Tang Chend9c5c5b2015-01-28 15:45:37 +08001960 hc->unplug_request = pc_machine_device_unplug_request_cb;
Tang Chen232391c2015-01-28 15:45:39 +08001961 hc->unplug = pc_machine_device_unplug_cb;
Igor Mammedov311ca982017-09-13 18:04:56 +02001962 mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
Eric Augerf6a0d062019-03-08 19:20:53 +01001963 mc->nvdimm_supported = true;
Igor Mammedovcd5ff832019-06-10 15:10:07 +02001964 mc->numa_mem_supported = true;
Igor Mammedovbd457782020-02-19 11:09:17 -05001965 mc->default_ram_id = "pc.ram";
Eduardo Habkost0efc2572016-10-13 17:48:36 -03001966
David Hildenbrandf2ffbe22018-04-23 18:51:24 +02001967 object_class_property_add(oc, PC_MACHINE_DEVMEM_REGION_SIZE, "int",
1968 pc_machine_get_device_memory_region_size, NULL,
Markus Armbrusterd2623122020-05-05 17:29:22 +02001969 NULL, NULL);
Eduardo Habkost0efc2572016-10-13 17:48:36 -03001970
Eduardo Habkost0efc2572016-10-13 17:48:36 -03001971 object_class_property_add(oc, PC_MACHINE_VMPORT, "OnOffAuto",
1972 pc_machine_get_vmport, pc_machine_set_vmport,
Markus Armbrusterd2623122020-05-05 17:29:22 +02001973 NULL, NULL);
Eduardo Habkost0efc2572016-10-13 17:48:36 -03001974 object_class_property_set_description(oc, PC_MACHINE_VMPORT,
Markus Armbruster7eecec72020-05-05 17:29:15 +02001975 "Enable vmport (pc & q35)");
Eduardo Habkost0efc2572016-10-13 17:48:36 -03001976
Chao Pengbe232eb2016-11-05 03:19:48 -04001977 object_class_property_add_bool(oc, PC_MACHINE_SMBUS,
Markus Armbrusterd2623122020-05-05 17:29:22 +02001978 pc_machine_get_smbus, pc_machine_set_smbus);
Chao Peng272f0422016-11-05 03:19:49 -04001979
1980 object_class_property_add_bool(oc, PC_MACHINE_SATA,
Markus Armbrusterd2623122020-05-05 17:29:22 +02001981 pc_machine_get_sata, pc_machine_set_sata);
Chao Pengfeddd2f2016-11-05 03:19:50 -04001982
1983 object_class_property_add_bool(oc, PC_MACHINE_PIT,
Markus Armbrusterd2623122020-05-05 17:29:22 +02001984 pc_machine_get_pit, pc_machine_set_pit);
Igor Mammedov95bee272014-06-02 15:25:12 +02001985}
1986
Igor Mammedovd5747ca2014-06-02 15:24:57 +02001987static const TypeInfo pc_machine_info = {
1988 .name = TYPE_PC_MACHINE,
Paolo Bonzinif0bb2762019-10-22 09:39:50 +02001989 .parent = TYPE_X86_MACHINE,
Igor Mammedovd5747ca2014-06-02 15:24:57 +02001990 .abstract = true,
1991 .instance_size = sizeof(PCMachineState),
Igor Mammedovbf1e8932014-06-02 15:25:27 +02001992 .instance_init = pc_machine_initfn,
Igor Mammedovd5747ca2014-06-02 15:24:57 +02001993 .class_size = sizeof(PCMachineClass),
Igor Mammedov95bee272014-06-02 15:25:12 +02001994 .class_init = pc_machine_class_init,
1995 .interfaces = (InterfaceInfo[]) {
1996 { TYPE_HOTPLUG_HANDLER },
1997 { }
1998 },
Igor Mammedovd5747ca2014-06-02 15:24:57 +02001999};
2000
2001static void pc_machine_register_types(void)
2002{
2003 type_register_static(&pc_machine_info);
2004}
2005
2006type_init(pc_machine_register_types)