#qemu-only -> submit upstream qemu, but improve first: # undo rather hacky pci_enabled -> model > MODEL_ISA changes # and replace checks wether to enable newer emulated Mac hardware # depending in the bits in a bitfield which is passed pc_init1() # like this: pc_init1(.... , ISA, ...) # pc_init1(.... , PCI | IOAPIC | PIIX, ..... # pc_init1(.... , PCI | ICH6, LPC, SMC , ...) Index: kvm-78/qemu/hw/pc.c =================================================================== --- kvm-78.orig/qemu/hw/pc.c +++ kvm-78/qemu/hw/pc.c @@ -58,6 +58,12 @@ static PITState *pit; static IOAPICState *ioapic; static PCIDevice *i440fx_state; +enum pc_model { + MODEL_ISA = 0, + MODEL_PCI = 1, + MODEL_MAC = 2 +}; + static void ioport80_write(void *opaque, uint32_t addr, uint32_t data) { } @@ -805,7 +811,7 @@ static void pc_init1(ram_addr_t ram_size const char *boot_device, DisplayState *ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, - int pci_enabled, const char *cpu_model) + int model, const char *cpu_model) { char buf[1024]; int ret, linux_boot, i; @@ -833,15 +839,19 @@ static void pc_init1(ram_addr_t ram_size /* init CPUs */ if (cpu_model == NULL) { + if(model == MODEL_MAC) { + cpu_model = "coreduo"; + } else { #ifdef TARGET_X86_64 - cpu_model = "qemu64"; + cpu_model = "qemu64"; #else - cpu_model = "qemu32"; + cpu_model = "qemu32"; #endif + } } for(i = 0; i < smp_cpus; i++) { - env = pc_new_cpu(i, cpu_model, pci_enabled); + env = pc_new_cpu(i, cpu_model, model > MODEL_ISA); } vmport_init(); @@ -880,8 +890,16 @@ static void pc_init1(ram_addr_t ram_size vga_ram_addr = qemu_ram_alloc(vga_ram_size); /* BIOS load */ - if (bios_name == NULL) - bios_name = BIOS_FILENAME; + if (bios_name == NULL) { + switch(model) { + case MODEL_MAC: + bios_name = "bios-mac.bin"; + break; + default: + bios_name = BIOS_FILENAME; + break; + } + } snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); bios_size = get_image_size(buf); if (bios_size <= 0 || @@ -956,7 +974,7 @@ static void pc_init1(ram_addr_t ram_size i8259 = i8259_init(cpu_irq[0]); ferr_irq = i8259[13]; - if (pci_enabled) { + if (model > MODEL_ISA) { pci_bus = i440fx_init(&i440fx_state, i8259); piix3_devfn = piix3_init(pci_bus, -1); } else { @@ -969,7 +987,7 @@ static void pc_init1(ram_addr_t ram_size register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL); if (cirrus_vga_enabled) { - if (pci_enabled) { + if (model > MODEL_ISA) { pci_cirrus_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr, vga_ram_addr, vga_ram_size); @@ -978,13 +996,13 @@ static void pc_init1(ram_addr_t ram_size vga_ram_addr, vga_ram_size); } } else if (vmsvga_enabled) { - if (pci_enabled) + if (model > MODEL_ISA) pci_vmsvga_init(pci_bus, ds, phys_ram_base + vga_ram_addr, vga_ram_addr, vga_ram_size); else fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__); } else { - if (pci_enabled) { + if (model > MODEL_ISA) { pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr, vga_ram_addr, vga_ram_size, 0, 0); } else { @@ -1000,8 +1018,13 @@ static void pc_init1(ram_addr_t ram_size register_ioport_read(0x92, 1, 1, ioport92_read, NULL); register_ioport_write(0x92, 1, 1, ioport92_write, NULL); - if (pci_enabled) { - ioapic = ioapic_init(); + switch (model) { + case MODEL_MAC: + applesmc_init(); + lpc_init(pci_bus, piix3_devfn, i8259); + case MODEL_PCI: + ioapic = ioapic_init(); + break; } #ifdef USE_KVM_PIT if (kvm_enabled() && qemu_kvm_pit_in_kernel()) @@ -1010,7 +1033,7 @@ static void pc_init1(ram_addr_t ram_size #endif pit = pit_init(0x40, i8259[0]); pcspk_init(pit); - if (pci_enabled) { + if (model > MODEL_ISA) { pic_set_alt_irq_func(isa_pic, ioapic_set_irq, ioapic); } @@ -1031,15 +1054,22 @@ static void pc_init1(ram_addr_t ram_size for(i = 0; i < nb_nics; i++) { nd = &nd_table[i]; if (!nd->model) { - if (pci_enabled) { - nd->model = "rtl8139"; - } else { - nd->model = "ne2k_isa"; + switch(model) { + case MODEL_ISA: + nd->model = "ne2k_isa"; + break; + case MODEL_MAC: + nd->model = "rtl8139"; + nd->link = Link_10mbps; + break; + default: + nd->model = "ne2k_pci"; + break; } } if (strcmp(nd->model, "ne2k_isa") == 0) { pc_init_ne2k_isa(nd, i8259); - } else if (pci_enabled) { + } else if (model > MODEL_ISA) { if (strcmp(nd->model, "?") == 0) fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n"); if (!pci_nic_init(pci_bus, nd, -1)) @@ -1068,19 +1098,25 @@ static void pc_init1(ram_addr_t ram_size hd[i] = NULL; } - if (pci_enabled) { - pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1, i8259); - } else { - for(i = 0; i < MAX_IDE_BUS; i++) { - isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], - hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); - } + switch(model) { + case MODEL_MAC: + pci_ich6_ide_init(pci_bus, hd, piix3_devfn + 1, i8259); + break; + case MODEL_PCI: + pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1, i8259); + break; + default: + for(i = 0; i < 2; i++) { + isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], + hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); + } + break; } i8042_init(i8259[1], i8259[12], 0x60); DMA_init(0); #ifdef HAS_AUDIO - audio_init(pci_enabled ? pci_bus : NULL, i8259); + audio_init((model > MODEL_ISA) ? pci_bus : NULL, i8259); #endif for(i = 0; i < MAX_FD; i++) { @@ -1094,11 +1130,11 @@ static void pc_init1(ram_addr_t ram_size cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd); - if (pci_enabled && usb_enabled) { + if ((model > MODEL_ISA) && usb_enabled) { usb_uhci_piix3_init(pci_bus, piix3_devfn + 2); } - if (pci_enabled && acpi_enabled) { + if ((model > MODEL_ISA) && acpi_enabled) { uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */ i2c_bus *smbus; @@ -1113,7 +1149,7 @@ static void pc_init1(ram_addr_t ram_size i440fx_init_memory_mappings(i440fx_state); } - if (pci_enabled) { + if (model > MODEL_ISA) { int max_bus; int bus, unit; void *scsi; @@ -1132,7 +1168,7 @@ static void pc_init1(ram_addr_t ram_size } /* Add virtio block devices */ - if (pci_enabled) { + if (model > MODEL_ISA) { int index; int unit_id = 0; @@ -1155,10 +1191,22 @@ static void pc_init1(ram_addr_t ram_size extboot_init(info->bdrv, 1); } - if (pci_enabled) + if (model > MODEL_ISA) virtio_balloon_init(pci_bus); } +static void pc_init_mac(ram_addr_t ram_size, int vga_ram_size, + const char *boot_device, DisplayState *ds, + const char *kernel_filename, + const char *kernel_cmdline, + const char *initrd_filename, + const char *cpu_model) +{ + pc_init1(ram_size, vga_ram_size, boot_device, ds, + kernel_filename, kernel_cmdline, + initrd_filename, MODEL_MAC, cpu_model); +} + static void pc_init_pci(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char *kernel_filename, @@ -1168,7 +1216,7 @@ static void pc_init_pci(ram_addr_t ram_s { pc_init1(ram_size, vga_ram_size, boot_device, ds, kernel_filename, kernel_cmdline, - initrd_filename, 1, cpu_model); + initrd_filename, MODEL_PCI, cpu_model); } static void pc_init_isa(ram_addr_t ram_size, int vga_ram_size, @@ -1180,7 +1228,7 @@ static void pc_init_isa(ram_addr_t ram_s { pc_init1(ram_size, vga_ram_size, boot_device, ds, kernel_filename, kernel_cmdline, - initrd_filename, 0, cpu_model); + initrd_filename, MODEL_ISA, cpu_model); } QEMUMachine pc_machine = { @@ -1190,6 +1238,14 @@ QEMUMachine pc_machine = { .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE, .max_cpus = 255, }; + +QEMUMachine mac_machine = { + .name = "mac", + .desc = "Intel-Mac", + .init = pc_init_mac, + .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE, + .max_cpus = 255, +}; QEMUMachine isapc_machine = { .name = "isapc", Index: kvm-78/qemu/hw/boards.h =================================================================== --- kvm-78.orig/qemu/hw/boards.h +++ kvm-78/qemu/hw/boards.h @@ -33,6 +33,7 @@ extern QEMUMachine bareetraxfs_machine; /* pc.c */ extern QEMUMachine pc_machine; extern QEMUMachine isapc_machine; +extern QEMUMachine mac_machine; /* ppc.c */ extern QEMUMachine prep_machine; Index: kvm-78/qemu/target-i386/machine.c =================================================================== --- kvm-78.orig/qemu/target-i386/machine.c +++ kvm-78/qemu/target-i386/machine.c @@ -10,6 +10,7 @@ void register_machines(void) { qemu_register_machine(&pc_machine); qemu_register_machine(&isapc_machine); + qemu_register_machine(&mac_machine); } static void cpu_put_seg(QEMUFile *f, SegmentCache *dt)