1ae0bfb79SBlue Swirl 23cbee15bSj_mayer /* 34d7ca41eSaurel32 * QEMU OldWorld PowerMac (currently ~G3 Beige) hardware System Emulator 43cbee15bSj_mayer * 53cbee15bSj_mayer * Copyright (c) 2004-2007 Fabrice Bellard 63cbee15bSj_mayer * Copyright (c) 2007 Jocelyn Mayer 73cbee15bSj_mayer * 83cbee15bSj_mayer * Permission is hereby granted, free of charge, to any person obtaining a copy 93cbee15bSj_mayer * of this software and associated documentation files (the "Software"), to deal 103cbee15bSj_mayer * in the Software without restriction, including without limitation the rights 113cbee15bSj_mayer * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 123cbee15bSj_mayer * copies of the Software, and to permit persons to whom the Software is 133cbee15bSj_mayer * furnished to do so, subject to the following conditions: 143cbee15bSj_mayer * 153cbee15bSj_mayer * The above copyright notice and this permission notice shall be included in 163cbee15bSj_mayer * all copies or substantial portions of the Software. 173cbee15bSj_mayer * 183cbee15bSj_mayer * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 193cbee15bSj_mayer * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 203cbee15bSj_mayer * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 213cbee15bSj_mayer * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 223cbee15bSj_mayer * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 233cbee15bSj_mayer * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 243cbee15bSj_mayer * THE SOFTWARE. 253cbee15bSj_mayer */ 26a8d25326SMarkus Armbruster 270d75590dSPeter Maydell #include "qemu/osdep.h" 28a8d25326SMarkus Armbruster #include "qemu-common.h" 29ab3dd749SPhilippe Mathieu-Daudé #include "qemu/units.h" 30da34e65cSMarkus Armbruster #include "qapi/error.h" 310d09e41aSPaolo Bonzini #include "hw/ppc/ppc.h" 32a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h" 33baec1910SAndreas Färber #include "mac.h" 340d09e41aSPaolo Bonzini #include "hw/input/adb.h" 359c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 361422e32dSPaolo Bonzini #include "net/net.h" 370d09e41aSPaolo Bonzini #include "hw/isa/isa.h" 38baec1910SAndreas Färber #include "hw/pci/pci.h" 39a773e64aSMark Cave-Ayland #include "hw/pci/pci_host.h" 40baec1910SAndreas Färber #include "hw/boards.h" 410d09e41aSPaolo Bonzini #include "hw/nvram/fw_cfg.h" 420d09e41aSPaolo Bonzini #include "hw/char/escc.h" 43e1218e48SMark Cave-Ayland #include "hw/misc/macio/macio.h" 44baec1910SAndreas Färber #include "hw/ide.h" 45baec1910SAndreas Färber #include "hw/loader.h" 46bbcc635fSMark Cave-Ayland #include "hw/fw-path-provider.h" 47ca20cf32SBlue Swirl #include "elf.h" 48c525436eSMarkus Armbruster #include "qemu/error-report.h" 499c17d615SPaolo Bonzini #include "sysemu/kvm.h" 5071e8a915SMarkus Armbruster #include "sysemu/reset.h" 51dc333cd6SAlexander Graf #include "kvm_ppc.h" 52022c62cbSPaolo Bonzini #include "exec/address-spaces.h" 533cbee15bSj_mayer 54e4bcb14cSths #define MAX_IDE_BUS 2 55271dd5e0Sblueswir1 #define CFG_ADDR 0xf0000510 56536d8cdaSAlexander Graf #define TBFREQ 16600000UL 579d1c1283SBALATON Zoltan #define CLOCKFREQ 266000000UL 589d1c1283SBALATON Zoltan #define BUSFREQ 66000000UL 59271dd5e0Sblueswir1 60b50de5cdSMark Cave-Ayland #define NDRV_VGA_FILENAME "qemu_vga.ndrv" 61b50de5cdSMark Cave-Ayland 62a773e64aSMark Cave-Ayland #define GRACKLE_BASE 0xfec00000 63a773e64aSMark Cave-Ayland 64ddcd5531SGonglei static void fw_cfg_boot_set(void *opaque, const char *boot_device, 65ddcd5531SGonglei Error **errp) 66513f789fSblueswir1 { 6748779e50SGabriel L. Somlo fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); 68513f789fSblueswir1 } 69513f789fSblueswir1 70409dbce5SAurelien Jarno static uint64_t translate_kernel_address(void *opaque, uint64_t addr) 71409dbce5SAurelien Jarno { 72409dbce5SAurelien Jarno return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; 73409dbce5SAurelien Jarno } 74409dbce5SAurelien Jarno 751bba0dc9SAndreas Färber static void ppc_heathrow_reset(void *opaque) 761bba0dc9SAndreas Färber { 77cd79664fSAndreas Färber PowerPCCPU *cpu = opaque; 781bba0dc9SAndreas Färber 79cd79664fSAndreas Färber cpu_reset(CPU(cpu)); 801bba0dc9SAndreas Färber } 811bba0dc9SAndreas Färber 823ef96221SMarcel Apfelbaum static void ppc_heathrow_init(MachineState *machine) 833cbee15bSj_mayer { 843ef96221SMarcel Apfelbaum ram_addr_t ram_size = machine->ram_size; 853ef96221SMarcel Apfelbaum const char *kernel_filename = machine->kernel_filename; 863ef96221SMarcel Apfelbaum const char *kernel_cmdline = machine->kernel_cmdline; 873ef96221SMarcel Apfelbaum const char *initrd_filename = machine->initrd_filename; 883ef96221SMarcel Apfelbaum const char *boot_device = machine->boot_order; 89c92bb2c7SAvi Kivity MemoryRegion *sysmem = get_system_memory(); 9072c33dd7SAndreas Färber PowerPCCPU *cpu = NULL; 91e2684c0bSAndreas Färber CPUPPCState *env = NULL; 925cea8590SPaul Brook char *filename; 933cbee15bSj_mayer int linux_boot, i; 94c92bb2c7SAvi Kivity MemoryRegion *bios = g_new(MemoryRegion, 1); 95b9e17a34SAlexander Graf uint32_t kernel_base, initrd_base, cmdline_base = 0; 967373048cSblueswir1 int32_t kernel_size, initrd_size; 973cbee15bSj_mayer PCIBus *pci_bus; 98017812dfSMark Cave-Ayland OldWorldMacIOState *macio; 9907a7484eSAndreas Färber MACIOIDEState *macio_ide; 100a773e64aSMark Cave-Ayland SysBusDevice *s; 101c2964600SMark Cave-Ayland DeviceState *dev, *pic_dev; 102293c867dSAndreas Färber BusState *adb_bus; 1039776874fSPeter Maydell int bios_size; 104fe6b6346SLike Xu unsigned int smp_cpus = machine->smp.cpus; 105513f789fSblueswir1 uint16_t ppc_boot_device; 106f455e98cSGerd Hoffmann DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 107271dd5e0Sblueswir1 void *fw_cfg; 108caae6c96SAlexander Graf uint64_t tbfreq; 1093cbee15bSj_mayer 1103cbee15bSj_mayer linux_boot = (kernel_filename != NULL); 1113cbee15bSj_mayer 1123cbee15bSj_mayer /* init CPUs */ 1133cbee15bSj_mayer for (i = 0; i < smp_cpus; i++) { 114f4c6604eSIgor Mammedov cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); 11572c33dd7SAndreas Färber env = &cpu->env; 11672c33dd7SAndreas Färber 117b0fb43d8Saurel32 /* Set time-base frequency to 16.6 Mhz */ 118536d8cdaSAlexander Graf cpu_ppc_tb_init(env, TBFREQ); 119cd79664fSAndreas Färber qemu_register_reset(ppc_heathrow_reset, cpu); 1203cbee15bSj_mayer } 1213cbee15bSj_mayer 1223cbee15bSj_mayer /* allocate RAM */ 123ab3dd749SPhilippe Mathieu-Daudé if (ram_size > 2047 * MiB) { 124ab3dd749SPhilippe Mathieu-Daudé error_report("Too much memory for this machine: %" PRId64 " MB, " 125ab3dd749SPhilippe Mathieu-Daudé "maximum 2047 MB", ram_size / MiB); 1266b4079f8Saurel32 exit(1); 1276b4079f8Saurel32 } 1286b4079f8Saurel32 1298ee06e4cSIgor Mammedov memory_region_add_subregion(sysmem, 0, machine->ram); 130a748ab6dSaurel32 1313cbee15bSj_mayer /* allocate and load BIOS */ 132*1bbd95cbSPhilippe Mathieu-Daudé memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE, 133f8ed85acSMarkus Armbruster &error_fatal); 134e206ad48SHu Tao 1353cbee15bSj_mayer if (bios_name == NULL) 136992e5acdSblueswir1 bios_name = PROM_FILENAME; 1375cea8590SPaul Brook filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 138c92bb2c7SAvi Kivity memory_region_add_subregion(sysmem, PROM_ADDR, bios); 139992e5acdSblueswir1 140992e5acdSblueswir1 /* Load OpenBIOS (ELF) */ 1415cea8590SPaul Brook if (filename) { 1426cdda0ffSAleksandar Markovic bios_size = load_elf(filename, NULL, 0, NULL, NULL, NULL, NULL, NULL, 1437ef295eaSPeter Crosthwaite 1, PPC_ELF_MACHINE, 0, 0); 1447267c094SAnthony Liguori g_free(filename); 1455cea8590SPaul Brook } else { 1465cea8590SPaul Brook bios_size = -1; 1475cea8590SPaul Brook } 1483cbee15bSj_mayer if (bios_size < 0 || bios_size > BIOS_SIZE) { 149c525436eSMarkus Armbruster error_report("could not load PowerPC bios '%s'", bios_name); 1503cbee15bSj_mayer exit(1); 1513cbee15bSj_mayer } 1523cbee15bSj_mayer 1533cbee15bSj_mayer if (linux_boot) { 15436bee1e3Saurel32 uint64_t lowaddr = 0; 155ca20cf32SBlue Swirl int bswap_needed; 156ca20cf32SBlue Swirl 157ca20cf32SBlue Swirl #ifdef BSWAP_NEEDED 158ca20cf32SBlue Swirl bswap_needed = 1; 159ca20cf32SBlue Swirl #else 160ca20cf32SBlue Swirl bswap_needed = 0; 161ca20cf32SBlue Swirl #endif 1623cbee15bSj_mayer kernel_base = KERNEL_LOAD_ADDR; 1634366e1dbSLiam Merwick kernel_size = load_elf(kernel_filename, NULL, 1644366e1dbSLiam Merwick translate_kernel_address, NULL, 1656cdda0ffSAleksandar Markovic NULL, &lowaddr, NULL, NULL, 1, PPC_ELF_MACHINE, 1667ef295eaSPeter Crosthwaite 0, 0); 16752f163b7Sblueswir1 if (kernel_size < 0) 16852f163b7Sblueswir1 kernel_size = load_aout(kernel_filename, kernel_base, 169ca20cf32SBlue Swirl ram_size - kernel_base, bswap_needed, 170ca20cf32SBlue Swirl TARGET_PAGE_SIZE); 17152f163b7Sblueswir1 if (kernel_size < 0) 17252f163b7Sblueswir1 kernel_size = load_image_targphys(kernel_filename, 17352f163b7Sblueswir1 kernel_base, 17452f163b7Sblueswir1 ram_size - kernel_base); 1753cbee15bSj_mayer if (kernel_size < 0) { 176c525436eSMarkus Armbruster error_report("could not load kernel '%s'", kernel_filename); 1773cbee15bSj_mayer exit(1); 1783cbee15bSj_mayer } 1793cbee15bSj_mayer /* load initrd */ 1803cbee15bSj_mayer if (initrd_filename) { 18139d96847SKamil Rytarowski initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 182dcac9679Spbrook initrd_size = load_image_targphys(initrd_filename, initrd_base, 183dcac9679Spbrook ram_size - initrd_base); 1843cbee15bSj_mayer if (initrd_size < 0) { 185c525436eSMarkus Armbruster error_report("could not load initial ram disk '%s'", 1863cbee15bSj_mayer initrd_filename); 1873cbee15bSj_mayer exit(1); 1883cbee15bSj_mayer } 18939d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size); 1903cbee15bSj_mayer } else { 1913cbee15bSj_mayer initrd_base = 0; 1923cbee15bSj_mayer initrd_size = 0; 19339d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 1943cbee15bSj_mayer } 1956ac0e82dSbalrog ppc_boot_device = 'm'; 1963cbee15bSj_mayer } else { 1973cbee15bSj_mayer kernel_base = 0; 1983cbee15bSj_mayer kernel_size = 0; 1993cbee15bSj_mayer initrd_base = 0; 2003cbee15bSj_mayer initrd_size = 0; 20128c5af54Sj_mayer ppc_boot_device = '\0'; 2020d913fdbSj_mayer for (i = 0; boot_device[i] != '\0'; i++) { 20328c5af54Sj_mayer /* TOFIX: for now, the second IDE channel is not properly 2040d913fdbSj_mayer * used by OHW. The Mac floppy disk are not emulated. 20528c5af54Sj_mayer * For now, OHW cannot boot from the network. 20628c5af54Sj_mayer */ 20728c5af54Sj_mayer #if 0 2080d913fdbSj_mayer if (boot_device[i] >= 'a' && boot_device[i] <= 'f') { 2090d913fdbSj_mayer ppc_boot_device = boot_device[i]; 21028c5af54Sj_mayer break; 2110d913fdbSj_mayer } 21228c5af54Sj_mayer #else 2130d913fdbSj_mayer if (boot_device[i] >= 'c' && boot_device[i] <= 'd') { 2140d913fdbSj_mayer ppc_boot_device = boot_device[i]; 21528c5af54Sj_mayer break; 2160d913fdbSj_mayer } 21728c5af54Sj_mayer #endif 21828c5af54Sj_mayer } 21928c5af54Sj_mayer if (ppc_boot_device == '\0') { 2206f76b817SAlistair Francis error_report("No valid boot device for G3 Beige machine"); 22128c5af54Sj_mayer exit(1); 22228c5af54Sj_mayer } 2233cbee15bSj_mayer } 2243cbee15bSj_mayer 2253cbee15bSj_mayer /* XXX: we register only 1 output pin for heathrow PIC */ 226a5ed75feSMark Cave-Ayland pic_dev = qdev_create(NULL, TYPE_HEATHROW); 227a5ed75feSMark Cave-Ayland qdev_init_nofail(pic_dev); 228a5ed75feSMark Cave-Ayland 2293cbee15bSj_mayer /* Connect the heathrow PIC outputs to the 6xx bus */ 2303cbee15bSj_mayer for (i = 0; i < smp_cpus; i++) { 2313cbee15bSj_mayer switch (PPC_INPUT(env)) { 2323cbee15bSj_mayer case PPC_FLAGS_INPUT_6xx: 233a5ed75feSMark Cave-Ayland qdev_connect_gpio_out(pic_dev, 0, 234a5ed75feSMark Cave-Ayland ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]); 2353cbee15bSj_mayer break; 2363cbee15bSj_mayer default: 237c525436eSMarkus Armbruster error_report("Bus model not supported on OldWorld Mac machine"); 238c525436eSMarkus Armbruster exit(1); 2393cbee15bSj_mayer } 2403cbee15bSj_mayer } 2413cbee15bSj_mayer 242caae6c96SAlexander Graf /* Timebase Frequency */ 243caae6c96SAlexander Graf if (kvm_enabled()) { 244caae6c96SAlexander Graf tbfreq = kvmppc_get_tbfreq(); 245caae6c96SAlexander Graf } else { 246caae6c96SAlexander Graf tbfreq = TBFREQ; 247caae6c96SAlexander Graf } 248caae6c96SAlexander Graf 2493cbee15bSj_mayer /* init basic PC hardware */ 2503cbee15bSj_mayer if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { 251c525436eSMarkus Armbruster error_report("Only 6xx bus is supported on heathrow machine"); 252c525436eSMarkus Armbruster exit(1); 2533cbee15bSj_mayer } 254a5ed75feSMark Cave-Ayland 255a773e64aSMark Cave-Ayland /* Grackle PCI host bridge */ 256a773e64aSMark Cave-Ayland dev = qdev_create(NULL, TYPE_GRACKLE_PCI_HOST_BRIDGE); 257ac43eb2eSMark Cave-Ayland qdev_prop_set_uint32(dev, "ofw-addr", 0x80000000); 258a773e64aSMark Cave-Ayland object_property_set_link(OBJECT(dev), OBJECT(pic_dev), "pic", 259a773e64aSMark Cave-Ayland &error_abort); 260a773e64aSMark Cave-Ayland qdev_init_nofail(dev); 261a773e64aSMark Cave-Ayland s = SYS_BUS_DEVICE(dev); 262a773e64aSMark Cave-Ayland sysbus_mmio_map(s, 0, GRACKLE_BASE); 263a773e64aSMark Cave-Ayland sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x200000); 264a773e64aSMark Cave-Ayland /* PCI hole */ 265a773e64aSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0x80000000ULL, 266a773e64aSMark Cave-Ayland sysbus_mmio_get_region(s, 2)); 267a94e5f99SMark Cave-Ayland /* Register 2 MB of ISA IO space */ 268a94e5f99SMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0xfe000000, 269a94e5f99SMark Cave-Ayland sysbus_mmio_get_region(s, 3)); 270a773e64aSMark Cave-Ayland 271a773e64aSMark Cave-Ayland pci_bus = PCI_HOST_BRIDGE(dev)->bus; 272a773e64aSMark Cave-Ayland 2733e20ad3aSAurelien Jarno pci_vga_init(pci_bus); 2743cbee15bSj_mayer 275343bd85aSMark Cave-Ayland for (i = 0; i < nb_nics; i++) { 27629b358f9SDavid Gibson pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); 277343bd85aSMark Cave-Ayland } 278e4bcb14cSths 279d8f94e1bSJohn Snow ide_drive_get(hd, ARRAY_SIZE(hd)); 280bd4524edSaurel32 281343bd85aSMark Cave-Ayland /* MacIO */ 282017812dfSMark Cave-Ayland macio = OLDWORLD_MACIO(pci_create(pci_bus, -1, TYPE_OLDWORLD_MACIO)); 28307a7484eSAndreas Färber dev = DEVICE(macio); 284b981289cSAlexander Graf qdev_prop_set_uint64(dev, "frequency", tbfreq); 285017812dfSMark Cave-Ayland object_property_set_link(OBJECT(macio), OBJECT(pic_dev), "pic", 286017812dfSMark Cave-Ayland &error_abort); 287b6712ea3SMark Cave-Ayland qdev_init_nofail(dev); 28807a7484eSAndreas Färber 28907a7484eSAndreas Färber macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 29014eefd0eSAlexander Graf "ide[0]")); 29107a7484eSAndreas Färber macio_ide_init_drives(macio_ide, hd); 29207a7484eSAndreas Färber 29314eefd0eSAlexander Graf macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 29414eefd0eSAlexander Graf "ide[1]")); 29514eefd0eSAlexander Graf macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]); 2963cbee15bSj_mayer 297293c867dSAndreas Färber dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda")); 298293c867dSAndreas Färber adb_bus = qdev_get_child_bus(dev, "adb.0"); 299293c867dSAndreas Färber dev = qdev_create(adb_bus, TYPE_ADB_KEYBOARD); 3002e4a7c9cSAndreas Färber qdev_init_nofail(dev); 301293c867dSAndreas Färber dev = qdev_create(adb_bus, TYPE_ADB_MOUSE); 3022e4a7c9cSAndreas Färber qdev_init_nofail(dev); 30345fa67fbSAndreas Färber 3044bcbe0b6SEduardo Habkost if (machine_usb(machine)) { 305afb9a60eSGerd Hoffmann pci_create_simple(pci_bus, -1, "pci-ohci"); 3063cbee15bSj_mayer } 3073cbee15bSj_mayer 3083cbee15bSj_mayer if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) 3093cbee15bSj_mayer graphic_depth = 15; 3103cbee15bSj_mayer 3113cbee15bSj_mayer /* No PCI init: the BIOS will do it */ 3123cbee15bSj_mayer 31381a07050SMark Cave-Ayland dev = qdev_create(NULL, TYPE_FW_CFG_MEM); 31481a07050SMark Cave-Ayland fw_cfg = FW_CFG(dev); 31581a07050SMark Cave-Ayland qdev_prop_set_uint32(dev, "data_width", 1); 31681a07050SMark Cave-Ayland qdev_prop_set_bit(dev, "dma_enabled", false); 31781a07050SMark Cave-Ayland object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, 31881a07050SMark Cave-Ayland OBJECT(fw_cfg), NULL); 31981a07050SMark Cave-Ayland qdev_init_nofail(dev); 32081a07050SMark Cave-Ayland s = SYS_BUS_DEVICE(dev); 32181a07050SMark Cave-Ayland sysbus_mmio_map(s, 0, CFG_ADDR); 32281a07050SMark Cave-Ayland sysbus_mmio_map(s, 1, CFG_ADDR + 2); 32381a07050SMark Cave-Ayland 3245836d168SIgor Mammedov fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); 325fe6b6346SLike Xu fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus); 326271dd5e0Sblueswir1 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); 327271dd5e0Sblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW); 328513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); 329513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 330513f789fSblueswir1 if (kernel_cmdline) { 331b9e17a34SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); 332b9e17a34SAlexander Graf pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline); 333513f789fSblueswir1 } else { 334513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); 335513f789fSblueswir1 } 336513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); 337513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 338513f789fSblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device); 3397f1aec5fSLaurent Vivier 3407f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); 3417f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); 3427f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); 3437f1aec5fSLaurent Vivier 34445024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); 345dc333cd6SAlexander Graf if (kvm_enabled()) { 34645024f09SAlexander Graf uint8_t *hypercall; 34745024f09SAlexander Graf 3487267c094SAnthony Liguori hypercall = g_malloc(16); 34945024f09SAlexander Graf kvmppc_get_hypercall(env, hypercall, 16); 35045024f09SAlexander Graf fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); 35145024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); 352dc333cd6SAlexander Graf } 353caae6c96SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq); 354a1014f25SAlexander Graf /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ 3559d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); 3569d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); 357dc333cd6SAlexander Graf 358b50de5cdSMark Cave-Ayland /* MacOS NDRV VGA driver */ 359b50de5cdSMark Cave-Ayland filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME); 360b50de5cdSMark Cave-Ayland if (filename) { 3619776874fSPeter Maydell gchar *ndrv_file; 3629776874fSPeter Maydell gsize ndrv_size; 363b50de5cdSMark Cave-Ayland 3649776874fSPeter Maydell if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) { 365b50de5cdSMark Cave-Ayland fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size); 366b50de5cdSMark Cave-Ayland } 367b50de5cdSMark Cave-Ayland g_free(filename); 368b50de5cdSMark Cave-Ayland } 369b50de5cdSMark Cave-Ayland 370513f789fSblueswir1 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); 3713cbee15bSj_mayer } 3723cbee15bSj_mayer 373bbcc635fSMark Cave-Ayland /* 374bbcc635fSMark Cave-Ayland * Implementation of an interface to adjust firmware path 375bbcc635fSMark Cave-Ayland * for the bootindex property handling. 376bbcc635fSMark Cave-Ayland */ 377bbcc635fSMark Cave-Ayland static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus, 378bbcc635fSMark Cave-Ayland DeviceState *dev) 379bbcc635fSMark Cave-Ayland { 380bbcc635fSMark Cave-Ayland PCIDevice *pci; 381bbcc635fSMark Cave-Ayland IDEBus *ide_bus; 382bbcc635fSMark Cave-Ayland IDEState *ide_s; 383bbcc635fSMark Cave-Ayland MACIOIDEState *macio_ide; 384bbcc635fSMark Cave-Ayland 385bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-oldworld")) { 386bbcc635fSMark Cave-Ayland pci = PCI_DEVICE(dev); 387bbcc635fSMark Cave-Ayland return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn)); 388bbcc635fSMark Cave-Ayland } 389bbcc635fSMark Cave-Ayland 390bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) { 391bbcc635fSMark Cave-Ayland macio_ide = MACIO_IDE(dev); 392bbcc635fSMark Cave-Ayland return g_strdup_printf("ata-3@%x", macio_ide->addr); 393bbcc635fSMark Cave-Ayland } 394bbcc635fSMark Cave-Ayland 395bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-drive")) { 396bbcc635fSMark Cave-Ayland ide_bus = IDE_BUS(qdev_get_parent_bus(dev)); 397bbcc635fSMark Cave-Ayland ide_s = idebus_active_if(ide_bus); 398bbcc635fSMark Cave-Ayland 399bbcc635fSMark Cave-Ayland if (ide_s->drive_kind == IDE_CD) { 400bbcc635fSMark Cave-Ayland return g_strdup("cdrom"); 401bbcc635fSMark Cave-Ayland } 402bbcc635fSMark Cave-Ayland 403484d366eSMark Cave-Ayland return g_strdup("disk"); 404bbcc635fSMark Cave-Ayland } 405bbcc635fSMark Cave-Ayland 406bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) { 407484d366eSMark Cave-Ayland return g_strdup("disk"); 408bbcc635fSMark Cave-Ayland } 409bbcc635fSMark Cave-Ayland 410bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) { 411bbcc635fSMark Cave-Ayland return g_strdup("cdrom"); 412bbcc635fSMark Cave-Ayland } 413bbcc635fSMark Cave-Ayland 414bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) { 415bbcc635fSMark Cave-Ayland return g_strdup("disk"); 416bbcc635fSMark Cave-Ayland } 417bbcc635fSMark Cave-Ayland 418bbcc635fSMark Cave-Ayland return NULL; 419bbcc635fSMark Cave-Ayland } 420bbcc635fSMark Cave-Ayland 421dc0ca80eSEric Auger static int heathrow_kvm_type(MachineState *machine, const char *arg) 422277c7a4dSAlexander Graf { 423277c7a4dSAlexander Graf /* Always force PR KVM */ 424277c7a4dSAlexander Graf return 2; 425277c7a4dSAlexander Graf } 426277c7a4dSAlexander Graf 427c8bd3526SMark Cave-Ayland static void heathrow_class_init(ObjectClass *oc, void *data) 428e264d29dSEduardo Habkost { 429c8bd3526SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc); 430bbcc635fSMark Cave-Ayland FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc); 431c8bd3526SMark Cave-Ayland 432e264d29dSEduardo Habkost mc->desc = "Heathrow based PowerMAC"; 433e264d29dSEduardo Habkost mc->init = ppc_heathrow_init; 4342059839bSMarkus Armbruster mc->block_default_type = IF_IDE; 435e264d29dSEduardo Habkost mc->max_cpus = MAX_CPUS; 43646214a27SAndreas Färber #ifndef TARGET_PPC64 437ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true; 43846214a27SAndreas Färber #endif 439f309ae85SEduardo Habkost /* TOFIX "cad" when Mac floppy is implemented */ 440e264d29dSEduardo Habkost mc->default_boot_order = "cd"; 441e264d29dSEduardo Habkost mc->kvm_type = heathrow_kvm_type; 442f4c6604eSIgor Mammedov mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1"); 4433232794bSMark Cave-Ayland mc->default_display = "std"; 444bbcc635fSMark Cave-Ayland mc->ignore_boot_device_suffixes = true; 4458ee06e4cSIgor Mammedov mc->default_ram_id = "ppc_heathrow.ram"; 446bbcc635fSMark Cave-Ayland fwc->get_dev_path = heathrow_fw_dev_path; 447f80f9ec9SAnthony Liguori } 448f80f9ec9SAnthony Liguori 449c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = { 450c8bd3526SMark Cave-Ayland .name = MACHINE_TYPE_NAME("g3beige"), 451c8bd3526SMark Cave-Ayland .parent = TYPE_MACHINE, 452bbcc635fSMark Cave-Ayland .class_init = heathrow_class_init, 453bbcc635fSMark Cave-Ayland .interfaces = (InterfaceInfo[]) { 454bbcc635fSMark Cave-Ayland { TYPE_FW_PATH_PROVIDER }, 455bbcc635fSMark Cave-Ayland { } 456bbcc635fSMark Cave-Ayland }, 457c8bd3526SMark Cave-Ayland }; 458c8bd3526SMark Cave-Ayland 459c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void) 460c8bd3526SMark Cave-Ayland { 461c8bd3526SMark Cave-Ayland type_register_static(&ppc_heathrow_machine_info); 462c8bd3526SMark Cave-Ayland } 463c8bd3526SMark Cave-Ayland 464c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types); 465