diff options
Diffstat (limited to 'hw/i386/pc_piix.c')
-rw-r--r-- | hw/i386/pc_piix.c | 331 |
1 files changed, 195 insertions, 136 deletions
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 6e1e654f3..7930a26c1 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -25,8 +25,10 @@ #include <glib.h> #include "hw/hw.h" +#include "hw/loader.h" #include "hw/i386/pc.h" #include "hw/i386/apic.h" +#include "hw/i386/smbios.h" #include "hw/pci/pci.h" #include "hw/pci/pci_ids.h" #include "hw/usb.h" @@ -56,21 +58,22 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 }; static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 }; static const int ide_irq[MAX_IDE_BUS] = { 14, 15 }; -static bool has_pvpanic; -static bool has_pci_info = true; +static bool has_pci_info; +static bool has_acpi_build = true; +static bool smbios_type1_defaults = true; +/* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to + * host addresses aligned at 1Gbyte boundaries. This way we can use 1GByte + * pages in the host. + */ +static bool gigabyte_align = true; /* PC hardware initialisation */ -static void pc_init1(MemoryRegion *system_memory, - MemoryRegion *system_io, - ram_addr_t ram_size, - const char *boot_device, - const char *kernel_filename, - const char *kernel_cmdline, - const char *initrd_filename, - const char *cpu_model, +static void pc_init1(QEMUMachineInitArgs *args, int pci_enabled, int kvmclock_enabled) { + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *system_io = get_system_io(); int i; ram_addr_t below_4g_mem_size, above_4g_mem_size; PCIBus *pci_bus; @@ -93,7 +96,7 @@ static void pc_init1(MemoryRegion *system_memory, FWCfgState *fw_cfg = NULL; PcGuestInfo *guest_info; - if (xen_enabled() && xen_hvm_init() != 0) { + if (xen_enabled() && xen_hvm_init(&ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisation failed\n"); exit(1); } @@ -102,23 +105,31 @@ static void pc_init1(MemoryRegion *system_memory, object_property_add_child(qdev_get_machine(), "icc-bridge", OBJECT(icc_bridge), NULL); - pc_cpus_init(cpu_model, icc_bridge); + pc_cpus_init(args->cpu_model, icc_bridge); if (kvm_enabled() && kvmclock_enabled) { kvmclock_create(); } - if (ram_size >= 0xe0000000 ) { - above_4g_mem_size = ram_size - 0xe0000000; - below_4g_mem_size = 0xe0000000; + /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory). + * If it doesn't, we need to split it in chunks below and above 4G. + * In any case, try to make sure that guest addresses aligned at + * 1G boundaries get mapped to host addresses aligned at 1G boundaries. + * For old machine types, use whatever split we used historically to avoid + * breaking migration. + */ + if (args->ram_size >= 0xe0000000) { + ram_addr_t lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000; + above_4g_mem_size = args->ram_size - lowmem; + below_4g_mem_size = lowmem; } else { above_4g_mem_size = 0; - below_4g_mem_size = ram_size; + below_4g_mem_size = args->ram_size; } if (pci_enabled) { pci_memory = g_new(MemoryRegion, 1); - memory_region_init(pci_memory, NULL, "pci", INT64_MAX); + memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); rom_memory = pci_memory; } else { pci_memory = NULL; @@ -126,13 +137,23 @@ static void pc_init1(MemoryRegion *system_memory, } guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size); + + guest_info->has_acpi_build = has_acpi_build; + guest_info->has_pci_info = has_pci_info; guest_info->isapc_ram_fw = !pci_enabled; + if (smbios_type1_defaults) { + /* These values are guest ABI, do not change */ + smbios_set_type1_defaults("QEMU", "Standard PC (i440FX + PIIX, 1996)", + args->machine->name); + } + /* allocate ram and load rom/bios */ if (!xen_enabled()) { fw_cfg = pc_memory_init(system_memory, - kernel_filename, kernel_cmdline, initrd_filename, + args->kernel_filename, args->kernel_cmdline, + args->initrd_filename, below_4g_mem_size, above_4g_mem_size, rom_memory, &ram_memory, guest_info); } @@ -148,9 +169,8 @@ static void pc_init1(MemoryRegion *system_memory, if (pci_enabled) { pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi, - system_memory, system_io, ram_size, + system_memory, system_io, args->ram_size, below_4g_mem_size, - 0x100000000ULL - below_4g_mem_size, above_4g_mem_size, pci_memory, ram_memory); } else { @@ -183,7 +203,8 @@ static void pc_init1(MemoryRegion *system_memory, pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL); /* init basic PC hardware */ - pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled()); + pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled(), + 0x4); pc_nic_init(isa_bus, pci_bus); @@ -200,14 +221,20 @@ static void pc_init1(MemoryRegion *system_memory, } else { for(i = 0; i < MAX_IDE_BUS; i++) { ISADevice *dev; + char busname[] = "ide.0"; dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); - idebus[i] = qdev_get_child_bus(DEVICE(dev), "ide.0"); + /* + * The ide bus name is ide.0 for the first bus and ide.1 for the + * second one. + */ + busname[4] = '0' + i; + idebus[i] = qdev_get_child_bus(DEVICE(dev), busname); } } - pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, + pc_cmos_init(below_4g_mem_size, above_4g_mem_size, args->boot_order, floppy, idebus[0], idebus[1], rtc_state); if (pci_enabled && usb_enabled(false)) { @@ -215,7 +242,7 @@ static void pc_init1(MemoryRegion *system_memory, } if (pci_enabled && acpi_enabled) { - i2c_bus *smbus; + I2CBus *smbus; smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1); /* TODO: Populate SPD eeprom data. */ @@ -228,103 +255,113 @@ static void pc_init1(MemoryRegion *system_memory, if (pci_enabled) { pc_pci_device_init(pci_bus); } - - if (has_pvpanic) { - pvpanic_init(isa_bus); - } } static void pc_init_pci(QEMUMachineInitArgs *args) { - ram_addr_t ram_size = args->ram_size; - const char *cpu_model = args->cpu_model; - const char *kernel_filename = args->kernel_filename; - const char *kernel_cmdline = args->kernel_cmdline; - const char *initrd_filename = args->initrd_filename; - const char *boot_device = args->boot_device; - pc_init1(get_system_memory(), - get_system_io(), - ram_size, boot_device, - kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 1, 1); + pc_init1(args, 1, 1); } -static void pc_init_pci_1_6(QEMUMachineInitArgs *args) +static void pc_compat_1_7(QEMUMachineInitArgs *args) { + smbios_type1_defaults = false; + gigabyte_align = false; + option_rom_has_mr = true; + x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC); +} + +static void pc_compat_1_6(QEMUMachineInitArgs *args) +{ + pc_compat_1_7(args); has_pci_info = false; - pc_init_pci(args); + rom_file_has_mr = false; + has_acpi_build = false; } -static void pc_init_pci_1_5(QEMUMachineInitArgs *args) +static void pc_compat_1_5(QEMUMachineInitArgs *args) { - has_pvpanic = true; - pc_init_pci_1_6(args); + pc_compat_1_6(args); } -static void pc_init_pci_1_4(QEMUMachineInitArgs *args) +static void pc_compat_1_4(QEMUMachineInitArgs *args) { + pc_compat_1_5(args); x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE); x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ); - has_pci_info = false; - pc_init_pci(args); } -static void pc_init_pci_1_3(QEMUMachineInitArgs *args) +static void pc_compat_1_3(QEMUMachineInitArgs *args) { + pc_compat_1_4(args); enable_compat_apic_id_mode(); - pc_init_pci_1_4(args); } -/* PC machine init function for pc-1.1 to pc-1.2 */ -static void pc_init_pci_1_2(QEMUMachineInitArgs *args) +/* PC compat function for pc-0.14 to pc-1.2 */ +static void pc_compat_1_2(QEMUMachineInitArgs *args) +{ + pc_compat_1_3(args); + x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI); +} + +static void pc_init_pci_1_7(QEMUMachineInitArgs *args) +{ + pc_compat_1_7(args); + pc_init_pci(args); +} + +static void pc_init_pci_1_6(QEMUMachineInitArgs *args) +{ + pc_compat_1_6(args); + pc_init_pci(args); +} + +static void pc_init_pci_1_5(QEMUMachineInitArgs *args) +{ + pc_compat_1_5(args); + pc_init_pci(args); +} + +static void pc_init_pci_1_4(QEMUMachineInitArgs *args) +{ + pc_compat_1_4(args); + pc_init_pci(args); +} + +static void pc_init_pci_1_3(QEMUMachineInitArgs *args) { - disable_kvm_pv_eoi(); - pc_init_pci_1_3(args); + pc_compat_1_3(args); + pc_init_pci(args); } -/* PC machine init function for pc-0.14 to pc-1.0 */ -static void pc_init_pci_1_0(QEMUMachineInitArgs *args) +/* PC machine init function for pc-0.14 to pc-1.2 */ +static void pc_init_pci_1_2(QEMUMachineInitArgs *args) { - pc_init_pci_1_2(args); + pc_compat_1_2(args); + pc_init_pci(args); } /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */ static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args) { - ram_addr_t ram_size = args->ram_size; - const char *cpu_model = args->cpu_model; - const char *kernel_filename = args->kernel_filename; - const char *kernel_cmdline = args->kernel_cmdline; - const char *initrd_filename = args->initrd_filename; - const char *boot_device = args->boot_device; has_pci_info = false; - disable_kvm_pv_eoi(); + has_acpi_build = false; + smbios_type1_defaults = false; + x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI); enable_compat_apic_id_mode(); - pc_init1(get_system_memory(), - get_system_io(), - ram_size, boot_device, - kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 1, 0); + pc_init1(args, 1, 0); } static void pc_init_isa(QEMUMachineInitArgs *args) { - ram_addr_t ram_size = args->ram_size; - const char *cpu_model = args->cpu_model; - const char *kernel_filename = args->kernel_filename; - const char *kernel_cmdline = args->kernel_cmdline; - const char *initrd_filename = args->initrd_filename; - const char *boot_device = args->boot_device; has_pci_info = false; - if (cpu_model == NULL) - cpu_model = "486"; - disable_kvm_pv_eoi(); + has_acpi_build = false; + smbios_type1_defaults = false; + if (!args->cpu_model) { + args->cpu_model = "486"; + } + x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI); enable_compat_apic_id_mode(); - pc_init1(get_system_memory(), - get_system_io(), - ram_size, boot_device, - kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 0, 1); + pc_init1(args, 0, 1); } #ifdef CONFIG_XEN @@ -341,40 +378,69 @@ static void pc_xen_hvm_init(QEMUMachineInitArgs *args) } #endif +#define PC_I440FX_MACHINE_OPTIONS \ + PC_DEFAULT_MACHINE_OPTIONS, \ + .desc = "Standard PC (i440FX + PIIX, 1996)", \ + .hot_add_cpu = pc_hot_add_cpu + +#define PC_I440FX_2_0_MACHINE_OPTIONS \ + PC_I440FX_MACHINE_OPTIONS, \ + .default_machine_opts = "firmware=bios-256k.bin" + +static QEMUMachine pc_i440fx_machine_v2_0 = { + PC_I440FX_2_0_MACHINE_OPTIONS, + .name = "pc-i440fx-2.0", + .alias = "pc", + .init = pc_init_pci, + .is_default = 1, +}; + +#define PC_I440FX_1_7_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS + +static QEMUMachine pc_i440fx_machine_v1_7 = { + PC_I440FX_1_7_MACHINE_OPTIONS, + .name = "pc-i440fx-1.7", + .init = pc_init_pci_1_7, + .compat_props = (GlobalProperty[]) { + PC_COMPAT_1_7, + { /* end of list */ } + }, +}; + +#define PC_I440FX_1_6_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS + static QEMUMachine pc_i440fx_machine_v1_6 = { + PC_I440FX_1_6_MACHINE_OPTIONS, .name = "pc-i440fx-1.6", - .alias = "pc", - .desc = "Standard PC (i440FX + PIIX, 1996)", .init = pc_init_pci_1_6, - .hot_add_cpu = pc_hot_add_cpu, - .max_cpus = 255, - .is_default = 1, - DEFAULT_MACHINE_OPTIONS, + .compat_props = (GlobalProperty[]) { + PC_COMPAT_1_6, + { /* end of list */ } + }, }; static QEMUMachine pc_i440fx_machine_v1_5 = { + PC_I440FX_1_6_MACHINE_OPTIONS, .name = "pc-i440fx-1.5", - .desc = "Standard PC (i440FX + PIIX, 1996)", .init = pc_init_pci_1_5, - .hot_add_cpu = pc_hot_add_cpu, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_1_5, { /* end of list */ } }, - DEFAULT_MACHINE_OPTIONS, }; +#define PC_I440FX_1_4_MACHINE_OPTIONS \ + PC_I440FX_1_6_MACHINE_OPTIONS, \ + .hot_add_cpu = NULL + static QEMUMachine pc_i440fx_machine_v1_4 = { + PC_I440FX_1_4_MACHINE_OPTIONS, .name = "pc-i440fx-1.4", - .desc = "Standard PC (i440FX + PIIX, 1996)", .init = pc_init_pci_1_4, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_1_4, { /* end of list */ } }, - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_1_3 \ @@ -398,15 +464,13 @@ static QEMUMachine pc_i440fx_machine_v1_4 = { } static QEMUMachine pc_machine_v1_3 = { + PC_I440FX_1_4_MACHINE_OPTIONS, .name = "pc-1.3", - .desc = "Standard PC", .init = pc_init_pci_1_3, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_1_3, { /* end of list */ } }, - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_1_2 \ @@ -437,16 +501,17 @@ static QEMUMachine pc_machine_v1_3 = { .value = "off",\ } +#define PC_I440FX_1_2_MACHINE_OPTIONS \ + PC_I440FX_1_4_MACHINE_OPTIONS, \ + .init = pc_init_pci_1_2 + static QEMUMachine pc_machine_v1_2 = { + PC_I440FX_1_2_MACHINE_OPTIONS, .name = "pc-1.2", - .desc = "Standard PC", - .init = pc_init_pci_1_2, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_1_2, { /* end of list */ } }, - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_1_1 \ @@ -482,15 +547,12 @@ static QEMUMachine pc_machine_v1_2 = { } static QEMUMachine pc_machine_v1_1 = { + PC_I440FX_1_2_MACHINE_OPTIONS, .name = "pc-1.1", - .desc = "Standard PC", - .init = pc_init_pci_1_2, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_1_1, { /* end of list */ } }, - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_1_0 \ @@ -514,32 +576,26 @@ static QEMUMachine pc_machine_v1_1 = { } static QEMUMachine pc_machine_v1_0 = { + PC_I440FX_1_2_MACHINE_OPTIONS, .name = "pc-1.0", - .desc = "Standard PC", - .init = pc_init_pci_1_0, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_1_0, { /* end of list */ } }, .hw_version = "1.0", - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_0_15 \ PC_COMPAT_1_0 static QEMUMachine pc_machine_v0_15 = { + PC_I440FX_1_2_MACHINE_OPTIONS, .name = "pc-0.15", - .desc = "Standard PC", - .init = pc_init_pci_1_0, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_0_15, { /* end of list */ } }, .hw_version = "0.15", - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_0_14 \ @@ -563,10 +619,8 @@ static QEMUMachine pc_machine_v0_15 = { } static QEMUMachine pc_machine_v0_14 = { + PC_I440FX_1_2_MACHINE_OPTIONS, .name = "pc-0.14", - .desc = "Standard PC", - .init = pc_init_pci_1_0, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_0_14, { @@ -581,7 +635,6 @@ static QEMUMachine pc_machine_v0_14 = { { /* end of list */ } }, .hw_version = "0.14", - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_0_13 \ @@ -596,11 +649,13 @@ static QEMUMachine pc_machine_v0_14 = { .value = stringify(1),\ } +#define PC_I440FX_0_13_MACHINE_OPTIONS \ + PC_I440FX_1_2_MACHINE_OPTIONS, \ + .init = pc_init_pci_no_kvmclock + static QEMUMachine pc_machine_v0_13 = { + PC_I440FX_0_13_MACHINE_OPTIONS, .name = "pc-0.13", - .desc = "Standard PC", - .init = pc_init_pci_no_kvmclock, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_0_13, { @@ -619,7 +674,6 @@ static QEMUMachine pc_machine_v0_13 = { { /* end of list */ } }, .hw_version = "0.13", - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_0_12 \ @@ -647,10 +701,8 @@ static QEMUMachine pc_machine_v0_13 = { } static QEMUMachine pc_machine_v0_12 = { + PC_I440FX_0_13_MACHINE_OPTIONS, .name = "pc-0.12", - .desc = "Standard PC", - .init = pc_init_pci_no_kvmclock, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_0_12, { @@ -665,7 +717,6 @@ static QEMUMachine pc_machine_v0_12 = { { /* end of list */ } }, .hw_version = "0.12", - DEFAULT_MACHINE_OPTIONS, }; #define PC_COMPAT_0_11 \ @@ -681,10 +732,8 @@ static QEMUMachine pc_machine_v0_12 = { } static QEMUMachine pc_machine_v0_11 = { + PC_I440FX_0_13_MACHINE_OPTIONS, .name = "pc-0.11", - .desc = "Standard PC, qemu 0.11", - .init = pc_init_pci_no_kvmclock, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_0_11, { @@ -699,14 +748,11 @@ static QEMUMachine pc_machine_v0_11 = { { /* end of list */ } }, .hw_version = "0.11", - DEFAULT_MACHINE_OPTIONS, }; static QEMUMachine pc_machine_v0_10 = { + PC_I440FX_0_13_MACHINE_OPTIONS, .name = "pc-0.10", - .desc = "Standard PC, qemu 0.10", - .init = pc_init_pci_no_kvmclock, - .max_cpus = 255, .compat_props = (GlobalProperty[]) { PC_COMPAT_0_11, { @@ -733,10 +779,10 @@ static QEMUMachine pc_machine_v0_10 = { { /* end of list */ } }, .hw_version = "0.10", - DEFAULT_MACHINE_OPTIONS, }; static QEMUMachine isapc_machine = { + PC_COMMON_MACHINE_OPTIONS, .name = "isapc", .desc = "ISA-only PC", .init = pc_init_isa, @@ -744,22 +790,35 @@ static QEMUMachine isapc_machine = { .compat_props = (GlobalProperty[]) { { /* end of list */ } }, - DEFAULT_MACHINE_OPTIONS, }; #ifdef CONFIG_XEN static QEMUMachine xenfv_machine = { + PC_COMMON_MACHINE_OPTIONS, .name = "xenfv", .desc = "Xen Fully-virtualized PC", .init = pc_xen_hvm_init, .max_cpus = HVM_MAX_VCPUS, .default_machine_opts = "accel=xen", - DEFAULT_MACHINE_OPTIONS, + .hot_add_cpu = pc_hot_add_cpu, + .compat_props = (GlobalProperty[]) { + /* xenfv has no fwcfg and so does not load acpi from QEMU. + * as such new acpi features don't work. + */ + { + .driver = "PIIX4_PM", + .property = "acpi-pci-hotplug-with-bridge-support", + .value = "off", + }, + { /* end of list */ } + }, }; #endif static void pc_machine_init(void) { + qemu_register_machine(&pc_i440fx_machine_v2_0); + qemu_register_machine(&pc_i440fx_machine_v1_7); qemu_register_machine(&pc_i440fx_machine_v1_6); qemu_register_machine(&pc_i440fx_machine_v1_5); qemu_register_machine(&pc_i440fx_machine_v1_4); |