1baec1910SAndreas Färber 2baec1910SAndreas Färber /* 3baec1910SAndreas Färber * QEMU OldWorld PowerMac (currently ~G3 Beige) hardware System Emulator 4baec1910SAndreas Färber * 5baec1910SAndreas Färber * Copyright (c) 2004-2007 Fabrice Bellard 6baec1910SAndreas Färber * Copyright (c) 2007 Jocelyn Mayer 7baec1910SAndreas Färber * 8baec1910SAndreas Färber * Permission is hereby granted, free of charge, to any person obtaining a copy 9baec1910SAndreas Färber * of this software and associated documentation files (the "Software"), to deal 10baec1910SAndreas Färber * in the Software without restriction, including without limitation the rights 11baec1910SAndreas Färber * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12baec1910SAndreas Färber * copies of the Software, and to permit persons to whom the Software is 13baec1910SAndreas Färber * furnished to do so, subject to the following conditions: 14baec1910SAndreas Färber * 15baec1910SAndreas Färber * The above copyright notice and this permission notice shall be included in 16baec1910SAndreas Färber * all copies or substantial portions of the Software. 17baec1910SAndreas Färber * 18baec1910SAndreas Färber * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19baec1910SAndreas Färber * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20baec1910SAndreas Färber * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21baec1910SAndreas Färber * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22baec1910SAndreas Färber * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23baec1910SAndreas Färber * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24baec1910SAndreas Färber * THE SOFTWARE. 25baec1910SAndreas Färber */ 260d75590dSPeter Maydell #include "qemu/osdep.h" 27da34e65cSMarkus Armbruster #include "qapi/error.h" 28baec1910SAndreas Färber #include "hw/hw.h" 290d09e41aSPaolo Bonzini #include "hw/ppc/ppc.h" 30baec1910SAndreas Färber #include "mac.h" 310d09e41aSPaolo Bonzini #include "hw/input/adb.h" 320d09e41aSPaolo Bonzini #include "hw/timer/m48t59.h" 33baec1910SAndreas Färber #include "sysemu/sysemu.h" 34baec1910SAndreas Färber #include "net/net.h" 350d09e41aSPaolo Bonzini #include "hw/isa/isa.h" 36baec1910SAndreas Färber #include "hw/pci/pci.h" 37baec1910SAndreas Färber #include "hw/boards.h" 380d09e41aSPaolo Bonzini #include "hw/nvram/fw_cfg.h" 390d09e41aSPaolo Bonzini #include "hw/char/escc.h" 40*e1218e48SMark Cave-Ayland #include "hw/misc/macio/macio.h" 41baec1910SAndreas Färber #include "hw/ide.h" 42baec1910SAndreas Färber #include "hw/loader.h" 43baec1910SAndreas Färber #include "elf.h" 44c525436eSMarkus Armbruster #include "qemu/error-report.h" 45baec1910SAndreas Färber #include "sysemu/kvm.h" 46baec1910SAndreas Färber #include "kvm_ppc.h" 474be74634SMarkus Armbruster #include "sysemu/block-backend.h" 48baec1910SAndreas Färber #include "exec/address-spaces.h" 49f348b6d1SVeronia Bahaa #include "qemu/cutils.h" 50baec1910SAndreas Färber 51baec1910SAndreas Färber #define MAX_IDE_BUS 2 52baec1910SAndreas Färber #define CFG_ADDR 0xf0000510 53536d8cdaSAlexander Graf #define TBFREQ 16600000UL 549d1c1283SBALATON Zoltan #define CLOCKFREQ 266000000UL 559d1c1283SBALATON Zoltan #define BUSFREQ 66000000UL 56baec1910SAndreas Färber 57b50de5cdSMark Cave-Ayland #define NDRV_VGA_FILENAME "qemu_vga.ndrv" 58b50de5cdSMark Cave-Ayland 59ddcd5531SGonglei static void fw_cfg_boot_set(void *opaque, const char *boot_device, 60ddcd5531SGonglei Error **errp) 61baec1910SAndreas Färber { 6248779e50SGabriel L. Somlo fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); 63baec1910SAndreas Färber } 64baec1910SAndreas Färber 65baec1910SAndreas Färber static uint64_t translate_kernel_address(void *opaque, uint64_t addr) 66baec1910SAndreas Färber { 67baec1910SAndreas Färber return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; 68baec1910SAndreas Färber } 69baec1910SAndreas Färber 70baec1910SAndreas Färber static void ppc_heathrow_reset(void *opaque) 71baec1910SAndreas Färber { 72baec1910SAndreas Färber PowerPCCPU *cpu = opaque; 73baec1910SAndreas Färber 74baec1910SAndreas Färber cpu_reset(CPU(cpu)); 75baec1910SAndreas Färber } 76baec1910SAndreas Färber 773ef96221SMarcel Apfelbaum static void ppc_heathrow_init(MachineState *machine) 78baec1910SAndreas Färber { 793ef96221SMarcel Apfelbaum ram_addr_t ram_size = machine->ram_size; 803ef96221SMarcel Apfelbaum const char *kernel_filename = machine->kernel_filename; 813ef96221SMarcel Apfelbaum const char *kernel_cmdline = machine->kernel_cmdline; 823ef96221SMarcel Apfelbaum const char *initrd_filename = machine->initrd_filename; 833ef96221SMarcel Apfelbaum const char *boot_device = machine->boot_order; 84baec1910SAndreas Färber MemoryRegion *sysmem = get_system_memory(); 85baec1910SAndreas Färber PowerPCCPU *cpu = NULL; 86baec1910SAndreas Färber CPUPPCState *env = NULL; 87baec1910SAndreas Färber char *filename; 88baec1910SAndreas Färber qemu_irq *pic, **heathrow_irqs; 89baec1910SAndreas Färber int linux_boot, i; 90baec1910SAndreas Färber MemoryRegion *ram = g_new(MemoryRegion, 1); 91baec1910SAndreas Färber MemoryRegion *bios = g_new(MemoryRegion, 1); 927d52857eSPaolo Bonzini MemoryRegion *isa = g_new(MemoryRegion, 1); 93baec1910SAndreas Färber uint32_t kernel_base, initrd_base, cmdline_base = 0; 94baec1910SAndreas Färber int32_t kernel_size, initrd_size; 95baec1910SAndreas Färber PCIBus *pci_bus; 96d037834aSAndreas Färber PCIDevice *macio; 9707a7484eSAndreas Färber MACIOIDEState *macio_ide; 98c2964600SMark Cave-Ayland DeviceState *dev, *pic_dev; 99c2964600SMark Cave-Ayland SysBusDevice *sbd; 100293c867dSAndreas Färber BusState *adb_bus; 101b50de5cdSMark Cave-Ayland int bios_size, ndrv_size; 102b50de5cdSMark Cave-Ayland uint8_t *ndrv_file; 103baec1910SAndreas Färber uint16_t ppc_boot_device; 104baec1910SAndreas Färber DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 105baec1910SAndreas Färber void *fw_cfg; 106caae6c96SAlexander Graf uint64_t tbfreq; 107baec1910SAndreas Färber 108baec1910SAndreas Färber linux_boot = (kernel_filename != NULL); 109baec1910SAndreas Färber 110baec1910SAndreas Färber /* init CPUs */ 111baec1910SAndreas Färber for (i = 0; i < smp_cpus; i++) { 112f4c6604eSIgor Mammedov cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); 113baec1910SAndreas Färber env = &cpu->env; 114baec1910SAndreas Färber 115baec1910SAndreas Färber /* Set time-base frequency to 16.6 Mhz */ 116536d8cdaSAlexander Graf cpu_ppc_tb_init(env, TBFREQ); 117baec1910SAndreas Färber qemu_register_reset(ppc_heathrow_reset, cpu); 118baec1910SAndreas Färber } 119baec1910SAndreas Färber 120baec1910SAndreas Färber /* allocate RAM */ 121baec1910SAndreas Färber if (ram_size > (2047 << 20)) { 122baec1910SAndreas Färber fprintf(stderr, 123baec1910SAndreas Färber "qemu: Too much memory for this machine: %d MB, maximum 2047 MB\n", 124baec1910SAndreas Färber ((unsigned int)ram_size / (1 << 20))); 125baec1910SAndreas Färber exit(1); 126baec1910SAndreas Färber } 127baec1910SAndreas Färber 128e938ba0cSShreyas B. Prabhu memory_region_allocate_system_memory(ram, NULL, "ppc_heathrow.ram", 129e938ba0cSShreyas B. Prabhu ram_size); 130baec1910SAndreas Färber memory_region_add_subregion(sysmem, 0, ram); 131baec1910SAndreas Färber 132baec1910SAndreas Färber /* allocate and load BIOS */ 13398a99ce0SPeter Maydell memory_region_init_ram(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE, 134f8ed85acSMarkus Armbruster &error_fatal); 135e206ad48SHu Tao 136baec1910SAndreas Färber if (bios_name == NULL) 137baec1910SAndreas Färber bios_name = PROM_FILENAME; 138baec1910SAndreas Färber filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 139baec1910SAndreas Färber memory_region_set_readonly(bios, true); 140baec1910SAndreas Färber memory_region_add_subregion(sysmem, PROM_ADDR, bios); 141baec1910SAndreas Färber 142baec1910SAndreas Färber /* Load OpenBIOS (ELF) */ 143baec1910SAndreas Färber if (filename) { 144baec1910SAndreas Färber bios_size = load_elf(filename, 0, NULL, NULL, NULL, NULL, 1457ef295eaSPeter Crosthwaite 1, PPC_ELF_MACHINE, 0, 0); 146baec1910SAndreas Färber g_free(filename); 147baec1910SAndreas Färber } else { 148baec1910SAndreas Färber bios_size = -1; 149baec1910SAndreas Färber } 150baec1910SAndreas Färber if (bios_size < 0 || bios_size > BIOS_SIZE) { 151c525436eSMarkus Armbruster error_report("could not load PowerPC bios '%s'", bios_name); 152baec1910SAndreas Färber exit(1); 153baec1910SAndreas Färber } 154baec1910SAndreas Färber 155baec1910SAndreas Färber if (linux_boot) { 156baec1910SAndreas Färber uint64_t lowaddr = 0; 157baec1910SAndreas Färber int bswap_needed; 158baec1910SAndreas Färber 159baec1910SAndreas Färber #ifdef BSWAP_NEEDED 160baec1910SAndreas Färber bswap_needed = 1; 161baec1910SAndreas Färber #else 162baec1910SAndreas Färber bswap_needed = 0; 163baec1910SAndreas Färber #endif 164baec1910SAndreas Färber kernel_base = KERNEL_LOAD_ADDR; 165baec1910SAndreas Färber kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL, 1667ef295eaSPeter Crosthwaite NULL, &lowaddr, NULL, 1, PPC_ELF_MACHINE, 1677ef295eaSPeter Crosthwaite 0, 0); 168baec1910SAndreas Färber if (kernel_size < 0) 169baec1910SAndreas Färber kernel_size = load_aout(kernel_filename, kernel_base, 170baec1910SAndreas Färber ram_size - kernel_base, bswap_needed, 171baec1910SAndreas Färber TARGET_PAGE_SIZE); 172baec1910SAndreas Färber if (kernel_size < 0) 173baec1910SAndreas Färber kernel_size = load_image_targphys(kernel_filename, 174baec1910SAndreas Färber kernel_base, 175baec1910SAndreas Färber ram_size - kernel_base); 176baec1910SAndreas Färber if (kernel_size < 0) { 177c525436eSMarkus Armbruster error_report("could not load kernel '%s'", kernel_filename); 178baec1910SAndreas Färber exit(1); 179baec1910SAndreas Färber } 180baec1910SAndreas Färber /* load initrd */ 181baec1910SAndreas Färber if (initrd_filename) { 18239d96847SKamil Rytarowski initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 183baec1910SAndreas Färber initrd_size = load_image_targphys(initrd_filename, initrd_base, 184baec1910SAndreas Färber ram_size - initrd_base); 185baec1910SAndreas Färber if (initrd_size < 0) { 186c525436eSMarkus Armbruster error_report("could not load initial ram disk '%s'", 187baec1910SAndreas Färber initrd_filename); 188baec1910SAndreas Färber exit(1); 189baec1910SAndreas Färber } 19039d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size); 191baec1910SAndreas Färber } else { 192baec1910SAndreas Färber initrd_base = 0; 193baec1910SAndreas Färber initrd_size = 0; 19439d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 195baec1910SAndreas Färber } 196baec1910SAndreas Färber ppc_boot_device = 'm'; 197baec1910SAndreas Färber } else { 198baec1910SAndreas Färber kernel_base = 0; 199baec1910SAndreas Färber kernel_size = 0; 200baec1910SAndreas Färber initrd_base = 0; 201baec1910SAndreas Färber initrd_size = 0; 202baec1910SAndreas Färber ppc_boot_device = '\0'; 203baec1910SAndreas Färber for (i = 0; boot_device[i] != '\0'; i++) { 204baec1910SAndreas Färber /* TOFIX: for now, the second IDE channel is not properly 205baec1910SAndreas Färber * used by OHW. The Mac floppy disk are not emulated. 206baec1910SAndreas Färber * For now, OHW cannot boot from the network. 207baec1910SAndreas Färber */ 208baec1910SAndreas Färber #if 0 209baec1910SAndreas Färber if (boot_device[i] >= 'a' && boot_device[i] <= 'f') { 210baec1910SAndreas Färber ppc_boot_device = boot_device[i]; 211baec1910SAndreas Färber break; 212baec1910SAndreas Färber } 213baec1910SAndreas Färber #else 214baec1910SAndreas Färber if (boot_device[i] >= 'c' && boot_device[i] <= 'd') { 215baec1910SAndreas Färber ppc_boot_device = boot_device[i]; 216baec1910SAndreas Färber break; 217baec1910SAndreas Färber } 218baec1910SAndreas Färber #endif 219baec1910SAndreas Färber } 220baec1910SAndreas Färber if (ppc_boot_device == '\0') { 2216f76b817SAlistair Francis error_report("No valid boot device for G3 Beige machine"); 222baec1910SAndreas Färber exit(1); 223baec1910SAndreas Färber } 224baec1910SAndreas Färber } 225baec1910SAndreas Färber 226baec1910SAndreas Färber /* Register 2 MB of ISA IO space */ 2277d52857eSPaolo Bonzini memory_region_init_alias(isa, NULL, "isa_mmio", 2287d52857eSPaolo Bonzini get_system_io(), 0, 0x00200000); 2297d52857eSPaolo Bonzini memory_region_add_subregion(sysmem, 0xfe000000, isa); 230baec1910SAndreas Färber 231baec1910SAndreas Färber /* XXX: we register only 1 output pin for heathrow PIC */ 232baec1910SAndreas Färber heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *)); 233baec1910SAndreas Färber heathrow_irqs[0] = 234baec1910SAndreas Färber g_malloc0(smp_cpus * sizeof(qemu_irq) * 1); 235baec1910SAndreas Färber /* Connect the heathrow PIC outputs to the 6xx bus */ 236baec1910SAndreas Färber for (i = 0; i < smp_cpus; i++) { 237baec1910SAndreas Färber switch (PPC_INPUT(env)) { 238baec1910SAndreas Färber case PPC_FLAGS_INPUT_6xx: 239baec1910SAndreas Färber heathrow_irqs[i] = heathrow_irqs[0] + (i * 1); 240baec1910SAndreas Färber heathrow_irqs[i][0] = 241baec1910SAndreas Färber ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; 242baec1910SAndreas Färber break; 243baec1910SAndreas Färber default: 244c525436eSMarkus Armbruster error_report("Bus model not supported on OldWorld Mac machine"); 245c525436eSMarkus Armbruster exit(1); 246baec1910SAndreas Färber } 247baec1910SAndreas Färber } 248baec1910SAndreas Färber 249caae6c96SAlexander Graf /* Timebase Frequency */ 250caae6c96SAlexander Graf if (kvm_enabled()) { 251caae6c96SAlexander Graf tbfreq = kvmppc_get_tbfreq(); 252caae6c96SAlexander Graf } else { 253caae6c96SAlexander Graf tbfreq = TBFREQ; 254caae6c96SAlexander Graf } 255caae6c96SAlexander Graf 256baec1910SAndreas Färber /* init basic PC hardware */ 257baec1910SAndreas Färber if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { 258c525436eSMarkus Armbruster error_report("Only 6xx bus is supported on heathrow machine"); 259c525436eSMarkus Armbruster exit(1); 260baec1910SAndreas Färber } 261c2964600SMark Cave-Ayland pic_dev = heathrow_pic_init(1, heathrow_irqs, &pic); 262baec1910SAndreas Färber pci_bus = pci_grackle_init(0xfec00000, pic, 263baec1910SAndreas Färber get_system_memory(), 264baec1910SAndreas Färber get_system_io()); 265baec1910SAndreas Färber pci_vga_init(pci_bus); 266baec1910SAndreas Färber 267343bd85aSMark Cave-Ayland for (i = 0; i < nb_nics; i++) { 26829b358f9SDavid Gibson pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); 269343bd85aSMark Cave-Ayland } 270baec1910SAndreas Färber 271d8f94e1bSJohn Snow ide_drive_get(hd, ARRAY_SIZE(hd)); 272baec1910SAndreas Färber 273343bd85aSMark Cave-Ayland /* MacIO */ 274d037834aSAndreas Färber macio = pci_create(pci_bus, -1, TYPE_OLDWORLD_MACIO); 27507a7484eSAndreas Färber dev = DEVICE(macio); 27645fa67fbSAndreas Färber qdev_connect_gpio_out(dev, 0, pic[0x12]); /* CUDA */ 277343bd85aSMark Cave-Ayland qdev_connect_gpio_out(dev, 1, pic[0x10]); /* ESCC-B */ 278343bd85aSMark Cave-Ayland qdev_connect_gpio_out(dev, 2, pic[0x0F]); /* ESCC-A */ 279343bd85aSMark Cave-Ayland qdev_connect_gpio_out(dev, 3, pic[0x0D]); /* IDE-0 */ 280343bd85aSMark Cave-Ayland qdev_connect_gpio_out(dev, 4, pic[0x02]); /* IDE-0 DMA */ 281343bd85aSMark Cave-Ayland qdev_connect_gpio_out(dev, 5, pic[0x0E]); /* IDE-1 */ 282343bd85aSMark Cave-Ayland qdev_connect_gpio_out(dev, 6, pic[0x03]); /* IDE-1 DMA */ 283b981289cSAlexander Graf qdev_prop_set_uint64(dev, "frequency", tbfreq); 284c2964600SMark Cave-Ayland sbd = SYS_BUS_DEVICE(pic_dev); 285c2964600SMark Cave-Ayland macio_init(macio, sysbus_mmio_get_region(sbd, 0)); 28607a7484eSAndreas Färber 28707a7484eSAndreas Färber macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 28814eefd0eSAlexander Graf "ide[0]")); 28907a7484eSAndreas Färber macio_ide_init_drives(macio_ide, hd); 29007a7484eSAndreas Färber 29114eefd0eSAlexander Graf macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 29214eefd0eSAlexander Graf "ide[1]")); 29314eefd0eSAlexander Graf macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]); 294baec1910SAndreas Färber 295293c867dSAndreas Färber dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda")); 296293c867dSAndreas Färber adb_bus = qdev_get_child_bus(dev, "adb.0"); 297293c867dSAndreas Färber dev = qdev_create(adb_bus, TYPE_ADB_KEYBOARD); 2982e4a7c9cSAndreas Färber qdev_init_nofail(dev); 299293c867dSAndreas Färber dev = qdev_create(adb_bus, TYPE_ADB_MOUSE); 3002e4a7c9cSAndreas Färber qdev_init_nofail(dev); 30145fa67fbSAndreas Färber 3024bcbe0b6SEduardo Habkost if (machine_usb(machine)) { 303baec1910SAndreas Färber pci_create_simple(pci_bus, -1, "pci-ohci"); 304baec1910SAndreas Färber } 305baec1910SAndreas Färber 306baec1910SAndreas Färber if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) 307baec1910SAndreas Färber graphic_depth = 15; 308baec1910SAndreas Färber 309baec1910SAndreas Färber /* No PCI init: the BIOS will do it */ 310baec1910SAndreas Färber 31166708822SLaszlo Ersek fw_cfg = fw_cfg_init_mem(CFG_ADDR, CFG_ADDR + 2); 3125836d168SIgor Mammedov fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); 31370db9222SEduardo Habkost fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus); 314baec1910SAndreas Färber fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); 315baec1910SAndreas Färber fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW); 316baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); 317baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 318baec1910SAndreas Färber if (kernel_cmdline) { 319baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); 320baec1910SAndreas Färber pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline); 321baec1910SAndreas Färber } else { 322baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); 323baec1910SAndreas Färber } 324baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); 325baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 326baec1910SAndreas Färber fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device); 327baec1910SAndreas Färber 328baec1910SAndreas Färber fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); 329baec1910SAndreas Färber fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); 330baec1910SAndreas Färber fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); 331baec1910SAndreas Färber 332baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); 333baec1910SAndreas Färber if (kvm_enabled()) { 334baec1910SAndreas Färber #ifdef CONFIG_KVM 335baec1910SAndreas Färber uint8_t *hypercall; 336baec1910SAndreas Färber 337baec1910SAndreas Färber hypercall = g_malloc(16); 338baec1910SAndreas Färber kvmppc_get_hypercall(env, hypercall, 16); 339baec1910SAndreas Färber fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); 340baec1910SAndreas Färber fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); 341baec1910SAndreas Färber #endif 342baec1910SAndreas Färber } 343caae6c96SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq); 344a1014f25SAlexander Graf /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ 3459d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); 3469d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); 347baec1910SAndreas Färber 348b50de5cdSMark Cave-Ayland /* MacOS NDRV VGA driver */ 349b50de5cdSMark Cave-Ayland filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME); 350b50de5cdSMark Cave-Ayland if (filename) { 351b50de5cdSMark Cave-Ayland ndrv_size = get_image_size(filename); 352b50de5cdSMark Cave-Ayland if (ndrv_size != -1) { 353b50de5cdSMark Cave-Ayland ndrv_file = g_malloc(ndrv_size); 354b50de5cdSMark Cave-Ayland ndrv_size = load_image(filename, ndrv_file); 355b50de5cdSMark Cave-Ayland 356b50de5cdSMark Cave-Ayland fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size); 357b50de5cdSMark Cave-Ayland } 358b50de5cdSMark Cave-Ayland g_free(filename); 359b50de5cdSMark Cave-Ayland } 360b50de5cdSMark Cave-Ayland 361baec1910SAndreas Färber qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); 362baec1910SAndreas Färber } 363baec1910SAndreas Färber 364277c7a4dSAlexander Graf static int heathrow_kvm_type(const char *arg) 365277c7a4dSAlexander Graf { 366277c7a4dSAlexander Graf /* Always force PR KVM */ 367277c7a4dSAlexander Graf return 2; 368277c7a4dSAlexander Graf } 369277c7a4dSAlexander Graf 370c8bd3526SMark Cave-Ayland static void heathrow_class_init(ObjectClass *oc, void *data) 371e264d29dSEduardo Habkost { 372c8bd3526SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc); 373c8bd3526SMark Cave-Ayland 374e264d29dSEduardo Habkost mc->desc = "Heathrow based PowerMAC"; 375e264d29dSEduardo Habkost mc->init = ppc_heathrow_init; 3762059839bSMarkus Armbruster mc->block_default_type = IF_IDE; 377e264d29dSEduardo Habkost mc->max_cpus = MAX_CPUS; 378baec1910SAndreas Färber #ifndef TARGET_PPC64 379e264d29dSEduardo Habkost mc->is_default = 1; 380baec1910SAndreas Färber #endif 381f309ae85SEduardo Habkost /* TOFIX "cad" when Mac floppy is implemented */ 382e264d29dSEduardo Habkost mc->default_boot_order = "cd"; 383e264d29dSEduardo Habkost mc->kvm_type = heathrow_kvm_type; 384f4c6604eSIgor Mammedov mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1"); 385baec1910SAndreas Färber } 386baec1910SAndreas Färber 387c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = { 388c8bd3526SMark Cave-Ayland .name = MACHINE_TYPE_NAME("g3beige"), 389c8bd3526SMark Cave-Ayland .parent = TYPE_MACHINE, 390c8bd3526SMark Cave-Ayland .class_init = heathrow_class_init 391c8bd3526SMark Cave-Ayland }; 392c8bd3526SMark Cave-Ayland 393c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void) 394c8bd3526SMark Cave-Ayland { 395c8bd3526SMark Cave-Ayland type_register_static(&ppc_heathrow_machine_info); 396c8bd3526SMark Cave-Ayland } 397c8bd3526SMark Cave-Ayland 398c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types); 399