xref: /qemu/hw/i386/pc_q35.c (revision 25519b062c70f2afe2d2f0c262f3838a41e8bc7c)
1df2d8b3eSIsaku Yamahata /*
2df2d8b3eSIsaku Yamahata  * Q35 chipset based pc system emulator
3df2d8b3eSIsaku Yamahata  *
4df2d8b3eSIsaku Yamahata  * Copyright (c) 2003-2004 Fabrice Bellard
5df2d8b3eSIsaku Yamahata  * Copyright (c) 2009, 2010
6df2d8b3eSIsaku Yamahata  *               Isaku Yamahata <yamahata at valinux co jp>
7df2d8b3eSIsaku Yamahata  *               VA Linux Systems Japan K.K.
8df2d8b3eSIsaku Yamahata  * Copyright (C) 2012 Jason Baron <jbaron@redhat.com>
9df2d8b3eSIsaku Yamahata  *
10df2d8b3eSIsaku Yamahata  * This is based on pc.c, but heavily modified.
11df2d8b3eSIsaku Yamahata  *
12df2d8b3eSIsaku Yamahata  * Permission is hereby granted, free of charge, to any person obtaining a copy
13df2d8b3eSIsaku Yamahata  * of this software and associated documentation files (the "Software"), to deal
14df2d8b3eSIsaku Yamahata  * in the Software without restriction, including without limitation the rights
15df2d8b3eSIsaku Yamahata  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16df2d8b3eSIsaku Yamahata  * copies of the Software, and to permit persons to whom the Software is
17df2d8b3eSIsaku Yamahata  * furnished to do so, subject to the following conditions:
18df2d8b3eSIsaku Yamahata  *
19df2d8b3eSIsaku Yamahata  * The above copyright notice and this permission notice shall be included in
20df2d8b3eSIsaku Yamahata  * all copies or substantial portions of the Software.
21df2d8b3eSIsaku Yamahata  *
22df2d8b3eSIsaku Yamahata  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23df2d8b3eSIsaku Yamahata  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24df2d8b3eSIsaku Yamahata  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25df2d8b3eSIsaku Yamahata  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26df2d8b3eSIsaku Yamahata  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27df2d8b3eSIsaku Yamahata  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28df2d8b3eSIsaku Yamahata  * THE SOFTWARE.
29df2d8b3eSIsaku Yamahata  */
3083c9f4caSPaolo Bonzini #include "hw/hw.h"
3104920fc0SMichael S. Tsirkin #include "hw/loader.h"
329c17d615SPaolo Bonzini #include "sysemu/arch_init.h"
330d09e41aSPaolo Bonzini #include "hw/i2c/smbus.h"
3483c9f4caSPaolo Bonzini #include "hw/boards.h"
350d09e41aSPaolo Bonzini #include "hw/timer/mc146818rtc.h"
360d09e41aSPaolo Bonzini #include "hw/xen/xen.h"
379c17d615SPaolo Bonzini #include "sysemu/kvm.h"
3883c9f4caSPaolo Bonzini #include "hw/kvm/clock.h"
390d09e41aSPaolo Bonzini #include "hw/pci-host/q35.h"
40022c62cbSPaolo Bonzini #include "exec/address-spaces.h"
410d09e41aSPaolo Bonzini #include "hw/i386/ich9.h"
42b29ad07eSMarkus Armbruster #include "hw/i386/smbios.h"
43df2d8b3eSIsaku Yamahata #include "hw/ide/pci.h"
44df2d8b3eSIsaku Yamahata #include "hw/ide/ahci.h"
45df2d8b3eSIsaku Yamahata #include "hw/usb.h"
46f0513d2cSIgor Mammedov #include "hw/cpu/icc_bus.h"
47c87b1520SDon Slutz #include "qemu/error-report.h"
48df2d8b3eSIsaku Yamahata 
49df2d8b3eSIsaku Yamahata /* ICH9 AHCI has 6 ports */
50df2d8b3eSIsaku Yamahata #define MAX_SATA_PORTS     6
51df2d8b3eSIsaku Yamahata 
5272c194f7SMichael S. Tsirkin static bool has_acpi_build = true;
53384fb32eSMichael S. Tsirkin static bool rsdp_in_ram = true;
54e6667f71SGabriel L. Somlo static bool smbios_defaults = true;
55c97294ecSGabriel L. Somlo static bool smbios_legacy_mode;
56caad057bSEduardo Habkost static bool smbios_uuid_encoded = true;
574e17997dSMichael S. Tsirkin /* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to
584e17997dSMichael S. Tsirkin  * host addresses aligned at 1Gbyte boundaries.  This way we can use 1GByte
594e17997dSMichael S. Tsirkin  * pages in the host.
604e17997dSMichael S. Tsirkin  */
619a305c8fSGerd Hoffmann static bool gigabyte_align = true;
62de268e13SIgor Mammedov static bool has_reserved_memory = true;
633ab135f3SHu Tao 
64df2d8b3eSIsaku Yamahata /* PC hardware initialisation */
653ef96221SMarcel Apfelbaum static void pc_q35_init(MachineState *machine)
66df2d8b3eSIsaku Yamahata {
67781bbd6bSIgor Mammedov     PCMachineState *pc_machine = PC_MACHINE(machine);
68df2d8b3eSIsaku Yamahata     ram_addr_t below_4g_mem_size, above_4g_mem_size;
69df2d8b3eSIsaku Yamahata     Q35PCIHost *q35_host;
70ce88812fSHu Tao     PCIHostState *phb;
71df2d8b3eSIsaku Yamahata     PCIBus *host_bus;
72df2d8b3eSIsaku Yamahata     PCIDevice *lpc;
73df2d8b3eSIsaku Yamahata     BusState *idebus[MAX_SATA_PORTS];
74df2d8b3eSIsaku Yamahata     ISADevice *rtc_state;
75df2d8b3eSIsaku Yamahata     ISADevice *floppy;
76df2d8b3eSIsaku Yamahata     MemoryRegion *pci_memory;
77df2d8b3eSIsaku Yamahata     MemoryRegion *rom_memory;
78df2d8b3eSIsaku Yamahata     MemoryRegion *ram_memory;
79df2d8b3eSIsaku Yamahata     GSIState *gsi_state;
80df2d8b3eSIsaku Yamahata     ISABus *isa_bus;
81df2d8b3eSIsaku Yamahata     int pci_enabled = 1;
82df2d8b3eSIsaku Yamahata     qemu_irq *cpu_irq;
83df2d8b3eSIsaku Yamahata     qemu_irq *gsi;
84df2d8b3eSIsaku Yamahata     qemu_irq *i8259;
85df2d8b3eSIsaku Yamahata     int i;
86df2d8b3eSIsaku Yamahata     ICH9LPCState *ich9_lpc;
87df2d8b3eSIsaku Yamahata     PCIDevice *ahci;
88f0513d2cSIgor Mammedov     DeviceState *icc_bridge;
893459a625SMichael S. Tsirkin     PcGuestInfo *guest_info;
90c87b1520SDon Slutz     ram_addr_t lowmem;
91d93162e1SJohn Snow     DriveInfo *hd[MAX_SATA_PORTS];
92f0513d2cSIgor Mammedov 
934e17997dSMichael S. Tsirkin     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
944e17997dSMichael S. Tsirkin      * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
954e17997dSMichael S. Tsirkin      * also known as MMCFG).
964e17997dSMichael S. Tsirkin      * If it doesn't, we need to split it in chunks below and above 4G.
974e17997dSMichael S. Tsirkin      * In any case, try to make sure that guest addresses aligned at
984e17997dSMichael S. Tsirkin      * 1G boundaries get mapped to host addresses aligned at 1G boundaries.
994e17997dSMichael S. Tsirkin      * For old machine types, use whatever split we used historically to avoid
1004e17997dSMichael S. Tsirkin      * breaking migration.
1014e17997dSMichael S. Tsirkin      */
1023ef96221SMarcel Apfelbaum     if (machine->ram_size >= 0xb0000000) {
103c87b1520SDon Slutz         lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
104c87b1520SDon Slutz     } else {
105c87b1520SDon Slutz         lowmem = 0xb0000000;
106c87b1520SDon Slutz     }
107c87b1520SDon Slutz 
108a9dd38dbSStefan Weil     /* Handle the machine opt max-ram-below-4g.  It is basically doing
109c87b1520SDon Slutz      * min(qemu limit, user limit).
110c87b1520SDon Slutz      */
111c87b1520SDon Slutz     if (lowmem > pc_machine->max_ram_below_4g) {
112c87b1520SDon Slutz         lowmem = pc_machine->max_ram_below_4g;
113c87b1520SDon Slutz         if (machine->ram_size - lowmem > lowmem &&
114c87b1520SDon Slutz             lowmem & ((1ULL << 30) - 1)) {
115c87b1520SDon Slutz             error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
116c87b1520SDon Slutz                          ") not a multiple of 1G; possible bad performance.",
117c87b1520SDon Slutz                          pc_machine->max_ram_below_4g);
118c87b1520SDon Slutz         }
119c87b1520SDon Slutz     }
120c87b1520SDon Slutz 
121c87b1520SDon Slutz     if (machine->ram_size >= lowmem) {
1223ef96221SMarcel Apfelbaum         above_4g_mem_size = machine->ram_size - lowmem;
1239a305c8fSGerd Hoffmann         below_4g_mem_size = lowmem;
124df2d8b3eSIsaku Yamahata     } else {
125df2d8b3eSIsaku Yamahata         above_4g_mem_size = 0;
1263ef96221SMarcel Apfelbaum         below_4g_mem_size = machine->ram_size;
127df2d8b3eSIsaku Yamahata     }
128df2d8b3eSIsaku Yamahata 
1293c2a9669SDon Slutz     if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size,
1303c2a9669SDon Slutz                                       &ram_memory) != 0) {
1313c2a9669SDon Slutz         fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
1323c2a9669SDon Slutz         exit(1);
1333c2a9669SDon Slutz     }
1343c2a9669SDon Slutz 
1353c2a9669SDon Slutz     icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
1363c2a9669SDon Slutz     object_property_add_child(qdev_get_machine(), "icc-bridge",
1373c2a9669SDon Slutz                               OBJECT(icc_bridge), NULL);
1383c2a9669SDon Slutz 
1393c2a9669SDon Slutz     pc_cpus_init(machine->cpu_model, icc_bridge);
1403c2a9669SDon Slutz     pc_acpi_init("q35-acpi-dsdt.aml");
1413c2a9669SDon Slutz 
1423c2a9669SDon Slutz     kvmclock_create();
1433c2a9669SDon Slutz 
144df2d8b3eSIsaku Yamahata     /* pci enabled */
145df2d8b3eSIsaku Yamahata     if (pci_enabled) {
146df2d8b3eSIsaku Yamahata         pci_memory = g_new(MemoryRegion, 1);
147286690e3SPaolo Bonzini         memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
148df2d8b3eSIsaku Yamahata         rom_memory = pci_memory;
149df2d8b3eSIsaku Yamahata     } else {
150df2d8b3eSIsaku Yamahata         pci_memory = NULL;
151df2d8b3eSIsaku Yamahata         rom_memory = get_system_memory();
152df2d8b3eSIsaku Yamahata     }
153df2d8b3eSIsaku Yamahata 
1543459a625SMichael S. Tsirkin     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
1556dd2a5c9SPaolo Bonzini     guest_info->isapc_ram_fw = false;
15672c194f7SMichael S. Tsirkin     guest_info->has_acpi_build = has_acpi_build;
157de268e13SIgor Mammedov     guest_info->has_reserved_memory = has_reserved_memory;
158384fb32eSMichael S. Tsirkin     guest_info->rsdp_in_ram = rsdp_in_ram;
1593459a625SMichael S. Tsirkin 
16007fb6176SPaolo Bonzini     /* Migration was not supported in 2.0 for Q35, so do not bother
16107fb6176SPaolo Bonzini      * with this hack (see hw/i386/acpi-build.c).
16207fb6176SPaolo Bonzini      */
16307fb6176SPaolo Bonzini     guest_info->legacy_acpi_table_size = 0;
16407fb6176SPaolo Bonzini 
165e6667f71SGabriel L. Somlo     if (smbios_defaults) {
1663ef96221SMarcel Apfelbaum         MachineClass *mc = MACHINE_GET_CLASS(machine);
167b29ad07eSMarkus Armbruster         /* These values are guest ABI, do not change */
168e6667f71SGabriel L. Somlo         smbios_set_defaults("QEMU", "Standard PC (Q35 + ICH9, 2009)",
169caad057bSEduardo Habkost                             mc->name, smbios_legacy_mode, smbios_uuid_encoded);
170b29ad07eSMarkus Armbruster     }
171b29ad07eSMarkus Armbruster 
172df2d8b3eSIsaku Yamahata     /* allocate ram and load rom/bios */
173df2d8b3eSIsaku Yamahata     if (!xen_enabled()) {
1749521d42bSPaolo Bonzini         pc_memory_init(machine, get_system_memory(),
1753b6fb9caSMarkus Armbruster                        below_4g_mem_size, above_4g_mem_size,
1763459a625SMichael S. Tsirkin                        rom_memory, &ram_memory, guest_info);
177df2d8b3eSIsaku Yamahata     }
178df2d8b3eSIsaku Yamahata 
179df2d8b3eSIsaku Yamahata     /* irq lines */
180df2d8b3eSIsaku Yamahata     gsi_state = g_malloc0(sizeof(*gsi_state));
181df2d8b3eSIsaku Yamahata     if (kvm_irqchip_in_kernel()) {
182df2d8b3eSIsaku Yamahata         kvm_pc_setup_irq_routing(pci_enabled);
183df2d8b3eSIsaku Yamahata         gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
184df2d8b3eSIsaku Yamahata                                  GSI_NUM_PINS);
185df2d8b3eSIsaku Yamahata     } else {
186df2d8b3eSIsaku Yamahata         gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
187df2d8b3eSIsaku Yamahata     }
188df2d8b3eSIsaku Yamahata 
189df2d8b3eSIsaku Yamahata     /* create pci host bus */
190df2d8b3eSIsaku Yamahata     q35_host = Q35_HOST_DEVICE(qdev_create(NULL, TYPE_Q35_HOST_DEVICE));
191df2d8b3eSIsaku Yamahata 
192c52dc697SIgor Mammedov     object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host), NULL);
193df2d8b3eSIsaku Yamahata     q35_host->mch.ram_memory = ram_memory;
194df2d8b3eSIsaku Yamahata     q35_host->mch.pci_address_space = pci_memory;
195df2d8b3eSIsaku Yamahata     q35_host->mch.system_memory = get_system_memory();
196c7e775e4SDong Xu Wang     q35_host->mch.address_space_io = get_system_io();
197df2d8b3eSIsaku Yamahata     q35_host->mch.below_4g_mem_size = below_4g_mem_size;
198df2d8b3eSIsaku Yamahata     q35_host->mch.above_4g_mem_size = above_4g_mem_size;
1993459a625SMichael S. Tsirkin     q35_host->mch.guest_info = guest_info;
200df2d8b3eSIsaku Yamahata     /* pci */
201df2d8b3eSIsaku Yamahata     qdev_init_nofail(DEVICE(q35_host));
202ce88812fSHu Tao     phb = PCI_HOST_BRIDGE(q35_host);
203ce88812fSHu Tao     host_bus = phb->bus;
204df2d8b3eSIsaku Yamahata     /* create ISA bus */
205df2d8b3eSIsaku Yamahata     lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
206df2d8b3eSIsaku Yamahata                                           ICH9_LPC_FUNC), true,
207df2d8b3eSIsaku Yamahata                                           TYPE_ICH9_LPC_DEVICE);
208781bbd6bSIgor Mammedov 
209781bbd6bSIgor Mammedov     object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
210781bbd6bSIgor Mammedov                              TYPE_HOTPLUG_HANDLER,
211781bbd6bSIgor Mammedov                              (Object **)&pc_machine->acpi_dev,
212781bbd6bSIgor Mammedov                              object_property_allow_set_link,
213781bbd6bSIgor Mammedov                              OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
214781bbd6bSIgor Mammedov     object_property_set_link(OBJECT(machine), OBJECT(lpc),
215781bbd6bSIgor Mammedov                              PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
216781bbd6bSIgor Mammedov 
217df2d8b3eSIsaku Yamahata     ich9_lpc = ICH9_LPC_DEVICE(lpc);
218df2d8b3eSIsaku Yamahata     ich9_lpc->pic = gsi;
219df2d8b3eSIsaku Yamahata     ich9_lpc->ioapic = gsi_state->ioapic_irq;
220df2d8b3eSIsaku Yamahata     pci_bus_irqs(host_bus, ich9_lpc_set_irq, ich9_lpc_map_irq, ich9_lpc,
221df2d8b3eSIsaku Yamahata                  ICH9_LPC_NB_PIRQS);
22291c3f2f0SJason Baron     pci_bus_set_route_irq_fn(host_bus, ich9_route_intx_pin_to_irq);
223df2d8b3eSIsaku Yamahata     isa_bus = ich9_lpc->isa_bus;
224df2d8b3eSIsaku Yamahata 
225df2d8b3eSIsaku Yamahata     /*end early*/
226df2d8b3eSIsaku Yamahata     isa_bus_irqs(isa_bus, gsi);
227df2d8b3eSIsaku Yamahata 
228df2d8b3eSIsaku Yamahata     if (kvm_irqchip_in_kernel()) {
229df2d8b3eSIsaku Yamahata         i8259 = kvm_i8259_init(isa_bus);
230df2d8b3eSIsaku Yamahata     } else if (xen_enabled()) {
231df2d8b3eSIsaku Yamahata         i8259 = xen_interrupt_controller_init();
232df2d8b3eSIsaku Yamahata     } else {
233df2d8b3eSIsaku Yamahata         cpu_irq = pc_allocate_cpu_irq();
234df2d8b3eSIsaku Yamahata         i8259 = i8259_init(isa_bus, cpu_irq[0]);
235df2d8b3eSIsaku Yamahata     }
236df2d8b3eSIsaku Yamahata 
237df2d8b3eSIsaku Yamahata     for (i = 0; i < ISA_NUM_IRQS; i++) {
238df2d8b3eSIsaku Yamahata         gsi_state->i8259_irq[i] = i8259[i];
239df2d8b3eSIsaku Yamahata     }
240df2d8b3eSIsaku Yamahata     if (pci_enabled) {
241552b48f4SJohn Snow         ioapic_init_gsi(gsi_state, "q35");
242df2d8b3eSIsaku Yamahata     }
243f0513d2cSIgor Mammedov     qdev_init_nofail(icc_bridge);
244df2d8b3eSIsaku Yamahata 
245df2d8b3eSIsaku Yamahata     pc_register_ferr_irq(gsi[13]);
246df2d8b3eSIsaku Yamahata 
247d1048befSDon Slutz     assert(pc_machine->vmport != ON_OFF_AUTO_MAX);
248d1048befSDon Slutz     if (pc_machine->vmport == ON_OFF_AUTO_AUTO) {
249d1048befSDon Slutz         pc_machine->vmport = xen_enabled() ? ON_OFF_AUTO_OFF : ON_OFF_AUTO_ON;
250d1048befSDon Slutz     }
251d1048befSDon Slutz 
252df2d8b3eSIsaku Yamahata     /* init basic PC hardware */
2539b23cfb7SDr. David Alan Gilbert     pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy,
254d1048befSDon Slutz                          (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);
255df2d8b3eSIsaku Yamahata 
256df2d8b3eSIsaku Yamahata     /* connect pm stuff to lpc */
257a3ac6b53SHu Tao     ich9_lpc_pm_init(lpc);
258df2d8b3eSIsaku Yamahata 
259df2d8b3eSIsaku Yamahata     /* ahci and SATA device, for q35 1 ahci controller is built-in */
260df2d8b3eSIsaku Yamahata     ahci = pci_create_simple_multifunction(host_bus,
261df2d8b3eSIsaku Yamahata                                            PCI_DEVFN(ICH9_SATA1_DEV,
262df2d8b3eSIsaku Yamahata                                                      ICH9_SATA1_FUNC),
263df2d8b3eSIsaku Yamahata                                            true, "ich9-ahci");
264df2d8b3eSIsaku Yamahata     idebus[0] = qdev_get_child_bus(&ahci->qdev, "ide.0");
265df2d8b3eSIsaku Yamahata     idebus[1] = qdev_get_child_bus(&ahci->qdev, "ide.1");
26601a2050fSPeter Maydell     g_assert(MAX_SATA_PORTS == ICH_AHCI(ahci)->ahci.ports);
267d93162e1SJohn Snow     ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
268d93162e1SJohn Snow     ahci_ide_create_devs(ahci, hd);
269df2d8b3eSIsaku Yamahata 
270de77a243SMarcel Apfelbaum     if (usb_enabled()) {
271df2d8b3eSIsaku Yamahata         /* Should we create 6 UHCI according to ich9 spec? */
272df2d8b3eSIsaku Yamahata         ehci_create_ich9_with_companions(host_bus, 0x1d);
273df2d8b3eSIsaku Yamahata     }
274df2d8b3eSIsaku Yamahata 
275df2d8b3eSIsaku Yamahata     /* TODO: Populate SPD eeprom data.  */
276df2d8b3eSIsaku Yamahata     smbus_eeprom_init(ich9_smb_init(host_bus,
277df2d8b3eSIsaku Yamahata                                     PCI_DEVFN(ICH9_SMB_DEV, ICH9_SMB_FUNC),
278df2d8b3eSIsaku Yamahata                                     0xb100),
279df2d8b3eSIsaku Yamahata                       8, NULL, 0);
280df2d8b3eSIsaku Yamahata 
2813ef96221SMarcel Apfelbaum     pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine->boot_order,
2822d996150SGu Zheng                  machine, floppy, idebus[0], idebus[1], rtc_state);
283df2d8b3eSIsaku Yamahata 
284df2d8b3eSIsaku Yamahata     /* the rest devices to which pci devfn is automatically assigned */
285df2d8b3eSIsaku Yamahata     pc_vga_init(isa_bus, host_bus);
286df2d8b3eSIsaku Yamahata     pc_nic_init(isa_bus, host_bus);
287df2d8b3eSIsaku Yamahata     if (pci_enabled) {
288df2d8b3eSIsaku Yamahata         pc_pci_device_init(host_bus);
289df2d8b3eSIsaku Yamahata     }
290df2d8b3eSIsaku Yamahata }
291df2d8b3eSIsaku Yamahata 
2925cb50e0aSJason Wang static void pc_compat_2_3(MachineState *machine)
2935cb50e0aSJason Wang {
2945cb50e0aSJason Wang }
2955cb50e0aSJason Wang 
29664bbd372SPaolo Bonzini static void pc_compat_2_2(MachineState *machine)
29764bbd372SPaolo Bonzini {
2985cb50e0aSJason Wang     pc_compat_2_3(machine);
299384fb32eSMichael S. Tsirkin     rsdp_in_ram = false;
300b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
301b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
302b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
303b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Penryn", FEAT_1_EDX, 0, CPUID_VME);
304b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Nehalem", FEAT_1_EDX, 0, CPUID_VME);
305b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Westmere", FEAT_1_EDX, 0, CPUID_VME);
306b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("SandyBridge", FEAT_1_EDX, 0, CPUID_VME);
307b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Haswell", FEAT_1_EDX, 0, CPUID_VME);
308b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Broadwell", FEAT_1_EDX, 0, CPUID_VME);
309b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Opteron_G1", FEAT_1_EDX, 0, CPUID_VME);
310b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Opteron_G2", FEAT_1_EDX, 0, CPUID_VME);
311b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Opteron_G3", FEAT_1_EDX, 0, CPUID_VME);
312b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Opteron_G4", FEAT_1_EDX, 0, CPUID_VME);
313b3a4f0b1SPaolo Bonzini     x86_cpu_compat_set_features("Opteron_G5", FEAT_1_EDX, 0, CPUID_VME);
31478a611f1SPaolo Bonzini     x86_cpu_compat_set_features("Haswell", FEAT_1_ECX, 0, CPUID_EXT_F16C);
31578a611f1SPaolo Bonzini     x86_cpu_compat_set_features("Haswell", FEAT_1_ECX, 0, CPUID_EXT_RDRAND);
31678a611f1SPaolo Bonzini     x86_cpu_compat_set_features("Broadwell", FEAT_1_ECX, 0, CPUID_EXT_F16C);
31778a611f1SPaolo Bonzini     x86_cpu_compat_set_features("Broadwell", FEAT_1_ECX, 0, CPUID_EXT_RDRAND);
31854ed388bSAlexander Graf     machine->suppress_vmdesc = true;
31964bbd372SPaolo Bonzini }
32064bbd372SPaolo Bonzini 
3212cad57c7SEduardo Habkost static void pc_compat_2_1(MachineState *machine)
3222cad57c7SEduardo Habkost {
32391aa70abSIgor Mammedov     PCMachineState *pcms = PC_MACHINE(machine);
32491aa70abSIgor Mammedov 
32564bbd372SPaolo Bonzini     pc_compat_2_2(machine);
32691aa70abSIgor Mammedov     pcms->enforce_aligned_dimm = false;
327caad057bSEduardo Habkost     smbios_uuid_encoded = false;
328e93abc14SEduardo Habkost     x86_cpu_compat_set_features("coreduo", FEAT_1_ECX, CPUID_EXT_VMX, 0);
329e93abc14SEduardo Habkost     x86_cpu_compat_set_features("core2duo", FEAT_1_ECX, CPUID_EXT_VMX, 0);
33075d373efSEduardo Habkost     x86_cpu_compat_kvm_no_autodisable(FEAT_8000_0001_ECX, CPUID_EXT3_SVM);
3312cad57c7SEduardo Habkost }
3322cad57c7SEduardo Habkost 
3333ef96221SMarcel Apfelbaum static void pc_compat_2_0(MachineState *machine)
3343458b2b0SMichael S. Tsirkin {
3352cad57c7SEduardo Habkost     pc_compat_2_1(machine);
336c97294ecSGabriel L. Somlo     smbios_legacy_mode = true;
337de268e13SIgor Mammedov     has_reserved_memory = false;
338927766c7SMichael S. Tsirkin     pc_set_legacy_acpi_data_size();
3393458b2b0SMichael S. Tsirkin }
3403458b2b0SMichael S. Tsirkin 
3413ef96221SMarcel Apfelbaum static void pc_compat_1_7(MachineState *machine)
342b29ad07eSMarkus Armbruster {
3433ef96221SMarcel Apfelbaum     pc_compat_2_0(machine);
344e6667f71SGabriel L. Somlo     smbios_defaults = false;
3459a305c8fSGerd Hoffmann     gigabyte_align = false;
346ac41881bSMichael S. Tsirkin     option_rom_has_mr = true;
3471cadaa94SEduardo Habkost     x86_cpu_compat_kvm_no_autoenable(FEAT_1_ECX, CPUID_EXT_X2APIC);
348b29ad07eSMarkus Armbruster }
349b29ad07eSMarkus Armbruster 
3503ef96221SMarcel Apfelbaum static void pc_compat_1_6(MachineState *machine)
351f8c457b8SMichael S. Tsirkin {
3523ef96221SMarcel Apfelbaum     pc_compat_1_7(machine);
35398bc3ab0SMichael S. Tsirkin     rom_file_has_mr = false;
35472c194f7SMichael S. Tsirkin     has_acpi_build = false;
35589b439f3SEduardo Habkost }
35689b439f3SEduardo Habkost 
3573ef96221SMarcel Apfelbaum static void pc_compat_1_5(MachineState *machine)
35889b439f3SEduardo Habkost {
3593ef96221SMarcel Apfelbaum     pc_compat_1_6(machine);
36089b439f3SEduardo Habkost }
36189b439f3SEduardo Habkost 
3623ef96221SMarcel Apfelbaum static void pc_compat_1_4(MachineState *machine)
36389b439f3SEduardo Habkost {
3643ef96221SMarcel Apfelbaum     pc_compat_1_5(machine);
36589b439f3SEduardo Habkost     x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
36689b439f3SEduardo Habkost     x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ);
36789b439f3SEduardo Habkost }
36889b439f3SEduardo Habkost 
3695cb50e0aSJason Wang static void pc_q35_init_2_3(MachineState *machine)
3705cb50e0aSJason Wang {
3715cb50e0aSJason Wang     pc_compat_2_3(machine);
3725cb50e0aSJason Wang     pc_q35_init(machine);
3735cb50e0aSJason Wang }
3745cb50e0aSJason Wang 
37564bbd372SPaolo Bonzini static void pc_q35_init_2_2(MachineState *machine)
37664bbd372SPaolo Bonzini {
37764bbd372SPaolo Bonzini     pc_compat_2_2(machine);
37864bbd372SPaolo Bonzini     pc_q35_init(machine);
37964bbd372SPaolo Bonzini }
38064bbd372SPaolo Bonzini 
3812cad57c7SEduardo Habkost static void pc_q35_init_2_1(MachineState *machine)
3822cad57c7SEduardo Habkost {
3832cad57c7SEduardo Habkost     pc_compat_2_1(machine);
3842cad57c7SEduardo Habkost     pc_q35_init(machine);
3852cad57c7SEduardo Habkost }
3862cad57c7SEduardo Habkost 
3873ef96221SMarcel Apfelbaum static void pc_q35_init_2_0(MachineState *machine)
3883458b2b0SMichael S. Tsirkin {
3893ef96221SMarcel Apfelbaum     pc_compat_2_0(machine);
3903ef96221SMarcel Apfelbaum     pc_q35_init(machine);
3913458b2b0SMichael S. Tsirkin }
3923458b2b0SMichael S. Tsirkin 
3933ef96221SMarcel Apfelbaum static void pc_q35_init_1_7(MachineState *machine)
394b29ad07eSMarkus Armbruster {
3953ef96221SMarcel Apfelbaum     pc_compat_1_7(machine);
3963ef96221SMarcel Apfelbaum     pc_q35_init(machine);
397b29ad07eSMarkus Armbruster }
398b29ad07eSMarkus Armbruster 
3993ef96221SMarcel Apfelbaum static void pc_q35_init_1_6(MachineState *machine)
40089b439f3SEduardo Habkost {
4013ef96221SMarcel Apfelbaum     pc_compat_1_6(machine);
4023ef96221SMarcel Apfelbaum     pc_q35_init(machine);
403f8c457b8SMichael S. Tsirkin }
404f8c457b8SMichael S. Tsirkin 
4053ef96221SMarcel Apfelbaum static void pc_q35_init_1_5(MachineState *machine)
4069604f70fSMichael S. Tsirkin {
4073ef96221SMarcel Apfelbaum     pc_compat_1_5(machine);
4083ef96221SMarcel Apfelbaum     pc_q35_init(machine);
4099604f70fSMichael S. Tsirkin }
4109604f70fSMichael S. Tsirkin 
4113ef96221SMarcel Apfelbaum static void pc_q35_init_1_4(MachineState *machine)
4129953f882SMarkus Armbruster {
4133ef96221SMarcel Apfelbaum     pc_compat_1_4(machine);
4143ef96221SMarcel Apfelbaum     pc_q35_init(machine);
4159953f882SMarkus Armbruster }
4169953f882SMarkus Armbruster 
417fddd179aSEduardo Habkost static void pc_q35_machine_options(QEMUMachine *m)
418fddd179aSEduardo Habkost {
419fddd179aSEduardo Habkost     pc_default_machine_options(m);
420fddd179aSEduardo Habkost     m->family = "pc_q35";
421fddd179aSEduardo Habkost     m->desc = "Standard PC (Q35 + ICH9, 2009)";
422fddd179aSEduardo Habkost     m->hot_add_cpu = pc_hot_add_cpu;
423fddd179aSEduardo Habkost     m->units_per_default_bus = 1;
424fddd179aSEduardo Habkost }
425a0dba644SMichael S. Tsirkin 
426fddd179aSEduardo Habkost static void pc_q35_2_4_machine_options(QEMUMachine *m)
427fddd179aSEduardo Habkost {
428fddd179aSEduardo Habkost     pc_q35_machine_options(m);
429fddd179aSEduardo Habkost     m->default_machine_opts = "firmware=bios-256k.bin";
430fddd179aSEduardo Habkost     m->default_display = "std";
431fddd179aSEduardo Habkost     m->alias = "q35";
432fddd179aSEduardo Habkost }
433aeca6e8dSGerd Hoffmann 
43461f219dfSEduardo Habkost DEFINE_PC_MACHINE(v2_4, "pc-q35-2.4", pc_q35_init,
435*25519b06SEduardo Habkost                   pc_q35_2_4_machine_options);
43661f219dfSEduardo Habkost 
4375cb50e0aSJason Wang 
438fddd179aSEduardo Habkost static void pc_q35_2_3_machine_options(QEMUMachine *m)
439fddd179aSEduardo Habkost {
440fddd179aSEduardo Habkost     pc_q35_2_4_machine_options(m);
441fddd179aSEduardo Habkost     m->alias = NULL;
442*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_2_3);
443fddd179aSEduardo Habkost }
4445cb50e0aSJason Wang 
44561f219dfSEduardo Habkost DEFINE_PC_MACHINE(v2_3, "pc-q35-2.3", pc_q35_init_2_3,
446*25519b06SEduardo Habkost                   pc_q35_2_3_machine_options);
44761f219dfSEduardo Habkost 
44864bbd372SPaolo Bonzini 
449fddd179aSEduardo Habkost static void pc_q35_2_2_machine_options(QEMUMachine *m)
450fddd179aSEduardo Habkost {
451fddd179aSEduardo Habkost     pc_q35_2_3_machine_options(m);
452*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_2_2);
453fddd179aSEduardo Habkost }
45464bbd372SPaolo Bonzini 
45561f219dfSEduardo Habkost DEFINE_PC_MACHINE(v2_2, "pc-q35-2.2", pc_q35_init_2_2,
456*25519b06SEduardo Habkost                   pc_q35_2_2_machine_options);
45761f219dfSEduardo Habkost 
458f9f21873SJan Kiszka 
459fddd179aSEduardo Habkost static void pc_q35_2_1_machine_options(QEMUMachine *m)
460fddd179aSEduardo Habkost {
461fddd179aSEduardo Habkost     pc_q35_2_2_machine_options(m);
462fddd179aSEduardo Habkost     m->default_display = NULL;
463*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_2_1);
464fddd179aSEduardo Habkost }
465f9f21873SJan Kiszka 
46661f219dfSEduardo Habkost DEFINE_PC_MACHINE(v2_1, "pc-q35-2.1", pc_q35_init_2_1,
467*25519b06SEduardo Habkost                   pc_q35_2_1_machine_options);
46861f219dfSEduardo Habkost 
4693458b2b0SMichael S. Tsirkin 
470fddd179aSEduardo Habkost static void pc_q35_2_0_machine_options(QEMUMachine *m)
471fddd179aSEduardo Habkost {
472fddd179aSEduardo Habkost     pc_q35_2_1_machine_options(m);
473*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_2_0);
474fddd179aSEduardo Habkost }
4753458b2b0SMichael S. Tsirkin 
47661f219dfSEduardo Habkost DEFINE_PC_MACHINE(v2_0, "pc-q35-2.0", pc_q35_init_2_0,
477*25519b06SEduardo Habkost                   pc_q35_2_0_machine_options);
47861f219dfSEduardo Habkost 
479aeca6e8dSGerd Hoffmann 
480fddd179aSEduardo Habkost static void pc_q35_1_7_machine_options(QEMUMachine *m)
481fddd179aSEduardo Habkost {
482fddd179aSEduardo Habkost     pc_q35_2_0_machine_options(m);
483fddd179aSEduardo Habkost     m->default_machine_opts = NULL;
484*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_1_7);
485fddd179aSEduardo Habkost }
486e9845f09SVincenzo Maffione 
48761f219dfSEduardo Habkost DEFINE_PC_MACHINE(v1_7, "pc-q35-1.7", pc_q35_init_1_7,
488*25519b06SEduardo Habkost                   pc_q35_1_7_machine_options);
48961f219dfSEduardo Habkost 
490e9845f09SVincenzo Maffione 
491fddd179aSEduardo Habkost static void pc_q35_1_6_machine_options(QEMUMachine *m)
492fddd179aSEduardo Habkost {
493fddd179aSEduardo Habkost     pc_q35_machine_options(m);
494*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_1_6);
495fddd179aSEduardo Habkost }
496a0dba644SMichael S. Tsirkin 
49761f219dfSEduardo Habkost DEFINE_PC_MACHINE(v1_6, "pc-q35-1.6", pc_q35_init_1_6,
498*25519b06SEduardo Habkost                   pc_q35_1_6_machine_options);
49961f219dfSEduardo Habkost 
50045053fdeSEduardo Habkost 
501fddd179aSEduardo Habkost static void pc_q35_1_5_machine_options(QEMUMachine *m)
502fddd179aSEduardo Habkost {
503fddd179aSEduardo Habkost     pc_q35_1_6_machine_options(m);
504*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_1_5);
505fddd179aSEduardo Habkost }
506b6b5c8e4SEduardo Habkost 
50761f219dfSEduardo Habkost DEFINE_PC_MACHINE(v1_5, "pc-q35-1.5", pc_q35_init_1_5,
508*25519b06SEduardo Habkost                   pc_q35_1_5_machine_options);
50961f219dfSEduardo Habkost 
510df2d8b3eSIsaku Yamahata 
511fddd179aSEduardo Habkost static void pc_q35_1_4_machine_options(QEMUMachine *m)
512fddd179aSEduardo Habkost {
513fddd179aSEduardo Habkost     pc_q35_1_5_machine_options(m);
514fddd179aSEduardo Habkost     m->hot_add_cpu = NULL;
515*25519b06SEduardo Habkost     SET_MACHINE_COMPAT(m, PC_COMPAT_1_4);
516fddd179aSEduardo Habkost }
517a0dba644SMichael S. Tsirkin 
51861f219dfSEduardo Habkost DEFINE_PC_MACHINE(v1_4, "pc-q35-1.4", pc_q35_init_1_4,
519*25519b06SEduardo Habkost                   pc_q35_1_4_machine_options);
520